Skip to content

Fix decode corruption issue#1

Open
wyc55069407 wants to merge 1 commit into
changchingyew:user/cyew3/mesa_d3d12_video_driver_1from
wyc55069407:user/cyew3/mesa_d3d12_video_driver_1
Open

Fix decode corruption issue#1
wyc55069407 wants to merge 1 commit into
changchingyew:user/cyew3/mesa_d3d12_video_driver_1from
wyc55069407:user/cyew3/mesa_d3d12_video_driver_1

Conversation

@wyc55069407
Copy link
Copy Markdown

Certain frames will have artifacts or green image(no data) due to
data not done copying into driver.
Root cause: there is a call of buffer_subdata in d3d12_video_decoder_end_frame to
create a temp resoure, do map/umap to set bitstream data (CPU side) into this resource,
call CopyBufferRegion to copy temp resource data into real bistream buffer, Then do decode.
However, there is sync missed between CopyBufferRegion and decode.

Fix is:

  1. Create a fence for sync between copy bitstream and decode workload.
  2. Add fence Signal at common CmdQueue after Execute CmdList of workload:
    copy bitstream from temp to bitstream buffer through CopyBufferRegion.
  3. Add fence Wait at decode CmdQueue before Execute CmdList of workload decode.

Signed-off-by: Wang, Yuchen yuchen.wang@intel.com

Certain frames will have artifacts or green image(no data) due to
data not done copying into driver.
Root cause: there is a call of buffer_subdata in d3d12_video_decoder_end_frame to
create a temp resoure, do map/umap to set bitstream data (CPU side) into this resource,
call CopyBufferRegion to copy temp resource data into real bistream buffer, Then do decode.
However, there is sync missed between CopyBufferRegion and decode.

Fix is:
1. Create a fence for sync between copy bitstream and decode workload.
2. Add fence Signal at common CmdQueue after Execute CmdList of workload:
copy bitstream from temp to bitstream buffer through CopyBufferRegion.
3. Add fence Wait at decode CmdQueue before Execute CmdList of workload decode.

Signed-off-by: Wang, Yuchen <yuchen.wang@intel.com>
@sivileri
Copy link
Copy Markdown

sivileri commented Apr 11, 2022

This is a valid fix, preferring the other fix proposed in 73a3057

Picked fix in https://gitlab.freedesktop.org/sivileri/mesa/-/commit/9ca2a6917f6708f0da601557a01abff8dc10ad79

Note: As I was evaluating and discussing this fix, please note for further reference that work done in the pipe->context queue can be synced directly by waiting on the CPU as below:

struct pipe_fence_handle *pCompletionFence = NULL;
pD3D12Enc->base.context->flush(pD3D12Enc->base.context, &pCompletionFence, PIPE_FLUSH_ASYNC | PIPE_FLUSH_HINT_FINISH);
if (pCompletionFence) {
   pD3D12Enc->m_pD3D12Screen->base.fence_finish(&pD3D12Enc->m_pD3D12Screen->base, NULL, pCompletionFence, PIPE_TIMEOUT_INFINITE);
   pD3D12Enc->m_pD3D12Screen->base.fence_reference(&pD3D12Enc->m_pD3D12Screen->base, &pCompletionFence, NULL);
} else {
   D3D12_LOG_ERROR("[d3d12_video_encoder] d3d12_video_encoder_encode_bitstream - pD3D12Enc->base.context->flush(...) returned a nullptr completion fence \n");
}

Alternatively, if you desire to wait on the GPU (on a separate queue independent from the pipe->context) you can directly sync the fence within the GPU and avoid a CPU wait as below:


   struct pipe_fence_handle *pCompletionFence = NULL;
   pD3D12Enc->base.context->flush(pD3D12Enc->base.context, &pCompletionFence, PIPE_FLUSH_ASYNC | PIPE_FLUSH_HINT_FINISH);
   if (pCompletionFence) {
      struct d3d12_fence *pD3D12CompletionFence = d3d12_fence(pCompletionFence);
      pD3D12Enc->m_spEncodeCommandQueue->Wait(pD3D12CompletionFence->cmdqueue_fence, pD3D12CompletionFence->value);
      pD3D12Enc->m_pD3D12Screen->base.fence_reference(&pD3D12Enc->m_pD3D12Screen->base, &pCompletionFence, NULL);
   } else {
      D3D12_LOG_ERROR("[d3d12_video_encoder] d3d12_video_encoder_encode_bitstream - pD3D12Enc->base.context->flush(...) returned a nullptr completion fence \n");
   }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants