[naga] Process overrides selectively for the active entry point #7652
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is intended to fix #5885. As that issue says, a missing override value should only be an error if that value is needed by the active entry point. Currently, we raise an error if any override does not have at least one of a default value in the shader or a pipeline-specified value.
This adds an argument to
process_overrides
to specify the desired entry point, and then modifies override processing to tolerate missing overrides if (and hopefully only if) they are not used by that entry point.During that processing, lists are constructed of the functions, globals, and entry points that cannot be used due to missing overrides. The MSL backend is changed to skip over those items while writing.
Opening as a draft to confirm the approach. Still some work left:
An alternate approach would be to rewrite the module after evaluating overrides. This would enable a more robust validation pass to confirm there are no remaining overrides, and if structured based on writing items reachable from the entrypoint rather than excluding items referencing unresolved overrides, would allow the backend to write a more minimal shader (as @cwfitzgerald mentioned here). But the current rewriting process for override evaluation does not do what is needed -- it requires all overrides be resolved, so there's never a need to remove any functions, entry points, or globals. The existing compaction operation also does not provide what we need, because it treats all functions, entry points, and globals as implicitly used. (Also, we compact the module when initially parsing the shader, before applying per-pipeline overrides, so we'd either need to adjust when compaction happens, or add a new compaction pass.)
It is also possible for there to be types (override-sized arrays) that depend on an unresolved override. Array sizes are resolved in the backend (see #6787). I've currently made the msl backend silently skip emitting unresolved override-sized arrays, but it might be better to add a fourth member in
UnresolvedOverrides
for types, to make this safer.Testing
Adds tests to the naga validation suite and a snapshot test.
Squash or Rebase? Squash, tentatively
Checklist
cargo fmt
.taplo format
.cargo clippy --tests
. If applicable, add:--target wasm32-unknown-unknown
cargo xtask test
to run tests.CHANGELOG.md
entry.