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

Binding arrays play nice with bounds checks #1855

Merged

Conversation

cwfitzgerald
Copy link
Member

Found an issue with binding indexing in the MSL backend when bounds checks were on.

This fixes the issue and adds a binding array bounds check policy that, for now, must be unchecked.

@cwfitzgerald cwfitzgerald force-pushed the binding-array-bounds-check-politeness branch from cc97ab4 to 1ac8dae Compare April 19, 2022 23:28
@kvark
Copy link
Member

kvark commented Apr 21, 2022

@jimblandy please review

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.

It looks to me like the generated MSL code isn't right.

src/proc/index.rs Outdated Show resolved Hide resolved
tests/out/msl/binding-arrays.msl Show resolved Hide resolved
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.

One question to check over, but otherwise, looks good to me! Thank you very much.

Comment on lines -3342 to +3355
Some(target) => match module.types[var.ty].inner {
crate::TypeInner::Image { .. } => target.texture.is_some(),
crate::TypeInner::Sampler { .. } => target.sampler.is_some(),
_ => target.buffer.is_some(),
},
Some(target) => {
let binding_ty = match module.types[var.ty].inner {
crate::TypeInner::BindingArray { base, .. } => {
&module.types[base].inner
}
ref ty => ty,
};
match *binding_ty {
crate::TypeInner::Image { .. } => target.texture.is_some(),
crate::TypeInner::Sampler { .. } => target.sampler.is_some(),
_ => target.buffer.is_some(),
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This seems like an unrelated fix. It's fine to include it in this PR, but if it has something to do with bounds checks, let me know, because I'm not understanding the patch.

Copy link
Member Author

@cwfitzgerald cwfitzgerald Apr 25, 2022

Choose a reason for hiding this comment

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

Ah yeah, sorry this should have been titled "fixes needed to get the binding indexing wgpu PR working" :)

tl;dr: Because of the change above this, it is now possible to get the type of binding array, and we need to "punch through" the binding array to find the actual type of binding we're looking at.

It's only related to bounds checks as this is code that is only hit when bounds checks are on.

@cwfitzgerald cwfitzgerald enabled auto-merge (squash) April 25, 2022 04:15
@cwfitzgerald cwfitzgerald merged commit 1aa9154 into gfx-rs:master Apr 25, 2022
@cwfitzgerald cwfitzgerald deleted the binding-array-bounds-check-politeness branch April 25, 2022 04:20
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.

3 participants