mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-21 23:11:01 +01:00
Though not explicitly specified one way or the other, we have been informed by DirectX engineers that signed integer overflow may be undefined behaviour in some cases. To avoid this, we therefore bitcast signed operands to unsigned prior to performing addition, subtraction, or multiplication, then bitcast the result back to signed. As signed types are represented as two's complement, this gives the correct result whilst avoid any potential undefined behaviour. Unfortunately HLSL's bitcast functions asint() and asuint() only work for the 32-bit int and uint types. We therefore only apply this workaround for 32-bit signed arithmetic. Support for other bit widths could be added in the future, but extra care must be taken when converting from unsigned to signed to avoid undefined or implemented-defined behaviour.
19 lines
273 B
HLSL
19 lines
273 B
HLSL
struct type_1 {
|
|
int member;
|
|
};
|
|
|
|
RWByteAddressBuffer unnamed : register(u0);
|
|
|
|
void function()
|
|
{
|
|
int _e3 = asint(unnamed.Load(0));
|
|
unnamed.Store(0, asuint(asint(asuint(_e3) + asuint(int(1)))));
|
|
return;
|
|
}
|
|
|
|
[numthreads(1, 1, 1)]
|
|
void main()
|
|
{
|
|
function();
|
|
}
|