Skip to content

Commit fae7936

Browse files
committed
D3D8: Route texture unload through video thread when threaded video active
Mirrors the fix for the D3D9 drivers. d3d8_load_texture already routes through video_thread_texture_handle via d3d8_video_texture_load_wrap_d3d, but d3d8_unload_texture called IDirect3DTexture8_Release directly on the caller's thread. Under threaded video, the video thread runs d3d8_frame and may have draw calls pending that reference the texture. Releasing the texture's refcount from the main thread while the video thread is using it can cause the D3D8 runtime to free the underlying resource before the pending draws complete. Fix: add d3d8_video_texture_unload_wrap_d3d and dispatch through video_thread_texture_handle when threaded video is active, matching the existing load pattern. Same class of race already addressed in D3D12, Vulkan, D3D10, D3D11, D3D9 Cg, and D3D9 HLSL. With this commit, every D3D-family driver in the codebase serialises texture load and unload on the video thread under threaded video. No behavioural change on non-threaded video.
1 parent b0c7881 commit fae7936

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

gfx/drivers/d3d8.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,13 +2130,36 @@ static uintptr_t d3d8_load_texture(void *video_data, void *data,
21302130
return id;
21312131
}
21322132

2133+
static int d3d8_video_texture_unload_wrap_d3d(void *data)
2134+
{
2135+
uintptr_t id = (uintptr_t)data;
2136+
if (id)
2137+
{
2138+
LPDIRECT3DTEXTURE8 texid = (LPDIRECT3DTEXTURE8)id;
2139+
IDirect3DTexture8_Release(texid);
2140+
}
2141+
return 0;
2142+
}
2143+
21332144
static void d3d8_unload_texture(void *data, bool threaded,
21342145
uintptr_t id)
21352146
{
21362147
LPDIRECT3DTEXTURE8 texid;
21372148
if (!id)
21382149
return;
21392150

2151+
/* Dispatch Release to the video thread when threaded video is
2152+
* active, so it is serialised with any pending draw calls
2153+
* that may still reference this texture. Matches the
2154+
* threading pattern already used by d3d8_load_texture
2155+
* above. */
2156+
if (threaded)
2157+
{
2158+
video_thread_texture_handle((void*)id,
2159+
d3d8_video_texture_unload_wrap_d3d);
2160+
return;
2161+
}
2162+
21402163
texid = (LPDIRECT3DTEXTURE8)id;
21412164
IDirect3DTexture8_Release(texid);
21422165
}

0 commit comments

Comments
 (0)