MSAA troubles with SDL3_GPU

Hey! I’m one of the people working on isle-portable, which utilises the new SDL_GPU feature introduced with SDL3. We have it set up as one of the possible 3D renderers to use, alongside OpenGL (and ES), and a software renderer. The OpenGL renderers currently have support for MSAA, however, the SDL_GPU renderer currently does not. I have been attempting to implement it, however I have largely been unsuccessful. There appears to be little documentation on the topic, unfortunately, and what I have found has not been successful.

As part of the render process, we create a SDL_GPUGraphicsPipelineCreateInfo, which has multisample_state. I created a SDL_GPUMultisampleState and set the sample_count there, and then set multisample_state to this SDL_GPUMultisampleState. While this “worked”, any sample_count values other than SDL_GPU_SAMPLECOUNT_1 result in broken visuals.

I admit, I don’t completely understand the rendering code, however we do create several SDL_GPUTextureCreateInfo objects, each of which contains a sample_count. However, changing textureInfo.sample_count in Direct3DRMSDL3GPURenderer::Resize to a value other than SDL_GPU_SAMPLECOUNT_1 results in flickering visuals when the window is resized, and does not actually result in antialiasing.

Any help on this matter would be greatly appreciated!

Kind regards,
@VoxelTek

1 Like

For textures, the sample count only needs to be higher than 1 if it’s being used as a render target and you’re using MSAA. I assume it needs to match the sample count in your graphics pipeline.

You need an MSAA resolve texture with a sample count of 1, and you have to specify it in your SDL_GPUColorTargetInfo as the resolve_texture when creating your render pass (make sure you also set the store op to SDL_GPU_STOREOP_RESOLVE).

Don’t set the swapchain texture as your color target texture. Use a render target texture with the same sample count as your graphics pipeline, and specify that as your color target for your render pass.

When your render pass is complete, you need to blit the resolve texture to your swapchain texture.

Look at TriangleMSAA.c in the SDL GPU examples