software-mansion / TypeGPU

TypeGPU is a TypeScript library that enhances the WebGPU API, allowing resource management in a type-safe, declarative way.
http://typegpu.com
MIT License
82 stars 0 forks source link

Fix write size bug #309

Closed reczkok closed 1 week ago

reczkok commented 1 week ago

Description in #307

closes #307

iwoplaza commented 1 week ago

I am wondering if we could simplify this fix by always allocating a buffer rounded up to the alignment of the data-type. This would remove the need to check if the type we are writing to is a primitive, but would allocate more memory than necessary in some cases.

reczkok commented 1 week ago

The only case when this would make a difference is when we have a buffer of just vec3. I don't think this would be a big deal but this would also mean our vec3 buffers are not the same size as WebGPU's. I think this could lead to some migration bugs.

iwoplaza commented 1 week ago

What if we always create buffers that are aligned, but write the minimum amount of bytes (unaligned). This should cover the case of any existing WebGPU buffer, and our own allocations. Would this raise any WebGPU errors?

reczkok commented 1 week ago

I don't think there would be any errors. Both writeBuffer() and copyBufferToBuffer() let us specify the size in bytes so there should be no problem with that.