Skip to content

Commit 599129d

Browse files
authored
Matrix tests and assorted bug tests (shader-slang#1814)
* #include an absolute path didn't work - because paths were taken to always be relative. * Some test around matrix layout. * A test for problem with C++ code output. * Default should be column major CPU/CUDA tests confused this. * Added column-major test * Small fixes around tabs/comments * Diagnostic problem for init of vector type with inappropriate params. * Test demonstrating inconsistency between GPU and 'CPU-like' non square matrices. * Added column major non square test. * Remove vector mismatch - because ambiguity is arguably reasonable because float can silently promote to a vector. * Small typo fixes for non-square-column-major.slang
1 parent b17701c commit 599129d

13 files changed

+239
-0
lines changed

tests/compute/column-major.slang

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// column-major.slang
2+
3+
// Unfortunately CPU and CUDA only work with row layout, so they have to be disabled here.
4+
5+
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -compile-arg -O3 -shaderobj
6+
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -shaderobj
7+
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -dx12 -shaderobj
8+
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type -shaderobj
9+
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -output-using-type -shaderobj
10+
11+
// This data is in column major layout order....
12+
//TEST_INPUT:cbuffer(data=[1.0 0.0 0.0 10.0 0.0 1.0 0.0 20.0 0.0 0.0 1.0 30.0 0.0 0.0 0.0 1.0]):name matrixBuffer
13+
14+
ConstantBuffer<float4x4> matrixBuffer;
15+
16+
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name output
17+
RWStructuredBuffer<float> output;
18+
19+
[numthreads(1, 1, 1)]
20+
void computeMain(uint3 tid : SV_DispatchThreadID)
21+
{
22+
float4 v = float4(1, 2, 3, 1);
23+
24+
float4x4 M = matrixBuffer;
25+
26+
float4 r = mul(v, M);
27+
28+
output[0] = r.x;
29+
output[1] = r.y;
30+
output[2] = r.z;
31+
output[3] = r.w;
32+
}

tests/compute/column-major.slang.expected.txt

Whitespace-only changes.

tests/compute/default-major.slang

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// default-major.slang
2+
3+
// The default layout should be column. Unfortunately CPU and CUDA only work with row layout, so they have to be disabled here.
4+
5+
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -compile-arg -O3 -shaderobj
6+
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -shaderobj
7+
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -dx12 -shaderobj
8+
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type -shaderobj
9+
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -output-using-type -shaderobj
10+
11+
// This data is in column major layout order....
12+
//TEST_INPUT:cbuffer(data=[1.0 0.0 0.0 10.0 0.0 1.0 0.0 20.0 0.0 0.0 1.0 30.0 0.0 0.0 0.0 1.0]):name matrixBuffer
13+
14+
ConstantBuffer<float4x4> matrixBuffer;
15+
16+
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name output
17+
RWStructuredBuffer<float> output;
18+
19+
[numthreads(1, 1, 1)]
20+
void computeMain(uint3 tid : SV_DispatchThreadID)
21+
{
22+
float4 v = float4(1, 2, 3, 1);
23+
24+
float4x4 M = matrixBuffer;
25+
26+
float4 r = mul(v, M);
27+
28+
output[0] = r.x;
29+
output[1] = r.y;
30+
output[2] = r.z;
31+
output[3] = r.w;
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type: float
2+
11.000000
3+
22.000000
4+
33.000000
5+
1.000000
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// non-square-column-major.slang
2+
3+
// Note! This test doesn't work on CUDA or CPU targets, because both these targets ignore
4+
// row/column major setting, as well as they handle alignment differently.
5+
6+
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -compile-arg -O3 -xslang -matrix-layout-column-major -shaderobj
7+
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -xslang -matrix-layout-column-major -shaderobj
8+
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -output-using-type -xslang -matrix-layout-column-major -shaderobj
9+
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type -xslang -matrix-layout-column-major -shaderobj
10+
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -output-using-type -xslang -matrix-layout-column-major -shaderobj
11+
12+
// matrix<R, C>
13+
//TEST_INPUT:cbuffer(data=[1.0 0.0 10.0 0.0 0.0 1.0 20.0 0.0]):name matrixBuffer
14+
ConstantBuffer<float3x2> matrixBuffer;
15+
16+
//TEST_INPUT:ubuffer(data=[0 0], stride=4):out,name output
17+
RWStructuredBuffer<float> output;
18+
19+
[numthreads(1, 1, 1)]
20+
void computeMain(uint3 tid : SV_DispatchThreadID)
21+
{
22+
float3 v = float3(1, 2, 1);
23+
24+
float3x2 M = matrixBuffer;
25+
26+
float2 r = mul(v, M);
27+
28+
output[0] = r.x;
29+
output[1] = r.y;
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
type: float
2+
11.000000
3+
22.000000
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// non-square-row-major.slang
2+
3+
// Note! This test doesn't work on CUDA or CPU targets, because both these targets
4+
// assume matrices are tightly packed, whereas GPU targets align rows to 16 bytes.
5+
6+
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -compile-arg -O3 -xslang -matrix-layout-row-major -shaderobj
7+
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -xslang -matrix-layout-row-major -shaderobj
8+
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -output-using-type -xslang -matrix-layout-row-major -shaderobj
9+
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type -xslang -matrix-layout-row-major -shaderobj
10+
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -output-using-type -xslang -matrix-layout-row-major -shaderobj
11+
12+
13+
// matrix<R, C>
14+
//TEST_INPUT:cbuffer(data=[1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 10.0 20.0 0.0 0.0 ]):name matrixBuffer
15+
ConstantBuffer<float3x2> matrixBuffer;
16+
17+
//TEST_INPUT:ubuffer(data=[0 0], stride=4):out,name output
18+
RWStructuredBuffer<float> output;
19+
20+
[numthreads(1, 1, 1)]
21+
void computeMain(uint3 tid : SV_DispatchThreadID)
22+
{
23+
float3 v = float3(1, 2, 1);
24+
25+
float3x2 M = matrixBuffer;
26+
27+
float2 r = mul(v, M);
28+
29+
output[0] = r.x;
30+
output[1] = r.y;
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
type: float
2+
11.000000
3+
22.000000

tests/compute/row-major.slang

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// row-major.slang
2+
3+
//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -compile-arg -O3 -xslang -matrix-layout-row-major -shaderobj
4+
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -xslang -matrix-layout-row-major -shaderobj
5+
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -output-using-type -xslang -matrix-layout-row-major -shaderobj
6+
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type -xslang -matrix-layout-row-major -shaderobj
7+
8+
//TEST_INPUT:cbuffer(data=[1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 10.0 20.0 30.0 1.0]):name matrixBuffer
9+
ConstantBuffer<float4x4> matrixBuffer;
10+
11+
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name output
12+
RWStructuredBuffer<float> output;
13+
14+
[numthreads(1, 1, 1)]
15+
void computeMain(uint3 tid : SV_DispatchThreadID)
16+
{
17+
float4 v = float4(1, 2, 3, 1);
18+
19+
float4x4 M = matrixBuffer;
20+
21+
float4 r = mul(v, M);
22+
23+
output[0] = r.x;
24+
output[1] = r.y;
25+
output[2] = r.z;
26+
output[3] = r.w;
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type: float
2+
11.000000
3+
22.000000
4+
33.000000
5+
1.000000
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// cpu-resource-issue.slang
2+
3+
// Enable this test - and cpu C++ compilation of output fails.
4+
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -compile-arg -O3 -xslang -matrix-layout-column-major -shaderobj
5+
6+
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -output-using-type -compile-arg -O3 -xslang -matrix-layout-column-major -shaderobj
7+
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -xslang -matrix-layout-column-major -shaderobj
8+
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -dx12 -xslang -matrix-layout-column-major -shaderobj
9+
//DISABLE_TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type -xslang -matrix-layout-column-major -shaderobj
10+
11+
//TEST_INPUT:cbuffer(data=[1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 10.0 20.0 30.0 1.0]):name matrixBuffer
12+
ConstantBuffer<float4x4> matrixBuffer;
13+
14+
//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name rowOrderMatrixOutput
15+
RWStructuredBuffer<float> rowOrderMatrixOutput;
16+
17+
void writeRow(float4 v, int rowIndex)
18+
{
19+
int baseIndex = rowIndex * 4;
20+
21+
rowOrderMatrixOutput[baseIndex + 0] = v.x;
22+
rowOrderMatrixOutput[baseIndex + 1] = v.y;
23+
rowOrderMatrixOutput[baseIndex + 2] = v.z;
24+
rowOrderMatrixOutput[baseIndex + 3] = v.w;
25+
}
26+
27+
[numthreads(1, 1, 1)]
28+
void computeMain(uint3 tid : SV_DispatchThreadID)
29+
{
30+
float4 v = float4(1, 2, 3, 1);
31+
32+
float4x4 M = matrixBuffer;
33+
34+
float4 r = mul(v, M);
35+
36+
writeRow(M[0], 0);
37+
writeRow(M[1], 1);
38+
writeRow(M[2], 2);
39+
writeRow(M[3], 3);
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// missing-loc-on-assignment.slang
2+
3+
//DIAGNOSTIC_TEST:SIMPLE:-target hlsl -stage compute -entry computeMain
4+
5+
//TEST_INPUT:cbuffer(data=[1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 10.0 20.0 30.0 1.0]):name matrixBuffer
6+
ConstantBuffer<float4x4> matrixBuffer;
7+
8+
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name output
9+
RWStructuredBuffer<float> output;
10+
11+
[numthreads(1, 1, 1)]
12+
void computeMain(uint3 tid : SV_DispatchThreadID)
13+
{
14+
float4 v = float4(1, 2, 3, 1);
15+
16+
// Produces an error but not a location(!)
17+
float4 M = matrixBuffer;
18+
19+
float4 r = mul(v, M);
20+
21+
output[0] = r.x;
22+
output[1] = r.y;
23+
output[2] = r.z;
24+
output[3] = r.w;
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
result code = -1
2+
standard error = {
3+
(0): error 30019: expected an expression of type 'vector<float,4>', got 'matrix<float,4,4>'
4+
}
5+
standard output = {
6+
}

0 commit comments

Comments
 (0)