@@ -14,6 +14,7 @@ use ash::vk;
1414use async_shutdown:: ShutdownManager ;
1515use tokio:: sync:: { broadcast, mpsc, watch} ;
1616
17+ use crate :: config:: RgbDirectMode ;
1718use crate :: session:: compositor:: frame:: { ExportedFrame , FrameColorSpace , HdrModeState } ;
1819use crate :: session:: manager:: SessionShutdownReason ;
1920
@@ -142,6 +143,7 @@ impl VideoPipeline {
142143 stop_session_manager : ShutdownManager < SessionShutdownReason > ,
143144 hdr_metadata_tx : watch:: Sender < HdrModeState > ,
144145 log_frame_spikes : bool ,
146+ rgb_direct_mode : RgbDirectMode ,
145147 ) -> Result < Self , ( ) > {
146148 tracing:: debug!( "Initializing video pipeline." ) ;
147149
@@ -159,6 +161,7 @@ impl VideoPipeline {
159161 max_reference_frames,
160162 encryption_key,
161163 log_frame_spikes,
164+ rgb_direct_mode,
162165 } ;
163166
164167 std:: thread:: Builder :: new ( )
@@ -192,6 +195,8 @@ struct VideoPipelineInner {
192195 max_reference_frames : u32 ,
193196 encryption_key : Option < Vec < u8 > > ,
194197 log_frame_spikes : bool ,
198+ /// Controls VK_VALVE_video_encode_rgb_conversion usage at encoder creation.
199+ rgb_direct_mode : RgbDirectMode ,
195200}
196201
197202impl VideoPipelineInner {
@@ -251,10 +256,32 @@ impl VideoPipelineInner {
251256
252257 // RGB-direct encode skips the compute-shader RGB→YUV pass and lets
253258 // the video encoder hardware do the conversion inline. Enabled
254- // whenever the device advertises VK_VALVE_video_encode_rgb_conversion.
255- let use_rgb_input = context. supports_rgb_direct_encode ( ) ;
256- if use_rgb_input {
257- tracing:: info!( "RGB-direct encode path active (VK_VALVE_video_encode_rgb_conversion)" ) ;
259+ // whenever the device advertises VK_VALVE_video_encode_rgb_conversion,
260+ // unless overridden via [stream.video] rgb_direct_encode in config.
261+ let device_supports_rgb_direct = context. supports_rgb_direct_encode ( ) ;
262+ let use_rgb_input = match self . rgb_direct_mode {
263+ RgbDirectMode :: Auto => device_supports_rgb_direct,
264+ RgbDirectMode :: Off => false ,
265+ RgbDirectMode :: Force => {
266+ if !device_supports_rgb_direct {
267+ return Err (
268+ "rgb_direct_encode = \" force\" but VK_VALVE_video_encode_rgb_conversion \
269+ is not advertised by this device"
270+ . to_string ( ) ,
271+ ) ;
272+ }
273+ true
274+ } ,
275+ } ;
276+ match ( self . rgb_direct_mode , device_supports_rgb_direct, use_rgb_input) {
277+ ( _, _, true ) => tracing:: info!( "RGB-direct encode path active (VK_VALVE_video_encode_rgb_conversion)" ) ,
278+ ( RgbDirectMode :: Off , true , _) => tracing:: info!(
279+ "Compute-shader RGB→YUV path active (rgb_direct_encode = \" off\" overrides device support)"
280+ ) ,
281+ ( _, false , _) => tracing:: info!(
282+ "Compute-shader RGB→YUV path active (VK_VALVE_video_encode_rgb_conversion not supported by this device)"
283+ ) ,
284+ _ => { } ,
258285 }
259286
260287 // Convert pixel format.
0 commit comments