From ba9526a580b0d9cfa8adcf4bf81538dad897cd66 Mon Sep 17 00:00:00 2001 From: "Herman S." <429230+has207@users.noreply.github.com> Date: Wed, 25 Feb 2026 14:50:43 +0900 Subject: [PATCH] [D3D12] Pre-create 3D-as-2D textures before draw setup --- src/xenia/gpu/d3d12/d3d12_texture_cache.cc | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/xenia/gpu/d3d12/d3d12_texture_cache.cc b/src/xenia/gpu/d3d12/d3d12_texture_cache.cc index 4d68be2c3..4296522a4 100644 --- a/src/xenia/gpu/d3d12/d3d12_texture_cache.cc +++ b/src/xenia/gpu/d3d12/d3d12_texture_cache.cc @@ -598,6 +598,33 @@ void D3D12TextureCache::RequestTextures(uint32_t used_texture_mask) { TextureCache::RequestTextures(used_texture_mask); + // Pre-create 3D-as-2D wrappers for any 3D textures while we're still in + // the texture loading phase (before graphics pipeline setup). LoadTextureData + // dispatches compute shaders, which must not happen during draw call setup + // as VKD3D asserts a graphics pipeline is active at that point. + if (cvars::gpu_3d_to_2d_texture) { + uint32_t textures_3d = used_texture_mask; + uint32_t index_3d; + while (xe::bit_scan_forward(textures_3d, &index_3d)) { + textures_3d = xe::clear_lowest_bit(textures_3d); + const TextureBinding* binding = GetValidTextureBinding(index_3d); + if (!binding || binding->key.dimension != xenos::DataDimension::k3D) { + continue; + } + D3D12Texture* texture = static_cast(binding->texture); + if (texture) { + texture->GetOrCreate3DAs2DResource( + D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE); + } + D3D12Texture* texture_signed = + static_cast(binding->texture_signed); + if (texture_signed) { + texture_signed->GetOrCreate3DAs2DResource( + D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE); + } + } + } + // Transition the textures to the needed usage - always in // NON_PIXEL_SHADER_RESOURCE | PIXEL_SHADER_RESOURCE states because barriers // between read-only stages, if needed, are discouraged (also if these were