From 9a231a5efb0ddce635e7e40c2d5b086ff4bd389a Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Thu, 12 Oct 2017 10:30:48 -0700 Subject: Do loop fix (#209) * Bug fix: emit logic for `do` loops This case was never tested, and I was outputting some garbage characters. This comit fixes the codegen and adds a test case. * Bug fix: make sure to pass through `[allow_uav_condition]` This also fixes the standard library definition of `IncrementCounter()` so that it returns a `uint` instead of `void`. --- tests/bugs/do-loop.hlsl | 35 ++++++++++++++++++++++++++++ tests/hlsl/simple/allow-uav-conditional.hlsl | 19 +++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 tests/bugs/do-loop.hlsl create mode 100644 tests/hlsl/simple/allow-uav-conditional.hlsl (limited to 'tests') diff --git a/tests/bugs/do-loop.hlsl b/tests/bugs/do-loop.hlsl new file mode 100644 index 000000000..eea62e92a --- /dev/null +++ b/tests/bugs/do-loop.hlsl @@ -0,0 +1,35 @@ +//TEST:COMPARE_HLSL: -profile vs_5_0 -target dxbc-assembly + +// Check output for `do` loops + +cbuffer C : register(b0) +{ + int n; +}; + +float4 main() : SV_Position +{ + float4 x = 0; + int i = n; + { + do + { + x = (x + (float)1) * x; + + // Note(tfoley): The "right" thing here would be + // `i--`, but that leads to a subtle difference + // in the final code between just invokeing `fxc` + // and invoking it on the Slang-generated output + // (despite the generated HLSL for this line being + // identical, modulo some `#line` directives). + // + // I'm using a binary operator that will yield + // the same code with its operands swapped, just + // to work around it. A better long-term fix + // is to have this test be an end-to-end test + // that we execute. + i = i*i; + } while((bool) i); + } + return x; +} diff --git a/tests/hlsl/simple/allow-uav-conditional.hlsl b/tests/hlsl/simple/allow-uav-conditional.hlsl new file mode 100644 index 000000000..3da239860 --- /dev/null +++ b/tests/hlsl/simple/allow-uav-conditional.hlsl @@ -0,0 +1,19 @@ +//TEST:COMPARE_HLSL: -profile cs_5_0 -target dxbc-assembly + +// Check output for `[allow_uav_conditional]` + +RWStructuredBuffer gBuffer : register(u0); + +[numthreads(16,1,1)] +void main( + uint tid : SV_DispatchThreadID) +{ + uint index = tid; + + [allow_uav_condition] + while(gBuffer[index] != 0) + { + index = gBuffer[index]; + gBuffer[index]--; + } +} -- cgit v1.2.3