From a2bb18ddd181a0eb3f9f553eeeba19d032feee9c Mon Sep 17 00:00:00 2001 From: assiduous Date: Sun, 7 Mar 2021 19:25:04 -0800 Subject: Vk backend: reorganized headers; removed PRS methods implemented in PipelineResourceSignatureBase --- Graphics/GraphicsEngineVulkan/CMakeLists.txt | 5 +- .../include/BottomLevelASVkImpl.hpp | 4 +- .../include/BufferViewVkImpl.hpp | 3 +- .../GraphicsEngineVulkan/include/BufferVkImpl.hpp | 6 +- .../include/CommandListVkImpl.hpp | 1 + .../include/CommandQueueVkImpl.hpp | 7 +- .../include/DescriptorPoolManager.hpp | 1 + .../include/DeviceContextVkImpl.hpp | 26 ++- .../GraphicsEngineVulkan/include/FenceVkImpl.hpp | 2 +- .../include/FramebufferCache.hpp | 1 + .../include/FramebufferVkImpl.hpp | 2 +- .../include/GenerateMipsVkHelper.hpp | 1 + .../include/ManagedVulkanObject.hpp | 4 +- .../include/PipelineResourceAttribsVk.hpp | 147 +++++++++++++ .../include/PipelineResourceSignatureVkImpl.hpp | 122 ++--------- .../include/PipelineStateVkImpl.hpp | 9 +- .../GraphicsEngineVulkan/include/QueryVkImpl.hpp | 2 +- .../include/RenderDeviceVkImpl.hpp | 11 +- .../include/RenderPassCache.hpp | 1 + .../GraphicsEngineVulkan/include/SamplerVkImpl.hpp | 3 +- .../include/ShaderBindingTableVkImpl.hpp | 3 +- .../include/ShaderResourceBindingVkImpl.hpp | 7 +- .../include/ShaderResourceCacheVk.hpp | 2 +- .../include/ShaderVariableManagerVk.hpp | 210 ++++++++++++++++++ .../include/ShaderVariableVk.hpp | 221 ------------------- .../GraphicsEngineVulkan/include/ShaderVkImpl.hpp | 3 +- .../include/SwapChainVkImpl.hpp | 1 + .../include/TextureViewVkImpl.hpp | 3 +- .../GraphicsEngineVulkan/include/TextureVkImpl.hpp | 3 +- .../include/TopLevelASVkImpl.hpp | 3 +- .../src/BottomLevelASVkImpl.cpp | 1 + .../src/CommandQueueVkImpl.cpp | 6 +- .../src/DeviceContextVkImpl.cpp | 6 +- Graphics/GraphicsEngineVulkan/src/FenceVkImpl.cpp | 2 +- .../GraphicsEngineVulkan/src/FramebufferCache.cpp | 2 +- .../GraphicsEngineVulkan/src/FramebufferVkImpl.cpp | 7 +- .../src/GenerateMipsVkHelper.cpp | 6 +- .../GraphicsEngineVulkan/src/PipelineLayoutVk.cpp | 6 +- .../src/PipelineResourceSignatureVkImpl.cpp | 34 +-- .../src/PipelineStateVkImpl.cpp | 9 +- .../GraphicsEngineVulkan/src/QueryManagerVk.cpp | 5 +- Graphics/GraphicsEngineVulkan/src/QueryVkImpl.cpp | 2 +- .../src/RenderDeviceVkImpl.cpp | 5 +- .../GraphicsEngineVulkan/src/RenderPassCache.cpp | 5 +- .../src/ShaderBindingTableVkImpl.cpp | 2 + .../src/ShaderResourceBindingVkImpl.cpp | 2 +- .../src/ShaderResourceCacheVk.cpp | 2 + .../src/ShaderVariableManagerVk.cpp | 237 +++++++++++++++++++++ .../GraphicsEngineVulkan/src/ShaderVariableVk.cpp | 214 ------------------- Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp | 6 +- .../GraphicsEngineVulkan/src/SwapChainVkImpl.cpp | 2 +- .../GraphicsEngineVulkan/src/TextureViewVkImpl.cpp | 2 +- .../GraphicsEngineVulkan/src/TextureVkImpl.cpp | 1 - .../GraphicsEngineVulkan/src/TopLevelASVkImpl.cpp | 1 + .../GraphicsEngineVulkan/src/VulkanDynamicHeap.cpp | 5 +- .../src/VulkanTypeConversions.cpp | 4 +- 56 files changed, 735 insertions(+), 653 deletions(-) create mode 100644 Graphics/GraphicsEngineVulkan/include/PipelineResourceAttribsVk.hpp create mode 100644 Graphics/GraphicsEngineVulkan/include/ShaderVariableManagerVk.hpp delete mode 100644 Graphics/GraphicsEngineVulkan/include/ShaderVariableVk.hpp create mode 100644 Graphics/GraphicsEngineVulkan/src/ShaderVariableManagerVk.cpp delete mode 100644 Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/CMakeLists.txt b/Graphics/GraphicsEngineVulkan/CMakeLists.txt index 61fe931e..a0a921d6 100644 --- a/Graphics/GraphicsEngineVulkan/CMakeLists.txt +++ b/Graphics/GraphicsEngineVulkan/CMakeLists.txt @@ -29,7 +29,7 @@ set(INCLUDE include/ManagedVulkanObject.hpp include/ShaderResourceBindingVkImpl.hpp include/ShaderResourceCacheVk.hpp - include/ShaderVariableVk.hpp + include/ShaderVariableManagerVk.hpp include/SwapChainVkImpl.hpp include/TextureVkImpl.hpp include/TextureViewVkImpl.hpp @@ -40,6 +40,7 @@ set(INCLUDE include/TopLevelASVkImpl.hpp include/ShaderBindingTableVkImpl.hpp include/PipelineResourceSignatureVkImpl.hpp + include/PipelineResourceAttribsVk.hpp ) set(VULKAN_UTILS_INCLUDE @@ -104,7 +105,7 @@ set(SRC src/ShaderVkImpl.cpp src/ShaderResourceBindingVkImpl.cpp src/ShaderResourceCacheVk.cpp - src/ShaderVariableVk.cpp + src/ShaderVariableManagerVk.cpp src/SwapChainVkImpl.cpp src/TextureVkImpl.cpp src/TextureViewVkImpl.cpp diff --git a/Graphics/GraphicsEngineVulkan/include/BottomLevelASVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/BottomLevelASVkImpl.hpp index 469aef6d..3f421920 100644 --- a/Graphics/GraphicsEngineVulkan/include/BottomLevelASVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/BottomLevelASVkImpl.hpp @@ -30,11 +30,11 @@ /// \file /// Definition of the Diligent::BottomLevelASVkImpl class -#include "RenderDeviceVk.h" -#include "RenderDeviceVkImpl.hpp" +#include "EngineVkImplTraits.hpp" #include "BottomLevelASVk.h" #include "BottomLevelASBase.hpp" #include "VulkanUtilities/VulkanObjectWrappers.hpp" +#include "VulkanUtilities/VulkanMemoryManager.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineVulkan/include/BufferViewVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/BufferViewVkImpl.hpp index 15091572..09d4b6dc 100644 --- a/Graphics/GraphicsEngineVulkan/include/BufferViewVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/BufferViewVkImpl.hpp @@ -30,11 +30,10 @@ /// \file /// Declaration of Diligent::BufferViewVkImpl class +#include "EngineVkImplTraits.hpp" #include "BufferViewVk.h" -#include "RenderDeviceVk.h" #include "BufferViewBase.hpp" #include "VulkanUtilities/VulkanObjectWrappers.hpp" -#include "RenderDeviceVkImpl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineVulkan/include/BufferVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/BufferVkImpl.hpp index caffa62f..2144fafc 100644 --- a/Graphics/GraphicsEngineVulkan/include/BufferVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/BufferVkImpl.hpp @@ -30,15 +30,15 @@ /// \file /// Declaration of Diligent::BufferVkImpl class +#include "EngineVkImplTraits.hpp" #include "BufferVk.h" -#include "RenderDeviceVk.h" #include "BufferBase.hpp" -#include "BufferViewVkImpl.hpp" +#include "BufferViewVkImpl.hpp" // Required by BufferBase + #include "VulkanDynamicHeap.hpp" #include "VulkanUtilities/VulkanObjectWrappers.hpp" #include "VulkanUtilities/VulkanMemoryManager.hpp" #include "STDAllocator.hpp" -#include "RenderDeviceVkImpl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineVulkan/include/CommandListVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/CommandListVkImpl.hpp index 63707812..2fff7842 100644 --- a/Graphics/GraphicsEngineVulkan/include/CommandListVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/CommandListVkImpl.hpp @@ -30,6 +30,7 @@ /// \file /// Declaration of Diligent::CommandListVkImpl class +#include "EngineVkImplTraits.hpp" #include "VulkanUtilities/VulkanHeaders.h" #include "CommandListBase.hpp" #include "RenderDeviceVkImpl.hpp" diff --git a/Graphics/GraphicsEngineVulkan/include/CommandQueueVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/CommandQueueVkImpl.hpp index cc1f7e3d..a9a61dee 100644 --- a/Graphics/GraphicsEngineVulkan/include/CommandQueueVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/CommandQueueVkImpl.hpp @@ -34,12 +34,15 @@ #include #include -#include "VulkanUtilities/VulkanHeaders.h" +#include "EngineVkImplTraits.hpp" #include "CommandQueueVk.h" #include "ObjectBase.hpp" -#include "VulkanUtilities/VulkanLogicalDevice.hpp" #include "FenceVkImpl.hpp" +#include "VulkanUtilities/VulkanHeaders.h" +#include "VulkanUtilities/VulkanLogicalDevice.hpp" + + namespace Diligent { diff --git a/Graphics/GraphicsEngineVulkan/include/DescriptorPoolManager.hpp b/Graphics/GraphicsEngineVulkan/include/DescriptorPoolManager.hpp index ae77ccaa..54fbe0ed 100644 --- a/Graphics/GraphicsEngineVulkan/include/DescriptorPoolManager.hpp +++ b/Graphics/GraphicsEngineVulkan/include/DescriptorPoolManager.hpp @@ -34,6 +34,7 @@ #include #include #include + #include "VulkanUtilities/VulkanObjectWrappers.hpp" namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp index ff0e27de..ed2adf11 100644 --- a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp @@ -33,30 +33,34 @@ #include #include +#include "EngineVkImplTraits.hpp" + #include "DeviceContextVk.h" #include "DeviceContextNextGenBase.hpp" -#include "VulkanUtilities/VulkanCommandBufferPool.hpp" -#include "VulkanUtilities/VulkanCommandBuffer.hpp" -#include "VulkanUploadHeap.hpp" -#include "VulkanDynamicHeap.hpp" -#include "ResourceReleaseQueue.hpp" -#include "DescriptorPoolManager.hpp" -#include "PipelineLayoutVk.hpp" -#include "GenerateMipsVkHelper.hpp" + +// Vk object implementations are required by DeviceContextBase #include "BufferVkImpl.hpp" #include "TextureVkImpl.hpp" #include "PipelineStateVkImpl.hpp" #include "QueryVkImpl.hpp" #include "FramebufferVkImpl.hpp" #include "RenderPassVkImpl.hpp" -#include "HashUtils.hpp" -#include "ManagedVulkanObject.hpp" -#include "QueryManagerVk.hpp" #include "BottomLevelASVkImpl.hpp" #include "TopLevelASVkImpl.hpp" #include "ShaderBindingTableVkImpl.hpp" #include "ShaderResourceBindingVkImpl.hpp" +#include "GenerateMipsVkHelper.hpp" +#include "PipelineLayoutVk.hpp" +#include "VulkanUtilities/VulkanCommandBufferPool.hpp" +#include "VulkanUtilities/VulkanCommandBuffer.hpp" +#include "VulkanUploadHeap.hpp" +#include "VulkanDynamicHeap.hpp" +#include "ResourceReleaseQueue.hpp" +#include "DescriptorPoolManager.hpp" +#include "HashUtils.hpp" +#include "ManagedVulkanObject.hpp" +#include "QueryManagerVk.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineVulkan/include/FenceVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/FenceVkImpl.hpp index a3a81edc..b720d604 100644 --- a/Graphics/GraphicsEngineVulkan/include/FenceVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/FenceVkImpl.hpp @@ -33,10 +33,10 @@ #include #include +#include "EngineVkImplTraits.hpp" #include "FenceVk.h" #include "FenceBase.hpp" #include "VulkanUtilities/VulkanFencePool.hpp" -#include "RenderDeviceVkImpl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineVulkan/include/FramebufferCache.hpp b/Graphics/GraphicsEngineVulkan/include/FramebufferCache.hpp index 2a26bf51..28f55b67 100644 --- a/Graphics/GraphicsEngineVulkan/include/FramebufferCache.hpp +++ b/Graphics/GraphicsEngineVulkan/include/FramebufferCache.hpp @@ -32,6 +32,7 @@ #include #include + #include "VulkanUtilities/VulkanObjectWrappers.hpp" namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/include/FramebufferVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/FramebufferVkImpl.hpp index 6877fd3d..19d4fd2a 100644 --- a/Graphics/GraphicsEngineVulkan/include/FramebufferVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/FramebufferVkImpl.hpp @@ -30,9 +30,9 @@ /// \file /// Declaration of Diligent::FramebufferVkImpl class +#include "EngineVkImplTraits.hpp" #include "FramebufferVk.h" #include "FramebufferBase.hpp" -#include "RenderDeviceVkImpl.hpp" #include "VulkanUtilities/VulkanObjectWrappers.hpp" namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/include/GenerateMipsVkHelper.hpp b/Graphics/GraphicsEngineVulkan/include/GenerateMipsVkHelper.hpp index 80a75309..fbc0ef4c 100644 --- a/Graphics/GraphicsEngineVulkan/include/GenerateMipsVkHelper.hpp +++ b/Graphics/GraphicsEngineVulkan/include/GenerateMipsVkHelper.hpp @@ -32,6 +32,7 @@ #include #include + #include "VulkanUtilities/VulkanLogicalDevice.hpp" #include "VulkanUtilities/VulkanCommandBuffer.hpp" diff --git a/Graphics/GraphicsEngineVulkan/include/ManagedVulkanObject.hpp b/Graphics/GraphicsEngineVulkan/include/ManagedVulkanObject.hpp index b1e38a61..18f1cf65 100644 --- a/Graphics/GraphicsEngineVulkan/include/ManagedVulkanObject.hpp +++ b/Graphics/GraphicsEngineVulkan/include/ManagedVulkanObject.hpp @@ -28,12 +28,14 @@ #pragma once #include "DeviceObjectBase.hpp" -#include "RenderDeviceVkImpl.hpp" #include "VulkanUtilities/VulkanLogicalDevice.hpp" +#include "RenderDeviceVkImpl.hpp" // Required by by ~ManagedVulkanObject() namespace Diligent { +class RenderDeviceVkImpl; + template class ManagedVulkanObject : public DeviceObjectBase { diff --git a/Graphics/GraphicsEngineVulkan/include/PipelineResourceAttribsVk.hpp b/Graphics/GraphicsEngineVulkan/include/PipelineResourceAttribsVk.hpp new file mode 100644 index 00000000..a597cb54 --- /dev/null +++ b/Graphics/GraphicsEngineVulkan/include/PipelineResourceAttribsVk.hpp @@ -0,0 +1,147 @@ +/* + * Copyright 2019-2021 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Declaration of Diligent::PipelineResourceSignatureVkImpl struct + +#include "BasicTypes.h" +#include "ShaderResourceCacheCommon.hpp" +#include "PrivateConstants.h" +#include "DebugUtilities.hpp" + +namespace Diligent +{ + +enum class DescriptorType : Uint8 +{ + Sampler, + CombinedImageSampler, + SeparateImage, + StorageImage, + UniformTexelBuffer, + StorageTexelBuffer, + StorageTexelBuffer_ReadOnly, + UniformBuffer, + UniformBufferDynamic, + StorageBuffer, + StorageBuffer_ReadOnly, + StorageBufferDynamic, + StorageBufferDynamic_ReadOnly, + InputAttachment, + AccelerationStructure, + Count, + Unknown = 0xFF, +}; + + +// sizeof(PipelineResourceAttribsVk) == 16, x64 +struct PipelineResourceAttribsVk +{ +private: + static constexpr Uint32 _BindingIndexBits = 16; + static constexpr Uint32 _SamplerIndBits = 16; + static constexpr Uint32 _ArraySizeBits = 26; + static constexpr Uint32 _DescrTypeBits = 4; + static constexpr Uint32 _DescrSetBits = 1; + static constexpr Uint32 _SamplerAssignedBits = 1; + + static_assert((_BindingIndexBits + _ArraySizeBits + _SamplerIndBits + _DescrTypeBits + _DescrSetBits + _SamplerAssignedBits) % 32 == 0, "Bits are not optimally packed"); + + // clang-format off + static_assert((1u << _DescrTypeBits) >= static_cast(DescriptorType::Count), "Not enough bits to store DescriptorType values"); + static_assert((1u << _BindingIndexBits) >= MAX_RESOURCES_IN_SIGNATURE, "Not enough bits to store resource binding index"); + static_assert((1u << _SamplerIndBits) >= MAX_RESOURCES_IN_SIGNATURE, "Not enough bits to store sampler resource index"); + // clang-format on + +public: + static constexpr Uint32 MaxDescriptorSets = (1u << _DescrSetBits); + static constexpr Uint32 InvalidSamplerInd = (1u << _SamplerIndBits) - 1; + + // clang-format off + const Uint32 BindingIndex : _BindingIndexBits; // Binding in the descriptor set + const Uint32 SamplerInd : _SamplerIndBits; // Index of the assigned sampler in m_Desc.Resources and m_pPipelineResourceAttribsVk + const Uint32 ArraySize : _ArraySizeBits; // Array size + const Uint32 DescrType : _DescrTypeBits; // Descriptor type (DescriptorType) + const Uint32 DescrSet : _DescrSetBits; // Descriptor set (0 or 1) + const Uint32 ImtblSamplerAssigned : _SamplerAssignedBits; // Immutable sampler flag + + const Uint32 SRBCacheOffset; // Offset in the SRB resource cache + const Uint32 StaticCacheOffset; // Offset in the static resource cache + // clang-format on + + PipelineResourceAttribsVk(Uint32 _BindingIndex, + Uint32 _SamplerInd, + Uint32 _ArraySize, + DescriptorType _DescrType, + Uint32 _DescrSet, + bool _ImtblSamplerAssigned, + Uint32 _SRBCacheOffset, + Uint32 _StaticCacheOffset) noexcept : + // clang-format off + BindingIndex {_BindingIndex }, + SamplerInd {_SamplerInd }, + ArraySize {_ArraySize }, + DescrType {static_cast(_DescrType)}, + DescrSet {_DescrSet }, + ImtblSamplerAssigned {_ImtblSamplerAssigned ? 1u : 0u}, + SRBCacheOffset {_SRBCacheOffset }, + StaticCacheOffset {_StaticCacheOffset } + // clang-format on + { + // clang-format off + VERIFY(BindingIndex == _BindingIndex, "Binding index (", _BindingIndex, ") exceeds maximum representable value"); + VERIFY(ArraySize == _ArraySize, "Array size (", _ArraySize, ") exceeds maximum representable value"); + VERIFY(SamplerInd == _SamplerInd, "Sampler index (", _SamplerInd, ") exceeds maximum representable value"); + VERIFY(GetDescriptorType() == _DescrType, "Descriptor type (", static_cast(_DescrType), ") exceeds maximum representable value"); + VERIFY(DescrSet == _DescrSet, "Descriptor set (", _DescrSet, ") exceeds maximum representable value"); + // clang-format on + } + + Uint32 CacheOffset(ResourceCacheContentType CacheType) const + { + return CacheType == ResourceCacheContentType::SRB ? SRBCacheOffset : StaticCacheOffset; + } + + DescriptorType GetDescriptorType() const + { + return static_cast(DescrType); + } + + bool IsImmutableSamplerAssigned() const + { + return ImtblSamplerAssigned != 0; + } + + bool IsCombinedWithSampler() const + { + return SamplerInd != InvalidSamplerInd; + } +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/include/PipelineResourceSignatureVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/PipelineResourceSignatureVkImpl.hpp index a1513c03..d41c4c5e 100644 --- a/Graphics/GraphicsEngineVulkan/include/PipelineResourceSignatureVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/PipelineResourceSignatureVkImpl.hpp @@ -34,45 +34,32 @@ #include "EngineVkImplTraits.hpp" #include "PipelineResourceSignatureBase.hpp" + +// ShaderVariableManagerVk, ShaderResourceCacheVk, and ShaderResourceBindingVkImpl +// are required by PipelineResourceSignatureBase +#include "ShaderResourceCacheVk.hpp" +#include "ShaderVariableManagerVk.hpp" +#include "ShaderResourceBindingVkImpl.hpp" + +#include "PipelineResourceAttribsVk.hpp" #include "VulkanUtilities/VulkanObjectWrappers.hpp" #include "SRBMemoryAllocator.hpp" -#include "ShaderResourceCacheCommon.hpp" namespace Diligent { class RenderDeviceVkImpl; -class ShaderResourceCacheVk; class ShaderVariableManagerVk; struct SPIRVShaderResourceAttribs; -enum class DescriptorType : Uint8 -{ - Sampler, - CombinedImageSampler, - SeparateImage, - StorageImage, - UniformTexelBuffer, - StorageTexelBuffer, - StorageTexelBuffer_ReadOnly, - UniformBuffer, - UniformBufferDynamic, - StorageBuffer, - StorageBuffer_ReadOnly, - StorageBufferDynamic, - StorageBufferDynamic_ReadOnly, - InputAttachment, - AccelerationStructure, - Count, - Unknown = 0xFF, -}; - /// Implementation of the Diligent::PipelineResourceSignatureVkImpl class class PipelineResourceSignatureVkImpl final : public PipelineResourceSignatureBase { public: using TPipelineResourceSignatureBase = PipelineResourceSignatureBase; + using ResourceAttribs = PipelineResourceAttribsVk; + // Descriptor set identifier (this is not the descriptor set index in the set layout!) enum DESCRIPTOR_SET_ID : size_t { @@ -88,6 +75,8 @@ public: // Static/mutable and dynamic descriptor sets static constexpr Uint32 MAX_DESCRIPTOR_SETS = DESCRIPTOR_SET_ID_NUM_SETS; + static_assert(ResourceAttribs::MaxDescriptorSets >= MAX_DESCRIPTOR_SETS, "Not enough bits to store descriptor set index"); + PipelineResourceSignatureVkImpl(IReferenceCounters* pRefCounters, RenderDeviceVkImpl* pDevice, const PipelineResourceSignatureDesc& Desc, @@ -103,75 +92,6 @@ public: return (HasDescriptorSet(DESCRIPTOR_SET_ID_STATIC_MUTABLE) ? 1 : 0) + (HasDescriptorSet(DESCRIPTOR_SET_ID_DYNAMIC) ? 1 : 0); } - // sizeof(ResourceAttribs) == 16, x64 - struct ResourceAttribs - { - private: - static constexpr Uint32 _BindingIndexBits = 16; - static constexpr Uint32 _SamplerIndBits = 16; - static constexpr Uint32 _ArraySizeBits = 26; - static constexpr Uint32 _DescrTypeBits = 4; - static constexpr Uint32 _DescrSetBits = 1; - static constexpr Uint32 _SamplerAssignedBits = 1; - - static_assert((_BindingIndexBits + _ArraySizeBits + _SamplerIndBits + _DescrTypeBits + _DescrSetBits + _SamplerAssignedBits) % 32 == 0, "Bits are not optimally packed"); - - static_assert((1u << _DescrTypeBits) >= static_cast(DescriptorType::Count), "Not enough bits to store DescriptorType values"); - static_assert((1u << _DescrSetBits) >= MAX_DESCRIPTOR_SETS, "Not enough bits to store descriptor set index"); - static_assert((1u << _BindingIndexBits) >= MAX_RESOURCES_IN_SIGNATURE, "Not enough bits to store resource binding index"); - static_assert((1u << _SamplerIndBits) >= MAX_RESOURCES_IN_SIGNATURE, "Not enough bits to store sampler resource index"); - - public: - static constexpr Uint32 InvalidSamplerInd = (1u << _SamplerIndBits) - 1; - - // clang-format off - const Uint32 BindingIndex : _BindingIndexBits; // Binding in the descriptor set - const Uint32 SamplerInd : _SamplerIndBits; // Index of the assigned sampler in m_Desc.Resources and m_pResourceAttribs - const Uint32 ArraySize : _ArraySizeBits; // Array size - const Uint32 DescrType : _DescrTypeBits; // Descriptor type (DescriptorType) - const Uint32 DescrSet : _DescrSetBits; // Descriptor set (0 or 1) - const Uint32 ImtblSamplerAssigned : _SamplerAssignedBits; // Immutable sampler flag - - const Uint32 SRBCacheOffset; // Offset in the SRB resource cache - const Uint32 StaticCacheOffset; // Offset in the static resource cache - // clang-format on - - ResourceAttribs(Uint32 _BindingIndex, - Uint32 _SamplerInd, - Uint32 _ArraySize, - DescriptorType _DescrType, - Uint32 _DescrSet, - bool _ImtblSamplerAssigned, - Uint32 _SRBCacheOffset, - Uint32 _StaticCacheOffset) noexcept : - // clang-format off - BindingIndex {_BindingIndex }, - SamplerInd {_SamplerInd }, - ArraySize {_ArraySize }, - DescrType {static_cast(_DescrType)}, - DescrSet {_DescrSet }, - ImtblSamplerAssigned {_ImtblSamplerAssigned ? 1u : 0u}, - SRBCacheOffset {_SRBCacheOffset }, - StaticCacheOffset {_StaticCacheOffset } - // clang-format on - { - VERIFY(BindingIndex == _BindingIndex, "Binding index (", _BindingIndex, ") exceeds maximum representable value"); - VERIFY(ArraySize == _ArraySize, "Array size (", _ArraySize, ") exceeds maximum representable value"); - VERIFY(SamplerInd == _SamplerInd, "Sampler index (", _SamplerInd, ") exceeds maximum representable value"); - VERIFY(GetDescriptorType() == _DescrType, "Descriptor type (", static_cast(_DescrType), ") exceeds maximum representable value"); - VERIFY(DescrSet == _DescrSet, "Descriptor set (", _DescrSet, ") exceeds maximum representable value"); - } - - Uint32 CacheOffset(ResourceCacheContentType CacheType) const - { - return CacheType == ResourceCacheContentType::SRB ? SRBCacheOffset : StaticCacheOffset; - } - - DescriptorType GetDescriptorType() const { return static_cast(DescrType); } - bool IsImmutableSamplerAssigned() const { return ImtblSamplerAssigned != 0; } - bool IsCombinedWithSampler() const { return SamplerInd != InvalidSamplerInd; } - }; - const ResourceAttribs& GetResourceAttribs(Uint32 ResIndex) const { VERIFY_EXPR(ResIndex < m_Desc.NumResources); @@ -196,24 +116,6 @@ public: bool HasDescriptorSet(DESCRIPTOR_SET_ID SetId) const { return m_VkDescrSetLayouts[SetId] != VK_NULL_HANDLE; } - /// Implementation of IPipelineResourceSignature::CreateShaderResourceBinding. - virtual void DILIGENT_CALL_TYPE CreateShaderResourceBinding(IShaderResourceBinding** ppShaderResourceBinding, - bool InitStaticResources) override final; - - /// Implementation of IPipelineResourceSignature::GetStaticVariableByName. - virtual IShaderResourceVariable* DILIGENT_CALL_TYPE GetStaticVariableByName(SHADER_TYPE ShaderType, const Char* Name) override final; - - /// Implementation of IPipelineResourceSignature::GetStaticVariableByIndex. - virtual IShaderResourceVariable* DILIGENT_CALL_TYPE GetStaticVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index) override final; - - /// Implementation of IPipelineResourceSignature::GetStaticVariableCount. - virtual Uint32 DILIGENT_CALL_TYPE GetStaticVariableCount(SHADER_TYPE ShaderType) const override final; - - /// Implementation of IPipelineResourceSignature::BindStaticResources. - virtual void DILIGENT_CALL_TYPE BindStaticResources(Uint32 ShaderFlags, - IResourceMapping* pResourceMapping, - Uint32 Flags) override final; - /// Implementation of IPipelineResourceSignature::IsCompatibleWith. virtual bool DILIGENT_CALL_TYPE IsCompatibleWith(const IPipelineResourceSignature* pPRS) const override final { diff --git a/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp index f36611df..18b23f91 100644 --- a/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp @@ -33,18 +33,17 @@ #include #include -#include "RenderDeviceVk.h" +#include "EngineVkImplTraits.hpp" #include "PipelineStateVk.h" #include "PipelineStateBase.hpp" -#include "ShaderVariableVk.hpp" +#include "PipelineResourceSignatureVkImpl.hpp" // Required by PipelineStateBase + +#include "ShaderVariableManagerVk.hpp" #include "FixedBlockMemoryAllocator.hpp" #include "SRBMemoryAllocator.hpp" #include "PipelineLayoutVk.hpp" #include "VulkanUtilities/VulkanObjectWrappers.hpp" #include "VulkanUtilities/VulkanCommandBuffer.hpp" -#include "RenderDeviceVkImpl.hpp" -#include "PipelineLayoutVk.hpp" -#include "PipelineResourceSignatureVkImpl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineVulkan/include/QueryVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/QueryVkImpl.hpp index cc3919c9..76f94f85 100644 --- a/Graphics/GraphicsEngineVulkan/include/QueryVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/QueryVkImpl.hpp @@ -32,9 +32,9 @@ #include +#include "EngineVkImplTraits.hpp" #include "QueryVk.h" #include "QueryBase.hpp" -#include "RenderDeviceVkImpl.hpp" #include "QueryManagerVk.hpp" namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.hpp index 71294e24..d9145764 100644 --- a/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.hpp @@ -33,24 +33,25 @@ #include "EngineVkImplTraits.hpp" +#include "CommandQueueVk.h" + #include "RenderDeviceBase.hpp" #include "RenderDeviceNextGenBase.hpp" -#include "DescriptorPoolManager.hpp" -#include "VulkanDynamicHeap.hpp" -#include "Atomics.hpp" -#include "CommandQueueVk.h" + #include "VulkanUtilities/VulkanInstance.hpp" #include "VulkanUtilities/VulkanPhysicalDevice.hpp" #include "VulkanUtilities/VulkanCommandBufferPool.hpp" #include "VulkanUtilities/VulkanLogicalDevice.hpp" #include "VulkanUtilities/VulkanObjectWrappers.hpp" #include "VulkanUtilities/VulkanMemoryManager.hpp" + +#include "DescriptorPoolManager.hpp" +#include "VulkanDynamicHeap.hpp" #include "VulkanUploadHeap.hpp" #include "FramebufferCache.hpp" #include "RenderPassCache.hpp" #include "CommandPoolManager.hpp" #include "DXCompiler.hpp" -#include "PipelineResourceSignatureVkImpl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineVulkan/include/RenderPassCache.hpp b/Graphics/GraphicsEngineVulkan/include/RenderPassCache.hpp index e8f7e177..0348501e 100644 --- a/Graphics/GraphicsEngineVulkan/include/RenderPassCache.hpp +++ b/Graphics/GraphicsEngineVulkan/include/RenderPassCache.hpp @@ -32,6 +32,7 @@ #include #include + #include "GraphicsTypes.h" #include "Constants.h" #include "HashUtils.hpp" diff --git a/Graphics/GraphicsEngineVulkan/include/SamplerVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/SamplerVkImpl.hpp index 5821e02e..5a74d660 100644 --- a/Graphics/GraphicsEngineVulkan/include/SamplerVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/SamplerVkImpl.hpp @@ -30,11 +30,10 @@ /// \file /// Declaration of Diligent::SamplerVkImpl class +#include "EngineVkImplTraits.hpp" #include "SamplerVk.h" -#include "RenderDeviceVk.h" #include "SamplerBase.hpp" #include "VulkanUtilities/VulkanObjectWrappers.hpp" -#include "RenderDeviceVkImpl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderBindingTableVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/ShaderBindingTableVkImpl.hpp index 5291f857..d8533118 100644 --- a/Graphics/GraphicsEngineVulkan/include/ShaderBindingTableVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/ShaderBindingTableVkImpl.hpp @@ -30,8 +30,7 @@ /// \file /// Definition of the Diligent::ShaderBindingTableVkImpl class -#include "RenderDeviceVk.h" -#include "RenderDeviceVkImpl.hpp" +#include "EngineVkImplTraits.hpp" #include "ShaderBindingTableVk.h" #include "ShaderBindingTableBase.hpp" #include "TopLevelASVkImpl.hpp" diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp index e77da610..1b448b6a 100644 --- a/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp @@ -30,13 +30,14 @@ /// \file /// Declaration of Diligent::ShaderResourceBindingVkImpl class +#include "EngineVkImplTraits.hpp" #include "ShaderResourceBindingVk.h" -#include "RenderDeviceVk.h" #include "ShaderResourceBindingBase.hpp" #include "ShaderBase.hpp" + +// ShaderVariableManagerVk and ShaderResourceCacheVk are required by ShaderResourceBindingBase #include "ShaderResourceCacheVk.hpp" -#include "ShaderVariableVk.hpp" -#include "PipelineResourceSignatureVkImpl.hpp" +#include "ShaderVariableManagerVk.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderResourceCacheVk.hpp b/Graphics/GraphicsEngineVulkan/include/ShaderResourceCacheVk.hpp index 7c8621c0..aac66247 100644 --- a/Graphics/GraphicsEngineVulkan/include/ShaderResourceCacheVk.hpp +++ b/Graphics/GraphicsEngineVulkan/include/ShaderResourceCacheVk.hpp @@ -59,8 +59,8 @@ #include "DescriptorPoolManager.hpp" #include "SPIRVShaderResources.hpp" #include "BufferVkImpl.hpp" -#include "PipelineResourceSignatureVkImpl.hpp" #include "ShaderResourceCacheCommon.hpp" +#include "PipelineResourceAttribsVk.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderVariableManagerVk.hpp b/Graphics/GraphicsEngineVulkan/include/ShaderVariableManagerVk.hpp new file mode 100644 index 00000000..b5d0c687 --- /dev/null +++ b/Graphics/GraphicsEngineVulkan/include/ShaderVariableManagerVk.hpp @@ -0,0 +1,210 @@ +/* + * Copyright 2019-2021 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Declaration of Diligent::ShaderVariableManagerVk and Diligent::ShaderVariableVkImpl classes + +// +// * ShaderVariableManagerVk keeps the list of variables of specific types +// * Every ShaderVariableVkImpl references ResourceAttribs by index from PipelineResourceSignatureVkImpl +// * ShaderVariableManagerVk keeps reference to ShaderResourceCacheVk +// * ShaderVariableManagerVk is used by PipelineResourceSignatureVkImpl to manage static resources and by +// ShaderResourceBindingVkImpl to manage mutable and dynamic resources +// +// __________________________ __________________________________________________________________________ +// | | | | | | +// .----| ShaderVariableManagerVk |-------------------------->| ShaderVariableVkImpl[0] | ShaderVariableVkImpl[1] | ... | +// | |__________________________| |___________________________|____________________________|_________________| +// | | \ | +// | m_pSignature m_ResIndex m_ResIndex +// | | \ | +// | ___________V_____________________ ______________________V_______________________V____________________________ +// | | | m_pResourceAttribs | | | | | +// | | PipelineResourceSignatureVkImpl |------------------->| Resource[0] | Resource[1] | ... | Resource[s+m+d-1] | +// | |_________________________________| |__________________|________________|_______________|_____________________| +// | | | +// | | | +// | | (DescriptorSet, CacheOffset) / (DescriptorSet, CacheOffset) +// | \ / +// | __________________________ ________V___________________________________________________V_______ +// | | | | | +// '--->| ShaderResourceCacheVk |-------------------------->| Resources | +// |__________________________| |____________________________________________________________________| +// +// + +#include + +#include "ShaderResourceVariableBase.hpp" +#include "ShaderResourceCacheVk.hpp" +#include "PipelineResourceAttribsVk.hpp" + +namespace Diligent +{ + +class ShaderVariableVkImpl; + +// sizeof(ShaderVariableManagerVk) == 40 (x64, msvc, Release) +class ShaderVariableManagerVk +{ +public: + ShaderVariableManagerVk(IObject& Owner, + ShaderResourceCacheVk& ResourceCache) noexcept : + m_Owner{Owner}, + m_ResourceCache{ResourceCache} + {} + + void Initialize(const PipelineResourceSignatureVkImpl& Signature, + IMemoryAllocator& Allocator, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes, + SHADER_TYPE ShaderType); + + ~ShaderVariableManagerVk(); + + void Destroy(IMemoryAllocator& Allocator); + + ShaderVariableVkImpl* GetVariable(const Char* Name) const; + ShaderVariableVkImpl* GetVariable(Uint32 Index) const; + + void BindResources(IResourceMapping* pResourceMapping, Uint32 Flags) const; + + static size_t GetRequiredMemorySize(const PipelineResourceSignatureVkImpl& Signature, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes, + SHADER_TYPE ShaderStages, + Uint32& NumVariables); + + Uint32 GetVariableCount() const { return m_NumVariables; } + + IObject& GetOwner() { return m_Owner; } + +private: + friend ShaderVariableVkImpl; + using ResourceAttribs = PipelineResourceAttribsVk; + + Uint32 GetVariableIndex(const ShaderVariableVkImpl& Variable); + + // These two methods can't be implemented in the header because they depend on PipelineResourceSignatureVkImpl + const PipelineResourceDesc& GetResourceDesc(Uint32 Index) const; + const ResourceAttribs& GetAttribs(Uint32 Index) const; + + template + static void ProcessSignatureResources(const PipelineResourceSignatureVkImpl& Signature, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes, + SHADER_TYPE ShaderStages, + HandlerType Handler); + +private: + PipelineResourceSignatureVkImpl const* m_pSignature = nullptr; + + IObject& m_Owner; + + // Variable mgr is owned by either Pipeline Resource Signature (in which case m_ResourceCache references + // static resource cache owned by the same PRS object), or by SRB object (in which case + // m_ResourceCache references the cache in the SRB). Thus the cache and the signature + // (which the variables reference) are guaranteed to be alive while the manager is alive. + ShaderResourceCacheVk& m_ResourceCache; + + // Memory is allocated through the allocator provided by the resource signature. If allocation granularity > 1, fixed block + // memory allocator is used. This ensures that all resources from different shader resource bindings reside in + // continuous memory. If allocation granularity == 1, raw allocator is used. + ShaderVariableVkImpl* m_pVariables = nullptr; + Uint32 m_NumVariables = 0; + +#ifdef DILIGENT_DEBUG + IMemoryAllocator* m_pDbgAllocator = nullptr; +#endif +}; + +// sizeof(ShaderVariableVkImpl) == 24 (x64) +class ShaderVariableVkImpl final : public ShaderVariableBase +{ +public: + using TBase = ShaderVariableBase; + + ShaderVariableVkImpl(ShaderVariableManagerVk& ParentManager, + Uint32 ResIndex) : + TBase{ParentManager}, + m_ResIndex{ResIndex} + {} + + // clang-format off + ShaderVariableVkImpl (const ShaderVariableVkImpl&) = delete; + ShaderVariableVkImpl (ShaderVariableVkImpl&&) = delete; + ShaderVariableVkImpl& operator= (const ShaderVariableVkImpl&) = delete; + ShaderVariableVkImpl& operator= (ShaderVariableVkImpl&&) = delete; + // clang-format on + + virtual SHADER_RESOURCE_VARIABLE_TYPE DILIGENT_CALL_TYPE GetType() const override final + { + return GetDesc().VarType; + } + + virtual void DILIGENT_CALL_TYPE Set(IDeviceObject* pObject) override final + { + BindResource(pObject, 0); + } + + virtual void DILIGENT_CALL_TYPE SetArray(IDeviceObject* const* ppObjects, + Uint32 FirstElement, + Uint32 NumElements) override final; + + virtual void DILIGENT_CALL_TYPE GetResourceDesc(ShaderResourceDesc& ResourceDesc) const override final + { + const auto& Desc = GetDesc(); + ResourceDesc.Name = Desc.Name; + ResourceDesc.Type = Desc.ResourceType; + ResourceDesc.ArraySize = Desc.ArraySize; + } + + virtual Uint32 DILIGENT_CALL_TYPE GetIndex() const override final + { + return m_ParentManager.GetVariableIndex(*this); + } + + // This method can't be implemented in the header because it depends on PipelineResourceSignatureVkImpl + virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final; + + const PipelineResourceDesc& GetDesc() const { return m_ParentManager.GetResourceDesc(m_ResIndex); } + + // This method can't be implemented in the header because it depends on PipelineResourceSignatureVkImpl + void BindResource(IDeviceObject* pObj, Uint32 ArrayIndex) const; + +private: + using ResourceAttribs = PipelineResourceAttribsVk; + + const ResourceAttribs& GetAttribs() const { return m_ParentManager.GetAttribs(m_ResIndex); } + +private: + const Uint32 m_ResIndex; // Index in Signatures' m_Desc.Resources +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderVariableVk.hpp b/Graphics/GraphicsEngineVulkan/include/ShaderVariableVk.hpp deleted file mode 100644 index 6a268f13..00000000 --- a/Graphics/GraphicsEngineVulkan/include/ShaderVariableVk.hpp +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright 2019-2021 Diligent Graphics LLC - * Copyright 2015-2019 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#pragma once - -/// \file -/// Declaration of Diligent::ShaderVariableManagerVk and Diligent::ShaderVariableVkImpl classes - -// -// * ShaderVariableManagerVk keeps the list of variables of specific types -// * Every ShaderVariableVkImpl references ResourceAttribs by index from PipelineResourceSignatureVkImpl -// * ShaderVariableManagerVk keeps reference to ShaderResourceCacheVk -// * ShaderVariableManagerVk is used by PipelineResourceSignatureVkImpl to manage static resources and by -// ShaderResourceBindingVkImpl to manage mutable and dynamic resources -// -// __________________________ __________________________________________________________________________ -// | | | | | | -// .----| ShaderVariableManagerVk |-------------------------->| ShaderVariableVkImpl[0] | ShaderVariableVkImpl[1] | ... | -// | |__________________________| |___________________________|____________________________|_________________| -// | | \ | -// | m_pSignature m_ResIndex m_ResIndex -// | | \ | -// | ___________V_____________________ ______________________V_______________________V____________________________ -// | | | m_pResourceAttribs | | | | | -// | | PipelineResourceSignatureVkImpl |------------------->| Resource[0] | Resource[1] | ... | Resource[s+m+d-1] | -// | |_________________________________| |__________________|________________|_______________|_____________________| -// | | | -// | | | -// | | (DescriptorSet, CacheOffset) / (DescriptorSet, CacheOffset) -// | \ / -// | __________________________ ________V___________________________________________________V_______ -// | | | | | -// '--->| ShaderResourceCacheVk |-------------------------->| Resources | -// |__________________________| |____________________________________________________________________| -// -// - -#include - -#include "ShaderResourceVariableBase.hpp" -#include "ShaderResourceCacheVk.hpp" -#include "PipelineResourceSignatureVkImpl.hpp" - -namespace Diligent -{ - -class ShaderVariableVkImpl; - -// sizeof(ShaderVariableManagerVk) == 40 (x64, msvc, Release) -class ShaderVariableManagerVk -{ -public: - ShaderVariableManagerVk(IObject& Owner, - ShaderResourceCacheVk& ResourceCache) noexcept : - m_Owner{Owner}, - m_ResourceCache{ResourceCache} - {} - - void Initialize(const PipelineResourceSignatureVkImpl& Signature, - IMemoryAllocator& Allocator, - const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, - Uint32 NumAllowedTypes, - SHADER_TYPE ShaderType); - - ~ShaderVariableManagerVk(); - - void Destroy(IMemoryAllocator& Allocator); - - ShaderVariableVkImpl* GetVariable(const Char* Name) const; - ShaderVariableVkImpl* GetVariable(Uint32 Index) const; - - void BindResources(IResourceMapping* pResourceMapping, Uint32 Flags) const; - - static size_t GetRequiredMemorySize(const PipelineResourceSignatureVkImpl& Signature, - const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, - Uint32 NumAllowedTypes, - SHADER_TYPE ShaderStages, - Uint32& NumVariables); - - Uint32 GetVariableCount() const { return m_NumVariables; } - - IObject& GetOwner() { return m_Owner; } - -private: - friend ShaderVariableVkImpl; - using ResourceAttribs = PipelineResourceSignatureVkImpl::ResourceAttribs; - - Uint32 GetVariableIndex(const ShaderVariableVkImpl& Variable); - - const PipelineResourceDesc& GetResourceDesc(Uint32 Index) const - { - VERIFY_EXPR(m_pSignature); - return m_pSignature->GetResourceDesc(Index); - } - const ResourceAttribs& GetAttribs(Uint32 Index) const - { - VERIFY_EXPR(m_pSignature); - return m_pSignature->GetResourceAttribs(Index); - } - - template - static void ProcessSignatureResources(const PipelineResourceSignatureVkImpl& Signature, - const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, - Uint32 NumAllowedTypes, - SHADER_TYPE ShaderStages, - HandlerType Handler); - -private: - PipelineResourceSignatureVkImpl const* m_pSignature = nullptr; - - IObject& m_Owner; - - // Variable mgr is owned by either Pipeline Resource Signature (in which case m_ResourceCache references - // static resource cache owned by the same PRS object), or by SRB object (in which case - // m_ResourceCache references the cache in the SRB). Thus the cache and the signature - // (which the variables reference) are guaranteed to be alive while the manager is alive. - ShaderResourceCacheVk& m_ResourceCache; - - // Memory is allocated through the allocator provided by the resource signature. If allocation granularity > 1, fixed block - // memory allocator is used. This ensures that all resources from different shader resource bindings reside in - // continuous memory. If allocation granularity == 1, raw allocator is used. - ShaderVariableVkImpl* m_pVariables = nullptr; - Uint32 m_NumVariables = 0; - -#ifdef DILIGENT_DEBUG - IMemoryAllocator* m_pDbgAllocator = nullptr; -#endif -}; - -// sizeof(ShaderVariableVkImpl) == 24 (x64) -class ShaderVariableVkImpl final : public ShaderVariableBase -{ -public: - using TBase = ShaderVariableBase; - - ShaderVariableVkImpl(ShaderVariableManagerVk& ParentManager, - Uint32 ResIndex) : - TBase{ParentManager}, - m_ResIndex{ResIndex} - {} - - // clang-format off - ShaderVariableVkImpl (const ShaderVariableVkImpl&) = delete; - ShaderVariableVkImpl (ShaderVariableVkImpl&&) = delete; - ShaderVariableVkImpl& operator= (const ShaderVariableVkImpl&) = delete; - ShaderVariableVkImpl& operator= (ShaderVariableVkImpl&&) = delete; - // clang-format on - - virtual SHADER_RESOURCE_VARIABLE_TYPE DILIGENT_CALL_TYPE GetType() const override final - { - return GetDesc().VarType; - } - - virtual void DILIGENT_CALL_TYPE Set(IDeviceObject* pObject) override final - { - BindResource(pObject, 0); - } - - virtual void DILIGENT_CALL_TYPE SetArray(IDeviceObject* const* ppObjects, - Uint32 FirstElement, - Uint32 NumElements) override final; - - virtual void DILIGENT_CALL_TYPE GetResourceDesc(ShaderResourceDesc& ResourceDesc) const override final - { - const auto& Desc = GetDesc(); - ResourceDesc.Name = Desc.Name; - ResourceDesc.Type = Desc.ResourceType; - ResourceDesc.ArraySize = Desc.ArraySize; - } - - virtual Uint32 DILIGENT_CALL_TYPE GetIndex() const override final - { - return m_ParentManager.GetVariableIndex(*this); - } - - virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final - { - return m_ParentManager.m_pSignature->IsBound(ArrayIndex, m_ResIndex, m_ParentManager.m_ResourceCache); - } - - const PipelineResourceDesc& GetDesc() const { return m_ParentManager.GetResourceDesc(m_ResIndex); } - - void BindResource(IDeviceObject* pObj, Uint32 ArrayIndex) const - { - m_ParentManager.m_pSignature->BindResource(pObj, ArrayIndex, m_ResIndex, m_ParentManager.m_ResourceCache); - } - -private: - using ResourceAttribs = PipelineResourceSignatureVkImpl::ResourceAttribs; - - const ResourceAttribs& GetAttribs() const { return m_ParentManager.GetAttribs(m_ResIndex); } - -private: - const Uint32 m_ResIndex; // Index in Signatures' m_Desc.Resources -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.hpp index f8b63b95..60c464d6 100644 --- a/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.hpp @@ -30,11 +30,10 @@ /// \file /// Declaration of Diligent::ShaderVkImpl class -#include "RenderDeviceVk.h" +#include "EngineVkImplTraits.hpp" #include "ShaderVk.h" #include "ShaderBase.hpp" #include "SPIRVShaderResources.hpp" -#include "RenderDeviceVkImpl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineVulkan/include/SwapChainVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/SwapChainVkImpl.hpp index a083c48c..94a6d5df 100644 --- a/Graphics/GraphicsEngineVulkan/include/SwapChainVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/SwapChainVkImpl.hpp @@ -30,6 +30,7 @@ /// \file /// Declaration of Diligent::SwapChainVkImpl class +#include "EngineVkImplTraits.hpp" #include "SwapChainVk.h" #include "SwapChainBase.hpp" #include "VulkanUtilities/VulkanInstance.hpp" diff --git a/Graphics/GraphicsEngineVulkan/include/TextureViewVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/TextureViewVkImpl.hpp index 67806c8b..271fee6c 100644 --- a/Graphics/GraphicsEngineVulkan/include/TextureViewVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/TextureViewVkImpl.hpp @@ -30,11 +30,10 @@ /// \file /// Declaration of Diligent::TextureViewVkImpl class +#include "EngineVkImplTraits.hpp" #include "TextureViewVk.h" -#include "RenderDeviceVk.h" #include "TextureViewBase.hpp" #include "VulkanUtilities/VulkanObjectWrappers.hpp" -#include "RenderDeviceVkImpl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineVulkan/include/TextureVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/TextureVkImpl.hpp index 9f5cfb84..7b20f577 100644 --- a/Graphics/GraphicsEngineVulkan/include/TextureVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/TextureVkImpl.hpp @@ -30,12 +30,11 @@ /// \file /// Declaration of Diligent::TextureVkImpl class +#include "EngineVkImplTraits.hpp" #include "TextureVk.h" -#include "RenderDeviceVk.h" #include "TextureBase.hpp" #include "TextureViewVkImpl.hpp" #include "VulkanUtilities/VulkanMemoryManager.hpp" -#include "RenderDeviceVkImpl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineVulkan/include/TopLevelASVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/TopLevelASVkImpl.hpp index 7f34104d..c8525039 100644 --- a/Graphics/GraphicsEngineVulkan/include/TopLevelASVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/TopLevelASVkImpl.hpp @@ -30,8 +30,7 @@ /// \file /// Definition of the Diligent::TopLevelASVkImpl class -#include "RenderDeviceVk.h" -#include "RenderDeviceVkImpl.hpp" +#include "EngineVkImplTraits.hpp" #include "TopLevelASVk.h" #include "TopLevelASBase.hpp" #include "BottomLevelASVkImpl.hpp" diff --git a/Graphics/GraphicsEngineVulkan/src/BottomLevelASVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/BottomLevelASVkImpl.cpp index c0f7ed2b..08154083 100644 --- a/Graphics/GraphicsEngineVulkan/src/BottomLevelASVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/BottomLevelASVkImpl.cpp @@ -27,6 +27,7 @@ #include "pch.h" #include "BottomLevelASVkImpl.hpp" +#include "RenderDeviceVkImpl.hpp" #include "VulkanTypeConversions.hpp" namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/src/CommandQueueVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/CommandQueueVkImpl.cpp index bd3833dd..3b725dd8 100644 --- a/Graphics/GraphicsEngineVulkan/src/CommandQueueVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/CommandQueueVkImpl.cpp @@ -25,10 +25,14 @@ * of the possibility of such damages. */ -#include #include "pch.h" + #include "CommandQueueVkImpl.hpp" +#include + +#include "RenderDeviceVkImpl.hpp" + namespace Diligent { diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index 0ac9c0fb..91faf339 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -27,18 +27,20 @@ #include "pch.h" +#include "DeviceContextVkImpl.hpp" + #include #include #include "RenderDeviceVkImpl.hpp" -#include "DeviceContextVkImpl.hpp" #include "PipelineStateVkImpl.hpp" #include "TextureVkImpl.hpp" #include "BufferVkImpl.hpp" #include "RenderPassVkImpl.hpp" +#include "FenceVkImpl.hpp" + #include "VulkanTypeConversions.hpp" #include "CommandListVkImpl.hpp" -#include "FenceVkImpl.hpp" #include "GraphicsAccessories.hpp" namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/src/FenceVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/FenceVkImpl.cpp index fa4c4536..9170516a 100644 --- a/Graphics/GraphicsEngineVulkan/src/FenceVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/FenceVkImpl.cpp @@ -28,8 +28,8 @@ #include "pch.h" #include "FenceVkImpl.hpp" -#include "EngineMemory.h" #include "RenderDeviceVkImpl.hpp" +#include "EngineMemory.h" namespace Diligent { diff --git a/Graphics/GraphicsEngineVulkan/src/FramebufferCache.cpp b/Graphics/GraphicsEngineVulkan/src/FramebufferCache.cpp index 9dfbf8a0..e8d535fe 100644 --- a/Graphics/GraphicsEngineVulkan/src/FramebufferCache.cpp +++ b/Graphics/GraphicsEngineVulkan/src/FramebufferCache.cpp @@ -27,8 +27,8 @@ #include "pch.h" #include "FramebufferCache.hpp" -#include "HashUtils.hpp" #include "RenderDeviceVkImpl.hpp" +#include "HashUtils.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineVulkan/src/FramebufferVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/FramebufferVkImpl.cpp index 88b7f2d8..407be488 100644 --- a/Graphics/GraphicsEngineVulkan/src/FramebufferVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/FramebufferVkImpl.cpp @@ -27,13 +27,16 @@ #include "pch.h" +#include "FramebufferVkImpl.hpp" + #include -#include "FramebufferVkImpl.hpp" -#include "EngineMemory.h" +#include "RenderDeviceVkImpl.hpp" #include "RenderPassVkImpl.hpp" #include "TextureViewVkImpl.hpp" +#include "EngineMemory.h" + namespace Diligent { diff --git a/Graphics/GraphicsEngineVulkan/src/GenerateMipsVkHelper.cpp b/Graphics/GraphicsEngineVulkan/src/GenerateMipsVkHelper.cpp index f46dd27d..43ab5814 100644 --- a/Graphics/GraphicsEngineVulkan/src/GenerateMipsVkHelper.cpp +++ b/Graphics/GraphicsEngineVulkan/src/GenerateMipsVkHelper.cpp @@ -26,12 +26,16 @@ */ #include "pch.h" -#include + #include "GenerateMipsVkHelper.hpp" + +#include + #include "RenderDeviceVkImpl.hpp" #include "DeviceContextVkImpl.hpp" #include "TextureViewVkImpl.hpp" #include "TextureVkImpl.hpp" + #include "PlatformMisc.hpp" #include "VulkanTypeConversions.hpp" #include "../../GraphicsTools/interface/ShaderMacroHelper.hpp" diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineLayoutVk.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineLayoutVk.cpp index 14183e97..35957ca7 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineLayoutVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineLayoutVk.cpp @@ -27,14 +27,16 @@ #include "pch.h" +#include "PipelineLayoutVk.hpp" + #include #include -#include "PipelineLayoutVk.hpp" #include "RenderDeviceVkImpl.hpp" +#include "PipelineResourceSignatureVkImpl.hpp" + #include "VulkanTypeConversions.hpp" #include "StringTools.hpp" -#include "PipelineResourceSignatureVkImpl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp index 799d98db..66502634 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp @@ -26,13 +26,15 @@ */ #include "pch.h" + #include "PipelineResourceSignatureVkImpl.hpp" -#include "ShaderResourceBindingVkImpl.hpp" + #include "RenderDeviceVkImpl.hpp" -#include "VulkanTypeConversions.hpp" #include "SamplerVkImpl.hpp" #include "TextureViewVkImpl.hpp" #include "TopLevelASVkImpl.hpp" + +#include "VulkanTypeConversions.hpp" #include "DynamicLinearAllocator.hpp" #include "SPIRVShaderResources.hpp" @@ -619,34 +621,6 @@ bool PipelineResourceSignatureVkImpl::IsCompatibleWith(const PipelineResourceSig return true; } -void PipelineResourceSignatureVkImpl::CreateShaderResourceBinding(IShaderResourceBinding** ppShaderResourceBinding, - bool InitStaticResources) -{ - CreateShaderResourceBindingImpl(ppShaderResourceBinding, InitStaticResources); -} - -Uint32 PipelineResourceSignatureVkImpl::GetStaticVariableCount(SHADER_TYPE ShaderType) const -{ - return GetStaticVariableCountImpl(ShaderType); -} - -IShaderResourceVariable* PipelineResourceSignatureVkImpl::GetStaticVariableByName(SHADER_TYPE ShaderType, const Char* Name) -{ - return GetStaticVariableByNameImpl(ShaderType, Name); -} - -IShaderResourceVariable* PipelineResourceSignatureVkImpl::GetStaticVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index) -{ - return GetStaticVariableByIndexImpl(ShaderType, Index); -} - -void PipelineResourceSignatureVkImpl::BindStaticResources(Uint32 ShaderFlags, - IResourceMapping* pResMapping, - Uint32 Flags) -{ - BindStaticResourcesImpl(ShaderFlags, pResMapping, Flags); -} - void PipelineResourceSignatureVkImpl::InitSRBResourceCache(ShaderResourceCacheVk& ResourceCache, IMemoryAllocator& CacheMemAllocator, const char* DbgPipelineName) const diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp index 364d6f1b..5298d20d 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp @@ -27,19 +27,20 @@ #include "pch.h" +#include "PipelineStateVkImpl.hpp" + #include #include -#include "PipelineStateVkImpl.hpp" -#include "ShaderVkImpl.hpp" -#include "VulkanTypeConversions.hpp" #include "RenderDeviceVkImpl.hpp" #include "DeviceContextVkImpl.hpp" +#include "ShaderVkImpl.hpp" #include "RenderPassVkImpl.hpp" #include "ShaderResourceBindingVkImpl.hpp" + +#include "VulkanTypeConversions.hpp" #include "EngineMemory.h" #include "StringTools.hpp" -#include "ShaderResourceBindingVkImpl.hpp" #if !DILIGENT_NO_HLSL diff --git a/Graphics/GraphicsEngineVulkan/src/QueryManagerVk.cpp b/Graphics/GraphicsEngineVulkan/src/QueryManagerVk.cpp index 1424024e..44cb7967 100644 --- a/Graphics/GraphicsEngineVulkan/src/QueryManagerVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/QueryManagerVk.cpp @@ -26,8 +26,11 @@ */ #include "pch.h" -#include + #include "QueryManagerVk.hpp" + +#include + #include "RenderDeviceVkImpl.hpp" #include "GraphicsAccessories.hpp" #include "VulkanUtilities/VulkanCommandBuffer.hpp" diff --git a/Graphics/GraphicsEngineVulkan/src/QueryVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/QueryVkImpl.cpp index 36cc0d37..59391744 100644 --- a/Graphics/GraphicsEngineVulkan/src/QueryVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/QueryVkImpl.cpp @@ -28,9 +28,9 @@ #include "pch.h" #include "QueryVkImpl.hpp" -#include "EngineMemory.h" #include "RenderDeviceVkImpl.hpp" #include "DeviceContextVkImpl.hpp" +#include "EngineMemory.h" namespace Diligent { diff --git a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp index cf66b3ce..8debcd97 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp @@ -26,11 +26,12 @@ */ #include "pch.h" + #include "RenderDeviceVkImpl.hpp" + #include "PipelineStateVkImpl.hpp" #include "ShaderVkImpl.hpp" #include "TextureVkImpl.hpp" -#include "VulkanTypeConversions.hpp" #include "SamplerVkImpl.hpp" #include "BufferVkImpl.hpp" #include "ShaderResourceBindingVkImpl.hpp" @@ -43,6 +44,8 @@ #include "TopLevelASVkImpl.hpp" #include "ShaderBindingTableVkImpl.hpp" #include "PipelineResourceSignatureVkImpl.hpp" + +#include "VulkanTypeConversions.hpp" #include "EngineMemory.h" namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/src/RenderPassCache.cpp b/Graphics/GraphicsEngineVulkan/src/RenderPassCache.cpp index 3becabff..5f75e6eb 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderPassCache.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderPassCache.cpp @@ -26,8 +26,11 @@ */ #include "pch.h" -#include + #include "RenderPassCache.hpp" + +#include + #include "RenderDeviceVkImpl.hpp" #include "PipelineStateVkImpl.hpp" #include "RenderPassVkImpl.hpp" diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderBindingTableVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderBindingTableVkImpl.cpp index d3773cf1..da1024c7 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderBindingTableVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderBindingTableVkImpl.cpp @@ -26,7 +26,9 @@ */ #include "pch.h" + #include "ShaderBindingTableVkImpl.hpp" +#include "RenderDeviceVkImpl.hpp" #include "BufferVkImpl.hpp" #include "VulkanTypeConversions.hpp" diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp index 797718fd..0d5e5396 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp @@ -27,9 +27,9 @@ #include "pch.h" #include "ShaderResourceBindingVkImpl.hpp" +#include "RenderDeviceVkImpl.hpp" #include "PipelineStateVkImpl.hpp" #include "ShaderVkImpl.hpp" -#include "RenderDeviceVkImpl.hpp" #include "FixedLinearAllocator.hpp" namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp index 4b2efdc4..c4c40f7c 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp @@ -28,12 +28,14 @@ #include "pch.h" #include "ShaderResourceCacheVk.hpp" + #include "DeviceContextVkImpl.hpp" #include "BufferViewVkImpl.hpp" #include "TextureViewVkImpl.hpp" #include "TextureVkImpl.hpp" #include "SamplerVkImpl.hpp" #include "TopLevelASVkImpl.hpp" + #include "VulkanTypeConversions.hpp" namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVariableManagerVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVariableManagerVk.cpp new file mode 100644 index 00000000..71d2811a --- /dev/null +++ b/Graphics/GraphicsEngineVulkan/src/ShaderVariableManagerVk.cpp @@ -0,0 +1,237 @@ +/* + * Copyright 2019-2021 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#include "pch.h" + +#include "ShaderVariableManagerVk.hpp" +#include "RenderDeviceVkImpl.hpp" +#include "PipelineResourceSignatureVkImpl.hpp" + +namespace Diligent +{ + +template +void ShaderVariableManagerVk::ProcessSignatureResources(const PipelineResourceSignatureVkImpl& Signature, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes, + SHADER_TYPE ShaderStages, + HandlerType Handler) +{ + const Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes); + const bool UsingSeparateSamplers = Signature.IsUsingSeparateSamplers(); + + for (Uint32 var_type = 0; var_type < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; ++var_type) + { + const auto VarType = static_cast(var_type); + if (IsAllowedType(VarType, AllowedTypeBits)) + { + const auto ResIdxRange = Signature.GetResourceIndexRange(VarType); + for (Uint32 r = ResIdxRange.first; r < ResIdxRange.second; ++r) + { + const auto& Res = Signature.GetResourceDesc(r); + const auto& Attr = Signature.GetResourceAttribs(r); + VERIFY_EXPR(Res.VarType == VarType); + + if ((Res.ShaderStages & ShaderStages) == 0) + continue; + + // When using HLSL-style combined image samplers, we need to skip separate samplers. + // Also always skip immutable separate samplers. + if (Res.ResourceType == SHADER_RESOURCE_TYPE_SAMPLER && + (!UsingSeparateSamplers || Attr.IsImmutableSamplerAssigned())) + continue; + + Handler(r); + } + } + } +} + +size_t ShaderVariableManagerVk::GetRequiredMemorySize(const PipelineResourceSignatureVkImpl& Signature, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes, + SHADER_TYPE ShaderStages, + Uint32& NumVariables) +{ + NumVariables = 0; + ProcessSignatureResources(Signature, AllowedVarTypes, NumAllowedTypes, ShaderStages, + [&NumVariables](Uint32) // + { + ++NumVariables; + }); + + return NumVariables * sizeof(ShaderVariableVkImpl); +} + +// Creates shader variable for every resource from SrcLayout whose type is one AllowedVarTypes +void ShaderVariableManagerVk::Initialize(const PipelineResourceSignatureVkImpl& Signature, + IMemoryAllocator& Allocator, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes, + SHADER_TYPE ShaderType) +{ +#ifdef DILIGENT_DEBUG + m_pDbgAllocator = &Allocator; +#endif + + VERIFY_EXPR(m_pSignature == nullptr); + + const Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes); + VERIFY_EXPR(m_NumVariables == 0); + const auto MemSize = GetRequiredMemorySize(Signature, AllowedVarTypes, NumAllowedTypes, ShaderType, m_NumVariables); + + if (m_NumVariables == 0) + return; + + auto* pRawMem = ALLOCATE_RAW(Allocator, "Raw memory buffer for shader variables", MemSize); + m_pVariables = reinterpret_cast(pRawMem); + + Uint32 VarInd = 0; + ProcessSignatureResources(Signature, AllowedVarTypes, NumAllowedTypes, ShaderType, + [this, &VarInd](Uint32 ResIndex) // + { + ::new (m_pVariables + VarInd) ShaderVariableVkImpl{*this, ResIndex}; + ++VarInd; + }); + VERIFY_EXPR(VarInd == m_NumVariables); + + m_pSignature = &Signature; +} + +ShaderVariableManagerVk::~ShaderVariableManagerVk() +{ + VERIFY(m_pVariables == nullptr, "Destroy() has not been called"); +} + +void ShaderVariableManagerVk::Destroy(IMemoryAllocator& Allocator) +{ + if (m_pVariables != nullptr) + { + VERIFY(m_pDbgAllocator == &Allocator, "Incosistent alloctor"); + + for (Uint32 v = 0; v < m_NumVariables; ++v) + m_pVariables[v].~ShaderVariableVkImpl(); + Allocator.Free(m_pVariables); + m_pVariables = nullptr; + } +} + +ShaderVariableVkImpl* ShaderVariableManagerVk::GetVariable(const Char* Name) const +{ + for (Uint32 v = 0; v < m_NumVariables; ++v) + { + auto& Var = m_pVariables[v]; + if (strcmp(Var.GetDesc().Name, Name) == 0) + return &Var; + } + return nullptr; +} + + +ShaderVariableVkImpl* ShaderVariableManagerVk::GetVariable(Uint32 Index) const +{ + if (Index >= m_NumVariables) + { + LOG_ERROR("Index ", Index, " is out of range"); + return nullptr; + } + + return m_pVariables + Index; +} + +Uint32 ShaderVariableManagerVk::GetVariableIndex(const ShaderVariableVkImpl& Variable) +{ + if (m_pVariables == nullptr) + { + LOG_ERROR("This shader variable manager has no variables"); + return ~0u; + } + + const auto Offset = reinterpret_cast(&Variable) - reinterpret_cast(m_pVariables); + DEV_CHECK_ERR(Offset % sizeof(ShaderVariableVkImpl) == 0, "Offset is not multiple of ShaderVariableVkImpl class size"); + const auto Index = static_cast(Offset / sizeof(ShaderVariableVkImpl)); + if (Index < m_NumVariables) + return Index; + else + { + LOG_ERROR("Failed to get variable index. The variable ", &Variable, " does not belong to this shader variable manager"); + return ~0u; + } +} + +const PipelineResourceDesc& ShaderVariableManagerVk::GetResourceDesc(Uint32 Index) const +{ + VERIFY_EXPR(m_pSignature); + return m_pSignature->GetResourceDesc(Index); +} + +const ShaderVariableManagerVk::ResourceAttribs& ShaderVariableManagerVk::GetAttribs(Uint32 Index) const +{ + VERIFY_EXPR(m_pSignature); + return m_pSignature->GetResourceAttribs(Index); +} + + +void ShaderVariableManagerVk::BindResources(IResourceMapping* pResourceMapping, Uint32 Flags) const +{ + if (!pResourceMapping) + { + LOG_ERROR_MESSAGE("Failed to bind resources: resource mapping is null"); + return; + } + + if ((Flags & BIND_SHADER_RESOURCES_UPDATE_ALL) == 0) + Flags |= BIND_SHADER_RESOURCES_UPDATE_ALL; + + for (Uint32 v = 0; v < m_NumVariables; ++v) + { + m_pVariables[v].BindResources(pResourceMapping, Flags); + } +} + +void ShaderVariableVkImpl::SetArray(IDeviceObject* const* ppObjects, + Uint32 FirstElement, + Uint32 NumElements) +{ + const auto& ResDesc = GetDesc(); + VerifyAndCorrectSetArrayArguments(ResDesc.Name, ResDesc.ArraySize, FirstElement, NumElements); + + for (Uint32 Elem = 0; Elem < NumElements; ++Elem) + BindResource(ppObjects[Elem], FirstElement + Elem); +} + +bool ShaderVariableVkImpl::IsBound(Uint32 ArrayIndex) const +{ + return m_ParentManager.m_pSignature->IsBound(ArrayIndex, m_ResIndex, m_ParentManager.m_ResourceCache); +} + +void ShaderVariableVkImpl::BindResource(IDeviceObject* pObj, Uint32 ArrayIndex) const +{ + m_ParentManager.m_pSignature->BindResource(pObj, ArrayIndex, m_ResIndex, m_ParentManager.m_ResourceCache); +} + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp deleted file mode 100644 index b56b3adc..00000000 --- a/Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright 2019-2021 Diligent Graphics LLC - * Copyright 2015-2019 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#include "pch.h" - -#include "ShaderVariableVk.hpp" -#include "ShaderResourceVariableBase.hpp" -#include "PipelineResourceSignatureVkImpl.hpp" - -namespace Diligent -{ - -template -void ShaderVariableManagerVk::ProcessSignatureResources(const PipelineResourceSignatureVkImpl& Signature, - const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, - Uint32 NumAllowedTypes, - SHADER_TYPE ShaderStages, - HandlerType Handler) -{ - const Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes); - const bool UsingSeparateSamplers = Signature.IsUsingSeparateSamplers(); - - for (Uint32 var_type = 0; var_type < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; ++var_type) - { - const auto VarType = static_cast(var_type); - if (IsAllowedType(VarType, AllowedTypeBits)) - { - const auto ResIdxRange = Signature.GetResourceIndexRange(VarType); - for (Uint32 r = ResIdxRange.first; r < ResIdxRange.second; ++r) - { - const auto& Res = Signature.GetResourceDesc(r); - const auto& Attr = Signature.GetResourceAttribs(r); - VERIFY_EXPR(Res.VarType == VarType); - - if ((Res.ShaderStages & ShaderStages) == 0) - continue; - - // When using HLSL-style combined image samplers, we need to skip separate samplers. - // Also always skip immutable separate samplers. - if (Res.ResourceType == SHADER_RESOURCE_TYPE_SAMPLER && - (!UsingSeparateSamplers || Attr.IsImmutableSamplerAssigned())) - continue; - - Handler(r); - } - } - } -} - -size_t ShaderVariableManagerVk::GetRequiredMemorySize(const PipelineResourceSignatureVkImpl& Signature, - const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, - Uint32 NumAllowedTypes, - SHADER_TYPE ShaderStages, - Uint32& NumVariables) -{ - NumVariables = 0; - ProcessSignatureResources(Signature, AllowedVarTypes, NumAllowedTypes, ShaderStages, - [&NumVariables](Uint32) // - { - ++NumVariables; - }); - - return NumVariables * sizeof(ShaderVariableVkImpl); -} - -// Creates shader variable for every resource from SrcLayout whose type is one AllowedVarTypes -void ShaderVariableManagerVk::Initialize(const PipelineResourceSignatureVkImpl& Signature, - IMemoryAllocator& Allocator, - const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, - Uint32 NumAllowedTypes, - SHADER_TYPE ShaderType) -{ -#ifdef DILIGENT_DEBUG - m_pDbgAllocator = &Allocator; -#endif - - VERIFY_EXPR(m_pSignature == nullptr); - - const Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes); - VERIFY_EXPR(m_NumVariables == 0); - const auto MemSize = GetRequiredMemorySize(Signature, AllowedVarTypes, NumAllowedTypes, ShaderType, m_NumVariables); - - if (m_NumVariables == 0) - return; - - auto* pRawMem = ALLOCATE_RAW(Allocator, "Raw memory buffer for shader variables", MemSize); - m_pVariables = reinterpret_cast(pRawMem); - - Uint32 VarInd = 0; - ProcessSignatureResources(Signature, AllowedVarTypes, NumAllowedTypes, ShaderType, - [this, &VarInd](Uint32 ResIndex) // - { - ::new (m_pVariables + VarInd) ShaderVariableVkImpl{*this, ResIndex}; - ++VarInd; - }); - VERIFY_EXPR(VarInd == m_NumVariables); - - m_pSignature = &Signature; -} - -ShaderVariableManagerVk::~ShaderVariableManagerVk() -{ - VERIFY(m_pVariables == nullptr, "Destroy() has not been called"); -} - -void ShaderVariableManagerVk::Destroy(IMemoryAllocator& Allocator) -{ - if (m_pVariables != nullptr) - { - VERIFY(m_pDbgAllocator == &Allocator, "Incosistent alloctor"); - - for (Uint32 v = 0; v < m_NumVariables; ++v) - m_pVariables[v].~ShaderVariableVkImpl(); - Allocator.Free(m_pVariables); - m_pVariables = nullptr; - } -} - -ShaderVariableVkImpl* ShaderVariableManagerVk::GetVariable(const Char* Name) const -{ - for (Uint32 v = 0; v < m_NumVariables; ++v) - { - auto& Var = m_pVariables[v]; - if (strcmp(Var.GetDesc().Name, Name) == 0) - return &Var; - } - return nullptr; -} - - -ShaderVariableVkImpl* ShaderVariableManagerVk::GetVariable(Uint32 Index) const -{ - if (Index >= m_NumVariables) - { - LOG_ERROR("Index ", Index, " is out of range"); - return nullptr; - } - - return m_pVariables + Index; -} - -Uint32 ShaderVariableManagerVk::GetVariableIndex(const ShaderVariableVkImpl& Variable) -{ - if (m_pVariables == nullptr) - { - LOG_ERROR("This shader variable manager has no variables"); - return ~0u; - } - - const auto Offset = reinterpret_cast(&Variable) - reinterpret_cast(m_pVariables); - DEV_CHECK_ERR(Offset % sizeof(ShaderVariableVkImpl) == 0, "Offset is not multiple of ShaderVariableVkImpl class size"); - const auto Index = static_cast(Offset / sizeof(ShaderVariableVkImpl)); - if (Index < m_NumVariables) - return Index; - else - { - LOG_ERROR("Failed to get variable index. The variable ", &Variable, " does not belong to this shader variable manager"); - return ~0u; - } -} - -void ShaderVariableManagerVk::BindResources(IResourceMapping* pResourceMapping, Uint32 Flags) const -{ - if (!pResourceMapping) - { - LOG_ERROR_MESSAGE("Failed to bind resources: resource mapping is null"); - return; - } - - if ((Flags & BIND_SHADER_RESOURCES_UPDATE_ALL) == 0) - Flags |= BIND_SHADER_RESOURCES_UPDATE_ALL; - - for (Uint32 v = 0; v < m_NumVariables; ++v) - { - m_pVariables[v].BindResources(pResourceMapping, Flags); - } -} - -void ShaderVariableVkImpl::SetArray(IDeviceObject* const* ppObjects, - Uint32 FirstElement, - Uint32 NumElements) -{ - const auto& ResDesc = GetDesc(); - VerifyAndCorrectSetArrayArguments(ResDesc.Name, ResDesc.ArraySize, FirstElement, NumElements); - - for (Uint32 Elem = 0; Elem < NumElements; ++Elem) - BindResource(ppObjects[Elem], FirstElement + Elem); -} - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp index 740b66de..90a7cf9c 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp @@ -25,11 +25,13 @@ * of the possibility of such damages. */ -#include -#include #include "pch.h" #include "ShaderVkImpl.hpp" + +#include +#include + #include "RenderDeviceVkImpl.hpp" #include "DataBlobImpl.hpp" #include "GLSLUtils.hpp" diff --git a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp index bd7c0d55..5135067b 100644 --- a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp @@ -29,8 +29,8 @@ #include "SwapChainVkImpl.hpp" #include "RenderDeviceVkImpl.hpp" #include "DeviceContextVkImpl.hpp" -#include "VulkanTypeConversions.hpp" #include "TextureVkImpl.hpp" +#include "VulkanTypeConversions.hpp" #include "EngineMemory.h" namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/src/TextureViewVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/TextureViewVkImpl.cpp index eeeb6002..03356eef 100644 --- a/Graphics/GraphicsEngineVulkan/src/TextureViewVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/TextureViewVkImpl.cpp @@ -27,8 +27,8 @@ #include "pch.h" #include "TextureViewVkImpl.hpp" -#include "DeviceContextVkImpl.hpp" #include "RenderDeviceVkImpl.hpp" +#include "DeviceContextVkImpl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp index 8cf3dbee..6b4d538e 100644 --- a/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp @@ -29,7 +29,6 @@ #include "TextureVkImpl.hpp" #include "RenderDeviceVkImpl.hpp" #include "DeviceContextVkImpl.hpp" -#include "VulkanTypeConversions.hpp" #include "TextureViewVkImpl.hpp" #include "VulkanTypeConversions.hpp" #include "EngineMemory.h" diff --git a/Graphics/GraphicsEngineVulkan/src/TopLevelASVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/TopLevelASVkImpl.cpp index c427fc79..2c0de29a 100644 --- a/Graphics/GraphicsEngineVulkan/src/TopLevelASVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/TopLevelASVkImpl.cpp @@ -27,6 +27,7 @@ #include "pch.h" #include "TopLevelASVkImpl.hpp" +#include "RenderDeviceVkImpl.hpp" #include "VulkanTypeConversions.hpp" namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanDynamicHeap.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanDynamicHeap.cpp index 0eb4fcf4..c2a9f6e6 100644 --- a/Graphics/GraphicsEngineVulkan/src/VulkanDynamicHeap.cpp +++ b/Graphics/GraphicsEngineVulkan/src/VulkanDynamicHeap.cpp @@ -26,9 +26,12 @@ */ #include "pch.h" + +#include "VulkanDynamicHeap.hpp" + #include #include -#include "VulkanDynamicHeap.hpp" + #include "RenderDeviceVkImpl.hpp" namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp index 56a4a871..22e8aa10 100644 --- a/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp +++ b/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp @@ -26,10 +26,12 @@ */ #include "pch.h" + +#include "VulkanTypeConversions.hpp" + #include #include -#include "VulkanTypeConversions.hpp" #include "PlatformMisc.hpp" #include "Align.hpp" #include "BasicMath.hpp" -- cgit v1.2.3