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

Author: Sil Vilerino <[email protected]>
Date:   Sun Apr 16 13:20:55 2023 -0400

d3d12: Support QPMin/QPMax app params

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

---

 src/gallium/drivers/d3d12/d3d12_video_enc.cpp      | 13 +++++++
 src/gallium/drivers/d3d12/d3d12_video_enc_h264.cpp | 40 ++++++++++++++++++++++
 src/gallium/drivers/d3d12/d3d12_video_enc_hevc.cpp | 39 +++++++++++++++++++++
 3 files changed, 92 insertions(+)

diff --git a/src/gallium/drivers/d3d12/d3d12_video_enc.cpp 
b/src/gallium/drivers/d3d12/d3d12_video_enc.cpp
index c512cce501d..d8a9e8b81b9 100644
--- a/src/gallium/drivers/d3d12/d3d12_video_enc.cpp
+++ b/src/gallium/drivers/d3d12/d3d12_video_enc.cpp
@@ -818,6 +818,19 @@ bool 
d3d12_video_encoder_negotiate_requested_features_and_d3d12_driver_caps(stru
          
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_VBR.MaxFrameBitSize
 = 0;
       }
 
+      bool isRequestingQPRangesSupported = 
((capEncoderSupportData.SupportFlags & 
D3D12_VIDEO_ENCODER_SUPPORT_FLAG_RATE_CONTROL_ADJUSTABLE_QP_RANGE_AVAILABLE) != 
0);
+      bool isClientRequestingQPRanges = 
((pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Flags & 
D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_QP_RANGE) != 0);
+
+      if(isClientRequestingQPRanges && !isRequestingQPRangesSupported) {
+         debug_printf("[d3d12_video_encoder] WARNING: Requested 
D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_QP_RANGE with QPMin %d QPMax %d 
but the feature is not supported, will continue encoding unsetting this feature 
as fallback.\n",
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.MinQP,
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.MaxQP);
+
+         pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Flags &= 
~D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_QP_RANGE;
+         
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.MinQP
 = 0;
+         
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.MaxQP
 = 0;
+      }
+
       ///
       /// Try fallback configuration
       ///
diff --git a/src/gallium/drivers/d3d12/d3d12_video_enc_h264.cpp 
b/src/gallium/drivers/d3d12/d3d12_video_enc_h264.cpp
index c3d94dc71ae..06745fc3f82 100644
--- a/src/gallium/drivers/d3d12/d3d12_video_enc_h264.cpp
+++ b/src/gallium/drivers/d3d12/d3d12_video_enc_h264.cpp
@@ -84,6 +84,19 @@ d3d12_video_encoder_update_current_rate_control_h264(struct 
d3d12_video_encoder
                
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_VBR.MaxFrameBitSize);
          }
 
+         if (picture->rate_ctrl[0].app_requested_qp_range) {
+            debug_printf(
+               "[d3d12_video_encoder_h264] 
d3d12_video_encoder_update_current_rate_control_h264 "
+               "Upper layer requested explicit MinQP: %d MaxQP: %d\n",
+               picture->rate_ctrl[0].min_qp, picture->rate_ctrl[0].max_qp);
+            pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Flags 
|=
+               D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_QP_RANGE;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_VBR.MinQP
 =
+               picture->rate_ctrl[0].min_qp;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_VBR.MaxQP
 =
+               picture->rate_ctrl[0].max_qp;
+         }
+
       } break;
       case PIPE_H2645_ENC_RATE_CONTROL_METHOD_QUALITY_VARIABLE:
       {
@@ -107,6 +120,19 @@ 
d3d12_video_encoder_update_current_rate_control_h264(struct d3d12_video_encoder
                
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_QVBR.MaxFrameBitSize);
          }
 
+         if (picture->rate_ctrl[0].app_requested_qp_range) {
+            debug_printf(
+               "[d3d12_video_encoder_h264] 
d3d12_video_encoder_update_current_rate_control_h264 "
+               "Upper layer requested explicit MinQP: %d MaxQP: %d\n",
+               picture->rate_ctrl[0].min_qp, picture->rate_ctrl[0].max_qp);
+            pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Flags 
|=
+               D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_QP_RANGE;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_QVBR.MinQP
 =
+               picture->rate_ctrl[0].min_qp;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_QVBR.MaxQP
 =
+               picture->rate_ctrl[0].max_qp;
+         }
+
       } break;
       case PIPE_H2645_ENC_RATE_CONTROL_METHOD_CONSTANT_SKIP:
       case PIPE_H2645_ENC_RATE_CONTROL_METHOD_CONSTANT:
@@ -151,6 +177,20 @@ 
d3d12_video_encoder_update_current_rate_control_h264(struct d3d12_video_encoder
                
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.MaxFrameBitSize);
          }
 
+         if (picture->rate_ctrl[0].app_requested_qp_range) {
+            debug_printf(
+               "[d3d12_video_encoder_h264] 
d3d12_video_encoder_update_current_rate_control_h264 "
+               "Upper layer requested explicit MinQP: %d MaxQP: %d\n",
+               picture->rate_ctrl[0].min_qp, picture->rate_ctrl[0].max_qp);
+
+            pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Flags 
|=
+               D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_QP_RANGE;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.MinQP
 =
+               picture->rate_ctrl[0].min_qp;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.MaxQP
 =
+               picture->rate_ctrl[0].max_qp;
+         }
+
       } break;
       case PIPE_H2645_ENC_RATE_CONTROL_METHOD_DISABLE:
       {
diff --git a/src/gallium/drivers/d3d12/d3d12_video_enc_hevc.cpp 
b/src/gallium/drivers/d3d12/d3d12_video_enc_hevc.cpp
index 7760dfce14f..ad766f46f97 100644
--- a/src/gallium/drivers/d3d12/d3d12_video_enc_hevc.cpp
+++ b/src/gallium/drivers/d3d12/d3d12_video_enc_hevc.cpp
@@ -84,6 +84,19 @@ d3d12_video_encoder_update_current_rate_control_hevc(struct 
d3d12_video_encoder
                
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_VBR.MaxFrameBitSize);
          }
 
+         if (picture->rc.app_requested_qp_range) {
+            debug_printf(
+               "[d3d12_video_encoder_hevc] 
d3d12_video_encoder_update_current_rate_control_hevc "
+               "Upper layer requested explicit MinQP: %d MaxQP: %d\n",
+               picture->rc.min_qp, picture->rc.max_qp);
+            pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Flags 
|=
+               D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_QP_RANGE;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_VBR.MinQP
 =
+               picture->rc.min_qp;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_VBR.MaxQP
 =
+               picture->rc.max_qp;
+         }
+
       } break;
       case PIPE_H2645_ENC_RATE_CONTROL_METHOD_QUALITY_VARIABLE:
       {
@@ -107,6 +120,19 @@ 
d3d12_video_encoder_update_current_rate_control_hevc(struct d3d12_video_encoder
                
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_QVBR.MaxFrameBitSize);
          }
 
+         if (picture->rc.app_requested_qp_range) {
+            debug_printf(
+               "[d3d12_video_encoder_hevc] 
d3d12_video_encoder_update_current_rate_control_hevc "
+               "Upper layer requested explicit MinQP: %d MaxQP: %d\n",
+               picture->rc.min_qp, picture->rc.max_qp);
+            pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Flags 
|=
+               D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_QP_RANGE;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_QVBR.MinQP
 =
+               picture->rc.min_qp;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_QVBR.MaxQP
 =
+               picture->rc.max_qp;
+         }
+
       } break;
       case PIPE_H2645_ENC_RATE_CONTROL_METHOD_CONSTANT_SKIP:
       case PIPE_H2645_ENC_RATE_CONTROL_METHOD_CONSTANT:
@@ -151,6 +177,19 @@ 
d3d12_video_encoder_update_current_rate_control_hevc(struct d3d12_video_encoder
                
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.MaxFrameBitSize);
          }
 
+         if (picture->rc.app_requested_qp_range) {
+            debug_printf(
+               "[d3d12_video_encoder_hevc] 
d3d12_video_encoder_update_current_rate_control_hevc "
+               "Upper layer requested explicit MinQP: %d MaxQP: %d\n",
+               picture->rc.min_qp, picture->rc.max_qp);
+            pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Flags 
|=
+               D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_QP_RANGE;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.MinQP
 =
+               picture->rc.min_qp;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.MaxQP
 =
+               picture->rc.max_qp;
+         }
+
       } break;
       case PIPE_H2645_ENC_RATE_CONTROL_METHOD_DISABLE:
       {

Reply via email to