Fix required immediate slots calculation and panics when slots overflow#9725
Fix required immediate slots calculation and panics when slots overflow#9725beicause wants to merge 6 commits into
Conversation
1393ae7 to
4a415f4
Compare
immediate_slots_required and panic when immediate size overflows 256 bytes
immediate_slots_required and panic when immediate size overflows 256 bytesimmediate_slots_required and panic when var<immediate> size overflows 256 bytes
12034a7 to
13ce0e8
Compare
13ce0e8 to
16a0228
Compare
immediate_slots_required and panic when var<immediate> size overflows 256 bytes| pub const fn from_range( | ||
| offset: u32, | ||
| size_bytes: u32, | ||
| ) -> Result<Self, ImmediateSlotsOverflowError> { |
There was a problem hiding this comment.
It might be simpler to use a BitVec to store the immediate slots so we don't have to plumb this error everywhere.
Or maybe just say that Naga's "Maximum byte-size of an immediate data variable." is 256 B, and reject such modules in validation.
A third option might be to represent the invalid state internally in ImmediateSlots, so it can can have impl Default and the structs that use it can derive Default. (With a type parameter for error or Infallible, if needed.) But I think one of the other options is probably simpler.
There was a problem hiding this comment.
bit_vec::BitVec is heap allocated thus it's not suitable for this.
naga itself doesn't use ImmediateSlots. It only used in wgpu-core.
There was a problem hiding this comment.
naga itself doesn't use
ImmediateSlots. It only used inwgpu-core
True. I was thinking of oversize immediates as something naga might want to support as valid WGSL for the interface reflection, even if not supported by wgpu or any actual implementation. But there's really no point in that.
But then I feel like it makes even less sense to plumb around ImmediateSlotsOverflowError and break derived Defaults for this case. Or put differently, it's weird for the error ImmediateSlotsOverflowError to only ever be unwrapped, never reported to a user.
What do you think about beicause/wgpu@fix-naga-immediate-slots-required...andyleiserson:jj-push-urxm? (We could also remove the overflow error, or not. I'm okay with the way it's used here, it's the way it's used in wgpu-core that bothers me.)
| pub const fn from_range( | ||
| offset: u32, | ||
| size_bytes: u32, | ||
| ) -> Result<Self, ImmediateSlotsOverflowError> { |
There was a problem hiding this comment.
naga itself doesn't use
ImmediateSlots. It only used inwgpu-core
True. I was thinking of oversize immediates as something naga might want to support as valid WGSL for the interface reflection, even if not supported by wgpu or any actual implementation. But there's really no point in that.
But then I feel like it makes even less sense to plumb around ImmediateSlotsOverflowError and break derived Defaults for this case. Or put differently, it's weird for the error ImmediateSlotsOverflowError to only ever be unwrapped, never reported to a user.
What do you think about beicause/wgpu@fix-naga-immediate-slots-required...andyleiserson:jj-push-urxm? (We could also remove the overflow error, or not. I'm okay with the way it's used here, it's the way it's used in wgpu-core that bothers me.)
Co-authored-by: Andy Leiserson <aleiserson@mozilla.com>
Connections
Immediates issue: #8556
Description
Fixes Naga
immediate_slots_requiredcalculation is incorrect #9724Fixes panic when
var<immediate>is larger than 256 bytes / the bitmask overflows.Testing
For 1, test with CTS
webgpu:api,validation,encoding,programmable,pipeline_immediate:required_slots_set:*For 2, test with CTS
webgpu:api,validation,pipeline,immediates:*.Squash or Rebase?
Squash
Checklist
wgpumay be affected behaviorally.CHANGELOG.mdentries for the user-facing effects of this change are present.