diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2019-03-04 06:41:15 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2019-03-04 06:41:15 +0000 |
| commit | 2f468cbac64474c16a87c2fd6f8c8bb06f3f7d0f (patch) | |
| tree | 3e94f468b7cb78d2bd8bbacdbb48a1db84fd2aa2 /Graphics/GraphicsEngineD3D12 | |
| parent | Cleaned up QueryInterface declaration in D3D12 backend (diff) | |
| download | DiligentCore-2f468cbac64474c16a87c2fd6f8c8bb06f3f7d0f.tar.gz DiligentCore-2f468cbac64474c16a87c2fd6f8c8bb06f3f7d0f.zip | |
Updated ShaderResourceLayoutD3D12 and few other objects in D3D12 backend to comply with the new API
Diffstat (limited to 'Graphics/GraphicsEngineD3D12')
12 files changed, 317 insertions, 346 deletions
diff --git a/Graphics/GraphicsEngineD3D12/include/RootSignature.h b/Graphics/GraphicsEngineD3D12/include/RootSignature.h index fbf17f4d..ebe2083e 100644 --- a/Graphics/GraphicsEngineD3D12/include/RootSignature.h +++ b/Graphics/GraphicsEngineD3D12/include/RootSignature.h @@ -40,12 +40,12 @@ class RootParameter { public: - RootParameter(D3D12_ROOT_PARAMETER_TYPE ParameterType, - Uint32 RootIndex, - UINT Register, - UINT RegisterSpace, - D3D12_SHADER_VISIBILITY Visibility, - SHADER_VARIABLE_TYPE VarType)noexcept : + RootParameter(D3D12_ROOT_PARAMETER_TYPE ParameterType, + Uint32 RootIndex, + UINT Register, + UINT RegisterSpace, + D3D12_SHADER_VISIBILITY Visibility, + SHADER_RESOURCE_VARIABLE_TYPE VarType)noexcept : m_RootIndex (RootIndex), m_ShaderVarType(VarType) { @@ -56,13 +56,13 @@ public: m_RootParam.Descriptor.RegisterSpace = RegisterSpace; } - RootParameter(D3D12_ROOT_PARAMETER_TYPE ParameterType, - Uint32 RootIndex, - UINT Register, - UINT RegisterSpace, - UINT NumDwords, - D3D12_SHADER_VISIBILITY Visibility, - SHADER_VARIABLE_TYPE VarType)noexcept : + RootParameter(D3D12_ROOT_PARAMETER_TYPE ParameterType, + Uint32 RootIndex, + UINT Register, + UINT RegisterSpace, + UINT NumDwords, + D3D12_SHADER_VISIBILITY Visibility, + SHADER_RESOURCE_VARIABLE_TYPE VarType)noexcept : m_RootIndex (RootIndex), m_ShaderVarType(VarType) { @@ -74,12 +74,12 @@ public: m_RootParam.Constants.RegisterSpace = RegisterSpace; } - RootParameter(D3D12_ROOT_PARAMETER_TYPE ParameterType, - Uint32 RootIndex, - UINT NumRanges, - D3D12_DESCRIPTOR_RANGE* pRanges, - D3D12_SHADER_VISIBILITY Visibility, - SHADER_VARIABLE_TYPE VarType)noexcept : + RootParameter(D3D12_ROOT_PARAMETER_TYPE ParameterType, + Uint32 RootIndex, + UINT NumRanges, + D3D12_DESCRIPTOR_RANGE* pRanges, + D3D12_SHADER_VISIBILITY Visibility, + SHADER_RESOURCE_VARIABLE_TYPE VarType)noexcept : m_RootIndex (RootIndex), m_ShaderVarType(VarType) { @@ -158,7 +158,7 @@ public: m_DescriptorTableSize = std::max(m_DescriptorTableSize, OffsetFromTableStart + Count); } - SHADER_VARIABLE_TYPE GetShaderVariableType()const{ return m_ShaderVarType; } + SHADER_RESOURCE_VARIABLE_TYPE GetShaderVariableType()const{ return m_ShaderVarType; } Uint32 GetDescriptorTableSize()const { VERIFY(m_RootParam.ParameterType == D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE, "Incorrect parameter table: descriptor table is expected"); @@ -274,10 +274,10 @@ public: private: - SHADER_VARIABLE_TYPE m_ShaderVarType = static_cast<SHADER_VARIABLE_TYPE>(-1); - D3D12_ROOT_PARAMETER m_RootParam = {}; - Uint32 m_DescriptorTableSize = 0; - Uint32 m_RootIndex = static_cast<Uint32>(-1); + SHADER_RESOURCE_VARIABLE_TYPE m_ShaderVarType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(-1); + D3D12_ROOT_PARAMETER m_RootParam = {}; + Uint32 m_DescriptorTableSize = 0; + Uint32 m_RootIndex = static_cast<Uint32>(-1); }; @@ -330,15 +330,15 @@ public: bool IsCompute, class DeviceContextD3D12Impl* pCtx)const; - Uint32 GetTotalSrvCbvUavSlots(SHADER_VARIABLE_TYPE VarType)const + Uint32 GetTotalSrvCbvUavSlots(SHADER_RESOURCE_VARIABLE_TYPE VarType)const { return m_TotalSrvCbvUavSlots[VarType]; } - Uint32 GetTotalSamplerSlots(SHADER_VARIABLE_TYPE VarType)const + Uint32 GetTotalSamplerSlots(SHADER_RESOURCE_VARIABLE_TYPE VarType)const { return m_TotalSamplerSlots[VarType]; } - Uint32 GetTotalRootViews(SHADER_VARIABLE_TYPE VarType)const + Uint32 GetTotalRootViews(SHADER_RESOURCE_VARIABLE_TYPE VarType)const { return m_TotalRootViews[VarType]; } @@ -359,9 +359,9 @@ private: std::vector<Uint32, STDAllocatorRawMem<Uint32> > GetCacheTableSizes()const; - std::array<Uint32, SHADER_VARIABLE_TYPE_NUM_TYPES> m_TotalSrvCbvUavSlots = {}; - std::array<Uint32, SHADER_VARIABLE_TYPE_NUM_TYPES> m_TotalSamplerSlots = {}; - std::array<Uint32, SHADER_VARIABLE_TYPE_NUM_TYPES> m_TotalRootViews = {}; + std::array<Uint32, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES> m_TotalSrvCbvUavSlots = {}; + std::array<Uint32, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES> m_TotalSamplerSlots = {}; + std::array<Uint32, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES> m_TotalRootViews = {}; CComPtr<ID3D12RootSignature> m_pd3d12RootSignature; @@ -402,16 +402,16 @@ private: return m_pRootViews[ViewInd]; } - void AddRootView(D3D12_ROOT_PARAMETER_TYPE ParameterType, - Uint32 RootIndex, - UINT Register, - D3D12_SHADER_VISIBILITY Visibility, - SHADER_VARIABLE_TYPE VarType); + void AddRootView(D3D12_ROOT_PARAMETER_TYPE ParameterType, + Uint32 RootIndex, + UINT Register, + D3D12_SHADER_VISIBILITY Visibility, + SHADER_RESOURCE_VARIABLE_TYPE VarType); - void AddRootTable(Uint32 RootIndex, - D3D12_SHADER_VISIBILITY Visibility, - SHADER_VARIABLE_TYPE VarType, - Uint32 NumRangesInNewTable = 1); + void AddRootTable(Uint32 RootIndex, + D3D12_SHADER_VISIBILITY Visibility, + SHADER_RESOURCE_VARIABLE_TYPE VarType, + Uint32 NumRangesInNewTable = 1); void AddDescriptorRanges(Uint32 RootTableInd, Uint32 NumExtraRanges = 1); @@ -446,9 +446,9 @@ private: // in m_RootParams (NOT the Root Index!), for every variable type // (static, mutable, dynamic) and every shader type, // or -1, if the table is not yet assigned to the combination - std::array<Uint8, SHADER_VARIABLE_TYPE_NUM_TYPES * 6> m_SrvCbvUavRootTablesMap; + std::array<Uint8, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES * 6> m_SrvCbvUavRootTablesMap; // This array contains the same data for Sampler root table - std::array<Uint8, SHADER_VARIABLE_TYPE_NUM_TYPES * 6> m_SamplerRootTablesMap; + std::array<Uint8, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES * 6> m_SamplerRootTablesMap; RootParamsManager m_RootParams; diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.h index 8f80e54b..674beafb 100644 --- a/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.h @@ -45,49 +45,20 @@ class ShaderD3D12Impl final : public ShaderBase<IShaderD3D12, RenderDeviceD3D12I public: using TShaderBase = ShaderBase<IShaderD3D12, RenderDeviceD3D12Impl>; - ShaderD3D12Impl(IReferenceCounters* pRefCounters, - RenderDeviceD3D12Impl* pRenderDeviceD3D12, - const ShaderCreationAttribs& ShaderCreationAttribs); + ShaderD3D12Impl(IReferenceCounters* pRefCounters, + RenderDeviceD3D12Impl* pRenderDeviceD3D12, + const ShaderCreateInfo& ShaderCI); ~ShaderD3D12Impl(); - virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override; - - virtual void BindResources( IResourceMapping* pResourceMapping, Uint32 Flags )override final - { - m_StaticVarsMgr.BindResources(pResourceMapping, Flags); - } - - virtual IShaderVariable* GetShaderVariable(const Char* Name)override final - { - return m_StaticVarsMgr.GetVariable(Name); - } - - virtual Uint32 GetVariableCount() const override final - { - return m_StaticVarsMgr.GetVariableCount(); - } - - virtual IShaderVariable* GetShaderVariable(Uint32 Index)override final - { - return m_StaticVarsMgr.GetVariable(Index); - } + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final; ID3DBlob* GetShaderByteCode(){return m_pShaderByteCode;} const std::shared_ptr<const ShaderResourcesD3D12>& GetShaderResources()const { return m_pShaderResources; } - const ShaderResourceLayoutD3D12& GetStaticResLayout()const { return m_StaticResLayout; } - const ShaderResourceCacheD3D12& GetStaticResCache() const { return m_StaticResCache; } - -#ifdef DEVELOPMENT - bool DvpVerifyStaticResourceBindings()const; -#endif private: // ShaderResources class instance must be referenced through the shared pointer, because // it is referenced by ShaderResourceLayoutD3D12 class instances std::shared_ptr<const ShaderResourcesD3D12> m_pShaderResources; - ShaderResourceLayoutD3D12 m_StaticResLayout; - ShaderResourceCacheD3D12 m_StaticResCache; - ShaderVariableManagerD3D12 m_StaticVarsMgr; }; } diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.h index aed47701..b45514da 100644 --- a/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.h @@ -53,11 +53,11 @@ public: virtual void BindResources(Uint32 ShaderFlags, IResourceMapping* pResMapping, Uint32 Flags)override; - virtual IShaderVariable* GetVariable(SHADER_TYPE ShaderType, const char* Name)override; + virtual IShaderResourceVariable* GetVariable(SHADER_TYPE ShaderType, const char* Name)override; virtual Uint32 GetVariableCount(SHADER_TYPE ShaderType) const override final; - virtual IShaderVariable* GetVariable(SHADER_TYPE ShaderType, Uint32 Index)override final; + virtual IShaderResourceVariable* GetVariable(SHADER_TYPE ShaderType, Uint32 Index)override final; virtual void InitializeStaticResources(const IPipelineState* pPipelineState)override final; diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.h b/Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.h index e734cf5c..2ae5c927 100644 --- a/Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.h +++ b/Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.h @@ -37,14 +37,14 @@ // | SRV/CBV/UAV - STATIC | SRV/CBV/UAV - MUTABLE | SRV/CBV/UAV - DYNAMIC | Samplers - STATIC | Samplers - MUTABLE | Samplers - DYNAMIC || // | | | | // -// s == NumCbvSrvUav[SHADER_VARIABLE_TYPE_STATIC] -// m == NumCbvSrvUav[SHADER_VARIABLE_TYPE_MUTABLE] -// d == NumCbvSrvUav[SHADER_VARIABLE_TYPE_DYNAMIC] +// s == NumCbvSrvUav[SHADER_RESOURCE_VARIABLE_TYPE_STATIC] +// m == NumCbvSrvUav[SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE] +// d == NumCbvSrvUav[SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC] // smd = s+m+d // -// s' == NumSamplers[SHADER_VARIABLE_TYPE_STATIC] -// m' == NumSamplers[SHADER_VARIABLE_TYPE_MUTABLE] -// d' == NumSamplers[SHADER_VARIABLE_TYPE_DYNAMIC] +// s' == NumSamplers[SHADER_RESOURCE_VARIABLE_TYPE_STATIC] +// m' == NumSamplers[SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE] +// d' == NumSamplers[SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC] // // Every D3D12Resource structure holds a reference to D3DShaderResourceAttribs structure from ShaderResourcesD3D12. // ShaderResourceLayoutD3D12 holds shared pointer to ShaderResourcesD3D12 instance. Note that ShaderResourcesD3D12::SamplerId @@ -86,14 +86,13 @@ // ** These resource layouts are used as reference layouts for shader resource binding objects // ** All variable types are preserved // ** Root indices and descriptor table offsets are assigned during the initialization -// * Every shader object (ShaderD3D12Impl) contains shader resource layout that facilitates management of static shader resources +// * Every pipeline state object also contains shader resource layout that facilitates management of static shader resources // ** The resource layout defines artificial layout where root index matches the resource type (CBV/SRV/UAV/SAM) // ** Only static variables are referenced // // * Every shader resource binding object (ShaderResourceBindingD3D12Impl) encompasses shader variable // manager (ShaderVariableManagerD3D12) for every active shader stage in the parent pipeline state that // handles mutable and dynamic resources -// * Every shader object (ShaderD3D12Impl) constains shader variable manager that handles static resources #include <array> @@ -118,16 +117,16 @@ public: ~ShaderResourceLayoutD3D12(); - // The method is called by - // - ShaderD3D12Impl class instance to initialize static resource layout and initialize shader resource cache - // to hold static resources - // - PipelineStateD3D12Impl class instance to reference all types of resources (static, mutable, dynamic). + // The method is called to + // - initialize static resource layout and initialize shader resource cache to hold static resources + // - initialize reference layouts that address all types of resources (static, mutable, dynamic). // Root indices and descriptor table offsets are assigned during the initialization; // no shader resource cache is provided void Initialize(ID3D12Device* pd3d12Device, + const PipelineResourceLayoutDesc& ResourceLayout, std::shared_ptr<const ShaderResourcesD3D12> pSrcResources, IMemoryAllocator& LayoutDataAllocator, - const SHADER_VARIABLE_TYPE* VarTypes, + const SHADER_RESOURCE_VARIABLE_TYPE* const VarTypes, Uint32 NumAllowedTypes, ShaderResourceCacheD3D12* pResourceCache, class RootSignature* pRootSig); @@ -141,7 +140,8 @@ public: D3D12Resource& operator = ( D3D12Resource&&) = delete; static constexpr const Uint32 ResourceTypeBits = 3; - static constexpr const Uint32 RootIndexBits = 16 - ResourceTypeBits; + static constexpr const Uint32 VariableTypeBits = 2; + static constexpr const Uint32 RootIndexBits = 16 - ResourceTypeBits - VariableTypeBits; static constexpr const Uint32 InvalidRootIndex = (1 << RootIndexBits) - 1; static constexpr const Uint32 MaxRootIndex = InvalidRootIndex - 1; @@ -150,24 +150,29 @@ public: static constexpr const Uint32 MaxSamplerId = InvalidSamplerId-1; static constexpr const Uint32 InvalidOffset = static_cast<Uint32>(-1); + static_assert( SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES < (1 << VariableTypeBits), "2 bits is not enough to store SHADER_RESOURCE_VARIABLE_TYPE"); static_assert( static_cast<int>(CachedResourceType::NumTypes) < (1 << ResourceTypeBits), "3 bits is not enough to store CachedResourceType"); - const ShaderResourceLayoutD3D12& ParentResLayout; - const D3DShaderResourceAttribs& Attribs; - const Uint32 OffsetFromTableStart; - const Uint16 ResourceType : ResourceTypeBits; // | 0 1 2 | - const Uint16 RootIndex : RootIndexBits; // | 3 4 5 ... 15 | - const Uint16 SamplerId; +/* 0 */ const ShaderResourceLayoutD3D12& ParentResLayout; +/* 8 */ const D3DShaderResourceAttribs& Attribs; +/*16 */ const Uint32 OffsetFromTableStart; +/*20.0*/ const Uint16 ResourceType : ResourceTypeBits; // | 0 1 2 | +/*20.3*/ const Uint16 VariableType : VariableTypeBits; // | 3 4 | +/*20.5*/ const Uint16 RootIndex : RootIndexBits; // | 5 6 7 ... 15 | +/*22 */ const Uint16 SamplerId; +/*24 */ // End of data D3D12Resource(const ShaderResourceLayoutD3D12& _ParentLayout, - const D3DShaderResourceAttribs& _Attribs, - CachedResourceType _ResType, + const D3DShaderResourceAttribs& _Attribs, + SHADER_RESOURCE_VARIABLE_TYPE _VariableType, + CachedResourceType _ResType, Uint32 _RootIndex, Uint32 _OffsetFromTableStart, Uint32 _SamplerId)noexcept : ParentResLayout (_ParentLayout), Attribs (_Attribs), ResourceType (static_cast<Uint16>(_ResType)), + VariableType (static_cast<Uint16>(_VariableType)), RootIndex (static_cast<Uint16>(_RootIndex)), SamplerId (static_cast<Uint16>(_SamplerId)), OffsetFromTableStart( _OffsetFromTableStart ) @@ -175,6 +180,7 @@ public: VERIFY(IsValidOffset(), "Offset must be valid"); VERIFY(IsValidRootIndex(), "Root index must be valid"); VERIFY(_RootIndex <= MaxRootIndex, "Root index (", _RootIndex, ") exceeds max allowed value (", MaxRootIndex, ")" ); + VERIFY(_VariableType < (1 << VariableTypeBits), "Variable type is out of representable range"); VERIFY(_SamplerId == InvalidSamplerId || _SamplerId <= MaxSamplerId, "Sampler id (", _SamplerId, ") exceeds max allowed value (", MaxSamplerId, ")" ); VERIFY(_SamplerId == InvalidSamplerId || GetResType() == CachedResourceType::TexSRV, "A sampler can only be assigned to a Texture SRV"); } @@ -191,6 +197,7 @@ public: bool IsValidOffset() const { return OffsetFromTableStart != InvalidOffset; } CachedResourceType GetResType() const { return static_cast<CachedResourceType>( ResourceType ); } + SHADER_RESOURCE_VARIABLE_TYPE GetVariableType() const { return static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(VariableType); } private: void CacheCB(IDeviceObject* pBuffer, @@ -224,21 +231,21 @@ public: IObject& GetOwner(){return m_Owner;} - Uint32 GetCbvSrvUavCount(SHADER_VARIABLE_TYPE VarType)const + Uint32 GetCbvSrvUavCount(SHADER_RESOURCE_VARIABLE_TYPE VarType)const { return m_CbvSrvUavOffsets[VarType + 1] - m_CbvSrvUavOffsets[VarType]; } - Uint32 GetSamplerCount(SHADER_VARIABLE_TYPE VarType)const + Uint32 GetSamplerCount(SHADER_RESOURCE_VARIABLE_TYPE VarType)const { return m_SamplersOffsets[VarType + 1] - m_SamplersOffsets[VarType]; } - const D3D12Resource& GetSrvCbvUav(SHADER_VARIABLE_TYPE VarType, Uint32 r)const + const D3D12Resource& GetSrvCbvUav(SHADER_RESOURCE_VARIABLE_TYPE VarType, Uint32 r)const { VERIFY_EXPR( r < GetCbvSrvUavCount(VarType) ); return GetResource(GetSrvCbvUavOffset(VarType,r)); } - const D3D12Resource& GetSampler(SHADER_VARIABLE_TYPE VarType, Uint32 s)const + const D3D12Resource& GetSampler(SHADER_RESOURCE_VARIABLE_TYPE VarType, Uint32 s)const { VERIFY_EXPR( s < GetSamplerCount(VarType) ); return GetResource(GetSamplerOffset(VarType,s)); @@ -250,20 +257,24 @@ private: const D3D12Resource& GetAssignedSampler(const D3D12Resource& TexSrv)const; D3D12Resource& GetAssignedSampler(const D3D12Resource& TexSrv); - const Char* GetShaderName()const; + const Char* GetShaderName()const + { + return m_pResources->GetShaderName(); + } + Uint32 GetTotalSrvCbvUavCount()const { VERIFY_EXPR(m_CbvSrvUavOffsets[0] == 0); - return m_CbvSrvUavOffsets[SHADER_VARIABLE_TYPE_NUM_TYPES]; + return m_CbvSrvUavOffsets[SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES]; } Uint32 GetTotalSamplerCount()const { - return m_SamplersOffsets[SHADER_VARIABLE_TYPE_NUM_TYPES] - m_SamplersOffsets[0]; + return m_SamplersOffsets[SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES] - m_SamplersOffsets[0]; } Uint32 GetTotalResourceCount()const { - return m_SamplersOffsets[SHADER_VARIABLE_TYPE_NUM_TYPES]; + return m_SamplersOffsets[SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES]; } D3D12Resource& GetResource(Uint32 r) @@ -279,25 +290,25 @@ private: return Resource[r]; } - Uint32 GetSrvCbvUavOffset(SHADER_VARIABLE_TYPE VarType, Uint32 r)const + Uint32 GetSrvCbvUavOffset(SHADER_RESOURCE_VARIABLE_TYPE VarType, Uint32 r)const { Uint32 Offset = m_CbvSrvUavOffsets[VarType] + r; VERIFY_EXPR( Offset < m_CbvSrvUavOffsets[VarType+1] ); return Offset; } - D3D12Resource& GetSrvCbvUav(SHADER_VARIABLE_TYPE VarType, Uint32 r) + D3D12Resource& GetSrvCbvUav(SHADER_RESOURCE_VARIABLE_TYPE VarType, Uint32 r) { VERIFY_EXPR( r < GetCbvSrvUavCount(VarType) ); return GetResource(GetSrvCbvUavOffset(VarType,r)); } - Uint32 GetSamplerOffset(SHADER_VARIABLE_TYPE VarType, Uint32 s)const + Uint32 GetSamplerOffset(SHADER_RESOURCE_VARIABLE_TYPE VarType, Uint32 s)const { auto Offset = m_SamplersOffsets[VarType] + s; VERIFY_EXPR( Offset < m_SamplersOffsets[VarType+1] ); return Offset; } - D3D12Resource& GetSampler(SHADER_VARIABLE_TYPE VarType, Uint32 s) + D3D12Resource& GetSampler(SHADER_RESOURCE_VARIABLE_TYPE VarType, Uint32 s) { VERIFY_EXPR( s < GetSamplerCount(VarType) ); return GetResource(GetSamplerOffset(VarType,s)); @@ -309,12 +320,12 @@ private: } void AllocateMemory(IMemoryAllocator& Allocator, - const std::array<Uint32, SHADER_VARIABLE_TYPE_NUM_TYPES>& CbvSrvUavCount, - const std::array<Uint32, SHADER_VARIABLE_TYPE_NUM_TYPES>& SamplerCount); + const std::array<Uint32, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES>& CbvSrvUavCount, + const std::array<Uint32, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES>& SamplerCount); std::unique_ptr<void, STDDeleterRawMem<void> > m_ResourceBuffer; - std::array<Uint16, SHADER_VARIABLE_TYPE_NUM_TYPES + 1> m_CbvSrvUavOffsets = {}; - std::array<Uint16, SHADER_VARIABLE_TYPE_NUM_TYPES + 1> m_SamplersOffsets = {}; + std::array<Uint16, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES + 1> m_CbvSrvUavOffsets = {}; + std::array<Uint16, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES + 1> m_SamplersOffsets = {}; CComPtr<ID3D12Device> m_pd3d12Device; IObject& m_Owner; diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.h b/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.h index 0c1127d2..0b6d2762 100644 --- a/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.h +++ b/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.h @@ -30,7 +30,7 @@ // * ShaderVariableManagerD3D12 keeps list of variables of specific types // * Every ShaderVariableD3D12Impl references D3D12Resource from ShaderResourceLayoutD3D12 // * ShaderVariableManagerD3D12 keeps pointer to ShaderResourceCacheD3D12 -// * ShaderVariableManagerD3D12 is used by ShaderD3D12Impl to manage static resources and by +// * ShaderVariableManagerD3D12 is used by PipelineStateD3D12Impl to manage static resources and by // ShaderResourceBindingD3D12Impl to manage mutable and dynamic resources // // _____________________________ ________________________________________________________________________________ @@ -75,11 +75,11 @@ public: {} ~ShaderVariableManagerD3D12(); - void Initialize(const ShaderResourceLayoutD3D12& Layout, - IMemoryAllocator& Allocator, - const SHADER_VARIABLE_TYPE* AllowedVarTypes, - Uint32 NumAllowedTypes, - ShaderResourceCacheD3D12& ResourceCache); + void Initialize(const ShaderResourceLayoutD3D12& Layout, + IMemoryAllocator& Allocator, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes, + ShaderResourceCacheD3D12& ResourceCache); void Destroy(IMemoryAllocator& Allocator); ShaderVariableD3D12Impl* GetVariable(const Char* Name); @@ -87,10 +87,10 @@ public: void BindResources( IResourceMapping* pResourceMapping, Uint32 Flags); - static size_t GetRequiredMemorySize(const ShaderResourceLayoutD3D12& Layout, - const SHADER_VARIABLE_TYPE* AllowedVarTypes, - Uint32 NumAllowedTypes, - Uint32& NumVariables); + static size_t GetRequiredMemorySize(const ShaderResourceLayoutD3D12& Layout, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes, + Uint32& NumVariables); Uint32 GetVariableCount()const { return m_NumVariables; } @@ -119,7 +119,7 @@ private: }; // sizeof(ShaderVariableD3D12Impl) == 24 (x64) -class ShaderVariableD3D12Impl final : public IShaderVariable +class ShaderVariableD3D12Impl final : public IShaderResourceVariable { public: ShaderVariableD3D12Impl(ShaderVariableManagerD3D12& ParentManager, @@ -154,16 +154,16 @@ public: return; *ppInterface = nullptr; - if (IID == IID_ShaderVariable || IID == IID_Unknown) + if (IID == IID_ShaderResourceVariable || IID == IID_Unknown) { *ppInterface = this; (*ppInterface)->AddRef(); } } - virtual SHADER_VARIABLE_TYPE GetType()const override final + virtual SHADER_RESOURCE_VARIABLE_TYPE GetType()const override final { - return m_Resource.Attribs.GetVariableType(); + return m_Resource.GetVariableType(); } virtual void Set(IDeviceObject *pObject)override final diff --git a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp index 8d5f1ba4..82c3f587 100644 --- a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp @@ -204,7 +204,7 @@ PipelineStateD3D12Impl :: PipelineStateD3D12Impl(IReferenceCounters* pRefCo std::array<size_t, MaxShadersInPipeline> ShaderVarMgrDataSizes = {}; for (Uint32 s = 0; s < m_NumShaders; ++s) { - std::array<SHADER_VARIABLE_TYPE, 2> AllowedVarTypes = { SHADER_VARIABLE_TYPE_MUTABLE, SHADER_VARIABLE_TYPE_DYNAMIC }; + std::array<SHADER_RESOURCE_VARIABLE_TYPE, 2> AllowedVarTypes = { SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC }; Uint32 NumVariablesUnused = 0; ShaderVarMgrDataSizes[s] = ShaderVariableManagerD3D12::GetRequiredMemorySize(m_pShaderResourceLayouts[s], AllowedVarTypes.data(), static_cast<Uint32>(AllowedVarTypes.size()), NumVariablesUnused); } @@ -324,8 +324,8 @@ ShaderResourceCacheD3D12* PipelineStateD3D12Impl::CommitAndTransitionShaderResou } - if( (m_RootSig.GetTotalSrvCbvUavSlots(SHADER_VARIABLE_TYPE_STATIC) != 0 || - m_RootSig.GetTotalRootViews(SHADER_VARIABLE_TYPE_STATIC) != 0) && !pResBindingD3D12Impl->StaticResourcesInitialized() ) + if( (m_RootSig.GetTotalSrvCbvUavSlots(SHADER_RESOURCE_VARIABLE_TYPE_STATIC) != 0 || + m_RootSig.GetTotalRootViews(SHADER_RESOURCE_VARIABLE_TYPE_STATIC) != 0) && !pResBindingD3D12Impl->StaticResourcesInitialized() ) { LOG_ERROR_MESSAGE("Static resources have not been initialized in the shader resource binding object being committed for PSO '", m_Desc.Name,"'. Please call IShaderResourceBinding::InitializeStaticResources()."); } @@ -357,7 +357,7 @@ ShaderResourceCacheD3D12* PipelineStateD3D12Impl::CommitAndTransitionShaderResou bool PipelineStateD3D12Impl::dbgContainsShaderResources()const { - for(auto VarType = SHADER_VARIABLE_TYPE_STATIC; VarType < SHADER_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_VARIABLE_TYPE>(VarType+1)) + for(auto VarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; VarType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(VarType+1)) { if (m_RootSig.GetTotalSrvCbvUavSlots(VarType) != 0 || m_RootSig.GetTotalRootViews (VarType) != 0) diff --git a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp index 82bf20dd..64da64c9 100644 --- a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp +++ b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp @@ -100,17 +100,17 @@ void RootSignature::RootParamsManager::AddRootView(D3D12_ROOT_PARAMETER_TYPE Par Uint32 RootIndex, UINT Register, D3D12_SHADER_VISIBILITY Visibility, - SHADER_VARIABLE_TYPE VarType) + SHADER_RESOURCE_VARIABLE_TYPE VarType) { auto *pRangePtr = Extend(0, 1, 0); VERIFY_EXPR((char*)pRangePtr == (char*)m_pMemory.get() + GetRequiredMemorySize(0, 0, 0)); new(m_pRootViews + m_NumRootViews-1) RootParameter(ParameterType, RootIndex, Register, 0u, Visibility, VarType); } -void RootSignature::RootParamsManager::AddRootTable(Uint32 RootIndex, - D3D12_SHADER_VISIBILITY Visibility, - SHADER_VARIABLE_TYPE VarType, - Uint32 NumRangesInNewTable) +void RootSignature::RootParamsManager::AddRootTable(Uint32 RootIndex, + D3D12_SHADER_VISIBILITY Visibility, + SHADER_RESOURCE_VARIABLE_TYPE VarType, + Uint32 NumRangesInNewTable) { auto *pRangePtr = Extend(1, 0, NumRangesInNewTable); VERIFY_EXPR( (char*)(pRangePtr + NumRangesInNewTable) == (char*)m_pMemory.get() + GetRequiredMemorySize(0, 0, 0)); @@ -304,8 +304,8 @@ void RootSignature::AllocateResourceSlot(SHADER_TYPE ShaderT else { // Use the same table for static and mutable resources. Treat both as static - auto RootTableType = (ShaderResAttribs.GetVariableType() == SHADER_VARIABLE_TYPE_DYNAMIC) ? SHADER_VARIABLE_TYPE_DYNAMIC : SHADER_VARIABLE_TYPE_STATIC; - auto TableIndKey = ShaderInd * SHADER_VARIABLE_TYPE_NUM_TYPES + RootTableType; + auto RootTableType = (ShaderResAttribs.GetVariableType() == SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC) ? SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC : SHADER_RESOURCE_VARIABLE_TYPE_STATIC; + auto TableIndKey = ShaderInd * SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES + RootTableType; // Get the table array index (this is not the root index!) auto& RootTableArrayInd = (( RangeType == D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER ) ? m_SamplerRootTablesMap : m_SrvCbvUavRootTablesMap)[ TableIndKey ]; if (RootTableArrayInd == InvalidRootTableIndex) @@ -397,17 +397,17 @@ void RootSignature::dbgVerifyRootParameters()const } VERIFY(dbgTotalSrvCbvUavSlots == - m_TotalSrvCbvUavSlots[SHADER_VARIABLE_TYPE_STATIC] + - m_TotalSrvCbvUavSlots[SHADER_VARIABLE_TYPE_MUTABLE] + - m_TotalSrvCbvUavSlots[SHADER_VARIABLE_TYPE_DYNAMIC], "Unexpected number of SRV CBV UAV resource slots"); + m_TotalSrvCbvUavSlots[SHADER_RESOURCE_VARIABLE_TYPE_STATIC] + + m_TotalSrvCbvUavSlots[SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE] + + m_TotalSrvCbvUavSlots[SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC], "Unexpected number of SRV CBV UAV resource slots"); VERIFY(dbgTotalSamplerSlots == - m_TotalSamplerSlots[SHADER_VARIABLE_TYPE_STATIC] + - m_TotalSamplerSlots[SHADER_VARIABLE_TYPE_MUTABLE] + - m_TotalSamplerSlots[SHADER_VARIABLE_TYPE_DYNAMIC], "Unexpected number of sampler slots"); + m_TotalSamplerSlots[SHADER_RESOURCE_VARIABLE_TYPE_STATIC] + + m_TotalSamplerSlots[SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE] + + m_TotalSamplerSlots[SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC], "Unexpected number of sampler slots"); VERIFY(dbgTotalRootViews == - m_TotalRootViews[SHADER_VARIABLE_TYPE_STATIC] + - m_TotalRootViews[SHADER_VARIABLE_TYPE_MUTABLE] + - m_TotalRootViews[SHADER_VARIABLE_TYPE_DYNAMIC], "Unexpected number of root views"); + m_TotalRootViews[SHADER_RESOURCE_VARIABLE_TYPE_STATIC] + + m_TotalRootViews[SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE] + + m_TotalRootViews[SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC], "Unexpected number of root views"); } #endif @@ -530,7 +530,7 @@ void RootSignature::Finalize(ID3D12Device* pd3d12Device) hr = pd3d12Device->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), __uuidof(m_pd3d12RootSignature), reinterpret_cast<void**>( static_cast<ID3D12RootSignature**>(&m_pd3d12RootSignature))); CHECK_D3D_RESULT_THROW(hr, "Failed to create root signature"); - bool bHasDynamicDescriptors = m_TotalSrvCbvUavSlots[SHADER_VARIABLE_TYPE_DYNAMIC] != 0 || m_TotalSamplerSlots[SHADER_VARIABLE_TYPE_DYNAMIC] != 0; + bool bHasDynamicDescriptors = m_TotalSrvCbvUavSlots[SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC] != 0 || m_TotalSamplerSlots[SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC] != 0; if(bHasDynamicDescriptors) { CommitDescriptorHandles = &RootSignature::CommitDescriptorHandlesInternal_SMD<false>; @@ -581,11 +581,11 @@ void RootSignature::InitResourceCache(RenderDeviceD3D12Impl* pDeviceD3D12Impl // Allocate space in GPU-visible descriptor heap for static and mutable variables only Uint32 TotalSrvCbvUavDescriptors = - m_TotalSrvCbvUavSlots[SHADER_VARIABLE_TYPE_STATIC] + - m_TotalSrvCbvUavSlots[SHADER_VARIABLE_TYPE_MUTABLE]; + m_TotalSrvCbvUavSlots[SHADER_RESOURCE_VARIABLE_TYPE_STATIC] + + m_TotalSrvCbvUavSlots[SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE]; Uint32 TotalSamplerDescriptors = - m_TotalSamplerSlots[SHADER_VARIABLE_TYPE_STATIC] + - m_TotalSamplerSlots[SHADER_VARIABLE_TYPE_MUTABLE]; + m_TotalSamplerSlots[SHADER_RESOURCE_VARIABLE_TYPE_STATIC] + + m_TotalSamplerSlots[SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE]; DescriptorHeapAllocation CbcSrvUavHeapSpace, SamplerHeapSpace; if(TotalSrvCbvUavDescriptors) @@ -624,7 +624,7 @@ void RootSignature::InitResourceCache(RenderDeviceD3D12Impl* pDeviceD3D12Impl #endif // Space for dynamic variables is allocated at every draw call - if( RootParam.GetShaderVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC ) + if( RootParam.GetShaderVariableType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC ) { if( HeapType == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV ) { @@ -886,8 +886,8 @@ void RootSignature::CommitDescriptorHandlesInternal_SMD(RenderDeviceD3D12Impl* { auto *pd3d12Device = pRenderDeviceD3D12->GetD3D12Device(); - Uint32 NumDynamicCbvSrvUavDescriptors = m_TotalSrvCbvUavSlots[SHADER_VARIABLE_TYPE_DYNAMIC]; - Uint32 NumDynamicSamplerDescriptors = m_TotalSamplerSlots [SHADER_VARIABLE_TYPE_DYNAMIC]; + Uint32 NumDynamicCbvSrvUavDescriptors = m_TotalSrvCbvUavSlots[SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC]; + Uint32 NumDynamicSamplerDescriptors = m_TotalSamplerSlots [SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC]; VERIFY_EXPR(NumDynamicCbvSrvUavDescriptors > 0 || NumDynamicSamplerDescriptors > 0); DescriptorHeapAllocation DynamicCbvSrvUavDescriptors, DynamicSamplerDescriptors; @@ -920,7 +920,7 @@ void RootSignature::CommitDescriptorHandlesInternal_SMD(RenderDeviceD3D12Impl* [&](Uint32 RootInd, const RootParameter& RootTable, const D3D12_ROOT_PARAMETER& D3D12Param, bool IsResourceTable, D3D12_DESCRIPTOR_HEAP_TYPE dbgHeapType) { D3D12_GPU_DESCRIPTOR_HANDLE RootTableGPUDescriptorHandle; - bool IsDynamicTable = RootTable.GetShaderVariableType() == SHADER_VARIABLE_TYPE_DYNAMIC; + bool IsDynamicTable = RootTable.GetShaderVariableType() == SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC; if (IsDynamicTable) { if( IsResourceTable ) @@ -1008,7 +1008,7 @@ void RootSignature::CommitDescriptorHandlesInternal_SM(RenderDeviceD3D12Impl* bool IsCompute, bool ValidateStates)const { - VERIFY_EXPR(m_TotalSrvCbvUavSlots[SHADER_VARIABLE_TYPE_DYNAMIC] == 0 && m_TotalSamplerSlots[SHADER_VARIABLE_TYPE_DYNAMIC] == 0); + VERIFY_EXPR(m_TotalSrvCbvUavSlots[SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC] == 0 && m_TotalSamplerSlots[SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC] == 0); CommandContext::ShaderDescriptorHeaps Heaps(ResourceCache.GetSrvCbvUavDescriptorHeap(), ResourceCache.GetSamplerDescriptorHeap()); if(Heaps) @@ -1017,7 +1017,7 @@ void RootSignature::CommitDescriptorHandlesInternal_SM(RenderDeviceD3D12Impl* m_RootParams.ProcessRootTables( [&](Uint32 RootInd, const RootParameter& RootTable, const D3D12_ROOT_PARAMETER& D3D12Param, bool IsResourceTable, D3D12_DESCRIPTOR_HEAP_TYPE dbgHeapType ) { - VERIFY(RootTable.GetShaderVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC, "Unexpected dynamic resource"); + VERIFY(RootTable.GetShaderVariableType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC, "Unexpected dynamic resource"); D3D12_GPU_DESCRIPTOR_HANDLE RootTableGPUDescriptorHandle = IsResourceTable ? ResourceCache.GetShaderVisibleTableGPUDescriptorHandle<D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV>(RootInd) : diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp index bdaf41b0..ba069332 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp @@ -32,40 +32,23 @@ namespace Diligent { -ShaderD3D12Impl::ShaderD3D12Impl(IReferenceCounters* pRefCounters, - RenderDeviceD3D12Impl* pRenderDeviceD3D12, - const ShaderCreationAttribs& ShaderCreationAttribs) : - TShaderBase(pRefCounters, pRenderDeviceD3D12, ShaderCreationAttribs.Desc), - ShaderD3DBase(ShaderCreationAttribs), - m_StaticResLayout(*this), - m_StaticResCache(ShaderResourceCacheD3D12::DbgCacheContentType::StaticShaderResources), - m_StaticVarsMgr(*this) +ShaderD3D12Impl::ShaderD3D12Impl(IReferenceCounters* pRefCounters, + RenderDeviceD3D12Impl* pRenderDeviceD3D12, + const ShaderCreateInfo& ShaderCI) : + TShaderBase(pRefCounters, pRenderDeviceD3D12, ShaderCI.Desc), + ShaderD3DBase(ShaderCI) { // Load shader resources auto& Allocator = GetRawAllocator(); auto* pRawMem = ALLOCATE(Allocator, "Allocator for ShaderResources", sizeof(ShaderResourcesD3D12)); - auto* pResources = new (pRawMem) ShaderResourcesD3D12(m_pShaderByteCode, m_Desc, ShaderCreationAttribs.UseCombinedTextureSamplers ? ShaderCreationAttribs.CombinedSamplerSuffix : nullptr); + auto* pResources = new (pRawMem) ShaderResourcesD3D12(m_pShaderByteCode, m_Desc, ShaderCI.UseCombinedTextureSamplers ? ShaderCI.CombinedSamplerSuffix : nullptr); m_pShaderResources.reset(pResources, STDDeleterRawMem<ShaderResourcesD3D12>(Allocator)); - - // Clone only static resources that will be set directly in the shader - // http://diligentgraphics.com/diligent-engine/architecture/d3d12/shader-resource-layout#Initializing-Special-Resource-Layout-for-Managing-Static-Shader-Resources - SHADER_VARIABLE_TYPE VarTypes[] = {SHADER_VARIABLE_TYPE_STATIC}; - m_StaticResLayout.Initialize(pRenderDeviceD3D12->GetD3D12Device(), m_pShaderResources, GetRawAllocator(), VarTypes, _countof(VarTypes), &m_StaticResCache, nullptr); - m_StaticVarsMgr.Initialize(m_StaticResLayout, GetRawAllocator(), nullptr, 0, m_StaticResCache); } ShaderD3D12Impl::~ShaderD3D12Impl() { - m_StaticVarsMgr.Destroy(GetRawAllocator()); } IMPLEMENT_QUERY_INTERFACE( ShaderD3D12Impl, IID_ShaderD3D12, TShaderBase ) -#ifdef DEVELOPMENT -bool ShaderD3D12Impl::DvpVerifyStaticResourceBindings()const -{ - return m_StaticResLayout.dvpVerifyBindings(m_StaticResCache); -} -#endif - } diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp index c8fbaeca..b8d46dbb 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp @@ -58,7 +58,7 @@ ShaderResourceBindingD3D12Impl::ShaderResourceBindingD3D12Impl(IReferenceCounter auto& VarDataAllocator = pPSO->GetSRBMemoryAllocator().GetShaderVariableDataAllocator(s); // http://diligentgraphics.com/diligent-engine/architecture/d3d12/shader-resource-layout#Initializing-Resource-Layouts-in-a-Shader-Resource-Binding-Object - std::array<SHADER_VARIABLE_TYPE, 2> AllowedVarTypes = { SHADER_VARIABLE_TYPE_MUTABLE, SHADER_VARIABLE_TYPE_DYNAMIC }; + std::array<SHADER_RESOURCE_VARIABLE_TYPE, 2> AllowedVarTypes = { SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC }; const auto& SrcLayout = pPSO->GetShaderResLayout(s); m_pShaderVarMgrs[s].Initialize(SrcLayout, VarDataAllocator, AllowedVarTypes.data(), static_cast<Uint32>(AllowedVarTypes.size()), m_ShaderResourceCache); @@ -96,7 +96,7 @@ void ShaderResourceBindingD3D12Impl::BindResources(Uint32 ShaderFlags, IResource } } -IShaderVariable *ShaderResourceBindingD3D12Impl::GetVariable(SHADER_TYPE ShaderType, const char *Name) +IShaderResourceVariable *ShaderResourceBindingD3D12Impl::GetVariable(SHADER_TYPE ShaderType, const char *Name) { auto ShaderInd = GetShaderTypeIndex(ShaderType); auto ResLayoutInd = m_ResourceLayoutIndex[ShaderInd]; @@ -121,7 +121,7 @@ Uint32 ShaderResourceBindingD3D12Impl::GetVariableCount(SHADER_TYPE ShaderType) return m_pShaderVarMgrs[ResLayoutInd].GetVariableCount(); } -IShaderVariable* ShaderResourceBindingD3D12Impl::GetVariable(SHADER_TYPE ShaderType, Uint32 Index) +IShaderResourceVariable* ShaderResourceBindingD3D12Impl::GetVariable(SHADER_TYPE ShaderType, Uint32 Index) { auto ShaderInd = GetShaderTypeIndex(ShaderType); auto ResLayoutInd = m_ResourceLayoutIndex[ShaderInd]; diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp index eada5310..ca133acc 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp @@ -33,6 +33,7 @@ #include "ShaderD3D12Impl.h" #include "RootSignature.h" #include "PipelineStateD3D12Impl.h" +#include "ShaderResourceVariableBase.h" namespace Diligent { @@ -78,20 +79,21 @@ D3D12_DESCRIPTOR_RANGE_TYPE GetDescriptorRangeType(CachedResourceType ResType) return ResTypeToDescrRangeTypeMap[ResType]; } -void ShaderResourceLayoutD3D12::AllocateMemory(IMemoryAllocator& Allocator, - const std::array<Uint32, SHADER_VARIABLE_TYPE_NUM_TYPES>& CbvSrvUavCount, - const std::array<Uint32, SHADER_VARIABLE_TYPE_NUM_TYPES>& SamplerCount) + +void ShaderResourceLayoutD3D12::AllocateMemory(IMemoryAllocator& Allocator, + const std::array<Uint32, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES>& CbvSrvUavCount, + const std::array<Uint32, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES>& SamplerCount) { m_CbvSrvUavOffsets[0] = 0; - for(SHADER_VARIABLE_TYPE VarType = SHADER_VARIABLE_TYPE_STATIC; VarType < SHADER_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_VARIABLE_TYPE>(VarType+1)) + for (SHADER_RESOURCE_VARIABLE_TYPE VarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; VarType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(VarType+1)) { VERIFY(m_CbvSrvUavOffsets[VarType] + CbvSrvUavCount[VarType] <= std::numeric_limits<Uint16>::max(), "Offset is not representable in 16 bits" ); m_CbvSrvUavOffsets[VarType+1] = static_cast<Uint16>(m_CbvSrvUavOffsets[VarType] + CbvSrvUavCount[VarType]); VERIFY_EXPR(GetCbvSrvUavCount(VarType) == CbvSrvUavCount[VarType]); } - m_SamplersOffsets[0] = m_CbvSrvUavOffsets[SHADER_VARIABLE_TYPE_NUM_TYPES]; - for(SHADER_VARIABLE_TYPE VarType = SHADER_VARIABLE_TYPE_STATIC; VarType < SHADER_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_VARIABLE_TYPE>(VarType+1)) + m_SamplersOffsets[0] = m_CbvSrvUavOffsets[SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES]; + for (SHADER_RESOURCE_VARIABLE_TYPE VarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; VarType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(VarType+1)) { VERIFY(m_SamplersOffsets[VarType] + SamplerCount[VarType] <= std::numeric_limits<Uint16>::max(), "Offset is not representable in 16 bits" ); m_SamplersOffsets[VarType+1] = static_cast<Uint16>(m_SamplersOffsets[VarType] + SamplerCount[VarType]); @@ -102,7 +104,7 @@ void ShaderResourceLayoutD3D12::AllocateMemory(IMemoryAllocator& if(MemSize == 0) return; - auto *pRawMem = ALLOCATE(Allocator, "Raw memory buffer for shader resource layout resources", MemSize); + auto* pRawMem = ALLOCATE(Allocator, "Raw memory buffer for shader resource layout resources", MemSize); m_ResourceBuffer = std::unique_ptr<void, STDDeleterRawMem<void> >(pRawMem, Allocator); } @@ -110,9 +112,10 @@ void ShaderResourceLayoutD3D12::AllocateMemory(IMemoryAllocator& // http://diligentgraphics.com/diligent-engine/architecture/d3d12/shader-resource-layout#Initializing-Shader-Resource-Layouts-and-Root-Signature-in-a-Pipeline-State-Object // http://diligentgraphics.com/diligent-engine/architecture/d3d12/shader-resource-cache#Initializing-Shader-Resource-Layouts-in-a-Pipeline-State void ShaderResourceLayoutD3D12::Initialize(ID3D12Device* pd3d12Device, + const PipelineResourceLayoutDesc& ResourceLayout, std::shared_ptr<const ShaderResourcesD3D12> pSrcResources, IMemoryAllocator& LayoutDataAllocator, - const SHADER_VARIABLE_TYPE* AllowedVarTypes, + const SHADER_RESOURCE_VARIABLE_TYPE* const AllowedVarTypes, Uint32 NumAllowedTypes, ShaderResourceCacheD3D12* pResourceCache, RootSignature* pRootSig) @@ -122,67 +125,78 @@ void ShaderResourceLayoutD3D12::Initialize(ID3D12Device* VERIFY_EXPR( (pResourceCache != nullptr) ^ (pRootSig != nullptr) ); - Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes); + const Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes); - std::array<Uint32, SHADER_VARIABLE_TYPE_NUM_TYPES> CbvSrvUavCount = {}; - std::array<Uint32, SHADER_VARIABLE_TYPE_NUM_TYPES> SamplerCount = {}; + std::array<Uint32, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES> CbvSrvUavCount = {}; + std::array<Uint32, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES> SamplerCount = {}; // Count number of resources to allocate all needed memory m_pResources->ProcessResources( - AllowedVarTypes, NumAllowedTypes, - [&](const D3DShaderResourceAttribs& CB, Uint32) { - VERIFY_EXPR(CB.IsAllowedType(AllowedTypeBits)); - ++CbvSrvUavCount[CB.GetVariableType()]; + auto VarType = m_pResources->FindVariableType(CB, ResourceLayout); + if (IsAllowedType(VarType, AllowedTypeBits)) + ++CbvSrvUavCount[VarType]; }, [&](const D3DShaderResourceAttribs& Sam, Uint32) { - VERIFY_EXPR(Sam.IsAllowedType(AllowedTypeBits)); - if (!Sam.IsStaticSampler()) + auto VarType = m_pResources->FindVariableType(Sam, ResourceLayout); + if (IsAllowedType(VarType, AllowedTypeBits)) { - ++SamplerCount[Sam.GetVariableType()]; + auto StaticSamplerInd = m_pResources->FindStaticSampler(Sam, ResourceLayout); + // Skip static samplers + if (StaticSamplerInd < 0) + ++SamplerCount[VarType]; } }, [&](const D3DShaderResourceAttribs& TexSRV, Uint32) { - VERIFY_EXPR(TexSRV.IsAllowedType(AllowedTypeBits)); - auto VarType = TexSRV.GetVariableType(); - ++CbvSrvUavCount[VarType]; - if(TexSRV.ValidSamplerAssigned()) + auto VarType = m_pResources->FindVariableType(TexSRV, ResourceLayout); + if (IsAllowedType(VarType, AllowedTypeBits)) { - auto SamplerId = TexSRV.GetSamplerId(); - const auto& SamplerAttribs = m_pResources->GetSampler(SamplerId); - DEV_CHECK_ERR(SamplerAttribs.GetVariableType() == TexSRV.GetVariableType(), - "The type (", GetShaderVariableTypeLiteralName(TexSRV.GetVariableType()),") of texture SRV variable '", TexSRV.Name, - "' is not consistent with the type (", GetShaderVariableTypeLiteralName(SamplerAttribs.GetVariableType()), - ") of the sampler '", SamplerAttribs.Name, "' that is assigned to it"); + ++CbvSrvUavCount[VarType]; + if (TexSRV.ValidSamplerAssigned()) + { + auto SamplerId = TexSRV.GetSamplerId(); + const auto& SamplerAttribs = m_pResources->GetSampler(SamplerId); + auto SamplerVarType = m_pResources->FindVariableType(SamplerAttribs, ResourceLayout); + DEV_CHECK_ERR(SamplerVarType == VarType, + "The type (", GetShaderVariableTypeLiteralName(VarType),") of texture SRV variable '", TexSRV.Name, + "' is not consistent with the type (", GetShaderVariableTypeLiteralName(SamplerVarType), + ") of the sampler '", SamplerAttribs.Name, "' that is assigned to it"); (void)SamplerVarType; + } } }, [&](const D3DShaderResourceAttribs& TexUAV, Uint32) { - VERIFY_EXPR(TexUAV.IsAllowedType(AllowedTypeBits)); - ++CbvSrvUavCount[TexUAV.GetVariableType()]; + auto VarType = m_pResources->FindVariableType(TexUAV, ResourceLayout); + if (IsAllowedType(VarType, AllowedTypeBits)) + ++CbvSrvUavCount[VarType]; }, [&](const D3DShaderResourceAttribs& BufSRV, Uint32) { - VERIFY_EXPR(BufSRV.IsAllowedType(AllowedTypeBits)); - ++CbvSrvUavCount[BufSRV.GetVariableType()]; + auto VarType = m_pResources->FindVariableType(BufSRV, ResourceLayout); + if (IsAllowedType(VarType, AllowedTypeBits)) + ++CbvSrvUavCount[VarType]; }, [&](const D3DShaderResourceAttribs& BufUAV, Uint32) { - VERIFY_EXPR(BufUAV.IsAllowedType(AllowedTypeBits)); - ++CbvSrvUavCount[BufUAV.GetVariableType()]; + auto VarType = m_pResources->FindVariableType(BufUAV, ResourceLayout); + if (IsAllowedType(VarType, AllowedTypeBits)) + ++CbvSrvUavCount[VarType]; } ); AllocateMemory(LayoutDataAllocator, CbvSrvUavCount, SamplerCount); - std::array<Uint32, SHADER_VARIABLE_TYPE_NUM_TYPES> CurrCbvSrvUav = {}; - std::array<Uint32, SHADER_VARIABLE_TYPE_NUM_TYPES> CurrSampler = {}; + std::array<Uint32, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES> CurrCbvSrvUav = {}; + std::array<Uint32, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES> CurrSampler = {}; Uint32 StaticResCacheTblSizes[4] = {0, 0, 0, 0}; - auto AddResource = [&](const D3DShaderResourceAttribs& Attribs, CachedResourceType ResType, Uint32 SamplerId = D3D12Resource::InvalidSamplerId) + auto AddResource = [&](const D3DShaderResourceAttribs& Attribs, + CachedResourceType ResType, + SHADER_RESOURCE_VARIABLE_TYPE VarType, + Uint32 SamplerId = D3D12Resource::InvalidSamplerId) { Uint32 RootIndex = D3D12Resource::InvalidRootIndex; Uint32 Offset = D3D12Resource::InvalidOffset; @@ -214,92 +228,112 @@ void ShaderResourceLayoutD3D12::Initialize(ID3D12Device* VERIFY(Offset != D3D12Resource::InvalidOffset, "Offset must be valid"); // Static samplers are never copied, and SamplerId == InvalidSamplerId - auto VarType = Attribs.GetVariableType(); auto& NewResource = (ResType == CachedResourceType::Sampler) ? GetSampler (VarType, CurrSampler [VarType]++) : GetSrvCbvUav(VarType, CurrCbvSrvUav[VarType]++); - ::new (&NewResource) D3D12Resource(*this, Attribs, ResType, RootIndex, Offset, SamplerId); + ::new (&NewResource) D3D12Resource(*this, Attribs, VarType, ResType, RootIndex, Offset, SamplerId); }; m_pResources->ProcessResources( - AllowedVarTypes, NumAllowedTypes, - [&](const D3DShaderResourceAttribs& CB, Uint32) { - VERIFY_EXPR( CB.IsAllowedType(AllowedTypeBits) ); - AddResource(CB, CachedResourceType::CBV); + auto VarType = m_pResources->FindVariableType(CB, ResourceLayout); + if (IsAllowedType(VarType, AllowedTypeBits)) + AddResource(CB, CachedResourceType::CBV, VarType); }, [&](const D3DShaderResourceAttribs& Sam, Uint32) { - VERIFY_EXPR( Sam.IsAllowedType(AllowedTypeBits) ); - if (Sam.IsStaticSampler()) + auto VarType = m_pResources->FindVariableType(Sam, ResourceLayout); + if (IsAllowedType(VarType, AllowedTypeBits)) { - if (pRootSig != nullptr) - pRootSig->InitStaticSampler(m_pResources->GetShaderType(), Sam.Name, m_pResources->GetCombinedSamplerSuffix(), Sam); - } - else - { - AddResource(Sam, CachedResourceType::Sampler); + auto StaticSamplerInd = m_pResources->FindStaticSampler(Sam, ResourceLayout); + if (StaticSamplerInd >= 0) + { + if (pRootSig != nullptr) + pRootSig->InitStaticSampler(m_pResources->GetShaderType(), Sam.Name, m_pResources->GetCombinedSamplerSuffix(), Sam); + } + else + { + AddResource(Sam, CachedResourceType::Sampler, VarType); + } } }, [&](const D3DShaderResourceAttribs& TexSRV, Uint32) { - VERIFY_EXPR(TexSRV.IsAllowedType(AllowedTypeBits) ); - static_assert(SHADER_VARIABLE_TYPE_NUM_TYPES == 3, "Unexpected number of shader variable types"); - VERIFY(CurrSampler[SHADER_VARIABLE_TYPE_STATIC] + CurrSampler[SHADER_VARIABLE_TYPE_MUTABLE] + CurrSampler[SHADER_VARIABLE_TYPE_DYNAMIC] == GetTotalSamplerCount(), "All samplers must be initialized before texture SRVs"); - - Uint32 SamplerId = D3D12Resource::InvalidSamplerId; - if (TexSRV.ValidSamplerAssigned()) + auto VarType = m_pResources->FindVariableType(TexSRV, ResourceLayout); + if (IsAllowedType(VarType, AllowedTypeBits)) { - const auto& SamplerAttribs = m_pResources->GetSampler(TexSRV.GetSamplerId()); - DEV_CHECK_ERR(SamplerAttribs.GetVariableType() == TexSRV.GetVariableType(), - "The type (", GetShaderVariableTypeLiteralName(TexSRV.GetVariableType()),") of texture SRV variable '", TexSRV.Name, - "' is not consistent with the type (", GetShaderVariableTypeLiteralName(SamplerAttribs.GetVariableType()), - ") of the sampler '", SamplerAttribs.Name, "' that is assigned to it"); - - if (SamplerAttribs.IsStaticSampler()) - { - // Static samplers are never copied, and SamplerId == InvalidSamplerId - } - else + static_assert(SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES == 3, "Unexpected number of shader variable types"); + VERIFY(CurrSampler[SHADER_RESOURCE_VARIABLE_TYPE_STATIC] + CurrSampler[SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE] + CurrSampler[SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC] == GetTotalSamplerCount(), "All samplers must be initialized before texture SRVs"); + + Uint32 SamplerId = D3D12Resource::InvalidSamplerId; + if (TexSRV.ValidSamplerAssigned()) { - auto SamplerCount = GetTotalSamplerCount(); - for (SamplerId = 0; SamplerId < SamplerCount; ++SamplerId) + const auto& SamplerAttribs = m_pResources->GetSampler(TexSRV.GetSamplerId()); + auto SamplerVarType = m_pResources->FindVariableType(SamplerAttribs, ResourceLayout); + DEV_CHECK_ERR(SamplerVarType == VarType, + "The type (", GetShaderVariableTypeLiteralName(VarType),") of texture SRV variable '", TexSRV.Name, + "' is not consistent with the type (", GetShaderVariableTypeLiteralName(SamplerVarType), + ") of the sampler '", SamplerAttribs.Name, "' that is assigned to it"); + + auto StaticSamplerInd = m_pResources->FindStaticSampler(SamplerAttribs, ResourceLayout); + if (StaticSamplerInd >= 0) { - const auto& Sampler = GetSampler(SamplerId); - if (strcmp(Sampler.Attribs.Name, SamplerAttribs.Name) == 0) - break; + // Static samplers are never copied, and SamplerId == InvalidSamplerId +#ifdef _DEBUG + auto SamplerCount = GetTotalSamplerCount(); + for (SamplerId = 0; SamplerId < SamplerCount; ++SamplerId) + { + const auto& Sampler = GetSampler(SamplerId); + if (strcmp(Sampler.Attribs.Name, SamplerAttribs.Name) == 0) + LOG_ERROR("Static sampler '", Sampler.Attribs.Name, "' was found among resources. This seems to be a bug"); + } +#endif } - if (SamplerId == SamplerCount) + else { - LOG_ERROR("Unable to find sampler '", SamplerAttribs.Name, "' assigned to texture SRV '", TexSRV.Name, "' in the list of already created resources. This seems to be a bug."); - SamplerId = D3D12Resource::InvalidSamplerId; + auto SamplerCount = GetTotalSamplerCount(); + for (SamplerId = 0; SamplerId < SamplerCount; ++SamplerId) + { + const auto& Sampler = GetSampler(SamplerId); + if (strcmp(Sampler.Attribs.Name, SamplerAttribs.Name) == 0) + break; + } + + if (SamplerId == SamplerCount) + { + LOG_ERROR("Unable to find sampler '", SamplerAttribs.Name, "' assigned to texture SRV '", TexSRV.Name, "' in the list of already created resources. This seems to be a bug."); + SamplerId = D3D12Resource::InvalidSamplerId; + } + VERIFY(SamplerId <= D3D12Resource::MaxSamplerId, "Sampler index excceeds allowed limit"); } - VERIFY(SamplerId <= D3D12Resource::MaxSamplerId, "Sampler index excceeds allowed limit"); } + AddResource(TexSRV, CachedResourceType::TexSRV, VarType, SamplerId); } - AddResource(TexSRV, CachedResourceType::TexSRV, SamplerId); }, [&](const D3DShaderResourceAttribs& TexUAV, Uint32) { - VERIFY_EXPR( TexUAV.IsAllowedType(AllowedTypeBits) ); - AddResource(TexUAV, CachedResourceType::TexUAV); + auto VarType = m_pResources->FindVariableType(TexUAV, ResourceLayout); + if (IsAllowedType(VarType, AllowedTypeBits)) + AddResource(TexUAV, CachedResourceType::TexUAV, VarType); }, [&](const D3DShaderResourceAttribs& BufSRV, Uint32) { - VERIFY_EXPR( BufSRV.IsAllowedType(AllowedTypeBits) ); - AddResource(BufSRV, CachedResourceType::BufSRV); + auto VarType = m_pResources->FindVariableType(BufSRV, ResourceLayout); + if (IsAllowedType(VarType, AllowedTypeBits)) + AddResource(BufSRV, CachedResourceType::BufSRV, VarType); }, [&](const D3DShaderResourceAttribs& BufUAV, Uint32) { - VERIFY_EXPR( BufUAV.IsAllowedType(AllowedTypeBits) ); - AddResource(BufUAV, CachedResourceType::BufUAV); + auto VarType = m_pResources->FindVariableType(BufUAV, ResourceLayout); + if (IsAllowedType(VarType, AllowedTypeBits)) + AddResource(BufUAV, CachedResourceType::BufUAV, VarType); } ); #ifdef _DEBUG - for(SHADER_VARIABLE_TYPE VarType = SHADER_VARIABLE_TYPE_STATIC; VarType < SHADER_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_VARIABLE_TYPE>(VarType+1)) + for(SHADER_RESOURCE_VARIABLE_TYPE VarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; VarType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(VarType+1)) { VERIFY( CurrCbvSrvUav[VarType] == CbvSrvUavCount[VarType], "Not all Srv/Cbv/Uavs are initialized, which result in a crash when dtor is called" ); VERIFY( CurrSampler[VarType] == SamplerCount [VarType], "Not all Samplers are initialized, which result in a crash when dtor is called" ); @@ -326,7 +360,7 @@ void ShaderResourceLayoutD3D12::Initialize(ID3D12Device* #define LOG_RESOURCE_BINDING_ERROR(ResType, pResource, VarName, ShaderName, ...)\ { \ - const auto &ResName = pResource->GetDesc().Name; \ + const auto& ResName = pResource->GetDesc().Name; \ LOG_ERROR_MESSAGE( "Failed to bind ", ResType, " '", ResName, "' to variable '", VarName, \ "' in shader '", ShaderName, "'. ", __VA_ARGS__ ); \ } @@ -347,11 +381,11 @@ void ShaderResourceLayoutD3D12::D3D12Resource::CacheCB(IDeviceObject* { if (pBuffD3D12->GetDesc().BindFlags & BIND_UNIFORM_BUFFER) { - if (Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC && DstRes.pObject != nullptr) + if (GetVariableType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC && DstRes.pObject != nullptr) { if (DstRes.pObject != pBuffD3D12) { - auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType()); + auto VarTypeStr = GetShaderVariableTypeLiteralName(GetVariableType()); LOG_ERROR_MESSAGE( "Non-null constant buffer is already bound to ", VarTypeStr, " shader variable '", Attribs.GetPrintName(ArrayInd), "' in shader '", ParentResLayout.GetShaderName(), "'. Attempting to bind another constant buffer is an error and will be ignored. Use another shader resource binding instance or label the variable as dynamic." ); } @@ -429,19 +463,21 @@ void ShaderResourceLayoutD3D12::D3D12Resource::CacheResourceView(IDeviceObject* auto ViewType = ViewDesc.ViewType; if (ViewType != dbgExpectedViewType) { - const auto *ExpectedViewTypeName = GetViewTypeLiteralName( dbgExpectedViewType ); - const auto *ActualViewTypeName = GetViewTypeLiteralName( ViewType ); + const auto* ExpectedViewTypeName = GetViewTypeLiteralName( dbgExpectedViewType ); + const auto* ActualViewTypeName = GetViewTypeLiteralName( ViewType ); LOG_RESOURCE_BINDING_ERROR(ResourceViewTraits<TResourceViewType>::Name, pViewD3D12, Attribs.GetPrintName(ArrayIndex), ParentResLayout.GetShaderName(), "Incorrect view type: ", ExpectedViewTypeName, " is expected, ", ActualViewTypeName, " provided." ); return; } #endif - if (Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC && DstRes.pObject != nullptr) + if (GetVariableType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC && DstRes.pObject != nullptr) { if (DstRes.pObject != pViewD3D12) { - auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType()); - LOG_ERROR_MESSAGE( "Non-null resource is already bound to ", VarTypeStr, " shader variable '", Attribs.GetPrintName(ArrayIndex), "' in shader '", ParentResLayout.GetShaderName(), "'. Attempting to bind another resource or null is an error and will be ignored. Use another shader resource binding instance or label the variable as dynamic." ); + auto VarTypeStr = GetShaderVariableTypeLiteralName(GetVariableType()); + LOG_ERROR_MESSAGE( "Non-null resource is already bound to ", VarTypeStr, " shader variable '", Attribs.GetPrintName(ArrayIndex), "' in shader '", + ParentResLayout.GetShaderName(), "'. Attempting to bind another resource or null is an error and will be " + "ignored. Use another shader resource binding instance or label the variable as dynamic." ); } // Do not update resource if one is already bound unless it is dynamic. This may be @@ -484,11 +520,11 @@ void ShaderResourceLayoutD3D12::D3D12Resource::CacheSampler(IDeviceObject* RefCntAutoPtr<ISamplerD3D12> pSamplerD3D12(pSampler, IID_SamplerD3D12); if (pSamplerD3D12) { - if (Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC && DstSam.pObject != nullptr) + if (GetVariableType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC && DstSam.pObject != nullptr) { if (DstSam.pObject != pSampler) { - auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType()); + auto VarTypeStr = GetShaderVariableTypeLiteralName(GetVariableType()); LOG_ERROR_MESSAGE( "Non-null sampler is already bound to ", VarTypeStr, " shader variable '", Attribs.GetPrintName(ArrayIndex), "' in shader '", ParentResLayout.GetShaderName(), "'. Attempting to bind another sampler is an error and will be ignored. Use another shader resource binding instance or label the variable as dynamic." ); } @@ -525,7 +561,7 @@ const ShaderResourceLayoutD3D12::D3D12Resource& ShaderResourceLayoutD3D12::GetAs VERIFY(TexSrv.GetResType() == CachedResourceType::TexSRV, "Unexpected resource type: texture SRV is expected"); VERIFY(TexSrv.ValidSamplerAssigned(), "Texture SRV has no associated sampler"); const auto& SamInfo = GetSampler(TexSrv.SamplerId); - VERIFY(SamInfo.Attribs.GetVariableType() == TexSrv.Attribs.GetVariableType(), "Inconsistent texture and sampler variable types"); + VERIFY(SamInfo.GetVariableType() == TexSrv.GetVariableType(), "Inconsistent texture and sampler variable types"); VERIFY(StreqSuff(SamInfo.Attribs.Name, TexSrv.Attribs.Name, m_pResources->GetCombinedSamplerSuffix()), "Sampler name '", SamInfo.Attribs.Name, "' does not match texture name '", TexSrv.Attribs.Name, '\''); return SamInfo; } @@ -563,7 +599,7 @@ void ShaderResourceLayoutD3D12::D3D12Resource::BindResource(IDeviceObject* } else { - if(Attribs.GetVariableType() == SHADER_VARIABLE_TYPE_DYNAMIC) + if(GetVariableType() == SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC) VERIFY(ShdrVisibleHeapCPUDescriptorHandle.ptr == 0, "Dynamic resources of a shader resource binding should be assigned shader visible descriptor space at every draw call"); else VERIFY(ShdrVisibleHeapCPUDescriptorHandle.ptr != 0, "Non-dynamics resources of a shader resource binding must be assigned shader visible descriptor space"); @@ -587,10 +623,10 @@ void ShaderResourceLayoutD3D12::D3D12Resource::BindResource(IDeviceObject* case CachedResourceType::TexSRV: CacheResourceView<ITextureViewD3D12>(pObj, DstRes, ArrayIndex, ShdrVisibleHeapCPUDescriptorHandle, TEXTURE_VIEW_SHADER_RESOURCE, [&](ITextureViewD3D12* pTexView) { - if(ValidSamplerAssigned()) + if (ValidSamplerAssigned()) { auto& Sam = ParentResLayout.GetAssignedSampler(*this); - VERIFY( !Sam.Attribs.IsStaticSampler(), "Static samplers should never be assigned space in the cache" ); + //VERIFY( !Sam.Attribs.IsStaticSampler(), "Static samplers should never be assigned space in the cache" ); VERIFY_EXPR(Attribs.BindCount == Sam.Attribs.BindCount || Sam.Attribs.BindCount == 1); auto SamplerArrInd = Sam.Attribs.BindCount > 1 ? ArrayIndex : 0; auto ShdrVisibleSamplerHeapCPUDescriptorHandle = ResourceCache.GetShaderVisibleTableCPUDescriptorHandle<D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER>(Sam.RootIndex, Sam.OffsetFromTableStart + SamplerArrInd); @@ -603,7 +639,7 @@ void ShaderResourceLayoutD3D12::D3D12Resource::BindResource(IDeviceObject* } else if (ResourceCache.DbgGetContentType() == ShaderResourceCacheD3D12::DbgCacheContentType::SRBResources) { - if(Attribs.GetVariableType() == SHADER_VARIABLE_TYPE_DYNAMIC) + if(GetVariableType() == SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC) VERIFY(ShdrVisibleSamplerHeapCPUDescriptorHandle.ptr == 0, "Dynamic resources of a shader resource binding should be assigned shader visible descriptor space at every draw call"); else VERIFY(ShdrVisibleSamplerHeapCPUDescriptorHandle.ptr != 0 || pTexView == nullptr, "Non-dynamics resources of a shader resource binding must be assigned shader visible descriptor space"); @@ -649,7 +685,7 @@ void ShaderResourceLayoutD3D12::D3D12Resource::BindResource(IDeviceObject* } else { - if (DstRes.pObject != nullptr && Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC) + if (DstRes.pObject != nullptr && GetVariableType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC) LOG_ERROR_MESSAGE( "Shader variable '", Attribs.Name, "' in shader '", ParentResLayout.GetShaderName(), "' is not dynamic but is being reset to null. This is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic if you need to bind another resource." ); DstRes = ShaderResourceCacheD3D12::Resource{}; @@ -659,7 +695,7 @@ void ShaderResourceLayoutD3D12::D3D12Resource::BindResource(IDeviceObject* D3D12_CPU_DESCRIPTOR_HANDLE NullHandle = {0}; auto SamplerArrInd = Sam.Attribs.BindCount > 1 ? ArrayIndex : 0; auto& DstSam = ResourceCache.GetRootTable(Sam.RootIndex).GetResource(Sam.OffsetFromTableStart + SamplerArrInd, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, ParentResLayout.m_pResources->GetShaderType()); - if (DstSam.pObject != nullptr && Sam.Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC) + if (DstSam.pObject != nullptr && Sam.GetVariableType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC) LOG_ERROR_MESSAGE( "Sampler variable '", Sam.Attribs.Name, "' in shader '", ParentResLayout.GetShaderName(), "' is not dynamic but is being reset to null. This is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic if you need to bind another sampler." ); DstSam = ShaderResourceCacheD3D12::Resource{}; } @@ -699,13 +735,13 @@ void ShaderResourceLayoutD3D12::CopyStaticResourceDesriptorHandles(const ShaderR // Samplers at root index D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER // Every resource is stored at offset that equals resource bind point - auto CbvSrvUavCount = DstLayout.GetCbvSrvUavCount(SHADER_VARIABLE_TYPE_STATIC); - VERIFY(GetCbvSrvUavCount(SHADER_VARIABLE_TYPE_STATIC) == CbvSrvUavCount, "Number of static resources in the source cache (", GetCbvSrvUavCount(SHADER_VARIABLE_TYPE_STATIC), ") is not consistent with the number of static resources in destination cache (", CbvSrvUavCount, ")" ); + auto CbvSrvUavCount = DstLayout.GetCbvSrvUavCount(SHADER_RESOURCE_VARIABLE_TYPE_STATIC); + VERIFY(GetCbvSrvUavCount(SHADER_RESOURCE_VARIABLE_TYPE_STATIC) == CbvSrvUavCount, "Number of static resources in the source cache (", GetCbvSrvUavCount(SHADER_RESOURCE_VARIABLE_TYPE_STATIC), ") is not consistent with the number of static resources in destination cache (", CbvSrvUavCount, ")" ); for(Uint32 r=0; r < CbvSrvUavCount; ++r) { // Get resource attributes - const auto& res = DstLayout.GetSrvCbvUav(SHADER_VARIABLE_TYPE_STATIC, r); + const auto& res = DstLayout.GetSrvCbvUav(SHADER_RESOURCE_VARIABLE_TYPE_STATIC, r); auto RangeType = GetDescriptorRangeType(res.GetResType()); for(Uint32 ArrInd = 0; ArrInd < res.Attribs.BindCount; ++ArrInd) { @@ -748,18 +784,18 @@ void ShaderResourceLayoutD3D12::CopyStaticResourceDesriptorHandles(const ShaderR { const auto& SamInfo = DstLayout.GetAssignedSampler(res); - VERIFY(!SamInfo.Attribs.IsStaticSampler(), "Static samplers should never be assigned space in the cache"); + //VERIFY(!SamInfo.Attribs.IsStaticSampler(), "Static samplers should never be assigned space in the cache"); VERIFY(SamInfo.Attribs.IsValidBindPoint(), "Sampler bind point must be valid"); VERIFY_EXPR(SamInfo.Attribs.BindCount == res.Attribs.BindCount || SamInfo.Attribs.BindCount == 1); } } - auto SamplerCount = DstLayout.GetSamplerCount(SHADER_VARIABLE_TYPE_STATIC); - VERIFY(GetSamplerCount(SHADER_VARIABLE_TYPE_STATIC) == SamplerCount, "Number of static-type samplers in the source cache (", GetSamplerCount(SHADER_VARIABLE_TYPE_STATIC), ") is not consistent with the number of static-type samplers in destination cache (", SamplerCount, ")" ); + auto SamplerCount = DstLayout.GetSamplerCount(SHADER_RESOURCE_VARIABLE_TYPE_STATIC); + VERIFY(GetSamplerCount(SHADER_RESOURCE_VARIABLE_TYPE_STATIC) == SamplerCount, "Number of static-type samplers in the source cache (", GetSamplerCount(SHADER_RESOURCE_VARIABLE_TYPE_STATIC), ") is not consistent with the number of static-type samplers in destination cache (", SamplerCount, ")" ); for(Uint32 s=0; s < SamplerCount; ++s) { - const auto& SamInfo = DstLayout.GetSampler(SHADER_VARIABLE_TYPE_STATIC, s); + const auto& SamInfo = DstLayout.GetSampler(SHADER_RESOURCE_VARIABLE_TYPE_STATIC, s); for(Uint32 ArrInd = 0; ArrInd < SamInfo.Attribs.BindCount; ++ArrInd) { auto BindPoint = SamInfo.Attribs.BindPoint + ArrInd; @@ -768,7 +804,7 @@ void ShaderResourceLayoutD3D12::CopyStaticResourceDesriptorHandles(const ShaderR const auto& SrcSampler = SrcCache.GetRootTable(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER).GetResource(BindPoint, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, m_pResources->GetShaderType()); if( !SrcSampler.pObject ) LOG_ERROR_MESSAGE( "No sampler assigned to static shader variable '", SamInfo.Attribs.GetPrintName(ArrInd), "' in shader '", GetShaderName(), "'." ); - auto &DstSampler = DstCache.GetRootTable(SamInfo.RootIndex).GetResource(SamInfo.OffsetFromTableStart + ArrInd, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, m_pResources->GetShaderType()); + auto& DstSampler = DstCache.GetRootTable(SamInfo.RootIndex).GetResource(SamInfo.OffsetFromTableStart + ArrInd, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, m_pResources->GetShaderType()); if(DstSampler.pObject != SrcSampler.pObject) { @@ -800,12 +836,12 @@ void ShaderResourceLayoutD3D12::CopyStaticResourceDesriptorHandles(const ShaderR bool ShaderResourceLayoutD3D12::dvpVerifyBindings(const ShaderResourceCacheD3D12& ResourceCache)const { bool BindingsOK = true; - for (SHADER_VARIABLE_TYPE VarType = SHADER_VARIABLE_TYPE_STATIC; VarType < SHADER_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_VARIABLE_TYPE>(VarType+1)) + for (SHADER_RESOURCE_VARIABLE_TYPE VarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; VarType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(VarType+1)) { for (Uint32 r=0; r < GetCbvSrvUavCount(VarType); ++r) { const auto& res = GetSrvCbvUav(VarType, r); - VERIFY(res.Attribs.GetVariableType() == VarType, "Unexpected variable type"); + VERIFY(res.GetVariableType() == VarType, "Unexpected variable type"); for (Uint32 ArrInd = 0; ArrInd < res.Attribs.BindCount; ++ArrInd) { @@ -819,7 +855,7 @@ bool ShaderResourceLayoutD3D12::dvpVerifyBindings(const ShaderResourceCacheD3D12 // Dynamic buffers do not have CPU descriptor handle as they do not keep D3D12 buffer, and space is allocated from the GPU ring buffer CachedRes.CPUDescriptorHandle.ptr == 0 && !(CachedRes.Type==CachedResourceType::CBV && CachedRes.pObject.RawPtr<const BufferD3D12Impl>()->GetDesc().Usage == USAGE_DYNAMIC) ) { - LOG_ERROR_MESSAGE( "No resource is bound to ", GetShaderVariableTypeLiteralName(res.Attribs.GetVariableType()), " variable '", res.Attribs.GetPrintName(ArrInd), "' in shader '", GetShaderName(), "'" ); + LOG_ERROR_MESSAGE( "No resource is bound to ", GetShaderVariableTypeLiteralName(res.GetVariableType()), " variable '", res.Attribs.GetPrintName(ArrInd), "' in shader '", GetShaderName(), "'" ); BindingsOK = false; } @@ -857,7 +893,7 @@ bool ShaderResourceLayoutD3D12::dvpVerifyBindings(const ShaderResourceCacheD3D12 } else { - if (res.Attribs.GetVariableType() == SHADER_VARIABLE_TYPE_DYNAMIC) + if (res.GetVariableType() == SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC) VERIFY(ShdrVisibleHeapCPUDescriptorHandle.ptr == 0, "Dynamic resources of a shader resource binding should be assigned shader visible descriptor space at every draw call"); else VERIFY(ShdrVisibleHeapCPUDescriptorHandle.ptr != 0, "Non-dynamics resources of a shader resource binding must be assigned shader visible descriptor space"); @@ -875,7 +911,7 @@ bool ShaderResourceLayoutD3D12::dvpVerifyBindings(const ShaderResourceCacheD3D12 { VERIFY(res.GetResType() == CachedResourceType::TexSRV, "Sampler can only be assigned to a texture SRV" ); const auto& SamInfo = GetAssignedSampler(res); - VERIFY(!SamInfo.Attribs.IsStaticSampler(), "Static samplers should never be assigned space in the cache" ); + //VERIFY(!SamInfo.Attribs.IsStaticSampler(), "Static samplers should never be assigned space in the cache" ); VERIFY(SamInfo.Attribs.IsValidBindPoint(), "Sampler bind point must be valid"); for (Uint32 ArrInd = 0; ArrInd < SamInfo.Attribs.BindCount; ++ArrInd) @@ -900,7 +936,7 @@ bool ShaderResourceLayoutD3D12::dvpVerifyBindings(const ShaderResourceCacheD3D12 } else if (ResourceCache.DbgGetContentType() == ShaderResourceCacheD3D12::DbgCacheContentType::SRBResources) { - if (SamInfo.Attribs.GetVariableType() == SHADER_VARIABLE_TYPE_DYNAMIC) + if (SamInfo.GetVariableType() == SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC) VERIFY(ShdrVisibleHeapCPUDescriptorHandle.ptr == 0, "Dynamic resources of a shader resource binding should be assigned shader visible descriptor space at every draw call"); else VERIFY(ShdrVisibleHeapCPUDescriptorHandle.ptr != 0, "Non-dynamics resources of a shader resource binding must be assigned shader visible descriptor space"); @@ -918,7 +954,7 @@ bool ShaderResourceLayoutD3D12::dvpVerifyBindings(const ShaderResourceCacheD3D12 for (Uint32 s=0; s < GetSamplerCount(VarType); ++s) { const auto& sam = GetSampler(VarType, s); - VERIFY(sam.Attribs.GetVariableType() == VarType, "Unexpected sampler variable type"); + VERIFY(sam.GetVariableType() == VarType, "Unexpected sampler variable type"); for (Uint32 ArrInd = 0; ArrInd < sam.Attribs.BindCount; ++ArrInd) { @@ -940,35 +976,4 @@ bool ShaderResourceLayoutD3D12::dvpVerifyBindings(const ShaderResourceCacheD3D12 } #endif -const Char* ShaderResourceLayoutD3D12::GetShaderName()const -{ - RefCntAutoPtr<IShader> pShader(&m_Owner, IID_Shader); - if (pShader) - { - return pShader->GetDesc().Name; - } - else - { - RefCntAutoPtr<IPipelineState> pPSO(&m_Owner, IID_PipelineState); - if(pPSO) - { - auto* pPSOD3D12 = pPSO.RawPtr<PipelineStateD3D12Impl>(); - auto* ppShaders = pPSOD3D12->GetShaders(); - auto NumShaders = pPSOD3D12->GetNumShaders(); - for (Uint32 s = 0; s < NumShaders; ++s) - { - const auto& ShaderDesc = ppShaders[s]->GetDesc(); - if(ShaderDesc.ShaderType == m_pResources->GetShaderType()) - return ShaderDesc.Name; - } - UNEXPECTED("Shader not found"); - } - else - { - UNEXPECTED("Shader resource layout owner is expected to be a shader or a pipeline state"); - } - } - return ""; -} - } diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp index efb6602a..2504d198 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp @@ -48,7 +48,7 @@ ShaderResourcesD3D12::ShaderResourcesD3D12(ID3DBlob* pShaderBytecode, const Shad Initialize<D3D12_SHADER_DESC, D3D12_SHADER_INPUT_BIND_DESC, ID3D12ShaderReflection>( pShaderBytecode, NewResourceHandler{}, - ShdrDesc, + ShdrDesc.Name, CombinedSamplerSuffix ); } diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp index 35bd4d81..877a270d 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp @@ -24,18 +24,19 @@ #include "pch.h" #include "ShaderVariableD3D12.h" +#include "ShaderResourceVariableBase.h" namespace Diligent { -size_t ShaderVariableManagerD3D12::GetRequiredMemorySize(const ShaderResourceLayoutD3D12& Layout, - const SHADER_VARIABLE_TYPE* AllowedVarTypes, - Uint32 NumAllowedTypes, - Uint32& NumVariables) +size_t ShaderVariableManagerD3D12::GetRequiredMemorySize(const ShaderResourceLayoutD3D12& Layout, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes, + Uint32& NumVariables) { NumVariables = 0; Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes); - for (SHADER_VARIABLE_TYPE VarType = SHADER_VARIABLE_TYPE_STATIC; VarType < SHADER_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_VARIABLE_TYPE>(VarType+1)) + for (SHADER_RESOURCE_VARIABLE_TYPE VarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; VarType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(VarType+1)) { if (IsAllowedType(VarType, AllowedTypeBits)) { @@ -49,11 +50,11 @@ size_t ShaderVariableManagerD3D12::GetRequiredMemorySize(const ShaderResourceLay } // Creates shader variable for every resource from SrcLayout whose type is one AllowedVarTypes -void ShaderVariableManagerD3D12::Initialize(const ShaderResourceLayoutD3D12& SrcLayout, - IMemoryAllocator& Allocator, - const SHADER_VARIABLE_TYPE* AllowedVarTypes, - Uint32 NumAllowedTypes, - ShaderResourceCacheD3D12& ResourceCache) +void ShaderVariableManagerD3D12::Initialize(const ShaderResourceLayoutD3D12& SrcLayout, + IMemoryAllocator& Allocator, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes, + ShaderResourceCacheD3D12& ResourceCache) { m_pResourceLayout = &SrcLayout; m_pResourceCache = &ResourceCache; @@ -72,7 +73,7 @@ void ShaderVariableManagerD3D12::Initialize(const ShaderResourceLayoutD3D12& Src m_pVariables = reinterpret_cast<ShaderVariableD3D12Impl*>(pRawMem); Uint32 VarInd = 0; - for (SHADER_VARIABLE_TYPE VarType = SHADER_VARIABLE_TYPE_STATIC; VarType < SHADER_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_VARIABLE_TYPE>(VarType+1)) + for (SHADER_RESOURCE_VARIABLE_TYPE VarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; VarType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(VarType+1)) { if (!IsAllowedType(VarType, AllowedTypeBits)) continue; @@ -177,7 +178,7 @@ void ShaderVariableManagerD3D12::BindResources( IResourceMapping* pResourceMappi auto &Var = m_pVariables[v]; const auto& Res = Var.m_Resource; - if ( (Flags & (1 << Res.Attribs.GetVariableType())) == 0 ) + if ( (Flags & (1 << Res.GetVariableType())) == 0 ) continue; for (Uint32 ArrInd = 0; ArrInd < Res.Attribs.BindCount; ++ArrInd) |
