Description
Found while trying to compact universally in process_overrides
for #7638.
This code adjusts emit statements by adjusting the beginning and ending handles for the range. This is correct in cases where expressions have been removed from the module but are otherwise unchanged, i.e. when the range for the emit has shifted backwards. It is not correct if constant evaluation has replaced an expression handle in the range with another handle located elsewhere in the handle space.
A test case for this is the snoise
function in the water example:
Validation of the module at the conclusion of process_overrides
fails with:
Function [4] 'snoise' is invalid:
Expression [90] can't be introduced - it's already in scope
This occurs because there are multiple emit statements including expression [90]
.
Note that this shader does not contain any overrides. So there is a question why process_overrides is rewriting expressions. The reason why is that constant evaluation of let
statements is inhibited during lowering because (quoting this):
The WGSL spec says that any expression that refers to a
let
-bound variable is not a const expression. This affects when errors must be reported, so we can't even treat suitablelet
bindings as constant as an optimization.
However, this same inhibition is not applicable in process_overrides. Perhaps it should be. There are a few possible fixes/changes that could be made here:
- Inhibit constant evaluation of let statements in process_overrides. Regardless of anything else, this may be necessary for the same reason that it is inhibited during lowering.
- Skip constant evaluation entirely in process_overrides if the module does not contain overrides, possibly skip everything in process_overrides except the compaction. (This change is included in [naga] Always compact the module in process_overrides #7795.)
- Fix the logic that adjusts emit statements. I think a problem similar to the above could arise from resolution of override expressions, so while the previous two items might fix this specific case, I don't think they are a complete solution.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status