glslang/Test/hlsl.promote.atomic.frag
steve-lunarg 05f75142d6 HLSL: opcode specific promotion rules for interlocked ops
PR #577 addresses most but not all of the intrinsic promotion problems.
This PR resolves all known cases in the remainder.

Interlocked ops need special promotion rules because at the time
of function selection, the first argument has not been converted
to a buffer object.  It's just an int or uint, but you don't want
to convert THAT argument, because that implies converting the
buffer object itself.  Rather, you can convert other arguments,
but want to stay in the same "family" of functions.  E.g, if
the first interlocked arg is a uint, use only the uint family,
never the int family, you can convert the other args as you please.

This PR allows making such opcode and arg specific choices by
passing the op and arg to the convertible lambda.  The code in
the new test "hlsl.promote.atomic.frag" would not compile without
this change, but it must compile.

Also, it provides better handling of downconversions (to "worse"
types), which are permitted in HLSL.  The existing method of
selecting upconversions is unchanged, but if that doesn't find
any valid ones, then it will allow downconversions.  In effect
this always uses an upconversion if there is one.
2016-12-07 12:00:32 -07:00

18 lines
433 B
GLSL

RWBuffer<uint> s_uintbuff; // UINT RWBuffer ...
float4 main() : SV_Target
{
int Loc; // ... with INT variables
int Inc;
int Orig;
// This must select the uint flavor of SPIR-V atomic op, and promote
// the other arguments as required. The output value from the
// imageAtomicAdd AST will be converted to an int for 'Orig'.
InterlockedAdd(s_uintbuff[Loc], Inc, Orig);
return float4(0,0,0,0);
}