From 59bcca99a11243873bf259385705dacd6bb70fea Mon Sep 17 00:00:00 2001 From: assiduous Date: Sun, 7 Mar 2021 15:22:38 -0800 Subject: Implemented common PRS methods directly in PipelineResourceSignatureBase; refactored include dependencies in D3D12 backend --- Graphics/GraphicsEngineD3D12/CMakeLists.txt | 5 +- .../include/BottomLevelASD3D12Impl.hpp | 2 +- .../include/BufferD3D12Impl.hpp | 4 +- .../include/BufferViewD3D12Impl.hpp | 4 +- .../include/CommandListD3D12Impl.hpp | 1 - .../include/CommandQueueD3D12Impl.hpp | 5 +- Graphics/GraphicsEngineD3D12/include/D3D12Utils.h | 1 + .../GraphicsEngineD3D12/include/DescriptorHeap.hpp | 2 +- .../include/DeviceContextD3D12Impl.hpp | 11 +- .../GraphicsEngineD3D12/include/FenceD3D12Impl.hpp | 2 +- .../include/FramebufferD3D12Impl.hpp | 2 +- .../GraphicsEngineD3D12/include/GenerateMips.hpp | 2 + .../include/PipelineResourceAttribsD3D12.hpp | 135 ++++++++++++ .../include/PipelineResourceSignatureD3D12Impl.hpp | 109 +--------- .../include/PipelineStateD3D12Impl.hpp | 4 +- .../GraphicsEngineD3D12/include/QueryD3D12Impl.hpp | 8 +- .../include/RenderPassD3D12Impl.hpp | 2 +- .../GraphicsEngineD3D12/include/RootSignature.hpp | 3 +- .../include/SamplerD3D12Impl.hpp | 2 +- .../include/ShaderBindingTableD3D12Impl.hpp | 4 +- .../include/ShaderD3D12Impl.hpp | 2 +- .../include/ShaderResourceBindingD3D12Impl.hpp | 11 +- .../include/ShaderResourceCacheD3D12.hpp | 2 +- .../include/ShaderVariableD3D12.hpp | 240 --------------------- .../include/ShaderVariableManagerD3D12.hpp | 230 ++++++++++++++++++++ .../include/TextureD3D12Impl.hpp | 3 +- .../include/TextureViewD3D12Impl.hpp | 3 +- .../include/TopLevelASD3D12Impl.hpp | 6 +- .../src/BottomLevelASD3D12Impl.cpp | 1 + .../GraphicsEngineD3D12/src/BufferD3D12Impl.cpp | 2 +- .../src/BufferViewD3D12Impl.cpp | 5 + .../GraphicsEngineD3D12/src/CommandContext.cpp | 3 + .../src/FramebufferD3D12Impl.cpp | 1 + .../src/PipelineResourceSignatureD3D12Impl.cpp | 29 --- .../src/PipelineStateD3D12Impl.cpp | 4 +- .../GraphicsEngineD3D12/src/QueryD3D12Impl.cpp | 7 + .../src/RenderPassD3D12Impl.cpp | 1 + Graphics/GraphicsEngineD3D12/src/RootSignature.cpp | 1 + .../GraphicsEngineD3D12/src/SamplerD3D12Impl.cpp | 1 + .../src/ShaderBindingTableD3D12Impl.cpp | 1 + .../src/ShaderResourceBindingD3D12Impl.cpp | 2 + .../src/ShaderResourceCacheD3D12.cpp | 4 +- .../src/ShaderVariableD3D12.cpp | 205 ------------------ .../src/ShaderVariableManagerD3D12.cpp | 230 ++++++++++++++++++++ .../GraphicsEngineD3D12/src/TextureD3D12Impl.cpp | 1 + .../src/TextureViewD3D12Impl.cpp | 2 + .../src/TopLevelASD3D12Impl.cpp | 1 + 47 files changed, 685 insertions(+), 621 deletions(-) create mode 100644 Graphics/GraphicsEngineD3D12/include/PipelineResourceAttribsD3D12.hpp delete mode 100644 Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.hpp create mode 100644 Graphics/GraphicsEngineD3D12/include/ShaderVariableManagerD3D12.hpp delete mode 100644 Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp create mode 100644 Graphics/GraphicsEngineD3D12/src/ShaderVariableManagerD3D12.cpp (limited to 'Graphics/GraphicsEngineD3D12') diff --git a/Graphics/GraphicsEngineD3D12/CMakeLists.txt b/Graphics/GraphicsEngineD3D12/CMakeLists.txt index a497ad68..87262891 100644 --- a/Graphics/GraphicsEngineD3D12/CMakeLists.txt +++ b/Graphics/GraphicsEngineD3D12/CMakeLists.txt @@ -34,7 +34,7 @@ set(INCLUDE include/ShaderResourceBindingD3D12Impl.hpp include/ShaderResourceCacheD3D12.hpp include/ShaderResourcesD3D12.hpp - include/ShaderVariableD3D12.hpp + include/ShaderVariableManagerD3D12.hpp include/SwapChainD3D12Impl.hpp include/TextureD3D12Impl.hpp include/TextureViewD3D12Impl.hpp @@ -42,6 +42,7 @@ set(INCLUDE include/TopLevelASD3D12Impl.hpp include/ShaderBindingTableD3D12Impl.hpp include/PipelineResourceSignatureD3D12Impl.hpp + include/PipelineResourceAttribsD3D12.hpp ) set(INTERFACE @@ -93,7 +94,7 @@ set(SRC src/ShaderResourceBindingD3D12Impl.cpp src/ShaderResourceCacheD3D12.cpp src/ShaderResourcesD3D12.cpp - src/ShaderVariableD3D12.cpp + src/ShaderVariableManagerD3D12.cpp src/SwapChainD3D12Impl.cpp src/TextureD3D12Impl.cpp src/TextureViewD3D12Impl.cpp diff --git a/Graphics/GraphicsEngineD3D12/include/BottomLevelASD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/BottomLevelASD3D12Impl.hpp index 9ffba139..4ab720e7 100644 --- a/Graphics/GraphicsEngineD3D12/include/BottomLevelASD3D12Impl.hpp +++ b/Graphics/GraphicsEngineD3D12/include/BottomLevelASD3D12Impl.hpp @@ -30,11 +30,11 @@ /// \file /// Declaration of Diligent::BottomLevelASD3D12Impl class +#include "EngineD3D12ImplTraits.hpp" #include "BottomLevelASD3D12.h" #include "RenderDeviceD3D12.h" #include "BottomLevelASBase.hpp" #include "D3D12ResourceBase.hpp" -#include "RenderDeviceD3D12Impl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineD3D12/include/BufferD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/BufferD3D12Impl.hpp index 49dbb25b..c2053c03 100644 --- a/Graphics/GraphicsEngineD3D12/include/BufferD3D12Impl.hpp +++ b/Graphics/GraphicsEngineD3D12/include/BufferD3D12Impl.hpp @@ -30,13 +30,13 @@ /// \file /// Declaration of Diligent::BufferD3D12Impl class +#include "EngineD3D12ImplTraits.hpp" #include "BufferD3D12.h" #include "RenderDeviceD3D12.h" #include "BufferBase.hpp" -#include "BufferViewD3D12Impl.hpp" #include "D3D12ResourceBase.hpp" #include "D3D12DynamicHeap.hpp" -#include "RenderDeviceD3D12Impl.hpp" +#include "BufferViewD3D12Impl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineD3D12/include/BufferViewD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/BufferViewD3D12Impl.hpp index beeeeb49..d9bdc9b1 100644 --- a/Graphics/GraphicsEngineD3D12/include/BufferViewD3D12Impl.hpp +++ b/Graphics/GraphicsEngineD3D12/include/BufferViewD3D12Impl.hpp @@ -30,11 +30,11 @@ /// \file /// Declaration of Diligent::BufferViewD3D12Impl class +#include "EngineD3D12ImplTraits.hpp" #include "BufferViewD3D12.h" #include "RenderDeviceD3D12.h" #include "BufferViewBase.hpp" #include "DescriptorHeap.hpp" -#include "RenderDeviceD3D12Impl.hpp" namespace Diligent { @@ -52,6 +52,8 @@ public: DescriptorHeapAllocation&& HandleAlloc, bool bIsDefaultView); + ~BufferViewD3D12Impl(); + IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_BufferViewD3D12, TBufferViewBase) /// Implementation of IBufferViewD3D12::GetCPUDescriptorHandle(). diff --git a/Graphics/GraphicsEngineD3D12/include/CommandListD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/CommandListD3D12Impl.hpp index 76f264d8..57f3d0e5 100644 --- a/Graphics/GraphicsEngineD3D12/include/CommandListD3D12Impl.hpp +++ b/Graphics/GraphicsEngineD3D12/include/CommandListD3D12Impl.hpp @@ -37,7 +37,6 @@ namespace Diligent { class DeviceContextD3D12Impl; -class CommandContext; /// Command list implementation in Direct3D12 backend. class CommandListD3D12Impl final : public CommandListBase diff --git a/Graphics/GraphicsEngineD3D12/include/CommandQueueD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/CommandQueueD3D12Impl.hpp index bc1e2a67..a3652103 100644 --- a/Graphics/GraphicsEngineD3D12/include/CommandQueueD3D12Impl.hpp +++ b/Graphics/GraphicsEngineD3D12/include/CommandQueueD3D12Impl.hpp @@ -30,11 +30,12 @@ /// \file /// Declaration of Diligent::CommandQueueD3D12Impl class -#include "CommandQueueD3D12.h" -#include "ObjectBase.hpp" #include #include +#include "CommandQueueD3D12.h" +#include "ObjectBase.hpp" + namespace Diligent { diff --git a/Graphics/GraphicsEngineD3D12/include/D3D12Utils.h b/Graphics/GraphicsEngineD3D12/include/D3D12Utils.h index e162c969..8b3ba7e4 100644 --- a/Graphics/GraphicsEngineD3D12/include/D3D12Utils.h +++ b/Graphics/GraphicsEngineD3D12/include/D3D12Utils.h @@ -28,6 +28,7 @@ #pragma once #include "BasicTypes.h" + namespace Diligent { diff --git a/Graphics/GraphicsEngineD3D12/include/DescriptorHeap.hpp b/Graphics/GraphicsEngineD3D12/include/DescriptorHeap.hpp index 3cf8d702..aaa9c0a7 100644 --- a/Graphics/GraphicsEngineD3D12/include/DescriptorHeap.hpp +++ b/Graphics/GraphicsEngineD3D12/include/DescriptorHeap.hpp @@ -36,7 +36,7 @@ #include #include #include -#include "ObjectBase.hpp" + #include "VariableSizeAllocationsManager.hpp" namespace Diligent diff --git a/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.hpp index 7fb46e60..06d2e117 100644 --- a/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.hpp +++ b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.hpp @@ -45,9 +45,14 @@ #include "BottomLevelASD3D12Impl.hpp" #include "TopLevelASD3D12Impl.hpp" + namespace Diligent { +class CommandContext; +class GraphicsContext; +class ComputeContext; + /// Device context implementation in Direct3D12 backend. class DeviceContextD3D12Impl final : public DeviceContextNextGenBase { @@ -326,10 +331,10 @@ public: private: void CommitD3D12IndexBuffer(GraphicsContext& GraphCtx, VALUE_TYPE IndexType); - void CommitD3D12VertexBuffers(class GraphicsContext& GraphCtx); + void CommitD3D12VertexBuffers(GraphicsContext& GraphCtx); void CommitRenderTargets(RESOURCE_STATE_TRANSITION_MODE StateTransitionMode); void CommitViewports(); - void CommitScissorRects(class GraphicsContext& GraphCtx, bool ScissorEnable); + void CommitScissorRects(GraphicsContext& GraphCtx, bool ScissorEnable); void TransitionSubpassAttachments(Uint32 NextSubpass); void CommitSubpassRenderTargets(); void Flush(bool RequestNewCmdCtx, @@ -417,7 +422,7 @@ private: friend class SwapChainD3D12Impl; - inline class CommandContext& GetCmdContext() + inline CommandContext& GetCmdContext() { // Make sure that the number of commands in the context is at least one, // so that the context cannot be disposed by Flush() diff --git a/Graphics/GraphicsEngineD3D12/include/FenceD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/FenceD3D12Impl.hpp index 81437a65..28a9c1f3 100644 --- a/Graphics/GraphicsEngineD3D12/include/FenceD3D12Impl.hpp +++ b/Graphics/GraphicsEngineD3D12/include/FenceD3D12Impl.hpp @@ -30,10 +30,10 @@ /// \file /// Declaration of Diligent::FenceD3D12Impl class +#include "EngineD3D12ImplTraits.hpp" #include "FenceD3D12.h" #include "RenderDeviceD3D12.h" #include "FenceBase.hpp" -#include "RenderDeviceD3D12Impl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineD3D12/include/FramebufferD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/FramebufferD3D12Impl.hpp index 243107e4..43be86ff 100644 --- a/Graphics/GraphicsEngineD3D12/include/FramebufferD3D12Impl.hpp +++ b/Graphics/GraphicsEngineD3D12/include/FramebufferD3D12Impl.hpp @@ -30,9 +30,9 @@ /// \file /// Declaration of Diligent::FramebufferD3D12Impl class +#include "EngineD3D12ImplTraits.hpp" #include "RenderDeviceD3D12.h" #include "FramebufferBase.hpp" -#include "RenderDeviceD3D12Impl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineD3D12/include/GenerateMips.hpp b/Graphics/GraphicsEngineD3D12/include/GenerateMips.hpp index a2c43444..6ab189aa 100644 --- a/Graphics/GraphicsEngineD3D12/include/GenerateMips.hpp +++ b/Graphics/GraphicsEngineD3D12/include/GenerateMips.hpp @@ -51,6 +51,7 @@ namespace Diligent { + class GenerateMipsHelper { public: @@ -63,4 +64,5 @@ private: CComPtr m_pGenerateMipsLinearPSO[4]; CComPtr m_pGenerateMipsGammaPSO[4]; }; + } // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D12/include/PipelineResourceAttribsD3D12.hpp b/Graphics/GraphicsEngineD3D12/include/PipelineResourceAttribsD3D12.hpp new file mode 100644 index 00000000..7f7daad5 --- /dev/null +++ b/Graphics/GraphicsEngineD3D12/include/PipelineResourceAttribsD3D12.hpp @@ -0,0 +1,135 @@ +/* + * 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::PipelineResourceAttribsD3D12 struct + +#include "BasicTypes.h" +#include "PrivateConstants.h" +#include "ShaderResourceCacheCommon.hpp" +#include "DebugUtilities.hpp" + +namespace Diligent +{ +// sizeof(ResourceAttribs) == 16, x64 +struct PipelineResourceAttribsD3D12 +{ +private: + static constexpr Uint32 _RegisterBits = 16; + static constexpr Uint32 _SRBRootIndexBits = 16; + static constexpr Uint32 _SamplerIndBits = 16; + static constexpr Uint32 _SpaceBits = 8; + static constexpr Uint32 _SigRootIndexBits = 3; + static constexpr Uint32 _SamplerAssignedBits = 1; + static constexpr Uint32 _RootParamTypeBits = 3; + + // clang-format off + static_assert((1u << _RegisterBits) >= MAX_RESOURCES_IN_SIGNATURE, "Not enough bits to store shader register"); + static_assert((1u << _SamplerIndBits) >= MAX_RESOURCES_IN_SIGNATURE, "Not enough bits to store sampler resource index"); + static_assert((1u << _RootParamTypeBits) > D3D12_ROOT_PARAMETER_TYPE_UAV + 1, "Not enough bits to store D3D12_ROOT_PARAMETER_TYPE"); + // clang-format on + +public: + static constexpr Uint32 InvalidSamplerInd = (1u << _SamplerIndBits) - 1; + static constexpr Uint32 InvalidSRBRootIndex = (1u << _SRBRootIndexBits) - 1; + static constexpr Uint32 InvalidSigRootIndex = (1u << _SigRootIndexBits) - 1; + static constexpr Uint32 InvalidRegister = (1u << _RegisterBits) - 1; + static constexpr Uint32 InvalidOffset = ~0u; + + // clang-format off +/* 0 */const Uint32 Register : _RegisterBits; // Shader register +/* 2 */const Uint32 SRBRootIndex : _SRBRootIndexBits; // Root view/table index in the SRB +/* 4 */const Uint32 SamplerInd : _SamplerIndBits; // Assigned sampler index in m_Desc.Resources and m_pResourceAttribs +/* 6 */const Uint32 Space : _SpaceBits; // Shader register space +/* 7.0*/const Uint32 SigRootIndex : _SigRootIndexBits; // Root table index for signature (static resources only) +/* 7.3*/const Uint32 ImtblSamplerAssigned : _SamplerAssignedBits; // Immutable sampler flag +/* 7.4*/const Uint32 RootParamType : _RootParamTypeBits; // Root parameter type (D3D12_ROOT_PARAMETER_TYPE) +/* 8 */const Uint32 SigOffsetFromTableStart; // Offset in the root table for signature (static only) +/* 12 */const Uint32 SRBOffsetFromTableStart; // Offset in the root table for SRB +/* 16 */ + // clang-format on + + PipelineResourceAttribsD3D12(Uint32 _Register, + Uint32 _Space, + Uint32 _SamplerInd, + Uint32 _SRBRootIndex, + Uint32 _SRBOffsetFromTableStart, + Uint32 _SigRootIndex, + Uint32 _SigOffsetFromTableStart, + bool _ImtblSamplerAssigned, + D3D12_ROOT_PARAMETER_TYPE _RootParamType) noexcept : + // clang-format off + Register {_Register }, + SRBRootIndex {_SRBRootIndex }, + SamplerInd {_SamplerInd }, + SigRootIndex {_SigRootIndex }, + Space {_Space }, + ImtblSamplerAssigned {_ImtblSamplerAssigned ? 1u : 0u }, + RootParamType {static_cast(_RootParamType)}, + SigOffsetFromTableStart{_SigOffsetFromTableStart }, + SRBOffsetFromTableStart{_SRBOffsetFromTableStart } + // clang-format on + { + VERIFY(Register == _Register, "Shader register (", _Register, ") exceeds maximum representable value"); + VERIFY(SRBRootIndex == _SRBRootIndex, "SRB Root index (", _SRBRootIndex, ") exceeds maximum representable value"); + VERIFY(SigRootIndex == _SigRootIndex, "Signature Root index (", _SigRootIndex, ") exceeds maximum representable value"); + VERIFY(SamplerInd == _SamplerInd, "Sampler index (", _SamplerInd, ") exceeds maximum representable value"); + VERIFY(Space == _Space, "Space (", _Space, ") exceeds maximum representable value"); + VERIFY(GetD3D12RootParamType() == _RootParamType, "Not enough bits to represent root parameter type"); + } + + bool IsImmutableSamplerAssigned() const + { + return ImtblSamplerAssigned != 0; + } + bool IsCombinedWithSampler() const + { + return SamplerInd != InvalidSamplerInd; + } + + Uint32 RootIndex(ResourceCacheContentType Type) const + { + return Type == ResourceCacheContentType::SRB ? SRBRootIndex : SigRootIndex; + } + Uint32 OffsetFromTableStart(ResourceCacheContentType Type) const + { + return Type == ResourceCacheContentType::SRB ? SRBOffsetFromTableStart : SigOffsetFromTableStart; + } + + D3D12_ROOT_PARAMETER_TYPE GetD3D12RootParamType() const { return static_cast(RootParamType); } + + bool IsRootView() const + { + return (GetD3D12RootParamType() == D3D12_ROOT_PARAMETER_TYPE_CBV || + GetD3D12RootParamType() == D3D12_ROOT_PARAMETER_TYPE_SRV || + GetD3D12RootParamType() == D3D12_ROOT_PARAMETER_TYPE_UAV); + } +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D12/include/PipelineResourceSignatureD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/PipelineResourceSignatureD3D12Impl.hpp index d68385f3..fba59c35 100644 --- a/Graphics/GraphicsEngineD3D12/include/PipelineResourceSignatureD3D12Impl.hpp +++ b/Graphics/GraphicsEngineD3D12/include/PipelineResourceSignatureD3D12Impl.hpp @@ -33,17 +33,22 @@ #include #include "EngineD3D12ImplTraits.hpp" +#include "PipelineResourceAttribsD3D12.hpp" #include "PipelineResourceSignatureBase.hpp" #include "SRBMemoryAllocator.hpp" #include "RootParamsManager.hpp" -#include "ShaderResourceCacheD3D12.hpp" #include "ResourceBindingMap.hpp" +// ShaderVariableManagerD3D12, ShaderResourceCacheD3D12, and ShaderResourceBindingD3D12Impl +// are required by PipelineResourceSignatureBase +#include "ShaderResourceCacheD3D12.hpp" +#include "ShaderVariableManagerD3D12.hpp" +#include "ShaderResourceBindingD3D12Impl.hpp" + namespace Diligent { class CommandContext; -class ShaderVariableManagerD3D12; struct D3DShaderResourceAttribs; /// Implementation of the Diligent::PipelineResourceSignatureD3D12Impl class @@ -58,92 +63,7 @@ public: bool bIsDeviceInternal = false); ~PipelineResourceSignatureD3D12Impl(); - // sizeof(ResourceAttribs) == 16, x64 - struct ResourceAttribs - { - private: - static constexpr Uint32 _RegisterBits = 16; - static constexpr Uint32 _SRBRootIndexBits = 16; - static constexpr Uint32 _SamplerIndBits = 16; - static constexpr Uint32 _SpaceBits = 8; - static constexpr Uint32 _SigRootIndexBits = 3; - static constexpr Uint32 _SamplerAssignedBits = 1; - static constexpr Uint32 _RootParamTypeBits = 3; - - static_assert((1u << _RegisterBits) >= MAX_RESOURCES_IN_SIGNATURE, "Not enough bits to store shader register"); - static_assert((1u << _SamplerIndBits) >= MAX_RESOURCES_IN_SIGNATURE, "Not enough bits to store sampler resource index"); - static_assert((1u << _RootParamTypeBits) > D3D12_ROOT_PARAMETER_TYPE_UAV + 1, "Not enough bits to store D3D12_ROOT_PARAMETER_TYPE"); - - public: - static constexpr Uint32 InvalidSamplerInd = (1u << _SamplerIndBits) - 1; - static constexpr Uint32 InvalidSRBRootIndex = (1u << _SRBRootIndexBits) - 1; - static constexpr Uint32 InvalidSigRootIndex = (1u << _SigRootIndexBits) - 1; - static constexpr Uint32 InvalidRegister = (1u << _RegisterBits) - 1; - static constexpr Uint32 InvalidOffset = ~0u; - - // clang-format off -/* 0 */const Uint32 Register : _RegisterBits; // Shader register -/* 2 */const Uint32 SRBRootIndex : _SRBRootIndexBits; // Root view/table index in the SRB -/* 4 */const Uint32 SamplerInd : _SamplerIndBits; // Assigned sampler index in m_Desc.Resources and m_pResourceAttribs -/* 6 */const Uint32 Space : _SpaceBits; // Shader register space -/* 7.0*/const Uint32 SigRootIndex : _SigRootIndexBits; // Root table index for signature (static resources only) -/* 7.3*/const Uint32 ImtblSamplerAssigned : _SamplerAssignedBits; // Immutable sampler flag -/* 7.4*/const Uint32 RootParamType : _RootParamTypeBits; // Root parameter type (D3D12_ROOT_PARAMETER_TYPE) -/* 8 */const Uint32 SigOffsetFromTableStart; // Offset in the root table for signature (static only) -/* 12 */const Uint32 SRBOffsetFromTableStart; // Offset in the root table for SRB -/* 16 */ - // clang-format on - - ResourceAttribs(Uint32 _Register, - Uint32 _Space, - Uint32 _SamplerInd, - Uint32 _SRBRootIndex, - Uint32 _SRBOffsetFromTableStart, - Uint32 _SigRootIndex, - Uint32 _SigOffsetFromTableStart, - bool _ImtblSamplerAssigned, - D3D12_ROOT_PARAMETER_TYPE _RootParamType) noexcept : - // clang-format off - Register {_Register }, - SRBRootIndex {_SRBRootIndex }, - SamplerInd {_SamplerInd }, - SigRootIndex {_SigRootIndex }, - Space {_Space }, - ImtblSamplerAssigned {_ImtblSamplerAssigned ? 1u : 0u }, - RootParamType {static_cast(_RootParamType)}, - SigOffsetFromTableStart{_SigOffsetFromTableStart }, - SRBOffsetFromTableStart{_SRBOffsetFromTableStart } - // clang-format on - { - VERIFY(Register == _Register, "Shader register (", _Register, ") exceeds maximum representable value"); - VERIFY(SRBRootIndex == _SRBRootIndex, "SRB Root index (", _SRBRootIndex, ") exceeds maximum representable value"); - VERIFY(SigRootIndex == _SigRootIndex, "Signature Root index (", _SigRootIndex, ") exceeds maximum representable value"); - VERIFY(SamplerInd == _SamplerInd, "Sampler index (", _SamplerInd, ") exceeds maximum representable value"); - VERIFY(Space == _Space, "Space (", _Space, ") exceeds maximum representable value"); - VERIFY(GetD3D12RootParamType() == _RootParamType, "Not enough bits to represent root parameter type"); - } - - bool IsImmutableSamplerAssigned() const { return ImtblSamplerAssigned != 0; } - bool IsCombinedWithSampler() const { return SamplerInd != InvalidSamplerInd; } - - Uint32 RootIndex(ResourceCacheContentType Type) const - { - return Type == ResourceCacheContentType::SRB ? SRBRootIndex : SigRootIndex; - } - Uint32 OffsetFromTableStart(ResourceCacheContentType Type) const - { - return Type == ResourceCacheContentType::SRB ? SRBOffsetFromTableStart : SigOffsetFromTableStart; - } - - D3D12_ROOT_PARAMETER_TYPE GetD3D12RootParamType() const { return static_cast(RootParamType); } - - bool IsRootView() const - { - return (GetD3D12RootParamType() == D3D12_ROOT_PARAMETER_TYPE_CBV || - GetD3D12RootParamType() == D3D12_ROOT_PARAMETER_TYPE_SRV || - GetD3D12RootParamType() == D3D12_ROOT_PARAMETER_TYPE_UAV); - } - }; + using ResourceAttribs = PipelineResourceAttribsD3D12; const ResourceAttribs& GetResourceAttribs(Uint32 ResIndex) const { @@ -210,19 +130,6 @@ public: return m_RootParams.GetNumRootViews(); } - virtual void DILIGENT_CALL_TYPE CreateShaderResourceBinding(IShaderResourceBinding** ppShaderResourceBinding, - bool InitStaticResources) override final; - - virtual IShaderResourceVariable* DILIGENT_CALL_TYPE GetStaticVariableByName(SHADER_TYPE ShaderType, const Char* Name) override final; - - virtual IShaderResourceVariable* DILIGENT_CALL_TYPE GetStaticVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index) override final; - - virtual Uint32 DILIGENT_CALL_TYPE GetStaticVariableCount(SHADER_TYPE ShaderType) const override final; - - virtual void DILIGENT_CALL_TYPE BindStaticResources(Uint32 ShaderFlags, - IResourceMapping* pResourceMapping, - Uint32 Flags) override final; - virtual bool DILIGENT_CALL_TYPE IsCompatibleWith(const IPipelineResourceSignature* pPRS) const override final { if (pPRS == nullptr) diff --git a/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.hpp index c8f35d36..8f8ee1cc 100644 --- a/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.hpp +++ b/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.hpp @@ -32,12 +32,12 @@ #include +#include "EngineD3D12ImplTraits.hpp" #include "RenderDeviceD3D12.h" #include "PipelineStateD3D12.h" -#include "PipelineResourceSignatureD3D12Impl.hpp" #include "PipelineStateBase.hpp" #include "RootSignature.hpp" -#include "RenderDeviceD3D12Impl.hpp" +#include "PipelineResourceSignatureD3D12Impl.hpp" // Requiured by PipelineStateBase namespace Diligent { diff --git a/Graphics/GraphicsEngineD3D12/include/QueryD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/QueryD3D12Impl.hpp index b39b37c5..2be65eaf 100644 --- a/Graphics/GraphicsEngineD3D12/include/QueryD3D12Impl.hpp +++ b/Graphics/GraphicsEngineD3D12/include/QueryD3D12Impl.hpp @@ -32,9 +32,10 @@ #include +#include "EngineD3D12ImplTraits.hpp" #include "QueryD3D12.h" #include "QueryBase.hpp" -#include "RenderDeviceD3D12Impl.hpp" +#include "QueryManagerD3D12.hpp" namespace Diligent { @@ -58,10 +59,7 @@ public: virtual bool DILIGENT_CALL_TYPE GetData(void* pData, Uint32 DataSize, bool AutoInvalidate) override final; /// Implementation of IQueryD3D12::GetD3D12QueryHeap(). - virtual ID3D12QueryHeap* DILIGENT_CALL_TYPE GetD3D12QueryHeap() override final - { - return m_pDevice->GetQueryManager().GetQueryHeap(m_Desc.Type); - } + virtual ID3D12QueryHeap* DILIGENT_CALL_TYPE GetD3D12QueryHeap() override final; /// Implementation of IQueryD3D12::GetQueryHeapIndex(). virtual Uint32 DILIGENT_CALL_TYPE GetQueryHeapIndex(Uint32 QueryId) const override final diff --git a/Graphics/GraphicsEngineD3D12/include/RenderPassD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/RenderPassD3D12Impl.hpp index 750a3381..e8967046 100644 --- a/Graphics/GraphicsEngineD3D12/include/RenderPassD3D12Impl.hpp +++ b/Graphics/GraphicsEngineD3D12/include/RenderPassD3D12Impl.hpp @@ -30,9 +30,9 @@ /// \file /// Declaration of Diligent::RenderPassD3D12Impl class +#include "EngineD3D12ImplTraits.hpp" #include "RenderDeviceD3D12.h" #include "RenderPassBase.hpp" -#include "RenderDeviceD3D12Impl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineD3D12/include/RootSignature.hpp b/Graphics/GraphicsEngineD3D12/include/RootSignature.hpp index 497cf11d..45ec655b 100644 --- a/Graphics/GraphicsEngineD3D12/include/RootSignature.hpp +++ b/Graphics/GraphicsEngineD3D12/include/RootSignature.hpp @@ -51,9 +51,9 @@ #include #include -#include "PipelineResourceSignatureD3D12Impl.hpp" #include "PrivateConstants.h" #include "ShaderResources.hpp" +#include "ObjectBase.hpp" #include "ResourceBindingMap.hpp" namespace Diligent @@ -61,6 +61,7 @@ namespace Diligent class RenderDeviceD3D12Impl; class RootSignatureCacheD3D12; +class PipelineResourceSignatureD3D12Impl; /// Implementation of the Diligent::RootSignature class class RootSignatureD3D12 final : public ObjectBase diff --git a/Graphics/GraphicsEngineD3D12/include/SamplerD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/SamplerD3D12Impl.hpp index 19c11df9..46940a78 100644 --- a/Graphics/GraphicsEngineD3D12/include/SamplerD3D12Impl.hpp +++ b/Graphics/GraphicsEngineD3D12/include/SamplerD3D12Impl.hpp @@ -30,11 +30,11 @@ /// \file /// Declaration of Diligent::SamplerD3D12Impl class +#include "EngineD3D12ImplTraits.hpp" #include "SamplerD3D12.h" #include "RenderDeviceD3D12.h" #include "SamplerBase.hpp" #include "DescriptorHeap.hpp" -#include "RenderDeviceD3D12Impl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderBindingTableD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/ShaderBindingTableD3D12Impl.hpp index ced783ba..960e69e7 100644 --- a/Graphics/GraphicsEngineD3D12/include/ShaderBindingTableD3D12Impl.hpp +++ b/Graphics/GraphicsEngineD3D12/include/ShaderBindingTableD3D12Impl.hpp @@ -30,13 +30,11 @@ /// \file /// Declaration of Diligent::ShaderBindingTableD3D12Impl class +#include "EngineD3D12ImplTraits.hpp" #include "ShaderBindingTableD3D12.h" -#include "RenderDeviceD3D12.h" #include "ShaderBindingTableBase.hpp" #include "TopLevelASD3D12Impl.hpp" #include "D3D12ResourceBase.hpp" -#include "RenderDeviceD3D12Impl.hpp" -#include "PipelineStateD3D12Impl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.hpp index cbdb0df3..711b1543 100644 --- a/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.hpp +++ b/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.hpp @@ -30,11 +30,11 @@ /// \file /// Declaration of Diligent::ShaderD3D12Impl class +#include "EngineD3D12ImplTraits.hpp" #include "RenderDeviceD3D12.h" #include "ShaderD3D12.h" #include "ShaderBase.hpp" #include "ShaderD3DBase.hpp" -#include "RenderDeviceD3D12Impl.hpp" #include "ShaderResourcesD3D12.hpp" namespace Diligent diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.hpp index 105f6e8d..75009356 100644 --- a/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.hpp +++ b/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.hpp @@ -30,16 +30,19 @@ /// \file /// Declaration of Diligent::ShaderResourceBindingD3D12Impl class -#include "ShaderResourceBindingD3D12.h" -#include "RenderDeviceD3D12.h" +#include "EngineD3D12ImplTraits.hpp" #include "ShaderResourceBindingBase.hpp" +#include "ShaderResourceBindingD3D12.h" + +// ShaderVariableManagerD3D12 and ShaderResourceCacheD3D12 are required by ShaderResourceBindingBase +#include "ShaderVariableManagerD3D12.hpp" #include "ShaderResourceCacheD3D12.hpp" -#include "ShaderVariableD3D12.hpp" -#include "PipelineResourceSignatureD3D12Impl.hpp" namespace Diligent { +class PipelineResourceSignatureD3D12Impl; + /// Implementation of the Diligent::IShaderResourceBindingD3D12 interface // sizeof(ShaderResourceBindingD3D12Impl) == 96 (x64, msvc, Release) class ShaderResourceBindingD3D12Impl final : public ShaderResourceBindingBase diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderResourceCacheD3D12.hpp b/Graphics/GraphicsEngineD3D12/include/ShaderResourceCacheD3D12.hpp index 4177fcc1..683846c9 100644 --- a/Graphics/GraphicsEngineD3D12/include/ShaderResourceCacheD3D12.hpp +++ b/Graphics/GraphicsEngineD3D12/include/ShaderResourceCacheD3D12.hpp @@ -105,8 +105,8 @@ #include #include -#include "DescriptorHeap.hpp" #include "Shader.h" +#include "DescriptorHeap.hpp" #include "RootParamsManager.hpp" #include "ShaderResourceCacheCommon.hpp" diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.hpp b/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.hpp deleted file mode 100644 index ddcb29bf..00000000 --- a/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.hpp +++ /dev/null @@ -1,240 +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::ShaderVariableManagerD3D12 and Diligent::ShaderVariableD3D12Impl classes - -// -// * ShaderVariableManagerD3D12 keeps the list of variables of specific types -// * Every ShaderVariableD3D12Impl references ResourceAttribs by index from PipelineResourceSignatureD3D12Impl -// * ShaderVariableManagerD3D12 keeps reference to ShaderResourceCacheD3D12 -// * ShaderVariableManagerD3D12 is used by PipelineResourceSignatureD3D12Impl to manage static resources and by -// ShaderResourceBindingD3D12Impl to manage mutable and dynamic resources -// -// _____________________________ ________________________________________________________________________________ -// | | | | | | -// .----| ShaderVariableManagerD3D12 |---------------->| ShaderVariableD3D12Impl[0] | ShaderVariableD3D12Impl[1] | ... | -// | |_____________________________| |______________________________|_______________________________|_________________| -// | | | | -// | m_pSignature m_ResIndex m_ResIndex -// | | | | -// | _____________V____________________ __________V_______________________________V_________________________________ -// | | | m_pResourceAttribs | | | | | -// | |PipelineResourceSignatureD3D12Impl|------------------->| Resource[0] | Resource[1] | ... | Resource[s+m+d-1] | -// | |__________________________________| |__________________|__________________|_____________|________________________| -// | | | -// m_ResourceCache | | -// | | (RootTable, Offset) / (RootTable, Offset) -// | \ / -// | __________________________ _______________V________________________________________________V_______ -// | | | | | -// '--->| ShaderResourceCacheD3D12 |---------------->| Resources | -// |__________________________| |________________________________________________________________________| -// - -#include "ShaderResourceVariableD3D.h" -#include "ShaderResourceVariableBase.hpp" -#include "ShaderResourceCacheD3D12.hpp" -#include "PipelineResourceSignatureD3D12Impl.hpp" - -namespace Diligent -{ - -class ShaderVariableD3D12Impl; - -// sizeof(ShaderVariableManagerD3D12) == 40 (x64, msvc, Release) -class ShaderVariableManagerD3D12 -{ -public: - ShaderVariableManagerD3D12(IObject& Owner, - ShaderResourceCacheD3D12& ResourceCache) noexcept : - m_Owner{Owner}, - m_ResourceCache{ResourceCache} - {} - - // clang-format off - ShaderVariableManagerD3D12 (const ShaderVariableManagerD3D12&) = delete; - ShaderVariableManagerD3D12 ( ShaderVariableManagerD3D12&&) = delete; - ShaderVariableManagerD3D12& operator= (const ShaderVariableManagerD3D12&) = delete; - ShaderVariableManagerD3D12& operator= ( ShaderVariableManagerD3D12&&) = delete; - // clang-format on - - void Initialize(const PipelineResourceSignatureD3D12Impl& Signature, - IMemoryAllocator& Allocator, - const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, - Uint32 NumAllowedTypes, - SHADER_TYPE ShaderStages); - ~ShaderVariableManagerD3D12(); - - void Destroy(IMemoryAllocator& Allocator); - - ShaderVariableD3D12Impl* GetVariable(const Char* Name) const; - ShaderVariableD3D12Impl* GetVariable(Uint32 Index) const; - - void BindResources(IResourceMapping* pResourceMapping, Uint32 Flags); - - static size_t GetRequiredMemorySize(const PipelineResourceSignatureD3D12Impl& 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 ShaderVariableD3D12Impl; - using ResourceAttribs = PipelineResourceSignatureD3D12Impl::ResourceAttribs; - - Uint32 GetVariableIndex(const ShaderVariableD3D12Impl& Variable); - - const PipelineResourceDesc& GetResourceDesc(Uint32 Index) const - { - VERIFY_EXPR(m_pSignature != nullptr); - return m_pSignature->GetResourceDesc(Index); - } - const ResourceAttribs& GetResourceAttribs(Uint32 Index) const - { - VERIFY_EXPR(m_pSignature != nullptr); - return m_pSignature->GetResourceAttribs(Index); - } - - template - static void ProcessSignatureResources(const PipelineResourceSignatureD3D12Impl& Signature, - const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, - Uint32 NumAllowedTypes, - SHADER_TYPE ShaderStages, - HandlerType Handler); - -private: - PipelineResourceSignatureD3D12Impl const* m_pSignature = nullptr; - - IObject& m_Owner; - - // Variable manager is owned by either Pipeline Resource Signature (in which case m_ResourceCache references - // static resource cache owned by the same signature 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. - ShaderResourceCacheD3D12& m_ResourceCache; - - // Memory is allocated through the allocator provided by the pipeline 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. - ShaderVariableD3D12Impl* m_pVariables = nullptr; - Uint32 m_NumVariables = 0; - -#ifdef DILIGENT_DEBUG - IMemoryAllocator* m_pDbgAllocator = nullptr; -#endif -}; - -// sizeof(ShaderVariableD3D12Impl) == 24 (x64) -class ShaderVariableD3D12Impl final : public ShaderVariableBase -{ -public: - using TBase = ShaderVariableBase; - ShaderVariableD3D12Impl(ShaderVariableManagerD3D12& ParentManager, - Uint32 ResIndex) : - TBase{ParentManager}, - m_ResIndex{ResIndex} - {} - - // clang-format off - ShaderVariableD3D12Impl (const ShaderVariableD3D12Impl&) = delete; - ShaderVariableD3D12Impl ( ShaderVariableD3D12Impl&&) = delete; - ShaderVariableD3D12Impl& operator= (const ShaderVariableD3D12Impl&) = delete; - ShaderVariableD3D12Impl& operator= ( ShaderVariableD3D12Impl&&) = delete; - // clang-format on - - virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final - { - if (ppInterface == nullptr) - return; - - *ppInterface = nullptr; - if (IID == IID_ShaderResourceVariableD3D || IID == IID_ShaderResourceVariable || IID == IID_Unknown) - { - *ppInterface = this; - (*ppInterface)->AddRef(); - } - } - - 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); - } - - virtual void DILIGENT_CALL_TYPE GetHLSLResourceDesc(HLSLShaderResourceDesc& HLSLResDesc) const override final - { - GetResourceDesc(HLSLResDesc); - HLSLResDesc.ShaderRegister = GetAttribs().Register; - } - - 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 = PipelineResourceSignatureD3D12Impl::ResourceAttribs; - const ResourceAttribs& GetAttribs() const { return m_ParentManager.GetResourceAttribs(m_ResIndex); } - -private: - const Uint32 m_ResIndex; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderVariableManagerD3D12.hpp b/Graphics/GraphicsEngineD3D12/include/ShaderVariableManagerD3D12.hpp new file mode 100644 index 00000000..a67b977c --- /dev/null +++ b/Graphics/GraphicsEngineD3D12/include/ShaderVariableManagerD3D12.hpp @@ -0,0 +1,230 @@ +/* + * 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::ShaderVariableManagerD3D12 and Diligent::ShaderVariableD3D12Impl classes + +// +// * ShaderVariableManagerD3D12 keeps the list of variables of specific types +// * Every ShaderVariableD3D12Impl references ResourceAttribs by index from PipelineResourceSignatureD3D12Impl +// * ShaderVariableManagerD3D12 keeps reference to ShaderResourceCacheD3D12 +// * ShaderVariableManagerD3D12 is used by PipelineResourceSignatureD3D12Impl to manage static resources and by +// ShaderResourceBindingD3D12Impl to manage mutable and dynamic resources +// +// _____________________________ ________________________________________________________________________________ +// | | | | | | +// .----| ShaderVariableManagerD3D12 |---------------->| ShaderVariableD3D12Impl[0] | ShaderVariableD3D12Impl[1] | ... | +// | |_____________________________| |______________________________|_______________________________|_________________| +// | | | | +// | m_pSignature m_ResIndex m_ResIndex +// | | | | +// | _____________V____________________ __________V_______________________________V_________________________________ +// | | | m_pResourceAttribs | | | | | +// | |PipelineResourceSignatureD3D12Impl|------------------->| Resource[0] | Resource[1] | ... | Resource[s+m+d-1] | +// | |__________________________________| |__________________|__________________|_____________|________________________| +// | | | +// m_ResourceCache | | +// | | (RootTable, Offset) / (RootTable, Offset) +// | \ / +// | __________________________ _______________V________________________________________________V_______ +// | | | | | +// '--->| ShaderResourceCacheD3D12 |---------------->| Resources | +// |__________________________| |________________________________________________________________________| +// + +#include "ShaderResourceVariableD3D.h" +#include "ShaderResourceVariableBase.hpp" +#include "PipelineResourceAttribsD3D12.hpp" + +namespace Diligent +{ + +class ShaderVariableD3D12Impl; +class ShaderResourceCacheD3D12; +class PipelineResourceSignatureD3D12Impl; + +// sizeof(ShaderVariableManagerD3D12) == 40 (x64, msvc, Release) +class ShaderVariableManagerD3D12 +{ +public: + ShaderVariableManagerD3D12(IObject& Owner, + ShaderResourceCacheD3D12& ResourceCache) noexcept : + m_Owner{Owner}, + m_ResourceCache{ResourceCache} + {} + + // clang-format off + ShaderVariableManagerD3D12 (const ShaderVariableManagerD3D12&) = delete; + ShaderVariableManagerD3D12 ( ShaderVariableManagerD3D12&&) = delete; + ShaderVariableManagerD3D12& operator= (const ShaderVariableManagerD3D12&) = delete; + ShaderVariableManagerD3D12& operator= ( ShaderVariableManagerD3D12&&) = delete; + // clang-format on + + void Initialize(const PipelineResourceSignatureD3D12Impl& Signature, + IMemoryAllocator& Allocator, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes, + SHADER_TYPE ShaderStages); + ~ShaderVariableManagerD3D12(); + + void Destroy(IMemoryAllocator& Allocator); + + ShaderVariableD3D12Impl* GetVariable(const Char* Name) const; + ShaderVariableD3D12Impl* GetVariable(Uint32 Index) const; + + void BindResources(IResourceMapping* pResourceMapping, Uint32 Flags); + + static size_t GetRequiredMemorySize(const PipelineResourceSignatureD3D12Impl& 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 ShaderVariableD3D12Impl; + using ResourceAttribs = PipelineResourceAttribsD3D12; + + Uint32 GetVariableIndex(const ShaderVariableD3D12Impl& Variable); + + // These methods can't be defined in the header due to dependency on PipelineResourceSignatureD3D12Impl + const PipelineResourceDesc& GetResourceDesc(Uint32 Index) const; + const ResourceAttribs& GetResourceAttribs(Uint32 Index) const; + + template + static void ProcessSignatureResources(const PipelineResourceSignatureD3D12Impl& Signature, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes, + SHADER_TYPE ShaderStages, + HandlerType Handler); + +private: + PipelineResourceSignatureD3D12Impl const* m_pSignature = nullptr; + + IObject& m_Owner; + + // Variable manager is owned by either Pipeline Resource Signature (in which case m_ResourceCache references + // static resource cache owned by the same signature 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. + ShaderResourceCacheD3D12& m_ResourceCache; + + // Memory is allocated through the allocator provided by the pipeline 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. + ShaderVariableD3D12Impl* m_pVariables = nullptr; + Uint32 m_NumVariables = 0; + +#ifdef DILIGENT_DEBUG + IMemoryAllocator* m_pDbgAllocator = nullptr; +#endif +}; + +// sizeof(ShaderVariableD3D12Impl) == 24 (x64) +class ShaderVariableD3D12Impl final : public ShaderVariableBase +{ +public: + using TBase = ShaderVariableBase; + ShaderVariableD3D12Impl(ShaderVariableManagerD3D12& ParentManager, + Uint32 ResIndex) : + TBase{ParentManager}, + m_ResIndex{ResIndex} + {} + + // clang-format off + ShaderVariableD3D12Impl (const ShaderVariableD3D12Impl&) = delete; + ShaderVariableD3D12Impl ( ShaderVariableD3D12Impl&&) = delete; + ShaderVariableD3D12Impl& operator= (const ShaderVariableD3D12Impl&) = delete; + ShaderVariableD3D12Impl& operator= ( ShaderVariableD3D12Impl&&) = delete; + // clang-format on + + virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final + { + if (ppInterface == nullptr) + return; + + *ppInterface = nullptr; + if (IID == IID_ShaderResourceVariableD3D || IID == IID_ShaderResourceVariable || IID == IID_Unknown) + { + *ppInterface = this; + (*ppInterface)->AddRef(); + } + } + + 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 defined in the header due to dependency on PipelineResourceSignatureD3D12Impl + virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final; + + virtual void DILIGENT_CALL_TYPE GetHLSLResourceDesc(HLSLShaderResourceDesc& HLSLResDesc) const override final + { + GetResourceDesc(HLSLResDesc); + HLSLResDesc.ShaderRegister = GetAttribs().Register; + } + + const PipelineResourceDesc& GetDesc() const { return m_ParentManager.GetResourceDesc(m_ResIndex); } + + // This method can't be defined in the header due to dependency on PipelineResourceSignatureD3D12Impl + void BindResource(IDeviceObject* pObj, Uint32 ArrayIndex) const; + +private: + using ResourceAttribs = PipelineResourceAttribsD3D12; + const ResourceAttribs& GetAttribs() const { return m_ParentManager.GetResourceAttribs(m_ResIndex); } + +private: + const Uint32 m_ResIndex; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D12/include/TextureD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/TextureD3D12Impl.hpp index 8a911fd3..526a7610 100644 --- a/Graphics/GraphicsEngineD3D12/include/TextureD3D12Impl.hpp +++ b/Graphics/GraphicsEngineD3D12/include/TextureD3D12Impl.hpp @@ -30,12 +30,11 @@ /// \file /// Declaration of Diligent::TextureD3D12Impl class +#include "EngineD3D12ImplTraits.hpp" #include "TextureD3D12.h" -#include "RenderDeviceD3D12.h" #include "TextureBase.hpp" #include "TextureViewD3D12Impl.hpp" #include "D3D12ResourceBase.hpp" -#include "RenderDeviceD3D12Impl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineD3D12/include/TextureViewD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/TextureViewD3D12Impl.hpp index 6fa2bdb2..08a48045 100644 --- a/Graphics/GraphicsEngineD3D12/include/TextureViewD3D12Impl.hpp +++ b/Graphics/GraphicsEngineD3D12/include/TextureViewD3D12Impl.hpp @@ -30,11 +30,10 @@ /// \file /// Declaration of Diligent::TextureViewD3D12Impl class +#include "EngineD3D12ImplTraits.hpp" #include "TextureViewD3D12.h" -#include "RenderDeviceD3D12.h" #include "TextureViewBase.hpp" #include "DescriptorHeap.hpp" -#include "RenderDeviceD3D12Impl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineD3D12/include/TopLevelASD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/TopLevelASD3D12Impl.hpp index a62bd7ce..8c45e87f 100644 --- a/Graphics/GraphicsEngineD3D12/include/TopLevelASD3D12Impl.hpp +++ b/Graphics/GraphicsEngineD3D12/include/TopLevelASD3D12Impl.hpp @@ -30,12 +30,12 @@ /// \file /// Declaration of Diligent::TopLevelASD3D12Impl class +#include "EngineD3D12ImplTraits.hpp" #include "TopLevelASD3D12.h" -#include "RenderDeviceD3D12.h" #include "TopLevelASBase.hpp" -#include "BottomLevelASD3D12Impl.hpp" #include "D3D12ResourceBase.hpp" -#include "RenderDeviceD3D12Impl.hpp" +#include "DescriptorHeap.hpp" +#include "BottomLevelASD3D12Impl.hpp" // Required by TopLevelASBase namespace Diligent { diff --git a/Graphics/GraphicsEngineD3D12/src/BottomLevelASD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/BottomLevelASD3D12Impl.cpp index bb8e2293..8f23a7e9 100644 --- a/Graphics/GraphicsEngineD3D12/src/BottomLevelASD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/BottomLevelASD3D12Impl.cpp @@ -26,6 +26,7 @@ */ #include "pch.h" + #include "BottomLevelASD3D12Impl.hpp" #include "RenderDeviceD3D12Impl.hpp" #include "D3D12TypeConversions.hpp" diff --git a/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp index db86297d..1ac066fc 100644 --- a/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp @@ -26,11 +26,11 @@ */ #include "pch.h" + #include "BufferD3D12Impl.hpp" #include "RenderDeviceD3D12Impl.hpp" #include "DeviceContextD3D12Impl.hpp" #include "D3D12TypeConversions.hpp" -#include "BufferViewD3D12Impl.hpp" #include "GraphicsAccessories.hpp" #include "DXGITypeConversions.hpp" #include "EngineMemory.h" diff --git a/Graphics/GraphicsEngineD3D12/src/BufferViewD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/BufferViewD3D12Impl.cpp index ee40368c..51edfbc3 100644 --- a/Graphics/GraphicsEngineD3D12/src/BufferViewD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/BufferViewD3D12Impl.cpp @@ -28,6 +28,7 @@ #include "pch.h" #include "BufferViewD3D12Impl.hpp" #include "BufferD3D12Impl.hpp" +#include "RenderDeviceD3D12Impl.hpp" namespace Diligent { @@ -52,4 +53,8 @@ BufferViewD3D12Impl::BufferViewD3D12Impl(IReferenceCounters* pRefCounters { } +BufferViewD3D12Impl::~BufferViewD3D12Impl() +{ +} + } // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp b/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp index e8617466..8104bcd8 100644 --- a/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp +++ b/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp @@ -26,8 +26,11 @@ */ #include "pch.h" + #include "d3dx12_win.h" + #include "CommandContext.hpp" +#include "RenderDeviceD3D12Impl.hpp" #include "TextureD3D12Impl.hpp" #include "BufferD3D12Impl.hpp" #include "BottomLevelASD3D12Impl.hpp" diff --git a/Graphics/GraphicsEngineD3D12/src/FramebufferD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/FramebufferD3D12Impl.cpp index 486e1913..d99a34fa 100644 --- a/Graphics/GraphicsEngineD3D12/src/FramebufferD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/FramebufferD3D12Impl.cpp @@ -28,6 +28,7 @@ #include "pch.h" #include "FramebufferD3D12Impl.hpp" +#include "RenderDeviceD3D12Impl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp index 27e51fae..79e82979 100644 --- a/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp @@ -31,7 +31,6 @@ #include "PipelineResourceSignatureD3D12Impl.hpp" #include "ShaderResourceCacheD3D12.hpp" -#include "ShaderVariableD3D12.hpp" #include "RenderDeviceD3D12Impl.hpp" #include "ShaderResourceBindingD3D12Impl.hpp" #include "BufferD3D12Impl.hpp" @@ -419,34 +418,6 @@ bool PipelineResourceSignatureD3D12Impl::IsCompatibleWith(const PipelineResource return true; } -void PipelineResourceSignatureD3D12Impl::CreateShaderResourceBinding(IShaderResourceBinding** ppShaderResourceBinding, - bool InitStaticResources) -{ - CreateShaderResourceBindingImpl(ppShaderResourceBinding, InitStaticResources); -} - -Uint32 PipelineResourceSignatureD3D12Impl::GetStaticVariableCount(SHADER_TYPE ShaderType) const -{ - return GetStaticVariableCountImpl(ShaderType); -} - -IShaderResourceVariable* PipelineResourceSignatureD3D12Impl::GetStaticVariableByName(SHADER_TYPE ShaderType, const Char* Name) -{ - return GetStaticVariableByNameImpl(ShaderType, Name); -} - -IShaderResourceVariable* PipelineResourceSignatureD3D12Impl::GetStaticVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index) -{ - return GetStaticVariableByIndexImpl(ShaderType, Index); -} - -void PipelineResourceSignatureD3D12Impl::BindStaticResources(Uint32 ShaderFlags, - IResourceMapping* pResMapping, - Uint32 Flags) -{ - BindStaticResourcesImpl(ShaderFlags, pResMapping, Flags); -} - size_t PipelineResourceSignatureD3D12Impl::CalculateHash() const { if (m_Desc.NumResources == 0 && m_Desc.NumImmutableSamplers == 0) diff --git a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp index 94e8b8b4..2a23c89e 100644 --- a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp @@ -39,14 +39,14 @@ #include "PipelineStateD3D12Impl.hpp" #include "ShaderD3D12Impl.hpp" -#include "D3D12TypeConversions.hpp" #include "RenderDeviceD3D12Impl.hpp" +#include "ShaderResourceBindingD3D12Impl.hpp" +#include "D3D12TypeConversions.hpp" #include "DXGITypeConversions.hpp" #include "CommandContext.hpp" #include "EngineMemory.h" #include "StringTools.hpp" #include "DynamicLinearAllocator.hpp" -#include "ShaderResourceBindingD3D12Impl.hpp" #include "DXBCUtils.hpp" #include "DXCompiler.hpp" #include "dxc/dxcapi.h" diff --git a/Graphics/GraphicsEngineD3D12/src/QueryD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/QueryD3D12Impl.cpp index bf5ed6dd..236a2026 100644 --- a/Graphics/GraphicsEngineD3D12/src/QueryD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/QueryD3D12Impl.cpp @@ -194,4 +194,11 @@ bool QueryD3D12Impl::GetData(void* pData, Uint32 DataSize, bool AutoInvalidate) } } +ID3D12QueryHeap* QueryD3D12Impl::GetD3D12QueryHeap() +{ + // This implementation can't be in the header because it requires + // definition of RenderDeviceD3D12Impl + return m_pDevice->GetQueryManager().GetQueryHeap(m_Desc.Type); +} + } // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D12/src/RenderPassD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/RenderPassD3D12Impl.cpp index 3991ab97..30e7e038 100644 --- a/Graphics/GraphicsEngineD3D12/src/RenderPassD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/RenderPassD3D12Impl.cpp @@ -28,6 +28,7 @@ #include "pch.h" #include "RenderPassD3D12Impl.hpp" +#include "RenderDeviceD3D12Impl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp index 44105f16..3f8ce2b6 100644 --- a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp +++ b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp @@ -32,6 +32,7 @@ #include "RenderDeviceD3D12Impl.hpp" #include "D3D12TypeConversions.hpp" #include "HashUtils.hpp" +#include "PipelineResourceSignatureD3D12Impl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineD3D12/src/SamplerD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/SamplerD3D12Impl.cpp index 0821787b..887dc7b6 100644 --- a/Graphics/GraphicsEngineD3D12/src/SamplerD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/SamplerD3D12Impl.cpp @@ -26,6 +26,7 @@ */ #include "pch.h" + #include "SamplerD3D12Impl.hpp" #include "RenderDeviceD3D12Impl.hpp" #include "D3D12TypeConversions.hpp" diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderBindingTableD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderBindingTableD3D12Impl.cpp index ed04481f..2f5b89a4 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderBindingTableD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderBindingTableD3D12Impl.cpp @@ -26,6 +26,7 @@ */ #include "pch.h" + #include "ShaderBindingTableD3D12Impl.hpp" #include "RenderDeviceD3D12Impl.hpp" #include "DeviceContextD3D12Impl.hpp" diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp index 0b6adc73..69d95100 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp @@ -26,9 +26,11 @@ */ #include "pch.h" + #include "ShaderResourceBindingD3D12Impl.hpp" #include "RenderDeviceD3D12Impl.hpp" #include "FixedLinearAllocator.hpp" +#include "PipelineResourceSignatureD3D12Impl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourceCacheD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourceCacheD3D12.cpp index c1cbe819..30c10b54 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderResourceCacheD3D12.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourceCacheD3D12.cpp @@ -28,13 +28,13 @@ #include "pch.h" #include "ShaderResourceCacheD3D12.hpp" -#include "BufferD3D12Impl.hpp" -#include "CommandContext.hpp" +#include "RenderDeviceD3D12Impl.hpp" #include "BufferD3D12Impl.hpp" #include "BufferViewD3D12Impl.hpp" #include "TextureD3D12Impl.hpp" #include "TextureViewD3D12Impl.hpp" #include "TopLevelASD3D12Impl.hpp" +#include "CommandContext.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp deleted file mode 100644 index af9ba39a..00000000 --- a/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp +++ /dev/null @@ -1,205 +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 "ShaderVariableD3D12.hpp" -#include "RenderDeviceD3D12Impl.hpp" - -namespace Diligent -{ - -template -void ShaderVariableManagerD3D12::ProcessSignatureResources(const PipelineResourceSignatureD3D12Impl& Signature, - const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, - Uint32 NumAllowedTypes, - SHADER_TYPE ShaderStages, - HandlerType Handler) -{ - const Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes); - const bool UsingCombinedSamplers = Signature.IsUsingCombinedSamplers(); - - for (SHADER_RESOURCE_VARIABLE_TYPE VarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; VarType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast(VarType + 1)) - { - 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)) - continue; - - if (Res.ResourceType == SHADER_RESOURCE_TYPE_SAMPLER && - (UsingCombinedSamplers || Attr.IsImmutableSamplerAssigned())) - { - // Skip samplers combined with textures and immutable samplers - continue; - } - - Handler(r); - } - } - } -} - -size_t ShaderVariableManagerD3D12::GetRequiredMemorySize(const PipelineResourceSignatureD3D12Impl& 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(ShaderVariableD3D12Impl); -} - -// Creates shader variable for every resource from Signature whose type is one AllowedVarTypes -void ShaderVariableManagerD3D12::Initialize(const PipelineResourceSignatureD3D12Impl& Signature, - IMemoryAllocator& Allocator, - const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, - Uint32 NumAllowedTypes, - SHADER_TYPE ShaderType) -{ -#ifdef DILIGENT_DEBUG - m_pDbgAllocator = &Allocator; -#endif - - 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) ShaderVariableD3D12Impl{*this, ResIndex}; - ++VarInd; - }); - VERIFY_EXPR(VarInd == m_NumVariables); - - m_pSignature = &Signature; -} - -ShaderVariableManagerD3D12::~ShaderVariableManagerD3D12() -{ - VERIFY(m_pVariables == nullptr, "Destroy() has not been called"); -} - -void ShaderVariableManagerD3D12::Destroy(IMemoryAllocator& Allocator) -{ - if (m_pVariables != nullptr) - { - VERIFY(m_pDbgAllocator == &Allocator, "Incosistent alloctor"); - - for (Uint32 v = 0; v < m_NumVariables; ++v) - m_pVariables[v].~ShaderVariableD3D12Impl(); - Allocator.Free(m_pVariables); - m_pVariables = nullptr; - } -} - -ShaderVariableD3D12Impl* ShaderVariableManagerD3D12::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; -} - - -ShaderVariableD3D12Impl* ShaderVariableManagerD3D12::GetVariable(Uint32 Index) const -{ - if (Index >= m_NumVariables) - { - LOG_ERROR("Index ", Index, " is out of range"); - return nullptr; - } - - return m_pVariables + Index; -} - -Uint32 ShaderVariableManagerD3D12::GetVariableIndex(const ShaderVariableD3D12Impl& 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(ShaderVariableD3D12Impl) == 0, "Offset is not multiple of ShaderVariableD3D12Impl class size"); - auto Index = static_cast(Offset / sizeof(ShaderVariableD3D12Impl)); - 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 ShaderVariableManagerD3D12::BindResources(IResourceMapping* pResourceMapping, Uint32 Flags) -{ - DEV_CHECK_ERR(pResourceMapping != nullptr, "Failed to bind resources: resource mapping is null"); - - 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 ShaderVariableD3D12Impl::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/GraphicsEngineD3D12/src/ShaderVariableManagerD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderVariableManagerD3D12.cpp new file mode 100644 index 00000000..1e201a4a --- /dev/null +++ b/Graphics/GraphicsEngineD3D12/src/ShaderVariableManagerD3D12.cpp @@ -0,0 +1,230 @@ +/* + * 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 "ShaderVariableManagerD3D12.hpp" +#include "RenderDeviceD3D12Impl.hpp" +#include "ShaderResourceCacheD3D12.hpp" +#include "PipelineResourceSignatureD3D12Impl.hpp" + +namespace Diligent +{ + +template +void ShaderVariableManagerD3D12::ProcessSignatureResources(const PipelineResourceSignatureD3D12Impl& Signature, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes, + SHADER_TYPE ShaderStages, + HandlerType Handler) +{ + const Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes); + const bool UsingCombinedSamplers = Signature.IsUsingCombinedSamplers(); + + for (SHADER_RESOURCE_VARIABLE_TYPE VarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; VarType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast(VarType + 1)) + { + 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)) + continue; + + if (Res.ResourceType == SHADER_RESOURCE_TYPE_SAMPLER && + (UsingCombinedSamplers || Attr.IsImmutableSamplerAssigned())) + { + // Skip samplers combined with textures and immutable samplers + continue; + } + + Handler(r); + } + } + } +} + +size_t ShaderVariableManagerD3D12::GetRequiredMemorySize(const PipelineResourceSignatureD3D12Impl& 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(ShaderVariableD3D12Impl); +} + +// Creates shader variable for every resource from Signature whose type is one AllowedVarTypes +void ShaderVariableManagerD3D12::Initialize(const PipelineResourceSignatureD3D12Impl& Signature, + IMemoryAllocator& Allocator, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes, + SHADER_TYPE ShaderType) +{ +#ifdef DILIGENT_DEBUG + m_pDbgAllocator = &Allocator; +#endif + + 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) ShaderVariableD3D12Impl{*this, ResIndex}; + ++VarInd; + }); + VERIFY_EXPR(VarInd == m_NumVariables); + + m_pSignature = &Signature; +} + +ShaderVariableManagerD3D12::~ShaderVariableManagerD3D12() +{ + VERIFY(m_pVariables == nullptr, "Destroy() has not been called"); +} + +void ShaderVariableManagerD3D12::Destroy(IMemoryAllocator& Allocator) +{ + if (m_pVariables != nullptr) + { + VERIFY(m_pDbgAllocator == &Allocator, "Incosistent alloctor"); + + for (Uint32 v = 0; v < m_NumVariables; ++v) + m_pVariables[v].~ShaderVariableD3D12Impl(); + Allocator.Free(m_pVariables); + m_pVariables = nullptr; + } +} + +const PipelineResourceDesc& ShaderVariableManagerD3D12::GetResourceDesc(Uint32 Index) const +{ + VERIFY_EXPR(m_pSignature != nullptr); + return m_pSignature->GetResourceDesc(Index); +} + +const ShaderVariableManagerD3D12::ResourceAttribs& ShaderVariableManagerD3D12::GetResourceAttribs(Uint32 Index) const +{ + VERIFY_EXPR(m_pSignature != nullptr); + return m_pSignature->GetResourceAttribs(Index); +} + + +ShaderVariableD3D12Impl* ShaderVariableManagerD3D12::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; +} + + +ShaderVariableD3D12Impl* ShaderVariableManagerD3D12::GetVariable(Uint32 Index) const +{ + if (Index >= m_NumVariables) + { + LOG_ERROR("Index ", Index, " is out of range"); + return nullptr; + } + + return m_pVariables + Index; +} + +Uint32 ShaderVariableManagerD3D12::GetVariableIndex(const ShaderVariableD3D12Impl& 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(ShaderVariableD3D12Impl) == 0, "Offset is not multiple of ShaderVariableD3D12Impl class size"); + auto Index = static_cast(Offset / sizeof(ShaderVariableD3D12Impl)); + 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 ShaderVariableManagerD3D12::BindResources(IResourceMapping* pResourceMapping, Uint32 Flags) +{ + DEV_CHECK_ERR(pResourceMapping != nullptr, "Failed to bind resources: resource mapping is null"); + + 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 ShaderVariableD3D12Impl::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 ShaderVariableD3D12Impl::IsBound(Uint32 ArrayIndex) const +{ + return m_ParentManager.m_pSignature->IsBound(ArrayIndex, m_ResIndex, m_ParentManager.m_ResourceCache); +} + +void ShaderVariableD3D12Impl::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/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp index 9958d158..f01eb476 100644 --- a/Graphics/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp @@ -26,6 +26,7 @@ */ #include "pch.h" + #include "TextureD3D12Impl.hpp" #include "RenderDeviceD3D12Impl.hpp" #include "DeviceContextD3D12Impl.hpp" diff --git a/Graphics/GraphicsEngineD3D12/src/TextureViewD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/TextureViewD3D12Impl.cpp index 78b519ba..925d5d2f 100644 --- a/Graphics/GraphicsEngineD3D12/src/TextureViewD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/TextureViewD3D12Impl.cpp @@ -26,8 +26,10 @@ */ #include "pch.h" + #include "TextureViewD3D12Impl.hpp" #include "DeviceContextD3D12Impl.hpp" +#include "RenderDeviceD3D12Impl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineD3D12/src/TopLevelASD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/TopLevelASD3D12Impl.cpp index 9ee26ff4..3c7ab4e2 100644 --- a/Graphics/GraphicsEngineD3D12/src/TopLevelASD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/TopLevelASD3D12Impl.cpp @@ -26,6 +26,7 @@ */ #include "pch.h" + #include "TopLevelASD3D12Impl.hpp" #include "RenderDeviceD3D12Impl.hpp" #include "D3D12TypeConversions.hpp" -- cgit v1.2.3