gpu: fix getMappedRange size alignment #223
No reviewers
Labels
No labels
CI
all
basisu
blog
bug
build
contributor-friendly
core
correctness
deferred
dev
direct3d-headers
docs
driver-os-issue
duplicate
dxcompiler
editor
examples
experiment
feature-idea
feedback
flac
freetype
gamemode
gkurve
glfw
gpu
gpu-dawn
harfbuzz
help welcome
in-progress
infrastructure
invalid
libmach
linux-audio-headers
long-term
mach
mach.gfx
mach.math
mach.physics
mach.testing
model3d
needs-triage
object
opengl-headers
opus
os/linux
os/macos
os/wasm
os/windows
package-manager
priority
proposal
proposal-accepted
question
roadmap
slipped
stability
sysaudio
sysgpu
sysjs
validating-fix
vulkan-zig-generated
wayland-headers
website
wontfix
wrench
www
x11-headers
xcode-frameworks
zig-update
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
hexops/mach!223
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix-mapped-range"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
rationale:
user needs to align buffer on creation, as in
so
size == sizeOf(T) * lenmight not always hold true.on
getMappedRangerequest, there is no way to specifythat size was manually aligned, and using the function directly
with realigned size gives extremely unhelpful error:
it seems, requested size must match size specified on creation exactly.
so this commit does exactly that. aligns buffer size to 4 - something
that user must have done already if this point is reached.
aligned buffer sizes stay unchanged.
the whole point is to reduce mental load for the user and prevent hacks
and workarounds for corner cases. original issue originated with
having u16 index buffer array with odd number of elements, which is a
perfectly valid thing to have.
it would be best to also auto align size on buffer creation to not force
user to know such obscure implementation details and learn magic numbers.
technically speaking, buffer size must be at least 4, so might want to
size.max(4)or something similar, but i'm not sure how practical this is - creating buffer with size less than 4.also, 4 is a magic number, so might define it more officially. wgpu.rs defines it as a constant
COPY_BUFFER_ALIGNMENTfor the whole crateThank you @d3m1gd! This looks like a good improvement over the status quo today, and so I've immediately merged this.
I think that we may need to do more here to be completely correct, though:
COPY_BUFFER_ALIGNMENTis not exposed through https://github.com/webgpu-native/webgpu-headers/blob/main/webgpu.h and so this makes me wonder if4is always the right alignment or not.minUniformBufferOffsetAlignmentandminStorageBufferOffsetAlignment, I'm not sure how they relate yet.I will dig into these further / reach out to the Dawn authors for clarification, unless you beat me to it :)