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. --- examples/shader-object/main.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'examples/shader-object') diff --git a/examples/shader-object/main.cpp b/examples/shader-object/main.cpp index 8a5bc8373..88ae24393 100644 --- a/examples/shader-object/main.cpp +++ b/examples/shader-object/main.cpp @@ -196,16 +196,12 @@ int main() // Next, we create a shader object that represents the transformer we want to use. // To do so, we first need to lookup for the `AddTransformer` type defined in the shader code. - ComPtr transformer; - ComPtr transformerObjectLayout; - slang::TypeLayoutReflection* addTransformerTypeLayout = slangReflection->getTypeLayout( - slangReflection->findTypeByName("AddTransformer")); + slang::TypeReflection* addTransformerType = slangReflection->findTypeByName("AddTransformer"); // Now we can use this type to create a shader object that can be bound to the root object. - SLANG_RETURN_ON_FAIL(renderer->createShaderObjectLayout( - addTransformerTypeLayout, transformerObjectLayout.writeRef())); + ComPtr transformer; SLANG_RETURN_ON_FAIL( - renderer->createShaderObject(transformerObjectLayout, transformer.writeRef())); + renderer->createShaderObject(addTransformerType, transformer.writeRef())); // Set the `c` field of the `AddTransformer`. float c = 1.0f; gfx::ShaderCursor(transformer).getPath("c").setData(&c, sizeof(float)); -- cgit v1.2.3