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/render-graphics-common.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'tools/gfx/render-graphics-common.cpp') diff --git a/tools/gfx/render-graphics-common.cpp b/tools/gfx/render-graphics-common.cpp index 2e35005d4..3e38b8b5a 100644 --- a/tools/gfx/render-graphics-common.cpp +++ b/tools/gfx/render-graphics-common.cpp @@ -26,7 +26,7 @@ public: struct SubObjectRangeInfo { - ComPtr layout; + RefPtr layout; // Index baseIndex; // Index count; Index bindingRangeIndex; @@ -317,7 +317,7 @@ public: SlangResult build(GraphicsCommonShaderObjectLayout** outLayout) { auto layout = - ComPtr(new GraphicsCommonShaderObjectLayout()); + RefPtr(new GraphicsCommonShaderObjectLayout()); SLANG_RETURN_ON_FAIL(layout->_init(this)); *outLayout = layout.detach(); @@ -980,7 +980,7 @@ protected: Result _writeOrdinaryData(char* dest, size_t destSize) { auto src = m_ordinaryData.getBuffer(); - auto srcSize = m_ordinaryData.getCount(); + auto srcSize = size_t(m_ordinaryData.getCount()); SLANG_ASSERT(srcSize <= destSize); @@ -1374,8 +1374,9 @@ protected: }; -Result SLANG_MCALL GraphicsAPIRenderer::createShaderObjectLayout( - slang::TypeLayoutReflection* typeLayout, IShaderObjectLayout** outLayout) +Result GraphicsAPIRenderer::createShaderObjectLayout( + slang::TypeLayoutReflection* typeLayout, + ShaderObjectLayoutBase** outLayout) { RefPtr layout; SLANG_RETURN_ON_FAIL(GraphicsCommonShaderObjectLayout::createForElementType( @@ -1384,8 +1385,9 @@ Result SLANG_MCALL GraphicsAPIRenderer::createShaderObjectLayout( return SLANG_OK; } -Result SLANG_MCALL - GraphicsAPIRenderer::createShaderObject(IShaderObjectLayout* layout, IShaderObject** outObject) +Result GraphicsAPIRenderer::createShaderObject( + ShaderObjectLayoutBase* layout, + IShaderObject** outObject) { RefPtr shaderObject; SLANG_RETURN_ON_FAIL(GraphicsCommonShaderObject::create(this, -- cgit v1.2.3