diff --git a/src/gallium/drivers/d3d12/d3d12_video_enc.cpp b/src/gallium/drivers/d3d12/d3d12_video_enc.cpp index 23a8623423d..f1f51026e4b 100644 --- a/src/gallium/drivers/d3d12/d3d12_video_enc.cpp +++ b/src/gallium/drivers/d3d12/d3d12_video_enc.cpp @@ -2089,12 +2089,9 @@ d3d12_video_encoder_encode_bitstream(struct pipe_video_codec * codec, D3D12_VIDEO_ENCODER_PICTURE_CONTROL_FLAGS picCtrlFlags = D3D12_VIDEO_ENCODER_PICTURE_CONTROL_FLAG_NONE; // Transition DPB reference pictures to read mode - uint32_t maxReferences = d3d12_video_encoder_get_current_max_dpb_capacity(pD3D12Enc); - std::vector rgReferenceTransitions(maxReferences); + std::vector rgReferenceTransitions; if ((referenceFramesDescriptor.NumTexture2Ds > 0) || (pD3D12Enc->m_upDPBManager->is_current_frame_used_as_reference())) { - rgReferenceTransitions.clear(); - rgReferenceTransitions.reserve(maxReferences); if (reconPicOutputTextureDesc.pReconstructedPicture != nullptr) picCtrlFlags |= D3D12_VIDEO_ENCODER_PICTURE_CONTROL_FLAG_USED_AS_REFERENCE_PICTURE; @@ -2103,6 +2100,10 @@ d3d12_video_encoder_encode_bitstream(struct pipe_video_codec * codec, if (referenceFramesDescriptor.pSubresources == nullptr) { + // Reserve allocation for AoT transitions count + rgReferenceTransitions.reserve(static_cast(referenceFramesDescriptor.NumTexture2Ds + + ((reconPicOutputTextureDesc.pReconstructedPicture != nullptr) ? 1u : 0u))); + // Array of resources mode for reference pictures // Transition all subresources of each reference frame independent resource allocation @@ -2142,6 +2143,10 @@ d3d12_video_encoder_encode_bitstream(struct pipe_video_codec * codec, } #endif + // Reserve allocation for texture array transitions count + rgReferenceTransitions.reserve( + static_cast(pD3D12Enc->m_currentEncodeConfig.m_encodeFormatInfo.PlaneCount * referencesTexArrayDesc.DepthOrArraySize)); + for (uint32_t referenceSubresource = 0; referenceSubresource < referencesTexArrayDesc.DepthOrArraySize; referenceSubresource++) {