From 5836266bfba9ab69b577f222836fd9f0aaf80c9c Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 20 Mar 2025 20:07:33 -0700
Subject: [PATCH] We need to rebind D3D12 resources after updating them
Fixes https://github.com/libsdl-org/SDL/issues/12544
(cherry picked from commit 4ceb02434b3d7604e41c328619c0ae80e70db9a0)
---
src/render/direct3d12/SDL_render_d3d12.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/render/direct3d12/SDL_render_d3d12.c b/src/render/direct3d12/SDL_render_d3d12.c
index 946ad828a3a7e..632e0f6712e35 100644
--- a/src/render/direct3d12/SDL_render_d3d12.c
+++ b/src/render/direct3d12/SDL_render_d3d12.c
@@ -1990,6 +1990,10 @@ static bool D3D12_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
}
}
#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;
+ }
return true;
}
@@ -2016,6 +2020,10 @@ static bool D3D12_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture,
if (!D3D12_UpdateTextureInternal(rendererData, textureData->mainTextureV, 0, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Vplane, Vpitch, &textureData->mainResourceStateV)) {
return false;
}
+ if (textureData->mainTextureResourceView.ptr == rendererData->currentShaderResource.ptr) {
+ // We'll need to rebind this resource after updating it
+ rendererData->currentShaderResource.ptr = 0;
+ }
return true;
}
@@ -2034,10 +2042,13 @@ static bool D3D12_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture,
if (!D3D12_UpdateTextureInternal(rendererData, textureData->mainTexture, 0, rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch, &textureData->mainResourceState)) {
return false;
}
-
if (!D3D12_UpdateTextureInternal(rendererData, textureData->mainTexture, 1, rect->x, rect->y, rect->w, rect->h, UVplane, UVpitch, &textureData->mainResourceState)) {
return false;
}
+ if (textureData->mainTextureResourceView.ptr == rendererData->currentShaderResource.ptr) {
+ // We'll need to rebind this resource after updating it
+ rendererData->currentShaderResource.ptr = 0;
+ }
return true;
}
#endif