yum-mirror/slang

Making it easier to work with shaders

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

James Helferty (NVIDIA)render-test: Change D3D12 default to sm_6_5 (#8320)f02b08490

master
2.4 KiB80 linesraw
1// We currently don't support matrix intrinsics on glsl based targets
2// There are problems with double on dx12/dxbc so we disable that
3
4//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -shaderobj
5//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -shaderobj
6//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -output-using-type -shaderobj
7//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -profile sm_6_0 -output-using-type -shaderobj -render-feature hardware-device
8//DISABLE_TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type -shaderobj -render-feature double
9//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -output-using-type -shaderobj
10
11//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0], stride=4):out,name outputBuffer
12RWStructuredBuffer<double> outputBuffer;
13
14typedef double Float;
15
16typedef matrix<Float, 2, 2> FloatMatrix;
17typedef matrix<int64_t, 2, 2> IntMatrix;
18typedef matrix<uint64_t, 2, 2> UIntMatrix;
19typedef vector<Float, 2> FloatVector;
20
21Float calcTotal(FloatVector v)
22{
23    return v.x + v.y;
24}
25
26Float calcTotal(FloatMatrix v) 
27{ 
28    return calcTotal(v[0]) + calcTotal(v[1]);
29}
30
31FloatMatrix makeFloatMatrix(Float f)
32{
33    FloatMatrix m = { { f, f }, { f, f } };
34    return m;
35}
36
37IntMatrix makeIntMatrix(int v)
38{
39    IntMatrix m = { { v, v }, { v, v } };
40    return m;
41}
42
43[numthreads(4, 1, 1)]
44void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
45{
46    int idx = int(dispatchThreadID.x);
47
48    Float scalarF = idx * (1.0f / (4.0f));
49
50    FloatMatrix ft = {}; 
51
52    FloatMatrix f = { { scalarF + 0.01, scalarF + 0.02}, { scalarF + 0.011, scalarF + 0.022}};
53    
54    // fmod - doesn't work on double on D3D/DX
55    // ft += FloatMatrix(IntMatrix(((f % makeFloatMatrix(0.11f)) * makeFloatMatrix(100)) + makeFloatMatrix(0.5)));
56    
57    ft += rcp(makeFloatMatrix(1.0l) + f);
58    ft += FloatMatrix(sign(f - makeFloatMatrix(0.5l)));
59    
60    // Lets try some matrix/matrix
61    ft = f * ft;
62    
63    // Lets try some vector matrix
64    
65    {
66        FloatMatrix r = {mul(f[0], ft), mul(ft, f[1])};
67        ft += r;
68    }
69    
70    ft += saturate(f * makeFloatMatrix(4) - makeFloatMatrix(2.0l));
71       
72    ft += abs(f * makeFloatMatrix(4) - makeFloatMatrix(2.0l));
73           
74    ft += min(makeFloatMatrix(0.5l), f);
75    ft += max(f, makeFloatMatrix(0.75l));
76
77    ft += clamp(f, makeFloatMatrix(0.1l), makeFloatMatrix(0.3l));
78    
79    outputBuffer[idx] = calcTotal(ft);
80}