fix(naga spv-out): OpConstantComposite does not support flattening#9940
fix(naga spv-out): OpConstantComposite does not support flattening#9940andyleiserson wants to merge 2 commits into
OpConstantComposite does not support flattening#9940Conversation
There was a problem hiding this comment.
The whole idea of naga::proc::flatten_compose is to produce an iterator over actual components, not vector-typed ZeroValue expressions. So I think we have more bugs than this; I would expect most uses of flatten_compose to be wrong.
I think rather than adding a new function that finishes the job that flatten_compose left undone, we need to change flatten_compose to return some indication of "this component is zero".
|
Like, having enum FlattenedComponent {
Zero,
Expression(Handle<Expression>),
}and have And then we'd need to see what the call sites look like. |
|
Many places that
wgpu/naga/src/proc/constant_evaluator.rs Line 1439 in 5c6478a
wgpu/naga/src/proc/constant_evaluator.rs Line 2236 in 5c6478a Seems like these two are just broken (sorry to paste as image):
|

SPIR-V's
OpConstantCompositedoes not support flattening vector constructors likevec4(vec2(), 1, 1).flatten_composeunfortunately can't handle these for us, because (unlike a nested composite or splat) the component zero value may not be in the arena. So add a dedicated helper in the SPIR-V backend to handle this.The constant evaluator does have a function
eval_zero_value_and_splat, which is used when this kind of nested compose appears in a larger const-evaluatable context. But in the specific case here, the nested compose appeared as an argument to a non-const function call. The constant evaluator didn't trigger on that.Even if the constant evaluator did resolve this, unless we declare that it is invalid IR, the SPIR-V backend still also needs to be able handle it correctly.
Fix for Firefox bug https://bugzilla.mozilla.org/show_bug.cgi?id=1984765.
Testing
Adds snapshot tests.
Squash or Rebase? Squash
Checklist
wgpumay be affected behaviorally.CHANGELOG.mdentries for the user-facing effects of this change are present.