Unity-Technologies / HLSLcc

DirectX shader bytecode cross compiler
Other
854 stars 123 forks source link

Possible incorrect translation of OPCODE_AND #12

Open TiemoJung opened 7 years ago

TiemoJung commented 7 years ago

Hi,

it looks like that for GLSL the operation OPCODE_AND may be wrong under certain circumstances. In the case when it is turned into a mix call. The third parameter, the selector is a boolean but gets cast to an float, this seems to be wrong as the cast seems to trigger undefined behavior when feed to glslang to turn it into spir-v. it should either used directly if the target supports it (glsl 4.5?) or turned into an appropriate vector manually (or don't use mix at all).

strandborg commented 7 years ago

Hi, can you provide a repro hlsl shader that triggers this please?

TiemoJung commented 7 years ago

Hi,

it looks like that this is probably a driver problem, the resulting spir-v is valid but as it seems the driver has troupe handling a sequence of select (convert bool to float) and mix correctly.

TiemoJung commented 7 years ago

Either way, it would be an optimization to use the bool directly instead of casting it to float (it results in removal of the mix call if turned into spir-v as example). Not sure since which version the boolean selector is allowed, at least 4.4 allows it.