Skip to content

Commit 85a134a

Browse files
committed
(gpu) change code convention
1 parent 4b9c65f commit 85a134a

File tree

126 files changed

+8387
-4245
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+8387
-4245
lines changed

.clang-format

+24-6
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,22 @@ BitFieldColonSpacing: After
2323
BreakBeforeConceptDeclarations: 'true'
2424
BreakBinaryOperations: RespectPrecedence
2525
EmptyLineBeforeAccessModifier: LogicalBlock
26+
EnumTrailingComma: Insert
27+
FixNamespaceComments: 'true'
2628
IndentExternBlock: Indent
2729
IndentGotoLabels: 'false'
2830
IndentRequiresClause: 'true'
2931
InsertBraces: 'false'
3032
InsertTrailingCommas: Wrapped
3133
LambdaBodyIndentation: Signature
3234
PPIndentWidth: 4
35+
PenaltyBreakAssignment: 1000
36+
PenaltyReturnTypeOnItsOwnLine: 1000
37+
PenaltyBreakBeforeFirstCallParameter: 1000
38+
PenaltyBreakOpenParenthesis: 1000
39+
PenaltyBreakBeforeMemberAccess: 10
40+
PenaltyIndentedWhitespace: 1
41+
ContinuationIndentWidth: 2
3342
ReferenceAlignment: Left
3443
# RemoveBracesLLVM: 'true'
3544
RequiresClausePosition: OwnLine
@@ -40,9 +49,18 @@ SpaceBeforeCaseColon: 'false'
4049
AlwaysBreakAfterDefinitionReturnType: None
4150
SpaceBeforeSquareBrackets: 'false'
4251
SpaceInEmptyBlock: 'false'
43-
AttributeMacros: [STORMKIT_FORCE_INLINE, STORMKIT_API, STORMKIT_PRIVATE, STORMKIT_PUBLIC]
52+
AttributeMacros: [STORMKIT_FORCE_INLINE, STORMKIT_API, STORMKIT_PRIVATE, STORMKIT_PUBLIC, STORMKIT_CONST, STORMKIT_PURE, STORMKIT_INTRINSIC]
4453
IfMacros: [CASE_DO, CASE_DO_RETURN, CASE, CASE_ARGS_DO]
4554
BreakAfterAttributes: Always
55+
Macros:
56+
- STORMKIT_FORCE_INLINE=[[maybe_unused]]
57+
- STORMKIT_API=[[maybe_unused]]
58+
- STORMKIT_PRIVATE=[[maybe_unused]]
59+
- STORMKIT_PUBLIC=[[maybe_unused]]
60+
- STORMKIT_CONST=[[maybe_unused]]
61+
- STORMKIT_PURE=[[maybe_unused]]
62+
- STORMKIT_INTRINSIC=[[maybe_unused]]
63+
4664
QualifierAlignment: Custom
4765
QualifierOrder: [static, inline, volatile, restrict, constexpr, const, type]
4866

@@ -64,7 +82,6 @@ ColumnLimit: '100'
6482
CompactNamespaces: 'true'
6583
ConstructorInitializerAllOnOneLineOrOnePerLine: 'false'
6684
ConstructorInitializerIndentWidth: '4'
67-
ContinuationIndentWidth: '4'
6885
IncludeBlocks: Preserve
6986
IndentCaseLabels: 'true'
7087
IndentWidth: '4'
@@ -76,7 +93,6 @@ MaxEmptyLinesToKeep: '1'
7693
NamespaceIndentation: All
7794
ObjCSpaceAfterProperty: true
7895
ObjCSpaceBeforeProtocolList: false
79-
PenaltyBreakAssignment: '0'
8096
PointerAlignment: Left
8197
SortIncludes: 'true'
8298
SortUsingDeclarations: 'true'
@@ -91,7 +107,6 @@ SpacesInAngles: 'false'
91107
Standard: c++20
92108
TabWidth: '4'
93109
UseTab: Never
94-
PenaltyBreakBeforeFirstCallParameter: '120'
95110
---
96111
Language: ObjC
97112
AlignAfterOpenBracket: Align
@@ -137,8 +152,12 @@ MaxEmptyLinesToKeep: '1'
137152
NamespaceIndentation: All
138153
ObjCSpaceAfterProperty: true
139154
ObjCSpaceBeforeProtocolList: false
140-
PenaltyBreakAssignment: '0'
141155
PointerAlignment: Right
156+
PenaltyBreakAssignment: 1000
157+
PenaltyReturnTypeOnItsOwnLine: 1000
158+
PenaltyBreakBeforeFirstCallParameter: 1000
159+
PenaltyBreakOpenParenthesis: 1000
160+
PenaltyBreakBeforeMemberAccess: 10
142161
SortIncludes: 'true'
143162
SortUsingDeclarations: 'true'
144163
SpaceAfterTemplateKeyword: 'false'
@@ -152,7 +171,6 @@ SpacesInAngles: 'false'
152171
Standard: c++20
153172
TabWidth: '4'
154173
UseTab: Never
155-
PenaltyBreakBeforeFirstCallParameter: '120'
156174
PenaltyIndentedWhitespace: '1'
157175
QualifierAlignment: Custom
158176
QualifierOrder: [static, inline, volatile, restrict, constexpr, const, type]

.github/workflows/Linux.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ jobs:
7979
libelf-dev
8080
libdwarf-dev
8181
mold
82+
nasm
8283
llvm${{ env.LLVM_VERSION }}
8384
llvm${{ env.LLVM_VERSION }}-dev
8485
llvm${{ env.LLVM_VERSION }}-runtime
@@ -123,7 +124,7 @@ jobs:
123124
- name: Setup XMake
124125
uses: xmake-io/github-action-setup-xmake@v1
125126
with:
126-
xmake-version: Arthapz/xmake#branch@improve-jobgraph-support2
127+
xmake-version: Arthapz/xmake#branch@dev-arthapz
127128
actions-cache-folder: .xmake-cache
128129

129130
- name: Cache XMake

.github/workflows/Windows.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ jobs:
8282
if: ${{ !steps.restore-xmakecache.outputs.cache-hit }}
8383
uses: xmake-io/github-action-setup-xmake@v1
8484
with:
85-
xmake-version: Arthapz/xmake#branch@fix-cmake-clang-msstl
85+
xmake-version: Arthapz/xmake#branch@dev-arthapz
8686
actions-cache-folder: '.xmake-cache'
8787

8888
- name: Cache XMake

.github/workflows/macOS.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
- name: Install build tools
5050
uses: tecolicom/actions-use-homebrew-tools@v1
5151
with:
52-
tools: llvm ninja meson mold
52+
tools: llvm ninja meson mold nasm pkgconf
5353
verbose: true
5454

5555
- name: Checkout
@@ -78,7 +78,7 @@ jobs:
7878
- name: Setup XMake
7979
uses: xmake-io/github-action-setup-xmake@v1
8080
with:
81-
xmake-version: Arthapz/xmake#branch@improve-jobgraph-support2
81+
xmake-version: Arthapz/xmake#branch@dev-arthapz
8282
actions-cache-folder: .xmake-cache
8383

8484
- name: Cache XMake

src/Gpu/Execution/CommandPool.cpp renamed to backup-src/execution/command_pool.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
// This file is subject to the license terms in the LICENSE file
33
// found in the top-level of this distribution
44

5-
module stormkit.Gpu;
5+
module stormkit.gpu;
66

77
import std;
88

99
import stormkit.core;
1010

11-
import stormkit.Gpu.Vulkan;
11+
import stormkit.gpu.vulkan;
1212
import :Core;
1313
import :Execution.CommandBuffer;
1414

@@ -44,12 +44,12 @@ namespace stormkit::gpu {
4444

4545
if (create_count > 0) {
4646
const auto allocate_info
47-
= vk::CommandBufferAllocateInfo { .commandPool = *vkHandle(),
47+
= vk::CommandBufferAllocateInfo { .commandPool = *native_handle(),
4848
.level = narrow<vk::CommandBufferLevel>(level),
4949
.commandBufferCount = as<UInt32>(count) };
5050

5151
// TODO handle error here
52-
std::ranges::move(device.vkHandle()
52+
std::ranges::move(device.native_handle()
5353
.allocateCommandBuffers(allocate_info)
5454
.transform_error(core :.monadic::assert(
5555
std::format("Failed to allocate {} command buffers",

src/Gpu/Execution/Pipeline.cpp renamed to backup-src/execution/pipeline.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
// This file is subject to the license terms in the LICENSE file
33
// found in the top-level of this distribution
44

5-
module stormkit.Gpu;
5+
module stormkit.gpu;
66

77
import std;
88

99
import stormkit.core;
1010

11-
import stormkit.Gpu.Vulkan;
11+
import stormkit.gpu.vulkan;
1212
import :Core;
1313
import :Execution.Pipeline;
1414
import :Execution.RenderPass;
@@ -17,7 +17,7 @@ import :Execution.RasterPipelineState;
1717
namespace stormkit::gpu {
1818
/////////////////////////////////////
1919
/////////////////////////////////////
20-
auto Pipeline::doInitRasterPipeline(const Device& device,
20+
auto Pipeline::do_initRasterPipeline(const Device& device,
2121
const PipelineLayout& layout,
2222
const RenderPass& render_pass,
2323
OptionalRef<const PipelineCache> pipeline_cache) noexcept
@@ -75,7 +75,7 @@ namespace stormkit::gpu {
7575
.depthClampEnable = state.rasterization_state.depth_clamp_enable,
7676
.rasterizerDiscardEnable = state.rasterization_state.rasterizer_discard_enable,
7777
.polygonMode = narrow<vk::PolygonMode>(state.rasterization_state.polygon_mode),
78-
.cullMode = toVkFlags<vk::CullModeFlagBits>(state.rasterization_state.cull_mode),
78+
.cullMode = to_vkflags<vk::CullModeFlagBits>(state.rasterization_state.cull_mode),
7979
.frontFace = narrow<vk::FrontFace>(state.rasterization_state.front_face),
8080
.lineWidth = state.rasterization_state.line_width
8181
};
@@ -97,7 +97,7 @@ namespace stormkit::gpu {
9797
.srcAlphaBlendFactor = narrow<vk::BlendFactor>(attachment.src_alpha_blend_factor),
9898
.dstAlphaBlendFactor = narrow<vk::BlendFactor>(attachment.dst_alpha_blend_factor),
9999
.alphaBlendOp = narrow<vk::BlendOp>(attachment.alpha_blend_operation),
100-
.colorWriteMask = toVkFlags<vk::ColorComponentFlagBits>(attachment.color_write_mask)
100+
.colorWriteMask = to_vkflags<vk::ColorComponentFlagBits>(attachment.color_write_mask)
101101
};
102102
})
103103
| std::ranges::to<std::vector>();
@@ -124,7 +124,7 @@ namespace stormkit::gpu {
124124
static constexpr auto NAME = "main";
125125
return vk::PipelineShaderStageCreateInfo {
126126
.stage = narrow<vk::ShaderStageFlagBits>(shader->type()),
127-
.module = toVkHandle(shader),
127+
.module = to_vkhandle(shader),
128128
.pName = NAME
129129
};
130130
})
@@ -149,8 +149,8 @@ namespace stormkit::gpu {
149149
.pDepthStencilState = &depth_stencil,
150150
.pColorBlendState = &color_blending,
151151
.pDynamicState = &dynamic_state,
152-
.layout = toVkHandle(layout),
153-
.renderPass = toVkHandle(render_pass),
152+
.layout = to_vkhandle(layout),
153+
.renderPass = to_vkhandle(render_pass),
154154
.subpass = 0,
155155
.basePipelineHandle = nullptr,
156156
.basePipelineIndex = -1

src/Gpu/Execution/PipelineCache.cpp renamed to backup-src/execution/pipeline_cache.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// This file is subject to the license terms in the LICENSE file
33
// found in the top-level of this distribution
44

5-
module stormkit.Gpu;
5+
module stormkit.gpu;
66

77
import std;
88

@@ -11,17 +11,17 @@ import stormkit.log;
1111

1212
#include <stormkit/log/log_macro.hpp>
1313

14-
import stormkit.Gpu.Vulkan;
14+
import stormkit.gpu.vulkan;
1515
import :Core;
1616
import :Execution.Pipeline;
1717

1818
namespace stormkit::gpu {
19-
LOGGER("stormkit.Gpu")
19+
LOGGER("stormkit.gpu")
2020

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

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

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

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

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

99-
return device.vkHandle()
99+
return device.native_handle()
100100
.createPipelineCache(create_info)
101101
.transform(core :.monadic::set(m_vk_pipeline_cache))
102102
.transform([this]() noexcept -> void {

src/Gpu/Execution/RenderPass.cpp renamed to backup-src/execution/render_pass.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
// This file is subject to the license terms in the LICENSE file
33
// found in the top-level of this distribution
44

5-
module stormkit.Gpu;
5+
module stormkit.gpu;
66

77
import std;
88

99
import stormkit.core;
1010

1111
import :Execution.RenderPass;
1212

13-
import stormkit.Gpu.Vulkan;
13+
import stormkit.gpu.vulkan;
1414
import :Core;
1515
import :Execution.RenderPass;
1616

@@ -27,7 +27,7 @@ namespace stormkit::gpu {
2727

2828
/////////////////////////////////////
2929
/////////////////////////////////////
30-
auto RenderPass::doInitRenderPass(const Device& device) noexcept -> VulkanExpected<void> {
30+
auto RenderPass::do_initRenderPass(const Device& device) noexcept -> VulkanExpected<void> {
3131
const auto attachments
3232
= m_description.attachments
3333
| std::views::transform([](auto&& attachment) {
@@ -93,7 +93,7 @@ namespace stormkit::gpu {
9393
.setSubpasses(subpasses)
9494
.setDependencies(subpasses_deps);
9595

96-
return device.vkHandle()
96+
return device.native_handle()
9797
.createRenderPass(create_info)
9898
.transform(core :.monadic::set(m_vk_render_pass));
9999
}

backup-src/resource/buffer.cpp

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright (C) 2024 Arthur LAURENT <[email protected]>
2+
// This file is subject to the license terms in the LICENSE file
3+
// found in the top-level of this distribution
4+
5+
module stormkit.gpu;
6+
7+
import std;
8+
9+
import stormkit.core;
10+
11+
import :core;
12+
import stormkit.gpu.vulkan;
13+
14+
import :resource.buffer;
15+
16+
namespace stormkit::gpu {
17+
/////////////////////////////////////
18+
/////////////////////////////////////
19+
auto Buffer::do_init() noexcept -> Expected<void> {
20+
const auto create_info = VkBufferCreateInfo {
21+
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
22+
.size = m_size,
23+
.usage = to_vkflags(m_usages),
24+
.sharingMode = VK_SHARING_MODE_EXCLUSIVE
25+
};
26+
return vk_call(vkCreateBuffer, m_vk_device, &create_info, nullptr)
27+
.transform(core::monadic::set(m_vk_handle))
28+
.transform([this, &info, &device]() noexcept -> VulkanExpected<void> {
29+
const auto requirements = vk_call<VkMemoryRequirements>(m_vk_device, m_vk_handle);
30+
31+
const auto allocate_info = VmaAllocationCreateInfo {
32+
.requiredFlags = to_vkflags(info.property)
33+
};
34+
35+
auto&& allocator = device.vmaAllocator();
36+
37+
auto&& [error, vma_allocation] = allocator
38+
.allocateMemoryUnique(requirements, allocate_info);
39+
if (error != vk::Result::eSuccess)
40+
return std::unexpected { narrow<vk::Result>(error) };
41+
42+
m_vma_allocation = std::move(vma_allocation);
43+
44+
error = allocator.bindBufferMemory(*m_vma_allocation, *m_vk_buffer.get());
45+
if (error != vk::Result::eSuccess)
46+
return std::unexpected { narrow<vk::Result>(error) };
47+
48+
if (m_is_persistently_mapped) auto _ = map(device, 0u);
49+
50+
return {};
51+
})
52+
.transform_error(monadic::from_vkflags<Result>());
53+
}
54+
55+
/////////////////////////////////////
56+
/////////////////////////////////////
57+
auto Buffer::find_memory_type(UInt type_filter,
58+
vk::MemoryPropertyFlags properties,
59+
const vk::PhysicalDeviceMemoryProperties& mem_properties,
60+
const vk::MemoryRequirements&) -> UInt {
61+
for (auto i : range(mem_properties.memoryTypeCount)) {
62+
if ((type_filter & (1 << i))
63+
and (check_flag_bit(mem_properties.memoryTypes[i].propertyFlags, properties)))
64+
return i;
65+
}
66+
67+
return 0;
68+
}
69+
} // namespace stormkit::gpu

0 commit comments

Comments
 (0)