Skip to content

(gpu) change code convention #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,22 @@ BitFieldColonSpacing: After
BreakBeforeConceptDeclarations: 'true'
BreakBinaryOperations: RespectPrecedence
EmptyLineBeforeAccessModifier: LogicalBlock
EnumTrailingComma: Insert
FixNamespaceComments: 'true'
IndentExternBlock: Indent
IndentGotoLabels: 'false'
IndentRequiresClause: 'true'
InsertBraces: 'false'
InsertTrailingCommas: Wrapped
LambdaBodyIndentation: Signature
PPIndentWidth: 4
PenaltyBreakAssignment: 1000
PenaltyReturnTypeOnItsOwnLine: 1000
PenaltyBreakBeforeFirstCallParameter: 1000
PenaltyBreakOpenParenthesis: 1000
PenaltyBreakBeforeMemberAccess: 10
PenaltyIndentedWhitespace: 1
ContinuationIndentWidth: 2
ReferenceAlignment: Left
# RemoveBracesLLVM: 'true'
RequiresClausePosition: OwnLine
Expand All @@ -40,9 +49,18 @@ SpaceBeforeCaseColon: 'false'
AlwaysBreakAfterDefinitionReturnType: None
SpaceBeforeSquareBrackets: 'false'
SpaceInEmptyBlock: 'false'
AttributeMacros: [STORMKIT_FORCE_INLINE, STORMKIT_API, STORMKIT_PRIVATE, STORMKIT_PUBLIC]
AttributeMacros: [STORMKIT_FORCE_INLINE, STORMKIT_API, STORMKIT_PRIVATE, STORMKIT_PUBLIC, STORMKIT_CONST, STORMKIT_PURE, STORMKIT_INTRINSIC]
IfMacros: [CASE_DO, CASE_DO_RETURN, CASE, CASE_ARGS_DO]
BreakAfterAttributes: Always
Macros:
- STORMKIT_FORCE_INLINE=[[maybe_unused]]
- STORMKIT_API=[[maybe_unused]]
- STORMKIT_PRIVATE=[[maybe_unused]]
- STORMKIT_PUBLIC=[[maybe_unused]]
- STORMKIT_CONST=[[maybe_unused]]
- STORMKIT_PURE=[[maybe_unused]]
- STORMKIT_INTRINSIC=[[maybe_unused]]

QualifierAlignment: Custom
QualifierOrder: [static, inline, volatile, restrict, constexpr, const, type]

Expand All @@ -64,7 +82,6 @@ ColumnLimit: '100'
CompactNamespaces: 'true'
ConstructorInitializerAllOnOneLineOrOnePerLine: 'false'
ConstructorInitializerIndentWidth: '4'
ContinuationIndentWidth: '4'
IncludeBlocks: Preserve
IndentCaseLabels: 'true'
IndentWidth: '4'
Expand All @@ -76,7 +93,6 @@ MaxEmptyLinesToKeep: '1'
NamespaceIndentation: All
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: false
PenaltyBreakAssignment: '0'
PointerAlignment: Left
SortIncludes: 'true'
SortUsingDeclarations: 'true'
Expand All @@ -91,7 +107,6 @@ SpacesInAngles: 'false'
Standard: c++20
TabWidth: '4'
UseTab: Never
PenaltyBreakBeforeFirstCallParameter: '120'
---
Language: ObjC
AlignAfterOpenBracket: Align
Expand Down Expand Up @@ -137,8 +152,12 @@ MaxEmptyLinesToKeep: '1'
NamespaceIndentation: All
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: false
PenaltyBreakAssignment: '0'
PointerAlignment: Right
PenaltyBreakAssignment: 1000
PenaltyReturnTypeOnItsOwnLine: 1000
PenaltyBreakBeforeFirstCallParameter: 1000
PenaltyBreakOpenParenthesis: 1000
PenaltyBreakBeforeMemberAccess: 10
SortIncludes: 'true'
SortUsingDeclarations: 'true'
SpaceAfterTemplateKeyword: 'false'
Expand All @@ -152,7 +171,6 @@ SpacesInAngles: 'false'
Standard: c++20
TabWidth: '4'
UseTab: Never
PenaltyBreakBeforeFirstCallParameter: '120'
PenaltyIndentedWhitespace: '1'
QualifierAlignment: Custom
QualifierOrder: [static, inline, volatile, restrict, constexpr, const, type]
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/Linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ jobs:
libelf-dev
libdwarf-dev
mold
nasm
llvm${{ env.LLVM_VERSION }}
llvm${{ env.LLVM_VERSION }}-dev
llvm${{ env.LLVM_VERSION }}-runtime
Expand Down Expand Up @@ -123,7 +124,7 @@ jobs:
- name: Setup XMake
uses: xmake-io/github-action-setup-xmake@v1
with:
xmake-version: Arthapz/xmake#branch@improve-jobgraph-support2
xmake-version: Arthapz/xmake#branch@dev-arthapz
actions-cache-folder: .xmake-cache

- name: Cache XMake
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
if: ${{ !steps.restore-xmakecache.outputs.cache-hit }}
uses: xmake-io/github-action-setup-xmake@v1
with:
xmake-version: Arthapz/xmake#branch@fix-cmake-clang-msstl
xmake-version: Arthapz/xmake#branch@dev-arthapz
actions-cache-folder: '.xmake-cache'

- name: Cache XMake
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/macOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
- name: Install build tools
uses: tecolicom/actions-use-homebrew-tools@v1
with:
tools: llvm ninja meson mold
tools: llvm ninja meson mold nasm pkgconf
verbose: true

- name: Checkout
Expand Down Expand Up @@ -78,7 +78,7 @@ jobs:
- name: Setup XMake
uses: xmake-io/github-action-setup-xmake@v1
with:
xmake-version: Arthapz/xmake#branch@improve-jobgraph-support2
xmake-version: Arthapz/xmake#branch@dev-arthapz
actions-cache-folder: .xmake-cache

- name: Cache XMake
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// This file is subject to the license terms in the LICENSE file
// found in the top-level of this distribution

module stormkit.Gpu;
module stormkit.gpu;

import std;

import stormkit.core;

import stormkit.Gpu.Vulkan;
import stormkit.gpu.vulkan;
import :Core;
import :Execution.CommandBuffer;

Expand Down Expand Up @@ -44,12 +44,12 @@ namespace stormkit::gpu {

if (create_count > 0) {
const auto allocate_info
= vk::CommandBufferAllocateInfo { .commandPool = *vkHandle(),
= vk::CommandBufferAllocateInfo { .commandPool = *native_handle(),
.level = narrow<vk::CommandBufferLevel>(level),
.commandBufferCount = as<UInt32>(count) };

// TODO handle error here
std::ranges::move(device.vkHandle()
std::ranges::move(device.native_handle()
.allocateCommandBuffers(allocate_info)
.transform_error(core :.monadic::assert(
std::format("Failed to allocate {} command buffers",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// This file is subject to the license terms in the LICENSE file
// found in the top-level of this distribution

module stormkit.Gpu;
module stormkit.gpu;

import std;

import stormkit.core;

import stormkit.Gpu.Vulkan;
import stormkit.gpu.vulkan;
import :Core;
import :Execution.Pipeline;
import :Execution.RenderPass;
Expand All @@ -17,7 +17,7 @@ import :Execution.RasterPipelineState;
namespace stormkit::gpu {
/////////////////////////////////////
/////////////////////////////////////
auto Pipeline::doInitRasterPipeline(const Device& device,
auto Pipeline::do_initRasterPipeline(const Device& device,
const PipelineLayout& layout,
const RenderPass& render_pass,
OptionalRef<const PipelineCache> pipeline_cache) noexcept
Expand Down Expand Up @@ -75,7 +75,7 @@ namespace stormkit::gpu {
.depthClampEnable = state.rasterization_state.depth_clamp_enable,
.rasterizerDiscardEnable = state.rasterization_state.rasterizer_discard_enable,
.polygonMode = narrow<vk::PolygonMode>(state.rasterization_state.polygon_mode),
.cullMode = toVkFlags<vk::CullModeFlagBits>(state.rasterization_state.cull_mode),
.cullMode = to_vkflags<vk::CullModeFlagBits>(state.rasterization_state.cull_mode),
.frontFace = narrow<vk::FrontFace>(state.rasterization_state.front_face),
.lineWidth = state.rasterization_state.line_width
};
Expand All @@ -97,7 +97,7 @@ namespace stormkit::gpu {
.srcAlphaBlendFactor = narrow<vk::BlendFactor>(attachment.src_alpha_blend_factor),
.dstAlphaBlendFactor = narrow<vk::BlendFactor>(attachment.dst_alpha_blend_factor),
.alphaBlendOp = narrow<vk::BlendOp>(attachment.alpha_blend_operation),
.colorWriteMask = toVkFlags<vk::ColorComponentFlagBits>(attachment.color_write_mask)
.colorWriteMask = to_vkflags<vk::ColorComponentFlagBits>(attachment.color_write_mask)
};
})
| std::ranges::to<std::vector>();
Expand All @@ -124,7 +124,7 @@ namespace stormkit::gpu {
static constexpr auto NAME = "main";
return vk::PipelineShaderStageCreateInfo {
.stage = narrow<vk::ShaderStageFlagBits>(shader->type()),
.module = toVkHandle(shader),
.module = to_vkhandle(shader),
.pName = NAME
};
})
Expand All @@ -149,8 +149,8 @@ namespace stormkit::gpu {
.pDepthStencilState = &depth_stencil,
.pColorBlendState = &color_blending,
.pDynamicState = &dynamic_state,
.layout = toVkHandle(layout),
.renderPass = toVkHandle(render_pass),
.layout = to_vkhandle(layout),
.renderPass = to_vkhandle(render_pass),
.subpass = 0,
.basePipelineHandle = nullptr,
.basePipelineIndex = -1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This file is subject to the license terms in the LICENSE file
// found in the top-level of this distribution

module stormkit.Gpu;
module stormkit.gpu;

import std;

Expand All @@ -11,17 +11,17 @@ import stormkit.log;

#include <stormkit/log/log_macro.hpp>

import stormkit.Gpu.Vulkan;
import stormkit.gpu.vulkan;
import :Core;
import :Execution.Pipeline;

namespace stormkit::gpu {
LOGGER("stormkit.Gpu")
LOGGER("stormkit.gpu")

/////////////////////////////////////
/////////////////////////////////////
auto PipelineCache::createNewPipelineCache(const Device& device) -> VulkanExpected<void> {
const auto physical_device_infos = device.physicalDevice().info();
const auto physical_device_infos = device.physical_device().info();

m_serialized.guard.magic = MAGIC;
m_serialized.guard.data_size = 0u;
Expand All @@ -34,7 +34,7 @@ namespace stormkit::gpu {
std::ranges::copy(physical_device_infos.pipeline_cache_uuid,
std::ranges::begin(m_serialized.uuid.value));

return device.vkHandle()
return device.native_handle()
.createPipelineCache({})
.transform(core :.monadic::set(m_vk_pipeline_cache))
.transform([this] noexcept -> void {
Expand All @@ -45,7 +45,7 @@ namespace stormkit::gpu {
/////////////////////////////////////
/////////////////////////////////////
auto PipelineCache::readPipelineCache(const Device& device) -> VulkanExpected<void> {
const auto physical_device_infos = device.physicalDevice().info();
const auto physical_device_infos = device.physical_device().info();

auto stream = std::ifstream { m_path.string(), std::ios::binary };
read(stream, as_bytes(m_serialized.guard));
Expand Down Expand Up @@ -96,7 +96,7 @@ namespace stormkit::gpu {

const auto create_info = vk::PipelineCacheCreateInfo {}.setInitialData<Byte>(data);

return device.vkHandle()
return device.native_handle()
.createPipelineCache(create_info)
.transform(core :.monadic::set(m_vk_pipeline_cache))
.transform([this]() noexcept -> void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// This file is subject to the license terms in the LICENSE file
// found in the top-level of this distribution

module stormkit.Gpu;
module stormkit.gpu;

import std;

import stormkit.core;

import :Execution.RenderPass;

import stormkit.Gpu.Vulkan;
import stormkit.gpu.vulkan;
import :Core;
import :Execution.RenderPass;

Expand All @@ -27,7 +27,7 @@ namespace stormkit::gpu {

/////////////////////////////////////
/////////////////////////////////////
auto RenderPass::doInitRenderPass(const Device& device) noexcept -> VulkanExpected<void> {
auto RenderPass::do_initRenderPass(const Device& device) noexcept -> VulkanExpected<void> {
const auto attachments
= m_description.attachments
| std::views::transform([](auto&& attachment) {
Expand Down Expand Up @@ -93,7 +93,7 @@ namespace stormkit::gpu {
.setSubpasses(subpasses)
.setDependencies(subpasses_deps);

return device.vkHandle()
return device.native_handle()
.createRenderPass(create_info)
.transform(core :.monadic::set(m_vk_render_pass));
}
Expand Down
69 changes: 69 additions & 0 deletions backup-src/resource/buffer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright (C) 2024 Arthur LAURENT <[email protected]>
// This file is subject to the license terms in the LICENSE file
// found in the top-level of this distribution

module stormkit.gpu;

import std;

import stormkit.core;

import :core;
import stormkit.gpu.vulkan;

import :resource.buffer;

namespace stormkit::gpu {
/////////////////////////////////////
/////////////////////////////////////
auto Buffer::do_init() noexcept -> Expected<void> {
const auto create_info = VkBufferCreateInfo {
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
.size = m_size,
.usage = to_vkflags(m_usages),
.sharingMode = VK_SHARING_MODE_EXCLUSIVE
};
return vk_call(vkCreateBuffer, m_vk_device, &create_info, nullptr)
.transform(core::monadic::set(m_vk_handle))
.transform([this, &info, &device]() noexcept -> VulkanExpected<void> {
const auto requirements = vk_call<VkMemoryRequirements>(m_vk_device, m_vk_handle);

const auto allocate_info = VmaAllocationCreateInfo {
.requiredFlags = to_vkflags(info.property)
};

auto&& allocator = device.vmaAllocator();

auto&& [error, vma_allocation] = allocator
.allocateMemoryUnique(requirements, allocate_info);
if (error != vk::Result::eSuccess)
return std::unexpected { narrow<vk::Result>(error) };

m_vma_allocation = std::move(vma_allocation);

error = allocator.bindBufferMemory(*m_vma_allocation, *m_vk_buffer.get());
if (error != vk::Result::eSuccess)
return std::unexpected { narrow<vk::Result>(error) };

if (m_is_persistently_mapped) auto _ = map(device, 0u);

return {};
})
.transform_error(monadic::from_vkflags<Result>());
}

/////////////////////////////////////
/////////////////////////////////////
auto Buffer::find_memory_type(UInt type_filter,
vk::MemoryPropertyFlags properties,
const vk::PhysicalDeviceMemoryProperties& mem_properties,
const vk::MemoryRequirements&) -> UInt {
for (auto i : range(mem_properties.memoryTypeCount)) {
if ((type_filter & (1 << i))
and (check_flag_bit(mem_properties.memoryTypes[i].propertyFlags, properties)))
return i;
}

return 0;
}
} // namespace stormkit::gpu
Loading