d3d12: HEVC Decode - Fix slice size and offsets translation from VA to DXVA
authorSil Vilerino <sivileri@microsoft.com>
Fri, 21 Oct 2022 13:58:35 +0000 (09:58 -0400)
committerMarge Bot <emma+marge@anholt.net>
Fri, 21 Oct 2022 17:56:38 +0000 (17:56 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19231>

src/gallium/drivers/d3d12/d3d12_video_dec_hevc.cpp

index 488363d..a501d88 100644 (file)
@@ -141,6 +141,8 @@ d3d12_video_decoder_prepare_dxva_slices_control_hevc(struct d3d12_video_decoder
    vecOutSliceControlBuffers.resize(TotalSlicesDXVAArrayByteSize);
 
    uint8_t* pData = vecOutSliceControlBuffers.data();
+   static const uint32_t start_code_size = 3;
+   uint32_t acum_slice_offset = (picture_hevc->slice_parameter.slice_count > 0) ? picture_hevc->slice_parameter.slice_data_offset[0] : 0;
    for (uint32_t sliceIdx = 0; sliceIdx < picture_hevc->slice_parameter.slice_count; sliceIdx++)
    {
       DXVA_Slice_HEVC_Short currentSliceEntry = {};
@@ -175,8 +177,12 @@ d3d12_video_decoder_prepare_dxva_slices_control_hevc(struct d3d12_video_decoder
          } break;
       }
 
-      currentSliceEntry.SliceBytesInBuffer = picture_hevc->slice_parameter.slice_data_size[sliceIdx];
-      currentSliceEntry.BSNALunitDataLocation = picture_hevc->slice_parameter.slice_data_offset[sliceIdx];
+      /* slice_data_size from pipe/va does not include the NAL unit size, DXVA requires it */
+      currentSliceEntry.SliceBytesInBuffer = picture_hevc->slice_parameter.slice_data_size[sliceIdx] + start_code_size;
+
+      /* slice_data_offset from pipe/va are relative to the current slice, and in DXVA they are absolute within the frame source buffer */
+      currentSliceEntry.BSNALunitDataLocation = acum_slice_offset;
+      acum_slice_offset += (currentSliceEntry.SliceBytesInBuffer + picture_hevc->slice_parameter.slice_data_offset[sliceIdx]);
 
       debug_printf("[d3d12_video_decoder_hevc] Detected slice index %" PRIu32 " with SliceBytesInBuffer %d - BSNALunitDataLocation %d - wBadSliceChopping: %" PRIu16
                   " for frame with "