diff options
Diffstat (limited to 'tools/gfx/renderer-shared.h')
| -rw-r--r-- | tools/gfx/renderer-shared.h | 50 |
1 files changed, 49 insertions, 1 deletions
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<ITransientResourceHeap*>(this); @@ -1194,6 +1195,48 @@ public: } }; +class ShaderTableBase + : public IShaderTable + , public Slang::ComObject +{ +public: + Slang::List<Slang::String> m_entryPointNames; + uint32_t m_rayGenShaderCount; + uint32_t m_missShaderCount; + uint32_t m_hitGroupCount; + + Slang::Dictionary<PipelineStateBase*, Slang::RefPtr<BufferResource>> 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<IShaderTable*>(this); + return nullptr; + } + + virtual Slang::RefPtr<BufferResource> 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 @@ -1256,6 +1299,11 @@ public: // 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( const RayTracingPipelineStateDesc& desc, IPipelineState** outState) override; |
