GPU: Allow multisample textures to be read (#15838)

(cherry picked from commit 1a2ba3b94d)
This commit is contained in:
Evan Hemsley
2026-09-14 12:12:41 -07:00
committed by cosmonaut
parent fd30f06df4
commit 42c75433d3
3 changed files with 47 additions and 5 deletions

View File

@@ -3391,6 +3391,9 @@ extern SDL_DECLSPEC void SDLCALL SDL_BindGPUIndexBuffer(
*
* The textures must have been created with SDL_GPU_TEXTUREUSAGE_SAMPLER.
*
* The textures being bound must have a matching type declared in the shader
* (2D, 3D, etc.). Multisample textures are not allowed.
*
* Be sure your shader is set up according to the requirements documented in
* SDL_CreateGPUShader().
*
@@ -3417,6 +3420,9 @@ extern SDL_DECLSPEC void SDLCALL SDL_BindGPUVertexSamplers(
* These textures must have been created with
* SDL_GPU_TEXTUREUSAGE_GRAPHICS_STORAGE_READ.
*
* The textures being bound must have a matching type declared in the shader
* (2D, 3D, 2DMS, etc.)
*
* Be sure your shader is set up according to the requirements documented in
* SDL_CreateGPUShader().
*
@@ -3464,6 +3470,9 @@ extern SDL_DECLSPEC void SDLCALL SDL_BindGPUVertexStorageBuffers(
*
* The textures must have been created with SDL_GPU_TEXTUREUSAGE_SAMPLER.
*
* The textures being bound must have a matching type declared in the shader
* (2D, 3D, etc.). Multisample textures are not allowed.
*
* Be sure your shader is set up according to the requirements documented in
* SDL_CreateGPUShader().
*
@@ -3490,6 +3499,9 @@ extern SDL_DECLSPEC void SDLCALL SDL_BindGPUFragmentSamplers(
* These textures must have been created with
* SDL_GPU_TEXTUREUSAGE_GRAPHICS_STORAGE_READ.
*
* The textures being bound must have a matching type declared in the shader
* (2D, 3D, 2DMS, etc.)
*
* Be sure your shader is set up according to the requirements documented in
* SDL_CreateGPUShader().
*
@@ -3712,6 +3724,9 @@ extern SDL_DECLSPEC void SDLCALL SDL_BindGPUComputePipeline(
*
* The textures must have been created with SDL_GPU_TEXTUREUSAGE_SAMPLER.
*
* The textures being bound must have a matching type declared in the shader
* (2D, 3D, etc.). Multisample textures are not allowed.
*
* Be sure your shader is set up according to the requirements documented in
* SDL_CreateGPUComputePipeline().
*
@@ -3738,6 +3753,9 @@ extern SDL_DECLSPEC void SDLCALL SDL_BindGPUComputeSamplers(
* These textures must have been created with
* SDL_GPU_TEXTUREUSAGE_COMPUTE_STORAGE_READ.
*
* The textures being bound must have a matching type declared in the shader
* (2D, 3D, 2DMS, etc.)
*
* Be sure your shader is set up according to the requirements documented in
* SDL_CreateGPUComputePipeline().
*

View File

@@ -1268,11 +1268,8 @@ SDL_GPUTexture *SDL_CreateGPUTexture(
failed = true;
}
if (createinfo->sample_count > SDL_GPU_SAMPLECOUNT_1 &&
(createinfo->usage & (SDL_GPU_TEXTUREUSAGE_SAMPLER |
SDL_GPU_TEXTUREUSAGE_GRAPHICS_STORAGE_READ |
SDL_GPU_TEXTUREUSAGE_COMPUTE_STORAGE_READ |
SDL_GPU_TEXTUREUSAGE_COMPUTE_STORAGE_WRITE))) {
SDL_assert_release(!"For multisample textures: usage cannot contain SAMPLER or STORAGE flags");
(createinfo->usage & SDL_GPU_TEXTUREUSAGE_COMPUTE_STORAGE_WRITE)) {
SDL_assert_release(!"For multisample textures: usage cannot contain COMPUTE_STORAGE_WRITE flag");
failed = true;
}
if (IsDepthFormat(createinfo->format) && (createinfo->usage & ~(SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET | SDL_GPU_TEXTUREUSAGE_SAMPLER))) {
@@ -2083,6 +2080,14 @@ void SDL_BindGPUVertexSamplers(
if (!((CommandBufferCommonHeader *)RENDERPASS_COMMAND_BUFFER)->ignore_render_pass_texture_validation)
{
CHECK_SAMPLER_TEXTURES
for (Uint32 i = 0; i < num_bindings; i += 1) {
TextureCommonHeader *texture_header = (TextureCommonHeader *)texture_sampler_bindings[i].texture;
if (texture_header->info.sample_count > SDL_GPU_SAMPLECOUNT_1)
{
SDL_assert_release(!"Multisample textures cannot be bound as samplers!");
}
}
}
for (Uint32 i = 0; i < num_bindings; i += 1) {
@@ -2196,6 +2201,14 @@ void SDL_BindGPUFragmentSamplers(
CHECK_SAMPLER_TEXTURES
}
for (Uint32 i = 0; i < num_bindings; i += 1) {
TextureCommonHeader *texture_header = (TextureCommonHeader *)texture_sampler_bindings[i].texture;
if (texture_header->info.sample_count > SDL_GPU_SAMPLECOUNT_1)
{
SDL_assert_release(!"Multisample textures cannot be bound as samplers!");
}
}
for (Uint32 i = 0; i < num_bindings; i += 1) {
((RenderPass *)render_pass)->fragment_sampler_bound[first_slot + i] = true;
}
@@ -2557,6 +2570,14 @@ void SDL_BindGPUComputeSamplers(
if (COMPUTEPASS_DEVICE->debug_mode) {
CHECK_COMPUTEPASS
for (Uint32 i = 0; i < num_bindings; i += 1) {
TextureCommonHeader *texture_header = (TextureCommonHeader *)texture_sampler_bindings[i].texture;
if (texture_header->info.sample_count > SDL_GPU_SAMPLECOUNT_1)
{
SDL_assert_release(!"Multisample textures cannot be bound as samplers!");
}
}
for (Uint32 i = 0; i < num_bindings; i += 1) {
((ComputePass *)compute_pass)->sampler_bound[first_slot + i] = true;
}

View File

@@ -3553,6 +3553,9 @@ static D3D12Texture *D3D12_INTERNAL_CreateTexture(
srvDesc.Texture3D.MipLevels = createinfo->num_levels;
srvDesc.Texture3D.MostDetailedMip = 0;
srvDesc.Texture3D.ResourceMinLODClamp = 0; // default behavior
} else if (createinfo->sample_count > SDL_GPU_SAMPLECOUNT_1) {
srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2DMS;
srvDesc.Texture2DMS.UnusedField_NothingToDefine = 0;
} else {
srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MipLevels = createinfo->num_levels;