From 599129dea6930cf64a403e5e0dbd7cc7293df8af Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 26 Apr 2021 16:15:54 -0400 Subject: Matrix tests and assorted bug tests (#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 --- tests/compute/column-major.slang | 32 +++++++++++++++++ tests/compute/column-major.slang.expected.txt | 0 tests/compute/default-major.slang | 32 +++++++++++++++++ tests/compute/default-major.slang.expected.txt | 5 +++ tests/compute/non-square-column-major.slang | 30 ++++++++++++++++ .../non-square-column-major.slang.expected.txt | 3 ++ tests/compute/non-square-row-major.slang | 31 +++++++++++++++++ .../non-square-row-major.slang.expected.txt | 3 ++ tests/compute/row-major.slang | 27 +++++++++++++++ tests/compute/row-major.slang.expected.txt | 5 +++ tests/current-bugs/cpp-resource-issue.slang | 40 ++++++++++++++++++++++ tests/current-bugs/missing-loc-on-assignment.slang | 25 ++++++++++++++ .../missing-loc-on-assignment.slang.expected | 6 ++++ 13 files changed, 239 insertions(+) create mode 100644 tests/compute/column-major.slang create mode 100644 tests/compute/column-major.slang.expected.txt create mode 100644 tests/compute/default-major.slang create mode 100644 tests/compute/default-major.slang.expected.txt create mode 100644 tests/compute/non-square-column-major.slang create mode 100644 tests/compute/non-square-column-major.slang.expected.txt create mode 100644 tests/compute/non-square-row-major.slang create mode 100644 tests/compute/non-square-row-major.slang.expected.txt create mode 100644 tests/compute/row-major.slang create mode 100644 tests/compute/row-major.slang.expected.txt create mode 100644 tests/current-bugs/cpp-resource-issue.slang create mode 100644 tests/current-bugs/missing-loc-on-assignment.slang create mode 100644 tests/current-bugs/missing-loc-on-assignment.slang.expected (limited to 'tests') diff --git a/tests/compute/column-major.slang b/tests/compute/column-major.slang new file mode 100644 index 000000000..ae4c008e9 --- /dev/null +++ b/tests/compute/column-major.slang @@ -0,0 +1,32 @@ +// column-major.slang + +// Unfortunately CPU and CUDA only work with row layout, so they have to be disabled here. + +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -compile-arg -O3 -shaderobj +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -shaderobj +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -dx12 -shaderobj +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type -shaderobj +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -output-using-type -shaderobj + +// This data is in column major layout order.... +//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 + +ConstantBuffer matrixBuffer; + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name output +RWStructuredBuffer output; + +[numthreads(1, 1, 1)] +void computeMain(uint3 tid : SV_DispatchThreadID) +{ + float4 v = float4(1, 2, 3, 1); + + float4x4 M = matrixBuffer; + + float4 r = mul(v, M); + + output[0] = r.x; + output[1] = r.y; + output[2] = r.z; + output[3] = r.w; +} diff --git a/tests/compute/column-major.slang.expected.txt b/tests/compute/column-major.slang.expected.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tests/compute/default-major.slang b/tests/compute/default-major.slang new file mode 100644 index 000000000..743dbe656 --- /dev/null +++ b/tests/compute/default-major.slang @@ -0,0 +1,32 @@ +// default-major.slang + +// The default layout should be column. Unfortunately CPU and CUDA only work with row layout, so they have to be disabled here. + +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -compile-arg -O3 -shaderobj +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -shaderobj +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -dx12 -shaderobj +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type -shaderobj +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -output-using-type -shaderobj + +// This data is in column major layout order.... +//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 + +ConstantBuffer matrixBuffer; + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name output +RWStructuredBuffer output; + +[numthreads(1, 1, 1)] +void computeMain(uint3 tid : SV_DispatchThreadID) +{ + float4 v = float4(1, 2, 3, 1); + + float4x4 M = matrixBuffer; + + float4 r = mul(v, M); + + output[0] = r.x; + output[1] = r.y; + output[2] = r.z; + output[3] = r.w; +} diff --git a/tests/compute/default-major.slang.expected.txt b/tests/compute/default-major.slang.expected.txt new file mode 100644 index 000000000..1e24f3253 --- /dev/null +++ b/tests/compute/default-major.slang.expected.txt @@ -0,0 +1,5 @@ +type: float +11.000000 +22.000000 +33.000000 +1.000000 diff --git a/tests/compute/non-square-column-major.slang b/tests/compute/non-square-column-major.slang new file mode 100644 index 000000000..ae82d4818 --- /dev/null +++ b/tests/compute/non-square-column-major.slang @@ -0,0 +1,30 @@ +// non-square-column-major.slang + +// Note! This test doesn't work on CUDA or CPU targets, because both these targets ignore +// row/column major setting, as well as they handle alignment differently. + +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -compile-arg -O3 -xslang -matrix-layout-column-major -shaderobj +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -xslang -matrix-layout-column-major -shaderobj +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -output-using-type -xslang -matrix-layout-column-major -shaderobj +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type -xslang -matrix-layout-column-major -shaderobj +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -output-using-type -xslang -matrix-layout-column-major -shaderobj + +// matrix +//TEST_INPUT:cbuffer(data=[1.0 0.0 10.0 0.0 0.0 1.0 20.0 0.0]):name matrixBuffer +ConstantBuffer matrixBuffer; + +//TEST_INPUT:ubuffer(data=[0 0], stride=4):out,name output +RWStructuredBuffer output; + +[numthreads(1, 1, 1)] +void computeMain(uint3 tid : SV_DispatchThreadID) +{ + float3 v = float3(1, 2, 1); + + float3x2 M = matrixBuffer; + + float2 r = mul(v, M); + + output[0] = r.x; + output[1] = r.y; +} diff --git a/tests/compute/non-square-column-major.slang.expected.txt b/tests/compute/non-square-column-major.slang.expected.txt new file mode 100644 index 000000000..df7317d53 --- /dev/null +++ b/tests/compute/non-square-column-major.slang.expected.txt @@ -0,0 +1,3 @@ +type: float +11.000000 +22.000000 diff --git a/tests/compute/non-square-row-major.slang b/tests/compute/non-square-row-major.slang new file mode 100644 index 000000000..9562e37ea --- /dev/null +++ b/tests/compute/non-square-row-major.slang @@ -0,0 +1,31 @@ +// non-square-row-major.slang + +// Note! This test doesn't work on CUDA or CPU targets, because both these targets +// assume matrices are tightly packed, whereas GPU targets align rows to 16 bytes. + +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -compile-arg -O3 -xslang -matrix-layout-row-major -shaderobj +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -xslang -matrix-layout-row-major -shaderobj +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -output-using-type -xslang -matrix-layout-row-major -shaderobj +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type -xslang -matrix-layout-row-major -shaderobj +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -output-using-type -xslang -matrix-layout-row-major -shaderobj + + +// matrix +//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 +ConstantBuffer matrixBuffer; + +//TEST_INPUT:ubuffer(data=[0 0], stride=4):out,name output +RWStructuredBuffer output; + +[numthreads(1, 1, 1)] +void computeMain(uint3 tid : SV_DispatchThreadID) +{ + float3 v = float3(1, 2, 1); + + float3x2 M = matrixBuffer; + + float2 r = mul(v, M); + + output[0] = r.x; + output[1] = r.y; +} diff --git a/tests/compute/non-square-row-major.slang.expected.txt b/tests/compute/non-square-row-major.slang.expected.txt new file mode 100644 index 000000000..df7317d53 --- /dev/null +++ b/tests/compute/non-square-row-major.slang.expected.txt @@ -0,0 +1,3 @@ +type: float +11.000000 +22.000000 diff --git a/tests/compute/row-major.slang b/tests/compute/row-major.slang new file mode 100644 index 000000000..d0e76475b --- /dev/null +++ b/tests/compute/row-major.slang @@ -0,0 +1,27 @@ +// row-major.slang + +//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -compile-arg -O3 -xslang -matrix-layout-row-major -shaderobj +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -xslang -matrix-layout-row-major -shaderobj +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -output-using-type -xslang -matrix-layout-row-major -shaderobj +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type -xslang -matrix-layout-row-major -shaderobj + +//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 +ConstantBuffer matrixBuffer; + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name output +RWStructuredBuffer output; + +[numthreads(1, 1, 1)] +void computeMain(uint3 tid : SV_DispatchThreadID) +{ + float4 v = float4(1, 2, 3, 1); + + float4x4 M = matrixBuffer; + + float4 r = mul(v, M); + + output[0] = r.x; + output[1] = r.y; + output[2] = r.z; + output[3] = r.w; +} diff --git a/tests/compute/row-major.slang.expected.txt b/tests/compute/row-major.slang.expected.txt new file mode 100644 index 000000000..1e24f3253 --- /dev/null +++ b/tests/compute/row-major.slang.expected.txt @@ -0,0 +1,5 @@ +type: float +11.000000 +22.000000 +33.000000 +1.000000 diff --git a/tests/current-bugs/cpp-resource-issue.slang b/tests/current-bugs/cpp-resource-issue.slang new file mode 100644 index 000000000..13906ba95 --- /dev/null +++ b/tests/current-bugs/cpp-resource-issue.slang @@ -0,0 +1,40 @@ +// cpu-resource-issue.slang + +// Enable this test - and cpu C++ compilation of output fails. +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -compile-arg -O3 -xslang -matrix-layout-column-major -shaderobj + +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -output-using-type -compile-arg -O3 -xslang -matrix-layout-column-major -shaderobj +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -xslang -matrix-layout-column-major -shaderobj +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -dx12 -xslang -matrix-layout-column-major -shaderobj +//DISABLE_TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type -xslang -matrix-layout-column-major -shaderobj + +//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 +ConstantBuffer matrixBuffer; + +//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 +RWStructuredBuffer rowOrderMatrixOutput; + +void writeRow(float4 v, int rowIndex) +{ + int baseIndex = rowIndex * 4; + + rowOrderMatrixOutput[baseIndex + 0] = v.x; + rowOrderMatrixOutput[baseIndex + 1] = v.y; + rowOrderMatrixOutput[baseIndex + 2] = v.z; + rowOrderMatrixOutput[baseIndex + 3] = v.w; +} + +[numthreads(1, 1, 1)] +void computeMain(uint3 tid : SV_DispatchThreadID) +{ + float4 v = float4(1, 2, 3, 1); + + float4x4 M = matrixBuffer; + + float4 r = mul(v, M); + + writeRow(M[0], 0); + writeRow(M[1], 1); + writeRow(M[2], 2); + writeRow(M[3], 3); +} diff --git a/tests/current-bugs/missing-loc-on-assignment.slang b/tests/current-bugs/missing-loc-on-assignment.slang new file mode 100644 index 000000000..97b29b301 --- /dev/null +++ b/tests/current-bugs/missing-loc-on-assignment.slang @@ -0,0 +1,25 @@ +// missing-loc-on-assignment.slang + +//DIAGNOSTIC_TEST:SIMPLE:-target hlsl -stage compute -entry computeMain + +//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 +ConstantBuffer matrixBuffer; + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name output +RWStructuredBuffer output; + +[numthreads(1, 1, 1)] +void computeMain(uint3 tid : SV_DispatchThreadID) +{ + float4 v = float4(1, 2, 3, 1); + + // Produces an error but not a location(!) + float4 M = matrixBuffer; + + float4 r = mul(v, M); + + output[0] = r.x; + output[1] = r.y; + output[2] = r.z; + output[3] = r.w; +} diff --git a/tests/current-bugs/missing-loc-on-assignment.slang.expected b/tests/current-bugs/missing-loc-on-assignment.slang.expected new file mode 100644 index 000000000..021701be9 --- /dev/null +++ b/tests/current-bugs/missing-loc-on-assignment.slang.expected @@ -0,0 +1,6 @@ +result code = -1 +standard error = { +(0): error 30019: expected an expression of type 'vector', got 'matrix' +} +standard output = { +} -- cgit v1.2.3