diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2019-09-18 13:20:22 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-09-18 13:20:22 -0700 |
| commit | a431d4f6da9e463c349c2e3819e87a83c8f2e043 (patch) | |
| tree | 08c10331608d0483dc89b5a0abd3ed9cc6878a75 /tests | |
| parent | a4c7cf32872c8bb191ee78ed91887a66f0b8b0f1 (diff) | |
Clean up some behavior of operator% (#1060)
Work on #1059
The `%` operator in the Slang implementation had several issues, and this change tries to address some of them:
* Renamed most occurences of "mod" describing this operator to be "rem" for "remainder" to better match its semantics in HLSL
* Split the operator into distinct integer and floating-point variants (`IRem` and `FRem`) to simplify having different codegen for the two
* Added floating-point variants of `operator%` and `operator%=` to the stdlib.
* Added custom C++ codegen for `kIROp_FRem` such that it maps to the standard C/C++ `remainder()` function
* Added custom GLSL codegen so that `kIROp_FRem` maps to the GLSL `mod()` function (which isn't correct...)
* Added a test case to confirm that D3D11, D3D12, and CPU targets all agree on the definition of floating-point `%`
* Fixed `render-test-tool` to allow a negative integer in a `data=...` specification. This didn't end up being used in the final test, but still seems like a good fix.
* Added a customized baseline for the Vulkan flavor of that test to confirm that we are *not* compiling correctly to SPIR-V just yet
Addressing the correctness of the output for GLSL/SPIR-V will have to come as a later change given that the operation we want is not exposed directly by unextended GLSL.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/compute/frem.slang | 29 | ||||
| -rw-r--r-- | tests/compute/frem.slang.2.expected.txt | 4 | ||||
| -rw-r--r-- | tests/compute/frem.slang.expected.txt | 4 |
3 files changed, 37 insertions, 0 deletions
diff --git a/tests/compute/frem.slang b/tests/compute/frem.slang new file mode 100644 index 000000000..60012ea1e --- /dev/null +++ b/tests/compute/frem.slang @@ -0,0 +1,29 @@ +// frem.slang + +//TEST(compute):COMPARE_COMPUTE: +//TEST(compute):COMPARE_COMPUTE:-cpu +//TEST(compute):COMPARE_COMPUTE:-vk + +// Test uses of floating-point `%` operator. + +RWStructuredBuffer<float> gInput; +//TEST_INPUT:ubuffer(data=[2.0 1.0 5.0 2.0 2.0 -4.0 -5.0 2.0], stride=4):dxbinding(0),glbinding(0),name=gInput + +int test(int inVal) +{ + float a = gInput[inVal*2]; + float b = gInput[inVal*2 + 1]; + return int(a % b); +} + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(1),glbinding(1),out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint tid = dispatchThreadID.x; + int inVal = tid; + int outVal = test(inVal); + outputBuffer[tid] = outVal; +}
\ No newline at end of file diff --git a/tests/compute/frem.slang.2.expected.txt b/tests/compute/frem.slang.2.expected.txt new file mode 100644 index 000000000..f22b9c805 --- /dev/null +++ b/tests/compute/frem.slang.2.expected.txt @@ -0,0 +1,4 @@ +0 +1 +FFFFFFFE +1 diff --git a/tests/compute/frem.slang.expected.txt b/tests/compute/frem.slang.expected.txt new file mode 100644 index 000000000..bafada4d1 --- /dev/null +++ b/tests/compute/frem.slang.expected.txt @@ -0,0 +1,4 @@ +0 +1 +2 +FFFFFFFF |
