gpuweb/spirv-execution-env

Enumerate sources of undefined and indeterminate behaviour

dneto0 opened this issue · 4 comments

Issue gpuweb/gpuweb#34 was an investigation of sources of undefined and indeterminate behaviour in the SPIR-V core spec. The WebGPU environment spec for SPIR-V should call out those cases and recommend what an implementation should do about them.

It's also worth taking a second closer look, in case we missed something the first time around.

After #3 was merged, the following items from gpuweb/gpuweb#34 remain to be addressed in spirv-execution-env.md:

  • division by zero
  • (not in the old issue): signed integer division, of INT_MIN by -1. This is an overflow of the positive signed integers
  • arithmetic or logical shift by more than the size of the integer type
  • using derivatives outside of uniform control flow (for the derivative group of instructions)
  • (not in the old issue): image instructions that rely on an implicit derivative should be in uniform control flow (for the derivative group)
  • anything from GLSL.std.450 extended instruction set?

The old issue explicitly did not deal with floating point exceptional cases. But the environment spec should bound the behaviours.

Out of all of these, derivatives outside of uniform control flow is the one that significantly concerns me. Are the underlying implementations actually safe and using "undefined behaviour" for mere wrong results, or can they actually access arbitrary memory in that case (for example)? I've tried to look it up in the various specifications/documentations, but with very little success.