Repository: libsdl-org/SDL
File: src/render/direct3d12/SDL_render_d3d12.c (C)

Code before:

    if (!shader_constants) {
        D3D12_SetupShaderConstants(renderer, cmd, NULL, &solid_constants);
        shader_constants = &solid_constants;
    }

    if (updateSubresource ||
        SDL_memcmp(shader_constants, &currentPipelineState->shader_constants, sizeof(*shader_constants)) != 0) {
        ID3D12GraphicsCommandList2_SetGraphicsRoot32BitConstants(rendererData->commandList,
                 1,
                 sizeof(*shader_constants) / sizeof(float),
                 shader_constants,
                 0);

        SDL_memcpy(&currentPipelineState->shader_constants, shader_constants, sizeof(*shader_constants));
    }

    return true;
}

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]) {
        D3D12_SAMPLER_DESC samplerDesc;
        SDL_zero(samplerDesc);
        samplerDesc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
        samplerDesc.MipLODBias = 0.0f;
        samplerDesc.MaxAnisotropy = 1;
#if defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES)
        // FIXME: Xbox doesn't support FUNC_NONE as of the October 2025 GDK, but
        // at the same time it fixes validation issues on Windows. It's probably
        // the more appropriate value, so get rid of this when GDK catches up.
        // -flibit
        samplerDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_ALWAYS;
#else
        samplerDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_NONE;
#endif
        samplerDesc.MinLOD = 0.0f;
        samplerDesc.MaxLOD = D3D12_FLOAT32_MAX;
        switch (scale_mode) {
        case SDL_SCALEMODE_NEAREST:
            samplerDesc.Filter = D3D12_FILTER_MIN_MAG_MIP_POINT;
            break;
        case SDL_SCALEMODE_PIXELART:    // Uses linear sampling
        case SDL_SCALEMODE_LINEAR:

Review comment (suggestion):
```suggestion
    if (format == SDL_PIXELFORMAT_INDEX8) {
        // We'll do linear sampling in the shader if needed
        scale_mode = SDL_SCALEMODE_NEAREST;
    }

```

Code after:

    if (!shader_constants) {
        D3D12_SetupShaderConstants(renderer, cmd, NULL, &solid_constants);
        shader_constants = &solid_constants;
    }

    if (updateSubresource ||
        SDL_memcmp(shader_constants, &currentPipelineState->shader_constants, sizeof(*shader_constants)) != 0) {
        ID3D12GraphicsCommandList2_SetGraphicsRoot32BitConstants(rendererData->commandList,
                 1,
                 sizeof(*shader_constants) / sizeof(float),
                 shader_constants,
                 0);

        SDL_memcpy(&currentPipelineState->shader_constants, shader_constants, sizeof(*shader_constants));
    }

    return true;
}

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]) {
        D3D12_SAMPLER_DESC samplerDesc;
        SDL_zero(samplerDesc);
        samplerDesc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
        samplerDesc.MipLODBias = 0.0f;
        samplerDesc.MaxAnisotropy = 1;
#if defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES)
        // FIXME: Xbox doesn't support FUNC_NONE as of the October 2025 GDK, but
        // at the same time it fixes validation issues on Windows. It's probably
        // the more appropriate value, so get rid of this when GDK catches up.
        // -flibit
        samplerDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_ALWAYS;
#else
        samplerDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_NONE;
#endif
        samplerDesc.MinLOD = 0.0f;
        samplerDesc.MaxLOD = D3D12_FLOAT32_MAX;
        switch (scale_mode) {
        case SDL_SCALEMODE_NEAREST:
            samplerDesc.Filter = D3D12_FILTER_MIN_MAG_MIP_POINT;
            break;
        case SDL_SCALEMODE_PIXELART:    // Uses linear sampling