Open hasali19 opened 2 years ago
The WGSL spec requires us to add some checks (akin to tint's) to handle undefined behavior of some operators and built-in functions which we aren't currently doing.
If implementing WGSL's division semantics happens to work around this FXC bug, that'd be great. The Naga HLSL back end code implementing the workaround should mention this FXC bug, so future developers will know we have unexpected constraints we're trying to meet.
Even once we fully implement WGSL's semantics for division by zero, there will still be times where wgpu simply can't anticipate what FXC will reject, and we will need to handle those cases as unexpected platform errors like "out of memory".
WGSL requires that division by zero in a runtime expression returns the left operand (surprising!). Implementing that check should clear this up on FXC, so we're re-purposing this issue to represent that project.
More specifically, this is what this issue is tracking:
If e2 is zero:
- It is a shader-creation error if e2 is a const-expression.
- It is a pipeline-creation error if e2 is an override-expression.
- Otherwise, e1.
The remainder operator also needs something similar.
I've found what seems to be another hlsl compilation failure caused by FXC. This one incorrectly reports a divide by zero error. Interestingly it's only rejected when the
divide
call is in a nested loop.Output:
Tint seems to be able to satisfy FXC by adding an extra check on
b
in thedivide
function: https://shader-playground.timjones.io/ac86c91d9f0f9b09c7668fa99534fe3f.