Open kayru opened 6 years ago
For SPIR-V CodeGen, to properly understand whether we are barrier'ing in varying control flow, a bunch of transformations (like const evaluation & folding, etc.) should be applied first. We leverage SPIRV-Tools to do the transformations. So I feel this is more suitable to happen in SPIRV-Tools validator.
@dneto0 @alan-baker
Yes, I think this would be generally useful as a SPIR-V validation step. But the messages would be terrible (today) since we don't carry source level debug info into SPIR-V. Well, at best we could carry line info which might not be too bad. Also, optimizations are not set up to really track debug info.
Whatever path we take for DXC would also apply to Glslang. E.g. if we do this in SPIR-V validation then it would cover both DXC and glslang.
I could see a useful feature in a front end like DXC where you can detect control dependence based on an expression that is known to be varying, and issue that as a warning. Because you don't have precise value information you get some false positives as well, so at best it's a warning.
@antiagainst this feature is not specific to SPIR-V. Such validation is also useful/desired for DXIL path.
If we had uniformity analysis we could look into solving this in clang. Related microsoft/hlsl-specs#246
FXC HLSL compiler has a useful validation feature that catches invalid synchronization, such as barriers in varying flow control.
Consider the following example HLSL shader:
FXC reports the following error:
It would be very useful to get similar analysis and error reporting in DXC.
One can try using different compilers (FXC, DXC and glslang) here: http://shader-playground.timjones.io/fe2ad3d9372d4a20f0f7de065e95e139
A similar issue is filed for glslang here: https://github.com/KhronosGroup/glslang/issues/1389