Skip to content

Commit 1fb79ac

Browse files
Add an example for using the reflection API (shader-slang#5839)
* 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>
1 parent 9c82ed3 commit 1fb79ac

File tree

6 files changed

+1638
-4
lines changed

6 files changed

+1638
-4
lines changed

examples/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ if(SLANG_ENABLE_EXAMPLES)
8383
example(platform-test WIN32_EXECUTABLE)
8484
example(ray-tracing WIN32_EXECUTABLE)
8585
example(ray-tracing-pipeline WIN32_EXECUTABLE)
86+
example(reflection-api)
8687
example(shader-object)
8788
example(shader-toy WIN32_EXECUTABLE)
8889
example(triangle WIN32_EXECUTABLE)

examples/reflection-api/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Slang Reflection API Example
2+
============================
3+
4+
This example shows basic usage of the Slang reflection API to
5+
traverse the parameters of a program, including type and
6+
layout information.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// compute-simple.slang
2+
3+
struct ImageProcessingOptions
4+
{
5+
float3 tintColor;
6+
float blurRadius;
7+
8+
bool useLookupTable;
9+
StructuredBuffer<float4> lookupTable;
10+
}
11+
12+
[shader("compute")]
13+
[numthreads(8, 8)]
14+
void processImage(
15+
uint3 threadID : SV_DispatchThreadID,
16+
uniform Texture2D inputImage,
17+
uniform RWTexture2D outputImage,
18+
uniform ImageProcessingOptions options)
19+
{
20+
/* actual logic would go here */
21+
}

0 commit comments

Comments
 (0)