这是indexloc提供的服务,不要输入任何密码
Skip to content

Error on viewFormat with no compatible usage? #4852

@toji

Description

@toji

Originally raised in #4746 (comment)

Should specifying a viewFormat that has no compatible usage defined on the texture trigger a validation error at texture creation time?

Example:

const t = device.createTexture({
  size: { width: 64, height: 64  },
  format: 'rgba8unorm',
  viewFormats: [ 'rgba8unorm-srgb' ],
  usage: GPUTextureUsage.STORAGE,
});

If we implemented this validation, the above would trigger an error because rgba8unorm-srgb cannot be used with STORAGE usage, which in turn means that you can't create a valid view with that format from this texture. If the texture was instead created with STORAGE | RENDER_ATTACHMENT usage it would not fail validation at texture creation time because even though STORAGE is still invalid to use with rgba8unorm-srgb you could still create a valid view with just the RENDER_ATTACHMENT usage.

It is worth noting that the validation proposed in #4426 and added in #4746 already ensures that views must be created with compatible formats and usages, so even without this validation there's no way to create invalid texture views. This instead would be an earlier error to help developers identify potential problems or performance pitfalls in their code.

Alternatively, browsers could be encouraged to surface warnings in this situation rather than surfacing it as an error, since the createTexture() call itself can succeed in this case and it's only later potential createView() calls using the viewFormat that would fail.

Metadata

Metadata

Assignees

Labels

apiWebGPU APIapi resolvedResolved - waiting for a change to the API specification

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions