Skip to content
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

[naga] resolve the size of override-sized arrays in backends #6787

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

Conversation

teoxoy
Copy link
Member

@teoxoy teoxoy commented Dec 19, 2024

Connections
Fixes #6722
Closes #6746

Description
Implements Jim's suggestion of resolving the size of override-sized arrays in backends so that we don't have to rebuild the types arena when processing overrides.

Testing
The new and existing tests passed.

@kentslaney
Copy link
Contributor

I'm confused about the status of this PR. In #6746 you said

I think it turned out well

but in #6788 you say

ultimately my attempt didn't work

Am I misreading or did something change? And where does this leave #6746?

@teoxoy
Copy link
Member Author

teoxoy commented Jan 6, 2025

but in #6788 you say

ultimately my attempt didn't work

In #6788 (comment) I was specifically talking about the issue Jim brought up in #6788; this PR doesn't touch the compactor.

And where does this leave #6746?

This PR obsoletes #6746.

Copy link
Member

@jimblandy jimblandy left a comment

Choose a reason for hiding this comment

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

Still reviewing.

size_expr,
)),
stride,
if old_size_expr != size_expr {
Copy link
Member

Choose a reason for hiding this comment

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

This could almost be a bug fix in its own right.

@kentslaney
Copy link
Contributor

@cwfitzgerald via Wgpu Users in reply to @junglie85

I assume I can parse a wgsl shaders through naga at build time to generate the module, then load that from disk (or embed bytes) at runtime? Does the module still need to be compiled to a specific backend format when creating the shader module from the naga module?

You can theoretically do it, as you can serialize a Naga module, but yeah we still need to translate it at runtime up hlsl/glsl/spirv/msl

Wouldn't this mean that it's better to resolve the size of override-sized arrays on the front end to minimize runtime overhead?

@cwfitzgerald
Copy link
Member

Eh, way more work than the gain - that's not a very common workflow.

@jimblandy jimblandy force-pushed the array-size-override branch from 998667d to bd02114 Compare January 15, 2025 01:43
@jimblandy
Copy link
Member

Is this an accurate description of the new process_overrides?

/// Replace all overrides in `module` with fully-evaluated constant expressions.
///
/// Given `pipeline_constants`, providing values for all overrides in
/// `module`:
///
/// - Replace all [`Override`] expressions with fully-evaluated
///   constant expressions.
///
/// - Replace all [`Override`][paso] array sizes with [`Expression`]
///   array sizes, referring to fully-evaluated constant expressions.
///
/// - Empty out the `module.overrides` arena.
///
/// Although the above is described in terms of changes to `module`'s
/// contents, this function only actually has shared access to
/// `module`. When changes are needed, this function clones `module`
/// and returns a [`Cow::Owned`] value. If no changes are needed, this
/// function returns a [`Cow::Borrowed`] value that just passes along
/// the original reference.
///
/// [`Override`]: Expression::Override
/// [paso]: crate::PendingArraySize::Override
/// [`Expression`]: crate::PendingArraySize::Expression

@teoxoy
Copy link
Member Author

teoxoy commented Jan 15, 2025

That does sound more accurate than the current doc. Do you want to push the commit? Or else I can fixup the first commit.

@jimblandy jimblandy force-pushed the array-size-override branch from bd02114 to b70b3e1 Compare January 15, 2025 17:08
@jimblandy jimblandy force-pushed the array-size-override branch from b70b3e1 to ed3cb16 Compare January 23, 2025 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[naga] panic when array override value already in arena
4 participants