Files
wgpu/tests/out/hlsl/collatz.hlsl
T
Dzmitry Malyshau 81f4ff032f HLSL: rewrite handling of interface matching rules (#1276)
* [hlsl-out] flatten the entry point inputs

Previously, the logic was re-ordering the inputs according to the binding.
This breaks if one of the inputs is a struct. With this change, the struct
fields are also flattened into the fake entry point struct. We also
construct the original arguments at the beginning of the function.

* hlsl-out: completely separate the flattened IO structs from the original IR structs

Previously, we had heuristics to detect if a particular struct needs the fields
to be re-ordered. We'd re-order interface structs without layout, and the detection
was very fragile and easily wrong.
The new logic is spawning separate struct types if we need any re-ordering to happen.
It's solid, there are no heuristics.
2021-08-22 22:40:31 -04:00

38 lines
816 B
HLSL

RWByteAddressBuffer v_indices : register(u0);
uint collatz_iterations(uint n_base)
{
uint n = (uint)0;
uint i = 0u;
n = n_base;
while(true) {
uint _expr5 = n;
if ((_expr5 <= 1u)) {
break;
}
uint _expr8 = n;
if (((_expr8 % 2u) == 0u)) {
uint _expr13 = n;
n = (_expr13 / 2u);
} else {
uint _expr17 = n;
n = ((3u * _expr17) + 1u);
}
uint _expr21 = i;
i = (_expr21 + 1u);
}
uint _expr24 = i;
return _expr24;
}
[numthreads(1, 1, 1)]
void main(uint3 global_id : SV_DispatchThreadID)
{
uint _expr8 = asuint(v_indices.Load(global_id.x*4+0));
const uint _e9 = collatz_iterations(_expr8);
v_indices.Store(global_id.x*4+0, asuint(_e9));
return;
}