yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

skallweitNVAdd ASAN support + fixes (#2614)93a6b6119

master
1.3 KiB38 linesraw
1// kernels.slang
2
3// This file demonstrates how ordinary shader code can make use of
4// a standalone GPU printing library implemented in `printing.slang`.
5//
6// The first step for using a module of Slang code is to `import` it.
7//
8import printing;
9//
10// The `import` declaration above brings all the types and functions
11// declared in the `printing` module (in `printing.slang`) into
12// scope so that our code can use them.
13
14// For simplicity, we will define a single compute shader that does
15// some simple printing.
16//
17[shader("compute")]
18[numthreads(32)]
19void computeMain(uint3 tid : SV_DispatchThreadID)
20{
21    // The `printing` module defines two main printing routines.
22    //
23    // The first is a `println` function in the style of Java,
24    // which takes zero or more arguments and prints them all
25    // followed by a newline.
26    //
27    // HACK: We are having to explicitly call `getStringHash` here
28    // because the print implementation wants to write out strings
29    // in terms of their hash code, and the current Slang implementation
30    // of `getStringHash` only applies to string literals.
31    //
32    println("hello from thread number ", tid.x);
33
34    // The second facility supported by `printing.slang` is a C-style
35    // `printf()` function.
36    //
37    printf_("printf from thread 0x%x\n", tid.x);
38}