Module: Mesa Branch: main Commit: 8d79376957b2c5f645cd853b5efe58e32c945b3d URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=8d79376957b2c5f645cd853b5efe58e32c945b3d
Author: Sil Vilerino <[email protected]> Date: Mon Jul 3 08:54:18 2023 -0400 d3d12: Video Decode - Remove unnecessary copy for texture array case Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25069> --- .../d3d12/d3d12_video_dec_references_mgr.cpp | 64 +++------------------- .../drivers/d3d12/d3d12_video_dec_references_mgr.h | 4 +- 2 files changed, 8 insertions(+), 60 deletions(-) diff --git a/src/gallium/drivers/d3d12/d3d12_video_dec_references_mgr.cpp b/src/gallium/drivers/d3d12/d3d12_video_dec_references_mgr.cpp index f9aa7564834..acc74d40456 100644 --- a/src/gallium/drivers/d3d12/d3d12_video_dec_references_mgr.cpp +++ b/src/gallium/drivers/d3d12/d3d12_video_dec_references_mgr.cpp @@ -75,65 +75,15 @@ d3d12_video_decoder_references_manager::get_current_frame_decode_output_texture( *ppOutTexture2D = reconPicture.pReconstructedPicture; *pOutSubresourceIndex = reconPicture.ReconstructedPictureSubresource; } else { - if (is_reference_only()) { - // When using clear DPB references (not ReferenceOnly) the decode output allocations come from - // m_upD3D12TexturesStorageManager as decode output == reconpic decode output Otherwise, when ReferenceOnly is - // true, both the reference frames in the DPB and the current frame reconpic output must be REFERENCE_ONLY, all - // the allocations are stored in m_upD3D12TexturesStorageManager but we need a +1 allocation without the - // REFERENCE_FRAME to use as clear decoded output. In this case d3d12_video_decoder_references_manager allocates - // and provides m_pClearDecodedOutputTexture Please note that m_pClearDecodedOutputTexture needs to be copied/read - // by the client before calling end_frame again, as the allocation will be reused for the next frame. - - if (m_pClearDecodedOutputTexture == nullptr) { - D3D12_HEAP_PROPERTIES Properties = - CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT, m_dpbDescriptor.m_NodeMask, m_dpbDescriptor.m_NodeMask); - CD3DX12_RESOURCE_DESC resDesc = CD3DX12_RESOURCE_DESC::Tex2D(m_dpbDescriptor.Format, - m_dpbDescriptor.Width, - m_dpbDescriptor.Height, - 1, - 1, - 1, - 0, - D3D12_RESOURCE_FLAG_NONE); - - HRESULT hr = m_pD3D12Screen->dev->CreateCommittedResource(&Properties, - D3D12_HEAP_FLAG_NONE, - &resDesc, - D3D12_RESOURCE_STATE_COMMON, - nullptr, - IID_PPV_ARGS(m_pClearDecodedOutputTexture.GetAddressOf())); - if (FAILED(hr)) { - debug_printf("CreateCommittedResource failed with HR %x\n", hr); - assert(false); - } - } - - *ppOutTexture2D = m_pClearDecodedOutputTexture.Get(); + if (is_pipe_buffer_underlying_output_decode_allocation()) { + auto vidBuffer = (struct d3d12_video_buffer *)(pCurrentDecodeTarget); + *ppOutTexture2D = d3d12_resource_resource(vidBuffer->texture); *pOutSubresourceIndex = 0; } else { - if(is_array_of_textures()) { - // In non ref picture and non texarray mode, we can just use the underlying allocation in pCurrentDecodeTarget - // and avoid an extra copy after decoding the frame. - assert(is_pipe_buffer_underlying_output_decode_allocation()); - - auto vidBuffer = (struct d3d12_video_buffer *)(pCurrentDecodeTarget); - *ppOutTexture2D = d3d12_resource_resource(vidBuffer->texture); - *pOutSubresourceIndex = 0; - #if DEBUG - D3D12_RESOURCE_DESC desc = GetDesc(*ppOutTexture2D); - assert(desc.DepthOrArraySize == 1); - // if the underlying resource is a texture array at some point (if the impl. changes) - // we need to also return the correct underlying subresource in *pOutSubresourceIndex = <subres> - #endif - - } else { - // The DPB Storage only has standard (without the ref only flags) allocations, directly use one of those. - d3d12_video_reconstructed_picture pFreshAllocation = - m_upD3D12TexturesStorageManager->get_new_tracked_picture_allocation(); - *ppOutTexture2D = pFreshAllocation.pReconstructedPicture; - *pOutSubresourceIndex = pFreshAllocation.ReconstructedPictureSubresource; - } - + d3d12_video_reconstructed_picture pFreshAllocation = + m_upD3D12TexturesStorageManager->get_new_tracked_picture_allocation(); + *ppOutTexture2D = pFreshAllocation.pReconstructedPicture; + *pOutSubresourceIndex = pFreshAllocation.ReconstructedPictureSubresource; } } } diff --git a/src/gallium/drivers/d3d12/d3d12_video_dec_references_mgr.h b/src/gallium/drivers/d3d12/d3d12_video_dec_references_mgr.h index 8976c6ad0cd..c01cecc5f3a 100644 --- a/src/gallium/drivers/d3d12/d3d12_video_dec_references_mgr.h +++ b/src/gallium/drivers/d3d12/d3d12_video_dec_references_mgr.h @@ -48,7 +48,7 @@ struct d3d12_video_decoder_references_manager bool is_pipe_buffer_underlying_output_decode_allocation() { - return (!is_reference_only() && is_array_of_textures()); + return (is_reference_only() || is_array_of_textures()); } void mark_all_references_as_unused(); @@ -145,8 +145,6 @@ struct d3d12_video_decoder_references_manager std::map<struct pipe_video_buffer *, uint8_t> m_DecodeTargetToOriginalIndex7Bits = { }; - ComPtr<ID3D12Resource> m_pClearDecodedOutputTexture; - const struct d3d12_screen * m_pD3D12Screen; uint16_t m_invalidIndex; d3d12_video_decode_dpb_descriptor m_dpbDescriptor = {};
