diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2024-10-29 14:49:26 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-29 14:49:26 +0800 |
| commit | f65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 (patch) | |
| tree | ea1d61342cd29368e19135000ec2948813096205 /examples/shader-object | |
| parent | a729c15e9dce9f5116a38afc66329ab2ca4cea54 (diff) | |
format
* format
* Minor test fixes
* enable checking cpp format in ci
Diffstat (limited to 'examples/shader-object')
| -rw-r--r-- | examples/shader-object/main.cpp | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/examples/shader-object/main.cpp b/examples/shader-object/main.cpp index 603278bcf..74d81604b 100644 --- a/examples/shader-object/main.cpp +++ b/examples/shader-object/main.cpp @@ -8,14 +8,14 @@ // simplifies shader specialization and parameter binding when using `interface` typed // shader parameters. // -#include "slang.h" #include "slang-com-ptr.h" +#include "slang.h" using Slang::ComPtr; -#include "slang-gfx.h" +#include "examples/example-base/example-base.h" #include "gfx-util/shader-cursor.h" +#include "slang-gfx.h" #include "source/core/slang-basic.h" -#include "examples/example-base/example-base.h" using namespace gfx; @@ -37,7 +37,7 @@ Result loadShaderProgram( // creates a Slang compilation session for us, so we just grab and use it here. ComPtr<slang::ISession> slangSession; SLANG_RETURN_ON_FAIL(device->getSlangSession(slangSession.writeRef())); - + // Once the session has been obtained, we can start loading code into it. // // The simplest way to load code is by calling `loadModule` with the name of a Slang @@ -61,7 +61,7 @@ Result loadShaderProgram( Slang::String path = resourceBase.resolveResource("shader-object.slang"); slang::IModule* module = slangSession->loadModule(path.getBuffer(), diagnosticsBlob.writeRef()); diagnoseIfNeeded(diagnosticsBlob); - if(!module) + if (!module) return SLANG_FAIL; // Loading the `shader-object` module will compile and check all the shader code in it, @@ -74,13 +74,13 @@ Result loadShaderProgram( // is no umambiguous way for the compiler to know which functions represent entry // points when it parses your code via `loadModule()`. // - char const* computeEntryPointName = "computeMain"; + char const* computeEntryPointName = "computeMain"; ComPtr<slang::IEntryPoint> computeEntryPoint; SLANG_RETURN_ON_FAIL( module->findEntryPointByName(computeEntryPointName, computeEntryPoint.writeRef())); - + // At this point we have a few different Slang API objects that represent - // pieces of our code: `module`, `vertexEntryPoint`, and `fragmentEntryPoint`. + // pieces of our code: `module`, `vertexEntryPoint`, and `fragmentEntryPoint`. // // A single Slang module could contain many different entry points (e.g., // four vertex entry points, three fragment entry points, and two compute @@ -177,10 +177,8 @@ int main(int argc, char* argv[]) bufferDesc.memoryType = MemoryType::DeviceLocal; ComPtr<gfx::IBufferResource> numbersBuffer; - SLANG_RETURN_ON_FAIL(device->createBufferResource( - bufferDesc, - (void*)initialData, - numbersBuffer.writeRef())); + SLANG_RETURN_ON_FAIL( + device->createBufferResource(bufferDesc, (void*)initialData, numbersBuffer.writeRef())); // Create a resource view for the buffer. ComPtr<gfx::IResourceView> bufferView; @@ -217,7 +215,9 @@ int main(int argc, char* argv[]) // Now we can use this type to create a shader object that can be bound to the root object. ComPtr<gfx::IShaderObject> transformer; SLANG_RETURN_ON_FAIL(device->createShaderObject( - addTransformerType, ShaderObjectContainerType::None, transformer.writeRef())); + addTransformerType, + ShaderObjectContainerType::None, + transformer.writeRef())); // Set the `c` field of the `AddTransformer`. float c = 1.0f; gfx::ShaderCursor(transformer).getPath("c").setData(&c, sizeof(float)); @@ -244,7 +244,10 @@ int main(int argc, char* argv[]) // Read back the results. ComPtr<ISlangBlob> resultBlob; SLANG_RETURN_ON_FAIL(device->readBufferResource( - numbersBuffer, 0, numberCount * sizeof(float), resultBlob.writeRef())); + numbersBuffer, + 0, + numberCount * sizeof(float), + resultBlob.writeRef())); auto result = reinterpret_cast<const float*>(resultBlob->getBufferPointer()); for (int i = 0; i < numberCount; i++) printf("%f\n", result[i]); |
