Skip to content

Commit

Permalink
Add an example for using the reflection API (#5839)
Browse files Browse the repository at this point in the history
* Add an example for using the reflection API

The example program is meant to accompany a document that goes into more detail about the mental model behind the reflection API and the way this program drives it.
Ideally this program can land before the document goes live, and then the document can be published with a link to the example.
After that, the example could be updated to include links into the live document.

Along with adding the example program, this change also adds some convenience functions to the reflection API to avoid cases where the program would otherwise need to cast between
`slang::ParameterCategory` and `SlangParameterCategory`.

* format code

* fixup: error noticed by clang

---------

Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
  • Loading branch information
tangent-vector and slangbot authored Dec 12, 2024
1 parent 9c82ed3 commit 1fb79ac
Show file tree
Hide file tree
Showing 6 changed files with 1,638 additions and 4 deletions.
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ if(SLANG_ENABLE_EXAMPLES)
example(platform-test WIN32_EXECUTABLE)
example(ray-tracing WIN32_EXECUTABLE)
example(ray-tracing-pipeline WIN32_EXECUTABLE)
example(reflection-api)
example(shader-object)
example(shader-toy WIN32_EXECUTABLE)
example(triangle WIN32_EXECUTABLE)
Expand Down
6 changes: 6 additions & 0 deletions examples/reflection-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Slang Reflection API Example
============================

This example shows basic usage of the Slang reflection API to
traverse the parameters of a program, including type and
layout information.
21 changes: 21 additions & 0 deletions examples/reflection-api/compute-simple.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// compute-simple.slang

struct ImageProcessingOptions
{
float3 tintColor;
float blurRadius;

bool useLookupTable;
StructuredBuffer<float4> lookupTable;
}

[shader("compute")]
[numthreads(8, 8)]
void processImage(
uint3 threadID : SV_DispatchThreadID,
uniform Texture2D inputImage,
uniform RWTexture2D outputImage,
uniform ImageProcessingOptions options)
{
/* actual logic would go here */
}
Loading

0 comments on commit 1fb79ac

Please sign in to comment.