yum-mirror/slang

Making it easier to work with shaders

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

Yong HeSupport parameter block in metal shader objects. (#4671)f114433de

master
1.3 KiB56 linesraw
1// entry-point-uniform-params.slang
2
3// Confirm that `uniform` parameters on
4// entry points are allowed, and work as expected.
5
6//DISABLE_TEST:CPU_REFLECTION: -profile cs_5_0 -entry computeMain -target cpp
7//TEST(compute):COMPARE_COMPUTE: -dx12 -shaderobj
8//TEST(compute):COMPARE_COMPUTE: -vk -shaderobj
9//TEST(compute):COMPARE_COMPUTE: -dx11 -shaderobj
10//TEST(compute):COMPARE_COMPUTE: -cuda -shaderobj
11//TEST(compute):COMPARE_COMPUTE: -cpu -shaderobj
12//TEST(compute):COMPARE_COMPUTE: -metal -shaderobj
13
14struct Signs
15{
16	int a;
17}
18
19struct Stuff
20{
21	int b;
22}
23
24struct Things
25{
26	int c;
27}
28
29// A shader parameter at global scope should be assigned
30// a register/binding before any related to the entry point.
31
32//TEST_INPUT:cbuffer(data=[1 0 0 0]):name=signs
33ConstantBuffer<Signs> signs;
34
35[numthreads(4, 1, 1)]
36void computeMain(
37//TEST_INPUT:uniform(data=[2]):name=stuff
38	uniform Stuff  stuff,
39//TEST_INPUT:uniform(data=[3]):name=things
40	uniform Things things,
41
42//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
43	uniform RWStructuredBuffer<int> outputBuffer,
44
45	int3 dispatchThreadID : SV_DispatchThreadID)
46{
47	int tid = dispatchThreadID.x;
48
49	int val = 0;
50	val = val*16 + signs.a;
51	val = val*16 + stuff.b;
52	val = val*16 + things.c;
53	val = val*16 + tid;
54
55	outputBuffer[tid] = val;
56}