Skip to content

Conversation

@inner-daemons
Copy link
Collaborator

@inner-daemons inner-daemons commented Nov 24, 2025

Connections
Closes #8565

Description
Here the spec discusses validation of multisample state for textures. It says the following:

["1d"](https://www.w3.org/TR/webgpu/#dom-gputexturedimension-1d)

        descriptor.[size](https://www.w3.org/TR/webgpu/#dom-gputexturedescriptor-size).[width](https://www.w3.org/TR/webgpu/#gpuextent3d-width) must be ≤ limits.[maxTextureDimension1D](https://www.w3.org/TR/webgpu/#dom-supported-limits-maxtexturedimension1d).

        descriptor.[size](https://www.w3.org/TR/webgpu/#dom-gputexturedescriptor-size).[height](https://www.w3.org/TR/webgpu/#gpuextent3d-height) must be 1.

        descriptor.[size](https://www.w3.org/TR/webgpu/#dom-gputexturedescriptor-size).[depthOrArrayLayers](https://www.w3.org/TR/webgpu/#gpuextent3d-depthorarraylayers) must be 1.

        descriptor.[sampleCount](https://www.w3.org/TR/webgpu/#dom-gputexturedescriptor-samplecount) must be 1.

        descriptor.[format](https://www.w3.org/TR/webgpu/#dom-gputexturedescriptor-format) must not be a [compressed format](https://www.w3.org/TR/webgpu/#compressed-format) or [depth-or-stencil format](https://www.w3.org/TR/webgpu/#depth-or-stencil-format).

["2d"](https://www.w3.org/TR/webgpu/#dom-gputexturedimension-2d)

        descriptor.[size](https://www.w3.org/TR/webgpu/#dom-gputexturedescriptor-size).[width](https://www.w3.org/TR/webgpu/#gpuextent3d-width) must be ≤ limits.[maxTextureDimension2D](https://www.w3.org/TR/webgpu/#dom-supported-limits-maxtexturedimension2d).

        descriptor.[size](https://www.w3.org/TR/webgpu/#dom-gputexturedescriptor-size).[height](https://www.w3.org/TR/webgpu/#gpuextent3d-height) must be ≤ limits.[maxTextureDimension2D](https://www.w3.org/TR/webgpu/#dom-supported-limits-maxtexturedimension2d).

        descriptor.[size](https://www.w3.org/TR/webgpu/#dom-gputexturedescriptor-size).[depthOrArrayLayers](https://www.w3.org/TR/webgpu/#gpuextent3d-depthorarraylayers) must be ≤ limits.[maxTextureArrayLayers](https://www.w3.org/TR/webgpu/#dom-supported-limits-maxtexturearraylayers).

["3d"](https://www.w3.org/TR/webgpu/#dom-gputexturedimension-3d)

        descriptor.[size](https://www.w3.org/TR/webgpu/#dom-gputexturedescriptor-size).[width](https://www.w3.org/TR/webgpu/#gpuextent3d-width) must be ≤ limits.[maxTextureDimension3D](https://www.w3.org/TR/webgpu/#dom-supported-limits-maxtexturedimension3d).

        descriptor.[size](https://www.w3.org/TR/webgpu/#dom-gputexturedescriptor-size).[height](https://www.w3.org/TR/webgpu/#gpuextent3d-height) must be ≤ limits.[maxTextureDimension3D](https://www.w3.org/TR/webgpu/#dom-supported-limits-maxtexturedimension3d).

        descriptor.[size](https://www.w3.org/TR/webgpu/#dom-gputexturedescriptor-size).[depthOrArrayLayers](https://www.w3.org/TR/webgpu/#gpuextent3d-depthorarraylayers) must be ≤ limits.[maxTextureDimension3D](https://www.w3.org/TR/webgpu/#dom-supported-limits-maxtexturedimension3d).

        descriptor.[sampleCount](https://www.w3.org/TR/webgpu/#dom-gputexturedescriptor-samplecount) must be 1.

        descriptor.[format](https://www.w3.org/TR/webgpu/#dom-gputexturedescriptor-format) must support ["3d"](https://www.w3.org/TR/webgpu/#dom-gputexturedimension-3d) textures according to [§ 26.1 Texture Format Capabilities](https://www.w3.org/TR/webgpu/#texture-format-caps).

Clearly, this disallows multisampling for 1D and 3D textures but allows it for 2D textures and 2D texture arrays. The existing validation only checked that an image with multisampling >1 had an array length or depth of 1. This incorrectly allowed 1D textures and 3D textures with depth 1 to have multisampling, and incorrectly blocked 2D texture arrays.

Testing
Nothing new

Squash or Rebase?
Squash

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • If this contains user-facing changes, add a CHANGELOG.md entry.

Copy link
Contributor

@andyleiserson andyleiserson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth a changelog mention.

#[error("Sample count {0} is not supported by format {1:?} on this device. The WebGPU spec guarantees {2:?} samples are supported by this format. With the TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES feature your device supports {3:?}.")]
InvalidSampleCount(u32, wgt::TextureFormat, Vec<u32>, Vec<u32>),
#[error("1D/3D texture multisample count must be 1, got {0}")]
Non2DMultisampledTexture(u32),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe InvalidMultisampledDimension to align with existing InvalidMultisampled* and Invalid*Dimension.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@andyleiserson
Copy link
Contributor

It seems like the CTS (webgpu:api,validation,createTexture:sample_count,1d_2d_array_3d:*) does not think multisampled array textures are valid.

Running that test locally, I also got an assertion failure in Metal. It looks like the wgpu-hal metal backend does not map the texture type properly for the array multisampled case.

@andyleiserson
Copy link
Contributor

incorrectly allowed ... 3D textures with depth 1 to have multisampling

This actually is not allowed by the code, because there are redundant checks related to multisampling. Depth-1 3D multisampled textures are disallowed in check_texture_dimension_size.

(I do think that redundant checks are bad because they result in exactly this kind of confusion, I filed #8568 about that.)

@inner-daemons
Copy link
Collaborator Author

@andyleiserson Thanks for the feedback. This might be more controversial than I assumed in that case, so maybe push it off until the next meeting or discuss further in the issue linked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Texture with multisample imposes too strict limits on depth_or_array_layers

2 participants