webgpu-native / webgpu-headers

**NOT STABLE YET!** See README.
https://webgpu-native.github.io/webgpu-headers/
BSD 3-Clause "New" or "Revised" License
394 stars 45 forks source link

WriteTexture doesn't need WGPUTextureDataLayout.offset #379

Closed kainino0x closed 6 days ago

kainino0x commented 1 month ago

While looking at some code in Blink I noticed that in C, there is no point in having WGPUTextureDataLayout.offset in wgpuQueueWriteTexture. It's there because (1) it matches JS and (2) we use the offset in WGPUImageCopyBuffer. However in C, it's possible to just offset the data pointer instead, with ptr + offset or &ptr[offset] (where offset is now in array elements, instead of bytes).

In webgpu.h we could remove this redundancy by moving offset out of WGPUTextureDataLayout into WGPUImageCopyBuffer. Is that worthwhile?

Kangz commented 1 month ago

IMHO it's probably not worthwhile, while a bit weird, it matches the JS API more and doesn't really have a cost associated with it.

kainino0x commented 1 month ago

It already doesn't match super well (because we take a raw pointer + length instead of a typed array), but it does still match better.

The place where this causes friction is in wire implementations, where it looks like you should send span(data, dataSize) but really you should not do this. Like, should dawn wire just do what you asked and copy the range you gave? Or should wire be smarter and avoid copying the part before the offset (so that logic moves from blink into dawn wire)?

Kangz commented 1 month ago

That seems like an implementation detail of dawn::wire? We didn't do it in dawn::wire because we didn't have the texture format in there at the time and didn't want to move complicated logic there. But now we could.

That said it seems somewhat irrelevant to this discussion since that's an optimization under the as-if rule.

kainino0x commented 2 weeks ago

Tentatively closing as I'd like to go with no change, but leaving the label to discuss if we want to reopen.

kainino0x commented 1 week ago

Nov 21 meeting:

kainino0x commented 1 week ago

On that tangent, see also:

kainino0x commented 6 days ago

Nov 25 meeting: