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

Author: Sil Vilerino <[email protected]>
Date:   Sat Apr 15 16:10:30 2023 -0400

d3d12: Support rate control HRD and MaxFrameSize 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      | 59 +++++++++----------
 src/gallium/drivers/d3d12/d3d12_video_enc_h264.cpp | 67 ++++++++++++++++++++++
 src/gallium/drivers/d3d12/d3d12_video_enc_hevc.cpp | 67 ++++++++++++++++++++++
 src/gallium/drivers/d3d12/d3d12_video_screen.cpp   |  2 +
 src/gallium/drivers/d3d12/d3d12_video_types.h      | 12 ----
 5 files changed, 162 insertions(+), 45 deletions(-)

diff --git a/src/gallium/drivers/d3d12/d3d12_video_enc.cpp 
b/src/gallium/drivers/d3d12/d3d12_video_enc.cpp
index bcd19809758..c512cce501d 100644
--- a/src/gallium/drivers/d3d12/d3d12_video_enc.cpp
+++ b/src/gallium/drivers/d3d12/d3d12_video_enc.cpp
@@ -792,45 +792,38 @@ bool 
d3d12_video_encoder_negotiate_requested_features_and_d3d12_driver_caps(stru
    ///   
 
    if ((capEncoderSupportData.ValidationFlags & 
(D3D12_VIDEO_ENCODER_VALIDATION_FLAG_RATE_CONTROL_CONFIGURATION_NOT_SUPPORTED | 
D3D12_VIDEO_ENCODER_VALIDATION_FLAG_RATE_CONTROL_MODE_NOT_SUPPORTED)) != 0) {
+      debug_printf("[d3d12_video_encoder] WARNING: Requested rate control is 
not supported, trying fallback to unsetting optional features\n");
 
-      if (D3D12_VIDEO_ENC_FALLBACK_RATE_CONTROL_CONFIG){ // Check if fallback 
mode is enabled, or we should just fail without support
+      bool isRequestingVBVSizesSupported = 
((capEncoderSupportData.SupportFlags & 
D3D12_VIDEO_ENCODER_SUPPORT_FLAG_RATE_CONTROL_VBV_SIZE_CONFIG_AVAILABLE) != 0);
+      bool isClientRequestingVBVSizes = 
((pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Flags & 
D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_VBV_SIZES) != 0);
       
-         debug_printf("[d3d12_video_encoder] WARNING: Requested rate control 
is not supported, trying fallback to unsetting optional features\n");
-
-         bool isRequestingVBVSizesSupported = 
((capEncoderSupportData.SupportFlags & 
D3D12_VIDEO_ENCODER_SUPPORT_FLAG_RATE_CONTROL_VBV_SIZE_CONFIG_AVAILABLE) != 0);
-         bool isClientRequestingVBVSizes = 
((pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Flags & 
D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_VBV_SIZES) != 0);
-         
-         if(isClientRequestingVBVSizes && !isRequestingVBVSizesSupported) {
-            debug_printf("[d3d12_video_encoder] WARNING: Requested 
D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_VBV_SIZES with VBVCapacity (bits): 
%" PRIu64 " and InitialVBVFullness (bits) %" PRIu64 " is not supported, will 
continue encoding unsetting this feature as fallback.\n",
-                  
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.VBVCapacity,
-                  
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.InitialVBVFullness);
-
-            pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Flags 
&= ~D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_VBV_SIZES;
-            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.VBVCapacity
 = 0;
-            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.InitialVBVFullness
 = 0;
-         }
-         
-         bool isRequestingPeakFrameSizeSupported = 
((capEncoderSupportData.SupportFlags & 
D3D12_VIDEO_ENCODER_SUPPORT_FLAG_RATE_CONTROL_MAX_FRAME_SIZE_AVAILABLE) != 0);
-         bool isClientRequestingPeakFrameSize = 
((pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Flags & 
D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_MAX_FRAME_SIZE) != 0);
-
-         if(isClientRequestingPeakFrameSize && 
!isRequestingPeakFrameSizeSupported) {
-            debug_printf("[d3d12_video_encoder] WARNING: Requested 
D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_MAX_FRAME_SIZE with 
MaxFrameBitSize %" PRIu64 " but the feature is not supported, will continue 
encoding unsetting this feature as fallback.\n",
-               
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_VBR.MaxFrameBitSize);
+      if(isClientRequestingVBVSizes && !isRequestingVBVSizesSupported) {
+         debug_printf("[d3d12_video_encoder] WARNING: Requested 
D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_VBV_SIZES with VBVCapacity (bits): 
%" PRIu64 " and InitialVBVFullness (bits) %" PRIu64 " is not supported, will 
continue encoding unsetting this feature as fallback.\n",
+               
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.VBVCapacity,
+               
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.InitialVBVFullness);
+
+         pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Flags &= 
~D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_VBV_SIZES;
+         
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.VBVCapacity
 = 0;
+         
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.InitialVBVFullness
 = 0;
+      }
 
-            pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Flags 
&= ~D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_MAX_FRAME_SIZE;
-            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_VBR.MaxFrameBitSize
 = 0;
-         }
+      bool isRequestingPeakFrameSizeSupported = 
((capEncoderSupportData.SupportFlags & 
D3D12_VIDEO_ENCODER_SUPPORT_FLAG_RATE_CONTROL_MAX_FRAME_SIZE_AVAILABLE) != 0);
+      bool isClientRequestingPeakFrameSize = 
((pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Flags & 
D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_MAX_FRAME_SIZE) != 0);
 
-         ///
-         /// Try fallback configuration
-         ///
-         configSupported = 
d3d12_video_encoder_query_d3d12_driver_caps(pD3D12Enc, /*inout*/ 
capEncoderSupportData)
-          && (((capEncoderSupportData.SupportFlags & 
D3D12_VIDEO_ENCODER_SUPPORT_FLAG_GENERAL_SUPPORT_OK) != 0)
-                           && (capEncoderSupportData.ValidationFlags == 
D3D12_VIDEO_ENCODER_VALIDATION_FLAG_NONE));
+      if(isClientRequestingPeakFrameSize && 
!isRequestingPeakFrameSizeSupported) {
+         debug_printf("[d3d12_video_encoder] WARNING: Requested 
D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_MAX_FRAME_SIZE with 
MaxFrameBitSize %" PRIu64 " but the feature is not supported, will continue 
encoding unsetting this feature as fallback.\n",
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_VBR.MaxFrameBitSize);
 
-      } else {
-         debug_printf("[d3d12_video_encoder] WARNING: Requested rate control 
is not supported. To continue with a fallback, must enable the OS environment 
variable D3D12_VIDEO_ENC_FALLBACK_RATE_CONTROL_CONFIG\n");
+         pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Flags &= 
~D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_MAX_FRAME_SIZE;
+         
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_VBR.MaxFrameBitSize
 = 0;
       }
+
+      ///
+      /// Try fallback configuration
+      ///
+      configSupported = d3d12_video_encoder_query_d3d12_driver_caps(pD3D12Enc, 
/*inout*/ capEncoderSupportData)
+         && (((capEncoderSupportData.SupportFlags & 
D3D12_VIDEO_ENCODER_SUPPORT_FLAG_GENERAL_SUPPORT_OK) != 0)
+                        && (capEncoderSupportData.ValidationFlags == 
D3D12_VIDEO_ENCODER_VALIDATION_FLAG_NONE));
    }
 
    if(!configSupported) {
diff --git a/src/gallium/drivers/d3d12/d3d12_video_enc_h264.cpp 
b/src/gallium/drivers/d3d12/d3d12_video_enc_h264.cpp
index 1783c37f2d6..c3d94dc71ae 100644
--- a/src/gallium/drivers/d3d12/d3d12_video_enc_h264.cpp
+++ b/src/gallium/drivers/d3d12/d3d12_video_enc_h264.cpp
@@ -51,6 +51,39 @@ d3d12_video_encoder_update_current_rate_control_h264(struct 
d3d12_video_encoder
             picture->rate_ctrl[0].target_bitrate;
          
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_VBR.PeakBitRate
 =
             picture->rate_ctrl[0].peak_bitrate;
+
+         if (D3D12_VIDEO_ENC_CBR_FORCE_VBV_EQUAL_BITRATE) {
+            debug_printf("[d3d12_video_encoder_h264] 
d3d12_video_encoder_update_current_rate_control_h264 
D3D12_VIDEO_ENC_CBR_FORCE_VBV_EQUAL_BITRATE environment variable is set, "
+                       ", forcing VBV Size = VBV Initial Capacity = Target 
Bitrate = %" PRIu64 " (bits)\n", 
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.TargetBitRate);
+            pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Flags 
|=
+               D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_VBV_SIZES;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.VBVCapacity
 =
+               
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.TargetBitRate;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.InitialVBVFullness
 =
+               
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.TargetBitRate;
+         } else if (picture->rate_ctrl[0].app_requested_hrd_buffer) {
+            debug_printf("[d3d12_video_encoder_h264] 
d3d12_video_encoder_update_current_rate_control_h264 HRD required by app,"
+                       " setting VBV Size = %d (bits) - VBV Initial Capacity 
%d (bits)\n", picture->rate_ctrl[0].vbv_buffer_size, 
picture->rate_ctrl[0].vbv_buf_initial_size);
+            pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Flags 
|=
+               D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_VBV_SIZES;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_VBR.VBVCapacity
 =
+               picture->rate_ctrl[0].vbv_buffer_size;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_VBR.InitialVBVFullness
 =
+               picture->rate_ctrl[0].vbv_buf_initial_size;
+         }
+
+         if (picture->rate_ctrl[0].max_au_size > 0) {
+            pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Flags 
|=
+               D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_MAX_FRAME_SIZE;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_VBR.MaxFrameBitSize
 =
+               picture->rate_ctrl[0].max_au_size;
+
+            debug_printf(
+               "[d3d12_video_encoder_h264] 
d3d12_video_encoder_update_current_rate_control_h264 "
+               "Upper layer requested explicit MaxFrameBitSize: %" PRIu64 "\n",
+               
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_VBR.MaxFrameBitSize);
+         }
+
       } break;
       case PIPE_H2645_ENC_RATE_CONTROL_METHOD_QUALITY_VARIABLE:
       {
@@ -61,6 +94,19 @@ d3d12_video_encoder_update_current_rate_control_h264(struct 
d3d12_video_encoder
             picture->rate_ctrl[0].peak_bitrate;
             
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_QVBR.ConstantQualityTarget
 =
             picture->rate_ctrl[0].vbr_quality_factor;
+
+         if (picture->rate_ctrl[0].max_au_size > 0) {
+            pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Flags 
|=
+               D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_MAX_FRAME_SIZE;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_QVBR.MaxFrameBitSize
 =
+               picture->rate_ctrl[0].max_au_size;
+
+            debug_printf(
+               "[d3d12_video_encoder_h264] 
d3d12_video_encoder_update_current_rate_control_h264 "
+               "Upper layer requested explicit MaxFrameBitSize: %" PRIu64 "\n",
+               
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_QVBR.MaxFrameBitSize);
+         }
+
       } break;
       case PIPE_H2645_ENC_RATE_CONTROL_METHOD_CONSTANT_SKIP:
       case PIPE_H2645_ENC_RATE_CONTROL_METHOD_CONSTANT:
@@ -82,6 +128,27 @@ d3d12_video_encoder_update_current_rate_control_h264(struct 
d3d12_video_encoder
                
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.TargetBitRate;
             
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.InitialVBVFullness
 =
                
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.TargetBitRate;
+         } else if (picture->rate_ctrl[0].app_requested_hrd_buffer) {
+            debug_printf("[d3d12_video_encoder_h264] 
d3d12_video_encoder_update_current_rate_control_h264 HRD required by app,"
+                       " setting VBV Size = %d (bits) - VBV Initial Capacity 
%d (bits)\n", picture->rate_ctrl[0].vbv_buffer_size, 
picture->rate_ctrl[0].vbv_buf_initial_size);
+            pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Flags 
|=
+               D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_VBV_SIZES;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.VBVCapacity
 =
+               picture->rate_ctrl[0].vbv_buffer_size;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.InitialVBVFullness
 =
+               picture->rate_ctrl[0].vbv_buf_initial_size;
+         }
+
+         if (picture->rate_ctrl[0].max_au_size > 0) {
+            pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Flags 
|=
+               D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_MAX_FRAME_SIZE;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.MaxFrameBitSize
 =
+               picture->rate_ctrl[0].max_au_size;
+
+            debug_printf(
+               "[d3d12_video_encoder_h264] 
d3d12_video_encoder_update_current_rate_control_h264 "
+               "Upper layer requested explicit MaxFrameBitSize: %" PRIu64 "\n",
+               
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.MaxFrameBitSize);
          }
 
       } break;
diff --git a/src/gallium/drivers/d3d12/d3d12_video_enc_hevc.cpp 
b/src/gallium/drivers/d3d12/d3d12_video_enc_hevc.cpp
index 1949125725c..7760dfce14f 100644
--- a/src/gallium/drivers/d3d12/d3d12_video_enc_hevc.cpp
+++ b/src/gallium/drivers/d3d12/d3d12_video_enc_hevc.cpp
@@ -51,6 +51,39 @@ d3d12_video_encoder_update_current_rate_control_hevc(struct 
d3d12_video_encoder
             picture->rc.target_bitrate;
          
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_VBR.PeakBitRate
 =
             picture->rc.peak_bitrate;
+
+         if (D3D12_VIDEO_ENC_CBR_FORCE_VBV_EQUAL_BITRATE) {
+            debug_printf("[d3d12_video_encoder_hevc] 
d3d12_video_encoder_update_current_rate_control_hevc 
D3D12_VIDEO_ENC_CBR_FORCE_VBV_EQUAL_BITRATE environment variable is set, "
+                       ", forcing VBV Size = VBV Initial Capacity = Target 
Bitrate = %" PRIu64 " (bits)\n", 
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.TargetBitRate);
+            pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Flags 
|=
+               D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_VBV_SIZES;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.VBVCapacity
 =
+               
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.TargetBitRate;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.InitialVBVFullness
 =
+               
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.TargetBitRate;
+         } else if (picture->rc.app_requested_hrd_buffer) {
+            debug_printf("[d3d12_video_encoder_hevc] 
d3d12_video_encoder_update_current_rate_control_hevc HRD required by app,"
+                       " setting VBV Size = %d (bits) - VBV Initial Capacity 
%d (bits)\n", picture->rc.vbv_buffer_size, picture->rc.vbv_buf_initial_size);
+            pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Flags 
|=
+               D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_VBV_SIZES;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_VBR.VBVCapacity
 =
+               picture->rc.vbv_buffer_size;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_VBR.InitialVBVFullness
 =
+               picture->rc.vbv_buf_initial_size;
+         }
+
+         if (picture->rc.max_au_size > 0) {
+            pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Flags 
|=
+               D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_MAX_FRAME_SIZE;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_VBR.MaxFrameBitSize
 =
+               picture->rc.max_au_size;
+
+            debug_printf(
+               "[d3d12_video_encoder_hevc] 
d3d12_video_encoder_update_current_rate_control_hevc "
+               "Upper layer requested explicit MaxFrameBitSize: %" PRIu64 "\n",
+               
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_VBR.MaxFrameBitSize);
+         }
+
       } break;
       case PIPE_H2645_ENC_RATE_CONTROL_METHOD_QUALITY_VARIABLE:
       {
@@ -61,6 +94,19 @@ d3d12_video_encoder_update_current_rate_control_hevc(struct 
d3d12_video_encoder
             picture->rc.peak_bitrate;
             
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_QVBR.ConstantQualityTarget
 =
             picture->rc.vbr_quality_factor;
+
+         if (picture->rc.max_au_size > 0) {
+            pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Flags 
|=
+               D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_MAX_FRAME_SIZE;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_QVBR.MaxFrameBitSize
 =
+               picture->rc.max_au_size;
+
+            debug_printf(
+               "[d3d12_video_encoder_hevc] 
d3d12_video_encoder_update_current_rate_control_hevc "
+               "Upper layer requested explicit MaxFrameBitSize: %" PRIu64 "\n",
+               
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_QVBR.MaxFrameBitSize);
+         }
+
       } break;
       case PIPE_H2645_ENC_RATE_CONTROL_METHOD_CONSTANT_SKIP:
       case PIPE_H2645_ENC_RATE_CONTROL_METHOD_CONSTANT:
@@ -82,6 +128,27 @@ d3d12_video_encoder_update_current_rate_control_hevc(struct 
d3d12_video_encoder
                
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.TargetBitRate;
             
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.InitialVBVFullness
 =
                
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.TargetBitRate;
+         } else if (picture->rc.app_requested_hrd_buffer) {
+            debug_printf("[d3d12_video_encoder_hevc] 
d3d12_video_encoder_update_current_rate_control_hevc HRD required by app,"
+                       " setting VBV Size = %d (bits) - VBV Initial Capacity 
%d (bits)\n", picture->rc.vbv_buffer_size, picture->rc.vbv_buf_initial_size);
+            pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Flags 
|=
+               D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_VBV_SIZES;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.VBVCapacity
 =
+               picture->rc.vbv_buffer_size;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.InitialVBVFullness
 =
+               picture->rc.vbv_buf_initial_size;
+         }
+
+         if (picture->rc.max_au_size > 0) {
+            pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Flags 
|=
+               D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_MAX_FRAME_SIZE;
+            
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.MaxFrameBitSize
 =
+               picture->rc.max_au_size;
+
+            debug_printf(
+               "[d3d12_video_encoder_hevc] 
d3d12_video_encoder_update_current_rate_control_hevc "
+               "Upper layer requested explicit MaxFrameBitSize: %" PRIu64 "\n",
+               
pD3D12Enc->m_currentEncodeConfig.m_encoderRateControlDesc.m_Config.m_Configuration_CBR.MaxFrameBitSize);
          }
 
       } break;
diff --git a/src/gallium/drivers/d3d12/d3d12_video_screen.cpp 
b/src/gallium/drivers/d3d12/d3d12_video_screen.cpp
index eb192e078d8..a86ef933924 100644
--- a/src/gallium/drivers/d3d12/d3d12_video_screen.cpp
+++ b/src/gallium/drivers/d3d12/d3d12_video_screen.cpp
@@ -1112,6 +1112,8 @@ d3d12_screen_get_video_param_encode(struct pipe_screen 
*pscreen,
          return true;
       case PIPE_VIDEO_CAP_SUPPORTS_CONTIGUOUS_PLANES_MAP:
          return true;
+      case PIPE_VIDEO_CAP_ENC_SUPPORTS_MAX_FRAME_SIZE:
+         return true;
       case PIPE_VIDEO_CAP_ENC_RATE_CONTROL_QVBR:
       {
          D3D12_FEATURE_DATA_VIDEO_ENCODER_RATE_CONTROL_MODE 
capRateControlModeData =
diff --git a/src/gallium/drivers/d3d12/d3d12_video_types.h 
b/src/gallium/drivers/d3d12/d3d12_video_types.h
index a40211ead75..08059dd8557 100644
--- a/src/gallium/drivers/d3d12/d3d12_video_types.h
+++ b/src/gallium/drivers/d3d12/d3d12_video_types.h
@@ -56,18 +56,6 @@ GetDesc(ID3D12VideoDecoderHeap *heap)
 }
 #endif
 
-// Allow encoder to continue the encoding session when an optional 
-// rate control mode such as the following is used but not supported
-//
-// D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_VBV_SIZES
-// D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_MAX_FRAME_SIZE
-//
-// If setting this OS Env variable to true, the encoding process will 
continue, disregarding the settings
-// requested for the optional RC mode
-//
-
-const bool D3D12_VIDEO_ENC_FALLBACK_RATE_CONTROL_CONFIG = 
debug_get_bool_option("D3D12_VIDEO_ENC_FALLBACK_RATE_CONTROL_CONFIG", false);
-
 /* For CBR mode, to guarantee bitrate of generated stream complies with
 * target bitrate (e.g. no over +/-10%), vbv_buffer_size should be same
 * as target bitrate. Controlled by OS env var 
D3D12_VIDEO_ENC_CBR_FORCE_VBV_EQUAL_BITRATE

Reply via email to