Fix GetSampler() bug for INDEX8 pixel format (#15099)

This commit is contained in:
Void Star Caster
2026-02-24 17:05:30 +01:00
committed by GitHub
parent 5212b82c4f
commit 4a4ae4a79d
5 changed files with 34 additions and 38 deletions

View File

@@ -2395,6 +2395,11 @@ static bool D3D11_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *
static ID3D11SamplerState *D3D11_GetSamplerState(D3D11_RenderData *data, SDL_PixelFormat format, SDL_ScaleMode scale_mode, SDL_TextureAddressMode address_u, SDL_TextureAddressMode address_v)
{
if (format == SDL_PIXELFORMAT_INDEX8) {
// We'll do linear sampling in the shader if needed
scale_mode = SDL_SCALEMODE_NEAREST;
}
Uint32 key = RENDER_SAMPLER_HASHKEY(scale_mode, address_u, address_v);
SDL_assert(key < SDL_arraysize(data->samplers));
if (!data->samplers[key]) {
@@ -2412,12 +2417,7 @@ static ID3D11SamplerState *D3D11_GetSamplerState(D3D11_RenderData *data, SDL_Pix
break;
case SDL_SCALEMODE_PIXELART: // Uses linear sampling
case SDL_SCALEMODE_LINEAR:
if (format == SDL_PIXELFORMAT_INDEX8) {
// We'll do linear sampling in the shader
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
} else {
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
}
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
break;
default:
SDL_SetError("Unknown scale mode: %d", scale_mode);

View File

@@ -2838,6 +2838,11 @@ static bool D3D12_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *
static D3D12_CPU_DESCRIPTOR_HANDLE *D3D12_GetSamplerState(D3D12_RenderData *data, SDL_PixelFormat format, SDL_ScaleMode scale_mode, SDL_TextureAddressMode address_u, SDL_TextureAddressMode address_v)
{
if (format == SDL_PIXELFORMAT_INDEX8) {
// We'll do linear sampling in the shader if needed
scale_mode = SDL_SCALEMODE_NEAREST;
}
Uint32 key = RENDER_SAMPLER_HASHKEY(scale_mode, address_u, address_v);
SDL_assert(key < SDL_arraysize(data->samplers));
if (!data->samplers_created[key]) {
@@ -2863,12 +2868,7 @@ static D3D12_CPU_DESCRIPTOR_HANDLE *D3D12_GetSamplerState(D3D12_RenderData *data
break;
case SDL_SCALEMODE_PIXELART: // Uses linear sampling
case SDL_SCALEMODE_LINEAR:
if (format == SDL_PIXELFORMAT_INDEX8) {
// We'll do linear sampling in the shader
samplerDesc.Filter = D3D12_FILTER_MIN_MAG_MIP_POINT;
} else {
samplerDesc.Filter = D3D12_FILTER_MIN_MAG_MIP_LINEAR;
}
samplerDesc.Filter = D3D12_FILTER_MIN_MAG_MIP_LINEAR;
break;
default:
SDL_SetError("Unknown scale mode: %d", scale_mode);

View File

@@ -790,6 +790,11 @@ static void SetViewportAndScissor(GPU_RenderData *data)
static SDL_GPUSampler *GetSampler(GPU_RenderData *data, SDL_PixelFormat format, SDL_ScaleMode scale_mode, SDL_TextureAddressMode address_u, SDL_TextureAddressMode address_v)
{
if (format == SDL_PIXELFORMAT_INDEX8) {
// We'll do linear sampling in the shader if needed
scale_mode = SDL_SCALEMODE_NEAREST;
}
Uint32 key = RENDER_SAMPLER_HASHKEY(scale_mode, address_u, address_v);
SDL_assert(key < SDL_arraysize(data->samplers));
if (!data->samplers[key]) {
@@ -803,16 +808,9 @@ static SDL_GPUSampler *GetSampler(GPU_RenderData *data, SDL_PixelFormat format,
break;
case SDL_SCALEMODE_PIXELART: // Uses linear sampling
case SDL_SCALEMODE_LINEAR:
if (format == SDL_PIXELFORMAT_INDEX8) {
// We'll do linear sampling in the shader
sci.min_filter = SDL_GPU_FILTER_NEAREST;
sci.mag_filter = SDL_GPU_FILTER_NEAREST;
sci.mipmap_mode = SDL_GPU_SAMPLERMIPMAPMODE_NEAREST;
} else {
sci.min_filter = SDL_GPU_FILTER_LINEAR;
sci.mag_filter = SDL_GPU_FILTER_LINEAR;
sci.mipmap_mode = SDL_GPU_SAMPLERMIPMAPMODE_LINEAR;
}
sci.min_filter = SDL_GPU_FILTER_LINEAR;
sci.mag_filter = SDL_GPU_FILTER_LINEAR;
sci.mipmap_mode = SDL_GPU_SAMPLERMIPMAPMODE_LINEAR;
break;
default:
SDL_SetError("Unknown scale mode: %d", scale_mode);

View File

@@ -1584,6 +1584,11 @@ static bool SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, c
static id<MTLSamplerState> GetSampler(SDL3METAL_RenderData *data, SDL_PixelFormat format, SDL_ScaleMode scale_mode, SDL_TextureAddressMode address_u, SDL_TextureAddressMode address_v)
{
if (format == SDL_PIXELFORMAT_INDEX8) {
// We'll do linear sampling in the shader if needed
scale_mode = SDL_SCALEMODE_NEAREST;
}
NSNumber *key = [NSNumber numberWithInteger:RENDER_SAMPLER_HASHKEY(scale_mode, address_u, address_v)];
id<MTLSamplerState> mtlsampler = data.mtlsamplers[key];
if (mtlsampler == nil) {
@@ -1596,14 +1601,8 @@ static id<MTLSamplerState> GetSampler(SDL3METAL_RenderData *data, SDL_PixelForma
break;
case SDL_SCALEMODE_PIXELART: // Uses linear sampling
case SDL_SCALEMODE_LINEAR:
if (format == SDL_PIXELFORMAT_INDEX8) {
// We'll do linear sampling in the shader
samplerdesc.minFilter = MTLSamplerMinMagFilterNearest;
samplerdesc.magFilter = MTLSamplerMinMagFilterNearest;
} else {
samplerdesc.minFilter = MTLSamplerMinMagFilterLinear;
samplerdesc.magFilter = MTLSamplerMinMagFilterLinear;
}
samplerdesc.minFilter = MTLSamplerMinMagFilterLinear;
samplerdesc.magFilter = MTLSamplerMinMagFilterLinear;
break;
default:
SDL_SetError("Unknown scale mode: %d", scale_mode);

View File

@@ -3870,6 +3870,11 @@ static bool VULKAN_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand
static VkSampler VULKAN_GetSampler(VULKAN_RenderData *data, SDL_PixelFormat format, SDL_ScaleMode scale_mode, SDL_TextureAddressMode address_u, SDL_TextureAddressMode address_v)
{
if (format == SDL_PIXELFORMAT_INDEX8) {
// We'll do linear sampling in the shader if needed
scale_mode = SDL_SCALEMODE_NEAREST;
}
Uint32 key = RENDER_SAMPLER_HASHKEY(scale_mode, address_u, address_v);
SDL_assert(key < SDL_arraysize(data->samplers));
if (!data->samplers[key]) {
@@ -3889,14 +3894,8 @@ static VkSampler VULKAN_GetSampler(VULKAN_RenderData *data, SDL_PixelFormat form
break;
case SDL_SCALEMODE_PIXELART: // Uses linear sampling
case SDL_SCALEMODE_LINEAR:
if (format == SDL_PIXELFORMAT_INDEX8) {
// We'll do linear sampling in the shader
samplerCreateInfo.magFilter = VK_FILTER_NEAREST;
samplerCreateInfo.minFilter = VK_FILTER_NEAREST;
} else {
samplerCreateInfo.magFilter = VK_FILTER_LINEAR;
samplerCreateInfo.minFilter = VK_FILTER_LINEAR;
}
samplerCreateInfo.magFilter = VK_FILTER_LINEAR;
samplerCreateInfo.minFilter = VK_FILTER_LINEAR;
break;
default:
SDL_SetError("Unknown scale mode: %d", scale_mode);