From a9e0506310b86fd8134647cd798572ed63f5fae9 Mon Sep 17 00:00:00 2001 From: Ricardo Pieper Date: Sun, 8 Feb 2026 12:20:04 -0300 Subject: [PATCH 1/9] Apple M-series support, work in progress. --- CMakeLists.txt | 9 +++++++-- src/codegen/gen_common.hh | 9 ++++++++- src/codegen/gen_types.hh | 7 +++++++ src/core/console/ConsoleTracy.cc | 1 + src/core/ecs/StructFieldTypes.hh | 1 + src/core/ecs/StructMetadata.hh | 1 + .../graphics/vulkan/core/DeviceContext.cc | 18 +++++++++--------- 7 files changed, 34 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 67b071ee9..155730795 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,7 +84,7 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") elseif(CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") - set(CMAKE_CXX_FLAGS "-Wall -Werror -Wformat-security -Wno-deprecated-volatile -fPIC") + set(CMAKE_CXX_FLAGS "-Wall -Wformat-security -Wno-deprecated-volatile -fPIC") set(CMAKE_CXX_FLAGS_RELEASE "-O3") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g3 -ggdb3 -Og") set(CMAKE_CXX_FLAGS_DEBUG "-g3 -ggdb3 -O0") @@ -97,7 +97,12 @@ endif() set(PROJECT_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(PROJECT_OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/bin) -set(CMAKE_INSTALL_RPATH $ORIGIN) +if(APPLE) + set(CMAKE_INSTALL_RPATH "@executable_path;/usr/local/lib") +elseif(UNIX) + set(CMAKE_INSTALL_RPATH "$ORIGIN") +endif() + set(CMAKE_BUILD_WITH_INSTALL_RPATH ON) # Put RUNTIME and LIBRARY outputs into a folder where we can run them without installing diff --git a/src/codegen/gen_common.hh b/src/codegen/gen_common.hh index 863576d5a..4b25e7744 100644 --- a/src/codegen/gen_common.hh +++ b/src/codegen/gen_common.hh @@ -58,6 +58,7 @@ std::string TypeToString() { auto typeStart = charStart; auto embeddingSignature = EmbedTypeIntoSignature(); + Logf("Embedding Signature on is_lock: %s", embeddingSignature); auto structStart = embeddingSignature.find("struct ", charStart); if (structStart == charStart) typeStart += "struct "s.size(); @@ -72,6 +73,8 @@ std::string TypeToString() { auto typeStart = charStart; auto embeddingSignature = EmbedTypeIntoSignature(); + Logf("Embedding Signature on is_dynamic_lock: %s", embeddingSignature); + auto structStart = embeddingSignature.find("struct ", charStart); if (structStart == charStart) typeStart += "struct "s.size(); @@ -84,6 +87,8 @@ std::string TypeToString() { auto typeStart = charStart; auto embeddingSignature = EmbedTypeIntoSignature(); + Logf("Embedding Signature on else: %s", embeddingSignature); + auto enumStart = embeddingSignature.find("enum ", charStart); if (enumStart == charStart) typeStart += "enum "s.size(); auto classStart = embeddingSignature.find("class ", charStart); @@ -92,7 +97,9 @@ std::string TypeToString() { if (structStart == charStart) typeStart += "struct "s.size(); auto typeLength = embeddingSignature.size() - typeStart - tailLength; - return std::string(embeddingSignature.substr(typeStart, typeLength)); + auto result = std::string(embeddingSignature.substr(typeStart, typeLength)); + Logf("Result from TypeToString: %s", result); + return result; } } diff --git a/src/codegen/gen_types.hh b/src/codegen/gen_types.hh index bb24d231c..9117e64c9 100644 --- a/src/codegen/gen_types.hh +++ b/src/codegen/gen_types.hh @@ -87,6 +87,8 @@ std::string LookupCTypeName(std::type_index type) { return "uint32_t"s; } else if constexpr (std::is_same()) { return "uint64_t"s; + } else if constexpr (std::is_same()) { + return "size_t"s; } else if constexpr (std::is_same()) { return "float"s; } else if constexpr (std::is_same()) { @@ -166,6 +168,7 @@ std::string LookupCTypeName(std::type_index type) { return "sp_compositor_ctx_t"s; } else { std::string scn = SnakeCaseTypeName(TypeToString()); + Logf("gen_types SnakeCaseTypeName got %s", scn); if (ecs::LookupComponent(type)) { if (!sp::starts_with(scn, "ecs_")) { scn = "ecs_" + scn; @@ -586,6 +589,8 @@ void GenerateCTypeDefinition(S &out, std::type_index type) { // Built-in } else if constexpr (std::is_same()) { // Built-in + } else if constexpr (std::is_same()) { + // Built-in } else if constexpr (std::is_same()) { // Built-in } else if constexpr (std::is_same()) { @@ -816,6 +821,8 @@ void GenerateCppTypeDefinition(S &out, std::type_index type) { // Built-in } else if constexpr (std::is_same()) { // Built-in + } else if constexpr (std::is_same()) { + // Built-in } else if constexpr (std::is_same()) { // Built-in } else if constexpr (std::is_same()) { diff --git a/src/core/console/ConsoleTracy.cc b/src/core/console/ConsoleTracy.cc index e271ebfb6..0934ed42c 100644 --- a/src/core/console/ConsoleTracy.cc +++ b/src/core/console/ConsoleTracy.cc @@ -7,6 +7,7 @@ #include "console/Console.hh" +#include #ifdef _WIN32 #include #endif diff --git a/src/core/ecs/StructFieldTypes.hh b/src/core/ecs/StructFieldTypes.hh index d5172859c..961be9ef9 100644 --- a/src/core/ecs/StructFieldTypes.hh +++ b/src/core/ecs/StructFieldTypes.hh @@ -42,6 +42,7 @@ namespace ecs { EventString, EventBytes, size_t, + uint64_t, VisibilityMask, sp::color_alpha_t, double, diff --git a/src/core/ecs/StructMetadata.hh b/src/core/ecs/StructMetadata.hh index 369becd0e..45762347f 100644 --- a/src/core/ecs/StructMetadata.hh +++ b/src/core/ecs/StructMetadata.hh @@ -69,6 +69,7 @@ namespace ecs { template static inline TypeInfo Lookup() { + // Logf("Lookup: %s", typeid(T).name()); using StrippedT = std::remove_pointer_t>; return TypeInfo{ .typeIndex = GetFieldTypeIndex(typeid(std::conditional_t, T, StrippedT>)), diff --git a/src/graphics/graphics/vulkan/core/DeviceContext.cc b/src/graphics/graphics/vulkan/core/DeviceContext.cc index 43e252f41..fd2c566f2 100644 --- a/src/graphics/graphics/vulkan/core/DeviceContext.cc +++ b/src/graphics/graphics/vulkan/core/DeviceContext.cc @@ -238,8 +238,8 @@ namespace sp::vulkan { } // currently we have code that assumes the transfer queue family is different from the other queues - Assert(queueFamilyIndex[QUEUE_TYPE_TRANSFER] != queueFamilyIndex[QUEUE_TYPE_GRAPHICS], - "transfer queue family overlaps graphics queue"); + // Assert(queueFamilyIndex[QUEUE_TYPE_TRANSFER] != queueFamilyIndex[QUEUE_TYPE_GRAPHICS], + // "transfer queue family overlaps graphics queue"); std::vector queueInfos; for (uint32 i = 0; i < queueFamilies.size(); i++) { @@ -254,7 +254,7 @@ namespace sp::vulkan { vector enabledDeviceExtensions = { VK_KHR_MULTIVIEW_EXTENSION_NAME, - VK_EXT_MEMORY_BUDGET_EXTENSION_NAME, + // VK_EXT_MEMORY_BUDGET_EXTENSION_NAME, VK_KHR_SHADER_NON_SEMANTIC_INFO_EXTENSION_NAME, VK_EXT_CALIBRATED_TIMESTAMPS_EXTENSION_NAME, VK_EXT_SHADER_VIEWPORT_INDEX_LAYER_EXTENSION_NAME, @@ -286,14 +286,14 @@ namespace sp::vulkan { physicalDevice.getFeatures2KHR(&deviceFeatures2); const auto &availableDeviceFeatures = deviceFeatures2.features; - Assert(availableDeviceFeatures.fillModeNonSolid, "device must support fillModeNonSolid"); + // Assert(availableDeviceFeatures.fillModeNonSolid, "device must support fillModeNonSolid"); Assert(availableDeviceFeatures.samplerAnisotropy, "device must support samplerAnisotropy"); Assert(availableDeviceFeatures.multiDrawIndirect, "device must support multiDrawIndirect"); Assert(availableDeviceFeatures.multiViewport, "device must support multiViewport"); Assert(availableDeviceFeatures.drawIndirectFirstInstance, "device must support drawIndirectFirstInstance"); Assert(availableDeviceFeatures.shaderInt16, "device must support shaderInt16"); Assert(availableDeviceFeatures.fragmentStoresAndAtomics, "device must support fragmentStoresAndAtomics"); - Assert(availableDeviceFeatures.wideLines, "device must support wideLines"); + // Assert(availableDeviceFeatures.wideLines, "device must support wideLines"); Assert(availableVulkan11Features.multiview, "device must support multiview"); Assert(availableVulkan11Features.shaderDrawParameters, "device must support shaderDrawParameters"); Assert(availableVulkan11Features.storageBuffer16BitAccess, "device must support storageBuffer16BitAccess"); @@ -302,7 +302,7 @@ namespace sp::vulkan { Assert(availableVulkan12Features.shaderOutputViewportIndex, "device must support shaderOutputViewportIndex"); Assert(availableVulkan12Features.shaderOutputLayer, "device must support shaderOutputLayer"); - Assert(availableVulkan12Features.drawIndirectCount, "device must support drawIndirectCount"); + // Assert(availableVulkan12Features.drawIndirectCount, "device must support drawIndirectCount"); Assert(availableVulkan12Features.runtimeDescriptorArray, "device must support runtimeDescriptorArray"); Assert(availableVulkan12Features.descriptorBindingPartiallyBound, "device must support descriptorBindingPartiallyBound"); @@ -316,7 +316,7 @@ namespace sp::vulkan { vk::PhysicalDeviceVulkan12Features enabledVulkan12Features; enabledVulkan12Features.shaderOutputViewportIndex = true; enabledVulkan12Features.shaderOutputLayer = true; - enabledVulkan12Features.drawIndirectCount = true; + enabledVulkan12Features.drawIndirectCount = false; enabledVulkan12Features.runtimeDescriptorArray = true; enabledVulkan12Features.descriptorBindingPartiallyBound = true; enabledVulkan12Features.descriptorBindingVariableDescriptorCount = true; @@ -334,14 +334,14 @@ namespace sp::vulkan { enabledDeviceFeatures2.pNext = &enabledVulkan11Features; auto &enabledDeviceFeatures = enabledDeviceFeatures2.features; enabledDeviceFeatures.dualSrcBlend = true; - enabledDeviceFeatures.fillModeNonSolid = true; + enabledDeviceFeatures.fillModeNonSolid = false; enabledDeviceFeatures.samplerAnisotropy = true; enabledDeviceFeatures.multiDrawIndirect = true; enabledDeviceFeatures.drawIndirectFirstInstance = true; enabledDeviceFeatures.multiViewport = true; enabledDeviceFeatures.shaderInt16 = true; enabledDeviceFeatures.fragmentStoresAndAtomics = true; - enabledDeviceFeatures.wideLines = true; + enabledDeviceFeatures.wideLines = false; vk::DeviceCreateInfo deviceInfo; deviceInfo.queueCreateInfoCount = queueInfos.size(); From d15e22057c3e87998865a6b01541d14fe8baadb5 Mon Sep 17 00:00:00 2001 From: Ricardo Pieper Date: Sun, 8 Feb 2026 12:31:32 -0300 Subject: [PATCH 2/9] Mac M-series support + Merge fix --- docs/generated/Default_Scripts.md | 8 +- docs/generated/Rendering_Components.md | 2 +- docs_generator/markdown_gen.hh | 4 +- ext/Tecs | 2 +- ext/tinygltf | 2 +- src/codegen/gen_common.hh | 7 +- src/codegen/gen_types.hh | 24 +++-- src/common/common/Common.cc | 10 +- src/common/common/Common.hh | 29 +++--- src/common/common/Hashing.hh | 6 +- src/common/common/RegisteredThread.cc | 5 +- src/common/common/RegisteredThread.hh | 2 + src/common/gui/ImGuiHelpers.hh | 2 +- src/core/assets/AssetManager.cc | 8 +- src/core/assets/AssetManager.hh | 2 +- src/core/console/ConsoleCoreCommands.cc | 8 +- src/core/console/ConsoleTracy.cc | 2 + src/core/ecs/DynamicLibrary.hh | 2 +- src/core/ecs/EventQueue.cc | 6 +- src/core/ecs/EventQueue.hh | 8 +- src/core/ecs/SignalExpression.cc | 66 ++++++------- src/core/ecs/SignalExpression.hh | 6 +- src/core/ecs/SignalExpressionNode.hh | 6 +- src/core/ecs/SignalRef.cc | 6 +- src/core/ecs/SignalRef.hh | 6 +- src/core/ecs/StructFieldTypes.hh | 4 +- src/core/ecs/StructMetadata.hh | 20 ++-- src/core/ecs/components/Events.cc | 16 ++-- src/core/ecs/components/Events.hh | 12 +-- src/core/ecs/components/PhysicsQuery.hh | 4 +- src/core/ecs/components/Renderable.cc | 2 +- src/core/ecs/components/Renderable.hh | 6 +- src/core/ecs/components/Signals.cc | 2 +- src/core/ecs/components/Signals.hh | 2 +- src/core/graphics/GenericCompositor.hh | 2 +- src/game/editor/EditorControls.cc | 6 +- src/game/editor/EntityPickerGui.cc | 7 ++ src/game/game/GameLogic.cc | 2 +- src/graphics/CMakeLists.txt | 2 +- src/graphics/graphics/core/GraphicsContext.hh | 1 + src/graphics/graphics/core/GraphicsManager.cc | 14 ++- src/graphics/graphics/core/GraphicsManager.hh | 3 +- src/graphics/graphics/core/Histogram.hh | 14 +-- src/graphics/graphics/vulkan/Compositor.cc | 16 ++-- src/graphics/graphics/vulkan/ProfilerGui.hh | 12 +-- src/graphics/graphics/vulkan/Renderer.cc | 4 +- src/graphics/graphics/vulkan/Renderer.hh | 2 +- .../graphics/vulkan/core/CommandContext.cc | 59 ++++++------ .../graphics/vulkan/core/CommandContext.hh | 94 +++++++++---------- .../graphics/vulkan/core/DeviceContext.cc | 27 +++--- .../graphics/vulkan/core/DeviceContext.hh | 15 +-- src/graphics/graphics/vulkan/core/Image.cc | 16 ++-- src/graphics/graphics/vulkan/core/Image.hh | 42 ++++----- src/graphics/graphics/vulkan/core/Memory.hh | 4 +- .../graphics/vulkan/core/PerfTimer.cc | 10 +- .../graphics/vulkan/core/PerfTimer.hh | 16 ++-- src/graphics/graphics/vulkan/core/Pipeline.cc | 46 ++++----- src/graphics/graphics/vulkan/core/Pipeline.hh | 30 +++--- .../graphics/vulkan/core/RenderPass.cc | 12 +-- .../graphics/vulkan/core/RenderPass.hh | 48 +++++----- src/graphics/graphics/vulkan/core/Shader.cc | 2 +- src/graphics/graphics/vulkan/core/Shader.hh | 28 +++--- src/graphics/graphics/vulkan/core/UniqueID.hh | 2 +- .../graphics/vulkan/core/VertexLayout.hh | 12 ++- src/graphics/graphics/vulkan/core/VkCommon.hh | 2 +- .../graphics/vulkan/render_graph/Pass.hh | 10 +- .../vulkan/render_graph/PassBuilder.cc | 14 +-- .../vulkan/render_graph/PassBuilder.hh | 14 +-- .../vulkan/render_graph/PooledImage.cc | 4 +- .../vulkan/render_graph/PooledImage.hh | 8 +- .../vulkan/render_graph/RenderGraph.cc | 8 +- .../vulkan/render_graph/RenderGraph.hh | 2 +- .../graphics/vulkan/render_graph/Resources.cc | 20 ++-- .../graphics/vulkan/render_graph/Resources.hh | 32 +++---- .../graphics/vulkan/render_passes/Blur.cc | 2 +- .../graphics/vulkan/render_passes/Blur.hh | 2 +- .../graphics/vulkan/render_passes/Lighting.cc | 15 +-- .../graphics/vulkan/render_passes/Mipmap.cc | 8 +- .../vulkan/render_passes/Screenshots.cc | 6 +- .../vulkan/render_passes/VisualizeBuffer.cc | 12 ++- .../vulkan/render_passes/VisualizeBuffer.hh | 2 +- .../graphics/vulkan/render_passes/Voxels.cc | 10 +- .../graphics/vulkan/render_passes/Voxels.hh | 6 +- .../graphics/vulkan/scene/GPUScene.cc | 28 +++--- .../graphics/vulkan/scene/GPUScene.hh | 32 +++---- src/graphics/graphics/vulkan/scene/Mesh.cc | 8 +- src/graphics/graphics/vulkan/scene/Mesh.hh | 10 +- .../graphics/vulkan/scene/TextureSet.cc | 8 +- .../graphics/vulkan/scene/TextureSet.hh | 2 +- src/physics/cooking/ConvexHull.cc | 4 +- src/physics/physx/PhysicsQuerySystem.cc | 2 +- src/physics/physx/PhysxManager.cc | 4 +- src/scripts/guis/SignalDisplayGui.cc | 2 +- src/scripts/scripts/MiscScripts.cc | 8 +- src/xr/openvr/OpenVrSystem.cc | 4 +- src/xr/openvr/OpenVrSystem.hh | 2 +- 96 files changed, 593 insertions(+), 543 deletions(-) diff --git a/docs/generated/Default_Scripts.md b/docs/generated/Default_Scripts.md index 116f91d57..be3e84f9f 100644 --- a/docs/generated/Default_Scripts.md +++ b/docs/generated/Default_Scripts.md @@ -68,8 +68,8 @@ The `component_from_signal` script has parameter type: map<string, [SignalExp | Parameter Name | Type | Default Value | Description | |------------|------|---------------|-------------| -| **delay_frames** | size_t | 1 | No description | -| **delay_ms** | size_t | 0 | No description | +| **delay_frames** | uint64 | 1 | No description | +| **delay_ms** | uint64 | 0 | No description | | **input** | [SignalExpression](#SignalExpression-type) | "" | No description | | **output** | string | "" | No description | @@ -260,8 +260,8 @@ The `physics_component_from_signal` script has parameter type: map<string, [S | Parameter Name | Type | Default Value | Description | |------------|------|---------------|-------------| -| **delay_frames** | size_t | 1 | No description | -| **delay_ms** | size_t | 0 | No description | +| **delay_frames** | uint64 | 1 | No description | +| **delay_ms** | uint64 | 0 | No description | | **input** | [SignalExpression](#SignalExpression-type) | "" | No description | | **output** | string | "" | No description | diff --git a/docs/generated/Rendering_Components.md b/docs/generated/Rendering_Components.md index 5688de2b9..7b84548c0 100644 --- a/docs/generated/Rendering_Components.md +++ b/docs/generated/Rendering_Components.md @@ -12,7 +12,7 @@ It is usually preferred to load the model using the [gltf Prefab Script](#gltf-p | Field Name | Type | Default Value | Description | |------------|------|---------------|-------------| | **model** | string | "" | Name of the GLTF model to display. Models are loaded from the `assets/models/` folder. | -| **mesh_index** | size_t | 0 | The index of the mesh to render from the GLTF model. Note, multi-mesh GLTF models can be automatically expanded into entities using the `gltf` prefab. | +| **mesh_index** | uint64 | 0 | The index of the mesh to render from the GLTF model. Note, multi-mesh GLTF models can be automatically expanded into entities using the `gltf` prefab. | | **visibility** | enum flags [VisibilityMask](#VisibilityMask-type) | "DirectCamera\|DirectEye\|LightingShadow\|LightingVoxel" | Visibility mask for different render passes. | | **emissive** | float | 0 | Emissive multiplier to turn this model into a light source | | **color_override** | vec4 (red, green, blue, alpha) | [-1, -1, -1, -1] | Override the mesh's texture to a flat RGBA color. Values are in the range 0.0 to 1.0. -1 means the original color is used. | diff --git a/docs_generator/markdown_gen.hh b/docs_generator/markdown_gen.hh index 0d63bfa28..ec7a0ca63 100644 --- a/docs_generator/markdown_gen.hh +++ b/docs_generator/markdown_gen.hh @@ -38,8 +38,8 @@ private: return "int32"; } else if constexpr (std::is_same()) { return "uint32"; - } else if constexpr (std::is_same()) { - return "size_t"; + } else if constexpr (std::is_same()) { + return "uint64"; } else if constexpr (std::is_same()) { return "float (degrees)"; } else if constexpr (std::is_same()) { diff --git a/ext/Tecs b/ext/Tecs index 9025a16bf..0d51d3128 160000 --- a/ext/Tecs +++ b/ext/Tecs @@ -1 +1 @@ -Subproject commit 9025a16bfb03ea0a89ca6ddac6b10ad746f9b1a4 +Subproject commit 0d51d3128da0b19a6c29d5fc3223bcf0e67a5673 diff --git a/ext/tinygltf b/ext/tinygltf index 8b428b6ae..11ad5692a 160000 --- a/ext/tinygltf +++ b/ext/tinygltf @@ -1 +1 @@ -Subproject commit 8b428b6aed25a088d26e95bdc05da6317b67b83b +Subproject commit 11ad5692ad3d3c5d0d382e09615481c334c3735b diff --git a/src/codegen/gen_common.hh b/src/codegen/gen_common.hh index 4b25e7744..42071d189 100644 --- a/src/codegen/gen_common.hh +++ b/src/codegen/gen_common.hh @@ -58,7 +58,6 @@ std::string TypeToString() { auto typeStart = charStart; auto embeddingSignature = EmbedTypeIntoSignature(); - Logf("Embedding Signature on is_lock: %s", embeddingSignature); auto structStart = embeddingSignature.find("struct ", charStart); if (structStart == charStart) typeStart += "struct "s.size(); @@ -73,7 +72,6 @@ std::string TypeToString() { auto typeStart = charStart; auto embeddingSignature = EmbedTypeIntoSignature(); - Logf("Embedding Signature on is_dynamic_lock: %s", embeddingSignature); auto structStart = embeddingSignature.find("struct ", charStart); if (structStart == charStart) typeStart += "struct "s.size(); @@ -87,7 +85,6 @@ std::string TypeToString() { auto typeStart = charStart; auto embeddingSignature = EmbedTypeIntoSignature(); - Logf("Embedding Signature on else: %s", embeddingSignature); auto enumStart = embeddingSignature.find("enum ", charStart); if (enumStart == charStart) typeStart += "enum "s.size(); @@ -97,9 +94,7 @@ std::string TypeToString() { if (structStart == charStart) typeStart += "struct "s.size(); auto typeLength = embeddingSignature.size() - typeStart - tailLength; - auto result = std::string(embeddingSignature.substr(typeStart, typeLength)); - Logf("Result from TypeToString: %s", result); - return result; + return std::string(embeddingSignature.substr(typeStart, typeLength)); } } diff --git a/src/codegen/gen_types.hh b/src/codegen/gen_types.hh index 9117e64c9..8f202d466 100644 --- a/src/codegen/gen_types.hh +++ b/src/codegen/gen_types.hh @@ -87,8 +87,6 @@ std::string LookupCTypeName(std::type_index type) { return "uint32_t"s; } else if constexpr (std::is_same()) { return "uint64_t"s; - } else if constexpr (std::is_same()) { - return "size_t"s; } else if constexpr (std::is_same()) { return "float"s; } else if constexpr (std::is_same()) { @@ -150,6 +148,9 @@ std::string LookupCTypeName(std::type_index type) { } else if constexpr (sp::is_vector()) { std::string subtype = StripTypeDecorators(LookupCTypeName(typeid(typename T::value_type))); return "sp_" + subtype + "_vector_t"; + } else if constexpr (sp::is_array()) { + std::string subtype = StripTypeDecorators(LookupCTypeName(typeid(typename T::value_type))); + return "sp_" + subtype + "_array_" + std::to_string(std::tuple_size()) + "_t"; } else if constexpr (sp::is_pair()) { std::string subtype = StripTypeDecorators(LookupCTypeName(typeid(typename T::first_type))); if constexpr (!std::is_same()) { @@ -168,7 +169,6 @@ std::string LookupCTypeName(std::type_index type) { return "sp_compositor_ctx_t"s; } else { std::string scn = SnakeCaseTypeName(TypeToString()); - Logf("gen_types SnakeCaseTypeName got %s", scn); if (ecs::LookupComponent(type)) { if (!sp::starts_with(scn, "ecs_")) { scn = "ecs_" + scn; @@ -589,8 +589,6 @@ void GenerateCTypeDefinition(S &out, std::type_index type) { // Built-in } else if constexpr (std::is_same()) { // Built-in - } else if constexpr (std::is_same()) { - // Built-in } else if constexpr (std::is_same()) { // Built-in } else if constexpr (std::is_same()) { @@ -672,6 +670,13 @@ void GenerateCTypeDefinition(S &out, std::type_index type) { out << "SP_EXPORT " << fullSubtype << " *sp_" << subtype << "_vector_resize(sp_" << subtype << "_vector_t *v, size_t new_size);" << std::endl; out << std::endl; + } else if constexpr (sp::is_array()) { + GenerateCTypeDefinition(out, typeid(typename T::value_type)); + std::string fullSubtype = LookupCTypeName(typeid(typename T::value_type)); + std::string subtype = StripTypeDecorators(fullSubtype); + out << "typedef " << fullSubtype << " sp_" << subtype + << "_array_" + std::to_string(std::tuple_size()) + "_t[" << std::to_string(std::tuple_size()) + << "];" << std::endl; } else if constexpr (sp::is_pair()) { GenerateCTypeDefinition(out, typeid(typename T::first_type)); GenerateCTypeDefinition(out, typeid(typename T::second_type)); @@ -821,8 +826,6 @@ void GenerateCppTypeDefinition(S &out, std::type_index type) { // Built-in } else if constexpr (std::is_same()) { // Built-in - } else if constexpr (std::is_same()) { - // Built-in } else if constexpr (std::is_same()) { // Built-in } else if constexpr (std::is_same()) { @@ -905,6 +908,13 @@ void GenerateCppTypeDefinition(S &out, std::type_index type) { out << "SP_EXPORT " << fullCSubtype << " *sp_" << subCType << "_vector_resize(sp_" << subCType << "_vector_t *v, size_t new_size);" << std::endl; out << std::endl; + } else if constexpr (sp::is_array()) { + GenerateCppTypeDefinition(out, typeid(typename T::value_type)); + std::string fullCSubtype = LookupCTypeName(typeid(typename T::value_type)); + std::string subCType = StripTypeDecorators(fullCSubtype); + std::string subCppType = TypeToString(); + out << "typedef std::array<" << subCppType << ", " << std::to_string(std::tuple_size()) << "> sp_" + << subCType << "_array_" + std::to_string(std::tuple_size()) + "_t;" << std::endl; } else if constexpr (sp::is_pair()) { GenerateCppTypeDefinition(out, typeid(typename T::first_type)); GenerateCppTypeDefinition(out, typeid(typename T::second_type)); diff --git a/src/common/common/Common.cc b/src/common/common/Common.cc index 286c4064f..dff1c0666 100644 --- a/src/common/common/Common.cc +++ b/src/common/common/Common.cc @@ -27,7 +27,7 @@ namespace sp { throw std::runtime_error("sp::Abort() called"); } - uint32 CeilToPowerOfTwo(uint32 v) { + uint32_t CeilToPowerOfTwo(uint32_t v) { v--; v |= v >> 1; v |= v >> 2; @@ -38,15 +38,15 @@ namespace sp { return v; } - uint32 Uint32Log2(uint32 v) { - uint32 r = 0; + uint32_t Uint32Log2(uint32_t v) { + uint32_t r = 0; while (v >>= 1) r++; return r; } - uint64 Uint64Log2(uint64 v) { - uint64 r = 0; + uint64_t Uint64Log2(uint64_t v) { + uint64_t r = 0; while (v >>= 1) r++; return r; diff --git a/src/common/common/Common.hh b/src/common/common/Common.hh index 6b898bd6c..bdb0456e8 100644 --- a/src/common/common/Common.hh +++ b/src/common/common/Common.hh @@ -7,6 +7,7 @@ #pragma once +#include #include using std::make_shared; using std::make_unique; @@ -34,25 +35,16 @@ typedef std::chrono::steady_clock chrono_clock; #include #include -typedef unsigned char uint8; -typedef signed char int8; -typedef uint16_t uint16; -typedef int16_t int16; -typedef uint32_t uint32; -typedef int32_t int32; -typedef uint64_t uint64; -typedef int64_t int64; - namespace sp { [[noreturn]] void Abort(); - uint32 CeilToPowerOfTwo(uint32 v); - uint32 Uint32Log2(uint32 v); - uint64 Uint64Log2(uint64 v); + uint32_t CeilToPowerOfTwo(uint32_t v); + uint32_t Uint32Log2(uint32_t v); + uint64_t Uint64Log2(uint64_t v); template - void ForEachBit(uint32 value, const T &func) { - uint32 bit = 1, index = 0; + void ForEachBit(uint32_t value, const T &func) { + uint32_t bit = 1, index = 0; while (value) { if (value & bit) func(index); value &= ~bit; @@ -75,8 +67,8 @@ namespace sp { NonMoveable &operator=(NonMoveable &&) = delete; }; - typedef std::array Hash128; - typedef uint64 Hash64; + typedef std::array Hash128; + typedef uint64_t Hash64; class angle_t { public: @@ -202,6 +194,11 @@ namespace sp { template struct is_vector> : std::true_type {}; + template + struct is_array : std::false_type {}; + template + struct is_array> : std::true_type {}; + template struct is_pair : std::false_type {}; template diff --git a/src/common/common/Hashing.hh b/src/common/common/Hashing.hh index 65f804c2b..d2efdc19e 100644 --- a/src/common/common/Hashing.hh +++ b/src/common/common/Hashing.hh @@ -29,14 +29,14 @@ namespace sp { HashKey(const T &input) : input(input) {} T input; - uint64 words[(sizeof(input) + sizeof(uint64) - 1) / sizeof(uint64)] = {0}; + uint64_t words[(sizeof(input) + sizeof(uint64_t) - 1) / sizeof(uint64_t)] = {0}; bool operator==(const HashKey &other) const { return std::memcmp(words, other.words, sizeof(words)) == 0; } Hash64 Hash() const { - uint64 hash = 0; + uint64_t hash = 0; for (size_t i = 0; i < std::size(words); i++) { // TODO: benchmark vs murmur3 for varying sized inputs hash_combine(hash, words[i]); @@ -54,7 +54,7 @@ namespace sp { } struct Hasher { - uint64 operator()(const HashKey &key) const { + uint64_t operator()(const HashKey &key) const { return key.Hash(); } }; diff --git a/src/common/common/RegisteredThread.cc b/src/common/common/RegisteredThread.cc index dd1315ed7..bdc6ee0ce 100644 --- a/src/common/common/RegisteredThread.cc +++ b/src/common/common/RegisteredThread.cc @@ -75,11 +75,14 @@ namespace sp { tracy::SetThreadName(threadName.c_str()); Tracef("RegisteredThread Started %s", threadName); Defer exit([this] { + Tracef("Thread stopping: %s", threadName); ThreadState current = state; if (current == ThreadState::Stopped || !state.compare_exchange_strong(current, ThreadState::Stopped)) { Errorf("RegisteredThread %s state already Stopped", threadName); + } else { + ThreadShutdown(); } - Tracef("Thread stopping: %s", threadName); + Tracef("Thread stopped: %s", threadName); state.notify_all(); }); diff --git a/src/common/common/RegisteredThread.hh b/src/common/common/RegisteredThread.hh index dd8dd108c..2b132a0f8 100644 --- a/src/common/common/RegisteredThread.hh +++ b/src/common/common/RegisteredThread.hh @@ -53,6 +53,8 @@ namespace sp { return true; } + virtual void ThreadShutdown() {} + enum class ThreadState : uint32_t { Stopped = 0, Started, diff --git a/src/common/gui/ImGuiHelpers.hh b/src/common/gui/ImGuiHelpers.hh index 9af6bd9ef..90f4c37ef 100644 --- a/src/common/gui/ImGuiHelpers.hh +++ b/src/common/gui/ImGuiHelpers.hh @@ -51,7 +51,7 @@ namespace sp { cmd.ClipRect.y - drawData->DisplayPos.y, cmd.ClipRect.z - drawData->DisplayPos.x, cmd.ClipRect.w - drawData->DisplayPos.y}; - cmdIter->textureId = cmd.TextureId; + cmdIter->textureId = (uint64_t)cmd.TextureId; cmdIter->indexCount = cmd.ElemCount; cmdIter->vertexOffset = vertexOffset + cmd.VtxOffset; cmdIter++; diff --git a/src/core/assets/AssetManager.cc b/src/core/assets/AssetManager.cc index d8e865cfc..6caa76f2d 100644 --- a/src/core/assets/AssetManager.cc +++ b/src/core/assets/AssetManager.cc @@ -107,11 +107,11 @@ namespace sp { std::vector AssetManager::ListBundledAssets(std::string_view prefix, std::string_view extension, - size_t maxDepth) const { + uint32_t maxDepth) const { std::vector results; std::optional ignorePrefix; - std::function appendDirectoryFiles = - [&](auto dir, auto &base, size_t depth) { + std::function appendDirectoryFiles = + [&](auto dir, auto &base, uint32_t depth) { if (std::filesystem::is_directory(dir)) { for (auto &entry : std::filesystem::directory_iterator(dir)) { if (entry.is_regular_file() && (extension.empty() || entry.path().extension() == extension)) { @@ -133,7 +133,7 @@ namespace sp { if (!bundleIndex.empty()) { for (auto &[path, range] : bundleIndex) { if (starts_with(path, prefix)) { - size_t depth = 0; + uint32_t depth = 0; size_t sep = prefix.length(); while (depth <= maxDepth && sep != std::string::npos) { sep = path.find('/', sep + 1); diff --git a/src/core/assets/AssetManager.hh b/src/core/assets/AssetManager.hh index d853b206a..f4aa77e38 100644 --- a/src/core/assets/AssetManager.hh +++ b/src/core/assets/AssetManager.hh @@ -52,7 +52,7 @@ namespace sp { std::filesystem::path GetExternalPath(std::string_view path) const; std::vector ListBundledAssets(std::string_view prefix, std::string_view extension = "", - size_t maxDepth = 4) const; + uint32_t maxDepth = 4) const; AsyncPtr Load(std::string_view path, AssetType type = AssetType::Bundled, bool reload = false); AsyncPtr LoadGltf(std::string_view name); diff --git a/src/core/console/ConsoleCoreCommands.cc b/src/core/console/ConsoleCoreCommands.cc index c05c09178..ac6b2a249 100644 --- a/src/core/console/ConsoleCoreCommands.cc +++ b/src/core/console/ConsoleCoreCommands.cc @@ -54,9 +54,11 @@ void sp::ConsoleManager::RegisterCoreCommands() { } }); - funcs.Register("wait", "Queue command for later (wait )", [](uint64 dt, string cmd) { - GetConsoleManager().QueueParseAndExecute(cmd, chrono_clock::now() + std::chrono::milliseconds(dt)); - }); + funcs.Register("wait", + "Queue command for later (wait )", + [](uint64_t dt, string cmd) { + GetConsoleManager().QueueParseAndExecute(cmd, chrono_clock::now() + std::chrono::milliseconds(dt)); + }); funcs.Register("toggle", "Toggle a CVar between values (toggle [ ])", diff --git a/src/core/console/ConsoleTracy.cc b/src/core/console/ConsoleTracy.cc index 0934ed42c..6a6c4fe0f 100644 --- a/src/core/console/ConsoleTracy.cc +++ b/src/core/console/ConsoleTracy.cc @@ -10,6 +10,8 @@ #include #ifdef _WIN32 #include +#else + #include #endif void sp::ConsoleManager::RegisterTracyCommands() { diff --git a/src/core/ecs/DynamicLibrary.hh b/src/core/ecs/DynamicLibrary.hh index db6946d26..55f70c2eb 100644 --- a/src/core/ecs/DynamicLibrary.hh +++ b/src/core/ecs/DynamicLibrary.hh @@ -67,7 +67,7 @@ namespace ecs { std::vector events; std::vector fields; - size_t contextSize = 0; + uint64_t contextSize = 0; void (*defaultInitFunc)(void *) = nullptr; void (*defaultFreeFunc)(void *) = nullptr; void (*initFunc)(void *, ScriptState &) = nullptr; diff --git a/src/core/ecs/EventQueue.cc b/src/core/ecs/EventQueue.cc index 1080c6ff3..902ff141f 100644 --- a/src/core/ecs/EventQueue.cc +++ b/src/core/ecs/EventQueue.cc @@ -169,15 +169,15 @@ namespace ecs { } } - size_t Event::Send(const DynamicLock &lock, Entity target, const Event &event) { + uint64_t Event::Send(const DynamicLock &lock, Entity target, const Event &event) { return EventBindings::SendEvent(lock, target, event); } - size_t Event::SendNamed(const DynamicLock &lock, const NamedEntity &target, const Event &event) { + uint64_t Event::SendNamed(const DynamicLock &lock, const NamedEntity &target, const Event &event) { return EventBindings::SendEvent(lock, target, event); } - size_t Event::SendRef(const DynamicLock &lock, const EntityRef &target, const Event &event) { + uint64_t Event::SendRef(const DynamicLock &lock, const EntityRef &target, const Event &event) { return EventBindings::SendEvent(lock, target, event); } diff --git a/src/core/ecs/EventQueue.hh b/src/core/ecs/EventQueue.hh index a66798832..b16358fb0 100644 --- a/src/core/ecs/EventQueue.hh +++ b/src/core/ecs/EventQueue.hh @@ -222,9 +222,11 @@ namespace ecs { template Event(std::string_view name, const Entity &source, const T &data) : name(name), source(source), data(data) {} - static size_t Send(const DynamicLock &lock, Entity target, const Event &event); - static size_t SendNamed(const DynamicLock &lock, const NamedEntity &target, const Event &event); - static size_t SendRef(const DynamicLock &lock, const EntityRef &target, const Event &event); + static uint64_t Send(const DynamicLock &lock, Entity target, const Event &event); + static uint64_t SendNamed(const DynamicLock &lock, + const NamedEntity &target, + const Event &event); + static uint64_t SendRef(const DynamicLock &lock, const EntityRef &target, const Event &event); std::string ToString() const; }; diff --git a/src/core/ecs/SignalExpression.cc b/src/core/ecs/SignalExpression.cc index 6caecc13c..63e2b142e 100644 --- a/src/core/ecs/SignalExpression.cc +++ b/src/core/ecs/SignalExpression.cc @@ -508,12 +508,12 @@ namespace ecs { return !rootNode->uncacheable; } - bool SignalExpression::CanEvaluate(const DynamicLock &lock, size_t depth) const { + bool SignalExpression::CanEvaluate(const DynamicLock &lock, uint32_t depth) const { if (!rootNode) return true; return rootNode->CanEvaluate(lock, depth); } - double SignalExpression::Evaluate(const DynamicLock &lock, size_t depth) const { + double SignalExpression::Evaluate(const DynamicLock &lock, uint32_t depth) const { DebugZoneScoped; DebugZoneStr(expr); if (!rootNode) return 0.0; @@ -541,7 +541,7 @@ namespace ecs { } } - double Node::Evaluate(const Context &ctx, size_t depth) const { + double Node::Evaluate(const Context &ctx, uint32_t depth) const { DebugAssertf(evaluate, "Node::Evaluate null compiled function: %s", text); double result = this->evaluate(ctx, *this, depth); DebugAssertf(std::isfinite(result), "expression::Node::Evaluate() returned non-finite value: %f", result); @@ -563,7 +563,7 @@ namespace ecs { } CompiledFunc ConstantNode::Compile() const { - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { return std::get(node).value; }; } @@ -573,7 +573,7 @@ namespace ecs { Errorf("SignalExpression has undefined identifier: %s", field.name); return nullptr; } - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { DebugZoneScoped; auto &identNode = std::get(node); if (identNode.field.type != typeid(EventData)) { @@ -585,7 +585,7 @@ namespace ecs { } CompiledFunc SignalNode::Compile() const { - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { DebugZoneScoped; auto &signalNode = std::get(node); if (depth >= MAX_SIGNAL_BINDING_DEPTH) { @@ -597,7 +597,7 @@ namespace ecs { } CompiledFunc ComponentNode::Compile() const { - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { DebugZoneScoped; auto &componentNode = std::get(node); if (!componentNode.component) return 0.0; @@ -628,7 +628,7 @@ namespace ecs { } CompiledFunc FocusCondition::Compile() const { - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { auto &focusNode = std::get(node); if (!ctx.lock.Has()) return 0.0; @@ -648,47 +648,47 @@ namespace ecs { CompiledFunc OneInputOperation::Compile() const { if (prefixStr == "( ") { - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { DebugAssertf(node.childNodes.size() > 0, "OneInputOperation::Compile null input node: %s", node.text); return node.childNodes[0]->Evaluate(ctx, depth); }; } else if (prefixStr == "-") { - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { DebugAssertf(node.childNodes.size() > 0, "OneInputOperation::Compile null input node: %s", node.text); return -node.childNodes[0]->Evaluate(ctx, depth); }; } else if (prefixStr == "!") { - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { DebugAssertf(node.childNodes.size() > 0, "OneInputOperation::Compile null input node: %s", node.text); return node.childNodes[0]->Evaluate(ctx, depth) >= 0.5 ? 0.0 : 1.0; }; } else if (prefixStr == "sin( ") { - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { DebugAssertf(node.childNodes.size() > 0, "OneInputOperation::Compile null input node: %s", node.text); return std::sin(node.childNodes[0]->Evaluate(ctx, depth)); }; } else if (prefixStr == "cos( ") { - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { DebugAssertf(node.childNodes.size() > 0, "OneInputOperation::Compile null input node: %s", node.text); return std::cos(node.childNodes[0]->Evaluate(ctx, depth)); }; } else if (prefixStr == "tan( ") { - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { DebugAssertf(node.childNodes.size() > 0, "OneInputOperation::Compile null input node: %s", node.text); return std::tan(node.childNodes[0]->Evaluate(ctx, depth)); }; } else if (prefixStr == "floor( ") { - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { DebugAssertf(node.childNodes.size() > 0, "OneInputOperation::Compile null input node: %s", node.text); return std::floor(node.childNodes[0]->Evaluate(ctx, depth)); }; } else if (prefixStr == "ceil( ") { - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { DebugAssertf(node.childNodes.size() > 0, "OneInputOperation::Compile null input node: %s", node.text); return std::ceil(node.childNodes[0]->Evaluate(ctx, depth)); }; } else if (prefixStr == "abs( ") { - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { DebugAssertf(node.childNodes.size() > 0, "OneInputOperation::Compile null input node: %s", node.text); return std::abs(node.childNodes[0]->Evaluate(ctx, depth)); }; @@ -699,14 +699,14 @@ namespace ecs { CompiledFunc TwoInputOperation::Compile() const { if (prefixStr == "min( ") { - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { DebugAssertf(node.childNodes.size() > 1, "TwoInputOperation::Compile null input node: %s", node.text); double inputA = node.childNodes[0]->Evaluate(ctx, depth); double inputB = node.childNodes[1]->Evaluate(ctx, depth); return std::min(inputA, inputB); }; } else if (prefixStr == "max( ") { - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { DebugAssertf(node.childNodes.size() > 1, "TwoInputOperation::Compile null input node: %s", node.text); double inputA = node.childNodes[0]->Evaluate(ctx, depth); double inputB = node.childNodes[1]->Evaluate(ctx, depth); @@ -714,7 +714,7 @@ namespace ecs { }; } else if (prefixStr == "") { if (middleStr == " + ") { - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { DebugAssertf(node.childNodes.size() > 1, "TwoInputOperation::Compile null input node: %s", node.text); @@ -728,7 +728,7 @@ namespace ecs { return result; }; } else if (middleStr == " - ") { - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { DebugAssertf(node.childNodes.size() > 1, "TwoInputOperation::Compile null input node: %s", node.text); @@ -742,7 +742,7 @@ namespace ecs { return result; }; } else if (middleStr == " * ") { - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { DebugAssertf(node.childNodes.size() > 1, "TwoInputOperation::Compile null input node: %s", node.text); @@ -756,7 +756,7 @@ namespace ecs { return result; }; } else if (middleStr == " / ") { - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { DebugAssertf(node.childNodes.size() > 1, "TwoInputOperation::Compile null input node: %s", node.text); @@ -770,7 +770,7 @@ namespace ecs { return result; }; } else if (middleStr == " && ") { - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { DebugAssertf(node.childNodes.size() > 1, "TwoInputOperation::Compile null input node: %s", node.text); @@ -779,7 +779,7 @@ namespace ecs { return (double)(inputA >= 0.5 && inputB >= 0.5); }; } else if (middleStr == " || ") { - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { DebugAssertf(node.childNodes.size() > 1, "TwoInputOperation::Compile null input node: %s", node.text); @@ -788,7 +788,7 @@ namespace ecs { return (double)(inputA >= 0.5 || inputB >= 0.5); }; } else if (middleStr == " > ") { - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { DebugAssertf(node.childNodes.size() > 1, "TwoInputOperation::Compile null input node: %s", node.text); @@ -797,7 +797,7 @@ namespace ecs { return (double)(inputA > inputB); }; } else if (middleStr == " >= ") { - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { DebugAssertf(node.childNodes.size() > 1, "TwoInputOperation::Compile null input node: %s", node.text); @@ -806,7 +806,7 @@ namespace ecs { return (double)(inputA >= inputB); }; } else if (middleStr == " < ") { - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { DebugAssertf(node.childNodes.size() > 1, "TwoInputOperation::Compile null input node: %s", node.text); @@ -815,7 +815,7 @@ namespace ecs { return (double)(inputA < inputB); }; } else if (middleStr == " <= ") { - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { DebugAssertf(node.childNodes.size() > 1, "TwoInputOperation::Compile null input node: %s", node.text); @@ -824,7 +824,7 @@ namespace ecs { return (double)(inputA <= inputB); }; } else if (middleStr == " == ") { - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { DebugAssertf(node.childNodes.size() > 1, "TwoInputOperation::Compile null input node: %s", node.text); @@ -833,7 +833,7 @@ namespace ecs { return (double)(inputA == inputB); }; } else if (middleStr == " != ") { - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { DebugAssertf(node.childNodes.size() > 1, "TwoInputOperation::Compile null input node: %s", node.text); @@ -850,7 +850,7 @@ namespace ecs { } CompiledFunc DeciderOperation::Compile() const { - return [](const Context &ctx, const Node &node, size_t depth) { + return [](const Context &ctx, const Node &node, uint32_t depth) { DebugAssertf(node.childNodes.size() > 2, "DeciderOperation::Compile null input node: %s", node.text); double condition = node.childNodes[0]->Evaluate(ctx, depth); if (condition >= 0.5) { @@ -861,7 +861,7 @@ namespace ecs { }; } - bool Node::CanEvaluate(const DynamicLock &lock, size_t depth) const { + bool Node::CanEvaluate(const DynamicLock &lock, uint32_t depth) const { if (std::holds_alternative(*this)) { const SignalNode &signalNode = std::get(*this); if (signalNode.signal.HasValue(lock)) return true; diff --git a/src/core/ecs/SignalExpression.hh b/src/core/ecs/SignalExpression.hh index 27fb8d62c..8455f768e 100644 --- a/src/core/ecs/SignalExpression.hh +++ b/src/core/ecs/SignalExpression.hh @@ -99,7 +99,7 @@ Signal expressions support the following operations and functions: bool Compile(); template - bool CanEvaluate(const LockType &lock, size_t depth = 0) const { + bool CanEvaluate(const LockType &lock, uint32_t depth = 0) const { if constexpr (LockType::template has_permissions()) { return true; } else if constexpr (LockType::template has_permissions()) { @@ -110,8 +110,8 @@ Signal expressions support the following operations and functions: } bool IsCacheable() const; - bool CanEvaluate(const DynamicLock &lock, size_t depth) const; - double Evaluate(const DynamicLock &lock, size_t depth = 0) const; + bool CanEvaluate(const DynamicLock &lock, uint32_t depth) const; + double Evaluate(const DynamicLock &lock, uint32_t depth = 0) const; double EvaluateEvent(const DynamicLock &lock, const EventData &input) const; bool operator==(const SignalExpression &other) const { diff --git a/src/core/ecs/SignalExpressionNode.hh b/src/core/ecs/SignalExpressionNode.hh index 897e1f14b..aa26f4df0 100644 --- a/src/core/ecs/SignalExpressionNode.hh +++ b/src/core/ecs/SignalExpressionNode.hh @@ -31,7 +31,7 @@ namespace ecs { namespace expression { struct Context; - using CompiledFunc = double (*)(const Context &, const Node &, size_t); + using CompiledFunc = double (*)(const Context &, const Node &, uint32_t); struct ConstantNode { double value = 0.0f; @@ -141,8 +141,8 @@ namespace ecs { CompiledFunc Compile(); void SubscribeToChildren(const Lock> &lock, const SignalRef &subscriber) const; - double Evaluate(const Context &ctx, size_t depth) const; - bool CanEvaluate(const DynamicLock &lock, size_t depth) const; + double Evaluate(const Context &ctx, uint32_t depth) const; + bool CanEvaluate(const DynamicLock &lock, uint32_t depth) const; SignalNodePtr SetScope(const EntityScope &scope) const; size_t Hash() const; diff --git a/src/core/ecs/SignalRef.cc b/src/core/ecs/SignalRef.cc index 65223f2fd..834c32474 100644 --- a/src/core/ecs/SignalRef.cc +++ b/src/core/ecs/SignalRef.cc @@ -135,7 +135,7 @@ namespace ecs { RefreshUncacheable(lock); } - void SignalRef::MarkDirty(const Lock> &lock, size_t depth) const { + void SignalRef::MarkDirty(const Lock> &lock, uint32_t depth) const { DebugZoneScoped; DebugZoneStr(String()); Assertf(IsLive(lock), "SiganlRef::MarkDirty() called with staging lock"); @@ -196,7 +196,7 @@ namespace ecs { } void SignalRef::UpdateDirtySubscribers(const DynamicLock, ReadSignalsLock> &lock, - size_t depth) const { + uint32_t depth) const { ZoneScoped; DebugZoneStr(String()); Assertf(IsLive(lock), "SiganlRef::MarkDirty() called with staging lock"); @@ -388,7 +388,7 @@ namespace ecs { return signals[index].expr; } - double SignalRef::GetSignal(const DynamicLock &lock, size_t depth) const { + double SignalRef::GetSignal(const DynamicLock &lock, uint32_t depth) const { DebugZoneScoped; DebugZoneStr(String()); Assertf(IsLive(lock), "SiganlRef::GetSignal() called with staging lock. Use SignalBindings instead"); diff --git a/src/core/ecs/SignalRef.hh b/src/core/ecs/SignalRef.hh index 4c06cb252..a9b7c5c91 100644 --- a/src/core/ecs/SignalRef.hh +++ b/src/core/ecs/SignalRef.hh @@ -51,10 +51,10 @@ namespace ecs { static SignalRef Lookup(const char *str, const EntityScope *scope = nullptr); void AddSubscriber(const Lock> &lock, const SignalRef &ref) const; - void MarkDirty(const Lock> &lock, size_t depth = 0) const; + void MarkDirty(const Lock> &lock, uint32_t depth = 0) const; bool IsCacheable(const Lock> &lock) const; void RefreshUncacheable(const Lock> &lock) const; - void UpdateDirtySubscribers(const DynamicLock, ReadSignalsLock> &lock, size_t depth = 0) const; + void UpdateDirtySubscribers(const DynamicLock, ReadSignalsLock> &lock, uint32_t depth = 0) const; double &SetValue(const Lock> &lock, double value) const; void ClearValue(const Lock> &lock) const; @@ -69,7 +69,7 @@ namespace ecs { bool HasBinding(const Lock> &lock) const; const SignalExpression &GetBinding(const Lock> &lock) const; - double GetSignal(const DynamicLock &lock, size_t depth = 0) const; + double GetSignal(const DynamicLock &lock, uint32_t depth = 0) const; explicit operator bool() const { return !!ptr; diff --git a/src/core/ecs/StructFieldTypes.hh b/src/core/ecs/StructFieldTypes.hh index 961be9ef9..94a05158a 100644 --- a/src/core/ecs/StructFieldTypes.hh +++ b/src/core/ecs/StructFieldTypes.hh @@ -17,6 +17,7 @@ #include "ecs/SignalRef.hh" #include "gui/GuiDrawData.hh" +#include #include #include #include @@ -41,8 +42,7 @@ namespace ecs { EventName, EventString, EventBytes, - size_t, - uint64_t, + uint64_t, // size_t VisibilityMask, sp::color_alpha_t, double, diff --git a/src/core/ecs/StructMetadata.hh b/src/core/ecs/StructMetadata.hh index 45762347f..fe97b2c2e 100644 --- a/src/core/ecs/StructMetadata.hh +++ b/src/core/ecs/StructMetadata.hh @@ -213,8 +213,8 @@ namespace ecs { struct StructField { std::string name, desc; TypeInfo type; - size_t size; - size_t offset = 0; + uint64_t size; + uint64_t offset = 0; int fieldIndex = -1; FieldAction actions = ~FieldAction::None; std::optional functionPointer; @@ -223,15 +223,15 @@ namespace ecs { StructField(const std::string &name, const std::string &desc, const TypeInfo &type, - size_t size, - size_t offset, + uint64_t size, + uint64_t offset, FieldAction actions, const std::optional &functionPointer) : name(name), desc(sp::trim(desc)), type(type), size(size), offset(offset), actions(actions), functionPointer(functionPointer) {} template - static size_t OffsetOf(const F T::*M) { + static uint64_t OffsetOf(const F T::*M) { // This is technically undefined behavior, but this is how the offsetof() macro works in MSVC. return reinterpret_cast(&(reinterpret_cast(NULL)->*M)); } @@ -285,7 +285,7 @@ namespace ecs { template static const StructField New(const std::string &name, const std::string &desc, - size_t offset, + uint64_t offset, FieldAction actions = FieldAction::None, const std::optional &functionPointer = {}) { return StructField(name, @@ -384,7 +384,11 @@ namespace ecs { static constexpr bool foo = std::is_trivially_copy_constructible_v; template - StructMetadata(const std::type_index &idx, size_t size, const char *name, const char *desc, Fields &&...fields) + StructMetadata(const std::type_index &idx, + uint64_t size, + const char *name, + const char *desc, + Fields &&...fields) : type(idx), size(size), name(name), description(sp::trim(desc)) { ( [&] { @@ -423,7 +427,7 @@ namespace ecs { } const std::type_index type; - const size_t size; + const uint64_t size; const std::string name; const std::string description; std::vector fields; diff --git a/src/core/ecs/components/Events.cc b/src/core/ecs/components/Events.cc index 7f6201bc9..1f0a31928 100644 --- a/src/core/ecs/components/Events.cc +++ b/src/core/ecs/components/Events.cc @@ -169,14 +169,14 @@ namespace ecs { } } - size_t EventInput::Add(const Event &event, size_t transactionId) const { + uint64_t EventInput::Add(const Event &event, uint64_t transactionId) const { AsyncEvent asyncEvent(event.name, event.source, event.data); asyncEvent.transactionId = transactionId; return Add(asyncEvent); } - size_t EventInput::Add(const AsyncEvent &event) const { - size_t eventsSent = 0; + uint64_t EventInput::Add(const AsyncEvent &event) const { + uint64_t eventsSent = 0; auto it = events.find(event.name); if (it != events.end()) { for (auto &queuePtr : it->second) { @@ -343,19 +343,19 @@ namespace ecs { return true; } - size_t EventBindings::SendEvent(const DynamicLock &lock, + uint64_t EventBindings::SendEvent(const DynamicLock &lock, const EntityRef &target, const Event &event, - size_t depth) { + uint32_t depth) { AsyncEvent asyncEvent = AsyncEvent(event.name, event.source, event.data); asyncEvent.transactionId = lock.GetTransactionId(); return SendAsyncEvent(lock, target, asyncEvent, depth); } - size_t EventBindings::SendAsyncEvent(const DynamicLock &lock, + uint64_t EventBindings::SendAsyncEvent(const DynamicLock &lock, const EntityRef &target, const AsyncEvent &event, - size_t depth) { + uint32_t depth) { ZoneScoped; Entity ent = target.Get(lock); if (!ent.Exists(lock)) { @@ -363,7 +363,7 @@ namespace ecs { return 0; } - size_t eventsSent = 0; + uint64_t eventsSent = 0; if (ent.Has(lock)) { auto &eventInput = ent.Get(lock); eventsSent += eventInput.Add(event); diff --git a/src/core/ecs/components/Events.hh b/src/core/ecs/components/Events.hh index cbc8346a1..8bf957925 100644 --- a/src/core/ecs/components/Events.hh +++ b/src/core/ecs/components/Events.hh @@ -35,8 +35,8 @@ namespace ecs { * A transactionId can be provided to synchronize event visibility with transactions. * If no transactionId is provided, this event will be immediately visible to all transactions. */ - size_t Add(const Event &event, size_t transactionId = 0) const; - size_t Add(const AsyncEvent &event) const; + uint64_t Add(const Event &event, uint64_t transactionId = 0) const; + uint64_t Add(const AsyncEvent &event) const; static bool Poll(Lock> lock, const EventQueueRef &queue, Event &eventOut); robin_hood::unordered_map, sp::StringHash, sp::StringEqual> events; @@ -144,14 +144,14 @@ their own event queues as needed. EventBinding &Bind(std::string_view source, EntityRef target, std::string_view dest); void Unbind(std::string_view source, EntityRef target, std::string_view dest); - static size_t SendEvent(const DynamicLock &lock, + static uint64_t SendEvent(const DynamicLock &lock, const EntityRef &target, const Event &event, - size_t depth = 0); - static size_t SendAsyncEvent(const DynamicLock &lock, + uint32_t depth = 0); + static uint64_t SendAsyncEvent(const DynamicLock &lock, const EntityRef &target, const AsyncEvent &event, - size_t depth = 0); + uint32_t depth = 0); using BindingList = typename std::vector; robin_hood::unordered_map sourceToDest; diff --git a/src/core/ecs/components/PhysicsQuery.hh b/src/core/ecs/components/PhysicsQuery.hh index bf2f19db0..2e0925a27 100644 --- a/src/core/ecs/components/PhysicsQuery.hh +++ b/src/core/ecs/components/PhysicsQuery.hh @@ -35,7 +35,7 @@ namespace ecs { glm::vec3 position = {0, 0, 0}; bool relativePosition = true; - uint32 maxHits = 1; + uint32_t maxHits = 1; bool operator==(const Raycast &other) const { return filterGroup == other.filterGroup && maxDistance == other.maxDistance && @@ -48,7 +48,7 @@ namespace ecs { Entity target, subTarget; glm::vec3 position, normal; float distance; - uint32 hits; + uint32_t hits; }; std::optional result; diff --git a/src/core/ecs/components/Renderable.cc b/src/core/ecs/components/Renderable.cc index ae1f047dd..f8afb9cf2 100644 --- a/src/core/ecs/components/Renderable.cc +++ b/src/core/ecs/components/Renderable.cc @@ -34,7 +34,7 @@ namespace ecs { if (dst.joints.empty()) dst.joints = src.joints; } - Renderable::Renderable(const std::string &modelName, size_t meshIndex) + Renderable::Renderable(const std::string &modelName, uint64_t meshIndex) : modelName(modelName), meshIndex(meshIndex) { if (modelName.empty()) { visibility = VisibilityMask::None; diff --git a/src/core/ecs/components/Renderable.hh b/src/core/ecs/components/Renderable.hh index 2dd5cf64c..8d3eeaff8 100644 --- a/src/core/ecs/components/Renderable.hh +++ b/src/core/ecs/components/Renderable.hh @@ -42,13 +42,13 @@ namespace ecs { struct Renderable { Renderable() {} - Renderable(const std::string &modelName, size_t meshIndex = 0); - Renderable(const std::string &modelName, sp::AsyncPtr model, size_t meshIndex = 0) + Renderable(const std::string &modelName, uint64_t meshIndex = 0); + Renderable(const std::string &modelName, sp::AsyncPtr model, uint64_t meshIndex = 0) : modelName(modelName), model(model), meshIndex(meshIndex) {} std::string modelName; sp::AsyncPtr model; - size_t meshIndex = 0; + uint64_t meshIndex = 0; struct Joint { EntityRef entity; diff --git a/src/core/ecs/components/Signals.cc b/src/core/ecs/components/Signals.cc index caa6c85b0..cad656975 100644 --- a/src/core/ecs/components/Signals.cc +++ b/src/core/ecs/components/Signals.cc @@ -80,7 +80,7 @@ namespace ecs { subscribers.emplace_back(subscriber.GetWeakRef()); } - double Signals::Signal::Value(const DynamicLock &lock, size_t depth) const { + double Signals::Signal::Value(const DynamicLock &lock, uint32_t depth) const { if (!std::isinf(value)) { return value; } else { diff --git a/src/core/ecs/components/Signals.hh b/src/core/ecs/components/Signals.hh index 7630c8161..16e27ebda 100644 --- a/src/core/ecs/components/Signals.hh +++ b/src/core/ecs/components/Signals.hh @@ -43,7 +43,7 @@ namespace ecs { Signal(const SignalRef &ref, const SignalExpression &expr); Signal(const SignalRef &ref, const SignalRef &subscriber); - double Value(const DynamicLock &lock, size_t depth = 0) const; + double Value(const DynamicLock &lock, uint32_t depth = 0) const; }; uint32_t changeCount = 0; diff --git a/src/core/graphics/GenericCompositor.hh b/src/core/graphics/GenericCompositor.hh index a8bce5576..56e06062f 100644 --- a/src/core/graphics/GenericCompositor.hh +++ b/src/core/graphics/GenericCompositor.hh @@ -24,7 +24,7 @@ namespace sp { public: virtual ~GenericCompositor() = default; - typedef uint32 ResourceID; + typedef uint32_t ResourceID; typedef InlineString<127> ResourceName; static constexpr uint64_t FontAtlasID = (uint64_t)std::numeric_limits::max() + 1; diff --git a/src/game/editor/EditorControls.cc b/src/game/editor/EditorControls.cc index a5ace8244..c100783bf 100644 --- a/src/game/editor/EditorControls.cc +++ b/src/game/editor/EditorControls.cc @@ -10,9 +10,9 @@ namespace sp { void EditorContext::RefreshEntityTree() { ZoneScoped; - entityTree.clear(); - ecs::QueueTransaction>([this](auto &lock) { + ZoneScopedN("RefreshEntityTree"); + entityTree.clear(); for (const ecs::Entity &ent : lock.template EntitiesWith()) { auto &name = ent.Get(lock); auto &tree = ent.Get(lock); @@ -460,7 +460,7 @@ namespace sp { ImGui::EndDisabled(); } ImGui::SameLine(); - if (ImGui::BeginCombo("##componentSelector", "...")) { + if (ImGui::BeginCombo("##componentSelector", selectedComponent ? selectedComponent->name.c_str() : "...")) { for (auto *comp : missingComponents) { bool isSelected = comp == selectedComponent; if (ImGui::Selectable(comp->name.c_str(), isSelected)) { diff --git a/src/game/editor/EntityPickerGui.cc b/src/game/editor/EntityPickerGui.cc index 1a04eec20..af429a70d 100644 --- a/src/game/editor/EntityPickerGui.cc +++ b/src/game/editor/EntityPickerGui.cc @@ -96,6 +96,7 @@ namespace sp { }); } ImGui::EndChild(); + if (!context->scene) ImGui::BeginDisabled(); if (ImGui::Button("New Entity") && context->scene) { GetSceneManager().QueueAction(SceneAction::ApplySystemScene, context->scene.data->name, @@ -112,10 +113,16 @@ namespace sp { ecs::Event{EDITOR_EVENT_EDIT_TARGET, pickerEntity.GetLive(), newTarget.GetLive()}); + context->RefreshEntityTree(); }); }); }); } + if (!context->scene) { + ImGui::EndDisabled(); + ImGui::SameLine(); + ImGui::TextUnformatted("No scene selected"); + } ImGui::EndTabItem(); } if (ImGui::BeginTabItem("Entity View")) { diff --git a/src/game/game/GameLogic.cc b/src/game/game/GameLogic.cc index b3a017b83..d5cf23a24 100644 --- a/src/game/game/GameLogic.cc +++ b/src/game/game/GameLogic.cc @@ -16,7 +16,7 @@ #include "input/KeyCodes.hh" namespace sp { - static CVar CVarLogicFPS("g.LogicFPS", 144, "Target frame rate for game logic scripts (0 for unlimited)"); + static CVar CVarLogicFPS("g.LogicFPS", 144, "Target frame rate for game logic scripts (0 for unlimited)"); GameLogic::GameLogic(LockFreeEventQueue &windowInputQueue) : RegisteredThread("GameLogic", CVarLogicFPS.Get(), true), windowInputQueue(windowInputQueue) { diff --git a/src/graphics/CMakeLists.txt b/src/graphics/CMakeLists.txt index 6c9a883c8..3a5e97616 100644 --- a/src/graphics/CMakeLists.txt +++ b/src/graphics/CMakeLists.txt @@ -48,7 +48,7 @@ target_link_libraries(${PROJECT_GRAPHICS_VULKAN_CORE_LIB} target_compile_definitions(${PROJECT_GRAPHICS_CORE_LIB} PUBLIC SP_GRAPHICS_SUPPORT - "$,TRACY_ENABLE_GRAPHICS,>" + # "$,TRACY_ENABLE_GRAPHICS,>" ) target_compile_definitions(${PROJECT_GRAPHICS_VULKAN_CORE_LIB} PUBLIC diff --git a/src/graphics/graphics/core/GraphicsContext.hh b/src/graphics/graphics/core/GraphicsContext.hh index a5a3075a0..ca03302b6 100644 --- a/src/graphics/graphics/core/GraphicsContext.hh +++ b/src/graphics/graphics/core/GraphicsContext.hh @@ -44,6 +44,7 @@ namespace sp { virtual void AttachWindow(const std::shared_ptr &context) = 0; virtual void InitRenderer(Game &game) = 0; + virtual void Shutdown() {} virtual GenericCompositor &GetCompositor() = 0; diff --git a/src/graphics/graphics/core/GraphicsManager.cc b/src/graphics/graphics/core/GraphicsManager.cc index b5a3cf22e..8e91128ff 100644 --- a/src/graphics/graphics/core/GraphicsManager.cc +++ b/src/graphics/graphics/core/GraphicsManager.cc @@ -26,7 +26,7 @@ namespace sp { "player:flatview", "The entity with a View component to display"); - static CVar CVarMaxFPS("r.MaxFPS", 144, "wait between frames to target this framerate (0 to disable)"); + static CVar CVarMaxFPS("r.MaxFPS", 144, "wait between frames to target this framerate (0 to disable)"); GraphicsManager::GraphicsManager(Game &game) : RegisteredThread("RenderThread", CVarMaxFPS.Get(), true), game(game) { @@ -52,7 +52,6 @@ namespace sp { GraphicsManager::~GraphicsManager() { StopThread(); - if (context) context->WaitIdle(); } void GraphicsManager::Init() { @@ -91,6 +90,17 @@ namespace sp { return true; } + void GraphicsManager::ThreadShutdown() { + if (context) { + context->Shutdown(); + windowGuiContext.reset(); + menuGui.reset(); + profilerGui.reset(); + context->WaitIdle(); + context.reset(); + } + } + bool GraphicsManager::InputFrame() { ZoneScoped; FrameMarkNamed("Input"); diff --git a/src/graphics/graphics/core/GraphicsManager.hh b/src/graphics/graphics/core/GraphicsManager.hh index 33aefc8c0..97636a33f 100644 --- a/src/graphics/graphics/core/GraphicsManager.hh +++ b/src/graphics/graphics/core/GraphicsManager.hh @@ -68,6 +68,7 @@ namespace sp { private: bool ThreadInit() override; + void ThreadShutdown() override; bool PreFrame() override; void PostFrame(bool stepMode) override; void Frame() override; @@ -77,7 +78,7 @@ namespace sp { chrono_clock::time_point renderStart; - std::shared_ptr windowGuiContext, menuGui; + shared_ptr windowGuiContext, menuGui; shared_ptr profilerGui; bool initialized = false; diff --git a/src/graphics/graphics/core/Histogram.hh b/src/graphics/graphics/core/Histogram.hh index b9325f562..8cb2d311a 100644 --- a/src/graphics/graphics/core/Histogram.hh +++ b/src/graphics/graphics/core/Histogram.hh @@ -12,10 +12,10 @@ namespace sp { template struct Histogram { - std::array buckets; - uint64 min = 0, max = 0, count = 0; + std::array buckets; + uint64_t min = 0, max = 0, count = 0; - void Reset(uint64 newMin, uint64 newMax) { + void Reset(uint64_t newMin, uint64_t newMax) { min = newMin; max = std::max(min + 1, newMax); count = 0; @@ -23,16 +23,16 @@ namespace sp { v = 0; } - void AddSample(uint64 sample) { + void AddSample(uint64_t sample) { // linear distribution of buckets between min and max size_t index = (sample - min) * (buckets.size() - 1) / (max - min); buckets[std::min(std::max(index, size_t(0)), buckets.size() - 1)]++; count++; } - uint64 GetPercentile(uint64 percentile) { - uint64 target = percentile * count / 100; - uint64 sum = 0; + uint64_t GetPercentile(uint64_t percentile) { + uint64_t target = percentile * count / 100; + uint64_t sum = 0; for (size_t i = 0; i < buckets.size(); i++) { sum += buckets[i]; if (sum >= target) return (i * 2 + 1) * (max - min) / 2 / (buckets.size() - 1) + min; diff --git a/src/graphics/graphics/vulkan/Compositor.cc b/src/graphics/graphics/vulkan/Compositor.cc index 13a7cf017..33ea16791 100644 --- a/src/graphics/graphics/vulkan/Compositor.cc +++ b/src/graphics/graphics/vulkan/Compositor.cc @@ -74,13 +74,13 @@ namespace sp::vulkan { fontAtlas->AddFont(&cfg); } - uint8 *fontData; + uint8_t *fontData; int fontWidth, fontHeight; fontAtlas->GetTexDataAsRGBA32(&fontData, &fontWidth, &fontHeight); ImageCreateInfo fontImageInfo; fontImageInfo.imageType = vk::ImageType::e2D; - fontImageInfo.extent = vk::Extent3D{(uint32)fontWidth, (uint32)fontHeight, 1}; + fontImageInfo.extent = vk::Extent3D{(uint32_t)fontWidth, (uint32_t)fontHeight, 1}; fontImageInfo.format = vk::Format::eR8G8B8A8Unorm; fontImageInfo.usage = vk::ImageUsageFlagBits::eSampled; @@ -689,7 +689,7 @@ namespace sp::vulkan { cmd.Raw().bindIndexBuffer(*indexBuffer, 0, idxType); cmd.Raw().bindVertexBuffers(0, {*vertexBuffer}, {0}); - uint32 idxOffset = 0; + uint32_t idxOffset = 0; for (const auto &pcmd : drawData.drawCommands) { if (pcmd.textureId == FontAtlasID) { cmd.SetImageView("tex", fontView->Get()); @@ -711,8 +711,8 @@ namespace sp::vulkan { glm::ivec2(viewportExtents) - 1); clipExtents = glm::clamp(clipExtents, glm::uvec2(0), viewportExtents - glm::uvec2(clipOffset)); - cmd.SetScissor(vk::Rect2D{{(int32)clipOffset.x, (int32)clipOffset.y}, - {(uint32)clipExtents.x, (uint32)clipExtents.y}}); + cmd.SetScissor(vk::Rect2D{{(int32_t)clipOffset.x, (int32_t)clipOffset.y}, + {(uint32_t)clipExtents.x, (uint32_t)clipExtents.y}}); cmd.DrawIndexed(pcmd.indexCount, 1, idxOffset, pcmd.vertexOffset, 0); idxOffset += pcmd.indexCount; @@ -799,7 +799,7 @@ namespace sp::vulkan { cmd.Raw().bindIndexBuffer(*indexBuffer, 0, idxType); cmd.Raw().bindVertexBuffers(0, {*vertexBuffer}, {0}); - uint32 idxOffset = 0, vtxOffset = 0; + uint32_t idxOffset = 0, vtxOffset = 0; for (const auto &cmdList : drawData->CmdLists) { for (const auto &pcmd : cmdList->CmdBuffer) { if (pcmd.UserCallback) continue; @@ -823,8 +823,8 @@ namespace sp::vulkan { clipRect.w -= drawData->DisplayPos.y; // TODO: Clamp to viewport - cmd.SetScissor(vk::Rect2D{{(int32)clipRect.x, (int32)clipRect.y}, - {(uint32)(clipRect.z - clipRect.x), (uint32)(clipRect.w - clipRect.y)}}); + cmd.SetScissor(vk::Rect2D{{(int32_t)clipRect.x, (int32_t)clipRect.y}, + {(uint32_t)(clipRect.z - clipRect.x), (uint32_t)(clipRect.w - clipRect.y)}}); cmd.DrawIndexed(pcmd.ElemCount, 1, idxOffset, vtxOffset, 0); idxOffset += pcmd.ElemCount; diff --git a/src/graphics/graphics/vulkan/ProfilerGui.hh b/src/graphics/graphics/vulkan/ProfilerGui.hh index c1e7e454f..4fe155ac4 100644 --- a/src/graphics/graphics/vulkan/ProfilerGui.hh +++ b/src/graphics/graphics/vulkan/ProfilerGui.hh @@ -129,12 +129,12 @@ namespace sp::vulkan { private: struct Sample { - uint64 cpuElapsed = 0, gpuElapsed = 0; + uint64_t cpuElapsed = 0, gpuElapsed = 0; }; struct Scope { std::string name; - size_t depth = 0; + uint32_t depth = 0; size_t sampleOffset = 0, sampleCount = 0; bool truncated = false; @@ -143,7 +143,7 @@ namespace sp::vulkan { struct Stats { struct { - uint64 avg = 0, p95 = 0, max = 0, min = std::numeric_limits::max(); + uint64_t avg = 0, p95 = 0, max = 0, min = std::numeric_limits::max(); } cpu, gpu; }; @@ -154,7 +154,7 @@ namespace sp::vulkan { return spacePadding.data() + paddingOffset; } - size_t AddResults(size_t offset = 0, size_t depth = 1) { + size_t AddResults(size_t offset = 0, uint32_t depth = 1) { while (offset < resultCount) { const auto &scope = resultScopes[offset]; @@ -229,7 +229,7 @@ namespace sp::vulkan { newWindow = true; lastWindowStart = now; - uint64 dhWindow = drawHistogram.max - drawHistogram.min; + uint64_t dhWindow = drawHistogram.max - drawHistogram.min; drawHistogram.min += dhWindow * 0.05; drawHistogram.max -= dhWindow * 0.05; } @@ -302,7 +302,7 @@ namespace sp::vulkan { void UpdateDrawHistogram(const Scope &scope, const Stats &stats) { if (drawHistogramIndex != lastDrawHistogramIndex || drawHistogramMode != lastDrawHistogramMode) { drawHistogram.max = 0; - drawHistogram.min = std::numeric_limits::max(); + drawHistogram.min = std::numeric_limits::max(); lastDrawHistogramIndex = drawHistogramIndex; lastDrawHistogramMode = drawHistogramMode; } diff --git a/src/graphics/graphics/vulkan/Renderer.cc b/src/graphics/graphics/vulkan/Renderer.cc index a83148629..bda09b135 100644 --- a/src/graphics/graphics/vulkan/Renderer.cc +++ b/src/graphics/graphics/vulkan/Renderer.cc @@ -46,7 +46,7 @@ namespace sp::vulkan { static CVar CVarMirrorXR("r.MirrorXR", false, "Mirror XR in primary window"); - static CVar CVarWindowViewTargetLayer("r.WindowViewTargetLayer", 0, "Array layer to view"); + static CVar CVarWindowViewTargetLayer("r.WindowViewTargetLayer", 0, "Array layer to view"); static CVar CVarXrViewTarget("r.XrView", defaultXrViewTarget, "HMD's render target"); @@ -386,7 +386,7 @@ namespace sp::vulkan { } } - auto executeHiddenAreaStencil = [this](uint32 eyeIndex) { + auto executeHiddenAreaStencil = [this](uint32_t eyeIndex) { return [this, eyeIndex](rg::Resources &resources, CommandContext &cmd) { cmd.SetShaders("basic_ortho_stencil.vert", "noop.frag"); diff --git a/src/graphics/graphics/vulkan/Renderer.hh b/src/graphics/graphics/vulkan/Renderer.hh index 4e8012fd2..82c3c0373 100644 --- a/src/graphics/graphics/vulkan/Renderer.hh +++ b/src/graphics/graphics/vulkan/Renderer.hh @@ -97,6 +97,6 @@ namespace sp::vulkan { std::vector xrRenderPoses; std::array hiddenAreaMesh; - std::array hiddenAreaTriangleCount; + std::array hiddenAreaTriangleCount; }; } // namespace sp::vulkan diff --git a/src/graphics/graphics/vulkan/core/CommandContext.cc b/src/graphics/graphics/vulkan/core/CommandContext.cc index dd163172c..9ce45fbe0 100644 --- a/src/graphics/graphics/vulkan/core/CommandContext.cc +++ b/src/graphics/graphics/vulkan/core/CommandContext.cc @@ -64,9 +64,9 @@ namespace sp::vulkan { renderPass = device.GetRenderPass(info); vk::ClearValue clearValues[MAX_COLOR_ATTACHMENTS + 1]; - uint32 clearValueCount = info.state.colorAttachmentCount; + uint32_t clearValueCount = info.state.colorAttachmentCount; - for (uint32 i = 0; i < info.state.colorAttachmentCount; i++) { + for (uint32_t i = 0; i < info.state.colorAttachmentCount; i++) { if (info.state.ShouldClear(i)) { clearValues[i].color = info.clearColors[i]; } @@ -119,7 +119,7 @@ namespace sp::vulkan { } } - void CommandContext::Dispatch(uint32 groupCountX, uint32 groupCountY, uint32 groupCountZ) { + void CommandContext::Dispatch(uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ) { FlushComputeState(); cmd->dispatch(groupCountX, groupCountY, groupCountZ); } @@ -129,21 +129,24 @@ namespace sp::vulkan { cmd->dispatchIndirect(*indirectBuffer, offset); } - void CommandContext::Draw(uint32 vertexes, uint32 instances, int32 firstVertex, uint32 firstInstance) { + void CommandContext::Draw(uint32_t vertexes, uint32_t instances, int32_t firstVertex, uint32_t firstInstance) { FlushGraphicsState(); cmd->draw(vertexes, instances, firstVertex, firstInstance); } - void CommandContext::DrawIndexed(uint32 indexes, - uint32 instances, - uint32 firstIndex, - int32 vertexOffset, - uint32 firstInstance) { + void CommandContext::DrawIndexed(uint32_t indexes, + uint32_t instances, + uint32_t firstIndex, + int32_t vertexOffset, + uint32_t firstInstance) { FlushGraphicsState(); cmd->drawIndexed(indexes, instances, firstIndex, vertexOffset, firstInstance); } - void CommandContext::DrawIndirect(BufferPtr drawCommands, vk::DeviceSize offset, uint32 drawCount, uint32 stride) { + void CommandContext::DrawIndirect(BufferPtr drawCommands, + vk::DeviceSize offset, + uint32_t drawCount, + uint32_t stride) { FlushGraphicsState(); cmd->drawIndirect(*drawCommands, offset, drawCount, stride); } @@ -152,16 +155,16 @@ namespace sp::vulkan { vk::DeviceSize offset, BufferPtr countBuffer, vk::DeviceSize countOffset, - uint32 maxDrawCount, - uint32 stride) { + uint32_t maxDrawCount, + uint32_t stride) { FlushGraphicsState(); cmd->drawIndirectCount(*drawCommands, offset, *countBuffer, countOffset, maxDrawCount, stride); } void CommandContext::DrawIndexedIndirect(BufferPtr drawCommands, vk::DeviceSize offset, - uint32 drawCount, - uint32 stride) { + uint32_t drawCount, + uint32_t stride) { FlushGraphicsState(); cmd->drawIndexedIndirect(*drawCommands, offset, drawCount, stride); } @@ -170,8 +173,8 @@ namespace sp::vulkan { vk::DeviceSize offset, BufferPtr countBuffer, vk::DeviceSize countOffset, - uint32 maxDrawCount, - uint32 stride) { + uint32_t maxDrawCount, + uint32_t stride) { FlushGraphicsState(); cmd->drawIndexedIndirectCount(*drawCommands, offset, *countBuffer, countOffset, maxDrawCount, stride); } @@ -338,7 +341,7 @@ namespace sp::vulkan { SetSingleShader(stage, device.LoadShader(name)); } - void CommandContext::SetShaderConstant(ShaderStage stage, uint32 index, uint32 data) { + void CommandContext::SetShaderConstant(ShaderStage stage, uint32_t index, uint32_t data) { Assert(pipelineInput.state.shaders[stage], "no shader bound to set constant"); auto &spec = pipelineInput.state.specializations[stage]; spec.values[index] = data; @@ -346,7 +349,7 @@ namespace sp::vulkan { SetDirty(DirtyFlags::Pipeline); } - void CommandContext::SetShaderConstant(ShaderStage stage, string_view name, uint32 data) { + void CommandContext::SetShaderConstant(ShaderStage stage, string_view name, uint32_t data) { Assert(pipelineInput.state.shaders[stage], "no shader bound to set constant"); auto shader = device.GetShader(pipelineInput.state.shaders[stage]); Assertf(shader, "bound shader is null when setting constant"); @@ -373,7 +376,7 @@ namespace sp::vulkan { SetDirty(DirtyFlags::PushConstants); } - void CommandContext::SetSampler(uint32 set, uint32 binding, const vk::Sampler &sampler) { + void CommandContext::SetSampler(uint32_t set, uint32_t binding, const vk::Sampler &sampler) { Assert(set < MAX_BOUND_DESCRIPTOR_SETS, "descriptor set index too high"); Assert(binding < MAX_BINDINGS_PER_DESCRIPTOR_SET, "binding index too high"); auto &image = shaderData.sets[set].bindings[binding].image; @@ -402,11 +405,11 @@ namespace sp::vulkan { Errorf("SetSampler binding %s not found on any bound shader: (last: %s)", bindingName, lastShader->name); } - void CommandContext::SetImageView(uint32 set, uint32 binding, const ImageViewPtr &view) { + void CommandContext::SetImageView(uint32_t set, uint32_t binding, const ImageViewPtr &view) { SetImageView(set, binding, view.get()); } - void CommandContext::SetImageView(uint32 set, uint32 binding, const ImageView *view) { + void CommandContext::SetImageView(uint32_t set, uint32_t binding, const ImageView *view) { Assert(set < MAX_BOUND_DESCRIPTOR_SETS, "descriptor set index too high"); Assert(binding < MAX_BINDINGS_PER_DESCRIPTOR_SET, "binding index too high"); auto &bindingDesc = shaderData.sets[set].bindings[binding]; @@ -466,8 +469,8 @@ namespace sp::vulkan { buffer->ByteSize()); } - void CommandContext::SetUniformBuffer(uint32 set, - uint32 binding, + void CommandContext::SetUniformBuffer(uint32_t set, + uint32_t binding, const BufferPtr &buffer, vk::DeviceSize offset, vk::DeviceSize range) { @@ -533,8 +536,8 @@ namespace sp::vulkan { SetUniformBuffer(bindingName, resources->GetBuffer(resourceID), offset, range); } - void CommandContext::SetStorageBuffer(uint32 set, - uint32 binding, + void CommandContext::SetStorageBuffer(uint32_t set, + uint32_t binding, const BufferPtr &buffer, vk::DeviceSize offset, vk::DeviceSize range) { @@ -600,7 +603,7 @@ namespace sp::vulkan { SetStorageBuffer(bindingName, resources->GetBuffer(resourceID), offset, range); } - BufferPtr CommandContext::AllocUniformBuffer(uint32 set, uint32 binding, vk::DeviceSize size) { + BufferPtr CommandContext::AllocUniformBuffer(uint32_t set, uint32_t binding, vk::DeviceSize size) { BufferDesc desc; desc.layout = size; desc.usage = vk::BufferUsageFlagBits::eUniformBuffer; @@ -620,7 +623,7 @@ namespace sp::vulkan { return buffer; } - void CommandContext::SetBindlessDescriptors(uint32 set, vk::DescriptorSet descriptorSet) { + void CommandContext::SetBindlessDescriptors(uint32_t set, vk::DescriptorSet descriptorSet) { Assert(set < MAX_BOUND_DESCRIPTOR_SETS, "descriptor set index too high"); bindlessSets[set] = descriptorSet; SetDescriptorDirty(set); @@ -629,7 +632,7 @@ namespace sp::vulkan { void CommandContext::FlushDescriptorSets(vk::PipelineBindPoint bindPoint) { auto layout = currentPipeline->GetLayout(); - for (uint32 set = 0; set < MAX_BOUND_DESCRIPTOR_SETS; set++) { + for (uint32_t set = 0; set < MAX_BOUND_DESCRIPTOR_SETS; set++) { if (!ResetDescriptorDirty(set)) continue; if (!layout->HasDescriptorSet(set)) continue; diff --git a/src/graphics/graphics/vulkan/core/CommandContext.hh b/src/graphics/graphics/vulkan/core/CommandContext.hh index 0ded509c1..30ca9eee3 100644 --- a/src/graphics/graphics/vulkan/core/CommandContext.hh +++ b/src/graphics/graphics/vulkan/core/CommandContext.hh @@ -40,16 +40,16 @@ namespace sp::vulkan { namespace render_graph { class Resources; - typedef uint32 ResourceID; + typedef uint32_t ResourceID; } // namespace render_graph struct ImageBarrierInfo { - uint32 baseMipLevel = 0; - uint32 mipLevelCount = 0; // default: use all levels - uint32 baseArrayLayer = 0; - uint32 arrayLayerCount = 0; // default: use all layers - uint32 srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; - uint32 dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + uint32_t baseMipLevel = 0; + uint32_t mipLevelCount = 0; // default: use all levels + uint32_t baseArrayLayer = 0; + uint32_t arrayLayerCount = 0; // default: use all layers + uint32_t srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + uint32_t dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; // false skips checking and saving the image layout, // caller must set the image's layout before passing the image to other code @@ -86,35 +86,35 @@ namespace sp::vulkan { PushConstants(&data, offset, sizeof(T)); } - void Dispatch(uint32 groupCountX, uint32 groupCountY, uint32 groupCountZ); + void Dispatch(uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ); // indirectBuffer stores a VkDispatchIndirectCommand object void DispatchIndirect(BufferPtr indirectBuffer, vk::DeviceSize offset); - void Draw(uint32 vertexes, uint32 instances = 1, int32 firstVertex = 0, uint32 firstInstance = 0); - void DrawIndexed(uint32 indexes, - uint32 instances = 1, - uint32 firstIndex = 0, - int32 vertexOffset = 0, - uint32 firstInstance = 0); + void Draw(uint32_t vertexes, uint32_t instances = 1, int32_t firstVertex = 0, uint32_t firstInstance = 0); + void DrawIndexed(uint32_t indexes, + uint32_t instances = 1, + uint32_t firstIndex = 0, + int32_t vertexOffset = 0, + uint32_t firstInstance = 0); void DrawIndirect(BufferPtr drawCommands, vk::DeviceSize offset, - uint32 drawCount, - uint32 stride = sizeof(VkDrawIndirectCommand)); + uint32_t drawCount, + uint32_t stride = sizeof(VkDrawIndirectCommand)); void DrawIndirectCount(BufferPtr drawCommands, vk::DeviceSize offset, BufferPtr countBuffer, vk::DeviceSize countOffset, - uint32 maxDrawCount, - uint32 stride = sizeof(VkDrawIndirectCommand)); + uint32_t maxDrawCount, + uint32_t stride = sizeof(VkDrawIndirectCommand)); void DrawIndexedIndirect(BufferPtr drawCommands, vk::DeviceSize offset, - uint32 drawCount, - uint32 stride = sizeof(VkDrawIndexedIndirectCommand)); + uint32_t drawCount, + uint32_t stride = sizeof(VkDrawIndexedIndirectCommand)); void DrawIndexedIndirectCount(BufferPtr drawCommands, vk::DeviceSize offset, BufferPtr countBuffer, vk::DeviceSize countOffset, - uint32 maxDrawCount, - uint32 stride = sizeof(VkDrawIndexedIndirectCommand)); + uint32_t maxDrawCount, + uint32_t stride = sizeof(VkDrawIndexedIndirectCommand)); void DrawScreenCover(const ImageViewPtr &view = nullptr); void DrawScreenCover(const color_alpha_t &color); @@ -141,15 +141,15 @@ namespace sp::vulkan { // Sets the shaders to a standard compute pipeline. void SetComputeShader(string_view name); - void SetShaderConstant(ShaderStage stage, string_view name, uint32 data); + void SetShaderConstant(ShaderStage stage, string_view name, uint32_t data); - template = 0> + template = 0> void SetShaderConstant(ShaderStage stage, string_view name, T data) { - SetShaderConstant(stage, name, std::bit_cast(data)); + SetShaderConstant(stage, name, std::bit_cast(data)); } void SetShaderConstant(ShaderStage stage, string_view name, bool data) { - SetShaderConstant(stage, name, (uint32)data); + SetShaderConstant(stage, name, (uint32_t)data); } void SetDefaultOpaqueState(); @@ -259,7 +259,7 @@ namespace sp::vulkan { } } - void SetStencilWriteMask(vk::StencilFaceFlags faces, uint32 mask) { + void SetStencilWriteMask(vk::StencilFaceFlags faces, uint32_t mask) { if (faces & vk::StencilFaceFlagBits::eFront) { if (mask != stencilState[0].writeMask) { stencilState[0].writeMask = mask; @@ -274,7 +274,7 @@ namespace sp::vulkan { } } - void SetStencilCompareMask(vk::StencilFaceFlags faces, uint32 mask) { + void SetStencilCompareMask(vk::StencilFaceFlags faces, uint32_t mask) { if (faces & vk::StencilFaceFlagBits::eFront) { if (mask != stencilState[0].compareMask) { stencilState[0].compareMask = mask; @@ -289,7 +289,7 @@ namespace sp::vulkan { } } - void SetStencilReference(vk::StencilFaceFlags faces, uint32 value) { + void SetStencilReference(vk::StencilFaceFlags faces, uint32_t value) { if (faces & vk::StencilFaceFlagBits::eFront) { if (value != stencilState[0].reference) { stencilState[0].reference = value; @@ -378,18 +378,18 @@ namespace sp::vulkan { } } - void SetImageView(uint32 set, uint32 binding, const ImageViewPtr &view); - void SetImageView(uint32 set, uint32 binding, const ImageView *view); + void SetImageView(uint32_t set, uint32_t binding, const ImageViewPtr &view); + void SetImageView(uint32_t set, uint32_t binding, const ImageView *view); void SetImageView(string_view bindingName, const ImageViewPtr &view); void SetImageView(string_view bindingName, const ImageView *view); void SetImageView(string_view bindingName, render_graph::ResourceID resourceID); void SetImageView(string_view bindingName, string_view resourceName); - void SetSampler(uint32 set, uint32 binding, const vk::Sampler &sampler); + void SetSampler(uint32_t set, uint32_t binding, const vk::Sampler &sampler); void SetSampler(string_view bindingName, const vk::Sampler &sampler); // Binds a buffer as to a uniform descriptor. Defaults to the whole buffer. - void SetUniformBuffer(uint32 set, - uint32 binding, + void SetUniformBuffer(uint32_t set, + uint32_t binding, const BufferPtr &buffer, vk::DeviceSize offset = 0, vk::DeviceSize range = 0); @@ -407,8 +407,8 @@ namespace sp::vulkan { vk::DeviceSize range = 0); // Binds a buffer as to a storage descriptor. Defaults to the whole buffer. - void SetStorageBuffer(uint32 set, - uint32 binding, + void SetStorageBuffer(uint32_t set, + uint32_t binding, const BufferPtr &buffer, vk::DeviceSize offset = 0, vk::DeviceSize range = 0); @@ -426,29 +426,29 @@ namespace sp::vulkan { vk::DeviceSize range = 0); // Buffer is stored in a pool for this frame, and reused in later frames. - BufferPtr AllocUniformBuffer(uint32 set, uint32 binding, vk::DeviceSize size); + BufferPtr AllocUniformBuffer(uint32_t set, uint32_t binding, vk::DeviceSize size); BufferPtr AllocUniformBuffer(string_view bindingName, vk::DeviceSize size); // Returns a CPU mapped pointer to the GPU buffer, valid at least until the CommandContext is submitted template - T *AllocUniformData(uint32 set, uint32 binding, uint32 count = 1) { + T *AllocUniformData(uint32_t set, uint32_t binding, uint32_t count = 1) { auto buffer = AllocUniformBuffer(set, binding, sizeof(T) * count); return static_cast(buffer->Mapped()); } template - void UploadUniformData(uint32 set, uint32 binding, const T *data, uint32 count = 1) { + void UploadUniformData(uint32_t set, uint32_t binding, const T *data, uint32_t count = 1) { auto buffer = AllocUniformBuffer(set, binding, sizeof(T) * count); buffer->CopyFrom(data, count); } template - void UploadUniformData(string_view bindingName, const T *data, uint32 count = 1) { + void UploadUniformData(string_view bindingName, const T *data, uint32_t count = 1) { auto buffer = AllocUniformBuffer(bindingName, sizeof(T) * count); buffer->CopyFrom(data, count); } - void SetBindlessDescriptors(uint32 set, vk::DescriptorSet descriptorSet); + void SetBindlessDescriptors(uint32_t set, vk::DescriptorSet descriptorSet); bool WritesToSwapchain() { return writesToSwapchain; @@ -485,7 +485,7 @@ namespace sp::vulkan { private: void SetSingleShader(ShaderStage stage, ShaderHandle handle); void SetSingleShader(ShaderStage stage, string_view name); - void SetShaderConstant(ShaderStage stage, uint32 index, uint32 data); + void SetShaderConstant(ShaderStage stage, uint32_t index, uint32_t data); bool TestDirty(DirtyFlags flags) { return static_cast(dirty & flags); @@ -501,17 +501,17 @@ namespace sp::vulkan { dirty |= flags; } - bool TestDescriptorDirty(uint32 set) { + bool TestDescriptorDirty(uint32_t set) { return static_cast(dirtyDescriptorSets & (1 << set)); } - bool ResetDescriptorDirty(uint32 set) { + bool ResetDescriptorDirty(uint32_t set) { bool ret = TestDescriptorDirty(set); dirtyDescriptorSets &= ~(1 << set); return ret; } - void SetDescriptorDirty(uint32 set) { + void SetDescriptorDirty(uint32_t set) { dirtyDescriptorSets |= (1 << set); } @@ -531,7 +531,7 @@ namespace sp::vulkan { float minDepth = 0.0f, maxDepth = 1.0f; struct StencilDynamicState { - uint32 writeMask = 0, compareMask = 0, reference = 0; + uint32_t writeMask = 0, compareMask = 0, reference = 0; } stencilState[2] = {}; // front and back PipelineCompileInput pipelineInput; @@ -542,7 +542,7 @@ namespace sp::vulkan { bool writesToSwapchain = false; DirtyFlags dirty; - uint32 dirtyDescriptorSets = 0; + uint32_t dirtyDescriptorSets = 0; ShaderDataBindings shaderData; std::array bindlessSets; diff --git a/src/graphics/graphics/vulkan/core/DeviceContext.cc b/src/graphics/graphics/vulkan/core/DeviceContext.cc index fd2c566f2..04a92ebb6 100644 --- a/src/graphics/graphics/vulkan/core/DeviceContext.cc +++ b/src/graphics/graphics/vulkan/core/DeviceContext.cc @@ -187,9 +187,9 @@ namespace sp::vulkan { } Assert(physicalDevice, "No suitable graphics device found!"); - std::array queueIndex; + std::array queueIndex; auto queueFamilies = physicalDevice.getQueueFamilyProperties(); - vector queuesUsedCount(queueFamilies.size()); + vector queuesUsedCount(queueFamilies.size()); vector> queuePriority(queueFamilies.size()); const auto findQueue = [&](QueueType queueType, @@ -242,7 +242,7 @@ namespace sp::vulkan { // "transfer queue family overlaps graphics queue"); std::vector queueInfos; - for (uint32 i = 0; i < queueFamilies.size(); i++) { + for (uint32_t i = 0; i < queueFamilies.size(); i++) { if (queuesUsedCount[i] == 0) continue; vk::DeviceQueueCreateInfo queueInfo; @@ -373,7 +373,7 @@ namespace sp::vulkan { tracing.tracyContexts.resize(QUEUE_TYPES_COUNT); #endif - for (uint32 queueType = 0; queueType < QUEUE_TYPES_COUNT; queueType++) { + for (uint32_t queueType = 0; queueType < QUEUE_TYPES_COUNT; queueType++) { auto familyIndex = queueFamilyIndex[queueType]; auto queue = device->getQueue(familyIndex, queueIndex[queueType]); queues[queueType] = queue; @@ -414,7 +414,7 @@ namespace sp::vulkan { frame.renderCompleteSemaphore = device->createSemaphoreUnique(semaphoreInfo); frame.inFlightFence = device->createFenceUnique(fenceInfo); - for (uint32 queueType = 0; queueType < QUEUE_TYPES_COUNT; queueType++) { + for (uint32_t queueType = 0; queueType < QUEUE_TYPES_COUNT; queueType++) { vk::CommandPoolCreateInfo poolInfo; poolInfo.queueFamilyIndex = queueFamilyIndex[queueType]; poolInfo.flags = vk::CommandPoolCreateFlagBits::eTransient; @@ -470,7 +470,7 @@ namespace sp::vulkan { threadContext->bufferPool = make_unique(*this); - for (uint32 queueType = 0; queueType < QUEUE_TYPES_COUNT; queueType++) { + for (uint32_t queueType = 0; queueType < QUEUE_TYPES_COUNT; queueType++) { vk::CommandPoolCreateInfo poolInfo; poolInfo.queueFamilyIndex = queueFamilyIndex[queueType]; poolInfo.flags = vk::CommandPoolCreateFlagBits::eTransient | @@ -655,6 +655,11 @@ namespace sp::vulkan { vkRenderer = make_shared(game, *this, graph, *compositor); } + void DeviceContext::Shutdown() { + vkRenderer.reset(); + compositor.reset(); + } + std::shared_ptr DeviceContext::GetRenderer() const { return vkRenderer; } @@ -1329,13 +1334,13 @@ namespace sp::vulkan { vk::AccessFlagBits::eTransferWrite, transferMips); - vk::Offset3D currentExtent = {(int32)image->Extent().width, - (int32)image->Extent().height, - (int32)image->Extent().depth}; + vk::Offset3D currentExtent = {(int32_t)image->Extent().width, + (int32_t)image->Extent().height, + (int32_t)image->Extent().depth}; transferMips.mipLevelCount = 1; - for (uint32 i = 1; i < image->MipLevels(); i++) { + for (uint32_t i = 1; i < image->MipLevels(); i++) { auto prevMipExtent = currentExtent; currentExtent.x = std::max(currentExtent.x >> 1, 1); currentExtent.y = std::max(currentExtent.y >> 1, 1); @@ -1637,7 +1642,7 @@ namespace sp::vulkan { void DeviceContext::ThreadContext::ReleaseAvailableResources() { ZoneScoped; - for (uint32 queueType = 0; queueType < QUEUE_TYPES_COUNT; queueType++) { + for (uint32_t queueType = 0; queueType < QUEUE_TYPES_COUNT; queueType++) { erase_if(pendingCommandContexts[queueType], [](auto &cmdHandle) { auto &cmd = cmdHandle.Get(); auto fence = cmd->Fence(); diff --git a/src/graphics/graphics/vulkan/core/DeviceContext.hh b/src/graphics/graphics/vulkan/core/DeviceContext.hh index a8273d66d..26139ae62 100644 --- a/src/graphics/graphics/vulkan/core/DeviceContext.hh +++ b/src/graphics/graphics/vulkan/core/DeviceContext.hh @@ -42,7 +42,7 @@ namespace sp { } // namespace sp namespace sp::vulkan { - const uint32 MAX_FRAMES_IN_FLIGHT = 2; + const uint32_t MAX_FRAMES_IN_FLIGHT = 2; class DescriptorPool; class PerfTimer; @@ -98,6 +98,7 @@ namespace sp::vulkan { void AttachWindow(const std::shared_ptr &context) override; void InitRenderer(Game &game) override; + void Shutdown() override; std::shared_ptr GetRenderer() const; GenericCompositor &GetCompositor() override; @@ -223,7 +224,7 @@ namespace sp::vulkan { tracy::VkCtx *GetTracyContext(CommandContextType type); #endif - uint32 QueueFamilyIndex(CommandContextType type) const { + uint32_t QueueFamilyIndex(CommandContextType type) const { return queueFamilyIndex[QueueType(type)]; } @@ -306,8 +307,8 @@ namespace sp::vulkan { shared_ptr bindlessImageSamplerDescriptorPool; std::array queues; - std::array queueFamilyIndex; - std::array queueLastSubmit; + std::array queueFamilyIndex; + std::array queueLastSubmit; vk::Extent3D imageTransferGranularity; vk::UniqueSwapchainKHR swapchain; @@ -318,7 +319,7 @@ namespace sp::vulkan { }; vector swapchainImageContexts; - uint32 swapchainImageIndex = 0; + uint32_t swapchainImageIndex = 0; SwapchainImageContext &SwapchainImage() { return swapchainImageContexts[swapchainImageIndex]; @@ -352,7 +353,7 @@ namespace sp::vulkan { }; std::array frameContexts; - uint32 frameIndex = 0; + uint32_t frameIndex = 0; FrameContext &Frame() { return frameContexts[frameIndex]; @@ -394,7 +395,7 @@ namespace sp::vulkan { glm::ivec2 systemWindowSize = glm::ivec2(0); glm::ivec4 storedWindowRect = glm::ivec4(0); // Remember window position and size when returning from fullscreen double lastFrameEnd = 0, fpsTimer = 0; - uint32 frameCounter = 0, frameCounterThisSecond = 0; + uint32_t frameCounter = 0, frameCounterThisSecond = 0; std::atomic_uint32_t measuredFrameRate; DispatchQueue frameBeginQueue, frameEndQueue, allocatorQueue; diff --git a/src/graphics/graphics/vulkan/core/Image.cc b/src/graphics/graphics/vulkan/core/Image.cc index 5e703a6ea..a8927aea1 100644 --- a/src/graphics/graphics/vulkan/core/Image.cc +++ b/src/graphics/graphics/vulkan/core/Image.cc @@ -50,7 +50,7 @@ namespace sp::vulkan { lastAccess = newAccess; } - vk::Format FormatFromTraits(uint32 components, uint32 bits, bool preferSrgb, bool logErrors) { + vk::Format FormatFromTraits(uint32_t components, uint32_t bits, bool preferSrgb, bool logErrors) { if (bits != 8 && bits != 16) { if (logErrors) Errorf("can't infer format with bits=%d", bits); return vk::Format::eUndefined; @@ -97,10 +97,10 @@ namespace sp::vulkan { } } - uint32 CalculateMipmapLevels(vk::Extent3D extent) { - uint32 dim = std::max(std::max(extent.width, extent.height), extent.depth); + uint32_t CalculateMipmapLevels(vk::Extent3D extent) { + uint32_t dim = std::max(std::max(extent.width, extent.height), extent.depth); if (dim <= 0) return 1; - uint32 cmp = 31; + uint32_t cmp = 31; while (!(dim >> cmp)) cmp--; return cmp + 1; @@ -161,8 +161,8 @@ namespace sp::vulkan { } struct FormatInfo { - uint32 sizeBytes; - uint32 componentCount; + uint32_t sizeBytes; + uint32_t componentCount; bool srgbTransfer = false; }; @@ -428,11 +428,11 @@ namespace sp::vulkan { }; // clang-format on - uint32 FormatComponentCount(vk::Format format) { + uint32_t FormatComponentCount(vk::Format format) { return formatTable.at((VkFormat)format).componentCount; } - uint32 FormatByteSize(vk::Format format) { + uint32_t FormatByteSize(vk::Format format) { return formatTable.at((VkFormat)format).sizeBytes; } diff --git a/src/graphics/graphics/vulkan/core/Image.hh b/src/graphics/graphics/vulkan/core/Image.hh index 37945e73a..c83d3e2f2 100644 --- a/src/graphics/graphics/vulkan/core/Image.hh +++ b/src/graphics/graphics/vulkan/core/Image.hh @@ -31,8 +31,8 @@ namespace sp::vulkan { vk::ImageType imageType = vk::ImageType::e2D; vk::Format format = vk::Format::eUndefined; vk::Extent3D extent = {}; - uint32 mipLevels = 0; // defaults to 1 if genMipmap is false, defaults to CalculateMipmapLevels otherwise - uint32 arrayLayers = 1; + uint32_t mipLevels = 0; // defaults to 1 if genMipmap is false, defaults to CalculateMipmapLevels otherwise + uint32_t arrayLayers = 1; vk::SampleCountFlagBits samples = vk::SampleCountFlagBits::e1; vk::ImageTiling tiling = vk::ImageTiling::eOptimal; vk::ImageUsageFlags usage = {}; @@ -60,7 +60,7 @@ namespace sp::vulkan { } vk::ImageFormatListCreateInfo GetVkFormatList() const { - return {(uint32)formats.size(), formats.data()}; + return {(uint32_t)formats.size(), formats.data()}; } }; @@ -76,11 +76,11 @@ namespace sp::vulkan { vk::ImageUsageFlags declaredUsage); // Creates an image reference, destructor does not destroy the image - Image(vk::Image image, vk::Format format, vk::Extent3D extent, uint32 mipLevels = 1, uint32 arrayLayers = 1) + Image(vk::Image image, vk::Format format, vk::Extent3D extent, uint32_t mipLevels = 1, uint32_t arrayLayers = 1) : UniqueMemory(VK_NULL_HANDLE), image(image), format(format), extent(extent), mipLevels(mipLevels), arrayLayers(arrayLayers) {} - Image(vk::Image image, vk::Format format, vk::Extent2D extent, uint32 mipLevels = 1, uint32 arrayLayers = 1) + Image(vk::Image image, vk::Format format, vk::Extent2D extent, uint32_t mipLevels = 1, uint32_t arrayLayers = 1) : Image(image, format, vk::Extent3D(extent, 1)) {} vk::Image operator*() const { @@ -99,11 +99,11 @@ namespace sp::vulkan { return extent; } - uint32 MipLevels() const { + uint32_t MipLevels() const { return mipLevels; } - uint32 ArrayLayers() const { + uint32_t ArrayLayers() const { return arrayLayers; } @@ -125,19 +125,19 @@ namespace sp::vulkan { return declaredUsage; } - uint32 LastQueueFamily() const { + uint32_t LastQueueFamily() const { return lastQueueFamilyIndex; } const vk::Semaphore &SetPendingCommand(std::shared_ptr pendingCmd, - uint32 queueFamilyIndex) { + uint32_t queueFamilyIndex) { static const vk::Semaphore emptySemaphore = {}; pendingCommand = pendingCmd; if (queueFamilyIndex != VK_QUEUE_FAMILY_IGNORED) lastQueueFamilyIndex = queueFamilyIndex; return pendingCommand ? pendingCommand->get() : emptySemaphore; } - const vk::Semaphore &GetWaitSemaphore(uint32 queueFamilyIndex = ~0u) { + const vk::Semaphore &GetWaitSemaphore(uint32_t queueFamilyIndex = ~0u) { static const vk::Semaphore emptySemaphore = {}; if (lastQueueFamilyIndex == queueFamilyIndex && queueFamilyIndex != ~0u) return emptySemaphore; return pendingCommand ? pendingCommand->get() : emptySemaphore; @@ -150,12 +150,12 @@ namespace sp::vulkan { vk::Image image; vk::Format format; vk::Extent3D extent; - uint32 mipLevels = 0, arrayLayers = 0; + uint32_t mipLevels = 0, arrayLayers = 0; vk::ImageLayout lastLayout = vk::ImageLayout::eUndefined; Access lastAccess = Access::None; vk::ImageUsageFlags usage = {}, declaredUsage = {}; - uint32 lastQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + uint32_t lastQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; std::shared_ptr pendingCommand; }; @@ -181,7 +181,7 @@ namespace sp::vulkan { // Creates a view to an image, retaining a reference to the image while the view is alive ImageView(vk::UniqueImageView &&view, const ImageViewCreateInfo &info = {}) : info(info) { extent = info.image->Extent(); - for (uint32 i = 0; i < info.baseMipLevel; i++) { + for (uint32_t i = 0; i < info.baseMipLevel; i++) { extent.width = (extent.width + 1) / 2; extent.height = (extent.height + 1) / 2; extent.depth = (extent.depth + 1) / 2; @@ -213,19 +213,19 @@ namespace sp::vulkan { return info.defaultSampler; } - uint32 BaseMipLevel() const { + uint32_t BaseMipLevel() const { return info.baseMipLevel; } - uint32 MipLevels() const { + uint32_t MipLevels() const { return info.mipLevelCount; } - uint32 BaseArrayLayer() const { + uint32_t BaseArrayLayer() const { return info.baseArrayLayer; } - uint32 ArrayLayers() const { + uint32_t ArrayLayers() const { return info.arrayLayerCount; } @@ -250,12 +250,12 @@ namespace sp::vulkan { vk::Extent3D extent; }; - vk::Format FormatFromTraits(uint32 components, uint32 bits, bool preferSrgb, bool logErrors = true); + vk::Format FormatFromTraits(uint32_t components, uint32_t bits, bool preferSrgb, bool logErrors = true); vk::ImageAspectFlags FormatToAspectFlags(vk::Format format); - uint32 FormatComponentCount(vk::Format format); - uint32 FormatByteSize(vk::Format format); + uint32_t FormatComponentCount(vk::Format format); + uint32_t FormatByteSize(vk::Format format); bool FormatIsSRGB(vk::Format format); vk::Format FormatSRGBToUnorm(vk::Format format); - uint32 CalculateMipmapLevels(vk::Extent3D extent); + uint32_t CalculateMipmapLevels(vk::Extent3D extent); vk::SamplerCreateInfo GLSamplerToVKSampler(int minFilter, int magFilter, int wrapS, int wrapT, int wrapR); } // namespace sp::vulkan diff --git a/src/graphics/graphics/vulkan/core/Memory.hh b/src/graphics/graphics/vulkan/core/Memory.hh index fe830aac4..397eadc4d 100644 --- a/src/graphics/graphics/vulkan/core/Memory.hh +++ b/src/graphics/graphics/vulkan/core/Memory.hh @@ -59,12 +59,12 @@ namespace sp::vulkan { }; struct InitialData { - const uint8 *data = nullptr; + const uint8_t *data = nullptr; size_t dataSize = 0; shared_ptr dataOwner; InitialData() = default; - InitialData(const uint8 *data, size_t dataSize, const shared_ptr &dataOwner = nullptr) + InitialData(const uint8_t *data, size_t dataSize, const shared_ptr &dataOwner = nullptr) : data(data), dataSize(dataSize), dataOwner(dataOwner) {} }; diff --git a/src/graphics/graphics/vulkan/core/PerfTimer.cc b/src/graphics/graphics/vulkan/core/PerfTimer.cc index e1a188628..35a217839 100644 --- a/src/graphics/graphics/vulkan/core/PerfTimer.cc +++ b/src/graphics/graphics/vulkan/core/PerfTimer.cc @@ -102,12 +102,12 @@ namespace sp::vulkan { } struct GPUQueryResult { - uint64 timestamp; + uint64_t timestamp; }; void PerfTimer::Tick() { // flush results from two frames ago - uint32 flushFrameIndex = (frameIndex + frames.size() - 2) % frames.size(); + uint32_t flushFrameIndex = (frameIndex + frames.size() - 2) % frames.size(); auto &frame = frames[flushFrameIndex]; if (!FlushResults(frame)) return; @@ -138,16 +138,16 @@ namespace sp::vulkan { auto gpuQueryResult = device->getQueryPoolResults(*frame.queryPool, 0, queryCount, - sizeof(uint64) * queryCount, + sizeof(uint64_t) * queryCount, frame.gpuTimestamps.data(), - sizeof(uint64), + sizeof(uint64_t), vk::QueryResultFlagBits::e64); if (gpuQueryResult == vk::Result::eNotReady) return false; while (!frame.pending.empty()) { auto query = frame.pending.front(); - uint64 gpuStart, gpuEnd; + uint64_t gpuStart, gpuEnd; if (query.gpuQueries[0] == ~0u) { gpuStart = ~0llu; diff --git a/src/graphics/graphics/vulkan/core/PerfTimer.hh b/src/graphics/graphics/vulkan/core/PerfTimer.hh index 11fdfd6a0..50aa2c85a 100644 --- a/src/graphics/graphics/vulkan/core/PerfTimer.hh +++ b/src/graphics/graphics/vulkan/core/PerfTimer.hh @@ -20,12 +20,12 @@ namespace sp::vulkan { struct TimeResult { string name; - size_t depth = 0; + uint32_t depth = 0; chrono_clock::duration cpuElapsed; - uint64 gpuElapsed = 0; + uint64_t gpuElapsed = 0; // used to propagate GPU elapsed time down the phase stack - uint64 gpuStart = ~0llu, gpuEnd = 0; + uint64_t gpuStart = ~0llu, gpuEnd = 0; }; struct TimeQuery { @@ -71,19 +71,19 @@ namespace sp::vulkan { struct FrameContext { vk::UniqueQueryPool queryPool; - uint32 queryOffset = 0; - uint32 queryCount = 0; - uint32 requiredQueryCount = 0; + uint32_t queryOffset = 0; + uint32_t queryCount = 0; + uint32_t requiredQueryCount = 0; std::stack stack; std::deque pending; - vector gpuTimestamps; + vector gpuTimestamps; vector results; }; std::array frames; - uint32 frameIndex = 0; + uint32_t frameIndex = 0; FrameContext &Frame() { return frames[frameIndex]; diff --git a/src/graphics/graphics/vulkan/core/Pipeline.cc b/src/graphics/graphics/vulkan/core/Pipeline.cc index 11c3222f1..62095e061 100644 --- a/src/graphics/graphics/vulkan/core/Pipeline.cc +++ b/src/graphics/graphics/vulkan/core/Pipeline.cc @@ -60,9 +60,9 @@ namespace sp::vulkan { ReflectShaders(); vk::DescriptorSetLayout layouts[MAX_BOUND_DESCRIPTOR_SETS] = {}; - uint32 layoutCount = 0; + uint32_t layoutCount = 0; - for (uint32 set = 0; set < MAX_BOUND_DESCRIPTOR_SETS; set++) { + for (uint32_t set = 0; set < MAX_BOUND_DESCRIPTOR_SETS; set++) { if (!HasDescriptorSet(set)) continue; descriptorPools[set] = manager.GetDescriptorPool(info.descriptorSets[set]); layouts[set] = descriptorPools[set]->GetDescriptorSetLayout(); @@ -83,7 +83,7 @@ namespace sp::vulkan { } void PipelineLayout::ReflectShaders() { - uint32 count; + uint32_t count; for (auto &stageStage : magic_enum::enum_values()) { auto &shader = shaders[stageStage]; @@ -108,13 +108,13 @@ namespace sp::vulkan { SpvReflectDescriptorSet *descriptorSets[MAX_BOUND_DESCRIPTOR_SETS]; reflect.EnumerateDescriptorSets(&count, descriptorSets); - for (uint32 setIndex = 0; setIndex < count; setIndex++) { + for (uint32_t setIndex = 0; setIndex < count; setIndex++) { auto descriptorSet = descriptorSets[setIndex]; auto set = descriptorSet->set; Assert(set < MAX_BOUND_DESCRIPTOR_SETS, "too many descriptor sets"); auto &setInfo = info.descriptorSets[set]; - for (uint32 bindingIndex = 0; bindingIndex < descriptorSet->binding_count; bindingIndex++) { + for (uint32_t bindingIndex = 0; bindingIndex < descriptorSet->binding_count; bindingIndex++) { auto &desc = descriptorSet->bindings[bindingIndex]; if (!desc->accessed) continue; @@ -181,15 +181,15 @@ namespace sp::vulkan { } void PipelineLayout::CreateDescriptorUpdateTemplates(DeviceContext &device) { - for (uint32 set = 0; set < MAX_BOUND_DESCRIPTOR_SETS; set++) { + for (uint32_t set = 0; set < MAX_BOUND_DESCRIPTOR_SETS; set++) { if (!HasDescriptorSet(set)) continue; if (IsBindlessSet(set)) continue; // bindless sets have variable size and must be updated manually vk::DescriptorUpdateTemplateEntry entries[MAX_BINDINGS_PER_DESCRIPTOR_SET]; - uint32 entryCount = 0; + uint32_t entryCount = 0; auto &setInfo = info.descriptorSets[set]; - auto setEntry = [&](uint32 binding, vk::DescriptorType type, size_t structOffset) { + auto setEntry = [&](uint32_t binding, vk::DescriptorType type, size_t structOffset) { Assert(entryCount < MAX_BINDINGS_PER_DESCRIPTOR_SET, "too many descriptors"); auto &entry = entries[entryCount++]; entry.descriptorType = type; @@ -201,16 +201,16 @@ namespace sp::vulkan { entry.stride = sizeof(DescriptorBinding); }; - ForEachBit(setInfo.sampledImagesMask, [&](uint32 binding) { + ForEachBit(setInfo.sampledImagesMask, [&](uint32_t binding) { setEntry(binding, vk::DescriptorType::eCombinedImageSampler, offsetof(DescriptorBinding, image)); }); - ForEachBit(setInfo.storageImagesMask, [&](uint32 binding) { + ForEachBit(setInfo.storageImagesMask, [&](uint32_t binding) { setEntry(binding, vk::DescriptorType::eStorageImage, offsetof(DescriptorBinding, image)); }); - ForEachBit(setInfo.uniformBuffersMask, [&](uint32 binding) { + ForEachBit(setInfo.uniformBuffersMask, [&](uint32_t binding) { setEntry(binding, vk::DescriptorType::eUniformBuffer, offsetof(DescriptorBinding, buffer)); }); - ForEachBit(setInfo.storageBuffersMask, [&](uint32 binding) { + ForEachBit(setInfo.storageBuffersMask, [&](uint32_t binding) { setEntry(binding, vk::DescriptorType::eStorageBuffer, offsetof(DescriptorBinding, buffer)); }); @@ -227,7 +227,7 @@ namespace sp::vulkan { } } - vk::DescriptorSet PipelineLayout::GetFilledDescriptorSet(uint32 set, const DescriptorSetBindings &setBindings) { + vk::DescriptorSet PipelineLayout::GetFilledDescriptorSet(uint32_t set, const DescriptorSetBindings &setBindings) { if (!HasDescriptorSet(set)) return VK_NULL_HANDLE; Assertf(!IsBindlessSet(set), "can't automatically fill bindless descriptor set %d", set); @@ -237,8 +237,8 @@ namespace sp::vulkan { // Hash of the subset of data that is actually accessed by the pipeline. Hash64 hash = 0; - ForEachBit(setLayout.sampledImagesMask | setLayout.storageImagesMask, [&](uint32 binding) { - for (uint32 i = 0; i < setLayout.descriptorCount[binding]; i++) { + ForEachBit(setLayout.sampledImagesMask | setLayout.storageImagesMask, [&](uint32_t binding) { + for (uint32_t i = 0; i < setLayout.descriptorCount[binding]; i++) { hash_combine(hash, bindings[binding + i].uniqueID); hash_combine(hash, bindings[binding + i].image.imageView); hash_combine(hash, bindings[binding + i].image.sampler); @@ -246,8 +246,8 @@ namespace sp::vulkan { } }); - ForEachBit(setLayout.uniformBuffersMask | setLayout.storageBuffersMask, [&](uint32 binding) { - for (uint32 i = 0; i < setLayout.descriptorCount[binding]; i++) { + ForEachBit(setLayout.uniformBuffersMask | setLayout.storageBuffersMask, [&](uint32_t binding) { + for (uint32_t i = 0; i < setLayout.descriptorCount[binding]; i++) { hash_combine(hash, bindings[binding + i].uniqueID); hash_combine(hash, bindings[binding + i].buffer.buffer); hash_combine(hash, bindings[binding + i].buffer.offset); @@ -260,7 +260,7 @@ namespace sp::vulkan { auto &sizes = info.sizes[set]; bool errors = false; - ForEachBit(setLayout.uniformBuffersMask | setLayout.storageBuffersMask, [&](uint32 binding) { + ForEachBit(setLayout.uniformBuffersMask | setLayout.storageBuffersMask, [&](uint32_t binding) { auto size = bindings[binding].buffer.range; auto minSize = sizes[binding].sizeBase; if (size == minSize) return; @@ -384,7 +384,7 @@ namespace sp::vulkan { specOut.mapEntryCount = 0; for (size_t i = 0; i < MAX_SPEC_CONSTANTS; i++) { if (!specIn.set[i]) continue; - specializationValues.emplace_back(i, i * sizeof(uint32), sizeof(uint32)); + specializationValues.emplace_back(i, i * sizeof(uint32_t), sizeof(uint32_t)); specOut.mapEntryCount++; } @@ -448,7 +448,7 @@ namespace sp::vulkan { colorBlending.pAttachments = colorBlendAttachments.data(); // TODO: support configuring each attachment - for (uint32 i = 0; i < colorBlending.attachmentCount; i++) { + for (uint32_t i = 0; i < colorBlending.attachmentCount; i++) { auto &blendState = colorBlendAttachments[i]; blendState.blendEnable = state.blendEnable; if (state.blendEnable) { @@ -522,7 +522,7 @@ namespace sp::vulkan { DescriptorPool::DescriptorPool(DeviceContext &device, const DescriptorSetLayoutInfo &layoutInfo) : device(device) { vector bindingFlags; - for (uint32 binding = 0; binding < layoutInfo.lastBinding + 1; binding++) { + for (uint32_t binding = 0; binding < layoutInfo.lastBinding + 1; binding++) { auto bindingBit = 1 << binding; vk::DescriptorType type; int count = 0; @@ -549,7 +549,7 @@ namespace sp::vulkan { Assert(!bindless, "Variable length binding arrays must be the last binding in the set"); auto stages = layoutInfo.stages[binding]; - uint32 descriptorCount = layoutInfo.descriptorCount[binding]; + uint32_t descriptorCount = layoutInfo.descriptorCount[binding]; if (descriptorCount == 0) { bindless = true; descriptorCount = MAX_BINDINGS_PER_BINDLESS_DESCRIPTOR_SET; @@ -628,7 +628,7 @@ namespace sp::vulkan { // for now, just allocate the maximum // if we have multiple bindless sets, it would be good to tailor the sizes depending on the usage - uint32 variableCount = bindings.back().descriptorCount; + uint32_t variableCount = bindings.back().descriptorCount; vk::DescriptorSetVariableDescriptorCountAllocateInfo countAllocInfo; countAllocInfo.descriptorSetCount = 1; countAllocInfo.pDescriptorCounts = &variableCount; diff --git a/src/graphics/graphics/vulkan/core/Pipeline.hh b/src/graphics/graphics/vulkan/core/Pipeline.hh index e802f14bf..c13538d06 100644 --- a/src/graphics/graphics/vulkan/core/Pipeline.hh +++ b/src/graphics/graphics/vulkan/core/Pipeline.hh @@ -21,7 +21,7 @@ namespace sp::vulkan { class RenderPass; struct SpecializationData { - std::array values = {}; + std::array values = {}; std::bitset set = {}; }; @@ -41,8 +41,8 @@ namespace sp::vulkan { unsigned depthTest : 1; unsigned blendEnable : 1; unsigned stencilTest : 1; - uint8 viewportCount = 1; - uint8 scissorCount = 1; + uint8_t viewportCount = 1; + uint8_t scissorCount = 1; vk::CompareOp depthCompareOp = vk::CompareOp::eLess; vk::CompareOp stencilCompareOp = vk::CompareOp::eAlways; vk::StencilOp stencilFailOp = vk::StencilOp::eKeep; @@ -57,23 +57,23 @@ namespace sp::vulkan { }; struct DescriptorSetLayoutInfo { - uint32 sampledImagesMask = 0; - uint32 uniformBuffersMask = 0; - uint32 storageBuffersMask = 0; - uint32 storageImagesMask = 0; - uint32 lastBinding = 0; + uint32_t sampledImagesMask = 0; + uint32_t uniformBuffersMask = 0; + uint32_t storageBuffersMask = 0; + uint32_t storageImagesMask = 0; + uint32_t lastBinding = 0; vk::ShaderStageFlags stages[MAX_BINDINGS_PER_DESCRIPTOR_SET] = {}; // count is usually 1, can be higher for array bindings, or 0 for an unbounded array - uint8 descriptorCount[MAX_BINDINGS_PER_DESCRIPTOR_SET] = {}; + uint8_t descriptorCount[MAX_BINDINGS_PER_DESCRIPTOR_SET] = {}; }; struct PipelineLayoutInfo { vk::PushConstantRange pushConstantRange; - uint32 descriptorSetsMask = 0; - uint32 bindlessMask = 0; + uint32_t descriptorSetsMask = 0; + uint32_t bindlessMask = 0; DescriptorSetLayoutInfo descriptorSets[MAX_BOUND_DESCRIPTOR_SETS] = {}; struct MemorySize { @@ -119,22 +119,22 @@ namespace sp::vulkan { return info; } - vk::DescriptorUpdateTemplate GetDescriptorUpdateTemplate(uint32 set) const { + vk::DescriptorUpdateTemplate GetDescriptorUpdateTemplate(uint32_t set) const { if (HasDescriptorSet(set)) { return *descriptorUpdateTemplates[set]; } return VK_NULL_HANDLE; } - bool HasDescriptorSet(uint32 set) const { + bool HasDescriptorSet(uint32_t set) const { return info.descriptorSetsMask & (1 << set); } - bool IsBindlessSet(uint32 set) const { + bool IsBindlessSet(uint32_t set) const { return info.bindlessMask & (1 << set); } - vk::DescriptorSet GetFilledDescriptorSet(uint32 set, const DescriptorSetBindings &setBindings); + vk::DescriptorSet GetFilledDescriptorSet(uint32_t set, const DescriptorSetBindings &setBindings); private: void ReflectShaders(); diff --git a/src/graphics/graphics/vulkan/core/RenderPass.cc b/src/graphics/graphics/vulkan/core/RenderPass.cc index 283f991e7..314277b66 100644 --- a/src/graphics/graphics/vulkan/core/RenderPass.cc +++ b/src/graphics/graphics/vulkan/core/RenderPass.cc @@ -12,7 +12,7 @@ namespace sp::vulkan { RenderPass::RenderPass(DeviceContext &device, const RenderPassInfo &info) : state(info.state) { - uint32 attachmentCount = 0; + uint32_t attachmentCount = 0; vk::AttachmentDescription attachments[MAX_COLOR_ATTACHMENTS + 1] = {}; vk::AttachmentReference colorAttachmentRefs[MAX_COLOR_ATTACHMENTS]; vk::AttachmentReference depthAttachmentRef; @@ -20,7 +20,7 @@ namespace sp::vulkan { auto &state = info.state; Assert(state.colorAttachmentCount < MAX_COLOR_ATTACHMENTS, "too many attachments"); - for (uint32 i = 0; i < state.colorAttachmentCount; i++) { + for (uint32_t i = 0; i < state.colorAttachmentCount; i++) { vk::AttachmentDescription &colorAttachment = attachments[i]; colorAttachment.samples = vk::SampleCountFlagBits::e1; colorAttachment.format = state.colorFormats[i]; @@ -141,7 +141,7 @@ namespace sp::vulkan { } void RenderPass::RecordImplicitImageLayoutTransitions(const RenderPassInfo &info) { - for (uint32 i = 0; i < info.state.colorAttachmentCount; i++) { + for (uint32_t i = 0; i < info.state.colorAttachmentCount; i++) { info.colorAttachments[i]->Image()->SetLayout(initialLayouts[i], finalLayouts[i]); } if (info.HasDepthStencil()) { @@ -155,9 +155,9 @@ namespace sp::vulkan { extent = vk::Extent2D{UINT32_MAX, UINT32_MAX}; vk::ImageView attachments[MAX_COLOR_ATTACHMENTS + 1]; - uint32 attachmentCount = info.state.colorAttachmentCount; + uint32_t attachmentCount = info.state.colorAttachmentCount; - for (uint32 i = 0; i < info.state.colorAttachmentCount; i++) { + for (uint32_t i = 0; i < info.state.colorAttachmentCount; i++) { auto &image = *info.colorAttachments[i]; attachments[i] = image; extent.width = std::min(extent.width, image.Extent().width); @@ -201,7 +201,7 @@ namespace sp::vulkan { FramebufferKey key; key.input.renderPass = info.state; - for (uint32 i = 0; i < info.state.colorAttachmentCount; i++) { + for (uint32_t i = 0; i < info.state.colorAttachmentCount; i++) { auto imageView = info.colorAttachments[i]; Assert(!!imageView, "render pass is missing a color image"); key.input.imageViewIDs[i] = imageView->GetUniqueID(); diff --git a/src/graphics/graphics/vulkan/core/RenderPass.hh b/src/graphics/graphics/vulkan/core/RenderPass.hh index e53ff6bde..2291a2fbf 100644 --- a/src/graphics/graphics/vulkan/core/RenderPass.hh +++ b/src/graphics/graphics/vulkan/core/RenderPass.hh @@ -17,32 +17,32 @@ namespace sp::vulkan { const size_t MAX_COLOR_ATTACHMENTS = 4; struct RenderPassState { - uint32 colorAttachmentCount = 0; + uint32_t colorAttachmentCount = 0; vk::Format colorFormats[MAX_COLOR_ATTACHMENTS] = {}; vk::Format depthStencilFormat = {}; // depth/stencil bit is at DEPTH_STENCIL_INDEX, not the actual depth attachment index - uint32 clearAttachments = 0; - uint32 loadAttachments = 0; - uint32 storeAttachments = 0; - uint32 readOnlyAttachments = 0; + uint32_t clearAttachments = 0; + uint32_t loadAttachments = 0; + uint32_t storeAttachments = 0; + uint32_t readOnlyAttachments = 0; // each bit represents a specific array layer to enable rendering to - uint32 multiviewMask = 0; + uint32_t multiviewMask = 0; // Vulkan allows you to specify an arbitrary number of correlation masks, to indicate that // multiple subsets of attachments are spatially correlated in different ways. We currently support a single // correlation mask, since all our attachments are spatially correlated in the same way. - uint32 multiviewCorrelationMask = 0; + uint32_t multiviewCorrelationMask = 0; - static const uint32 DEPTH_STENCIL_INDEX = 31; + static const uint32_t DEPTH_STENCIL_INDEX = 31; bool HasDepthStencil() const { return depthStencilFormat != vk::Format::eUndefined; } - void SetLoadStore(uint32 index, LoadOp loadOp, StoreOp storeOp) { - uint32 attachmentBit = 1 << index; + void SetLoadStore(uint32_t index, LoadOp loadOp, StoreOp storeOp) { + uint32_t attachmentBit = 1 << index; if (loadOp == LoadOp::Clear) { clearAttachments |= attachmentBit; } else { @@ -65,26 +65,26 @@ namespace sp::vulkan { } } - vk::AttachmentLoadOp LoadOp(uint32 index) const { - uint32 attachmentBit = 1 << index; + vk::AttachmentLoadOp LoadOp(uint32_t index) const { + uint32_t attachmentBit = 1 << index; if (clearAttachments & attachmentBit) return vk::AttachmentLoadOp::eClear; if (loadAttachments & attachmentBit) return vk::AttachmentLoadOp::eLoad; return vk::AttachmentLoadOp::eDontCare; } - vk::AttachmentStoreOp StoreOp(uint32 index) const { - uint32 attachmentBit = 1 << index; + vk::AttachmentStoreOp StoreOp(uint32_t index) const { + uint32_t attachmentBit = 1 << index; if (storeAttachments & attachmentBit) return vk::AttachmentStoreOp::eStore; return vk::AttachmentStoreOp::eDontCare; } - bool ReadOnly(uint32 index) const { - uint32 attachmentBit = 1 << index; + bool ReadOnly(uint32_t index) const { + uint32_t attachmentBit = 1 << index; return readOnlyAttachments & attachmentBit; } - bool ShouldClear(uint32 index) const { - uint32 attachmentBit = 1 << index; + bool ShouldClear(uint32_t index) const { + uint32_t attachmentBit = 1 << index; return clearAttachments & attachmentBit; } }; @@ -93,7 +93,7 @@ namespace sp::vulkan { RenderPassState state; ImageViewPtr colorAttachments[MAX_COLOR_ATTACHMENTS] = {}; ImageViewPtr depthStencilAttachment; - uint32 minAttachmentLayers = ~0u; + uint32_t minAttachmentLayers = ~0u; vk::ClearColorValue clearColors[MAX_COLOR_ATTACHMENTS] = {}; vk::ClearDepthStencilValue clearDepthStencil = {1.0f, 0}; @@ -103,7 +103,7 @@ namespace sp::vulkan { StoreOp storeOp, vk::ClearColorValue clear = {}) { Assert(state.colorAttachmentCount < MAX_COLOR_ATTACHMENTS, "too many color attachments"); - uint32 index = state.colorAttachmentCount++; + uint32_t index = state.colorAttachmentCount++; SetColorAttachment(index, view, loadOp, storeOp, clear); } @@ -112,7 +112,7 @@ namespace sp::vulkan { PushColorAttachment(view, loadOp, storeOp, clearValues); } - void SetColorAttachment(uint32 index, + void SetColorAttachment(uint32_t index, const ImageViewPtr &view, LoadOp loadOp, StoreOp storeOp, @@ -138,7 +138,7 @@ namespace sp::vulkan { } void EnableMultiviewForAllLayers(const ImageViewPtr &view) { - uint32 layers = view->ArrayLayers(); + uint32_t layers = view->ArrayLayers(); if (layers < minAttachmentLayers) { minAttachmentLayers = layers; } @@ -146,7 +146,7 @@ namespace sp::vulkan { state.multiviewMask = 0; if (minAttachmentLayers >= 2) { - for (uint32 i = 0; i < minAttachmentLayers; i++) { + for (uint32_t i = 0; i < minAttachmentLayers; i++) { state.multiviewMask |= (1 << i); } } @@ -168,7 +168,7 @@ namespace sp::vulkan { // Updates the cached layout of the framebuffer attachment images void RecordImplicitImageLayoutTransitions(const RenderPassInfo &info); - uint32 ColorAttachmentCount() const { + uint32_t ColorAttachmentCount() const { return state.colorAttachmentCount; } diff --git a/src/graphics/graphics/vulkan/core/Shader.cc b/src/graphics/graphics/vulkan/core/Shader.cc index 715f7d9ab..ab1f242db 100644 --- a/src/graphics/graphics/vulkan/core/Shader.cc +++ b/src/graphics/graphics/vulkan/core/Shader.cc @@ -29,7 +29,7 @@ namespace sp::vulkan { InlineVector descriptorSets; for (auto *descriptorSet : reflectBuffer) { auto &set = descriptorSets.emplace_back(Shader::DescriptorSet{descriptorSet->set, {}}); - for (uint32 bindingIndex = 0; bindingIndex < descriptorSet->binding_count; bindingIndex++) { + for (uint32_t bindingIndex = 0; bindingIndex < descriptorSet->binding_count; bindingIndex++) { auto &binding = descriptorSet->bindings[bindingIndex]; std::string bindingName = binding->name ? binding->name : ""; if (bindingName.empty() && binding->type_description) { diff --git a/src/graphics/graphics/vulkan/core/Shader.hh b/src/graphics/graphics/vulkan/core/Shader.hh index 80343eab5..58b80db2f 100644 --- a/src/graphics/graphics/vulkan/core/Shader.hh +++ b/src/graphics/graphics/vulkan/core/Shader.hh @@ -15,13 +15,13 @@ #include namespace sp::vulkan { - const uint32 MAX_PUSH_CONSTANT_SIZE = 128; - const uint32 MAX_PUSH_CONSTANT_BLOCKS = 1; - const uint32 MAX_SPEC_CONSTANTS = 16; - const uint32 MAX_BOUND_DESCRIPTOR_SETS = 4; - const uint32 MAX_BINDINGS_PER_DESCRIPTOR_SET = 32; - const uint32 MAX_DESCRIPTOR_SETS_PER_POOL = 16; - const uint32 MAX_BINDINGS_PER_BINDLESS_DESCRIPTOR_SET = 65535; + const uint32_t MAX_PUSH_CONSTANT_SIZE = 128; + const uint32_t MAX_PUSH_CONSTANT_BLOCKS = 1; + const uint32_t MAX_SPEC_CONSTANTS = 16; + const uint32_t MAX_BOUND_DESCRIPTOR_SETS = 4; + const uint32_t MAX_BINDINGS_PER_DESCRIPTOR_SET = 32; + const uint32_t MAX_DESCRIPTOR_SETS_PER_POOL = 16; + const uint32_t MAX_BINDINGS_PER_BINDLESS_DESCRIPTOR_SET = 65535; class Model; @@ -56,23 +56,23 @@ namespace sp::vulkan { struct DescriptorSetBinding { std::string name; vk::DescriptorType type; - uint32 bindingId; + uint32_t bindingId; bool accessed; }; struct DescriptorSet { - uint32 setId; + uint32_t setId; InlineVector bindings; }; struct SpecConstant { std::string name; - uint32 constantId; + uint32_t constantId; }; struct PushConstant { - uint32 offset; - uint32 size; + uint32_t offset; + uint32_t size; }; const InlineVector descriptorSets; @@ -99,7 +99,7 @@ namespace sp::vulkan { VkDescriptorImageInfo image; }; UniqueID uniqueID = 0; - uint32 arrayStride = 0; + uint32_t arrayStride = 0; }; struct DescriptorSetBindings { @@ -107,7 +107,7 @@ namespace sp::vulkan { }; struct ShaderDataBindings { - uint8 pushConstants[MAX_PUSH_CONSTANT_SIZE]; + uint8_t pushConstants[MAX_PUSH_CONSTANT_SIZE]; DescriptorSetBindings sets[MAX_BOUND_DESCRIPTOR_SETS]; }; } // namespace sp::vulkan diff --git a/src/graphics/graphics/vulkan/core/UniqueID.hh b/src/graphics/graphics/vulkan/core/UniqueID.hh index cddc83f54..16c47b095 100644 --- a/src/graphics/graphics/vulkan/core/UniqueID.hh +++ b/src/graphics/graphics/vulkan/core/UniqueID.hh @@ -12,7 +12,7 @@ namespace sp::vulkan { class DeviceContext; - typedef uint64 UniqueID; + typedef uint64_t UniqueID; class HasUniqueID { public: diff --git a/src/graphics/graphics/vulkan/core/VertexLayout.hh b/src/graphics/graphics/vulkan/core/VertexLayout.hh index 13e7f5952..c90002d61 100644 --- a/src/graphics/graphics/vulkan/core/VertexLayout.hh +++ b/src/graphics/graphics/vulkan/core/VertexLayout.hh @@ -16,15 +16,15 @@ namespace sp::vulkan { struct VertexLayout { VertexLayout() {} - VertexLayout(uint32 binding, uint32 stride, vk::VertexInputRate inputRate = vk::VertexInputRate::eVertex) { + VertexLayout(uint32_t binding, uint32_t stride, vk::VertexInputRate inputRate = vk::VertexInputRate::eVertex) { PushBinding(binding, stride, inputRate); } - VertexLayout(uint32 binding, size_t stride, vk::VertexInputRate inputRate = vk::VertexInputRate::eVertex) { - PushBinding(binding, (uint32)stride, inputRate); + VertexLayout(uint32_t binding, size_t stride, vk::VertexInputRate inputRate = vk::VertexInputRate::eVertex) { + PushBinding(binding, (uint32_t)stride, inputRate); } - void PushAttribute(uint32 location, uint32 binding, vk::Format format, uint32 offset) { + void PushAttribute(uint32_t location, uint32_t binding, vk::Format format, uint32_t offset) { PushAttribute(vk::VertexInputAttributeDescription(location, binding, format, offset)); } @@ -33,7 +33,9 @@ namespace sp::vulkan { attributes[attributeCount++] = attribute; } - void PushBinding(uint32 binding, uint32 stride, vk::VertexInputRate inputRate = vk::VertexInputRate::eVertex) { + void PushBinding(uint32_t binding, + uint32_t stride, + vk::VertexInputRate inputRate = vk::VertexInputRate::eVertex) { PushBinding(vk::VertexInputBindingDescription(binding, stride, inputRate)); } diff --git a/src/graphics/graphics/vulkan/core/VkCommon.hh b/src/graphics/graphics/vulkan/core/VkCommon.hh index 415f895ff..28ab97c90 100644 --- a/src/graphics/graphics/vulkan/core/VkCommon.hh +++ b/src/graphics/graphics/vulkan/core/VkCommon.hh @@ -17,7 +17,7 @@ #include namespace sp::vulkan { - typedef uint32 ShaderHandle; + typedef uint32_t ShaderHandle; class DeviceContext; class CommandContext; diff --git a/src/graphics/graphics/vulkan/render_graph/Pass.hh b/src/graphics/graphics/vulkan/render_graph/Pass.hh index 94764b3b9..442fb9d5e 100644 --- a/src/graphics/graphics/vulkan/render_graph/Pass.hh +++ b/src/graphics/graphics/vulkan/render_graph/Pass.hh @@ -27,7 +27,7 @@ namespace sp::vulkan::render_graph { struct ResourceIDFutureAccess { ResourceID id; Access access; - uint32 framesFromNow; + uint32_t framesFromNow; }; struct AttachmentInfo { @@ -37,7 +37,7 @@ namespace sp::vulkan::render_graph { StoreOp storeOp = StoreOp::DontCare; vk::ClearColorValue clearColor = {}; vk::ClearDepthStencilValue clearDepthStencil = {1.0f, 0}; - uint32 arrayIndex = ~0u; // if the attachment is an array image, this can be set to render to a specific index + uint32_t arrayIndex = ~0u; // if the attachment is an array image, this can be set to render to a specific index void SetClearColor(glm::vec4 clear) { std::array clearValues = {clear.r, clear.g, clear.b, clear.a}; @@ -57,7 +57,7 @@ namespace sp::vulkan::render_graph { void AddAccess(ResourceID id, Access access) { accesses.push_back({id, access}); } - void AddFutureRead(ResourceID id, Access access, uint32 framesFromNow) { + void AddFutureRead(ResourceID id, Access access, uint32_t framesFromNow) { futureReads.push_back({id, access, framesFromNow}); } @@ -85,7 +85,7 @@ namespace sp::vulkan::render_graph { InlineVector futureReads; std::array attachments; bool active = false, required = false; - uint8 primaryAttachmentIndex = 0; + uint8_t primaryAttachmentIndex = 0; bool isRenderPass = false; bool flushCommands = false; // true will submit pending command buffers @@ -94,6 +94,6 @@ namespace sp::vulkan::render_graph { std::function> executeFunc; - InlineVector scopes; + InlineVector scopes; }; } // namespace sp::vulkan::render_graph diff --git a/src/graphics/graphics/vulkan/render_graph/PassBuilder.cc b/src/graphics/graphics/vulkan/render_graph/PassBuilder.cc index 04bda52d3..9cabab609 100644 --- a/src/graphics/graphics/vulkan/render_graph/PassBuilder.cc +++ b/src/graphics/graphics/vulkan/render_graph/PassBuilder.cc @@ -18,7 +18,7 @@ namespace sp::vulkan::render_graph { return id; } - ResourceID PassBuilder::ReadPreviousFrame(string_view name, Access access, uint32 framesAgo) { + ResourceID PassBuilder::ReadPreviousFrame(string_view name, Access access, uint32_t framesAgo) { auto thisFrameID = resources.GetID(name, false); if (thisFrameID == InvalidResource) thisFrameID = resources.ReserveID(name); if (thisFrameID == InvalidResource) return InvalidResource; @@ -58,18 +58,18 @@ namespace sp::vulkan::render_graph { return resource; } - void PassBuilder::SetColorAttachment(uint32 index, string_view name, const AttachmentInfo &info) { + void PassBuilder::SetColorAttachment(uint32_t index, string_view name, const AttachmentInfo &info) { SetColorAttachment(index, GetID(name), info); } - void PassBuilder::SetColorAttachment(uint32 index, ResourceID id, const AttachmentInfo &info) { + void PassBuilder::SetColorAttachment(uint32_t index, ResourceID id, const AttachmentInfo &info) { auto &res = resources.GetResourceRef(id); Assert(res.type == Resource::Type::Image, "resource must be a render target"); Write(id, Access::ColorAttachmentReadWrite); SetAttachment(index, id, info); } - Resource PassBuilder::OutputColorAttachment(uint32 index, + Resource PassBuilder::OutputColorAttachment(uint32_t index, string_view name, ImageDesc desc, const AttachmentInfo &info) { @@ -95,7 +95,7 @@ namespace sp::vulkan::render_graph { return resource; } - void PassBuilder::SetPrimaryAttachment(uint32 index) { + void PassBuilder::SetPrimaryAttachment(uint32_t index) { Assert(index < pass.attachments.size(), "index must point to a valid attachment"); pass.primaryAttachmentIndex = index; } @@ -117,7 +117,7 @@ namespace sp::vulkan::render_graph { return resource; } - Resource PassBuilder::OutputAttachment(uint32 index, + Resource PassBuilder::OutputAttachment(uint32_t index, string_view name, const ImageDesc &desc, const AttachmentInfo &info) { @@ -126,7 +126,7 @@ namespace sp::vulkan::render_graph { return resource; } - void PassBuilder::SetAttachment(uint32 index, ResourceID id, const AttachmentInfo &info) { + void PassBuilder::SetAttachment(uint32_t index, ResourceID id, const AttachmentInfo &info) { auto &attachment = pass.attachments[index]; attachment = info; attachment.resourceID = id; diff --git a/src/graphics/graphics/vulkan/render_graph/PassBuilder.hh b/src/graphics/graphics/vulkan/render_graph/PassBuilder.hh index 9f9240a99..7dc77b173 100644 --- a/src/graphics/graphics/vulkan/render_graph/PassBuilder.hh +++ b/src/graphics/graphics/vulkan/render_graph/PassBuilder.hh @@ -27,7 +27,7 @@ namespace sp::vulkan::render_graph { void Read(ResourceID id, Access access); ResourceID Read(string_view name, Access access); - ResourceID ReadPreviousFrame(string_view name, Access access, uint32 framesAgo = 1); + ResourceID ReadPreviousFrame(string_view name, Access access, uint32_t framesAgo = 1); void Write(ResourceID id, Access access); ResourceID Write(string_view name, Access access); @@ -36,16 +36,16 @@ namespace sp::vulkan::render_graph { const Resource &ReadUniform(string_view name); const Resource &ReadUniform(ResourceID id); - void SetColorAttachment(uint32 index, string_view name, const AttachmentInfo &info); - void SetColorAttachment(uint32 index, ResourceID id, const AttachmentInfo &info); - Resource OutputColorAttachment(uint32 index, string_view name, ImageDesc desc, const AttachmentInfo &info); + void SetColorAttachment(uint32_t index, string_view name, const AttachmentInfo &info); + void SetColorAttachment(uint32_t index, ResourceID id, const AttachmentInfo &info); + Resource OutputColorAttachment(uint32_t index, string_view name, ImageDesc desc, const AttachmentInfo &info); void SetDepthAttachment(string_view name, const AttachmentInfo &info); void SetDepthAttachment(ResourceID id, const AttachmentInfo &info); Resource OutputDepthAttachment(string_view name, ImageDesc desc, const AttachmentInfo &info); // The attachment at this index will become the LastOutput of the graph after the pass, defaults to 0 - void SetPrimaryAttachment(uint32 index); + void SetPrimaryAttachment(uint32_t index); Resource CreateImage(string_view name, const ImageDesc &desc, Access access); @@ -84,9 +84,9 @@ namespace sp::vulkan::render_graph { } private: - Resource OutputAttachment(uint32 index, string_view name, const ImageDesc &desc, const AttachmentInfo &info); + Resource OutputAttachment(uint32_t index, string_view name, const ImageDesc &desc, const AttachmentInfo &info); - void SetAttachment(uint32 index, ResourceID id, const AttachmentInfo &info); + void SetAttachment(uint32_t index, ResourceID id, const AttachmentInfo &info); Resources &resources; Pass &pass; diff --git a/src/graphics/graphics/vulkan/render_graph/PooledImage.cc b/src/graphics/graphics/vulkan/render_graph/PooledImage.cc index 8ef5bf799..06cb7f924 100644 --- a/src/graphics/graphics/vulkan/render_graph/PooledImage.cc +++ b/src/graphics/graphics/vulkan/render_graph/PooledImage.cc @@ -11,7 +11,7 @@ #include "graphics/vulkan/core/DeviceContext.hh" namespace sp::vulkan::render_graph { - const ImageViewPtr &PooledImage::LayerImageView(uint32 layer) { + const ImageViewPtr &PooledImage::LayerImageView(uint32_t layer) { Assert(layer < desc.arrayLayers, "render target image layer too high"); if (layerImageViews.empty()) layerImageViews.resize(desc.arrayLayers); @@ -26,7 +26,7 @@ namespace sp::vulkan::render_graph { return view; } - const ImageViewPtr &PooledImage::MipImageView(uint32 mip) { + const ImageViewPtr &PooledImage::MipImageView(uint32_t mip) { Assert(mip < desc.mipLevels, "render target image layer too high"); if (mipImageViews.empty()) mipImageViews.resize(desc.mipLevels); diff --git a/src/graphics/graphics/vulkan/render_graph/PooledImage.hh b/src/graphics/graphics/vulkan/render_graph/PooledImage.hh index fb0c36f6c..883ed058b 100644 --- a/src/graphics/graphics/vulkan/render_graph/PooledImage.hh +++ b/src/graphics/graphics/vulkan/render_graph/PooledImage.hh @@ -14,8 +14,8 @@ namespace sp::vulkan::render_graph { struct ImageDesc { vk::Extent3D extent; - uint32 mipLevels = 1; - uint32 arrayLayers = 1; + uint32_t mipLevels = 1; + uint32_t arrayLayers = 1; vk::Format format = vk::Format::eUndefined; vk::ImageType imageType = vk::ImageType::e2D; vk::ImageViewType primaryViewType = vk::ImageViewType::e2D; // when e2D, derived from imageType @@ -48,8 +48,8 @@ namespace sp::vulkan::render_graph { return imageView; } - const ImageViewPtr &LayerImageView(uint32 layer); - const ImageViewPtr &MipImageView(uint32 mip); + const ImageViewPtr &LayerImageView(uint32_t layer); + const ImageViewPtr &MipImageView(uint32_t mip); const ImageViewPtr &DepthImageView(); const ImageDesc &Desc() const { diff --git a/src/graphics/graphics/vulkan/render_graph/RenderGraph.cc b/src/graphics/graphics/vulkan/render_graph/RenderGraph.cc index f31c5acfa..e20d735d2 100644 --- a/src/graphics/graphics/vulkan/render_graph/RenderGraph.cc +++ b/src/graphics/graphics/vulkan/render_graph/RenderGraph.cc @@ -78,7 +78,7 @@ namespace sp::vulkan::render_graph { } if (!pendingCmds.empty()) { - device.Submit({(uint32)pendingCmds.size(), pendingCmds.data()}, {}, {}, {}, {}, lastSubmit); + device.Submit({(uint32_t)pendingCmds.size(), pendingCmds.data()}, {}, {}, {}, {}, lastSubmit); pendingCmds.clear(); } }; @@ -92,7 +92,7 @@ namespace sp::vulkan::render_graph { RenderPassInfo renderPassInfo; - for (uint32 i = 0; i < pass.attachments.size(); i++) { + for (uint32_t i = 0; i < pass.attachments.size(); i++) { auto &attachment = pass.attachments[i]; if (attachment.resourceID == InvalidResource) continue; pass.isRenderPass = true; @@ -120,8 +120,8 @@ namespace sp::vulkan::render_graph { } for (int i = std::max(pass.scopes.size(), frameScopeStack.size()) - 1; i >= 0; i--) { - uint8 passScope = i < (int)pass.scopes.size() ? pass.scopes[i] : 255; - uint8 resScope = i < (int)frameScopeStack.size() ? frameScopeStack[i] : 255; + uint8_t passScope = i < (int)pass.scopes.size() ? pass.scopes[i] : 255; + uint8_t resScope = i < (int)frameScopeStack.size() ? frameScopeStack[i] : 255; if (resScope != passScope) { if (resScope != 255) { #ifdef TRACY_ENABLE_GRAPHICS diff --git a/src/graphics/graphics/vulkan/render_graph/RenderGraph.hh b/src/graphics/graphics/vulkan/render_graph/RenderGraph.hh index 110c8362d..51e32f7ee 100644 --- a/src/graphics/graphics/vulkan/render_graph/RenderGraph.hh +++ b/src/graphics/graphics/vulkan/render_graph/RenderGraph.hh @@ -98,7 +98,7 @@ namespace sp::vulkan::render_graph { private: RenderGraph &graph; ResourceName name; - uint32 passIndex = ~0u; + uint32_t passIndex = ~0u; }; class GraphScope { diff --git a/src/graphics/graphics/vulkan/render_graph/Resources.cc b/src/graphics/graphics/vulkan/render_graph/Resources.cc index 16e3fd67e..7f237db8e 100644 --- a/src/graphics/graphics/vulkan/render_graph/Resources.cc +++ b/src/graphics/graphics/vulkan/render_graph/Resources.cc @@ -82,22 +82,22 @@ namespace sp::vulkan::render_graph { return pooledImage->ImageView(); } - ImageViewPtr Resources::GetImageLayerView(string_view name, uint32 layer) { + ImageViewPtr Resources::GetImageLayerView(string_view name, uint32_t layer) { return GetImageLayerView(GetID(name), layer); } - ImageViewPtr Resources::GetImageLayerView(ResourceID id, uint32 layer) { + ImageViewPtr Resources::GetImageLayerView(ResourceID id, uint32_t layer) { if (id >= resources.size()) return nullptr; auto pooledImage = GetPooledImage(id); if (!pooledImage) return nullptr; return pooledImage->LayerImageView(layer); } - ImageViewPtr Resources::GetImageMipView(string_view name, uint32 mip) { + ImageViewPtr Resources::GetImageMipView(string_view name, uint32_t mip) { return GetImageMipView(GetID(name), mip); } - ImageViewPtr Resources::GetImageMipView(ResourceID id, uint32 mip) { + ImageViewPtr Resources::GetImageMipView(ResourceID id, uint32_t mip) { if (id >= resources.size()) return nullptr; auto pooledImage = GetPooledImage(id); if (!pooledImage) return nullptr; @@ -175,7 +175,7 @@ namespace sp::vulkan::render_graph { return invalidResourceName; } - ResourceID Resources::GetID(string_view name, bool assertExists, uint32 framesAgo) const { + ResourceID Resources::GetID(string_view name, bool assertExists, uint32_t framesAgo) const { if (renderThread == std::thread::id()) { renderThread = std::this_thread::get_id(); } else { @@ -183,7 +183,7 @@ namespace sp::vulkan::render_graph { } ResourceID result = InvalidResource; - uint32 getFrameIndex = (frameIndex + RESOURCE_FRAME_COUNT - framesAgo) % RESOURCE_FRAME_COUNT; + uint32_t getFrameIndex = (frameIndex + RESOURCE_FRAME_COUNT - framesAgo) % RESOURCE_FRAME_COUNT; auto lastSep = name.rfind('/'); if (starts_with(name, "/")) { @@ -257,7 +257,7 @@ namespace sp::vulkan::render_graph { return resource.id; } - uint32 Resources::RefCount(ResourceID id) { + uint32_t Resources::RefCount(ResourceID id) { Assert(id < resources.size(), "id out of range"); return refCounts[id]; } @@ -426,7 +426,7 @@ namespace sp::vulkan::render_graph { } Assert(scopeStack.size() < MAX_RESOURCE_SCOPE_DEPTH, "too many nested scopes"); - scopeStack.push_back((uint8)scopeIndex); + scopeStack.push_back((uint8_t)scopeIndex); } void Resources::EndScope() { @@ -436,14 +436,14 @@ namespace sp::vulkan::render_graph { scopeStack.pop_back(); } - ResourceID Resources::Scope::GetID(string_view name, uint32 frameIndex) const { + ResourceID Resources::Scope::GetID(string_view name, uint32_t frameIndex) const { auto &resourceNames = frames[frameIndex].resourceNames; auto it = resourceNames.find(name); if (it != resourceNames.end()) return it->second; return InvalidResource; } - void Resources::Scope::SetID(string_view name, ResourceID id, uint32 frameIndex, bool replace) { + void Resources::Scope::SetID(string_view name, ResourceID id, uint32_t frameIndex, bool replace) { auto &resourceNames = frames[frameIndex].resourceNames; auto &nameID = resourceNames[name.data()]; if (!replace) Assert(!nameID, "resource already registered"); diff --git a/src/graphics/graphics/vulkan/render_graph/Resources.hh b/src/graphics/graphics/vulkan/render_graph/Resources.hh index efd2583f4..8a1388536 100644 --- a/src/graphics/graphics/vulkan/render_graph/Resources.hh +++ b/src/graphics/graphics/vulkan/render_graph/Resources.hh @@ -19,12 +19,12 @@ #include namespace sp::vulkan::render_graph { - typedef uint32 ResourceID; + typedef uint32_t ResourceID; typedef InlineString<127> ResourceName; - const uint32 MAX_RESOURCE_SCOPES = sizeof(uint8); - const uint32 MAX_RESOURCE_SCOPE_DEPTH = 4; - const uint32 RESOURCE_FRAME_COUNT = 2; + const uint32_t MAX_RESOURCE_SCOPES = sizeof(uint8_t); + const uint32_t MAX_RESOURCE_SCOPE_DEPTH = 4; + const uint32_t RESOURCE_FRAME_COUNT = 2; const ResourceID InvalidResource = ~0u; @@ -59,7 +59,7 @@ namespace sp::vulkan::render_graph { return imageDesc.extent; } - uint32 ImageLayers() const { + uint32_t ImageLayers() const { return imageDesc.arrayLayers; } @@ -90,10 +90,10 @@ namespace sp::vulkan::render_graph { ImageViewPtr GetImageView(ResourceID id); ImageViewPtr GetImageView(string_view name); - ImageViewPtr GetImageLayerView(ResourceID id, uint32 layer); - ImageViewPtr GetImageLayerView(string_view name, uint32 layer); - ImageViewPtr GetImageMipView(ResourceID id, uint32 mip); - ImageViewPtr GetImageMipView(string_view name, uint32 mip); + ImageViewPtr GetImageLayerView(ResourceID id, uint32_t layer); + ImageViewPtr GetImageLayerView(string_view name, uint32_t layer); + ImageViewPtr GetImageMipView(ResourceID id, uint32_t mip); + ImageViewPtr GetImageMipView(string_view name, uint32_t mip); ImageViewPtr GetImageDepthView(ResourceID id); ImageViewPtr GetImageDepthView(string_view name); @@ -103,7 +103,7 @@ namespace sp::vulkan::render_graph { const Resource &GetResource(string_view name) const; const Resource &GetResource(ResourceID id) const; const ResourceName &GetName(ResourceID id) const; - ResourceID GetID(string_view name, bool assertExists = true, uint32 framesAgo = 0) const; + ResourceID GetID(string_view name, bool assertExists = true, uint32_t framesAgo = 0) const; ResourceID AddExternalImageView(string_view name, ImageViewPtr view, bool allowReplace = false); @@ -123,7 +123,7 @@ namespace sp::vulkan::render_graph { void ResizeIfNeeded(); - uint32 RefCount(ResourceID id); + uint32_t RefCount(ResourceID id); void IncrementRef(ResourceID id); void DecrementRef(ResourceID id); void AddUsageFromAccess(ResourceID id, Access access); @@ -143,7 +143,7 @@ namespace sp::vulkan::render_graph { } DeviceContext &device; - uint32 frameIndex = 0; + uint32_t frameIndex = 0; mutable std::thread::id renderThread; struct Scope { @@ -155,13 +155,13 @@ namespace sp::vulkan::render_graph { }; std::array frames = {}; - ResourceID GetID(string_view name, uint32 frameIndex) const; - void SetID(string_view name, ResourceID id, uint32 frameIndex, bool replace = false); + ResourceID GetID(string_view name, uint32_t frameIndex) const; + void SetID(string_view name, ResourceID id, uint32_t frameIndex, bool replace = false); void ClearID(ResourceID id); }; vector nameScopes; - InlineVector scopeStack; // refers to indexes in nameScopes + InlineVector scopeStack; // refers to indexes in nameScopes vector resources; vector resourceNames; @@ -169,7 +169,7 @@ namespace sp::vulkan::render_graph { vector externalIDs; size_t lastResourceCount = 0, consecutiveGrowthFrames = 0; - vector refCounts; + vector refCounts; vector images; vector buffers; diff --git a/src/graphics/graphics/vulkan/render_passes/Blur.cc b/src/graphics/graphics/vulkan/render_passes/Blur.cc index 8f9fb38fd..f99b823fc 100644 --- a/src/graphics/graphics/vulkan/render_passes/Blur.cc +++ b/src/graphics/graphics/vulkan/render_passes/Blur.cc @@ -15,7 +15,7 @@ namespace sp::vulkan::renderer { ResourceID AddGaussianBlur1D(RenderGraph &graph, ResourceID sourceID, glm::ivec2 direction, - uint32 downsample, + uint32_t downsample, float scale, float clip) { diff --git a/src/graphics/graphics/vulkan/render_passes/Blur.hh b/src/graphics/graphics/vulkan/render_passes/Blur.hh index 3025a3370..75b8499db 100644 --- a/src/graphics/graphics/vulkan/render_passes/Blur.hh +++ b/src/graphics/graphics/vulkan/render_passes/Blur.hh @@ -13,7 +13,7 @@ namespace sp::vulkan::renderer { ResourceID AddGaussianBlur1D(RenderGraph &graph, ResourceID sourceID, glm::ivec2 direction, - uint32 downsample = 1, + uint32_t downsample = 1, float scale = 1.0f, float clip = FLT_MAX); diff --git a/src/graphics/graphics/vulkan/render_passes/Lighting.cc b/src/graphics/graphics/vulkan/render_passes/Lighting.cc index 99173fa75..90c4489a2 100644 --- a/src/graphics/graphics/vulkan/render_passes/Lighting.cc +++ b/src/graphics/graphics/vulkan/render_passes/Lighting.cc @@ -265,23 +265,24 @@ namespace sp::vulkan::renderer { } void Lighting::AllocateShadowMap() { - uint64 totalPixels = 0; - for (uint32 i = 0; i < lights.size(); i++) { + uint64_t totalPixels = 0; + for (uint32_t i = 0; i < lights.size(); i++) { auto extents = views[i].extents; - auto allocExtents = std::max(CeilToPowerOfTwo((uint32)extents.x), CeilToPowerOfTwo((uint32)extents.y)); + auto allocExtents = std::max(CeilToPowerOfTwo((uint32_t)extents.x), CeilToPowerOfTwo((uint32_t)extents.y)); totalPixels += allocExtents * allocExtents; } - uint32 width = CeilToPowerOfTwo((uint32)ceil(sqrt((double)totalPixels))); + uint32_t width = CeilToPowerOfTwo((uint32_t)ceil(sqrt((double)totalPixels))); shadowAtlasSize = glm::ivec2(width, width); freeRectangles.clear(); freeRectangles.push_back({{0, 0}, {width, width}}); glm::vec4 mapOffsetScale(shadowAtlasSize, shadowAtlasSize); - for (uint32 i = 0; i < lights.size(); i++) { + for (uint32_t i = 0; i < lights.size(); i++) { auto extents = views[i].extents; - auto allocExtents = glm::ivec2(CeilToPowerOfTwo((uint32)extents.x), CeilToPowerOfTwo((uint32)extents.y)); + auto allocExtents = glm::ivec2(CeilToPowerOfTwo((uint32_t)extents.x), + CeilToPowerOfTwo((uint32_t)extents.y)); int rectIndex = -1; for (int r = freeRectangles.size() - 1; r >= 0; r--) { if (glm::all(glm::greaterThanEqual(freeRectangles[r].second, extents))) { @@ -490,7 +491,7 @@ namespace sp::vulkan::renderer { auto visibility = (const std::array *)buffer->Mapped(); for (uint32_t lightIndex = 0; lightIndex < MAX_LIGHTS; lightIndex++) { for (uint32_t opticIndex = 0; opticIndex < MAX_OPTICS; opticIndex++) { - uint32 visible = visibility[lightIndex][opticIndex]; + uint32_t visible = visibility[lightIndex][opticIndex]; if (visible == 1) { Assertf(opticIndex < optics.size(), "Optic index out of range"); } else if (visible != 0) { diff --git a/src/graphics/graphics/vulkan/render_passes/Mipmap.cc b/src/graphics/graphics/vulkan/render_passes/Mipmap.cc index 019ed9d6a..48663d95a 100644 --- a/src/graphics/graphics/vulkan/render_passes/Mipmap.cc +++ b/src/graphics/graphics/vulkan/render_passes/Mipmap.cc @@ -50,11 +50,11 @@ namespace sp::vulkan::renderer { auto baseMipExtent = image->Extent(); - vk::Offset3D currentExtent = {(int32)baseMipExtent.width, - (int32)baseMipExtent.height, - (int32)baseMipExtent.depth}; + vk::Offset3D currentExtent = {(int32_t)baseMipExtent.width, + (int32_t)baseMipExtent.height, + (int32_t)baseMipExtent.depth}; - for (uint32 i = 1; i < image->MipLevels(); i++) { + for (uint32_t i = 1; i < image->MipLevels(); i++) { auto prevMipExtent = currentExtent; currentExtent.x = std::max(currentExtent.x >> 1, 1); currentExtent.y = std::max(currentExtent.y >> 1, 1); diff --git a/src/graphics/graphics/vulkan/render_passes/Screenshots.cc b/src/graphics/graphics/vulkan/render_passes/Screenshots.cc index 87963b8a4..39edaaf2f 100644 --- a/src/graphics/graphics/vulkan/render_passes/Screenshots.cc +++ b/src/graphics/graphics/vulkan/render_passes/Screenshots.cc @@ -87,7 +87,7 @@ namespace sp::vulkan::renderer { outputDesc.arrayLayers = 1; outputDesc.tiling = vk::ImageTiling::eLinear; - uint32 components = FormatComponentCount(view->Format()); + uint32_t components = FormatComponentCount(view->Format()); if (components == 1) { outputDesc.format = vk::Format::eR8Srgb; } else if (components == 2) { @@ -171,11 +171,11 @@ namespace sp::vulkan::renderer { fpng_init = true; } - uint8 *data; + uint8_t *data; outputImage->Map((void **)&data); size_t fpngInputRowPitch = extent.width * components; - std::vector fpngInput(extent.height * fpngInputRowPitch); + std::vector fpngInput(extent.height * fpngInputRowPitch); data += subResourceLayout.offset; for (size_t row = 0; row < extent.height; row++) { diff --git a/src/graphics/graphics/vulkan/render_passes/VisualizeBuffer.cc b/src/graphics/graphics/vulkan/render_passes/VisualizeBuffer.cc index 84f51be27..6acd1c3fa 100644 --- a/src/graphics/graphics/vulkan/render_passes/VisualizeBuffer.cc +++ b/src/graphics/graphics/vulkan/render_passes/VisualizeBuffer.cc @@ -11,9 +11,11 @@ #include "graphics/vulkan/core/DeviceContext.hh" namespace sp::vulkan::renderer { - static CVar CVarWindowViewChannel("r.WindowViewChannel", 0, "A specific channel to view. 0-3 maps to RGBA"); + static CVar CVarWindowViewChannel("r.WindowViewChannel", + 0, + "A specific channel to view. 0-3 maps to RGBA"); - ResourceID VisualizeBuffer(RenderGraph &graph, ResourceID sourceID, uint32 arrayLayer) { + ResourceID VisualizeBuffer(RenderGraph &graph, ResourceID sourceID, uint32_t arrayLayer) { ResourceID outputID; graph.AddPass("VisualizeBuffer") .Build([&](PassBuilder &builder) { @@ -43,10 +45,10 @@ namespace sp::vulkan::renderer { } auto format = source->Format(); - uint32 comp = FormatComponentCount(format); - uint32 swizzle = 0b11000000; // rrra + uint32_t comp = FormatComponentCount(format); + uint32_t swizzle = 0b11000000; // rrra if (comp > 1) { - uint32 channel = CVarWindowViewChannel.Get(); + uint32_t channel = CVarWindowViewChannel.Get(); switch (channel) { case 3: swizzle = 0b11111111; // aaaa diff --git a/src/graphics/graphics/vulkan/render_passes/VisualizeBuffer.hh b/src/graphics/graphics/vulkan/render_passes/VisualizeBuffer.hh index 27e2360f8..9b4b1863f 100644 --- a/src/graphics/graphics/vulkan/render_passes/VisualizeBuffer.hh +++ b/src/graphics/graphics/vulkan/render_passes/VisualizeBuffer.hh @@ -10,5 +10,5 @@ #include "Common.hh" namespace sp::vulkan::renderer { - ResourceID VisualizeBuffer(RenderGraph &graph, ResourceID sourceID, uint32 arrayLayer = ~0u); + ResourceID VisualizeBuffer(RenderGraph &graph, ResourceID sourceID, uint32_t arrayLayer = ~0u); } // namespace sp::vulkan::renderer diff --git a/src/graphics/graphics/vulkan/render_passes/Voxels.cc b/src/graphics/graphics/vulkan/render_passes/Voxels.cc index 877858526..ecd53a376 100644 --- a/src/graphics/graphics/vulkan/render_passes/Voxels.cc +++ b/src/graphics/graphics/vulkan/render_passes/Voxels.cc @@ -32,12 +32,12 @@ namespace sp::vulkan::renderer { static CVar CVarLightLowPass("r.LightLowPass", 0.95, "Blend this amount of light in from the previous frame"); - static CVar CVarVoxelFillIndex("r.VoxelFillIndex", 7, "Voxel layer index to read for light feedback"); + static CVar CVarVoxelFillIndex("r.VoxelFillIndex", 7, "Voxel layer index to read for light feedback"); static CVar CVarReprojectVoxelGrid("r.VoxelReprojectGrid", true, "Account for the voxel grid moving when sampling previous frames"); - static CVar CVarVoxelFragmentBuckets("r.VoxelFragmentBuckets", + static CVar CVarVoxelFragmentBuckets("r.VoxelFragmentBuckets", 9, "The number of fragments that can be written to a voxel."); @@ -202,10 +202,10 @@ namespace sp::vulkan::renderer { fragmentListCount = std::min(MAX_VOXEL_FRAGMENT_LISTS, CVarVoxelFragmentBuckets.Get()); auto voxelFillIndex = std::min(CVarVoxelFillIndex.Get(), voxelLayerCount - 1); - uint32 totalFragmentListSize = 0; + uint32_t totalFragmentListSize = 0; { auto fragmentListSize = (voxelGridSize.x * voxelGridSize.y * voxelGridSize.z) / 2; - for (uint32 i = 0; i < fragmentListCount; i++) { + for (uint32_t i = 0; i < fragmentListCount; i++) { fragmentListSizes[i].capacity = fragmentListSize; fragmentListSizes[i].offset = totalFragmentListSize; totalFragmentListSize += fragmentListSize; @@ -503,7 +503,7 @@ namespace sp::vulkan::renderer { auto map = (const GPUVoxelFragmentList *)buffer->Mapped(); bool printDebug = debugThisFrame.test(); debugThisFrame.clear(); - for (uint32 i = 0; i < listCount; i++) { + for (uint32_t i = 0; i < listCount; i++) { if (printDebug) { Logf("fragment list %d, count: %u, capacity %u", i, map[i].count, map[i].capacity); } diff --git a/src/graphics/graphics/vulkan/render_passes/Voxels.hh b/src/graphics/graphics/vulkan/render_passes/Voxels.hh index 05e7f8b6b..7dc6db0fc 100644 --- a/src/graphics/graphics/vulkan/render_passes/Voxels.hh +++ b/src/graphics/graphics/vulkan/render_passes/Voxels.hh @@ -12,7 +12,7 @@ #include "graphics/vulkan/scene/GPUScene.hh" namespace sp::vulkan::renderer { - static const uint32 MAX_VOXEL_FRAGMENT_LISTS = 16; + static const uint32_t MAX_VOXEL_FRAGMENT_LISTS = 16; class Lighting; @@ -42,10 +42,10 @@ namespace sp::vulkan::renderer { GPUScene &scene; struct FragmentListSize { - uint32 capacity, offset; + uint32_t capacity, offset; }; std::array fragmentListSizes; - uint32 fragmentListCount; + uint32_t fragmentListCount; ecs::Transform voxelToWorld; glm::ivec3 voxelGridSize = glm::ivec3(0); diff --git a/src/graphics/graphics/vulkan/scene/GPUScene.cc b/src/graphics/graphics/vulkan/scene/GPUScene.cc index e31c14f62..e6600b472 100644 --- a/src/graphics/graphics/vulkan/scene/GPUScene.cc +++ b/src/graphics/graphics/vulkan/scene/GPUScene.cc @@ -16,7 +16,7 @@ namespace sp::vulkan { GPUScene::GPUScene(DeviceContext &device) : device(device), textures(device) { - indexBuffer = device.AllocateBuffer({sizeof(uint32), 64 * 1024 * 1024}, + indexBuffer = device.AllocateBuffer({sizeof(uint32_t), 64 * 1024 * 1024}, vk::BufferUsageFlagBits::eIndexBuffer | vk::BufferUsageFlagBits::eTransferDst, VMA_MEMORY_USAGE_GPU_ONLY); @@ -254,7 +254,7 @@ namespace sp::vulkan { GPUScene::DrawBufferIDs GPUScene::GenerateDrawsForView(rg::RenderGraph &graph, ecs::VisibilityMask viewMask, - uint32 instanceCount) { + uint32_t instanceCount) { DrawBufferIDs bufferIDs; graph.AddPass("GenerateDrawsForView") @@ -264,14 +264,14 @@ namespace sp::vulkan { graph.AddPass("Clear") .Build([&](rg::PassBuilder &builder) { auto drawCmds = builder.CreateBuffer( - {sizeof(uint32), sizeof(VkDrawIndexedIndirectCommand), maxDraws}, + {sizeof(uint32_t), sizeof(VkDrawIndexedIndirectCommand), maxDraws}, Residency::GPU_ONLY, Access::TransferWrite); bufferIDs.drawCommandsBuffer = drawCmds.id; }) .Execute([bufferIDs](rg::Resources &resources, CommandContext &cmd) { auto drawBuffer = resources.GetBuffer(bufferIDs.drawCommandsBuffer); - cmd.Raw().fillBuffer(*drawBuffer, 0, sizeof(uint32), 0); + cmd.Raw().fillBuffer(*drawBuffer, 0, sizeof(uint32_t), 0); }); builder.Read("RenderableEntities", Access::ComputeShaderReadStorage); @@ -292,9 +292,9 @@ namespace sp::vulkan { cmd.SetStorageBuffer("DrawParamsList", bufferIDs.drawParamsBuffer); struct { - uint32 renderableCount; - uint32 instanceCount; - uint32 visibilityMask; + uint32_t renderableCount; + uint32_t instanceCount; + uint32_t visibilityMask; } constants; constants.renderableCount = renderableCount; constants.instanceCount = instanceCount; @@ -310,14 +310,14 @@ namespace sp::vulkan { glm::vec3 viewPosition, ecs::VisibilityMask viewMask, bool reverseSort, - uint32 instanceCount) { + uint32_t instanceCount) { DrawBufferIDs bufferIDs; graph.AddPass("GenerateSortedDrawsForView") .Build([&](rg::PassBuilder &builder) { const auto maxDraws = primitiveCountPowerOfTwo; - auto drawCmds = builder.CreateBuffer({sizeof(uint32), sizeof(VkDrawIndexedIndirectCommand), maxDraws}, + auto drawCmds = builder.CreateBuffer({sizeof(uint32_t), sizeof(VkDrawIndexedIndirectCommand), maxDraws}, Residency::CPU_TO_GPU, Access::HostWrite); bufferIDs.drawCommandsBuffer = drawCmds.id; @@ -413,7 +413,7 @@ namespace sp::vulkan { if (drawParamsBuffer) cmd.SetStorageBuffer(1, 0, drawParamsBuffer); cmd.DrawIndexedIndirectCount(drawCommandsBuffer, - sizeof(uint32), + sizeof(uint32_t), drawCommandsBuffer, 0, drawCommandsBuffer->ArraySize()); @@ -427,12 +427,12 @@ namespace sp::vulkan { graph.AddPass("Clear") .Build([&](rg::PassBuilder &builder) { builder.CreateBuffer("WarpedVertexDrawCmds", - {sizeof(uint32), sizeof(VkDrawIndirectCommand), maxDraws}, + {sizeof(uint32_t), sizeof(VkDrawIndirectCommand), maxDraws}, Residency::GPU_ONLY, Access::TransferWrite); }) .Execute([](rg::Resources &resources, CommandContext &cmd) { - cmd.Raw().fillBuffer(*resources.GetBuffer("WarpedVertexDrawCmds"), 0, sizeof(uint32), 0); + cmd.Raw().fillBuffer(*resources.GetBuffer("WarpedVertexDrawCmds"), 0, sizeof(uint32_t), 0); }); builder.Read("RenderableEntities", Access::ComputeShaderReadStorage); @@ -455,7 +455,7 @@ namespace sp::vulkan { cmd.SetStorageBuffer("DrawParamsList", "WarpedVertexDrawParams"); struct { - uint32 renderableCount; + uint32_t renderableCount; } constants; constants.renderableCount = renderableCount; cmd.PushConstants(constants); @@ -490,7 +490,7 @@ namespace sp::vulkan { cmd.SetVertexLayout(SceneVertex::Layout()); cmd.SetPrimitiveTopology(vk::PrimitiveTopology::ePointList); cmd.Raw().bindVertexBuffers(0, {*vertexBuffer}, {0}); - cmd.DrawIndirect(cmdBuffer, sizeof(uint32), primitiveCount); + cmd.DrawIndirect(cmdBuffer, sizeof(uint32_t), primitiveCount); cmd.EndRenderPass(); }); } diff --git a/src/graphics/graphics/vulkan/scene/GPUScene.hh b/src/graphics/graphics/vulkan/scene/GPUScene.hh index 7cd6e481d..86b1fae9c 100644 --- a/src/graphics/graphics/vulkan/scene/GPUScene.hh +++ b/src/graphics/graphics/vulkan/scene/GPUScene.hh @@ -41,21 +41,21 @@ namespace sp::vulkan { static_assert(sizeof(GPUViewState) % 16 == 0, "std140 alignment"); struct GPUMeshPrimitive { - uint32 firstIndex, vertexOffset; - uint32 indexCount, vertexCount; // count of elements in the index/vertex buffers - uint32 jointsVertexOffset; - uint16 baseColorTexID, metallicRoughnessTexID; + uint32_t firstIndex, vertexOffset; + uint32_t indexCount, vertexCount; // count of elements in the index/vertex buffers + uint32_t jointsVertexOffset; + uint16_t baseColorTexID, metallicRoughnessTexID; // other material properties of the primitive can be stored here (or material ID) }; - static_assert(sizeof(GPUMeshPrimitive) % sizeof(uint32) == 0, "std430 alignment"); + static_assert(sizeof(GPUMeshPrimitive) % sizeof(uint32_t) == 0, "std430 alignment"); struct GPUMeshModel { - uint32 primitiveOffset; - uint32 primitiveCount; - uint32 indexOffset; - uint32 vertexOffset; + uint32_t primitiveOffset; + uint32_t primitiveCount; + uint32_t indexOffset; + uint32_t vertexOffset; }; - static_assert(sizeof(GPUMeshModel) % sizeof(uint32) == 0, "std430 alignment"); + static_assert(sizeof(GPUMeshModel) % sizeof(uint32_t) == 0, "std430 alignment"); struct GPURenderableEntity { glm::mat4 modelToWorld; @@ -99,14 +99,14 @@ namespace sp::vulkan { DrawBufferIDs GenerateDrawsForView(rg::RenderGraph &graph, ecs::VisibilityMask viewMask, - uint32 instanceCount = 1); + uint32_t instanceCount = 1); // Sort primitives nearest first by default. DrawBufferIDs GenerateSortedDrawsForView(rg::RenderGraph &graph, glm::vec3 viewPosition, ecs::VisibilityMask viewMask, bool reverseSort = false, - uint32 instanceCount = 1); + uint32_t instanceCount = 1); void DrawSceneIndirect(CommandContext &cmd, BufferPtr vertexBuffer, @@ -131,13 +131,13 @@ namespace sp::vulkan { bool operator==(const OpticInstance &) const = default; }; - uint32 renderableCount = 0; + uint32_t renderableCount = 0; std::vector opticEntities; std::vector jointPoses; - uint32 vertexCount = 0; - uint32 primitiveCount = 0; - uint32 primitiveCountPowerOfTwo = 1; // Always at least 1. Used to size draw command buffers. + uint32_t vertexCount = 0; + uint32_t primitiveCount = 0; + uint32_t primitiveCountPowerOfTwo = 1; // Always at least 1. Used to size draw command buffers. TextureSet textures; robin_hood::unordered_map liveTextureCache; diff --git a/src/graphics/graphics/vulkan/scene/Mesh.cc b/src/graphics/graphics/vulkan/scene/Mesh.cc index e925fa614..15079f664 100644 --- a/src/graphics/graphics/vulkan/scene/Mesh.cc +++ b/src/graphics/graphics/vulkan/scene/Mesh.cc @@ -32,12 +32,12 @@ namespace sp::vulkan { } indexBuffer = scene.indexBuffer->ArrayAllocate(indexCount); - staging.indexBuffer = device.AllocateBuffer({sizeof(uint32), indexCount}, + staging.indexBuffer = device.AllocateBuffer({sizeof(uint32_t), indexCount}, vk::BufferUsageFlagBits::eTransferSrc, VMA_MEMORY_USAGE_CPU_ONLY); Assertf(indexBuffer->ByteSize() == staging.indexBuffer->ByteSize(), "index staging buffer size mismatch"); - auto indexData = (uint32 *)staging.indexBuffer->Mapped(); + auto indexData = (uint32_t *)staging.indexBuffer->Mapped(); auto indexDataStart = indexData; vertexBuffer = scene.vertexBuffer->ArrayAllocate(vertexCount); @@ -157,14 +157,14 @@ namespace sp::vulkan { transfer.emplace_back(staging.modelEntry, modelEntry); // TODO replace with span constructor in vk-hpp v1.2.189 - staging.transferComplete = device.TransferBuffers({(uint32)transfer.size(), transfer.data()}); + staging.transferComplete = device.TransferBuffers({(uint32_t)transfer.size(), transfer.data()}); } Mesh::~Mesh() { Tracef("Destroying Vulkan model %s", modelName); } - uint32 Mesh::SceneIndex() const { + uint32_t Mesh::SceneIndex() const { return modelEntry->ArrayOffset(); } } // namespace sp::vulkan diff --git a/src/graphics/graphics/vulkan/scene/Mesh.hh b/src/graphics/graphics/vulkan/scene/Mesh.hh index 94df89444..7cbc5d2df 100644 --- a/src/graphics/graphics/vulkan/scene/Mesh.hh +++ b/src/graphics/graphics/vulkan/scene/Mesh.hh @@ -39,14 +39,14 @@ namespace sp::vulkan { Mesh(shared_ptr source, size_t meshIndex, GPUScene &scene, DeviceContext &device); ~Mesh(); - uint32 SceneIndex() const; - uint32 PrimitiveCount() const { + uint32_t SceneIndex() const; + uint32_t PrimitiveCount() const { return primitives.size(); } - uint32 IndexCount() const { + uint32_t IndexCount() const { return indexCount; } - uint32 VertexCount() const { + uint32_t VertexCount() const { return vertexCount; } @@ -70,7 +70,7 @@ namespace sp::vulkan { vector primitives; - uint32 vertexCount = 0, indexCount = 0, jointsCount = 0; + uint32_t vertexCount = 0, indexCount = 0, jointsCount = 0; struct { BufferPtr indexBuffer, vertexBuffer, jointsBuffer, primitiveList, modelEntry; AsyncPtr transferComplete; diff --git a/src/graphics/graphics/vulkan/scene/TextureSet.cc b/src/graphics/graphics/vulkan/scene/TextureSet.cc index bac49c5e9..f6c701be3 100644 --- a/src/graphics/graphics/vulkan/scene/TextureSet.cc +++ b/src/graphics/graphics/vulkan/scene/TextureSet.cc @@ -142,9 +142,9 @@ namespace sp::vulkan { if (textureIndex < 0 || (size_t)textureIndex >= gltfModel.textures.size()) { if (factor.size() == 0) factor.push_back(1); // default texture is a single white pixel - auto data = make_shared>(); + auto data = make_shared>(); for (size_t i = 0; i < 4; i++) { - (*data)[i] = uint8(255.0 * factor.at(std::min(factor.size() - 1, i))); + (*data)[i] = uint8_t(255.0 * factor.at(std::min(factor.size() - 1, i))); } // Create a single pixel texture based on the factor data provided @@ -253,7 +253,7 @@ namespace sp::vulkan { descriptorWrite.dstArrayElement = texturesToFlush[queueIndex]; // compact consecutive descriptors into one write - uint32 descriptorCount = 0; + uint32_t descriptorCount = 0; do { descriptorCount++; queueIndex++; @@ -288,7 +288,7 @@ namespace sp::vulkan { } ImageViewPtr TextureSet::CreateSinglePixel(glm::u8vec4 value) { - static_assert(sizeof(value) == sizeof(uint8[4])); + static_assert(sizeof(value) == sizeof(uint8_t[4])); ImageCreateInfo imageInfo; imageInfo.imageType = vk::ImageType::e2D; diff --git a/src/graphics/graphics/vulkan/scene/TextureSet.hh b/src/graphics/graphics/vulkan/scene/TextureSet.hh index 72af86f15..85a23e753 100644 --- a/src/graphics/graphics/vulkan/scene/TextureSet.hh +++ b/src/graphics/graphics/vulkan/scene/TextureSet.hh @@ -18,7 +18,7 @@ #include namespace sp::vulkan { - typedef uint16 TextureIndex; + typedef uint16_t TextureIndex; struct TextureHandle { TextureIndex index = 0; diff --git a/src/physics/cooking/ConvexHull.cc b/src/physics/cooking/ConvexHull.cc index 388713885..6ac8a3079 100644 --- a/src/physics/cooking/ConvexHull.cc +++ b/src/physics/cooking/ConvexHull.cc @@ -106,7 +106,7 @@ namespace sp { params); Assert(res, "building convex decomposition"); - for (uint32 i = 0; i < interfaceVHACD->GetNConvexHulls(); i++) { + for (uint32_t i = 0; i < interfaceVHACD->GetNConvexHulls(); i++) { VHACD::IVHACD::ConvexHull ihull; interfaceVHACD->GetConvexHull(i, ihull); if (ihull.m_points.size() < 3) continue; @@ -193,7 +193,7 @@ namespace sp { } // Increment if the Collision Cache format ever changes - const uint32 hullCacheMagic = 0xc044; + const uint32_t hullCacheMagic = 0xc044; #pragma pack(push, 1) struct hullCacheHeader { diff --git a/src/physics/physx/PhysicsQuerySystem.cc b/src/physics/physx/PhysicsQuerySystem.cc index 8b1f9f7d5..d14216de6 100644 --- a/src/physics/physx/PhysicsQuerySystem.cc +++ b/src/physics/physx/PhysicsQuerySystem.cc @@ -56,7 +56,7 @@ namespace sp { if (arg.maxHits == 1) { hit.maxNbTouches = 0; } else { - hit.maxNbTouches = std::min((uint32)touches.size(), arg.maxHits); + hit.maxNbTouches = std::min((uint32_t)touches.size(), arg.maxHits); } manager.scene->raycast(GlmVec3ToPxVec3(rayStart), diff --git a/src/physics/physx/PhysxManager.cc b/src/physics/physx/PhysxManager.cc index 0e0096979..0084db3c5 100644 --- a/src/physics/physx/PhysxManager.cc +++ b/src/physics/physx/PhysxManager.cc @@ -35,7 +35,7 @@ namespace sp { using namespace physx; CVar CVarPhysxDebugCollision("x.DebugColliders", false, "Show physx colliders"); - static CVar CVarPhysicsFPS("x.PhysicsFPS", 144, "Target frame rate for physics to run"); + static CVar CVarPhysicsFPS("x.PhysicsFPS", 144, "Target frame rate for physics to run"); PhysxManager::PhysxManager(LockFreeEventQueue &windowInputQueue) : RegisteredThread("PhysX", CVarPhysicsFPS.Get(), true), windowInputQueue(windowInputQueue), @@ -922,7 +922,7 @@ namespace sp { InlineVector shapes(nShapes); actor->getShapes(shapes.data(), shapes.size()); - for (uint32 i = 0; i < nShapes; ++i) { + for (uint32_t i = 0; i < nShapes; ++i) { SetCollisionGroup(shapes[i], group); } diff --git a/src/scripts/guis/SignalDisplayGui.cc b/src/scripts/guis/SignalDisplayGui.cc index 1b9b79d5c..7717b3e23 100644 --- a/src/scripts/guis/SignalDisplayGui.cc +++ b/src/scripts/guis/SignalDisplayGui.cc @@ -56,7 +56,7 @@ namespace sp::scripts { fontAtlas->AddFont(&cfg); } - uint8 *fontData; + uint8_t *fontData; int fontWidth, fontHeight; fontAtlas->GetTexDataAsRGBA32(&fontData, &fontWidth, &fontHeight); } diff --git a/src/scripts/scripts/MiscScripts.cc b/src/scripts/scripts/MiscScripts.cc index ec1bb53bb..ce488d8f1 100644 --- a/src/scripts/scripts/MiscScripts.cc +++ b/src/scripts/scripts/MiscScripts.cc @@ -364,13 +364,13 @@ namespace sp::scripts { PhysicsScript physicsSignalFromSignal("physics_signal_from_signal", MetadataSignalFromSignal); struct DebounceSignal { - size_t delayFrames = 1; - size_t delayMs = 0; + uint64_t delayFrames = 1; + uint64_t delayMs = 0; SignalExpression input; std::string output; std::optional lastSignal; - size_t frameCount = 0; + uint64_t frameCount = 0; void OnTick(ScriptState &state, DynamicLock, ReadSignalsLock> lock, @@ -390,7 +390,7 @@ namespace sp::scripts { frameCount = 0; lastSignal = currentInput; } - if (frameCount >= std::max(delayFrames, (size_t)(std::chrono::milliseconds(delayMs) / interval))) { + if (frameCount >= std::max(delayFrames, (uint64_t)(std::chrono::milliseconds(delayMs) / interval))) { ref.SetValue(lock, currentInput); } } diff --git a/src/xr/openvr/OpenVrSystem.cc b/src/xr/openvr/OpenVrSystem.cc index 10daecd91..d26fbc5f3 100644 --- a/src/xr/openvr/OpenVrSystem.cc +++ b/src/xr/openvr/OpenVrSystem.cc @@ -190,8 +190,8 @@ namespace sp::xr { vulkanData.m_nImage = (uint64_t)(VkImage)(**image); vulkanData.m_unArraySize = image->ArrayLayers(); - vulkanData.m_unArrayIndex = (uint32)eye; - vulkanData.m_nFormat = (uint32)image->Format(); + vulkanData.m_unArrayIndex = (uint32_t)eye; + vulkanData.m_nFormat = (uint32_t)image->Format(); vulkanData.m_nWidth = tex->GetWidth(); vulkanData.m_nHeight = tex->GetHeight(); vulkanData.m_nSampleCount = 1; diff --git a/src/xr/openvr/OpenVrSystem.hh b/src/xr/openvr/OpenVrSystem.hh index 51c9b65a0..897bbfe14 100644 --- a/src/xr/openvr/OpenVrSystem.hh +++ b/src/xr/openvr/OpenVrSystem.hh @@ -68,7 +68,7 @@ namespace sp { std::array reservedEntities = {}; std::array trackedDevices = {}; - uint32 frameCountWorkaround = 0; + uint32_t frameCountWorkaround = 0; int texWidth = 0, texHeight = 0; friend class EventHandler; From e1e88879911e19a0ed77876269abc4173762bc11 Mon Sep 17 00:00:00 2001 From: Ricardo Pieper Date: Sun, 8 Feb 2026 12:50:54 -0300 Subject: [PATCH 3/9] DeviceContext + Shader changes. Game actually launches now but does not render much --- src/graphics/graphics/vulkan/core/DeviceContext.cc | 5 ++--- src/graphics/graphics/vulkan/core/Shader.hh | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/graphics/graphics/vulkan/core/DeviceContext.cc b/src/graphics/graphics/vulkan/core/DeviceContext.cc index 04a92ebb6..91bc58c03 100644 --- a/src/graphics/graphics/vulkan/core/DeviceContext.cc +++ b/src/graphics/graphics/vulkan/core/DeviceContext.cc @@ -252,13 +252,12 @@ namespace sp::vulkan { queueInfos.push_back(queueInfo); } - vector enabledDeviceExtensions = { - VK_KHR_MULTIVIEW_EXTENSION_NAME, + vector enabledDeviceExtensions = {VK_KHR_MULTIVIEW_EXTENSION_NAME, // VK_EXT_MEMORY_BUDGET_EXTENSION_NAME, VK_KHR_SHADER_NON_SEMANTIC_INFO_EXTENSION_NAME, VK_EXT_CALIBRATED_TIMESTAMPS_EXTENSION_NAME, VK_EXT_SHADER_VIEWPORT_INDEX_LAYER_EXTENSION_NAME, - }; + "VK_KHR_portability_subset"}; if (enableSwapchain) { enabledDeviceExtensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME); diff --git a/src/graphics/graphics/vulkan/core/Shader.hh b/src/graphics/graphics/vulkan/core/Shader.hh index 58b80db2f..8510472ce 100644 --- a/src/graphics/graphics/vulkan/core/Shader.hh +++ b/src/graphics/graphics/vulkan/core/Shader.hh @@ -21,7 +21,7 @@ namespace sp::vulkan { const uint32_t MAX_BOUND_DESCRIPTOR_SETS = 4; const uint32_t MAX_BINDINGS_PER_DESCRIPTOR_SET = 32; const uint32_t MAX_DESCRIPTOR_SETS_PER_POOL = 16; - const uint32_t MAX_BINDINGS_PER_BINDLESS_DESCRIPTOR_SET = 65535; + const uint32_t MAX_BINDINGS_PER_BINDLESS_DESCRIPTOR_SET = 640; class Model; From af9b3911b1ef63d3ece6fbbb5ced3c01ef068aaf Mon Sep 17 00:00:00 2001 From: Ricardo Pieper Date: Sun, 8 Feb 2026 13:09:03 -0300 Subject: [PATCH 4/9] Device enumeration fix + logs --- src/graphics/graphics/vulkan/core/DeviceContext.cc | 10 +++++++++- src/main/glfw/MainGlfw.cc | 4 +++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/graphics/graphics/vulkan/core/DeviceContext.cc b/src/graphics/graphics/vulkan/core/DeviceContext.cc index 91bc58c03..1c490d904 100644 --- a/src/graphics/graphics/vulkan/core/DeviceContext.cc +++ b/src/graphics/graphics/vulkan/core/DeviceContext.cc @@ -176,13 +176,21 @@ namespace sp::vulkan { } auto physicalDevices = instance.enumeratePhysicalDevices(); + + for (auto &device : physicalDevices) { + auto properties = device.getProperties(); + Logf("Found graphics device: %s %u", properties.deviceName.data(), properties.deviceID); + } + // TODO: Prioritize discrete GPUs and check for capabilities like Geometry/Compute shaders if (physicalDevices.size() > 0) { // TODO: Check device extension support physicalDeviceProperties.pNext = &physicalDeviceDescriptorIndexingProperties; physicalDevices.front().getProperties2(&physicalDeviceProperties); // auto features = device.getFeatures(); - Logf("Using graphics device: %s", physicalDeviceProperties.properties.deviceName.data()); + Logf("Using graphics device: %s %u", + physicalDeviceProperties.properties.deviceName.data(), + physicalDeviceProperties.properties.deviceID); physicalDevice = physicalDevices.front(); } Assert(physicalDevice, "No suitable graphics device found!"); diff --git a/src/main/glfw/MainGlfw.cc b/src/main/glfw/MainGlfw.cc index 9856f43f4..838e944f9 100644 --- a/src/main/glfw/MainGlfw.cc +++ b/src/main/glfw/MainGlfw.cc @@ -207,6 +207,8 @@ int main(int argc, char **argv) { extensions.emplace_back(requiredExtensions[i]); } + extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME); + #ifndef SP_GRAPHICS_SUPPORT_HEADLESS // Create window and surface glm::ivec2 initialSize = glm::ivec2(0); @@ -247,7 +249,7 @@ int main(int argc, char **argv) { createInfo.setPNext((VkDebugUtilsMessengerCreateInfoEXT *)&debugInfo); #endif - + createInfo.flags |= vk::InstanceCreateFlagBits::eEnumeratePortabilityKHR; vk::Instance vkInstance = vk::createInstance(createInfo); sp_graphics_set_vulkan_instance(GameGraphics, vkInstance, [](sp_graphics_ctx_t *graphics, VkInstance instance) { if (instance) ((vk::Instance)instance).destroy(); From 06fee351a5b7020f74a7b98fe50cc60ddb28406f Mon Sep 17 00:00:00 2001 From: Jacob Wirth Date: Mon, 9 Feb 2026 00:05:13 -0800 Subject: [PATCH 5/9] Fix graphics resource free bug --- src/game/game/SceneManager.cc | 3 --- src/graphics/graphics/vulkan/render_graph/PassBuilder.cc | 2 ++ src/graphics/graphics/vulkan/render_graph/Resources.cc | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/game/game/SceneManager.cc b/src/game/game/SceneManager.cc index ad89410ac..c44de6f11 100644 --- a/src/game/game/SceneManager.cc +++ b/src/game/game/SceneManager.cc @@ -12,8 +12,6 @@ #include "assets/JsonHelpers.hh" #include "common/Logging.hh" #include "common/Tracing.hh" -#include "console/Console.hh" -#include "console/ConsoleBindingManager.hh" #include "ecs/EcsImpl.hh" #include "ecs/EntityReferenceManager.hh" #include "ecs/ScriptManager.hh" @@ -23,7 +21,6 @@ #include #include -#include #include #include #include diff --git a/src/graphics/graphics/vulkan/render_graph/PassBuilder.cc b/src/graphics/graphics/vulkan/render_graph/PassBuilder.cc index 9cabab609..8b6d44285 100644 --- a/src/graphics/graphics/vulkan/render_graph/PassBuilder.cc +++ b/src/graphics/graphics/vulkan/render_graph/PassBuilder.cc @@ -7,6 +7,8 @@ #include "PassBuilder.hh" +#include "graphics/vulkan/render_graph/Resources.hh" + namespace sp::vulkan::render_graph { void PassBuilder::Read(ResourceID id, Access access) { pass.AddAccess(id, access); diff --git a/src/graphics/graphics/vulkan/render_graph/Resources.cc b/src/graphics/graphics/vulkan/render_graph/Resources.cc index 7f237db8e..522f9a143 100644 --- a/src/graphics/graphics/vulkan/render_graph/Resources.cc +++ b/src/graphics/graphics/vulkan/render_graph/Resources.cc @@ -455,7 +455,7 @@ namespace sp::vulkan::render_graph { auto it = frame.resourceNames.begin(); while (it != frame.resourceNames.end()) { if (it->second == id) { - frame.resourceNames.erase(it++); + it = frame.resourceNames.erase(it); } else { it++; } From 82455accffff7616811e63808af6c6b966413f42 Mon Sep 17 00:00:00 2001 From: Jacob Wirth Date: Mon, 9 Feb 2026 00:11:20 -0800 Subject: [PATCH 6/9] Add scene reload test --- assets/scripts/tests/scene-reload.txt | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 assets/scripts/tests/scene-reload.txt diff --git a/assets/scripts/tests/scene-reload.txt b/assets/scripts/tests/scene-reload.txt new file mode 100644 index 000000000..74df1358a --- /dev/null +++ b/assets/scripts/tests/scene-reload.txt @@ -0,0 +1,40 @@ +x.PhysicsFPS 120 +g.LogicFPS 120 +loadscene test1 +screenshot reload-before1.png +stepgraphics +steplogic +stepphysics +stepgraphics 120 +screenshot reload-before2.png +stepgraphics +assert_position test1:animbox 0 1.5 -4.875 + +reloadscene +screenshot reload-after1.png +stepgraphics +assert_position test1:animbox 0 1.5 -4.875 +steplogic +stepphysics +stepgraphics + +reloadscene +reloadscene +reloadscene +reloadscene +screenshot reload-after2.png +stepgraphics +assert_position test1:animbox 0 1.5 -4.875 +steplogic 2700 +stepphysics 2 +stepgraphics 120 +screenshot reload-after3.png +stepgraphics +assert_position test1:animbox 0 1.5 -4.875 +stepphysics 120 +assert_position test1:animbox 0 2 -4.875 +stepphysics 120 +assert_position test1:animbox 0 5 -4.875 +stepgraphics 120 +screenshot reload-after4.png +stepgraphics From bf1abc995e9d3c51878cdc96bf540996180551e8 Mon Sep 17 00:00:00 2001 From: Jacob Wirth Date: Mon, 9 Feb 2026 00:23:32 -0800 Subject: [PATCH 7/9] Update missed size_t to uint64_t --- src/core/ecs/EventQueue.cc | 6 +++--- src/core/ecs/EventQueue.hh | 10 +++++----- src/core/ecs/components/Events.hh | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/core/ecs/EventQueue.cc b/src/core/ecs/EventQueue.cc index 902ff141f..7f33747ab 100644 --- a/src/core/ecs/EventQueue.cc +++ b/src/core/ecs/EventQueue.cc @@ -246,13 +246,13 @@ namespace ecs { return true; } - bool EventQueue::Add(const Event &event, size_t transactionId) { + bool EventQueue::Add(const Event &event, uint64_t transactionId) { AsyncEvent asyncEvent(event.name, event.source, event.data); asyncEvent.transactionId = transactionId; return Add(asyncEvent); } - bool EventQueue::Poll(Event &eventOut, size_t transactionId) { + bool EventQueue::Poll(Event &eventOut, uint64_t transactionId) { bool outputSet = false; while (!outputSet) { State s = state.load(); @@ -291,7 +291,7 @@ namespace ecs { return s.head == s.tail; } - size_t EventQueue::Size() { + uint32_t EventQueue::Size() { State s = state.load(); if (s.head > s.tail) { return s.tail + events.size() - s.head; diff --git a/src/core/ecs/EventQueue.hh b/src/core/ecs/EventQueue.hh index b16358fb0..80962cb8c 100644 --- a/src/core/ecs/EventQueue.hh +++ b/src/core/ecs/EventQueue.hh @@ -251,7 +251,7 @@ namespace ecs { Entity source; sp::AsyncPtr data; - size_t transactionId = 0; + uint64_t transactionId = 0; AsyncEvent() {} AsyncEvent(std::string_view name, const Entity &source, const sp::AsyncPtr &data) @@ -280,16 +280,16 @@ namespace ecs { // Returns false if the queue is full bool Add(const AsyncEvent &event); // Returns false if the queue is full - bool Add(const Event &event, size_t transactionId = 0); + bool Add(const Event &event, uint64_t transactionId = 0); // Returns false if the queue is empty - bool Poll(Event &eventOut, size_t transactionId = 0); + bool Poll(Event &eventOut, uint64_t transactionId = 0); bool Empty(); void Clear(); - size_t Size(); + uint32_t Size(); - size_t Capacity() const { + uint32_t Capacity() const { return events.size(); } diff --git a/src/core/ecs/components/Events.hh b/src/core/ecs/components/Events.hh index eb0e3704b..8bf957925 100644 --- a/src/core/ecs/components/Events.hh +++ b/src/core/ecs/components/Events.hh @@ -35,8 +35,8 @@ namespace ecs { * A transactionId can be provided to synchronize event visibility with transactions. * If no transactionId is provided, this event will be immediately visible to all transactions. */ - size_t Add(const Event &event, size_t transactionId = 0) const; - size_t Add(const AsyncEvent &event) const; + uint64_t Add(const Event &event, uint64_t transactionId = 0) const; + uint64_t Add(const AsyncEvent &event) const; static bool Poll(Lock> lock, const EventQueueRef &queue, Event &eventOut); robin_hood::unordered_map, sp::StringHash, sp::StringEqual> events; From 536b435244bc8ee516bee38aecb78d94afdb44f8 Mon Sep 17 00:00:00 2001 From: Jacob Wirth Date: Mon, 9 Feb 2026 01:02:48 -0800 Subject: [PATCH 8/9] Try updating the renderer to not use drawIndirectCount feature --- src/graphics/graphics/vulkan/Renderer.cc | 8 ++-- .../graphics/vulkan/core/CommandContext.cc | 36 +++++++-------- .../graphics/vulkan/core/CommandContext.hh | 24 +++++----- .../graphics/vulkan/core/DeviceContext.cc | 4 +- .../graphics/vulkan/render_passes/Lighting.cc | 6 ++- .../graphics/vulkan/render_passes/Outline.cc | 6 ++- .../vulkan/render_passes/Transparency.cc | 3 +- .../graphics/vulkan/render_passes/Voxels.cc | 3 +- .../graphics/vulkan/scene/GPUScene.cc | 46 +++++++++++++++---- .../graphics/vulkan/scene/GPUScene.hh | 4 +- 10 files changed, 89 insertions(+), 51 deletions(-) diff --git a/src/graphics/graphics/vulkan/Renderer.cc b/src/graphics/graphics/vulkan/Renderer.cc index bda09b135..3ec4a7a3d 100644 --- a/src/graphics/graphics/vulkan/Renderer.cc +++ b/src/graphics/graphics/vulkan/Renderer.cc @@ -294,7 +294,7 @@ namespace sp::vulkan { if (!view) return {}; view.UpdateViewMatrix(lock, ent); - GPUScene::DrawBufferIDs drawIDs; + GPUScene::DrawBufferIDs drawIDs = {}; if (CVarSortedDraw.Get()) { glm::vec3 viewPos = view.invViewMat * glm::vec4(0, 0, 0, 1); drawIDs = scene.GenerateSortedDrawsForView(graph, viewPos, view.visibilityMask, CVarDrawReverseOrder.Get()); @@ -338,7 +338,8 @@ namespace sp::vulkan { scene.DrawSceneIndirect(cmd, resources.GetBuffer("WarpedVertexBuffer"), resources.GetBuffer(drawIDs.drawCommandsBuffer), - resources.GetBuffer(drawIDs.drawParamsBuffer)); + resources.GetBuffer(drawIDs.drawParamsBuffer), + drawIDs.commandCount); }); return view; } @@ -471,7 +472,8 @@ namespace sp::vulkan { scene.DrawSceneIndirect(cmd, resources.GetBuffer("WarpedVertexBuffer"), resources.GetBuffer(drawIDs.drawCommandsBuffer), - resources.GetBuffer(drawIDs.drawParamsBuffer)); + resources.GetBuffer(drawIDs.drawParamsBuffer), + drawIDs.commandCount); GPUViewState *viewState; viewStateBuf->Map((void **)&viewState); diff --git a/src/graphics/graphics/vulkan/core/CommandContext.cc b/src/graphics/graphics/vulkan/core/CommandContext.cc index 9ce45fbe0..407b4aa05 100644 --- a/src/graphics/graphics/vulkan/core/CommandContext.cc +++ b/src/graphics/graphics/vulkan/core/CommandContext.cc @@ -151,15 +151,15 @@ namespace sp::vulkan { cmd->drawIndirect(*drawCommands, offset, drawCount, stride); } - void CommandContext::DrawIndirectCount(BufferPtr drawCommands, - vk::DeviceSize offset, - BufferPtr countBuffer, - vk::DeviceSize countOffset, - uint32_t maxDrawCount, - uint32_t stride) { - FlushGraphicsState(); - cmd->drawIndirectCount(*drawCommands, offset, *countBuffer, countOffset, maxDrawCount, stride); - } + // void CommandContext::DrawIndirectCount(BufferPtr drawCommands, + // vk::DeviceSize offset, + // BufferPtr countBuffer, + // vk::DeviceSize countOffset, + // uint32_t maxDrawCount, + // uint32_t stride) { + // FlushGraphicsState(); + // cmd->drawIndirectCount(*drawCommands, offset, *countBuffer, countOffset, maxDrawCount, stride); + // } void CommandContext::DrawIndexedIndirect(BufferPtr drawCommands, vk::DeviceSize offset, @@ -169,15 +169,15 @@ namespace sp::vulkan { cmd->drawIndexedIndirect(*drawCommands, offset, drawCount, stride); } - void CommandContext::DrawIndexedIndirectCount(BufferPtr drawCommands, - vk::DeviceSize offset, - BufferPtr countBuffer, - vk::DeviceSize countOffset, - uint32_t maxDrawCount, - uint32_t stride) { - FlushGraphicsState(); - cmd->drawIndexedIndirectCount(*drawCommands, offset, *countBuffer, countOffset, maxDrawCount, stride); - } + // void CommandContext::DrawIndexedIndirectCount(BufferPtr drawCommands, + // vk::DeviceSize offset, + // BufferPtr countBuffer, + // vk::DeviceSize countOffset, + // uint32_t maxDrawCount, + // uint32_t stride) { + // FlushGraphicsState(); + // cmd->drawIndexedIndirectCount(*drawCommands, offset, *countBuffer, countOffset, maxDrawCount, stride); + // } void CommandContext::DrawScreenCover(const ImageViewPtr &view) { SetShaders("screen_cover.vert", "screen_cover.frag"); diff --git a/src/graphics/graphics/vulkan/core/CommandContext.hh b/src/graphics/graphics/vulkan/core/CommandContext.hh index 30ca9eee3..24ba5af64 100644 --- a/src/graphics/graphics/vulkan/core/CommandContext.hh +++ b/src/graphics/graphics/vulkan/core/CommandContext.hh @@ -99,22 +99,22 @@ namespace sp::vulkan { vk::DeviceSize offset, uint32_t drawCount, uint32_t stride = sizeof(VkDrawIndirectCommand)); - void DrawIndirectCount(BufferPtr drawCommands, - vk::DeviceSize offset, - BufferPtr countBuffer, - vk::DeviceSize countOffset, - uint32_t maxDrawCount, - uint32_t stride = sizeof(VkDrawIndirectCommand)); + // void DrawIndirectCount(BufferPtr drawCommands, + // vk::DeviceSize offset, + // BufferPtr countBuffer, + // vk::DeviceSize countOffset, + // uint32_t maxDrawCount, + // uint32_t stride = sizeof(VkDrawIndirectCommand)); void DrawIndexedIndirect(BufferPtr drawCommands, vk::DeviceSize offset, uint32_t drawCount, uint32_t stride = sizeof(VkDrawIndexedIndirectCommand)); - void DrawIndexedIndirectCount(BufferPtr drawCommands, - vk::DeviceSize offset, - BufferPtr countBuffer, - vk::DeviceSize countOffset, - uint32_t maxDrawCount, - uint32_t stride = sizeof(VkDrawIndexedIndirectCommand)); + // void DrawIndexedIndirectCount(BufferPtr drawCommands, + // vk::DeviceSize offset, + // BufferPtr countBuffer, + // vk::DeviceSize countOffset, + // uint32_t maxDrawCount, + // uint32_t stride = sizeof(VkDrawIndexedIndirectCommand)); void DrawScreenCover(const ImageViewPtr &view = nullptr); void DrawScreenCover(const color_alpha_t &color); diff --git a/src/graphics/graphics/vulkan/core/DeviceContext.cc b/src/graphics/graphics/vulkan/core/DeviceContext.cc index 93a0865fc..b6e2087e2 100644 --- a/src/graphics/graphics/vulkan/core/DeviceContext.cc +++ b/src/graphics/graphics/vulkan/core/DeviceContext.cc @@ -302,7 +302,7 @@ namespace sp::vulkan { Assert(availableVulkan12Features.shaderOutputViewportIndex, "device must support shaderOutputViewportIndex"); Assert(availableVulkan12Features.shaderOutputLayer, "device must support shaderOutputLayer"); - Assert(availableVulkan12Features.drawIndirectCount, "device must support drawIndirectCount"); + // Assert(availableVulkan12Features.drawIndirectCount, "device must support drawIndirectCount"); Assert(availableVulkan12Features.runtimeDescriptorArray, "device must support runtimeDescriptorArray"); Assert(availableVulkan12Features.descriptorBindingPartiallyBound, "device must support descriptorBindingPartiallyBound"); @@ -316,7 +316,7 @@ namespace sp::vulkan { vk::PhysicalDeviceVulkan12Features enabledVulkan12Features; enabledVulkan12Features.shaderOutputViewportIndex = true; enabledVulkan12Features.shaderOutputLayer = true; - enabledVulkan12Features.drawIndirectCount = true; + // enabledVulkan12Features.drawIndirectCount = true; enabledVulkan12Features.runtimeDescriptorArray = true; enabledVulkan12Features.descriptorBindingPartiallyBound = true; enabledVulkan12Features.descriptorBindingVariableDescriptorCount = true; diff --git a/src/graphics/graphics/vulkan/render_passes/Lighting.cc b/src/graphics/graphics/vulkan/render_passes/Lighting.cc index 90c4489a2..8b29b128c 100644 --- a/src/graphics/graphics/vulkan/render_passes/Lighting.cc +++ b/src/graphics/graphics/vulkan/render_passes/Lighting.cc @@ -436,7 +436,8 @@ namespace sp::vulkan::renderer { scene.DrawSceneIndirect(cmd, resources.GetBuffer("WarpedVertexBuffer"), resources.GetBuffer(drawAllIDs.drawCommandsBuffer), - resources.GetBuffer(drawAllIDs.drawParamsBuffer)); + resources.GetBuffer(drawAllIDs.drawParamsBuffer), + drawAllIDs.commandCount); } }); @@ -478,7 +479,8 @@ namespace sp::vulkan::renderer { scene.DrawSceneIndirect(cmd, resources.GetBuffer("WarpedVertexBuffer"), resources.GetBuffer(drawOpticIDs.drawCommandsBuffer), - resources.GetBuffer(drawOpticIDs.drawParamsBuffer)); + resources.GetBuffer(drawOpticIDs.drawParamsBuffer), + drawOpticIDs.commandCount); } }); diff --git a/src/graphics/graphics/vulkan/render_passes/Outline.cc b/src/graphics/graphics/vulkan/render_passes/Outline.cc index 7bb588c91..acefa72cb 100644 --- a/src/graphics/graphics/vulkan/render_passes/Outline.cc +++ b/src/graphics/graphics/vulkan/render_passes/Outline.cc @@ -42,7 +42,8 @@ namespace sp::vulkan::renderer { scene->DrawSceneIndirect(cmd, resources.GetBuffer("WarpedVertexBuffer"), resources.GetBuffer(drawIDs.drawCommandsBuffer), - resources.GetBuffer(drawIDs.drawParamsBuffer)); + resources.GetBuffer(drawIDs.drawParamsBuffer), + drawIDs.commandCount); }); graph.AddPass("Outlines") @@ -73,7 +74,8 @@ namespace sp::vulkan::renderer { scene->DrawSceneIndirect(cmd, resources.GetBuffer("WarpedVertexBuffer"), resources.GetBuffer(drawIDs.drawCommandsBuffer), - resources.GetBuffer(drawIDs.drawParamsBuffer)); + resources.GetBuffer(drawIDs.drawParamsBuffer), + drawIDs.commandCount); }); } } // namespace sp::vulkan::renderer diff --git a/src/graphics/graphics/vulkan/render_passes/Transparency.cc b/src/graphics/graphics/vulkan/render_passes/Transparency.cc index 9327cf601..1f191fb90 100644 --- a/src/graphics/graphics/vulkan/render_passes/Transparency.cc +++ b/src/graphics/graphics/vulkan/render_passes/Transparency.cc @@ -83,7 +83,8 @@ namespace sp::vulkan::renderer { scene.DrawSceneIndirect(cmd, resources.GetBuffer("WarpedVertexBuffer"), resources.GetBuffer(drawIDs.drawCommandsBuffer), - resources.GetBuffer(drawIDs.drawParamsBuffer)); + resources.GetBuffer(drawIDs.drawParamsBuffer), + drawIDs.commandCount); }); } } // namespace sp::vulkan::renderer diff --git a/src/graphics/graphics/vulkan/render_passes/Voxels.cc b/src/graphics/graphics/vulkan/render_passes/Voxels.cc index ecd53a376..0305cccbb 100644 --- a/src/graphics/graphics/vulkan/render_passes/Voxels.cc +++ b/src/graphics/graphics/vulkan/render_passes/Voxels.cc @@ -395,7 +395,8 @@ namespace sp::vulkan::renderer { scene.DrawSceneIndirect(cmd, resources.GetBuffer("WarpedVertexBuffer"), resources.GetBuffer(drawID.drawCommandsBuffer), - resources.GetBuffer(drawID.drawParamsBuffer)); + resources.GetBuffer(drawID.drawParamsBuffer), + drawID.commandCount); cmd.EndRenderPass(); }); diff --git a/src/graphics/graphics/vulkan/scene/GPUScene.cc b/src/graphics/graphics/vulkan/scene/GPUScene.cc index e6600b472..ae5145b09 100644 --- a/src/graphics/graphics/vulkan/scene/GPUScene.cc +++ b/src/graphics/graphics/vulkan/scene/GPUScene.cc @@ -255,7 +255,7 @@ namespace sp::vulkan { GPUScene::DrawBufferIDs GPUScene::GenerateDrawsForView(rg::RenderGraph &graph, ecs::VisibilityMask viewMask, uint32_t instanceCount) { - DrawBufferIDs bufferIDs; + DrawBufferIDs bufferIDs = {}; graph.AddPass("GenerateDrawsForView") .Build([&](rg::PassBuilder &builder) { @@ -282,6 +282,17 @@ namespace sp::vulkan { Residency::GPU_ONLY, Access::ComputeShaderWrite); bufferIDs.drawParamsBuffer = drawParams.id; + + bufferIDs.commandCount = 0; + for (size_t i = 0; i < renderables.size(); i++) { + auto &renderable = renderables[i]; + if (((ecs::VisibilityMask)renderable.visibilityMask & viewMask) != viewMask) continue; + + auto mesh = meshes[i].lock(); + if (!mesh || !mesh->CheckReady()) continue; + + bufferIDs.commandCount += mesh->PrimitiveCount(); + } }) .Execute([this, viewMask, bufferIDs, instanceCount](rg::Resources &resources, CommandContext &cmd) { cmd.SetComputeShader("generate_draws_for_view.comp"); @@ -311,7 +322,7 @@ namespace sp::vulkan { ecs::VisibilityMask viewMask, bool reverseSort, uint32_t instanceCount) { - DrawBufferIDs bufferIDs; + DrawBufferIDs bufferIDs = {}; graph.AddPass("GenerateSortedDrawsForView") .Build([&](rg::PassBuilder &builder) { @@ -326,6 +337,17 @@ namespace sp::vulkan { Residency::CPU_TO_GPU, Access::HostWrite); bufferIDs.drawParamsBuffer = drawParams.id; + + bufferIDs.commandCount = 0; + for (size_t i = 0; i < renderables.size(); i++) { + auto &renderable = renderables[i]; + if (((ecs::VisibilityMask)renderable.visibilityMask & viewMask) != viewMask) continue; + + auto mesh = meshes[i].lock(); + if (!mesh || !mesh->CheckReady()) continue; + + bufferIDs.commandCount += mesh->PrimitiveCount(); + } }) .Execute([this, viewMask, viewPosition, bufferIDs, instanceCount, reverseSort](rg::Resources &resources, CommandContext &cmd) { @@ -402,8 +424,13 @@ namespace sp::vulkan { void GPUScene::DrawSceneIndirect(CommandContext &cmd, BufferPtr vertexBuffer, BufferPtr drawCommandsBuffer, - BufferPtr drawParamsBuffer) { - if (vertexCount == 0) return; + BufferPtr drawParamsBuffer, + size_t commandCount) { + if (vertexCount == 0 || !drawCommandsBuffer) return; + Assertf(commandCount <= drawCommandsBuffer->ArraySize(), + "GPUScene::DrawSceneIndirect called with too many commands: %llu/%llu", + commandCount, + drawParamsBuffer->ArraySize()); cmd.SetBindlessDescriptors(2, textures.GetDescriptorSet()); @@ -412,11 +439,12 @@ namespace sp::vulkan { cmd.Raw().bindVertexBuffers(0, {*vertexBuffer}, {0}); if (drawParamsBuffer) cmd.SetStorageBuffer(1, 0, drawParamsBuffer); - cmd.DrawIndexedIndirectCount(drawCommandsBuffer, - sizeof(uint32_t), - drawCommandsBuffer, - 0, - drawCommandsBuffer->ArraySize()); + // cmd.DrawIndexedIndirectCount(drawCommandsBuffer, + // sizeof(uint32_t), + // drawCommandsBuffer, + // 0, + // drawCommandsBuffer->ArraySize()); + cmd.DrawIndexedIndirect(drawCommandsBuffer, sizeof(uint32_t), commandCount); } void GPUScene::AddGeometryWarp(rg::RenderGraph &graph) { diff --git a/src/graphics/graphics/vulkan/scene/GPUScene.hh b/src/graphics/graphics/vulkan/scene/GPUScene.hh index 86b1fae9c..f82949c2e 100644 --- a/src/graphics/graphics/vulkan/scene/GPUScene.hh +++ b/src/graphics/graphics/vulkan/scene/GPUScene.hh @@ -95,6 +95,7 @@ namespace sp::vulkan { struct DrawBufferIDs { rg::ResourceID drawCommandsBuffer; // first 4 bytes are the number of draws rg::ResourceID drawParamsBuffer = 0; + size_t commandCount = 0; }; DrawBufferIDs GenerateDrawsForView(rg::RenderGraph &graph, @@ -111,7 +112,8 @@ namespace sp::vulkan { void DrawSceneIndirect(CommandContext &cmd, BufferPtr vertexBuffer, BufferPtr drawCommandsBuffer, - BufferPtr drawParamsBuffer); + BufferPtr drawParamsBuffer, + size_t commandCount); void AddGeometryWarp(rg::RenderGraph &graph); From 0804443f22884ec473acabab9abae1c228145107 Mon Sep 17 00:00:00 2001 From: Jacob Wirth Date: Wed, 11 Feb 2026 18:03:42 -0800 Subject: [PATCH 9/9] Switch fillCounters to a storage buffer, other validation warning fixes --- shaders/lib/voxel_trace_debug.glsl | 3 ++ shaders/vulkan/lib/exposure_state.glsl | 2 +- shaders/vulkan/voxel_debug.frag | 5 +- shaders/vulkan/voxel_fill.frag | 9 +++- shaders/vulkan/voxel_fill_layer.comp | 4 +- shaders/vulkan/voxel_merge.comp | 4 +- shaders/vulkan/voxel_merge_layer.comp | 4 +- shaders/vulkan/voxel_merge_layer_serial.comp | 4 +- shaders/vulkan/voxel_merge_serial.comp | 20 +++++--- .../graphics/vulkan/core/DeviceContext.cc | 23 +++++---- .../graphics/vulkan/render_passes/Blur.cc | 1 + .../graphics/vulkan/render_passes/Voxels.cc | 49 ++++++++++++------- src/scripts/guis/SignalDisplayGui.cc | 6 ++- 13 files changed, 88 insertions(+), 46 deletions(-) diff --git a/shaders/lib/voxel_trace_debug.glsl b/shaders/lib/voxel_trace_debug.glsl index 3b986f8fc..ab9fce9e7 100644 --- a/shaders/lib/voxel_trace_debug.glsl +++ b/shaders/lib/voxel_trace_debug.glsl @@ -12,10 +12,13 @@ float GetVoxelNearest(vec3 position, int level, out vec3 radiance) { // uint count = imageLoad(fillCounters, ivec3(position)).r; + // int fillIndex = int(position.x) * voxelInfo.gridSize.y * voxelInfo.gridSize.z + int(position.y) * voxelInfo.gridSize.z + int(position.z); + // uint count = fillCounters[fillIndex]; vec4 radianceData = texelFetch(voxelRadiance, ivec3(position) >> level, level); vec4 normalData = texelFetch(voxelNormals, ivec3(position) >> level, level); // radiance = vec3(length(normalData.xyz / normalData.w)); radiance = radianceData.rgb; // abs(normalData.xyz); + // radiance = vec3(count); return radianceData.a; } diff --git a/shaders/vulkan/lib/exposure_state.glsl b/shaders/vulkan/lib/exposure_state.glsl index 4f622499f..1a51d7046 100644 --- a/shaders/vulkan/lib/exposure_state.glsl +++ b/shaders/vulkan/lib/exposure_state.glsl @@ -5,6 +5,6 @@ * If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -buffer ExposureState { +readonly buffer ExposureState { float exposure; }; diff --git a/shaders/vulkan/voxel_debug.frag b/shaders/vulkan/voxel_debug.frag index 860547e2c..453ef6731 100644 --- a/shaders/vulkan/voxel_debug.frag +++ b/shaders/vulkan/voxel_debug.frag @@ -27,7 +27,10 @@ INCLUDE_LAYOUT(binding = 2) #include "lib/exposure_state.glsl" layout(binding = 3) uniform sampler2DArray overlayTex; -layout(binding = 4, r32ui) readonly uniform uimage3D fillCounters; +// layout(binding = 4, r32ui) readonly uniform uimage3D fillCounters; +layout(std430, binding = 4) readonly buffer FillCounters { + uint fillCounters[]; +}; layout(binding = 5) uniform sampler3D voxelRadiance; layout(binding = 6) uniform sampler3D voxelNormals; diff --git a/shaders/vulkan/voxel_fill.frag b/shaders/vulkan/voxel_fill.frag index c13ace580..aba470734 100644 --- a/shaders/vulkan/voxel_fill.frag +++ b/shaders/vulkan/voxel_fill.frag @@ -42,7 +42,10 @@ layout(set = 2, binding = 0) uniform sampler2D textures[]; #include "../lib/shading.glsl" -layout(binding = 4, r32ui) uniform uimage3D fillCounters; +// layout(binding = 4, r32ui) uniform uimage3D fillCounters; +layout(std430, binding = 4) buffer FillCounters { + uint fillCounters[]; +}; layout(binding = 5, rgba16f) writeonly uniform image3D radianceOut; layout(binding = 6, rgba16f) writeonly uniform image3D normalsOut; @@ -103,7 +106,9 @@ void main() { pixelRadiance = clamp(pixelRadiance, vec3(-8192), vec3(8192)); } - uint bucket = min(FRAGMENT_LIST_COUNT - 1, imageAtomicAdd(fillCounters, ivec3(inVoxelPos), 1)); + // uint bucket = min(FRAGMENT_LIST_COUNT - 1, imageAtomicAdd(fillCounters, ivec3(inVoxelPos), 1)); + int fillIndex = int(inVoxelPos.x) * voxelInfo.gridSize.y * voxelInfo.gridSize.z + int(inVoxelPos.y) * voxelInfo.gridSize.z + int(inVoxelPos.z); + uint bucket = min(FRAGMENT_LIST_COUNT - 1, atomicAdd(fillCounters[fillIndex], 1)); uint index = atomicAdd(fragmentListMetadata[bucket].count, 1); if (index >= fragmentListMetadata[bucket].capacity) return; if (index % MipmapWorkGroupSize == 0) atomicAdd(fragmentListMetadata[bucket].cmd.x, 1); diff --git a/shaders/vulkan/voxel_fill_layer.comp b/shaders/vulkan/voxel_fill_layer.comp index 30f1947ab..2e4b12bb8 100644 --- a/shaders/vulkan/voxel_fill_layer.comp +++ b/shaders/vulkan/voxel_fill_layer.comp @@ -16,14 +16,14 @@ layout(binding = 0) uniform VoxelStateUniform { VoxelState voxelInfo; }; -layout(std430, binding = 1) buffer VoxelFragmentListMetadata { +layout(std430, binding = 1) readonly buffer VoxelFragmentListMetadata { uint count; uint capacity; uint offset; VkDispatchIndirectCommand cmd; }; -layout(std430, binding = 2) buffer VoxelFragmentList { +layout(std430, binding = 2) readonly buffer VoxelFragmentList { VoxelFragment fragmentLists[]; }; diff --git a/shaders/vulkan/voxel_merge.comp b/shaders/vulkan/voxel_merge.comp index ab9b88528..7ddbde8e4 100644 --- a/shaders/vulkan/voxel_merge.comp +++ b/shaders/vulkan/voxel_merge.comp @@ -14,14 +14,14 @@ layout(local_size_x = 16, local_size_y = 16) in; layout(binding = 0, rgba16f) uniform image3D voxelRadiance; layout(binding = 1, rgba16f) uniform image3D voxelNormals; -layout(std430, binding = 2) buffer VoxelFragmentListMetadata { +layout(std430, binding = 2) readonly buffer VoxelFragmentListMetadata { uint count; uint capacity; uint offset; VkDispatchIndirectCommand cmd; }; -layout(std430, binding = 3) buffer VoxelFragmentList { +layout(std430, binding = 3) readonly buffer VoxelFragmentList { VoxelFragment fragmentLists[]; // Already bound at +offset }; diff --git a/shaders/vulkan/voxel_merge_layer.comp b/shaders/vulkan/voxel_merge_layer.comp index bf114d69a..0573b23e5 100644 --- a/shaders/vulkan/voxel_merge_layer.comp +++ b/shaders/vulkan/voxel_merge_layer.comp @@ -16,14 +16,14 @@ layout(binding = 0) uniform VoxelStateUniform { VoxelState voxelInfo; }; -layout(std430, binding = 1) buffer VoxelFragmentListMetadata { +layout(std430, binding = 1) readonly buffer VoxelFragmentListMetadata { uint count; uint capacity; uint offset; VkDispatchIndirectCommand cmd; }; -layout(std430, binding = 2) buffer VoxelFragmentList { +layout(std430, binding = 2) readonly buffer VoxelFragmentList { VoxelFragment fragmentLists[]; // Already bound at +offset }; diff --git a/shaders/vulkan/voxel_merge_layer_serial.comp b/shaders/vulkan/voxel_merge_layer_serial.comp index 87fee18bf..ca3c862a3 100644 --- a/shaders/vulkan/voxel_merge_layer_serial.comp +++ b/shaders/vulkan/voxel_merge_layer_serial.comp @@ -16,14 +16,14 @@ layout(binding = 0) uniform VoxelStateUniform { VoxelState voxelInfo; }; -layout(std430, binding = 1) buffer VoxelFragmentListMetadata { +layout(std430, binding = 1) readonly buffer VoxelFragmentListMetadata { uint count; uint capacity; uint offset; VkDispatchIndirectCommand cmd; }; -layout(std430, binding = 2) buffer VoxelFragmentList { +layout(std430, binding = 2) readonly buffer VoxelFragmentList { VoxelFragment fragmentLists[]; // Already bound at +offset }; diff --git a/shaders/vulkan/voxel_merge_serial.comp b/shaders/vulkan/voxel_merge_serial.comp index d0941a292..b7138dbc6 100644 --- a/shaders/vulkan/voxel_merge_serial.comp +++ b/shaders/vulkan/voxel_merge_serial.comp @@ -10,26 +10,32 @@ layout(local_size_x = 1, local_size_y = 1) in; #include "../lib/voxel_shared.glsl" +#include "../lib/types_common.glsl" layout(binding = 0, rgba16f) uniform image3D voxelRadiance; layout(binding = 1, rgba16f) uniform image3D voxelNormals; -layout(std430, binding = 2) buffer VoxelFragmentListMetadata { +layout(std430, binding = 2) readonly buffer VoxelFragmentListMetadata { uint count; uint capacity; uint offset; VkDispatchIndirectCommand cmd; }; -layout(std430, binding = 3) buffer VoxelFragmentList { +layout(std430, binding = 3) readonly buffer VoxelFragmentList { VoxelFragment fragmentList[]; }; -layout(binding = 4, r32ui) uniform uimage3D fillCounters; +// layout(binding = 4, r32ui) uniform uimage3D fillCounters; +layout(std430, binding = 4) readonly buffer FillCounters { + uint fillCounters[]; +}; + +layout(binding = 8) uniform VoxelStateUniform { + VoxelState voxelInfo; +}; -#include "../lib/types_common.glsl" #include "../lib/util.glsl" -#include "../lib/voxel_shared.glsl" layout(constant_id = 0) const int FRAGMENT_LIST_COUNT = 1; @@ -41,7 +47,9 @@ void main() { vec4 existingRadiance = imageLoad(voxelRadiance, position); vec4 existingNormal = imageLoad(voxelNormals, position); - uint overflowCount = imageLoad(fillCounters, position).r - FRAGMENT_LIST_COUNT + 1; + // uint overflowCount = imageLoad(fillCounters, position).r - FRAGMENT_LIST_COUNT + 1; + int fillIndex = int(position.x) * voxelInfo.gridSize.y * voxelInfo.gridSize.z + int(position.y) * voxelInfo.gridSize.z + int(position.z); + uint overflowCount = fillCounters[fillIndex] - FRAGMENT_LIST_COUNT + 1; float weight = 1.0f / (FRAGMENT_LIST_COUNT + existingRadiance.w - 1); // isNotLast = true if existingRadiance.w - 1 < overflowCount float isNotLast = 1 - step(overflowCount, existingRadiance.w - 1); diff --git a/src/graphics/graphics/vulkan/core/DeviceContext.cc b/src/graphics/graphics/vulkan/core/DeviceContext.cc index b6e2087e2..bf4f9af4c 100644 --- a/src/graphics/graphics/vulkan/core/DeviceContext.cc +++ b/src/graphics/graphics/vulkan/core/DeviceContext.cc @@ -1092,8 +1092,9 @@ namespace sp::vulkan { auto cmd = device.GetFencedCommandContext(type); auto info = GetAccessInfo(access); cmd->ImageBarrier(image, info.imageLayout, info.stageMask, info.accessMask, transferToQueue); - device.PushInFlightObject(image, cmd->Fence()); - auto transferComplete = image->SetPendingCommand(device.GetEmptySemaphore(cmd->Fence()), + auto fence = cmd->Fence(); + device.PushInFlightObject(image, fence); + auto transferComplete = image->SetPendingCommand(device.GetEmptySemaphore(fence), transferToQueue.dstQueueFamilyIndex); if (waitSemaphore) { device.Submit(cmd, {transferComplete}, {waitSemaphore}, {info.stageMask}); @@ -1171,6 +1172,7 @@ namespace sp::vulkan { transferToCompute.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; } + ImageViewPtr factorView; { GPUZone(this, factorCmd, "ApplyFactor"); @@ -1186,7 +1188,7 @@ namespace sp::vulkan { factorViewInfo.format = factorFormat; factorViewInfo.mipLevelCount = 1; factorViewInfo.usage = vk::ImageUsageFlagBits::eStorage; - auto factorView = CreateImageView(factorViewInfo); + factorView = CreateImageView(factorViewInfo); factorCmd->SetComputeShader("texture_factor.comp"); factorCmd->SetImageView("texture", factorView); @@ -1207,9 +1209,10 @@ namespace sp::vulkan { factorCmd->Dispatch((createInfo.extent.width + 15) / 16, (createInfo.extent.height + 15) / 16, 1); - PushInFlightObject(factorView, factorCmd->Fence()); } - auto factorComplete = image->SetPendingCommand(GetEmptySemaphore(factorCmd->Fence()), + auto fence = factorCmd->Fence(); + PushInFlightObject(factorView, fence); + auto factorComplete = image->SetPendingCommand(GetEmptySemaphore(fence), transferToCompute.dstQueueFamilyIndex); if (waitSemaphore) { Submit(factorCmd, @@ -1273,8 +1276,9 @@ namespace sp::vulkan { vk::ImageLayout::eTransferDstOptimal, {region}); - PushInFlightObject(stagingBuf, transferCmd->Fence()); - auto transferComplete = image->SetPendingCommand(GetEmptySemaphore(transferCmd->Fence()), + auto fence = transferCmd->Fence(); + PushInFlightObject(stagingBuf, fence); + auto transferComplete = image->SetPendingCommand(GetEmptySemaphore(fence), transferToTransferAsync.dstQueueFamilyIndex); { ZoneScopedN("CopyBufferToImage"); @@ -1380,8 +1384,9 @@ namespace sp::vulkan { vk::PipelineStageFlagBits::eFragmentShader, vk::AccessFlagBits::eShaderRead); } - PushInFlightObject(image, graphicsCmd->Fence()); - auto mipmapComplete = image->SetPendingCommand(GetEmptySemaphore(graphicsCmd->Fence()), + auto fence = graphicsCmd->Fence(); + PushInFlightObject(image, fence); + auto mipmapComplete = image->SetPendingCommand(GetEmptySemaphore(fence), transferToGeneral.dstQueueFamilyIndex); if (waitSemaphore) { Submit(graphicsCmd, {mipmapComplete}, {waitSemaphore}, {vk::PipelineStageFlagBits::eTransfer}); diff --git a/src/graphics/graphics/vulkan/render_passes/Blur.cc b/src/graphics/graphics/vulkan/render_passes/Blur.cc index f99b823fc..7c4744a10 100644 --- a/src/graphics/graphics/vulkan/render_passes/Blur.cc +++ b/src/graphics/graphics/vulkan/render_passes/Blur.cc @@ -36,6 +36,7 @@ namespace sp::vulkan::renderer { auto desc = builder.DeriveImage(sourceID); desc.extent.width = std::max(desc.extent.width / downsample, 1u); desc.extent.height = std::max(desc.extent.height / downsample, 1u); + desc.mipLevels = CalculateMipmapLevels(desc.extent); builder.OutputColorAttachment(0, "", desc, {LoadOp::DontCare, StoreOp::Store}); }) .Execute([sourceID, constants](Resources &resources, CommandContext &cmd) { diff --git a/src/graphics/graphics/vulkan/render_passes/Voxels.cc b/src/graphics/graphics/vulkan/render_passes/Voxels.cc index 0305cccbb..6065d6f3c 100644 --- a/src/graphics/graphics/vulkan/render_passes/Voxels.cc +++ b/src/graphics/graphics/vulkan/render_passes/Voxels.cc @@ -219,17 +219,22 @@ namespace sp::vulkan::renderer { desc.extent = voxelGridExtents; desc.primaryViewType = vk::ImageViewType::e3D; desc.imageType = vk::ImageType::e3D; - desc.mipLevels = voxelGridMips; - desc.format = vk::Format::eR32Uint; - builder.CreateImage("FillCounters", desc, clearCounters ? Access::TransferWrite : Access::None); + // desc.format = vk::Format::eR32Uint; + // builder.CreateImage("FillCounters", desc, clearCounters ? Access::TransferWrite : Access::None); + desc.mipLevels = voxelGridMips; desc.sampler = SamplerType::TrilinearClampBorder; desc.format = vk::Format::eR16G16B16A16Sfloat; builder.CreateImage("Radiance", desc, clearRadiance ? Access::TransferWrite : Access::None); // desc.format = vk::Format::eR8G8B8A8Snorm; builder.CreateImage("Normals", desc, clearNormals ? Access::TransferWrite : Access::None); + builder.CreateBuffer("FillCounters", + {sizeof(uint32_t), voxelGridExtents.width * voxelGridExtents.height * voxelGridExtents.depth}, + Residency::GPU_ONLY, + clearCounters ? Access::TransferWrite : Access::None); + builder.CreateBuffer("FragmentListMetadata", {sizeof(GPUVoxelFragmentList), MAX_VOXEL_FRAGMENT_LISTS}, Residency::GPU_ONLY, @@ -240,7 +245,8 @@ namespace sp::vulkan::renderer { Residency::GPU_ONLY, Access::None); }) - .Execute([this, clearRadiance, clearCounters, clearNormals](rg::Resources &resources, CommandContext &cmd) { + .Execute([this, clearRadiance, clearCounters, clearNormals, voxelGridExtents](rg::Resources &resources, + CommandContext &cmd) { if (clearRadiance) { auto radianceView = resources.GetImageView("Radiance"); vk::ClearColorValue clear; @@ -254,16 +260,21 @@ namespace sp::vulkan::renderer { {range}); } if (clearCounters) { - auto counterView = resources.GetImageView("FillCounters"); - vk::ClearColorValue clear; - vk::ImageSubresourceRange range; - range.layerCount = 1; - range.levelCount = counterView->MipLevels(); - range.aspectMask = vk::ImageAspectFlagBits::eColor; - cmd.Raw().clearColorImage(*counterView->Image(), - vk::ImageLayout::eTransferDstOptimal, - clear, - {range}); + // auto counterView = resources.GetImageView("FillCounters"); + // vk::ClearColorValue clear; + // vk::ImageSubresourceRange range; + // range.layerCount = 1; + // range.levelCount = counterView->MipLevels(); + // range.aspectMask = vk::ImageAspectFlagBits::eColor; + // cmd.Raw().clearColorImage(*counterView->Image(), + // vk::ImageLayout::eTransferDstOptimal, + // clear, + // {range}); + auto counterBuffer = resources.GetBuffer("FillCounters"); + cmd.Raw().fillBuffer(*counterBuffer, + 0, + sizeof(uint32_t) * voxelGridExtents.width * voxelGridExtents.height * voxelGridExtents.depth, + 0); } if (clearNormals) { auto normalsView = resources.GetImageView("Normals"); @@ -366,7 +377,8 @@ namespace sp::vulkan::renderer { cmd.SetUniformBuffer("VoxelStateUniform", resources.GetBuffer("VoxelState")); cmd.SetUniformBuffer("LightData", "LightState"); cmd.SetImageView("shadowMap", "ShadowMap/Linear"); - cmd.SetImageView("fillCounters", resources.GetImageMipView("FillCounters", 0)); + // cmd.SetImageView("fillCounters", resources.GetImageMipView("FillCounters", 0)); + cmd.SetStorageBuffer("FillCounters", "FillCounters"); cmd.SetImageView("radianceOut", resources.GetImageMipView("Radiance", 0)); cmd.SetImageView("normalsOut", resources.GetImageMipView("Normals", 0)); cmd.SetStorageBuffer("VoxelFragmentListMetadata", "FragmentListMetadata"); @@ -447,6 +459,7 @@ namespace sp::vulkan::renderer { .Execute([this, i = fragmentListCount - 1](rg::Resources &resources, CommandContext &cmd) { cmd.SetComputeShader("voxel_merge_serial.comp"); cmd.SetShaderConstant(ShaderStage::Compute, "FRAGMENT_LIST_COUNT", fragmentListCount); + cmd.SetUniformBuffer("VoxelStateUniform", resources.GetBuffer("VoxelState")); cmd.SetImageView("voxelRadiance", resources.GetImageMipView("Radiance", 0)); cmd.SetImageView("voxelNormals", resources.GetImageMipView("Normals", 0)); @@ -462,7 +475,8 @@ namespace sp::vulkan::renderer { fragmentListSizes[i].offset * sizeof(GPUVoxelFragment), fragmentListSizes[i].capacity * sizeof(GPUVoxelFragment)); - cmd.SetImageView("fillCounters", resources.GetImageMipView("FillCounters", 0)); + // cmd.SetImageView("fillCounters", resources.GetImageMipView("FillCounters", 0)); + cmd.SetStorageBuffer("FillCounters", "FillCounters"); cmd.Dispatch(1, 1, 1); }); @@ -855,7 +869,8 @@ namespace sp::vulkan::renderer { cmd.SetUniformBuffer("VoxelStateUniform", "VoxelState"); cmd.SetStorageBuffer("ExposureState", "ExposureState"); cmd.SetImageView("overlayTex", resources.LastOutputID()); - cmd.SetImageView("fillCounters", "Voxels/FillCounters"); + // cmd.SetImageView("fillCounters", "Voxels/FillCounters"); + cmd.SetStorageBuffer("FillCounters", "Voxels/FillCounters"); cmd.SetImageView("voxelRadiance", "Voxels/Radiance"); cmd.SetImageView("voxelNormals", "Voxels/Normals"); diff --git a/src/scripts/guis/SignalDisplayGui.cc b/src/scripts/guis/SignalDisplayGui.cc index 7717b3e23..a889c0247 100644 --- a/src/scripts/guis/SignalDisplayGui.cc +++ b/src/scripts/guis/SignalDisplayGui.cc @@ -63,8 +63,10 @@ namespace sp::scripts { void Destroy(ScriptState &state) { Debugf("Destroying signal display: %llu", state.GetInstanceId()); - ImGui::DestroyContext(imCtx); - imCtx = nullptr; + if (imCtx) { + ImGui::DestroyContext(imCtx); + imCtx = nullptr; + } } bool PreDefine(ScriptState &state, Entity ent) {