From 5cab22e20decc7991886ac25137a092cb9148d99 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Sat, 19 Dec 2020 23:24:31 +0100 Subject: [PATCH] Fixes for Vulkan descriptor types iterations --- .../GraphicsDevice/Vulkan/DescriptorSetVulkan.cpp | 12 ++++++------ .../GraphicsDevice/Vulkan/DescriptorSetVulkan.h | 13 ++++++++----- .../Vulkan/GPUPipelineStateVulkan.cpp | 10 +++++----- .../GraphicsDevice/Vulkan/GPUPipelineStateVulkan.h | 2 +- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/Source/Engine/GraphicsDevice/Vulkan/DescriptorSetVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/DescriptorSetVulkan.cpp index 9857e15bf..ea7298ea9 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/DescriptorSetVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/DescriptorSetVulkan.cpp @@ -115,7 +115,7 @@ void DescriptorSetLayoutVulkan::Compile() // Check for maxDescriptorSetStorageBuffersDynamic if (LayoutTypes[VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC] > limits.maxDescriptorSetUniformBuffersDynamic) - { + { // TODO: Downgrade to non-dynamic? } ASSERT(LayoutTypes[VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC] @@ -172,7 +172,7 @@ DescriptorPoolVulkan::DescriptorPoolVulkan(GPUDeviceVulkan* device) , Layout(layout) #endif { - Array> types; + Array> types; #if VULKAN_USE_DESCRIPTOR_POOL_MANAGER // Max number of descriptor sets layout allocations @@ -180,10 +180,10 @@ DescriptorPoolVulkan::DescriptorPoolVulkan(GPUDeviceVulkan* device) // Descriptor sets number required to allocate the max number of descriptor sets layout. // When we're hashing pools with types usage ID the descriptor pool can be used for different layouts so the initial layout does not make much sense. - // In the latter case we'll be probably overallocating the descriptor types but given the relatively small number of max allocations this should not have + // In the latter case we'll be probably over-allocating the descriptor types but given the relatively small number of max allocations this should not have // a serious impact. MaxDescriptorSets = MaxSetsAllocations * (VULKAN_HASH_POOLS_WITH_TYPES_USAGE_ID ? 1 : Layout.GetLayouts().Count()); - for (uint32 typeIndex = VK_DESCRIPTOR_TYPE_SAMPLER; typeIndex < VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT + 1; ++typeIndex) + for (uint32 typeIndex = VULKAN_DESCRIPTOR_TYPE_BEGIN; typeIndex <= VULKAN_DESCRIPTOR_TYPE_END; typeIndex++) { const VkDescriptorType descriptorType = (VkDescriptorType)typeIndex; const uint32 typesUsed = Layout.GetTypesUsed(descriptorType); @@ -258,7 +258,7 @@ DescriptorPoolVulkan::~DescriptorPoolVulkan() void DescriptorPoolVulkan::TrackAddUsage(const DescriptorSetLayoutVulkan& layout) { // Check and increment our current type usage - for (uint32 typeIndex = VK_DESCRIPTOR_TYPE_SAMPLER; typeIndex < VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT + 1; typeIndex++) + for (uint32 typeIndex = VULKAN_DESCRIPTOR_TYPE_BEGIN; typeIndex <= VULKAN_DESCRIPTOR_TYPE_END; typeIndex++) { #if VULKAN_USE_DESCRIPTOR_POOL_MANAGER ASSERT(Layout.GetTypesUsed((VkDescriptorType)typeIndex) == layout.GetTypesUsed((VkDescriptorType)typeIndex)); @@ -275,7 +275,7 @@ void DescriptorPoolVulkan::TrackAddUsage(const DescriptorSetLayoutVulkan& layout void DescriptorPoolVulkan::TrackRemoveUsage(const DescriptorSetLayoutVulkan& layout) { // Check and increment our current type usage - for (uint32 typeIndex = VK_DESCRIPTOR_TYPE_SAMPLER; typeIndex < VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT + 1; typeIndex++) + for (uint32 typeIndex = VULKAN_DESCRIPTOR_TYPE_BEGIN; typeIndex <= VULKAN_DESCRIPTOR_TYPE_END; typeIndex++) { #if VULKAN_USE_DESCRIPTOR_POOL_MANAGER ASSERT(Layout.GetTypesUsed((VkDescriptorType)typeIndex) == layout.GetTypesUsed((VkDescriptorType)typeIndex)); diff --git a/Source/Engine/GraphicsDevice/Vulkan/DescriptorSetVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/DescriptorSetVulkan.h index 848c5cc9b..4f33d88a1 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/DescriptorSetVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/DescriptorSetVulkan.h @@ -15,6 +15,9 @@ #if GRAPHICS_API_VULKAN +#define VULKAN_DESCRIPTOR_TYPE_BEGIN VK_DESCRIPTOR_TYPE_SAMPLER +#define VULKAN_DESCRIPTOR_TYPE_END VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT + class GPUDeviceVulkan; class CmdBufferVulkan; class GPUContextVulkan; @@ -110,7 +113,7 @@ public: protected: - uint32 LayoutTypes[VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT]; + uint32 LayoutTypes[VULKAN_DESCRIPTOR_TYPE_END]; Array SetLayouts; uint32 _hash = 0; @@ -259,9 +262,9 @@ private: #if VULKAN_USE_DESCRIPTOR_POOL_MANAGER const DescriptorSetLayoutVulkan& Layout; #else - int32 MaxAllocatedTypes[VK_DESCRIPTOR_TYPE_RANGE_SIZE]; - int32 NumAllocatedTypes[VK_DESCRIPTOR_TYPE_RANGE_SIZE]; - int32 PeakAllocatedTypes[VK_DESCRIPTOR_TYPE_RANGE_SIZE]; + int32 MaxAllocatedTypes[VULKAN_DESCRIPTOR_TYPE_END]; + int32 NumAllocatedTypes[VULKAN_DESCRIPTOR_TYPE_END]; + int32 PeakAllocatedTypes[VULKAN_DESCRIPTOR_TYPE_END]; #endif public: @@ -291,7 +294,7 @@ public: #if VULKAN_USE_DESCRIPTOR_POOL_MANAGER return MaxDescriptorSets > NumAllocatedDescriptorSets + layout.GetLayouts().Count(); #else - for (uint32 typeIndex = VK_DESCRIPTOR_TYPE_BEGIN_RANGE; typeIndex < VK_DESCRIPTOR_TYPE_END_RANGE; typeIndex++) + for (uint32 typeIndex = VULKAN_DESCRIPTOR_TYPE_BEGIN; typeIndex <= VULKAN_DESCRIPTOR_TYPE_END; typeIndex++) { if (NumAllocatedTypes[typeIndex] + (int32)layout.GetTypesUsed((VkDescriptorType)typeIndex) > MaxAllocatedTypes[typeIndex]) { diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.cpp index fa03e622e..4d527a2bb 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.cpp @@ -286,11 +286,11 @@ bool GPUPipelineStateVulkan::Init(const Description& desc) // Dynamic RenderToolsVulkan::ZeroStruct(_descDynamic, VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO); - _dynamicStates.Push(VK_DYNAMIC_STATE_VIEWPORT); - _dynamicStates.Push(VK_DYNAMIC_STATE_SCISSOR); - _dynamicStates.Push(VK_DYNAMIC_STATE_STENCIL_REFERENCE); - _descDynamic.dynamicStateCount = _dynamicStates.Count(); - _descDynamic.pDynamicStates = _dynamicStates.Get(); + _descDynamic.pDynamicStates = _dynamicStates; + _dynamicStates[_descDynamic.dynamicStateCount++] = VK_DYNAMIC_STATE_VIEWPORT; + _dynamicStates[_descDynamic.dynamicStateCount++] = VK_DYNAMIC_STATE_SCISSOR; + _dynamicStates[_descDynamic.dynamicStateCount++] = VK_DYNAMIC_STATE_STENCIL_REFERENCE; + static_assert(ARRAY_COUNT(_dynamicStates) <= 3, "Invalid dynamic states array."); _desc.pDynamicState = &_descDynamic; // Multisample diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.h index 8e39ac1d8..d1ebabea2 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUPipelineStateVulkan.h @@ -131,7 +131,7 @@ private: VkPipelineTessellationStateCreateInfo _descTessellation; VkPipelineViewportStateCreateInfo _descViewport; VkPipelineDynamicStateCreateInfo _descDynamic; - Array _dynamicStates; + VkDynamicState _dynamicStates[3]; VkPipelineMultisampleStateCreateInfo _descMultisample; VkPipelineDepthStencilStateCreateInfo _descDepthStencil; VkPipelineRasterizationStateCreateInfo _descRasterization;