I'd like to use multisample anti-aliasing (MSAA) with my texture, but it's not working. When I create the texture, I set sampleCount
to 4:
const texture = device.createTexture({
size: [imageBitmap.width, imageBitmap.height],
format: 'rgba8unorm',
sampleCount: 4,
usage:
GPUTextureUsage.RENDER_ATTACHMENT |
GPUTextureUsage.TEXTURE_BINDING |
GPUTextureUsage.COPY_DST
});
The WGSL documentation says multisampled textures can't be read with samplers, so the fragment shader uses textureLoad
instead of textureSample
:
@group(0) @binding(1) var tex : texture_multisampled_2d<f32>;
@fragment
fn fragmentMain(fragData: DataStruct) -> @location(0) vec4f {
return textureLoad(tex, fragData.uvPos, 0);
}
When I run the application, I'm told "no matching call to textureLoad(texture_multisampled_2d, vec2, abstract-int)". Any ideas? Are there any examples that use MSAA textures?
You didn't show the definition of
DataStruct
but my guess isDataStruct.uvPos
is not a compatible type.textureLoad
takes an integer texel coordinate, not a floating point normalized texture coordinate liketextureSample
From the spec
Notice above,
C
, is onlyi32
oru32
, notf32
Otherwise, what are you trying to use MSAA textures for? The most common usage is for anti-aliasing but in that case you never read the texture directly. You just set it as a render target and set a non-MSAA texture as the resolve target like this answer