Skip to content

[naga] Remove non-essential override references via compaction #7703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from

Conversation

andyleiserson
Copy link
Contributor

@andyleiserson andyleiserson commented May 19, 2025

Adds a mode to compaction that removes unused functions, global variables, and named types and overrides. This mode is used everywhere except the compaction at the end of lowering, where it is important to preserve unused items for type checking and other validation of the module.

Pruning all but the active entry point and then compacting makes process_overrides tolerant of missing values for overrides that are not used by the active entry point.

Fixes #5885

This change also removes the compact feature from naga (enables the associated code unconditionally) due to the new use of compaction for overrides and lack of clear justification for the feature flag. See the first comment for more discussion.

Testing
Adds several cases in the validation test to verify that compaction removes references to non-essential overrides. Also enables the relevant CTS tests, which are now passing.

Squash or Rebase? Squash

Important TODOs

  • The call to compact within the benchmark added by Update naga benchmarks and add a compaction benchmark #7715 needs to updated with the 2nd argument in this PR.
  • This change should have two changelog entries: one for the overrides, and one for removal of the compact feature (assuming that's what we do).

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.

@andyleiserson
Copy link
Contributor Author

andyleiserson commented May 19, 2025

There is a question what to do about the compact feature. Currently wgsl-in requires compact, so in many environments it is already required. But when wgsl-in is not set, we need a strategy for controlling the use of compaction in process_overrides:

  1. Remove the compact feature and build the associated functionality unconditionally, as this PR currently does.
  2. Make process_overrides conditional upon the compact feature, and arrange for the feature to be set when necessary. (A change would be needed to the no-features clippy runs, because wgpu-hal uses process_overrides, but does not enable compact.)
  3. Make process_overrides available unconditionally, but when built without the compact feature, specifying all overrides is required.
  4. Make process_overrides conditional upon a new feature (overrides?) which would depend on compact.

I have listed in my order of preference, but I don't have all the context about use cases and build size concerns that might justify one of my non-preferred options.

let (module, info) = naga::back::pipeline_constants::process_overrides(
module,
info,
None,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It already came in useful to be able to pass the actual entry point here, and I have the changes to do that, but unless there's a desire to have them in this PR, I'll hold them for a follow-up so that this one doesn't get any bigger.

@andyleiserson
Copy link
Contributor Author

Some performance data: compacting all of the wgsl snapshot tests, with the reachability changes (#7674), before this change:

compact/shader: compact time:   [298.90 µs 299.67 µs 300.65 µs]
                        thrpt:  [472.03 MiB/s 473.57 MiB/s 474.78 MiB/s]

After this change, with !preserve_unused:

compact/shader: compact time:   [336.43 µs 337.32 µs 338.28 µs]
                        thrpt:  [419.06 MiB/s 420.25 MiB/s 421.37 MiB/s]
                 change:
                        time:   [+12.296% +12.679% +13.089%] (p = 0.00 < 0.05)
                        thrpt:  [-11.574% -11.253% -10.950%]
                        Performance has regressed.

Without the reachability changes, after this change, with !preserve_unused:

compact/shader: compact time:   [194.58 µs 195.04 µs 195.50 µs]
                        thrpt:  [691.40 MiB/s 693.02 MiB/s 694.64 MiB/s]

Performance of other stages (with this change; wgsl-in includes a compaction and is ~1% slower, validation and hlsl-out are unchanged):

front/shader: wgsl-in   time:   [8.8573 ms 8.8659 ms 8.8749 ms]
                        thrpt:  [21.790 MiB/s 21.812 MiB/s 21.833 MiB/s]
validate/shader: validation
                        time:   [719.47 µs 720.31 µs 721.13 µs]
                        thrpt:  [268.17 MiB/s 268.47 MiB/s 268.79 MiB/s]
back/shader: hlsl-out   time:   [1.4870 ms 1.5040 ms 1.5299 ms]
                        thrpt:  [92.661 MiB/s 94.255 MiB/s 95.334 MiB/s]

@andyleiserson andyleiserson requested a review from crowlKats as a code owner May 22, 2025 21:06
@andyleiserson andyleiserson added the PR: run CTS PRs that should trigger the GitHub actions workflow for the WebGPU conformance test suite (CTS) label May 22, 2025
Adds a mode to compaction that removes unused functions, global
variables, and named types and overrides. This mode is used
everywhere except the compaction at the end of lowering, where
it is important to preserve unused items for type checking and
other validation of the module.

Pruning all but the active entry point and then compacting makes
`process_overrides` tolerant of missing values for overrides that are
not used by the active entry point.

Fixes gfx-rs#5885
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: run CTS PRs that should trigger the GitHub actions workflow for the WebGPU conformance test suite (CTS)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Naga shouldn't evaluate overrides unless they're used by the entry point
2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy