From f85bc7ae98486b37518958e659f659f1ff9b125c Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 21 Jan 2022 10:17:39 -0800 Subject: GFX: seperated ShaderTable. (#2090) --- tools/gfx/renderer-shared.h | 50 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'tools/gfx/renderer-shared.h') diff --git a/tools/gfx/renderer-shared.h b/tools/gfx/renderer-shared.h index 33d51e9ad..6baade085 100644 --- a/tools/gfx/renderer-shared.h +++ b/tools/gfx/renderer-shared.h @@ -39,6 +39,7 @@ struct GfxGUID static const Slang::Guid IID_IQueryPool; static const Slang::Guid IID_IAccelerationStructure; static const Slang::Guid IID_IFence; + static const Slang::Guid IID_IShaderTable; }; // We use a `BreakableReference` to avoid the cyclic reference situation in gfx implementation. @@ -1186,7 +1187,7 @@ public: } public: SLANG_COM_OBJECT_IUNKNOWN_ALL - ITransientResourceHeap* getInterface(const Slang::Guid& guid) + ITransientResourceHeap* getInterface(const Slang::Guid& guid) { if (guid == GfxGUID::IID_ISlangUnknown || guid == GfxGUID::IID_ITransientResourceHeap) return static_cast(this); @@ -1194,6 +1195,48 @@ public: } }; +class ShaderTableBase + : public IShaderTable + , public Slang::ComObject +{ +public: + Slang::List m_entryPointNames; + uint32_t m_rayGenShaderCount; + uint32_t m_missShaderCount; + uint32_t m_hitGroupCount; + + Slang::Dictionary> m_deviceBuffers; + + SLANG_COM_OBJECT_IUNKNOWN_ALL + IShaderTable* getInterface(const Slang::Guid& guid) + { + if (guid == GfxGUID::IID_ISlangUnknown || guid == GfxGUID::IID_IShaderTable) + return static_cast(this); + return nullptr; + } + + virtual Slang::RefPtr createDeviceBuffer( + PipelineStateBase* pipeline, + TransientResourceHeapBase* transientHeap, + IResourceCommandEncoder* encoder) = 0; + + BufferResource* getOrCreateBuffer( + PipelineStateBase* pipeline, + TransientResourceHeapBase* transientHeap, + IResourceCommandEncoder* encoder) + { + if (auto ptr = m_deviceBuffers.TryGetValue(pipeline)) + { + return ptr->Ptr(); + } + auto result = createDeviceBuffer(pipeline, transientHeap, encoder); + m_deviceBuffers[pipeline] = result; + return result; + } + + Result init(const IShaderTable::Desc& desc); +}; + // Renderer implementation shared by all platforms. // Responsible for shader compilation, specialization and caching. class RendererBase : public IDevice, public Slang::ComObject @@ -1254,6 +1297,11 @@ public: const IAccelerationStructure::CreateDesc& desc, IAccelerationStructure** outView) override; + // Provides a default implementation that returns SLANG_E_NOT_AVAILABLE for platforms + // without ray tracing support. + virtual SLANG_NO_THROW Result SLANG_MCALL + createShaderTable(const IShaderTable::Desc& desc, IShaderTable** outTable) override; + // Provides a default implementation that returns SLANG_E_NOT_AVAILABLE for platforms // without ray tracing support. virtual SLANG_NO_THROW Result SLANG_MCALL createRayTracingPipelineState( -- cgit v1.2.3