From b1e376fa1e7dd0ff59991bdf1d3d859d3b63a74a Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Wed, 17 Feb 2021 18:42:23 -0800 Subject: Streamline shader object creation (#1717) This change kind of rolls together two different simplifications: 1. The `createShaderObject()` shouldn't really need to take an `IShaderObjectLayout` because it could just take the `slang::TypeLayoutReflection` instead and create the shader-object layout behind the scenes. 2. For that matter, it needn't take a `slang::TypeLayoutReflection` either, becaues it could just take a `slang::TypeReflection` and query the layout of that type behind the scenes. The combination of these two changes means: * `IShaderObjectLayout` is gone from the public API, as is `createShaderObjectLayout()` * `createShaderObject()` directly takes a `slang::TypeReflection` and allocates a shader object of that type The result is simpler and more streamlined application code. Note that under the hood the implementation still has shader-object layouts, using the `ShaderObjectLayoutBase` class. A few locations had to change to use `RefPtr`s instead of `ComPtr`s now that the class is no longer a public COM-lite API type. The hope is that this change makes it easier to allocate/cache layouts for things like specialized types "under the hood," as is needed to implement parameter setting for static specialization. --- tools/gfx/renderer-shared.h | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'tools/gfx/renderer-shared.h') diff --git a/tools/gfx/renderer-shared.h b/tools/gfx/renderer-shared.h index 26ed5b040..7b7a6d757 100644 --- a/tools/gfx/renderer-shared.h +++ b/tools/gfx/renderer-shared.h @@ -129,7 +129,7 @@ struct ExtendedShaderObjectTypeList } }; -class ShaderObjectLayoutBase : public IShaderObjectLayout, public Slang::RefObject +class ShaderObjectLayoutBase : public Slang::RefObject { protected: RendererBase* m_renderer; @@ -137,9 +137,6 @@ protected: ShaderComponentID m_componentID = 0; public: - SLANG_REF_OBJECT_IUNKNOWN_ALL - IShaderObjectLayout* getInterface(const Slang::Guid& guid); - RendererBase* getRenderer() { return m_renderer; } slang::TypeLayoutReflection* getElementTypeLayout() @@ -163,6 +160,7 @@ protected: // The specialized shader object type. ExtendedShaderObjectType shaderObjectType = { nullptr, kInvalidComponentID }; + public: SLANG_REF_OBJECT_IUNKNOWN_ALL IShaderObject* getInterface(const Slang::Guid& guid); @@ -355,6 +353,7 @@ protected: // Responsible for shader compilation, specialization and caching. class RendererBase : public Slang::RefObject, public IRenderer { + friend class ShaderObjectBase; public: SLANG_REF_OBJECT_IUNKNOWN_ALL @@ -364,6 +363,8 @@ public: virtual SLANG_NO_THROW Result SLANG_MCALL getSlangSession(slang::ISession** outSlangSession) SLANG_OVERRIDE; IRenderer* getInterface(const Slang::Guid& guid); + virtual SLANG_NO_THROW Result SLANG_MCALL createShaderObject(slang::TypeReflection* type, IShaderObject** outObject) SLANG_OVERRIDE; + protected: // Retrieves the currently bound unspecialized pipeline. // If the bound pipeline is not created from a Slang component, an implementation should return null. @@ -371,6 +372,21 @@ protected: ExtendedShaderObjectTypeList specializationArgs; // Given current pipeline and root shader object binding, generate and bind a specialized pipeline if necessary. Result maybeSpecializePipeline(ShaderObjectBase* inRootShaderObject); + + + virtual Result createShaderObjectLayout( + slang::TypeLayoutReflection* typeLayout, + ShaderObjectLayoutBase** outLayout) = 0; + + Result getShaderObjectLayout( + slang::TypeReflection* type, + ShaderObjectLayoutBase** outLayout); + + virtual Result createShaderObject( + ShaderObjectLayoutBase* layout, + IShaderObject** outObject) = 0; + + protected: virtual SLANG_NO_THROW SlangResult SLANG_MCALL initialize(const Desc& desc, void* inWindowHandle); protected: @@ -378,6 +394,8 @@ protected: public: SlangContext slangContext; ShaderCache shaderCache; + + Slang::Dictionary> m_shaderObjectLayoutCache; }; } -- cgit v1.2.3