diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2019-03-07 02:58:56 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2019-03-07 02:58:56 +0000 |
| commit | bc9fc76496034a50faf3d7fe7be868d5d62f6663 (patch) | |
| tree | e9438fe09533409c57c9c63b2f69a895e2cf8615 /Graphics/GraphicsEngineD3D11 | |
| parent | Merge pull request #67 from StarshipVendingMachine/android-vulkan (diff) | |
| parent | Minor comment updates (diff) | |
| download | DiligentCore-bc9fc76496034a50faf3d7fe7be868d5d62f6663.tar.gz DiligentCore-bc9fc76496034a50faf3d7fe7be868d5d62f6663.zip | |
Merged var_type_refactor into master
Diffstat (limited to 'Graphics/GraphicsEngineD3D11')
26 files changed, 720 insertions, 640 deletions
diff --git a/Graphics/GraphicsEngineD3D11/CMakeLists.txt b/Graphics/GraphicsEngineD3D11/CMakeLists.txt index b263d602..f54fa680 100644 --- a/Graphics/GraphicsEngineD3D11/CMakeLists.txt +++ b/Graphics/GraphicsEngineD3D11/CMakeLists.txt @@ -34,11 +34,10 @@ set(INTERFACE interface/BufferD3D11.h interface/BufferViewD3D11.h interface/DeviceContextD3D11.h - interface/EngineD3D11Attribs.h + interface/EngineFactoryD3D11.h interface/FenceD3D11.h interface/PipelineStateD3D11.h interface/RenderDeviceD3D11.h - interface/RenderDeviceFactoryD3D11.h interface/SamplerD3D11.h interface/ShaderD3D11.h interface/ShaderResourceBindingD3D11.h @@ -54,11 +53,11 @@ set(SRC src/CommandListD3D11Impl.cpp src/D3D11TypeConversions.cpp src/DeviceContextD3D11Impl.cpp + src/EngineFactoryD3D11.cpp src/FenceD3D11Impl.cpp src/GUIDDef.cpp src/PipelineStateD3D11Impl.cpp src/RenderDeviceD3D11Impl.cpp - src/RenderDeviceFactoryD3D11.cpp src/SamplerD3D11Impl.cpp src/ShaderD3D11Impl.cpp src/ShaderResourceBindingD3D11Impl.cpp diff --git a/Graphics/GraphicsEngineD3D11/include/BufferD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/BufferD3D11Impl.h index 8b39f607..71b91345 100644 --- a/Graphics/GraphicsEngineD3D11/include/BufferD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/BufferD3D11Impl.h @@ -58,7 +58,7 @@ public: ~BufferD3D11Impl(); - virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override final; + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final; virtual ID3D11Buffer* GetD3D11Buffer()override final{ return m_pd3d11Buffer; } diff --git a/Graphics/GraphicsEngineD3D11/include/BufferViewD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/BufferViewD3D11Impl.h index 208dd1ee..d705536e 100644 --- a/Graphics/GraphicsEngineD3D11/include/BufferViewD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/BufferViewD3D11Impl.h @@ -48,7 +48,7 @@ public: ID3D11View* pD3D11View, bool bIsDefaultView); - virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface ) final; + virtual void QueryInterface(const INTERFACE_ID& IID, IObject **ppInterface) final; virtual ID3D11View* GetD3D11View()override final { diff --git a/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h index df013869..01a54eeb 100755 --- a/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h @@ -53,13 +53,13 @@ class DeviceContextD3D11Impl final : public DeviceContextBase<IDeviceContextD3D1 public:
using TDeviceContextBase = DeviceContextBase<IDeviceContextD3D11, DeviceContextD3D11ImplTraits>;
- DeviceContextD3D11Impl(IReferenceCounters* pRefCounters,
- IMemoryAllocator& Allocator,
- IRenderDevice* pDevice,
- ID3D11DeviceContext* pd3d11DeviceContext,
- const struct EngineD3D11Attribs& EngineAttribs,
- bool bIsDeferred);
- virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override final;
+ DeviceContextD3D11Impl(IReferenceCounters* pRefCounters,
+ IMemoryAllocator& Allocator,
+ IRenderDevice* pDevice,
+ ID3D11DeviceContext* pd3d11DeviceContext,
+ const struct EngineD3D11CreateInfo& EngineAttribs,
+ bool bIsDeferred);
+ virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final;
virtual void SetPipelineState(IPipelineState* pPipelineState)override final;
diff --git a/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.h index af93c8eb..c56d8479 100644 --- a/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.h @@ -48,8 +48,22 @@ public: const PipelineStateDesc& PipelineDesc); ~PipelineStateD3D11Impl(); - virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override final; + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final; + + virtual void BindStaticResources(Uint32 ShaderFlags, IResourceMapping* pResourceMapping, Uint32 Flags)override final; + + virtual Uint32 GetStaticVariableCount(SHADER_TYPE ShaderType) const override final; + + virtual IShaderResourceVariable* GetStaticShaderVariable(SHADER_TYPE ShaderType, const Char* Name) override final; + + virtual IShaderResourceVariable* GetStaticShaderVariable(SHADER_TYPE ShaderType, Uint32 Index) override final; + + virtual void CreateShaderResourceBinding( IShaderResourceBinding **ppShaderResourceBinding, bool InitStaticResources )override final; + + virtual bool IsCompatibleWith(const IPipelineState *pPSO)const override final; + + /// Implementation of the IPipelineStateD3D11::GetD3D11BlendState() method. virtual ID3D11BlendState* GetD3D11BlendState()override final; @@ -68,23 +82,54 @@ public: virtual ID3D11HullShader* GetD3D11HullShader()override final; virtual ID3D11ComputeShader* GetD3D11ComputeShader()override final; - virtual void CreateShaderResourceBinding( IShaderResourceBinding **ppShaderResourceBinding, bool InitStaticResources )override final; - - virtual bool IsCompatibleWith(const IPipelineState *pPSO)const override final; SRBMemoryAllocator& GetSRBMemoryAllocator() { return m_SRBMemAllocator; } + const ShaderResourceLayoutD3D11& GetStaticResourceLayout(Uint32 s)const + { + VERIFY_EXPR(s < m_NumShaders); + return m_pStaticResourceLayouts[s]; + } + + ShaderResourceCacheD3D11& GetStaticResourceCache(Uint32 s) + { + VERIFY_EXPR(s < m_NumShaders); + return m_pStaticResourceCaches[s]; + } + + void SetStaticSamplers(ShaderResourceCacheD3D11& ResourceCache, Uint32 ShaderInd)const; + private: + CComPtr<ID3D11BlendState> m_pd3d11BlendState; CComPtr<ID3D11RasterizerState> m_pd3d11RasterizerState; CComPtr<ID3D11DepthStencilState> m_pd3d11DepthStencilState; CComPtr<ID3D11InputLayout> m_pd3d11InputLayout; + // The caches are indexed by the shader order in the PSO, not shader index + ShaderResourceCacheD3D11* m_pStaticResourceCaches = nullptr; + ShaderResourceLayoutD3D11* m_pStaticResourceLayouts= nullptr; + // SRB memory allocator must be defined before the default shader res binding SRBMemoryAllocator m_SRBMemAllocator; + + Int8 m_ResourceLayoutIndex[6] = {-1, -1, -1, -1, -1, -1}; + + Uint16 m_StaticSamplerOffsets[MaxShadersInPipeline+1] = {}; + struct StaticSamplerInfo + { + const D3DShaderResourceAttribs& Attribs; + RefCntAutoPtr<ISampler> pSampler; + StaticSamplerInfo(const D3DShaderResourceAttribs& _Attribs, + RefCntAutoPtr<ISampler> _pSampler) : + Attribs (_Attribs), + pSampler (std::move(_pSampler)) + {} + }; + std::vector< StaticSamplerInfo, STDAllocatorRawMem<StaticSamplerInfo> > m_StaticSamplers; }; } diff --git a/Graphics/GraphicsEngineD3D11/include/RenderDeviceD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/RenderDeviceD3D11Impl.h index 95548464..b325554f 100644 --- a/Graphics/GraphicsEngineD3D11/include/RenderDeviceD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/RenderDeviceD3D11Impl.h @@ -29,7 +29,6 @@ #include "RenderDeviceD3D11.h" #include "RenderDeviceD3DBase.h" #include "DeviceContextD3D11.h" -#include "EngineD3D11Attribs.h" namespace Diligent { @@ -40,16 +39,16 @@ class RenderDeviceD3D11Impl final : public RenderDeviceD3DBase<IRenderDeviceD3D1 public: using TRenderDeviceBase = RenderDeviceD3DBase<IRenderDeviceD3D11>; - RenderDeviceD3D11Impl( IReferenceCounters* pRefCounters, - IMemoryAllocator& RawMemAllocator, - const EngineD3D11Attribs& EngineAttribs, - ID3D11Device* pd3d11Device, - Uint32 NumDeferredContexts ); - virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override final; + RenderDeviceD3D11Impl( IReferenceCounters* pRefCounters, + IMemoryAllocator& RawMemAllocator, + const EngineD3D11CreateInfo& EngineAttribs, + ID3D11Device* pd3d11Device, + Uint32 NumDeferredContexts ); + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final; virtual void CreateBuffer(const BufferDesc& BuffDesc, const BufferData* pBuffData, IBuffer** ppBuffer)override final; - virtual void CreateShader(const ShaderCreationAttribs& ShaderCreationAttribs, IShader** ppShader)override final; + virtual void CreateShader(const ShaderCreateInfo& ShaderCI, IShader** ppShader)override final; virtual void CreateTexture(const TextureDesc& TexDesc, const TextureData* pData, ITexture** ppTexture)override final; @@ -74,10 +73,11 @@ public: private: virtual void TestTextureFormat( TEXTURE_FORMAT TexFormat )override final; - EngineD3D11Attribs m_EngineAttribs; + EngineD3D11CreateInfo m_EngineAttribs; /// D3D11 device CComPtr<ID3D11Device> m_pd3d11Device; }; } + diff --git a/Graphics/GraphicsEngineD3D11/include/SamplerD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/SamplerD3D11Impl.h index 5745bf18..4cac7884 100644 --- a/Graphics/GraphicsEngineD3D11/include/SamplerD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/SamplerD3D11Impl.h @@ -46,7 +46,7 @@ public: const SamplerDesc& SamplerDesc); ~SamplerD3D11Impl(); - virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject** ppInterface ) final; + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final; virtual ID3D11SamplerState* GetD3D11SamplerState()override final{ return m_pd3dSampler; } diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/ShaderD3D11Impl.h index 5bafbb1f..35a50a08 100644 --- a/Graphics/GraphicsEngineD3D11/include/ShaderD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/ShaderD3D11Impl.h @@ -50,32 +50,21 @@ public: ShaderD3D11Impl(IReferenceCounters* pRefCounters, class RenderDeviceD3D11Impl* pRenderDeviceD3D11, - const ShaderCreationAttribs& CreationAttribs); + const ShaderCreateInfo& ShaderCI); ~ShaderD3D11Impl(); - virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject** ppInterface )override final; + IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_ShaderD3D11, TShaderBase); - virtual void BindResources( IResourceMapping* pResourceMapping, Uint32 Flags )override final + virtual Uint32 GetResourceCount()const override final { - m_StaticResLayout.BindResources(pResourceMapping, Flags, m_StaticResCache); - } - - virtual IShaderVariable* GetShaderVariable( const Char* Name )override final - { - return m_StaticResLayout.GetShaderVariable(Name); - } - - virtual Uint32 GetVariableCount() const override final - { - return m_StaticResLayout.GetTotalResourceCount(); + return m_pShaderResources->GetTotalResources(); } - virtual IShaderVariable* GetShaderVariable(Uint32 Index)override final + virtual ShaderResourceDesc GetResource(Uint32 Index)const override final { - return m_StaticResLayout.GetShaderVariable(Index); + return m_pShaderResources->GetShaderResourceDesc(Index); } - virtual ID3D11DeviceChild* GetD3D11Shader()override final { return m_pShader; @@ -83,9 +72,7 @@ public: ID3DBlob* GetBytecode(){return m_pShaderByteCode;} - ShaderResourceLayoutD3D11& GetStaticResourceLayout(){return m_StaticResLayout;} - const std::shared_ptr<const ShaderResourcesD3D11>& GetResources()const{return m_pShaderResources;} - Uint32 GetShaderTypeIndex()const{return m_ShaderTypeIndex;} + const std::shared_ptr<const ShaderResourcesD3D11>& GetD3D11Resources()const{return m_pShaderResources;} private: /// D3D11 shader @@ -94,10 +81,6 @@ private: // ShaderResources class instance must be referenced through the shared pointer, because // it is referenced by ShaderResourceLayoutD3D11 class instances std::shared_ptr<const ShaderResourcesD3D11> m_pShaderResources; - - ShaderResourceCacheD3D11 m_StaticResCache; - ShaderResourceLayoutD3D11 m_StaticResLayout; - Uint32 m_ShaderTypeIndex; // VS == 0, PS == 1, GS == 2, HS == 3, DS == 4, CS == 5 }; } diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderResourceBindingD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/ShaderResourceBindingD3D11Impl.h index 9f175f1d..b3274b21 100755 --- a/Graphics/GraphicsEngineD3D11/include/ShaderResourceBindingD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/ShaderResourceBindingD3D11Impl.h @@ -48,15 +48,15 @@ public: bool IsInternal);
~ShaderResourceBindingD3D11Impl();
- virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject** ppInterface )override final;
+ virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final;
virtual void BindResources(Uint32 ShaderFlags, IResourceMapping* pResMapping, Uint32 Flags)override final;
- virtual IShaderVariable* GetVariable(SHADER_TYPE ShaderType, const char *Name)override final;
+ virtual IShaderResourceVariable* GetVariable(SHADER_TYPE ShaderType, const char *Name)override final;
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;
@@ -74,14 +74,14 @@ public: private:
// The caches are indexed by the shader order in the PSO, not shader index
- ShaderResourceCacheD3D11* m_pBoundResourceCaches = nullptr;
- ShaderResourceLayoutD3D11* m_pResourceLayouts = nullptr;
+ ShaderResourceCacheD3D11* m_pBoundResourceCaches = nullptr;
+ ShaderResourceLayoutD3D11* m_pResourceLayouts = nullptr;
- Int8 m_ShaderTypeIndex[6] = {};
+ Int8 m_ShaderTypeIndex[6] = {};
// Resource layout index in m_ResourceLayouts[] array for every shader stage
- Int8 m_ResourceLayoutIndex[6];
- Uint8 m_NumActiveShaders = 0;
+ Int8 m_ResourceLayoutIndex[6] = {-1, -1, -1, -1, -1, -1};
+ Uint8 m_NumActiveShaders = 0;
bool m_bIsStaticResourcesBound = false;
};
diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.h b/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.h index 02cde863..f25dff7c 100755 --- a/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.h +++ b/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.h @@ -117,8 +117,8 @@ public: static size_t GetRequriedMemorySize(const class ShaderResourcesD3D11& Resources);
- void Initialize(const class ShaderResourcesD3D11& Resources, class IMemoryAllocator &MemAllocator);
- void Initialize(Uint32 CBCount, Uint32 SRVCount, Uint32 SamplerCount, Uint32 UAVCount, class IMemoryAllocator &MemAllocator);
+ void Initialize(const class ShaderResourcesD3D11& Resources, class IMemoryAllocator& MemAllocator);
+ void Initialize(Uint32 CBCount, Uint32 SRVCount, Uint32 SamplerCount, Uint32 UAVCount, class IMemoryAllocator& MemAllocator);
void Destroy(class IMemoryAllocator& MemAllocator);
diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h b/Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h index 61970f9d..bfc39727 100644 --- a/Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h +++ b/Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h @@ -41,10 +41,18 @@ class IMemoryAllocator; /// Diligent::ShaderResourceLayoutD3D11 class /// http://diligentgraphics.com/diligent-engine/architecture/d3d11/shader-resource-layout/ +// sizeof(ShaderResourceLayoutD3D11) == 64 (x64) class ShaderResourceLayoutD3D11 { public: - ShaderResourceLayoutD3D11(IObject& Owner); + ShaderResourceLayoutD3D11(IObject& Owner, + std::shared_ptr<const ShaderResourcesD3D11> pSrcResources, + const PipelineResourceLayoutDesc& ResourceLayout, + const SHADER_RESOURCE_VARIABLE_TYPE* VarTypes, + Uint32 NumVarTypes, + ShaderResourceCacheD3D11& ResourceCache, + IMemoryAllocator& ResCacheDataAllocator, + IMemoryAllocator& ResLayoutDataAllocator); ~ShaderResourceLayoutD3D11(); // No copies, only moves are allowed @@ -53,26 +61,21 @@ public: ShaderResourceLayoutD3D11 ( ShaderResourceLayoutD3D11&&) = default; ShaderResourceLayoutD3D11& operator = ( ShaderResourceLayoutD3D11&&) = delete; - static size_t GetRequiredMemorySize(const ShaderResourcesD3D11& SrcResources, - const SHADER_VARIABLE_TYPE* VarTypes, - Uint32 NumVarTypes); + static size_t GetRequiredMemorySize(const ShaderResourcesD3D11& SrcResources, + const PipelineResourceLayoutDesc& ResourceLayout, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes); - void Initialize(std::shared_ptr<const ShaderResourcesD3D11> pSrcResources, - const SHADER_VARIABLE_TYPE* VarTypes, - Uint32 NumVarTypes, - ShaderResourceCacheD3D11& ResourceCache, - IMemoryAllocator& ResCacheDataAllocator, - IMemoryAllocator& ResLayoutDataAllocator); - - void CopyResources(ShaderResourceCacheD3D11& DstCache); + void CopyResources(ShaderResourceCacheD3D11& DstCache)const; using ShaderVariableD3D11Base = ShaderVariableD3DBase<ShaderResourceLayoutD3D11>; struct ConstBuffBindInfo final : ShaderVariableD3D11Base { ConstBuffBindInfo( const D3DShaderResourceAttribs& ResourceAttribs, - ShaderResourceLayoutD3D11& ParentResLayout ) : - ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs) + ShaderResourceLayoutD3D11& ParentResLayout, + SHADER_RESOURCE_VARIABLE_TYPE VariableType) : + ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs, VariableType) {} // Non-virtual function __forceinline void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex); @@ -84,15 +87,16 @@ public: BindResource(ppObjects[elem], FirstElement+elem); } - __forceinline bool IsBound(Uint32 ArrayIndex); + __forceinline bool IsBound(Uint32 ArrayIndex)const; }; struct TexSRVBindInfo final : ShaderVariableD3D11Base { TexSRVBindInfo( const D3DShaderResourceAttribs& _TextureAttribs, Uint32 _SamplerIndex, - ShaderResourceLayoutD3D11& ParentResLayout) : - ShaderVariableD3D11Base(ParentResLayout, _TextureAttribs), + ShaderResourceLayoutD3D11& ParentResLayout, + SHADER_RESOURCE_VARIABLE_TYPE VariableType) : + ShaderVariableD3D11Base(ParentResLayout, _TextureAttribs, VariableType), SamplerIndex(_SamplerIndex) {} @@ -117,8 +121,9 @@ public: struct TexUAVBindInfo final : ShaderVariableD3D11Base { TexUAVBindInfo( const D3DShaderResourceAttribs& ResourceAttribs, - ShaderResourceLayoutD3D11& ParentResLayout ) : - ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs) + ShaderResourceLayoutD3D11& ParentResLayout, + SHADER_RESOURCE_VARIABLE_TYPE VariableType ) : + ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs, VariableType) {} // Provide non-virtual function @@ -137,8 +142,9 @@ public: struct BuffUAVBindInfo final : ShaderVariableD3D11Base { BuffUAVBindInfo( const D3DShaderResourceAttribs& ResourceAttribs, - ShaderResourceLayoutD3D11& ParentResLayout ) : - ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs) + ShaderResourceLayoutD3D11& ParentResLayout, + SHADER_RESOURCE_VARIABLE_TYPE VariableType ) : + ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs, VariableType) {} // Non-virtual function @@ -157,8 +163,9 @@ public: struct BuffSRVBindInfo final : ShaderVariableD3D11Base { BuffSRVBindInfo( const D3DShaderResourceAttribs& ResourceAttribs, - ShaderResourceLayoutD3D11& ParentResLayout ) : - ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs) + ShaderResourceLayoutD3D11& ParentResLayout, + SHADER_RESOURCE_VARIABLE_TYPE VariableType ) : + ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs, VariableType) {} // Non-virtual function @@ -177,8 +184,9 @@ public: struct SamplerBindInfo final : ShaderVariableD3D11Base { SamplerBindInfo( const D3DShaderResourceAttribs& ResourceAttribs, - ShaderResourceLayoutD3D11& ParentResLayout ) : - ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs) + ShaderResourceLayoutD3D11& ParentResLayout, + SHADER_RESOURCE_VARIABLE_TYPE VariableType) : + ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs, VariableType) {} // Non-virtual function @@ -197,13 +205,13 @@ public: // dbgResourceCache is only used for sanity check and as a remainder that the resource cache must be alive // while Layout is alive void BindResources( IResourceMapping* pResourceMapping, Uint32 Flags, const ShaderResourceCacheD3D11& dbgResourceCache ); - + #ifdef DEVELOPMENT bool dvpVerifyBindings()const; #endif - IShaderVariable* GetShaderVariable( const Char* Name ); - IShaderVariable* GetShaderVariable( Uint32 Index ); + IShaderResourceVariable* GetShaderVariable( const Char* Name ); + IShaderResourceVariable* GetShaderVariable( Uint32 Index ); __forceinline SHADER_TYPE GetShaderType()const{return m_pResources->GetShaderType();} IObject& GetOwner(){return m_Owner;} @@ -233,28 +241,34 @@ public: template<> Uint32 GetNumResources<BuffUAVBindInfo> () const { return GetNumBufUAVs(); } template<> Uint32 GetNumResources<SamplerBindInfo> () const { return GetNumSamplers(); } -private: - const Char* GetShaderName()const { return m_pResources->GetShaderName(); } - // No need to use shared pointer, as the resource cache is either part of the same - // ShaderD3D11Impl object, or ShaderResourceBindingD3D11Impl object - ShaderResourceCacheD3D11* m_pResourceCache = nullptr; +private: + +/* 0 */ IObject& m_Owner; +/* 8 */ std::shared_ptr<const ShaderResourcesD3D11> m_pResources; - std::unique_ptr<void, STDDeleterRawMem<void> > m_ResourceBuffer; + // No need to use shared pointer, as the resource cache is either part of the same + // ShaderD3D11Impl object, or ShaderResourceBindingD3D11Impl object +/*24*/ ShaderResourceCacheD3D11& m_ResourceCache; - // Offsets in bytes - using OffsetType = Uint16; - OffsetType m_TexSRVsOffset = 0; - OffsetType m_TexUAVsOffset = 0; - OffsetType m_BuffSRVsOffset = 0; - OffsetType m_BuffUAVsOffset = 0; - OffsetType m_SamplerOffset = 0; - OffsetType m_MemorySize = 0; +/*32*/ std::unique_ptr<void, STDDeleterRawMem<void> > m_ResourceBuffer; + // Offsets in bytes + using OffsetType = Uint16; +/*48*/ OffsetType m_TexSRVsOffset = 0; +/*50*/ OffsetType m_TexUAVsOffset = 0; +/*52*/ OffsetType m_BuffSRVsOffset = 0; +/*54*/ OffsetType m_BuffUAVsOffset = 0; +/*56*/ OffsetType m_SamplerOffset = 0; +/*58*/ OffsetType m_MemorySize = 0; +/*60 - 64*/ +/*64*/ // End of data + + template<typename ResourceType> OffsetType GetResourceOffset()const; template<> OffsetType GetResourceOffset<ConstBuffBindInfo>() const { return 0; } template<> OffsetType GetResourceOffset<TexSRVBindInfo> () const { return m_TexSRVsOffset; } @@ -280,7 +294,7 @@ private: } template<typename ResourceType> - IShaderVariable* GetResourceByName( const Char* Name ); + IShaderResourceVariable* GetResourceByName( const Char* Name ); template<typename THandleCB, typename THandleTexSRV, @@ -314,8 +328,37 @@ private: HandleSampler(GetResource<SamplerBindInfo>(s)); } - std::shared_ptr<const ShaderResourcesD3D11> m_pResources; - IObject& m_Owner; + template<typename THandleCB, + typename THandleTexSRV, + typename THandleTexUAV, + typename THandleBufSRV, + typename THandleBufUAV, + typename THandleSampler> + void HandleConstResources(THandleCB HandleCB, + THandleTexSRV HandleTexSRV, + THandleTexUAV HandleTexUAV, + THandleBufSRV HandleBufSRV, + THandleBufUAV HandleBufUAV, + THandleSampler HandleSampler)const + { + for (Uint32 cb = 0; cb < GetNumResources<ConstBuffBindInfo>(); ++cb) + HandleCB(GetConstResource<ConstBuffBindInfo>(cb)); + + for (Uint32 t = 0; t < GetNumResources<TexSRVBindInfo>(); ++t) + HandleTexSRV(GetConstResource<TexSRVBindInfo>(t)); + + for (Uint32 u = 0; u < GetNumResources<TexUAVBindInfo>(); ++u) + HandleTexUAV(GetConstResource<TexUAVBindInfo>(u)); + + for (Uint32 s = 0; s < GetNumResources<BuffSRVBindInfo>(); ++s) + HandleBufSRV(GetConstResource<BuffSRVBindInfo>(s)); + + for (Uint32 u = 0; u < GetNumResources<BuffUAVBindInfo>(); ++u) + HandleBufUAV(GetConstResource<BuffUAVBindInfo>(u)); + + for (Uint32 s = 0; s < GetNumResources<SamplerBindInfo>(); ++s) + HandleSampler(GetConstResource<SamplerBindInfo>(s)); + } friend class ShaderVariableIndexLocator; friend class ShaderVariableLocator; diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderResourcesD3D11.h b/Graphics/GraphicsEngineD3D11/include/ShaderResourcesD3D11.h index da8d4a34..c2c3a34d 100644 --- a/Graphics/GraphicsEngineD3D11/include/ShaderResourcesD3D11.h +++ b/Graphics/GraphicsEngineD3D11/include/ShaderResourcesD3D11.h @@ -28,7 +28,7 @@ // ShaderResourcesD3D11 are created by ShaderD3D11Impl instances. They are then referenced by ShaderResourceLayoutD3D11 objects, which are in turn -// created by instances of ShaderResourceBindingsD3D11Impl (and ShaderD3D11Impl too) +// created by instances of ShaderResourceBindingsD3D11Impl and PipelineStateD3D11Impl // // _________________ // | | @@ -64,13 +64,17 @@ // | | shared_ptr | | shared_ptr| | | | | // | ShaderD3D11Impl |--------------->| ShaderResourcesD3D11 |<---------------| ShaderResourceLayoutD3D11 |<-----| ShaderResourceBindingD3D11Impl | // |_________________| |______________________| | |___________________________| |________________________________| -// | A | -// V | | -// ____<m_StaticResLayout>____ | | ____<m_pResourceLayouts>___ ________________________________ +// A | +// | | +// _____<StaticResLayout>_____ | | ____<m_pResourceLayouts>___ ________________________________ // | | shared_ptr | | | | | | // | ShaderResourceLayoutD3D11 |------------------- ----| ShaderResourceLayoutD3D11 |<-----| ShaderResourceBindingD3D11Impl | // |___________________________| |___________________________| |________________________________| -// +// A +// ___________|______________ +// | | +// | PipelineStateD3D11Impl | +// |__________________________| // #include <vector> @@ -111,10 +115,7 @@ public: class ShaderResourceCacheD3D11& ResourceCache)const; #endif - const Char* GetShaderName() const { return m_ShaderName; } - - void SetStaticSamplers(class ShaderResourceCacheD3D11& ResourceCache)const; - + private: using MaxBindPointType = Int8; @@ -128,16 +129,6 @@ private: static_assert(D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT-1 <= MaxAllowedBindPoint, "Not enough bits to represent max SRV slot"); static_assert(D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT-1 <= MaxAllowedBindPoint, "Not enough bits to represent max Sampler slot"); static_assert(D3D11_PS_CS_UAV_REGISTER_COUNT-1 <= MaxAllowedBindPoint, "Not enough bits to represent max UAV slot"); - - // ShaderResourcesD3D11 is part of the ShaderD3D11Impl object, so we can simply - // reference shader name without the need to copy it - const Char* const m_ShaderName; - - using StaticSamplerAttribs = std::pair<const D3DShaderResourceAttribs&, RefCntAutoPtr<ISampler>>; - using StaticSamplerVector = std::vector<StaticSamplerAttribs, STDAllocatorRawMem<StaticSamplerAttribs>>; - void InitStaticSamplers(StaticSamplerVector&& StaticSamplers); - - StaticSamplerVector m_StaticSamplers; }; } diff --git a/Graphics/GraphicsEngineD3D11/include/SwapChainD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/SwapChainD3D11Impl.h index 7dd8680e..98d92676 100644 --- a/Graphics/GraphicsEngineD3D11/include/SwapChainD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/SwapChainD3D11Impl.h @@ -47,7 +47,7 @@ public: void* pNativeWndHandle); ~SwapChainD3D11Impl(); - virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override final; + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final; virtual void Present(Uint32 SyncInterval)override final; virtual void Resize( Uint32 NewWidth, Uint32 NewHeight )override final; diff --git a/Graphics/GraphicsEngineD3D11/include/TextureBaseD3D11.h b/Graphics/GraphicsEngineD3D11/include/TextureBaseD3D11.h index 56ef5bc3..1333bd8e 100644 --- a/Graphics/GraphicsEngineD3D11/include/TextureBaseD3D11.h +++ b/Graphics/GraphicsEngineD3D11/include/TextureBaseD3D11.h @@ -51,7 +51,7 @@ public: const TextureData* pInitData = nullptr); ~TextureBaseD3D11(); - virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override final; + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final; virtual ID3D11Resource* GetD3D11Texture()override final{ return m_pd3d11Texture; } diff --git a/Graphics/GraphicsEngineD3D11/include/TextureViewD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/TextureViewD3D11Impl.h index 3fcea2da..423b6dee 100644 --- a/Graphics/GraphicsEngineD3D11/include/TextureViewD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/TextureViewD3D11Impl.h @@ -49,7 +49,7 @@ public: ID3D11View* pD3D11View, bool bIsDefaultView); - virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override final; + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final; virtual ID3D11View* GetD3D11View()override final { diff --git a/Graphics/GraphicsEngineD3D11/interface/EngineD3D11Attribs.h b/Graphics/GraphicsEngineD3D11/interface/EngineD3D11Attribs.h deleted file mode 100644 index a5208ef5..00000000 --- a/Graphics/GraphicsEngineD3D11/interface/EngineD3D11Attribs.h +++ /dev/null @@ -1,70 +0,0 @@ -/* 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 - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. - * - * 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 -/// Definition of the Engine D3D11 attribs - -#include "../../GraphicsEngine/interface/GraphicsTypes.h" - -namespace Diligent -{ - /// Debug flags that can be specified when creating Direct3D11-based engine implementation. - /// - /// \sa CreateDeviceAndContextsD3D11Type, CreateSwapChainD3D11Type, LoadGraphicsEngineD3D11 - enum class EngineD3D11DebugFlags : Uint32 - { - /// Before executing draw/dispatch command, verify that - /// all required shader resources are bound to the device context - VerifyCommittedShaderResources = 0x01, - - /// Verify that all committed cotext resources are relevant, - /// i.e. they are consistent with the committed resource cache. - /// This is very expensive operation and should generally not be - /// necessary. - VerifyCommittedResourceRelevance = 0x02 - }; - - /// Attributes of the Direct3D11-based engine implementation - struct EngineD3D11Attribs : public EngineCreationAttribs - { - static constexpr Uint32 DefaultAdapterId = 0xFFFFFFFF; - - /// Id of the hardware adapter the engine should be initialized on - Uint32 AdapterId = DefaultAdapterId; - - /// Debug flags. See Diligent::EngineD3D11DebugFlags for a list of allowed values. - /// - /// \sa CreateDeviceAndContextsD3D11Type, CreateSwapChainD3D11Type, LoadGraphicsEngineD3D11 - Uint32 DebugFlags; - - EngineD3D11Attribs() : - DebugFlags(0) - { - #ifdef _DEBUG - DebugFlags = static_cast<Uint32>(EngineD3D11DebugFlags::VerifyCommittedShaderResources); - #endif - } - }; -} diff --git a/Graphics/GraphicsEngineD3D11/interface/RenderDeviceFactoryD3D11.h b/Graphics/GraphicsEngineD3D11/interface/EngineFactoryD3D11.h index a4dd8476..dceab777 100644 --- a/Graphics/GraphicsEngineD3D11/interface/RenderDeviceFactoryD3D11.h +++ b/Graphics/GraphicsEngineD3D11/interface/EngineFactoryD3D11.h @@ -36,18 +36,16 @@ # include "../../../Common/interface/StringTools.h" #endif -#include "EngineD3D11Attribs.h" - namespace Diligent { class IEngineFactoryD3D11 { public: - virtual void CreateDeviceAndContextsD3D11( const EngineD3D11Attribs& EngineAttribs, - IRenderDevice** ppDevice, - IDeviceContext** ppContexts, - Uint32 NumDeferredContexts ) = 0; + virtual void CreateDeviceAndContextsD3D11(const EngineD3D11CreateInfo& EngineCI, + IRenderDevice** ppDevice, + IDeviceContext** ppContexts, + Uint32 NumDeferredContexts ) = 0; virtual void CreateSwapChainD3D11( IRenderDevice* pDevice, IDeviceContext* pImmediateContext, @@ -56,12 +54,12 @@ public: void* pNativeWndHandle, ISwapChain** ppSwapChain ) = 0; - virtual void AttachToD3D11Device(void* pd3d11NativeDevice, - void* pd3d11ImmediateContext, - const EngineD3D11Attribs& EngineAttribs, - IRenderDevice** ppDevice, - IDeviceContext** ppContexts, - Uint32 NumDeferredContexts) = 0; + virtual void AttachToD3D11Device(void* pd3d11NativeDevice, + void* pd3d11ImmediateContext, + const EngineD3D11CreateInfo& EngineCI, + IRenderDevice** ppDevice, + IDeviceContext** ppContexts, + Uint32 NumDeferredContexts) = 0; virtual void EnumerateHardwareAdapters(Uint32& NumAdapters, HardwareAdapterAttribs* Adapters) = 0; diff --git a/Graphics/GraphicsEngineD3D11/readme.md b/Graphics/GraphicsEngineD3D11/readme.md index 3a9dab60..121d4a49 100644 --- a/Graphics/GraphicsEngineD3D11/readme.md +++ b/Graphics/GraphicsEngineD3D11/readme.md @@ -8,7 +8,7 @@ Implementation of Direct3D11 back-end The following code snippet shows how to initialize Diligent Engine in D3D11 mode. ```cpp -#include "RenderDeviceFactoryD3D11.h" +#include "EngineFactoryD3D11.h" using namespace Diligent; // ... diff --git a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp index 03327e15..f177586d 100755 --- a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp @@ -34,7 +34,6 @@ #include "PipelineStateD3D11Impl.h"
#include "SwapChainD3D11.h"
#include "ShaderResourceBindingD3D11Impl.h"
-#include "EngineD3D11Attribs.h"
#include "EngineD3D11Defines.h"
#include "CommandListD3D11Impl.h"
#include "RenderDeviceD3D11Impl.h"
@@ -42,12 +41,12 @@ namespace Diligent
{
- DeviceContextD3D11Impl::DeviceContextD3D11Impl( IReferenceCounters* pRefCounters,
- IMemoryAllocator& Allocator,
- IRenderDevice* pDevice,
- ID3D11DeviceContext* pd3d11DeviceContext,
- const struct EngineD3D11Attribs& EngineAttribs,
- bool bIsDeferred ) :
+ DeviceContextD3D11Impl::DeviceContextD3D11Impl( IReferenceCounters* pRefCounters,
+ IMemoryAllocator& Allocator,
+ IRenderDevice* pDevice,
+ ID3D11DeviceContext* pd3d11DeviceContext,
+ const struct EngineD3D11CreateInfo& EngineAttribs,
+ bool bIsDeferred ) :
TDeviceContextBase(pRefCounters, pDevice, bIsDeferred),
m_pd3d11DeviceContext( pd3d11DeviceContext ),
m_DebugFlags(EngineAttribs.DebugFlags),
@@ -151,19 +150,16 @@ namespace Diligent VERIFY_EXPR(pPSO != nullptr);
static_assert(TransitionResources || CommitResources, "At least one of TransitionResources or CommitResources flags is expected to be true");
-#ifdef DEVELOPMENT
- auto pdbgPipelineStateD3D11 = ValidatedCast<PipelineStateD3D11Impl>( pPSO );
- auto ppdbgShaders = pdbgPipelineStateD3D11->GetShaders();
-#endif
+ auto* pPipelineStateD3D11 = ValidatedCast<PipelineStateD3D11Impl>(pPSO);
if (pShaderResourceBinding == nullptr)
{
#ifdef DEVELOPMENT
bool ResourcesPresent = false;
- for (Uint32 s = 0; s < pdbgPipelineStateD3D11->GetNumShaders(); ++s)
+ for (Uint32 s = 0; s < pPipelineStateD3D11->GetNumShaders(); ++s)
{
- auto* pShaderD3D11 = ValidatedCast<ShaderD3D11Impl>(ppdbgShaders[s]);
- if (pShaderD3D11->GetResources()->GetTotalResources() > 0)
+ auto* pShaderD3D11 = pPipelineStateD3D11->GetShader<ShaderD3D11Impl>(s);
+ if (pShaderD3D11->GetD3D11Resources()->GetTotalResources() > 0)
ResourcesPresent = true;
}
@@ -179,7 +175,7 @@ namespace Diligent auto pShaderResBindingD3D11 = ValidatedCast<ShaderResourceBindingD3D11Impl>(pShaderResourceBinding);
#ifdef DEVELOPMENT
- if (pdbgPipelineStateD3D11->IsIncompatibleWith(pShaderResourceBinding->GetPipelineState()))
+ if (pPipelineStateD3D11->IsIncompatibleWith(pShaderResourceBinding->GetPipelineState()))
{
LOG_ERROR_MESSAGE("Shader resource binding does not match Pipeline State");
return;
@@ -187,16 +183,14 @@ namespace Diligent #endif
auto NumShaders = pShaderResBindingD3D11->GetNumActiveShaders();
- VERIFY(NumShaders == pdbgPipelineStateD3D11->GetNumShaders(), "Number of active shaders in shader resource binding is not consistent with the number of shaders in the pipeline state");
+ VERIFY(NumShaders == pPipelineStateD3D11->GetNumShaders(), "Number of active shaders in shader resource binding is not consistent with the number of shaders in the pipeline state");
#ifdef DEVELOPMENT
bool StaticResourcesPresent = false;
for (Uint32 s = 0; s < NumShaders; ++s)
{
- pShaderResBindingD3D11->GetResourceLayout(s).dvpVerifyBindings();
- // Static resource bindings are verified in BindStaticShaderResources()
- auto* pShaderD3D11 = ValidatedCast<ShaderD3D11Impl>(ppdbgShaders[s]);
- if (pShaderD3D11->GetStaticResourceLayout().GetTotalResourceCount() > 0)
+ const auto& StaticResLayout = pPipelineStateD3D11->GetStaticResourceLayout(s);
+ if (StaticResLayout.GetTotalResourceCount() > 0)
StaticResourcesPresent = true;
}
// Static resource bindings are verified in BindStaticShaderResources()
@@ -213,8 +207,8 @@ namespace Diligent auto ShaderTypeInd = pShaderResBindingD3D11->GetActiveShaderTypeIndex(s);
#ifdef DEVELOPMENT
- auto* pShaderD3D11 = ValidatedCast<ShaderD3D11Impl>(ppdbgShaders[s]);
- VERIFY_EXPR( ShaderTypeInd == static_cast<Int32>(pShaderD3D11->GetShaderTypeIndex()) );
+ auto* pShaderD3D11 = pPipelineStateD3D11->GetShader<ShaderD3D11Impl>(s);
+ VERIFY_EXPR( ShaderTypeInd == static_cast<Int32>(GetShaderTypeIndex(pShaderD3D11->GetDesc().ShaderType)) );
#endif
auto& Cache = pShaderResBindingD3D11->GetResourceCache(s);
@@ -359,8 +353,8 @@ namespace Diligent auto ShaderTypeInd = pShaderResBindingD3D11->GetActiveShaderTypeIndex(s);
#ifdef DEVELOPMENT
- auto* pShaderD3D11 = ValidatedCast<ShaderD3D11Impl>(ppdbgShaders[s]);
- VERIFY_EXPR( ShaderTypeInd == static_cast<Int32>(pShaderD3D11->GetShaderTypeIndex()) );
+ auto* pShaderD3D11 = pPipelineStateD3D11->GetShader<ShaderD3D11Impl>(s);
+ VERIFY_EXPR( ShaderTypeInd == static_cast<Int32>(GetShaderTypeIndex(pShaderD3D11->GetDesc().ShaderType)) );
#endif
auto& Cache = pShaderResBindingD3D11->GetResourceCache(s);
@@ -595,7 +589,7 @@ namespace Diligent if (CommitResources && (m_DebugFlags & (Uint32)EngineD3D11DebugFlags::VerifyCommittedShaderResources) != 0)
{
// Use full resource layout to verify that all required resources are committed
- pShaderD3D11->GetResources()->dvpVerifyCommittedResources(
+ pShaderD3D11->GetD3D11Resources()->dvpVerifyCommittedResources(
m_CommittedD3D11CBs[ShaderTypeInd],
m_CommittedD3D11SRVs[ShaderTypeInd],
m_CommittedD3D11SRVResources[ShaderTypeInd],
diff --git a/Graphics/GraphicsEngineD3D11/src/RenderDeviceFactoryD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/EngineFactoryD3D11.cpp index 7e5ff13f..d69a94ee 100644 --- a/Graphics/GraphicsEngineD3D11/src/RenderDeviceFactoryD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/EngineFactoryD3D11.cpp @@ -25,7 +25,7 @@ /// Routines that initialize D3D11-based engine implementation #include "pch.h" -#include "RenderDeviceFactoryD3D11.h" +#include "EngineFactoryD3D11.h" #include "RenderDeviceD3D11Impl.h" #include "DeviceContextD3D11Impl.h" #include "SwapChainD3D11Impl.h" @@ -48,24 +48,24 @@ public: return &TheFactory; } - void CreateDeviceAndContextsD3D11( const EngineD3D11Attribs& EngineAttribs, - IRenderDevice** ppDevice, - IDeviceContext** ppContexts, - Uint32 NumDeferredContexts )override final; - - void CreateSwapChainD3D11( IRenderDevice* pDevice, - IDeviceContext* pImmediateContext, - const SwapChainDesc& SCDesc, - const FullScreenModeDesc& FSDesc, - void* pNativeWndHandle, - ISwapChain** ppSwapChain )override final; - - void AttachToD3D11Device(void* pd3d11NativeDevice, - void* pd3d11ImmediateContext, - const EngineD3D11Attribs& EngineAttribs, - IRenderDevice** ppDevice, - IDeviceContext** ppContexts, - Uint32 NumDeferredContexts)override final; + void CreateDeviceAndContextsD3D11(const EngineD3D11CreateInfo& EngineCI, + IRenderDevice** ppDevice, + IDeviceContext** ppContexts, + Uint32 NumDeferredContexts)override final; + + void CreateSwapChainD3D11(IRenderDevice* pDevice, + IDeviceContext* pImmediateContext, + const SwapChainDesc& SCDesc, + const FullScreenModeDesc& FSDesc, + void* pNativeWndHandle, + ISwapChain** ppSwapChain)override final; + + void AttachToD3D11Device(void* pd3d11NativeDevice, + void* pd3d11ImmediateContext, + const EngineD3D11CreateInfo& EngineCI, + IRenderDevice** ppDevice, + IDeviceContext** ppContexts, + Uint32 NumDeferredContexts)override final; }; @@ -92,7 +92,7 @@ inline bool SdkLayersAvailable() /// Creates render device and device contexts for Direct3D11-based engine implementation -/// \param [in] EngineAttribs - Engine creation attributes. +/// \param [in] EngineCI - Engine creation attributes. /// \param [out] ppDevice - Address of the memory location where pointer to /// the created device will be written /// \param [out] ppContexts - Address of the memory location where pointers to @@ -103,13 +103,13 @@ inline bool SdkLayersAvailable() /// of deferred contexts is requested, pointers to the /// contexts are written to ppContexts array starting /// at position 1 -void EngineFactoryD3D11Impl::CreateDeviceAndContextsD3D11( const EngineD3D11Attribs& EngineAttribs, - IRenderDevice** ppDevice, - IDeviceContext** ppContexts, - Uint32 NumDeferredContexts ) +void EngineFactoryD3D11Impl::CreateDeviceAndContextsD3D11(const EngineD3D11CreateInfo& EngineCI, + IRenderDevice** ppDevice, + IDeviceContext** ppContexts, + Uint32 NumDeferredContexts ) { - if (EngineAttribs.DebugMessageCallback != nullptr) - SetDebugMessageCallback(EngineAttribs.DebugMessageCallback); + if (EngineCI.DebugMessageCallback != nullptr) + SetDebugMessageCallback(EngineCI.DebugMessageCallback); VERIFY( ppDevice && ppContexts, "Null pointer provided" ); if( !ppDevice || !ppContexts ) @@ -153,14 +153,14 @@ void EngineFactoryD3D11Impl::CreateDeviceAndContextsD3D11( const EngineD3D11Attr CComPtr<ID3D11DeviceContext> pd3d11Context; CComPtr<IDXGIAdapter1> hardwareAdapter; - if(EngineAttribs.AdapterId != EngineD3D11Attribs::DefaultAdapterId) + if (EngineCI.AdapterId != EngineD3D11CreateInfo::DefaultAdapterId) { auto Adapters = FindCompatibleAdapters(); - if (EngineAttribs.AdapterId < Adapters.size()) - hardwareAdapter = Adapters[EngineAttribs.AdapterId]; + if (EngineCI.AdapterId < Adapters.size()) + hardwareAdapter = Adapters[EngineCI.AdapterId]; else { - LOG_ERROR_AND_THROW(EngineAttribs.AdapterId, " is not a valid hardware adapter id. Total number of compatible adapters available on this system: ", Adapters.size()); + LOG_ERROR_AND_THROW(EngineCI.AdapterId, " is not a valid hardware adapter id. Total number of compatible adapters available on this system: ", Adapters.size()); } } @@ -199,7 +199,7 @@ void EngineFactoryD3D11Impl::CreateDeviceAndContextsD3D11( const EngineD3D11Attr return; } - AttachToD3D11Device(pd3d11Device, pd3d11Context, EngineAttribs, ppDevice, ppContexts, NumDeferredContexts); + AttachToD3D11Device(pd3d11Device, pd3d11Context, EngineCI, ppDevice, ppContexts, NumDeferredContexts); } @@ -207,7 +207,7 @@ void EngineFactoryD3D11Impl::CreateDeviceAndContextsD3D11( const EngineD3D11Attr /// \param [in] pd3d11NativeDevice - pointer to native D3D11 device /// \param [in] pd3d11ImmediateContext - pointer to native D3D11 immediate context -/// \param [in] EngineAttribs - Engine creation attributes. +/// \param [in] EngineCI - Engine creation attributes. /// \param [out] ppDevice - Address of the memory location where pointer to /// the created device will be written /// \param [out] ppContexts - Address of the memory location where pointers to @@ -218,15 +218,15 @@ void EngineFactoryD3D11Impl::CreateDeviceAndContextsD3D11( const EngineD3D11Attr /// of deferred contexts is requested, pointers to the /// contexts are written to ppContexts array starting /// at position 1 -void EngineFactoryD3D11Impl::AttachToD3D11Device(void* pd3d11NativeDevice, - void* pd3d11ImmediateContext, - const EngineD3D11Attribs& EngineAttribs, - IRenderDevice** ppDevice, - IDeviceContext** ppContexts, - Uint32 NumDeferredContexts) +void EngineFactoryD3D11Impl::AttachToD3D11Device(void* pd3d11NativeDevice, + void* pd3d11ImmediateContext, + const EngineD3D11CreateInfo& EngineCI, + IRenderDevice** ppDevice, + IDeviceContext** ppContexts, + Uint32 NumDeferredContexts) { - if (EngineAttribs.DebugMessageCallback != nullptr) - SetDebugMessageCallback(EngineAttribs.DebugMessageCallback); + if (EngineCI.DebugMessageCallback != nullptr) + SetDebugMessageCallback(EngineCI.DebugMessageCallback); VERIFY( ppDevice && ppContexts, "Null pointer provided" ); if( !ppDevice || !ppContexts ) @@ -237,14 +237,14 @@ void EngineFactoryD3D11Impl::AttachToD3D11Device(void* pd3d1 ID3D11Device *pd3d11Device = reinterpret_cast<ID3D11Device *>(pd3d11NativeDevice); ID3D11DeviceContext *pd3d11ImmediateCtx = reinterpret_cast<ID3D11DeviceContext *>(pd3d11ImmediateContext); - SetRawAllocator(EngineAttribs.pRawMemAllocator); + SetRawAllocator(EngineCI.pRawMemAllocator); auto &RawAlloctor = GetRawAllocator(); RenderDeviceD3D11Impl *pRenderDeviceD3D11(NEW_RC_OBJ(RawAlloctor, "RenderDeviceD3D11Impl instance", RenderDeviceD3D11Impl) - (RawAlloctor, EngineAttribs, pd3d11Device, NumDeferredContexts)); + (RawAlloctor, EngineCI, pd3d11Device, NumDeferredContexts)); pRenderDeviceD3D11->QueryInterface(IID_RenderDevice, reinterpret_cast<IObject**>(ppDevice)); RefCntAutoPtr<DeviceContextD3D11Impl> pDeviceContextD3D11(NEW_RC_OBJ(RawAlloctor, "DeviceContextD3D11Impl instance", DeviceContextD3D11Impl) - (RawAlloctor, pRenderDeviceD3D11, pd3d11ImmediateCtx, EngineAttribs, false)); + (RawAlloctor, pRenderDeviceD3D11, pd3d11ImmediateCtx, EngineCI, false)); // We must call AddRef() (implicitly through QueryInterface()) because pRenderDeviceD3D11 will // keep a weak reference to the context pDeviceContextD3D11->QueryInterface(IID_DeviceContext, reinterpret_cast<IObject**>(ppContexts)); @@ -257,7 +257,7 @@ void EngineFactoryD3D11Impl::AttachToD3D11Device(void* pd3d1 CHECK_D3D_RESULT_THROW(hr, "Failed to create D3D11 deferred context"); RefCntAutoPtr<DeviceContextD3D11Impl> pDeferredCtxD3D11( NEW_RC_OBJ(RawAlloctor, "DeviceContextD3D11Impl instance", DeviceContextD3D11Impl) - (RawAlloctor, pRenderDeviceD3D11, pd3d11DeferredCtx, EngineAttribs, true)); + (RawAlloctor, pRenderDeviceD3D11, pd3d11DeferredCtx, EngineCI, true)); // We must call AddRef() (implicitly through QueryInterface()) because pRenderDeviceD3D12 will // keep a weak reference to the context pDeferredCtxD3D11->QueryInterface(IID_DeviceContext, reinterpret_cast<IObject**>(ppContexts + 1 + DeferredCtx)); @@ -299,12 +299,12 @@ void EngineFactoryD3D11Impl::AttachToD3D11Device(void* pd3d1 /// /// \param [out] ppSwapChain - Address of the memory location where pointer to the new /// swap chain will be written -void EngineFactoryD3D11Impl::CreateSwapChainD3D11( IRenderDevice* pDevice, - IDeviceContext* pImmediateContext, - const SwapChainDesc& SCDesc, - const FullScreenModeDesc& FSDesc, - void* pNativeWndHandle, - ISwapChain** ppSwapChain ) +void EngineFactoryD3D11Impl::CreateSwapChainD3D11(IRenderDevice* pDevice, + IDeviceContext* pImmediateContext, + const SwapChainDesc& SCDesc, + const FullScreenModeDesc& FSDesc, + void* pNativeWndHandle, + ISwapChain** ppSwapChain) { VERIFY( ppSwapChain, "Null pointer provided" ); if( !ppSwapChain ) diff --git a/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp index 90828884..d9cc1c21 100644 --- a/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp @@ -27,6 +27,7 @@ #include "RenderDeviceD3D11Impl.h" #include "ShaderResourceBindingD3D11Impl.h" #include "EngineMemory.h" +#include "ShaderD3D11Impl.h" namespace Diligent { @@ -35,7 +36,8 @@ PipelineStateD3D11Impl::PipelineStateD3D11Impl(IReferenceCounters* pRefCoun RenderDeviceD3D11Impl* pRenderDeviceD3D11, const PipelineStateDesc& PipelineDesc) : TPipelineStateBase(pRefCounters, pRenderDeviceD3D11, PipelineDesc), - m_SRBMemAllocator(GetRawAllocator()) + m_SRBMemAllocator(GetRawAllocator()), + m_StaticSamplers(STD_ALLOCATOR_RAW_MEM(StaticSamplerInfo, GetRawAllocator(), "Allocator for vector<StaticSamplerInfo>")) { if (PipelineDesc.IsComputePipeline) { @@ -50,7 +52,7 @@ PipelineStateD3D11Impl::PipelineStateD3D11Impl(IReferenceCounters* pRefCoun { LOG_ERROR_AND_THROW(GetShaderTypeLiteralName(SHADER_TYPE_COMPUTE), " shader is expeceted while ", GetShaderTypeLiteralName(m_pCS->GetDesc().ShaderType), " provided"); } - m_ShaderResourceLayoutHash = pCS->GetResources()->GetHash(); + m_ShaderResourceLayoutHash = pCS->GetD3D11Resources()->GetHash(); } else { @@ -64,7 +66,7 @@ PipelineStateD3D11Impl::PipelineStateD3D11Impl(IReferenceCounters* pRefCoun LOG_ERROR_AND_THROW( GetShaderTypeLiteralName(ExpectedType), " shader is expeceted while ", GetShaderTypeLiteralName(m_p##ShortName->GetDesc().ShaderType)," provided" ); \ } \ if(pShader!=nullptr) \ - HashCombine(m_ShaderResourceLayoutHash, pShader->GetResources()->GetHash() ); \ + HashCombine(m_ShaderResourceLayoutHash, pShader->GetD3D11Resources()->GetHash() ); \ } INIT_SHADER(VS, SHADER_TYPE_VERTEX); @@ -110,26 +112,109 @@ PipelineStateD3D11Impl::PipelineStateD3D11Impl(IReferenceCounters* pRefCoun } } - if(PipelineDesc.SRBAllocationGranularity > 1) + auto* pStaticResLayoutRawMem = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceLayoutD3D11", m_NumShaders * sizeof(ShaderResourceLayoutD3D11)); + m_pStaticResourceLayouts = reinterpret_cast<ShaderResourceLayoutD3D11*>(pStaticResLayoutRawMem); + + auto* pResCacheRawMem = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceCacheD3D11", m_NumShaders * sizeof(ShaderResourceCacheD3D11)); + m_pStaticResourceCaches = reinterpret_cast<ShaderResourceCacheD3D11*>(pResCacheRawMem); + + const auto& ResourceLayout = PipelineDesc.ResourceLayout; + +#ifdef DEVELOPMENT { - std::array<size_t, MaxShadersInPipeline> ShaderResLayoutDataSizes = {}; - std::array<size_t, MaxShadersInPipeline> ShaderResCacheDataSizes = {}; + const ShaderResources* pResources[MaxShadersInPipeline] = {}; for (Uint32 s = 0; s < m_NumShaders; ++s) { auto* pShader = GetShader<const ShaderD3D11Impl>(s); - const auto& ShaderResources = *pShader->GetResources(); - std::array<SHADER_VARIABLE_TYPE, 2> AllowedVarTypes = { SHADER_VARIABLE_TYPE_MUTABLE, SHADER_VARIABLE_TYPE_DYNAMIC }; - ShaderResLayoutDataSizes[s] = ShaderResourceLayoutD3D11::GetRequiredMemorySize(ShaderResources, AllowedVarTypes.data(), static_cast<Uint32>(AllowedVarTypes.size())); + pResources[s] = &(*pShader->GetD3D11Resources()); + } + ShaderResources::DvpVerifyResourceLayout(ResourceLayout, pResources, m_NumShaders); + } +#endif + + decltype(m_StaticSamplers) StaticSamplers(STD_ALLOCATOR_RAW_MEM(StaticSamplerInfo, GetRawAllocator(), "Allocator for vector<StaticSamplerInfo>")); + std::array<size_t, MaxShadersInPipeline> ShaderResLayoutDataSizes = {}; + std::array<size_t, MaxShadersInPipeline> ShaderResCacheDataSizes = {}; + for (Uint32 s = 0; s < m_NumShaders; ++s) + { + auto* pShader = GetShader<const ShaderD3D11Impl>(s); + const auto& ShaderResources = *pShader->GetD3D11Resources(); + + new (m_pStaticResourceCaches+s) ShaderResourceCacheD3D11; + // Do not initialize the cache as this will be performed by the resource layout + + // Shader resource layout will only contain dynamic and mutable variables + const SHADER_RESOURCE_VARIABLE_TYPE StaticVarTypes[] = {SHADER_RESOURCE_VARIABLE_TYPE_STATIC}; + new (m_pStaticResourceLayouts + s) + ShaderResourceLayoutD3D11 + { + *this, + pShader->GetD3D11Resources(), + m_Desc.ResourceLayout, + StaticVarTypes, + _countof(StaticVarTypes), + m_pStaticResourceCaches[s], + GetRawAllocator(), + GetRawAllocator() + }; + + // Initialize static samplers + for(Uint32 sam = 0; sam < ShaderResources.GetNumSamplers(); ++sam) + { + const auto& SamplerAttribs = ShaderResources.GetSampler(sam); + auto SrcStaticSamplerInd = ShaderResources.FindStaticSampler(SamplerAttribs, ResourceLayout); + if (SrcStaticSamplerInd >= 0) + { + const auto& SrcStaticSamplerInfo = ResourceLayout.StaticSamplers[SrcStaticSamplerInd]; + RefCntAutoPtr<ISampler> pStaticSampler; + pRenderDeviceD3D11->CreateSampler(SrcStaticSamplerInfo.Desc, &pStaticSampler); + StaticSamplers.emplace_back(SamplerAttribs, std::move(pStaticSampler)); + } + } + m_StaticSamplerOffsets[s + 1] = static_cast<Uint16>(StaticSamplers.size()); + + if (PipelineDesc.SRBAllocationGranularity > 1) + { + const SHADER_RESOURCE_VARIABLE_TYPE SRBVarTypes[] = { SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC }; + ShaderResLayoutDataSizes[s] = ShaderResourceLayoutD3D11::GetRequiredMemorySize(ShaderResources, ResourceLayout, SRBVarTypes, _countof(SRBVarTypes)); ShaderResCacheDataSizes[s] = ShaderResourceCacheD3D11::GetRequriedMemorySize(ShaderResources); } + + auto ShaderInd = GetShaderTypeIndex(pShader->GetDesc().ShaderType); + m_ResourceLayoutIndex[ShaderInd] = static_cast<Int8>(s); + } + if (PipelineDesc.SRBAllocationGranularity > 1) + { m_SRBMemAllocator.Initialize(PipelineDesc.SRBAllocationGranularity, m_NumShaders, ShaderResLayoutDataSizes.data(), m_NumShaders, ShaderResCacheDataSizes.data()); } + + m_StaticSamplers.reserve(StaticSamplers.size()); + for(auto& Sam : StaticSamplers) + m_StaticSamplers.emplace_back(std::move(Sam)); + + for (Uint32 s = 0; s < m_NumShaders; ++s) + { + // Initialize static samplers in the static resource cache to avoid warning messages + SetStaticSamplers(m_pStaticResourceCaches[s], s); + } } PipelineStateD3D11Impl::~PipelineStateD3D11Impl() { + for (Uint32 s = 0; s < m_NumShaders; ++s) + { + m_pStaticResourceCaches[s].Destroy(GetRawAllocator()); + m_pStaticResourceCaches[s].~ShaderResourceCacheD3D11(); + } + GetRawAllocator().Free(m_pStaticResourceCaches); + + for (Uint32 l = 0; l < m_NumShaders; ++l) + { + m_pStaticResourceLayouts[l].~ShaderResourceLayoutD3D11(); + } + GetRawAllocator().Free(m_pStaticResourceLayouts); } IMPLEMENT_QUERY_INTERFACE( PipelineStateD3D11Impl, IID_PipelineStateD3D11, TPipelineStateBase ) @@ -183,11 +268,11 @@ bool PipelineStateD3D11Impl::IsCompatibleWith(const IPipelineState* pPSO)const { auto* pShader0 = GetShader<const ShaderD3D11Impl>(s); auto* pShader1 = pPSOD3D11->GetShader<const ShaderD3D11Impl>(s); - if (pShader0->GetShaderTypeIndex() != pShader1->GetShaderTypeIndex()) + if (pShader0->GetDesc().ShaderType != pShader1->GetDesc().ShaderType) return false; - const ShaderResourcesD3D11* pRes0 = pShader0->GetResources().get(); - const ShaderResourcesD3D11* pRes1 = pShader1->GetResources().get(); - if (!pRes0->IsCompatibleWith(*pRes1)) + const auto& Res0 = *pShader0->GetD3D11Resources(); + const auto& Res1 = *pShader1->GetD3D11Resources(); + if (!Res0.IsCompatibleWith(Res1)) return false; } @@ -236,4 +321,57 @@ ID3D11ComputeShader* PipelineStateD3D11Impl::GetD3D11ComputeShader() return static_cast<ID3D11ComputeShader*>(pCSD3D11->GetD3D11Shader()); } + +void PipelineStateD3D11Impl::BindStaticResources(Uint32 ShaderFlags, IResourceMapping* pResourceMapping, Uint32 Flags) +{ + for (Uint32 s=0; s < m_NumShaders; ++s) + { + auto& StaticResLayout = m_pStaticResourceLayouts[s]; + if ( (ShaderFlags & StaticResLayout.GetShaderType()) != 0 ) + StaticResLayout.BindResources(pResourceMapping, Flags, m_pStaticResourceCaches[s]); + } +} + +Uint32 PipelineStateD3D11Impl::GetStaticVariableCount(SHADER_TYPE ShaderType) const +{ + const auto LayoutInd = m_ResourceLayoutIndex[GetShaderTypeIndex(ShaderType)]; + if (LayoutInd < 0) + return 0; + + return m_pStaticResourceLayouts[LayoutInd].GetTotalResourceCount(); +} + +IShaderResourceVariable* PipelineStateD3D11Impl::GetStaticShaderVariable(SHADER_TYPE ShaderType, const Char* Name) +{ + const auto LayoutInd = m_ResourceLayoutIndex[GetShaderTypeIndex(ShaderType)]; + if (LayoutInd < 0) + return nullptr; + + return m_pStaticResourceLayouts[LayoutInd].GetShaderVariable(Name); +} + +IShaderResourceVariable* PipelineStateD3D11Impl::GetStaticShaderVariable(SHADER_TYPE ShaderType, Uint32 Index) +{ + const auto LayoutInd = m_ResourceLayoutIndex[GetShaderTypeIndex(ShaderType)]; + if (LayoutInd < 0) + return nullptr; + + return m_pStaticResourceLayouts[LayoutInd].GetShaderVariable(Index); +} + +void PipelineStateD3D11Impl::SetStaticSamplers(ShaderResourceCacheD3D11& ResourceCache, Uint32 ShaderInd)const +{ + auto NumCachedSamplers = ResourceCache.GetSamplerCount(); + for (Uint32 s = m_StaticSamplerOffsets[ShaderInd]; s < m_StaticSamplerOffsets[ShaderInd+1]; ++s) + { + auto& SamplerInfo = m_StaticSamplers[s]; + const auto& SamAttribs = SamplerInfo.Attribs; + auto* pSamplerD3D11Impl = SamplerInfo.pSampler.RawPtr<SamplerD3D11Impl>(); + // Limiting EndBindPoint is required when initializing static samplers in a Shader's static cache + auto EndBindPoint = std::min( static_cast<Uint32>(SamAttribs.BindPoint) + SamAttribs.BindCount, NumCachedSamplers); + for (Uint32 BindPoint = SamAttribs.BindPoint; BindPoint < EndBindPoint; ++BindPoint ) + ResourceCache.SetSampler(BindPoint, pSamplerD3D11Impl); + } +} + } diff --git a/Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp index 2d08f430..04f54ad5 100644 --- a/Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp @@ -40,11 +40,11 @@ namespace Diligent { -RenderDeviceD3D11Impl :: RenderDeviceD3D11Impl(IReferenceCounters* pRefCounters, - IMemoryAllocator& RawMemAllocator, - const EngineD3D11Attribs& EngineAttribs, - ID3D11Device* pd3d11Device, - Uint32 NumDeferredContexts) : +RenderDeviceD3D11Impl :: RenderDeviceD3D11Impl(IReferenceCounters* pRefCounters, + IMemoryAllocator& RawMemAllocator, + const EngineD3D11CreateInfo& EngineAttribs, + ID3D11Device* pd3d11Device, + Uint32 NumDeferredContexts) : TRenderDeviceBase { pRefCounters, @@ -134,13 +134,13 @@ void RenderDeviceD3D11Impl :: CreateBuffer(const BufferDesc& BuffDesc, const Buf ); } -void RenderDeviceD3D11Impl :: CreateShader(const ShaderCreationAttribs& ShaderCreationAttribs, IShader** ppShader) +void RenderDeviceD3D11Impl :: CreateShader(const ShaderCreateInfo& ShaderCI, IShader** ppShader) { - CreateDeviceObject( "shader", ShaderCreationAttribs.Desc, ppShader, + CreateDeviceObject( "shader", ShaderCI.Desc, ppShader, [&]() { ShaderD3D11Impl* pShaderD3D11( NEW_RC_OBJ(m_ShaderObjAllocator, "ShaderD3D11Impl instance", ShaderD3D11Impl) - (this, ShaderCreationAttribs ) ); + (this, ShaderCI) ); pShaderD3D11->QueryInterface( IID_Shader, reinterpret_cast<IObject**>(ppShader) ); OnCreateDeviceObject( pShaderD3D11 ); diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp index 12288cdd..677cd40c 100644 --- a/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp @@ -32,14 +32,12 @@ namespace Diligent ShaderD3D11Impl::ShaderD3D11Impl(IReferenceCounters* pRefCounters, RenderDeviceD3D11Impl* pRenderDeviceD3D11, - const ShaderCreationAttribs& CreationAttribs) : - TShaderBase(pRefCounters, pRenderDeviceD3D11, CreationAttribs.Desc), - ShaderD3DBase(CreationAttribs), - m_StaticResLayout(*this), - m_ShaderTypeIndex(Diligent::GetShaderTypeIndex(CreationAttribs.Desc.ShaderType)) + const ShaderCreateInfo& ShaderCI) : + TShaderBase(pRefCounters, pRenderDeviceD3D11, ShaderCI.Desc), + ShaderD3DBase(ShaderCI) { auto *pDeviceD3D11 = pRenderDeviceD3D11->GetD3D11Device(); - switch(CreationAttribs.Desc.ShaderType) + switch (ShaderCI.Desc.ShaderType) { #define CREATE_SHADER(SHADER_NAME, ShaderName)\ @@ -76,29 +74,18 @@ ShaderD3D11Impl::ShaderD3D11Impl(IReferenceCounters* pRefCounters, } // Load shader resources - auto &Allocator = GetRawAllocator(); - auto *pRawMem = ALLOCATE(Allocator, "Allocator for ShaderResources", sizeof(ShaderResourcesD3D11)); - auto *pResources = new (pRawMem) ShaderResourcesD3D11(pRenderDeviceD3D11, m_pShaderByteCode, m_Desc, CreationAttribs.UseCombinedTextureSamplers ? CreationAttribs.CombinedSamplerSuffix : nullptr); + auto& Allocator = GetRawAllocator(); + auto* pRawMem = ALLOCATE(Allocator, "Allocator for ShaderResources", sizeof(ShaderResourcesD3D11)); + auto* pResources = new (pRawMem) ShaderResourcesD3D11(pRenderDeviceD3D11, m_pShaderByteCode, m_Desc, ShaderCI.UseCombinedTextureSamplers ? ShaderCI.CombinedSamplerSuffix : nullptr); m_pShaderResources.reset(pResources, STDDeleterRawMem<ShaderResourcesD3D11>(Allocator)); - // Clone only static resources that will be set directly in the shader - SHADER_VARIABLE_TYPE VarTypes[] = {SHADER_VARIABLE_TYPE_STATIC}; - // The method will also initialize resource cache to have enough space to hold static variables only! - m_StaticResLayout.Initialize(m_pShaderResources, VarTypes, _countof(VarTypes), m_StaticResCache, GetRawAllocator(), GetRawAllocator()); - - // This is not required, but still... - m_pShaderResources->SetStaticSamplers(m_StaticResCache); - // Byte code is only required for the vertex shader to create input layout - if( CreationAttribs.Desc.ShaderType != SHADER_TYPE_VERTEX ) + if( ShaderCI.Desc.ShaderType != SHADER_TYPE_VERTEX ) m_pShaderByteCode.Release(); } ShaderD3D11Impl::~ShaderD3D11Impl() { - m_StaticResCache.Destroy(GetRawAllocator()); } -IMPLEMENT_QUERY_INTERFACE( ShaderD3D11Impl, IID_ShaderD3D11, TShaderBase ) - } diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp index 3cce0055..a99da5de 100644 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp @@ -37,24 +37,21 @@ ShaderResourceBindingD3D11Impl::ShaderResourceBindingD3D11Impl( IReferenceCounte TBase( pRefCounters, pPSO, IsInternal ), m_bIsStaticResourcesBound(false) { - for(size_t s=0; s < _countof(m_ResourceLayoutIndex); ++s) - m_ResourceLayoutIndex[s] = -1; + m_NumActiveShaders = static_cast<Uint8>(pPSO->GetNumShaders()); - auto ppShaders = pPSO->GetShaders(); - m_NumActiveShaders = static_cast<Uint8>( pPSO->GetNumShaders() ); - - auto *pResLayoutRawMem = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceLayoutD3D11", m_NumActiveShaders * sizeof(ShaderResourceLayoutD3D11)); + auto* pResLayoutRawMem = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceLayoutD3D11", m_NumActiveShaders * sizeof(ShaderResourceLayoutD3D11)); m_pResourceLayouts = reinterpret_cast<ShaderResourceLayoutD3D11*>(pResLayoutRawMem); - auto *pResCacheRawMem = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceCacheD3D11", m_NumActiveShaders * sizeof(ShaderResourceCacheD3D11)); + auto* pResCacheRawMem = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceCacheD3D11", m_NumActiveShaders * sizeof(ShaderResourceCacheD3D11)); m_pBoundResourceCaches = reinterpret_cast<ShaderResourceCacheD3D11*>(pResCacheRawMem); + + const auto& PSODesc = pPSO->GetDesc(); // Reserve memory for resource layouts for (Uint8 s = 0; s < m_NumActiveShaders; ++s) { - auto *pShaderD3D11 = ValidatedCast<ShaderD3D11Impl>(ppShaders[s]); - auto ShaderInd = pShaderD3D11->GetShaderTypeIndex(); - VERIFY_EXPR(static_cast<Int32>(ShaderInd) == GetShaderTypeIndex(pShaderD3D11->GetDesc().ShaderType)); + auto* pShaderD3D11 = pPSO->GetShader<ShaderD3D11Impl>(s); + auto ShaderInd = GetShaderTypeIndex(pShaderD3D11->GetDesc().ShaderType); auto& SRBMemAllocator = pPSO->GetSRBMemoryAllocator(); auto& ResCacheDataAllocator = SRBMemAllocator.GetResourceCacheDataAllocator(s); @@ -62,17 +59,25 @@ ShaderResourceBindingD3D11Impl::ShaderResourceBindingD3D11Impl( IReferenceCounte // Initialize resource cache to have enough space to contain all shader resources, including static ones // Static resources are copied before resources are committed - const auto& Resources = *pShaderD3D11->GetResources(); + const auto& Resources = *pShaderD3D11->GetD3D11Resources(); new (m_pBoundResourceCaches+s) ShaderResourceCacheD3D11; m_pBoundResourceCaches[s].Initialize(Resources, ResCacheDataAllocator); // Shader resource layout will only contain dynamic and mutable variables // http://diligentgraphics.com/diligent-engine/architecture/d3d11/shader-resource-cache#Shader-Resource-Cache-Initialization - SHADER_VARIABLE_TYPE VarTypes[] = {SHADER_VARIABLE_TYPE_MUTABLE, SHADER_VARIABLE_TYPE_DYNAMIC}; - new (m_pResourceLayouts + s) ShaderResourceLayoutD3D11(*this); - m_pResourceLayouts[s].Initialize(pShaderD3D11->GetResources(), VarTypes, _countof(VarTypes), m_pBoundResourceCaches[s], ResCacheDataAllocator, ResLayoutDataAllocator); - - Resources.SetStaticSamplers(m_pBoundResourceCaches[s]); + SHADER_RESOURCE_VARIABLE_TYPE VarTypes[] = {SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC}; + new (m_pResourceLayouts + s) + ShaderResourceLayoutD3D11 + { + *this, + pShaderD3D11->GetD3D11Resources(), + PSODesc.ResourceLayout, + VarTypes, + _countof(VarTypes), + m_pBoundResourceCaches[s], + ResCacheDataAllocator, + ResLayoutDataAllocator + }; m_ResourceLayoutIndex[ShaderInd] = s; m_ShaderTypeIndex[s] = static_cast<Int8>(ShaderInd); @@ -99,7 +104,7 @@ ShaderResourceBindingD3D11Impl::~ShaderResourceBindingD3D11Impl() IMPLEMENT_QUERY_INTERFACE( ShaderResourceBindingD3D11Impl, IID_ShaderResourceBindingD3D11, TBase ) -void ShaderResourceBindingD3D11Impl::BindResources(Uint32 ShaderFlags, IResourceMapping *pResMapping, Uint32 Flags) +void ShaderResourceBindingD3D11Impl::BindResources(Uint32 ShaderFlags, IResourceMapping* pResMapping, Uint32 Flags) { for(Uint32 ResLayoutInd = 0; ResLayoutInd < m_NumActiveShaders; ++ResLayoutInd) { @@ -135,9 +140,10 @@ void ShaderResourceBindingD3D11Impl::InitializeStaticResources(const IPipelineSt for (Uint32 shader = 0; shader < NumShaders; ++shader) { + const auto& StaticResLayout = pPSOD3D11->GetStaticResourceLayout(shader); auto* pShaderD3D11 = ValidatedCast<ShaderD3D11Impl>(ppShaders[shader]); #ifdef DEVELOPMENT - if (!pShaderD3D11->GetStaticResourceLayout().dvpVerifyBindings()) + if (!StaticResLayout.dvpVerifyBindings()) { LOG_ERROR_MESSAGE("Static resources in SRB of PSO '", pPSOD3D11->GetDesc().Name, "' will not be successfully initialized " "because not all static resource bindings in shader '", pShaderD3D11->GetDesc().Name, "' are valid. " @@ -147,17 +153,18 @@ void ShaderResourceBindingD3D11Impl::InitializeStaticResources(const IPipelineSt #endif #ifdef _DEBUG - auto ShaderTypeInd = pShaderD3D11->GetShaderTypeIndex(); + auto ShaderTypeInd = GetShaderTypeIndex(pShaderD3D11->GetDesc().ShaderType); auto ResourceLayoutInd = m_ResourceLayoutIndex[ShaderTypeInd]; VERIFY_EXPR(ResourceLayoutInd == static_cast<Int8>(shader) ); #endif - pShaderD3D11->GetStaticResourceLayout().CopyResources( m_pBoundResourceCaches[shader] ); + StaticResLayout.CopyResources(m_pBoundResourceCaches[shader]); + pPSOD3D11->SetStaticSamplers(m_pBoundResourceCaches[shader], shader); } m_bIsStaticResourcesBound = true; } -IShaderVariable* ShaderResourceBindingD3D11Impl::GetVariable(SHADER_TYPE ShaderType, const char* Name) +IShaderResourceVariable* ShaderResourceBindingD3D11Impl::GetVariable(SHADER_TYPE ShaderType, const char* Name) { auto Ind = GetShaderTypeIndex(ShaderType); VERIFY_EXPR(Ind >= 0 && Ind < _countof(m_ResourceLayoutIndex)); @@ -185,7 +192,7 @@ Uint32 ShaderResourceBindingD3D11Impl::GetVariableCount(SHADER_TYPE ShaderType) return m_pResourceLayouts[ResLayoutIndex].GetTotalResourceCount(); } -IShaderVariable* ShaderResourceBindingD3D11Impl::GetVariable(SHADER_TYPE ShaderType, Uint32 Index) +IShaderResourceVariable* ShaderResourceBindingD3D11Impl::GetVariable(SHADER_TYPE ShaderType, Uint32 Index) { auto Ind = GetShaderTypeIndex(ShaderType); VERIFY_EXPR(Ind >= 0 && Ind < _countof(m_ResourceLayoutIndex)); diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp index 5321d5e3..262902b0 100755 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp @@ -33,14 +33,11 @@ #include "TextureViewD3D11.h"
#include "SamplerD3D11Impl.h"
#include "ShaderD3D11Impl.h"
+#include "ShaderResourceVariableBase.h"
namespace Diligent
{
-ShaderResourceLayoutD3D11::ShaderResourceLayoutD3D11(IObject& Owner) :
- m_Owner(Owner)
-{
-}
ShaderResourceLayoutD3D11::~ShaderResourceLayoutD3D11()
{
@@ -77,11 +74,15 @@ ShaderResourceLayoutD3D11::~ShaderResourceLayoutD3D11() );
}
-size_t ShaderResourceLayoutD3D11::GetRequiredMemorySize(const ShaderResourcesD3D11& SrcResources,
- const SHADER_VARIABLE_TYPE* VarTypes,
- Uint32 NumVarTypes)
+
+size_t ShaderResourceLayoutD3D11::GetRequiredMemorySize(const ShaderResourcesD3D11& SrcResources,
+ const PipelineResourceLayoutDesc& ResourceLayout,
+ const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes,
+ Uint32 NumAllowedTypes)
{
- auto ResCounters = SrcResources.CountResources(VarTypes, NumVarTypes);
+ // Skip static samplers as they are initialized directly in the resource cache by the PSO
+ constexpr bool CountStaticSamplers = false;
+ auto ResCounters = SrcResources.CountResources(ResourceLayout, AllowedVarTypes, NumAllowedTypes, CountStaticSamplers);
auto MemSize = ResCounters.NumCBs * sizeof(ConstBuffBindInfo) +
ResCounters.NumTexSRVs * sizeof(TexSRVBindInfo) +
ResCounters.NumTexUAVs * sizeof(TexUAVBindInfo) +
@@ -91,22 +92,27 @@ size_t ShaderResourceLayoutD3D11::GetRequiredMemorySize(const ShaderResourcesD3D return MemSize;
}
-void ShaderResourceLayoutD3D11::Initialize(std::shared_ptr<const ShaderResourcesD3D11> pSrcResources,
- const SHADER_VARIABLE_TYPE* VarTypes,
- Uint32 NumVarTypes,
- ShaderResourceCacheD3D11& ResourceCache,
- IMemoryAllocator& ResCacheDataAllocator,
- IMemoryAllocator& ResLayoutDataAllocator)
+
+ShaderResourceLayoutD3D11::ShaderResourceLayoutD3D11(IObject& Owner,
+ std::shared_ptr<const ShaderResourcesD3D11> pSrcResources,
+ const PipelineResourceLayoutDesc& ResourceLayout,
+ const SHADER_RESOURCE_VARIABLE_TYPE* VarTypes,
+ Uint32 NumVarTypes,
+ ShaderResourceCacheD3D11& ResourceCache,
+ IMemoryAllocator& ResCacheDataAllocator,
+ IMemoryAllocator& ResLayoutDataAllocator) :
+ m_Owner (Owner),
+ m_pResources (std::move(pSrcResources)),
+ m_ResourceCache (ResourceCache)
{
// http://diligentgraphics.com/diligent-engine/architecture/d3d11/shader-resource-layout#Shader-Resource-Layout-Initialization
- m_pResources = std::move(pSrcResources);
- m_pResourceCache = &ResourceCache;
-
- auto AllowedTypeBits = GetAllowedTypeBits(VarTypes, NumVarTypes);
+ const auto AllowedTypeBits = GetAllowedTypeBits(VarTypes, NumVarTypes);
// Count total number of resources of allowed types
- auto ResCounters = m_pResources->CountResources(VarTypes, NumVarTypes);
+ // Skip static samplers as they are initialized directly in the resource cache by the PSO
+ constexpr bool CountStaticSamplers = false;
+ auto ResCounters = m_pResources->CountResources(ResourceLayout, VarTypes, NumVarTypes, CountStaticSamplers);
// Initialize offsets
size_t CurrentOffset = 0;
@@ -119,7 +125,7 @@ void ShaderResourceLayoutD3D11::Initialize(std::shared_ptr<const ShaderResources return Offset;
};
- auto CBOffset = AdvanceOffset(ResCounters.NumCBs * sizeof(ConstBuffBindInfo)); CBOffset; // To suppress warning
+ auto CBOffset = AdvanceOffset(ResCounters.NumCBs * sizeof(ConstBuffBindInfo)); (void)CBOffset; // To suppress warning
m_TexSRVsOffset = AdvanceOffset(ResCounters.NumTexSRVs * sizeof(TexSRVBindInfo) );
m_TexUAVsOffset = AdvanceOffset(ResCounters.NumTexUAVs * sizeof(TexUAVBindInfo) );
m_BuffSRVsOffset = AdvanceOffset(ResCounters.NumBufSRVs * sizeof(BuffSRVBindInfo) );
@@ -127,11 +133,11 @@ void ShaderResourceLayoutD3D11::Initialize(std::shared_ptr<const ShaderResources m_SamplerOffset = AdvanceOffset(ResCounters.NumSamplers * sizeof(SamplerBindInfo) );
m_MemorySize = AdvanceOffset(0);
- VERIFY_EXPR(m_MemorySize == GetRequiredMemorySize(*m_pResources, VarTypes, NumVarTypes));
+ VERIFY_EXPR(m_MemorySize == GetRequiredMemorySize(*m_pResources, ResourceLayout, VarTypes, NumVarTypes));
if (m_MemorySize)
{
- auto *pRawMem = ALLOCATE(ResLayoutDataAllocator, "Raw memory buffer for shader resource layout resources", m_MemorySize);
+ auto* pRawMem = ALLOCATE(ResLayoutDataAllocator, "Raw memory buffer for shader resource layout resources", m_MemorySize);
m_ResourceBuffer = std::unique_ptr<void, STDDeleterRawMem<void> >(pRawMem, ResLayoutDataAllocator);
}
@@ -155,87 +161,119 @@ void ShaderResourceLayoutD3D11::Initialize(std::shared_ptr<const ShaderResources Uint32 NumSamplerSlots = 0;
Uint32 NumUAVSlots = 0;
m_pResources->ProcessResources(
- VarTypes, NumVarTypes,
-
[&](const D3DShaderResourceAttribs& CB, Uint32)
{
- VERIFY_EXPR( CB.IsAllowedType(AllowedTypeBits) );
-
- // Initialize current CB in place, increment CB counter
- new (&GetResource<ConstBuffBindInfo>(cb++)) ConstBuffBindInfo( CB, *this );
- NumCBSlots = std::max(NumCBSlots, Uint32{CB.BindPoint} + Uint32{CB.BindCount});
+ auto VarType = m_pResources->FindVariableType(CB, ResourceLayout);
+ if (IsAllowedType(VarType, AllowedTypeBits))
+ {
+ // Initialize current CB in place, increment CB counter
+ new (&GetResource<ConstBuffBindInfo>(cb++)) ConstBuffBindInfo(CB, *this, VarType);
+ NumCBSlots = std::max(NumCBSlots, Uint32{CB.BindPoint} + Uint32{CB.BindCount});
+ }
},
[&](const D3DShaderResourceAttribs& Sampler, Uint32)
{
- VERIFY_EXPR(Sampler.IsAllowedType(AllowedTypeBits));
-
- // Skip static samplers as they are initialized in the resource cache
- if (!Sampler.IsStaticSampler())
+ auto VarType = m_pResources->FindVariableType(Sampler, ResourceLayout);
+ if (IsAllowedType(VarType, AllowedTypeBits))
{
+ auto StaticSamplerInd = m_pResources->FindStaticSampler(Sampler, ResourceLayout);
+ if (StaticSamplerInd >= 0)
+ {
+ // Skip static samplers as they are initialized directly in the resource cache by the PSO
+ return;
+ }
// Initialize current sampler in place, increment sampler counter
- new (&GetResource<SamplerBindInfo>(sam++)) SamplerBindInfo( Sampler, *this );
+ new (&GetResource<SamplerBindInfo>(sam++)) SamplerBindInfo(Sampler, *this, VarType);
NumSamplerSlots = std::max(NumSamplerSlots, Uint32{Sampler.BindPoint} + Uint32{Sampler.BindCount});
}
},
[&](const D3DShaderResourceAttribs& TexSRV, Uint32)
{
- VERIFY_EXPR( TexSRV.IsAllowedType(AllowedTypeBits) );
+ auto VarType = m_pResources->FindVariableType(TexSRV, ResourceLayout);
+ if (!IsAllowedType(VarType, AllowedTypeBits))
+ return;
+
auto NumSamplers = GetNumSamplers();
VERIFY(sam == NumSamplers, "All samplers must be initialized before texture SRVs");
Uint32 AssignedSamplerIndex = TexSRVBindInfo::InvalidSamplerIndex;
- if (TexSRV.ValidSamplerAssigned())
+ if (TexSRV.IsCombinedWithSampler())
{
- const auto& AssignedSamplerAttribs = m_pResources->GetSampler(TexSRV.GetSamplerId());
- DEV_CHECK_ERR(AssignedSamplerAttribs.GetVariableType() == TexSRV.GetVariableType(),
- "The type (", GetShaderVariableTypeLiteralName(TexSRV.GetVariableType()),") of texture SRV variable '", TexSRV.Name,
- "' is not consistent with the type (", GetShaderVariableTypeLiteralName(AssignedSamplerAttribs.GetVariableType()),
+ const auto& AssignedSamplerAttribs = m_pResources->GetCombinedSampler(TexSRV);
+ auto AssignedSamplerType = m_pResources->FindVariableType(AssignedSamplerAttribs, ResourceLayout);
+ DEV_CHECK_ERR(AssignedSamplerType == VarType,
+ "The type (", GetShaderVariableTypeLiteralName(VarType),") of texture SRV variable '", TexSRV.Name,
+ "' is not consistent with the type (", GetShaderVariableTypeLiteralName(AssignedSamplerType),
") of the sampler '", AssignedSamplerAttribs.Name, "' that is assigned to it");
- // Do not assign static sampler to texture SRV as it is initialized directly in the shader resource cache
- if (!AssignedSamplerAttribs.IsStaticSampler())
+
+ bool SamplerFound = false;
+ for (AssignedSamplerIndex = 0; AssignedSamplerIndex < NumSamplers; ++AssignedSamplerIndex)
+ {
+ const auto& Sampler = GetResource<SamplerBindInfo>(AssignedSamplerIndex);
+ SamplerFound = strcmp(Sampler.m_Attribs.Name, AssignedSamplerAttribs.Name) == 0;
+ if (SamplerFound)
+ break; // Otherwise AssignedSamplerIndex will be incremented
+ }
+
+ if (!SamplerFound)
{
- for (AssignedSamplerIndex = 0; AssignedSamplerIndex < NumSamplers; ++AssignedSamplerIndex)
+ AssignedSamplerIndex = TexSRVBindInfo::InvalidSamplerIndex;
+#ifdef _DEBUG
+ if (m_pResources->FindStaticSampler(AssignedSamplerAttribs, ResourceLayout) < 0)
{
- const auto& Sampler = GetResource<SamplerBindInfo>(AssignedSamplerIndex);
- if (strcmp(Sampler.Attribs.Name, AssignedSamplerAttribs.Name) == 0)
- break;
+ LOG_ERROR("Unable to find non-static sampler assigned to texture SRV '", TexSRV.Name, "'. This seems to be a bug.");
}
- VERIFY(AssignedSamplerIndex < NumSamplers, "Unable to find assigned sampler");
+#endif
+ }
+ else
+ {
+#ifdef _DEBUG
+ if (m_pResources->FindStaticSampler(AssignedSamplerAttribs, ResourceLayout) >= 0)
+ {
+ LOG_ERROR("Static sampler '", AssignedSamplerAttribs.Name, "' is assigned to texture SRV '", TexSRV.Name, "'. This seems to be a bug.");
+ }
+#endif
}
}
// Initialize tex SRV in place, increment counter of tex SRVs
- new (&GetResource<TexSRVBindInfo>(texSrv++)) TexSRVBindInfo( TexSRV, AssignedSamplerIndex, *this );
+ new (&GetResource<TexSRVBindInfo>(texSrv++)) TexSRVBindInfo(TexSRV, AssignedSamplerIndex, *this, VarType);
NumSRVSlots = std::max(NumSRVSlots, Uint32{TexSRV.BindPoint} + Uint32{TexSRV.BindCount});
},
[&](const D3DShaderResourceAttribs& TexUAV, Uint32)
{
- VERIFY_EXPR( TexUAV.IsAllowedType(AllowedTypeBits) );
-
- // Initialize tex UAV in place, increment counter of tex UAVs
- new (&GetResource<TexUAVBindInfo>(texUav++)) TexUAVBindInfo( TexUAV, *this );
- NumUAVSlots = std::max(NumUAVSlots, Uint32{TexUAV.BindPoint} + Uint32{TexUAV.BindCount});
+ auto VarType = m_pResources->FindVariableType(TexUAV, ResourceLayout);
+ if (IsAllowedType(VarType, AllowedTypeBits))
+ {
+ // Initialize tex UAV in place, increment counter of tex UAVs
+ new (&GetResource<TexUAVBindInfo>(texUav++)) TexUAVBindInfo(TexUAV, *this, VarType);
+ NumUAVSlots = std::max(NumUAVSlots, Uint32{TexUAV.BindPoint} + Uint32{TexUAV.BindCount});
+ }
},
[&](const D3DShaderResourceAttribs& BuffSRV, Uint32)
{
- VERIFY_EXPR(BuffSRV.IsAllowedType(AllowedTypeBits));
-
- // Initialize buff SRV in place, increment counter of buff SRVs
- new (&GetResource<BuffSRVBindInfo>(bufSrv++)) BuffSRVBindInfo( BuffSRV, *this );
- NumSRVSlots = std::max(NumSRVSlots, Uint32{BuffSRV.BindPoint} + Uint32{BuffSRV.BindCount});
+ auto VarType = m_pResources->FindVariableType(BuffSRV, ResourceLayout);
+ if (IsAllowedType(VarType, AllowedTypeBits))
+ {
+ // Initialize buff SRV in place, increment counter of buff SRVs
+ new (&GetResource<BuffSRVBindInfo>(bufSrv++)) BuffSRVBindInfo(BuffSRV, *this, VarType);
+ NumSRVSlots = std::max(NumSRVSlots, Uint32{BuffSRV.BindPoint} + Uint32{BuffSRV.BindCount});
+ }
},
[&](const D3DShaderResourceAttribs& BuffUAV, Uint32)
{
- VERIFY_EXPR(BuffUAV.IsAllowedType(AllowedTypeBits));
-
- // Initialize buff UAV in place, increment counter of buff UAVs
- new (&GetResource<BuffUAVBindInfo>(bufUav++)) BuffUAVBindInfo( BuffUAV, *this );
- NumUAVSlots = std::max(NumUAVSlots, Uint32{BuffUAV.BindPoint} + Uint32{BuffUAV.BindCount});
+ auto VarType = m_pResources->FindVariableType(BuffUAV, ResourceLayout);
+ if (IsAllowedType(VarType, AllowedTypeBits))
+ {
+ // Initialize buff UAV in place, increment counter of buff UAVs
+ new (&GetResource<BuffUAVBindInfo>(bufUav++)) BuffUAVBindInfo(BuffUAV, *this, VarType);
+ NumUAVSlots = std::max(NumUAVSlots, Uint32{BuffUAV.BindPoint} + Uint32{BuffUAV.BindCount});
+ }
}
);
@@ -250,21 +288,19 @@ void ShaderResourceLayoutD3D11::Initialize(std::shared_ptr<const ShaderResources // hold all variable types. The corresponding layout in the SRB is initialized to keep mutable and dynamic
// variables only
// http://diligentgraphics.com/diligent-engine/architecture/d3d11/shader-resource-cache#Shader-Resource-Cache-Initialization
- if (!m_pResourceCache->IsInitialized())
+ if (!m_ResourceCache.IsInitialized())
{
// NOTE that here we are using max bind points required to cache only the shader variables of allowed types!
- m_pResourceCache->Initialize(NumCBSlots, NumSRVSlots, NumSamplerSlots, NumUAVSlots, ResCacheDataAllocator);
+ m_ResourceCache.Initialize(NumCBSlots, NumSRVSlots, NumSamplerSlots, NumUAVSlots, ResCacheDataAllocator);
}
}
-void ShaderResourceLayoutD3D11::CopyResources(ShaderResourceCacheD3D11& DstCache)
+void ShaderResourceLayoutD3D11::CopyResources(ShaderResourceCacheD3D11& DstCache)const
{
- VERIFY(m_pResourceCache, "Resource cache must not be null");
-
- VERIFY( DstCache.GetCBCount() >= m_pResourceCache->GetCBCount(), "Dst cache is not large enough to contain all CBs" );
- VERIFY( DstCache.GetSRVCount() >= m_pResourceCache->GetSRVCount(), "Dst cache is not large enough to contain all SRVs" );
- VERIFY( DstCache.GetSamplerCount() >= m_pResourceCache->GetSamplerCount(), "Dst cache is not large enough to contain all samplers" );
- VERIFY( DstCache.GetUAVCount() >= m_pResourceCache->GetUAVCount(), "Dst cache is not large enough to contain all UAVs" );
+ VERIFY( DstCache.GetCBCount() >= m_ResourceCache.GetCBCount(), "Dst cache is not large enough to contain all CBs" );
+ VERIFY( DstCache.GetSRVCount() >= m_ResourceCache.GetSRVCount(), "Dst cache is not large enough to contain all SRVs" );
+ VERIFY( DstCache.GetSamplerCount() >= m_ResourceCache.GetSamplerCount(), "Dst cache is not large enough to contain all samplers" );
+ VERIFY( DstCache.GetUAVCount() >= m_ResourceCache.GetUAVCount(), "Dst cache is not large enough to contain all UAVs" );
ShaderResourceCacheD3D11::CachedCB* CachedCBs = nullptr;
ID3D11Buffer** d3d11CBs = nullptr;
@@ -274,10 +310,10 @@ void ShaderResourceLayoutD3D11::CopyResources(ShaderResourceCacheD3D11& DstCache ID3D11SamplerState** d3d11Samplers = nullptr;
ShaderResourceCacheD3D11::CachedResource* CachedUAVResources = nullptr;
ID3D11UnorderedAccessView** d3d11UAVs = nullptr;
- m_pResourceCache->GetCBArrays (CachedCBs, d3d11CBs);
- m_pResourceCache->GetSRVArrays (CachedSRVResources, d3d11SRVs);
- m_pResourceCache->GetSamplerArrays(CachedSamplers, d3d11Samplers);
- m_pResourceCache->GetUAVArrays (CachedUAVResources, d3d11UAVs);
+ m_ResourceCache.GetCBArrays (CachedCBs, d3d11CBs);
+ m_ResourceCache.GetSRVArrays (CachedSRVResources, d3d11SRVs);
+ m_ResourceCache.GetSamplerArrays(CachedSamplers, d3d11Samplers);
+ m_ResourceCache.GetUAVArrays (CachedUAVResources, d3d11UAVs);
ShaderResourceCacheD3D11::CachedCB* DstCBs = nullptr;
@@ -293,12 +329,12 @@ void ShaderResourceLayoutD3D11::CopyResources(ShaderResourceCacheD3D11& DstCache DstCache.GetSamplerArrays(DstSamplers, DstD3D11Samplers);
DstCache.GetUAVArrays (DstUAVResources, DstD3D11UAVs);
- HandleResources(
+ HandleConstResources(
[&](const ConstBuffBindInfo& cb)
{
- for(auto CBSlot = cb.Attribs.BindPoint; CBSlot < cb.Attribs.BindPoint+cb.Attribs.BindCount; ++CBSlot)
+ for (auto CBSlot = cb.m_Attribs.BindPoint; CBSlot < cb.m_Attribs.BindPoint+cb.m_Attribs.BindCount; ++CBSlot)
{
- VERIFY_EXPR(CBSlot < m_pResourceCache->GetCBCount() && CBSlot < DstCache.GetCBCount());
+ VERIFY_EXPR(CBSlot < m_ResourceCache.GetCBCount() && CBSlot < DstCache.GetCBCount());
DstCBs [CBSlot] = CachedCBs[CBSlot];
DstD3D11CBs[CBSlot] = d3d11CBs [CBSlot];
}
@@ -306,9 +342,9 @@ void ShaderResourceLayoutD3D11::CopyResources(ShaderResourceCacheD3D11& DstCache [&](const TexSRVBindInfo& ts)
{
- for(auto SRVSlot = ts.Attribs.BindPoint; SRVSlot < ts.Attribs.BindPoint + ts.Attribs.BindCount; ++SRVSlot)
+ for (auto SRVSlot = ts.m_Attribs.BindPoint; SRVSlot < ts.m_Attribs.BindPoint + ts.m_Attribs.BindCount; ++SRVSlot)
{
- VERIFY_EXPR(SRVSlot < m_pResourceCache->GetSRVCount() && SRVSlot < DstCache.GetSRVCount());
+ VERIFY_EXPR(SRVSlot < m_ResourceCache.GetSRVCount() && SRVSlot < DstCache.GetSRVCount());
DstSRVResources[SRVSlot] = CachedSRVResources[SRVSlot];
DstD3D11SRVs [SRVSlot] = d3d11SRVs [SRVSlot];
}
@@ -316,9 +352,9 @@ void ShaderResourceLayoutD3D11::CopyResources(ShaderResourceCacheD3D11& DstCache [&](const TexUAVBindInfo& uav)
{
- for(auto UAVSlot = uav.Attribs.BindPoint; UAVSlot < uav.Attribs.BindPoint + uav.Attribs.BindCount; ++UAVSlot)
+ for (auto UAVSlot = uav.m_Attribs.BindPoint; UAVSlot < uav.m_Attribs.BindPoint + uav.m_Attribs.BindCount; ++UAVSlot)
{
- VERIFY_EXPR(UAVSlot < m_pResourceCache->GetUAVCount() && UAVSlot < DstCache.GetUAVCount());
+ VERIFY_EXPR(UAVSlot < m_ResourceCache.GetUAVCount() && UAVSlot < DstCache.GetUAVCount());
DstUAVResources[UAVSlot] = CachedUAVResources[UAVSlot];
DstD3D11UAVs [UAVSlot] = d3d11UAVs [UAVSlot];
}
@@ -326,9 +362,9 @@ void ShaderResourceLayoutD3D11::CopyResources(ShaderResourceCacheD3D11& DstCache [&](const BuffSRVBindInfo& srv)
{
- for(auto SRVSlot = srv.Attribs.BindPoint; SRVSlot < srv.Attribs.BindPoint + srv.Attribs.BindCount; ++SRVSlot)
+ for (auto SRVSlot = srv.m_Attribs.BindPoint; SRVSlot < srv.m_Attribs.BindPoint + srv.m_Attribs.BindCount; ++SRVSlot)
{
- VERIFY_EXPR(SRVSlot < m_pResourceCache->GetSRVCount() && SRVSlot < DstCache.GetSRVCount());
+ VERIFY_EXPR(SRVSlot < m_ResourceCache.GetSRVCount() && SRVSlot < DstCache.GetSRVCount());
DstSRVResources[SRVSlot] = CachedSRVResources[SRVSlot];
DstD3D11SRVs [SRVSlot] = d3d11SRVs [SRVSlot];
}
@@ -336,9 +372,9 @@ void ShaderResourceLayoutD3D11::CopyResources(ShaderResourceCacheD3D11& DstCache [&](const BuffUAVBindInfo& uav)
{
- for(auto UAVSlot = uav.Attribs.BindPoint; UAVSlot < uav.Attribs.BindPoint + uav.Attribs.BindCount; ++UAVSlot)
+ for (auto UAVSlot = uav.m_Attribs.BindPoint; UAVSlot < uav.m_Attribs.BindPoint + uav.m_Attribs.BindCount; ++UAVSlot)
{
- VERIFY_EXPR(UAVSlot < m_pResourceCache->GetUAVCount() && UAVSlot < DstCache.GetUAVCount());
+ VERIFY_EXPR(UAVSlot < m_ResourceCache.GetUAVCount() && UAVSlot < DstCache.GetUAVCount());
DstUAVResources[UAVSlot] = CachedUAVResources[UAVSlot];
DstD3D11UAVs [UAVSlot] = d3d11UAVs [UAVSlot];
}
@@ -346,10 +382,10 @@ void ShaderResourceLayoutD3D11::CopyResources(ShaderResourceCacheD3D11& DstCache [&](const SamplerBindInfo& sam)
{
- VERIFY(!sam.Attribs.IsStaticSampler(), "Variables are not created for static samplers");
- for(auto SamSlot = sam.Attribs.BindPoint; SamSlot < sam.Attribs.BindPoint + sam.Attribs.BindCount; ++SamSlot)
+ //VERIFY(!sam.IsStaticSampler, "Variables are not created for static samplers");
+ for (auto SamSlot = sam.m_Attribs.BindPoint; SamSlot < sam.m_Attribs.BindPoint + sam.m_Attribs.BindCount; ++SamSlot)
{
- VERIFY_EXPR(SamSlot < m_pResourceCache->GetSamplerCount() && SamSlot < DstCache.GetSamplerCount());
+ VERIFY_EXPR(SamSlot < m_ResourceCache.GetSamplerCount() && SamSlot < DstCache.GetSamplerCount());
DstSamplers [SamSlot] = CachedSamplers[SamSlot];
DstD3D11Samplers[SamSlot] = d3d11Samplers [SamSlot];
}
@@ -360,7 +396,7 @@ void ShaderResourceLayoutD3D11::CopyResources(ShaderResourceCacheD3D11& DstCache #define LOG_RESOURCE_BINDING_ERROR(ResType, pResource, Attribs, ArrayInd, ShaderName, ...)\
do{ \
const auto* ResName = pResource->GetDesc().Name; \
- if(Attribs.BindCount>1) \
+ if (Attribs.BindCount>1) \
LOG_ERROR_MESSAGE( "Failed to bind ", ResType, " '", ResName, "' to variable '", Attribs.Name,\
"[", ArrayInd, "]' in shader '", ShaderName, "'. ", __VA_ARGS__ ); \
else \
@@ -371,46 +407,42 @@ do{ void ShaderResourceLayoutD3D11::ConstBuffBindInfo::BindResource(IDeviceObject* pBuffer,
Uint32 ArrayIndex)
{
- VERIFY(m_ParentResLayout.m_pResourceCache != nullptr, "Resource cache is null");
- DEV_CHECK_ERR(ArrayIndex < Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", Attribs.Name, "'. Max allowed index: ", Attribs.BindCount);
- auto& ResourceCache = *m_ParentResLayout.m_pResourceCache;
+ DEV_CHECK_ERR(ArrayIndex < m_Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", m_Attribs.Name, "'. Max allowed index: ", m_Attribs.BindCount);
+ auto& ResourceCache = m_ParentResLayout.m_ResourceCache;
// We cannot use ValidatedCast<> here as the resource retrieved from the
// resource mapping can be of wrong type
RefCntAutoPtr<BufferD3D11Impl> pBuffD3D11Impl(pBuffer, IID_BufferD3D11);
#ifdef DEVELOPMENT
if (pBuffer && !pBuffD3D11Impl)
- LOG_RESOURCE_BINDING_ERROR("buffer", pBuffer, Attribs, ArrayIndex, m_ParentResLayout.GetShaderName(), "Incorrect resource type: buffer is expected.");
+ LOG_RESOURCE_BINDING_ERROR("buffer", pBuffer, m_Attribs, ArrayIndex, m_ParentResLayout.GetShaderName(), "Incorrect resource type: buffer is expected.");
if (pBuffD3D11Impl && (pBuffD3D11Impl->GetDesc().BindFlags & BIND_UNIFORM_BUFFER) == 0)
{
- LOG_RESOURCE_BINDING_ERROR("buffer", pBuffer, Attribs, ArrayIndex, m_ParentResLayout.GetShaderName(), "Buffer was not created with BIND_UNIFORM_BUFFER flag.");
+ LOG_RESOURCE_BINDING_ERROR("buffer", pBuffer, m_Attribs, ArrayIndex, m_ParentResLayout.GetShaderName(), "Buffer was not created with BIND_UNIFORM_BUFFER flag.");
pBuffD3D11Impl.Release();
}
- if (Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC)
+ if (GetType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC)
{
- auto& CachedCB = ResourceCache.GetCB(Attribs.BindPoint + ArrayIndex);
+ auto& CachedCB = ResourceCache.GetCB(m_Attribs.BindPoint + ArrayIndex);
if (CachedCB.pBuff != nullptr && CachedCB.pBuff != pBuffD3D11Impl)
{
- auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType());
- LOG_ERROR_MESSAGE( "Non-null constant buffer is already bound to ", VarTypeStr, " shader variable '", Attribs.GetPrintName(ArrayIndex), "' in shader '", m_ParentResLayout.GetShaderName(), "'. Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." );
+ auto VarTypeStr = GetShaderVariableTypeLiteralName(GetType());
+ LOG_ERROR_MESSAGE( "Non-null constant buffer is already bound to ", VarTypeStr, " shader variable '", m_Attribs.GetPrintName(ArrayIndex), "' in shader '", m_ParentResLayout.GetShaderName(), "'. Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." );
}
}
#endif
- ResourceCache.SetCB(Attribs.BindPoint + ArrayIndex, std::move(pBuffD3D11Impl) );
+ ResourceCache.SetCB(m_Attribs.BindPoint + ArrayIndex, std::move(pBuffD3D11Impl) );
}
-bool ShaderResourceLayoutD3D11::ConstBuffBindInfo::IsBound(Uint32 ArrayIndex)
+bool ShaderResourceLayoutD3D11::ConstBuffBindInfo::IsBound(Uint32 ArrayIndex)const
{
- auto* pResourceCache = m_ParentResLayout.m_pResourceCache;
- VERIFY(pResourceCache, "Resource cache is null");
- VERIFY_EXPR(ArrayIndex < Attribs.BindCount);
-
- return pResourceCache->IsCBBound(Attribs.BindPoint + ArrayIndex);
+ VERIFY_EXPR(ArrayIndex < m_Attribs.BindCount);
+ return m_ParentResLayout.m_ResourceCache.IsCBBound(m_Attribs.BindPoint + ArrayIndex);
}
@@ -445,26 +477,25 @@ bool dbgVerifyViewType( const char* ViewTypeName, void ShaderResourceLayoutD3D11::TexSRVBindInfo::BindResource(IDeviceObject* pView,
Uint32 ArrayIndex)
{
- VERIFY(m_ParentResLayout.m_pResourceCache, "Resource cache is null");
- DEV_CHECK_ERR(ArrayIndex < Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", Attribs.Name, "'. Max allowed index: ", Attribs.BindCount);
- auto& ResourceCache = *m_ParentResLayout.m_pResourceCache;
+ DEV_CHECK_ERR(ArrayIndex < m_Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", m_Attribs.Name, "'. Max allowed index: ", m_Attribs.BindCount);
+ auto& ResourceCache = m_ParentResLayout.m_ResourceCache;
// We cannot use ValidatedCast<> here as the resource retrieved from the
// resource mapping can be of wrong type
RefCntAutoPtr<TextureViewD3D11Impl> pViewD3D11(pView, IID_TextureViewD3D11);
#ifdef DEVELOPMENT
if (pView && !pViewD3D11)
- LOG_RESOURCE_BINDING_ERROR("resource", pView, Attribs, ArrayIndex, m_ParentResLayout.GetShaderName(), "Incorect resource type: texture view is expected.");
- if (pViewD3D11 && !dbgVerifyViewType("texture view", pViewD3D11.RawPtr(), Attribs, ArrayIndex, TEXTURE_VIEW_SHADER_RESOURCE, m_ParentResLayout.GetShaderName()))
+ LOG_RESOURCE_BINDING_ERROR("resource", pView, m_Attribs, ArrayIndex, m_ParentResLayout.GetShaderName(), "Incorect resource type: texture view is expected.");
+ if (pViewD3D11 && !dbgVerifyViewType("texture view", pViewD3D11.RawPtr(), m_Attribs, ArrayIndex, TEXTURE_VIEW_SHADER_RESOURCE, m_ParentResLayout.GetShaderName()))
pViewD3D11.Release();
- if( Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC)
+ if( GetType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC)
{
- auto& CachedSRV = ResourceCache.GetSRV(Attribs.BindPoint + ArrayIndex);
+ auto& CachedSRV = ResourceCache.GetSRV(m_Attribs.BindPoint + ArrayIndex);
if (CachedSRV.pView != nullptr && CachedSRV.pView != pViewD3D11)
{
- auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType());
- LOG_ERROR_MESSAGE( "Non-null texture SRV is already bound to ", VarTypeStr, " shader variable '", Attribs.GetPrintName(ArrayIndex), "' in shader '", m_ParentResLayout.GetShaderName(), "'. Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." );
+ auto VarTypeStr = GetShaderVariableTypeLiteralName(GetType());
+ LOG_ERROR_MESSAGE( "Non-null texture SRV is already bound to ", VarTypeStr, " shader variable '", m_Attribs.GetPrintName(ArrayIndex), "' in shader '", m_ParentResLayout.GetShaderName(), "'. Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." );
}
}
#endif
@@ -472,9 +503,9 @@ void ShaderResourceLayoutD3D11::TexSRVBindInfo::BindResource(IDeviceObject* pVie if (ValidSamplerAssigned())
{
auto& Sampler = m_ParentResLayout.GetResource<SamplerBindInfo>(SamplerIndex);
- VERIFY(!Sampler.Attribs.IsStaticSampler(), "Static samplers are not assigned to texture SRVs as they are initialized directly in the shader resource cache");
- VERIFY_EXPR(Sampler.Attribs.BindCount == Attribs.BindCount || Sampler.Attribs.BindCount == 1);
- auto SamplerBindPoint = Sampler.Attribs.BindPoint + (Sampler.Attribs.BindCount != 1 ? ArrayIndex : 0);
+ //VERIFY(!Sampler.IsStaticSampler, "Static samplers are not assigned to texture SRVs as they are initialized directly in the shader resource cache");
+ VERIFY_EXPR(Sampler.m_Attribs.BindCount == m_Attribs.BindCount || Sampler.m_Attribs.BindCount == 1);
+ auto SamplerBindPoint = Sampler.m_Attribs.BindPoint + (Sampler.m_Attribs.BindCount != 1 ? ArrayIndex : 0);
SamplerD3D11Impl* pSamplerD3D11Impl = nullptr;
if (pViewD3D11)
@@ -483,37 +514,36 @@ void ShaderResourceLayoutD3D11::TexSRVBindInfo::BindResource(IDeviceObject* pVie #ifdef DEVELOPMENT
if (pSamplerD3D11Impl == nullptr)
{
- if(Sampler.Attribs.BindCount > 1)
- LOG_ERROR_MESSAGE( "Failed to bind sampler to variable '", Sampler.Attribs.Name, "[", ArrayIndex,"]'. Sampler is not set in the texture view '", pViewD3D11->GetDesc().Name, "'" );
+ if(Sampler.m_Attribs.BindCount > 1)
+ LOG_ERROR_MESSAGE( "Failed to bind sampler to variable '", Sampler.m_Attribs.Name, "[", ArrayIndex,"]'. Sampler is not set in the texture view '", pViewD3D11->GetDesc().Name, "'" );
else
- LOG_ERROR_MESSAGE( "Failed to bind sampler to variable '", Sampler.Attribs.Name, "'. Sampler is not set in the texture view '", pViewD3D11->GetDesc().Name, "'" );
+ LOG_ERROR_MESSAGE( "Failed to bind sampler to variable '", Sampler.m_Attribs.Name, "'. Sampler is not set in the texture view '", pViewD3D11->GetDesc().Name, "'" );
}
#endif
}
#ifdef DEVELOPMENT
- if (Sampler.Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC)
+ if (Sampler.GetType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC)
{
auto& CachedSampler = ResourceCache.GetSampler(SamplerBindPoint);
if (CachedSampler.pSampler != nullptr && CachedSampler.pSampler != pSamplerD3D11Impl)
{
- auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType());
- LOG_ERROR_MESSAGE( "Non-null sampler is already bound to ", VarTypeStr, " shader variable '", Sampler.Attribs.GetPrintName(ArrayIndex), "' in shader '", m_ParentResLayout.GetShaderName(), "'. Attempting to bind another sampler or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." );
+ auto VarTypeStr = GetShaderVariableTypeLiteralName(GetType());
+ LOG_ERROR_MESSAGE( "Non-null sampler is already bound to ", VarTypeStr, " shader variable '", Sampler.m_Attribs.GetPrintName(ArrayIndex), "' in shader '", m_ParentResLayout.GetShaderName(), "'. Attempting to bind another sampler or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." );
}
}
#endif
ResourceCache.SetSampler(SamplerBindPoint, pSamplerD3D11Impl);
}
- ResourceCache.SetTexSRV(Attribs.BindPoint + ArrayIndex, std::move(pViewD3D11));
+ ResourceCache.SetTexSRV(m_Attribs.BindPoint + ArrayIndex, std::move(pViewD3D11));
}
void ShaderResourceLayoutD3D11::SamplerBindInfo::BindResource(IDeviceObject* pSampler,
Uint32 ArrayIndex)
{
- VERIFY(m_ParentResLayout.m_pResourceCache != nullptr, "Resource cache is null");
- DEV_CHECK_ERR(ArrayIndex < Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", Attribs.Name, "'. Max allowed index: ", Attribs.BindCount);
- auto& ResourceCache = *m_ParentResLayout.m_pResourceCache;
- VERIFY(!Attribs.IsStaticSampler(), "Cannot bind sampler to a static sampler");
+ DEV_CHECK_ERR(ArrayIndex < m_Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", m_Attribs.Name, "'. Max allowed index: ", m_Attribs.BindCount);
+ auto& ResourceCache = m_ParentResLayout.m_ResourceCache;
+ //VERIFY(!IsStaticSampler, "Cannot bind sampler to a static sampler");
// We cannot use ValidatedCast<> here as the resource retrieved from the
// resource mapping can be of wrong type
@@ -521,165 +551,147 @@ void ShaderResourceLayoutD3D11::SamplerBindInfo::BindResource(IDeviceObject* pSa #ifdef DEVELOPMENT
if (pSampler && !pSamplerD3D11)
- LOG_RESOURCE_BINDING_ERROR("sampler", pSampler, Attribs, ArrayIndex, m_ParentResLayout.GetShaderName(), "Incorect resource type: sampler is expected.");
+ LOG_RESOURCE_BINDING_ERROR("sampler", pSampler, m_Attribs, ArrayIndex, m_ParentResLayout.GetShaderName(), "Incorect resource type: sampler is expected.");
- if (Attribs.ValidTexSRVAssigned())
+ if (m_Attribs.IsCombinedWithTexSRV())
{
- auto* TexSRVName = m_ParentResLayout.m_pResources->GetTexSRV(Attribs.GetTexSRVId()).Name;
- LOG_WARNING_MESSAGE("Texture sampler sampler '", Attribs.Name, "' is assigned to texture SRV '", TexSRVName, "' and should not be accessed directly. The sampler is initialized when texture SRV is set to '", TexSRVName, "' variable.");
+ auto* TexSRVName = m_ParentResLayout.m_pResources->GetCombinedTextureSRV(m_Attribs).Name;
+ LOG_WARNING_MESSAGE("Texture sampler sampler '", m_Attribs.Name, "' is assigned to texture SRV '", TexSRVName, "' and should not be accessed directly. The sampler is initialized when texture SRV is set to '", TexSRVName, "' variable.");
}
- if (Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC)
+ if (GetType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC)
{
- auto& CachedSampler = ResourceCache.GetSampler(Attribs.BindPoint + ArrayIndex);
+ auto& CachedSampler = ResourceCache.GetSampler(m_Attribs.BindPoint + ArrayIndex);
if( CachedSampler.pSampler != nullptr && CachedSampler.pSampler != pSamplerD3D11)
{
- auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType());
- LOG_ERROR_MESSAGE( "Non-null sampler is already bound to ", VarTypeStr, " shader variable '", Attribs.GetPrintName(ArrayIndex), "' in shader '", m_ParentResLayout.GetShaderName(), "'. Attempting to bind another sampler or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." );
+ auto VarTypeStr = GetShaderVariableTypeLiteralName(GetType());
+ LOG_ERROR_MESSAGE( "Non-null sampler is already bound to ", VarTypeStr, " shader variable '", m_Attribs.GetPrintName(ArrayIndex), "' in shader '", m_ParentResLayout.GetShaderName(), "'. Attempting to bind another sampler or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." );
}
}
#endif
- ResourceCache.SetSampler(Attribs.BindPoint + ArrayIndex, std::move(pSamplerD3D11));
+ ResourceCache.SetSampler(m_Attribs.BindPoint + ArrayIndex, std::move(pSamplerD3D11));
}
void ShaderResourceLayoutD3D11::BuffSRVBindInfo::BindResource(IDeviceObject* pView,
Uint32 ArrayIndex)
{
- VERIFY(m_ParentResLayout.m_pResourceCache != nullptr, "Resource cache is null");
- DEV_CHECK_ERR(ArrayIndex < Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", Attribs.Name, "'. Max allowed index: ", Attribs.BindCount);
- auto& ResourceCache = *m_ParentResLayout.m_pResourceCache;
+ DEV_CHECK_ERR(ArrayIndex < m_Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", m_Attribs.Name, "'. Max allowed index: ", m_Attribs.BindCount);
+ auto& ResourceCache = m_ParentResLayout.m_ResourceCache;
// We cannot use ValidatedCast<> here as the resource retrieved from the
// resource mapping can be of wrong type
RefCntAutoPtr<BufferViewD3D11Impl> pViewD3D11(pView, IID_BufferViewD3D11);
#ifdef DEVELOPMENT
if (pView && !pViewD3D11)
- LOG_RESOURCE_BINDING_ERROR("resource", pView, Attribs, ArrayIndex, m_ParentResLayout.GetShaderName(), "Incorect resource type: buffer view is expected.");
- if (pViewD3D11 && !dbgVerifyViewType("buffer view", pViewD3D11.RawPtr(), Attribs, ArrayIndex, BUFFER_VIEW_SHADER_RESOURCE, m_ParentResLayout.GetShaderName()))
+ LOG_RESOURCE_BINDING_ERROR("resource", pView, m_Attribs, ArrayIndex, m_ParentResLayout.GetShaderName(), "Incorect resource type: buffer view is expected.");
+ if (pViewD3D11 && !dbgVerifyViewType("buffer view", pViewD3D11.RawPtr(), m_Attribs, ArrayIndex, BUFFER_VIEW_SHADER_RESOURCE, m_ParentResLayout.GetShaderName()))
pViewD3D11.Release();
- if (Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC)
+ if (GetType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC)
{
- auto& CachedSRV = ResourceCache.GetSRV(Attribs.BindPoint + ArrayIndex);
+ auto& CachedSRV = ResourceCache.GetSRV(m_Attribs.BindPoint + ArrayIndex);
if (CachedSRV.pView != nullptr && CachedSRV.pView != pViewD3D11)
{
- auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType());
- LOG_ERROR_MESSAGE( "Non-null buffer SRV is already bound to ", VarTypeStr, " shader variable '", Attribs.GetPrintName(ArrayIndex), "' in shader '", m_ParentResLayout.GetShaderName(), "'. Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." );
+ auto VarTypeStr = GetShaderVariableTypeLiteralName(GetType());
+ LOG_ERROR_MESSAGE( "Non-null buffer SRV is already bound to ", VarTypeStr, " shader variable '", m_Attribs.GetPrintName(ArrayIndex), "' in shader '", m_ParentResLayout.GetShaderName(), "'. Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." );
}
}
#endif
- ResourceCache.SetBufSRV(Attribs.BindPoint + ArrayIndex, std::move(pViewD3D11));
+ ResourceCache.SetBufSRV(m_Attribs.BindPoint + ArrayIndex, std::move(pViewD3D11));
}
void ShaderResourceLayoutD3D11::TexUAVBindInfo::BindResource(IDeviceObject* pView,
Uint32 ArrayIndex)
{
- VERIFY(m_ParentResLayout.m_pResourceCache != nullptr, "Resource cache is null");
- DEV_CHECK_ERR(ArrayIndex < Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", Attribs.Name, "'. Max allowed index: ", Attribs.BindCount);
- auto& ResourceCache = *m_ParentResLayout.m_pResourceCache;
+ DEV_CHECK_ERR(ArrayIndex < m_Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", m_Attribs.Name, "'. Max allowed index: ", m_Attribs.BindCount);
+ auto& ResourceCache = m_ParentResLayout.m_ResourceCache;
// We cannot use ValidatedCast<> here as the resource retrieved from the
// resource mapping can be of wrong type
RefCntAutoPtr<TextureViewD3D11Impl> pViewD3D11(pView, IID_TextureViewD3D11);
#ifdef DEVELOPMENT
if (pView && !pViewD3D11)
- LOG_RESOURCE_BINDING_ERROR("resource", pView, Attribs, ArrayIndex, m_ParentResLayout.GetShaderName(), "Incorect resource type: texture view is expected.");
- if (pViewD3D11 && !dbgVerifyViewType("texture view", pViewD3D11.RawPtr(), Attribs, ArrayIndex, TEXTURE_VIEW_UNORDERED_ACCESS, m_ParentResLayout.GetShaderName()))
+ LOG_RESOURCE_BINDING_ERROR("resource", pView, m_Attribs, ArrayIndex, m_ParentResLayout.GetShaderName(), "Incorect resource type: texture view is expected.");
+ if (pViewD3D11 && !dbgVerifyViewType("texture view", pViewD3D11.RawPtr(), m_Attribs, ArrayIndex, TEXTURE_VIEW_UNORDERED_ACCESS, m_ParentResLayout.GetShaderName()))
pViewD3D11.Release();
- if (Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC)
+ if (GetType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC)
{
- auto& CachedUAV = ResourceCache.GetUAV(Attribs.BindPoint + ArrayIndex);
+ auto& CachedUAV = ResourceCache.GetUAV(m_Attribs.BindPoint + ArrayIndex);
if (CachedUAV.pView != nullptr && CachedUAV.pView != pViewD3D11)
{
- auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType());
- LOG_ERROR_MESSAGE( "Non-null texture UAV is already bound to ", VarTypeStr, " shader variable '", Attribs.GetPrintName(ArrayIndex), "' in shader '", m_ParentResLayout.GetShaderName(), "'. Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." );
+ auto VarTypeStr = GetShaderVariableTypeLiteralName(GetType());
+ LOG_ERROR_MESSAGE( "Non-null texture UAV is already bound to ", VarTypeStr, " shader variable '", m_Attribs.GetPrintName(ArrayIndex), "' in shader '", m_ParentResLayout.GetShaderName(), "'. Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." );
}
}
#endif
- ResourceCache.SetTexUAV(Attribs.BindPoint + ArrayIndex, std::move(pViewD3D11));
+ ResourceCache.SetTexUAV(m_Attribs.BindPoint + ArrayIndex, std::move(pViewD3D11));
}
void ShaderResourceLayoutD3D11::BuffUAVBindInfo::BindResource(IDeviceObject* pView,
Uint32 ArrayIndex)
{
- VERIFY(m_ParentResLayout.m_pResourceCache != nullptr, "Resource cache is null");
- DEV_CHECK_ERR(ArrayIndex < Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", Attribs.Name, "'. Max allowed index: ", Attribs.BindCount);
- auto& ResourceCache = *m_ParentResLayout.m_pResourceCache;
+ DEV_CHECK_ERR(ArrayIndex < m_Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", m_Attribs.Name, "'. Max allowed index: ", m_Attribs.BindCount);
+ auto& ResourceCache = m_ParentResLayout.m_ResourceCache;
// We cannot use ValidatedCast<> here as the resource retrieved from the
// resource mapping can be of wrong type
RefCntAutoPtr<BufferViewD3D11Impl> pViewD3D11(pView, IID_BufferViewD3D11);
#ifdef DEVELOPMENT
if (pView && !pViewD3D11)
- LOG_RESOURCE_BINDING_ERROR("resource", pView, Attribs, ArrayIndex, m_ParentResLayout.GetShaderName(), "Incorect resource type: buffer view is expected.");
- if (pViewD3D11 && !dbgVerifyViewType("buffer view", pViewD3D11.RawPtr(), Attribs, ArrayIndex, BUFFER_VIEW_UNORDERED_ACCESS, m_ParentResLayout.GetShaderName()) )
+ LOG_RESOURCE_BINDING_ERROR("resource", pView, m_Attribs, ArrayIndex, m_ParentResLayout.GetShaderName(), "Incorect resource type: buffer view is expected.");
+ if (pViewD3D11 && !dbgVerifyViewType("buffer view", pViewD3D11.RawPtr(), m_Attribs, ArrayIndex, BUFFER_VIEW_UNORDERED_ACCESS, m_ParentResLayout.GetShaderName()) )
pViewD3D11.Release();
- if (Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC)
+ if (GetType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC)
{
- auto& CachedUAV = ResourceCache.GetUAV(Attribs.BindPoint + ArrayIndex);
+ auto& CachedUAV = ResourceCache.GetUAV(m_Attribs.BindPoint + ArrayIndex);
if (CachedUAV.pView != nullptr && CachedUAV.pView != pViewD3D11)
{
- auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType());
- LOG_ERROR_MESSAGE( "Non-null buffer UAV is already bound to ", VarTypeStr, " shader variable '", Attribs.GetPrintName(ArrayIndex), "' in shader '", m_ParentResLayout.GetShaderName(), "'. Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." );
+ auto VarTypeStr = GetShaderVariableTypeLiteralName(GetType());
+ LOG_ERROR_MESSAGE( "Non-null buffer UAV is already bound to ", VarTypeStr, " shader variable '", m_Attribs.GetPrintName(ArrayIndex), "' in shader '", m_ParentResLayout.GetShaderName(), "'. Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." );
}
}
#endif
- ResourceCache.SetBufUAV(Attribs.BindPoint + ArrayIndex, std::move(pViewD3D11));
+ ResourceCache.SetBufUAV(m_Attribs.BindPoint + ArrayIndex, std::move(pViewD3D11));
}
bool ShaderResourceLayoutD3D11::TexSRVBindInfo::IsBound(Uint32 ArrayIndex)const
{
- auto* pResourceCache = m_ParentResLayout.m_pResourceCache;
- VERIFY(pResourceCache != nullptr, "Resource cache is null");
- VERIFY_EXPR(ArrayIndex < Attribs.BindCount);
-
- return pResourceCache->IsSRVBound(Attribs.BindPoint + ArrayIndex, true);
+ VERIFY_EXPR(ArrayIndex < m_Attribs.BindCount);
+ return m_ParentResLayout.m_ResourceCache.IsSRVBound(m_Attribs.BindPoint + ArrayIndex, true);
}
bool ShaderResourceLayoutD3D11::BuffSRVBindInfo::IsBound(Uint32 ArrayIndex)const
{
- auto* pResourceCache = m_ParentResLayout.m_pResourceCache;
- VERIFY(pResourceCache, "Resource cache is null");
- VERIFY_EXPR(ArrayIndex < Attribs.BindCount);
-
- return pResourceCache->IsSRVBound(Attribs.BindPoint + ArrayIndex, false);
+ VERIFY_EXPR(ArrayIndex < m_Attribs.BindCount);
+ return m_ParentResLayout.m_ResourceCache.IsSRVBound(m_Attribs.BindPoint + ArrayIndex, false);
}
bool ShaderResourceLayoutD3D11::TexUAVBindInfo::IsBound(Uint32 ArrayIndex)const
{
- auto* pResourceCache = m_ParentResLayout.m_pResourceCache;
- VERIFY(pResourceCache, "Resource cache is null");
- VERIFY_EXPR(ArrayIndex < Attribs.BindCount);
-
- return pResourceCache->IsUAVBound(Attribs.BindPoint + ArrayIndex, true);
+ VERIFY_EXPR(ArrayIndex < m_Attribs.BindCount);
+ return m_ParentResLayout.m_ResourceCache.IsUAVBound(m_Attribs.BindPoint + ArrayIndex, true);
}
bool ShaderResourceLayoutD3D11::BuffUAVBindInfo::IsBound(Uint32 ArrayIndex)const
{
- auto* pResourceCache = m_ParentResLayout.m_pResourceCache;
- VERIFY(pResourceCache, "Resource cache is null");
- VERIFY_EXPR(ArrayIndex < Attribs.BindCount);
-
- return pResourceCache->IsUAVBound(Attribs.BindPoint + ArrayIndex, false);
+ VERIFY_EXPR(ArrayIndex < m_Attribs.BindCount);
+ return m_ParentResLayout.m_ResourceCache.IsUAVBound(m_Attribs.BindPoint + ArrayIndex, false);
}
bool ShaderResourceLayoutD3D11::SamplerBindInfo::IsBound(Uint32 ArrayIndex)const
{
- auto* pResourceCache = m_ParentResLayout.m_pResourceCache;
- VERIFY(pResourceCache, "Resource cache is null");
- VERIFY_EXPR(ArrayIndex < Attribs.BindCount);
-
- return pResourceCache->IsSamplerBound(Attribs.BindPoint + ArrayIndex);
+ VERIFY_EXPR(ArrayIndex < m_Attribs.BindCount);
+ return m_ParentResLayout.m_ResourceCache.IsSamplerBound(m_Attribs.BindPoint + ArrayIndex);
}
@@ -695,17 +707,17 @@ public: }
template<typename ResourceType>
- void Bind( ResourceType &Res)
+ void Bind( ResourceType& Res)
{
- if ( (Flags & (1 << Res.Attribs.GetVariableType())) == 0 )
+ if ( (Flags & (1 << Res.GetType())) == 0 )
return;
- for (Uint16 elem=0; elem < Res.Attribs.BindCount; ++elem)
+ for (Uint16 elem=0; elem < Res.m_Attribs.BindCount; ++elem)
{
if ( (Flags & BIND_SHADER_RESOURCES_KEEP_EXISTING) && Res.IsBound(elem) )
continue;
- const auto* VarName = Res.Attribs.Name;
+ const auto* VarName = Res.m_Attribs.Name;
RefCntAutoPtr<IDeviceObject> pRes;
ResourceMapping.GetResource( VarName, &pRes, elem );
if (pRes)
@@ -728,7 +740,7 @@ private: void ShaderResourceLayoutD3D11::BindResources( IResourceMapping* pResourceMapping, Uint32 Flags, const ShaderResourceCacheD3D11& dbgResourceCache )
{
- VERIFY(&dbgResourceCache == m_pResourceCache, "Resource cache does not match the cache provided at initialization");
+ VERIFY(&dbgResourceCache == &m_ResourceCache, "Resource cache does not match the cache provided at initialization");
if (pResourceMapping == nullptr)
{
@@ -776,39 +788,40 @@ void ShaderResourceLayoutD3D11::BindResources( IResourceMapping* pResourceMappin }
template<typename ResourceType>
-IShaderVariable* ShaderResourceLayoutD3D11::GetResourceByName( const Char* Name )
+IShaderResourceVariable* ShaderResourceLayoutD3D11::GetResourceByName( const Char* Name )
{
auto NumResources = GetNumResources<ResourceType>();
for (Uint32 res = 0; res < NumResources; ++res)
{
auto& Resource = GetResource<ResourceType>(res);
- if (strcmp(Resource.Attribs.Name, Name) == 0)
+ if (strcmp(Resource.m_Attribs.Name, Name) == 0)
return &Resource;
}
return nullptr;
}
-IShaderVariable* ShaderResourceLayoutD3D11::GetShaderVariable(const Char* Name)
+IShaderResourceVariable* ShaderResourceLayoutD3D11::GetShaderVariable(const Char* Name)
{
- if(auto* pCB = GetResourceByName<ConstBuffBindInfo>(Name))
+ if (auto* pCB = GetResourceByName<ConstBuffBindInfo>(Name))
return pCB;
- if(auto* pTexSRV = GetResourceByName<TexSRVBindInfo>(Name))
+ if (auto* pTexSRV = GetResourceByName<TexSRVBindInfo>(Name))
return pTexSRV;
- if(auto* pTexUAV = GetResourceByName<TexUAVBindInfo>(Name))
+ if (auto* pTexUAV = GetResourceByName<TexUAVBindInfo>(Name))
return pTexUAV;
- if(auto* pBuffSRV = GetResourceByName<BuffSRVBindInfo>(Name))
+ if (auto* pBuffSRV = GetResourceByName<BuffSRVBindInfo>(Name))
return pBuffSRV;
- if(auto* pBuffUAV = GetResourceByName<BuffUAVBindInfo>(Name))
+ if (auto* pBuffUAV = GetResourceByName<BuffUAVBindInfo>(Name))
return pBuffUAV;
if (!m_pResources->IsUsingCombinedTextureSamplers())
{
- if(auto* pSampler = GetResourceByName<SamplerBindInfo>(Name))
+ // Static samplers are never created in the resource layout
+ if (auto* pSampler = GetResourceByName<SamplerBindInfo>(Name))
return pSampler;
}
@@ -900,7 +913,7 @@ public: }
template<typename ResourceType>
- IShaderVariable* TryResource()
+ IShaderResourceVariable* TryResource()
{
#ifdef _DEBUG
VERIFY(Layout.GetResourceOffset<ResourceType>() >= dbgPreviousResourceOffset, "Resource types are processed out of order!");
@@ -924,7 +937,7 @@ private: #endif
};
-IShaderVariable* ShaderResourceLayoutD3D11::GetShaderVariable( Uint32 Index )
+IShaderResourceVariable* ShaderResourceLayoutD3D11::GetShaderVariable( Uint32 Index )
{
ShaderVariableLocator VarLocator(*this, Index);
@@ -967,19 +980,17 @@ do{ \ LOG_ERROR_MESSAGE( "No resource is bound to ", VarType, " variable '", Attrs.Name, "[", BindPt-Attrs.BindPoint, "]' in shader '", GetShaderName(), "'" );\
}while(false)
- m_pResourceCache->dbgVerifyCacheConsistency();
+ m_ResourceCache.dbgVerifyCacheConsistency();
bool BindingsOK = true;
- // Use const_cast to avoid duplication of the HandleResources() function
- // The function actually changes nothing
- const_cast<ShaderResourceLayoutD3D11*>(this)->HandleResources(
+ HandleConstResources(
[&](const ConstBuffBindInfo& cb)
{
- for (Uint32 BindPoint = cb.Attribs.BindPoint; BindPoint < Uint32{cb.Attribs.BindPoint} + cb.Attribs.BindCount; ++BindPoint)
+ for (Uint32 BindPoint = cb.m_Attribs.BindPoint; BindPoint < Uint32{cb.m_Attribs.BindPoint} + cb.m_Attribs.BindCount; ++BindPoint)
{
- if (!m_pResourceCache->IsCBBound(BindPoint))
+ if (!m_ResourceCache.IsCBBound(BindPoint))
{
- LOG_MISSING_BINDING("constant buffer", cb.Attribs, BindPoint);
+ LOG_MISSING_BINDING("constant buffer", cb.m_Attribs, BindPoint);
BindingsOK = false;
}
}
@@ -987,32 +998,32 @@ do{ \ [&](const TexSRVBindInfo& ts)
{
- for (Uint32 BindPoint = ts.Attribs.BindPoint; BindPoint < Uint32{ts.Attribs.BindPoint} + ts.Attribs.BindCount; ++BindPoint)
+ for (Uint32 BindPoint = ts.m_Attribs.BindPoint; BindPoint < Uint32{ts.m_Attribs.BindPoint} + ts.m_Attribs.BindCount; ++BindPoint)
{
- if (!m_pResourceCache->IsSRVBound(BindPoint, true))
+ if (!m_ResourceCache.IsSRVBound(BindPoint, true))
{
- LOG_MISSING_BINDING("texture", ts.Attribs, BindPoint);
+ LOG_MISSING_BINDING("texture", ts.m_Attribs, BindPoint);
BindingsOK = false;
}
if (ts.ValidSamplerAssigned())
{
const auto& Sampler = GetConstResource<SamplerBindInfo>(ts.SamplerIndex);
- VERIFY_EXPR(Sampler.Attribs.BindCount == ts.Attribs.BindCount || Sampler.Attribs.BindCount == 1);
+ VERIFY_EXPR(Sampler.m_Attribs.BindCount == ts.m_Attribs.BindCount || Sampler.m_Attribs.BindCount == 1);
// Verify that if single sampler is used for all texture array elements, all samplers set in the resource views are consistent
- if (ts.Attribs.BindCount > 1 && Sampler.Attribs.BindCount == 1)
+ if (ts.m_Attribs.BindCount > 1 && Sampler.m_Attribs.BindCount == 1)
{
ShaderResourceCacheD3D11::CachedSampler* pCachedSamplers = nullptr;
ID3D11SamplerState** ppCachedD3D11Samplers = nullptr;
- m_pResourceCache->GetSamplerArrays(pCachedSamplers, ppCachedD3D11Samplers);
- VERIFY_EXPR(Sampler.Attribs.BindPoint < m_pResourceCache->GetSamplerCount());
- const auto& CachedSampler = pCachedSamplers[Sampler.Attribs.BindPoint];
+ m_ResourceCache.GetSamplerArrays(pCachedSamplers, ppCachedD3D11Samplers);
+ VERIFY_EXPR(Sampler.m_Attribs.BindPoint < m_ResourceCache.GetSamplerCount());
+ const auto& CachedSampler = pCachedSamplers[Sampler.m_Attribs.BindPoint];
ShaderResourceCacheD3D11::CachedResource* pCachedResources = nullptr;
ID3D11ShaderResourceView** ppCachedD3D11Resources = nullptr;
- m_pResourceCache->GetSRVArrays(pCachedResources, ppCachedD3D11Resources);
- VERIFY_EXPR(BindPoint < m_pResourceCache->GetSRVCount());
+ m_ResourceCache.GetSRVArrays(pCachedResources, ppCachedD3D11Resources);
+ VERIFY_EXPR(BindPoint < m_ResourceCache.GetSRVCount());
auto& CachedResource = pCachedResources[BindPoint];
if (CachedResource.pView)
{
@@ -1020,7 +1031,7 @@ do{ \ auto* pSampler = pTexView->GetSampler();
if (pSampler != nullptr && pSampler != CachedSampler.pSampler.RawPtr())
{
- LOG_ERROR_MESSAGE( "All elements of texture array '", ts.Attribs.Name, "' in shader '", GetShaderName(), "' share the same sampler. However, the sampler set in view for element ", BindPoint - ts.Attribs.BindPoint, " does not match bound sampler. This may cause incorrect behavior on GL platform." );
+ LOG_ERROR_MESSAGE( "All elements of texture array '", ts.m_Attribs.Name, "' in shader '", GetShaderName(), "' share the same sampler. However, the sampler set in view for element ", BindPoint - ts.m_Attribs.BindPoint, " does not match bound sampler. This may cause incorrect behavior on GL platform." );
}
}
}
@@ -1030,11 +1041,11 @@ do{ \ [&](const TexUAVBindInfo& uav)
{
- for (Uint32 BindPoint = uav.Attribs.BindPoint; BindPoint < Uint32{uav.Attribs.BindPoint} + uav.Attribs.BindCount; ++BindPoint)
+ for (Uint32 BindPoint = uav.m_Attribs.BindPoint; BindPoint < Uint32{uav.m_Attribs.BindPoint} + uav.m_Attribs.BindCount; ++BindPoint)
{
- if (!m_pResourceCache->IsUAVBound(BindPoint, true))
+ if (!m_ResourceCache.IsUAVBound(BindPoint, true))
{
- LOG_MISSING_BINDING("texture UAV", uav.Attribs, BindPoint);
+ LOG_MISSING_BINDING("texture UAV", uav.m_Attribs, BindPoint);
BindingsOK = false;
}
}
@@ -1042,11 +1053,11 @@ do{ \ [&](const BuffSRVBindInfo& buf)
{
- for (Uint32 BindPoint = buf.Attribs.BindPoint; BindPoint < Uint32{buf.Attribs.BindPoint} + buf.Attribs.BindCount; ++BindPoint)
+ for (Uint32 BindPoint = buf.m_Attribs.BindPoint; BindPoint < Uint32{buf.m_Attribs.BindPoint} + buf.m_Attribs.BindCount; ++BindPoint)
{
- if (!m_pResourceCache->IsSRVBound(BindPoint, false))
+ if (!m_ResourceCache.IsSRVBound(BindPoint, false))
{
- LOG_MISSING_BINDING("buffer", buf.Attribs, BindPoint);
+ LOG_MISSING_BINDING("buffer", buf.m_Attribs, BindPoint);
BindingsOK = false;
}
}
@@ -1054,11 +1065,11 @@ do{ \ [&](const BuffUAVBindInfo& uav)
{
- for (Uint32 BindPoint = uav.Attribs.BindPoint; BindPoint < Uint32{uav.Attribs.BindPoint} + uav.Attribs.BindCount; ++BindPoint)
+ for (Uint32 BindPoint = uav.m_Attribs.BindPoint; BindPoint < Uint32{uav.m_Attribs.BindPoint} + uav.m_Attribs.BindCount; ++BindPoint)
{
- if (!m_pResourceCache->IsUAVBound(BindPoint, false))
+ if (!m_ResourceCache.IsUAVBound(BindPoint, false))
{
- LOG_MISSING_BINDING("buffer UAV", uav.Attribs, BindPoint);
+ LOG_MISSING_BINDING("buffer UAV", uav.m_Attribs, BindPoint);
BindingsOK = false;
}
}
@@ -1066,11 +1077,11 @@ do{ \ [&](const SamplerBindInfo& sam)
{
- for (Uint32 BindPoint = sam.Attribs.BindPoint; BindPoint < Uint32{sam.Attribs.BindPoint} + sam.Attribs.BindCount; ++BindPoint)
+ for (Uint32 BindPoint = sam.m_Attribs.BindPoint; BindPoint < Uint32{sam.m_Attribs.BindPoint} + sam.m_Attribs.BindCount; ++BindPoint)
{
- if (!m_pResourceCache->IsSamplerBound(BindPoint))
+ if (!m_ResourceCache.IsSamplerBound(BindPoint))
{
- LOG_MISSING_BINDING("sampler", sam.Attribs, BindPoint);
+ LOG_MISSING_BINDING("sampler", sam.m_Attribs, BindPoint);
BindingsOK = false;
}
}
diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp index af72e1a0..b80cbccd 100755 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp @@ -37,9 +37,7 @@ ShaderResourcesD3D11::ShaderResourcesD3D11(RenderDeviceD3D11Impl* pDeviceD3D11Im ID3DBlob* pShaderBytecode,
const ShaderDesc& ShdrDesc,
const char* CombinedSamplerSuffix) :
- ShaderResources(ShdrDesc.ShaderType),
- m_ShaderName(ShdrDesc.Name),
- m_StaticSamplers(STD_ALLOCATOR_RAW_MEM(StaticSamplerAttribs, GetRawAllocator(), "Allocator for vector<StaticSamplerAttribs>"))
+ ShaderResources(ShdrDesc.ShaderType)
{
class NewResourceHandler
{
@@ -51,8 +49,7 @@ ShaderResourcesD3D11::ShaderResourcesD3D11(RenderDeviceD3D11Impl* pDeviceD3D11Im pDeviceD3D11Impl (_pDeviceD3D11Impl),
ShdrDesc (_ShdrDesc),
CombinedSamplerSuffix(_CombinedSamplerSuffix),
- Resources (_Resources),
- m_StaticSamplers (STD_ALLOCATOR_RAW_MEM(StaticSamplerAttribs, GetRawAllocator(), "Allocator for vector<StaticSamplerAttribs>"))
+ Resources (_Resources)
{}
void OnNewCB(const D3DShaderResourceAttribs& CBAttribs)
@@ -83,24 +80,6 @@ ShaderResourcesD3D11::ShaderResourcesD3D11(RenderDeviceD3D11Impl* pDeviceD3D11Im {
VERIFY( SamplerAttribs.BindPoint + SamplerAttribs.BindCount-1 <= MaxAllowedBindPoint, "Sampler bind point exceeds supported range" );
Resources.m_MaxSamplerBindPoint = std::max(Resources.m_MaxSamplerBindPoint, static_cast<MaxBindPointType>(SamplerAttribs.BindPoint + SamplerAttribs.BindCount-1));
-
- if (SamplerAttribs.IsStaticSampler())
- {
- // Find attributes of this static sampler
- Uint32 ssd = 0;
- for (; ssd < ShdrDesc.NumStaticSamplers; ++ssd)
- {
- const auto& StaticSamplerDesc = ShdrDesc.StaticSamplers[ssd];
- if (StreqSuff(SamplerAttribs.Name, StaticSamplerDesc.SamplerOrTextureName, CombinedSamplerSuffix))
- {
- RefCntAutoPtr<ISampler> pSampler;
- pDeviceD3D11Impl->CreateSampler(StaticSamplerDesc.Desc, &pSampler);
- m_StaticSamplers.emplace_back(SamplerAttribs, std::move(pSampler));
- break;
- }
- }
- VERIFY(ssd < ShdrDesc.NumStaticSamplers, "Unable to find sampler '", SamplerAttribs.Name, "' in the list of static samplers. This should never happen and likely indicates a bug in static sampler enumeration code.");
- }
}
void OnNewTexSRV(const D3DShaderResourceAttribs& TexAttribs)
@@ -111,7 +90,6 @@ ShaderResourcesD3D11::ShaderResourcesD3D11(RenderDeviceD3D11Impl* pDeviceD3D11Im ~NewResourceHandler()
{
- Resources.InitStaticSamplers(std::move(m_StaticSamplers));
}
private:
@@ -119,42 +97,20 @@ ShaderResourcesD3D11::ShaderResourcesD3D11(RenderDeviceD3D11Impl* pDeviceD3D11Im const ShaderDesc& ShdrDesc;
const char* CombinedSamplerSuffix;
ShaderResourcesD3D11& Resources;
-
- StaticSamplerVector m_StaticSamplers;
};
Initialize<D3D11_SHADER_DESC, D3D11_SHADER_INPUT_BIND_DESC, ID3D11ShaderReflection>(
pShaderBytecode,
NewResourceHandler{pDeviceD3D11Impl, ShdrDesc, CombinedSamplerSuffix, *this},
- ShdrDesc,
+ ShdrDesc.Name,
CombinedSamplerSuffix);
}
-void ShaderResourcesD3D11::InitStaticSamplers(StaticSamplerVector&& StaticSamplers)
-{
- m_StaticSamplers.reserve(StaticSamplers.size());
- for(auto& Sam : StaticSamplers)
- m_StaticSamplers.emplace_back(std::move(Sam));
-}
ShaderResourcesD3D11::~ShaderResourcesD3D11()
{
}
-void ShaderResourcesD3D11::SetStaticSamplers(ShaderResourceCacheD3D11& ResourceCache)const
-{
- auto NumCachedSamplers = ResourceCache.GetSamplerCount();
- for (const auto& SS : m_StaticSamplers)
- {
- const auto& SamAttribs = SS.first;
- VERIFY_EXPR(SamAttribs.IsStaticSampler());
- auto* pSamplerD3D11Impl = const_cast<SamplerD3D11Impl*>(SS.second.RawPtr<SamplerD3D11Impl>());
- // Limiting EndBindPoint is required when initializing static samplers in a Shader's static cache
- auto EndBindPoint = std::min( static_cast<Uint32>(SamAttribs.BindPoint) + SamAttribs.BindCount, NumCachedSamplers);
- for(Uint32 BindPoint = SamAttribs.BindPoint; BindPoint < EndBindPoint; ++BindPoint )
- ResourceCache.SetSampler(BindPoint, pSamplerD3D11Impl);
- }
-}
#ifdef DEVELOPMENT
static String DbgMakeResourceName(const D3DShaderResourceAttribs& Attr, Uint32 BindPoint)
@@ -188,8 +144,6 @@ void ShaderResourcesD3D11::dvpVerifyCommittedResources(ID3D11Buffer* ResourceCache.GetUAVArrays (CachedUAVResources, d3d11UAVs);
ProcessResources(
- nullptr, 0,
-
[&](const D3DShaderResourceAttribs& cb, Uint32)
{
for (auto BindPoint = cb.BindPoint; BindPoint < cb.BindPoint + cb.BindCount; ++BindPoint)
@@ -298,9 +252,9 @@ void ShaderResourcesD3D11::dvpVerifyCommittedResources(ID3D11Buffer* }
}
- if (tex.ValidSamplerAssigned())
+ if (tex.IsCombinedWithSampler())
{
- const auto& SamAttribs = GetSampler( tex.GetSamplerId() );
+ const auto& SamAttribs = GetCombinedSampler(tex);
VERIFY_EXPR(SamAttribs.IsValidBindPoint());
VERIFY_EXPR(SamAttribs.BindCount == 1 || SamAttribs.BindCount == tex.BindCount);
}
|
