From c36bdfb3fe9d0062221bfb763d83821080a7ea99 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 13 Sep 2026 17:09:37 +0000 Subject: [PATCH 1/6] Restyled by astyle --- examples/compute_particles_c/entry_main.c | 130 +-- examples/hello_triangle/entry_main.c | 23 +- examples/hello_triangle/entry_main.cpp | 10 +- generator/bitmask.cpp | 110 +-- generator/entry_main.cpp | 10 +- generator/enum.cpp | 84 +- generator/function.cpp | 194 ++-- generator/generator.cpp | 354 +++---- generator/generator.hpp | 18 +- generator/handle.cpp | 130 +-- generator/struct.cpp | 38 +- generator/types.hpp | 56 +- generator/validation.cpp | 2 +- generator/variant.cpp | 40 +- .../wisdom/dx12/detail/dx12_detail.hpp | 77 +- src/include/wisdom/dx12/dx12_command_list.cpp | 152 +-- .../wisdom/dx12/dx12_descriptor_heap.cpp | 78 +- src/include/wisdom/dx12/dx12_device.cpp | 342 +++---- src/include/wisdom/dx12/dx12_impl.cpp | 30 +- .../wisdom/dx12/dx12_resource_allocator.cpp | 86 +- src/include/wisdom/generated/cpp_api.hpp | 916 ++++++++++-------- src/include/wisdom/generated/dx12_convert.hpp | 28 +- src/include/wisdom/generated/vk_convert.hpp | 12 +- src/include/wisdom/global/internal.hpp | 12 +- .../wisdom/vulkan/detail/vk_detail.hpp | 52 +- src/include/wisdom/vulkan/detail/vk_ext1.hpp | 40 +- src/include/wisdom/vulkan/vk_command_list.cpp | 152 +-- .../wisdom/vulkan/vk_descriptor_heap.cpp | 38 +- src/include/wisdom/vulkan/vk_device.cpp | 482 ++++----- src/include/wisdom/vulkan/vk_extensions.hpp | 44 +- src/include/wisdom/vulkan/vk_impl.cpp | 16 +- .../wisdom/vulkan/vk_resource_allocator.cpp | 46 +- src/include/wisdom/vulkan/vk_swapchain.cpp | 70 +- src/include/wisdom/vulkan/vk_tables.hpp | 12 +- src/include/wisdom/wisdom.hpp | 20 +- .../wisdom_platform/generated/cpp_api.hpp | 120 ++- .../vulkan/vk_platform_wayland.cpp | 4 +- .../vulkan/vk_platform_win32.cpp | 4 +- .../vulkan/vk_platform_xcb.cpp | 4 +- .../vulkan/vk_platform_xlib.cpp | 4 +- tests/basic/platform_check.cpp | 10 +- 41 files changed, 2149 insertions(+), 1901 deletions(-) diff --git a/examples/compute_particles_c/entry_main.c b/examples/compute_particles_c/entry_main.c index e2f7e8cb..d062621f 100644 --- a/examples/compute_particles_c/entry_main.c +++ b/examples/compute_particles_c/entry_main.c @@ -268,10 +268,10 @@ void ResizeDepth(BasicRenderer* renderer, uint32_t width, uint32_t height) .memory_flags = WisMemoryFlagsNone, }; WisResult result = wisResourceAllocatorCreateTexture( - &renderer->allocator, - &depth_desc, - &renderer->depth_texture[i] - ); + &renderer->allocator, + &depth_desc, + &renderer->depth_texture[i] + ); printf( "CreateDepthTexture[%u] result: %d, platform_code: %d, error: %s\n", i, @@ -285,7 +285,7 @@ void ResizeDepth(BasicRenderer* renderer, uint32_t width, uint32_t height) .array_layer_count = 1, }; wisViewHeapWriteDepthStencil(&renderer->dsv_heap, &renderer->depth_texture[i], &dsv_desc, i); - barriers[i] = (WisTextureBarrier){ + barriers[i] = (WisTextureBarrier) { .sync_before = WisBarrierSyncNone, .sync_after = WisBarrierSyncNone, .access_before = WisResourceAccessNone, @@ -311,10 +311,10 @@ void ResizeDepth(BasicRenderer* renderer, uint32_t width, uint32_t height) // insert a fence result = wisCommandQueueSignalFence( - &renderer->gfx_queue, - wisGetFenceView(&renderer->aux_fence), - ++renderer->aux_fence_value - ); + &renderer->gfx_queue, + wisGetFenceView(&renderer->aux_fence), + ++renderer->aux_fence_value + ); result = wisFenceWait(&renderer->aux_fence, renderer->aux_fence_value, UINT64_MAX); } @@ -403,11 +403,11 @@ void InitRenderer(BasicRenderer* renderer, SDL_Window* window) WisInstanceExtensionHeader* extensions[] = {platform.platform_extension}; WisInstance instance = {0}; WisResult result = wisCreateInstance( - &debug_desc, - extensions, - sizeof(extensions) / sizeof(WisInstanceExtensionHeader*), - &instance - ); + &debug_desc, + extensions, + sizeof(extensions) / sizeof(WisInstanceExtensionHeader*), + &instance + ); printf( "CreateInstance result: %d, platform_code: %d, error: %s\n", result.status, @@ -433,10 +433,10 @@ void InitRenderer(BasicRenderer* renderer, SDL_Window* window) // Query format support and choose swapchain format bool present_support = wisDeviceGetFormatPresentationSupport( - &renderer->device, - wisGetSurfaceView(&surface), - WisDataFormatRGB10A2Unorm - ); + &renderer->device, + wisGetSurfaceView(&surface), + WisDataFormatRGB10A2Unorm + ); if (present_support) { renderer->swapchain_format = WisDataFormatRGB10A2Unorm; printf("Surface supports the desired swapchain format.\n"); @@ -458,12 +458,12 @@ void InitRenderer(BasicRenderer* renderer, SDL_Window* window) .composite_alpha = WisCompositeAlphaOpaque, }; result = wisDeviceCreateSwapchain( - &renderer->device, - &surface, - &renderer->gfx_queue, - &swapchain_desc, - &renderer->swapchain - ); + &renderer->device, + &surface, + &renderer->gfx_queue, + &swapchain_desc, + &renderer->swapchain + ); // Destroy instance as we no longer need it wisDestroySurface(&surface); @@ -489,10 +489,10 @@ void InitRenderer(BasicRenderer* renderer, SDL_Window* window) for (uint32_t i = 0; i < FRAMES_IN_FLIGHT; ++i) { result = wisDeviceCreateCommandAllocator( - &renderer->device, - WisCommandQueueTypeGraphics, - &renderer->frames[i].command_allocator - ); + &renderer->device, + WisCommandQueueTypeGraphics, + &renderer->frames[i].command_allocator + ); printf( "CreateCommandAllocator[%u] result: %d, platform_code: %d, error: %s\n", i, @@ -502,9 +502,9 @@ void InitRenderer(BasicRenderer* renderer, SDL_Window* window) ); result = wisCommandAllocatorCreateCommandList( - &renderer->frames[i].command_allocator, - &renderer->frames[i].command_list - ); + &renderer->frames[i].command_allocator, + &renderer->frames[i].command_list + ); printf( "CreateCommandList[%u] result: %d, platform_code: %d, error: %s\n", i, @@ -578,10 +578,10 @@ void DestoyRenderer(BasicRenderer* renderer) { if (renderer->next_fence_value > 0) { WisResult result = wisCommandQueueSignalFence( - &renderer->gfx_queue, - wisGetFenceView(&renderer->fence), - ++renderer->next_fence_value - ); + &renderer->gfx_queue, + wisGetFenceView(&renderer->fence), + ++renderer->next_fence_value + ); printf( "Flush SignalFence result: %d, platform_code: %d, error: %s\n", result.status, @@ -626,10 +626,10 @@ void DestoyRenderer(BasicRenderer* renderer) void WaitForFinish(BasicRenderer* renderer) { WisResult result = wisCommandQueueSignalFence( - &renderer->gfx_queue, - wisGetFenceView(&renderer->fence), - renderer->next_fence_value - ); + &renderer->gfx_queue, + wisGetFenceView(&renderer->fence), + renderer->next_fence_value + ); printf( "WaitForFinish SignalFence result: %d, platform_code: %d, error: %s\n", result.status, @@ -667,10 +667,10 @@ void InitRenderTask(BasicRenderTask* task, BasicRenderer* renderer) .push_descriptor_count = 1, }; WisResult result = wisDeviceCreateRootSignature( - &renderer->device, - &compute_root_signature_desc, - &task->compute_signature - ); + &renderer->device, + &compute_root_signature_desc, + &task->compute_signature + ); printf( "CreateRootSignature for ComputeShader result: %d, platform_code: %d, error: %s\n", result.status, @@ -797,10 +797,10 @@ void InitResourceContainer(ResourceContainer* container, BasicRenderer* renderer .memory_type = WisMemoryTypeDeviceLocal, }; WisResult result = wisResourceAllocatorCreateBuffer( - &renderer->allocator, - &particle_buffer_desc, - &container->particle_buffer - ); + &renderer->allocator, + &particle_buffer_desc, + &container->particle_buffer + ); printf( "Create ParticleBuffer result: %d, platform_code: %d, error: %s\n", result.status, @@ -1009,19 +1009,22 @@ void Render(BasicRenderer* renderer, const ResourceContainer* resources, const B WisRenderPassDesc render_pass_desc = { .flags = 0, .render_targets = - {{.target = swap_rt, - .load_op = WisLoadOpClear, - .store_op = WisStoreOpStore, - .clear_value = {0.5f, 1.0f, 1.0f, 1.0f}}}, + { { .target = swap_rt, + .load_op = WisLoadOpClear, + .store_op = WisStoreOpStore, + .clear_value = {0.5f, 1.0f, 1.0f, 1.0f} + } + }, .render_target_count = 1, .depth_stencil = - {.target = wisViewHeapGetViewAddress(&renderer->dsv_heap, renderer->frame_index), - .load_op_depth = WisLoadOpClear, - .load_op_stencil = WisLoadOpDontCare, - .store_op_depth = WisStoreOpStore, - .store_op_stencil = WisStoreOpDontCare, - .flags = WisDepthStencilFlagsIgnoreStencil, - .clear_depth = 1.0f}, + { .target = wisViewHeapGetViewAddress(&renderer->dsv_heap, renderer->frame_index), + .load_op_depth = WisLoadOpClear, + .load_op_stencil = WisLoadOpDontCare, + .store_op_depth = WisStoreOpStore, + .store_op_stencil = WisStoreOpDontCare, + .flags = WisDepthStencilFlagsIgnoreStencil, + .clear_depth = 1.0f + }, }; result = wisCommandListBegin(&frame->command_list); @@ -1085,10 +1088,10 @@ void Render(BasicRenderer* renderer, const ResourceContainer* resources, const B frame->fence_value = renderer->next_fence_value; result = wisCommandQueueSignalFence( - &renderer->gfx_queue, - wisGetFenceView(&renderer->fence), - renderer->next_fence_value - ); + &renderer->gfx_queue, + wisGetFenceView(&renderer->fence), + renderer->next_fence_value + ); print_info( "Frame[%u] SignalFence result: %d, platform_code: %d, error: %s\n", renderer->frame_index, @@ -1154,7 +1157,8 @@ void HandleEvents(bool* running, BasicRenderer* renderer) ResizeDepth(renderer, update_desc.width, update_desc.height); - } break; + } + break; default: break; } diff --git a/examples/hello_triangle/entry_main.c b/examples/hello_triangle/entry_main.c index 0bb39ee2..45ef4f6d 100644 --- a/examples/hello_triangle/entry_main.c +++ b/examples/hello_triangle/entry_main.c @@ -238,8 +238,8 @@ static bool init_app(HelloTriangleApp* app, SDL_Window* window) wisGetSurfaceView(&surface), WisDataFormatRGB10A2Unorm ) - ? WisDataFormatRGB10A2Unorm - : WisDataFormatBGRA8Unorm; + ? WisDataFormatRGB10A2Unorm + : WisDataFormatBGRA8Unorm; WisSwapchainDesc swapchain_desc = { .width = app->width, @@ -273,10 +273,10 @@ static bool init_app(HelloTriangleApp* app, SDL_Window* window) for (uint32_t i = 0; i < FRAMES_IN_FLIGHT; ++i) { result = wisDeviceCreateCommandAllocator( - &app->device, - WisCommandQueueTypeGraphics, - &app->frames[i].command_allocator - ); + &app->device, + WisCommandQueueTypeGraphics, + &app->frames[i].command_allocator + ); if (!check_result(result, "wisDeviceCreateCommandAllocator")) { return false; } @@ -453,11 +453,12 @@ static void draw_frame(HelloTriangleApp* app, float angle) WisRenderPassDesc render_pass = { .render_targets = {{ - .target = target_rtv, - .load_op = WisLoadOpClear, - .store_op = WisStoreOpStore, - .clear_value = {0.1f, 0.1f, 0.15f, 1.0f}, - }}, + .target = target_rtv, + .load_op = WisLoadOpClear, + .store_op = WisStoreOpStore, + .clear_value = {0.1f, 0.1f, 0.15f, 1.0f}, + } + }, .render_target_count = 1, }; diff --git a/examples/hello_triangle/entry_main.cpp b/examples/hello_triangle/entry_main.cpp index 1f03d8e7..5bc1ef16 100644 --- a/examples/hello_triangle/entry_main.cpp +++ b/examples/hello_triangle/entry_main.cpp @@ -33,14 +33,14 @@ struct HelloTriangleApp { uint64_t next_fence_value = 1; wis::Swapchain swapchain{}; - wis::Texture swapchain_textures[SWAPCHAIN_FRAMES]{}; + wis::Texture swapchain_textures[SWAPCHAIN_FRAMES] {}; wis::ViewHeap rtv_heap{}; wis::DataFormat swapchain_format = wis::DataFormat::BGRA8Unorm; wis::RootSignature root_signature{}; wis::Pipeline pipeline{}; - FrameContext frames[FRAMES_IN_FLIGHT]{}; + FrameContext frames[FRAMES_IN_FLIGHT] {}; uint32_t frame_index = 0; uint32_t width = 800; @@ -206,8 +206,8 @@ static bool init_app(HelloTriangleApp* app, SDL_Window* window) } app->swapchain_format = app->device.GetFormatPresentationSupport(surface.GetView(), wis::DataFormat::RGB10A2Unorm) - ? wis::DataFormat::RGB10A2Unorm - : wis::DataFormat::BGRA8Unorm; + ? wis::DataFormat::RGB10A2Unorm + : wis::DataFormat::BGRA8Unorm; wis::SwapchainDesc swapchain_desc = { .width = app->width, @@ -340,7 +340,7 @@ static void draw_frame(HelloTriangleApp* app, float angle) wis::Texture& target_texture = app->swapchain_textures[swapchain_index]; uint64_t target_rtv = app->rtv_heap.GetViewAddress(swapchain_index); - wis::TextureBarrier barriers[2]{}; + wis::TextureBarrier barriers[2] {}; barriers[0].sync_before = wis::BarrierSync::None; barriers[0].sync_after = wis::BarrierSync::RenderTarget; barriers[0].access_before = wis::ResourceAccess::None; diff --git a/generator/bitmask.cpp b/generator/bitmask.cpp index 2692c5ca..0c529fed 100644 --- a/generator/bitmask.cpp +++ b/generator/bitmask.cpp @@ -53,7 +53,7 @@ void Generator::ParseBitmask(tinyxml2::XMLElement* type) } for (auto* impl_type = type->FirstChildElement("impl_type"); impl_type; - impl_type = impl_type->NextSiblingElement("impl_type")) { + impl_type = impl_type->NextSiblingElement("impl_type")) { auto impl_for = impl_type->FindAttribute("for")->Value(); auto backend = ParseBackend(impl_for); auto impl_name = impl_type->FindAttribute("name")->Value(); @@ -114,11 +114,11 @@ std::string Generator::MakeCBitmask(const WisBitmask& s, DocKind kind) for (auto& m : s.values) { if (m.is_bit) { st_decl += MakeValueDocumentation( - s, - m, - std::format(" Wis{}{} = (1u << {}),", s.name, m.name, m.value_or_bit), - kind - ); + s, + m, + std::format(" Wis{}{} = (1u << {}),", s.name, m.name, m.value_or_bit), + kind + ); continue; } st_decl += MakeValueDocumentation(s, m, std::format(" Wis{}{} = {},", s.name, m.name, m.value_or_bit), kind); @@ -139,11 +139,11 @@ std::string Generator::MakeCPPBitmask(const WisBitmask& s, DocKind kind) for (auto& m : s.values) { if (m.is_bit) { st_decl += MakeValueDocumentation( - s, - m, - std::format(" {} = (1u << {}),", m.name, m.value_or_bit), - kind - ); + s, + m, + std::format(" {} = (1u << {}),", m.name, m.value_or_bit), + kind + ); continue; } st_decl += MakeValueDocumentation(s, m, std::format(" {} = {},", m.name, m.value_or_bit), kind); @@ -210,19 +210,19 @@ std::string Generator::MakeBitmaskConverter(const WisBitmask& s, Backend backend if (cvt.direct) { converters = std::format( - "constexpr inline {} {}Convert({} value) noexcept {{\n return static_cast<{}>(value);\n}}\n\n", - cvt.value, - backend_tag, - GetCFullTypename(s.name, backend), - cvt.value - ); + "constexpr inline {} {}Convert({} value) noexcept {{\n return static_cast<{}>(value);\n}}\n\n", + cvt.value, + backend_tag, + GetCFullTypename(s.name, backend), + cvt.value + ); } else { converters = std::format( - "constexpr inline {} {}Convert({} value) noexcept {{\n", - cvt.value, - backend_tag, - GetCFullTypename(s.name, backend) - ); + "constexpr inline {} {}Convert({} value) noexcept {{\n", + cvt.value, + backend_tag, + GetCFullTypename(s.name, backend) + ); // Start with default value converters += std::format(" {} result = static_cast<{}>(0);\n", cvt.value, cvt.value); @@ -233,12 +233,12 @@ std::string Generator::MakeBitmaskConverter(const WisBitmask& s, Backend backend continue; } converters += std::format( - " if (value & {}{}) {{ result = static_cast<{}>(result | {}); }}\n", - GetCFullTypename(s.name, backend), - m.name, - cvt.value, - convert_value - ); + " if (value & {}{}) {{ result = static_cast<{}>(result | {}); }}\n", + GetCFullTypename(s.name, backend), + m.name, + cvt.value, + convert_value + ); } } else { for (auto& m : s.values) { @@ -247,11 +247,11 @@ std::string Generator::MakeBitmaskConverter(const WisBitmask& s, Backend backend continue; } converters += std::format( - " if (value & {}{}) {{ result |= {}; }}\n", - GetCFullTypename(s.name, backend), - m.name, - convert_value - ); + " if (value & {}{}) {{ result |= {}; }}\n", + GetCFullTypename(s.name, backend), + m.name, + convert_value + ); } } @@ -261,19 +261,19 @@ std::string Generator::MakeBitmaskConverter(const WisBitmask& s, Backend backend if (cvt.convert_back) { if (cvt.direct) { converters += std::format( - "constexpr inline {} {}Convert({} value) noexcept {{\n return static_cast<{}>(value);\n}}\n\n", - wisdom_type, - backend_tag, - cvt.value, - wisdom_type - ); + "constexpr inline {} {}Convert({} value) noexcept {{\n return static_cast<{}>(value);\n}}\n\n", + wisdom_type, + backend_tag, + cvt.value, + wisdom_type + ); } else { converters += std::format( - "constexpr inline {} {}Convert({} value) noexcept {{\n", - wisdom_type, - backend_tag, - cvt.value - ); + "constexpr inline {} {}Convert({} value) noexcept {{\n", + wisdom_type, + backend_tag, + cvt.value + ); converters += std::format(" {} result = static_cast<{}>(0);\n", wisdom_type, wisdom_type); for (auto& m : s.values) { @@ -282,12 +282,12 @@ std::string Generator::MakeBitmaskConverter(const WisBitmask& s, Backend backend continue; } converters += std::format( - " if (value & {}) {{ result = static_cast<{}>(result | {}{}); }}\n", - convert_value, - wisdom_type, - wisdom_type, - m.name - ); + " if (value & {}) {{ result = static_cast<{}>(result | {}{}); }}\n", + convert_value, + wisdom_type, + wisdom_type, + m.name + ); } converters += std::format(" return result;\n}}\n\n"); @@ -310,11 +310,11 @@ void Generator::WriteBitmaskDocumentation(std::filesystem::path enum_output_path files.push_back(enum_file_path); std::string enum_template_content = std::format( - " * C version:\n```c\n{}```\n" - "C++ version:\n```cpp\nnamespace wis{{\n{}}}\n```\n", - MakeCBitmask(enum_ref, DocKind::VersionOnly), - MakeCPPBitmask(enum_ref, DocKind::VersionOnly) - ); + " * C version:\n```c\n{}```\n" + "C++ version:\n```cpp\nnamespace wis{{\n{}}}\n```\n", + MakeCBitmask(enum_ref, DocKind::VersionOnly), + MakeCPPBitmask(enum_ref, DocKind::VersionOnly) + ); std::string enum_description = std::format(" * {}", MakeBitmaskDescription(enum_ref)); std::string enum_refs = GetRefs(enum_name); ReplaceAll(enum_template_content, "\n", "\n * "); diff --git a/generator/entry_main.cpp b/generator/entry_main.cpp index 5e0c425b..5d47afa0 100644 --- a/generator/entry_main.cpp +++ b/generator/entry_main.cpp @@ -49,10 +49,10 @@ int main(int argc, char** argv) std::string_view arg = argv[1]; if (arg == "-h" || arg == "--help") { std::cout - << "Usage: " << argv[0] << " [module_name,...]\n" - << "If module_name is provided, generates API for that platform module. Otherwise, generates core API.\n" - << "Modules are stored in xml folder. For example, if module_name is 'platform', the generator will look " - "for 'xml/platform.xml' and generate API for it.\n"; + << "Usage: " << argv[0] << " [module_name,...]\n" + << "If module_name is provided, generates API for that platform module. Otherwise, generates core API.\n" + << "Modules are stored in xml folder. For example, if module_name is 'platform', the generator will look " + "for 'xml/platform.xml' and generate API for it.\n"; return 0; } @@ -64,7 +64,7 @@ int main(int argc, char** argv) size_t next_comma = arg.find(',', i); std::string_view platform_module_name = arg.substr(i, next_comma - i); auto module_path = std::filesystem::path(input_file).parent_path() - / (std::string(platform_module_name) + std::string(".xml")); + / (std::string(platform_module_name) + std::string(".xml")); g.ParseFile(module_path); g.WriteModuleAPI(); diff --git a/generator/enum.cpp b/generator/enum.cpp index a301b5cd..e5933d53 100644 --- a/generator/enum.cpp +++ b/generator/enum.cpp @@ -53,7 +53,7 @@ void Generator::ParseEnum(tinyxml2::XMLElement* type) } for (auto* impl_type = type->FirstChildElement("impl_type"); impl_type; - impl_type = impl_type->NextSiblingElement("impl_type")) { + impl_type = impl_type->NextSiblingElement("impl_type")) { auto impl_for = impl_type->FindAttribute("for")->Value(); auto backend = ParseBackend(impl_for); auto impl_name = impl_type->FindAttribute("name")->Value(); @@ -145,11 +145,11 @@ void Generator::WriteEnumDocumentation(std::filesystem::path enum_output_path) files.push_back(enum_file_path); std::string enum_template_content = std::format( - " * C version:\n```c\n{}```\n" - "C++ version:\n```cpp\nnamespace wis{{\n{}}}\n```\n", - MakeCEnum(enum_ref, DocKind::VersionOnly), - MakeCPPEnum(enum_ref, DocKind::VersionOnly) - ); + " * C version:\n```c\n{}```\n" + "C++ version:\n```cpp\nnamespace wis{{\n{}}}\n```\n", + MakeCEnum(enum_ref, DocKind::VersionOnly), + MakeCPPEnum(enum_ref, DocKind::VersionOnly) + ); std::string enum_description = std::format(" * {}", MakeEnumDescription(enum_ref)); std::string enum_refs = GetRefs(enum_name); ReplaceAll(enum_template_content, "\n", "\n * "); @@ -192,11 +192,11 @@ std::string Generator::MakeEnumDescription(const WisEnum& s) } translates += std::format( - "{} `{}` for {} implementation", - has_translate ? ", and" : "", - cvt.value, - impl_names[i] - ); + "{} `{}` for {} implementation", + has_translate ? ", and" : "", + cvt.value, + impl_names[i] + ); has_translate = true; } if (has_translate) { @@ -223,29 +223,29 @@ std::string Generator::MakeEnumConverter(const WisEnum& s, Backend backend) if (cvt.direct) { converters = std::format( - "constexpr inline {} {}Convert({} value) noexcept {{\n return static_cast<{}>(value);\n}}\n\n", - cvt.value, - backend_tag, - GetCFullTypename(s.name, backend), - cvt.value - ); + "constexpr inline {} {}Convert({} value) noexcept {{\n return static_cast<{}>(value);\n}}\n\n", + cvt.value, + backend_tag, + GetCFullTypename(s.name, backend), + cvt.value + ); } else { converters = std::format( - "constexpr inline {} {}Convert({} value) noexcept {{\n switch(value) {{\n", - cvt.value, - backend_tag, - GetCFullTypename(s.name, backend) - ); + "constexpr inline {} {}Convert({} value) noexcept {{\n switch(value) {{\n", + cvt.value, + backend_tag, + GetCFullTypename(s.name, backend) + ); for (auto& m : s.values) { auto convert_value = m.converts[static_cast(backend)]; if (convert_value.empty()) { continue; } converters += std::format( - " case {}: return {};\n", - std::format("{}{}", GetCFullTypename(s.name, backend), m.name), - convert_value - ); + " case {}: return {};\n", + std::format("{}{}", GetCFullTypename(s.name, backend), m.name), + convert_value + ); } if (!cvt.default_value.empty()) { @@ -258,19 +258,19 @@ std::string Generator::MakeEnumConverter(const WisEnum& s, Backend backend) if (cvt.convert_back) { if (cvt.direct) { converters += std::format( - "constexpr inline {} {}Convert({} value) noexcept {{\n return static_cast<{}>(value);\n}}\n\n", - wisdom_type, - backend_tag, - cvt.value, - wisdom_type - ); + "constexpr inline {} {}Convert({} value) noexcept {{\n return static_cast<{}>(value);\n}}\n\n", + wisdom_type, + backend_tag, + cvt.value, + wisdom_type + ); } else { converters += std::format( - "constexpr inline {} {}Convert({} value) noexcept {{\n", - wisdom_type, - backend_tag, - cvt.value - ); + "constexpr inline {} {}Convert({} value) noexcept {{\n", + wisdom_type, + backend_tag, + cvt.value + ); for (auto& m : s.values) { auto convert_value = m.converts[static_cast(backend)]; @@ -278,11 +278,11 @@ std::string Generator::MakeEnumConverter(const WisEnum& s, Backend backend) continue; } converters += std::format( - " if (value == {}) {{ return {}{}; }}\n", - convert_value, - wisdom_type, - m.name - ); + " if (value == {}) {{ return {}{}; }}\n", + convert_value, + wisdom_type, + m.name + ); } converters += std::format(" return static_cast<{}>(0);\n}}\n\n", wisdom_type); diff --git a/generator/function.cpp b/generator/function.cpp index 3ecc1284..e6c92fe7 100644 --- a/generator/function.cpp +++ b/generator/function.cpp @@ -196,8 +196,8 @@ std::string Generator::MakeCFunctionProto( } else if (func.return_type.has_result) { full_return_type = GetCFullTypename("Result", Backend::Any); std::string arg_name = func.return_type.opt_name.empty() - ? std::format("out_{}", MakeSnakeCase(func.return_type.type)) - : std::string(func.return_type.opt_name); + ? std::format("out_{}", MakeSnakeCase(func.return_type.type)) + : std::string(func.return_type.opt_name); std::string prefix = ""; size_t length = full_return_type.size() + 1 + pre_decl.size() + 1 + function_full_name.size(); @@ -262,14 +262,14 @@ std::string Generator::MakeCFunctionProto( } return std::format( - "{}{} {}({}{}{});\n", - pre_decl, - full_return_type, - function_full_name, - this_arg, - params.empty() && !post_return.empty() ? ",\n" : params.c_str(), - post_return - ); + "{}{} {}({}{}{});\n", + pre_decl, + full_return_type, + function_full_name, + this_arg, + params.empty() && !post_return.empty() ? ",\n" : params.c_str(), + post_return + ); } //---------------------------------------------------------------------------------------------------------------------- @@ -305,23 +305,23 @@ std::string Generator::MakeCPPFunctionProto( break; case Direct: full_return_type = GetMemberTypeString( - func.return_type, - type != ProtoType::Universal ? backend : Backend::Any - ); + func.return_type, + type != ProtoType::Universal ? backend : Backend::Any + ); break; case ResultOnly: full_return_type = "wis::Result"; break; case ResultAndValue: full_return_type = GetMemberTypeString( - func.return_type, - type != ProtoType::Universal ? backend : Backend::Any - ); + func.return_type, + type != ProtoType::Universal ? backend : Backend::Any + ); // Add out parameter for result { std::string prefix = ""; size_t length = full_return_type.size() + 1 + pre_decl.size() + 1 + func.name.size() + func_prefix.size() - + xclass_code.size(); + + xclass_code.size(); if (func.parameters.size() > 0) { prefix = ",\n" + std::string(length, ' '); } @@ -336,7 +336,7 @@ std::string Generator::MakeCPPFunctionProto( } size_t length = full_return_type.size() + 1 + pre_decl.size() + 1 + func.name.size() + func_prefix.size() - + xclass_code.size(); + + xclass_code.size(); size_t max_arg_length = post_return_length; // account for spans @@ -390,27 +390,27 @@ std::string Generator::MakeCPPFunctionProto( } if ((func.modifier & Modifier::Construct) != 0) { return std::format( - "{}{}{}{}({}{}){} noexcept;\n", - func_prefix, - xclass_code, - func_prefix, - std::string_view(xclass_code.begin(), xclass_code.end() - 2), - params, - post_return, - func.modifier & Modifier::Const ? " const" : "" - ); + "{}{}{}{}({}{}){} noexcept;\n", + func_prefix, + xclass_code, + func_prefix, + std::string_view(xclass_code.begin(), xclass_code.end() - 2), + params, + post_return, + func.modifier & Modifier::Const ? " const" : "" + ); } return std::format( - "{}{} {}{}{}({}{}){} noexcept;\n", - pre_decl, - full_return_type, - func_prefix, - xclass_code, - func.name, - params, - post_return, - func.modifier & Modifier::Const ? " const" : "" - ); + "{}{} {}{}{}({}{}){} noexcept;\n", + pre_decl, + full_return_type, + func_prefix, + xclass_code, + func.name, + params, + post_return, + func.modifier & Modifier::Const ? " const" : "" + ); } //---------------------------------------------------------------------------------------------------------------------- @@ -482,21 +482,21 @@ std::string Generator::MakeCPPFunctionImpl( switch (func.return_type.GetKind()) { case ReturnTypeKind::ResultAndValue: { auto ret_value_name = func.return_type.opt_name.empty() - ? std::format("out_{}", MakeSnakeCase(func.return_type.type)) - : std::string(func.return_type.opt_name); + ? std::format("out_{}", MakeSnakeCase(func.return_type.type)) + : std::string(func.return_type.opt_name); // Prepare out parameter body += std::format( - " {} {}{{}};\n", - GetMemberTypeString(func.return_type, backend), - ret_value_name - ); + " {} {}{{}};\n", + GetMemberTypeString(func.return_type, backend), + ret_value_name + ); body += std::format( - " const WisResult wis_result = ::{}({}", - c_name, - func.this_type.empty() ? "" : "&_impl_storage" - ); + " const WisResult wis_result = ::{}({}", + c_name, + func.this_type.empty() ? "" : "&_impl_storage" + ); if (func.parameters.size() > 0 && !func.this_type.empty()) { body += arg_prefix; @@ -510,21 +510,22 @@ std::string Generator::MakeCPPFunctionImpl( body += std::format(", {}.GetStorage());\n", ret_value_name); } else { body += std::format( - ", reinterpret_cast<{}*>(&{}));\n", - GetMemberTypeString(func.return_type, backend), - ret_value_name - ); + ", reinterpret_cast<{}*>(&{}));\n", + GetMemberTypeString(func.return_type, backend), + ret_value_name + ); } body += " out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, " "wis_result.error };\n"; body += std::format(" return {};\n", ret_value_name); - } break; + } + break; case ReturnTypeKind::ResultOnly: { body += std::format( - " const WisResult wis_result = ::{}({}", - c_name, - func.this_type.empty() ? "" : "&_impl_storage" - ); + " const WisResult wis_result = ::{}({}", + c_name, + func.this_type.empty() ? "" : "&_impl_storage" + ); constexpr static std::string_view arg_prefix = ",\n "; if (func.parameters.size() > 0 && !func.this_type.empty()) { body += arg_prefix; @@ -533,7 +534,8 @@ std::string Generator::MakeCPPFunctionImpl( body += ");\n"; body += " return wis::Result{ static_cast(wis_result.status), wis_result.platform_code, " "wis_result.error };\n"; - } break; + } + break; case ReturnTypeKind::Direct: { auto ret_type = GetType(func.return_type.type); std::string return_cast; @@ -551,25 +553,26 @@ std::string Generator::MakeCPPFunctionImpl( break; default: return_cast = std::format( - "reinterpret_cast<{}>", - GetMemberTypeString(func.return_type, backend) - ); + "reinterpret_cast<{}>", + GetMemberTypeString(func.return_type, backend) + ); break; } body += std::format( - " return {}(::{}({}", - return_cast, - c_name, - func.this_type.empty() ? "" : "&_impl_storage" - ); + " return {}(::{}({}", + return_cast, + c_name, + func.this_type.empty() ? "" : "&_impl_storage" + ); constexpr static std::string_view arg_prefix = ",\n "; if (func.parameters.size() > 0 && !func.this_type.empty()) { body += arg_prefix; } body += GetFunctionCallParameters(func, backend); body += "));\n"; - } break; + } + break; case ReturnTypeKind::Void: { body += std::format(" ::{}({}", c_name, func.this_type.empty() ? "" : "&_impl_storage"); constexpr static std::string_view arg_prefix = ",\n "; @@ -578,7 +581,8 @@ std::string Generator::MakeCPPFunctionImpl( } body += GetFunctionCallParameters(func, backend); body += ");\n"; - } break; + } + break; default: break; } @@ -619,18 +623,18 @@ std::string Generator::MakeFunctionDescription(const WisFunction& s) if (!s.this_type.empty()) { if (s.modifier & Modifier::Construct) { description += std::format( - "- **this** `self` is a pointer to uninitialized {{{}::}} instance memory. It will be initialized by " - "this function.\n", - s.this_type - ); + "- **this** `self` is a pointer to uninitialized {{{}::}} instance memory. It will be initialized by " + "this function.\n", + s.this_type + ); // There must also be a note about the destroy function in the description description += std::format("**note** The corresponding destroy function is `wisDestroy{}`.\n", s.this_type); } else { description += std::format( - "- **this** `self` self is a pointer to the valid {{{}::}} instance.\n", - s.this_type - ); + "- **this** `self` self is a pointer to the valid {{{}::}} instance.\n", + s.this_type + ); } } @@ -641,21 +645,21 @@ std::string Generator::MakeFunctionDescription(const WisFunction& s) switch (s.return_type.GetKind()) { case ReturnTypeKind::Direct: description += std::format( - "\n- **return** {}\n", - s.return_type.doc.empty() ? "No description." : s.return_type.doc - ); + "\n- **return** {}\n", + s.return_type.doc.empty() ? "No description." : s.return_type.doc + ); break; case ReturnTypeKind::ResultOnly: description += std::format("\n- **return** denoting the outcome of operation.\n"); break; case ReturnTypeKind::ResultAndValue: { std::string arg_name = s.return_type.opt_name.empty() ? std::format("out_{}", MakeSnakeCase(s.return_type.type)) - : std::string(s.return_type.opt_name); + : std::string(s.return_type.opt_name); description += std::format( - "- `{}` {}\n", - s.return_type.opt_name.empty() ? "value" : s.return_type.opt_name, - s.return_type.doc.empty() ? "No description." : s.return_type.doc - ); + "- `{}` {}\n", + s.return_type.opt_name.empty() ? "value" : s.return_type.opt_name, + s.return_type.doc.empty() ? "No description." : s.return_type.doc + ); description += std::format("\n- **return** denoting the outcome of operation.\n"); break; } @@ -684,10 +688,10 @@ void Generator::WriteFunctionDocumentation(std::filesystem::path func_output_pat for (auto& func_name : function_names) { auto& func_def = function_map[func_name]; std::string full_func_name = std::format( - "wis{}{}", - func_def.modifier & (Destroy | Construct) ? "" : func_def.this_type, - func_def.name - ); + "wis{}{}", + func_def.modifier & (Destroy | Construct) ? "" : func_def.this_type, + func_def.name + ); auto func_doc_path = func_output_path / std::format("{}_function.h", MakeSnakeCase(full_func_name.substr(3))); files.push_back(func_doc_path); @@ -705,18 +709,18 @@ void Generator::WriteFunctionDocumentation(std::filesystem::path func_output_pat } std::string vk_code_cpp = func_def.modifier & Modifier::Destroy || !supports_vk - ? "" - : MakeCPPFunctionImpl(func_def, Backend::Vulkan, "", DocKind::VersionOnly); + ? "" + : MakeCPPFunctionImpl(func_def, Backend::Vulkan, "", DocKind::VersionOnly); std::string dx_code_cpp = func_def.modifier & Modifier::Destroy || !supports_dx - ? "" - : MakeCPPFunctionImpl(func_def, Backend::DX12, "", DocKind::VersionOnly); + ? "" + : MakeCPPFunctionImpl(func_def, Backend::DX12, "", DocKind::VersionOnly); std::string regular_code_cpp = func_def.modifier & Modifier::Destroy || !(supports_vk && supports_dx) - ? "" - : MakeCPPFunctionImpl(func_def, Backend::Any, "", DocKind::VersionOnly); + ? "" + : MakeCPPFunctionImpl(func_def, Backend::Any, "", DocKind::VersionOnly); std::string cpp_code = regular_code_cpp; std::string cpp_impl_code = func_def.modifier & Modifier::Destroy || !(supports_vk && supports_dx) - ? "" - : vk_code_cpp + '\n' + dx_code_cpp; + ? "" + : vk_code_cpp + '\n' + dx_code_cpp; if (cpp_code.empty()) { cpp_code = !vk_code_cpp.empty() ? vk_code_cpp : dx_code_cpp; } @@ -749,7 +753,7 @@ void Generator::WriteDelegateDocumentation(std::filesystem::path func_output_pat for (auto& delegate_name : module_map.at(active_module_name).delegates_in_order) { auto full_delegate_name = GetCFullTypename(delegate_name, Backend::Any); auto delegate_doc_path = func_output_path - / std::format("{}_delegate.h", MakeSnakeCase(full_delegate_name.substr(3))); + / std::format("{}_delegate.h", MakeSnakeCase(full_delegate_name.substr(3))); auto& delegate_def = delegate_map[delegate_name]; files.push_back(delegate_doc_path); diff --git a/generator/generator.cpp b/generator/generator.cpp index 1f454c7f..93b31506 100644 --- a/generator/generator.cpp +++ b/generator/generator.cpp @@ -18,7 +18,7 @@ void Generator::ParseFile(std::filesystem::path file) bool has_modules = false; for (auto* module_node = root->FirstChildElement("module"); module_node; - module_node = module_node->NextSiblingElement("module")) { + module_node = module_node->NextSiblingElement("module")) { has_modules = true; auto* module_attr = module_node->FindAttribute("name"); @@ -140,7 +140,7 @@ void Generator::ParseRegistrySections(tinyxml2::XMLElement* root) void Generator::ParseIncludes(tinyxml2::XMLElement* includes) { for (auto* include = includes->FirstChildElement("include"); include; - include = include->NextSiblingElement("include")) { + include = include->NextSiblingElement("include")) { auto file = include->GetText(); auto rpath = std::filesystem::path(INPUT_FILE).parent_path() / file; auto absolute = std::filesystem::absolute(rpath); @@ -185,8 +185,8 @@ void Generator::WriteCAPI(std::filesystem::path dir) auto& module = module_map.at(active_module_name); bool has_independent_api = !module.enums_in_order.empty() || !module.bitmasks_in_order.empty() - || !module.structs_in_order.empty() || !module.constants_in_order.empty() - || !module.delegates_in_order.empty() || !module.functions_in_order.empty(); + || !module.structs_in_order.empty() || !module.constants_in_order.empty() + || !module.delegates_in_order.empty() || !module.functions_in_order.empty(); auto path = dir / "c_api.h"; if (!has_independent_api) { @@ -207,12 +207,12 @@ void Generator::WriteCAPI(std::filesystem::path dir) #include #include )" - : R"(#include + : R"(#include #include "wisdom_exports.h" )"; auto api_macro = module.name == "Core" ? "WIS_INLINE WISDOM_API " - : std::format("WIS_INLINE WISDOM_{}_API ", header_guard); + : std::format("WIS_INLINE WISDOM_{}_API ", header_guard); // Write header // clang-format off @@ -229,8 +229,8 @@ extern "C" {{ if (!module.enums_in_order.empty() || !module.bitmasks_in_order.empty()) { file << "\n//==============================================================\n" - "// Enums\n" - "//==============================================================\n\n"; + "// Enums\n" + "//==============================================================\n\n"; // Write enums for (auto& enum_name : module.enums_in_order) { @@ -249,8 +249,8 @@ extern "C" {{ if (!module.delegates_in_order.empty()) { file << "\n//==============================================================\n" - "// Delegates\n" - "//==============================================================\n\n"; + "// Delegates\n" + "//==============================================================\n\n"; // Write delegates (before structs, as structs may reference delegates) for (auto& delegate_name : module.delegates_in_order) { auto& delegate_def = delegate_map[delegate_name]; @@ -261,8 +261,8 @@ extern "C" {{ if (!module.structs_in_order.empty()) { file << "\n//==============================================================\n" - "// Structs\n" - "//==============================================================\n\n"; + "// Structs\n" + "//==============================================================\n\n"; // Write structs for (auto& struct_name : module.structs_in_order) { auto& struct_def = struct_map[struct_name]; @@ -273,8 +273,8 @@ extern "C" {{ if (!module.constants_in_order.empty()) { file << "\n//==============================================================\n" - "// Constants\n" - "//==============================================================\n\n"; + "// Constants\n" + "//==============================================================\n\n"; // Write constants for (auto& const_name : module.constants_in_order) { auto& const_def = constant_map[const_name]; @@ -368,8 +368,8 @@ void Generator::WriteCPPAPI(std::filesystem::path dir) { auto& module = module_map.at(active_module_name); bool has_independent_api = !module.enums_in_order.empty() || !module.bitmasks_in_order.empty() - || !module.structs_in_order.empty() || !module.constants_in_order.empty() - || !module.delegates_in_order.empty() || !module.functions_in_order.empty(); + || !module.structs_in_order.empty() || !module.constants_in_order.empty() + || !module.delegates_in_order.empty() || !module.functions_in_order.empty(); auto path = dir / "cpp_api.hpp"; if (!has_independent_api) { @@ -390,7 +390,7 @@ void Generator::WriteCPPAPI(std::filesystem::path dir) #include #include "c_api.h" )" - : R"(#include + : R"(#include #include "wisdom_exports.h" #include "c_api.h" )"; @@ -412,8 +412,8 @@ namespace wis {{ if (!module.enums_in_order.empty() || !module.bitmasks_in_order.empty()) { file << "\n//==============================================================\n" - "// Enums\n" - "//==============================================================\n\n"; + "// Enums\n" + "//==============================================================\n\n"; // Write enums for (auto& enum_name : module.enums_in_order) { @@ -432,8 +432,8 @@ namespace wis {{ if (!module.delegates_in_order.empty()) { file << "\n//==============================================================\n" - "// Delegates\n" - "//==============================================================\n\n"; + "// Delegates\n" + "//==============================================================\n\n"; // Write delegates (before structs, as structs may reference delegates) for (auto& delegate_name : module.delegates_in_order) { auto& delegate_def = delegate_map[delegate_name]; @@ -444,8 +444,8 @@ namespace wis {{ if (!module.structs_in_order.empty()) { file << "\n//==============================================================\n" - "// Structs\n" - "//==============================================================\n\n"; + "// Structs\n" + "//==============================================================\n\n"; // Write structs for (auto& struct_name : module.structs_in_order) { auto& struct_def = struct_map[struct_name]; @@ -456,8 +456,8 @@ namespace wis {{ if (!module.constants_in_order.empty()) { file << "\n//==============================================================\n" - "// Constants\n" - "//==============================================================\n\n"; + "// Constants\n" + "//==============================================================\n\n"; // Write constants for (auto& const_name : module.constants_in_order) { auto& const_def = constant_map[const_name]; @@ -467,7 +467,7 @@ namespace wis {{ } file << std::format( - R"( + R"( }} // namespace wis #ifdef WISDOM_DX12 @@ -475,8 +475,8 @@ namespace wis {{ namespace wis {{ )", - include_root - ); + include_root + ); // Write Views for handles for (auto& handle_name : module.views_in_order) { @@ -517,7 +517,7 @@ namespace wis {{ } file << std::format( - R"( + R"( }} // namespace wis #endif // WISDOM_DX12 @@ -526,8 +526,8 @@ namespace wis {{ namespace wis {{ )", - include_root - ); + include_root + ); // Write Views for handles for (auto& handle_name : module.views_in_order) { @@ -585,14 +585,14 @@ void Generator::WriteCIndependentAPI(std::filesystem::path dir) auto& module = module_map.at(active_module_name); auto independent_name = module.name == "Core" ? std::string("wisdom") - : std::format("wisdom_{}", MakeSnakeCase(module.name)); + : std::format("wisdom_{}", MakeSnakeCase(module.name)); auto module_folder = std::filesystem::path(module.gen_path).filename().generic_string(); if (module_folder.empty()) { module_folder = std::filesystem::path(module.gen_path).parent_path().filename().generic_string(); } auto backend_include = module_folder == "wisdom" ? std::string("generated/c_api.h") - : std::format("../{}/generated/c_api.h", module_folder); + : std::format("../{}/generated/c_api.h", module_folder); auto header_guard = std::format("WISDOM_{}_H", MakeUpperSnakeCase(module.name)); std::filesystem::path path_w = dir / (independent_name + ".h"); @@ -605,7 +605,7 @@ void Generator::WriteCIndependentAPI(std::filesystem::path dir) // Write header file_w << std::format( - R"(// This file is generated. Do not edit directly. + R"(// This file is generated. Do not edit directly. #ifndef {0} #define {0} @@ -625,9 +625,9 @@ static_assert(WISDOM_UWP && _WIN32, "Platform error"); #if defined(WISDOM_DX12) && !FORCEVK_SWITCH )", - header_guard, - backend_include - ); + header_guard, + backend_include + ); constexpr static auto impl_dx = GetBackendSuffix(Backend::DX12); constexpr static auto impl_vk = GetBackendSuffix(Backend::Vulkan); @@ -661,18 +661,18 @@ static_assert(WISDOM_UWP && _WIN32, "Platform error"); if (dx_has_handles) { file_w << "\n\n//==============================================================\n" - "// Handles\n" - "//==============================================================\n\n"; + "// Handles\n" + "//==============================================================\n\n"; // Write handles for (auto& handle_name : module.handles_in_order) { auto& handle_def = handle_map[handle_name]; if (has(handle_def.GetBackend(), Backend::DX12)) { file_w << std::format( - "typedef struct {} {};\n", - GetCFullTypename(handle_def.name, Backend::DX12), - GetCFullTypename(handle_def.name) - ); + "typedef struct {} {};\n", + GetCFullTypename(handle_def.name, Backend::DX12), + GetCFullTypename(handle_def.name) + ); } } @@ -681,46 +681,46 @@ static_assert(WISDOM_UWP && _WIN32, "Platform error"); auto& handle_def = handle_map[handle_name]; if (handle_def.GetViewSize(Backend::DX12) > 0) { file_w << std::format( - "typedef struct {}View {}View;\n", - GetCFullTypename(handle_def.name, Backend::DX12), - GetCFullTypename(handle_def.name) - ); + "typedef struct {}View {}View;\n", + GetCFullTypename(handle_def.name, Backend::DX12), + GetCFullTypename(handle_def.name) + ); } } } if (dx_has_variants) { file_w << "\n\n//==============================================================\n" - "// Variants\n" - "//==============================================================\n\n"; + "// Variants\n" + "//==============================================================\n\n"; // Write variants for (auto& variant_name : module.variants_in_order) { auto& variant_def = variant_map[variant_name]; if (has(variant_def.backend, Backend::DX12)) { file_w << std::format( - "typedef struct {} {};\n", - GetCFullTypename(variant_def.name, Backend::DX12), - GetCFullTypename(variant_def.name) - ); + "typedef struct {} {};\n", + GetCFullTypename(variant_def.name, Backend::DX12), + GetCFullTypename(variant_def.name) + ); } } } file_w << "\n\n//==============================================================\n" - "// Functions\n" - "//==============================================================\n\n"; + "// Functions\n" + "//==============================================================\n\n"; // Write view getters for handles for (auto& handle_name : module.handles_in_order) { auto& handle_def = handle_map[handle_name]; if (has(handle_def.GetBackend(), Backend::DX12) && handle_def.GetViewSize(Backend::DX12) > 0) { file_w << std::format( - "#define wisGet{}View wisGet{}{}View\n", - handle_def.name, - GetBackendSuffix(Backend::DX12), - handle_def.name - ); + "#define wisGet{}View wisGet{}{}View\n", + handle_def.name, + GetBackendSuffix(Backend::DX12), + handle_def.name + ); } } @@ -729,10 +729,10 @@ static_assert(WISDOM_UWP && _WIN32, "Platform error"); auto& func_def = function_map[func_name]; if (has(func_def.backend, Backend::DX12)) { file_w << std::format( - "#define {} {}\n", - GetCFullFunctionName(func_name), - GetCFullFunctionName(func_name, Backend::DX12) - ); + "#define {} {}\n", + GetCFullFunctionName(func_name), + GetCFullFunctionName(func_name, Backend::DX12) + ); } } @@ -770,18 +770,18 @@ static_assert(WISDOM_UWP && _WIN32, "Platform error"); if (vk_has_handles) { file_w << "\n\n//==============================================================\n" - "// Handles\n" - "//==============================================================\n\n"; + "// Handles\n" + "//==============================================================\n\n"; // Write handles for (auto& handle_name : module.handles_in_order) { auto& handle_def = handle_map[handle_name]; if (has(handle_def.GetBackend(), Backend::Vulkan)) { file_w << std::format( - "typedef struct {} {};\n", - GetCFullTypename(handle_def.name, Backend::Vulkan), - GetCFullTypename(handle_def.name) - ); + "typedef struct {} {};\n", + GetCFullTypename(handle_def.name, Backend::Vulkan), + GetCFullTypename(handle_def.name) + ); } } @@ -790,46 +790,46 @@ static_assert(WISDOM_UWP && _WIN32, "Platform error"); auto& handle_def = handle_map[handle_name]; if (handle_def.GetViewSize(Backend::Vulkan) > 0) { file_w << std::format( - "typedef struct {}View {}View;\n", - GetCFullTypename(handle_def.name, Backend::Vulkan), - GetCFullTypename(handle_def.name) - ); + "typedef struct {}View {}View;\n", + GetCFullTypename(handle_def.name, Backend::Vulkan), + GetCFullTypename(handle_def.name) + ); } } } if (vk_has_variants) { file_w << "\n\n//==============================================================\n" - "// Variants\n" - "//==============================================================\n\n"; + "// Variants\n" + "//==============================================================\n\n"; // Write variants for (auto& variant_name : module.variants_in_order) { auto& variant_def = variant_map[variant_name]; if (has(variant_def.backend, Backend::Vulkan)) { file_w << std::format( - "typedef struct {} {};\n", - GetCFullTypename(variant_def.name, Backend::Vulkan), - GetCFullTypename(variant_def.name) - ); + "typedef struct {} {};\n", + GetCFullTypename(variant_def.name, Backend::Vulkan), + GetCFullTypename(variant_def.name) + ); } } } file_w << "\n\n//==============================================================\n" - "// Functions\n" - "//==============================================================\n\n"; + "// Functions\n" + "//==============================================================\n\n"; // Write view getters for handles for (auto& handle_name : module.handles_in_order) { auto& handle_def = handle_map[handle_name]; if (has(handle_def.GetBackend(), Backend::Vulkan) && handle_def.GetViewSize(Backend::Vulkan) > 0) { file_w << std::format( - "#define wisGet{}View wisGet{}{}View\n", - handle_def.name, - GetBackendSuffix(Backend::Vulkan), - handle_def.name - ); + "#define wisGet{}View wisGet{}{}View\n", + handle_def.name, + GetBackendSuffix(Backend::Vulkan), + handle_def.name + ); } } @@ -838,10 +838,10 @@ static_assert(WISDOM_UWP && _WIN32, "Platform error"); auto& func_def = function_map[func_name]; if (has(func_def.backend, Backend::Vulkan)) { file_w << std::format( - "#define {} {}\n", - GetCFullFunctionName(func_name), - GetCFullFunctionName(func_name, Backend::Vulkan) - ); + "#define {} {}\n", + GetCFullFunctionName(func_name), + GetCFullFunctionName(func_name, Backend::Vulkan) + ); } } @@ -869,14 +869,14 @@ void Generator::WriteCPPIndependentAPI(std::filesystem::path dir) auto& module = module_map.at(active_module_name); auto independent_name = module.name == "Core" ? std::string("wisdom") - : std::format("wisdom_{}", MakeSnakeCase(module.name)); + : std::format("wisdom_{}", MakeSnakeCase(module.name)); auto module_folder = std::filesystem::path(module.gen_path).filename().generic_string(); if (module_folder.empty()) { module_folder = std::filesystem::path(module.gen_path).parent_path().filename().generic_string(); } auto backend_include = module_folder == "wisdom" ? std::string("generated/cpp_api.hpp") - : std::format("../{}/generated/cpp_api.hpp", module_folder); + : std::format("../{}/generated/cpp_api.hpp", module_folder); auto header_guard = std::format("WISDOM_{}_HPP", MakeUpperSnakeCase(module.name)); std::filesystem::path path_w = dir / (independent_name + ".hpp"); @@ -889,7 +889,7 @@ void Generator::WriteCPPIndependentAPI(std::filesystem::path dir) // Write header file_w << std::format( - R"(// This file is generated. Do not edit directly. + R"(// This file is generated. Do not edit directly. #ifndef {0} #define {0} @@ -911,9 +911,9 @@ void Generator::WriteCPPIndependentAPI(std::filesystem::path dir) namespace wis {{ )", - header_guard, - backend_include - ); + header_guard, + backend_include + ); if (module.name == "Core") { file_w << "static constexpr wis::ShaderIntermediate shader_intermediate = wis::ShaderIntermediate::DXIL;\n"; @@ -954,18 +954,18 @@ namespace wis {{ if (dx_has_handles) { file_w << "\n\n//==============================================================\n" - "// Handles\n" - "//==============================================================\n\n"; + "// Handles\n" + "//==============================================================\n\n"; // Write handles for (auto& handle_name : module.handles_in_order) { auto& handle_def = handle_map[handle_name]; if (has(handle_def.GetBackend(), Backend::DX12)) { file_w << std::format( - "using {} = {};\n", - handle_def.name, - GetCPPFullTypename(handle_def.name, Backend::DX12) - ); + "using {} = {};\n", + handle_def.name, + GetCPPFullTypename(handle_def.name, Backend::DX12) + ); } } @@ -974,36 +974,36 @@ namespace wis {{ auto& handle_def = handle_map[handle_name]; if (handle_def.GetViewSize(Backend::DX12) > 0) { file_w << std::format( - "using {}View = {};\n", - handle_def.name, - GetCPPFullTypename(handle_def.name, Backend::DX12) + "View" - ); + "using {}View = {};\n", + handle_def.name, + GetCPPFullTypename(handle_def.name, Backend::DX12) + "View" + ); } } } if (dx_has_variants) { file_w << "\n\n//==============================================================\n" - "// Variants\n" - "//==============================================================\n\n"; + "// Variants\n" + "//==============================================================\n\n"; // Write variants for (auto& variant_name : module.variants_in_order) { auto& variant_def = variant_map[variant_name]; if (has(variant_def.backend, Backend::DX12)) { file_w << std::format( - "using {} = {};\n", - variant_def.name, - GetCPPFullTypename(variant_def.name, Backend::DX12) - ); + "using {} = {};\n", + variant_def.name, + GetCPPFullTypename(variant_def.name, Backend::DX12) + ); } } } if (dx_has_functions) { file_w << "\n\n//==============================================================\n" - "// Functions\n" - "//==============================================================\n\n"; + "// Functions\n" + "//==============================================================\n\n"; // Write functions for (auto& func_name : module.free_functions_in_order) { @@ -1063,18 +1063,18 @@ namespace wis { if (vk_has_handles) { file_w << "\n\n//==============================================================\n" - "// Handles\n" - "//==============================================================\n\n"; + "// Handles\n" + "//==============================================================\n\n"; // Write handles for (auto& handle_name : module.handles_in_order) { auto& handle_def = handle_map[handle_name]; if (has(handle_def.GetBackend(), Backend::Vulkan)) { file_w << std::format( - "using {} = {};\n", - handle_def.name, - GetCPPFullTypename(handle_def.name, Backend::Vulkan) - ); + "using {} = {};\n", + handle_def.name, + GetCPPFullTypename(handle_def.name, Backend::Vulkan) + ); } } @@ -1083,36 +1083,36 @@ namespace wis { auto& handle_def = handle_map[handle_name]; if (handle_def.GetViewSize(Backend::Vulkan) > 0) { file_w << std::format( - "using {}View = {};\n", - handle_def.name, - GetCPPFullTypename(handle_def.name, Backend::Vulkan) + "View" - ); + "using {}View = {};\n", + handle_def.name, + GetCPPFullTypename(handle_def.name, Backend::Vulkan) + "View" + ); } } } if (vk_has_variants) { file_w << "\n\n//==============================================================\n" - "// Variants\n" - "//==============================================================\n\n"; + "// Variants\n" + "//==============================================================\n\n"; // Write variants for (auto& variant_name : module.variants_in_order) { auto& variant_def = variant_map[variant_name]; if (has(variant_def.backend, Backend::Vulkan)) { file_w << std::format( - "using {} = {};\n", - variant_def.name, - GetCPPFullTypename(variant_def.name, Backend::Vulkan) - ); + "using {} = {};\n", + variant_def.name, + GetCPPFullTypename(variant_def.name, Backend::Vulkan) + ); } } } if (vk_has_functions) { file_w << "\n\n//==============================================================\n" - "// Functions\n" - "//==============================================================\n\n"; + "// Functions\n" + "//==============================================================\n\n"; // Write functions for (auto& func_name : module.free_functions_in_order) { @@ -1120,7 +1120,7 @@ namespace wis { auto& func_def = function_map[key]; if (has(func_def.backend, Backend::Vulkan)) { file_w - << MakeCPPFunctionImpl(func_def, Backend::Vulkan, "inline ", DocKind::Full, ProtoType::Universal); + << MakeCPPFunctionImpl(func_def, Backend::Vulkan, "inline ", DocKind::Full, ProtoType::Universal); file_w << '\n'; } } @@ -1161,7 +1161,7 @@ void Generator::WriteConversions(std::filesystem::path dir) // Write header file_dx << std::format( - R"(// This file is generated. Do not edit directly. + R"(// This file is generated. Do not edit directly. #ifndef WISDOM_{0}_CPP_DX12_CONVERT_HPP #define WISDOM_{0}_CPP_DX12_CONVERT_HPP #ifndef __cplusplus @@ -1174,10 +1174,10 @@ void Generator::WriteConversions(std::filesystem::path dir) namespace wis{{ namespace detail {{ )", - header_guard - ); + header_guard + ); file_vk << std::format( - R"(// This file is generated. Do not edit directly. + R"(// This file is generated. Do not edit directly. #ifndef WISDOM_{0}_CPP_VK_CONVERT_HPP #define WISDOM_{0}_CPP_VK_CONVERT_HPP #ifndef __cplusplus @@ -1190,8 +1190,8 @@ namespace wis{{ namespace detail {{ namespace wis{{ namespace detail {{ )", - header_guard - ); + header_guard + ); // Write enums for (auto& enum_name : module.enums_in_order) { @@ -1212,19 +1212,19 @@ namespace wis{{ namespace detail {{ // Write footer file_dx << std::format( - R"( + R"( }}}} #endif // WISDOM_{}_CPP_DX12_CONVERT_HPP )", - header_guard - ); + header_guard + ); file_vk << std::format( - R"( + R"( }}}} #endif // WISDOM_{}_CPP_VK_CONVERT_HPP )", - header_guard - ); + header_guard + ); } void Generator::WriteDocumentation( @@ -1247,9 +1247,9 @@ void Generator::WriteDocumentation( if (!file_exists) { std::string xenum = std::vformat( - doc_template, - std::make_format_args(object_name, code, desc, active_module_name) - ); + doc_template, + std::make_format_args(object_name, code, desc, active_module_name) + ); enum_file << FinalizeCDocumentation(xenum, object_name); enum_file.close(); @@ -1279,22 +1279,22 @@ void Generator::WriteDocumentation( // Replace the references section if (ref_start != std::string::npos && ref_end != std::string::npos && ref_end > ref_start) { existing_content = existing_content.substr(0, ref_start) + "\\cond WIS_GEN_REFS\n" + std::string(refs) - + existing_content.substr(ref_end); + + existing_content.substr(ref_end); } // Replace the vuids section if (vuid_start != std::string::npos && vuid_end != std::string::npos && vuid_end > vuid_start) { existing_content = existing_content.substr(0, vuid_start) + "\\cond WIS_GEN_WIS_IDS\n" + std::string(vuids) - + existing_content.substr(vuid_end); + + existing_content.substr(vuid_end); } // Replace the description section if (desc_start != std::string::npos && desc_end != std::string::npos && desc_end > desc_start) { existing_content = existing_content.substr(0, desc_start) + "\\cond WIS_GEN_DESC\n" + std::string(desc) - + existing_content.substr(desc_end); + + existing_content.substr(desc_end); } // Replace the generated section if (gen_start != std::string::npos && gen_end != std::string::npos && gen_end > gen_start) { existing_content = existing_content.substr(0, gen_start) + "\\cond WIS_GEN_CODE\n" + std::string(code) - + existing_content.substr(gen_end); + + existing_content.substr(gen_end); } // Write back to file @@ -1360,7 +1360,9 @@ void Generator::TryMakeRef(std::string_view type, std::string_view ref) } } -void Generator::TryMakeRef(std::string_view type, FunctionKey ref) { dependency_tree[type].functions.push_back(ref); } +void Generator::TryMakeRef(std::string_view type, FunctionKey ref) { + dependency_tree[type].functions.push_back(ref); +} std::string Generator::GetCFullTypename(std::string_view type, Backend backend) { @@ -1459,35 +1461,35 @@ std::string Generator::FinalizeCDocumentation(std::string doc, std::string_view auto& x = enum_map.at(this_type_view); auto evalue = x.HasValue(value); replacement = evalue ? std::format("`{}{}`", GetCFullTypename(x.name, backend), evalue->name) - : GetCFullTypename(x.name, backend); + : GetCFullTypename(x.name, backend); break; } case TypeKind::Bitmask: { auto& b = bitmask_map.at(this_type_view); auto evalue = b.HasValue(value); replacement = evalue ? std::format("`{}{}`", GetCFullTypename(b.name, backend), evalue->name) - : GetCFullTypename(b.name, backend); + : GetCFullTypename(b.name, backend); break; } case TypeKind::Struct: { auto& s = struct_map.at(this_type_view); auto member = s.HasValue(value); replacement = member ? std::format("`{}::{}`", GetCFullTypename(s.name, backend), member->name) - : GetCFullTypename(s.name, backend); + : GetCFullTypename(s.name, backend); break; } case TypeKind::Variant: { auto& v = variant_map.at(this_type_view); auto m = v.HasValue(value); replacement = m ? std::format("`{}::{}`", GetCFullTypename(v.name, backend), m->name) - : GetCFullTypename(v.name, backend); + : GetCFullTypename(v.name, backend); break; } case TypeKind::FuncPointer: { auto& d = delegate_map.at(this_type_view); auto m = d.HasValue(value); replacement = m ? std::format("`{}::{}`", GetCFullTypename(d.name, backend), m->name) - : GetCFullTypename(d.name, backend); + : GetCFullTypename(d.name, backend); break; } case TypeKind::Handle: { @@ -1576,35 +1578,35 @@ std::string Generator::FinalizeCPPDocumentation(std::string doc, std::string_vie auto& x = enum_map.at(this_type_view); auto evalue = x.HasValue(value); replacement = evalue ? std::format("`{}::{}`", GetCPPFullTypename(x.name, backend), evalue->name) - : GetCPPFullTypename(x.name, backend); + : GetCPPFullTypename(x.name, backend); break; } case TypeKind::Bitmask: { auto& b = bitmask_map.at(this_type_view); auto evalue = b.HasValue(value); replacement = evalue ? std::format("`{}::{}`", GetCPPFullTypename(b.name, backend), evalue->name) - : GetCPPFullTypename(b.name, backend); + : GetCPPFullTypename(b.name, backend); break; } case TypeKind::Struct: { auto& s = struct_map.at(this_type_view); auto member = s.HasValue(value); replacement = member ? std::format("`{}::{}`", GetCPPFullTypename(s.name, backend), member->name) - : GetCPPFullTypename(s.name, backend); + : GetCPPFullTypename(s.name, backend); break; } case TypeKind::Variant: { auto& v = variant_map.at(this_type_view); auto m = v.HasValue(value); replacement = m ? std::format("`{}::{}`", GetCPPFullTypename(v.name, backend), m->name) - : GetCPPFullTypename(v.name, backend); + : GetCPPFullTypename(v.name, backend); break; } case TypeKind::FuncPointer: { auto& d = delegate_map.at(this_type_view); auto m = d.HasValue(value); replacement = m ? std::format("`{}::{}`", GetCPPFullTypename(d.name, backend), m->name) - : GetCPPFullTypename(d.name, backend); + : GetCPPFullTypename(d.name, backend); break; } case TypeKind::Handle: { @@ -1676,9 +1678,9 @@ std::string Generator::GetSpecificationCode( if (!c_impl_code.empty()) { // append a details section template_content_c += std::format( - "
\nC Implementation Specific Version:\n```c\n{}```\n
\n", - c_impl_code - ); + "
\nC Implementation Specific Version:\n```c\n{}```\n
\n", + c_impl_code + ); } } @@ -1688,10 +1690,10 @@ std::string Generator::GetSpecificationCode( if (!cpp_impl_code.empty()) { // append a details section template_content_cpp += std::format( - "
\nC++ Implementation Specific Version:\n```cpp\nnamespace " - "wis{{\n{}}}\n```\n
\n", - cpp_impl_code - ); + "
\nC++ Implementation Specific Version:\n```cpp\nnamespace " + "wis{{\n{}}}\n```\n
\n", + cpp_impl_code + ); } } @@ -1942,11 +1944,11 @@ std::string Generator::GetFunctionCallParameters(const WisFunction& func, Backen if (p.modifier & Modifier::Span) { body += std::format( - "reinterpret_cast<{}>({}.data()), {}.size()", - GetMemberTypeString(p, backend), - p.name, - p.name - ); + "reinterpret_cast<{}>({}.data()), {}.size()", + GetMemberTypeString(p, backend), + p.name, + p.name + ); i++; // skip next parameter (the size) if (i < func.parameters.size() - 1) { body += arg_prefix; diff --git a/generator/generator.hpp b/generator/generator.hpp index 8464737c..a46fd561 100644 --- a/generator/generator.hpp +++ b/generator/generator.hpp @@ -25,7 +25,9 @@ class Generator void ParseFile(std::filesystem::path file); void WriteModuleAPI(); void WriteModuleAPIDoc(std::string_view module_name = {}); - auto GetFiles() const { return std::span{files}; } + auto GetFiles() const { + return std::span {files}; + } public: void ParseIncludes(tinyxml2::XMLElement* includes); @@ -253,7 +255,7 @@ class Generator } } return pre_doc ? std::format(" {}\n {}\n", documentation, value_decl) - : std::format("{}{}\n", value_decl, documentation); + : std::format("{}{}\n", value_decl, documentation); } template @@ -267,9 +269,9 @@ class Generator // This arg if (!type.this_type.empty()) { args += std::format( - "@param self is a pointer to the valid {{{}::}} instance.\n", - type.this_type - ); + "@param self is a pointer to the valid {{{}::}} instance.\n", + type.this_type + ); } // Function arguments @@ -354,9 +356,9 @@ class Generator } if (member.modifier & Modifier::Span) { return std::format( - "wis::span<{}>", - attributes_pre + GetCPPFullTypename(member.type, backend) + attributes_inter - ); + "wis::span<{}>", + attributes_pre + GetCPPFullTypename(member.type, backend) + attributes_inter + ); } return attributes_pre + GetCPPFullTypename(member.type, backend) + attributes_inter; } else { diff --git a/generator/handle.cpp b/generator/handle.cpp index e4fb52d6..2d55414b 100644 --- a/generator/handle.cpp +++ b/generator/handle.cpp @@ -169,10 +169,10 @@ std::string Generator::MakeCHandle(const WisHandle& s, Backend backend, DocKind auto impl_string = GetBackendSuffix(backend); auto extends_macro = s.extends == Extends::None - ? std::string("WIS_DEFINE_HANDLE") - : (s.extends == Extends::Instance - ? std::format("WIS_DEFINE_{}_INSTANCE_EXT_HANDLE", impl_string) - : std::format("WIS_DEFINE_{}_DEVICE_EXT_HANDLE", impl_string)); + ? std::string("WIS_DEFINE_HANDLE") + : (s.extends == Extends::Instance + ? std::format("WIS_DEFINE_{}_INSTANCE_EXT_HANDLE", impl_string) + : std::format("WIS_DEFINE_{}_DEVICE_EXT_HANDLE", impl_string)); auto full_name = GetCFullTypename(s.name, backend); @@ -191,12 +191,12 @@ std::string Generator::MakeCHandle(const WisHandle& s, Backend backend, DocKind auto view_name = s.view_override.empty() ? full_name : GetCFullTypename(s.view_override, backend); st_decl += std::format( - "\nstatic inline {}View wisGet{}{}View(const {}* handle){{\n", - view_name, - impl_string, - s.name, - full_name - ); + "\nstatic inline {}View wisGet{}{}View(const {}* handle){{\n", + view_name, + impl_string, + s.name, + full_name + ); st_decl += std::format(" {}View v;\n", view_name); st_decl += " memcpy(&v, handle, sizeof(v));\n" " return v;\n}\n"; @@ -212,23 +212,23 @@ std::string Generator::MakeCPPHandle(const WisHandle& s, Backend backend, DocKin auto full_name = GetCFullTypename(s.name, backend); std::string deleter = std::format( - "struct {}{}Deleter {{\n " - "void operator()({}* handle) noexcept {{\n ", - impl_string, - s.name, - full_name - ); + "struct {}{}Deleter {{\n " + "void operator()({}* handle) noexcept {{\n ", + impl_string, + s.name, + full_name + ); std::string st_decl = std::format( - "class {}{} : public wis::impl::Implements{{\npublic:\n", - impl_string, - s.name, - impl_string, - s.name, - full_name, - impl_string, - s.name - ); + "class {}{} : public wis::impl::Implements{{\npublic:\n", + impl_string, + s.name, + impl_string, + s.name, + full_name, + impl_string, + s.name + ); if (!s.doc.empty()) { std::string xdoc = MakeTypeDocumentation(s, kind); @@ -246,25 +246,25 @@ std::string Generator::MakeCPPHandle(const WisHandle& s, Backend backend, DocKin // Strict aliasing rules prevent us from doing a simple cast, so we have to memcpy the data to a new view struct auto view_name = s.view_override.empty() ? s.name : s.view_override; st_decl2 += std::format( - " WIS_NODISCARD {}{}View GetView() const noexcept {{\n" - " {}{}View v;\n" - " std::memcpy(&v, &_impl_storage, sizeof(v));\n" - " return v;\n" - " }}\n", - impl_string, - view_name, - impl_string, - view_name - ); + " WIS_NODISCARD {}{}View GetView() const noexcept {{\n" + " {}{}View v;\n" + " std::memcpy(&v, &_impl_storage, sizeof(v));\n" + " return v;\n" + " }}\n", + impl_string, + view_name, + impl_string, + view_name + ); // add conversion operator to view st_decl2 += std::format( - " WIS_NODISCARD operator {}{}View() const noexcept {{\n" - " return GetView();\n" - " }}\n", - impl_string, - view_name - ); + " WIS_NODISCARD operator {}{}View() const noexcept {{\n" + " return GetView();\n" + " }}\n", + impl_string, + view_name + ); } // Add all the functions @@ -272,11 +272,11 @@ std::string Generator::MakeCPPHandle(const WisHandle& s, Backend backend, DocKin FunctionKey func_key{s.name, func_name}; auto& func_ref = function_map[func_key]; auto c_name = std::format( - "wis{}{}{}", - impl_string, - func_ref.modifier & (Destroy | Construct) ? "" : func_ref.this_type, - func_ref.name - ); + "wis{}{}{}", + impl_string, + func_ref.modifier & (Destroy | Construct) ? "" : func_ref.this_type, + func_ref.name + ); if (func_ref.modifier & Modifier::Destroy) { deleter += std::format(" ::{}(handle);\n", c_name); continue; @@ -315,17 +315,17 @@ std::string Generator::MakeCPPHandle(const WisHandle& s, Backend backend, DocKin } ctor_decl += std::format( - " {}{}({}) noexcept\n" - " :ImplType(wis::in_place)\n" - " {{\n" - " ::{}({});\n" - " }}\n", - impl_string, - s.name, - params, - c_name, - args - ); + " {}{}({}) noexcept\n" + " :ImplType(wis::in_place)\n" + " {{\n" + " ::{}({});\n" + " }}\n", + impl_string, + s.name, + params, + c_name, + args + ); continue; } @@ -334,14 +334,14 @@ std::string Generator::MakeCPPHandle(const WisHandle& s, Backend backend, DocKin if (s.extends != Extends::None) { auto header = s.extends == Extends::Instance ? GetCPPFullTypename("InstanceExtensionHeader", backend) - : GetCPPFullTypename("DeviceExtensionHeader", backend); + : GetCPPFullTypename("DeviceExtensionHeader", backend); ctor_decl += std::format( - " // Operator & overload\n" - "{}* operator&() noexcept {{\n" - " return &GetMutableInternal().header;\n" - "}}\n", - header - ); + " // Operator & overload\n" + "{}* operator&() noexcept {{\n" + " return &GetMutableInternal().header;\n" + "}}\n", + header + ); } deleter += " }\n};\n"; @@ -372,7 +372,7 @@ void Generator::WriteHandleDocumentation(std::filesystem::path handle_output_pat // Make a folder for enums starting with this letter std::filesystem::create_directories(handle_output_path); std::filesystem::path handle_file_path = handle_output_path - / std::format("{}_handle.h", MakeSnakeCase(handle_name)); + / std::format("{}_handle.h", MakeSnakeCase(handle_name)); auto& handle_ref = handle_map[handle_name]; files.push_back(handle_file_path); diff --git a/generator/struct.cpp b/generator/struct.cpp index 8a4cbd3f..514eb8c6 100644 --- a/generator/struct.cpp +++ b/generator/struct.cpp @@ -91,10 +91,10 @@ std::string Generator::MakeCStruct(const WisStruct& s, DocKind kind) { auto full_name = GetCFullTypename(s.name, Backend::Any); std::string st_decl = std::format( - "typedef struct {} {} {{\n", - s.modifier & Modifier::Nodiscard ? "WIS_NODISCARD" : "", - full_name - ); + "typedef struct {} {} {{\n", + s.modifier & Modifier::Nodiscard ? "WIS_NODISCARD" : "", + full_name + ); if (!s.doc.empty()) { std::string xdoc = MakeTypeDocumentation(s, kind); st_decl = std::format("{}\n{}", xdoc, st_decl); @@ -118,10 +118,10 @@ std::string Generator::MakeCStruct(const WisStruct& s, DocKind kind) std::string Generator::MakeCPPStruct(const WisStruct& s, DocKind kind) { std::string st_decl = std::format( - "struct {} {} {{\n", - s.modifier & Modifier::Nodiscard ? "WIS_NODISCARD" : "", - s.name - ); + "struct {} {} {{\n", + s.modifier & Modifier::Nodiscard ? "WIS_NODISCARD" : "", + s.name + ); if (!s.doc.empty()) { std::string xdoc = MakeTypeDocumentation(s, kind); st_decl = std::format("{}\n{}", xdoc, st_decl); @@ -142,11 +142,11 @@ std::string Generator::MakeCPPStruct(const WisStruct& s, DocKind kind) } st_decl += MakeValueDocumentation( - s, - m, - MakeCPPMemberDeclaration(m, max_type_length, Backend::Any), - kind - ); + s, + m, + MakeCPPMemberDeclaration(m, max_type_length, Backend::Any), + kind + ); prev_span = m.modifier & Modifier::Span; } st_decl += "};\n"; @@ -213,16 +213,16 @@ void Generator::WriteStructDocumentation(std::filesystem::path struct_output_pat for (const auto& struct_name : struct_names) { // Make a folder for enums starting with this letter std::filesystem::path struct_file_path = struct_output_path - / std::format("{}_struct.h", MakeSnakeCase(struct_name)); + / std::format("{}_struct.h", MakeSnakeCase(struct_name)); auto& struct_ref = struct_map[struct_name]; files.push_back(struct_file_path); std::string struct_template_content = std::format( - " * C version:\n```c\n{}```\n" - "C++ version:\n```cpp\nnamespace wis{{\n{}}}\n```\n", - MakeCStruct(struct_ref, DocKind::VersionOnly), - MakeCPPStruct(struct_ref, DocKind::VersionOnly) - ); + " * C version:\n```c\n{}```\n" + "C++ version:\n```cpp\nnamespace wis{{\n{}}}\n```\n", + MakeCStruct(struct_ref, DocKind::VersionOnly), + MakeCPPStruct(struct_ref, DocKind::VersionOnly) + ); std::string struct_description = std::format(" * {}", MakeStructDescription(struct_ref)); std::string struct_refs = GetRefs(struct_name); diff --git a/generator/types.hpp b/generator/types.hpp index dfe6932c..5d99f4cb 100644 --- a/generator/types.hpp +++ b/generator/types.hpp @@ -41,7 +41,9 @@ constexpr Backend operator&(Backend a, Backend b) { return static_cast(static_cast(a) & static_cast(b)); } -constexpr bool has(Backend a, Backend b) { return (a & b) == b; } +constexpr bool has(Backend a, Backend b) { + return (a & b) == b; +} enum class ImplOs { None, @@ -118,8 +120,11 @@ struct WisEnum { public: std::optional HasValue(std::string_view name) const noexcept { - auto enum_value = std::find_if(values.begin(), values.end(), [&](auto& v) { return v.name == name; }); - return enum_value != values.end() ? std::optional{*enum_value} : std::nullopt; + auto enum_value = std::find_if(values.begin(), values.end(), [&](auto& v) { + return v.name == name; + }); + return enum_value != values.end() ? std::optional {*enum_value} : + std::nullopt; } }; @@ -142,8 +147,11 @@ struct WisBitmask { public: std::optional HasValue(std::string_view name) const noexcept { - auto enum_value = std::find_if(values.begin(), values.end(), [&](auto& v) { return v.name == name; }); - return enum_value != values.end() ? std::optional{*enum_value} : std::nullopt; + auto enum_value = std::find_if(values.begin(), values.end(), [&](auto& v) { + return v.name == name; + }); + return enum_value != values.end() ? std::optional {*enum_value} : + std::nullopt; } }; @@ -174,10 +182,14 @@ struct WisStruct { return {}; } - auto enum_value = std::find_if(members.begin(), members.end(), [&](auto& v) { return v.name == name; }); + auto enum_value = std::find_if(members.begin(), members.end(), [&](auto& v) { + return v.name == name; + }); return *enum_value; } - void FilterBackend(Backend b) { backend = backend & b; } + void FilterBackend(Backend b) { + backend = backend & b; + } }; //---------------------------------------------------------------------------------------------------------------------- @@ -256,10 +268,18 @@ struct WisReturnType { return ReturnTypeKind::ResultAndValue; } - bool IsVoid() const noexcept { return type.empty() && !has_result; } - bool IsRV() const noexcept { return has_result && !type.empty(); } - bool IsDirect() const noexcept { return !has_result && !type.empty(); } - bool IsResultOnly() const noexcept { return has_result && type.empty(); } + bool IsVoid() const noexcept { + return type.empty() && !has_result; + } + bool IsRV() const noexcept { + return has_result && !type.empty(); + } + bool IsDirect() const noexcept { + return !has_result && !type.empty(); + } + bool IsResultOnly() const noexcept { + return has_result && type.empty(); + } }; struct WisFunction { std::string_view name; @@ -278,7 +298,9 @@ struct WisFunction { if (name.empty()) { return {}; } - auto enum_value = std::find_if(parameters.begin(), parameters.end(), [&](auto& v) { return v.name == name; }); + auto enum_value = std::find_if(parameters.begin(), parameters.end(), [&](auto& v) { + return v.name == name; + }); if (enum_value == parameters.end()) { // it can be return value if (return_type.opt_name == name) { @@ -296,9 +318,13 @@ struct WisFunction { } // constructor or destructor - bool IsCD() const noexcept { return modifier & (Modifier::Construct | Modifier::Destroy); } + bool IsCD() const noexcept { + return modifier & (Modifier::Construct | Modifier::Destroy); + } - void FilterBackend(Backend b) { backend = backend & b; } + void FilterBackend(Backend b) { + backend = backend & b; + } }; static inline constexpr Severity from_chars(std::string_view input) noexcept @@ -342,7 +368,7 @@ template <> struct hash { std::size_t operator()(const FunctionKey& k) const noexcept { - return std::hash{}(k.first) ^ (std::hash{}(k.second) << 1); + return std::hash {}(k.first) ^ (std::hash {}(k.second) << 1); } }; } // namespace std diff --git a/generator/validation.cpp b/generator/validation.cpp index 33388eed..640e7ef3 100644 --- a/generator/validation.cpp +++ b/generator/validation.cpp @@ -4,7 +4,7 @@ void Generator::ParseValidations(tinyxml2::XMLElement* validations) { for (auto* validation = validations->FirstChildElement("validation"); validation; - validation = validation->NextSiblingElement("validation")) { + validation = validation->NextSiblingElement("validation")) { auto name = validation->FindAttribute("for")->Value(); auto& ref = validation_map[name]; diff --git a/generator/variant.cpp b/generator/variant.cpp index 2b7deb44..fc5affd3 100644 --- a/generator/variant.cpp +++ b/generator/variant.cpp @@ -91,10 +91,10 @@ std::string Generator::MakeCVariant(const WisStruct& s, Backend backend, DocKind auto impl_suffix = GetBackendSuffix(backend); auto full_name = GetCFullTypename(s.name, backend); std::string st_decl = std::format( - "typedef struct {}{} {{\n", - s.modifier & Modifier::Nodiscard ? "WIS_NODISCARD " : "", - full_name - ); + "typedef struct {}{} {{\n", + s.modifier & Modifier::Nodiscard ? "WIS_NODISCARD " : "", + full_name + ); if (!s.doc.empty()) { std::string xdoc = MakeTypeDocumentation(s, kind); st_decl = std::format("{}\n{}", xdoc, st_decl); @@ -123,11 +123,11 @@ std::string Generator::MakeCPPVariant(const WisStruct& s, Backend backend, DocKi auto impl_suffix = GetBackendSuffix(backend); std::string st_decl = std::format( - "struct {}{}{} {{\n", - s.modifier & Modifier::Nodiscard ? "WIS_NODISCARD " : "", - impl_suffix, - s.name - ); + "struct {}{}{} {{\n", + s.modifier & Modifier::Nodiscard ? "WIS_NODISCARD " : "", + impl_suffix, + s.name + ); if (!s.doc.empty()) { std::string xdoc = MakeTypeDocumentation(s, kind); st_decl = std::format("{}\n{}", xdoc, st_decl); @@ -171,7 +171,7 @@ void Generator::WriteVariantDocumentation(std::filesystem::path struct_output_pa for (const auto& variant_name : variant_names) { // Make a folder for enums starting with this letter std::filesystem::path variant_file_path = struct_output_path - / std::format("{}_struct.h", MakeSnakeCase(variant_name)); + / std::format("{}_struct.h", MakeSnakeCase(variant_name)); auto& variant_ref = variant_map[variant_name]; files.push_back(variant_file_path); @@ -181,8 +181,8 @@ void Generator::WriteVariantDocumentation(std::filesystem::path struct_output_pa std::string vk_code = supports_vk ? MakeCVariant(variant_ref, Backend::Vulkan, DocKind::VersionOnly) : ""; std::string dx_code = supports_dx ? MakeCVariant(variant_ref, Backend::DX12, DocKind::VersionOnly) : ""; std::string regular_code = supports_vk && supports_dx - ? MakeCVariant(variant_ref, Backend::Any, DocKind::VersionOnly) - : ""; + ? MakeCVariant(variant_ref, Backend::Any, DocKind::VersionOnly) + : ""; std::string c_code = regular_code; std::string cimpl_code = supports_vk && supports_dx ? (vk_code + '\n' + dx_code) : ""; @@ -191,18 +191,18 @@ void Generator::WriteVariantDocumentation(std::filesystem::path struct_output_pa } std::string vk_cpp = variant_ref.modifier & Modifier::COnly || !supports_vk - ? "" - : MakeCPPVariant(variant_ref, Backend::Vulkan, DocKind::VersionOnly); + ? "" + : MakeCPPVariant(variant_ref, Backend::Vulkan, DocKind::VersionOnly); std::string dx_cpp = variant_ref.modifier & Modifier::COnly || !supports_dx - ? "" - : MakeCPPVariant(variant_ref, Backend::DX12, DocKind::VersionOnly); + ? "" + : MakeCPPVariant(variant_ref, Backend::DX12, DocKind::VersionOnly); std::string regular_code_cpp = variant_ref.modifier & Modifier::COnly || !(supports_vk && supports_dx) - ? "" - : MakeCPPVariant(variant_ref, Backend::Any, DocKind::VersionOnly); + ? "" + : MakeCPPVariant(variant_ref, Backend::Any, DocKind::VersionOnly); std::string cpp_code = regular_code_cpp; std::string cimpl_code_cpp = variant_ref.modifier & Modifier::COnly || !(supports_vk && supports_dx) - ? "" - : vk_cpp + '\n' + dx_cpp; + ? "" + : vk_cpp + '\n' + dx_cpp; if (cpp_code.empty()) { cpp_code = !vk_cpp.empty() ? vk_cpp : dx_cpp; } diff --git a/src/include/wisdom/dx12/detail/dx12_detail.hpp b/src/include/wisdom/dx12/detail/dx12_detail.hpp index 262d5ad8..71d982f3 100644 --- a/src/include/wisdom/dx12/detail/dx12_detail.hpp +++ b/src/include/wisdom/dx12/detail/dx12_detail.hpp @@ -57,11 +57,11 @@ struct DX12DebugLayerThunk final : public IUnknownImplRegisterMessageCallback( - DX12CallbackThunk, - D3D12_MESSAGE_CALLBACK_FLAG_NONE, - this, - &cookie - ); + DX12CallbackThunk, + D3D12_MESSAGE_CALLBACK_FLAG_NONE, + this, + &cookie + ); // Debug layer creation failure is allowed to silently fail (void)hr; } @@ -136,18 +136,18 @@ struct DX12RootSignatureKey { //---------------------------------------------------------------------------------------------------------------------- struct DX12ShaderHeader { - uint64_t hash[2]{}; // Hash of the shader bytecode, used for caching and identification purposes. + uint64_t hash[2] {}; // Hash of the shader bytecode, used for caching and identification purposes. std::size_t size = 0; // Size of the shader bytecode in bytes. // bytecode follows immediately after the header in memory. wis::span GetBytecode() const noexcept { - return wis::span{reinterpret_cast(this + 1), size}; + return wis::span {reinterpret_cast(this + 1), size}; } wis::span GetMutableBytecode() noexcept { - return wis::span{reinterpret_cast(this + 1), size}; + return wis::span {reinterpret_cast(this + 1), size}; } }; @@ -244,7 +244,7 @@ inline constexpr uint32_t DX12GetCopyPlaneSlice(WisBarrierFlags flags, uint16_t //---------------------------------------------------------------------------------------------------------------------- // Barrier helper constants constexpr static uint32_t dx12_max_barrier_size = std::max( - {sizeof(D3D12_BUFFER_BARRIER), sizeof(D3D12_TEXTURE_BARRIER), sizeof(D3D12_GLOBAL_BARRIER)} +{sizeof(D3D12_BUFFER_BARRIER), sizeof(D3D12_TEXTURE_BARRIER), sizeof(D3D12_GLOBAL_BARRIER)} ); constexpr static uint32_t dx12_static_size = wis::TransientMaxBarrierCount * dx12_max_barrier_size; @@ -268,8 +268,8 @@ inline std::array, 3> DX12AllocateBarriers( { std::array, 3> spans; std::size_t needed_size = barriers.buffer_barrier_count * sizeof(D3D12_BUFFER_BARRIER) - + barriers.texture_barrier_count * sizeof(D3D12_TEXTURE_BARRIER) - + barriers.global_barrier_count * sizeof(D3D12_GLOBAL_BARRIER); + + barriers.texture_barrier_count * sizeof(D3D12_TEXTURE_BARRIER) + + barriers.global_barrier_count * sizeof(D3D12_GLOBAL_BARRIER); if (needed_size <= dx12_static_size) { spans[0] = {local_scratch, barriers.buffer_barrier_count * sizeof(D3D12_BUFFER_BARRIER)}; @@ -403,7 +403,7 @@ inline void DX12InsertBarriers( return; } - uint8_t local_scratch[dx12_static_size]{}; + uint8_t local_scratch[dx12_static_size] {}; auto [buffer_span, texture_span, global_span] = DX12AllocateBarriers(impl, local_scratch, *barriers); @@ -444,13 +444,13 @@ inline void DX12InsertBarriers( bool release_barrier = qfot_barrier && src.queue_type_before == queue_type; auto layout_before = DX12GetOptimalBarrierLayout( - queue_type, - acquire_barrier ? WisTextureStateCommon : src.state_before - ); + queue_type, + acquire_barrier ? WisTextureStateCommon : src.state_before + ); auto layout_after = DX12GetOptimalBarrierLayout( - queue_type, - release_barrier ? WisTextureStateCommon : src.state_after - ); + queue_type, + release_barrier ? WisTextureStateCommon : src.state_after + ); texture_barriers_span[i] = D3D12_TEXTURE_BARRIER{ .SyncBefore = DX12Convert(src.sync_before), @@ -461,16 +461,16 @@ inline void DX12InsertBarriers( .LayoutAfter = layout_after, .pResource = std::bit_cast(src.texture), .Subresources = - { - .IndexOrFirstMipLevel = src.subresource_range.base_mip_level, - .NumMipLevels = src.subresource_range.mip_level_count, - .FirstArraySlice = src.subresource_range.base_array_layer, - .NumArraySlices = src.subresource_range.array_layer_count, - .FirstPlane = src.flags & WisBarrierFlagsPlanarImage ? src.subresource_range.plane_slice : 0u, - .NumPlanes = src.flags & WisBarrierFlagsPlanarImage ? src.subresource_range.plane_slice_count : 1u, - }, + { + .IndexOrFirstMipLevel = src.subresource_range.base_mip_level, + .NumMipLevels = src.subresource_range.mip_level_count, + .FirstArraySlice = src.subresource_range.base_array_layer, + .NumArraySlices = src.subresource_range.array_layer_count, + .FirstPlane = src.flags & WisBarrierFlagsPlanarImage ? src.subresource_range.plane_slice : 0u, + .NumPlanes = src.flags & WisBarrierFlagsPlanarImage ? src.subresource_range.plane_slice_count : 1u, + }, .Flags = src.state_before == WisTextureStateUndefined ? D3D12_TEXTURE_BARRIER_FLAG_DISCARD - : D3D12_TEXTURE_BARRIER_FLAG_NONE, + : D3D12_TEXTURE_BARRIER_FLAG_NONE, }; } @@ -488,16 +488,19 @@ inline void DX12InsertBarriers( }; } - D3D12_BARRIER_GROUP groups[]{ - {.Type = D3D12_BARRIER_TYPE_BUFFER, - .NumBarriers = real_buffer_barrier_count, - .pBufferBarriers = buffer_barriers_span.data()}, - {.Type = D3D12_BARRIER_TYPE_TEXTURE, - .NumBarriers = static_cast(barriers->texture_barrier_count), - .pTextureBarriers = texture_barriers_span.data()}, - {.Type = D3D12_BARRIER_TYPE_GLOBAL, - .NumBarriers = static_cast(barriers->global_barrier_count), - .pGlobalBarriers = global_barriers_span.data()} + D3D12_BARRIER_GROUP groups[] { + { .Type = D3D12_BARRIER_TYPE_BUFFER, + .NumBarriers = real_buffer_barrier_count, + .pBufferBarriers = buffer_barriers_span.data() + }, + { .Type = D3D12_BARRIER_TYPE_TEXTURE, + .NumBarriers = static_cast(barriers->texture_barrier_count), + .pTextureBarriers = texture_barriers_span.data() + }, + { .Type = D3D12_BARRIER_TYPE_GLOBAL, + .NumBarriers = static_cast(barriers->global_barrier_count), + .pGlobalBarriers = global_barriers_span.data() + } }; list->Barrier(std::size(groups), groups); } diff --git a/src/include/wisdom/dx12/dx12_command_list.cpp b/src/include/wisdom/dx12/dx12_command_list.cpp index c8c1684e..d387d8de 100644 --- a/src/include/wisdom/dx12/dx12_command_list.cpp +++ b/src/include/wisdom/dx12/dx12_command_list.cpp @@ -21,7 +21,7 @@ inline D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_SUBRESOURCE_PARAMETERS* DX12Alloc if (new_size > impl.rp_memory_size) { delete[] impl.render_pass_memory; impl.render_pass_memory = new (std::nothrow) - D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_SUBRESOURCE_PARAMETERS[new_size]; + D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_SUBRESOURCE_PARAMETERS[new_size]; impl.rp_memory_size = impl.render_pass_memory ? new_size : 0; } return impl.render_pass_memory; @@ -84,17 +84,17 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListSetDescriptorHeaps( uint32_t heap_count = (resource_heap != 0) + (sampler_heap != 0); ID3D12DescriptorHeap* heaps[] = { resource_heap ? wis::from_handle(resource_heap)->descriptor_heap - : nullptr, + : nullptr, sampler_heap ? wis::from_handle(sampler_heap)->descriptor_heap - : nullptr, + : nullptr, }; impl.descriptor_handle = resource_heap - ? wis::from_handle(resource_heap)->gpu_handle - : D3D12_GPU_DESCRIPTOR_HANDLE{0}; + ? wis::from_handle(resource_heap)->gpu_handle + : D3D12_GPU_DESCRIPTOR_HANDLE{0}; impl.sampler_handle = sampler_heap - ? wis::from_handle(sampler_heap)->gpu_handle - : D3D12_GPU_DESCRIPTOR_HANDLE{0}; + ? wis::from_handle(sampler_heap)->gpu_handle + : D3D12_GPU_DESCRIPTOR_HANDLE{0}; if (heap_count > 0) { impl.list->SetDescriptorHeaps(heap_count, heaps + heap_offset); @@ -134,12 +134,12 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListSetPushConstants( default: case WisPipelineTypeGraphics: impl.list - ->SetGraphicsRoot32BitConstants(data->root_index, data->data_size / 4, data->data, data->push_offset / 4); + ->SetGraphicsRoot32BitConstants(data->root_index, data->data_size / 4, data->data, data->push_offset / 4); break; case WisPipelineTypeRayTracing: case WisPipelineTypeCompute: impl.list - ->SetComputeRoot32BitConstants(data->root_index, data->data_size / 4, data->data, data->push_offset / 4); + ->SetComputeRoot32BitConstants(data->root_index, data->data_size / 4, data->data, data->push_offset / 4); } } @@ -347,14 +347,14 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListBeginRenderPass( render_targets[i] = { .cpuDescriptor = aux ? aux->handle : D3D12_CPU_DESCRIPTOR_HANDLE{src.target}, .BeginningAccess = - { - .Type = wis::detail::DX12Convert(src.load_op), - }, + { + .Type = wis::detail::DX12Convert(src.load_op), + }, .EndingAccess = - { - .Type = src.resolve_desc ? D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE - : wis::detail::DX12Convert(src.store_op), - }, + { + .Type = src.resolve_desc ? D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE + : wis::detail::DX12Convert(src.store_op), + }, }; if (src.load_op == WisLoadOpClear) { render_targets[i].BeginningAccess.Clear.ClearValue = { @@ -381,7 +381,7 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListBeginRenderPass( // Encode the other parameters .pSubresourceParameters = static_cast< - const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_SUBRESOURCE_PARAMETERS*>(static_cast(dst) + const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_SUBRESOURCE_PARAMETERS*>(static_cast(dst) ), .Format = static_cast(dst->format), .ResolveMode = wis::detail::DX12Convert(resolve.mode), @@ -397,38 +397,38 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListBeginRenderPass( bool ignore_stencil = (desc->depth_stencil.flags & WisDepthStencilFlagsIgnoreStencil); flags |= (desc->depth_stencil.flags & WisDepthStencilFlagsReadOnlyDepth) && !ignore_depth - ? D3D12_RENDER_PASS_FLAG_BIND_READ_ONLY_DEPTH - : D3D12_RENDER_PASS_FLAG_NONE; + ? D3D12_RENDER_PASS_FLAG_BIND_READ_ONLY_DEPTH + : D3D12_RENDER_PASS_FLAG_NONE; flags |= (desc->depth_stencil.flags & WisDepthStencilFlagsReadOnlyStencil) && !ignore_stencil - ? D3D12_RENDER_PASS_FLAG_BIND_READ_ONLY_STENCIL - : D3D12_RENDER_PASS_FLAG_NONE; + ? D3D12_RENDER_PASS_FLAG_BIND_READ_ONLY_STENCIL + : D3D12_RENDER_PASS_FLAG_NONE; auto& src = desc->depth_stencil; auto* aux = wis::detail::DX12DecodeViewAddress(src.target); depth_stencil = { .cpuDescriptor = aux ? aux->handle : D3D12_CPU_DESCRIPTOR_HANDLE{src.target}, .DepthBeginningAccess = - { - .Type = ignore_depth ? D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_NO_ACCESS - : wis::detail::DX12Convert(src.load_op_depth), - }, + { + .Type = ignore_depth ? D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_NO_ACCESS + : wis::detail::DX12Convert(src.load_op_depth), + }, .StencilBeginningAccess = - { - .Type = ignore_stencil ? D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_NO_ACCESS - : wis::detail::DX12Convert(src.load_op_stencil), - }, + { + .Type = ignore_stencil ? D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_NO_ACCESS + : wis::detail::DX12Convert(src.load_op_stencil), + }, .DepthEndingAccess = - { - .Type = ignore_depth ? D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_NO_ACCESS - : src.resolve_depth_desc ? D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE - : wis::detail::DX12Convert(src.store_op_depth), - }, + { + .Type = ignore_depth ? D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_NO_ACCESS + : src.resolve_depth_desc ? D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE + : wis::detail::DX12Convert(src.store_op_depth), + }, .StencilEndingAccess = - { - .Type = ignore_stencil ? D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_NO_ACCESS - : src.resolve_stencil_desc ? D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE - : wis::detail::DX12Convert(src.store_op_stencil), - }, + { + .Type = ignore_stencil ? D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_NO_ACCESS + : src.resolve_stencil_desc ? D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE + : wis::detail::DX12Convert(src.store_op_stencil), + }, }; if (src.resolve_depth_desc) { @@ -450,7 +450,7 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListBeginRenderPass( // Encode the other parameters .pSubresourceParameters = static_cast< - const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_SUBRESOURCE_PARAMETERS*>(static_cast(dst) + const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_SUBRESOURCE_PARAMETERS*>(static_cast(dst) ), .Format = static_cast(dst->format), .ResolveMode = wis::detail::DX12Convert(resolve.mode), @@ -476,7 +476,7 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListBeginRenderPass( .SubresourceCount = layer_count, // Encode the other parameters .pSubresourceParameters = static_cast< - const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_SUBRESOURCE_PARAMETERS*>(static_cast(dst) + const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_SUBRESOURCE_PARAMETERS*>(static_cast(dst) ), .Format = static_cast(dst->format), .ResolveMode = wis::detail::DX12Convert(resolve.mode), @@ -501,7 +501,7 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListBeginRenderPass( auto& dst = render_targets[i].EndingAccess.Resolve; auto* src_aux = wis::detail::DX12DecodeViewAddress(src.target); auto* dst_aux = reinterpret_cast(dst.pSubresourceParameters - ); + ); wis::span subresource_params{ subresources + offset, @@ -513,12 +513,12 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListBeginRenderPass( .SrcSubresource = src_aux->base_subresource + j * src_aux->subresource_stride, .DstSubresource = dst_aux->base_subresource + j * dst_aux->subresource_stride, .SrcRect = - { - .left = 0, - .top = 0, - .right = static_cast(width), - .bottom = static_cast(height), - }, + { + .left = 0, + .top = 0, + .right = static_cast(width), + .bottom = static_cast(height), + }, }; } dst.pSubresourceParameters = subresource_params.data(); @@ -538,8 +538,8 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListBeginRenderPass( if (src.resolve_depth_desc) { auto& dst_depth = depth_stencil.DepthEndingAccess.Resolve; auto* dst_depth_aux = reinterpret_cast( - dst_depth.pSubresourceParameters - ); + dst_depth.pSubresourceParameters + ); wis::span subresource_params{ subresources + offset, @@ -550,14 +550,14 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListBeginRenderPass( subresource_params[j] = { .SrcSubresource = aux->base_subresource + j * aux->subresource_stride, .DstSubresource = (dst_depth_aux ? dst_depth_aux->base_subresource : 0) - + j * (dst_depth_aux ? dst_depth_aux->subresource_stride : 0), + + j * (dst_depth_aux ? dst_depth_aux->subresource_stride : 0), .SrcRect = - { - .left = 0, - .top = 0, - .right = static_cast(width), - .bottom = static_cast(height), - }, + { + .left = 0, + .top = 0, + .right = static_cast(width), + .bottom = static_cast(height), + }, }; } depth_stencil.DepthEndingAccess.Resolve.pSubresourceParameters = subresource_params.data(); @@ -571,8 +571,8 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListBeginRenderPass( auto& dst_stencil = depth_stencil.StencilEndingAccess.Resolve; auto* dst_stencil_aux = reinterpret_cast( - dst_stencil.pSubresourceParameters - ); + dst_stencil.pSubresourceParameters + ); wis::span subresource_params{ subresources + offset, @@ -583,14 +583,14 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListBeginRenderPass( subresource_params[j] = { .SrcSubresource = aux->base_stencil_subresource + j * aux->subresource_stride, .DstSubresource = (dst_stencil_aux ? dst_stencil_aux->base_stencil_subresource : 0) - + j * (dst_stencil_aux ? dst_stencil_aux->subresource_stride : 0), + + j * (dst_stencil_aux ? dst_stencil_aux->subresource_stride : 0), .SrcRect = - { - .left = 0, - .top = 0, - .right = static_cast(width), - .bottom = static_cast(height), - }, + { + .left = 0, + .top = 0, + .right = static_cast(width), + .bottom = static_cast(height), + }, }; } depth_stencil.StencilEndingAccess.Resolve.pSubresourceParameters = subresource_params.data(); @@ -689,7 +689,7 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListCopyBufferToTexture( uint32_t plane_slice = wis::detail::DX12GetCopyPlaneSlice(region.texture_region.flags, subresource.plane_slice); uint32_t dst_subresource = subresource.mip_level + subresource.array_layer * texture_desc.MipLevels - + plane_slice * texture_desc.MipLevels * texture_desc.DepthOrArraySize; + + plane_slice * texture_desc.MipLevels * texture_desc.DepthOrArraySize; D3D12_TEXTURE_COPY_LOCATION dst_location{ .pResource = dst, .Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, @@ -756,7 +756,7 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListCopyTextureToBuffer( uint32_t plane_slice = wis::detail::DX12GetCopyPlaneSlice(region.texture_region.flags, subresource.plane_slice); uint32_t src_subresource = subresource.mip_level + subresource.array_layer * texture_desc.MipLevels - + plane_slice * texture_desc.MipLevels * texture_desc.DepthOrArraySize; + + plane_slice * texture_desc.MipLevels * texture_desc.DepthOrArraySize; D3D12_TEXTURE_COPY_LOCATION src_location{ .pResource = src, .Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, @@ -831,18 +831,18 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListCopyTexture( const auto& dst_subresource = region.dst_region.target_subresource; uint32_t src_plane_slice = wis::detail::DX12GetCopyPlaneSlice( - region.src_region.flags, - src_subresource.plane_slice - ); + region.src_region.flags, + src_subresource.plane_slice + ); uint32_t src_subresource_index = src_subresource.mip_level + src_subresource.array_layer * src_desc.MipLevels - + src_plane_slice * src_desc.MipLevels * src_desc.DepthOrArraySize; + + src_plane_slice * src_desc.MipLevels * src_desc.DepthOrArraySize; uint32_t dst_plane_slice = wis::detail::DX12GetCopyPlaneSlice( - region.dst_region.flags, - dst_subresource.plane_slice - ); + region.dst_region.flags, + dst_subresource.plane_slice + ); uint32_t dst_subresource_index = dst_subresource.mip_level + dst_subresource.array_layer * dst_desc.MipLevels - + dst_plane_slice * dst_desc.MipLevels * dst_desc.DepthOrArraySize; + + dst_plane_slice * dst_desc.MipLevels * dst_desc.DepthOrArraySize; D3D12_TEXTURE_COPY_LOCATION dst_location{ .pResource = dst, diff --git a/src/include/wisdom/dx12/dx12_descriptor_heap.cpp b/src/include/wisdom/dx12/dx12_descriptor_heap.cpp index aac4e712..3fe028c4 100644 --- a/src/include/wisdom/dx12/dx12_descriptor_heap.cpp +++ b/src/include/wisdom/dx12/dx12_descriptor_heap.cpp @@ -37,13 +37,13 @@ inline DXGI_FORMAT DX12GetSRVFormat(const WisTextureBinding& binding) noexcept inline uint32_t DX12GetComponentMapping(WisComponentMapping mapping) noexcept { uint32_t r = mapping.r ? wis::detail::DX12Convert(mapping.r) - : D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_0; + : D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_0; uint32_t g = mapping.g ? wis::detail::DX12Convert(mapping.g) - : D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_1; + : D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_1; uint32_t b = mapping.b ? wis::detail::DX12Convert(mapping.b) - : D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_2; + : D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_2; uint32_t a = mapping.a ? wis::detail::DX12Convert(mapping.a) - : D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_3; + : D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_3; return D3D12_ENCODE_SHADER_4_COMPONENT_MAPPING(r, g, b, a); } @@ -215,7 +215,7 @@ inline void DX12FillRTVAuxData( // even though RT can be non-array, it may be a part of array uint32_t base_subresource = render_target.mip_level + mip_levels * render_target.base_array_layer - + plane_stride * plane_slice; + + plane_stride * plane_slice; switch (render_target.layout) { default: @@ -284,7 +284,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DescriptorHeapWriteConstantBuffer( }; heap.device->CreateConstantBufferView( &cbv_desc, - {heap.cpu_handle.ptr + static_cast(index) * heap.descriptor_size} + {heap.cpu_handle.ptr + static_cast(index) * heap.descriptor_size} ); return wis::detail::dx_success; } @@ -305,17 +305,17 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DescriptorHeapWriteStructuredBuffer( .ViewDimension = D3D12_SRV_DIMENSION_BUFFER, .Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING, .Buffer = - { - .FirstElement = data->array_offset, - .NumElements = data->structure_count, - .StructureByteStride = data->stride_bytes, - .Flags = D3D12_BUFFER_SRV_FLAG_NONE, - }, + { + .FirstElement = data->array_offset, + .NumElements = data->structure_count, + .StructureByteStride = data->stride_bytes, + .Flags = D3D12_BUFFER_SRV_FLAG_NONE, + }, }; heap.device->CreateShaderResourceView( resource, &srv_desc, - {heap.cpu_handle.ptr + static_cast(index) * heap.descriptor_size} + {heap.cpu_handle.ptr + static_cast(index) * heap.descriptor_size} ); return wis::detail::dx_success; } @@ -335,18 +335,18 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DescriptorHeapWriteRWStructuredBuffer( .Format = DXGI_FORMAT_UNKNOWN, // must be UNKNOWN for structured buffers .ViewDimension = D3D12_UAV_DIMENSION_BUFFER, .Buffer = - { - .FirstElement = data->array_offset, - .NumElements = data->structure_count, - .StructureByteStride = data->stride_bytes, - .Flags = D3D12_BUFFER_UAV_FLAG_NONE, - }, + { + .FirstElement = data->array_offset, + .NumElements = data->structure_count, + .StructureByteStride = data->stride_bytes, + .Flags = D3D12_BUFFER_UAV_FLAG_NONE, + }, }; heap.device->CreateUnorderedAccessView( resource, nullptr, &uav_desc, - {heap.cpu_handle.ptr + static_cast(index) * heap.descriptor_size} + {heap.cpu_handle.ptr + static_cast(index) * heap.descriptor_size} ); return wis::detail::dx_success; } @@ -358,19 +358,19 @@ wisDX12DescriptorHeapWriteSampler(const WisDX12DescriptorHeap* self, const WisSa auto& heap = wis::from_handle_ref(self); auto min_filter = !sampler->is_anisotropic ? wis::detail::DX12Convert(sampler->min_filter) - : D3D12_FILTER_TYPE_LINEAR; + : D3D12_FILTER_TYPE_LINEAR; auto mag_filter = !sampler->is_anisotropic ? wis::detail::DX12Convert(sampler->mag_filter) - : D3D12_FILTER_TYPE_LINEAR; + : D3D12_FILTER_TYPE_LINEAR; auto reduction_mode = sampler->comparison_op != WisCompareOpNone - ? D3D12_FILTER_REDUCTION_TYPE::D3D12_FILTER_REDUCTION_TYPE_COMPARISON - : wis::detail::DX12Convert(sampler->reduction_mode); + ? D3D12_FILTER_REDUCTION_TYPE::D3D12_FILTER_REDUCTION_TYPE_COMPARISON + : wis::detail::DX12Convert(sampler->reduction_mode); auto basic_filter = D3D12_ENCODE_BASIC_FILTER( - min_filter, - mag_filter, - wis::detail::DX12Convert(sampler->mip_filter), - reduction_mode - ); + min_filter, + mag_filter, + wis::detail::DX12Convert(sampler->mip_filter), + reduction_mode + ); auto filter = D3D12_FILTER(sampler->is_anisotropic * D3D12_ANISOTROPIC_FILTERING_BIT | basic_filter); constexpr static std::array border_colors[] = { @@ -394,7 +394,7 @@ wisDX12DescriptorHeapWriteSampler(const WisDX12DescriptorHeap* self, const WisSa }; heap.device->CreateSampler( &sampler_desc, - {heap.cpu_handle.ptr + static_cast(index) * heap.descriptor_size} + {heap.cpu_handle.ptr + static_cast(index) * heap.descriptor_size} ); return wis::detail::dx_success; } @@ -413,7 +413,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DescriptorHeapWriteTexture( heap.device->CreateShaderResourceView( resource, &desc, - {heap.cpu_handle.ptr + static_cast(index) * heap.descriptor_size} + {heap.cpu_handle.ptr + static_cast(index) * heap.descriptor_size} ); return wis::detail::dx_success; } @@ -433,7 +433,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DescriptorHeapWriteRWTexture( resource, nullptr, &desc, - {heap.cpu_handle.ptr + static_cast(index) * heap.descriptor_size} + {heap.cpu_handle.ptr + static_cast(index) * heap.descriptor_size} ); return wis::detail::dx_success; } @@ -452,7 +452,7 @@ wisDX12DescriptorHeapWriteAccelerationStructure(const WisDX12DescriptorHeap* sel heap.device->CreateShaderResourceView( nullptr, &desc, - {heap.cpu_handle.ptr + static_cast(index) * heap.descriptor_size} + {heap.cpu_handle.ptr + static_cast(index) * heap.descriptor_size} ); return wis::detail::dx_success; } @@ -469,9 +469,9 @@ WIS_EXTERN_C WISDOM_API void wisDX12DescriptorHeapCopyDescriptors( auto& heap = wis::from_handle_ref(self); heap.device->CopyDescriptorsSimple( count, - {heap.cpu_handle.ptr + static_cast(dst_index) * heap.descriptor_size}, - {std::bit_cast(src_ptr) + static_cast(src_index) * heap.descriptor_size}, - heap.type + {heap.cpu_handle.ptr + static_cast(dst_index) * heap.descriptor_size}, + {std::bit_cast(src_ptr) + static_cast(src_index) * heap.descriptor_size}, + heap.type ); } @@ -677,9 +677,9 @@ WIS_EXTERN_C WISDOM_API void wisDX12ViewHeapCopyViews( heap.device->CopyDescriptorsSimple( count, - {heap.cpu_handle.ptr + static_cast(dst_index) * heap.descriptor_size}, - {src_handle_ptr}, - heap.type + {heap.cpu_handle.ptr + static_cast(dst_index) * heap.descriptor_size}, + {src_handle_ptr}, + heap.type ); // copy aux data if present diff --git a/src/include/wisdom/dx12/dx12_device.cpp b/src/include/wisdom/dx12/dx12_device.cpp index bf5eb8e7..fff677dd 100644 --- a/src/include/wisdom/dx12/dx12_device.cpp +++ b/src/include/wisdom/dx12/dx12_device.cpp @@ -42,8 +42,8 @@ wisDX12DeviceCreateCommandQueue(const WisDX12Device* self, WisCommandQueueType t bool supported = (device.queue_priorities[type] & ~0x7fu) != 0; if (!supported) { return wis::detail::make_result< - wis::detail::Func(), - "Requested command queue type is not supported or not enabled by the device">(E_INVALIDARG); + wis::detail::Func(), + "Requested command queue type is not supported or not enabled by the device">(E_INVALIDARG); } D3D12_COMMAND_QUEUE_DESC desc{ @@ -75,10 +75,10 @@ wisDX12DeviceCreateCommandAllocator(const WisDX12Device* self, WisCommandQueueTy wis::com_ptr allocator; auto hr = device.device->CreateCommandAllocator( - wis::detail::DX12Convert(type), - IID_ID3D12CommandAllocator, - allocator.put_void_unchecked() - ); + wis::detail::DX12Convert(type), + IID_ID3D12CommandAllocator, + allocator.put_void_unchecked() + ); if (!wis::detail::succeeded(hr)) { return wis::detail::make_result(hr); } @@ -102,7 +102,7 @@ wisDX12DeviceCreateFence(const WisDX12Device* self, uint64_t initial_value, WisD wis::com_ptr out_fence; auto hr = device.device - ->CreateFence(initial_value, D3D12_FENCE_FLAG_NONE, IID_ID3D12Fence, out_fence.put_void_unchecked()); + ->CreateFence(initial_value, D3D12_FENCE_FLAG_NONE, IID_ID3D12Fence, out_fence.put_void_unchecked()); if (!wis::detail::succeeded(hr)) { return wis::detail::make_result(hr); } @@ -111,8 +111,8 @@ wisDX12DeviceCreateFence(const WisDX12Device* self, uint64_t initial_value, WisD auto event_handle = CreateEventW(nullptr, false, false, nullptr); if (!event_handle) { return wis::detail::make_result( - HRESULT_FROM_WIN32(GetLastError()) - ); + HRESULT_FROM_WIN32(GetLastError()) + ); } auto& internal = *new (fence) wis::impl::DX12FenceImpl{ @@ -156,7 +156,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateDescriptorHeap( wis::com_ptr descriptor_heap; HRESULT hr = device.device - ->CreateDescriptorHeap(&heap_desc, IID_ID3D12DescriptorHeap, descriptor_heap.put_void_unchecked()); + ->CreateDescriptorHeap(&heap_desc, IID_ID3D12DescriptorHeap, descriptor_heap.put_void_unchecked()); if (!wis::detail::succeeded(hr)) { return wis::detail::make_result(hr); } @@ -194,7 +194,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateViewHeap( wis::com_ptr descriptor_heap; HRESULT hr = device.device - ->CreateDescriptorHeap(&heap_desc, IID_ID3D12DescriptorHeap, descriptor_heap.put_void_unchecked()); + ->CreateDescriptorHeap(&heap_desc, IID_ID3D12DescriptorHeap, descriptor_heap.put_void_unchecked()); if (!wis::detail::succeeded(hr)) { return wis::detail::make_result(hr); } @@ -210,12 +210,12 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateViewHeap( && "[INTERNAL ERROR] DescriptorHandle is not aligned! Report the issue to the developers." ); - aux_data = new (std::nothrow) wis::detail::DX12RenderTargetViewAuxData[capacity]{}; + aux_data = new (std::nothrow) wis::detail::DX12RenderTargetViewAuxData[capacity] {}; if (!aux_data) { raw_heap->Release(); return wis::detail::make_result( - E_OUTOFMEMORY - ); + E_OUTOFMEMORY + ); } for (uint32_t i = 0; i < capacity; ++i) { aux_data[i].handle = {cpu_handle.ptr + static_cast(i) * descriptor_size}; @@ -251,8 +251,8 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateRootSignature( const auto& push_constant = desc->push_constants[i]; if (push_constant.size_bytes % 4 != 0) { return wis::detail::make_result( - E_INVALIDARG - ); + E_INVALIDARG + ); } push_constant_size += push_constant.size_bytes; } @@ -261,12 +261,12 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateRootSignature( // Check limits if (push_constant_size + 2 * desc->push_descriptor_count + desc->descriptor_table_count > max_root_parameters) { return wis::detail::make_result(E_INVALIDARG - ); + ); } D3D12_ROOT_PARAMETER1 root_parameters[max_root_parameters]; std::size_t num_root_parameters = desc->push_constant_count + desc->push_descriptor_count - + desc->descriptor_table_count; + + desc->descriptor_table_count; wis::span root_parameters_span{root_parameters, num_root_parameters}; // Push constants @@ -275,11 +275,11 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateRootSignature( root_parameters_span[i] = { .ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS, .Constants = - { - .ShaderRegister = static_cast(src.bind_register), - .RegisterSpace = static_cast(src.bind_space), - .Num32BitValues = static_cast(src.size_bytes / 4), - }, + { + .ShaderRegister = static_cast(src.bind_register), + .RegisterSpace = static_cast(src.bind_space), + .Num32BitValues = static_cast(src.size_bytes / 4), + }, .ShaderVisibility = wis::detail::DX12Convert(src.visibility), }; } @@ -291,18 +291,18 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateRootSignature( if (!wis::detail::DX12IsPushable(src.type)) { return wis::detail:: - make_result(E_INVALIDARG - ); + make_result(E_INVALIDARG + ); } root_parameters_span[i] = { .ParameterType = wis::detail::DX12RootParameterType(src.type), .Descriptor = - { - .ShaderRegister = src.bind_register, - .RegisterSpace = src.bind_space, - .Flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE, - }, + { + .ShaderRegister = src.bind_register, + .RegisterSpace = src.bind_space, + .Flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE, + }, .ShaderVisibility = wis::detail::DX12Convert(src.visibility), }; } @@ -323,8 +323,8 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateRootSignature( ranges = wis::make_unique(range_count); if (!ranges) { return wis::detail::make_result( - E_OUTOFMEMORY - ); + E_OUTOFMEMORY + ); } wis::span ranges_span{ranges.get(), range_count}; @@ -340,7 +340,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateRootSignature( .BaseShaderRegister = src.bind_register, .RegisterSpace = src.bind_space, .Flags = src.count > 1 ? D3D12_DESCRIPTOR_RANGE_FLAG_DESCRIPTORS_VOLATILE - : D3D12_DESCRIPTOR_RANGE_FLAG_NONE, + : D3D12_DESCRIPTOR_RANGE_FLAG_NONE, .OffsetInDescriptorsFromTableStart = src.descriptor_offset, }; } @@ -348,10 +348,10 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateRootSignature( root_parameters_span[i] = { .ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE, .DescriptorTable = - { - .NumDescriptorRanges = static_cast(table.entry_count), - .pDescriptorRanges = ranges.get() + range_offset, - }, + { + .NumDescriptorRanges = static_cast(table.entry_count), + .pDescriptorRanges = ranges.get() + range_offset, + }, .ShaderVisibility = wis::detail::DX12Convert(table.visibility), }; range_offset += table.entry_count; @@ -361,13 +361,13 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateRootSignature( D3D12_VERSIONED_ROOT_SIGNATURE_DESC rsig_desc{ .Version = D3D_ROOT_SIGNATURE_VERSION_1_2, .Desc_1_2 = - { - .NumParameters = static_cast(num_root_parameters), - .pParameters = root_parameters, - .NumStaticSamplers = 0, - .pStaticSamplers = nullptr, - .Flags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT, - }, + { + .NumParameters = static_cast(num_root_parameters), + .pParameters = root_parameters, + .NumStaticSamplers = 0, + .pStaticSamplers = nullptr, + .Flags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT, + }, }; wis::com_ptr signature; @@ -401,12 +401,12 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateRootSignature( wis::com_ptr root_signature; hr = device.device->CreateRootSignature( - 0, - signature->GetBufferPointer(), - signature->GetBufferSize(), - IID_ID3D12RootSignature, - root_signature.put_void_unchecked() - ); + 0, + signature->GetBufferPointer(), + signature->GetBufferSize(), + IID_ID3D12RootSignature, + root_signature.put_void_unchecked() + ); if (!wis::detail::succeeded(hr)) { return wis::detail::make_result(hr); } @@ -415,7 +415,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateRootSignature( XXH128_hash_t hash = XXH3_128bits(signature->GetBufferPointer(), signature->GetBufferSize()); wis::detail::DX12RootSignatureKey key{.hash{hash.low64, hash.high64}}; root_signature - ->SetPrivateData(wis::detail::DX12RootSignatureKey::guid, sizeof(wis::detail::DX12RootSignatureKey), &key); + ->SetPrivateData(wis::detail::DX12RootSignatureKey::guid, sizeof(wis::detail::DX12RootSignatureKey), &key); auto& layout_impl = *new (layout) wis::impl::DX12RootSignatureImpl{.root_signature = root_signature.detach()}; return res; @@ -442,50 +442,54 @@ WIS_EXTERN_C WISDOM_API void wisDX12DeviceQueryProperties(const WisDX12Device* s props->max_queue_priority[i] = WisCommandQueuePriority(device.queue_priorities[i] & 0x7f); } props->relaxed_queue_transition = true; - } break; + } + break; case WisQueryPropertyTypeDeviceDescriptorHeapProperties: { auto* props = static_cast(next); D3D12_FEATURE_DATA_D3D12_OPTIONS19 options19 = {}; if (wis::detail::succeeded( - device.device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS19, &options19, sizeof(options19)) - )) { + device.device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS19, &options19, sizeof(options19)) + )) { props->max_descriptor_heap_size = options19.MaxViewDescriptorHeapSize; props->max_sampler_heap_size = options19.MaxSamplerDescriptorHeapSize; props->max_sampler_heap_size_with_embedded = options19.MaxSamplerDescriptorHeapSizeWithStaticSamplers; props->descriptor_increment_size = device.device->GetDescriptorHandleIncrementSize( - D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV - ); + D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV + ); props->sampler_increment_size = device.device->GetDescriptorHandleIncrementSize( - D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER - ); + D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER + ); props->render_target_increment_size = device.device->GetDescriptorHandleIncrementSize( - D3D12_DESCRIPTOR_HEAP_TYPE_RTV - ); + D3D12_DESCRIPTOR_HEAP_TYPE_RTV + ); props->depth_stencil_increment_size = device.device->GetDescriptorHandleIncrementSize( - D3D12_DESCRIPTOR_HEAP_TYPE_DSV - ); + D3D12_DESCRIPTOR_HEAP_TYPE_DSV + ); props->render_target_with_ms_increment_size = sizeof(wis::detail::DX12RenderTargetViewAuxData); props->depth_stencil_with_ms_increment_size = sizeof(wis::detail::DX12RenderTargetViewAuxData); } - } break; + } + break; case WisQueryPropertyTypeDeviceMemoryProperties: { auto* props = static_cast(next); D3D12_FEATURE_DATA_D3D12_OPTIONS16 options16 = {}; if (wis::detail::succeeded( - device.device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS16, &options16, sizeof(options16)) - )) { + device.device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS16, &options16, sizeof(options16)) + )) { props->gpu_upload_supported = options16.GPUUploadHeapSupported; props->host_image_copy_supported = options16.GPUUploadHeapSupported; } - } break; + } + break; case WisQueryPropertyTypeDeviceBindingProperties: { auto* props = static_cast(next); props->max_vertex_input_bindings = D3D12_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; props->max_vertex_input_attributes = D3D12_IA_VERTEX_INPUT_STRUCTURE_ELEMENT_COUNT; props->multiple_viewports_supported = true; // D3D12 supports up to 16 viewports and scissor rectangles props->address_commands_supported = true; // D3D12 supports buffer address commands - } break; + } + break; default: break; } @@ -508,17 +512,17 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceWaitForMultipleFences( HANDLE event_handle = CreateEventW(nullptr, false, false, nullptr); if (!event_handle) { return wis::detail::make_result( - HRESULT_FROM_WIN32(GetLastError()) - ); + HRESULT_FROM_WIN32(GetLastError()) + ); } auto hr = device.device->SetEventOnMultipleFenceCompletion( - reinterpret_cast(fences), - fence_values, - static_cast(fence_count), - static_cast(wait_for), - event_handle - ); + reinterpret_cast(fences), + fence_values, + static_cast(fence_count), + static_cast(wait_for), + event_handle + ); CloseHandle(event_handle); @@ -543,8 +547,8 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreatePipelineCache( data_copy = static_cast(malloc(data_size)); if (!data_copy) { return wis::detail::make_result( - E_OUTOFMEMORY - ); + E_OUTOFMEMORY + ); } std::memcpy(data_copy, initial_data, data_size); } @@ -552,11 +556,11 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreatePipelineCache( wis::com_ptr pipeline_library; auto hr = device.device->CreatePipelineLibrary( - data_copy, - data_size, - IID_ID3D12PipelineLibrary1, - pipeline_library.put_void_unchecked() - ); + data_copy, + data_size, + IID_ID3D12PipelineLibrary1, + pipeline_library.put_void_unchecked() + ); if (!wis::detail::succeeded(hr)) { free(data_copy); @@ -581,11 +585,11 @@ wisDX12DeviceCreateShader(const WisDX12Device* self, const uint8_t* data, size_t auto& device = wis::from_handle_ref(self); std::unique_ptr shader_header{reinterpret_cast( - operator new(wis::aligned_size(size, 8ull) + sizeof(wis::detail::DX12ShaderHeader), std::nothrow) - )}; + operator new(wis::aligned_size(size, 8ull) + sizeof(wis::detail::DX12ShaderHeader), std::nothrow) + )}; if (!shader_header) { return wis::detail::make_result(E_OUTOFMEMORY - ); + ); } std::construct_at(shader_header.get()); @@ -621,14 +625,14 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateComputePipeline( // Validate root signature if (!rootsig) { return wis::detail::make_result< - wis::detail::Func(), - "Invalid root signature provided for compute pipeline creation">(E_INVALIDARG); + wis::detail::Func(), + "Invalid root signature provided for compute pipeline creation">(E_INVALIDARG); } // Validate shader if (!shader) { return wis::detail::make_result( - E_INVALIDARG - ); + E_INVALIDARG + ); } auto bytecode = shader->GetBytecode(); @@ -678,11 +682,11 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateComputePipeline( // Try to load pipeline from cache first if available HRESULT hr = cache->LoadPipeline( - name_buffer, - &pso_desc, - IID_ID3D12PipelineState, - pipeline_state.put_void_unchecked() - ); + name_buffer, + &pso_desc, + IID_ID3D12PipelineState, + pipeline_state.put_void_unchecked() + ); if (wis::detail::succeeded(hr)) { auto& pipeline_impl = *new (pipeline) wis::impl::DX12PipelineImpl{ .pipeline_state = pipeline_state.detach(), @@ -693,13 +697,13 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateComputePipeline( // Cache miss if (desc->flags & WisPipelineFlagsFailOnCacheMiss) { return wis::detail::make_result< - wis::detail::Func(), - "Pipeline not found in cache and creation is set to fail on cache miss">(WisStatusError, E_FAIL); + wis::detail::Func(), + "Pipeline not found in cache and creation is set to fail on cache miss">(WisStatusError, E_FAIL); } } auto hr = device.device - ->CreatePipelineState(&pso_desc, IID_ID3D12PipelineState, pipeline_state.put_void_unchecked()); + ->CreatePipelineState(&pso_desc, IID_ID3D12PipelineState, pipeline_state.put_void_unchecked()); if (!wis::detail::succeeded(hr)) { return wis::detail::make_result(hr); } @@ -727,8 +731,8 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateGraphicsPipeline( auto* rootsig = std::bit_cast(desc->root_signature); if (!rootsig) { return wis::detail::make_result< - wis::detail::Func(), - "Invalid root signature provided for graphics pipeline creation">(E_INVALIDARG); + wis::detail::Func(), + "Invalid root signature provided for graphics pipeline creation">(E_INVALIDARG); } struct GraphicsPipelineStream { @@ -755,8 +759,8 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateGraphicsPipeline( } stream{ .root_signature = rootsig, .flags = desc->flags & WisPipelineFlagsEnablePrimitiveRestart - ? D3D12_PIPELINE_STATE_FLAG_DYNAMIC_INDEX_BUFFER_STRIP_CUT - : D3D12_PIPELINE_STATE_FLAG_NONE, + ? D3D12_PIPELINE_STATE_FLAG_DYNAMIC_INDEX_BUFFER_STRIP_CUT + : D3D12_PIPELINE_STATE_FLAG_NONE, }; static constexpr size_t shader_stage_count = 5; @@ -774,7 +778,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateGraphicsPipeline( stream.vertex_shader = {{bytecode.data(), bytecode.size()}}; } else { return wis::detail:: - make_result(E_INVALIDARG); + make_result(E_INVALIDARG); } if (auto ps = shader_headers[1]) { auto bytecode = ps->GetBytecode(); @@ -796,7 +800,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateGraphicsPipeline( //--Render targets if (desc->render_attachments.attachments_count > wis::MaxRenderTargets) { return wis::detail:: - make_result(E_INVALIDARG); + make_result(E_INVALIDARG); } D3D12_RT_FORMAT_ARRAY& rtv_formats = stream.rtv_formats; @@ -809,7 +813,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateGraphicsPipeline( } //--Multiview - D3D12_VIEW_INSTANCE_LOCATION view_locs[wis::MaxRenderTargets]{}; + D3D12_VIEW_INSTANCE_LOCATION view_locs[wis::MaxRenderTargets] {}; if (desc->render_attachments.view_mask) { uint32_t view_mask = desc->render_attachments.view_mask; for (uint32_t i = 0u; i < wis::MaxRenderTargets; i++) { @@ -832,7 +836,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateGraphicsPipeline( //--Input layout wis::span slots{desc->input_layout.bindings, desc->input_layout.binding_count}; wis::span attrs{desc->input_layout.attributes, desc->input_layout.attribute_count}; - D3D12_INPUT_ELEMENT_DESC reasonable_max_input_elements[wis::MinSupportedInputAttributes * 2]{}; + D3D12_INPUT_ELEMENT_DESC reasonable_max_input_elements[wis::MinSupportedInputAttributes * 2] {}; std::unique_ptr input_elements; wis::span input_elements_span; if (!slots.empty() && !attrs.empty()) { @@ -872,16 +876,16 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateGraphicsPipeline( } stream.rasterizer = CD3DX12_RASTERIZER_DESC2{D3D12_RASTERIZER_DESC2{ - .FillMode = wis::detail::DX12Convert(raster.fill_mode), - .CullMode = wis::detail::DX12Convert(raster.cull_mode), - .FrontCounterClockwise = wis::detail::DX12Convert(raster.front_face), - .DepthBias = bias ? raster.depth_bias : 0.0f, - .DepthBiasClamp = bias ? raster.depth_bias_clamp : 0.0f, - .SlopeScaledDepthBias = bias ? raster.depth_bias_slope_factor : 0.0f, - .DepthClipEnable = raster.depth_clip_enable, - .LineRasterizationMode = wis::detail::DX12Convert(raster.line_rasterization), - .ConservativeRaster = wis::detail::DX12Convert(raster.conservative_rasterization) - }}; + .FillMode = wis::detail::DX12Convert(raster.fill_mode), + .CullMode = wis::detail::DX12Convert(raster.cull_mode), + .FrontCounterClockwise = wis::detail::DX12Convert(raster.front_face), + .DepthBias = bias ? raster.depth_bias : 0.0f, + .DepthBiasClamp = bias ? raster.depth_bias_clamp : 0.0f, + .SlopeScaledDepthBias = bias ? raster.depth_bias_slope_factor : 0.0f, + .DepthClipEnable = raster.depth_clip_enable, + .LineRasterizationMode = wis::detail::DX12Convert(raster.line_rasterization), + .ConservativeRaster = wis::detail::DX12Convert(raster.conservative_rasterization) + }}; } //--Multisample @@ -902,29 +906,30 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateGraphicsPipeline( if (desc->depth_stencil_desc) { auto& ds = *desc->depth_stencil_desc; stream.depth_stencil = CD3DX12_DEPTH_STENCIL_DESC2{ - {.DepthEnable = ds.depth_enable, - .DepthWriteMask = D3D12_DEPTH_WRITE_MASK(ds.depth_write_enable), - .DepthFunc = wis::detail::DX12Convert(ds.depth_comp), - .StencilEnable = ds.stencil_enable, - .FrontFace = - D3D12_DEPTH_STENCILOP_DESC1{ - .StencilFailOp = wis::detail::DX12Convert(ds.stencil_front.fail_op), - .StencilDepthFailOp = wis::detail::DX12Convert(ds.stencil_front.depth_fail_op), - .StencilPassOp = wis::detail::DX12Convert(ds.stencil_front.pass_op), - .StencilFunc = wis::detail::DX12Convert(ds.stencil_front.stencil_comp), - .StencilReadMask = ds.stencil_front.read_mask, - .StencilWriteMask = ds.stencil_front.write_mask, - }, - .BackFace = - D3D12_DEPTH_STENCILOP_DESC1{ - .StencilFailOp = wis::detail::DX12Convert(ds.stencil_back.fail_op), - .StencilDepthFailOp = wis::detail::DX12Convert(ds.stencil_back.depth_fail_op), - .StencilPassOp = wis::detail::DX12Convert(ds.stencil_back.pass_op), - .StencilFunc = wis::detail::DX12Convert(ds.stencil_back.stencil_comp), - .StencilReadMask = ds.stencil_back.read_mask, - .StencilWriteMask = ds.stencil_back.write_mask, - }, - .DepthBoundsTestEnable = ds.depth_bound_test} + { .DepthEnable = ds.depth_enable, + .DepthWriteMask = D3D12_DEPTH_WRITE_MASK(ds.depth_write_enable), + .DepthFunc = wis::detail::DX12Convert(ds.depth_comp), + .StencilEnable = ds.stencil_enable, + .FrontFace = + D3D12_DEPTH_STENCILOP_DESC1{ + .StencilFailOp = wis::detail::DX12Convert(ds.stencil_front.fail_op), + .StencilDepthFailOp = wis::detail::DX12Convert(ds.stencil_front.depth_fail_op), + .StencilPassOp = wis::detail::DX12Convert(ds.stencil_front.pass_op), + .StencilFunc = wis::detail::DX12Convert(ds.stencil_front.stencil_comp), + .StencilReadMask = ds.stencil_front.read_mask, + .StencilWriteMask = ds.stencil_front.write_mask, + }, + .BackFace = + D3D12_DEPTH_STENCILOP_DESC1{ + .StencilFailOp = wis::detail::DX12Convert(ds.stencil_back.fail_op), + .StencilDepthFailOp = wis::detail::DX12Convert(ds.stencil_back.depth_fail_op), + .StencilPassOp = wis::detail::DX12Convert(ds.stencil_back.pass_op), + .StencilFunc = wis::detail::DX12Convert(ds.stencil_back.stencil_comp), + .StencilReadMask = ds.stencil_back.read_mask, + .StencilWriteMask = ds.stencil_back.write_mask, + }, + .DepthBoundsTestEnable = ds.depth_bound_test + } }; } else { // Fix for depth stencil @@ -1017,9 +1022,9 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateGraphicsPipeline( // Hash pso stream wis::span pso_stream_bytes{// start after bytecodes - reinterpret_cast(&stream.flags), - // end at the end of the struct - reinterpret_cast(&stream + 1) + reinterpret_cast(&stream.flags), + // end at the end of the struct + reinterpret_cast(&stream + 1) }; XXH128_hash_t stream_hash = XXH3_128bits(pso_stream_bytes.data(), pso_stream_bytes.size()); rehash_input.pso_hash[0] = stream_hash.low64; @@ -1039,11 +1044,11 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateGraphicsPipeline( // Try to load pipeline from cache first if available HRESULT hr = cache->LoadPipeline( - name_buffer, - &psstream_desc, - IID_ID3D12PipelineState, - pipeline_state.put_void_unchecked() - ); + name_buffer, + &psstream_desc, + IID_ID3D12PipelineState, + pipeline_state.put_void_unchecked() + ); if (wis::detail::succeeded(hr)) { auto& pipeline_impl = *new (pipeline) wis::impl::DX12PipelineImpl{ .pipeline_state = pipeline_state.detach(), @@ -1054,16 +1059,16 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateGraphicsPipeline( // Cache miss if (desc->flags & WisPipelineFlagsFailOnCacheMiss) { return wis::detail::make_result< - wis::detail::Func(), - "Pipeline not found in cache and creation is set to fail on cache miss">(WisStatusError, E_FAIL); + wis::detail::Func(), + "Pipeline not found in cache and creation is set to fail on cache miss">(WisStatusError, E_FAIL); } } HRESULT hr = device.device->CreatePipelineState( - &psstream_desc, - IID_ID3D12PipelineState, - pipeline_state.put_void_unchecked() - ); + &psstream_desc, + IID_ID3D12PipelineState, + pipeline_state.put_void_unchecked() + ); if (!wis::detail::succeeded(hr)) { return wis::detail::make_result(hr); } @@ -1107,8 +1112,8 @@ wisDX12DeviceGetSurfaceParameters(const WisDX12Device* self, WisDX12SurfaceView .max_swapchain_images = DXGI_MAX_SWAP_CHAIN_BUFFERS, .alpha_modes_supported = 0b0000'1111, // Support all alpha modes (premultiplied, postmultiplied, opaque, custom) .texture_usage_flags_supported = static_cast( - WisTextureUsageFlagsRenderTarget | WisTextureUsageFlagsShaderResource | WisTextureUsageFlagsCopySrc - | WisTextureUsageFlagsCopyDst | WisTextureUsageFlagsUnorderedAccess + WisTextureUsageFlagsRenderTarget | WisTextureUsageFlagsShaderResource | WisTextureUsageFlagsCopySrc + | WisTextureUsageFlagsCopyDst | WisTextureUsageFlagsUnorderedAccess ), .stereo_supported = impl.factory->IsWindowedStereoEnabled() > 0, }; @@ -1133,7 +1138,8 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateSwapchain( BOOL xtearing = FALSE; device.factory->CheckFeatureSupport(DXGI_FEATURE_PRESENT_ALLOW_TEARING, &xtearing, sizeof(xtearing)); return bool(xtearing); - }(); + } + (); DXGI_USAGE usage = 0; switch (desc->texture_usage_flags) { @@ -1170,21 +1176,21 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateSwapchain( HRESULT hr = S_OK; if (surface_impl.uwp) { hr = device.factory->CreateSwapChainForCoreWindow( - queue_impl.queue, - static_cast(surface_impl.surface), - &swap_chain_desc, - nullptr, - swap_chain1.put_unchecked() - ); + queue_impl.queue, + static_cast(surface_impl.surface), + &swap_chain_desc, + nullptr, + swap_chain1.put_unchecked() + ); } else { hr = device.factory->CreateSwapChainForHwnd( - queue_impl.queue, - static_cast(surface_impl.surface), - &swap_chain_desc, - nullptr, - nullptr, - swap_chain1.put_unchecked() - ); + queue_impl.queue, + static_cast(surface_impl.surface), + &swap_chain_desc, + nullptr, + nullptr, + swap_chain1.put_unchecked() + ); } if (!wis::detail::succeeded(hr)) { diff --git a/src/include/wisdom/dx12/dx12_impl.cpp b/src/include/wisdom/dx12/dx12_impl.cpp index 43b6cfec..04693d45 100644 --- a/src/include/wisdom/dx12/dx12_impl.cpp +++ b/src/include/wisdom/dx12/dx12_impl.cpp @@ -90,20 +90,20 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12TextureWriteSubresource( UINT row_pitch = 0; UINT slice_pitch = 0; auto hr = D3D12_PROPERTY_LAYOUT_FORMAT_TABLE::CalculateMinimumRowMajorRowPitch( - desc.Format, - target_region->box.width, - row_pitch - ); + desc.Format, + target_region->box.width, + row_pitch + ); if (!wis::detail::succeeded(hr)) { return wis::detail::make_result(hr); } hr = D3D12_PROPERTY_LAYOUT_FORMAT_TABLE::CalculateMinimumRowMajorSlicePitch( - desc.Format, - row_pitch, - target_region->box.height, - slice_pitch - ); + desc.Format, + row_pitch, + target_region->box.height, + slice_pitch + ); if (!wis::detail::succeeded(hr)) { return wis::detail::make_result(hr); } @@ -117,12 +117,12 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12TextureWriteSubresource( .back = is_3d ? target_region->box.z + target_region->box.depth : 1, }; auto subresource = D3D12CalcSubresource( - target_region->target_subresource.mip_level, - target_region->target_subresource.array_layer, - target_region->target_subresource.plane_slice, - desc.MipLevels, - is_3d ? 1 : desc.DepthOrArraySize - ); + target_region->target_subresource.mip_level, + target_region->target_subresource.array_layer, + target_region->target_subresource.plane_slice, + desc.MipLevels, + is_3d ? 1 : desc.DepthOrArraySize + ); hr = resource->WriteToSubresource(subresource, &dst_box, source_data, row_pitch, slice_pitch); if (!wis::detail::succeeded(hr)) { return wis::detail::make_result(hr); diff --git a/src/include/wisdom/dx12/dx12_resource_allocator.cpp b/src/include/wisdom/dx12/dx12_resource_allocator.cpp index 07f15e73..6a9f2d63 100644 --- a/src/include/wisdom/dx12/dx12_resource_allocator.cpp +++ b/src/include/wisdom/dx12/dx12_resource_allocator.cpp @@ -21,23 +21,23 @@ inline WisResult DX12CreateResource( { if (all_desc.HeapType == D3D12_HEAP_TYPE_GPU_UPLOAD && !allocator->IsGPUUploadHeapSupported()) { return wis::detail::make_result( - E_NOTIMPL - ); + E_NOTIMPL + ); } wis::com_ptr resource; wis::com_ptr allocation; HRESULT hr = allocator->CreateResource3( - &all_desc, - &res_desc, - initial_layout, - nullptr, - static_cast(cast_formats.size()), - cast_formats.data(), - allocation.put_unchecked(), - resource.iid(), - resource.put_void_unchecked() - ); + &all_desc, + &res_desc, + initial_layout, + nullptr, + static_cast(cast_formats.size()), + cast_formats.data(), + allocation.put_unchecked(), + resource.iid(), + resource.put_void_unchecked() + ); if (!wis::detail::succeeded(hr)) { return wis::detail::make_result(hr); @@ -131,9 +131,9 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12ResourceAllocatorCreateBuffer( { auto& [allocator, device] = wis::from_handle_ref(self); uint64_t size = wis::aligned_size( - desc->size_bytes, - static_cast(D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT) - ); + desc->size_bytes, + static_cast(D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT) + ); D3D12_RESOURCE_DESC1 buffer_desc{ .Dimension = D3D12_RESOURCE_DIMENSION_BUFFER, .Alignment = 0, @@ -153,13 +153,13 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12ResourceAllocatorCreateBuffer( .HeapType = wis::detail::DX12Convert(desc->memory_type), }; return wis::detail::DX12CreateResource( - all_desc, - buffer_desc, - D3D12_BARRIER_LAYOUT_UNDEFINED, - allocator, - {}, - buffer - ); + all_desc, + buffer_desc, + D3D12_BARRIER_LAYOUT_UNDEFINED, + allocator, + {}, + buffer + ); } //---------------------------------------------------------------------------------------------------------------------- @@ -179,13 +179,13 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12ResourceAllocatorCreateTexture( // planar formats are uncastable if (desc->format >= WisDataFormatNV12) { return wis::detail::DX12CreateResource( - all_desc, - tex_desc, - D3D12_BARRIER_LAYOUT_UNDEFINED, - impl.allocator, - {}, - buffer - ); + all_desc, + tex_desc, + D3D12_BARRIER_LAYOUT_UNDEFINED, + impl.allocator, + {}, + buffer + ); } static constexpr uint32_t max_cast_formats = 16; @@ -221,22 +221,22 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12ResourceAllocatorCreateTexture( if (directly_mappable) { return wis::detail::DX12CreateResource( - all_desc, - tex_desc, - D3D12_BARRIER_LAYOUT_UNDEFINED, - impl.allocator, - {reinterpret_cast(desc->cast_formats), desc->cast_format_count}, - buffer - ); + all_desc, + tex_desc, + D3D12_BARRIER_LAYOUT_UNDEFINED, + impl.allocator, + {reinterpret_cast(desc->cast_formats), desc->cast_format_count}, + buffer + ); } return wis::detail::DX12CreateResource( - all_desc, - tex_desc, - D3D12_BARRIER_LAYOUT_UNDEFINED, - impl.allocator, - cast_formats_span, - buffer - ); + all_desc, + tex_desc, + D3D12_BARRIER_LAYOUT_UNDEFINED, + impl.allocator, + cast_formats_span, + buffer + ); } #endif // WIS_DX12_RESOURCE_ALLOCATOR_CPP diff --git a/src/include/wisdom/generated/cpp_api.hpp b/src/include/wisdom/generated/cpp_api.hpp index ba95d003..015d3b92 100644 --- a/src/include/wisdom/generated/cpp_api.hpp +++ b/src/include/wisdom/generated/cpp_api.hpp @@ -2868,7 +2868,9 @@ struct DX12IndexBufferDesc { }; struct DX12TextureDeleter { - void operator()(WisDX12Texture* handle) noexcept { ::wisDX12DestroyTexture(handle); } + void operator()(WisDX12Texture* handle) noexcept { + ::wisDX12DestroyTexture(handle); + } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a GPU texture resource. @@ -2886,7 +2888,9 @@ class DX12Texture : public wis::impl::Implements(&target_region) - ); + &_impl_storage, + source_data, + reinterpret_cast(&target_region) + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } }; struct DX12BufferDeleter { - void operator()(WisDX12Buffer* handle) noexcept { ::wisDX12DestroyBuffer(handle); } + void operator()(WisDX12Buffer* handle) noexcept { + ::wisDX12DestroyBuffer(handle); + } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a GPU buffer resource. @@ -2926,13 +2932,17 @@ class DX12Buffer : public wis::impl::Implements rects) const noexcept { const WisResult wis_result = ::wisDX12SwapchainPresent( - &_impl_storage, - static_cast(flags), - reinterpret_cast(rects.data()), - rects.size() - ); + &_impl_storage, + static_cast(flags), + reinterpret_cast(rects.data()), + rects.size() + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -2987,9 +2999,9 @@ class DX12Swapchain { std::uint32_t index{}; const WisResult wis_result = ::wisDX12SwapchainGetCurrentIndex( - &_impl_storage, - reinterpret_cast(&index) - ); + &_impl_storage, + reinterpret_cast(&index) + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -3007,9 +3019,9 @@ class DX12Swapchain inline wis::Result Update(const wis::SwapchainUpdateDesc& desc) const noexcept { const WisResult wis_result = ::wisDX12SwapchainUpdate( - &_impl_storage, - reinterpret_cast(&desc) - ); + &_impl_storage, + reinterpret_cast(&desc) + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -3021,16 +3033,18 @@ class DX12Swapchain inline wis::Result GetTextures(wis::span buffers) const noexcept { const WisResult wis_result = ::wisDX12SwapchainGetTextures( - &_impl_storage, - reinterpret_cast(buffers.data()), - buffers.size() - ); + &_impl_storage, + reinterpret_cast(buffers.data()), + buffers.size() + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } }; struct DX12SurfaceDeleter { - void operator()(WisDX12Surface* handle) noexcept { ::wisDX12DestroySurface(handle); } + void operator()(WisDX12Surface* handle) noexcept { + ::wisDX12DestroySurface(handle); + } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a GPU surface, which can be used as a target for rendering and @@ -3049,11 +3063,15 @@ class DX12Surface : public wis::impl::Implements(&texture), - reinterpret_cast(&render_target), - index - )); + &_impl_storage, + reinterpret_cast(&texture), + reinterpret_cast(&render_target), + index + )); } /** * @brief Provided by Wisdom 0.7.0. Writes a depth stencil view to the view heap and returns the CPU descriptor @@ -3106,11 +3124,11 @@ class DX12ViewHeap ) const noexcept { return (::wisDX12ViewHeapWriteDepthStencil( - &_impl_storage, - reinterpret_cast(&texture), - reinterpret_cast(&render_target), - index - )); + &_impl_storage, + reinterpret_cast(&texture), + reinterpret_cast(&render_target), + index + )); } /** * @brief Provided by Wisdom 0.7.1. Writes a texture view for video decode output and returns the texture view @@ -3128,11 +3146,11 @@ class DX12ViewHeap ) const noexcept { return (::wisDX12ViewHeapWriteVideoDecodeTarget( - &_impl_storage, - reinterpret_cast(&texture), - reinterpret_cast(&render_target), - index - )); + &_impl_storage, + reinterpret_cast(&texture), + reinterpret_cast(&render_target), + index + )); } /** * @brief Provided by Wisdom 0.7.0. Returns the CPU descriptor handle for the view heap. @@ -3173,7 +3191,9 @@ class DX12ViewHeap }; struct DX12PipelineDeleter { - void operator()(WisDX12Pipeline* handle) noexcept { ::wisDX12DestroyPipeline(handle); } + void operator()(WisDX12Pipeline* handle) noexcept { + ::wisDX12DestroyPipeline(handle); + } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a GPU pipeline state object, which encapsulates the state of the @@ -3193,11 +3213,15 @@ class DX12Pipeline std::memcpy(&v, &_impl_storage, sizeof(v)); return v; } - WIS_NODISCARD operator DX12PipelineView() const noexcept { return GetView(); } + WIS_NODISCARD operator DX12PipelineView() const noexcept { + return GetView(); + } }; struct DX12ShaderDeleter { - void operator()(WisDX12Shader* handle) noexcept { ::wisDX12DestroyShader(handle); } + void operator()(WisDX12Shader* handle) noexcept { + ::wisDX12DestroyShader(handle); + } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a GPU shader module, which contains shader code and allows to @@ -3216,11 +3240,15 @@ class DX12Shader : public wis::impl::Implements + Implements { public: using ImplType::ImplType; @@ -3241,7 +3269,9 @@ class DX12PipelineCache std::memcpy(&v, &_impl_storage, sizeof(v)); return v; } - WIS_NODISCARD operator DX12PipelineCacheView() const noexcept { return GetView(); } + WIS_NODISCARD operator DX12PipelineCacheView() const noexcept { + return GetView(); + } /** * @brief Provided by Wisdom 0.7.0. Gets the data from the pipeline cache. * @param data points to an array that is filled with serialized cache data on success. @@ -3251,10 +3281,10 @@ class DX12PipelineCache inline wis::Result Serialize(wis::span data) const noexcept { const WisResult wis_result = ::wisDX12PipelineCacheSerialize( - &_impl_storage, - reinterpret_cast(data.data()), - data.size() - ); + &_impl_storage, + reinterpret_cast(data.data()), + data.size() + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -3269,7 +3299,9 @@ class DX12PipelineCache }; struct DX12DescriptorHeapDeleter { - void operator()(WisDX12DescriptorHeap* handle) noexcept { ::wisDX12DestroyDescriptorHeap(handle); } + void operator()(WisDX12DescriptorHeap* handle) noexcept { + ::wisDX12DestroyDescriptorHeap(handle); + } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a storage for descriptors used in contiguous array. @@ -3277,7 +3309,7 @@ struct DX12DescriptorHeapDeleter { * */ class DX12DescriptorHeap : public wis::impl:: - Implements + Implements { public: using ImplType::ImplType; @@ -3303,10 +3335,10 @@ class DX12DescriptorHeap inline wis::Result WriteConstantBuffer(const wis::ConstantBufferBinding& data, std::uint32_t index) const noexcept { const WisResult wis_result = ::wisDX12DescriptorHeapWriteConstantBuffer( - &_impl_storage, - reinterpret_cast(&data), - index - ); + &_impl_storage, + reinterpret_cast(&data), + index + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -3325,11 +3357,11 @@ class DX12DescriptorHeap ) const noexcept { const WisResult wis_result = ::wisDX12DescriptorHeapWriteStructuredBuffer( - &_impl_storage, - buffer, - reinterpret_cast(&data), - index - ); + &_impl_storage, + buffer, + reinterpret_cast(&data), + index + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -3348,11 +3380,11 @@ class DX12DescriptorHeap ) const noexcept { const WisResult wis_result = ::wisDX12DescriptorHeapWriteRWStructuredBuffer( - &_impl_storage, - buffer, - reinterpret_cast(&data), - index - ); + &_impl_storage, + buffer, + reinterpret_cast(&data), + index + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -3365,10 +3397,10 @@ class DX12DescriptorHeap inline wis::Result WriteSampler(const wis::SamplerDesc& sampler, std::uint32_t index) const noexcept { const WisResult wis_result = ::wisDX12DescriptorHeapWriteSampler( - &_impl_storage, - reinterpret_cast(&sampler), - index - ); + &_impl_storage, + reinterpret_cast(&sampler), + index + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -3380,14 +3412,14 @@ class DX12DescriptorHeap * * */ inline wis::Result WriteTexture(wis::DX12TextureView texture, const wis::TextureBinding& data, std::uint32_t index) - const noexcept + const noexcept { const WisResult wis_result = ::wisDX12DescriptorHeapWriteTexture( - &_impl_storage, - texture, - reinterpret_cast(&data), - index - ); + &_impl_storage, + texture, + reinterpret_cast(&data), + index + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -3405,11 +3437,11 @@ class DX12DescriptorHeap ) const noexcept { const WisResult wis_result = ::wisDX12DescriptorHeapWriteRWTexture( - &_impl_storage, - texture, - reinterpret_cast(&data), - index - ); + &_impl_storage, + texture, + reinterpret_cast(&data), + index + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -3445,7 +3477,9 @@ class DX12DescriptorHeap }; struct DX12RootSignatureDeleter { - void operator()(WisDX12RootSignature* handle) noexcept { ::wisDX12DestroyRootSignature(handle); } + void operator()(WisDX12RootSignature* handle) noexcept { + ::wisDX12DestroyRootSignature(handle); + } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a pipeline layout and a constant data storage, which defines @@ -3454,7 +3488,7 @@ struct DX12RootSignatureDeleter { * */ class DX12RootSignature : public wis::impl:: - Implements + Implements { public: using ImplType::ImplType; @@ -3466,11 +3500,15 @@ class DX12RootSignature std::memcpy(&v, &_impl_storage, sizeof(v)); return v; } - WIS_NODISCARD operator DX12RootSignatureView() const noexcept { return GetView(); } + WIS_NODISCARD operator DX12RootSignatureView() const noexcept { + return GetView(); + } }; struct DX12ResourceAllocatorDeleter { - void operator()(WisDX12ResourceAllocator* handle) noexcept { ::wisDX12DestroyResourceAllocator(handle); } + void operator()(WisDX12ResourceAllocator* handle) noexcept { + ::wisDX12DestroyResourceAllocator(handle); + } }; /** * @brief Provided by Wisdom 0.7.0. Class for allocating and managing GPU resources like buffers and textures. @@ -3478,7 +3516,7 @@ struct DX12ResourceAllocatorDeleter { * */ class DX12ResourceAllocator : public wis::impl:: - Implements + Implements { public: using ImplType::ImplType; @@ -3492,14 +3530,14 @@ class DX12ResourceAllocator * * */ WIS_NODISCARD inline wis::DX12Buffer CreateBuffer(const wis::BufferDesc& desc, wis::Result& out_result) - const noexcept + const noexcept { wis::DX12Buffer buffer{}; const WisResult wis_result = ::wisDX12ResourceAllocatorCreateBuffer( - &_impl_storage, - reinterpret_cast(&desc), - buffer.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&desc), + buffer.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -3515,14 +3553,14 @@ class DX12ResourceAllocator * * */ WIS_NODISCARD inline wis::DX12Texture CreateTexture(const wis::TextureDesc& desc, wis::Result& out_result) - const noexcept + const noexcept { wis::DX12Texture texture{}; const WisResult wis_result = ::wisDX12ResourceAllocatorCreateTexture( - &_impl_storage, - reinterpret_cast(&desc), - texture.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&desc), + texture.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -3533,7 +3571,9 @@ class DX12ResourceAllocator }; struct DX12FenceDeleter { - void operator()(WisDX12Fence* handle) noexcept { ::wisDX12DestroyFence(handle); } + void operator()(WisDX12Fence* handle) noexcept { + ::wisDX12DestroyFence(handle); + } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a fence for GPU-CPU and GPU-GPU synchronization. @@ -3551,7 +3591,9 @@ class DX12Fence : public wis::impl::Implements + Implements { public: using ImplType::ImplType; @@ -4073,7 +4123,9 @@ class DX12CommandAllocator }; struct DX12CommandQueueDeleter { - void operator()(WisDX12CommandQueue* handle) noexcept { ::wisDX12DestroyCommandQueue(handle); } + void operator()(WisDX12CommandQueue* handle) noexcept { + ::wisDX12DestroyCommandQueue(handle); + } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a command queue for submitting command lists to the GPU. @@ -4095,10 +4147,10 @@ class DX12CommandQueue inline wis::Result Submit(wis::span lists) const noexcept { const WisResult wis_result = ::wisDX12CommandQueueSubmit( - &_impl_storage, - reinterpret_cast(lists.data()), - lists.size() - ); + &_impl_storage, + reinterpret_cast(lists.data()), + lists.size() + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -4130,7 +4182,9 @@ class DX12CommandQueue }; struct DX12DeviceDeleter { - void operator()(WisDX12Device* handle) noexcept { ::wisDX12DestroyDevice(handle); } + void operator()(WisDX12Device* handle) noexcept { + ::wisDX12DestroyDevice(handle); + } }; /** * @brief Provided by Wisdom 0.7.0. Central class representing logical device. @@ -4150,14 +4204,14 @@ class DX12Device : public wis::impl::Implements(type), - queue.GetStorage() - ); + &_impl_storage, + static_cast(type), + queue.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4179,10 +4233,10 @@ class DX12Device : public wis::impl::Implements(type), - allocator.GetStorage() - ); + &_impl_storage, + static_cast(type), + allocator.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4239,10 +4293,10 @@ class DX12Device : public wis::impl::Implements(&desc), - layout.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&desc), + layout.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4264,10 +4318,10 @@ class DX12Device : public wis::impl::Implements(&desc), - heap.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&desc), + heap.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4293,12 +4347,12 @@ class DX12Device : public wis::impl::Implements(type), - capacity, - static_cast(flags), - heap.GetStorage() - ); + &_impl_storage, + static_cast(type), + capacity, + static_cast(flags), + heap.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4337,13 +4391,13 @@ class DX12Device : public wis::impl::Implements(wait_for), - timeout - ); + &_impl_storage, + fences, + fence_values, + fence_count, + static_cast(wait_for), + timeout + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -4360,11 +4414,11 @@ class DX12Device : public wis::impl::Implements(initial_data.data()), - initial_data.size(), - cache.GetStorage() - ); + &_impl_storage, + reinterpret_cast(initial_data.data()), + initial_data.size(), + cache.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4380,15 +4434,15 @@ class DX12Device : public wis::impl::Implements data, wis::Result& out_result) - const noexcept + const noexcept { wis::DX12Shader shader{}; const WisResult wis_result = ::wisDX12DeviceCreateShader( - &_impl_storage, - reinterpret_cast(data.data()), - data.size(), - shader.GetStorage() - ); + &_impl_storage, + reinterpret_cast(data.data()), + data.size(), + shader.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4410,10 +4464,10 @@ class DX12Device : public wis::impl::Implements(&desc), - pipeline.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&desc), + pipeline.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4435,10 +4489,10 @@ class DX12Device : public wis::impl::Implements(&desc), - pipeline.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&desc), + pipeline.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4455,10 +4509,10 @@ class DX12Device : public wis::impl::Implements(format)) - ); + ); } /** * @brief Provided by Wisdom 0.7.0. Gets presentation parameters for the specified surface. @@ -4474,10 +4528,10 @@ class DX12Device : public wis::impl::Implements(¶ms) - ); + &_impl_storage, + surface, + reinterpret_cast(¶ms) + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4504,12 +4558,12 @@ class DX12Device : public wis::impl::Implements(&surface), - reinterpret_cast(&queue), - reinterpret_cast(&desc), - swapchain.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&surface), + reinterpret_cast(&queue), + reinterpret_cast(&desc), + swapchain.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4525,14 +4579,14 @@ class DX12Device : public wis::impl::Implements(format), - reinterpret_cast(&properties) - ); + &_impl_storage, + static_cast(format), + reinterpret_cast(&properties) + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4543,7 +4597,9 @@ class DX12Device : public wis::impl::Implements(&desc) - ); + &_impl_storage, + index, + reinterpret_cast(&desc) + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4618,11 +4674,11 @@ class DX12AdapterQuery { wis::DX12Device device{}; const WisResult wis_result = ::wisDX12AdapterQueryCreateDevice( - &_impl_storage, - index, - reinterpret_cast(&requirements), - device.GetStorage() - ); + &_impl_storage, + index, + reinterpret_cast(&requirements), + device.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4633,7 +4689,9 @@ class DX12AdapterQuery }; struct DX12InstanceDeleter { - void operator()(WisDX12Instance* handle) noexcept { ::wisDX12DestroyInstance(handle); } + void operator()(WisDX12Instance* handle) noexcept { + ::wisDX12DestroyInstance(handle); + } }; /** * @brief Provided by Wisdom 0.7.0. Class for creating adapters. @@ -4657,14 +4715,14 @@ class DX12Instance * * */ WIS_NODISCARD inline wis::DX12AdapterQuery QueryAdapters(wis::AdapterPreference preference, wis::Result& out_result) - const noexcept + const noexcept { wis::DX12AdapterQuery query{}; const WisResult wis_result = ::wisDX12InstanceQueryAdapters( - &_impl_storage, - static_cast(preference), - query.GetStorage() - ); + &_impl_storage, + static_cast(preference), + query.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4692,11 +4750,11 @@ WIS_NODISCARD inline wis::DX12Instance DX12CreateInstance( { wis::DX12Instance instance{}; const WisResult wis_result = ::wisDX12CreateInstance( - reinterpret_cast(debug_desc), - reinterpret_cast(extensions.data()), - extensions.size(), - instance.GetStorage() - ); + reinterpret_cast(debug_desc), + reinterpret_cast(extensions.data()), + extensions.size(), + instance.GetStorage() + ); out_result = wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; return instance; } @@ -4910,7 +4968,9 @@ struct VKIndexBufferDesc { }; struct VKTextureDeleter { - void operator()(WisVKTexture* handle) noexcept { ::wisVKDestroyTexture(handle); } + void operator()(WisVKTexture* handle) noexcept { + ::wisVKDestroyTexture(handle); + } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a GPU texture resource. @@ -4928,7 +4988,9 @@ class VKTexture : public wis::impl::Implements(&target_region) - ); + &_impl_storage, + source_data, + reinterpret_cast(&target_region) + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } }; struct VKBufferDeleter { - void operator()(WisVKBuffer* handle) noexcept { ::wisVKDestroyBuffer(handle); } + void operator()(WisVKBuffer* handle) noexcept { + ::wisVKDestroyBuffer(handle); + } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a GPU buffer resource. @@ -4968,13 +5032,17 @@ class VKBuffer : public wis::impl::Implements rects) const noexcept { const WisResult wis_result = ::wisVKSwapchainPresent( - &_impl_storage, - static_cast(flags), - reinterpret_cast(rects.data()), - rects.size() - ); + &_impl_storage, + static_cast(flags), + reinterpret_cast(rects.data()), + rects.size() + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -5028,9 +5098,9 @@ class VKSwapchain : public wis::impl::Implements(&index) - ); + &_impl_storage, + reinterpret_cast(&index) + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -5048,9 +5118,9 @@ class VKSwapchain : public wis::impl::Implements(&desc) - ); + &_impl_storage, + reinterpret_cast(&desc) + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -5062,16 +5132,18 @@ class VKSwapchain : public wis::impl::Implements buffers) const noexcept { const WisResult wis_result = ::wisVKSwapchainGetTextures( - &_impl_storage, - reinterpret_cast(buffers.data()), - buffers.size() - ); + &_impl_storage, + reinterpret_cast(buffers.data()), + buffers.size() + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } }; struct VKSurfaceDeleter { - void operator()(WisVKSurface* handle) noexcept { ::wisVKDestroySurface(handle); } + void operator()(WisVKSurface* handle) noexcept { + ::wisVKDestroySurface(handle); + } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a GPU surface, which can be used as a target for rendering and @@ -5090,11 +5162,15 @@ class VKSurface : public wis::impl::Implements(&texture), - reinterpret_cast(&render_target), - index - )); + &_impl_storage, + reinterpret_cast(&texture), + reinterpret_cast(&render_target), + index + )); } /** * @brief Provided by Wisdom 0.7.0. Writes a depth stencil view to the view heap and returns the CPU descriptor @@ -5146,11 +5222,11 @@ class VKViewHeap : public wis::impl::Implements(&texture), - reinterpret_cast(&render_target), - index - )); + &_impl_storage, + reinterpret_cast(&texture), + reinterpret_cast(&render_target), + index + )); } /** * @brief Provided by Wisdom 0.7.1. Writes a texture view for video decode output and returns the texture view @@ -5168,11 +5244,11 @@ class VKViewHeap : public wis::impl::Implements(&texture), - reinterpret_cast(&render_target), - index - )); + &_impl_storage, + reinterpret_cast(&texture), + reinterpret_cast(&render_target), + index + )); } /** * @brief Provided by Wisdom 0.7.0. Returns the CPU descriptor handle for the view heap. @@ -5213,7 +5289,9 @@ class VKViewHeap : public wis::impl::Implements data) const noexcept { const WisResult wis_result = ::wisVKPipelineCacheSerialize( - &_impl_storage, - reinterpret_cast(data.data()), - data.size() - ); + &_impl_storage, + reinterpret_cast(data.data()), + data.size() + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -5307,7 +5395,9 @@ class VKPipelineCache }; struct VKDescriptorHeapDeleter { - void operator()(WisVKDescriptorHeap* handle) noexcept { ::wisVKDestroyDescriptorHeap(handle); } + void operator()(WisVKDescriptorHeap* handle) noexcept { + ::wisVKDestroyDescriptorHeap(handle); + } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a storage for descriptors used in contiguous array. @@ -5340,10 +5430,10 @@ class VKDescriptorHeap inline wis::Result WriteConstantBuffer(const wis::ConstantBufferBinding& data, std::uint32_t index) const noexcept { const WisResult wis_result = ::wisVKDescriptorHeapWriteConstantBuffer( - &_impl_storage, - reinterpret_cast(&data), - index - ); + &_impl_storage, + reinterpret_cast(&data), + index + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -5362,11 +5452,11 @@ class VKDescriptorHeap ) const noexcept { const WisResult wis_result = ::wisVKDescriptorHeapWriteStructuredBuffer( - &_impl_storage, - buffer, - reinterpret_cast(&data), - index - ); + &_impl_storage, + buffer, + reinterpret_cast(&data), + index + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -5385,11 +5475,11 @@ class VKDescriptorHeap ) const noexcept { const WisResult wis_result = ::wisVKDescriptorHeapWriteRWStructuredBuffer( - &_impl_storage, - buffer, - reinterpret_cast(&data), - index - ); + &_impl_storage, + buffer, + reinterpret_cast(&data), + index + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -5402,10 +5492,10 @@ class VKDescriptorHeap inline wis::Result WriteSampler(const wis::SamplerDesc& sampler, std::uint32_t index) const noexcept { const WisResult wis_result = ::wisVKDescriptorHeapWriteSampler( - &_impl_storage, - reinterpret_cast(&sampler), - index - ); + &_impl_storage, + reinterpret_cast(&sampler), + index + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -5417,14 +5507,14 @@ class VKDescriptorHeap * * */ inline wis::Result WriteTexture(wis::VKTextureView texture, const wis::TextureBinding& data, std::uint32_t index) - const noexcept + const noexcept { const WisResult wis_result = ::wisVKDescriptorHeapWriteTexture( - &_impl_storage, - texture, - reinterpret_cast(&data), - index - ); + &_impl_storage, + texture, + reinterpret_cast(&data), + index + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -5436,14 +5526,14 @@ class VKDescriptorHeap * * */ inline wis::Result WriteRWTexture(wis::VKTextureView texture, const wis::TextureBinding& data, std::uint32_t index) - const noexcept + const noexcept { const WisResult wis_result = ::wisVKDescriptorHeapWriteRWTexture( - &_impl_storage, - texture, - reinterpret_cast(&data), - index - ); + &_impl_storage, + texture, + reinterpret_cast(&data), + index + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -5479,7 +5569,9 @@ class VKDescriptorHeap }; struct VKRootSignatureDeleter { - void operator()(WisVKRootSignature* handle) noexcept { ::wisVKDestroyRootSignature(handle); } + void operator()(WisVKRootSignature* handle) noexcept { + ::wisVKDestroyRootSignature(handle); + } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a pipeline layout and a constant data storage, which defines @@ -5499,11 +5591,15 @@ class VKRootSignature std::memcpy(&v, &_impl_storage, sizeof(v)); return v; } - WIS_NODISCARD operator VKRootSignatureView() const noexcept { return GetView(); } + WIS_NODISCARD operator VKRootSignatureView() const noexcept { + return GetView(); + } }; struct VKResourceAllocatorDeleter { - void operator()(WisVKResourceAllocator* handle) noexcept { ::wisVKDestroyResourceAllocator(handle); } + void operator()(WisVKResourceAllocator* handle) noexcept { + ::wisVKDestroyResourceAllocator(handle); + } }; /** * @brief Provided by Wisdom 0.7.0. Class for allocating and managing GPU resources like buffers and textures. @@ -5511,7 +5607,7 @@ struct VKResourceAllocatorDeleter { * */ class VKResourceAllocator : public wis::impl:: - Implements + Implements { public: using ImplType::ImplType; @@ -5528,10 +5624,10 @@ class VKResourceAllocator { wis::VKBuffer buffer{}; const WisResult wis_result = ::wisVKResourceAllocatorCreateBuffer( - &_impl_storage, - reinterpret_cast(&desc), - buffer.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&desc), + buffer.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -5547,14 +5643,14 @@ class VKResourceAllocator * * */ WIS_NODISCARD inline wis::VKTexture CreateTexture(const wis::TextureDesc& desc, wis::Result& out_result) - const noexcept + const noexcept { wis::VKTexture texture{}; const WisResult wis_result = ::wisVKResourceAllocatorCreateTexture( - &_impl_storage, - reinterpret_cast(&desc), - texture.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&desc), + texture.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -5565,7 +5661,9 @@ class VKResourceAllocator }; struct VKFenceDeleter { - void operator()(WisVKFence* handle) noexcept { ::wisVKDestroyFence(handle); } + void operator()(WisVKFence* handle) noexcept { + ::wisVKDestroyFence(handle); + } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a fence for GPU-CPU and GPU-GPU synchronization. @@ -5583,7 +5681,9 @@ class VKFence : public wis::impl::Implements + Implements { public: using ImplType::ImplType; @@ -6102,7 +6210,9 @@ class VKCommandAllocator }; struct VKCommandQueueDeleter { - void operator()(WisVKCommandQueue* handle) noexcept { ::wisVKDestroyCommandQueue(handle); } + void operator()(WisVKCommandQueue* handle) noexcept { + ::wisVKDestroyCommandQueue(handle); + } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a command queue for submitting command lists to the GPU. @@ -6124,10 +6234,10 @@ class VKCommandQueue inline wis::Result Submit(wis::span lists) const noexcept { const WisResult wis_result = ::wisVKCommandQueueSubmit( - &_impl_storage, - reinterpret_cast(lists.data()), - lists.size() - ); + &_impl_storage, + reinterpret_cast(lists.data()), + lists.size() + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -6159,7 +6269,9 @@ class VKCommandQueue }; struct VKDeviceDeleter { - void operator()(WisVKDevice* handle) noexcept { ::wisVKDestroyDevice(handle); } + void operator()(WisVKDevice* handle) noexcept { + ::wisVKDestroyDevice(handle); + } }; /** * @brief Provided by Wisdom 0.7.0. Central class representing logical device. @@ -6179,14 +6291,14 @@ class VKDevice : public wis::impl::Implements(type), - queue.GetStorage() - ); + &_impl_storage, + static_cast(type), + queue.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6208,10 +6320,10 @@ class VKDevice : public wis::impl::Implements(type), - allocator.GetStorage() - ); + &_impl_storage, + static_cast(type), + allocator.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6268,10 +6380,10 @@ class VKDevice : public wis::impl::Implements(&desc), - layout.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&desc), + layout.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6293,10 +6405,10 @@ class VKDevice : public wis::impl::Implements(&desc), - heap.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&desc), + heap.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6322,12 +6434,12 @@ class VKDevice : public wis::impl::Implements(type), - capacity, - static_cast(flags), - heap.GetStorage() - ); + &_impl_storage, + static_cast(type), + capacity, + static_cast(flags), + heap.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6366,13 +6478,13 @@ class VKDevice : public wis::impl::Implements(wait_for), - timeout - ); + &_impl_storage, + fences, + fence_values, + fence_count, + static_cast(wait_for), + timeout + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -6389,11 +6501,11 @@ class VKDevice : public wis::impl::Implements(initial_data.data()), - initial_data.size(), - cache.GetStorage() - ); + &_impl_storage, + reinterpret_cast(initial_data.data()), + initial_data.size(), + cache.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6409,15 +6521,15 @@ class VKDevice : public wis::impl::Implements data, wis::Result& out_result) - const noexcept + const noexcept { wis::VKShader shader{}; const WisResult wis_result = ::wisVKDeviceCreateShader( - &_impl_storage, - reinterpret_cast(data.data()), - data.size(), - shader.GetStorage() - ); + &_impl_storage, + reinterpret_cast(data.data()), + data.size(), + shader.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6439,10 +6551,10 @@ class VKDevice : public wis::impl::Implements(&desc), - pipeline.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&desc), + pipeline.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6464,10 +6576,10 @@ class VKDevice : public wis::impl::Implements(&desc), - pipeline.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&desc), + pipeline.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6484,7 +6596,7 @@ class VKDevice : public wis::impl::Implements(format))); } @@ -6502,10 +6614,10 @@ class VKDevice : public wis::impl::Implements(¶ms) - ); + &_impl_storage, + surface, + reinterpret_cast(¶ms) + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6532,12 +6644,12 @@ class VKDevice : public wis::impl::Implements(&surface), - reinterpret_cast(&queue), - reinterpret_cast(&desc), - swapchain.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&surface), + reinterpret_cast(&queue), + reinterpret_cast(&desc), + swapchain.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6553,14 +6665,14 @@ class VKDevice : public wis::impl::Implements(format), - reinterpret_cast(&properties) - ); + &_impl_storage, + static_cast(format), + reinterpret_cast(&properties) + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6571,7 +6683,9 @@ class VKDevice : public wis::impl::Implements(&desc) - ); + &_impl_storage, + index, + reinterpret_cast(&desc) + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6646,11 +6760,11 @@ class VKAdapterQuery { wis::VKDevice device{}; const WisResult wis_result = ::wisVKAdapterQueryCreateDevice( - &_impl_storage, - index, - reinterpret_cast(&requirements), - device.GetStorage() - ); + &_impl_storage, + index, + reinterpret_cast(&requirements), + device.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6661,7 +6775,9 @@ class VKAdapterQuery }; struct VKInstanceDeleter { - void operator()(WisVKInstance* handle) noexcept { ::wisVKDestroyInstance(handle); } + void operator()(WisVKInstance* handle) noexcept { + ::wisVKDestroyInstance(handle); + } }; /** * @brief Provided by Wisdom 0.7.0. Class for creating adapters. @@ -6684,14 +6800,14 @@ class VKInstance : public wis::impl::Implements(preference), - query.GetStorage() - ); + &_impl_storage, + static_cast(preference), + query.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6719,11 +6835,11 @@ WIS_NODISCARD inline wis::VKInstance VKCreateInstance( { wis::VKInstance instance{}; const WisResult wis_result = ::wisVKCreateInstance( - reinterpret_cast(debug_desc), - reinterpret_cast(extensions.data()), - extensions.size(), - instance.GetStorage() - ); + reinterpret_cast(debug_desc), + reinterpret_cast(extensions.data()), + extensions.size(), + instance.GetStorage() + ); out_result = wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; return instance; } diff --git a/src/include/wisdom/generated/dx12_convert.hpp b/src/include/wisdom/generated/dx12_convert.hpp index 4465c66a..e2095a1b 100644 --- a/src/include/wisdom/generated/dx12_convert.hpp +++ b/src/include/wisdom/generated/dx12_convert.hpp @@ -160,7 +160,9 @@ constexpr inline DXGI_FORMAT DX12Convert(WisDataFormat value) noexcept } } -constexpr inline uint32_t DX12Convert(WisSampleCount value) noexcept { return static_cast(value); } +constexpr inline uint32_t DX12Convert(WisSampleCount value) noexcept { + return static_cast(value); +} constexpr inline DXGI_GPU_PREFERENCE DX12Convert(WisAdapterPreference value) noexcept { @@ -402,11 +404,17 @@ constexpr inline D3D12_PRIMITIVE_TOPOLOGY_TYPE DX12Convert(WisTopologyType value } } -constexpr inline D3D12_FILL_MODE DX12Convert(WisFillMode value) noexcept { return static_cast(value); } +constexpr inline D3D12_FILL_MODE DX12Convert(WisFillMode value) noexcept { + return static_cast(value); +} -constexpr inline D3D12_CULL_MODE DX12Convert(WisCullMode value) noexcept { return static_cast(value); } +constexpr inline D3D12_CULL_MODE DX12Convert(WisCullMode value) noexcept { + return static_cast(value); +} -constexpr inline BOOL DX12Convert(WisWindingOrder value) noexcept { return static_cast(value); } +constexpr inline BOOL DX12Convert(WisWindingOrder value) noexcept { + return static_cast(value); +} constexpr inline D3D12_CONSERVATIVE_RASTERIZATION_MODE DX12Convert(WisConservativeRasterization value) noexcept { @@ -418,11 +426,17 @@ constexpr inline D3D12_LINE_RASTERIZATION_MODE DX12Convert(WisLineRasterization return static_cast(value); } -constexpr inline D3D12_BLEND DX12Convert(WisBlendFactor value) noexcept { return static_cast(value); } +constexpr inline D3D12_BLEND DX12Convert(WisBlendFactor value) noexcept { + return static_cast(value); +} -constexpr inline D3D12_BLEND_OP DX12Convert(WisBlendOp value) noexcept { return static_cast(value); } +constexpr inline D3D12_BLEND_OP DX12Convert(WisBlendOp value) noexcept { + return static_cast(value); +} -constexpr inline D3D12_LOGIC_OP DX12Convert(WisLogicOp value) noexcept { return static_cast(value); } +constexpr inline D3D12_LOGIC_OP DX12Convert(WisLogicOp value) noexcept { + return static_cast(value); +} constexpr inline D3D_PRIMITIVE_TOPOLOGY DX12Convert(WisPrimitiveTopology value) noexcept { diff --git a/src/include/wisdom/generated/vk_convert.hpp b/src/include/wisdom/generated/vk_convert.hpp index 24abc9e4..8628bbd4 100644 --- a/src/include/wisdom/generated/vk_convert.hpp +++ b/src/include/wisdom/generated/vk_convert.hpp @@ -371,7 +371,7 @@ constexpr inline VkMemoryPropertyFlags VKConvert(WisMemoryType value) noexcept return VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT; case WisMemoryTypeGPUUpload: return VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT - | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; + | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; default: return static_cast(0); } @@ -855,9 +855,9 @@ constexpr inline VkPipelineStageFlags2 VKConvert(WisBarrierSync value) noexcept } if (value & WisBarrierSyncDraw) { result |= VK_PIPELINE_STAGE_2_VERTEX_ATTRIBUTE_INPUT_BIT | VK_PIPELINE_STAGE_2_INDEX_INPUT_BIT - | VK_PIPELINE_STAGE_2_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT - | VK_PIPELINE_STAGE_2_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_2_LATE_FRAGMENT_TESTS_BIT - | VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT; + | VK_PIPELINE_STAGE_2_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT + | VK_PIPELINE_STAGE_2_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_2_LATE_FRAGMENT_TESTS_BIT + | VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT; } if (value & WisBarrierSyncIndexInput) { result |= VK_PIPELINE_STAGE_2_INDEX_INPUT_BIT; @@ -885,14 +885,14 @@ constexpr inline VkPipelineStageFlags2 VKConvert(WisBarrierSync value) noexcept } if (value & WisBarrierSyncResolve) { result |= VK_PIPELINE_STAGE_2_COPY_BIT | VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT - | VK_PIPELINE_STAGE_2_RESOLVE_BIT | VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT; + | VK_PIPELINE_STAGE_2_RESOLVE_BIT | VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT; } if (value & WisBarrierSyncExecuteIndirect) { result |= VK_PIPELINE_STAGE_2_DRAW_INDIRECT_BIT | VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT; } if (value & WisBarrierSyncAllShading) { result |= VK_PIPELINE_STAGE_2_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT - | VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT; + | VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT; } if (value & WisBarrierSyncNonPixelShading) { result |= VK_PIPELINE_STAGE_2_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT; diff --git a/src/include/wisdom/global/internal.hpp b/src/include/wisdom/global/internal.hpp index c1ac2ff2..29cca6a0 100644 --- a/src/include/wisdom/global/internal.hpp +++ b/src/include/wisdom/global/internal.hpp @@ -78,7 +78,9 @@ struct Implements { } /// @brief Destructor, calls the Deleter on the internal implementation - ~Implements() noexcept { Deleter{}(GetStorage()); } + ~Implements() noexcept { + Deleter{}(GetStorage()); + } public: /// @brief Get the immutable internal implementation @@ -97,7 +99,9 @@ struct Implements { /// @brief Get the storage pointer /// @return Pointer to the storage - [[nodiscard]] Storage* GetStorage() noexcept { return &_impl_storage; } + [[nodiscard]] Storage* GetStorage() noexcept { + return &_impl_storage; + } /// @brief Check if the handle holds a valid object /// @return true if the first 8 bytes of storage are non-zero @@ -108,7 +112,9 @@ struct Implements { } /// @brief Bool conversion, checks handle validity - explicit operator bool() const noexcept { return IsValid(); } + explicit operator bool() const noexcept { + return IsValid(); + } public: Storage _impl_storage; diff --git a/src/include/wisdom/vulkan/detail/vk_detail.hpp b/src/include/wisdom/vulkan/detail/vk_detail.hpp index 44e833c4..348e2094 100644 --- a/src/include/wisdom/vulkan/detail/vk_detail.hpp +++ b/src/include/wisdom/vulkan/detail/vk_detail.hpp @@ -43,8 +43,12 @@ struct VKScopeGuard { VKScopeGuard(const VKScopeGuard&) = delete; VKScopeGuard& operator=(const VKScopeGuard&) = delete; - HandleType* PutUnchecked() noexcept { return &handle; } - HandleType Release() noexcept { return std::exchange(handle, nullptr); } + HandleType* PutUnchecked() noexcept { + return &handle; + } + HandleType Release() noexcept { + return std::exchange(handle, nullptr); + } }; template @@ -143,7 +147,7 @@ struct VKDebugCallbackThunk { // Get device handle if possible uint64_t device = 0; for (auto&& obj : - wis::span{pCallbackData->pObjects, pCallbackData->objectCount}) { + wis::span {pCallbackData->pObjects, pCallbackData->objectCount}) { if (obj.objectType == VK_OBJECT_TYPE_DEVICE) { device = obj.objectHandle; break; @@ -269,8 +273,8 @@ struct VKDeviceHeader { // Destroy semaphores auto& last_family = queue_families[family_count - 1]; std::binary_semaphore* begin = reinterpret_cast( - reinterpret_cast(this) + sizeof(*this) - ); + reinterpret_cast(this) + sizeof(*this) + ); std::binary_semaphore* end = last_family.semaphore_offset + last_family.queue_count + begin; for (std::binary_semaphore* sem = begin; sem < end; ++sem) { sem->release(); @@ -291,7 +295,7 @@ struct VKDeviceHeader { return nullptr; // No valid family index for this queue type } return reinterpret_cast(reinterpret_cast(this) + sizeof(*this)) - + queue_families[type].semaphore_offset + queue_index; + + queue_families[type].semaphore_offset + queue_index; } }; @@ -324,11 +328,11 @@ struct VKSwapchainHeader { VkSurfaceKHR surface; // store surface handle for later use in presentation and swapchain recreation VkPhysicalDevice physical_device; // store physical device for later use in swapchain recreation PFN_vkGetPhysicalDeviceSurfaceCapabilities2KHR - vkGetPhysicalDeviceSurfaceCapabilities2KHR; // store function pointer for later use in swapchain recreation + vkGetPhysicalDeviceSurfaceCapabilities2KHR; // store function pointer for later use in swapchain recreation VkSwapchainCreateInfoKHR create_info; // store create info for later use in presentation and swapchain recreation VkSwapchainPresentScalingCreateInfoKHR - scaling_create_info; // store scaling create info for later use in presentation and swapchain recreation + scaling_create_info; // store scaling create info for later use in presentation and swapchain recreation VkPresentModeKHR modes[reasonable_mode_count]; uint8_t mode_count; @@ -337,29 +341,29 @@ struct VKSwapchainHeader { wis::span GetImageAvailableSemaphores() const noexcept { - return wis::span{reinterpret_cast(this + 1), create_info.minImageCount}; + return wis::span {reinterpret_cast(this + 1), create_info.minImageCount}; } wis::span GetRenderFinishedSemaphores() const noexcept { - return wis::span{ + return wis::span { reinterpret_cast(this + 1) + create_info.minImageCount, create_info.minImageCount }; } wis::span GetSemaphores() const noexcept { - return wis::span{ + return wis::span { reinterpret_cast(this + 1), create_info.minImageCount * 2 }; } wis::span GetSupportedPresentModes() const noexcept { - return wis::span{modes, mode_count}; + return wis::span {modes, mode_count}; } wis::span GetSupportedFormats() noexcept { - return wis::span{ + return wis::span { reinterpret_cast(this + 1) + create_info.minImageCount * 2, format_count }; @@ -396,24 +400,24 @@ struct alignas(void*) VKRootSignatureControlBlock { wis::span GetRootBindingOffsets() const noexcept { - return wis::span{reinterpret_cast(this + 1), root_parameter_count}; + return wis::span {reinterpret_cast(this + 1), root_parameter_count}; } wis::span GetRootBindingOffsets() noexcept { - return wis::span{reinterpret_cast(this + 1), root_parameter_count}; + return wis::span {reinterpret_cast(this + 1), root_parameter_count}; } wis::span GetMappings() noexcept { - return wis::span{ + return wis::span { reinterpret_cast(GetRootBindingOffsets().end()), mapping_count }; } wis::span GetMappings() const noexcept { - return wis::span{ + return wis::span { reinterpret_cast(GetRootBindingOffsets().end()), mapping_count }; @@ -622,8 +626,8 @@ inline void VKReleaseSwapchain(VkSwapchainKHR swap, VKSwapchainControlBlock* hea //---------------------------------------------------------------------------------------------------------------------- // Barrier helper constants constexpr static uint32_t vk_max_barrier_size = std::max( - {sizeof(VkBufferMemoryBarrier), sizeof(VkImageMemoryBarrier2), sizeof(VkMemoryBarrier2)} -); +{sizeof(VkBufferMemoryBarrier), sizeof(VkImageMemoryBarrier2), sizeof(VkMemoryBarrier2)} + ); constexpr static uint32_t vk_static_barrier_size = WIS_TRANSIENT_MAX_BARRIER_COUNT * vk_max_barrier_size; template @@ -646,8 +650,8 @@ inline std::array, 3> VKAllocateBarriers( { std::array, 3> spans; std::size_t needed_size = barriers.buffer_barrier_count * sizeof(VkBufferMemoryBarrier2) - + barriers.texture_barrier_count * sizeof(VkImageMemoryBarrier2) - + barriers.global_barrier_count * sizeof(VkMemoryBarrier2); + + barriers.texture_barrier_count * sizeof(VkImageMemoryBarrier2) + + barriers.global_barrier_count * sizeof(VkMemoryBarrier2); if (needed_size <= vk_static_barrier_size) { spans[0] = {local_scratch, barriers.buffer_barrier_count * sizeof(VkBufferMemoryBarrier2)}; @@ -731,7 +735,7 @@ inline void VKInsertBarriers(const Impl& impl, const WisVKBarrierGroup* barriers return; } - uint8_t local_scratch[vk_static_barrier_size]{}; + uint8_t local_scratch[vk_static_barrier_size] {}; auto [buffer_span, texture_span, global_span] = VKAllocateBarriers(impl, local_scratch, *barriers); @@ -783,8 +787,8 @@ inline void VKInsertBarriers(const Impl& impl, const WisVKBarrierGroup* barriers if (src.queue_type_before != src.queue_type_after) { if (impl.maintenance9 - && (impl.queue_indices[src.queue_type_before].compatible_to_families - & (1 << impl.queue_indices[src.queue_type_after].family_index))) { + && (impl.queue_indices[src.queue_type_before].compatible_to_families + & (1 << impl.queue_indices[src.queue_type_after].family_index))) { if (src.queue_type_before == impl.queue_type) { real_texture_barrier_count--; continue; diff --git a/src/include/wisdom/vulkan/detail/vk_ext1.hpp b/src/include/wisdom/vulkan/detail/vk_ext1.hpp index 443490af..fcded411 100644 --- a/src/include/wisdom/vulkan/detail/vk_ext1.hpp +++ b/src/include/wisdom/vulkan/detail/vk_ext1.hpp @@ -165,33 +165,33 @@ struct DeviceExtension1 : VKDeviceExtensionImpl { if (features.descriptor_heap) { // Descriptor heap properties auto& descriptor_heap_properties = *collector.GetEnabledPropertyStruct< - VkPhysicalDeviceDescriptorHeapPropertiesEXT>( - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_HEAP_PROPERTIES_EXT - ); + VkPhysicalDeviceDescriptorHeapPropertiesEXT>( + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_HEAP_PROPERTIES_EXT + ); // A lot of space is going to be wasted, but the usage will be simpler and more efficient if we use the same // size for both resource and sampler descriptors, so we take the max of the two alignments as the // descriptor size features.resource_desc_size = static_cast(std::max( - descriptor_heap_properties.imageDescriptorAlignment, - descriptor_heap_properties.bufferDescriptorAlignment - )); + descriptor_heap_properties.imageDescriptorAlignment, + descriptor_heap_properties.bufferDescriptorAlignment + )); features.sampler_desc_size = static_cast(descriptor_heap_properties.samplerDescriptorAlignment); features.max_root_space = static_cast(descriptor_heap_properties.maxPushDataSize); features.descriptor_heap_reserved_size = wis::aligned_size( - static_cast(descriptor_heap_properties.minResourceHeapReservedRange), - features.resource_desc_size - ); + static_cast(descriptor_heap_properties.minResourceHeapReservedRange), + features.resource_desc_size + ); features.sampler_heap_reserved_size = wis::aligned_size( - static_cast(descriptor_heap_properties.minSamplerHeapReservedRange), - features.sampler_desc_size - ); + static_cast(descriptor_heap_properties.minSamplerHeapReservedRange), + features.sampler_desc_size + ); features.sampler_heap_reserved_size_with_embedded = wis::aligned_size( - static_cast(descriptor_heap_properties.minSamplerHeapReservedRangeWithEmbedded), - features.sampler_desc_size - ); + static_cast(descriptor_heap_properties.minSamplerHeapReservedRangeWithEmbedded), + features.sampler_desc_size + ); features.descriptor_heap_alignment = static_cast(descriptor_heap_properties.resourceHeapAlignment - ); + ); features.sampler_heap_alignment = static_cast(descriptor_heap_properties.samplerHeapAlignment); features.max_descriptor_heap_size = descriptor_heap_properties.maxResourceHeapSize; features.max_sampler_heap_size = descriptor_heap_properties.maxSamplerHeapSize; @@ -199,11 +199,11 @@ struct DeviceExtension1 : VKDeviceExtensionImpl { // Get Device properties auto& device_properties = *collector.GetEnabledPropertyStruct( - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2 - ); + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2 + ); features.max_vertex_attributes = static_cast( - device_properties.properties.limits.maxVertexInputAttributes - ); + device_properties.properties.limits.maxVertexInputAttributes + ); features.max_vertex_bindings = static_cast(device_properties.properties.limits.maxVertexInputBindings); features.multiple_viewports = device_properties.properties.limits.maxViewports > 1 ? 1 : 0; diff --git a/src/include/wisdom/vulkan/vk_command_list.cpp b/src/include/wisdom/vulkan/vk_command_list.cpp index 149a867c..9b9df387 100644 --- a/src/include/wisdom/vulkan/vk_command_list.cpp +++ b/src/include/wisdom/vulkan/vk_command_list.cpp @@ -60,9 +60,9 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListSetDescriptorHeaps( if (resource_heap) { auto& res_heap = wis::from_handle_ref(resource_heap); VkDeviceSize reserved_resource_descriptor_size = static_cast(res_heap.reserved_size) - * res_heap.descriptor_size; + * res_heap.descriptor_size; VkDeviceSize total_resource_heap_size = static_cast(res_heap.heap_size) * res_heap.descriptor_size - + reserved_resource_descriptor_size; + + reserved_resource_descriptor_size; VkBindHeapInfoEXT bind_resource_info{ .sType = VK_STRUCTURE_TYPE_BIND_HEAP_INFO_EXT, .pNext = nullptr, @@ -76,9 +76,9 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListSetDescriptorHeaps( if (sampler_heap) { auto& samp_heap = wis::from_handle_ref(sampler_heap); VkDeviceSize reserved_sampler_descriptor_size = static_cast(samp_heap.reserved_size) - * samp_heap.descriptor_size; + * samp_heap.descriptor_size; VkDeviceSize total_sampler_heap_size = static_cast(samp_heap.heap_size) * samp_heap.descriptor_size - + reserved_sampler_descriptor_size; + + reserved_sampler_descriptor_size; VkBindHeapInfoEXT bind_sampler_info{ .sType = VK_STRUCTURE_TYPE_BIND_HEAP_INFO_EXT, .pNext = nullptr, @@ -204,7 +204,7 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListSetViewports( }; } impl.command_list_table - ->vkCmdSetViewportWithCount(impl.command_buffer, static_cast(max_count), vk_viewports); + ->vkCmdSetViewportWithCount(impl.command_buffer, static_cast(max_count), vk_viewports); } //---------------------------------------------------------------------------------------------------------------------- @@ -240,7 +240,7 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListSetDepthBias( { auto& impl = wis::from_handle_ref(self); impl.command_list_table - ->vkCmdSetDepthBias(impl.command_buffer, depth_bias, depth_bias_clamp, slope_scaled_depth_bias); + ->vkCmdSetDepthBias(impl.command_buffer, depth_bias, depth_bias_clamp, slope_scaled_depth_bias); } //---------------------------------------------------------------------------------------------------------------------- @@ -428,7 +428,7 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListDrawIndexed( { auto& impl = wis::from_handle_ref(self); impl.command_list_table - ->vkCmdDrawIndexed(impl.command_buffer, index_count, instance_count, start_index, base_vertex, start_instance); + ->vkCmdDrawIndexed(impl.command_buffer, index_count, instance_count, start_index, base_vertex, start_instance); } //---------------------------------------------------------------------------------------------------------------------- @@ -469,8 +469,8 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListCopyBufferToTexture( while (region_offset < region_count) { uint32_t current_region_count = static_cast( - std::min(region_count - region_offset, static_cast(wis::MaxCopyRegions)) - ); + std::min(region_count - region_offset, static_cast(wis::MaxCopyRegions)) + ); for (size_t i = 0; i < current_region_count; ++i) { const auto& region = regions[region_offset + i]; @@ -487,8 +487,8 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListCopyBufferToTexture( } if (aspect_mask == 0) { aspect_mask = (region.texture_region.flags & WisBarrierFlagsPlanarImage) - ? (VK_IMAGE_ASPECT_PLANE_0_BIT << subresource.plane_slice) - : VK_IMAGE_ASPECT_COLOR_BIT; + ? (VK_IMAGE_ASPECT_PLANE_0_BIT << subresource.plane_slice) + : VK_IMAGE_ASPECT_COLOR_BIT; } convert_regions[i] = { @@ -496,18 +496,18 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListCopyBufferToTexture( .bufferRowLength = region.buffer_row_length, .bufferImageHeight = region.buffer_image_height, .imageSubresource = - { - .aspectMask = aspect_mask, - .mipLevel = subresource.mip_level, - .baseArrayLayer = subresource.array_layer, - .layerCount = 1, - }, + { + .aspectMask = aspect_mask, + .mipLevel = subresource.mip_level, + .baseArrayLayer = subresource.array_layer, + .layerCount = 1, + }, .imageOffset = - { - .x = static_cast(box.x), - .y = static_cast(box.y), - .z = static_cast(box.z), - }, + { + .x = static_cast(box.x), + .y = static_cast(box.y), + .z = static_cast(box.z), + }, .imageExtent = {.width = box.width, .height = box.height, .depth = box.depth}, }; } @@ -540,8 +540,8 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListCopyTextureToBuffer( while (region_offset < region_count) { uint32_t current_region_count = static_cast( - std::min(region_count - region_offset, static_cast(wis::MaxCopyRegions)) - ); + std::min(region_count - region_offset, static_cast(wis::MaxCopyRegions)) + ); for (size_t i = 0; i < current_region_count; ++i) { const auto& region = regions[region_offset + i]; @@ -558,8 +558,8 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListCopyTextureToBuffer( } if (aspect_mask == 0) { aspect_mask = (region.texture_region.flags & WisBarrierFlagsPlanarImage) - ? (VK_IMAGE_ASPECT_PLANE_0_BIT << subresource.plane_slice) - : VK_IMAGE_ASPECT_COLOR_BIT; + ? (VK_IMAGE_ASPECT_PLANE_0_BIT << subresource.plane_slice) + : VK_IMAGE_ASPECT_COLOR_BIT; } convert_regions[i] = { @@ -567,18 +567,18 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListCopyTextureToBuffer( .bufferRowLength = region.buffer_row_length, .bufferImageHeight = region.buffer_image_height, .imageSubresource = - { - .aspectMask = aspect_mask, - .mipLevel = subresource.mip_level, - .baseArrayLayer = subresource.array_layer, - .layerCount = 1, - }, + { + .aspectMask = aspect_mask, + .mipLevel = subresource.mip_level, + .baseArrayLayer = subresource.array_layer, + .layerCount = 1, + }, .imageOffset = - { - .x = static_cast(box.x), - .y = static_cast(box.y), - .z = static_cast(box.z), - }, + { + .x = static_cast(box.x), + .y = static_cast(box.y), + .z = static_cast(box.z), + }, .imageExtent = {.width = box.width, .height = box.height, .depth = box.depth}, }; } @@ -611,8 +611,8 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListCopyTexture( while (region_offset < region_count) { uint32_t current_region_count = static_cast( - std::min(region_count - region_offset, static_cast(wis::MaxCopyRegions)) - ); + std::min(region_count - region_offset, static_cast(wis::MaxCopyRegions)) + ); for (size_t i = 0; i < current_region_count; ++i) { const auto& region = regions[region_offset + i]; @@ -630,8 +630,8 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListCopyTexture( } if (src_aspect_mask == 0) { src_aspect_mask = (region.src_region.flags & WisBarrierFlagsPlanarImage) - ? (VK_IMAGE_ASPECT_PLANE_0_BIT << src_subresource.plane_slice) - : VK_IMAGE_ASPECT_COLOR_BIT; + ? (VK_IMAGE_ASPECT_PLANE_0_BIT << src_subresource.plane_slice) + : VK_IMAGE_ASPECT_COLOR_BIT; } VkImageAspectFlags dst_aspect_mask = 0; @@ -643,37 +643,37 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListCopyTexture( } if (dst_aspect_mask == 0) { dst_aspect_mask = (region.dst_region.flags & WisBarrierFlagsPlanarImage) - ? (VK_IMAGE_ASPECT_PLANE_0_BIT << dst_subresource.plane_slice) - : VK_IMAGE_ASPECT_COLOR_BIT; + ? (VK_IMAGE_ASPECT_PLANE_0_BIT << dst_subresource.plane_slice) + : VK_IMAGE_ASPECT_COLOR_BIT; } convert_regions[i] = { .srcSubresource = - { - .aspectMask = src_aspect_mask, - .mipLevel = src_subresource.mip_level, - .baseArrayLayer = src_subresource.array_layer, - .layerCount = 1, - }, + { + .aspectMask = src_aspect_mask, + .mipLevel = src_subresource.mip_level, + .baseArrayLayer = src_subresource.array_layer, + .layerCount = 1, + }, .srcOffset = - { - .x = static_cast(src_box.x), - .y = static_cast(src_box.y), - .z = static_cast(src_box.z), - }, + { + .x = static_cast(src_box.x), + .y = static_cast(src_box.y), + .z = static_cast(src_box.z), + }, .dstSubresource = - { - .aspectMask = dst_aspect_mask, - .mipLevel = dst_subresource.mip_level, - .baseArrayLayer = dst_subresource.array_layer, - .layerCount = 1, - }, + { + .aspectMask = dst_aspect_mask, + .mipLevel = dst_subresource.mip_level, + .baseArrayLayer = dst_subresource.array_layer, + .layerCount = 1, + }, .dstOffset = - { - .x = static_cast(dst_box.x), - .y = static_cast(dst_box.y), - .z = static_cast(dst_box.z), - }, + { + .x = static_cast(dst_box.x), + .y = static_cast(dst_box.y), + .z = static_cast(dst_box.z), + }, .extent = {.width = src_box.width, .height = src_box.height, .depth = src_box.depth}, }; } @@ -717,7 +717,7 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListSetVertexBuffers( } impl.command_list_table - ->vkCmdBindVertexBuffers2(impl.command_buffer, start_slot, count, buffers_vk, offsets, sizes, strides); + ->vkCmdBindVertexBuffers2(impl.command_buffer, start_slot, count, buffers_vk, offsets, sizes, strides); } //---------------------------------------------------------------------------------------------------------------------- @@ -738,17 +738,17 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListSetVertexBuffers2( .pNext = nullptr, .setStride = VK_TRUE, .addressRange = - { - .address = buffers[i].buffer, - .size = buffers[i].size, - .stride = buffers[i].stride, - }, + { + .address = buffers[i].buffer, + .size = buffers[i].size, + .stride = buffers[i].stride, + }, .addressFlags = 0, // reserved for future use }; } impl.command_list_table - ->vkCmdBindVertexBuffers3KHR(impl.command_buffer, start_slot, count, bind_vertex_buffer_infos); + ->vkCmdBindVertexBuffers3KHR(impl.command_buffer, start_slot, count, bind_vertex_buffer_infos); } //---------------------------------------------------------------------------------------------------------------------- @@ -781,10 +781,10 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListSetIndexBuffer2( .sType = VK_STRUCTURE_TYPE_BIND_INDEX_BUFFER_3_INFO_KHR, .pNext = nullptr, .addressRange = - { - .address = buffer->buffer, - .size = buffer->size, - }, + { + .address = buffer->buffer, + .size = buffer->size, + }, .addressFlags = 0, // reserved for future use .indexType = wis::detail::VKConvert(index_type), }; diff --git a/src/include/wisdom/vulkan/vk_descriptor_heap.cpp b/src/include/wisdom/vulkan/vk_descriptor_heap.cpp index ca54117a..1a2b5e78 100644 --- a/src/include/wisdom/vulkan/vk_descriptor_heap.cpp +++ b/src/include/wisdom/vulkan/vk_descriptor_heap.cpp @@ -12,12 +12,12 @@ namespace wis::detail { inline VkImageAspectFlags VKGetAspectFlags(const WisTextureBinding& binding) noexcept { if ((binding.flags & WisTextureBindingFlagsStencilView) - && (binding.format == WisDataFormatD24UnormS8Uint || binding.format == WisDataFormatD32FloatS8Uint)) { + && (binding.format == WisDataFormatD24UnormS8Uint || binding.format == WisDataFormatD32FloatS8Uint)) { return VK_IMAGE_ASPECT_STENCIL_BIT; } if ((binding.flags & WisTextureBindingFlagsDepthView) && (binding.format == WisDataFormatD32FloatS8Uint || binding.format == WisDataFormatD24UnormS8Uint) - || (binding.format == WisDataFormatD16Unorm || binding.format == WisDataFormatD32Float)) { + || (binding.format == WisDataFormatD16Unorm || binding.format == WisDataFormatD32Float)) { return VK_IMAGE_ASPECT_DEPTH_BIT; } if (binding.range.plane_slice) { @@ -34,12 +34,12 @@ inline VkImageViewCreateInfo VKGetSRVDesc(const WisTextureBinding& binding) noex .flags = 0, .format = wis::detail::VKConvert(binding.format), .components = - { - .r = wis::detail::VKConvert(binding.component_mapping.r), - .g = wis::detail::VKConvert(binding.component_mapping.g), - .b = wis::detail::VKConvert(binding.component_mapping.b), - .a = wis::detail::VKConvert(binding.component_mapping.a), - }, + { + .r = wis::detail::VKConvert(binding.component_mapping.r), + .g = wis::detail::VKConvert(binding.component_mapping.g), + .b = wis::detail::VKConvert(binding.component_mapping.b), + .a = wis::detail::VKConvert(binding.component_mapping.a), + }, }; auto aspect_flags = VKGetAspectFlags(binding); @@ -98,7 +98,7 @@ inline VkImageViewCreateInfo VKGetSRVDesc(const WisTextureBinding& binding) noex case WisTextureLayoutTexture2DMS: srv_desc.viewType = VK_IMAGE_VIEW_TYPE_2D; srv_desc.subresourceRange = - {.aspectMask = aspect_flags, .baseMipLevel = 0, .levelCount = 1, .baseArrayLayer = 0, .layerCount = 1}; + {.aspectMask = aspect_flags, .baseMipLevel = 0, .levelCount = 1, .baseArrayLayer = 0, .layerCount = 1}; break; case WisTextureLayoutTexture2DMSArray: srv_desc.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY; @@ -343,7 +343,7 @@ WIS_EXTERN_C WISDOM_API void wisVKDestroyViewHeap(WisVKViewHeap* self) for (uint32_t i = 0; i < impl.capacity; ++i) { if (impl.view_heap[i].view != VK_NULL_HANDLE) { impl.device_header->header.device_table - .vkDestroyImageView(impl.device_header->header.device, impl.view_heap[i].view, nullptr); + .vkDestroyImageView(impl.device_header->header.device, impl.view_heap[i].view, nullptr); } } @@ -388,7 +388,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDescriptorHeapWriteConstantBuffer( VkResult result = table.vkWriteResourceDescriptorsEXT(heap.device, 1, &resource_desc, &host_range); if (!wis::detail::succeeded(result)) { return wis::detail:: - make_result(result); + make_result(result); } return wis::detail::vk_success; } @@ -430,7 +430,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDescriptorHeapWriteStructuredBuffer( VkResult result = table.vkWriteResourceDescriptorsEXT(heap.device, 1, &resource_desc, &host_range); if (!wis::detail::succeeded(result)) { return wis::detail:: - make_result(result); + make_result(result); } return wis::detail::vk_success; } @@ -464,7 +464,7 @@ wisVKDescriptorHeapWriteSampler(const WisVKDescriptorHeap* self, const WisSample .sType = VK_STRUCTURE_TYPE_SAMPLER_REDUCTION_MODE_CREATE_INFO, .pNext = nullptr, // Custom border? .reductionMode = sampler->comparison_op != WisCompareOpNever ? VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE - : wis::detail::VKConvert(sampler->reduction_mode) + : wis::detail::VKConvert(sampler->reduction_mode) }; VkSamplerCreateInfo sampler_info{ .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, @@ -489,7 +489,7 @@ wisVKDescriptorHeapWriteSampler(const WisVKDescriptorHeap* self, const WisSample VkResult result = table.vkWriteSamplerDescriptorsEXT(heap.device, 1, &sampler_info, &host_range); if (!wis::detail::succeeded(result)) { return wis::detail:: - make_result(result); + make_result(result); } return wis::detail::vk_success; } @@ -534,7 +534,7 @@ WISDOM_API WisResult wisVKDescriptorHeapWriteTexture( VkResult result = table.vkWriteResourceDescriptorsEXT(heap.device, 1, &resource_desc, &host_range); if (!wis::detail::succeeded(result)) { return wis::detail:: - make_result(result); + make_result(result); } return wis::detail::vk_success; } @@ -573,7 +573,7 @@ WISDOM_API WisResult wisVKDescriptorHeapWriteRWTexture( VkResult result = table.vkWriteResourceDescriptorsEXT(heap.device, 1, &resource_desc, &host_range); if (!wis::detail::succeeded(result)) { return wis::detail:: - make_result(result); + make_result(result); } return wis::detail::vk_success; } @@ -602,7 +602,7 @@ wisVKDescriptorHeapWriteAccelerationStructure(const WisVKDescriptorHeap* self, u VkResult result = table.vkWriteResourceDescriptorsEXT(heap.device, 1, &resource_desc, &host_range); if (!wis::detail::succeeded(result)) { return wis::detail:: - make_result(result); + make_result(result); } return wis::detail::vk_success; } @@ -688,13 +688,13 @@ WIS_EXTERN_C WISDOM_API void wisVKViewHeapCopyViews( return; // Invalid range, do nothing } auto* src_views = reinterpret_cast(std::bit_cast(src_ptr)) - + src_index; + + src_index; auto* dst_views = heap.view_heap + dst_index; for (uint32_t i = 0; i < count; ++i) { // Destroy existing view at destination if it's not null if (dst_views[i].view != VK_NULL_HANDLE) { heap.device_header->header.device_table - .vkDestroyImageView(heap.device_header->header.device, dst_views[i].view, nullptr); + .vkDestroyImageView(heap.device_header->header.device, dst_views[i].view, nullptr); } dst_views[i] = src_views[i]; } diff --git a/src/include/wisdom/vulkan/vk_device.cpp b/src/include/wisdom/vulkan/vk_device.cpp index b9474ace..42e41aec 100644 --- a/src/include/wisdom/vulkan/vk_device.cpp +++ b/src/include/wisdom/vulkan/vk_device.cpp @@ -29,7 +29,7 @@ constexpr VkSpirvResourceTypeFlagsEXT GetResourceTypeFlags(const WisDescriptorTy return VK_SPIRV_RESOURCE_TYPE_READ_WRITE_STORAGE_BUFFER_BIT_EXT; case WisDescriptorTypeBuffer: return VK_SPIRV_RESOURCE_TYPE_READ_WRITE_STORAGE_BUFFER_BIT_EXT - | VK_SPIRV_RESOURCE_TYPE_READ_ONLY_STORAGE_BUFFER_BIT_EXT; + | VK_SPIRV_RESOURCE_TYPE_READ_ONLY_STORAGE_BUFFER_BIT_EXT; case WisDescriptorTypeAccelerationStructure: return VK_SPIRV_RESOURCE_TYPE_ACCELERATION_STRUCTURE_BIT_EXT; default: @@ -38,7 +38,7 @@ constexpr VkSpirvResourceTypeFlagsEXT GetResourceTypeFlags(const WisDescriptorTy } inline std::array GetMapCountPerShaderType(const WisRootSignatureDesc& desc -) noexcept + ) noexcept { std::array counts{}; // 1. Push constants @@ -128,16 +128,16 @@ wisVKDeviceCreateCommandQueue(const WisVKDevice* self, WisCommandQueueType type, using QueueTypeUnderlying = std::underlying_type_t; if (static_cast(type) < 0 || static_cast(type) >= WisCommandQueueTypeCount) { return wis::detail::make_result( - VK_ERROR_INITIALIZATION_FAILED - ); + VK_ERROR_INITIALIZATION_FAILED + ); } // Get queue family index based on type uint8_t queue_family_index = device.device_header->header.queue_residency[static_cast(type)]; if (queue_family_index == wis::detail::VKQueueFamilyProperties::invalid_family_index) { return wis::detail::make_result< - wis::detail::Func(), - "No suitable queue family found for the requested queue type">(VK_ERROR_FEATURE_NOT_PRESENT); + wis::detail::Func(), + "No suitable queue family found for the requested queue type">(VK_ERROR_FEATURE_NOT_PRESENT); } auto& queue_family = device.device_header->header.queue_families[queue_family_index]; @@ -176,24 +176,24 @@ wisVKDeviceCreateCommandAllocator(const WisVKDevice* self, WisCommandQueueType t using QueueTypeUnderlying = std::underlying_type_t; if (static_cast(type) < 0 || static_cast(type) >= WisCommandQueueTypeCount) { return wis::detail::make_result( - VK_ERROR_INITIALIZATION_FAILED - ); + VK_ERROR_INITIALIZATION_FAILED + ); } // Get queue family index based on type uint8_t queue_family_index = device.device_header->header.queue_residency[static_cast(type)]; if (queue_family_index == wis::detail::VKQueueFamilyProperties::invalid_family_index) { return wis::detail::make_result< - wis::detail::Func(), - "No suitable queue family found for the requested queue type">(VK_ERROR_FEATURE_NOT_PRESENT); + wis::detail::Func(), + "No suitable queue family found for the requested queue type">(VK_ERROR_FEATURE_NOT_PRESENT); } std::unique_ptr - pool_control_block = wis::make_unique(); + pool_control_block = wis::make_unique(); if (!pool_control_block) { return wis::detail::make_result< - wis::detail::Func(), - "Failed to allocate memory for command pool control block">(VK_ERROR_OUT_OF_HOST_MEMORY); + wis::detail::Func(), + "Failed to allocate memory for command pool control block">(VK_ERROR_OUT_OF_HOST_MEMORY); } uint8_t queue_family = device.device_header->header.queue_families[queue_family_index].family_index; @@ -286,8 +286,8 @@ wisVKDeviceCreateDescriptorHeap(const WisVKDevice* self, const WisDescriptorHeap // 0. If heap is supported if (!features.descriptor_heap) { return wis::detail::make_result< - wis::detail::Func(), - "Descriptor heaps are not supported by this Vulkan device">(VK_ERROR_FEATURE_NOT_PRESENT); + wis::detail::Func(), + "Descriptor heaps are not supported by this Vulkan device">(VK_ERROR_FEATURE_NOT_PRESENT); } // 1. Calculate descriptor memory requirements based on desc @@ -296,32 +296,32 @@ wisVKDeviceCreateDescriptorHeap(const WisVKDevice* self, const WisDescriptorHeap bool embedded_samplers = !(desc->flags & WisDescriptorHeapFlagsDisallowEmbeddedSamplers); std::size_t heap_alignment = is_shader_heap ? is_sampler_heap ? features.sampler_heap_alignment - : features.descriptor_heap_alignment - : __STDCPP_DEFAULT_NEW_ALIGNMENT__; + : features.descriptor_heap_alignment + : __STDCPP_DEFAULT_NEW_ALIGNMENT__; std::size_t descriptor_size = is_sampler_heap ? features.sampler_desc_size : features.resource_desc_size; std::size_t reserved_size = is_shader_heap ? is_sampler_heap ? embedded_samplers - ? features.sampler_heap_reserved_size_with_embedded - : features.sampler_heap_reserved_size - : features.descriptor_heap_reserved_size - : 0; + ? features.sampler_heap_reserved_size_with_embedded + : features.sampler_heap_reserved_size + : features.descriptor_heap_reserved_size + : 0; std::size_t max_heap_size = is_shader_heap - ? is_sampler_heap ? features.max_sampler_heap_size : features.max_descriptor_heap_size - : std::numeric_limits::max(); + ? is_sampler_heap ? features.max_sampler_heap_size : features.max_descriptor_heap_size + : std::numeric_limits::max(); std::size_t required_size = wis::aligned_size( - desc->descriptor_count * descriptor_size + reserved_size, - heap_alignment - ); + desc->descriptor_count * descriptor_size + reserved_size, + heap_alignment + ); if (is_shader_heap && required_size > max_heap_size) { return wis::detail::make_result< - wis::detail::Func(), - "Requested descriptor heap size exceeds the maximum supported by this Vulkan device">( - VK_ERROR_INITIALIZATION_FAILED - ); + wis::detail::Func(), + "Requested descriptor heap size exceeds the maximum supported by this Vulkan device">( + VK_ERROR_INITIALIZATION_FAILED + ); } if (!is_shader_heap) { @@ -329,8 +329,8 @@ wisVKDeviceCreateDescriptorHeap(const WisVKDevice* self, const WisDescriptorHeap VkBuffer buffer = reinterpret_cast(std::malloc(required_size)); if (!buffer) { return wis::detail::make_result< - wis::detail::Func(), - "Failed to allocate memory for non-shader visible descriptor heap">(VK_ERROR_OUT_OF_HOST_MEMORY); + wis::detail::Func(), + "Failed to allocate memory for non-shader visible descriptor heap">(VK_ERROR_OUT_OF_HOST_MEMORY); } // Fill descriptor heap impl @@ -360,7 +360,7 @@ wisVKDeviceCreateDescriptorHeap(const WisVKDevice* self, const WisDescriptorHeap }; VmaAllocationCreateInfo alloc_info{ .flags = VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT - | VMA_ALLOCATION_CREATE_MAPPED_BIT, + | VMA_ALLOCATION_CREATE_MAPPED_BIT, .usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE, .requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, .preferredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, @@ -370,18 +370,18 @@ wisVKDeviceCreateDescriptorHeap(const WisVKDevice* self, const WisDescriptorHeap VmaAllocation allocation = VK_NULL_HANDLE; VmaAllocationInfo alloc_info_out{}; VkResult vr = vmaCreateBufferWithAlignment( - header.allocator, - &buffer_info, - &alloc_info, - heap_alignment, - &buffer, - &allocation, - &alloc_info_out - ); + header.allocator, + &buffer_info, + &alloc_info, + heap_alignment, + &buffer, + &allocation, + &alloc_info_out + ); if (!wis::detail::succeeded(vr)) { return wis::detail:: - make_result(vr); + make_result(vr); } // Get GPU address of the buffer @@ -417,11 +417,11 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateViewHeap( { (void)flags; auto& device = *wis::from_handle(self); - wis::detail::VKRenderTargetView* view_heap = new (std::nothrow) wis::detail::VKRenderTargetView[capacity]{}; + wis::detail::VKRenderTargetView* view_heap = new (std::nothrow) wis::detail::VKRenderTargetView[capacity] {}; if (!view_heap) { return wis::detail::make_result( - VK_ERROR_OUT_OF_HOST_MEMORY - ); + VK_ERROR_OUT_OF_HOST_MEMORY + ); } new (heap) wis::impl::VKViewHeapImpl{ @@ -443,8 +443,8 @@ wisVKDeviceCreateRootSignature(const WisVKDevice* self, const WisRootSignatureDe if (!features.descriptor_heap) { return wis::detail::make_result< - wis::detail::Func(), - "Descriptor heaps are not supported by this Vulkan device">(VK_ERROR_FEATURE_NOT_PRESENT); + wis::detail::Func(), + "Descriptor heaps are not supported by this Vulkan device">(VK_ERROR_FEATURE_NOT_PRESENT); } // Use only 64 DWORDs, same as DX12 @@ -454,8 +454,8 @@ wisVKDeviceCreateRootSignature(const WisVKDevice* self, const WisRootSignatureDe const auto& push_constant = desc->push_constants[i]; if (push_constant.size_bytes % 4 != 0) { return wis::detail::make_result( - VK_ERROR_INITIALIZATION_FAILED - ); + VK_ERROR_INITIALIZATION_FAILED + ); } push_constant_size += push_constant.size_bytes; } @@ -463,35 +463,35 @@ wisVKDeviceCreateRootSignature(const WisVKDevice* self, const WisRootSignatureDe // 1. Count the number of root parameters needed std::size_t total_dwords_needed = push_constant_size + desc->push_descriptor_count * 2 - + desc->descriptor_table_count; + + desc->descriptor_table_count; if (total_dwords_needed > max_root_parameters) { return wis::detail::make_result< - wis::detail::Func(), - "Root signature requires more than 64 DWORDs, which is not supported by this implementation">( - VK_ERROR_INITIALIZATION_FAILED - ); + wis::detail::Func(), + "Root signature requires more than 64 DWORDs, which is not supported by this implementation">( + VK_ERROR_INITIALIZATION_FAILED + ); } // 2. Count the number of VkDescriptorSetAndBindingMappingEXT structures // Hard part is to pack the tables into a contiguous arrays for each shader type uint32_t total_table_count = 0; std::array table_counts_per_shader = wis::detail::GetMapCountPerShaderType(*desc - ); + ); std::array - local_offsets_per_shader = wis::detail::GetMappingOffsetPerShaderType( - table_counts_per_shader, - total_table_count - ); + local_offsets_per_shader = wis::detail::GetMappingOffsetPerShaderType( + table_counts_per_shader, + total_table_count + ); std::size_t root_param_count = desc->push_constant_count + desc->push_descriptor_count - + desc->descriptor_table_count; + + desc->descriptor_table_count; std::size_t static_sampler_count = 0; // allocate root signature table std::size_t root_sig_size = sizeof(wis::detail::VKRootSignatureControlBlock) - + wis::aligned_size(root_param_count, 2u) * sizeof(uint32_t) - + // Root parameter binding indices, aligned to 8 bytes + + wis::aligned_size(root_param_count, 2u) * sizeof(uint32_t) + + // Root parameter binding indices, aligned to 8 bytes total_table_count * sizeof(VkDescriptorSetAndBindingMappingEXT); std::unique_ptr root_sig_control_block{ @@ -513,14 +513,14 @@ wisVKDeviceCreateRootSignature(const WisVKDevice* self, const WisRootSignatureDe } rootsig_header->shader_mapping_offset[i] = local_offsets_per_shader[i].offset - - (local_offsets_per_shader[i].even ? 0 : table_counts_per_shader[0] - ); // If even, "all" maps are after + - (local_offsets_per_shader[i].even ? 0 : table_counts_per_shader[0] + ); // If even, "all" maps are after // this stage, if odd, "all" maps // are before this stage rootsig_header->shader_mapping_sizes[i] = table_counts_per_shader[i] - + (local_offsets_per_shader[i].even ? 0 : table_counts_per_shader[0] - ); // If even, this stage maps + "all" + + (local_offsets_per_shader[i].even ? 0 : table_counts_per_shader[0] + ); // If even, this stage maps + "all" // maps, if odd, only this stage maps if (!all_offset) { @@ -586,16 +586,16 @@ wisVKDeviceCreateRootSignature(const WisVKDevice* self, const WisRootSignatureDe uint32_t local_count = entry.count; uint32_t local_offset = heap_byte_offset; uint32_t heap_stride = entry.type == WisDescriptorTypeSampler ? features.sampler_desc_size - : features.resource_desc_size; + : features.resource_desc_size; // Check for unbounded array if (entry.count == std::numeric_limits::max()) { if (j != src.entry_count - 1) { return wis::detail::make_result< - wis::detail::Func(), - "Unbounded array descriptor table entry must be the last entry in the table">( - VK_ERROR_INITIALIZATION_FAILED - ); + wis::detail::Func(), + "Unbounded array descriptor table entry must be the last entry in the table">( + VK_ERROR_INITIALIZATION_FAILED + ); } local_count = 1; } @@ -607,20 +607,22 @@ wisVKDeviceCreateRootSignature(const WisVKDevice* self, const WisRootSignatureDe heap_byte_offset = local_offset + local_count * heap_stride; auto& mapping = mappings[local_offsets_per_shader[visibility].offset++] = - {.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_AND_BINDING_MAPPING_EXT, - .pNext = nullptr, - .descriptorSet = entry.bind_space, - .firstBinding = entry.bind_register, - .bindingCount = local_count, - .resourceMask = wis::detail::GetResourceTypeFlags(entry.type), - .source = VK_DESCRIPTOR_MAPPING_SOURCE_HEAP_WITH_PUSH_INDEX_EXT, - .sourceData = - {.pushIndex = { - .heapOffset = local_offset, - .pushOffset = push_address_offset, - .heapIndexStride = 1, - .heapArrayStride = heap_stride, - }}}; + { .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_AND_BINDING_MAPPING_EXT, + .pNext = nullptr, + .descriptorSet = entry.bind_space, + .firstBinding = entry.bind_register, + .bindingCount = local_count, + .resourceMask = wis::detail::GetResourceTypeFlags(entry.type), + .source = VK_DESCRIPTOR_MAPPING_SOURCE_HEAP_WITH_PUSH_INDEX_EXT, + .sourceData = + { .pushIndex = { + .heapOffset = local_offset, + .pushOffset = push_address_offset, + .heapIndexStride = 1, + .heapArrayStride = heap_stride, + } + } + }; } root_param_offsets[root_param_index++] = push_address_offset; @@ -674,14 +676,15 @@ WIS_EXTERN_C WISDOM_API void wisVKDeviceQueryProperties(const WisVKDevice* self, auto& family_index = header.queue_residency[i]; bool supported = family_index != wis::detail::VKQueueFamilyProperties::invalid_family_index; WisCommandQueuePriority priority = WisCommandQueuePriority( - supported ? (header.queue_families[family_index].queue_priority) : 0 - ); + supported ? (header.queue_families[family_index].queue_priority) : 0 + ); props->supported_queues[i] = supported; props->max_queue_priority[i] = priority; } props->relaxed_queue_transition = header.features.maintenance9; - } break; + } + break; case WisQueryPropertyTypeDeviceDescriptorHeapProperties: { auto* props = static_cast(next); if (!header.features.descriptor_heap) { @@ -689,20 +692,21 @@ WIS_EXTERN_C WISDOM_API void wisVKDeviceQueryProperties(const WisVKDevice* self, } auto real_dheap_size = header.features.max_descriptor_heap_size - - header.features.descriptor_heap_reserved_size; + - header.features.descriptor_heap_reserved_size; auto real_sheap_size = header.features.max_sampler_heap_size - header.features.sampler_heap_reserved_size; auto real_sheap_size_with_embedded = header.features.max_sampler_heap_size - - header.features.sampler_heap_reserved_size_with_embedded; + - header.features.sampler_heap_reserved_size_with_embedded; props->max_descriptor_heap_size = real_dheap_size / header.features.resource_desc_size; props->max_sampler_heap_size = real_sheap_size / header.features.sampler_desc_size; props->max_sampler_heap_size_with_embedded = real_sheap_size_with_embedded - / header.features.sampler_desc_size; + / header.features.sampler_desc_size; props->descriptor_increment_size = header.features.resource_desc_size; props->sampler_increment_size = header.features.sampler_desc_size; props->render_target_increment_size = sizeof(wis::detail::VKRenderTargetView); props->depth_stencil_increment_size = sizeof(wis::detail::VKRenderTargetView); - } break; + } + break; case WisQueryPropertyTypeDeviceMemoryProperties: { auto* props = static_cast(next); props->host_image_copy_supported = header.features.host_image_copy; @@ -733,20 +737,22 @@ WIS_EXTERN_C WISDOM_API void wisVKDeviceQueryProperties(const WisVKDevice* self, const VkMemoryPropertyFlags flags = mem_props->memoryTypes[i].propertyFlags; if ((flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) && (flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) - && (flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) { + && (flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) { props->gpu_upload_supported = true; break; } } - } break; + } + break; case WisQueryPropertyTypeDeviceBindingProperties: { auto* props = static_cast(next); props->max_vertex_input_bindings = header.features.max_vertex_bindings; props->max_vertex_input_attributes = header.features.max_vertex_attributes; props->multiple_viewports_supported = header.features.multiple_viewports; props->address_commands_supported = header.features.address_commands; - } break; + } + break; default: break; } @@ -790,8 +796,8 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreatePipelineCache( { if (data_size > 0 && data_size < sizeof(VkPipelineCacheHeaderVersionOne)) { return wis::detail::make_result< - wis::detail::Func(), - "Data size is too small to contain a valid pipeline cache header">(VK_ERROR_INITIALIZATION_FAILED); + wis::detail::Func(), + "Data size is too small to contain a valid pipeline cache header">(VK_ERROR_INITIALIZATION_FAILED); } auto& device = *wis::from_handle(self); @@ -818,9 +824,9 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreatePipelineCache( if (std::memcmp(initial_data, &cache_header_correct, sizeof(VkPipelineCacheHeaderVersionOne)) != 0) { return wis::detail::make_result< - wis::detail::Func(), - "Initial data pipeline cache header does not match the device's pipeline cache header, indicating it " - "is incompatible">(VK_ERROR_INITIALIZATION_FAILED); + wis::detail::Func(), + "Initial data pipeline cache header does not match the device's pipeline cache header, indicating it " + "is incompatible">(VK_ERROR_INITIALIZATION_FAILED); } } @@ -839,7 +845,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreatePipelineCache( } auto& cache_impl = *new (cache) - wis::impl::VKPipelineCacheImpl{.cache = cache_handle, .device_header = device.device_header}; + wis::impl::VKPipelineCacheImpl{.cache = cache_handle, .device_header = device.device_header}; device.device_header->AddRef(); return wis::detail::vk_success; @@ -867,7 +873,7 @@ wisVKDeviceCreateShader(const WisVKDevice* self, const uint8_t* data, size_t siz } auto& shader_impl = *new (shader - ) wis::impl::VKShaderImpl{.shader_module = shader_handle, .device_header = device.device_header}; + ) wis::impl::VKShaderImpl{.shader_module = shader_handle, .device_header = device.device_header}; device.device_header->AddRef(); return wis::detail::vk_success; } @@ -904,13 +910,14 @@ wisVKDeviceCreateComputePipeline(const WisVKDevice* self, const WisVKComputePipe .pNext = &pipeline_flags_info, .flags = 0, .stage = - {.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, - .pNext = &mapping, - .flags = 0, - .stage = VK_SHADER_STAGE_COMPUTE_BIT, - .module = shader, - .pName = "main", - .pSpecializationInfo = nullptr}, + { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, + .pNext = &mapping, + .flags = 0, + .stage = VK_SHADER_STAGE_COMPUTE_BIT, + .module = shader, + .pName = "main", + .pSpecializationInfo = nullptr + }, .layout = nullptr }; @@ -922,7 +929,7 @@ wisVKDeviceCreateComputePipeline(const WisVKDevice* self, const WisVKComputePipe } auto& pipeline_impl = *new (pipeline - ) wis::impl::VKPipelineImpl{.pipeline = pipeline_handle, .device_header = device.device_header}; + ) wis::impl::VKPipelineImpl{.pipeline = pipeline_handle, .device_header = device.device_header}; pipeline_impl.device_header->AddRef(); return wis::detail::vk_success; } @@ -941,8 +948,8 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateGraphicsPipeline( if (!rsig) { return wis::detail::make_result( - VK_ERROR_INITIALIZATION_FAILED - ); + VK_ERROR_INITIALIZATION_FAILED + ); } //--Shader stages @@ -964,7 +971,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateGraphicsPipeline( }; VkShaderDescriptorSetAndBindingMappingInfoEXT mappings[max_shader_stages]; VkPipelineShaderStageCreateInfo - shader_stages[max_shader_stages]; // intentionally uninitialized, will be filled based on provided shaders + shader_stages[max_shader_stages]; // intentionally uninitialized, will be filled based on provided shaders for (uint32_t i = 0; i < max_shader_stages; i++) { auto smodule = shader_modules[i]; @@ -1015,12 +1022,12 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateGraphicsPipeline( uint32_t ia_count = desc->input_layout.attribute_count; if (desc->input_layout.attribute_count > wis::MinSupportedInputAttributes * 2) { dynamic_vertex_attributes = wis::make_unique( - desc->input_layout.attribute_count - ); + desc->input_layout.attribute_count + ); if (!dynamic_vertex_attributes) { return wis::detail::make_result< - wis::detail::Func(), - "Failed to allocate memory for vertex input attribute descriptions">(VK_ERROR_OUT_OF_HOST_MEMORY); + wis::detail::Func(), + "Failed to allocate memory for vertex input attribute descriptions">(VK_ERROR_OUT_OF_HOST_MEMORY); } ia_span = {dynamic_vertex_attributes.get(), ia_count}; @@ -1044,11 +1051,11 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateGraphicsPipeline( .flags = 0, .vertexBindingDescriptionCount = static_cast(desc->input_layout.binding_count), .pVertexBindingDescriptions = desc->input_layout.binding_count - ? reinterpret_cast( - desc->input_layout.bindings - ) // strict aliasing violation, but we control the data and it's guaranteed - // to be compatible - : nullptr, + ? reinterpret_cast( + desc->input_layout.bindings + ) // strict aliasing violation, but we control the data and it's guaranteed + // to be compatible + : nullptr, .vertexAttributeDescriptionCount = static_cast(desc->input_layout.attribute_count), .pVertexAttributeDescriptions = desc->input_layout.attribute_count ? ia_span.data() : nullptr, }; @@ -1140,8 +1147,8 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateGraphicsPipeline( uint32_t rt_count = desc->render_attachments.attachments_count; if (rt_count > wis::MaxRenderTargets) { return wis::detail::make_result< - wis::detail::Func(), - "Exceeded maximum number of render target attachments (8)">(VK_ERROR_UNKNOWN); + wis::detail::Func(), + "Exceeded maximum number of render target attachments (8)">(VK_ERROR_UNKNOWN); } VkFormat rt_formats[wis::MaxRenderTargets]; for (uint32_t i = 0; i < rt_count; i++) { @@ -1209,25 +1216,25 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateGraphicsPipeline( .depthBoundsTestEnable = ds.depth_bound_test, .stencilTestEnable = ds.stencil_enable, .front = - VkStencilOpState{ - .failOp = wis::detail::VKConvert(ds.stencil_front.fail_op), - .passOp = wis::detail::VKConvert(ds.stencil_front.pass_op), - .depthFailOp = wis::detail::VKConvert(ds.stencil_front.depth_fail_op), - .compareOp = wis::detail::VKConvert(ds.stencil_front.stencil_comp), - .compareMask = ds.stencil_front.read_mask, - .writeMask = ds.stencil_front.write_mask, - .reference = 0, - }, + VkStencilOpState{ + .failOp = wis::detail::VKConvert(ds.stencil_front.fail_op), + .passOp = wis::detail::VKConvert(ds.stencil_front.pass_op), + .depthFailOp = wis::detail::VKConvert(ds.stencil_front.depth_fail_op), + .compareOp = wis::detail::VKConvert(ds.stencil_front.stencil_comp), + .compareMask = ds.stencil_front.read_mask, + .writeMask = ds.stencil_front.write_mask, + .reference = 0, + }, .back = - VkStencilOpState{ - .failOp = wis::detail::VKConvert(ds.stencil_back.fail_op), - .passOp = wis::detail::VKConvert(ds.stencil_back.pass_op), - .depthFailOp = wis::detail::VKConvert(ds.stencil_back.depth_fail_op), - .compareOp = wis::detail::VKConvert(ds.stencil_back.stencil_comp), - .compareMask = ds.stencil_back.read_mask, - .writeMask = ds.stencil_back.write_mask, - .reference = 0, - }, + VkStencilOpState{ + .failOp = wis::detail::VKConvert(ds.stencil_back.fail_op), + .passOp = wis::detail::VKConvert(ds.stencil_back.pass_op), + .depthFailOp = wis::detail::VKConvert(ds.stencil_back.depth_fail_op), + .compareOp = wis::detail::VKConvert(ds.stencil_back.stencil_comp), + .compareMask = ds.stencil_back.read_mask, + .writeMask = ds.stencil_back.write_mask, + .reference = 0, + }, .minDepthBounds = 0.0f, .maxDepthBounds = 1.0f, }; @@ -1243,7 +1250,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateGraphicsPipeline( .dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO, .alphaBlendOp = VK_BLEND_OP_ADD, .colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT - | VK_COLOR_COMPONENT_A_BIT, + | VK_COLOR_COMPONENT_A_BIT, }; VkPipelineColorBlendAttachmentState color_blend_attachment[wis::MaxRenderTargets]; VkPipelineColorBlendStateCreateInfo color_blending; @@ -1366,20 +1373,20 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateGraphicsPipeline( VkPipeline pipeline_handle = VK_NULL_HANDLE; auto vr = table.vkCreateGraphicsPipelines( - device.device, - std::bit_cast(desc->cache), - 1u, - &info, - nullptr, - &pipeline_handle - ); + device.device, + std::bit_cast(desc->cache), + 1u, + &info, + nullptr, + &pipeline_handle + ); if (!wis::detail::succeeded(vr)) { return wis::detail::make_result(vr); } auto& pipeline_impl = *new (pipeline - ) wis::impl::VKPipelineImpl{.pipeline = pipeline_handle, .device_header = device.device_header}; + ) wis::impl::VKPipelineImpl{.pipeline = pipeline_handle, .device_header = device.device_header}; device.device_header->AddRef(); return wis::detail::vk_success; @@ -1416,8 +1423,8 @@ wisVKDeviceGetSurfaceParameters(const WisVKDevice* self, WisVKSurfaceView surfac *params = { .min_swapchain_images = capabilities.surfaceCapabilities.minImageCount, .max_swapchain_images = capabilities.surfaceCapabilities.maxImageCount == 0 - ? wis::AbsoluteMaxSwapchainImages - : capabilities.surfaceCapabilities.maxImageCount, + ? wis::AbsoluteMaxSwapchainImages + : capabilities.surfaceCapabilities.maxImageCount, .alpha_modes_supported = alpha, .texture_usage_flags_supported = wis::detail::VKConvert(capabilities.surfaceCapabilities.supportedUsageFlags), .stereo_supported = capabilities.surfaceCapabilities.maxImageArrayLayers > 1, @@ -1459,11 +1466,11 @@ WIS_EXTERN_C WISDOM_API bool wisVKDeviceGetFormatPresentationSupport( } vr = atable.vkGetPhysicalDeviceSurfaceFormatsKHR( - device.physical_device, - vk_surface, - &format_count, - format_span.data() - ); + device.physical_device, + vk_surface, + &format_count, + format_span.data() + ); if (!wis::detail::succeeded(vr)) { return false; } @@ -1500,15 +1507,15 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateSwapchain( uint32_t format_count = 0; auto vr = atable.vkGetPhysicalDeviceSurfaceFormatsKHR( - device.physical_device, - surface_impl.surface, - &format_count, - nullptr - ); + device.physical_device, + surface_impl.surface, + &format_count, + nullptr + ); if (!wis::detail::succeeded(vr) || format_count == 0) { return wis::detail::make_result< - wis::detail::Func(), - "Failed to get surface formats or no formats supported by the surface">(VK_ERROR_INITIALIZATION_FAILED); + wis::detail::Func(), + "Failed to get surface formats or no formats supported by the surface">(VK_ERROR_INITIALIZATION_FAILED); } if (format_count > reasonable_format_count) { @@ -1523,11 +1530,11 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateSwapchain( } vr = atable.vkGetPhysicalDeviceSurfaceFormatsKHR( - device.physical_device, - surface_impl.surface, - &format_count, - format_span.data() - ); + device.physical_device, + surface_impl.surface, + &format_count, + format_span.data() + ); if (!wis::detail::succeeded(vr)) { return wis::detail::make_result(vr); } @@ -1539,9 +1546,9 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateSwapchain( if (format_it == format_span.end()) { return wis::detail::make_result< - wis::detail::Func(), - "The requested format is not supported for presentation on the given surface">(VK_ERROR_FORMAT_NOT_SUPPORTED - ); + wis::detail::Func(), + "The requested format is not supported for presentation on the given surface">(VK_ERROR_FORMAT_NOT_SUPPORTED + ); } // Query surface props @@ -1559,19 +1566,19 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateSwapchain( // validate requested parameters against capabilities if (desc->image_count < capabilities.surfaceCapabilities.minImageCount - || (capabilities.surfaceCapabilities.maxImageCount != 0 - && desc->image_count > capabilities.surfaceCapabilities.maxImageCount)) { + || (capabilities.surfaceCapabilities.maxImageCount != 0 + && desc->image_count > capabilities.surfaceCapabilities.maxImageCount)) { return wis::detail::make_result< - wis::detail::Func(), - "Requested swapchain image count is out of bounds for the given surface">(VK_ERROR_INITIALIZATION_FAILED); + wis::detail::Func(), + "Requested swapchain image count is out of bounds for the given surface">(VK_ERROR_INITIALIZATION_FAILED); } if (desc->flags & WisSwapchainFlagsStereo) { if (capabilities.surfaceCapabilities.maxImageArrayLayers == 1) { return wis::detail::make_result< - wis::detail::Func(), - "Stereo swapchain requested but the surface does not support image array layers">( - VK_ERROR_INITIALIZATION_FAILED - ); + wis::detail::Func(), + "Stereo swapchain requested but the surface does not support image array layers">( + VK_ERROR_INITIALIZATION_FAILED + ); } array_layer_count++; } @@ -1611,14 +1618,14 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateSwapchain( // Create swapchain control block in a single allocation with the header to ensure they are close together in // memory, which is important for cache performance since the header is accessed on every frame. std::size_t header_size = sizeof(wis::detail::VKSwapchainControlBlock) + desc->image_count * sizeof(VkSemaphore) * 2 - + // semaphores for present and render complete for each image + + // semaphores for present and render complete for each image format_count - * sizeof(VkSurfaceFormatKHR); // store supported formats for use in mode switching + * sizeof(VkSurfaceFormatKHR); // store supported formats for use in mode switching std::unique_ptr header_storage{new (std::nothrow) std::byte[header_size]}; if (!header_storage) { return wis::detail::make_result( - VK_ERROR_OUT_OF_HOST_MEMORY - ); + VK_ERROR_OUT_OF_HOST_MEMORY + ); } wis::detail::VKSwapchainControlBlock* header = new (header_storage.get()) wis::detail::VKSwapchainControlBlock; @@ -1633,8 +1640,8 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateSwapchain( // Copy the supported formats for use in mode switching auto* format_storage = reinterpret_cast( - reinterpret_cast(header + 1) + desc->image_count * 2 - ); // format storage is immediately after the semaphores + reinterpret_cast(header + 1) + desc->image_count * 2 + ); // format storage is immediately after the semaphores for (uint32_t i = 0; i < format_count; i++) { format_storage[i] = format_span[i]; } @@ -1661,18 +1668,18 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateSwapchain( .imageFormat = vk_format, .imageColorSpace = format_it->colorSpace, .imageExtent = - { - .width = std::clamp( - desc->width, - capabilities.surfaceCapabilities.minImageExtent.width, - capabilities.surfaceCapabilities.maxImageExtent.width - ), - .height = std::clamp( - desc->height, - capabilities.surfaceCapabilities.minImageExtent.height, - capabilities.surfaceCapabilities.maxImageExtent.height - ), - }, + { + .width = std::clamp( + desc->width, + capabilities.surfaceCapabilities.minImageExtent.width, + capabilities.surfaceCapabilities.maxImageExtent.width + ), + .height = std::clamp( + desc->height, + capabilities.surfaceCapabilities.minImageExtent.height, + capabilities.surfaceCapabilities.maxImageExtent.height + ), + }, .imageArrayLayers = array_layer_count, .imageUsage = wis::detail::VKConvert(desc->texture_usage_flags), .imageSharingMode = VK_SHARING_MODE_EXCLUSIVE, @@ -1712,7 +1719,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateSwapchain( } stable.vkDestroySwapchainKHR(device.device, swapchain_handle, nullptr); return wis::detail:: - make_result(vr); + make_result(vr); } } @@ -1730,7 +1737,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateSwapchain( } stable.vkDestroySwapchainKHR(device.device, swapchain_handle, nullptr); return wis::detail:: - make_result(vr); + make_result(vr); } swap_head.surface_header = surface_impl.surface_header; @@ -1756,13 +1763,13 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateSwapchain( // Acquire the next image index for the new swapchain to update internal state auto result = impl.swapchain_table->vkAcquireNextImageKHR( - impl.device, - impl.swapchain, - impl.lazy_acquire ? 0 : std::numeric_limits::max(), - semaphores[impl.acquire_index], - nullptr, - &impl.present_index - ); + impl.device, + impl.swapchain, + impl.lazy_acquire ? 0 : std::numeric_limits::max(), + semaphores[impl.acquire_index], + nullptr, + &impl.present_index + ); if (result != VK_SUCCESS) { return result; // Caller can choose to handle timeout differently (e.g. by skipping rendering and trying @@ -1787,7 +1794,8 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateSwapchain( }; impl.acquire_index = (impl.acquire_index + 1) % swapchain_header.create_info.minImageCount; return swapchain_table.vkQueueSubmit2(impl.present_queue, 1, &desc2, nullptr); - }(swap_impl); + } + (swap_impl); if (!wis::detail::succeeded(vr)) { for (uint32_t j = 0; j < desc->image_count * 2; j++) { @@ -1802,7 +1810,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateSwapchain( ); // ensure the destructor doesn't attempt to clean up a partially initialized swapchain return wis::detail:: - make_result(vr); + make_result(vr); } return wis::detail::vk_success; @@ -1832,8 +1840,8 @@ wisVKDeviceGetFormatProperties(const WisVKDevice* self, WisDataFormat format, Wi if (features & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) { support_flags |= WisFormatSupportFlagsShaderResource | WisFormatSupportFlagsTexture1D - | WisFormatSupportFlagsTexture2D | WisFormatSupportFlagsTexture3D - | WisFormatSupportFlagsTextureCube; + | WisFormatSupportFlagsTexture2D | WisFormatSupportFlagsTexture3D + | WisFormatSupportFlagsTextureCube; } if (features & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) { support_flags |= WisFormatSupportFlagsRenderTarget; @@ -1852,42 +1860,42 @@ wisVKDeviceGetFormatProperties(const WisVKDevice* self, WisDataFormat format, Wi if (features & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) { VkImageFormatProperties image_props{}; if (wis::detail::succeeded(atable.vkGetPhysicalDeviceImageFormatProperties( - device.physical_device, - vk_format, - VK_IMAGE_TYPE_2D, - VK_IMAGE_TILING_OPTIMAL, - VK_IMAGE_USAGE_SAMPLED_BIT, - 0, - &image_props - ))) { + device.physical_device, + vk_format, + VK_IMAGE_TYPE_2D, + VK_IMAGE_TILING_OPTIMAL, + VK_IMAGE_USAGE_SAMPLED_BIT, + 0, + &image_props + ))) { sample_counts |= image_props.sampleCounts; } } if (features & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) { VkImageFormatProperties image_props{}; if (wis::detail::succeeded(atable.vkGetPhysicalDeviceImageFormatProperties( - device.physical_device, - vk_format, - VK_IMAGE_TYPE_2D, - VK_IMAGE_TILING_OPTIMAL, - VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, - 0, - &image_props - ))) { + device.physical_device, + vk_format, + VK_IMAGE_TYPE_2D, + VK_IMAGE_TILING_OPTIMAL, + VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, + 0, + &image_props + ))) { sample_counts |= image_props.sampleCounts; } } if (features & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) { VkImageFormatProperties image_props{}; if (wis::detail::succeeded(atable.vkGetPhysicalDeviceImageFormatProperties( - device.physical_device, - vk_format, - VK_IMAGE_TYPE_2D, - VK_IMAGE_TILING_OPTIMAL, - VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, - 0, - &image_props - ))) { + device.physical_device, + vk_format, + VK_IMAGE_TYPE_2D, + VK_IMAGE_TILING_OPTIMAL, + VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, + 0, + &image_props + ))) { sample_counts |= image_props.sampleCounts; } } @@ -1905,7 +1913,7 @@ wisVKDeviceGetFormatProperties(const WisVKDevice* self, WisDataFormat format, Wi if (max_sample_count > WisSampleCountS1) { if (features & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT - || features & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) { + || features & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) { support_flags |= WisFormatSupportFlagsMultisampleRenderTarget; } support_flags |= WisFormatSupportFlagsMultisampleResolve; diff --git a/src/include/wisdom/vulkan/vk_extensions.hpp b/src/include/wisdom/vulkan/vk_extensions.hpp index 563d29c2..f2a70839 100644 --- a/src/include/wisdom/vulkan/vk_extensions.hpp +++ b/src/include/wisdom/vulkan/vk_extensions.hpp @@ -39,21 +39,31 @@ struct CStringHash { // hash for VkExtensionProperties struct VkExtensionPropertiesHash { using is_transparent = void; - std::size_t operator()(const VkExtensionProperties& ext) const noexcept { return CStringHash{}(ext.extensionName); } - std::size_t operator()(const char* name) const noexcept { return CStringHash{}(name); } + std::size_t operator()(const VkExtensionProperties& ext) const noexcept { + return CStringHash{}(ext.extensionName); + } + std::size_t operator()(const char* name) const noexcept { + return CStringHash{}(name); + } }; //---------------------------------------------------------------------------------------------------------------------- struct VkLayerPropertiesHash { using is_transparent = void; - std::size_t operator()(const VkLayerProperties& layer) const noexcept { return CStringHash{}(layer.layerName); } - std::size_t operator()(const char* name) const noexcept { return CStringHash{}(name); } + std::size_t operator()(const VkLayerProperties& layer) const noexcept { + return CStringHash{}(layer.layerName); + } + std::size_t operator()(const char* name) const noexcept { + return CStringHash{}(name); + } }; // Equality helpers //---------------------------------------------------------------------------------------------------------------------- struct CStringEqual { - bool operator()(const char* a, const char* b) const { return std::strncmp(a, b, VK_MAX_EXTENSION_NAME_SIZE) == 0; } + bool operator()(const char* a, const char* b) const { + return std::strncmp(a, b, VK_MAX_EXTENSION_NAME_SIZE) == 0; + } }; //---------------------------------------------------------------------------------------------------------------------- @@ -92,13 +102,13 @@ struct VkLayerPropertiesEqual { using CStringSet = std::unordered_set; using VkExtensionPropertiesSet = std:: - unordered_set; + unordered_set; using VkLayerPropertiesSet = std::unordered_set; } // namespace detail //---------------------------------------------------------------------------------------------------------------------- struct WISDOM_API VKInstanceExtensionCollector { - constexpr static const char* instance_extensions[]{ + constexpr static const char* instance_extensions[] { VK_KHR_SURFACE_EXTENSION_NAME, VK_EXT_SURFACE_MAINTENANCE_1_EXTENSION_NAME, VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME, @@ -226,7 +236,9 @@ struct WISDOM_API VKDeviceExtensionCollector { template struct VKInstanceExtensionImpl : public VKInstanceExtensionHeader { VKInstanceExtensionImpl() noexcept - : VKInstanceExtensionHeader{&VKInstanceExtensionImpl::InitThunk} + : VKInstanceExtensionHeader { + &VKInstanceExtensionImpl::InitThunk + } { assert( std::uintptr_t(static_cast(this)) == std::uintptr_t(static_cast(this)) @@ -245,9 +257,9 @@ struct VKInstanceExtensionImpl : public VKInstanceExtensionHeader { return reinterpret_cast(self)->CollectInfo(*collector); } return reinterpret_cast(self)->Init( - const_cast(*instance_impl), - const_cast(*collector) - ); + const_cast(*instance_impl), + const_cast(*collector) + ); } public: @@ -267,7 +279,9 @@ struct VKInstanceExtensionImpl : public VKInstanceExtensionHeader { template struct VKDeviceExtensionImpl : public VKDeviceExtensionHeader { VKDeviceExtensionImpl() noexcept - : VKDeviceExtensionHeader{&VKDeviceExtensionImpl::InitThunk} + : VKDeviceExtensionHeader { + &VKDeviceExtensionImpl::InitThunk + } { assert( std::uintptr_t(static_cast(this)) == std::uintptr_t(static_cast(this)) @@ -286,9 +300,9 @@ struct VKDeviceExtensionImpl : public VKDeviceExtensionHeader { return reinterpret_cast(self)->CollectInfo(*collector); } return reinterpret_cast(self)->Init( - const_cast(*device_impl), - const_cast(*collector) - ); + const_cast(*device_impl), + const_cast(*collector) + ); } public: diff --git a/src/include/wisdom/vulkan/vk_impl.cpp b/src/include/wisdom/vulkan/vk_impl.cpp index 84bd85b6..08f7292e 100644 --- a/src/include/wisdom/vulkan/vk_impl.cpp +++ b/src/include/wisdom/vulkan/vk_impl.cpp @@ -103,14 +103,16 @@ wisVKTextureWriteSubresource(const WisVKTexture* self, const void* source_data, .memoryRowLength = 0, .memoryImageHeight = 0, .imageSubresource = - {.aspectMask = plane_to_aspect_mask(target_region->target_subresource.plane_slice), - .mipLevel = target_region->target_subresource.mip_level, - .baseArrayLayer = target_region->target_subresource.array_layer, - .layerCount = 1}, + { .aspectMask = plane_to_aspect_mask(target_region->target_subresource.plane_slice), + .mipLevel = target_region->target_subresource.mip_level, + .baseArrayLayer = target_region->target_subresource.array_layer, + .layerCount = 1 + }, .imageOffset = - {static_cast(target_region->box.x), - static_cast(target_region->box.y), - static_cast(target_region->box.z)}, + { static_cast(target_region->box.x), + static_cast(target_region->box.y), + static_cast(target_region->box.z) + }, .imageExtent{target_region->box.width, target_region->box.height, target_region->box.depth}, }; diff --git a/src/include/wisdom/vulkan/vk_resource_allocator.cpp b/src/include/wisdom/vulkan/vk_resource_allocator.cpp index 75a2bb7b..84efe1f1 100644 --- a/src/include/wisdom/vulkan/vk_resource_allocator.cpp +++ b/src/include/wisdom/vulkan/vk_resource_allocator.cpp @@ -16,8 +16,8 @@ inline VkImageCreateInfo VKFillImageDesc(const WisTextureDesc& desc) noexcept .flags = (usage & (VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR | VK_IMAGE_USAGE_VIDEO_DECODE_SRC_BIT_KHR | VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR)) - ? VK_IMAGE_CREATE_VIDEO_PROFILE_INDEPENDENT_BIT_KHR - : VkImageCreateFlags{0}, + ? VK_IMAGE_CREATE_VIDEO_PROFILE_INDEPENDENT_BIT_KHR + : VkImageCreateFlags{0}, .format = wis::detail::VKConvert(desc.format), .samples = VK_SAMPLE_COUNT_1_BIT, .usage = usage, @@ -115,8 +115,8 @@ wisVKResourceAllocatorCreateBuffer(const WisVKResourceAllocator* self, const Wis buffer_info.flags = (buffer_info.usage & (VK_BUFFER_USAGE_VIDEO_DECODE_DST_BIT_KHR | VK_BUFFER_USAGE_VIDEO_DECODE_SRC_BIT_KHR)) - ? VK_BUFFER_CREATE_VIDEO_PROFILE_INDEPENDENT_BIT_KHR - : 0; + ? VK_BUFFER_CREATE_VIDEO_PROFILE_INDEPENDENT_BIT_KHR + : 0; VmaAllocationCreateFlags flags = wis::detail::VKConvert(desc->memory_flags); if (desc->memory_flags & WisMemoryFlagsMapped) { @@ -142,13 +142,13 @@ wisVKResourceAllocatorCreateBuffer(const WisVKResourceAllocator* self, const Wis VkBuffer buffer_handle = VK_NULL_HANDLE; VmaAllocation allocation_handle = VK_NULL_HANDLE; VkResult vr = vmaCreateBuffer( - allocator.allocator, - &buffer_info, - &alloc_info, - &buffer_handle, - &allocation_handle, - nullptr - ); + allocator.allocator, + &buffer_info, + &alloc_info, + &buffer_handle, + &allocation_handle, + nullptr + ); if (!wis::detail::succeeded(vr)) { return wis::detail::make_result(vr); } @@ -185,8 +185,8 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKResourceAllocatorCreateTexture( // Check memory type, you can't create a texture with upload or readback memory types if (desc->memory_type == WisMemoryTypeUpload || desc->memory_type == WisMemoryTypeReadback) { return wis::detail::make_result( - VK_ERROR_UNKNOWN - ); + VK_ERROR_UNKNOWN + ); } VkImageCreateInfo image_info = wis::detail::VKFillImageDesc(*desc); @@ -230,7 +230,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKResourceAllocatorCreateTexture( VkImage image_handle = VK_NULL_HANDLE; VmaAllocation allocation_handle = VK_NULL_HANDLE; VkResult - vr = vmaCreateImage(allocator.allocator, &image_info, &alloc_info, &image_handle, &allocation_handle, nullptr); + vr = vmaCreateImage(allocator.allocator, &image_info, &alloc_info, &image_handle, &allocation_handle, nullptr); if (!wis::detail::succeeded(vr)) { return wis::detail::make_result(vr); } @@ -250,13 +250,13 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKResourceAllocatorCreateTexture( .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED, .newLayout = VK_IMAGE_LAYOUT_GENERAL, .subresourceRange = - { - .aspectMask = wis::detail::VKAspectFlags(image_info.format), - .baseMipLevel = 0, - .levelCount = image_info.mipLevels, - .baseArrayLayer = 0, - .layerCount = image_info.arrayLayers, - }, + { + .aspectMask = wis::detail::VKAspectFlags(image_info.format), + .baseMipLevel = 0, + .levelCount = image_info.mipLevels, + .baseArrayLayer = 0, + .layerCount = image_info.arrayLayers, + }, }; vr = table.vkTransitionImageLayoutEXT(header.device, 1, &transition_info); @@ -273,8 +273,8 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKResourceAllocatorCreateTexture( .width = static_cast(image_info.extent.width), .height = static_cast(image_info.extent.height), .depth_or_array_size = desc->layout == WisTextureLayoutTexture3D - ? static_cast(image_info.extent.depth) - : static_cast(image_info.arrayLayers), + ? static_cast(image_info.extent.depth) + : static_cast(image_info.arrayLayers), }; impl.device_header->AddRef(); diff --git a/src/include/wisdom/vulkan/vk_swapchain.cpp b/src/include/wisdom/vulkan/vk_swapchain.cpp index bc8d2b1b..67fc3da2 100644 --- a/src/include/wisdom/vulkan/vk_swapchain.cpp +++ b/src/include/wisdom/vulkan/vk_swapchain.cpp @@ -17,13 +17,13 @@ inline VkResult VKAcquireNextImage(const impl::VKSwapchainImpl& impl) noexcept // Acquire the next image index for the new swapchain to update internal state auto result = impl.swapchain_table->vkAcquireNextImageKHR( - impl.device, - impl.swapchain, - impl.lazy_acquire ? 0 : std::numeric_limits::max(), - semaphores[impl.acquire_index], - nullptr, - &impl.present_index - ); + impl.device, + impl.swapchain, + impl.lazy_acquire ? 0 : std::numeric_limits::max(), + semaphores[impl.acquire_index], + nullptr, + &impl.present_index + ); if (result != VK_SUCCESS) { return result; // Caller can choose to handle timeout differently (e.g. by skipping rendering and trying again @@ -158,8 +158,8 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKSwapchainUpdate(const WisVKSwapchain* sel VkFormat new_format = wis::detail::VKConvert(desc->format); bool size_changed = desc->width != 0 && desc->height != 0 - && (desc->width != create_info.imageExtent.width || desc->height != create_info.imageExtent.height - ); + && (desc->width != create_info.imageExtent.width || desc->height != create_info.imageExtent.height + ); bool format_changed = desc->format != WisDataFormatUnknown && new_format != create_info.imageFormat; bool count_changed = desc->image_count != 0 && desc->image_count != create_info.minImageCount; bool vsync_changed = desc->vsync != (create_info.presentMode == VK_PRESENT_MODE_FIFO_KHR); @@ -187,13 +187,15 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKSwapchainUpdate(const WisVKSwapchain* sel if (format_changed) { auto formats = header.GetSupportedFormats(); if (std::ranges::find_if( - formats, - [new_format](const VkSurfaceFormatKHR& fmt) { return fmt.format == new_format; } + formats, + [new_format](const VkSurfaceFormatKHR& fmt) { + return fmt.format == new_format; + } ) - == std::end(formats)) { + == std::end(formats)) { return wis::detail::make_result( - VK_ERROR_FORMAT_NOT_SUPPORTED - ); + VK_ERROR_FORMAT_NOT_SUPPORTED + ); } } @@ -212,16 +214,16 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKSwapchainUpdate(const WisVKSwapchain* sel header.vkGetPhysicalDeviceSurfaceCapabilities2KHR(header.physical_device, &surface_info, &capabilities); capabilities.surfaceCapabilities.maxImageCount = capabilities.surfaceCapabilities.maxImageCount == 0 - ? wis::AbsoluteMaxSwapchainImages - : capabilities.surfaceCapabilities.maxImageCount; + ? wis::AbsoluteMaxSwapchainImages + : capabilities.surfaceCapabilities.maxImageCount; } if (count_changed - && (desc->image_count < capabilities.surfaceCapabilities.minImageCount - || desc->image_count > capabilities.surfaceCapabilities.maxImageCount)) { + && (desc->image_count < capabilities.surfaceCapabilities.minImageCount + || desc->image_count > capabilities.surfaceCapabilities.maxImageCount)) { return wis::detail::make_result< - wis::detail::Func(), - "Requested swapchain image count is out of bounds for the given surface">(VK_ERROR_INITIALIZATION_FAILED); + wis::detail::Func(), + "Requested swapchain image count is out of bounds for the given surface">(VK_ERROR_INITIALIZATION_FAILED); } // Store backups @@ -239,17 +241,17 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKSwapchainUpdate(const WisVKSwapchain* sel }; create_info.imageExtent.width = desc->width != 0 ? std::clamp( - desc->width, - capabilities.surfaceCapabilities.minImageExtent.width, - capabilities.surfaceCapabilities.maxImageExtent.width - ) - : create_info.imageExtent.width; + desc->width, + capabilities.surfaceCapabilities.minImageExtent.width, + capabilities.surfaceCapabilities.maxImageExtent.width + ) + : create_info.imageExtent.width; create_info.imageExtent.height = desc->height != 0 ? std::clamp( - desc->height, - capabilities.surfaceCapabilities.minImageExtent.height, - capabilities.surfaceCapabilities.maxImageExtent.height - ) - : create_info.imageExtent.height; + desc->height, + capabilities.surfaceCapabilities.minImageExtent.height, + capabilities.surfaceCapabilities.maxImageExtent.height + ) + : create_info.imageExtent.height; create_info.imageFormat = desc->format != WisDataFormatUnknown ? new_format : create_info.imageFormat; create_info.minImageCount = desc->image_count != 0 ? desc->image_count : create_info.minImageCount; @@ -272,7 +274,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKSwapchainUpdate(const WisVKSwapchain* sel // Wait for the GPU to finish with the swapchain vr = impl.swapchain_table - ->vkWaitForFences(impl.device, 1, &impl.destroy_fence, VK_TRUE, std::numeric_limits::max()); + ->vkWaitForFences(impl.device, 1, &impl.destroy_fence, VK_TRUE, std::numeric_limits::max()); if (!wis::detail::succeeded(vr)) { restore_on_failure(); return wis::detail::make_result(vr); @@ -288,7 +290,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKSwapchainUpdate(const WisVKSwapchain* sel if (vr != VK_SUCCESS) { // no restore return wis::detail:: - make_result(vr); + make_result(vr); } return wis::detail::vk_success; @@ -308,8 +310,8 @@ wisVKSwapchainGetTextures(const WisVKSwapchain* self, WisVKTexture* buffers, siz if (buffer_count < actual_buffer_count) { return wis::detail::make_result< - wis::detail::Func(), - "Provided buffer count is less than the number of swapchain images">(VK_ERROR_UNKNOWN); + wis::detail::Func(), + "Provided buffer count is less than the number of swapchain images">(VK_ERROR_UNKNOWN); } // Cheat the allocation of the output array to avoid dynamic memory allocation in this function by treating the diff --git a/src/include/wisdom/vulkan/vk_tables.hpp b/src/include/wisdom/vulkan/vk_tables.hpp index 0fed82c8..2b1e327e 100644 --- a/src/include/wisdom/vulkan/vk_tables.hpp +++ b/src/include/wisdom/vulkan/vk_tables.hpp @@ -16,7 +16,7 @@ typedef struct VkPhysicalDeviceDeviceAddressCommandsFeaturesKHR { } VkPhysicalDeviceDeviceAddressCommandsFeaturesKHR; static constexpr VkStructureType - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEVICE_ADDRESS_COMMANDS_FEATURES_KHR = VkStructureType(1000318006); +VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEVICE_ADDRESS_COMMANDS_FEATURES_KHR = VkStructureType(1000318006); static constexpr VkStructureType VK_STRUCTURE_TYPE_BIND_VERTEX_BUFFER_3_INFO_KHR = VkStructureType(1000318008); static constexpr VkStructureType VK_STRUCTURE_TYPE_BIND_INDEX_BUFFER_3_INFO_KHR = VkStructureType(1000318007); @@ -44,11 +44,11 @@ typedef struct VkBindIndexBuffer3InfoKHR { } VkBindIndexBuffer3InfoKHR; using PFN_vkCmdBindVertexBuffers3KHR = void (*)( - VkCommandBuffer commandBuffer, - uint32_t firstBinding, - uint32_t bindingCount, - const VkBindVertexBuffer3InfoKHR* pBindingInfos -); + VkCommandBuffer commandBuffer, + uint32_t firstBinding, + uint32_t bindingCount, + const VkBindVertexBuffer3InfoKHR* pBindingInfos + ); using PFN_vkCmdBindIndexBuffer3KHR = void (*)(VkCommandBuffer commandBuffer, const VkBindIndexBuffer3InfoKHR* pInfo); #endif // VK_KHR_device_address_commands diff --git a/src/include/wisdom/wisdom.hpp b/src/include/wisdom/wisdom.hpp index 9f6d7f66..cd4ae1e0 100644 --- a/src/include/wisdom/wisdom.hpp +++ b/src/include/wisdom/wisdom.hpp @@ -91,11 +91,11 @@ WIS_NODISCARD inline wis::Instance CreateInstance( { wis::DX12Instance instance{}; const WisResult wis_result = ::wisDX12CreateInstance( - reinterpret_cast(debug_desc), - reinterpret_cast(extensions.data()), - extensions.size(), - instance.GetStorage() - ); + reinterpret_cast(debug_desc), + reinterpret_cast(extensions.data()), + extensions.size(), + instance.GetStorage() + ); out_result = wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; return instance; } @@ -177,11 +177,11 @@ WIS_NODISCARD inline wis::Instance CreateInstance( { wis::VKInstance instance{}; const WisResult wis_result = ::wisVKCreateInstance( - reinterpret_cast(debug_desc), - reinterpret_cast(extensions.data()), - extensions.size(), - instance.GetStorage() - ); + reinterpret_cast(debug_desc), + reinterpret_cast(extensions.data()), + extensions.size(), + instance.GetStorage() + ); out_result = wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; return instance; } diff --git a/src/platform/wisdom_platform/generated/cpp_api.hpp b/src/platform/wisdom_platform/generated/cpp_api.hpp index 74cc9072..75f8ce00 100644 --- a/src/platform/wisdom_platform/generated/cpp_api.hpp +++ b/src/platform/wisdom_platform/generated/cpp_api.hpp @@ -70,7 +70,9 @@ struct UWPWindowDesc { namespace wis { struct DX12Win32ExtensionDeleter { - void operator()(WisDX12Win32Extension* handle) noexcept { ::wisDX12DestroyWin32Extension(handle); } + void operator()(WisDX12Win32Extension* handle) noexcept { + ::wisDX12DestroyWin32Extension(handle); + } }; /** * @brief Provided by Wisdom 0.7.0. Extension for Win32 surface creation functions. @@ -78,7 +80,7 @@ struct DX12Win32ExtensionDeleter { * */ class DX12Win32Extension : public wis::impl:: - Implements + Implements { public: DX12Win32Extension() noexcept @@ -87,7 +89,9 @@ class DX12Win32Extension ::wisDX12InitWin32Extension(GetStorage()); } // Operator & overload - wis::DX12InstanceExtensionHeader* operator&() noexcept { return &GetMutableInternal().header; } + wis::DX12InstanceExtensionHeader* operator&() noexcept { + return &GetMutableInternal().header; + } public: /** @@ -104,10 +108,10 @@ class DX12Win32Extension { wis::DX12Surface surface{}; const WisResult wis_result = ::wisDX12Win32ExtensionCreateSurface( - &_impl_storage, - reinterpret_cast(&info), - surface.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&info), + surface.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -121,11 +125,15 @@ class DX12Win32Extension * @return bool true if the extension is supported, false otherwise. * * */ - WIS_NODISCARD inline bool Supported() noexcept { return (::wisDX12Win32ExtensionSupported(&_impl_storage)); } + WIS_NODISCARD inline bool Supported() noexcept { + return (::wisDX12Win32ExtensionSupported(&_impl_storage)); + } }; struct DX12UWPExtensionDeleter { - void operator()(WisDX12UWPExtension* handle) noexcept { ::wisDX12DestroyUWPExtension(handle); } + void operator()(WisDX12UWPExtension* handle) noexcept { + ::wisDX12DestroyUWPExtension(handle); + } }; /** * @brief Provided by Wisdom 0.7.0. Extension for UWP surface creation functions. @@ -141,7 +149,9 @@ class DX12UWPExtension ::wisDX12InitUWPExtension(GetStorage()); } // Operator & overload - wis::DX12InstanceExtensionHeader* operator&() noexcept { return &GetMutableInternal().header; } + wis::DX12InstanceExtensionHeader* operator&() noexcept { + return &GetMutableInternal().header; + } public: /** @@ -158,10 +168,10 @@ class DX12UWPExtension { wis::DX12Surface surface{}; const WisResult wis_result = ::wisDX12UWPExtensionCreateSurface( - &_impl_storage, - reinterpret_cast(&info), - surface.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&info), + surface.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -179,7 +189,9 @@ class DX12UWPExtension namespace wis { struct VKXlibExtensionDeleter { - void operator()(WisVKXlibExtension* handle) noexcept { ::wisVKDestroyXlibExtension(handle); } + void operator()(WisVKXlibExtension* handle) noexcept { + ::wisVKDestroyXlibExtension(handle); + } }; /** * @brief Provided by Wisdom 0.7.0. Extension for Xlib surface creation functions. @@ -195,7 +207,9 @@ class VKXlibExtension ::wisVKInitXlibExtension(GetStorage()); } // Operator & overload - wis::VKInstanceExtensionHeader* operator&() noexcept { return &GetMutableInternal().header; } + wis::VKInstanceExtensionHeader* operator&() noexcept { + return &GetMutableInternal().header; + } public: /** @@ -209,10 +223,10 @@ class VKXlibExtension { wis::VKSurface surface{}; const WisResult wis_result = ::wisVKXlibExtensionCreateSurface( - &_impl_storage, - reinterpret_cast(&info), - surface.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&info), + surface.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -225,11 +239,15 @@ class VKXlibExtension * @return bool true if the extension is supported, false otherwise. * * */ - WIS_NODISCARD inline bool Supported() noexcept { return (::wisVKXlibExtensionSupported(&_impl_storage)); } + WIS_NODISCARD inline bool Supported() noexcept { + return (::wisVKXlibExtensionSupported(&_impl_storage)); + } }; struct VKXCBExtensionDeleter { - void operator()(WisVKXCBExtension* handle) noexcept { ::wisVKDestroyXCBExtension(handle); } + void operator()(WisVKXCBExtension* handle) noexcept { + ::wisVKDestroyXCBExtension(handle); + } }; /** * @brief Provided by Wisdom 0.7.0. Extension for Xlib surface creation functions. @@ -245,7 +263,9 @@ class VKXCBExtension ::wisVKInitXCBExtension(GetStorage()); } // Operator & overload - wis::VKInstanceExtensionHeader* operator&() noexcept { return &GetMutableInternal().header; } + wis::VKInstanceExtensionHeader* operator&() noexcept { + return &GetMutableInternal().header; + } public: /** @@ -259,10 +279,10 @@ class VKXCBExtension { wis::VKSurface surface{}; const WisResult wis_result = ::wisVKXCBExtensionCreateSurface( - &_impl_storage, - reinterpret_cast(&info), - surface.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&info), + surface.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -275,11 +295,15 @@ class VKXCBExtension * @return bool true if the extension is supported, false otherwise. * * */ - WIS_NODISCARD inline bool Supported() noexcept { return (::wisVKXCBExtensionSupported(&_impl_storage)); } + WIS_NODISCARD inline bool Supported() noexcept { + return (::wisVKXCBExtensionSupported(&_impl_storage)); + } }; struct VKWaylandExtensionDeleter { - void operator()(WisVKWaylandExtension* handle) noexcept { ::wisVKDestroyWaylandExtension(handle); } + void operator()(WisVKWaylandExtension* handle) noexcept { + ::wisVKDestroyWaylandExtension(handle); + } }; /** * @brief Provided by Wisdom 0.7.0. Extension for Xlib surface creation functions. @@ -287,7 +311,7 @@ struct VKWaylandExtensionDeleter { * */ class VKWaylandExtension : public wis::impl:: - Implements + Implements { public: VKWaylandExtension() noexcept @@ -296,7 +320,9 @@ class VKWaylandExtension ::wisVKInitWaylandExtension(GetStorage()); } // Operator & overload - wis::VKInstanceExtensionHeader* operator&() noexcept { return &GetMutableInternal().header; } + wis::VKInstanceExtensionHeader* operator&() noexcept { + return &GetMutableInternal().header; + } public: /** @@ -313,10 +339,10 @@ class VKWaylandExtension { wis::VKSurface surface{}; const WisResult wis_result = ::wisVKWaylandExtensionCreateSurface( - &_impl_storage, - reinterpret_cast(&info), - surface.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&info), + surface.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -329,11 +355,15 @@ class VKWaylandExtension * @return bool true if the extension is supported, false otherwise. * * */ - WIS_NODISCARD inline bool Supported() noexcept { return (::wisVKWaylandExtensionSupported(&_impl_storage)); } + WIS_NODISCARD inline bool Supported() noexcept { + return (::wisVKWaylandExtensionSupported(&_impl_storage)); + } }; struct VKWin32ExtensionDeleter { - void operator()(WisVKWin32Extension* handle) noexcept { ::wisVKDestroyWin32Extension(handle); } + void operator()(WisVKWin32Extension* handle) noexcept { + ::wisVKDestroyWin32Extension(handle); + } }; /** * @brief Provided by Wisdom 0.7.0. Extension for Win32 surface creation functions. @@ -349,7 +379,9 @@ class VKWin32Extension ::wisVKInitWin32Extension(GetStorage()); } // Operator & overload - wis::VKInstanceExtensionHeader* operator&() noexcept { return &GetMutableInternal().header; } + wis::VKInstanceExtensionHeader* operator&() noexcept { + return &GetMutableInternal().header; + } public: /** @@ -366,10 +398,10 @@ class VKWin32Extension { wis::VKSurface surface{}; const WisResult wis_result = ::wisVKWin32ExtensionCreateSurface( - &_impl_storage, - reinterpret_cast(&info), - surface.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&info), + surface.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -383,7 +415,9 @@ class VKWin32Extension * @return bool true if the extension is supported, false otherwise. * * */ - WIS_NODISCARD inline bool Supported() noexcept { return (::wisVKWin32ExtensionSupported(&_impl_storage)); } + WIS_NODISCARD inline bool Supported() noexcept { + return (::wisVKWin32ExtensionSupported(&_impl_storage)); + } }; } // namespace wis diff --git a/src/platform/wisdom_platform/vulkan/vk_platform_wayland.cpp b/src/platform/wisdom_platform/vulkan/vk_platform_wayland.cpp index 7c88e638..7d38c9a3 100644 --- a/src/platform/wisdom_platform/vulkan/vk_platform_wayland.cpp +++ b/src/platform/wisdom_platform/vulkan/vk_platform_wayland.cpp @@ -79,8 +79,8 @@ wisVKWaylandExtensionCreateSurface(WisVKWaylandExtension* self, const WisWayland auto& itable = impl.instance_control_block->header.instance_table; itable.vkDestroySurfaceKHR(impl.instance_control_block->header.instance, vk_surface, nullptr); return wis::detail::make_result( - VK_ERROR_OUT_OF_HOST_MEMORY - ); + VK_ERROR_OUT_OF_HOST_MEMORY + ); } header->header.instance_header = impl.instance_control_block, header->header.surface = vk_surface, diff --git a/src/platform/wisdom_platform/vulkan/vk_platform_win32.cpp b/src/platform/wisdom_platform/vulkan/vk_platform_win32.cpp index d56332ed..fd157fe6 100644 --- a/src/platform/wisdom_platform/vulkan/vk_platform_win32.cpp +++ b/src/platform/wisdom_platform/vulkan/vk_platform_win32.cpp @@ -106,8 +106,8 @@ wisVKWin32ExtensionCreateSurface(WisVKWin32Extension* self, const WisWin32Window auto& itable = impl.instance_control_block->header.instance_table; itable.vkDestroySurfaceKHR(impl.instance_control_block->header.instance, vk_surface, nullptr); return wis::detail::make_result( - VK_ERROR_OUT_OF_HOST_MEMORY - ); + VK_ERROR_OUT_OF_HOST_MEMORY + ); } header->header.instance_header = impl.instance_control_block, header->header.surface = vk_surface, diff --git a/src/platform/wisdom_platform/vulkan/vk_platform_xcb.cpp b/src/platform/wisdom_platform/vulkan/vk_platform_xcb.cpp index 18e5a05a..2e4343fc 100644 --- a/src/platform/wisdom_platform/vulkan/vk_platform_xcb.cpp +++ b/src/platform/wisdom_platform/vulkan/vk_platform_xcb.cpp @@ -83,8 +83,8 @@ wisVKXCBExtensionCreateSurface(WisVKXCBExtension* self, const WisXCBWindowDesc* auto& itable = impl.instance_control_block->header.instance_table; itable.vkDestroySurfaceKHR(impl.instance_control_block->header.instance, vk_surface, nullptr); return wis::detail::make_result( - VK_ERROR_OUT_OF_HOST_MEMORY - ); + VK_ERROR_OUT_OF_HOST_MEMORY + ); } header->header.instance_header = impl.instance_control_block, header->header.surface = vk_surface, diff --git a/src/platform/wisdom_platform/vulkan/vk_platform_xlib.cpp b/src/platform/wisdom_platform/vulkan/vk_platform_xlib.cpp index 9b8ebc73..48d6f676 100644 --- a/src/platform/wisdom_platform/vulkan/vk_platform_xlib.cpp +++ b/src/platform/wisdom_platform/vulkan/vk_platform_xlib.cpp @@ -84,8 +84,8 @@ wisVKXlibExtensionCreateSurface(WisVKXlibExtension* self, const WisXlibWindowDes auto& itable = impl.instance_control_block->header.instance_table; itable.vkDestroySurfaceKHR(impl.instance_control_block->header.instance, vk_surface, nullptr); return wis::detail::make_result( - VK_ERROR_OUT_OF_HOST_MEMORY - ); + VK_ERROR_OUT_OF_HOST_MEMORY + ); } header->header.instance_header = impl.instance_control_block, header->header.surface = vk_surface, diff --git a/tests/basic/platform_check.cpp b/tests/basic/platform_check.cpp index 8e0905dc..19cd829e 100644 --- a/tests/basic/platform_check.cpp +++ b/tests/basic/platform_check.cpp @@ -21,11 +21,11 @@ TEST_CASE("check_platform_support") &win32_extension.header, }; WisResult result = wisCreateInstance( - NULL, - extensions, - sizeof(extensions) / sizeof(WisInstanceExtensionHeader*), - &instance - ); + NULL, + extensions, + sizeof(extensions) / sizeof(WisInstanceExtensionHeader*), + &instance + ); // Expect partial success REQUIRE(result.status >= 0); From 5022d96b7bdc42cdd4c8ef2a3f0dd2d3943af277 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 13 Sep 2026 17:09:42 +0000 Subject: [PATCH 2/6] Restyled by black --- conanfile.py | 45 +++++++++++++++++++++------------------ test_package/conanfile.py | 1 + 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/conanfile.py b/conanfile.py index eff31720..14cc92f5 100644 --- a/conanfile.py +++ b/conanfile.py @@ -11,6 +11,7 @@ class WisdomConan(ConanFile): """ """ + name = "wisdom" package_type = "library" @@ -46,8 +47,9 @@ def requirements(self): """ """ # If windows platform support is enabled, we need to require the D3D12 Memory Allocator if self.settings.os == "Windows": - self.requires("d3d12-memory-allocator/[>=3.0.1 <4]", - transitive_headers=True) + self.requires( + "d3d12-memory-allocator/[>=3.0.1 <4]", transitive_headers=True + ) self.requires("vulkan-memory-allocator/3.3.0", transitive_headers=True) def export_sources(self): @@ -100,8 +102,7 @@ def generate(self): tc.variables["WISDOM_BUILD_EXAMPLES"] = False tc.variables["WISDOM_BUILD_TESTS"] = False tc.variables["WISDOM_BUILD_DOCS"] = False - tc.variables["WISDOM_BUILD_STATIC"] = not self.options.get_safe( - "shared") + tc.variables["WISDOM_BUILD_STATIC"] = not self.options.get_safe("shared") tc.variables["WISDOM_BUILD_SHARED"] = self.options.get_safe("shared") tc.variables["WISDOM_BUILD_PLATFORM"] = self.options.build_platform tc.variables["WISDOM_USE_AGILITY_SDK"] = False @@ -138,13 +139,15 @@ def package_info(self): if self.options.get_safe("shared"): # Core Shared self.cpp_info.components["core"].set_property( - "cmake_target_name", "wis::wisdom-shared") + "cmake_target_name", "wis::wisdom-shared" + ) self.cpp_info.components["core"].libs = [f"wisdom-shared{suffix}"] # Platform Shared if self.options.build_platform: self.cpp_info.components["platform"].set_property( - "cmake_target_name", "wis::wisdom-platform-shared") + "cmake_target_name", "wis::wisdom-platform-shared" + ) self.cpp_info.components["platform"].requires = ["core"] self.cpp_info.components["platform"].libs = [ f"wisdom-platform-shared{suffix}" @@ -152,29 +155,29 @@ def package_info(self): else: # Core Static self.cpp_info.components["core"].set_property( - "cmake_target_name", "wis::wisdom") - self.cpp_info.components["core"].libs = [ - f"wisdom{suffix}", f"vkma{suffix}" - ] + "cmake_target_name", "wis::wisdom" + ) + self.cpp_info.components["core"].libs = [f"wisdom{suffix}", f"vkma{suffix}"] # Platform Static if self.options.build_platform: self.cpp_info.components["platform"].set_property( - "cmake_target_name", "wis::wisdom-platform") + "cmake_target_name", "wis::wisdom-platform" + ) self.cpp_info.components["platform"].requires = ["core"] - self.cpp_info.components["platform"].libs = [ - f"wisdom-platform{suffix}" - ] + self.cpp_info.components["platform"].libs = [f"wisdom-platform{suffix}"] self.cpp_info.components["core"].requires = [ "vulkan-memory-allocator::vulkan-memory-allocator" ] if self.settings.os == "Windows": - self.cpp_info.components["core"].defines.extend([ - "D3D12MA_USING_DIRECTX_HEADERS=1", - "VK_USE_PLATFORM_WIN32_KHR=1", - ]) + self.cpp_info.components["core"].defines.extend( + [ + "D3D12MA_USING_DIRECTX_HEADERS=1", + "VK_USE_PLATFORM_WIN32_KHR=1", + ] + ) self.cpp_info.components["core"].requires.extend( - ["d3d12-memory-allocator::d3d12-memory-allocator"]) - self.cpp_info.components["core"].system_libs.extend( - ["dxgi", "DXGUID"]) + ["d3d12-memory-allocator::d3d12-memory-allocator"] + ) + self.cpp_info.components["core"].system_libs.extend(["dxgi", "DXGUID"]) diff --git a/test_package/conanfile.py b/test_package/conanfile.py index e5432794..0669a92e 100644 --- a/test_package/conanfile.py +++ b/test_package/conanfile.py @@ -9,6 +9,7 @@ class WisdomTestConan(ConanFile): """ """ + settings = "os", "compiler", "build_type", "arch" generators = "CMakeDeps" From d5ea1c12c0fe4f4a174e4a734fe14f63d5e1b7da Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 13 Sep 2026 17:09:50 +0000 Subject: [PATCH 3/6] Restyled by clang-format --- examples/compute_particles_c/entry_main.c | 130 ++- examples/hello_triangle/entry_main.c | 23 +- examples/hello_triangle/entry_main.cpp | 10 +- generator/bitmask.cpp | 110 +-- generator/entry_main.cpp | 10 +- generator/enum.cpp | 84 +- generator/function.cpp | 194 ++-- generator/generator.cpp | 354 ++++--- generator/generator.hpp | 18 +- generator/handle.cpp | 130 +-- generator/struct.cpp | 38 +- generator/types.hpp | 56 +- generator/validation.cpp | 2 +- generator/variant.cpp | 40 +- .../wisdom/dx12/detail/dx12_detail.hpp | 77 +- src/include/wisdom/dx12/dx12_command_list.cpp | 152 +-- .../wisdom/dx12/dx12_descriptor_heap.cpp | 78 +- src/include/wisdom/dx12/dx12_device.cpp | 342 ++++--- src/include/wisdom/dx12/dx12_impl.cpp | 30 +- .../wisdom/dx12/dx12_resource_allocator.cpp | 86 +- src/include/wisdom/generated/cpp_api.hpp | 916 ++++++++---------- src/include/wisdom/generated/dx12_convert.hpp | 28 +- src/include/wisdom/generated/vk_convert.hpp | 12 +- src/include/wisdom/global/internal.hpp | 12 +- .../wisdom/vulkan/detail/vk_detail.hpp | 52 +- src/include/wisdom/vulkan/detail/vk_ext1.hpp | 40 +- src/include/wisdom/vulkan/vk_command_list.cpp | 152 +-- .../wisdom/vulkan/vk_descriptor_heap.cpp | 38 +- src/include/wisdom/vulkan/vk_device.cpp | 482 +++++---- src/include/wisdom/vulkan/vk_extensions.hpp | 44 +- src/include/wisdom/vulkan/vk_impl.cpp | 16 +- .../wisdom/vulkan/vk_resource_allocator.cpp | 46 +- src/include/wisdom/vulkan/vk_swapchain.cpp | 70 +- src/include/wisdom/vulkan/vk_tables.hpp | 12 +- src/include/wisdom/wisdom.hpp | 20 +- .../wisdom_platform/generated/cpp_api.hpp | 120 +-- .../vulkan/vk_platform_wayland.cpp | 4 +- .../vulkan/vk_platform_win32.cpp | 4 +- .../vulkan/vk_platform_xcb.cpp | 4 +- .../vulkan/vk_platform_xlib.cpp | 4 +- tests/basic/platform_check.cpp | 10 +- 41 files changed, 1901 insertions(+), 2149 deletions(-) diff --git a/examples/compute_particles_c/entry_main.c b/examples/compute_particles_c/entry_main.c index d062621f..e2f7e8cb 100644 --- a/examples/compute_particles_c/entry_main.c +++ b/examples/compute_particles_c/entry_main.c @@ -268,10 +268,10 @@ void ResizeDepth(BasicRenderer* renderer, uint32_t width, uint32_t height) .memory_flags = WisMemoryFlagsNone, }; WisResult result = wisResourceAllocatorCreateTexture( - &renderer->allocator, - &depth_desc, - &renderer->depth_texture[i] - ); + &renderer->allocator, + &depth_desc, + &renderer->depth_texture[i] + ); printf( "CreateDepthTexture[%u] result: %d, platform_code: %d, error: %s\n", i, @@ -285,7 +285,7 @@ void ResizeDepth(BasicRenderer* renderer, uint32_t width, uint32_t height) .array_layer_count = 1, }; wisViewHeapWriteDepthStencil(&renderer->dsv_heap, &renderer->depth_texture[i], &dsv_desc, i); - barriers[i] = (WisTextureBarrier) { + barriers[i] = (WisTextureBarrier){ .sync_before = WisBarrierSyncNone, .sync_after = WisBarrierSyncNone, .access_before = WisResourceAccessNone, @@ -311,10 +311,10 @@ void ResizeDepth(BasicRenderer* renderer, uint32_t width, uint32_t height) // insert a fence result = wisCommandQueueSignalFence( - &renderer->gfx_queue, - wisGetFenceView(&renderer->aux_fence), - ++renderer->aux_fence_value - ); + &renderer->gfx_queue, + wisGetFenceView(&renderer->aux_fence), + ++renderer->aux_fence_value + ); result = wisFenceWait(&renderer->aux_fence, renderer->aux_fence_value, UINT64_MAX); } @@ -403,11 +403,11 @@ void InitRenderer(BasicRenderer* renderer, SDL_Window* window) WisInstanceExtensionHeader* extensions[] = {platform.platform_extension}; WisInstance instance = {0}; WisResult result = wisCreateInstance( - &debug_desc, - extensions, - sizeof(extensions) / sizeof(WisInstanceExtensionHeader*), - &instance - ); + &debug_desc, + extensions, + sizeof(extensions) / sizeof(WisInstanceExtensionHeader*), + &instance + ); printf( "CreateInstance result: %d, platform_code: %d, error: %s\n", result.status, @@ -433,10 +433,10 @@ void InitRenderer(BasicRenderer* renderer, SDL_Window* window) // Query format support and choose swapchain format bool present_support = wisDeviceGetFormatPresentationSupport( - &renderer->device, - wisGetSurfaceView(&surface), - WisDataFormatRGB10A2Unorm - ); + &renderer->device, + wisGetSurfaceView(&surface), + WisDataFormatRGB10A2Unorm + ); if (present_support) { renderer->swapchain_format = WisDataFormatRGB10A2Unorm; printf("Surface supports the desired swapchain format.\n"); @@ -458,12 +458,12 @@ void InitRenderer(BasicRenderer* renderer, SDL_Window* window) .composite_alpha = WisCompositeAlphaOpaque, }; result = wisDeviceCreateSwapchain( - &renderer->device, - &surface, - &renderer->gfx_queue, - &swapchain_desc, - &renderer->swapchain - ); + &renderer->device, + &surface, + &renderer->gfx_queue, + &swapchain_desc, + &renderer->swapchain + ); // Destroy instance as we no longer need it wisDestroySurface(&surface); @@ -489,10 +489,10 @@ void InitRenderer(BasicRenderer* renderer, SDL_Window* window) for (uint32_t i = 0; i < FRAMES_IN_FLIGHT; ++i) { result = wisDeviceCreateCommandAllocator( - &renderer->device, - WisCommandQueueTypeGraphics, - &renderer->frames[i].command_allocator - ); + &renderer->device, + WisCommandQueueTypeGraphics, + &renderer->frames[i].command_allocator + ); printf( "CreateCommandAllocator[%u] result: %d, platform_code: %d, error: %s\n", i, @@ -502,9 +502,9 @@ void InitRenderer(BasicRenderer* renderer, SDL_Window* window) ); result = wisCommandAllocatorCreateCommandList( - &renderer->frames[i].command_allocator, - &renderer->frames[i].command_list - ); + &renderer->frames[i].command_allocator, + &renderer->frames[i].command_list + ); printf( "CreateCommandList[%u] result: %d, platform_code: %d, error: %s\n", i, @@ -578,10 +578,10 @@ void DestoyRenderer(BasicRenderer* renderer) { if (renderer->next_fence_value > 0) { WisResult result = wisCommandQueueSignalFence( - &renderer->gfx_queue, - wisGetFenceView(&renderer->fence), - ++renderer->next_fence_value - ); + &renderer->gfx_queue, + wisGetFenceView(&renderer->fence), + ++renderer->next_fence_value + ); printf( "Flush SignalFence result: %d, platform_code: %d, error: %s\n", result.status, @@ -626,10 +626,10 @@ void DestoyRenderer(BasicRenderer* renderer) void WaitForFinish(BasicRenderer* renderer) { WisResult result = wisCommandQueueSignalFence( - &renderer->gfx_queue, - wisGetFenceView(&renderer->fence), - renderer->next_fence_value - ); + &renderer->gfx_queue, + wisGetFenceView(&renderer->fence), + renderer->next_fence_value + ); printf( "WaitForFinish SignalFence result: %d, platform_code: %d, error: %s\n", result.status, @@ -667,10 +667,10 @@ void InitRenderTask(BasicRenderTask* task, BasicRenderer* renderer) .push_descriptor_count = 1, }; WisResult result = wisDeviceCreateRootSignature( - &renderer->device, - &compute_root_signature_desc, - &task->compute_signature - ); + &renderer->device, + &compute_root_signature_desc, + &task->compute_signature + ); printf( "CreateRootSignature for ComputeShader result: %d, platform_code: %d, error: %s\n", result.status, @@ -797,10 +797,10 @@ void InitResourceContainer(ResourceContainer* container, BasicRenderer* renderer .memory_type = WisMemoryTypeDeviceLocal, }; WisResult result = wisResourceAllocatorCreateBuffer( - &renderer->allocator, - &particle_buffer_desc, - &container->particle_buffer - ); + &renderer->allocator, + &particle_buffer_desc, + &container->particle_buffer + ); printf( "Create ParticleBuffer result: %d, platform_code: %d, error: %s\n", result.status, @@ -1009,22 +1009,19 @@ void Render(BasicRenderer* renderer, const ResourceContainer* resources, const B WisRenderPassDesc render_pass_desc = { .flags = 0, .render_targets = - { { .target = swap_rt, - .load_op = WisLoadOpClear, - .store_op = WisStoreOpStore, - .clear_value = {0.5f, 1.0f, 1.0f, 1.0f} - } - }, + {{.target = swap_rt, + .load_op = WisLoadOpClear, + .store_op = WisStoreOpStore, + .clear_value = {0.5f, 1.0f, 1.0f, 1.0f}}}, .render_target_count = 1, .depth_stencil = - { .target = wisViewHeapGetViewAddress(&renderer->dsv_heap, renderer->frame_index), - .load_op_depth = WisLoadOpClear, - .load_op_stencil = WisLoadOpDontCare, - .store_op_depth = WisStoreOpStore, - .store_op_stencil = WisStoreOpDontCare, - .flags = WisDepthStencilFlagsIgnoreStencil, - .clear_depth = 1.0f - }, + {.target = wisViewHeapGetViewAddress(&renderer->dsv_heap, renderer->frame_index), + .load_op_depth = WisLoadOpClear, + .load_op_stencil = WisLoadOpDontCare, + .store_op_depth = WisStoreOpStore, + .store_op_stencil = WisStoreOpDontCare, + .flags = WisDepthStencilFlagsIgnoreStencil, + .clear_depth = 1.0f}, }; result = wisCommandListBegin(&frame->command_list); @@ -1088,10 +1085,10 @@ void Render(BasicRenderer* renderer, const ResourceContainer* resources, const B frame->fence_value = renderer->next_fence_value; result = wisCommandQueueSignalFence( - &renderer->gfx_queue, - wisGetFenceView(&renderer->fence), - renderer->next_fence_value - ); + &renderer->gfx_queue, + wisGetFenceView(&renderer->fence), + renderer->next_fence_value + ); print_info( "Frame[%u] SignalFence result: %d, platform_code: %d, error: %s\n", renderer->frame_index, @@ -1157,8 +1154,7 @@ void HandleEvents(bool* running, BasicRenderer* renderer) ResizeDepth(renderer, update_desc.width, update_desc.height); - } - break; + } break; default: break; } diff --git a/examples/hello_triangle/entry_main.c b/examples/hello_triangle/entry_main.c index 45ef4f6d..0bb39ee2 100644 --- a/examples/hello_triangle/entry_main.c +++ b/examples/hello_triangle/entry_main.c @@ -238,8 +238,8 @@ static bool init_app(HelloTriangleApp* app, SDL_Window* window) wisGetSurfaceView(&surface), WisDataFormatRGB10A2Unorm ) - ? WisDataFormatRGB10A2Unorm - : WisDataFormatBGRA8Unorm; + ? WisDataFormatRGB10A2Unorm + : WisDataFormatBGRA8Unorm; WisSwapchainDesc swapchain_desc = { .width = app->width, @@ -273,10 +273,10 @@ static bool init_app(HelloTriangleApp* app, SDL_Window* window) for (uint32_t i = 0; i < FRAMES_IN_FLIGHT; ++i) { result = wisDeviceCreateCommandAllocator( - &app->device, - WisCommandQueueTypeGraphics, - &app->frames[i].command_allocator - ); + &app->device, + WisCommandQueueTypeGraphics, + &app->frames[i].command_allocator + ); if (!check_result(result, "wisDeviceCreateCommandAllocator")) { return false; } @@ -453,12 +453,11 @@ static void draw_frame(HelloTriangleApp* app, float angle) WisRenderPassDesc render_pass = { .render_targets = {{ - .target = target_rtv, - .load_op = WisLoadOpClear, - .store_op = WisStoreOpStore, - .clear_value = {0.1f, 0.1f, 0.15f, 1.0f}, - } - }, + .target = target_rtv, + .load_op = WisLoadOpClear, + .store_op = WisStoreOpStore, + .clear_value = {0.1f, 0.1f, 0.15f, 1.0f}, + }}, .render_target_count = 1, }; diff --git a/examples/hello_triangle/entry_main.cpp b/examples/hello_triangle/entry_main.cpp index 5bc1ef16..1f03d8e7 100644 --- a/examples/hello_triangle/entry_main.cpp +++ b/examples/hello_triangle/entry_main.cpp @@ -33,14 +33,14 @@ struct HelloTriangleApp { uint64_t next_fence_value = 1; wis::Swapchain swapchain{}; - wis::Texture swapchain_textures[SWAPCHAIN_FRAMES] {}; + wis::Texture swapchain_textures[SWAPCHAIN_FRAMES]{}; wis::ViewHeap rtv_heap{}; wis::DataFormat swapchain_format = wis::DataFormat::BGRA8Unorm; wis::RootSignature root_signature{}; wis::Pipeline pipeline{}; - FrameContext frames[FRAMES_IN_FLIGHT] {}; + FrameContext frames[FRAMES_IN_FLIGHT]{}; uint32_t frame_index = 0; uint32_t width = 800; @@ -206,8 +206,8 @@ static bool init_app(HelloTriangleApp* app, SDL_Window* window) } app->swapchain_format = app->device.GetFormatPresentationSupport(surface.GetView(), wis::DataFormat::RGB10A2Unorm) - ? wis::DataFormat::RGB10A2Unorm - : wis::DataFormat::BGRA8Unorm; + ? wis::DataFormat::RGB10A2Unorm + : wis::DataFormat::BGRA8Unorm; wis::SwapchainDesc swapchain_desc = { .width = app->width, @@ -340,7 +340,7 @@ static void draw_frame(HelloTriangleApp* app, float angle) wis::Texture& target_texture = app->swapchain_textures[swapchain_index]; uint64_t target_rtv = app->rtv_heap.GetViewAddress(swapchain_index); - wis::TextureBarrier barriers[2] {}; + wis::TextureBarrier barriers[2]{}; barriers[0].sync_before = wis::BarrierSync::None; barriers[0].sync_after = wis::BarrierSync::RenderTarget; barriers[0].access_before = wis::ResourceAccess::None; diff --git a/generator/bitmask.cpp b/generator/bitmask.cpp index 0c529fed..2692c5ca 100644 --- a/generator/bitmask.cpp +++ b/generator/bitmask.cpp @@ -53,7 +53,7 @@ void Generator::ParseBitmask(tinyxml2::XMLElement* type) } for (auto* impl_type = type->FirstChildElement("impl_type"); impl_type; - impl_type = impl_type->NextSiblingElement("impl_type")) { + impl_type = impl_type->NextSiblingElement("impl_type")) { auto impl_for = impl_type->FindAttribute("for")->Value(); auto backend = ParseBackend(impl_for); auto impl_name = impl_type->FindAttribute("name")->Value(); @@ -114,11 +114,11 @@ std::string Generator::MakeCBitmask(const WisBitmask& s, DocKind kind) for (auto& m : s.values) { if (m.is_bit) { st_decl += MakeValueDocumentation( - s, - m, - std::format(" Wis{}{} = (1u << {}),", s.name, m.name, m.value_or_bit), - kind - ); + s, + m, + std::format(" Wis{}{} = (1u << {}),", s.name, m.name, m.value_or_bit), + kind + ); continue; } st_decl += MakeValueDocumentation(s, m, std::format(" Wis{}{} = {},", s.name, m.name, m.value_or_bit), kind); @@ -139,11 +139,11 @@ std::string Generator::MakeCPPBitmask(const WisBitmask& s, DocKind kind) for (auto& m : s.values) { if (m.is_bit) { st_decl += MakeValueDocumentation( - s, - m, - std::format(" {} = (1u << {}),", m.name, m.value_or_bit), - kind - ); + s, + m, + std::format(" {} = (1u << {}),", m.name, m.value_or_bit), + kind + ); continue; } st_decl += MakeValueDocumentation(s, m, std::format(" {} = {},", m.name, m.value_or_bit), kind); @@ -210,19 +210,19 @@ std::string Generator::MakeBitmaskConverter(const WisBitmask& s, Backend backend if (cvt.direct) { converters = std::format( - "constexpr inline {} {}Convert({} value) noexcept {{\n return static_cast<{}>(value);\n}}\n\n", - cvt.value, - backend_tag, - GetCFullTypename(s.name, backend), - cvt.value - ); + "constexpr inline {} {}Convert({} value) noexcept {{\n return static_cast<{}>(value);\n}}\n\n", + cvt.value, + backend_tag, + GetCFullTypename(s.name, backend), + cvt.value + ); } else { converters = std::format( - "constexpr inline {} {}Convert({} value) noexcept {{\n", - cvt.value, - backend_tag, - GetCFullTypename(s.name, backend) - ); + "constexpr inline {} {}Convert({} value) noexcept {{\n", + cvt.value, + backend_tag, + GetCFullTypename(s.name, backend) + ); // Start with default value converters += std::format(" {} result = static_cast<{}>(0);\n", cvt.value, cvt.value); @@ -233,12 +233,12 @@ std::string Generator::MakeBitmaskConverter(const WisBitmask& s, Backend backend continue; } converters += std::format( - " if (value & {}{}) {{ result = static_cast<{}>(result | {}); }}\n", - GetCFullTypename(s.name, backend), - m.name, - cvt.value, - convert_value - ); + " if (value & {}{}) {{ result = static_cast<{}>(result | {}); }}\n", + GetCFullTypename(s.name, backend), + m.name, + cvt.value, + convert_value + ); } } else { for (auto& m : s.values) { @@ -247,11 +247,11 @@ std::string Generator::MakeBitmaskConverter(const WisBitmask& s, Backend backend continue; } converters += std::format( - " if (value & {}{}) {{ result |= {}; }}\n", - GetCFullTypename(s.name, backend), - m.name, - convert_value - ); + " if (value & {}{}) {{ result |= {}; }}\n", + GetCFullTypename(s.name, backend), + m.name, + convert_value + ); } } @@ -261,19 +261,19 @@ std::string Generator::MakeBitmaskConverter(const WisBitmask& s, Backend backend if (cvt.convert_back) { if (cvt.direct) { converters += std::format( - "constexpr inline {} {}Convert({} value) noexcept {{\n return static_cast<{}>(value);\n}}\n\n", - wisdom_type, - backend_tag, - cvt.value, - wisdom_type - ); + "constexpr inline {} {}Convert({} value) noexcept {{\n return static_cast<{}>(value);\n}}\n\n", + wisdom_type, + backend_tag, + cvt.value, + wisdom_type + ); } else { converters += std::format( - "constexpr inline {} {}Convert({} value) noexcept {{\n", - wisdom_type, - backend_tag, - cvt.value - ); + "constexpr inline {} {}Convert({} value) noexcept {{\n", + wisdom_type, + backend_tag, + cvt.value + ); converters += std::format(" {} result = static_cast<{}>(0);\n", wisdom_type, wisdom_type); for (auto& m : s.values) { @@ -282,12 +282,12 @@ std::string Generator::MakeBitmaskConverter(const WisBitmask& s, Backend backend continue; } converters += std::format( - " if (value & {}) {{ result = static_cast<{}>(result | {}{}); }}\n", - convert_value, - wisdom_type, - wisdom_type, - m.name - ); + " if (value & {}) {{ result = static_cast<{}>(result | {}{}); }}\n", + convert_value, + wisdom_type, + wisdom_type, + m.name + ); } converters += std::format(" return result;\n}}\n\n"); @@ -310,11 +310,11 @@ void Generator::WriteBitmaskDocumentation(std::filesystem::path enum_output_path files.push_back(enum_file_path); std::string enum_template_content = std::format( - " * C version:\n```c\n{}```\n" - "C++ version:\n```cpp\nnamespace wis{{\n{}}}\n```\n", - MakeCBitmask(enum_ref, DocKind::VersionOnly), - MakeCPPBitmask(enum_ref, DocKind::VersionOnly) - ); + " * C version:\n```c\n{}```\n" + "C++ version:\n```cpp\nnamespace wis{{\n{}}}\n```\n", + MakeCBitmask(enum_ref, DocKind::VersionOnly), + MakeCPPBitmask(enum_ref, DocKind::VersionOnly) + ); std::string enum_description = std::format(" * {}", MakeBitmaskDescription(enum_ref)); std::string enum_refs = GetRefs(enum_name); ReplaceAll(enum_template_content, "\n", "\n * "); diff --git a/generator/entry_main.cpp b/generator/entry_main.cpp index 5d47afa0..5e0c425b 100644 --- a/generator/entry_main.cpp +++ b/generator/entry_main.cpp @@ -49,10 +49,10 @@ int main(int argc, char** argv) std::string_view arg = argv[1]; if (arg == "-h" || arg == "--help") { std::cout - << "Usage: " << argv[0] << " [module_name,...]\n" - << "If module_name is provided, generates API for that platform module. Otherwise, generates core API.\n" - << "Modules are stored in xml folder. For example, if module_name is 'platform', the generator will look " - "for 'xml/platform.xml' and generate API for it.\n"; + << "Usage: " << argv[0] << " [module_name,...]\n" + << "If module_name is provided, generates API for that platform module. Otherwise, generates core API.\n" + << "Modules are stored in xml folder. For example, if module_name is 'platform', the generator will look " + "for 'xml/platform.xml' and generate API for it.\n"; return 0; } @@ -64,7 +64,7 @@ int main(int argc, char** argv) size_t next_comma = arg.find(',', i); std::string_view platform_module_name = arg.substr(i, next_comma - i); auto module_path = std::filesystem::path(input_file).parent_path() - / (std::string(platform_module_name) + std::string(".xml")); + / (std::string(platform_module_name) + std::string(".xml")); g.ParseFile(module_path); g.WriteModuleAPI(); diff --git a/generator/enum.cpp b/generator/enum.cpp index e5933d53..a301b5cd 100644 --- a/generator/enum.cpp +++ b/generator/enum.cpp @@ -53,7 +53,7 @@ void Generator::ParseEnum(tinyxml2::XMLElement* type) } for (auto* impl_type = type->FirstChildElement("impl_type"); impl_type; - impl_type = impl_type->NextSiblingElement("impl_type")) { + impl_type = impl_type->NextSiblingElement("impl_type")) { auto impl_for = impl_type->FindAttribute("for")->Value(); auto backend = ParseBackend(impl_for); auto impl_name = impl_type->FindAttribute("name")->Value(); @@ -145,11 +145,11 @@ void Generator::WriteEnumDocumentation(std::filesystem::path enum_output_path) files.push_back(enum_file_path); std::string enum_template_content = std::format( - " * C version:\n```c\n{}```\n" - "C++ version:\n```cpp\nnamespace wis{{\n{}}}\n```\n", - MakeCEnum(enum_ref, DocKind::VersionOnly), - MakeCPPEnum(enum_ref, DocKind::VersionOnly) - ); + " * C version:\n```c\n{}```\n" + "C++ version:\n```cpp\nnamespace wis{{\n{}}}\n```\n", + MakeCEnum(enum_ref, DocKind::VersionOnly), + MakeCPPEnum(enum_ref, DocKind::VersionOnly) + ); std::string enum_description = std::format(" * {}", MakeEnumDescription(enum_ref)); std::string enum_refs = GetRefs(enum_name); ReplaceAll(enum_template_content, "\n", "\n * "); @@ -192,11 +192,11 @@ std::string Generator::MakeEnumDescription(const WisEnum& s) } translates += std::format( - "{} `{}` for {} implementation", - has_translate ? ", and" : "", - cvt.value, - impl_names[i] - ); + "{} `{}` for {} implementation", + has_translate ? ", and" : "", + cvt.value, + impl_names[i] + ); has_translate = true; } if (has_translate) { @@ -223,29 +223,29 @@ std::string Generator::MakeEnumConverter(const WisEnum& s, Backend backend) if (cvt.direct) { converters = std::format( - "constexpr inline {} {}Convert({} value) noexcept {{\n return static_cast<{}>(value);\n}}\n\n", - cvt.value, - backend_tag, - GetCFullTypename(s.name, backend), - cvt.value - ); + "constexpr inline {} {}Convert({} value) noexcept {{\n return static_cast<{}>(value);\n}}\n\n", + cvt.value, + backend_tag, + GetCFullTypename(s.name, backend), + cvt.value + ); } else { converters = std::format( - "constexpr inline {} {}Convert({} value) noexcept {{\n switch(value) {{\n", - cvt.value, - backend_tag, - GetCFullTypename(s.name, backend) - ); + "constexpr inline {} {}Convert({} value) noexcept {{\n switch(value) {{\n", + cvt.value, + backend_tag, + GetCFullTypename(s.name, backend) + ); for (auto& m : s.values) { auto convert_value = m.converts[static_cast(backend)]; if (convert_value.empty()) { continue; } converters += std::format( - " case {}: return {};\n", - std::format("{}{}", GetCFullTypename(s.name, backend), m.name), - convert_value - ); + " case {}: return {};\n", + std::format("{}{}", GetCFullTypename(s.name, backend), m.name), + convert_value + ); } if (!cvt.default_value.empty()) { @@ -258,19 +258,19 @@ std::string Generator::MakeEnumConverter(const WisEnum& s, Backend backend) if (cvt.convert_back) { if (cvt.direct) { converters += std::format( - "constexpr inline {} {}Convert({} value) noexcept {{\n return static_cast<{}>(value);\n}}\n\n", - wisdom_type, - backend_tag, - cvt.value, - wisdom_type - ); + "constexpr inline {} {}Convert({} value) noexcept {{\n return static_cast<{}>(value);\n}}\n\n", + wisdom_type, + backend_tag, + cvt.value, + wisdom_type + ); } else { converters += std::format( - "constexpr inline {} {}Convert({} value) noexcept {{\n", - wisdom_type, - backend_tag, - cvt.value - ); + "constexpr inline {} {}Convert({} value) noexcept {{\n", + wisdom_type, + backend_tag, + cvt.value + ); for (auto& m : s.values) { auto convert_value = m.converts[static_cast(backend)]; @@ -278,11 +278,11 @@ std::string Generator::MakeEnumConverter(const WisEnum& s, Backend backend) continue; } converters += std::format( - " if (value == {}) {{ return {}{}; }}\n", - convert_value, - wisdom_type, - m.name - ); + " if (value == {}) {{ return {}{}; }}\n", + convert_value, + wisdom_type, + m.name + ); } converters += std::format(" return static_cast<{}>(0);\n}}\n\n", wisdom_type); diff --git a/generator/function.cpp b/generator/function.cpp index e6c92fe7..3ecc1284 100644 --- a/generator/function.cpp +++ b/generator/function.cpp @@ -196,8 +196,8 @@ std::string Generator::MakeCFunctionProto( } else if (func.return_type.has_result) { full_return_type = GetCFullTypename("Result", Backend::Any); std::string arg_name = func.return_type.opt_name.empty() - ? std::format("out_{}", MakeSnakeCase(func.return_type.type)) - : std::string(func.return_type.opt_name); + ? std::format("out_{}", MakeSnakeCase(func.return_type.type)) + : std::string(func.return_type.opt_name); std::string prefix = ""; size_t length = full_return_type.size() + 1 + pre_decl.size() + 1 + function_full_name.size(); @@ -262,14 +262,14 @@ std::string Generator::MakeCFunctionProto( } return std::format( - "{}{} {}({}{}{});\n", - pre_decl, - full_return_type, - function_full_name, - this_arg, - params.empty() && !post_return.empty() ? ",\n" : params.c_str(), - post_return - ); + "{}{} {}({}{}{});\n", + pre_decl, + full_return_type, + function_full_name, + this_arg, + params.empty() && !post_return.empty() ? ",\n" : params.c_str(), + post_return + ); } //---------------------------------------------------------------------------------------------------------------------- @@ -305,23 +305,23 @@ std::string Generator::MakeCPPFunctionProto( break; case Direct: full_return_type = GetMemberTypeString( - func.return_type, - type != ProtoType::Universal ? backend : Backend::Any - ); + func.return_type, + type != ProtoType::Universal ? backend : Backend::Any + ); break; case ResultOnly: full_return_type = "wis::Result"; break; case ResultAndValue: full_return_type = GetMemberTypeString( - func.return_type, - type != ProtoType::Universal ? backend : Backend::Any - ); + func.return_type, + type != ProtoType::Universal ? backend : Backend::Any + ); // Add out parameter for result { std::string prefix = ""; size_t length = full_return_type.size() + 1 + pre_decl.size() + 1 + func.name.size() + func_prefix.size() - + xclass_code.size(); + + xclass_code.size(); if (func.parameters.size() > 0) { prefix = ",\n" + std::string(length, ' '); } @@ -336,7 +336,7 @@ std::string Generator::MakeCPPFunctionProto( } size_t length = full_return_type.size() + 1 + pre_decl.size() + 1 + func.name.size() + func_prefix.size() - + xclass_code.size(); + + xclass_code.size(); size_t max_arg_length = post_return_length; // account for spans @@ -390,27 +390,27 @@ std::string Generator::MakeCPPFunctionProto( } if ((func.modifier & Modifier::Construct) != 0) { return std::format( - "{}{}{}{}({}{}){} noexcept;\n", - func_prefix, - xclass_code, - func_prefix, - std::string_view(xclass_code.begin(), xclass_code.end() - 2), - params, - post_return, - func.modifier & Modifier::Const ? " const" : "" - ); + "{}{}{}{}({}{}){} noexcept;\n", + func_prefix, + xclass_code, + func_prefix, + std::string_view(xclass_code.begin(), xclass_code.end() - 2), + params, + post_return, + func.modifier & Modifier::Const ? " const" : "" + ); } return std::format( - "{}{} {}{}{}({}{}){} noexcept;\n", - pre_decl, - full_return_type, - func_prefix, - xclass_code, - func.name, - params, - post_return, - func.modifier & Modifier::Const ? " const" : "" - ); + "{}{} {}{}{}({}{}){} noexcept;\n", + pre_decl, + full_return_type, + func_prefix, + xclass_code, + func.name, + params, + post_return, + func.modifier & Modifier::Const ? " const" : "" + ); } //---------------------------------------------------------------------------------------------------------------------- @@ -482,21 +482,21 @@ std::string Generator::MakeCPPFunctionImpl( switch (func.return_type.GetKind()) { case ReturnTypeKind::ResultAndValue: { auto ret_value_name = func.return_type.opt_name.empty() - ? std::format("out_{}", MakeSnakeCase(func.return_type.type)) - : std::string(func.return_type.opt_name); + ? std::format("out_{}", MakeSnakeCase(func.return_type.type)) + : std::string(func.return_type.opt_name); // Prepare out parameter body += std::format( - " {} {}{{}};\n", - GetMemberTypeString(func.return_type, backend), - ret_value_name - ); + " {} {}{{}};\n", + GetMemberTypeString(func.return_type, backend), + ret_value_name + ); body += std::format( - " const WisResult wis_result = ::{}({}", - c_name, - func.this_type.empty() ? "" : "&_impl_storage" - ); + " const WisResult wis_result = ::{}({}", + c_name, + func.this_type.empty() ? "" : "&_impl_storage" + ); if (func.parameters.size() > 0 && !func.this_type.empty()) { body += arg_prefix; @@ -510,22 +510,21 @@ std::string Generator::MakeCPPFunctionImpl( body += std::format(", {}.GetStorage());\n", ret_value_name); } else { body += std::format( - ", reinterpret_cast<{}*>(&{}));\n", - GetMemberTypeString(func.return_type, backend), - ret_value_name - ); + ", reinterpret_cast<{}*>(&{}));\n", + GetMemberTypeString(func.return_type, backend), + ret_value_name + ); } body += " out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, " "wis_result.error };\n"; body += std::format(" return {};\n", ret_value_name); - } - break; + } break; case ReturnTypeKind::ResultOnly: { body += std::format( - " const WisResult wis_result = ::{}({}", - c_name, - func.this_type.empty() ? "" : "&_impl_storage" - ); + " const WisResult wis_result = ::{}({}", + c_name, + func.this_type.empty() ? "" : "&_impl_storage" + ); constexpr static std::string_view arg_prefix = ",\n "; if (func.parameters.size() > 0 && !func.this_type.empty()) { body += arg_prefix; @@ -534,8 +533,7 @@ std::string Generator::MakeCPPFunctionImpl( body += ");\n"; body += " return wis::Result{ static_cast(wis_result.status), wis_result.platform_code, " "wis_result.error };\n"; - } - break; + } break; case ReturnTypeKind::Direct: { auto ret_type = GetType(func.return_type.type); std::string return_cast; @@ -553,26 +551,25 @@ std::string Generator::MakeCPPFunctionImpl( break; default: return_cast = std::format( - "reinterpret_cast<{}>", - GetMemberTypeString(func.return_type, backend) - ); + "reinterpret_cast<{}>", + GetMemberTypeString(func.return_type, backend) + ); break; } body += std::format( - " return {}(::{}({}", - return_cast, - c_name, - func.this_type.empty() ? "" : "&_impl_storage" - ); + " return {}(::{}({}", + return_cast, + c_name, + func.this_type.empty() ? "" : "&_impl_storage" + ); constexpr static std::string_view arg_prefix = ",\n "; if (func.parameters.size() > 0 && !func.this_type.empty()) { body += arg_prefix; } body += GetFunctionCallParameters(func, backend); body += "));\n"; - } - break; + } break; case ReturnTypeKind::Void: { body += std::format(" ::{}({}", c_name, func.this_type.empty() ? "" : "&_impl_storage"); constexpr static std::string_view arg_prefix = ",\n "; @@ -581,8 +578,7 @@ std::string Generator::MakeCPPFunctionImpl( } body += GetFunctionCallParameters(func, backend); body += ");\n"; - } - break; + } break; default: break; } @@ -623,18 +619,18 @@ std::string Generator::MakeFunctionDescription(const WisFunction& s) if (!s.this_type.empty()) { if (s.modifier & Modifier::Construct) { description += std::format( - "- **this** `self` is a pointer to uninitialized {{{}::}} instance memory. It will be initialized by " - "this function.\n", - s.this_type - ); + "- **this** `self` is a pointer to uninitialized {{{}::}} instance memory. It will be initialized by " + "this function.\n", + s.this_type + ); // There must also be a note about the destroy function in the description description += std::format("**note** The corresponding destroy function is `wisDestroy{}`.\n", s.this_type); } else { description += std::format( - "- **this** `self` self is a pointer to the valid {{{}::}} instance.\n", - s.this_type - ); + "- **this** `self` self is a pointer to the valid {{{}::}} instance.\n", + s.this_type + ); } } @@ -645,21 +641,21 @@ std::string Generator::MakeFunctionDescription(const WisFunction& s) switch (s.return_type.GetKind()) { case ReturnTypeKind::Direct: description += std::format( - "\n- **return** {}\n", - s.return_type.doc.empty() ? "No description." : s.return_type.doc - ); + "\n- **return** {}\n", + s.return_type.doc.empty() ? "No description." : s.return_type.doc + ); break; case ReturnTypeKind::ResultOnly: description += std::format("\n- **return** denoting the outcome of operation.\n"); break; case ReturnTypeKind::ResultAndValue: { std::string arg_name = s.return_type.opt_name.empty() ? std::format("out_{}", MakeSnakeCase(s.return_type.type)) - : std::string(s.return_type.opt_name); + : std::string(s.return_type.opt_name); description += std::format( - "- `{}` {}\n", - s.return_type.opt_name.empty() ? "value" : s.return_type.opt_name, - s.return_type.doc.empty() ? "No description." : s.return_type.doc - ); + "- `{}` {}\n", + s.return_type.opt_name.empty() ? "value" : s.return_type.opt_name, + s.return_type.doc.empty() ? "No description." : s.return_type.doc + ); description += std::format("\n- **return** denoting the outcome of operation.\n"); break; } @@ -688,10 +684,10 @@ void Generator::WriteFunctionDocumentation(std::filesystem::path func_output_pat for (auto& func_name : function_names) { auto& func_def = function_map[func_name]; std::string full_func_name = std::format( - "wis{}{}", - func_def.modifier & (Destroy | Construct) ? "" : func_def.this_type, - func_def.name - ); + "wis{}{}", + func_def.modifier & (Destroy | Construct) ? "" : func_def.this_type, + func_def.name + ); auto func_doc_path = func_output_path / std::format("{}_function.h", MakeSnakeCase(full_func_name.substr(3))); files.push_back(func_doc_path); @@ -709,18 +705,18 @@ void Generator::WriteFunctionDocumentation(std::filesystem::path func_output_pat } std::string vk_code_cpp = func_def.modifier & Modifier::Destroy || !supports_vk - ? "" - : MakeCPPFunctionImpl(func_def, Backend::Vulkan, "", DocKind::VersionOnly); + ? "" + : MakeCPPFunctionImpl(func_def, Backend::Vulkan, "", DocKind::VersionOnly); std::string dx_code_cpp = func_def.modifier & Modifier::Destroy || !supports_dx - ? "" - : MakeCPPFunctionImpl(func_def, Backend::DX12, "", DocKind::VersionOnly); + ? "" + : MakeCPPFunctionImpl(func_def, Backend::DX12, "", DocKind::VersionOnly); std::string regular_code_cpp = func_def.modifier & Modifier::Destroy || !(supports_vk && supports_dx) - ? "" - : MakeCPPFunctionImpl(func_def, Backend::Any, "", DocKind::VersionOnly); + ? "" + : MakeCPPFunctionImpl(func_def, Backend::Any, "", DocKind::VersionOnly); std::string cpp_code = regular_code_cpp; std::string cpp_impl_code = func_def.modifier & Modifier::Destroy || !(supports_vk && supports_dx) - ? "" - : vk_code_cpp + '\n' + dx_code_cpp; + ? "" + : vk_code_cpp + '\n' + dx_code_cpp; if (cpp_code.empty()) { cpp_code = !vk_code_cpp.empty() ? vk_code_cpp : dx_code_cpp; } @@ -753,7 +749,7 @@ void Generator::WriteDelegateDocumentation(std::filesystem::path func_output_pat for (auto& delegate_name : module_map.at(active_module_name).delegates_in_order) { auto full_delegate_name = GetCFullTypename(delegate_name, Backend::Any); auto delegate_doc_path = func_output_path - / std::format("{}_delegate.h", MakeSnakeCase(full_delegate_name.substr(3))); + / std::format("{}_delegate.h", MakeSnakeCase(full_delegate_name.substr(3))); auto& delegate_def = delegate_map[delegate_name]; files.push_back(delegate_doc_path); diff --git a/generator/generator.cpp b/generator/generator.cpp index 93b31506..1f454c7f 100644 --- a/generator/generator.cpp +++ b/generator/generator.cpp @@ -18,7 +18,7 @@ void Generator::ParseFile(std::filesystem::path file) bool has_modules = false; for (auto* module_node = root->FirstChildElement("module"); module_node; - module_node = module_node->NextSiblingElement("module")) { + module_node = module_node->NextSiblingElement("module")) { has_modules = true; auto* module_attr = module_node->FindAttribute("name"); @@ -140,7 +140,7 @@ void Generator::ParseRegistrySections(tinyxml2::XMLElement* root) void Generator::ParseIncludes(tinyxml2::XMLElement* includes) { for (auto* include = includes->FirstChildElement("include"); include; - include = include->NextSiblingElement("include")) { + include = include->NextSiblingElement("include")) { auto file = include->GetText(); auto rpath = std::filesystem::path(INPUT_FILE).parent_path() / file; auto absolute = std::filesystem::absolute(rpath); @@ -185,8 +185,8 @@ void Generator::WriteCAPI(std::filesystem::path dir) auto& module = module_map.at(active_module_name); bool has_independent_api = !module.enums_in_order.empty() || !module.bitmasks_in_order.empty() - || !module.structs_in_order.empty() || !module.constants_in_order.empty() - || !module.delegates_in_order.empty() || !module.functions_in_order.empty(); + || !module.structs_in_order.empty() || !module.constants_in_order.empty() + || !module.delegates_in_order.empty() || !module.functions_in_order.empty(); auto path = dir / "c_api.h"; if (!has_independent_api) { @@ -207,12 +207,12 @@ void Generator::WriteCAPI(std::filesystem::path dir) #include #include )" - : R"(#include + : R"(#include #include "wisdom_exports.h" )"; auto api_macro = module.name == "Core" ? "WIS_INLINE WISDOM_API " - : std::format("WIS_INLINE WISDOM_{}_API ", header_guard); + : std::format("WIS_INLINE WISDOM_{}_API ", header_guard); // Write header // clang-format off @@ -229,8 +229,8 @@ extern "C" {{ if (!module.enums_in_order.empty() || !module.bitmasks_in_order.empty()) { file << "\n//==============================================================\n" - "// Enums\n" - "//==============================================================\n\n"; + "// Enums\n" + "//==============================================================\n\n"; // Write enums for (auto& enum_name : module.enums_in_order) { @@ -249,8 +249,8 @@ extern "C" {{ if (!module.delegates_in_order.empty()) { file << "\n//==============================================================\n" - "// Delegates\n" - "//==============================================================\n\n"; + "// Delegates\n" + "//==============================================================\n\n"; // Write delegates (before structs, as structs may reference delegates) for (auto& delegate_name : module.delegates_in_order) { auto& delegate_def = delegate_map[delegate_name]; @@ -261,8 +261,8 @@ extern "C" {{ if (!module.structs_in_order.empty()) { file << "\n//==============================================================\n" - "// Structs\n" - "//==============================================================\n\n"; + "// Structs\n" + "//==============================================================\n\n"; // Write structs for (auto& struct_name : module.structs_in_order) { auto& struct_def = struct_map[struct_name]; @@ -273,8 +273,8 @@ extern "C" {{ if (!module.constants_in_order.empty()) { file << "\n//==============================================================\n" - "// Constants\n" - "//==============================================================\n\n"; + "// Constants\n" + "//==============================================================\n\n"; // Write constants for (auto& const_name : module.constants_in_order) { auto& const_def = constant_map[const_name]; @@ -368,8 +368,8 @@ void Generator::WriteCPPAPI(std::filesystem::path dir) { auto& module = module_map.at(active_module_name); bool has_independent_api = !module.enums_in_order.empty() || !module.bitmasks_in_order.empty() - || !module.structs_in_order.empty() || !module.constants_in_order.empty() - || !module.delegates_in_order.empty() || !module.functions_in_order.empty(); + || !module.structs_in_order.empty() || !module.constants_in_order.empty() + || !module.delegates_in_order.empty() || !module.functions_in_order.empty(); auto path = dir / "cpp_api.hpp"; if (!has_independent_api) { @@ -390,7 +390,7 @@ void Generator::WriteCPPAPI(std::filesystem::path dir) #include #include "c_api.h" )" - : R"(#include + : R"(#include #include "wisdom_exports.h" #include "c_api.h" )"; @@ -412,8 +412,8 @@ namespace wis {{ if (!module.enums_in_order.empty() || !module.bitmasks_in_order.empty()) { file << "\n//==============================================================\n" - "// Enums\n" - "//==============================================================\n\n"; + "// Enums\n" + "//==============================================================\n\n"; // Write enums for (auto& enum_name : module.enums_in_order) { @@ -432,8 +432,8 @@ namespace wis {{ if (!module.delegates_in_order.empty()) { file << "\n//==============================================================\n" - "// Delegates\n" - "//==============================================================\n\n"; + "// Delegates\n" + "//==============================================================\n\n"; // Write delegates (before structs, as structs may reference delegates) for (auto& delegate_name : module.delegates_in_order) { auto& delegate_def = delegate_map[delegate_name]; @@ -444,8 +444,8 @@ namespace wis {{ if (!module.structs_in_order.empty()) { file << "\n//==============================================================\n" - "// Structs\n" - "//==============================================================\n\n"; + "// Structs\n" + "//==============================================================\n\n"; // Write structs for (auto& struct_name : module.structs_in_order) { auto& struct_def = struct_map[struct_name]; @@ -456,8 +456,8 @@ namespace wis {{ if (!module.constants_in_order.empty()) { file << "\n//==============================================================\n" - "// Constants\n" - "//==============================================================\n\n"; + "// Constants\n" + "//==============================================================\n\n"; // Write constants for (auto& const_name : module.constants_in_order) { auto& const_def = constant_map[const_name]; @@ -467,7 +467,7 @@ namespace wis {{ } file << std::format( - R"( + R"( }} // namespace wis #ifdef WISDOM_DX12 @@ -475,8 +475,8 @@ namespace wis {{ namespace wis {{ )", - include_root - ); + include_root + ); // Write Views for handles for (auto& handle_name : module.views_in_order) { @@ -517,7 +517,7 @@ namespace wis {{ } file << std::format( - R"( + R"( }} // namespace wis #endif // WISDOM_DX12 @@ -526,8 +526,8 @@ namespace wis {{ namespace wis {{ )", - include_root - ); + include_root + ); // Write Views for handles for (auto& handle_name : module.views_in_order) { @@ -585,14 +585,14 @@ void Generator::WriteCIndependentAPI(std::filesystem::path dir) auto& module = module_map.at(active_module_name); auto independent_name = module.name == "Core" ? std::string("wisdom") - : std::format("wisdom_{}", MakeSnakeCase(module.name)); + : std::format("wisdom_{}", MakeSnakeCase(module.name)); auto module_folder = std::filesystem::path(module.gen_path).filename().generic_string(); if (module_folder.empty()) { module_folder = std::filesystem::path(module.gen_path).parent_path().filename().generic_string(); } auto backend_include = module_folder == "wisdom" ? std::string("generated/c_api.h") - : std::format("../{}/generated/c_api.h", module_folder); + : std::format("../{}/generated/c_api.h", module_folder); auto header_guard = std::format("WISDOM_{}_H", MakeUpperSnakeCase(module.name)); std::filesystem::path path_w = dir / (independent_name + ".h"); @@ -605,7 +605,7 @@ void Generator::WriteCIndependentAPI(std::filesystem::path dir) // Write header file_w << std::format( - R"(// This file is generated. Do not edit directly. + R"(// This file is generated. Do not edit directly. #ifndef {0} #define {0} @@ -625,9 +625,9 @@ static_assert(WISDOM_UWP && _WIN32, "Platform error"); #if defined(WISDOM_DX12) && !FORCEVK_SWITCH )", - header_guard, - backend_include - ); + header_guard, + backend_include + ); constexpr static auto impl_dx = GetBackendSuffix(Backend::DX12); constexpr static auto impl_vk = GetBackendSuffix(Backend::Vulkan); @@ -661,18 +661,18 @@ static_assert(WISDOM_UWP && _WIN32, "Platform error"); if (dx_has_handles) { file_w << "\n\n//==============================================================\n" - "// Handles\n" - "//==============================================================\n\n"; + "// Handles\n" + "//==============================================================\n\n"; // Write handles for (auto& handle_name : module.handles_in_order) { auto& handle_def = handle_map[handle_name]; if (has(handle_def.GetBackend(), Backend::DX12)) { file_w << std::format( - "typedef struct {} {};\n", - GetCFullTypename(handle_def.name, Backend::DX12), - GetCFullTypename(handle_def.name) - ); + "typedef struct {} {};\n", + GetCFullTypename(handle_def.name, Backend::DX12), + GetCFullTypename(handle_def.name) + ); } } @@ -681,46 +681,46 @@ static_assert(WISDOM_UWP && _WIN32, "Platform error"); auto& handle_def = handle_map[handle_name]; if (handle_def.GetViewSize(Backend::DX12) > 0) { file_w << std::format( - "typedef struct {}View {}View;\n", - GetCFullTypename(handle_def.name, Backend::DX12), - GetCFullTypename(handle_def.name) - ); + "typedef struct {}View {}View;\n", + GetCFullTypename(handle_def.name, Backend::DX12), + GetCFullTypename(handle_def.name) + ); } } } if (dx_has_variants) { file_w << "\n\n//==============================================================\n" - "// Variants\n" - "//==============================================================\n\n"; + "// Variants\n" + "//==============================================================\n\n"; // Write variants for (auto& variant_name : module.variants_in_order) { auto& variant_def = variant_map[variant_name]; if (has(variant_def.backend, Backend::DX12)) { file_w << std::format( - "typedef struct {} {};\n", - GetCFullTypename(variant_def.name, Backend::DX12), - GetCFullTypename(variant_def.name) - ); + "typedef struct {} {};\n", + GetCFullTypename(variant_def.name, Backend::DX12), + GetCFullTypename(variant_def.name) + ); } } } file_w << "\n\n//==============================================================\n" - "// Functions\n" - "//==============================================================\n\n"; + "// Functions\n" + "//==============================================================\n\n"; // Write view getters for handles for (auto& handle_name : module.handles_in_order) { auto& handle_def = handle_map[handle_name]; if (has(handle_def.GetBackend(), Backend::DX12) && handle_def.GetViewSize(Backend::DX12) > 0) { file_w << std::format( - "#define wisGet{}View wisGet{}{}View\n", - handle_def.name, - GetBackendSuffix(Backend::DX12), - handle_def.name - ); + "#define wisGet{}View wisGet{}{}View\n", + handle_def.name, + GetBackendSuffix(Backend::DX12), + handle_def.name + ); } } @@ -729,10 +729,10 @@ static_assert(WISDOM_UWP && _WIN32, "Platform error"); auto& func_def = function_map[func_name]; if (has(func_def.backend, Backend::DX12)) { file_w << std::format( - "#define {} {}\n", - GetCFullFunctionName(func_name), - GetCFullFunctionName(func_name, Backend::DX12) - ); + "#define {} {}\n", + GetCFullFunctionName(func_name), + GetCFullFunctionName(func_name, Backend::DX12) + ); } } @@ -770,18 +770,18 @@ static_assert(WISDOM_UWP && _WIN32, "Platform error"); if (vk_has_handles) { file_w << "\n\n//==============================================================\n" - "// Handles\n" - "//==============================================================\n\n"; + "// Handles\n" + "//==============================================================\n\n"; // Write handles for (auto& handle_name : module.handles_in_order) { auto& handle_def = handle_map[handle_name]; if (has(handle_def.GetBackend(), Backend::Vulkan)) { file_w << std::format( - "typedef struct {} {};\n", - GetCFullTypename(handle_def.name, Backend::Vulkan), - GetCFullTypename(handle_def.name) - ); + "typedef struct {} {};\n", + GetCFullTypename(handle_def.name, Backend::Vulkan), + GetCFullTypename(handle_def.name) + ); } } @@ -790,46 +790,46 @@ static_assert(WISDOM_UWP && _WIN32, "Platform error"); auto& handle_def = handle_map[handle_name]; if (handle_def.GetViewSize(Backend::Vulkan) > 0) { file_w << std::format( - "typedef struct {}View {}View;\n", - GetCFullTypename(handle_def.name, Backend::Vulkan), - GetCFullTypename(handle_def.name) - ); + "typedef struct {}View {}View;\n", + GetCFullTypename(handle_def.name, Backend::Vulkan), + GetCFullTypename(handle_def.name) + ); } } } if (vk_has_variants) { file_w << "\n\n//==============================================================\n" - "// Variants\n" - "//==============================================================\n\n"; + "// Variants\n" + "//==============================================================\n\n"; // Write variants for (auto& variant_name : module.variants_in_order) { auto& variant_def = variant_map[variant_name]; if (has(variant_def.backend, Backend::Vulkan)) { file_w << std::format( - "typedef struct {} {};\n", - GetCFullTypename(variant_def.name, Backend::Vulkan), - GetCFullTypename(variant_def.name) - ); + "typedef struct {} {};\n", + GetCFullTypename(variant_def.name, Backend::Vulkan), + GetCFullTypename(variant_def.name) + ); } } } file_w << "\n\n//==============================================================\n" - "// Functions\n" - "//==============================================================\n\n"; + "// Functions\n" + "//==============================================================\n\n"; // Write view getters for handles for (auto& handle_name : module.handles_in_order) { auto& handle_def = handle_map[handle_name]; if (has(handle_def.GetBackend(), Backend::Vulkan) && handle_def.GetViewSize(Backend::Vulkan) > 0) { file_w << std::format( - "#define wisGet{}View wisGet{}{}View\n", - handle_def.name, - GetBackendSuffix(Backend::Vulkan), - handle_def.name - ); + "#define wisGet{}View wisGet{}{}View\n", + handle_def.name, + GetBackendSuffix(Backend::Vulkan), + handle_def.name + ); } } @@ -838,10 +838,10 @@ static_assert(WISDOM_UWP && _WIN32, "Platform error"); auto& func_def = function_map[func_name]; if (has(func_def.backend, Backend::Vulkan)) { file_w << std::format( - "#define {} {}\n", - GetCFullFunctionName(func_name), - GetCFullFunctionName(func_name, Backend::Vulkan) - ); + "#define {} {}\n", + GetCFullFunctionName(func_name), + GetCFullFunctionName(func_name, Backend::Vulkan) + ); } } @@ -869,14 +869,14 @@ void Generator::WriteCPPIndependentAPI(std::filesystem::path dir) auto& module = module_map.at(active_module_name); auto independent_name = module.name == "Core" ? std::string("wisdom") - : std::format("wisdom_{}", MakeSnakeCase(module.name)); + : std::format("wisdom_{}", MakeSnakeCase(module.name)); auto module_folder = std::filesystem::path(module.gen_path).filename().generic_string(); if (module_folder.empty()) { module_folder = std::filesystem::path(module.gen_path).parent_path().filename().generic_string(); } auto backend_include = module_folder == "wisdom" ? std::string("generated/cpp_api.hpp") - : std::format("../{}/generated/cpp_api.hpp", module_folder); + : std::format("../{}/generated/cpp_api.hpp", module_folder); auto header_guard = std::format("WISDOM_{}_HPP", MakeUpperSnakeCase(module.name)); std::filesystem::path path_w = dir / (independent_name + ".hpp"); @@ -889,7 +889,7 @@ void Generator::WriteCPPIndependentAPI(std::filesystem::path dir) // Write header file_w << std::format( - R"(// This file is generated. Do not edit directly. + R"(// This file is generated. Do not edit directly. #ifndef {0} #define {0} @@ -911,9 +911,9 @@ void Generator::WriteCPPIndependentAPI(std::filesystem::path dir) namespace wis {{ )", - header_guard, - backend_include - ); + header_guard, + backend_include + ); if (module.name == "Core") { file_w << "static constexpr wis::ShaderIntermediate shader_intermediate = wis::ShaderIntermediate::DXIL;\n"; @@ -954,18 +954,18 @@ namespace wis {{ if (dx_has_handles) { file_w << "\n\n//==============================================================\n" - "// Handles\n" - "//==============================================================\n\n"; + "// Handles\n" + "//==============================================================\n\n"; // Write handles for (auto& handle_name : module.handles_in_order) { auto& handle_def = handle_map[handle_name]; if (has(handle_def.GetBackend(), Backend::DX12)) { file_w << std::format( - "using {} = {};\n", - handle_def.name, - GetCPPFullTypename(handle_def.name, Backend::DX12) - ); + "using {} = {};\n", + handle_def.name, + GetCPPFullTypename(handle_def.name, Backend::DX12) + ); } } @@ -974,36 +974,36 @@ namespace wis {{ auto& handle_def = handle_map[handle_name]; if (handle_def.GetViewSize(Backend::DX12) > 0) { file_w << std::format( - "using {}View = {};\n", - handle_def.name, - GetCPPFullTypename(handle_def.name, Backend::DX12) + "View" - ); + "using {}View = {};\n", + handle_def.name, + GetCPPFullTypename(handle_def.name, Backend::DX12) + "View" + ); } } } if (dx_has_variants) { file_w << "\n\n//==============================================================\n" - "// Variants\n" - "//==============================================================\n\n"; + "// Variants\n" + "//==============================================================\n\n"; // Write variants for (auto& variant_name : module.variants_in_order) { auto& variant_def = variant_map[variant_name]; if (has(variant_def.backend, Backend::DX12)) { file_w << std::format( - "using {} = {};\n", - variant_def.name, - GetCPPFullTypename(variant_def.name, Backend::DX12) - ); + "using {} = {};\n", + variant_def.name, + GetCPPFullTypename(variant_def.name, Backend::DX12) + ); } } } if (dx_has_functions) { file_w << "\n\n//==============================================================\n" - "// Functions\n" - "//==============================================================\n\n"; + "// Functions\n" + "//==============================================================\n\n"; // Write functions for (auto& func_name : module.free_functions_in_order) { @@ -1063,18 +1063,18 @@ namespace wis { if (vk_has_handles) { file_w << "\n\n//==============================================================\n" - "// Handles\n" - "//==============================================================\n\n"; + "// Handles\n" + "//==============================================================\n\n"; // Write handles for (auto& handle_name : module.handles_in_order) { auto& handle_def = handle_map[handle_name]; if (has(handle_def.GetBackend(), Backend::Vulkan)) { file_w << std::format( - "using {} = {};\n", - handle_def.name, - GetCPPFullTypename(handle_def.name, Backend::Vulkan) - ); + "using {} = {};\n", + handle_def.name, + GetCPPFullTypename(handle_def.name, Backend::Vulkan) + ); } } @@ -1083,36 +1083,36 @@ namespace wis { auto& handle_def = handle_map[handle_name]; if (handle_def.GetViewSize(Backend::Vulkan) > 0) { file_w << std::format( - "using {}View = {};\n", - handle_def.name, - GetCPPFullTypename(handle_def.name, Backend::Vulkan) + "View" - ); + "using {}View = {};\n", + handle_def.name, + GetCPPFullTypename(handle_def.name, Backend::Vulkan) + "View" + ); } } } if (vk_has_variants) { file_w << "\n\n//==============================================================\n" - "// Variants\n" - "//==============================================================\n\n"; + "// Variants\n" + "//==============================================================\n\n"; // Write variants for (auto& variant_name : module.variants_in_order) { auto& variant_def = variant_map[variant_name]; if (has(variant_def.backend, Backend::Vulkan)) { file_w << std::format( - "using {} = {};\n", - variant_def.name, - GetCPPFullTypename(variant_def.name, Backend::Vulkan) - ); + "using {} = {};\n", + variant_def.name, + GetCPPFullTypename(variant_def.name, Backend::Vulkan) + ); } } } if (vk_has_functions) { file_w << "\n\n//==============================================================\n" - "// Functions\n" - "//==============================================================\n\n"; + "// Functions\n" + "//==============================================================\n\n"; // Write functions for (auto& func_name : module.free_functions_in_order) { @@ -1120,7 +1120,7 @@ namespace wis { auto& func_def = function_map[key]; if (has(func_def.backend, Backend::Vulkan)) { file_w - << MakeCPPFunctionImpl(func_def, Backend::Vulkan, "inline ", DocKind::Full, ProtoType::Universal); + << MakeCPPFunctionImpl(func_def, Backend::Vulkan, "inline ", DocKind::Full, ProtoType::Universal); file_w << '\n'; } } @@ -1161,7 +1161,7 @@ void Generator::WriteConversions(std::filesystem::path dir) // Write header file_dx << std::format( - R"(// This file is generated. Do not edit directly. + R"(// This file is generated. Do not edit directly. #ifndef WISDOM_{0}_CPP_DX12_CONVERT_HPP #define WISDOM_{0}_CPP_DX12_CONVERT_HPP #ifndef __cplusplus @@ -1174,10 +1174,10 @@ void Generator::WriteConversions(std::filesystem::path dir) namespace wis{{ namespace detail {{ )", - header_guard - ); + header_guard + ); file_vk << std::format( - R"(// This file is generated. Do not edit directly. + R"(// This file is generated. Do not edit directly. #ifndef WISDOM_{0}_CPP_VK_CONVERT_HPP #define WISDOM_{0}_CPP_VK_CONVERT_HPP #ifndef __cplusplus @@ -1190,8 +1190,8 @@ namespace wis{{ namespace detail {{ namespace wis{{ namespace detail {{ )", - header_guard - ); + header_guard + ); // Write enums for (auto& enum_name : module.enums_in_order) { @@ -1212,19 +1212,19 @@ namespace wis{{ namespace detail {{ // Write footer file_dx << std::format( - R"( + R"( }}}} #endif // WISDOM_{}_CPP_DX12_CONVERT_HPP )", - header_guard - ); + header_guard + ); file_vk << std::format( - R"( + R"( }}}} #endif // WISDOM_{}_CPP_VK_CONVERT_HPP )", - header_guard - ); + header_guard + ); } void Generator::WriteDocumentation( @@ -1247,9 +1247,9 @@ void Generator::WriteDocumentation( if (!file_exists) { std::string xenum = std::vformat( - doc_template, - std::make_format_args(object_name, code, desc, active_module_name) - ); + doc_template, + std::make_format_args(object_name, code, desc, active_module_name) + ); enum_file << FinalizeCDocumentation(xenum, object_name); enum_file.close(); @@ -1279,22 +1279,22 @@ void Generator::WriteDocumentation( // Replace the references section if (ref_start != std::string::npos && ref_end != std::string::npos && ref_end > ref_start) { existing_content = existing_content.substr(0, ref_start) + "\\cond WIS_GEN_REFS\n" + std::string(refs) - + existing_content.substr(ref_end); + + existing_content.substr(ref_end); } // Replace the vuids section if (vuid_start != std::string::npos && vuid_end != std::string::npos && vuid_end > vuid_start) { existing_content = existing_content.substr(0, vuid_start) + "\\cond WIS_GEN_WIS_IDS\n" + std::string(vuids) - + existing_content.substr(vuid_end); + + existing_content.substr(vuid_end); } // Replace the description section if (desc_start != std::string::npos && desc_end != std::string::npos && desc_end > desc_start) { existing_content = existing_content.substr(0, desc_start) + "\\cond WIS_GEN_DESC\n" + std::string(desc) - + existing_content.substr(desc_end); + + existing_content.substr(desc_end); } // Replace the generated section if (gen_start != std::string::npos && gen_end != std::string::npos && gen_end > gen_start) { existing_content = existing_content.substr(0, gen_start) + "\\cond WIS_GEN_CODE\n" + std::string(code) - + existing_content.substr(gen_end); + + existing_content.substr(gen_end); } // Write back to file @@ -1360,9 +1360,7 @@ void Generator::TryMakeRef(std::string_view type, std::string_view ref) } } -void Generator::TryMakeRef(std::string_view type, FunctionKey ref) { - dependency_tree[type].functions.push_back(ref); -} +void Generator::TryMakeRef(std::string_view type, FunctionKey ref) { dependency_tree[type].functions.push_back(ref); } std::string Generator::GetCFullTypename(std::string_view type, Backend backend) { @@ -1461,35 +1459,35 @@ std::string Generator::FinalizeCDocumentation(std::string doc, std::string_view auto& x = enum_map.at(this_type_view); auto evalue = x.HasValue(value); replacement = evalue ? std::format("`{}{}`", GetCFullTypename(x.name, backend), evalue->name) - : GetCFullTypename(x.name, backend); + : GetCFullTypename(x.name, backend); break; } case TypeKind::Bitmask: { auto& b = bitmask_map.at(this_type_view); auto evalue = b.HasValue(value); replacement = evalue ? std::format("`{}{}`", GetCFullTypename(b.name, backend), evalue->name) - : GetCFullTypename(b.name, backend); + : GetCFullTypename(b.name, backend); break; } case TypeKind::Struct: { auto& s = struct_map.at(this_type_view); auto member = s.HasValue(value); replacement = member ? std::format("`{}::{}`", GetCFullTypename(s.name, backend), member->name) - : GetCFullTypename(s.name, backend); + : GetCFullTypename(s.name, backend); break; } case TypeKind::Variant: { auto& v = variant_map.at(this_type_view); auto m = v.HasValue(value); replacement = m ? std::format("`{}::{}`", GetCFullTypename(v.name, backend), m->name) - : GetCFullTypename(v.name, backend); + : GetCFullTypename(v.name, backend); break; } case TypeKind::FuncPointer: { auto& d = delegate_map.at(this_type_view); auto m = d.HasValue(value); replacement = m ? std::format("`{}::{}`", GetCFullTypename(d.name, backend), m->name) - : GetCFullTypename(d.name, backend); + : GetCFullTypename(d.name, backend); break; } case TypeKind::Handle: { @@ -1578,35 +1576,35 @@ std::string Generator::FinalizeCPPDocumentation(std::string doc, std::string_vie auto& x = enum_map.at(this_type_view); auto evalue = x.HasValue(value); replacement = evalue ? std::format("`{}::{}`", GetCPPFullTypename(x.name, backend), evalue->name) - : GetCPPFullTypename(x.name, backend); + : GetCPPFullTypename(x.name, backend); break; } case TypeKind::Bitmask: { auto& b = bitmask_map.at(this_type_view); auto evalue = b.HasValue(value); replacement = evalue ? std::format("`{}::{}`", GetCPPFullTypename(b.name, backend), evalue->name) - : GetCPPFullTypename(b.name, backend); + : GetCPPFullTypename(b.name, backend); break; } case TypeKind::Struct: { auto& s = struct_map.at(this_type_view); auto member = s.HasValue(value); replacement = member ? std::format("`{}::{}`", GetCPPFullTypename(s.name, backend), member->name) - : GetCPPFullTypename(s.name, backend); + : GetCPPFullTypename(s.name, backend); break; } case TypeKind::Variant: { auto& v = variant_map.at(this_type_view); auto m = v.HasValue(value); replacement = m ? std::format("`{}::{}`", GetCPPFullTypename(v.name, backend), m->name) - : GetCPPFullTypename(v.name, backend); + : GetCPPFullTypename(v.name, backend); break; } case TypeKind::FuncPointer: { auto& d = delegate_map.at(this_type_view); auto m = d.HasValue(value); replacement = m ? std::format("`{}::{}`", GetCPPFullTypename(d.name, backend), m->name) - : GetCPPFullTypename(d.name, backend); + : GetCPPFullTypename(d.name, backend); break; } case TypeKind::Handle: { @@ -1678,9 +1676,9 @@ std::string Generator::GetSpecificationCode( if (!c_impl_code.empty()) { // append a details section template_content_c += std::format( - "
\nC Implementation Specific Version:\n```c\n{}```\n
\n", - c_impl_code - ); + "
\nC Implementation Specific Version:\n```c\n{}```\n
\n", + c_impl_code + ); } } @@ -1690,10 +1688,10 @@ std::string Generator::GetSpecificationCode( if (!cpp_impl_code.empty()) { // append a details section template_content_cpp += std::format( - "
\nC++ Implementation Specific Version:\n```cpp\nnamespace " - "wis{{\n{}}}\n```\n
\n", - cpp_impl_code - ); + "
\nC++ Implementation Specific Version:\n```cpp\nnamespace " + "wis{{\n{}}}\n```\n
\n", + cpp_impl_code + ); } } @@ -1944,11 +1942,11 @@ std::string Generator::GetFunctionCallParameters(const WisFunction& func, Backen if (p.modifier & Modifier::Span) { body += std::format( - "reinterpret_cast<{}>({}.data()), {}.size()", - GetMemberTypeString(p, backend), - p.name, - p.name - ); + "reinterpret_cast<{}>({}.data()), {}.size()", + GetMemberTypeString(p, backend), + p.name, + p.name + ); i++; // skip next parameter (the size) if (i < func.parameters.size() - 1) { body += arg_prefix; diff --git a/generator/generator.hpp b/generator/generator.hpp index a46fd561..8464737c 100644 --- a/generator/generator.hpp +++ b/generator/generator.hpp @@ -25,9 +25,7 @@ class Generator void ParseFile(std::filesystem::path file); void WriteModuleAPI(); void WriteModuleAPIDoc(std::string_view module_name = {}); - auto GetFiles() const { - return std::span {files}; - } + auto GetFiles() const { return std::span{files}; } public: void ParseIncludes(tinyxml2::XMLElement* includes); @@ -255,7 +253,7 @@ class Generator } } return pre_doc ? std::format(" {}\n {}\n", documentation, value_decl) - : std::format("{}{}\n", value_decl, documentation); + : std::format("{}{}\n", value_decl, documentation); } template @@ -269,9 +267,9 @@ class Generator // This arg if (!type.this_type.empty()) { args += std::format( - "@param self is a pointer to the valid {{{}::}} instance.\n", - type.this_type - ); + "@param self is a pointer to the valid {{{}::}} instance.\n", + type.this_type + ); } // Function arguments @@ -356,9 +354,9 @@ class Generator } if (member.modifier & Modifier::Span) { return std::format( - "wis::span<{}>", - attributes_pre + GetCPPFullTypename(member.type, backend) + attributes_inter - ); + "wis::span<{}>", + attributes_pre + GetCPPFullTypename(member.type, backend) + attributes_inter + ); } return attributes_pre + GetCPPFullTypename(member.type, backend) + attributes_inter; } else { diff --git a/generator/handle.cpp b/generator/handle.cpp index 2d55414b..e4fb52d6 100644 --- a/generator/handle.cpp +++ b/generator/handle.cpp @@ -169,10 +169,10 @@ std::string Generator::MakeCHandle(const WisHandle& s, Backend backend, DocKind auto impl_string = GetBackendSuffix(backend); auto extends_macro = s.extends == Extends::None - ? std::string("WIS_DEFINE_HANDLE") - : (s.extends == Extends::Instance - ? std::format("WIS_DEFINE_{}_INSTANCE_EXT_HANDLE", impl_string) - : std::format("WIS_DEFINE_{}_DEVICE_EXT_HANDLE", impl_string)); + ? std::string("WIS_DEFINE_HANDLE") + : (s.extends == Extends::Instance + ? std::format("WIS_DEFINE_{}_INSTANCE_EXT_HANDLE", impl_string) + : std::format("WIS_DEFINE_{}_DEVICE_EXT_HANDLE", impl_string)); auto full_name = GetCFullTypename(s.name, backend); @@ -191,12 +191,12 @@ std::string Generator::MakeCHandle(const WisHandle& s, Backend backend, DocKind auto view_name = s.view_override.empty() ? full_name : GetCFullTypename(s.view_override, backend); st_decl += std::format( - "\nstatic inline {}View wisGet{}{}View(const {}* handle){{\n", - view_name, - impl_string, - s.name, - full_name - ); + "\nstatic inline {}View wisGet{}{}View(const {}* handle){{\n", + view_name, + impl_string, + s.name, + full_name + ); st_decl += std::format(" {}View v;\n", view_name); st_decl += " memcpy(&v, handle, sizeof(v));\n" " return v;\n}\n"; @@ -212,23 +212,23 @@ std::string Generator::MakeCPPHandle(const WisHandle& s, Backend backend, DocKin auto full_name = GetCFullTypename(s.name, backend); std::string deleter = std::format( - "struct {}{}Deleter {{\n " - "void operator()({}* handle) noexcept {{\n ", - impl_string, - s.name, - full_name - ); + "struct {}{}Deleter {{\n " + "void operator()({}* handle) noexcept {{\n ", + impl_string, + s.name, + full_name + ); std::string st_decl = std::format( - "class {}{} : public wis::impl::Implements{{\npublic:\n", - impl_string, - s.name, - impl_string, - s.name, - full_name, - impl_string, - s.name - ); + "class {}{} : public wis::impl::Implements{{\npublic:\n", + impl_string, + s.name, + impl_string, + s.name, + full_name, + impl_string, + s.name + ); if (!s.doc.empty()) { std::string xdoc = MakeTypeDocumentation(s, kind); @@ -246,25 +246,25 @@ std::string Generator::MakeCPPHandle(const WisHandle& s, Backend backend, DocKin // Strict aliasing rules prevent us from doing a simple cast, so we have to memcpy the data to a new view struct auto view_name = s.view_override.empty() ? s.name : s.view_override; st_decl2 += std::format( - " WIS_NODISCARD {}{}View GetView() const noexcept {{\n" - " {}{}View v;\n" - " std::memcpy(&v, &_impl_storage, sizeof(v));\n" - " return v;\n" - " }}\n", - impl_string, - view_name, - impl_string, - view_name - ); + " WIS_NODISCARD {}{}View GetView() const noexcept {{\n" + " {}{}View v;\n" + " std::memcpy(&v, &_impl_storage, sizeof(v));\n" + " return v;\n" + " }}\n", + impl_string, + view_name, + impl_string, + view_name + ); // add conversion operator to view st_decl2 += std::format( - " WIS_NODISCARD operator {}{}View() const noexcept {{\n" - " return GetView();\n" - " }}\n", - impl_string, - view_name - ); + " WIS_NODISCARD operator {}{}View() const noexcept {{\n" + " return GetView();\n" + " }}\n", + impl_string, + view_name + ); } // Add all the functions @@ -272,11 +272,11 @@ std::string Generator::MakeCPPHandle(const WisHandle& s, Backend backend, DocKin FunctionKey func_key{s.name, func_name}; auto& func_ref = function_map[func_key]; auto c_name = std::format( - "wis{}{}{}", - impl_string, - func_ref.modifier & (Destroy | Construct) ? "" : func_ref.this_type, - func_ref.name - ); + "wis{}{}{}", + impl_string, + func_ref.modifier & (Destroy | Construct) ? "" : func_ref.this_type, + func_ref.name + ); if (func_ref.modifier & Modifier::Destroy) { deleter += std::format(" ::{}(handle);\n", c_name); continue; @@ -315,17 +315,17 @@ std::string Generator::MakeCPPHandle(const WisHandle& s, Backend backend, DocKin } ctor_decl += std::format( - " {}{}({}) noexcept\n" - " :ImplType(wis::in_place)\n" - " {{\n" - " ::{}({});\n" - " }}\n", - impl_string, - s.name, - params, - c_name, - args - ); + " {}{}({}) noexcept\n" + " :ImplType(wis::in_place)\n" + " {{\n" + " ::{}({});\n" + " }}\n", + impl_string, + s.name, + params, + c_name, + args + ); continue; } @@ -334,14 +334,14 @@ std::string Generator::MakeCPPHandle(const WisHandle& s, Backend backend, DocKin if (s.extends != Extends::None) { auto header = s.extends == Extends::Instance ? GetCPPFullTypename("InstanceExtensionHeader", backend) - : GetCPPFullTypename("DeviceExtensionHeader", backend); + : GetCPPFullTypename("DeviceExtensionHeader", backend); ctor_decl += std::format( - " // Operator & overload\n" - "{}* operator&() noexcept {{\n" - " return &GetMutableInternal().header;\n" - "}}\n", - header - ); + " // Operator & overload\n" + "{}* operator&() noexcept {{\n" + " return &GetMutableInternal().header;\n" + "}}\n", + header + ); } deleter += " }\n};\n"; @@ -372,7 +372,7 @@ void Generator::WriteHandleDocumentation(std::filesystem::path handle_output_pat // Make a folder for enums starting with this letter std::filesystem::create_directories(handle_output_path); std::filesystem::path handle_file_path = handle_output_path - / std::format("{}_handle.h", MakeSnakeCase(handle_name)); + / std::format("{}_handle.h", MakeSnakeCase(handle_name)); auto& handle_ref = handle_map[handle_name]; files.push_back(handle_file_path); diff --git a/generator/struct.cpp b/generator/struct.cpp index 514eb8c6..8a4cbd3f 100644 --- a/generator/struct.cpp +++ b/generator/struct.cpp @@ -91,10 +91,10 @@ std::string Generator::MakeCStruct(const WisStruct& s, DocKind kind) { auto full_name = GetCFullTypename(s.name, Backend::Any); std::string st_decl = std::format( - "typedef struct {} {} {{\n", - s.modifier & Modifier::Nodiscard ? "WIS_NODISCARD" : "", - full_name - ); + "typedef struct {} {} {{\n", + s.modifier & Modifier::Nodiscard ? "WIS_NODISCARD" : "", + full_name + ); if (!s.doc.empty()) { std::string xdoc = MakeTypeDocumentation(s, kind); st_decl = std::format("{}\n{}", xdoc, st_decl); @@ -118,10 +118,10 @@ std::string Generator::MakeCStruct(const WisStruct& s, DocKind kind) std::string Generator::MakeCPPStruct(const WisStruct& s, DocKind kind) { std::string st_decl = std::format( - "struct {} {} {{\n", - s.modifier & Modifier::Nodiscard ? "WIS_NODISCARD" : "", - s.name - ); + "struct {} {} {{\n", + s.modifier & Modifier::Nodiscard ? "WIS_NODISCARD" : "", + s.name + ); if (!s.doc.empty()) { std::string xdoc = MakeTypeDocumentation(s, kind); st_decl = std::format("{}\n{}", xdoc, st_decl); @@ -142,11 +142,11 @@ std::string Generator::MakeCPPStruct(const WisStruct& s, DocKind kind) } st_decl += MakeValueDocumentation( - s, - m, - MakeCPPMemberDeclaration(m, max_type_length, Backend::Any), - kind - ); + s, + m, + MakeCPPMemberDeclaration(m, max_type_length, Backend::Any), + kind + ); prev_span = m.modifier & Modifier::Span; } st_decl += "};\n"; @@ -213,16 +213,16 @@ void Generator::WriteStructDocumentation(std::filesystem::path struct_output_pat for (const auto& struct_name : struct_names) { // Make a folder for enums starting with this letter std::filesystem::path struct_file_path = struct_output_path - / std::format("{}_struct.h", MakeSnakeCase(struct_name)); + / std::format("{}_struct.h", MakeSnakeCase(struct_name)); auto& struct_ref = struct_map[struct_name]; files.push_back(struct_file_path); std::string struct_template_content = std::format( - " * C version:\n```c\n{}```\n" - "C++ version:\n```cpp\nnamespace wis{{\n{}}}\n```\n", - MakeCStruct(struct_ref, DocKind::VersionOnly), - MakeCPPStruct(struct_ref, DocKind::VersionOnly) - ); + " * C version:\n```c\n{}```\n" + "C++ version:\n```cpp\nnamespace wis{{\n{}}}\n```\n", + MakeCStruct(struct_ref, DocKind::VersionOnly), + MakeCPPStruct(struct_ref, DocKind::VersionOnly) + ); std::string struct_description = std::format(" * {}", MakeStructDescription(struct_ref)); std::string struct_refs = GetRefs(struct_name); diff --git a/generator/types.hpp b/generator/types.hpp index 5d99f4cb..dfe6932c 100644 --- a/generator/types.hpp +++ b/generator/types.hpp @@ -41,9 +41,7 @@ constexpr Backend operator&(Backend a, Backend b) { return static_cast(static_cast(a) & static_cast(b)); } -constexpr bool has(Backend a, Backend b) { - return (a & b) == b; -} +constexpr bool has(Backend a, Backend b) { return (a & b) == b; } enum class ImplOs { None, @@ -120,11 +118,8 @@ struct WisEnum { public: std::optional HasValue(std::string_view name) const noexcept { - auto enum_value = std::find_if(values.begin(), values.end(), [&](auto& v) { - return v.name == name; - }); - return enum_value != values.end() ? std::optional {*enum_value} : - std::nullopt; + auto enum_value = std::find_if(values.begin(), values.end(), [&](auto& v) { return v.name == name; }); + return enum_value != values.end() ? std::optional{*enum_value} : std::nullopt; } }; @@ -147,11 +142,8 @@ struct WisBitmask { public: std::optional HasValue(std::string_view name) const noexcept { - auto enum_value = std::find_if(values.begin(), values.end(), [&](auto& v) { - return v.name == name; - }); - return enum_value != values.end() ? std::optional {*enum_value} : - std::nullopt; + auto enum_value = std::find_if(values.begin(), values.end(), [&](auto& v) { return v.name == name; }); + return enum_value != values.end() ? std::optional{*enum_value} : std::nullopt; } }; @@ -182,14 +174,10 @@ struct WisStruct { return {}; } - auto enum_value = std::find_if(members.begin(), members.end(), [&](auto& v) { - return v.name == name; - }); + auto enum_value = std::find_if(members.begin(), members.end(), [&](auto& v) { return v.name == name; }); return *enum_value; } - void FilterBackend(Backend b) { - backend = backend & b; - } + void FilterBackend(Backend b) { backend = backend & b; } }; //---------------------------------------------------------------------------------------------------------------------- @@ -268,18 +256,10 @@ struct WisReturnType { return ReturnTypeKind::ResultAndValue; } - bool IsVoid() const noexcept { - return type.empty() && !has_result; - } - bool IsRV() const noexcept { - return has_result && !type.empty(); - } - bool IsDirect() const noexcept { - return !has_result && !type.empty(); - } - bool IsResultOnly() const noexcept { - return has_result && type.empty(); - } + bool IsVoid() const noexcept { return type.empty() && !has_result; } + bool IsRV() const noexcept { return has_result && !type.empty(); } + bool IsDirect() const noexcept { return !has_result && !type.empty(); } + bool IsResultOnly() const noexcept { return has_result && type.empty(); } }; struct WisFunction { std::string_view name; @@ -298,9 +278,7 @@ struct WisFunction { if (name.empty()) { return {}; } - auto enum_value = std::find_if(parameters.begin(), parameters.end(), [&](auto& v) { - return v.name == name; - }); + auto enum_value = std::find_if(parameters.begin(), parameters.end(), [&](auto& v) { return v.name == name; }); if (enum_value == parameters.end()) { // it can be return value if (return_type.opt_name == name) { @@ -318,13 +296,9 @@ struct WisFunction { } // constructor or destructor - bool IsCD() const noexcept { - return modifier & (Modifier::Construct | Modifier::Destroy); - } + bool IsCD() const noexcept { return modifier & (Modifier::Construct | Modifier::Destroy); } - void FilterBackend(Backend b) { - backend = backend & b; - } + void FilterBackend(Backend b) { backend = backend & b; } }; static inline constexpr Severity from_chars(std::string_view input) noexcept @@ -368,7 +342,7 @@ template <> struct hash { std::size_t operator()(const FunctionKey& k) const noexcept { - return std::hash {}(k.first) ^ (std::hash {}(k.second) << 1); + return std::hash{}(k.first) ^ (std::hash{}(k.second) << 1); } }; } // namespace std diff --git a/generator/validation.cpp b/generator/validation.cpp index 640e7ef3..33388eed 100644 --- a/generator/validation.cpp +++ b/generator/validation.cpp @@ -4,7 +4,7 @@ void Generator::ParseValidations(tinyxml2::XMLElement* validations) { for (auto* validation = validations->FirstChildElement("validation"); validation; - validation = validation->NextSiblingElement("validation")) { + validation = validation->NextSiblingElement("validation")) { auto name = validation->FindAttribute("for")->Value(); auto& ref = validation_map[name]; diff --git a/generator/variant.cpp b/generator/variant.cpp index fc5affd3..2b7deb44 100644 --- a/generator/variant.cpp +++ b/generator/variant.cpp @@ -91,10 +91,10 @@ std::string Generator::MakeCVariant(const WisStruct& s, Backend backend, DocKind auto impl_suffix = GetBackendSuffix(backend); auto full_name = GetCFullTypename(s.name, backend); std::string st_decl = std::format( - "typedef struct {}{} {{\n", - s.modifier & Modifier::Nodiscard ? "WIS_NODISCARD " : "", - full_name - ); + "typedef struct {}{} {{\n", + s.modifier & Modifier::Nodiscard ? "WIS_NODISCARD " : "", + full_name + ); if (!s.doc.empty()) { std::string xdoc = MakeTypeDocumentation(s, kind); st_decl = std::format("{}\n{}", xdoc, st_decl); @@ -123,11 +123,11 @@ std::string Generator::MakeCPPVariant(const WisStruct& s, Backend backend, DocKi auto impl_suffix = GetBackendSuffix(backend); std::string st_decl = std::format( - "struct {}{}{} {{\n", - s.modifier & Modifier::Nodiscard ? "WIS_NODISCARD " : "", - impl_suffix, - s.name - ); + "struct {}{}{} {{\n", + s.modifier & Modifier::Nodiscard ? "WIS_NODISCARD " : "", + impl_suffix, + s.name + ); if (!s.doc.empty()) { std::string xdoc = MakeTypeDocumentation(s, kind); st_decl = std::format("{}\n{}", xdoc, st_decl); @@ -171,7 +171,7 @@ void Generator::WriteVariantDocumentation(std::filesystem::path struct_output_pa for (const auto& variant_name : variant_names) { // Make a folder for enums starting with this letter std::filesystem::path variant_file_path = struct_output_path - / std::format("{}_struct.h", MakeSnakeCase(variant_name)); + / std::format("{}_struct.h", MakeSnakeCase(variant_name)); auto& variant_ref = variant_map[variant_name]; files.push_back(variant_file_path); @@ -181,8 +181,8 @@ void Generator::WriteVariantDocumentation(std::filesystem::path struct_output_pa std::string vk_code = supports_vk ? MakeCVariant(variant_ref, Backend::Vulkan, DocKind::VersionOnly) : ""; std::string dx_code = supports_dx ? MakeCVariant(variant_ref, Backend::DX12, DocKind::VersionOnly) : ""; std::string regular_code = supports_vk && supports_dx - ? MakeCVariant(variant_ref, Backend::Any, DocKind::VersionOnly) - : ""; + ? MakeCVariant(variant_ref, Backend::Any, DocKind::VersionOnly) + : ""; std::string c_code = regular_code; std::string cimpl_code = supports_vk && supports_dx ? (vk_code + '\n' + dx_code) : ""; @@ -191,18 +191,18 @@ void Generator::WriteVariantDocumentation(std::filesystem::path struct_output_pa } std::string vk_cpp = variant_ref.modifier & Modifier::COnly || !supports_vk - ? "" - : MakeCPPVariant(variant_ref, Backend::Vulkan, DocKind::VersionOnly); + ? "" + : MakeCPPVariant(variant_ref, Backend::Vulkan, DocKind::VersionOnly); std::string dx_cpp = variant_ref.modifier & Modifier::COnly || !supports_dx - ? "" - : MakeCPPVariant(variant_ref, Backend::DX12, DocKind::VersionOnly); + ? "" + : MakeCPPVariant(variant_ref, Backend::DX12, DocKind::VersionOnly); std::string regular_code_cpp = variant_ref.modifier & Modifier::COnly || !(supports_vk && supports_dx) - ? "" - : MakeCPPVariant(variant_ref, Backend::Any, DocKind::VersionOnly); + ? "" + : MakeCPPVariant(variant_ref, Backend::Any, DocKind::VersionOnly); std::string cpp_code = regular_code_cpp; std::string cimpl_code_cpp = variant_ref.modifier & Modifier::COnly || !(supports_vk && supports_dx) - ? "" - : vk_cpp + '\n' + dx_cpp; + ? "" + : vk_cpp + '\n' + dx_cpp; if (cpp_code.empty()) { cpp_code = !vk_cpp.empty() ? vk_cpp : dx_cpp; } diff --git a/src/include/wisdom/dx12/detail/dx12_detail.hpp b/src/include/wisdom/dx12/detail/dx12_detail.hpp index 71d982f3..262d5ad8 100644 --- a/src/include/wisdom/dx12/detail/dx12_detail.hpp +++ b/src/include/wisdom/dx12/detail/dx12_detail.hpp @@ -57,11 +57,11 @@ struct DX12DebugLayerThunk final : public IUnknownImplRegisterMessageCallback( - DX12CallbackThunk, - D3D12_MESSAGE_CALLBACK_FLAG_NONE, - this, - &cookie - ); + DX12CallbackThunk, + D3D12_MESSAGE_CALLBACK_FLAG_NONE, + this, + &cookie + ); // Debug layer creation failure is allowed to silently fail (void)hr; } @@ -136,18 +136,18 @@ struct DX12RootSignatureKey { //---------------------------------------------------------------------------------------------------------------------- struct DX12ShaderHeader { - uint64_t hash[2] {}; // Hash of the shader bytecode, used for caching and identification purposes. + uint64_t hash[2]{}; // Hash of the shader bytecode, used for caching and identification purposes. std::size_t size = 0; // Size of the shader bytecode in bytes. // bytecode follows immediately after the header in memory. wis::span GetBytecode() const noexcept { - return wis::span {reinterpret_cast(this + 1), size}; + return wis::span{reinterpret_cast(this + 1), size}; } wis::span GetMutableBytecode() noexcept { - return wis::span {reinterpret_cast(this + 1), size}; + return wis::span{reinterpret_cast(this + 1), size}; } }; @@ -244,7 +244,7 @@ inline constexpr uint32_t DX12GetCopyPlaneSlice(WisBarrierFlags flags, uint16_t //---------------------------------------------------------------------------------------------------------------------- // Barrier helper constants constexpr static uint32_t dx12_max_barrier_size = std::max( -{sizeof(D3D12_BUFFER_BARRIER), sizeof(D3D12_TEXTURE_BARRIER), sizeof(D3D12_GLOBAL_BARRIER)} + {sizeof(D3D12_BUFFER_BARRIER), sizeof(D3D12_TEXTURE_BARRIER), sizeof(D3D12_GLOBAL_BARRIER)} ); constexpr static uint32_t dx12_static_size = wis::TransientMaxBarrierCount * dx12_max_barrier_size; @@ -268,8 +268,8 @@ inline std::array, 3> DX12AllocateBarriers( { std::array, 3> spans; std::size_t needed_size = barriers.buffer_barrier_count * sizeof(D3D12_BUFFER_BARRIER) - + barriers.texture_barrier_count * sizeof(D3D12_TEXTURE_BARRIER) - + barriers.global_barrier_count * sizeof(D3D12_GLOBAL_BARRIER); + + barriers.texture_barrier_count * sizeof(D3D12_TEXTURE_BARRIER) + + barriers.global_barrier_count * sizeof(D3D12_GLOBAL_BARRIER); if (needed_size <= dx12_static_size) { spans[0] = {local_scratch, barriers.buffer_barrier_count * sizeof(D3D12_BUFFER_BARRIER)}; @@ -403,7 +403,7 @@ inline void DX12InsertBarriers( return; } - uint8_t local_scratch[dx12_static_size] {}; + uint8_t local_scratch[dx12_static_size]{}; auto [buffer_span, texture_span, global_span] = DX12AllocateBarriers(impl, local_scratch, *barriers); @@ -444,13 +444,13 @@ inline void DX12InsertBarriers( bool release_barrier = qfot_barrier && src.queue_type_before == queue_type; auto layout_before = DX12GetOptimalBarrierLayout( - queue_type, - acquire_barrier ? WisTextureStateCommon : src.state_before - ); + queue_type, + acquire_barrier ? WisTextureStateCommon : src.state_before + ); auto layout_after = DX12GetOptimalBarrierLayout( - queue_type, - release_barrier ? WisTextureStateCommon : src.state_after - ); + queue_type, + release_barrier ? WisTextureStateCommon : src.state_after + ); texture_barriers_span[i] = D3D12_TEXTURE_BARRIER{ .SyncBefore = DX12Convert(src.sync_before), @@ -461,16 +461,16 @@ inline void DX12InsertBarriers( .LayoutAfter = layout_after, .pResource = std::bit_cast(src.texture), .Subresources = - { - .IndexOrFirstMipLevel = src.subresource_range.base_mip_level, - .NumMipLevels = src.subresource_range.mip_level_count, - .FirstArraySlice = src.subresource_range.base_array_layer, - .NumArraySlices = src.subresource_range.array_layer_count, - .FirstPlane = src.flags & WisBarrierFlagsPlanarImage ? src.subresource_range.plane_slice : 0u, - .NumPlanes = src.flags & WisBarrierFlagsPlanarImage ? src.subresource_range.plane_slice_count : 1u, - }, + { + .IndexOrFirstMipLevel = src.subresource_range.base_mip_level, + .NumMipLevels = src.subresource_range.mip_level_count, + .FirstArraySlice = src.subresource_range.base_array_layer, + .NumArraySlices = src.subresource_range.array_layer_count, + .FirstPlane = src.flags & WisBarrierFlagsPlanarImage ? src.subresource_range.plane_slice : 0u, + .NumPlanes = src.flags & WisBarrierFlagsPlanarImage ? src.subresource_range.plane_slice_count : 1u, + }, .Flags = src.state_before == WisTextureStateUndefined ? D3D12_TEXTURE_BARRIER_FLAG_DISCARD - : D3D12_TEXTURE_BARRIER_FLAG_NONE, + : D3D12_TEXTURE_BARRIER_FLAG_NONE, }; } @@ -488,19 +488,16 @@ inline void DX12InsertBarriers( }; } - D3D12_BARRIER_GROUP groups[] { - { .Type = D3D12_BARRIER_TYPE_BUFFER, - .NumBarriers = real_buffer_barrier_count, - .pBufferBarriers = buffer_barriers_span.data() - }, - { .Type = D3D12_BARRIER_TYPE_TEXTURE, - .NumBarriers = static_cast(barriers->texture_barrier_count), - .pTextureBarriers = texture_barriers_span.data() - }, - { .Type = D3D12_BARRIER_TYPE_GLOBAL, - .NumBarriers = static_cast(barriers->global_barrier_count), - .pGlobalBarriers = global_barriers_span.data() - } + D3D12_BARRIER_GROUP groups[]{ + {.Type = D3D12_BARRIER_TYPE_BUFFER, + .NumBarriers = real_buffer_barrier_count, + .pBufferBarriers = buffer_barriers_span.data()}, + {.Type = D3D12_BARRIER_TYPE_TEXTURE, + .NumBarriers = static_cast(barriers->texture_barrier_count), + .pTextureBarriers = texture_barriers_span.data()}, + {.Type = D3D12_BARRIER_TYPE_GLOBAL, + .NumBarriers = static_cast(barriers->global_barrier_count), + .pGlobalBarriers = global_barriers_span.data()} }; list->Barrier(std::size(groups), groups); } diff --git a/src/include/wisdom/dx12/dx12_command_list.cpp b/src/include/wisdom/dx12/dx12_command_list.cpp index d387d8de..c8c1684e 100644 --- a/src/include/wisdom/dx12/dx12_command_list.cpp +++ b/src/include/wisdom/dx12/dx12_command_list.cpp @@ -21,7 +21,7 @@ inline D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_SUBRESOURCE_PARAMETERS* DX12Alloc if (new_size > impl.rp_memory_size) { delete[] impl.render_pass_memory; impl.render_pass_memory = new (std::nothrow) - D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_SUBRESOURCE_PARAMETERS[new_size]; + D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_SUBRESOURCE_PARAMETERS[new_size]; impl.rp_memory_size = impl.render_pass_memory ? new_size : 0; } return impl.render_pass_memory; @@ -84,17 +84,17 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListSetDescriptorHeaps( uint32_t heap_count = (resource_heap != 0) + (sampler_heap != 0); ID3D12DescriptorHeap* heaps[] = { resource_heap ? wis::from_handle(resource_heap)->descriptor_heap - : nullptr, + : nullptr, sampler_heap ? wis::from_handle(sampler_heap)->descriptor_heap - : nullptr, + : nullptr, }; impl.descriptor_handle = resource_heap - ? wis::from_handle(resource_heap)->gpu_handle - : D3D12_GPU_DESCRIPTOR_HANDLE{0}; + ? wis::from_handle(resource_heap)->gpu_handle + : D3D12_GPU_DESCRIPTOR_HANDLE{0}; impl.sampler_handle = sampler_heap - ? wis::from_handle(sampler_heap)->gpu_handle - : D3D12_GPU_DESCRIPTOR_HANDLE{0}; + ? wis::from_handle(sampler_heap)->gpu_handle + : D3D12_GPU_DESCRIPTOR_HANDLE{0}; if (heap_count > 0) { impl.list->SetDescriptorHeaps(heap_count, heaps + heap_offset); @@ -134,12 +134,12 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListSetPushConstants( default: case WisPipelineTypeGraphics: impl.list - ->SetGraphicsRoot32BitConstants(data->root_index, data->data_size / 4, data->data, data->push_offset / 4); + ->SetGraphicsRoot32BitConstants(data->root_index, data->data_size / 4, data->data, data->push_offset / 4); break; case WisPipelineTypeRayTracing: case WisPipelineTypeCompute: impl.list - ->SetComputeRoot32BitConstants(data->root_index, data->data_size / 4, data->data, data->push_offset / 4); + ->SetComputeRoot32BitConstants(data->root_index, data->data_size / 4, data->data, data->push_offset / 4); } } @@ -347,14 +347,14 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListBeginRenderPass( render_targets[i] = { .cpuDescriptor = aux ? aux->handle : D3D12_CPU_DESCRIPTOR_HANDLE{src.target}, .BeginningAccess = - { - .Type = wis::detail::DX12Convert(src.load_op), - }, + { + .Type = wis::detail::DX12Convert(src.load_op), + }, .EndingAccess = - { - .Type = src.resolve_desc ? D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE - : wis::detail::DX12Convert(src.store_op), - }, + { + .Type = src.resolve_desc ? D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE + : wis::detail::DX12Convert(src.store_op), + }, }; if (src.load_op == WisLoadOpClear) { render_targets[i].BeginningAccess.Clear.ClearValue = { @@ -381,7 +381,7 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListBeginRenderPass( // Encode the other parameters .pSubresourceParameters = static_cast< - const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_SUBRESOURCE_PARAMETERS*>(static_cast(dst) + const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_SUBRESOURCE_PARAMETERS*>(static_cast(dst) ), .Format = static_cast(dst->format), .ResolveMode = wis::detail::DX12Convert(resolve.mode), @@ -397,38 +397,38 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListBeginRenderPass( bool ignore_stencil = (desc->depth_stencil.flags & WisDepthStencilFlagsIgnoreStencil); flags |= (desc->depth_stencil.flags & WisDepthStencilFlagsReadOnlyDepth) && !ignore_depth - ? D3D12_RENDER_PASS_FLAG_BIND_READ_ONLY_DEPTH - : D3D12_RENDER_PASS_FLAG_NONE; + ? D3D12_RENDER_PASS_FLAG_BIND_READ_ONLY_DEPTH + : D3D12_RENDER_PASS_FLAG_NONE; flags |= (desc->depth_stencil.flags & WisDepthStencilFlagsReadOnlyStencil) && !ignore_stencil - ? D3D12_RENDER_PASS_FLAG_BIND_READ_ONLY_STENCIL - : D3D12_RENDER_PASS_FLAG_NONE; + ? D3D12_RENDER_PASS_FLAG_BIND_READ_ONLY_STENCIL + : D3D12_RENDER_PASS_FLAG_NONE; auto& src = desc->depth_stencil; auto* aux = wis::detail::DX12DecodeViewAddress(src.target); depth_stencil = { .cpuDescriptor = aux ? aux->handle : D3D12_CPU_DESCRIPTOR_HANDLE{src.target}, .DepthBeginningAccess = - { - .Type = ignore_depth ? D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_NO_ACCESS - : wis::detail::DX12Convert(src.load_op_depth), - }, + { + .Type = ignore_depth ? D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_NO_ACCESS + : wis::detail::DX12Convert(src.load_op_depth), + }, .StencilBeginningAccess = - { - .Type = ignore_stencil ? D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_NO_ACCESS - : wis::detail::DX12Convert(src.load_op_stencil), - }, + { + .Type = ignore_stencil ? D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_NO_ACCESS + : wis::detail::DX12Convert(src.load_op_stencil), + }, .DepthEndingAccess = - { - .Type = ignore_depth ? D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_NO_ACCESS - : src.resolve_depth_desc ? D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE - : wis::detail::DX12Convert(src.store_op_depth), - }, + { + .Type = ignore_depth ? D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_NO_ACCESS + : src.resolve_depth_desc ? D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE + : wis::detail::DX12Convert(src.store_op_depth), + }, .StencilEndingAccess = - { - .Type = ignore_stencil ? D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_NO_ACCESS - : src.resolve_stencil_desc ? D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE - : wis::detail::DX12Convert(src.store_op_stencil), - }, + { + .Type = ignore_stencil ? D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_NO_ACCESS + : src.resolve_stencil_desc ? D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE + : wis::detail::DX12Convert(src.store_op_stencil), + }, }; if (src.resolve_depth_desc) { @@ -450,7 +450,7 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListBeginRenderPass( // Encode the other parameters .pSubresourceParameters = static_cast< - const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_SUBRESOURCE_PARAMETERS*>(static_cast(dst) + const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_SUBRESOURCE_PARAMETERS*>(static_cast(dst) ), .Format = static_cast(dst->format), .ResolveMode = wis::detail::DX12Convert(resolve.mode), @@ -476,7 +476,7 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListBeginRenderPass( .SubresourceCount = layer_count, // Encode the other parameters .pSubresourceParameters = static_cast< - const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_SUBRESOURCE_PARAMETERS*>(static_cast(dst) + const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_SUBRESOURCE_PARAMETERS*>(static_cast(dst) ), .Format = static_cast(dst->format), .ResolveMode = wis::detail::DX12Convert(resolve.mode), @@ -501,7 +501,7 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListBeginRenderPass( auto& dst = render_targets[i].EndingAccess.Resolve; auto* src_aux = wis::detail::DX12DecodeViewAddress(src.target); auto* dst_aux = reinterpret_cast(dst.pSubresourceParameters - ); + ); wis::span subresource_params{ subresources + offset, @@ -513,12 +513,12 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListBeginRenderPass( .SrcSubresource = src_aux->base_subresource + j * src_aux->subresource_stride, .DstSubresource = dst_aux->base_subresource + j * dst_aux->subresource_stride, .SrcRect = - { - .left = 0, - .top = 0, - .right = static_cast(width), - .bottom = static_cast(height), - }, + { + .left = 0, + .top = 0, + .right = static_cast(width), + .bottom = static_cast(height), + }, }; } dst.pSubresourceParameters = subresource_params.data(); @@ -538,8 +538,8 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListBeginRenderPass( if (src.resolve_depth_desc) { auto& dst_depth = depth_stencil.DepthEndingAccess.Resolve; auto* dst_depth_aux = reinterpret_cast( - dst_depth.pSubresourceParameters - ); + dst_depth.pSubresourceParameters + ); wis::span subresource_params{ subresources + offset, @@ -550,14 +550,14 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListBeginRenderPass( subresource_params[j] = { .SrcSubresource = aux->base_subresource + j * aux->subresource_stride, .DstSubresource = (dst_depth_aux ? dst_depth_aux->base_subresource : 0) - + j * (dst_depth_aux ? dst_depth_aux->subresource_stride : 0), + + j * (dst_depth_aux ? dst_depth_aux->subresource_stride : 0), .SrcRect = - { - .left = 0, - .top = 0, - .right = static_cast(width), - .bottom = static_cast(height), - }, + { + .left = 0, + .top = 0, + .right = static_cast(width), + .bottom = static_cast(height), + }, }; } depth_stencil.DepthEndingAccess.Resolve.pSubresourceParameters = subresource_params.data(); @@ -571,8 +571,8 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListBeginRenderPass( auto& dst_stencil = depth_stencil.StencilEndingAccess.Resolve; auto* dst_stencil_aux = reinterpret_cast( - dst_stencil.pSubresourceParameters - ); + dst_stencil.pSubresourceParameters + ); wis::span subresource_params{ subresources + offset, @@ -583,14 +583,14 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListBeginRenderPass( subresource_params[j] = { .SrcSubresource = aux->base_stencil_subresource + j * aux->subresource_stride, .DstSubresource = (dst_stencil_aux ? dst_stencil_aux->base_stencil_subresource : 0) - + j * (dst_stencil_aux ? dst_stencil_aux->subresource_stride : 0), + + j * (dst_stencil_aux ? dst_stencil_aux->subresource_stride : 0), .SrcRect = - { - .left = 0, - .top = 0, - .right = static_cast(width), - .bottom = static_cast(height), - }, + { + .left = 0, + .top = 0, + .right = static_cast(width), + .bottom = static_cast(height), + }, }; } depth_stencil.StencilEndingAccess.Resolve.pSubresourceParameters = subresource_params.data(); @@ -689,7 +689,7 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListCopyBufferToTexture( uint32_t plane_slice = wis::detail::DX12GetCopyPlaneSlice(region.texture_region.flags, subresource.plane_slice); uint32_t dst_subresource = subresource.mip_level + subresource.array_layer * texture_desc.MipLevels - + plane_slice * texture_desc.MipLevels * texture_desc.DepthOrArraySize; + + plane_slice * texture_desc.MipLevels * texture_desc.DepthOrArraySize; D3D12_TEXTURE_COPY_LOCATION dst_location{ .pResource = dst, .Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, @@ -756,7 +756,7 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListCopyTextureToBuffer( uint32_t plane_slice = wis::detail::DX12GetCopyPlaneSlice(region.texture_region.flags, subresource.plane_slice); uint32_t src_subresource = subresource.mip_level + subresource.array_layer * texture_desc.MipLevels - + plane_slice * texture_desc.MipLevels * texture_desc.DepthOrArraySize; + + plane_slice * texture_desc.MipLevels * texture_desc.DepthOrArraySize; D3D12_TEXTURE_COPY_LOCATION src_location{ .pResource = src, .Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, @@ -831,18 +831,18 @@ WIS_EXTERN_C WISDOM_API void wisDX12CommandListCopyTexture( const auto& dst_subresource = region.dst_region.target_subresource; uint32_t src_plane_slice = wis::detail::DX12GetCopyPlaneSlice( - region.src_region.flags, - src_subresource.plane_slice - ); + region.src_region.flags, + src_subresource.plane_slice + ); uint32_t src_subresource_index = src_subresource.mip_level + src_subresource.array_layer * src_desc.MipLevels - + src_plane_slice * src_desc.MipLevels * src_desc.DepthOrArraySize; + + src_plane_slice * src_desc.MipLevels * src_desc.DepthOrArraySize; uint32_t dst_plane_slice = wis::detail::DX12GetCopyPlaneSlice( - region.dst_region.flags, - dst_subresource.plane_slice - ); + region.dst_region.flags, + dst_subresource.plane_slice + ); uint32_t dst_subresource_index = dst_subresource.mip_level + dst_subresource.array_layer * dst_desc.MipLevels - + dst_plane_slice * dst_desc.MipLevels * dst_desc.DepthOrArraySize; + + dst_plane_slice * dst_desc.MipLevels * dst_desc.DepthOrArraySize; D3D12_TEXTURE_COPY_LOCATION dst_location{ .pResource = dst, diff --git a/src/include/wisdom/dx12/dx12_descriptor_heap.cpp b/src/include/wisdom/dx12/dx12_descriptor_heap.cpp index 3fe028c4..aac4e712 100644 --- a/src/include/wisdom/dx12/dx12_descriptor_heap.cpp +++ b/src/include/wisdom/dx12/dx12_descriptor_heap.cpp @@ -37,13 +37,13 @@ inline DXGI_FORMAT DX12GetSRVFormat(const WisTextureBinding& binding) noexcept inline uint32_t DX12GetComponentMapping(WisComponentMapping mapping) noexcept { uint32_t r = mapping.r ? wis::detail::DX12Convert(mapping.r) - : D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_0; + : D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_0; uint32_t g = mapping.g ? wis::detail::DX12Convert(mapping.g) - : D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_1; + : D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_1; uint32_t b = mapping.b ? wis::detail::DX12Convert(mapping.b) - : D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_2; + : D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_2; uint32_t a = mapping.a ? wis::detail::DX12Convert(mapping.a) - : D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_3; + : D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_3; return D3D12_ENCODE_SHADER_4_COMPONENT_MAPPING(r, g, b, a); } @@ -215,7 +215,7 @@ inline void DX12FillRTVAuxData( // even though RT can be non-array, it may be a part of array uint32_t base_subresource = render_target.mip_level + mip_levels * render_target.base_array_layer - + plane_stride * plane_slice; + + plane_stride * plane_slice; switch (render_target.layout) { default: @@ -284,7 +284,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DescriptorHeapWriteConstantBuffer( }; heap.device->CreateConstantBufferView( &cbv_desc, - {heap.cpu_handle.ptr + static_cast(index) * heap.descriptor_size} + {heap.cpu_handle.ptr + static_cast(index) * heap.descriptor_size} ); return wis::detail::dx_success; } @@ -305,17 +305,17 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DescriptorHeapWriteStructuredBuffer( .ViewDimension = D3D12_SRV_DIMENSION_BUFFER, .Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING, .Buffer = - { - .FirstElement = data->array_offset, - .NumElements = data->structure_count, - .StructureByteStride = data->stride_bytes, - .Flags = D3D12_BUFFER_SRV_FLAG_NONE, - }, + { + .FirstElement = data->array_offset, + .NumElements = data->structure_count, + .StructureByteStride = data->stride_bytes, + .Flags = D3D12_BUFFER_SRV_FLAG_NONE, + }, }; heap.device->CreateShaderResourceView( resource, &srv_desc, - {heap.cpu_handle.ptr + static_cast(index) * heap.descriptor_size} + {heap.cpu_handle.ptr + static_cast(index) * heap.descriptor_size} ); return wis::detail::dx_success; } @@ -335,18 +335,18 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DescriptorHeapWriteRWStructuredBuffer( .Format = DXGI_FORMAT_UNKNOWN, // must be UNKNOWN for structured buffers .ViewDimension = D3D12_UAV_DIMENSION_BUFFER, .Buffer = - { - .FirstElement = data->array_offset, - .NumElements = data->structure_count, - .StructureByteStride = data->stride_bytes, - .Flags = D3D12_BUFFER_UAV_FLAG_NONE, - }, + { + .FirstElement = data->array_offset, + .NumElements = data->structure_count, + .StructureByteStride = data->stride_bytes, + .Flags = D3D12_BUFFER_UAV_FLAG_NONE, + }, }; heap.device->CreateUnorderedAccessView( resource, nullptr, &uav_desc, - {heap.cpu_handle.ptr + static_cast(index) * heap.descriptor_size} + {heap.cpu_handle.ptr + static_cast(index) * heap.descriptor_size} ); return wis::detail::dx_success; } @@ -358,19 +358,19 @@ wisDX12DescriptorHeapWriteSampler(const WisDX12DescriptorHeap* self, const WisSa auto& heap = wis::from_handle_ref(self); auto min_filter = !sampler->is_anisotropic ? wis::detail::DX12Convert(sampler->min_filter) - : D3D12_FILTER_TYPE_LINEAR; + : D3D12_FILTER_TYPE_LINEAR; auto mag_filter = !sampler->is_anisotropic ? wis::detail::DX12Convert(sampler->mag_filter) - : D3D12_FILTER_TYPE_LINEAR; + : D3D12_FILTER_TYPE_LINEAR; auto reduction_mode = sampler->comparison_op != WisCompareOpNone - ? D3D12_FILTER_REDUCTION_TYPE::D3D12_FILTER_REDUCTION_TYPE_COMPARISON - : wis::detail::DX12Convert(sampler->reduction_mode); + ? D3D12_FILTER_REDUCTION_TYPE::D3D12_FILTER_REDUCTION_TYPE_COMPARISON + : wis::detail::DX12Convert(sampler->reduction_mode); auto basic_filter = D3D12_ENCODE_BASIC_FILTER( - min_filter, - mag_filter, - wis::detail::DX12Convert(sampler->mip_filter), - reduction_mode - ); + min_filter, + mag_filter, + wis::detail::DX12Convert(sampler->mip_filter), + reduction_mode + ); auto filter = D3D12_FILTER(sampler->is_anisotropic * D3D12_ANISOTROPIC_FILTERING_BIT | basic_filter); constexpr static std::array border_colors[] = { @@ -394,7 +394,7 @@ wisDX12DescriptorHeapWriteSampler(const WisDX12DescriptorHeap* self, const WisSa }; heap.device->CreateSampler( &sampler_desc, - {heap.cpu_handle.ptr + static_cast(index) * heap.descriptor_size} + {heap.cpu_handle.ptr + static_cast(index) * heap.descriptor_size} ); return wis::detail::dx_success; } @@ -413,7 +413,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DescriptorHeapWriteTexture( heap.device->CreateShaderResourceView( resource, &desc, - {heap.cpu_handle.ptr + static_cast(index) * heap.descriptor_size} + {heap.cpu_handle.ptr + static_cast(index) * heap.descriptor_size} ); return wis::detail::dx_success; } @@ -433,7 +433,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DescriptorHeapWriteRWTexture( resource, nullptr, &desc, - {heap.cpu_handle.ptr + static_cast(index) * heap.descriptor_size} + {heap.cpu_handle.ptr + static_cast(index) * heap.descriptor_size} ); return wis::detail::dx_success; } @@ -452,7 +452,7 @@ wisDX12DescriptorHeapWriteAccelerationStructure(const WisDX12DescriptorHeap* sel heap.device->CreateShaderResourceView( nullptr, &desc, - {heap.cpu_handle.ptr + static_cast(index) * heap.descriptor_size} + {heap.cpu_handle.ptr + static_cast(index) * heap.descriptor_size} ); return wis::detail::dx_success; } @@ -469,9 +469,9 @@ WIS_EXTERN_C WISDOM_API void wisDX12DescriptorHeapCopyDescriptors( auto& heap = wis::from_handle_ref(self); heap.device->CopyDescriptorsSimple( count, - {heap.cpu_handle.ptr + static_cast(dst_index) * heap.descriptor_size}, - {std::bit_cast(src_ptr) + static_cast(src_index) * heap.descriptor_size}, - heap.type + {heap.cpu_handle.ptr + static_cast(dst_index) * heap.descriptor_size}, + {std::bit_cast(src_ptr) + static_cast(src_index) * heap.descriptor_size}, + heap.type ); } @@ -677,9 +677,9 @@ WIS_EXTERN_C WISDOM_API void wisDX12ViewHeapCopyViews( heap.device->CopyDescriptorsSimple( count, - {heap.cpu_handle.ptr + static_cast(dst_index) * heap.descriptor_size}, - {src_handle_ptr}, - heap.type + {heap.cpu_handle.ptr + static_cast(dst_index) * heap.descriptor_size}, + {src_handle_ptr}, + heap.type ); // copy aux data if present diff --git a/src/include/wisdom/dx12/dx12_device.cpp b/src/include/wisdom/dx12/dx12_device.cpp index fff677dd..bf5eb8e7 100644 --- a/src/include/wisdom/dx12/dx12_device.cpp +++ b/src/include/wisdom/dx12/dx12_device.cpp @@ -42,8 +42,8 @@ wisDX12DeviceCreateCommandQueue(const WisDX12Device* self, WisCommandQueueType t bool supported = (device.queue_priorities[type] & ~0x7fu) != 0; if (!supported) { return wis::detail::make_result< - wis::detail::Func(), - "Requested command queue type is not supported or not enabled by the device">(E_INVALIDARG); + wis::detail::Func(), + "Requested command queue type is not supported or not enabled by the device">(E_INVALIDARG); } D3D12_COMMAND_QUEUE_DESC desc{ @@ -75,10 +75,10 @@ wisDX12DeviceCreateCommandAllocator(const WisDX12Device* self, WisCommandQueueTy wis::com_ptr allocator; auto hr = device.device->CreateCommandAllocator( - wis::detail::DX12Convert(type), - IID_ID3D12CommandAllocator, - allocator.put_void_unchecked() - ); + wis::detail::DX12Convert(type), + IID_ID3D12CommandAllocator, + allocator.put_void_unchecked() + ); if (!wis::detail::succeeded(hr)) { return wis::detail::make_result(hr); } @@ -102,7 +102,7 @@ wisDX12DeviceCreateFence(const WisDX12Device* self, uint64_t initial_value, WisD wis::com_ptr out_fence; auto hr = device.device - ->CreateFence(initial_value, D3D12_FENCE_FLAG_NONE, IID_ID3D12Fence, out_fence.put_void_unchecked()); + ->CreateFence(initial_value, D3D12_FENCE_FLAG_NONE, IID_ID3D12Fence, out_fence.put_void_unchecked()); if (!wis::detail::succeeded(hr)) { return wis::detail::make_result(hr); } @@ -111,8 +111,8 @@ wisDX12DeviceCreateFence(const WisDX12Device* self, uint64_t initial_value, WisD auto event_handle = CreateEventW(nullptr, false, false, nullptr); if (!event_handle) { return wis::detail::make_result( - HRESULT_FROM_WIN32(GetLastError()) - ); + HRESULT_FROM_WIN32(GetLastError()) + ); } auto& internal = *new (fence) wis::impl::DX12FenceImpl{ @@ -156,7 +156,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateDescriptorHeap( wis::com_ptr descriptor_heap; HRESULT hr = device.device - ->CreateDescriptorHeap(&heap_desc, IID_ID3D12DescriptorHeap, descriptor_heap.put_void_unchecked()); + ->CreateDescriptorHeap(&heap_desc, IID_ID3D12DescriptorHeap, descriptor_heap.put_void_unchecked()); if (!wis::detail::succeeded(hr)) { return wis::detail::make_result(hr); } @@ -194,7 +194,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateViewHeap( wis::com_ptr descriptor_heap; HRESULT hr = device.device - ->CreateDescriptorHeap(&heap_desc, IID_ID3D12DescriptorHeap, descriptor_heap.put_void_unchecked()); + ->CreateDescriptorHeap(&heap_desc, IID_ID3D12DescriptorHeap, descriptor_heap.put_void_unchecked()); if (!wis::detail::succeeded(hr)) { return wis::detail::make_result(hr); } @@ -210,12 +210,12 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateViewHeap( && "[INTERNAL ERROR] DescriptorHandle is not aligned! Report the issue to the developers." ); - aux_data = new (std::nothrow) wis::detail::DX12RenderTargetViewAuxData[capacity] {}; + aux_data = new (std::nothrow) wis::detail::DX12RenderTargetViewAuxData[capacity]{}; if (!aux_data) { raw_heap->Release(); return wis::detail::make_result( - E_OUTOFMEMORY - ); + E_OUTOFMEMORY + ); } for (uint32_t i = 0; i < capacity; ++i) { aux_data[i].handle = {cpu_handle.ptr + static_cast(i) * descriptor_size}; @@ -251,8 +251,8 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateRootSignature( const auto& push_constant = desc->push_constants[i]; if (push_constant.size_bytes % 4 != 0) { return wis::detail::make_result( - E_INVALIDARG - ); + E_INVALIDARG + ); } push_constant_size += push_constant.size_bytes; } @@ -261,12 +261,12 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateRootSignature( // Check limits if (push_constant_size + 2 * desc->push_descriptor_count + desc->descriptor_table_count > max_root_parameters) { return wis::detail::make_result(E_INVALIDARG - ); + ); } D3D12_ROOT_PARAMETER1 root_parameters[max_root_parameters]; std::size_t num_root_parameters = desc->push_constant_count + desc->push_descriptor_count - + desc->descriptor_table_count; + + desc->descriptor_table_count; wis::span root_parameters_span{root_parameters, num_root_parameters}; // Push constants @@ -275,11 +275,11 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateRootSignature( root_parameters_span[i] = { .ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS, .Constants = - { - .ShaderRegister = static_cast(src.bind_register), - .RegisterSpace = static_cast(src.bind_space), - .Num32BitValues = static_cast(src.size_bytes / 4), - }, + { + .ShaderRegister = static_cast(src.bind_register), + .RegisterSpace = static_cast(src.bind_space), + .Num32BitValues = static_cast(src.size_bytes / 4), + }, .ShaderVisibility = wis::detail::DX12Convert(src.visibility), }; } @@ -291,18 +291,18 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateRootSignature( if (!wis::detail::DX12IsPushable(src.type)) { return wis::detail:: - make_result(E_INVALIDARG - ); + make_result(E_INVALIDARG + ); } root_parameters_span[i] = { .ParameterType = wis::detail::DX12RootParameterType(src.type), .Descriptor = - { - .ShaderRegister = src.bind_register, - .RegisterSpace = src.bind_space, - .Flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE, - }, + { + .ShaderRegister = src.bind_register, + .RegisterSpace = src.bind_space, + .Flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE, + }, .ShaderVisibility = wis::detail::DX12Convert(src.visibility), }; } @@ -323,8 +323,8 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateRootSignature( ranges = wis::make_unique(range_count); if (!ranges) { return wis::detail::make_result( - E_OUTOFMEMORY - ); + E_OUTOFMEMORY + ); } wis::span ranges_span{ranges.get(), range_count}; @@ -340,7 +340,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateRootSignature( .BaseShaderRegister = src.bind_register, .RegisterSpace = src.bind_space, .Flags = src.count > 1 ? D3D12_DESCRIPTOR_RANGE_FLAG_DESCRIPTORS_VOLATILE - : D3D12_DESCRIPTOR_RANGE_FLAG_NONE, + : D3D12_DESCRIPTOR_RANGE_FLAG_NONE, .OffsetInDescriptorsFromTableStart = src.descriptor_offset, }; } @@ -348,10 +348,10 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateRootSignature( root_parameters_span[i] = { .ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE, .DescriptorTable = - { - .NumDescriptorRanges = static_cast(table.entry_count), - .pDescriptorRanges = ranges.get() + range_offset, - }, + { + .NumDescriptorRanges = static_cast(table.entry_count), + .pDescriptorRanges = ranges.get() + range_offset, + }, .ShaderVisibility = wis::detail::DX12Convert(table.visibility), }; range_offset += table.entry_count; @@ -361,13 +361,13 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateRootSignature( D3D12_VERSIONED_ROOT_SIGNATURE_DESC rsig_desc{ .Version = D3D_ROOT_SIGNATURE_VERSION_1_2, .Desc_1_2 = - { - .NumParameters = static_cast(num_root_parameters), - .pParameters = root_parameters, - .NumStaticSamplers = 0, - .pStaticSamplers = nullptr, - .Flags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT, - }, + { + .NumParameters = static_cast(num_root_parameters), + .pParameters = root_parameters, + .NumStaticSamplers = 0, + .pStaticSamplers = nullptr, + .Flags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT, + }, }; wis::com_ptr signature; @@ -401,12 +401,12 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateRootSignature( wis::com_ptr root_signature; hr = device.device->CreateRootSignature( - 0, - signature->GetBufferPointer(), - signature->GetBufferSize(), - IID_ID3D12RootSignature, - root_signature.put_void_unchecked() - ); + 0, + signature->GetBufferPointer(), + signature->GetBufferSize(), + IID_ID3D12RootSignature, + root_signature.put_void_unchecked() + ); if (!wis::detail::succeeded(hr)) { return wis::detail::make_result(hr); } @@ -415,7 +415,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateRootSignature( XXH128_hash_t hash = XXH3_128bits(signature->GetBufferPointer(), signature->GetBufferSize()); wis::detail::DX12RootSignatureKey key{.hash{hash.low64, hash.high64}}; root_signature - ->SetPrivateData(wis::detail::DX12RootSignatureKey::guid, sizeof(wis::detail::DX12RootSignatureKey), &key); + ->SetPrivateData(wis::detail::DX12RootSignatureKey::guid, sizeof(wis::detail::DX12RootSignatureKey), &key); auto& layout_impl = *new (layout) wis::impl::DX12RootSignatureImpl{.root_signature = root_signature.detach()}; return res; @@ -442,54 +442,50 @@ WIS_EXTERN_C WISDOM_API void wisDX12DeviceQueryProperties(const WisDX12Device* s props->max_queue_priority[i] = WisCommandQueuePriority(device.queue_priorities[i] & 0x7f); } props->relaxed_queue_transition = true; - } - break; + } break; case WisQueryPropertyTypeDeviceDescriptorHeapProperties: { auto* props = static_cast(next); D3D12_FEATURE_DATA_D3D12_OPTIONS19 options19 = {}; if (wis::detail::succeeded( - device.device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS19, &options19, sizeof(options19)) - )) { + device.device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS19, &options19, sizeof(options19)) + )) { props->max_descriptor_heap_size = options19.MaxViewDescriptorHeapSize; props->max_sampler_heap_size = options19.MaxSamplerDescriptorHeapSize; props->max_sampler_heap_size_with_embedded = options19.MaxSamplerDescriptorHeapSizeWithStaticSamplers; props->descriptor_increment_size = device.device->GetDescriptorHandleIncrementSize( - D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV - ); + D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV + ); props->sampler_increment_size = device.device->GetDescriptorHandleIncrementSize( - D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER - ); + D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER + ); props->render_target_increment_size = device.device->GetDescriptorHandleIncrementSize( - D3D12_DESCRIPTOR_HEAP_TYPE_RTV - ); + D3D12_DESCRIPTOR_HEAP_TYPE_RTV + ); props->depth_stencil_increment_size = device.device->GetDescriptorHandleIncrementSize( - D3D12_DESCRIPTOR_HEAP_TYPE_DSV - ); + D3D12_DESCRIPTOR_HEAP_TYPE_DSV + ); props->render_target_with_ms_increment_size = sizeof(wis::detail::DX12RenderTargetViewAuxData); props->depth_stencil_with_ms_increment_size = sizeof(wis::detail::DX12RenderTargetViewAuxData); } - } - break; + } break; case WisQueryPropertyTypeDeviceMemoryProperties: { auto* props = static_cast(next); D3D12_FEATURE_DATA_D3D12_OPTIONS16 options16 = {}; if (wis::detail::succeeded( - device.device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS16, &options16, sizeof(options16)) - )) { + device.device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS16, &options16, sizeof(options16)) + )) { props->gpu_upload_supported = options16.GPUUploadHeapSupported; props->host_image_copy_supported = options16.GPUUploadHeapSupported; } - } - break; + } break; case WisQueryPropertyTypeDeviceBindingProperties: { auto* props = static_cast(next); props->max_vertex_input_bindings = D3D12_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; props->max_vertex_input_attributes = D3D12_IA_VERTEX_INPUT_STRUCTURE_ELEMENT_COUNT; props->multiple_viewports_supported = true; // D3D12 supports up to 16 viewports and scissor rectangles props->address_commands_supported = true; // D3D12 supports buffer address commands - } - break; + } break; default: break; } @@ -512,17 +508,17 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceWaitForMultipleFences( HANDLE event_handle = CreateEventW(nullptr, false, false, nullptr); if (!event_handle) { return wis::detail::make_result( - HRESULT_FROM_WIN32(GetLastError()) - ); + HRESULT_FROM_WIN32(GetLastError()) + ); } auto hr = device.device->SetEventOnMultipleFenceCompletion( - reinterpret_cast(fences), - fence_values, - static_cast(fence_count), - static_cast(wait_for), - event_handle - ); + reinterpret_cast(fences), + fence_values, + static_cast(fence_count), + static_cast(wait_for), + event_handle + ); CloseHandle(event_handle); @@ -547,8 +543,8 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreatePipelineCache( data_copy = static_cast(malloc(data_size)); if (!data_copy) { return wis::detail::make_result( - E_OUTOFMEMORY - ); + E_OUTOFMEMORY + ); } std::memcpy(data_copy, initial_data, data_size); } @@ -556,11 +552,11 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreatePipelineCache( wis::com_ptr pipeline_library; auto hr = device.device->CreatePipelineLibrary( - data_copy, - data_size, - IID_ID3D12PipelineLibrary1, - pipeline_library.put_void_unchecked() - ); + data_copy, + data_size, + IID_ID3D12PipelineLibrary1, + pipeline_library.put_void_unchecked() + ); if (!wis::detail::succeeded(hr)) { free(data_copy); @@ -585,11 +581,11 @@ wisDX12DeviceCreateShader(const WisDX12Device* self, const uint8_t* data, size_t auto& device = wis::from_handle_ref(self); std::unique_ptr shader_header{reinterpret_cast( - operator new(wis::aligned_size(size, 8ull) + sizeof(wis::detail::DX12ShaderHeader), std::nothrow) - )}; + operator new(wis::aligned_size(size, 8ull) + sizeof(wis::detail::DX12ShaderHeader), std::nothrow) + )}; if (!shader_header) { return wis::detail::make_result(E_OUTOFMEMORY - ); + ); } std::construct_at(shader_header.get()); @@ -625,14 +621,14 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateComputePipeline( // Validate root signature if (!rootsig) { return wis::detail::make_result< - wis::detail::Func(), - "Invalid root signature provided for compute pipeline creation">(E_INVALIDARG); + wis::detail::Func(), + "Invalid root signature provided for compute pipeline creation">(E_INVALIDARG); } // Validate shader if (!shader) { return wis::detail::make_result( - E_INVALIDARG - ); + E_INVALIDARG + ); } auto bytecode = shader->GetBytecode(); @@ -682,11 +678,11 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateComputePipeline( // Try to load pipeline from cache first if available HRESULT hr = cache->LoadPipeline( - name_buffer, - &pso_desc, - IID_ID3D12PipelineState, - pipeline_state.put_void_unchecked() - ); + name_buffer, + &pso_desc, + IID_ID3D12PipelineState, + pipeline_state.put_void_unchecked() + ); if (wis::detail::succeeded(hr)) { auto& pipeline_impl = *new (pipeline) wis::impl::DX12PipelineImpl{ .pipeline_state = pipeline_state.detach(), @@ -697,13 +693,13 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateComputePipeline( // Cache miss if (desc->flags & WisPipelineFlagsFailOnCacheMiss) { return wis::detail::make_result< - wis::detail::Func(), - "Pipeline not found in cache and creation is set to fail on cache miss">(WisStatusError, E_FAIL); + wis::detail::Func(), + "Pipeline not found in cache and creation is set to fail on cache miss">(WisStatusError, E_FAIL); } } auto hr = device.device - ->CreatePipelineState(&pso_desc, IID_ID3D12PipelineState, pipeline_state.put_void_unchecked()); + ->CreatePipelineState(&pso_desc, IID_ID3D12PipelineState, pipeline_state.put_void_unchecked()); if (!wis::detail::succeeded(hr)) { return wis::detail::make_result(hr); } @@ -731,8 +727,8 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateGraphicsPipeline( auto* rootsig = std::bit_cast(desc->root_signature); if (!rootsig) { return wis::detail::make_result< - wis::detail::Func(), - "Invalid root signature provided for graphics pipeline creation">(E_INVALIDARG); + wis::detail::Func(), + "Invalid root signature provided for graphics pipeline creation">(E_INVALIDARG); } struct GraphicsPipelineStream { @@ -759,8 +755,8 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateGraphicsPipeline( } stream{ .root_signature = rootsig, .flags = desc->flags & WisPipelineFlagsEnablePrimitiveRestart - ? D3D12_PIPELINE_STATE_FLAG_DYNAMIC_INDEX_BUFFER_STRIP_CUT - : D3D12_PIPELINE_STATE_FLAG_NONE, + ? D3D12_PIPELINE_STATE_FLAG_DYNAMIC_INDEX_BUFFER_STRIP_CUT + : D3D12_PIPELINE_STATE_FLAG_NONE, }; static constexpr size_t shader_stage_count = 5; @@ -778,7 +774,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateGraphicsPipeline( stream.vertex_shader = {{bytecode.data(), bytecode.size()}}; } else { return wis::detail:: - make_result(E_INVALIDARG); + make_result(E_INVALIDARG); } if (auto ps = shader_headers[1]) { auto bytecode = ps->GetBytecode(); @@ -800,7 +796,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateGraphicsPipeline( //--Render targets if (desc->render_attachments.attachments_count > wis::MaxRenderTargets) { return wis::detail:: - make_result(E_INVALIDARG); + make_result(E_INVALIDARG); } D3D12_RT_FORMAT_ARRAY& rtv_formats = stream.rtv_formats; @@ -813,7 +809,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateGraphicsPipeline( } //--Multiview - D3D12_VIEW_INSTANCE_LOCATION view_locs[wis::MaxRenderTargets] {}; + D3D12_VIEW_INSTANCE_LOCATION view_locs[wis::MaxRenderTargets]{}; if (desc->render_attachments.view_mask) { uint32_t view_mask = desc->render_attachments.view_mask; for (uint32_t i = 0u; i < wis::MaxRenderTargets; i++) { @@ -836,7 +832,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateGraphicsPipeline( //--Input layout wis::span slots{desc->input_layout.bindings, desc->input_layout.binding_count}; wis::span attrs{desc->input_layout.attributes, desc->input_layout.attribute_count}; - D3D12_INPUT_ELEMENT_DESC reasonable_max_input_elements[wis::MinSupportedInputAttributes * 2] {}; + D3D12_INPUT_ELEMENT_DESC reasonable_max_input_elements[wis::MinSupportedInputAttributes * 2]{}; std::unique_ptr input_elements; wis::span input_elements_span; if (!slots.empty() && !attrs.empty()) { @@ -876,16 +872,16 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateGraphicsPipeline( } stream.rasterizer = CD3DX12_RASTERIZER_DESC2{D3D12_RASTERIZER_DESC2{ - .FillMode = wis::detail::DX12Convert(raster.fill_mode), - .CullMode = wis::detail::DX12Convert(raster.cull_mode), - .FrontCounterClockwise = wis::detail::DX12Convert(raster.front_face), - .DepthBias = bias ? raster.depth_bias : 0.0f, - .DepthBiasClamp = bias ? raster.depth_bias_clamp : 0.0f, - .SlopeScaledDepthBias = bias ? raster.depth_bias_slope_factor : 0.0f, - .DepthClipEnable = raster.depth_clip_enable, - .LineRasterizationMode = wis::detail::DX12Convert(raster.line_rasterization), - .ConservativeRaster = wis::detail::DX12Convert(raster.conservative_rasterization) - }}; + .FillMode = wis::detail::DX12Convert(raster.fill_mode), + .CullMode = wis::detail::DX12Convert(raster.cull_mode), + .FrontCounterClockwise = wis::detail::DX12Convert(raster.front_face), + .DepthBias = bias ? raster.depth_bias : 0.0f, + .DepthBiasClamp = bias ? raster.depth_bias_clamp : 0.0f, + .SlopeScaledDepthBias = bias ? raster.depth_bias_slope_factor : 0.0f, + .DepthClipEnable = raster.depth_clip_enable, + .LineRasterizationMode = wis::detail::DX12Convert(raster.line_rasterization), + .ConservativeRaster = wis::detail::DX12Convert(raster.conservative_rasterization) + }}; } //--Multisample @@ -906,30 +902,29 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateGraphicsPipeline( if (desc->depth_stencil_desc) { auto& ds = *desc->depth_stencil_desc; stream.depth_stencil = CD3DX12_DEPTH_STENCIL_DESC2{ - { .DepthEnable = ds.depth_enable, - .DepthWriteMask = D3D12_DEPTH_WRITE_MASK(ds.depth_write_enable), - .DepthFunc = wis::detail::DX12Convert(ds.depth_comp), - .StencilEnable = ds.stencil_enable, - .FrontFace = - D3D12_DEPTH_STENCILOP_DESC1{ - .StencilFailOp = wis::detail::DX12Convert(ds.stencil_front.fail_op), - .StencilDepthFailOp = wis::detail::DX12Convert(ds.stencil_front.depth_fail_op), - .StencilPassOp = wis::detail::DX12Convert(ds.stencil_front.pass_op), - .StencilFunc = wis::detail::DX12Convert(ds.stencil_front.stencil_comp), - .StencilReadMask = ds.stencil_front.read_mask, - .StencilWriteMask = ds.stencil_front.write_mask, - }, - .BackFace = - D3D12_DEPTH_STENCILOP_DESC1{ - .StencilFailOp = wis::detail::DX12Convert(ds.stencil_back.fail_op), - .StencilDepthFailOp = wis::detail::DX12Convert(ds.stencil_back.depth_fail_op), - .StencilPassOp = wis::detail::DX12Convert(ds.stencil_back.pass_op), - .StencilFunc = wis::detail::DX12Convert(ds.stencil_back.stencil_comp), - .StencilReadMask = ds.stencil_back.read_mask, - .StencilWriteMask = ds.stencil_back.write_mask, - }, - .DepthBoundsTestEnable = ds.depth_bound_test - } + {.DepthEnable = ds.depth_enable, + .DepthWriteMask = D3D12_DEPTH_WRITE_MASK(ds.depth_write_enable), + .DepthFunc = wis::detail::DX12Convert(ds.depth_comp), + .StencilEnable = ds.stencil_enable, + .FrontFace = + D3D12_DEPTH_STENCILOP_DESC1{ + .StencilFailOp = wis::detail::DX12Convert(ds.stencil_front.fail_op), + .StencilDepthFailOp = wis::detail::DX12Convert(ds.stencil_front.depth_fail_op), + .StencilPassOp = wis::detail::DX12Convert(ds.stencil_front.pass_op), + .StencilFunc = wis::detail::DX12Convert(ds.stencil_front.stencil_comp), + .StencilReadMask = ds.stencil_front.read_mask, + .StencilWriteMask = ds.stencil_front.write_mask, + }, + .BackFace = + D3D12_DEPTH_STENCILOP_DESC1{ + .StencilFailOp = wis::detail::DX12Convert(ds.stencil_back.fail_op), + .StencilDepthFailOp = wis::detail::DX12Convert(ds.stencil_back.depth_fail_op), + .StencilPassOp = wis::detail::DX12Convert(ds.stencil_back.pass_op), + .StencilFunc = wis::detail::DX12Convert(ds.stencil_back.stencil_comp), + .StencilReadMask = ds.stencil_back.read_mask, + .StencilWriteMask = ds.stencil_back.write_mask, + }, + .DepthBoundsTestEnable = ds.depth_bound_test} }; } else { // Fix for depth stencil @@ -1022,9 +1017,9 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateGraphicsPipeline( // Hash pso stream wis::span pso_stream_bytes{// start after bytecodes - reinterpret_cast(&stream.flags), - // end at the end of the struct - reinterpret_cast(&stream + 1) + reinterpret_cast(&stream.flags), + // end at the end of the struct + reinterpret_cast(&stream + 1) }; XXH128_hash_t stream_hash = XXH3_128bits(pso_stream_bytes.data(), pso_stream_bytes.size()); rehash_input.pso_hash[0] = stream_hash.low64; @@ -1044,11 +1039,11 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateGraphicsPipeline( // Try to load pipeline from cache first if available HRESULT hr = cache->LoadPipeline( - name_buffer, - &psstream_desc, - IID_ID3D12PipelineState, - pipeline_state.put_void_unchecked() - ); + name_buffer, + &psstream_desc, + IID_ID3D12PipelineState, + pipeline_state.put_void_unchecked() + ); if (wis::detail::succeeded(hr)) { auto& pipeline_impl = *new (pipeline) wis::impl::DX12PipelineImpl{ .pipeline_state = pipeline_state.detach(), @@ -1059,16 +1054,16 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateGraphicsPipeline( // Cache miss if (desc->flags & WisPipelineFlagsFailOnCacheMiss) { return wis::detail::make_result< - wis::detail::Func(), - "Pipeline not found in cache and creation is set to fail on cache miss">(WisStatusError, E_FAIL); + wis::detail::Func(), + "Pipeline not found in cache and creation is set to fail on cache miss">(WisStatusError, E_FAIL); } } HRESULT hr = device.device->CreatePipelineState( - &psstream_desc, - IID_ID3D12PipelineState, - pipeline_state.put_void_unchecked() - ); + &psstream_desc, + IID_ID3D12PipelineState, + pipeline_state.put_void_unchecked() + ); if (!wis::detail::succeeded(hr)) { return wis::detail::make_result(hr); } @@ -1112,8 +1107,8 @@ wisDX12DeviceGetSurfaceParameters(const WisDX12Device* self, WisDX12SurfaceView .max_swapchain_images = DXGI_MAX_SWAP_CHAIN_BUFFERS, .alpha_modes_supported = 0b0000'1111, // Support all alpha modes (premultiplied, postmultiplied, opaque, custom) .texture_usage_flags_supported = static_cast( - WisTextureUsageFlagsRenderTarget | WisTextureUsageFlagsShaderResource | WisTextureUsageFlagsCopySrc - | WisTextureUsageFlagsCopyDst | WisTextureUsageFlagsUnorderedAccess + WisTextureUsageFlagsRenderTarget | WisTextureUsageFlagsShaderResource | WisTextureUsageFlagsCopySrc + | WisTextureUsageFlagsCopyDst | WisTextureUsageFlagsUnorderedAccess ), .stereo_supported = impl.factory->IsWindowedStereoEnabled() > 0, }; @@ -1138,8 +1133,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateSwapchain( BOOL xtearing = FALSE; device.factory->CheckFeatureSupport(DXGI_FEATURE_PRESENT_ALLOW_TEARING, &xtearing, sizeof(xtearing)); return bool(xtearing); - } - (); + }(); DXGI_USAGE usage = 0; switch (desc->texture_usage_flags) { @@ -1176,21 +1170,21 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12DeviceCreateSwapchain( HRESULT hr = S_OK; if (surface_impl.uwp) { hr = device.factory->CreateSwapChainForCoreWindow( - queue_impl.queue, - static_cast(surface_impl.surface), - &swap_chain_desc, - nullptr, - swap_chain1.put_unchecked() - ); + queue_impl.queue, + static_cast(surface_impl.surface), + &swap_chain_desc, + nullptr, + swap_chain1.put_unchecked() + ); } else { hr = device.factory->CreateSwapChainForHwnd( - queue_impl.queue, - static_cast(surface_impl.surface), - &swap_chain_desc, - nullptr, - nullptr, - swap_chain1.put_unchecked() - ); + queue_impl.queue, + static_cast(surface_impl.surface), + &swap_chain_desc, + nullptr, + nullptr, + swap_chain1.put_unchecked() + ); } if (!wis::detail::succeeded(hr)) { diff --git a/src/include/wisdom/dx12/dx12_impl.cpp b/src/include/wisdom/dx12/dx12_impl.cpp index 04693d45..43b6cfec 100644 --- a/src/include/wisdom/dx12/dx12_impl.cpp +++ b/src/include/wisdom/dx12/dx12_impl.cpp @@ -90,20 +90,20 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12TextureWriteSubresource( UINT row_pitch = 0; UINT slice_pitch = 0; auto hr = D3D12_PROPERTY_LAYOUT_FORMAT_TABLE::CalculateMinimumRowMajorRowPitch( - desc.Format, - target_region->box.width, - row_pitch - ); + desc.Format, + target_region->box.width, + row_pitch + ); if (!wis::detail::succeeded(hr)) { return wis::detail::make_result(hr); } hr = D3D12_PROPERTY_LAYOUT_FORMAT_TABLE::CalculateMinimumRowMajorSlicePitch( - desc.Format, - row_pitch, - target_region->box.height, - slice_pitch - ); + desc.Format, + row_pitch, + target_region->box.height, + slice_pitch + ); if (!wis::detail::succeeded(hr)) { return wis::detail::make_result(hr); } @@ -117,12 +117,12 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12TextureWriteSubresource( .back = is_3d ? target_region->box.z + target_region->box.depth : 1, }; auto subresource = D3D12CalcSubresource( - target_region->target_subresource.mip_level, - target_region->target_subresource.array_layer, - target_region->target_subresource.plane_slice, - desc.MipLevels, - is_3d ? 1 : desc.DepthOrArraySize - ); + target_region->target_subresource.mip_level, + target_region->target_subresource.array_layer, + target_region->target_subresource.plane_slice, + desc.MipLevels, + is_3d ? 1 : desc.DepthOrArraySize + ); hr = resource->WriteToSubresource(subresource, &dst_box, source_data, row_pitch, slice_pitch); if (!wis::detail::succeeded(hr)) { return wis::detail::make_result(hr); diff --git a/src/include/wisdom/dx12/dx12_resource_allocator.cpp b/src/include/wisdom/dx12/dx12_resource_allocator.cpp index 6a9f2d63..07f15e73 100644 --- a/src/include/wisdom/dx12/dx12_resource_allocator.cpp +++ b/src/include/wisdom/dx12/dx12_resource_allocator.cpp @@ -21,23 +21,23 @@ inline WisResult DX12CreateResource( { if (all_desc.HeapType == D3D12_HEAP_TYPE_GPU_UPLOAD && !allocator->IsGPUUploadHeapSupported()) { return wis::detail::make_result( - E_NOTIMPL - ); + E_NOTIMPL + ); } wis::com_ptr resource; wis::com_ptr allocation; HRESULT hr = allocator->CreateResource3( - &all_desc, - &res_desc, - initial_layout, - nullptr, - static_cast(cast_formats.size()), - cast_formats.data(), - allocation.put_unchecked(), - resource.iid(), - resource.put_void_unchecked() - ); + &all_desc, + &res_desc, + initial_layout, + nullptr, + static_cast(cast_formats.size()), + cast_formats.data(), + allocation.put_unchecked(), + resource.iid(), + resource.put_void_unchecked() + ); if (!wis::detail::succeeded(hr)) { return wis::detail::make_result(hr); @@ -131,9 +131,9 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12ResourceAllocatorCreateBuffer( { auto& [allocator, device] = wis::from_handle_ref(self); uint64_t size = wis::aligned_size( - desc->size_bytes, - static_cast(D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT) - ); + desc->size_bytes, + static_cast(D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT) + ); D3D12_RESOURCE_DESC1 buffer_desc{ .Dimension = D3D12_RESOURCE_DIMENSION_BUFFER, .Alignment = 0, @@ -153,13 +153,13 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12ResourceAllocatorCreateBuffer( .HeapType = wis::detail::DX12Convert(desc->memory_type), }; return wis::detail::DX12CreateResource( - all_desc, - buffer_desc, - D3D12_BARRIER_LAYOUT_UNDEFINED, - allocator, - {}, - buffer - ); + all_desc, + buffer_desc, + D3D12_BARRIER_LAYOUT_UNDEFINED, + allocator, + {}, + buffer + ); } //---------------------------------------------------------------------------------------------------------------------- @@ -179,13 +179,13 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12ResourceAllocatorCreateTexture( // planar formats are uncastable if (desc->format >= WisDataFormatNV12) { return wis::detail::DX12CreateResource( - all_desc, - tex_desc, - D3D12_BARRIER_LAYOUT_UNDEFINED, - impl.allocator, - {}, - buffer - ); + all_desc, + tex_desc, + D3D12_BARRIER_LAYOUT_UNDEFINED, + impl.allocator, + {}, + buffer + ); } static constexpr uint32_t max_cast_formats = 16; @@ -221,22 +221,22 @@ WIS_EXTERN_C WISDOM_API WisResult wisDX12ResourceAllocatorCreateTexture( if (directly_mappable) { return wis::detail::DX12CreateResource( - all_desc, - tex_desc, - D3D12_BARRIER_LAYOUT_UNDEFINED, - impl.allocator, - {reinterpret_cast(desc->cast_formats), desc->cast_format_count}, - buffer - ); + all_desc, + tex_desc, + D3D12_BARRIER_LAYOUT_UNDEFINED, + impl.allocator, + {reinterpret_cast(desc->cast_formats), desc->cast_format_count}, + buffer + ); } return wis::detail::DX12CreateResource( - all_desc, - tex_desc, - D3D12_BARRIER_LAYOUT_UNDEFINED, - impl.allocator, - cast_formats_span, - buffer - ); + all_desc, + tex_desc, + D3D12_BARRIER_LAYOUT_UNDEFINED, + impl.allocator, + cast_formats_span, + buffer + ); } #endif // WIS_DX12_RESOURCE_ALLOCATOR_CPP diff --git a/src/include/wisdom/generated/cpp_api.hpp b/src/include/wisdom/generated/cpp_api.hpp index 015d3b92..ba95d003 100644 --- a/src/include/wisdom/generated/cpp_api.hpp +++ b/src/include/wisdom/generated/cpp_api.hpp @@ -2868,9 +2868,7 @@ struct DX12IndexBufferDesc { }; struct DX12TextureDeleter { - void operator()(WisDX12Texture* handle) noexcept { - ::wisDX12DestroyTexture(handle); - } + void operator()(WisDX12Texture* handle) noexcept { ::wisDX12DestroyTexture(handle); } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a GPU texture resource. @@ -2888,9 +2886,7 @@ class DX12Texture : public wis::impl::Implements(&target_region) - ); + &_impl_storage, + source_data, + reinterpret_cast(&target_region) + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } }; struct DX12BufferDeleter { - void operator()(WisDX12Buffer* handle) noexcept { - ::wisDX12DestroyBuffer(handle); - } + void operator()(WisDX12Buffer* handle) noexcept { ::wisDX12DestroyBuffer(handle); } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a GPU buffer resource. @@ -2932,17 +2926,13 @@ class DX12Buffer : public wis::impl::Implements rects) const noexcept { const WisResult wis_result = ::wisDX12SwapchainPresent( - &_impl_storage, - static_cast(flags), - reinterpret_cast(rects.data()), - rects.size() - ); + &_impl_storage, + static_cast(flags), + reinterpret_cast(rects.data()), + rects.size() + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -2999,9 +2987,9 @@ class DX12Swapchain { std::uint32_t index{}; const WisResult wis_result = ::wisDX12SwapchainGetCurrentIndex( - &_impl_storage, - reinterpret_cast(&index) - ); + &_impl_storage, + reinterpret_cast(&index) + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -3019,9 +3007,9 @@ class DX12Swapchain inline wis::Result Update(const wis::SwapchainUpdateDesc& desc) const noexcept { const WisResult wis_result = ::wisDX12SwapchainUpdate( - &_impl_storage, - reinterpret_cast(&desc) - ); + &_impl_storage, + reinterpret_cast(&desc) + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -3033,18 +3021,16 @@ class DX12Swapchain inline wis::Result GetTextures(wis::span buffers) const noexcept { const WisResult wis_result = ::wisDX12SwapchainGetTextures( - &_impl_storage, - reinterpret_cast(buffers.data()), - buffers.size() - ); + &_impl_storage, + reinterpret_cast(buffers.data()), + buffers.size() + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } }; struct DX12SurfaceDeleter { - void operator()(WisDX12Surface* handle) noexcept { - ::wisDX12DestroySurface(handle); - } + void operator()(WisDX12Surface* handle) noexcept { ::wisDX12DestroySurface(handle); } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a GPU surface, which can be used as a target for rendering and @@ -3063,15 +3049,11 @@ class DX12Surface : public wis::impl::Implements(&texture), - reinterpret_cast(&render_target), - index - )); + &_impl_storage, + reinterpret_cast(&texture), + reinterpret_cast(&render_target), + index + )); } /** * @brief Provided by Wisdom 0.7.0. Writes a depth stencil view to the view heap and returns the CPU descriptor @@ -3124,11 +3106,11 @@ class DX12ViewHeap ) const noexcept { return (::wisDX12ViewHeapWriteDepthStencil( - &_impl_storage, - reinterpret_cast(&texture), - reinterpret_cast(&render_target), - index - )); + &_impl_storage, + reinterpret_cast(&texture), + reinterpret_cast(&render_target), + index + )); } /** * @brief Provided by Wisdom 0.7.1. Writes a texture view for video decode output and returns the texture view @@ -3146,11 +3128,11 @@ class DX12ViewHeap ) const noexcept { return (::wisDX12ViewHeapWriteVideoDecodeTarget( - &_impl_storage, - reinterpret_cast(&texture), - reinterpret_cast(&render_target), - index - )); + &_impl_storage, + reinterpret_cast(&texture), + reinterpret_cast(&render_target), + index + )); } /** * @brief Provided by Wisdom 0.7.0. Returns the CPU descriptor handle for the view heap. @@ -3191,9 +3173,7 @@ class DX12ViewHeap }; struct DX12PipelineDeleter { - void operator()(WisDX12Pipeline* handle) noexcept { - ::wisDX12DestroyPipeline(handle); - } + void operator()(WisDX12Pipeline* handle) noexcept { ::wisDX12DestroyPipeline(handle); } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a GPU pipeline state object, which encapsulates the state of the @@ -3213,15 +3193,11 @@ class DX12Pipeline std::memcpy(&v, &_impl_storage, sizeof(v)); return v; } - WIS_NODISCARD operator DX12PipelineView() const noexcept { - return GetView(); - } + WIS_NODISCARD operator DX12PipelineView() const noexcept { return GetView(); } }; struct DX12ShaderDeleter { - void operator()(WisDX12Shader* handle) noexcept { - ::wisDX12DestroyShader(handle); - } + void operator()(WisDX12Shader* handle) noexcept { ::wisDX12DestroyShader(handle); } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a GPU shader module, which contains shader code and allows to @@ -3240,15 +3216,11 @@ class DX12Shader : public wis::impl::Implements + Implements { public: using ImplType::ImplType; @@ -3269,9 +3241,7 @@ class DX12PipelineCache std::memcpy(&v, &_impl_storage, sizeof(v)); return v; } - WIS_NODISCARD operator DX12PipelineCacheView() const noexcept { - return GetView(); - } + WIS_NODISCARD operator DX12PipelineCacheView() const noexcept { return GetView(); } /** * @brief Provided by Wisdom 0.7.0. Gets the data from the pipeline cache. * @param data points to an array that is filled with serialized cache data on success. @@ -3281,10 +3251,10 @@ class DX12PipelineCache inline wis::Result Serialize(wis::span data) const noexcept { const WisResult wis_result = ::wisDX12PipelineCacheSerialize( - &_impl_storage, - reinterpret_cast(data.data()), - data.size() - ); + &_impl_storage, + reinterpret_cast(data.data()), + data.size() + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -3299,9 +3269,7 @@ class DX12PipelineCache }; struct DX12DescriptorHeapDeleter { - void operator()(WisDX12DescriptorHeap* handle) noexcept { - ::wisDX12DestroyDescriptorHeap(handle); - } + void operator()(WisDX12DescriptorHeap* handle) noexcept { ::wisDX12DestroyDescriptorHeap(handle); } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a storage for descriptors used in contiguous array. @@ -3309,7 +3277,7 @@ struct DX12DescriptorHeapDeleter { * */ class DX12DescriptorHeap : public wis::impl:: - Implements + Implements { public: using ImplType::ImplType; @@ -3335,10 +3303,10 @@ class DX12DescriptorHeap inline wis::Result WriteConstantBuffer(const wis::ConstantBufferBinding& data, std::uint32_t index) const noexcept { const WisResult wis_result = ::wisDX12DescriptorHeapWriteConstantBuffer( - &_impl_storage, - reinterpret_cast(&data), - index - ); + &_impl_storage, + reinterpret_cast(&data), + index + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -3357,11 +3325,11 @@ class DX12DescriptorHeap ) const noexcept { const WisResult wis_result = ::wisDX12DescriptorHeapWriteStructuredBuffer( - &_impl_storage, - buffer, - reinterpret_cast(&data), - index - ); + &_impl_storage, + buffer, + reinterpret_cast(&data), + index + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -3380,11 +3348,11 @@ class DX12DescriptorHeap ) const noexcept { const WisResult wis_result = ::wisDX12DescriptorHeapWriteRWStructuredBuffer( - &_impl_storage, - buffer, - reinterpret_cast(&data), - index - ); + &_impl_storage, + buffer, + reinterpret_cast(&data), + index + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -3397,10 +3365,10 @@ class DX12DescriptorHeap inline wis::Result WriteSampler(const wis::SamplerDesc& sampler, std::uint32_t index) const noexcept { const WisResult wis_result = ::wisDX12DescriptorHeapWriteSampler( - &_impl_storage, - reinterpret_cast(&sampler), - index - ); + &_impl_storage, + reinterpret_cast(&sampler), + index + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -3412,14 +3380,14 @@ class DX12DescriptorHeap * * */ inline wis::Result WriteTexture(wis::DX12TextureView texture, const wis::TextureBinding& data, std::uint32_t index) - const noexcept + const noexcept { const WisResult wis_result = ::wisDX12DescriptorHeapWriteTexture( - &_impl_storage, - texture, - reinterpret_cast(&data), - index - ); + &_impl_storage, + texture, + reinterpret_cast(&data), + index + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -3437,11 +3405,11 @@ class DX12DescriptorHeap ) const noexcept { const WisResult wis_result = ::wisDX12DescriptorHeapWriteRWTexture( - &_impl_storage, - texture, - reinterpret_cast(&data), - index - ); + &_impl_storage, + texture, + reinterpret_cast(&data), + index + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -3477,9 +3445,7 @@ class DX12DescriptorHeap }; struct DX12RootSignatureDeleter { - void operator()(WisDX12RootSignature* handle) noexcept { - ::wisDX12DestroyRootSignature(handle); - } + void operator()(WisDX12RootSignature* handle) noexcept { ::wisDX12DestroyRootSignature(handle); } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a pipeline layout and a constant data storage, which defines @@ -3488,7 +3454,7 @@ struct DX12RootSignatureDeleter { * */ class DX12RootSignature : public wis::impl:: - Implements + Implements { public: using ImplType::ImplType; @@ -3500,15 +3466,11 @@ class DX12RootSignature std::memcpy(&v, &_impl_storage, sizeof(v)); return v; } - WIS_NODISCARD operator DX12RootSignatureView() const noexcept { - return GetView(); - } + WIS_NODISCARD operator DX12RootSignatureView() const noexcept { return GetView(); } }; struct DX12ResourceAllocatorDeleter { - void operator()(WisDX12ResourceAllocator* handle) noexcept { - ::wisDX12DestroyResourceAllocator(handle); - } + void operator()(WisDX12ResourceAllocator* handle) noexcept { ::wisDX12DestroyResourceAllocator(handle); } }; /** * @brief Provided by Wisdom 0.7.0. Class for allocating and managing GPU resources like buffers and textures. @@ -3516,7 +3478,7 @@ struct DX12ResourceAllocatorDeleter { * */ class DX12ResourceAllocator : public wis::impl:: - Implements + Implements { public: using ImplType::ImplType; @@ -3530,14 +3492,14 @@ class DX12ResourceAllocator * * */ WIS_NODISCARD inline wis::DX12Buffer CreateBuffer(const wis::BufferDesc& desc, wis::Result& out_result) - const noexcept + const noexcept { wis::DX12Buffer buffer{}; const WisResult wis_result = ::wisDX12ResourceAllocatorCreateBuffer( - &_impl_storage, - reinterpret_cast(&desc), - buffer.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&desc), + buffer.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -3553,14 +3515,14 @@ class DX12ResourceAllocator * * */ WIS_NODISCARD inline wis::DX12Texture CreateTexture(const wis::TextureDesc& desc, wis::Result& out_result) - const noexcept + const noexcept { wis::DX12Texture texture{}; const WisResult wis_result = ::wisDX12ResourceAllocatorCreateTexture( - &_impl_storage, - reinterpret_cast(&desc), - texture.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&desc), + texture.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -3571,9 +3533,7 @@ class DX12ResourceAllocator }; struct DX12FenceDeleter { - void operator()(WisDX12Fence* handle) noexcept { - ::wisDX12DestroyFence(handle); - } + void operator()(WisDX12Fence* handle) noexcept { ::wisDX12DestroyFence(handle); } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a fence for GPU-CPU and GPU-GPU synchronization. @@ -3591,9 +3551,7 @@ class DX12Fence : public wis::impl::Implements + Implements { public: using ImplType::ImplType; @@ -4123,9 +4073,7 @@ class DX12CommandAllocator }; struct DX12CommandQueueDeleter { - void operator()(WisDX12CommandQueue* handle) noexcept { - ::wisDX12DestroyCommandQueue(handle); - } + void operator()(WisDX12CommandQueue* handle) noexcept { ::wisDX12DestroyCommandQueue(handle); } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a command queue for submitting command lists to the GPU. @@ -4147,10 +4095,10 @@ class DX12CommandQueue inline wis::Result Submit(wis::span lists) const noexcept { const WisResult wis_result = ::wisDX12CommandQueueSubmit( - &_impl_storage, - reinterpret_cast(lists.data()), - lists.size() - ); + &_impl_storage, + reinterpret_cast(lists.data()), + lists.size() + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -4182,9 +4130,7 @@ class DX12CommandQueue }; struct DX12DeviceDeleter { - void operator()(WisDX12Device* handle) noexcept { - ::wisDX12DestroyDevice(handle); - } + void operator()(WisDX12Device* handle) noexcept { ::wisDX12DestroyDevice(handle); } }; /** * @brief Provided by Wisdom 0.7.0. Central class representing logical device. @@ -4204,14 +4150,14 @@ class DX12Device : public wis::impl::Implements(type), - queue.GetStorage() - ); + &_impl_storage, + static_cast(type), + queue.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4233,10 +4179,10 @@ class DX12Device : public wis::impl::Implements(type), - allocator.GetStorage() - ); + &_impl_storage, + static_cast(type), + allocator.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4293,10 +4239,10 @@ class DX12Device : public wis::impl::Implements(&desc), - layout.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&desc), + layout.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4318,10 +4264,10 @@ class DX12Device : public wis::impl::Implements(&desc), - heap.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&desc), + heap.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4347,12 +4293,12 @@ class DX12Device : public wis::impl::Implements(type), - capacity, - static_cast(flags), - heap.GetStorage() - ); + &_impl_storage, + static_cast(type), + capacity, + static_cast(flags), + heap.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4391,13 +4337,13 @@ class DX12Device : public wis::impl::Implements(wait_for), - timeout - ); + &_impl_storage, + fences, + fence_values, + fence_count, + static_cast(wait_for), + timeout + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -4414,11 +4360,11 @@ class DX12Device : public wis::impl::Implements(initial_data.data()), - initial_data.size(), - cache.GetStorage() - ); + &_impl_storage, + reinterpret_cast(initial_data.data()), + initial_data.size(), + cache.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4434,15 +4380,15 @@ class DX12Device : public wis::impl::Implements data, wis::Result& out_result) - const noexcept + const noexcept { wis::DX12Shader shader{}; const WisResult wis_result = ::wisDX12DeviceCreateShader( - &_impl_storage, - reinterpret_cast(data.data()), - data.size(), - shader.GetStorage() - ); + &_impl_storage, + reinterpret_cast(data.data()), + data.size(), + shader.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4464,10 +4410,10 @@ class DX12Device : public wis::impl::Implements(&desc), - pipeline.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&desc), + pipeline.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4489,10 +4435,10 @@ class DX12Device : public wis::impl::Implements(&desc), - pipeline.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&desc), + pipeline.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4509,10 +4455,10 @@ class DX12Device : public wis::impl::Implements(format)) - ); + ); } /** * @brief Provided by Wisdom 0.7.0. Gets presentation parameters for the specified surface. @@ -4528,10 +4474,10 @@ class DX12Device : public wis::impl::Implements(¶ms) - ); + &_impl_storage, + surface, + reinterpret_cast(¶ms) + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4558,12 +4504,12 @@ class DX12Device : public wis::impl::Implements(&surface), - reinterpret_cast(&queue), - reinterpret_cast(&desc), - swapchain.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&surface), + reinterpret_cast(&queue), + reinterpret_cast(&desc), + swapchain.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4579,14 +4525,14 @@ class DX12Device : public wis::impl::Implements(format), - reinterpret_cast(&properties) - ); + &_impl_storage, + static_cast(format), + reinterpret_cast(&properties) + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4597,9 +4543,7 @@ class DX12Device : public wis::impl::Implements(&desc) - ); + &_impl_storage, + index, + reinterpret_cast(&desc) + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4674,11 +4618,11 @@ class DX12AdapterQuery { wis::DX12Device device{}; const WisResult wis_result = ::wisDX12AdapterQueryCreateDevice( - &_impl_storage, - index, - reinterpret_cast(&requirements), - device.GetStorage() - ); + &_impl_storage, + index, + reinterpret_cast(&requirements), + device.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4689,9 +4633,7 @@ class DX12AdapterQuery }; struct DX12InstanceDeleter { - void operator()(WisDX12Instance* handle) noexcept { - ::wisDX12DestroyInstance(handle); - } + void operator()(WisDX12Instance* handle) noexcept { ::wisDX12DestroyInstance(handle); } }; /** * @brief Provided by Wisdom 0.7.0. Class for creating adapters. @@ -4715,14 +4657,14 @@ class DX12Instance * * */ WIS_NODISCARD inline wis::DX12AdapterQuery QueryAdapters(wis::AdapterPreference preference, wis::Result& out_result) - const noexcept + const noexcept { wis::DX12AdapterQuery query{}; const WisResult wis_result = ::wisDX12InstanceQueryAdapters( - &_impl_storage, - static_cast(preference), - query.GetStorage() - ); + &_impl_storage, + static_cast(preference), + query.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -4750,11 +4692,11 @@ WIS_NODISCARD inline wis::DX12Instance DX12CreateInstance( { wis::DX12Instance instance{}; const WisResult wis_result = ::wisDX12CreateInstance( - reinterpret_cast(debug_desc), - reinterpret_cast(extensions.data()), - extensions.size(), - instance.GetStorage() - ); + reinterpret_cast(debug_desc), + reinterpret_cast(extensions.data()), + extensions.size(), + instance.GetStorage() + ); out_result = wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; return instance; } @@ -4968,9 +4910,7 @@ struct VKIndexBufferDesc { }; struct VKTextureDeleter { - void operator()(WisVKTexture* handle) noexcept { - ::wisVKDestroyTexture(handle); - } + void operator()(WisVKTexture* handle) noexcept { ::wisVKDestroyTexture(handle); } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a GPU texture resource. @@ -4988,9 +4928,7 @@ class VKTexture : public wis::impl::Implements(&target_region) - ); + &_impl_storage, + source_data, + reinterpret_cast(&target_region) + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } }; struct VKBufferDeleter { - void operator()(WisVKBuffer* handle) noexcept { - ::wisVKDestroyBuffer(handle); - } + void operator()(WisVKBuffer* handle) noexcept { ::wisVKDestroyBuffer(handle); } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a GPU buffer resource. @@ -5032,17 +4968,13 @@ class VKBuffer : public wis::impl::Implements rects) const noexcept { const WisResult wis_result = ::wisVKSwapchainPresent( - &_impl_storage, - static_cast(flags), - reinterpret_cast(rects.data()), - rects.size() - ); + &_impl_storage, + static_cast(flags), + reinterpret_cast(rects.data()), + rects.size() + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -5098,9 +5028,9 @@ class VKSwapchain : public wis::impl::Implements(&index) - ); + &_impl_storage, + reinterpret_cast(&index) + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -5118,9 +5048,9 @@ class VKSwapchain : public wis::impl::Implements(&desc) - ); + &_impl_storage, + reinterpret_cast(&desc) + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -5132,18 +5062,16 @@ class VKSwapchain : public wis::impl::Implements buffers) const noexcept { const WisResult wis_result = ::wisVKSwapchainGetTextures( - &_impl_storage, - reinterpret_cast(buffers.data()), - buffers.size() - ); + &_impl_storage, + reinterpret_cast(buffers.data()), + buffers.size() + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } }; struct VKSurfaceDeleter { - void operator()(WisVKSurface* handle) noexcept { - ::wisVKDestroySurface(handle); - } + void operator()(WisVKSurface* handle) noexcept { ::wisVKDestroySurface(handle); } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a GPU surface, which can be used as a target for rendering and @@ -5162,15 +5090,11 @@ class VKSurface : public wis::impl::Implements(&texture), - reinterpret_cast(&render_target), - index - )); + &_impl_storage, + reinterpret_cast(&texture), + reinterpret_cast(&render_target), + index + )); } /** * @brief Provided by Wisdom 0.7.0. Writes a depth stencil view to the view heap and returns the CPU descriptor @@ -5222,11 +5146,11 @@ class VKViewHeap : public wis::impl::Implements(&texture), - reinterpret_cast(&render_target), - index - )); + &_impl_storage, + reinterpret_cast(&texture), + reinterpret_cast(&render_target), + index + )); } /** * @brief Provided by Wisdom 0.7.1. Writes a texture view for video decode output and returns the texture view @@ -5244,11 +5168,11 @@ class VKViewHeap : public wis::impl::Implements(&texture), - reinterpret_cast(&render_target), - index - )); + &_impl_storage, + reinterpret_cast(&texture), + reinterpret_cast(&render_target), + index + )); } /** * @brief Provided by Wisdom 0.7.0. Returns the CPU descriptor handle for the view heap. @@ -5289,9 +5213,7 @@ class VKViewHeap : public wis::impl::Implements data) const noexcept { const WisResult wis_result = ::wisVKPipelineCacheSerialize( - &_impl_storage, - reinterpret_cast(data.data()), - data.size() - ); + &_impl_storage, + reinterpret_cast(data.data()), + data.size() + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -5395,9 +5307,7 @@ class VKPipelineCache }; struct VKDescriptorHeapDeleter { - void operator()(WisVKDescriptorHeap* handle) noexcept { - ::wisVKDestroyDescriptorHeap(handle); - } + void operator()(WisVKDescriptorHeap* handle) noexcept { ::wisVKDestroyDescriptorHeap(handle); } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a storage for descriptors used in contiguous array. @@ -5430,10 +5340,10 @@ class VKDescriptorHeap inline wis::Result WriteConstantBuffer(const wis::ConstantBufferBinding& data, std::uint32_t index) const noexcept { const WisResult wis_result = ::wisVKDescriptorHeapWriteConstantBuffer( - &_impl_storage, - reinterpret_cast(&data), - index - ); + &_impl_storage, + reinterpret_cast(&data), + index + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -5452,11 +5362,11 @@ class VKDescriptorHeap ) const noexcept { const WisResult wis_result = ::wisVKDescriptorHeapWriteStructuredBuffer( - &_impl_storage, - buffer, - reinterpret_cast(&data), - index - ); + &_impl_storage, + buffer, + reinterpret_cast(&data), + index + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -5475,11 +5385,11 @@ class VKDescriptorHeap ) const noexcept { const WisResult wis_result = ::wisVKDescriptorHeapWriteRWStructuredBuffer( - &_impl_storage, - buffer, - reinterpret_cast(&data), - index - ); + &_impl_storage, + buffer, + reinterpret_cast(&data), + index + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -5492,10 +5402,10 @@ class VKDescriptorHeap inline wis::Result WriteSampler(const wis::SamplerDesc& sampler, std::uint32_t index) const noexcept { const WisResult wis_result = ::wisVKDescriptorHeapWriteSampler( - &_impl_storage, - reinterpret_cast(&sampler), - index - ); + &_impl_storage, + reinterpret_cast(&sampler), + index + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -5507,14 +5417,14 @@ class VKDescriptorHeap * * */ inline wis::Result WriteTexture(wis::VKTextureView texture, const wis::TextureBinding& data, std::uint32_t index) - const noexcept + const noexcept { const WisResult wis_result = ::wisVKDescriptorHeapWriteTexture( - &_impl_storage, - texture, - reinterpret_cast(&data), - index - ); + &_impl_storage, + texture, + reinterpret_cast(&data), + index + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -5526,14 +5436,14 @@ class VKDescriptorHeap * * */ inline wis::Result WriteRWTexture(wis::VKTextureView texture, const wis::TextureBinding& data, std::uint32_t index) - const noexcept + const noexcept { const WisResult wis_result = ::wisVKDescriptorHeapWriteRWTexture( - &_impl_storage, - texture, - reinterpret_cast(&data), - index - ); + &_impl_storage, + texture, + reinterpret_cast(&data), + index + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -5569,9 +5479,7 @@ class VKDescriptorHeap }; struct VKRootSignatureDeleter { - void operator()(WisVKRootSignature* handle) noexcept { - ::wisVKDestroyRootSignature(handle); - } + void operator()(WisVKRootSignature* handle) noexcept { ::wisVKDestroyRootSignature(handle); } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a pipeline layout and a constant data storage, which defines @@ -5591,15 +5499,11 @@ class VKRootSignature std::memcpy(&v, &_impl_storage, sizeof(v)); return v; } - WIS_NODISCARD operator VKRootSignatureView() const noexcept { - return GetView(); - } + WIS_NODISCARD operator VKRootSignatureView() const noexcept { return GetView(); } }; struct VKResourceAllocatorDeleter { - void operator()(WisVKResourceAllocator* handle) noexcept { - ::wisVKDestroyResourceAllocator(handle); - } + void operator()(WisVKResourceAllocator* handle) noexcept { ::wisVKDestroyResourceAllocator(handle); } }; /** * @brief Provided by Wisdom 0.7.0. Class for allocating and managing GPU resources like buffers and textures. @@ -5607,7 +5511,7 @@ struct VKResourceAllocatorDeleter { * */ class VKResourceAllocator : public wis::impl:: - Implements + Implements { public: using ImplType::ImplType; @@ -5624,10 +5528,10 @@ class VKResourceAllocator { wis::VKBuffer buffer{}; const WisResult wis_result = ::wisVKResourceAllocatorCreateBuffer( - &_impl_storage, - reinterpret_cast(&desc), - buffer.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&desc), + buffer.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -5643,14 +5547,14 @@ class VKResourceAllocator * * */ WIS_NODISCARD inline wis::VKTexture CreateTexture(const wis::TextureDesc& desc, wis::Result& out_result) - const noexcept + const noexcept { wis::VKTexture texture{}; const WisResult wis_result = ::wisVKResourceAllocatorCreateTexture( - &_impl_storage, - reinterpret_cast(&desc), - texture.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&desc), + texture.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -5661,9 +5565,7 @@ class VKResourceAllocator }; struct VKFenceDeleter { - void operator()(WisVKFence* handle) noexcept { - ::wisVKDestroyFence(handle); - } + void operator()(WisVKFence* handle) noexcept { ::wisVKDestroyFence(handle); } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a fence for GPU-CPU and GPU-GPU synchronization. @@ -5681,9 +5583,7 @@ class VKFence : public wis::impl::Implements + Implements { public: using ImplType::ImplType; @@ -6210,9 +6102,7 @@ class VKCommandAllocator }; struct VKCommandQueueDeleter { - void operator()(WisVKCommandQueue* handle) noexcept { - ::wisVKDestroyCommandQueue(handle); - } + void operator()(WisVKCommandQueue* handle) noexcept { ::wisVKDestroyCommandQueue(handle); } }; /** * @brief Provided by Wisdom 0.7.0. Class representing a command queue for submitting command lists to the GPU. @@ -6234,10 +6124,10 @@ class VKCommandQueue inline wis::Result Submit(wis::span lists) const noexcept { const WisResult wis_result = ::wisVKCommandQueueSubmit( - &_impl_storage, - reinterpret_cast(lists.data()), - lists.size() - ); + &_impl_storage, + reinterpret_cast(lists.data()), + lists.size() + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -6269,9 +6159,7 @@ class VKCommandQueue }; struct VKDeviceDeleter { - void operator()(WisVKDevice* handle) noexcept { - ::wisVKDestroyDevice(handle); - } + void operator()(WisVKDevice* handle) noexcept { ::wisVKDestroyDevice(handle); } }; /** * @brief Provided by Wisdom 0.7.0. Central class representing logical device. @@ -6291,14 +6179,14 @@ class VKDevice : public wis::impl::Implements(type), - queue.GetStorage() - ); + &_impl_storage, + static_cast(type), + queue.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6320,10 +6208,10 @@ class VKDevice : public wis::impl::Implements(type), - allocator.GetStorage() - ); + &_impl_storage, + static_cast(type), + allocator.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6380,10 +6268,10 @@ class VKDevice : public wis::impl::Implements(&desc), - layout.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&desc), + layout.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6405,10 +6293,10 @@ class VKDevice : public wis::impl::Implements(&desc), - heap.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&desc), + heap.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6434,12 +6322,12 @@ class VKDevice : public wis::impl::Implements(type), - capacity, - static_cast(flags), - heap.GetStorage() - ); + &_impl_storage, + static_cast(type), + capacity, + static_cast(flags), + heap.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6478,13 +6366,13 @@ class VKDevice : public wis::impl::Implements(wait_for), - timeout - ); + &_impl_storage, + fences, + fence_values, + fence_count, + static_cast(wait_for), + timeout + ); return wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; } /** @@ -6501,11 +6389,11 @@ class VKDevice : public wis::impl::Implements(initial_data.data()), - initial_data.size(), - cache.GetStorage() - ); + &_impl_storage, + reinterpret_cast(initial_data.data()), + initial_data.size(), + cache.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6521,15 +6409,15 @@ class VKDevice : public wis::impl::Implements data, wis::Result& out_result) - const noexcept + const noexcept { wis::VKShader shader{}; const WisResult wis_result = ::wisVKDeviceCreateShader( - &_impl_storage, - reinterpret_cast(data.data()), - data.size(), - shader.GetStorage() - ); + &_impl_storage, + reinterpret_cast(data.data()), + data.size(), + shader.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6551,10 +6439,10 @@ class VKDevice : public wis::impl::Implements(&desc), - pipeline.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&desc), + pipeline.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6576,10 +6464,10 @@ class VKDevice : public wis::impl::Implements(&desc), - pipeline.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&desc), + pipeline.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6596,7 +6484,7 @@ class VKDevice : public wis::impl::Implements(format))); } @@ -6614,10 +6502,10 @@ class VKDevice : public wis::impl::Implements(¶ms) - ); + &_impl_storage, + surface, + reinterpret_cast(¶ms) + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6644,12 +6532,12 @@ class VKDevice : public wis::impl::Implements(&surface), - reinterpret_cast(&queue), - reinterpret_cast(&desc), - swapchain.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&surface), + reinterpret_cast(&queue), + reinterpret_cast(&desc), + swapchain.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6665,14 +6553,14 @@ class VKDevice : public wis::impl::Implements(format), - reinterpret_cast(&properties) - ); + &_impl_storage, + static_cast(format), + reinterpret_cast(&properties) + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6683,9 +6571,7 @@ class VKDevice : public wis::impl::Implements(&desc) - ); + &_impl_storage, + index, + reinterpret_cast(&desc) + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6760,11 +6646,11 @@ class VKAdapterQuery { wis::VKDevice device{}; const WisResult wis_result = ::wisVKAdapterQueryCreateDevice( - &_impl_storage, - index, - reinterpret_cast(&requirements), - device.GetStorage() - ); + &_impl_storage, + index, + reinterpret_cast(&requirements), + device.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6775,9 +6661,7 @@ class VKAdapterQuery }; struct VKInstanceDeleter { - void operator()(WisVKInstance* handle) noexcept { - ::wisVKDestroyInstance(handle); - } + void operator()(WisVKInstance* handle) noexcept { ::wisVKDestroyInstance(handle); } }; /** * @brief Provided by Wisdom 0.7.0. Class for creating adapters. @@ -6800,14 +6684,14 @@ class VKInstance : public wis::impl::Implements(preference), - query.GetStorage() - ); + &_impl_storage, + static_cast(preference), + query.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -6835,11 +6719,11 @@ WIS_NODISCARD inline wis::VKInstance VKCreateInstance( { wis::VKInstance instance{}; const WisResult wis_result = ::wisVKCreateInstance( - reinterpret_cast(debug_desc), - reinterpret_cast(extensions.data()), - extensions.size(), - instance.GetStorage() - ); + reinterpret_cast(debug_desc), + reinterpret_cast(extensions.data()), + extensions.size(), + instance.GetStorage() + ); out_result = wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; return instance; } diff --git a/src/include/wisdom/generated/dx12_convert.hpp b/src/include/wisdom/generated/dx12_convert.hpp index e2095a1b..4465c66a 100644 --- a/src/include/wisdom/generated/dx12_convert.hpp +++ b/src/include/wisdom/generated/dx12_convert.hpp @@ -160,9 +160,7 @@ constexpr inline DXGI_FORMAT DX12Convert(WisDataFormat value) noexcept } } -constexpr inline uint32_t DX12Convert(WisSampleCount value) noexcept { - return static_cast(value); -} +constexpr inline uint32_t DX12Convert(WisSampleCount value) noexcept { return static_cast(value); } constexpr inline DXGI_GPU_PREFERENCE DX12Convert(WisAdapterPreference value) noexcept { @@ -404,17 +402,11 @@ constexpr inline D3D12_PRIMITIVE_TOPOLOGY_TYPE DX12Convert(WisTopologyType value } } -constexpr inline D3D12_FILL_MODE DX12Convert(WisFillMode value) noexcept { - return static_cast(value); -} +constexpr inline D3D12_FILL_MODE DX12Convert(WisFillMode value) noexcept { return static_cast(value); } -constexpr inline D3D12_CULL_MODE DX12Convert(WisCullMode value) noexcept { - return static_cast(value); -} +constexpr inline D3D12_CULL_MODE DX12Convert(WisCullMode value) noexcept { return static_cast(value); } -constexpr inline BOOL DX12Convert(WisWindingOrder value) noexcept { - return static_cast(value); -} +constexpr inline BOOL DX12Convert(WisWindingOrder value) noexcept { return static_cast(value); } constexpr inline D3D12_CONSERVATIVE_RASTERIZATION_MODE DX12Convert(WisConservativeRasterization value) noexcept { @@ -426,17 +418,11 @@ constexpr inline D3D12_LINE_RASTERIZATION_MODE DX12Convert(WisLineRasterization return static_cast(value); } -constexpr inline D3D12_BLEND DX12Convert(WisBlendFactor value) noexcept { - return static_cast(value); -} +constexpr inline D3D12_BLEND DX12Convert(WisBlendFactor value) noexcept { return static_cast(value); } -constexpr inline D3D12_BLEND_OP DX12Convert(WisBlendOp value) noexcept { - return static_cast(value); -} +constexpr inline D3D12_BLEND_OP DX12Convert(WisBlendOp value) noexcept { return static_cast(value); } -constexpr inline D3D12_LOGIC_OP DX12Convert(WisLogicOp value) noexcept { - return static_cast(value); -} +constexpr inline D3D12_LOGIC_OP DX12Convert(WisLogicOp value) noexcept { return static_cast(value); } constexpr inline D3D_PRIMITIVE_TOPOLOGY DX12Convert(WisPrimitiveTopology value) noexcept { diff --git a/src/include/wisdom/generated/vk_convert.hpp b/src/include/wisdom/generated/vk_convert.hpp index 8628bbd4..24abc9e4 100644 --- a/src/include/wisdom/generated/vk_convert.hpp +++ b/src/include/wisdom/generated/vk_convert.hpp @@ -371,7 +371,7 @@ constexpr inline VkMemoryPropertyFlags VKConvert(WisMemoryType value) noexcept return VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT; case WisMemoryTypeGPUUpload: return VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT - | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; + | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; default: return static_cast(0); } @@ -855,9 +855,9 @@ constexpr inline VkPipelineStageFlags2 VKConvert(WisBarrierSync value) noexcept } if (value & WisBarrierSyncDraw) { result |= VK_PIPELINE_STAGE_2_VERTEX_ATTRIBUTE_INPUT_BIT | VK_PIPELINE_STAGE_2_INDEX_INPUT_BIT - | VK_PIPELINE_STAGE_2_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT - | VK_PIPELINE_STAGE_2_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_2_LATE_FRAGMENT_TESTS_BIT - | VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT; + | VK_PIPELINE_STAGE_2_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT + | VK_PIPELINE_STAGE_2_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_2_LATE_FRAGMENT_TESTS_BIT + | VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT; } if (value & WisBarrierSyncIndexInput) { result |= VK_PIPELINE_STAGE_2_INDEX_INPUT_BIT; @@ -885,14 +885,14 @@ constexpr inline VkPipelineStageFlags2 VKConvert(WisBarrierSync value) noexcept } if (value & WisBarrierSyncResolve) { result |= VK_PIPELINE_STAGE_2_COPY_BIT | VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT - | VK_PIPELINE_STAGE_2_RESOLVE_BIT | VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT; + | VK_PIPELINE_STAGE_2_RESOLVE_BIT | VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT; } if (value & WisBarrierSyncExecuteIndirect) { result |= VK_PIPELINE_STAGE_2_DRAW_INDIRECT_BIT | VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT; } if (value & WisBarrierSyncAllShading) { result |= VK_PIPELINE_STAGE_2_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT - | VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT; + | VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT; } if (value & WisBarrierSyncNonPixelShading) { result |= VK_PIPELINE_STAGE_2_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT; diff --git a/src/include/wisdom/global/internal.hpp b/src/include/wisdom/global/internal.hpp index 29cca6a0..c1ac2ff2 100644 --- a/src/include/wisdom/global/internal.hpp +++ b/src/include/wisdom/global/internal.hpp @@ -78,9 +78,7 @@ struct Implements { } /// @brief Destructor, calls the Deleter on the internal implementation - ~Implements() noexcept { - Deleter{}(GetStorage()); - } + ~Implements() noexcept { Deleter{}(GetStorage()); } public: /// @brief Get the immutable internal implementation @@ -99,9 +97,7 @@ struct Implements { /// @brief Get the storage pointer /// @return Pointer to the storage - [[nodiscard]] Storage* GetStorage() noexcept { - return &_impl_storage; - } + [[nodiscard]] Storage* GetStorage() noexcept { return &_impl_storage; } /// @brief Check if the handle holds a valid object /// @return true if the first 8 bytes of storage are non-zero @@ -112,9 +108,7 @@ struct Implements { } /// @brief Bool conversion, checks handle validity - explicit operator bool() const noexcept { - return IsValid(); - } + explicit operator bool() const noexcept { return IsValid(); } public: Storage _impl_storage; diff --git a/src/include/wisdom/vulkan/detail/vk_detail.hpp b/src/include/wisdom/vulkan/detail/vk_detail.hpp index 348e2094..44e833c4 100644 --- a/src/include/wisdom/vulkan/detail/vk_detail.hpp +++ b/src/include/wisdom/vulkan/detail/vk_detail.hpp @@ -43,12 +43,8 @@ struct VKScopeGuard { VKScopeGuard(const VKScopeGuard&) = delete; VKScopeGuard& operator=(const VKScopeGuard&) = delete; - HandleType* PutUnchecked() noexcept { - return &handle; - } - HandleType Release() noexcept { - return std::exchange(handle, nullptr); - } + HandleType* PutUnchecked() noexcept { return &handle; } + HandleType Release() noexcept { return std::exchange(handle, nullptr); } }; template @@ -147,7 +143,7 @@ struct VKDebugCallbackThunk { // Get device handle if possible uint64_t device = 0; for (auto&& obj : - wis::span {pCallbackData->pObjects, pCallbackData->objectCount}) { + wis::span{pCallbackData->pObjects, pCallbackData->objectCount}) { if (obj.objectType == VK_OBJECT_TYPE_DEVICE) { device = obj.objectHandle; break; @@ -273,8 +269,8 @@ struct VKDeviceHeader { // Destroy semaphores auto& last_family = queue_families[family_count - 1]; std::binary_semaphore* begin = reinterpret_cast( - reinterpret_cast(this) + sizeof(*this) - ); + reinterpret_cast(this) + sizeof(*this) + ); std::binary_semaphore* end = last_family.semaphore_offset + last_family.queue_count + begin; for (std::binary_semaphore* sem = begin; sem < end; ++sem) { sem->release(); @@ -295,7 +291,7 @@ struct VKDeviceHeader { return nullptr; // No valid family index for this queue type } return reinterpret_cast(reinterpret_cast(this) + sizeof(*this)) - + queue_families[type].semaphore_offset + queue_index; + + queue_families[type].semaphore_offset + queue_index; } }; @@ -328,11 +324,11 @@ struct VKSwapchainHeader { VkSurfaceKHR surface; // store surface handle for later use in presentation and swapchain recreation VkPhysicalDevice physical_device; // store physical device for later use in swapchain recreation PFN_vkGetPhysicalDeviceSurfaceCapabilities2KHR - vkGetPhysicalDeviceSurfaceCapabilities2KHR; // store function pointer for later use in swapchain recreation + vkGetPhysicalDeviceSurfaceCapabilities2KHR; // store function pointer for later use in swapchain recreation VkSwapchainCreateInfoKHR create_info; // store create info for later use in presentation and swapchain recreation VkSwapchainPresentScalingCreateInfoKHR - scaling_create_info; // store scaling create info for later use in presentation and swapchain recreation + scaling_create_info; // store scaling create info for later use in presentation and swapchain recreation VkPresentModeKHR modes[reasonable_mode_count]; uint8_t mode_count; @@ -341,29 +337,29 @@ struct VKSwapchainHeader { wis::span GetImageAvailableSemaphores() const noexcept { - return wis::span {reinterpret_cast(this + 1), create_info.minImageCount}; + return wis::span{reinterpret_cast(this + 1), create_info.minImageCount}; } wis::span GetRenderFinishedSemaphores() const noexcept { - return wis::span { + return wis::span{ reinterpret_cast(this + 1) + create_info.minImageCount, create_info.minImageCount }; } wis::span GetSemaphores() const noexcept { - return wis::span { + return wis::span{ reinterpret_cast(this + 1), create_info.minImageCount * 2 }; } wis::span GetSupportedPresentModes() const noexcept { - return wis::span {modes, mode_count}; + return wis::span{modes, mode_count}; } wis::span GetSupportedFormats() noexcept { - return wis::span { + return wis::span{ reinterpret_cast(this + 1) + create_info.minImageCount * 2, format_count }; @@ -400,24 +396,24 @@ struct alignas(void*) VKRootSignatureControlBlock { wis::span GetRootBindingOffsets() const noexcept { - return wis::span {reinterpret_cast(this + 1), root_parameter_count}; + return wis::span{reinterpret_cast(this + 1), root_parameter_count}; } wis::span GetRootBindingOffsets() noexcept { - return wis::span {reinterpret_cast(this + 1), root_parameter_count}; + return wis::span{reinterpret_cast(this + 1), root_parameter_count}; } wis::span GetMappings() noexcept { - return wis::span { + return wis::span{ reinterpret_cast(GetRootBindingOffsets().end()), mapping_count }; } wis::span GetMappings() const noexcept { - return wis::span { + return wis::span{ reinterpret_cast(GetRootBindingOffsets().end()), mapping_count }; @@ -626,8 +622,8 @@ inline void VKReleaseSwapchain(VkSwapchainKHR swap, VKSwapchainControlBlock* hea //---------------------------------------------------------------------------------------------------------------------- // Barrier helper constants constexpr static uint32_t vk_max_barrier_size = std::max( -{sizeof(VkBufferMemoryBarrier), sizeof(VkImageMemoryBarrier2), sizeof(VkMemoryBarrier2)} - ); + {sizeof(VkBufferMemoryBarrier), sizeof(VkImageMemoryBarrier2), sizeof(VkMemoryBarrier2)} +); constexpr static uint32_t vk_static_barrier_size = WIS_TRANSIENT_MAX_BARRIER_COUNT * vk_max_barrier_size; template @@ -650,8 +646,8 @@ inline std::array, 3> VKAllocateBarriers( { std::array, 3> spans; std::size_t needed_size = barriers.buffer_barrier_count * sizeof(VkBufferMemoryBarrier2) - + barriers.texture_barrier_count * sizeof(VkImageMemoryBarrier2) - + barriers.global_barrier_count * sizeof(VkMemoryBarrier2); + + barriers.texture_barrier_count * sizeof(VkImageMemoryBarrier2) + + barriers.global_barrier_count * sizeof(VkMemoryBarrier2); if (needed_size <= vk_static_barrier_size) { spans[0] = {local_scratch, barriers.buffer_barrier_count * sizeof(VkBufferMemoryBarrier2)}; @@ -735,7 +731,7 @@ inline void VKInsertBarriers(const Impl& impl, const WisVKBarrierGroup* barriers return; } - uint8_t local_scratch[vk_static_barrier_size] {}; + uint8_t local_scratch[vk_static_barrier_size]{}; auto [buffer_span, texture_span, global_span] = VKAllocateBarriers(impl, local_scratch, *barriers); @@ -787,8 +783,8 @@ inline void VKInsertBarriers(const Impl& impl, const WisVKBarrierGroup* barriers if (src.queue_type_before != src.queue_type_after) { if (impl.maintenance9 - && (impl.queue_indices[src.queue_type_before].compatible_to_families - & (1 << impl.queue_indices[src.queue_type_after].family_index))) { + && (impl.queue_indices[src.queue_type_before].compatible_to_families + & (1 << impl.queue_indices[src.queue_type_after].family_index))) { if (src.queue_type_before == impl.queue_type) { real_texture_barrier_count--; continue; diff --git a/src/include/wisdom/vulkan/detail/vk_ext1.hpp b/src/include/wisdom/vulkan/detail/vk_ext1.hpp index fcded411..443490af 100644 --- a/src/include/wisdom/vulkan/detail/vk_ext1.hpp +++ b/src/include/wisdom/vulkan/detail/vk_ext1.hpp @@ -165,33 +165,33 @@ struct DeviceExtension1 : VKDeviceExtensionImpl { if (features.descriptor_heap) { // Descriptor heap properties auto& descriptor_heap_properties = *collector.GetEnabledPropertyStruct< - VkPhysicalDeviceDescriptorHeapPropertiesEXT>( - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_HEAP_PROPERTIES_EXT - ); + VkPhysicalDeviceDescriptorHeapPropertiesEXT>( + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_HEAP_PROPERTIES_EXT + ); // A lot of space is going to be wasted, but the usage will be simpler and more efficient if we use the same // size for both resource and sampler descriptors, so we take the max of the two alignments as the // descriptor size features.resource_desc_size = static_cast(std::max( - descriptor_heap_properties.imageDescriptorAlignment, - descriptor_heap_properties.bufferDescriptorAlignment - )); + descriptor_heap_properties.imageDescriptorAlignment, + descriptor_heap_properties.bufferDescriptorAlignment + )); features.sampler_desc_size = static_cast(descriptor_heap_properties.samplerDescriptorAlignment); features.max_root_space = static_cast(descriptor_heap_properties.maxPushDataSize); features.descriptor_heap_reserved_size = wis::aligned_size( - static_cast(descriptor_heap_properties.minResourceHeapReservedRange), - features.resource_desc_size - ); + static_cast(descriptor_heap_properties.minResourceHeapReservedRange), + features.resource_desc_size + ); features.sampler_heap_reserved_size = wis::aligned_size( - static_cast(descriptor_heap_properties.minSamplerHeapReservedRange), - features.sampler_desc_size - ); + static_cast(descriptor_heap_properties.minSamplerHeapReservedRange), + features.sampler_desc_size + ); features.sampler_heap_reserved_size_with_embedded = wis::aligned_size( - static_cast(descriptor_heap_properties.minSamplerHeapReservedRangeWithEmbedded), - features.sampler_desc_size - ); + static_cast(descriptor_heap_properties.minSamplerHeapReservedRangeWithEmbedded), + features.sampler_desc_size + ); features.descriptor_heap_alignment = static_cast(descriptor_heap_properties.resourceHeapAlignment - ); + ); features.sampler_heap_alignment = static_cast(descriptor_heap_properties.samplerHeapAlignment); features.max_descriptor_heap_size = descriptor_heap_properties.maxResourceHeapSize; features.max_sampler_heap_size = descriptor_heap_properties.maxSamplerHeapSize; @@ -199,11 +199,11 @@ struct DeviceExtension1 : VKDeviceExtensionImpl { // Get Device properties auto& device_properties = *collector.GetEnabledPropertyStruct( - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2 - ); + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2 + ); features.max_vertex_attributes = static_cast( - device_properties.properties.limits.maxVertexInputAttributes - ); + device_properties.properties.limits.maxVertexInputAttributes + ); features.max_vertex_bindings = static_cast(device_properties.properties.limits.maxVertexInputBindings); features.multiple_viewports = device_properties.properties.limits.maxViewports > 1 ? 1 : 0; diff --git a/src/include/wisdom/vulkan/vk_command_list.cpp b/src/include/wisdom/vulkan/vk_command_list.cpp index 9b9df387..149a867c 100644 --- a/src/include/wisdom/vulkan/vk_command_list.cpp +++ b/src/include/wisdom/vulkan/vk_command_list.cpp @@ -60,9 +60,9 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListSetDescriptorHeaps( if (resource_heap) { auto& res_heap = wis::from_handle_ref(resource_heap); VkDeviceSize reserved_resource_descriptor_size = static_cast(res_heap.reserved_size) - * res_heap.descriptor_size; + * res_heap.descriptor_size; VkDeviceSize total_resource_heap_size = static_cast(res_heap.heap_size) * res_heap.descriptor_size - + reserved_resource_descriptor_size; + + reserved_resource_descriptor_size; VkBindHeapInfoEXT bind_resource_info{ .sType = VK_STRUCTURE_TYPE_BIND_HEAP_INFO_EXT, .pNext = nullptr, @@ -76,9 +76,9 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListSetDescriptorHeaps( if (sampler_heap) { auto& samp_heap = wis::from_handle_ref(sampler_heap); VkDeviceSize reserved_sampler_descriptor_size = static_cast(samp_heap.reserved_size) - * samp_heap.descriptor_size; + * samp_heap.descriptor_size; VkDeviceSize total_sampler_heap_size = static_cast(samp_heap.heap_size) * samp_heap.descriptor_size - + reserved_sampler_descriptor_size; + + reserved_sampler_descriptor_size; VkBindHeapInfoEXT bind_sampler_info{ .sType = VK_STRUCTURE_TYPE_BIND_HEAP_INFO_EXT, .pNext = nullptr, @@ -204,7 +204,7 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListSetViewports( }; } impl.command_list_table - ->vkCmdSetViewportWithCount(impl.command_buffer, static_cast(max_count), vk_viewports); + ->vkCmdSetViewportWithCount(impl.command_buffer, static_cast(max_count), vk_viewports); } //---------------------------------------------------------------------------------------------------------------------- @@ -240,7 +240,7 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListSetDepthBias( { auto& impl = wis::from_handle_ref(self); impl.command_list_table - ->vkCmdSetDepthBias(impl.command_buffer, depth_bias, depth_bias_clamp, slope_scaled_depth_bias); + ->vkCmdSetDepthBias(impl.command_buffer, depth_bias, depth_bias_clamp, slope_scaled_depth_bias); } //---------------------------------------------------------------------------------------------------------------------- @@ -428,7 +428,7 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListDrawIndexed( { auto& impl = wis::from_handle_ref(self); impl.command_list_table - ->vkCmdDrawIndexed(impl.command_buffer, index_count, instance_count, start_index, base_vertex, start_instance); + ->vkCmdDrawIndexed(impl.command_buffer, index_count, instance_count, start_index, base_vertex, start_instance); } //---------------------------------------------------------------------------------------------------------------------- @@ -469,8 +469,8 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListCopyBufferToTexture( while (region_offset < region_count) { uint32_t current_region_count = static_cast( - std::min(region_count - region_offset, static_cast(wis::MaxCopyRegions)) - ); + std::min(region_count - region_offset, static_cast(wis::MaxCopyRegions)) + ); for (size_t i = 0; i < current_region_count; ++i) { const auto& region = regions[region_offset + i]; @@ -487,8 +487,8 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListCopyBufferToTexture( } if (aspect_mask == 0) { aspect_mask = (region.texture_region.flags & WisBarrierFlagsPlanarImage) - ? (VK_IMAGE_ASPECT_PLANE_0_BIT << subresource.plane_slice) - : VK_IMAGE_ASPECT_COLOR_BIT; + ? (VK_IMAGE_ASPECT_PLANE_0_BIT << subresource.plane_slice) + : VK_IMAGE_ASPECT_COLOR_BIT; } convert_regions[i] = { @@ -496,18 +496,18 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListCopyBufferToTexture( .bufferRowLength = region.buffer_row_length, .bufferImageHeight = region.buffer_image_height, .imageSubresource = - { - .aspectMask = aspect_mask, - .mipLevel = subresource.mip_level, - .baseArrayLayer = subresource.array_layer, - .layerCount = 1, - }, + { + .aspectMask = aspect_mask, + .mipLevel = subresource.mip_level, + .baseArrayLayer = subresource.array_layer, + .layerCount = 1, + }, .imageOffset = - { - .x = static_cast(box.x), - .y = static_cast(box.y), - .z = static_cast(box.z), - }, + { + .x = static_cast(box.x), + .y = static_cast(box.y), + .z = static_cast(box.z), + }, .imageExtent = {.width = box.width, .height = box.height, .depth = box.depth}, }; } @@ -540,8 +540,8 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListCopyTextureToBuffer( while (region_offset < region_count) { uint32_t current_region_count = static_cast( - std::min(region_count - region_offset, static_cast(wis::MaxCopyRegions)) - ); + std::min(region_count - region_offset, static_cast(wis::MaxCopyRegions)) + ); for (size_t i = 0; i < current_region_count; ++i) { const auto& region = regions[region_offset + i]; @@ -558,8 +558,8 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListCopyTextureToBuffer( } if (aspect_mask == 0) { aspect_mask = (region.texture_region.flags & WisBarrierFlagsPlanarImage) - ? (VK_IMAGE_ASPECT_PLANE_0_BIT << subresource.plane_slice) - : VK_IMAGE_ASPECT_COLOR_BIT; + ? (VK_IMAGE_ASPECT_PLANE_0_BIT << subresource.plane_slice) + : VK_IMAGE_ASPECT_COLOR_BIT; } convert_regions[i] = { @@ -567,18 +567,18 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListCopyTextureToBuffer( .bufferRowLength = region.buffer_row_length, .bufferImageHeight = region.buffer_image_height, .imageSubresource = - { - .aspectMask = aspect_mask, - .mipLevel = subresource.mip_level, - .baseArrayLayer = subresource.array_layer, - .layerCount = 1, - }, + { + .aspectMask = aspect_mask, + .mipLevel = subresource.mip_level, + .baseArrayLayer = subresource.array_layer, + .layerCount = 1, + }, .imageOffset = - { - .x = static_cast(box.x), - .y = static_cast(box.y), - .z = static_cast(box.z), - }, + { + .x = static_cast(box.x), + .y = static_cast(box.y), + .z = static_cast(box.z), + }, .imageExtent = {.width = box.width, .height = box.height, .depth = box.depth}, }; } @@ -611,8 +611,8 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListCopyTexture( while (region_offset < region_count) { uint32_t current_region_count = static_cast( - std::min(region_count - region_offset, static_cast(wis::MaxCopyRegions)) - ); + std::min(region_count - region_offset, static_cast(wis::MaxCopyRegions)) + ); for (size_t i = 0; i < current_region_count; ++i) { const auto& region = regions[region_offset + i]; @@ -630,8 +630,8 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListCopyTexture( } if (src_aspect_mask == 0) { src_aspect_mask = (region.src_region.flags & WisBarrierFlagsPlanarImage) - ? (VK_IMAGE_ASPECT_PLANE_0_BIT << src_subresource.plane_slice) - : VK_IMAGE_ASPECT_COLOR_BIT; + ? (VK_IMAGE_ASPECT_PLANE_0_BIT << src_subresource.plane_slice) + : VK_IMAGE_ASPECT_COLOR_BIT; } VkImageAspectFlags dst_aspect_mask = 0; @@ -643,37 +643,37 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListCopyTexture( } if (dst_aspect_mask == 0) { dst_aspect_mask = (region.dst_region.flags & WisBarrierFlagsPlanarImage) - ? (VK_IMAGE_ASPECT_PLANE_0_BIT << dst_subresource.plane_slice) - : VK_IMAGE_ASPECT_COLOR_BIT; + ? (VK_IMAGE_ASPECT_PLANE_0_BIT << dst_subresource.plane_slice) + : VK_IMAGE_ASPECT_COLOR_BIT; } convert_regions[i] = { .srcSubresource = - { - .aspectMask = src_aspect_mask, - .mipLevel = src_subresource.mip_level, - .baseArrayLayer = src_subresource.array_layer, - .layerCount = 1, - }, + { + .aspectMask = src_aspect_mask, + .mipLevel = src_subresource.mip_level, + .baseArrayLayer = src_subresource.array_layer, + .layerCount = 1, + }, .srcOffset = - { - .x = static_cast(src_box.x), - .y = static_cast(src_box.y), - .z = static_cast(src_box.z), - }, + { + .x = static_cast(src_box.x), + .y = static_cast(src_box.y), + .z = static_cast(src_box.z), + }, .dstSubresource = - { - .aspectMask = dst_aspect_mask, - .mipLevel = dst_subresource.mip_level, - .baseArrayLayer = dst_subresource.array_layer, - .layerCount = 1, - }, + { + .aspectMask = dst_aspect_mask, + .mipLevel = dst_subresource.mip_level, + .baseArrayLayer = dst_subresource.array_layer, + .layerCount = 1, + }, .dstOffset = - { - .x = static_cast(dst_box.x), - .y = static_cast(dst_box.y), - .z = static_cast(dst_box.z), - }, + { + .x = static_cast(dst_box.x), + .y = static_cast(dst_box.y), + .z = static_cast(dst_box.z), + }, .extent = {.width = src_box.width, .height = src_box.height, .depth = src_box.depth}, }; } @@ -717,7 +717,7 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListSetVertexBuffers( } impl.command_list_table - ->vkCmdBindVertexBuffers2(impl.command_buffer, start_slot, count, buffers_vk, offsets, sizes, strides); + ->vkCmdBindVertexBuffers2(impl.command_buffer, start_slot, count, buffers_vk, offsets, sizes, strides); } //---------------------------------------------------------------------------------------------------------------------- @@ -738,17 +738,17 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListSetVertexBuffers2( .pNext = nullptr, .setStride = VK_TRUE, .addressRange = - { - .address = buffers[i].buffer, - .size = buffers[i].size, - .stride = buffers[i].stride, - }, + { + .address = buffers[i].buffer, + .size = buffers[i].size, + .stride = buffers[i].stride, + }, .addressFlags = 0, // reserved for future use }; } impl.command_list_table - ->vkCmdBindVertexBuffers3KHR(impl.command_buffer, start_slot, count, bind_vertex_buffer_infos); + ->vkCmdBindVertexBuffers3KHR(impl.command_buffer, start_slot, count, bind_vertex_buffer_infos); } //---------------------------------------------------------------------------------------------------------------------- @@ -781,10 +781,10 @@ WIS_EXTERN_C WISDOM_API void wisVKCommandListSetIndexBuffer2( .sType = VK_STRUCTURE_TYPE_BIND_INDEX_BUFFER_3_INFO_KHR, .pNext = nullptr, .addressRange = - { - .address = buffer->buffer, - .size = buffer->size, - }, + { + .address = buffer->buffer, + .size = buffer->size, + }, .addressFlags = 0, // reserved for future use .indexType = wis::detail::VKConvert(index_type), }; diff --git a/src/include/wisdom/vulkan/vk_descriptor_heap.cpp b/src/include/wisdom/vulkan/vk_descriptor_heap.cpp index 1a2b5e78..ca54117a 100644 --- a/src/include/wisdom/vulkan/vk_descriptor_heap.cpp +++ b/src/include/wisdom/vulkan/vk_descriptor_heap.cpp @@ -12,12 +12,12 @@ namespace wis::detail { inline VkImageAspectFlags VKGetAspectFlags(const WisTextureBinding& binding) noexcept { if ((binding.flags & WisTextureBindingFlagsStencilView) - && (binding.format == WisDataFormatD24UnormS8Uint || binding.format == WisDataFormatD32FloatS8Uint)) { + && (binding.format == WisDataFormatD24UnormS8Uint || binding.format == WisDataFormatD32FloatS8Uint)) { return VK_IMAGE_ASPECT_STENCIL_BIT; } if ((binding.flags & WisTextureBindingFlagsDepthView) && (binding.format == WisDataFormatD32FloatS8Uint || binding.format == WisDataFormatD24UnormS8Uint) - || (binding.format == WisDataFormatD16Unorm || binding.format == WisDataFormatD32Float)) { + || (binding.format == WisDataFormatD16Unorm || binding.format == WisDataFormatD32Float)) { return VK_IMAGE_ASPECT_DEPTH_BIT; } if (binding.range.plane_slice) { @@ -34,12 +34,12 @@ inline VkImageViewCreateInfo VKGetSRVDesc(const WisTextureBinding& binding) noex .flags = 0, .format = wis::detail::VKConvert(binding.format), .components = - { - .r = wis::detail::VKConvert(binding.component_mapping.r), - .g = wis::detail::VKConvert(binding.component_mapping.g), - .b = wis::detail::VKConvert(binding.component_mapping.b), - .a = wis::detail::VKConvert(binding.component_mapping.a), - }, + { + .r = wis::detail::VKConvert(binding.component_mapping.r), + .g = wis::detail::VKConvert(binding.component_mapping.g), + .b = wis::detail::VKConvert(binding.component_mapping.b), + .a = wis::detail::VKConvert(binding.component_mapping.a), + }, }; auto aspect_flags = VKGetAspectFlags(binding); @@ -98,7 +98,7 @@ inline VkImageViewCreateInfo VKGetSRVDesc(const WisTextureBinding& binding) noex case WisTextureLayoutTexture2DMS: srv_desc.viewType = VK_IMAGE_VIEW_TYPE_2D; srv_desc.subresourceRange = - {.aspectMask = aspect_flags, .baseMipLevel = 0, .levelCount = 1, .baseArrayLayer = 0, .layerCount = 1}; + {.aspectMask = aspect_flags, .baseMipLevel = 0, .levelCount = 1, .baseArrayLayer = 0, .layerCount = 1}; break; case WisTextureLayoutTexture2DMSArray: srv_desc.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY; @@ -343,7 +343,7 @@ WIS_EXTERN_C WISDOM_API void wisVKDestroyViewHeap(WisVKViewHeap* self) for (uint32_t i = 0; i < impl.capacity; ++i) { if (impl.view_heap[i].view != VK_NULL_HANDLE) { impl.device_header->header.device_table - .vkDestroyImageView(impl.device_header->header.device, impl.view_heap[i].view, nullptr); + .vkDestroyImageView(impl.device_header->header.device, impl.view_heap[i].view, nullptr); } } @@ -388,7 +388,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDescriptorHeapWriteConstantBuffer( VkResult result = table.vkWriteResourceDescriptorsEXT(heap.device, 1, &resource_desc, &host_range); if (!wis::detail::succeeded(result)) { return wis::detail:: - make_result(result); + make_result(result); } return wis::detail::vk_success; } @@ -430,7 +430,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDescriptorHeapWriteStructuredBuffer( VkResult result = table.vkWriteResourceDescriptorsEXT(heap.device, 1, &resource_desc, &host_range); if (!wis::detail::succeeded(result)) { return wis::detail:: - make_result(result); + make_result(result); } return wis::detail::vk_success; } @@ -464,7 +464,7 @@ wisVKDescriptorHeapWriteSampler(const WisVKDescriptorHeap* self, const WisSample .sType = VK_STRUCTURE_TYPE_SAMPLER_REDUCTION_MODE_CREATE_INFO, .pNext = nullptr, // Custom border? .reductionMode = sampler->comparison_op != WisCompareOpNever ? VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE - : wis::detail::VKConvert(sampler->reduction_mode) + : wis::detail::VKConvert(sampler->reduction_mode) }; VkSamplerCreateInfo sampler_info{ .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, @@ -489,7 +489,7 @@ wisVKDescriptorHeapWriteSampler(const WisVKDescriptorHeap* self, const WisSample VkResult result = table.vkWriteSamplerDescriptorsEXT(heap.device, 1, &sampler_info, &host_range); if (!wis::detail::succeeded(result)) { return wis::detail:: - make_result(result); + make_result(result); } return wis::detail::vk_success; } @@ -534,7 +534,7 @@ WISDOM_API WisResult wisVKDescriptorHeapWriteTexture( VkResult result = table.vkWriteResourceDescriptorsEXT(heap.device, 1, &resource_desc, &host_range); if (!wis::detail::succeeded(result)) { return wis::detail:: - make_result(result); + make_result(result); } return wis::detail::vk_success; } @@ -573,7 +573,7 @@ WISDOM_API WisResult wisVKDescriptorHeapWriteRWTexture( VkResult result = table.vkWriteResourceDescriptorsEXT(heap.device, 1, &resource_desc, &host_range); if (!wis::detail::succeeded(result)) { return wis::detail:: - make_result(result); + make_result(result); } return wis::detail::vk_success; } @@ -602,7 +602,7 @@ wisVKDescriptorHeapWriteAccelerationStructure(const WisVKDescriptorHeap* self, u VkResult result = table.vkWriteResourceDescriptorsEXT(heap.device, 1, &resource_desc, &host_range); if (!wis::detail::succeeded(result)) { return wis::detail:: - make_result(result); + make_result(result); } return wis::detail::vk_success; } @@ -688,13 +688,13 @@ WIS_EXTERN_C WISDOM_API void wisVKViewHeapCopyViews( return; // Invalid range, do nothing } auto* src_views = reinterpret_cast(std::bit_cast(src_ptr)) - + src_index; + + src_index; auto* dst_views = heap.view_heap + dst_index; for (uint32_t i = 0; i < count; ++i) { // Destroy existing view at destination if it's not null if (dst_views[i].view != VK_NULL_HANDLE) { heap.device_header->header.device_table - .vkDestroyImageView(heap.device_header->header.device, dst_views[i].view, nullptr); + .vkDestroyImageView(heap.device_header->header.device, dst_views[i].view, nullptr); } dst_views[i] = src_views[i]; } diff --git a/src/include/wisdom/vulkan/vk_device.cpp b/src/include/wisdom/vulkan/vk_device.cpp index 42e41aec..b9474ace 100644 --- a/src/include/wisdom/vulkan/vk_device.cpp +++ b/src/include/wisdom/vulkan/vk_device.cpp @@ -29,7 +29,7 @@ constexpr VkSpirvResourceTypeFlagsEXT GetResourceTypeFlags(const WisDescriptorTy return VK_SPIRV_RESOURCE_TYPE_READ_WRITE_STORAGE_BUFFER_BIT_EXT; case WisDescriptorTypeBuffer: return VK_SPIRV_RESOURCE_TYPE_READ_WRITE_STORAGE_BUFFER_BIT_EXT - | VK_SPIRV_RESOURCE_TYPE_READ_ONLY_STORAGE_BUFFER_BIT_EXT; + | VK_SPIRV_RESOURCE_TYPE_READ_ONLY_STORAGE_BUFFER_BIT_EXT; case WisDescriptorTypeAccelerationStructure: return VK_SPIRV_RESOURCE_TYPE_ACCELERATION_STRUCTURE_BIT_EXT; default: @@ -38,7 +38,7 @@ constexpr VkSpirvResourceTypeFlagsEXT GetResourceTypeFlags(const WisDescriptorTy } inline std::array GetMapCountPerShaderType(const WisRootSignatureDesc& desc - ) noexcept +) noexcept { std::array counts{}; // 1. Push constants @@ -128,16 +128,16 @@ wisVKDeviceCreateCommandQueue(const WisVKDevice* self, WisCommandQueueType type, using QueueTypeUnderlying = std::underlying_type_t; if (static_cast(type) < 0 || static_cast(type) >= WisCommandQueueTypeCount) { return wis::detail::make_result( - VK_ERROR_INITIALIZATION_FAILED - ); + VK_ERROR_INITIALIZATION_FAILED + ); } // Get queue family index based on type uint8_t queue_family_index = device.device_header->header.queue_residency[static_cast(type)]; if (queue_family_index == wis::detail::VKQueueFamilyProperties::invalid_family_index) { return wis::detail::make_result< - wis::detail::Func(), - "No suitable queue family found for the requested queue type">(VK_ERROR_FEATURE_NOT_PRESENT); + wis::detail::Func(), + "No suitable queue family found for the requested queue type">(VK_ERROR_FEATURE_NOT_PRESENT); } auto& queue_family = device.device_header->header.queue_families[queue_family_index]; @@ -176,24 +176,24 @@ wisVKDeviceCreateCommandAllocator(const WisVKDevice* self, WisCommandQueueType t using QueueTypeUnderlying = std::underlying_type_t; if (static_cast(type) < 0 || static_cast(type) >= WisCommandQueueTypeCount) { return wis::detail::make_result( - VK_ERROR_INITIALIZATION_FAILED - ); + VK_ERROR_INITIALIZATION_FAILED + ); } // Get queue family index based on type uint8_t queue_family_index = device.device_header->header.queue_residency[static_cast(type)]; if (queue_family_index == wis::detail::VKQueueFamilyProperties::invalid_family_index) { return wis::detail::make_result< - wis::detail::Func(), - "No suitable queue family found for the requested queue type">(VK_ERROR_FEATURE_NOT_PRESENT); + wis::detail::Func(), + "No suitable queue family found for the requested queue type">(VK_ERROR_FEATURE_NOT_PRESENT); } std::unique_ptr - pool_control_block = wis::make_unique(); + pool_control_block = wis::make_unique(); if (!pool_control_block) { return wis::detail::make_result< - wis::detail::Func(), - "Failed to allocate memory for command pool control block">(VK_ERROR_OUT_OF_HOST_MEMORY); + wis::detail::Func(), + "Failed to allocate memory for command pool control block">(VK_ERROR_OUT_OF_HOST_MEMORY); } uint8_t queue_family = device.device_header->header.queue_families[queue_family_index].family_index; @@ -286,8 +286,8 @@ wisVKDeviceCreateDescriptorHeap(const WisVKDevice* self, const WisDescriptorHeap // 0. If heap is supported if (!features.descriptor_heap) { return wis::detail::make_result< - wis::detail::Func(), - "Descriptor heaps are not supported by this Vulkan device">(VK_ERROR_FEATURE_NOT_PRESENT); + wis::detail::Func(), + "Descriptor heaps are not supported by this Vulkan device">(VK_ERROR_FEATURE_NOT_PRESENT); } // 1. Calculate descriptor memory requirements based on desc @@ -296,32 +296,32 @@ wisVKDeviceCreateDescriptorHeap(const WisVKDevice* self, const WisDescriptorHeap bool embedded_samplers = !(desc->flags & WisDescriptorHeapFlagsDisallowEmbeddedSamplers); std::size_t heap_alignment = is_shader_heap ? is_sampler_heap ? features.sampler_heap_alignment - : features.descriptor_heap_alignment - : __STDCPP_DEFAULT_NEW_ALIGNMENT__; + : features.descriptor_heap_alignment + : __STDCPP_DEFAULT_NEW_ALIGNMENT__; std::size_t descriptor_size = is_sampler_heap ? features.sampler_desc_size : features.resource_desc_size; std::size_t reserved_size = is_shader_heap ? is_sampler_heap ? embedded_samplers - ? features.sampler_heap_reserved_size_with_embedded - : features.sampler_heap_reserved_size - : features.descriptor_heap_reserved_size - : 0; + ? features.sampler_heap_reserved_size_with_embedded + : features.sampler_heap_reserved_size + : features.descriptor_heap_reserved_size + : 0; std::size_t max_heap_size = is_shader_heap - ? is_sampler_heap ? features.max_sampler_heap_size : features.max_descriptor_heap_size - : std::numeric_limits::max(); + ? is_sampler_heap ? features.max_sampler_heap_size : features.max_descriptor_heap_size + : std::numeric_limits::max(); std::size_t required_size = wis::aligned_size( - desc->descriptor_count * descriptor_size + reserved_size, - heap_alignment - ); + desc->descriptor_count * descriptor_size + reserved_size, + heap_alignment + ); if (is_shader_heap && required_size > max_heap_size) { return wis::detail::make_result< - wis::detail::Func(), - "Requested descriptor heap size exceeds the maximum supported by this Vulkan device">( - VK_ERROR_INITIALIZATION_FAILED - ); + wis::detail::Func(), + "Requested descriptor heap size exceeds the maximum supported by this Vulkan device">( + VK_ERROR_INITIALIZATION_FAILED + ); } if (!is_shader_heap) { @@ -329,8 +329,8 @@ wisVKDeviceCreateDescriptorHeap(const WisVKDevice* self, const WisDescriptorHeap VkBuffer buffer = reinterpret_cast(std::malloc(required_size)); if (!buffer) { return wis::detail::make_result< - wis::detail::Func(), - "Failed to allocate memory for non-shader visible descriptor heap">(VK_ERROR_OUT_OF_HOST_MEMORY); + wis::detail::Func(), + "Failed to allocate memory for non-shader visible descriptor heap">(VK_ERROR_OUT_OF_HOST_MEMORY); } // Fill descriptor heap impl @@ -360,7 +360,7 @@ wisVKDeviceCreateDescriptorHeap(const WisVKDevice* self, const WisDescriptorHeap }; VmaAllocationCreateInfo alloc_info{ .flags = VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT - | VMA_ALLOCATION_CREATE_MAPPED_BIT, + | VMA_ALLOCATION_CREATE_MAPPED_BIT, .usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE, .requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, .preferredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, @@ -370,18 +370,18 @@ wisVKDeviceCreateDescriptorHeap(const WisVKDevice* self, const WisDescriptorHeap VmaAllocation allocation = VK_NULL_HANDLE; VmaAllocationInfo alloc_info_out{}; VkResult vr = vmaCreateBufferWithAlignment( - header.allocator, - &buffer_info, - &alloc_info, - heap_alignment, - &buffer, - &allocation, - &alloc_info_out - ); + header.allocator, + &buffer_info, + &alloc_info, + heap_alignment, + &buffer, + &allocation, + &alloc_info_out + ); if (!wis::detail::succeeded(vr)) { return wis::detail:: - make_result(vr); + make_result(vr); } // Get GPU address of the buffer @@ -417,11 +417,11 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateViewHeap( { (void)flags; auto& device = *wis::from_handle(self); - wis::detail::VKRenderTargetView* view_heap = new (std::nothrow) wis::detail::VKRenderTargetView[capacity] {}; + wis::detail::VKRenderTargetView* view_heap = new (std::nothrow) wis::detail::VKRenderTargetView[capacity]{}; if (!view_heap) { return wis::detail::make_result( - VK_ERROR_OUT_OF_HOST_MEMORY - ); + VK_ERROR_OUT_OF_HOST_MEMORY + ); } new (heap) wis::impl::VKViewHeapImpl{ @@ -443,8 +443,8 @@ wisVKDeviceCreateRootSignature(const WisVKDevice* self, const WisRootSignatureDe if (!features.descriptor_heap) { return wis::detail::make_result< - wis::detail::Func(), - "Descriptor heaps are not supported by this Vulkan device">(VK_ERROR_FEATURE_NOT_PRESENT); + wis::detail::Func(), + "Descriptor heaps are not supported by this Vulkan device">(VK_ERROR_FEATURE_NOT_PRESENT); } // Use only 64 DWORDs, same as DX12 @@ -454,8 +454,8 @@ wisVKDeviceCreateRootSignature(const WisVKDevice* self, const WisRootSignatureDe const auto& push_constant = desc->push_constants[i]; if (push_constant.size_bytes % 4 != 0) { return wis::detail::make_result( - VK_ERROR_INITIALIZATION_FAILED - ); + VK_ERROR_INITIALIZATION_FAILED + ); } push_constant_size += push_constant.size_bytes; } @@ -463,35 +463,35 @@ wisVKDeviceCreateRootSignature(const WisVKDevice* self, const WisRootSignatureDe // 1. Count the number of root parameters needed std::size_t total_dwords_needed = push_constant_size + desc->push_descriptor_count * 2 - + desc->descriptor_table_count; + + desc->descriptor_table_count; if (total_dwords_needed > max_root_parameters) { return wis::detail::make_result< - wis::detail::Func(), - "Root signature requires more than 64 DWORDs, which is not supported by this implementation">( - VK_ERROR_INITIALIZATION_FAILED - ); + wis::detail::Func(), + "Root signature requires more than 64 DWORDs, which is not supported by this implementation">( + VK_ERROR_INITIALIZATION_FAILED + ); } // 2. Count the number of VkDescriptorSetAndBindingMappingEXT structures // Hard part is to pack the tables into a contiguous arrays for each shader type uint32_t total_table_count = 0; std::array table_counts_per_shader = wis::detail::GetMapCountPerShaderType(*desc - ); + ); std::array - local_offsets_per_shader = wis::detail::GetMappingOffsetPerShaderType( - table_counts_per_shader, - total_table_count - ); + local_offsets_per_shader = wis::detail::GetMappingOffsetPerShaderType( + table_counts_per_shader, + total_table_count + ); std::size_t root_param_count = desc->push_constant_count + desc->push_descriptor_count - + desc->descriptor_table_count; + + desc->descriptor_table_count; std::size_t static_sampler_count = 0; // allocate root signature table std::size_t root_sig_size = sizeof(wis::detail::VKRootSignatureControlBlock) - + wis::aligned_size(root_param_count, 2u) * sizeof(uint32_t) - + // Root parameter binding indices, aligned to 8 bytes + + wis::aligned_size(root_param_count, 2u) * sizeof(uint32_t) + + // Root parameter binding indices, aligned to 8 bytes total_table_count * sizeof(VkDescriptorSetAndBindingMappingEXT); std::unique_ptr root_sig_control_block{ @@ -513,14 +513,14 @@ wisVKDeviceCreateRootSignature(const WisVKDevice* self, const WisRootSignatureDe } rootsig_header->shader_mapping_offset[i] = local_offsets_per_shader[i].offset - - (local_offsets_per_shader[i].even ? 0 : table_counts_per_shader[0] - ); // If even, "all" maps are after + - (local_offsets_per_shader[i].even ? 0 : table_counts_per_shader[0] + ); // If even, "all" maps are after // this stage, if odd, "all" maps // are before this stage rootsig_header->shader_mapping_sizes[i] = table_counts_per_shader[i] - + (local_offsets_per_shader[i].even ? 0 : table_counts_per_shader[0] - ); // If even, this stage maps + "all" + + (local_offsets_per_shader[i].even ? 0 : table_counts_per_shader[0] + ); // If even, this stage maps + "all" // maps, if odd, only this stage maps if (!all_offset) { @@ -586,16 +586,16 @@ wisVKDeviceCreateRootSignature(const WisVKDevice* self, const WisRootSignatureDe uint32_t local_count = entry.count; uint32_t local_offset = heap_byte_offset; uint32_t heap_stride = entry.type == WisDescriptorTypeSampler ? features.sampler_desc_size - : features.resource_desc_size; + : features.resource_desc_size; // Check for unbounded array if (entry.count == std::numeric_limits::max()) { if (j != src.entry_count - 1) { return wis::detail::make_result< - wis::detail::Func(), - "Unbounded array descriptor table entry must be the last entry in the table">( - VK_ERROR_INITIALIZATION_FAILED - ); + wis::detail::Func(), + "Unbounded array descriptor table entry must be the last entry in the table">( + VK_ERROR_INITIALIZATION_FAILED + ); } local_count = 1; } @@ -607,22 +607,20 @@ wisVKDeviceCreateRootSignature(const WisVKDevice* self, const WisRootSignatureDe heap_byte_offset = local_offset + local_count * heap_stride; auto& mapping = mappings[local_offsets_per_shader[visibility].offset++] = - { .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_AND_BINDING_MAPPING_EXT, - .pNext = nullptr, - .descriptorSet = entry.bind_space, - .firstBinding = entry.bind_register, - .bindingCount = local_count, - .resourceMask = wis::detail::GetResourceTypeFlags(entry.type), - .source = VK_DESCRIPTOR_MAPPING_SOURCE_HEAP_WITH_PUSH_INDEX_EXT, - .sourceData = - { .pushIndex = { - .heapOffset = local_offset, - .pushOffset = push_address_offset, - .heapIndexStride = 1, - .heapArrayStride = heap_stride, - } - } - }; + {.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_AND_BINDING_MAPPING_EXT, + .pNext = nullptr, + .descriptorSet = entry.bind_space, + .firstBinding = entry.bind_register, + .bindingCount = local_count, + .resourceMask = wis::detail::GetResourceTypeFlags(entry.type), + .source = VK_DESCRIPTOR_MAPPING_SOURCE_HEAP_WITH_PUSH_INDEX_EXT, + .sourceData = + {.pushIndex = { + .heapOffset = local_offset, + .pushOffset = push_address_offset, + .heapIndexStride = 1, + .heapArrayStride = heap_stride, + }}}; } root_param_offsets[root_param_index++] = push_address_offset; @@ -676,15 +674,14 @@ WIS_EXTERN_C WISDOM_API void wisVKDeviceQueryProperties(const WisVKDevice* self, auto& family_index = header.queue_residency[i]; bool supported = family_index != wis::detail::VKQueueFamilyProperties::invalid_family_index; WisCommandQueuePriority priority = WisCommandQueuePriority( - supported ? (header.queue_families[family_index].queue_priority) : 0 - ); + supported ? (header.queue_families[family_index].queue_priority) : 0 + ); props->supported_queues[i] = supported; props->max_queue_priority[i] = priority; } props->relaxed_queue_transition = header.features.maintenance9; - } - break; + } break; case WisQueryPropertyTypeDeviceDescriptorHeapProperties: { auto* props = static_cast(next); if (!header.features.descriptor_heap) { @@ -692,21 +689,20 @@ WIS_EXTERN_C WISDOM_API void wisVKDeviceQueryProperties(const WisVKDevice* self, } auto real_dheap_size = header.features.max_descriptor_heap_size - - header.features.descriptor_heap_reserved_size; + - header.features.descriptor_heap_reserved_size; auto real_sheap_size = header.features.max_sampler_heap_size - header.features.sampler_heap_reserved_size; auto real_sheap_size_with_embedded = header.features.max_sampler_heap_size - - header.features.sampler_heap_reserved_size_with_embedded; + - header.features.sampler_heap_reserved_size_with_embedded; props->max_descriptor_heap_size = real_dheap_size / header.features.resource_desc_size; props->max_sampler_heap_size = real_sheap_size / header.features.sampler_desc_size; props->max_sampler_heap_size_with_embedded = real_sheap_size_with_embedded - / header.features.sampler_desc_size; + / header.features.sampler_desc_size; props->descriptor_increment_size = header.features.resource_desc_size; props->sampler_increment_size = header.features.sampler_desc_size; props->render_target_increment_size = sizeof(wis::detail::VKRenderTargetView); props->depth_stencil_increment_size = sizeof(wis::detail::VKRenderTargetView); - } - break; + } break; case WisQueryPropertyTypeDeviceMemoryProperties: { auto* props = static_cast(next); props->host_image_copy_supported = header.features.host_image_copy; @@ -737,22 +733,20 @@ WIS_EXTERN_C WISDOM_API void wisVKDeviceQueryProperties(const WisVKDevice* self, const VkMemoryPropertyFlags flags = mem_props->memoryTypes[i].propertyFlags; if ((flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) && (flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) - && (flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) { + && (flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) { props->gpu_upload_supported = true; break; } } - } - break; + } break; case WisQueryPropertyTypeDeviceBindingProperties: { auto* props = static_cast(next); props->max_vertex_input_bindings = header.features.max_vertex_bindings; props->max_vertex_input_attributes = header.features.max_vertex_attributes; props->multiple_viewports_supported = header.features.multiple_viewports; props->address_commands_supported = header.features.address_commands; - } - break; + } break; default: break; } @@ -796,8 +790,8 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreatePipelineCache( { if (data_size > 0 && data_size < sizeof(VkPipelineCacheHeaderVersionOne)) { return wis::detail::make_result< - wis::detail::Func(), - "Data size is too small to contain a valid pipeline cache header">(VK_ERROR_INITIALIZATION_FAILED); + wis::detail::Func(), + "Data size is too small to contain a valid pipeline cache header">(VK_ERROR_INITIALIZATION_FAILED); } auto& device = *wis::from_handle(self); @@ -824,9 +818,9 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreatePipelineCache( if (std::memcmp(initial_data, &cache_header_correct, sizeof(VkPipelineCacheHeaderVersionOne)) != 0) { return wis::detail::make_result< - wis::detail::Func(), - "Initial data pipeline cache header does not match the device's pipeline cache header, indicating it " - "is incompatible">(VK_ERROR_INITIALIZATION_FAILED); + wis::detail::Func(), + "Initial data pipeline cache header does not match the device's pipeline cache header, indicating it " + "is incompatible">(VK_ERROR_INITIALIZATION_FAILED); } } @@ -845,7 +839,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreatePipelineCache( } auto& cache_impl = *new (cache) - wis::impl::VKPipelineCacheImpl{.cache = cache_handle, .device_header = device.device_header}; + wis::impl::VKPipelineCacheImpl{.cache = cache_handle, .device_header = device.device_header}; device.device_header->AddRef(); return wis::detail::vk_success; @@ -873,7 +867,7 @@ wisVKDeviceCreateShader(const WisVKDevice* self, const uint8_t* data, size_t siz } auto& shader_impl = *new (shader - ) wis::impl::VKShaderImpl{.shader_module = shader_handle, .device_header = device.device_header}; + ) wis::impl::VKShaderImpl{.shader_module = shader_handle, .device_header = device.device_header}; device.device_header->AddRef(); return wis::detail::vk_success; } @@ -910,14 +904,13 @@ wisVKDeviceCreateComputePipeline(const WisVKDevice* self, const WisVKComputePipe .pNext = &pipeline_flags_info, .flags = 0, .stage = - { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, - .pNext = &mapping, - .flags = 0, - .stage = VK_SHADER_STAGE_COMPUTE_BIT, - .module = shader, - .pName = "main", - .pSpecializationInfo = nullptr - }, + {.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, + .pNext = &mapping, + .flags = 0, + .stage = VK_SHADER_STAGE_COMPUTE_BIT, + .module = shader, + .pName = "main", + .pSpecializationInfo = nullptr}, .layout = nullptr }; @@ -929,7 +922,7 @@ wisVKDeviceCreateComputePipeline(const WisVKDevice* self, const WisVKComputePipe } auto& pipeline_impl = *new (pipeline - ) wis::impl::VKPipelineImpl{.pipeline = pipeline_handle, .device_header = device.device_header}; + ) wis::impl::VKPipelineImpl{.pipeline = pipeline_handle, .device_header = device.device_header}; pipeline_impl.device_header->AddRef(); return wis::detail::vk_success; } @@ -948,8 +941,8 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateGraphicsPipeline( if (!rsig) { return wis::detail::make_result( - VK_ERROR_INITIALIZATION_FAILED - ); + VK_ERROR_INITIALIZATION_FAILED + ); } //--Shader stages @@ -971,7 +964,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateGraphicsPipeline( }; VkShaderDescriptorSetAndBindingMappingInfoEXT mappings[max_shader_stages]; VkPipelineShaderStageCreateInfo - shader_stages[max_shader_stages]; // intentionally uninitialized, will be filled based on provided shaders + shader_stages[max_shader_stages]; // intentionally uninitialized, will be filled based on provided shaders for (uint32_t i = 0; i < max_shader_stages; i++) { auto smodule = shader_modules[i]; @@ -1022,12 +1015,12 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateGraphicsPipeline( uint32_t ia_count = desc->input_layout.attribute_count; if (desc->input_layout.attribute_count > wis::MinSupportedInputAttributes * 2) { dynamic_vertex_attributes = wis::make_unique( - desc->input_layout.attribute_count - ); + desc->input_layout.attribute_count + ); if (!dynamic_vertex_attributes) { return wis::detail::make_result< - wis::detail::Func(), - "Failed to allocate memory for vertex input attribute descriptions">(VK_ERROR_OUT_OF_HOST_MEMORY); + wis::detail::Func(), + "Failed to allocate memory for vertex input attribute descriptions">(VK_ERROR_OUT_OF_HOST_MEMORY); } ia_span = {dynamic_vertex_attributes.get(), ia_count}; @@ -1051,11 +1044,11 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateGraphicsPipeline( .flags = 0, .vertexBindingDescriptionCount = static_cast(desc->input_layout.binding_count), .pVertexBindingDescriptions = desc->input_layout.binding_count - ? reinterpret_cast( - desc->input_layout.bindings - ) // strict aliasing violation, but we control the data and it's guaranteed - // to be compatible - : nullptr, + ? reinterpret_cast( + desc->input_layout.bindings + ) // strict aliasing violation, but we control the data and it's guaranteed + // to be compatible + : nullptr, .vertexAttributeDescriptionCount = static_cast(desc->input_layout.attribute_count), .pVertexAttributeDescriptions = desc->input_layout.attribute_count ? ia_span.data() : nullptr, }; @@ -1147,8 +1140,8 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateGraphicsPipeline( uint32_t rt_count = desc->render_attachments.attachments_count; if (rt_count > wis::MaxRenderTargets) { return wis::detail::make_result< - wis::detail::Func(), - "Exceeded maximum number of render target attachments (8)">(VK_ERROR_UNKNOWN); + wis::detail::Func(), + "Exceeded maximum number of render target attachments (8)">(VK_ERROR_UNKNOWN); } VkFormat rt_formats[wis::MaxRenderTargets]; for (uint32_t i = 0; i < rt_count; i++) { @@ -1216,25 +1209,25 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateGraphicsPipeline( .depthBoundsTestEnable = ds.depth_bound_test, .stencilTestEnable = ds.stencil_enable, .front = - VkStencilOpState{ - .failOp = wis::detail::VKConvert(ds.stencil_front.fail_op), - .passOp = wis::detail::VKConvert(ds.stencil_front.pass_op), - .depthFailOp = wis::detail::VKConvert(ds.stencil_front.depth_fail_op), - .compareOp = wis::detail::VKConvert(ds.stencil_front.stencil_comp), - .compareMask = ds.stencil_front.read_mask, - .writeMask = ds.stencil_front.write_mask, - .reference = 0, - }, + VkStencilOpState{ + .failOp = wis::detail::VKConvert(ds.stencil_front.fail_op), + .passOp = wis::detail::VKConvert(ds.stencil_front.pass_op), + .depthFailOp = wis::detail::VKConvert(ds.stencil_front.depth_fail_op), + .compareOp = wis::detail::VKConvert(ds.stencil_front.stencil_comp), + .compareMask = ds.stencil_front.read_mask, + .writeMask = ds.stencil_front.write_mask, + .reference = 0, + }, .back = - VkStencilOpState{ - .failOp = wis::detail::VKConvert(ds.stencil_back.fail_op), - .passOp = wis::detail::VKConvert(ds.stencil_back.pass_op), - .depthFailOp = wis::detail::VKConvert(ds.stencil_back.depth_fail_op), - .compareOp = wis::detail::VKConvert(ds.stencil_back.stencil_comp), - .compareMask = ds.stencil_back.read_mask, - .writeMask = ds.stencil_back.write_mask, - .reference = 0, - }, + VkStencilOpState{ + .failOp = wis::detail::VKConvert(ds.stencil_back.fail_op), + .passOp = wis::detail::VKConvert(ds.stencil_back.pass_op), + .depthFailOp = wis::detail::VKConvert(ds.stencil_back.depth_fail_op), + .compareOp = wis::detail::VKConvert(ds.stencil_back.stencil_comp), + .compareMask = ds.stencil_back.read_mask, + .writeMask = ds.stencil_back.write_mask, + .reference = 0, + }, .minDepthBounds = 0.0f, .maxDepthBounds = 1.0f, }; @@ -1250,7 +1243,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateGraphicsPipeline( .dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO, .alphaBlendOp = VK_BLEND_OP_ADD, .colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT - | VK_COLOR_COMPONENT_A_BIT, + | VK_COLOR_COMPONENT_A_BIT, }; VkPipelineColorBlendAttachmentState color_blend_attachment[wis::MaxRenderTargets]; VkPipelineColorBlendStateCreateInfo color_blending; @@ -1373,20 +1366,20 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateGraphicsPipeline( VkPipeline pipeline_handle = VK_NULL_HANDLE; auto vr = table.vkCreateGraphicsPipelines( - device.device, - std::bit_cast(desc->cache), - 1u, - &info, - nullptr, - &pipeline_handle - ); + device.device, + std::bit_cast(desc->cache), + 1u, + &info, + nullptr, + &pipeline_handle + ); if (!wis::detail::succeeded(vr)) { return wis::detail::make_result(vr); } auto& pipeline_impl = *new (pipeline - ) wis::impl::VKPipelineImpl{.pipeline = pipeline_handle, .device_header = device.device_header}; + ) wis::impl::VKPipelineImpl{.pipeline = pipeline_handle, .device_header = device.device_header}; device.device_header->AddRef(); return wis::detail::vk_success; @@ -1423,8 +1416,8 @@ wisVKDeviceGetSurfaceParameters(const WisVKDevice* self, WisVKSurfaceView surfac *params = { .min_swapchain_images = capabilities.surfaceCapabilities.minImageCount, .max_swapchain_images = capabilities.surfaceCapabilities.maxImageCount == 0 - ? wis::AbsoluteMaxSwapchainImages - : capabilities.surfaceCapabilities.maxImageCount, + ? wis::AbsoluteMaxSwapchainImages + : capabilities.surfaceCapabilities.maxImageCount, .alpha_modes_supported = alpha, .texture_usage_flags_supported = wis::detail::VKConvert(capabilities.surfaceCapabilities.supportedUsageFlags), .stereo_supported = capabilities.surfaceCapabilities.maxImageArrayLayers > 1, @@ -1466,11 +1459,11 @@ WIS_EXTERN_C WISDOM_API bool wisVKDeviceGetFormatPresentationSupport( } vr = atable.vkGetPhysicalDeviceSurfaceFormatsKHR( - device.physical_device, - vk_surface, - &format_count, - format_span.data() - ); + device.physical_device, + vk_surface, + &format_count, + format_span.data() + ); if (!wis::detail::succeeded(vr)) { return false; } @@ -1507,15 +1500,15 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateSwapchain( uint32_t format_count = 0; auto vr = atable.vkGetPhysicalDeviceSurfaceFormatsKHR( - device.physical_device, - surface_impl.surface, - &format_count, - nullptr - ); + device.physical_device, + surface_impl.surface, + &format_count, + nullptr + ); if (!wis::detail::succeeded(vr) || format_count == 0) { return wis::detail::make_result< - wis::detail::Func(), - "Failed to get surface formats or no formats supported by the surface">(VK_ERROR_INITIALIZATION_FAILED); + wis::detail::Func(), + "Failed to get surface formats or no formats supported by the surface">(VK_ERROR_INITIALIZATION_FAILED); } if (format_count > reasonable_format_count) { @@ -1530,11 +1523,11 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateSwapchain( } vr = atable.vkGetPhysicalDeviceSurfaceFormatsKHR( - device.physical_device, - surface_impl.surface, - &format_count, - format_span.data() - ); + device.physical_device, + surface_impl.surface, + &format_count, + format_span.data() + ); if (!wis::detail::succeeded(vr)) { return wis::detail::make_result(vr); } @@ -1546,9 +1539,9 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateSwapchain( if (format_it == format_span.end()) { return wis::detail::make_result< - wis::detail::Func(), - "The requested format is not supported for presentation on the given surface">(VK_ERROR_FORMAT_NOT_SUPPORTED - ); + wis::detail::Func(), + "The requested format is not supported for presentation on the given surface">(VK_ERROR_FORMAT_NOT_SUPPORTED + ); } // Query surface props @@ -1566,19 +1559,19 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateSwapchain( // validate requested parameters against capabilities if (desc->image_count < capabilities.surfaceCapabilities.minImageCount - || (capabilities.surfaceCapabilities.maxImageCount != 0 - && desc->image_count > capabilities.surfaceCapabilities.maxImageCount)) { + || (capabilities.surfaceCapabilities.maxImageCount != 0 + && desc->image_count > capabilities.surfaceCapabilities.maxImageCount)) { return wis::detail::make_result< - wis::detail::Func(), - "Requested swapchain image count is out of bounds for the given surface">(VK_ERROR_INITIALIZATION_FAILED); + wis::detail::Func(), + "Requested swapchain image count is out of bounds for the given surface">(VK_ERROR_INITIALIZATION_FAILED); } if (desc->flags & WisSwapchainFlagsStereo) { if (capabilities.surfaceCapabilities.maxImageArrayLayers == 1) { return wis::detail::make_result< - wis::detail::Func(), - "Stereo swapchain requested but the surface does not support image array layers">( - VK_ERROR_INITIALIZATION_FAILED - ); + wis::detail::Func(), + "Stereo swapchain requested but the surface does not support image array layers">( + VK_ERROR_INITIALIZATION_FAILED + ); } array_layer_count++; } @@ -1618,14 +1611,14 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateSwapchain( // Create swapchain control block in a single allocation with the header to ensure they are close together in // memory, which is important for cache performance since the header is accessed on every frame. std::size_t header_size = sizeof(wis::detail::VKSwapchainControlBlock) + desc->image_count * sizeof(VkSemaphore) * 2 - + // semaphores for present and render complete for each image + + // semaphores for present and render complete for each image format_count - * sizeof(VkSurfaceFormatKHR); // store supported formats for use in mode switching + * sizeof(VkSurfaceFormatKHR); // store supported formats for use in mode switching std::unique_ptr header_storage{new (std::nothrow) std::byte[header_size]}; if (!header_storage) { return wis::detail::make_result( - VK_ERROR_OUT_OF_HOST_MEMORY - ); + VK_ERROR_OUT_OF_HOST_MEMORY + ); } wis::detail::VKSwapchainControlBlock* header = new (header_storage.get()) wis::detail::VKSwapchainControlBlock; @@ -1640,8 +1633,8 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateSwapchain( // Copy the supported formats for use in mode switching auto* format_storage = reinterpret_cast( - reinterpret_cast(header + 1) + desc->image_count * 2 - ); // format storage is immediately after the semaphores + reinterpret_cast(header + 1) + desc->image_count * 2 + ); // format storage is immediately after the semaphores for (uint32_t i = 0; i < format_count; i++) { format_storage[i] = format_span[i]; } @@ -1668,18 +1661,18 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateSwapchain( .imageFormat = vk_format, .imageColorSpace = format_it->colorSpace, .imageExtent = - { - .width = std::clamp( - desc->width, - capabilities.surfaceCapabilities.minImageExtent.width, - capabilities.surfaceCapabilities.maxImageExtent.width - ), - .height = std::clamp( - desc->height, - capabilities.surfaceCapabilities.minImageExtent.height, - capabilities.surfaceCapabilities.maxImageExtent.height - ), - }, + { + .width = std::clamp( + desc->width, + capabilities.surfaceCapabilities.minImageExtent.width, + capabilities.surfaceCapabilities.maxImageExtent.width + ), + .height = std::clamp( + desc->height, + capabilities.surfaceCapabilities.minImageExtent.height, + capabilities.surfaceCapabilities.maxImageExtent.height + ), + }, .imageArrayLayers = array_layer_count, .imageUsage = wis::detail::VKConvert(desc->texture_usage_flags), .imageSharingMode = VK_SHARING_MODE_EXCLUSIVE, @@ -1719,7 +1712,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateSwapchain( } stable.vkDestroySwapchainKHR(device.device, swapchain_handle, nullptr); return wis::detail:: - make_result(vr); + make_result(vr); } } @@ -1737,7 +1730,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateSwapchain( } stable.vkDestroySwapchainKHR(device.device, swapchain_handle, nullptr); return wis::detail:: - make_result(vr); + make_result(vr); } swap_head.surface_header = surface_impl.surface_header; @@ -1763,13 +1756,13 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateSwapchain( // Acquire the next image index for the new swapchain to update internal state auto result = impl.swapchain_table->vkAcquireNextImageKHR( - impl.device, - impl.swapchain, - impl.lazy_acquire ? 0 : std::numeric_limits::max(), - semaphores[impl.acquire_index], - nullptr, - &impl.present_index - ); + impl.device, + impl.swapchain, + impl.lazy_acquire ? 0 : std::numeric_limits::max(), + semaphores[impl.acquire_index], + nullptr, + &impl.present_index + ); if (result != VK_SUCCESS) { return result; // Caller can choose to handle timeout differently (e.g. by skipping rendering and trying @@ -1794,8 +1787,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateSwapchain( }; impl.acquire_index = (impl.acquire_index + 1) % swapchain_header.create_info.minImageCount; return swapchain_table.vkQueueSubmit2(impl.present_queue, 1, &desc2, nullptr); - } - (swap_impl); + }(swap_impl); if (!wis::detail::succeeded(vr)) { for (uint32_t j = 0; j < desc->image_count * 2; j++) { @@ -1810,7 +1802,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKDeviceCreateSwapchain( ); // ensure the destructor doesn't attempt to clean up a partially initialized swapchain return wis::detail:: - make_result(vr); + make_result(vr); } return wis::detail::vk_success; @@ -1840,8 +1832,8 @@ wisVKDeviceGetFormatProperties(const WisVKDevice* self, WisDataFormat format, Wi if (features & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) { support_flags |= WisFormatSupportFlagsShaderResource | WisFormatSupportFlagsTexture1D - | WisFormatSupportFlagsTexture2D | WisFormatSupportFlagsTexture3D - | WisFormatSupportFlagsTextureCube; + | WisFormatSupportFlagsTexture2D | WisFormatSupportFlagsTexture3D + | WisFormatSupportFlagsTextureCube; } if (features & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) { support_flags |= WisFormatSupportFlagsRenderTarget; @@ -1860,42 +1852,42 @@ wisVKDeviceGetFormatProperties(const WisVKDevice* self, WisDataFormat format, Wi if (features & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) { VkImageFormatProperties image_props{}; if (wis::detail::succeeded(atable.vkGetPhysicalDeviceImageFormatProperties( - device.physical_device, - vk_format, - VK_IMAGE_TYPE_2D, - VK_IMAGE_TILING_OPTIMAL, - VK_IMAGE_USAGE_SAMPLED_BIT, - 0, - &image_props - ))) { + device.physical_device, + vk_format, + VK_IMAGE_TYPE_2D, + VK_IMAGE_TILING_OPTIMAL, + VK_IMAGE_USAGE_SAMPLED_BIT, + 0, + &image_props + ))) { sample_counts |= image_props.sampleCounts; } } if (features & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) { VkImageFormatProperties image_props{}; if (wis::detail::succeeded(atable.vkGetPhysicalDeviceImageFormatProperties( - device.physical_device, - vk_format, - VK_IMAGE_TYPE_2D, - VK_IMAGE_TILING_OPTIMAL, - VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, - 0, - &image_props - ))) { + device.physical_device, + vk_format, + VK_IMAGE_TYPE_2D, + VK_IMAGE_TILING_OPTIMAL, + VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, + 0, + &image_props + ))) { sample_counts |= image_props.sampleCounts; } } if (features & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) { VkImageFormatProperties image_props{}; if (wis::detail::succeeded(atable.vkGetPhysicalDeviceImageFormatProperties( - device.physical_device, - vk_format, - VK_IMAGE_TYPE_2D, - VK_IMAGE_TILING_OPTIMAL, - VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, - 0, - &image_props - ))) { + device.physical_device, + vk_format, + VK_IMAGE_TYPE_2D, + VK_IMAGE_TILING_OPTIMAL, + VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, + 0, + &image_props + ))) { sample_counts |= image_props.sampleCounts; } } @@ -1913,7 +1905,7 @@ wisVKDeviceGetFormatProperties(const WisVKDevice* self, WisDataFormat format, Wi if (max_sample_count > WisSampleCountS1) { if (features & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT - || features & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) { + || features & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) { support_flags |= WisFormatSupportFlagsMultisampleRenderTarget; } support_flags |= WisFormatSupportFlagsMultisampleResolve; diff --git a/src/include/wisdom/vulkan/vk_extensions.hpp b/src/include/wisdom/vulkan/vk_extensions.hpp index f2a70839..563d29c2 100644 --- a/src/include/wisdom/vulkan/vk_extensions.hpp +++ b/src/include/wisdom/vulkan/vk_extensions.hpp @@ -39,31 +39,21 @@ struct CStringHash { // hash for VkExtensionProperties struct VkExtensionPropertiesHash { using is_transparent = void; - std::size_t operator()(const VkExtensionProperties& ext) const noexcept { - return CStringHash{}(ext.extensionName); - } - std::size_t operator()(const char* name) const noexcept { - return CStringHash{}(name); - } + std::size_t operator()(const VkExtensionProperties& ext) const noexcept { return CStringHash{}(ext.extensionName); } + std::size_t operator()(const char* name) const noexcept { return CStringHash{}(name); } }; //---------------------------------------------------------------------------------------------------------------------- struct VkLayerPropertiesHash { using is_transparent = void; - std::size_t operator()(const VkLayerProperties& layer) const noexcept { - return CStringHash{}(layer.layerName); - } - std::size_t operator()(const char* name) const noexcept { - return CStringHash{}(name); - } + std::size_t operator()(const VkLayerProperties& layer) const noexcept { return CStringHash{}(layer.layerName); } + std::size_t operator()(const char* name) const noexcept { return CStringHash{}(name); } }; // Equality helpers //---------------------------------------------------------------------------------------------------------------------- struct CStringEqual { - bool operator()(const char* a, const char* b) const { - return std::strncmp(a, b, VK_MAX_EXTENSION_NAME_SIZE) == 0; - } + bool operator()(const char* a, const char* b) const { return std::strncmp(a, b, VK_MAX_EXTENSION_NAME_SIZE) == 0; } }; //---------------------------------------------------------------------------------------------------------------------- @@ -102,13 +92,13 @@ struct VkLayerPropertiesEqual { using CStringSet = std::unordered_set; using VkExtensionPropertiesSet = std:: - unordered_set; + unordered_set; using VkLayerPropertiesSet = std::unordered_set; } // namespace detail //---------------------------------------------------------------------------------------------------------------------- struct WISDOM_API VKInstanceExtensionCollector { - constexpr static const char* instance_extensions[] { + constexpr static const char* instance_extensions[]{ VK_KHR_SURFACE_EXTENSION_NAME, VK_EXT_SURFACE_MAINTENANCE_1_EXTENSION_NAME, VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME, @@ -236,9 +226,7 @@ struct WISDOM_API VKDeviceExtensionCollector { template struct VKInstanceExtensionImpl : public VKInstanceExtensionHeader { VKInstanceExtensionImpl() noexcept - : VKInstanceExtensionHeader { - &VKInstanceExtensionImpl::InitThunk - } + : VKInstanceExtensionHeader{&VKInstanceExtensionImpl::InitThunk} { assert( std::uintptr_t(static_cast(this)) == std::uintptr_t(static_cast(this)) @@ -257,9 +245,9 @@ struct VKInstanceExtensionImpl : public VKInstanceExtensionHeader { return reinterpret_cast(self)->CollectInfo(*collector); } return reinterpret_cast(self)->Init( - const_cast(*instance_impl), - const_cast(*collector) - ); + const_cast(*instance_impl), + const_cast(*collector) + ); } public: @@ -279,9 +267,7 @@ struct VKInstanceExtensionImpl : public VKInstanceExtensionHeader { template struct VKDeviceExtensionImpl : public VKDeviceExtensionHeader { VKDeviceExtensionImpl() noexcept - : VKDeviceExtensionHeader { - &VKDeviceExtensionImpl::InitThunk - } + : VKDeviceExtensionHeader{&VKDeviceExtensionImpl::InitThunk} { assert( std::uintptr_t(static_cast(this)) == std::uintptr_t(static_cast(this)) @@ -300,9 +286,9 @@ struct VKDeviceExtensionImpl : public VKDeviceExtensionHeader { return reinterpret_cast(self)->CollectInfo(*collector); } return reinterpret_cast(self)->Init( - const_cast(*device_impl), - const_cast(*collector) - ); + const_cast(*device_impl), + const_cast(*collector) + ); } public: diff --git a/src/include/wisdom/vulkan/vk_impl.cpp b/src/include/wisdom/vulkan/vk_impl.cpp index 08f7292e..84bd85b6 100644 --- a/src/include/wisdom/vulkan/vk_impl.cpp +++ b/src/include/wisdom/vulkan/vk_impl.cpp @@ -103,16 +103,14 @@ wisVKTextureWriteSubresource(const WisVKTexture* self, const void* source_data, .memoryRowLength = 0, .memoryImageHeight = 0, .imageSubresource = - { .aspectMask = plane_to_aspect_mask(target_region->target_subresource.plane_slice), - .mipLevel = target_region->target_subresource.mip_level, - .baseArrayLayer = target_region->target_subresource.array_layer, - .layerCount = 1 - }, + {.aspectMask = plane_to_aspect_mask(target_region->target_subresource.plane_slice), + .mipLevel = target_region->target_subresource.mip_level, + .baseArrayLayer = target_region->target_subresource.array_layer, + .layerCount = 1}, .imageOffset = - { static_cast(target_region->box.x), - static_cast(target_region->box.y), - static_cast(target_region->box.z) - }, + {static_cast(target_region->box.x), + static_cast(target_region->box.y), + static_cast(target_region->box.z)}, .imageExtent{target_region->box.width, target_region->box.height, target_region->box.depth}, }; diff --git a/src/include/wisdom/vulkan/vk_resource_allocator.cpp b/src/include/wisdom/vulkan/vk_resource_allocator.cpp index 84efe1f1..75a2bb7b 100644 --- a/src/include/wisdom/vulkan/vk_resource_allocator.cpp +++ b/src/include/wisdom/vulkan/vk_resource_allocator.cpp @@ -16,8 +16,8 @@ inline VkImageCreateInfo VKFillImageDesc(const WisTextureDesc& desc) noexcept .flags = (usage & (VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR | VK_IMAGE_USAGE_VIDEO_DECODE_SRC_BIT_KHR | VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR)) - ? VK_IMAGE_CREATE_VIDEO_PROFILE_INDEPENDENT_BIT_KHR - : VkImageCreateFlags{0}, + ? VK_IMAGE_CREATE_VIDEO_PROFILE_INDEPENDENT_BIT_KHR + : VkImageCreateFlags{0}, .format = wis::detail::VKConvert(desc.format), .samples = VK_SAMPLE_COUNT_1_BIT, .usage = usage, @@ -115,8 +115,8 @@ wisVKResourceAllocatorCreateBuffer(const WisVKResourceAllocator* self, const Wis buffer_info.flags = (buffer_info.usage & (VK_BUFFER_USAGE_VIDEO_DECODE_DST_BIT_KHR | VK_BUFFER_USAGE_VIDEO_DECODE_SRC_BIT_KHR)) - ? VK_BUFFER_CREATE_VIDEO_PROFILE_INDEPENDENT_BIT_KHR - : 0; + ? VK_BUFFER_CREATE_VIDEO_PROFILE_INDEPENDENT_BIT_KHR + : 0; VmaAllocationCreateFlags flags = wis::detail::VKConvert(desc->memory_flags); if (desc->memory_flags & WisMemoryFlagsMapped) { @@ -142,13 +142,13 @@ wisVKResourceAllocatorCreateBuffer(const WisVKResourceAllocator* self, const Wis VkBuffer buffer_handle = VK_NULL_HANDLE; VmaAllocation allocation_handle = VK_NULL_HANDLE; VkResult vr = vmaCreateBuffer( - allocator.allocator, - &buffer_info, - &alloc_info, - &buffer_handle, - &allocation_handle, - nullptr - ); + allocator.allocator, + &buffer_info, + &alloc_info, + &buffer_handle, + &allocation_handle, + nullptr + ); if (!wis::detail::succeeded(vr)) { return wis::detail::make_result(vr); } @@ -185,8 +185,8 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKResourceAllocatorCreateTexture( // Check memory type, you can't create a texture with upload or readback memory types if (desc->memory_type == WisMemoryTypeUpload || desc->memory_type == WisMemoryTypeReadback) { return wis::detail::make_result( - VK_ERROR_UNKNOWN - ); + VK_ERROR_UNKNOWN + ); } VkImageCreateInfo image_info = wis::detail::VKFillImageDesc(*desc); @@ -230,7 +230,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKResourceAllocatorCreateTexture( VkImage image_handle = VK_NULL_HANDLE; VmaAllocation allocation_handle = VK_NULL_HANDLE; VkResult - vr = vmaCreateImage(allocator.allocator, &image_info, &alloc_info, &image_handle, &allocation_handle, nullptr); + vr = vmaCreateImage(allocator.allocator, &image_info, &alloc_info, &image_handle, &allocation_handle, nullptr); if (!wis::detail::succeeded(vr)) { return wis::detail::make_result(vr); } @@ -250,13 +250,13 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKResourceAllocatorCreateTexture( .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED, .newLayout = VK_IMAGE_LAYOUT_GENERAL, .subresourceRange = - { - .aspectMask = wis::detail::VKAspectFlags(image_info.format), - .baseMipLevel = 0, - .levelCount = image_info.mipLevels, - .baseArrayLayer = 0, - .layerCount = image_info.arrayLayers, - }, + { + .aspectMask = wis::detail::VKAspectFlags(image_info.format), + .baseMipLevel = 0, + .levelCount = image_info.mipLevels, + .baseArrayLayer = 0, + .layerCount = image_info.arrayLayers, + }, }; vr = table.vkTransitionImageLayoutEXT(header.device, 1, &transition_info); @@ -273,8 +273,8 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKResourceAllocatorCreateTexture( .width = static_cast(image_info.extent.width), .height = static_cast(image_info.extent.height), .depth_or_array_size = desc->layout == WisTextureLayoutTexture3D - ? static_cast(image_info.extent.depth) - : static_cast(image_info.arrayLayers), + ? static_cast(image_info.extent.depth) + : static_cast(image_info.arrayLayers), }; impl.device_header->AddRef(); diff --git a/src/include/wisdom/vulkan/vk_swapchain.cpp b/src/include/wisdom/vulkan/vk_swapchain.cpp index 67fc3da2..bc8d2b1b 100644 --- a/src/include/wisdom/vulkan/vk_swapchain.cpp +++ b/src/include/wisdom/vulkan/vk_swapchain.cpp @@ -17,13 +17,13 @@ inline VkResult VKAcquireNextImage(const impl::VKSwapchainImpl& impl) noexcept // Acquire the next image index for the new swapchain to update internal state auto result = impl.swapchain_table->vkAcquireNextImageKHR( - impl.device, - impl.swapchain, - impl.lazy_acquire ? 0 : std::numeric_limits::max(), - semaphores[impl.acquire_index], - nullptr, - &impl.present_index - ); + impl.device, + impl.swapchain, + impl.lazy_acquire ? 0 : std::numeric_limits::max(), + semaphores[impl.acquire_index], + nullptr, + &impl.present_index + ); if (result != VK_SUCCESS) { return result; // Caller can choose to handle timeout differently (e.g. by skipping rendering and trying again @@ -158,8 +158,8 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKSwapchainUpdate(const WisVKSwapchain* sel VkFormat new_format = wis::detail::VKConvert(desc->format); bool size_changed = desc->width != 0 && desc->height != 0 - && (desc->width != create_info.imageExtent.width || desc->height != create_info.imageExtent.height - ); + && (desc->width != create_info.imageExtent.width || desc->height != create_info.imageExtent.height + ); bool format_changed = desc->format != WisDataFormatUnknown && new_format != create_info.imageFormat; bool count_changed = desc->image_count != 0 && desc->image_count != create_info.minImageCount; bool vsync_changed = desc->vsync != (create_info.presentMode == VK_PRESENT_MODE_FIFO_KHR); @@ -187,15 +187,13 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKSwapchainUpdate(const WisVKSwapchain* sel if (format_changed) { auto formats = header.GetSupportedFormats(); if (std::ranges::find_if( - formats, - [new_format](const VkSurfaceFormatKHR& fmt) { - return fmt.format == new_format; - } + formats, + [new_format](const VkSurfaceFormatKHR& fmt) { return fmt.format == new_format; } ) - == std::end(formats)) { + == std::end(formats)) { return wis::detail::make_result( - VK_ERROR_FORMAT_NOT_SUPPORTED - ); + VK_ERROR_FORMAT_NOT_SUPPORTED + ); } } @@ -214,16 +212,16 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKSwapchainUpdate(const WisVKSwapchain* sel header.vkGetPhysicalDeviceSurfaceCapabilities2KHR(header.physical_device, &surface_info, &capabilities); capabilities.surfaceCapabilities.maxImageCount = capabilities.surfaceCapabilities.maxImageCount == 0 - ? wis::AbsoluteMaxSwapchainImages - : capabilities.surfaceCapabilities.maxImageCount; + ? wis::AbsoluteMaxSwapchainImages + : capabilities.surfaceCapabilities.maxImageCount; } if (count_changed - && (desc->image_count < capabilities.surfaceCapabilities.minImageCount - || desc->image_count > capabilities.surfaceCapabilities.maxImageCount)) { + && (desc->image_count < capabilities.surfaceCapabilities.minImageCount + || desc->image_count > capabilities.surfaceCapabilities.maxImageCount)) { return wis::detail::make_result< - wis::detail::Func(), - "Requested swapchain image count is out of bounds for the given surface">(VK_ERROR_INITIALIZATION_FAILED); + wis::detail::Func(), + "Requested swapchain image count is out of bounds for the given surface">(VK_ERROR_INITIALIZATION_FAILED); } // Store backups @@ -241,17 +239,17 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKSwapchainUpdate(const WisVKSwapchain* sel }; create_info.imageExtent.width = desc->width != 0 ? std::clamp( - desc->width, - capabilities.surfaceCapabilities.minImageExtent.width, - capabilities.surfaceCapabilities.maxImageExtent.width - ) - : create_info.imageExtent.width; + desc->width, + capabilities.surfaceCapabilities.minImageExtent.width, + capabilities.surfaceCapabilities.maxImageExtent.width + ) + : create_info.imageExtent.width; create_info.imageExtent.height = desc->height != 0 ? std::clamp( - desc->height, - capabilities.surfaceCapabilities.minImageExtent.height, - capabilities.surfaceCapabilities.maxImageExtent.height - ) - : create_info.imageExtent.height; + desc->height, + capabilities.surfaceCapabilities.minImageExtent.height, + capabilities.surfaceCapabilities.maxImageExtent.height + ) + : create_info.imageExtent.height; create_info.imageFormat = desc->format != WisDataFormatUnknown ? new_format : create_info.imageFormat; create_info.minImageCount = desc->image_count != 0 ? desc->image_count : create_info.minImageCount; @@ -274,7 +272,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKSwapchainUpdate(const WisVKSwapchain* sel // Wait for the GPU to finish with the swapchain vr = impl.swapchain_table - ->vkWaitForFences(impl.device, 1, &impl.destroy_fence, VK_TRUE, std::numeric_limits::max()); + ->vkWaitForFences(impl.device, 1, &impl.destroy_fence, VK_TRUE, std::numeric_limits::max()); if (!wis::detail::succeeded(vr)) { restore_on_failure(); return wis::detail::make_result(vr); @@ -290,7 +288,7 @@ WIS_EXTERN_C WISDOM_API WisResult wisVKSwapchainUpdate(const WisVKSwapchain* sel if (vr != VK_SUCCESS) { // no restore return wis::detail:: - make_result(vr); + make_result(vr); } return wis::detail::vk_success; @@ -310,8 +308,8 @@ wisVKSwapchainGetTextures(const WisVKSwapchain* self, WisVKTexture* buffers, siz if (buffer_count < actual_buffer_count) { return wis::detail::make_result< - wis::detail::Func(), - "Provided buffer count is less than the number of swapchain images">(VK_ERROR_UNKNOWN); + wis::detail::Func(), + "Provided buffer count is less than the number of swapchain images">(VK_ERROR_UNKNOWN); } // Cheat the allocation of the output array to avoid dynamic memory allocation in this function by treating the diff --git a/src/include/wisdom/vulkan/vk_tables.hpp b/src/include/wisdom/vulkan/vk_tables.hpp index 2b1e327e..0fed82c8 100644 --- a/src/include/wisdom/vulkan/vk_tables.hpp +++ b/src/include/wisdom/vulkan/vk_tables.hpp @@ -16,7 +16,7 @@ typedef struct VkPhysicalDeviceDeviceAddressCommandsFeaturesKHR { } VkPhysicalDeviceDeviceAddressCommandsFeaturesKHR; static constexpr VkStructureType -VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEVICE_ADDRESS_COMMANDS_FEATURES_KHR = VkStructureType(1000318006); + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEVICE_ADDRESS_COMMANDS_FEATURES_KHR = VkStructureType(1000318006); static constexpr VkStructureType VK_STRUCTURE_TYPE_BIND_VERTEX_BUFFER_3_INFO_KHR = VkStructureType(1000318008); static constexpr VkStructureType VK_STRUCTURE_TYPE_BIND_INDEX_BUFFER_3_INFO_KHR = VkStructureType(1000318007); @@ -44,11 +44,11 @@ typedef struct VkBindIndexBuffer3InfoKHR { } VkBindIndexBuffer3InfoKHR; using PFN_vkCmdBindVertexBuffers3KHR = void (*)( - VkCommandBuffer commandBuffer, - uint32_t firstBinding, - uint32_t bindingCount, - const VkBindVertexBuffer3InfoKHR* pBindingInfos - ); + VkCommandBuffer commandBuffer, + uint32_t firstBinding, + uint32_t bindingCount, + const VkBindVertexBuffer3InfoKHR* pBindingInfos +); using PFN_vkCmdBindIndexBuffer3KHR = void (*)(VkCommandBuffer commandBuffer, const VkBindIndexBuffer3InfoKHR* pInfo); #endif // VK_KHR_device_address_commands diff --git a/src/include/wisdom/wisdom.hpp b/src/include/wisdom/wisdom.hpp index cd4ae1e0..9f6d7f66 100644 --- a/src/include/wisdom/wisdom.hpp +++ b/src/include/wisdom/wisdom.hpp @@ -91,11 +91,11 @@ WIS_NODISCARD inline wis::Instance CreateInstance( { wis::DX12Instance instance{}; const WisResult wis_result = ::wisDX12CreateInstance( - reinterpret_cast(debug_desc), - reinterpret_cast(extensions.data()), - extensions.size(), - instance.GetStorage() - ); + reinterpret_cast(debug_desc), + reinterpret_cast(extensions.data()), + extensions.size(), + instance.GetStorage() + ); out_result = wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; return instance; } @@ -177,11 +177,11 @@ WIS_NODISCARD inline wis::Instance CreateInstance( { wis::VKInstance instance{}; const WisResult wis_result = ::wisVKCreateInstance( - reinterpret_cast(debug_desc), - reinterpret_cast(extensions.data()), - extensions.size(), - instance.GetStorage() - ); + reinterpret_cast(debug_desc), + reinterpret_cast(extensions.data()), + extensions.size(), + instance.GetStorage() + ); out_result = wis::Result{static_cast(wis_result.status), wis_result.platform_code, wis_result.error}; return instance; } diff --git a/src/platform/wisdom_platform/generated/cpp_api.hpp b/src/platform/wisdom_platform/generated/cpp_api.hpp index 75f8ce00..74cc9072 100644 --- a/src/platform/wisdom_platform/generated/cpp_api.hpp +++ b/src/platform/wisdom_platform/generated/cpp_api.hpp @@ -70,9 +70,7 @@ struct UWPWindowDesc { namespace wis { struct DX12Win32ExtensionDeleter { - void operator()(WisDX12Win32Extension* handle) noexcept { - ::wisDX12DestroyWin32Extension(handle); - } + void operator()(WisDX12Win32Extension* handle) noexcept { ::wisDX12DestroyWin32Extension(handle); } }; /** * @brief Provided by Wisdom 0.7.0. Extension for Win32 surface creation functions. @@ -80,7 +78,7 @@ struct DX12Win32ExtensionDeleter { * */ class DX12Win32Extension : public wis::impl:: - Implements + Implements { public: DX12Win32Extension() noexcept @@ -89,9 +87,7 @@ class DX12Win32Extension ::wisDX12InitWin32Extension(GetStorage()); } // Operator & overload - wis::DX12InstanceExtensionHeader* operator&() noexcept { - return &GetMutableInternal().header; - } + wis::DX12InstanceExtensionHeader* operator&() noexcept { return &GetMutableInternal().header; } public: /** @@ -108,10 +104,10 @@ class DX12Win32Extension { wis::DX12Surface surface{}; const WisResult wis_result = ::wisDX12Win32ExtensionCreateSurface( - &_impl_storage, - reinterpret_cast(&info), - surface.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&info), + surface.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -125,15 +121,11 @@ class DX12Win32Extension * @return bool true if the extension is supported, false otherwise. * * */ - WIS_NODISCARD inline bool Supported() noexcept { - return (::wisDX12Win32ExtensionSupported(&_impl_storage)); - } + WIS_NODISCARD inline bool Supported() noexcept { return (::wisDX12Win32ExtensionSupported(&_impl_storage)); } }; struct DX12UWPExtensionDeleter { - void operator()(WisDX12UWPExtension* handle) noexcept { - ::wisDX12DestroyUWPExtension(handle); - } + void operator()(WisDX12UWPExtension* handle) noexcept { ::wisDX12DestroyUWPExtension(handle); } }; /** * @brief Provided by Wisdom 0.7.0. Extension for UWP surface creation functions. @@ -149,9 +141,7 @@ class DX12UWPExtension ::wisDX12InitUWPExtension(GetStorage()); } // Operator & overload - wis::DX12InstanceExtensionHeader* operator&() noexcept { - return &GetMutableInternal().header; - } + wis::DX12InstanceExtensionHeader* operator&() noexcept { return &GetMutableInternal().header; } public: /** @@ -168,10 +158,10 @@ class DX12UWPExtension { wis::DX12Surface surface{}; const WisResult wis_result = ::wisDX12UWPExtensionCreateSurface( - &_impl_storage, - reinterpret_cast(&info), - surface.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&info), + surface.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -189,9 +179,7 @@ class DX12UWPExtension namespace wis { struct VKXlibExtensionDeleter { - void operator()(WisVKXlibExtension* handle) noexcept { - ::wisVKDestroyXlibExtension(handle); - } + void operator()(WisVKXlibExtension* handle) noexcept { ::wisVKDestroyXlibExtension(handle); } }; /** * @brief Provided by Wisdom 0.7.0. Extension for Xlib surface creation functions. @@ -207,9 +195,7 @@ class VKXlibExtension ::wisVKInitXlibExtension(GetStorage()); } // Operator & overload - wis::VKInstanceExtensionHeader* operator&() noexcept { - return &GetMutableInternal().header; - } + wis::VKInstanceExtensionHeader* operator&() noexcept { return &GetMutableInternal().header; } public: /** @@ -223,10 +209,10 @@ class VKXlibExtension { wis::VKSurface surface{}; const WisResult wis_result = ::wisVKXlibExtensionCreateSurface( - &_impl_storage, - reinterpret_cast(&info), - surface.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&info), + surface.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -239,15 +225,11 @@ class VKXlibExtension * @return bool true if the extension is supported, false otherwise. * * */ - WIS_NODISCARD inline bool Supported() noexcept { - return (::wisVKXlibExtensionSupported(&_impl_storage)); - } + WIS_NODISCARD inline bool Supported() noexcept { return (::wisVKXlibExtensionSupported(&_impl_storage)); } }; struct VKXCBExtensionDeleter { - void operator()(WisVKXCBExtension* handle) noexcept { - ::wisVKDestroyXCBExtension(handle); - } + void operator()(WisVKXCBExtension* handle) noexcept { ::wisVKDestroyXCBExtension(handle); } }; /** * @brief Provided by Wisdom 0.7.0. Extension for Xlib surface creation functions. @@ -263,9 +245,7 @@ class VKXCBExtension ::wisVKInitXCBExtension(GetStorage()); } // Operator & overload - wis::VKInstanceExtensionHeader* operator&() noexcept { - return &GetMutableInternal().header; - } + wis::VKInstanceExtensionHeader* operator&() noexcept { return &GetMutableInternal().header; } public: /** @@ -279,10 +259,10 @@ class VKXCBExtension { wis::VKSurface surface{}; const WisResult wis_result = ::wisVKXCBExtensionCreateSurface( - &_impl_storage, - reinterpret_cast(&info), - surface.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&info), + surface.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -295,15 +275,11 @@ class VKXCBExtension * @return bool true if the extension is supported, false otherwise. * * */ - WIS_NODISCARD inline bool Supported() noexcept { - return (::wisVKXCBExtensionSupported(&_impl_storage)); - } + WIS_NODISCARD inline bool Supported() noexcept { return (::wisVKXCBExtensionSupported(&_impl_storage)); } }; struct VKWaylandExtensionDeleter { - void operator()(WisVKWaylandExtension* handle) noexcept { - ::wisVKDestroyWaylandExtension(handle); - } + void operator()(WisVKWaylandExtension* handle) noexcept { ::wisVKDestroyWaylandExtension(handle); } }; /** * @brief Provided by Wisdom 0.7.0. Extension for Xlib surface creation functions. @@ -311,7 +287,7 @@ struct VKWaylandExtensionDeleter { * */ class VKWaylandExtension : public wis::impl:: - Implements + Implements { public: VKWaylandExtension() noexcept @@ -320,9 +296,7 @@ class VKWaylandExtension ::wisVKInitWaylandExtension(GetStorage()); } // Operator & overload - wis::VKInstanceExtensionHeader* operator&() noexcept { - return &GetMutableInternal().header; - } + wis::VKInstanceExtensionHeader* operator&() noexcept { return &GetMutableInternal().header; } public: /** @@ -339,10 +313,10 @@ class VKWaylandExtension { wis::VKSurface surface{}; const WisResult wis_result = ::wisVKWaylandExtensionCreateSurface( - &_impl_storage, - reinterpret_cast(&info), - surface.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&info), + surface.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -355,15 +329,11 @@ class VKWaylandExtension * @return bool true if the extension is supported, false otherwise. * * */ - WIS_NODISCARD inline bool Supported() noexcept { - return (::wisVKWaylandExtensionSupported(&_impl_storage)); - } + WIS_NODISCARD inline bool Supported() noexcept { return (::wisVKWaylandExtensionSupported(&_impl_storage)); } }; struct VKWin32ExtensionDeleter { - void operator()(WisVKWin32Extension* handle) noexcept { - ::wisVKDestroyWin32Extension(handle); - } + void operator()(WisVKWin32Extension* handle) noexcept { ::wisVKDestroyWin32Extension(handle); } }; /** * @brief Provided by Wisdom 0.7.0. Extension for Win32 surface creation functions. @@ -379,9 +349,7 @@ class VKWin32Extension ::wisVKInitWin32Extension(GetStorage()); } // Operator & overload - wis::VKInstanceExtensionHeader* operator&() noexcept { - return &GetMutableInternal().header; - } + wis::VKInstanceExtensionHeader* operator&() noexcept { return &GetMutableInternal().header; } public: /** @@ -398,10 +366,10 @@ class VKWin32Extension { wis::VKSurface surface{}; const WisResult wis_result = ::wisVKWin32ExtensionCreateSurface( - &_impl_storage, - reinterpret_cast(&info), - surface.GetStorage() - ); + &_impl_storage, + reinterpret_cast(&info), + surface.GetStorage() + ); out_result = wis::Result{ static_cast(wis_result.status), wis_result.platform_code, @@ -415,9 +383,7 @@ class VKWin32Extension * @return bool true if the extension is supported, false otherwise. * * */ - WIS_NODISCARD inline bool Supported() noexcept { - return (::wisVKWin32ExtensionSupported(&_impl_storage)); - } + WIS_NODISCARD inline bool Supported() noexcept { return (::wisVKWin32ExtensionSupported(&_impl_storage)); } }; } // namespace wis diff --git a/src/platform/wisdom_platform/vulkan/vk_platform_wayland.cpp b/src/platform/wisdom_platform/vulkan/vk_platform_wayland.cpp index 7d38c9a3..7c88e638 100644 --- a/src/platform/wisdom_platform/vulkan/vk_platform_wayland.cpp +++ b/src/platform/wisdom_platform/vulkan/vk_platform_wayland.cpp @@ -79,8 +79,8 @@ wisVKWaylandExtensionCreateSurface(WisVKWaylandExtension* self, const WisWayland auto& itable = impl.instance_control_block->header.instance_table; itable.vkDestroySurfaceKHR(impl.instance_control_block->header.instance, vk_surface, nullptr); return wis::detail::make_result( - VK_ERROR_OUT_OF_HOST_MEMORY - ); + VK_ERROR_OUT_OF_HOST_MEMORY + ); } header->header.instance_header = impl.instance_control_block, header->header.surface = vk_surface, diff --git a/src/platform/wisdom_platform/vulkan/vk_platform_win32.cpp b/src/platform/wisdom_platform/vulkan/vk_platform_win32.cpp index fd157fe6..d56332ed 100644 --- a/src/platform/wisdom_platform/vulkan/vk_platform_win32.cpp +++ b/src/platform/wisdom_platform/vulkan/vk_platform_win32.cpp @@ -106,8 +106,8 @@ wisVKWin32ExtensionCreateSurface(WisVKWin32Extension* self, const WisWin32Window auto& itable = impl.instance_control_block->header.instance_table; itable.vkDestroySurfaceKHR(impl.instance_control_block->header.instance, vk_surface, nullptr); return wis::detail::make_result( - VK_ERROR_OUT_OF_HOST_MEMORY - ); + VK_ERROR_OUT_OF_HOST_MEMORY + ); } header->header.instance_header = impl.instance_control_block, header->header.surface = vk_surface, diff --git a/src/platform/wisdom_platform/vulkan/vk_platform_xcb.cpp b/src/platform/wisdom_platform/vulkan/vk_platform_xcb.cpp index 2e4343fc..18e5a05a 100644 --- a/src/platform/wisdom_platform/vulkan/vk_platform_xcb.cpp +++ b/src/platform/wisdom_platform/vulkan/vk_platform_xcb.cpp @@ -83,8 +83,8 @@ wisVKXCBExtensionCreateSurface(WisVKXCBExtension* self, const WisXCBWindowDesc* auto& itable = impl.instance_control_block->header.instance_table; itable.vkDestroySurfaceKHR(impl.instance_control_block->header.instance, vk_surface, nullptr); return wis::detail::make_result( - VK_ERROR_OUT_OF_HOST_MEMORY - ); + VK_ERROR_OUT_OF_HOST_MEMORY + ); } header->header.instance_header = impl.instance_control_block, header->header.surface = vk_surface, diff --git a/src/platform/wisdom_platform/vulkan/vk_platform_xlib.cpp b/src/platform/wisdom_platform/vulkan/vk_platform_xlib.cpp index 48d6f676..9b8ebc73 100644 --- a/src/platform/wisdom_platform/vulkan/vk_platform_xlib.cpp +++ b/src/platform/wisdom_platform/vulkan/vk_platform_xlib.cpp @@ -84,8 +84,8 @@ wisVKXlibExtensionCreateSurface(WisVKXlibExtension* self, const WisXlibWindowDes auto& itable = impl.instance_control_block->header.instance_table; itable.vkDestroySurfaceKHR(impl.instance_control_block->header.instance, vk_surface, nullptr); return wis::detail::make_result( - VK_ERROR_OUT_OF_HOST_MEMORY - ); + VK_ERROR_OUT_OF_HOST_MEMORY + ); } header->header.instance_header = impl.instance_control_block, header->header.surface = vk_surface, diff --git a/tests/basic/platform_check.cpp b/tests/basic/platform_check.cpp index 19cd829e..8e0905dc 100644 --- a/tests/basic/platform_check.cpp +++ b/tests/basic/platform_check.cpp @@ -21,11 +21,11 @@ TEST_CASE("check_platform_support") &win32_extension.header, }; WisResult result = wisCreateInstance( - NULL, - extensions, - sizeof(extensions) / sizeof(WisInstanceExtensionHeader*), - &instance - ); + NULL, + extensions, + sizeof(extensions) / sizeof(WisInstanceExtensionHeader*), + &instance + ); // Expect partial success REQUIRE(result.status >= 0); From 4438ddcca0683d7094bffd093a1235a8959a3049 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 13 Sep 2026 17:09:55 +0000 Subject: [PATCH 4/6] Restyled by isort --- conanfile.py | 8 ++------ test_package/conanfile.py | 4 +--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/conanfile.py b/conanfile.py index 14cc92f5..e80b78cf 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,12 +1,8 @@ import os from conan import ConanFile -from conan.tools.cmake import CMake -from conan.tools.cmake import cmake_layout -from conan.tools.cmake import CMakeDeps -from conan.tools.cmake import CMakeToolchain -from conan.tools.files import copy -from conan.tools.files import load +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout +from conan.tools.files import copy, load class WisdomConan(ConanFile): diff --git a/test_package/conanfile.py b/test_package/conanfile.py index 0669a92e..5570726f 100644 --- a/test_package/conanfile.py +++ b/test_package/conanfile.py @@ -2,9 +2,7 @@ from conan import ConanFile from conan.tools.build import can_run -from conan.tools.cmake import CMake -from conan.tools.cmake import cmake_layout -from conan.tools.cmake import CMakeToolchain +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout class WisdomTestConan(ConanFile): From 0cfdddf1a5c71783dd5f78f916e5152c1982d5e3 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 13 Sep 2026 17:10:05 +0000 Subject: [PATCH 5/6] Restyled by reorder-python-imports --- conanfile.py | 8 ++++++-- test_package/conanfile.py | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/conanfile.py b/conanfile.py index e80b78cf..14cc92f5 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,8 +1,12 @@ import os from conan import ConanFile -from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout -from conan.tools.files import copy, load +from conan.tools.cmake import CMake +from conan.tools.cmake import cmake_layout +from conan.tools.cmake import CMakeDeps +from conan.tools.cmake import CMakeToolchain +from conan.tools.files import copy +from conan.tools.files import load class WisdomConan(ConanFile): diff --git a/test_package/conanfile.py b/test_package/conanfile.py index 5570726f..0669a92e 100644 --- a/test_package/conanfile.py +++ b/test_package/conanfile.py @@ -2,7 +2,9 @@ from conan import ConanFile from conan.tools.build import can_run -from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +from conan.tools.cmake import CMake +from conan.tools.cmake import cmake_layout +from conan.tools.cmake import CMakeToolchain class WisdomTestConan(ConanFile): From 3f1e28e369fa636093ee1376ad6e3bcfcd06150e Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 13 Sep 2026 17:10:13 +0000 Subject: [PATCH 6/6] Restyled by yapf --- conanfile.py | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/conanfile.py b/conanfile.py index 14cc92f5..a16d8e92 100644 --- a/conanfile.py +++ b/conanfile.py @@ -47,9 +47,8 @@ def requirements(self): """ """ # If windows platform support is enabled, we need to require the D3D12 Memory Allocator if self.settings.os == "Windows": - self.requires( - "d3d12-memory-allocator/[>=3.0.1 <4]", transitive_headers=True - ) + self.requires("d3d12-memory-allocator/[>=3.0.1 <4]", + transitive_headers=True) self.requires("vulkan-memory-allocator/3.3.0", transitive_headers=True) def export_sources(self): @@ -102,7 +101,8 @@ def generate(self): tc.variables["WISDOM_BUILD_EXAMPLES"] = False tc.variables["WISDOM_BUILD_TESTS"] = False tc.variables["WISDOM_BUILD_DOCS"] = False - tc.variables["WISDOM_BUILD_STATIC"] = not self.options.get_safe("shared") + tc.variables["WISDOM_BUILD_STATIC"] = not self.options.get_safe( + "shared") tc.variables["WISDOM_BUILD_SHARED"] = self.options.get_safe("shared") tc.variables["WISDOM_BUILD_PLATFORM"] = self.options.build_platform tc.variables["WISDOM_USE_AGILITY_SDK"] = False @@ -139,15 +139,13 @@ def package_info(self): if self.options.get_safe("shared"): # Core Shared self.cpp_info.components["core"].set_property( - "cmake_target_name", "wis::wisdom-shared" - ) + "cmake_target_name", "wis::wisdom-shared") self.cpp_info.components["core"].libs = [f"wisdom-shared{suffix}"] # Platform Shared if self.options.build_platform: self.cpp_info.components["platform"].set_property( - "cmake_target_name", "wis::wisdom-platform-shared" - ) + "cmake_target_name", "wis::wisdom-platform-shared") self.cpp_info.components["platform"].requires = ["core"] self.cpp_info.components["platform"].libs = [ f"wisdom-platform-shared{suffix}" @@ -155,29 +153,29 @@ def package_info(self): else: # Core Static self.cpp_info.components["core"].set_property( - "cmake_target_name", "wis::wisdom" - ) - self.cpp_info.components["core"].libs = [f"wisdom{suffix}", f"vkma{suffix}"] + "cmake_target_name", "wis::wisdom") + self.cpp_info.components["core"].libs = [ + f"wisdom{suffix}", f"vkma{suffix}" + ] # Platform Static if self.options.build_platform: self.cpp_info.components["platform"].set_property( - "cmake_target_name", "wis::wisdom-platform" - ) + "cmake_target_name", "wis::wisdom-platform") self.cpp_info.components["platform"].requires = ["core"] - self.cpp_info.components["platform"].libs = [f"wisdom-platform{suffix}"] + self.cpp_info.components["platform"].libs = [ + f"wisdom-platform{suffix}" + ] self.cpp_info.components["core"].requires = [ "vulkan-memory-allocator::vulkan-memory-allocator" ] if self.settings.os == "Windows": - self.cpp_info.components["core"].defines.extend( - [ - "D3D12MA_USING_DIRECTX_HEADERS=1", - "VK_USE_PLATFORM_WIN32_KHR=1", - ] - ) + self.cpp_info.components["core"].defines.extend([ + "D3D12MA_USING_DIRECTX_HEADERS=1", + "VK_USE_PLATFORM_WIN32_KHR=1", + ]) self.cpp_info.components["core"].requires.extend( - ["d3d12-memory-allocator::d3d12-memory-allocator"] - ) - self.cpp_info.components["core"].system_libs.extend(["dxgi", "DXGUID"]) + ["d3d12-memory-allocator::d3d12-memory-allocator"]) + self.cpp_info.components["core"].system_libs.extend( + ["dxgi", "DXGUID"])