-
Notifications
You must be signed in to change notification settings - Fork 342
Description
In the current texture swizzle proposal, a non-default swizzle is not allowed on a texture view that has usage RENDER_ATTACHMENT
or STORAGE_BINDING
. I'm curious if it would be better to move that restriction and make it so:
- a view passed as a colorAttachment or depthStencilAttachment or resolveTarget to
beginRenderPass
must have the default swizzle - a view bound to a storage texture binding in a bind group must have the default swizzle.
As the proposal is now, if you declare a texture with either RENDER_ATTACHMENT
or STORAGE_BINDING
then anytime you call createView
with a swizzle you have to remember to remove those usages or you'll get a validation error. This is extra work for the user
const texture = device.createTexture({
format: 'rgba8unorm',
size,
usage: GPUTextureUsage.TEXTURE_BINDING |
GPUTextureUsage.STORAGE_BINDING |
GPUTextureUsage.RENDER_ATTACHMENT,
});
const bindGroup = device.createBindGroup({
layout,
entries: [
{ binding: 0, resource: texture.createView({ swizzle: nonDefaultSwizzle }), // <======= ERROR!
],
});
On the other hand, if we switched to the validation as suggested above then, in general, you don't have to remember this detail. You'll only get an error if you try to use a swizzle on a storage binding or a render pass attachment. You won't get an error in the common usecase.
This doesn't seem like it has any big performance difference, but it makes it easier to use swizzles. They end up just working more often than the current proposal.