Module: Mesa
Branch: main
Commit: 311d653df958336db4e829d1b11e1a63860f7bd5
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=311d653df958336db4e829d1b11e1a63860f7bd5

Author: Sil Vilerino <sivil...@microsoft.com>
Date:   Wed Dec 27 10:36:12 2023 -0500

d3d12: Fix AV1 Encode - log2 rounding for tile_info section

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26853>

---

 .../d3d12_video_encoder_bitstream_builder_av1.cpp  | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git 
a/src/gallium/drivers/d3d12/d3d12_video_encoder_bitstream_builder_av1.cpp 
b/src/gallium/drivers/d3d12/d3d12_video_encoder_bitstream_builder_av1.cpp
index 96b7e32eb8e..9cb62b9ef4e 100644
--- a/src/gallium/drivers/d3d12/d3d12_video_encoder_bitstream_builder_av1.cpp
+++ b/src/gallium/drivers/d3d12/d3d12_video_encoder_bitstream_builder_av1.cpp
@@ -307,6 +307,14 @@ get_relative_dist(int a, int b, int OrderHintBits, uint8_t 
enable_order_hint)
    return diff;
 }
 
+static uint32_t
+tile_log2(uint32_t blkSize, uint32_t target)
+{
+   uint32_t k = 0;
+   for (k = 0; (blkSize << k) < target; k++);
+   return k;
+}
+
 void
 
d3d12_video_bitstream_builder_av1::write_pic_data(d3d12_video_encoder_bitstream 
*pBit,
                                                   const av1_seq_header_t 
*pSeqHdr,
@@ -438,13 +446,13 @@ 
d3d12_video_bitstream_builder_av1::write_pic_data(d3d12_video_encoder_bitstream
          unsigned maxTileWidthSb = 
pPicHdr->tile_info.tile_support_caps.MaxTileWidth;
          unsigned maxTileAreaSb = 
pPicHdr->tile_info.tile_support_caps.MaxTileArea;
 
-         unsigned minLog2TileCols = 
log2(pPicHdr->tile_info.tile_support_caps.MinTileCols);
-         unsigned maxLog2TileCols = 
log2(pPicHdr->tile_info.tile_support_caps.MaxTileCols);
-         unsigned log2TileCols = 
log2(pPicHdr->tile_info.tile_partition.ColCount);
+         unsigned minLog2TileCols = tile_log2(maxTileWidthSb, 
pPicHdr->tile_info.tile_support_caps.MinTileCols);
+         unsigned maxLog2TileCols = tile_log2(1, 
pPicHdr->tile_info.tile_support_caps.MaxTileCols);
+         unsigned log2TileCols = tile_log2(1, 
pPicHdr->tile_info.tile_partition.ColCount);
 
-         unsigned minLog2TileRows = 
log2(pPicHdr->tile_info.tile_support_caps.MinTileRows);
-         unsigned maxLog2TileRows = 
log2(pPicHdr->tile_info.tile_support_caps.MaxTileRows);
-         unsigned log2TileRows = 
log2(pPicHdr->tile_info.tile_partition.RowCount);
+         unsigned minLog2TileRows = tile_log2(1, 
pPicHdr->tile_info.tile_support_caps.MinTileRows);
+         unsigned maxLog2TileRows = tile_log2(1, 
pPicHdr->tile_info.tile_support_caps.MaxTileRows);
+         unsigned log2TileRows = tile_log2(1, 
pPicHdr->tile_info.tile_partition.RowCount);
 
          pBit->put_bits(1, pPicHdr->tile_info.uniform_tile_spacing_flag);   // 
uniform_tile_spacing_flag
 
@@ -862,7 +870,7 @@ 
d3d12_video_bitstream_builder_av1::calculate_tile_group_obu_size(
 
    bool tile_start_and_end_present_flag = !(tileGroup.tg_start == 0 && 
(tileGroup.tg_end == (NumTiles - 1)));
    if (!(NumTiles == 1 || !tile_start_and_end_present_flag)) {
-      uint8_t tileBits = log2(TilesPartition.ColCount) + 
log2(TilesPartition.RowCount);
+      uint8_t tileBits = tile_log2(1, TilesPartition.ColCount) + tile_log2(1, 
TilesPartition.RowCount);
       tile_group_obu_size_bits += tileBits;   // tg_start      f(tileBits)
       tile_group_obu_size_bits += tileBits;   // tg_end           f(tileBits)
    }

Reply via email to