From 21f4bc47b6f21973dea2cd88d79a0decddc74f50 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 10 Sep 2026 08:39:00 -0700
Subject: [PATCH] Remove SDL_HAVE_YUV checks from render drivers
This doesn't actually save much code size and complicates the drivers a fair bit.
Upside is that you'll now be able to build SDL without software YUV support and still be able to play videos with hardware acceleration enabled.
---
src/render/SDL_render.c | 18 ++++++-------
src/render/SDL_sysrender.h | 2 --
src/render/direct3d/SDL_render_d3d.c | 32 ----------------------
src/render/direct3d11/SDL_render_d3d11.c | 22 ---------------
src/render/direct3d12/SDL_render_d3d12.c | 20 --------------
src/render/gpu/SDL_render_gpu.c | 20 --------------
src/render/metal/SDL_render_metal.m | 23 +---------------
src/render/opengl/SDL_render_gl.c | 22 ---------------
src/render/opengl/SDL_shaders_gl.c | 6 -----
src/render/opengl/SDL_shaders_gl.h | 2 --
src/render/opengles2/SDL_render_gles2.c | 34 ------------------------
src/render/opengles2/SDL_shaders_gles2.c | 4 ---
src/render/opengles2/SDL_shaders_gles2.h | 2 --
src/render/vitagxm/SDL_render_vita_gxm.c | 10 -------
src/render/vulkan/SDL_render_vulkan.c | 14 ----------
src/video/SDL_yuv.c | 10 +++----
16 files changed, 12 insertions(+), 229 deletions(-)
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index d1a915b87822e..c6351f9b5ac9b 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -2468,7 +2468,6 @@ bool SDL_UpdateYUVTexture(SDL_Texture *texture, const SDL_Rect *rect,
const Uint8 *Uplane, int Upitch,
const Uint8 *Vplane, int Vpitch)
{
-#ifdef SDL_HAVE_YUV
SDL_Renderer *renderer;
SDL_Rect real_rect;
@@ -2513,9 +2512,12 @@ bool SDL_UpdateYUVTexture(SDL_Texture *texture, const SDL_Rect *rect,
return true; // nothing to do.
}
+#ifdef SDL_HAVE_YUV
if (texture->yuv) {
return SDL_UpdateTextureYUVPlanar(texture, &real_rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch);
- } else {
+ } else
+#endif
+ {
SDL_assert(!texture->native);
renderer = texture->renderer;
SDL_assert(renderer->UpdateTextureYUV);
@@ -2528,16 +2530,12 @@ bool SDL_UpdateYUVTexture(SDL_Texture *texture, const SDL_Rect *rect,
return SDL_Unsupported();
}
}
-#else
- return false;
-#endif
}
bool SDL_UpdateNVTexture(SDL_Texture *texture, const SDL_Rect *rect,
const Uint8 *Yplane, int Ypitch,
const Uint8 *UVplane, int UVpitch)
{
-#ifdef SDL_HAVE_YUV
SDL_Renderer *renderer;
SDL_Rect real_rect;
@@ -2574,9 +2572,12 @@ bool SDL_UpdateNVTexture(SDL_Texture *texture, const SDL_Rect *rect,
return true; // nothing to do.
}
+#ifdef SDL_HAVE_YUV
if (texture->yuv) {
return SDL_UpdateTextureNVPlanar(texture, &real_rect, Yplane, Ypitch, UVplane, UVpitch);
- } else {
+ } else
+#endif
+ {
SDL_assert(!texture->native);
renderer = texture->renderer;
SDL_assert(renderer->UpdateTextureNV);
@@ -2589,9 +2590,6 @@ bool SDL_UpdateNVTexture(SDL_Texture *texture, const SDL_Rect *rect,
return SDL_Unsupported();
}
}
-#else
- return false;
-#endif
}
#ifdef SDL_HAVE_YUV
diff --git a/src/render/SDL_sysrender.h b/src/render/SDL_sysrender.h
index 87fbbaf35d242..6642fe693ab11 100644
--- a/src/render/SDL_sysrender.h
+++ b/src/render/SDL_sysrender.h
@@ -252,7 +252,6 @@ struct SDL_Renderer
bool (*UpdateTexture)(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect, const void *pixels,
int pitch);
-#ifdef SDL_HAVE_YUV
bool (*UpdateTextureYUV)(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect,
const Uint8 *Yplane, int Ypitch,
@@ -262,7 +261,6 @@ struct SDL_Renderer
const SDL_Rect *rect,
const Uint8 *Yplane, int Ypitch,
const Uint8 *UVplane, int UVpitch);
-#endif
bool (*LockTexture)(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect, void **pixels, int *pitch);
void (*UnlockTexture)(SDL_Renderer *renderer, SDL_Texture *texture);
diff --git a/src/render/direct3d/SDL_render_d3d.c b/src/render/direct3d/SDL_render_d3d.c
index 929dbdafd6721..18ded015e7dca 100644
--- a/src/render/direct3d/SDL_render_d3d.c
+++ b/src/render/direct3d/SDL_render_d3d.c
@@ -104,7 +104,6 @@ typedef struct
const float *shader_params;
float palette_shader_params[4];
-#ifdef SDL_HAVE_YUV
// YV12 texture support
bool yuv;
D3D_TextureRep utexture;
@@ -112,7 +111,6 @@ typedef struct
Uint8 *pixels;
int pitch;
SDL_Rect locked_rect;
-#endif
} D3D_TextureData;
typedef struct
@@ -628,7 +626,6 @@ static bool D3D_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
if (!D3D_UpdateTextureRep(data->device, &texturedata->texture, rect->x, rect->y, rect->w, rect->h, pixels, pitch)) {
return false;
}
-#ifdef SDL_HAVE_YUV
if (texturedata->yuv) {
if (texture->format == SDL_PIXELFORMAT_I444) {
// Skip to the correct offset into the next texture
@@ -656,7 +653,6 @@ static bool D3D_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
}
}
}
-#endif
return true;
}
@@ -690,7 +686,6 @@ static bool D3D_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_
texturedata->palette_shader_params[2] = texture->w;
texturedata->palette_shader_params[3] = texture->h;
}
-#ifdef SDL_HAVE_YUV
if (texture->format == SDL_PIXELFORMAT_YV12 ||
texture->format == SDL_PIXELFORMAT_IYUV) {
texturedata->yuv = true;
@@ -726,7 +721,6 @@ static bool D3D_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_
return SDL_SetError("Unsupported YUV colorspace");
}
}
-#endif
return true;
}
@@ -742,7 +736,6 @@ static bool D3D_RecreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
if (!D3D_RecreateTextureRep(data->device, &texturedata->texture)) {
return false;
}
-#ifdef SDL_HAVE_YUV
if (texturedata->yuv) {
if (!D3D_RecreateTextureRep(data->device, &texturedata->utexture)) {
return false;
@@ -752,11 +745,9 @@ static bool D3D_RecreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
return false;
}
}
-#endif
return true;
}
-#ifdef SDL_HAVE_YUV
static bool D3D_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect,
const Uint8 *Yplane, int Ypitch,
@@ -790,7 +781,6 @@ static bool D3D_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture,
}
return true;
}
-#endif
static bool D3D_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect, void **pixels, int *pitch)
@@ -802,7 +792,6 @@ static bool D3D_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
if (!texturedata) {
return SDL_SetError("Texture is not currently available");
}
-#ifdef SDL_HAVE_YUV
texturedata->locked_rect = *rect;
if (texturedata->yuv) {
@@ -823,7 +812,6 @@ static bool D3D_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
rect->x * SDL_BYTESPERPIXEL(texture->format));
*pitch = texturedata->pitch;
} else
-#endif
{
RECT d3drect;
D3DLOCKED_RECT locked;
@@ -856,7 +844,6 @@ static void D3D_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
if (!texturedata) {
return;
}
-#ifdef SDL_HAVE_YUV
if (texturedata->yuv) {
const SDL_Rect *rect = &texturedata->locked_rect;
void *pixels =
@@ -864,7 +851,6 @@ static void D3D_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
rect->x * SDL_BYTESPERPIXEL(texture->format));
D3D_UpdateTexture(renderer, texture, rect, pixels, texturedata->pitch);
} else
-#endif
{
IDirect3DTexture9_UnlockRect(texturedata->texture.staging, 0);
texturedata->texture.dirty = true;
@@ -1117,10 +1103,8 @@ static bool SetupTextureState(D3D_RenderData *data, SDL_Texture *texture, SDL_Sc
} else {
*shader = SHADER_PALETTE_NEAREST;
}
-#ifdef SDL_HAVE_YUV
} else if (texturedata->yuv) {
*shader = SHADER_YUV;
-#endif // SDL_HAVE_YUV
}
*shader_params = texturedata->shader_params;
@@ -1133,7 +1117,6 @@ static bool SetupTextureState(D3D_RenderData *data, SDL_Texture *texture, SDL_Sc
return false;
}
}
-#ifdef SDL_HAVE_YUV
if (texturedata->yuv) {
if (!BindTextureRep(data->device, &texturedata->utexture, 1)) {
return false;
@@ -1142,7 +1125,6 @@ static bool SetupTextureState(D3D_RenderData *data, SDL_Texture *texture, SDL_Sc
return false;
}
}
-#endif
return true;
}
@@ -1165,12 +1147,10 @@ static bool SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd)
((oldtexturedata && data->drawstate.texture->palette) || data->drawstate.texture_state_dirty)) {
IDirect3DDevice9_SetTexture(data->device, 1, NULL);
}
-#ifdef SDL_HAVE_YUV
if ((!newtexturedata || !newtexturedata->yuv) && ((oldtexturedata && oldtexturedata->yuv) || data->drawstate.texture_state_dirty)) {
IDirect3DDevice9_SetTexture(data->device, 1, NULL);
IDirect3DDevice9_SetTexture(data->device, 2, NULL);
}
-#endif
if (texture && !SetupTextureState(data, texture, cmd->data.draw.texture_scale_mode, &shader, &shader_params)) {
return false;
}
@@ -1204,12 +1184,10 @@ static bool SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd)
D3D_PaletteData *palettedata = (D3D_PaletteData *)texture->palette->internal;
UpdateDirtyTexture(data->device, &palettedata->texture);
}
-#ifdef SDL_HAVE_YUV
if (texturedata->yuv) {
UpdateDirtyTexture(data->device, &texturedata->utexture);
UpdateDirtyTexture(data->device, &texturedata->vtexture);
}
-#endif // SDL_HAVE_YUV
}
}
@@ -1217,7 +1195,6 @@ static bool SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd)
UpdateTextureScaleMode(data, cmd->data.draw.texture_scale_mode, 0);
UpdateTextureAddressMode(data, cmd->data.draw.texture_address_mode_u, cmd->data.draw.texture_address_mode_v, 0);
-#ifdef SDL_HAVE_YUV
D3D_TextureData *texturedata = (D3D_TextureData *)texture->internal;
if (texturedata && texturedata->yuv) {
UpdateTextureScaleMode(data, cmd->data.draw.texture_scale_mode, 1);
@@ -1225,7 +1202,6 @@ static bool SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd)
UpdateTextureAddressMode(data, cmd->data.draw.texture_address_mode_u, cmd->data.draw.texture_address_mode_v, 1);
UpdateTextureAddressMode(data, cmd->data.draw.texture_address_mode_u, cmd->data.draw.texture_address_mode_v, 2);
}
-#endif // SDL_HAVE_YUV
}
if (blend != data->drawstate.blend) {
@@ -1678,12 +1654,10 @@ static void D3D_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
if (texture->palette) {
IDirect3DDevice9_SetTexture(renderdata->device, 1, NULL);
}
-#ifdef SDL_HAVE_YUV
if (data && data->yuv) {
IDirect3DDevice9_SetTexture(renderdata->device, 1, NULL);
IDirect3DDevice9_SetTexture(renderdata->device, 2, NULL);
}
-#endif
}
if (!data) {
@@ -1691,11 +1665,9 @@ static void D3D_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
}
D3D_DestroyTextureRep(&data->texture);
-#ifdef SDL_HAVE_YUV
D3D_DestroyTextureRep(&data->utexture);
D3D_DestroyTextureRep(&data->vtexture);
SDL_free(data->pixels);
-#endif
SDL_free(data);
texture->internal = NULL;
}
@@ -1913,9 +1885,7 @@ static bool D3D_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_P
renderer->DestroyPalette = D3D_DestroyPalette;
renderer->CreateTexture = D3D_CreateTexture;
renderer->UpdateTexture = D3D_UpdateTexture;
-#ifdef SDL_HAVE_YUV
renderer->UpdateTextureYUV = D3D_UpdateTextureYUV;
-#endif
renderer->LockTexture = D3D_LockTexture;
renderer->UnlockTexture = D3D_UnlockTexture;
renderer->SetRenderTarget = D3D_SetRenderTarget;
@@ -2046,13 +2016,11 @@ static bool D3D_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_P
data->shaders[SHADER_PALETTE_LINEAR]) {
SDL_AddSupportedTextureFormat(renderer, SDL_PIXELFORMAT_INDEX8);
}
-#ifdef SDL_HAVE_YUV
if (caps.MaxSimultaneousTextures >= 3 && data->shaders[SHADER_YUV]) {
SDL_AddSupportedTextureFormat(renderer, SDL_PIXELFORMAT_YV12);
SDL_AddSupportedTextureFormat(renderer, SDL_PIXELFORMAT_IYUV);
SDL_AddSupportedTextureFormat(renderer, SDL_PIXELFORMAT_I444);
}
-#endif
SDL_SetPointerProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_D3D9_DEVICE_POINTER, data->device);
diff --git a/src/render/direct3d11/SDL_render_d3d11.c b/src/render/direct3d11/SDL_render_d3d11.c
index 121c61d3c96e9..17ed394b355c1 100644
--- a/src/render/direct3d11/SDL_render_d3d11.c
+++ b/src/render/direct3d11/SDL_render_d3d11.c
@@ -128,7 +128,6 @@ typedef struct
int lockedTexturePositionX;
int lockedTexturePositionY;
const float *YCbCr_matrix;
-#ifdef SDL_HAVE_YUV
// YV12 texture support
bool yuv;
ID3D11Texture2D *mainTextureU;
@@ -143,7 +142,6 @@ typedef struct
Uint8 *pixels;
int pitch;
SDL_Rect locked_rect;
-#endif
} D3D11_TextureData;
// Blend mode data
@@ -1272,7 +1270,6 @@ static bool D3D11_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SD
}
SDL_SetPointerProperty(SDL_GetTextureProperties(texture), SDL_PROP_TEXTURE_D3D11_TEXTURE_POINTER, textureData->mainTexture);
-#ifdef SDL_HAVE_YUV
if (texture->format == SDL_PIXELFORMAT_YV12 ||
texture->format == SDL_PIXELFORMAT_IYUV ||
texture->format == SDL_PIXELFORMAT_I0FL) {
@@ -1364,7 +1361,6 @@ static bool D3D11_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SD
return SDL_SetError("Unsupported YUV colorspace");
}
}
-#endif // SDL_HAVE_YUV
SDL_zero(resourceViewDesc);
resourceViewDesc.Format = SDLPixelFormatToDXGIMainResourceViewFormat(texture->format, renderer->output_colorspace);
resourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
@@ -1378,7 +1374,6 @@ static bool D3D11_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SD
return WIN_SetErrorFromHRESULT("ID3D11Device1::CreateShaderResourceView", result);
}
-#ifdef SDL_HAVE_YUV
if (textureData->yuv) {
result = ID3D11Device_CreateShaderResourceView(rendererData->d3dDevice,
(ID3D11Resource *)textureData->mainTextureU,
@@ -1413,7 +1408,6 @@ static bool D3D11_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SD
return WIN_SetErrorFromHRESULT("ID3D11Device1::CreateShaderResourceView", result);
}
}
-#endif // SDL_HAVE_YUV
if (texture->access & SDL_TEXTUREACCESS_TARGET) {
D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc;
@@ -1447,14 +1441,12 @@ static void D3D11_DestroyTexture(SDL_Renderer *renderer,
SAFE_RELEASE(data->mainTextureResourceView);
SAFE_RELEASE(data->mainTextureRenderTargetView);
SAFE_RELEASE(data->stagingTexture);
-#ifdef SDL_HAVE_YUV
SAFE_RELEASE(data->mainTextureU);
SAFE_RELEASE(data->mainTextureResourceViewU);
SAFE_RELEASE(data->mainTextureV);
SAFE_RELEASE(data->mainTextureResourceViewV);
SAFE_RELEASE(data->mainTextureResourceViewNV);
SDL_free(data->pixels);
-#endif
SDL_free(data);
texture->internal = NULL;
}
@@ -1562,7 +1554,6 @@ static bool D3D11_UpdateTextureInternal(D3D11_RenderData *rendererData, ID3D11Te
return true;
}
-#ifdef SDL_HAVE_YUV
static bool D3D11_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect,
const Uint8 *Yplane, int Ypitch,
@@ -1573,7 +1564,6 @@ static bool D3D11_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture,
const Uint8 *Yplane, int Ypitch,
const Uint8 *Uplane, int Upitch,
const Uint8 *Vplane, int Vpitch);
-#endif
static bool D3D11_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect, const void *srcPixels,
@@ -1586,7 +1576,6 @@ static bool D3D11_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
return SDL_SetError("Texture is not currently available");
}
-#ifdef SDL_HAVE_YUV
if (textureData->nv12) {
int UVbpp = SDL_BYTESPERPIXEL(texture->format) * 2;
int Ypitch = srcPitch;
@@ -1623,7 +1612,6 @@ static bool D3D11_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
}
}
}
-#endif
if (!D3D11_UpdateTextureInternal(rendererData, textureData->mainTexture, SDL_BYTESPERPIXEL(texture->format), rect->x, rect->y, rect->w, rect->h, srcPixels, srcPitch)) {
return false;
@@ -1631,7 +1619,6 @@ static bool D3D11_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
return true;
}
-#ifdef SDL_HAVE_YUV
static bool D3D11_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect,
const Uint8 *Yplane, int Ypitch,
@@ -1779,7 +1766,6 @@ static bool D3D11_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture,
return true;
}
-#endif
static bool D3D11_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect, void **pixels, int *pitch)
@@ -1793,7 +1779,6 @@ static bool D3D11_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
if (!textureData) {
return SDL_SetError("Texture is not currently available");
}
-#ifdef SDL_HAVE_YUV
if (textureData->yuv || textureData->nv12) {
// It's more efficient to upload directly...
if (!textureData->pixels) {
@@ -1814,7 +1799,6 @@ static bool D3D11_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
*pitch = textureData->pitch;
return true;
}
-#endif
if (textureData->stagingTexture) {
return SDL_SetError("texture is already locked");
}
@@ -1874,7 +1858,6 @@ static void D3D11_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
if (!textureData) {
return;
}
-#ifdef SDL_HAVE_YUV
if (textureData->yuv || textureData->nv12) {
const SDL_Rect *rect = &textureData->locked_rect;
void *pixels =
@@ -1883,7 +1866,6 @@ static void D3D11_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
D3D11_UpdateTexture(renderer, texture, rect, pixels, textureData->pitch);
return;
}
-#endif
// Commit the pixel buffer's changes back to the staging texture:
ID3D11DeviceContext_Unmap(rendererData->d3dContext,
(ID3D11Resource *)textureData->stagingTexture,
@@ -2590,14 +2572,12 @@ static bool D3D11_SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *
++numShaderSamplers;
}
-#ifdef SDL_HAVE_YUV
if (textureData->yuv) {
shaderResources[numShaderResources++] = textureData->mainTextureResourceViewU;
shaderResources[numShaderResources++] = textureData->mainTextureResourceViewV;
} else if (textureData->nv12) {
shaderResources[numShaderResources++] = textureData->mainTextureResourceViewNV;
}
-#endif // SDL_HAVE_YUV
return D3D11_SetDrawState(renderer, cmd, &constants, numShaderResources, shaderResources, numShaderSamplers, shaderSamplers, matrix);
}
@@ -3011,10 +2991,8 @@ static bool D3D11_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL
renderer->DestroyPalette = D3D11_DestroyPalette;
renderer->CreateTexture = D3D11_CreateTexture;
renderer->UpdateTexture = D3D11_UpdateTexture;
-#ifdef SDL_HAVE_YUV
renderer->UpdateTextureYUV = D3D11_UpdateTextureYUV;
renderer->UpdateTextureNV = D3D11_UpdateTextureNV;
-#endif
renderer->LockTexture = D3D11_LockTexture;
renderer->UnlockTexture = D3D11_UnlockTexture;
renderer->SetRenderTarget = D3D11_SetRenderTarget;
diff --git a/src/render/direct3d12/SDL_render_d3d12.c b/src/render/direct3d12/SDL_render_d3d12.c
index 8051b183850f9..c85b62296fa7e 100644
--- a/src/render/direct3d12/SDL_render_d3d12.c
+++ b/src/render/direct3d12/SDL_render_d3d12.c
@@ -127,7 +127,6 @@ typedef struct
ID3D12Resource *stagingBuffer;
D3D12_RESOURCE_STATES stagingResourceState;
const float *YCbCr_matrix;
-#ifdef SDL_HAVE_YUV
// YV12 texture support
bool yuv;
ID3D12Resource *mainTextureU;
@@ -146,7 +145,6 @@ typedef struct
Uint8 *pixels;
int pitch;
-#endif
SDL_Rect lockedRect;
} D3D12_TextureData;
@@ -1691,7 +1689,6 @@ static bool D3D12_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SD
textureData->mainResourceState = D3D12_RESOURCE_STATE_COPY_DEST;
SDL_SetPointerProperty(SDL_GetTextureProperties(texture), SDL_PROP_TEXTURE_D3D12_TEXTURE_POINTER, textureData->mainTexture);
-#ifdef SDL_HAVE_YUV
if (texture->format == SDL_PIXELFORMAT_YV12 ||
texture->format == SDL_PIXELFORMAT_IYUV ||
texture->format == SDL_PIXELFORMAT_I0FL) {
@@ -1805,7 +1802,6 @@ static bool D3D12_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SD
return SDL_SetError("Unsupported YUV colorspace");
}
}
-#endif // SDL_HAVE_YUV
SDL_zero(resourceViewDesc);
resourceViewDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
resourceViewDesc.Format = SDLPixelFormatToDXGIMainResourceViewFormat(texture->format, renderer->output_colorspace);
@@ -1821,7 +1817,6 @@ static bool D3D12_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SD
&resourceViewDesc,
textureData->mainTextureResourceView);
-#ifdef SDL_HAVE_YUV
if (textureData->yuv) {
D3D_CALL_RET(rendererData->srvDescriptorHeap, GetCPUDescriptorHandleForHeapStart, &textureData->mainTextureResourceViewU);
textureData->mainSRVIndexU = D3D12_GetAvailableSRVIndex(renderer);
@@ -1858,7 +1853,6 @@ static bool D3D12_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SD
&nvResourceViewDesc,
textureData->mainTextureResourceViewNV);
}
-#endif // SDL_HAVE_YUV
if (texture->access & SDL_TEXTUREACCESS_TARGET) {
D3D12_RENDER_TARGET_VIEW_DESC renderTargetViewDesc;
@@ -1896,7 +1890,6 @@ static void D3D12_DestroyTexture(SDL_Renderer *renderer,
D3D_SAFE_RELEASE(textureData->mainTexture);
D3D_SAFE_RELEASE(textureData->stagingBuffer);
D3D12_FreeSRVIndex(renderer, textureData->mainSRVIndex);
-#ifdef SDL_HAVE_YUV
D3D_SAFE_RELEASE(textureData->mainTextureU);
D3D_SAFE_RELEASE(textureData->mainTextureV);
if (textureData->yuv) {
@@ -1907,7 +1900,6 @@ static void D3D12_DestroyTexture(SDL_Renderer *renderer,
D3D12_FreeSRVIndex(renderer, textureData->mainSRVIndexNV);
}
SDL_free(textureData->pixels);
-#endif
SDL_free(textureData);
texture->internal = NULL;
}
@@ -2064,7 +2056,6 @@ static bool D3D12_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
if (!D3D12_UpdateTextureInternal(rendererData, textureData->mainTexture, 0, rect->x, rect->y, rect->w, rect->h, srcPixels, srcPitch, &textureData->mainResourceState)) {
return false;
}
-#ifdef SDL_HAVE_YUV
if (textureData->yuv) {
if (texture->format == SDL_PIXELFORMAT_I444 || texture->format == SDL_PIXELFORMAT_I4FL) {
// Skip to the correct offset into the next texture
@@ -2109,7 +2100,6 @@ static bool D3D12_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
return false;
}
}
-#endif // SDL_HAVE_YUV
if (textureData->mainTextureResourceView.ptr == rendererData->currentShaderResource.ptr) {
// We'll need to rebind this resource after updating it
rendererData->currentShaderResource.ptr = 0;
@@ -2117,7 +2107,6 @@ static bool D3D12_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
return true;
}
-#ifdef SDL_HAVE_YUV
static bool D3D12_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect,
const Uint8 *Yplane, int Ypitch,
@@ -2180,7 +2169,6 @@ static bool D3D12_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture,
}
return true;
}
-#endif
static bool D3D12_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect, void **pixels, int *pitch)
@@ -2199,7 +2187,6 @@ static bool D3D12_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
if (!textureData) {
return SDL_SetError("Texture is not currently available");
}
-#ifdef SDL_HAVE_YUV
if (textureData->yuv || textureData->nv12) {
// It's more efficient to upload directly...
if (!textureData->pixels) {
@@ -2220,7 +2207,6 @@ static bool D3D12_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
*pitch = textureData->pitch;
return true;
}
-#endif
if (textureData->stagingBuffer) {
return SDL_SetError("texture is already locked");
}
@@ -2322,7 +2308,6 @@ static void D3D12_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
if (!textureData) {
return;
}
-#ifdef SDL_HAVE_YUV
if (textureData->yuv || textureData->nv12) {
const SDL_Rect *rect = &textureData->lockedRect;
void *pixels =
@@ -2331,7 +2316,6 @@ static void D3D12_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
D3D12_UpdateTexture(renderer, texture, rect, pixels, textureData->pitch);
return;
}
-#endif
// Commit the pixel buffer's changes back to the staging texture:
ID3D12Resource_Unmap(textureData->stagingBuffer, 0, NULL);
@@ -3071,7 +3055,6 @@ static bool D3D12_SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *
shaderSamplers[numShaderSamplers++] = *textureSampler;
}
-#ifdef SDL_HAVE_YUV
if (textureData->yuv) {
D3D12_TransitionResource(rendererData, textureData->mainTextureU, textureData->mainResourceStateU, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
textureData->mainResourceStateU = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
@@ -3085,7 +3068,6 @@ static bool D3D12_SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *
textureData->mainResourceState = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
shaderResources[numShaderResources++] = textureData->mainTextureResourceViewNV;
}
-#endif // SDL_HAVE_YUV
return D3D12_SetDrawState(renderer, cmd, &constants, D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE, numShaderResources, shaderResources, numShaderSamplers, shaderSamplers);
}
@@ -3612,10 +3594,8 @@ bool D3D12_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Proper
renderer->DestroyPalette = D3D12_DestroyPalette;
renderer->CreateTexture = D3D12_CreateTexture;
renderer->UpdateTexture = D3D12_UpdateTexture;
-#ifdef SDL_HAVE_YUV
renderer->UpdateTextureYUV = D3D12_UpdateTextureYUV;
renderer->UpdateTextureNV = D3D12_UpdateTextureNV;
-#endif
renderer->LockTexture = D3D12_LockTexture;
renderer->UnlockTexture = D3D12_UnlockTexture;
renderer->SetRenderTarget = D3D12_SetRenderTarget;
diff --git a/src/render/gpu/SDL_render_gpu.c b/src/render/gpu/SDL_render_gpu.c
index c6e7ff38bc9b4..c5f2d5401a600 100644
--- a/src/render/gpu/SDL_render_gpu.c
+++ b/src/render/gpu/SDL_render_gpu.c
@@ -141,7 +141,6 @@ typedef struct GPU_TextureData
int pitch;
SDL_Rect locked_rect;
const float *YCbCr_matrix;
-#ifdef SDL_HAVE_YUV
// YV12 texture support
bool yuv;
bool external_texture_u;
@@ -153,7 +152,6 @@ typedef struct GPU_TextureData
bool nv12;
bool external_texture_nv;
SDL_GPUTexture *textureNV;
-#endif
} GPU_TextureData;
// TODO: Sort this list based on what the GPU driver prefers?
@@ -325,7 +323,6 @@ static bool GPU_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_
size_t size, pitch;
if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
if (!SDL_CalculateYUVSize(texture->format, texture->w, texture->h, &size, &pitch)) {
- SDL_free(data);
return false;
}
data->pitch = (int)pitch;
@@ -335,7 +332,6 @@ static bool GPU_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_
}
data->pixels = SDL_calloc(1, size);
if (!data->pixels) {
- SDL_free(data);
return false;
}
@@ -370,7 +366,6 @@ static bool GPU_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_
SDL_PropertiesID props = SDL_GetTextureProperties(texture);
SDL_SetPointerProperty(props, SDL_PROP_TEXTURE_GPU_TEXTURE_POINTER, data->texture);
-#ifdef SDL_HAVE_YUV
if (texture->format == SDL_PIXELFORMAT_YV12 ||
texture->format == SDL_PIXELFORMAT_IYUV ||
texture->format == SDL_PIXELFORMAT_I0FL) {
@@ -469,7 +464,6 @@ static bool GPU_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_
return SDL_SetError("Unsupported YUV colorspace");
}
}
-#endif // SDL_HAVE_YUV
return true;
}
@@ -528,7 +522,6 @@ static bool GPU_UpdateTextureInternal(GPU_RenderData *renderdata, SDL_GPUCopyPas
return true;
}
-#ifdef SDL_HAVE_YUV
static bool GPU_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect,
const Uint8 *Yplane, int Ypitch,
@@ -539,7 +532,6 @@ static bool GPU_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture,
const Uint8 *Yplane, int Ypitch,
const Uint8 *Uplane, int Upitch,
const Uint8 *Vplane, int Vpitch);
-#endif
static bool GPU_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
{
@@ -553,7 +545,6 @@ static bool GPU_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, cons
retval = GPU_UpdateTextureInternal(renderdata, cpass, data->texture, bpp, rect->x, rect->y, rect->w, rect->h, pixels, pitch);
-#ifdef SDL_HAVE_YUV
if (data->nv12) {
const Uint8 *Yplane = (const Uint8 *)pixels;
const Uint8 *UVplane = Yplane + rect->h * pitch;
@@ -591,13 +582,11 @@ static bool GPU_Upd
(Patch may be truncated, please check the link at the top of this post.)