naga
naga copied to clipboard
Support dynamic indexing of by-value matrices, per WGSL
WGSL permits dynamically indexing matrices that are not stored in variables:
- A function parameter may be a matrix.
- A formal parameter expression does not evaluate to a pointer, but rather to the passed value.
- A matrix access expression does not require a pointer to the matrix.
At present, Naga does not permit this: typifier::ResolveContext::resolve
only permits indexing matrices behind pointers. This is in part because the only SPIR-V instructions that can take dynamic indices operate on pointers, not values. (The WGSL spec description of matrix access expressions mentions the SPIR-V OpCompositeAccess
, which isn't sufficient for the job; filed as gpuweb/gpuweb#1782.)
We solved the analogous problem for arrays in #723 by moving the value to a temporary variable, obtaining a pointer to that, and then indexing the pointer. It seems like the same tactic would work here.
https://github.com/gpuweb/gpuweb/pull/1801 removed this, so all dynamic accesses from wgsl must happen from a reference now which means that no local will be needed, closing.
The committee reversed its position, and the ability to index matrices and arrays dynamically was re-added in gpuweb/gpuweb#2427.