From dfb95160266e1be49edc08863c4c760c3f774f9a Mon Sep 17 00:00:00 2001 From: Sil Vilerino Date: Thu, 26 Oct 2023 08:24:53 -0400 Subject: [PATCH] d3d12: d3d12_video_buffer_create_impl - Fix resource importing Only align resource dimensions on creation, not when importing existing D3D resource object. Otherwise importing the resource fails since the resource descriptor does not match the aligned dimensions passed in the template. Fixes: 62fded5e4f8 ("d3d12: Allocate d3d12_video_buffer with higher alignment for compatibility") Part-of: --- .../drivers/d3d12/d3d12_video_buffer.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/gallium/drivers/d3d12/d3d12_video_buffer.cpp b/src/gallium/drivers/d3d12/d3d12_video_buffer.cpp index a801ce11c0f..14dc1a6156d 100644 --- a/src/gallium/drivers/d3d12/d3d12_video_buffer.cpp +++ b/src/gallium/drivers/d3d12/d3d12_video_buffer.cpp @@ -73,10 +73,20 @@ d3d12_video_buffer_create_impl(struct pipe_context *pipe, templ.target = PIPE_TEXTURE_2D; templ.bind = pD3D12VideoBuffer->base.bind; templ.format = pD3D12VideoBuffer->base.buffer_format; - // YUV 4:2:0 formats in D3D12 need to at least be multiple of 2 dimensions - // However, we allocate with a higher alignment to maximize HW compatibility - templ.width0 = align(pD3D12VideoBuffer->base.width, 2); - templ.height0 = align(pD3D12VideoBuffer->base.height, 16); + if (handle) + { + // YUV 4:2:0 formats in D3D12 always require multiple of 2 dimensions + // We must respect the input dimensions of the imported resource handle (e.g no extra aligning) + templ.width0 = align(pD3D12VideoBuffer->base.width, 2); + templ.height0 = align(pD3D12VideoBuffer->base.height, 2); + } + else + { + // When creating (e.g not importing) resources we allocate + // with a higher alignment to maximize HW compatibility + templ.width0 = align(pD3D12VideoBuffer->base.width, 2); + templ.height0 = align(pD3D12VideoBuffer->base.height, 16); + } templ.depth0 = 1; templ.array_size = 1; templ.flags = 0;