yum-mirror/slang

Making it easier to work with shaders

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

Yong He[Metal] Fix global constant array emit. (#4392)33e81a031

master
1.0 KiB33 linesraw
1// static-const-array.slang
2
3//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -shaderobj
4//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type -shaderobj
5//TEST(compute):COMPARE_COMPUTE_EX:-cpu -slang -compute -output-using-type -shaderobj
6
7//TEST_INPUT:ubuffer(data=[0 0 0 0  0 0 0 0], stride=4):out, name outputBuffer
8RWStructuredBuffer<float> outputBuffer;
9
10static const float3 kArray[8] =
11{
12    float3(-0.4706069, -0.4427112, - - + 0.6461146),
13    float3(-0.9057375, +0.3003471, +0.9542373),
14    float3(-0.3487388, +0.4037880, +0.5335386),
15    float3(+0.1023042, +0.6439373, +0.6520134),
16    float3(+0.5699277, +0.3513750, +0.6695386),
17    float3(+0.2939128, -0.1131226, +0.3149309),
18    float3(+0.7836658, -0.4208784, +0.8895339),
19    float3(+0.1564120, -0.8198990, +0.8346850)
20};
21
22float test(int val)
23{
24	return kArray[val].x + kArray[val].y + kArray[val].z;
25}
26
27[numthreads(8, 1, 1)]
28void computeMain(int3 tid : SV_DispatchThreadID)
29{
30	int inVal = tid.x;
31	float outVal = test(inVal);
32	outputBuffer[inVal] = outVal;
33}