diff options
| author | Yong He <yonghe@outlook.com> | 2020-12-10 09:43:09 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-10 09:43:09 -0800 |
| commit | e4a8251749cf1fbf005b045e26e25f3ef7cccb8b (patch) | |
| tree | 209bb9617acb91c9cc1a9cc14f9aab5e92ca9871 /tools/gfx/render.h | |
| parent | b8e1f62fb9cc66481b35231149448e47f096d257 (diff) | |
Move ShaderObject to be under renderer interface. (#1633)
* Move ShaderObject to be under renderer interface.
* Make `create*PipelineState` take `const PipelineStateDesc&`.
* Move ShaderCursor implementation to a cpp file
Diffstat (limited to 'tools/gfx/render.h')
| -rw-r--r-- | tools/gfx/render.h | 81 |
1 files changed, 78 insertions, 3 deletions
diff --git a/tools/gfx/render.h b/tools/gfx/render.h index 5ad338594..fb9e10724 100644 --- a/tools/gfx/render.h +++ b/tools/gfx/render.h @@ -634,6 +634,38 @@ public: void const* data) = 0; }; +struct ShaderOffset +{ + SlangInt uniformOffset = 0; + SlangInt bindingRangeIndex = 0; + SlangInt bindingArrayIndex = 0; +}; + +class ShaderObjectLayout : public Slang::RefObject +{}; + +class ShaderObject : public Slang::RefObject +{ +public: + ShaderObject* getObject(ShaderOffset const& offset) + { + ShaderObject* object = nullptr; + SLANG_RETURN_NULL_ON_FAIL(getObject(offset, &object)); + return object; + } + + virtual slang::TypeLayoutReflection* getElementTypeLayout() = 0; + virtual Slang::Index getEntryPointCount() = 0; + virtual ShaderObject* getEntryPoint(Slang::Index index) = 0; + virtual SlangResult setData(ShaderOffset const& offset, void const* data, size_t size) = 0; + virtual SlangResult getObject(ShaderOffset const& offset, ShaderObject** object) = 0; + virtual SlangResult setObject(ShaderOffset const& offset, ShaderObject* object) = 0; + virtual SlangResult setResource(ShaderOffset const& offset, ResourceView* resourceView) = 0; + virtual SlangResult setSampler(ShaderOffset const& offset, SamplerState* sampler) = 0; + virtual SlangResult setCombinedTextureSampler( + ShaderOffset const& offset, ResourceView* textureView, SamplerState* sampler) = 0; +}; + enum class StencilOp : uint8_t { Keep, @@ -779,11 +811,14 @@ struct BlendDesc struct GraphicsPipelineStateDesc { ShaderProgram* program; - PipelineLayout* pipelineLayout; + // Application should set either pipelineLayout or rootShaderObjectLayout, but not both. + PipelineLayout* pipelineLayout = nullptr; + // Application should set either pipelineLayout or rootShaderObjectLayout, but not both. + ShaderObjectLayout* rootShaderObjectLayout = nullptr; InputLayout* inputLayout; UInt framebufferWidth; UInt framebufferHeight; - UInt renderTargetCount; + UInt renderTargetCount = 0; // Not used if rootShaderObjectLayout is set. DepthStencilDesc depthStencil; RasterizerDesc rasterizer; BlendDesc blend; @@ -792,7 +827,8 @@ struct GraphicsPipelineStateDesc struct ComputePipelineStateDesc { ShaderProgram* program; - PipelineLayout* pipelineLayout; + PipelineLayout* pipelineLayout = nullptr; + ShaderObjectLayout* rootShaderObjectLayout = nullptr; }; class PipelineState : public Slang::RefObject @@ -910,6 +946,45 @@ public: return layout; } + virtual Result createShaderObjectLayout( + slang::TypeLayoutReflection* typeLayout, ShaderObjectLayout** outLayout) = 0; + + inline RefPtr<ShaderObjectLayout> createShaderObjectLayout(slang::TypeLayoutReflection* typeLayout) + { + RefPtr<ShaderObjectLayout> layout; + SLANG_RETURN_NULL_ON_FAIL(createShaderObjectLayout(typeLayout, layout.writeRef())); + return layout; + } + + virtual Result createRootShaderObjectLayout(slang::ProgramLayout* layout, ShaderObjectLayout** outLayout) = 0; + + inline RefPtr<ShaderObjectLayout> createRootShaderObjectLayout(slang::ProgramLayout* layout) + { + RefPtr<ShaderObjectLayout> result; + SLANG_RETURN_NULL_ON_FAIL(createRootShaderObjectLayout(layout, result.writeRef())); + return result; + } + + virtual Result createShaderObject(ShaderObjectLayout* layout, ShaderObject** outObject) = 0; + + inline RefPtr<ShaderObject> createShaderObject(ShaderObjectLayout* layout) + { + RefPtr<ShaderObject> object; + SLANG_RETURN_NULL_ON_FAIL(createShaderObject(layout, object.writeRef())); + return object; + } + + virtual Result createRootShaderObject(ShaderObjectLayout* layout, ShaderObject** outObject) = 0; + + inline RefPtr<ShaderObject> createRootShaderObject(ShaderObjectLayout* layout) + { + RefPtr<ShaderObject> object; + SLANG_RETURN_NULL_ON_FAIL(createRootShaderObject(layout, object.writeRef())); + return object; + } + + virtual Result bindRootShaderObject(PipelineType pipelineType, ShaderObject* object) = 0; + virtual Result createPipelineLayout(const PipelineLayout::Desc& desc, PipelineLayout** outLayout) = 0; inline RefPtr<PipelineLayout> createPipelineLayout(const PipelineLayout::Desc& desc) |
