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

Author: Sil Vilerino <[email protected]>
Date:   Fri Dec  1 17:18:10 2023 -0500

d3d12: Use enc_constraint_set_flags for H264 NALU writing

Reviewed-by: Jesse Natalie <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26573>

---

 src/gallium/drivers/d3d12/d3d12_video_enc_h264.cpp   |  5 +----
 .../d3d12_video_encoder_bitstream_builder_h264.cpp   | 20 ++++----------------
 .../d3d12/d3d12_video_encoder_nalu_writer_h264.cpp   |  9 ++-------
 .../d3d12/d3d12_video_encoder_nalu_writer_h264.h     |  3 +--
 src/gallium/drivers/d3d12/d3d12_video_screen.cpp     |  3 +--
 src/gallium/drivers/d3d12/d3d12_video_types.h        |  3 +--
 6 files changed, 10 insertions(+), 33 deletions(-)

diff --git a/src/gallium/drivers/d3d12/d3d12_video_enc_h264.cpp 
b/src/gallium/drivers/d3d12/d3d12_video_enc_h264.cpp
index 7357039b385..347660f2c09 100644
--- a/src/gallium/drivers/d3d12/d3d12_video_enc_h264.cpp
+++ b/src/gallium/drivers/d3d12/d3d12_video_enc_h264.cpp
@@ -591,11 +591,9 @@ d3d12_video_encoder_convert_level_h264(uint32_t 
h264SpecLevel)
 
 void
 
d3d12_video_encoder_convert_from_d3d12_level_h264(D3D12_VIDEO_ENCODER_LEVELS_H264
 level12,
-                                                  uint32_t &specLevel,
-                                                  uint32_t 
&constraint_set3_flag)
+                                                  uint32_t &specLevel)
 {
    specLevel = 0;
-   constraint_set3_flag = 0;
 
    switch (level12) {
       case D3D12_VIDEO_ENCODER_LEVELS_H264_1:
@@ -605,7 +603,6 @@ 
d3d12_video_encoder_convert_from_d3d12_level_h264(D3D12_VIDEO_ENCODER_LEVELS_H26
       case D3D12_VIDEO_ENCODER_LEVELS_H264_1b:
       {
          specLevel = 11;
-         constraint_set3_flag = 1;
       } break;
       case D3D12_VIDEO_ENCODER_LEVELS_H264_11:
       {
diff --git 
a/src/gallium/drivers/d3d12/d3d12_video_encoder_bitstream_builder_h264.cpp 
b/src/gallium/drivers/d3d12/d3d12_video_encoder_bitstream_builder_h264.cpp
index aff4d715b2a..9756e822d43 100644
--- a/src/gallium/drivers/d3d12/d3d12_video_encoder_bitstream_builder_h264.cpp
+++ b/src/gallium/drivers/d3d12/d3d12_video_encoder_bitstream_builder_h264.cpp
@@ -69,20 +69,10 @@ d3d12_video_bitstream_builder_h264::build_sps(const struct 
pipe_h264_enc_seq_par
                                               size_t &                         
           writtenBytes)
 {
    H264_SPEC_PROFILES profile_idc          = (H264_SPEC_PROFILES) 
u_get_h264_profile_idc(profile);
-   uint32_t           constraint_set1_flag = ((profile_idc == 
H264_PROFILE_MAIN) || (profile_idc == H264_PROFILE_CONSTRAINED_BASELINE)) ? 1 : 
0;
-   uint32_t           constraint_set3_flag = 0;
    uint32_t           level_idc            = 0;
    d3d12_video_encoder_convert_from_d3d12_level_h264(
       level,
-      level_idc,
-      constraint_set3_flag /*Always 0 except if level is 11 or 1b in which 
case 0 means 11, 1 means 1b*/);
-
-   // constraint_set3_flag is for Main profile only and levels 11 or 1b: 
levels 11 if off, level 1b if on. Always 0 for
-   // HIGH/HIGH10 profiles
-   if ((profile == PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH) || (profile == 
PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH10)) {
-      // Force 0 for high profiles
-      constraint_set3_flag = 0;
-   }
+      level_idc);
 
    assert((inputFmt == DXGI_FORMAT_NV12) || (inputFmt == DXGI_FORMAT_P010));
 
@@ -112,8 +102,7 @@ d3d12_video_bitstream_builder_h264::build_sps(const struct 
pipe_h264_enc_seq_par
    }
 
    H264_SPS spsStructure = { static_cast<uint32_t>(profile_idc),
-                             constraint_set1_flag,
-                             constraint_set3_flag,
+                             seqData.enc_constraint_set_flags,
                              level_idc,
                              seq_parameter_set_id,
                              bit_depth_luma_minus8,
@@ -300,7 +289,7 @@ d3d12_video_bitstream_builder_h264::print_sps(const 
H264_SPS &sps)
    // d3d12_video_encoder_bitstream_builder_h264.h
 
    static_assert(sizeof(H264_SPS) ==
-                (sizeof(uint32_t) * 21 + sizeof(H264_VUI_PARAMS)), "Update the 
print function if structure changes");
+                (sizeof(uint32_t) * 20 + sizeof(H264_VUI_PARAMS)), "Update the 
print function if structure changes");
 
    static_assert(sizeof(H264_VUI_PARAMS) ==
                  (sizeof(uint32_t) * 32 + 2*sizeof(H264_HRD_PARAMS)), "Update 
the print function if structure changes");
@@ -311,8 +300,7 @@ d3d12_video_bitstream_builder_h264::print_sps(const 
H264_SPS &sps)
    // Declared fields from definition in 
d3d12_video_encoder_bitstream_builder_h264.h
    debug_printf("[D3D12 d3d12_video_bitstream_builder_h264] H264_SPS values 
below:\n");
    debug_printf("profile_idc: %d\n", sps.profile_idc);
-   debug_printf("constraint_set1_flag: %d\n", sps.constraint_set1_flag);
-   debug_printf("constraint_set3_flag: %d\n", sps.constraint_set3_flag);
+   debug_printf("constraint_set_flags: %x\n", sps.constraint_set_flags);
    debug_printf("level_idc: %d\n", sps.level_idc);
    debug_printf("seq_parameter_set_id: %d\n", sps.seq_parameter_set_id);
    debug_printf("bit_depth_luma_minus8: %d\n", sps.bit_depth_luma_minus8);
diff --git a/src/gallium/drivers/d3d12/d3d12_video_encoder_nalu_writer_h264.cpp 
b/src/gallium/drivers/d3d12/d3d12_video_encoder_nalu_writer_h264.cpp
index 3f4ef3e1fe8..6957550303e 100644
--- a/src/gallium/drivers/d3d12/d3d12_video_encoder_nalu_writer_h264.cpp
+++ b/src/gallium/drivers/d3d12/d3d12_video_encoder_nalu_writer_h264.cpp
@@ -48,13 +48,8 @@ 
d3d12_video_nalu_writer_h264::write_sps_bytes(d3d12_video_encoder_bitstream *pBi
    assert(pSPS->seq_parameter_set_id < 32);
 
    pBitstream->put_bits(8, pSPS->profile_idc);
-   pBitstream->put_bits(1, 0);   // constraint_set0_flag
-   pBitstream->put_bits(1, pSPS->constraint_set1_flag);
-   pBitstream->put_bits(1, 0);   // constraint_set2_flag
-   pBitstream->put_bits(1, pSPS->constraint_set3_flag);
-   pBitstream->put_bits(1, 0);   // constraint_set4_flag
-   pBitstream->put_bits(1, 0);   // constraint_set5_flag
-   pBitstream->put_bits(2, 0);
+   pBitstream->put_bits(6, pSPS->constraint_set_flags);
+   pBitstream->put_bits(2, 0); // reserved_zero_2bits
    pBitstream->put_bits(8, pSPS->level_idc);
    pBitstream->exp_Golomb_ue(pSPS->seq_parameter_set_id);
 
diff --git a/src/gallium/drivers/d3d12/d3d12_video_encoder_nalu_writer_h264.h 
b/src/gallium/drivers/d3d12/d3d12_video_encoder_nalu_writer_h264.h
index 6af79312539..b2ea73ef1ac 100644
--- a/src/gallium/drivers/d3d12/d3d12_video_encoder_nalu_writer_h264.h
+++ b/src/gallium/drivers/d3d12/d3d12_video_encoder_nalu_writer_h264.h
@@ -110,8 +110,7 @@ struct H264_VUI_PARAMS
 struct H264_SPS
 {
    uint32_t profile_idc;
-   uint32_t constraint_set1_flag;
-   uint32_t constraint_set3_flag;
+   uint32_t constraint_set_flags;
    uint32_t level_idc;
    uint32_t seq_parameter_set_id;
    uint32_t bit_depth_luma_minus8;
diff --git a/src/gallium/drivers/d3d12/d3d12_video_screen.cpp 
b/src/gallium/drivers/d3d12/d3d12_video_screen.cpp
index 570d70a9ac0..6b4a5cb21c1 100644
--- a/src/gallium/drivers/d3d12/d3d12_video_screen.cpp
+++ b/src/gallium/drivers/d3d12/d3d12_video_screen.cpp
@@ -892,8 +892,7 @@ d3d12_has_video_encode_support(struct pipe_screen *pscreen,
                                                                 minLvl,
                                                                 maxLvl,
                                                                 
spD3D12VideoDevice.Get())) {
-            uint32_t constraintset3flag = false;
-            
d3d12_video_encoder_convert_from_d3d12_level_h264(maxLvlSettingH264, 
maxLvlSpec, constraintset3flag);
+            
d3d12_video_encoder_convert_from_d3d12_level_h264(maxLvlSettingH264, 
maxLvlSpec);
             supportsProfile = true;
 
             DXGI_FORMAT encodeFormat = 
d3d12_convert_pipe_video_profile_to_dxgi_format(profile);
diff --git a/src/gallium/drivers/d3d12/d3d12_video_types.h 
b/src/gallium/drivers/d3d12/d3d12_video_types.h
index fb319278fb7..8b03289544f 100644
--- a/src/gallium/drivers/d3d12/d3d12_video_types.h
+++ b/src/gallium/drivers/d3d12/d3d12_video_types.h
@@ -132,8 +132,7 @@ struct d3d12_video_decode_output_conversion_arguments
 
 void
 
d3d12_video_encoder_convert_from_d3d12_level_h264(D3D12_VIDEO_ENCODER_LEVELS_H264
 level12,
-                                                  uint32_t &                   
   specLevel,
-                                                  uint32_t &                   
   constraint_set3_flag);
+                                                  uint32_t &                   
   specLevel);
 void
 
d3d12_video_encoder_convert_from_d3d12_level_hevc(D3D12_VIDEO_ENCODER_LEVELS_HEVC
 level12,
                                                   uint32_t &                   
   specLevel);

Reply via email to