shader-slang / slang-rhi

Slang Render Hardware Interface
Other
25 stars 7 forks source link

WebGPU buffers of MemoryType::Upload can't be created #104

Open aleino-nv opened 1 week ago

aleino-nv commented 1 week ago

It is a WebGPU limitation that mappable buffers can't have any other usages. (The spec mentions this clearly.)

Currently in Slang-RHI, if a buffer with MemoryType::Upload is created then this constraint will be violated and buffer creation just fails.

aleino-nv commented 1 week ago

Example WebGPU error message:

WGPU error: Buffer usages (BufferUsage::(MapWrite|CopySrc|CopyDst)) is invalid. If a buffer usage contains 
BufferUsage::MapWrite the only other allowed usage is BufferUsage::CopySrc.
 - While calling [Device].CreateBuffer([BufferDescriptor "Unnamed buffer (size=96, elementSize=0, format=Unknown, 
 memoryType=Upload, usage=VertexBuffer, defaultState=VertexBuffer)"]).
aleino-nv commented 1 week ago

Thus far, when I've run into this it has turned out that MemoryType::Upload wasn't actually necessary -- the buffers typically get initialized with data at creation time and then never updated from the host.

Switching to MemoryType::DeviceLocal is often a viable workaround.