@@ -127,7 +127,7 @@ pub struct VideoParams {
127127 pub color_space : u32 ,
128128 pub color_range : u32 ,
129129 pub bit_depth : u32 ,
130- pub _pad : u32 ,
130+ pub color_trc : u32 ,
131131 pub viewport_width : f32 ,
132132 pub viewport_height : f32 ,
133133 pub video_width : f32 ,
@@ -145,6 +145,7 @@ pub struct VideoState {
145145 pub color_space : u32 ,
146146 pub color_range : u32 ,
147147 pub bit_depth : u32 ,
148+ pub color_trc : u32 ,
148149}
149150
150151pub struct VulkanEngine < ' a > {
@@ -440,6 +441,17 @@ impl<'a> VulkanEngine<'a> {
440441 immediate_size : 0 ,
441442 } ) ;
442443
444+ // Shared shader headers — included at compile time, resolved via simple string replacement.
445+ // This is the single source of truth for AudioUniforms layout and glyph font.
446+ const SHADER_COMMON : & str = include_str ! ( "shaders/_common.wgsl" ) ;
447+ const SHADER_GLYPH_FONT : & str = include_str ! ( "shaders/_glyph_font.wgsl" ) ;
448+
449+ let resolve_shader_includes = |source : & str | -> String {
450+ source
451+ . replace ( "// INCLUDE: common" , SHADER_COMMON )
452+ . replace ( "// INCLUDE: glyph_font" , SHADER_GLYPH_FONT )
453+ } ;
454+
443455 let get_shader_source = |id : u32 | -> & ' static str {
444456 match id {
445457 0 => include_str ! ( "shaders/vis_spectrum.wgsl" ) ,
@@ -457,14 +469,14 @@ impl<'a> VulkanEngine<'a> {
457469 }
458470 } ;
459471
460- let shader_sources: Vec < & ' static str > = crate :: state:: VISUALIZERS . iter ( ) . map ( |v| get_shader_source ( v. id ) ) . collect ( ) ;
472+ let shader_sources: Vec < String > = crate :: state:: VISUALIZERS . iter ( ) . map ( |v| resolve_shader_includes ( get_shader_source ( v. id ) ) ) . collect ( ) ;
461473
462474 let mut render_pipelines = Vec :: new ( ) ;
463475
464476 let scope_fallback = device. push_error_scope ( wgpu:: ErrorFilter :: Validation ) ;
465477 let fallback_shader = device. create_shader_module ( wgpu:: ShaderModuleDescriptor {
466478 label : Some ( "Fallback Shader" ) ,
467- source : wgpu:: ShaderSource :: Wgsl ( std:: borrow:: Cow :: Borrowed ( shader_sources[ 0 ] ) ) ,
479+ source : wgpu:: ShaderSource :: Wgsl ( std:: borrow:: Cow :: Borrowed ( & shader_sources[ 0 ] ) ) ,
468480 } ) ;
469481
470482 let fallback_pipeline = device. create_render_pipeline ( & wgpu:: RenderPipelineDescriptor {
@@ -511,7 +523,7 @@ impl<'a> VulkanEngine<'a> {
511523
512524 let shader = device. create_shader_module ( wgpu:: ShaderModuleDescriptor {
513525 label : Some ( & format ! ( "Shader {}" , i) ) ,
514- source : wgpu:: ShaderSource :: Wgsl ( std:: borrow:: Cow :: Borrowed ( source) ) ,
526+ source : wgpu:: ShaderSource :: Wgsl ( std:: borrow:: Cow :: Borrowed ( source. as_str ( ) ) ) ,
515527 } ) ;
516528
517529 let pipeline = device. create_render_pipeline ( & wgpu:: RenderPipelineDescriptor {
@@ -657,7 +669,11 @@ impl<'a> VulkanEngine<'a> {
657669 cache : None ,
658670 } ) ;
659671
660- let hud_shader = device. create_shader_module ( wgpu:: include_wgsl!( "shaders/hud.wgsl" ) ) ;
672+ let hud_source = resolve_shader_includes ( include_str ! ( "shaders/hud.wgsl" ) ) ;
673+ let hud_shader = device. create_shader_module ( wgpu:: ShaderModuleDescriptor {
674+ label : Some ( "HUD Shader" ) ,
675+ source : wgpu:: ShaderSource :: Wgsl ( std:: borrow:: Cow :: Borrowed ( & hud_source) ) ,
676+ } ) ;
661677 let hud_pipeline = device. create_render_pipeline ( & wgpu:: RenderPipelineDescriptor {
662678 label : Some ( "HUD Pipeline" ) ,
663679 layout : Some ( & render_pipeline_layout) ,
@@ -740,7 +756,11 @@ impl<'a> VulkanEngine<'a> {
740756 wgpu:: BindGroupEntry { binding : 1 , resource : wgpu:: BindingResource :: TextureView ( & history_view) } ,
741757 ] ,
742758 } ) ;
743- let heatmap_compute_shader = device. create_shader_module ( wgpu:: include_wgsl!( "shaders/heatmap_compute.wgsl" ) ) ;
759+ let heatmap_source = resolve_shader_includes ( include_str ! ( "shaders/heatmap_compute.wgsl" ) ) ;
760+ let heatmap_compute_shader = device. create_shader_module ( wgpu:: ShaderModuleDescriptor {
761+ label : Some ( "Heatmap Compute Shader" ) ,
762+ source : wgpu:: ShaderSource :: Wgsl ( std:: borrow:: Cow :: Borrowed ( & heatmap_source) ) ,
763+ } ) ;
744764 let heatmap_compute_pipeline_layout = device. create_pipeline_layout ( & wgpu:: PipelineLayoutDescriptor {
745765 label : Some ( "heatmap_compute_layout" ) , bind_group_layouts : & [ Some ( & heatmap_compute_layout) ] , immediate_size : 0 ,
746766 } ) ;
@@ -826,7 +846,11 @@ impl<'a> VulkanEngine<'a> {
826846 ] ,
827847 } ) ;
828848
829- let ferrofluidsim_compute_shader = device. create_shader_module ( wgpu:: include_wgsl!( "shaders/ferrofluidsim_compute.wgsl" ) ) ;
849+ let ferrofluidsim_source = resolve_shader_includes ( include_str ! ( "shaders/ferrofluidsim_compute.wgsl" ) ) ;
850+ let ferrofluidsim_compute_shader = device. create_shader_module ( wgpu:: ShaderModuleDescriptor {
851+ label : Some ( "Ferrofluid Sim Compute Shader" ) ,
852+ source : wgpu:: ShaderSource :: Wgsl ( std:: borrow:: Cow :: Borrowed ( & ferrofluidsim_source) ) ,
853+ } ) ;
830854 let ferrofluidsim_pipeline_layout = device. create_pipeline_layout ( & wgpu:: PipelineLayoutDescriptor {
831855 label : Some ( "ferrofluidsim_layout" ) , bind_group_layouts : & [ Some ( & ferrofluidsim_compute_layout) ] , immediate_size : 0 ,
832856 } ) ;
@@ -1281,11 +1305,13 @@ impl<'a> VulkanEngine<'a> {
12811305 color_space : frame. color_space ,
12821306 color_range : frame. color_range ,
12831307 bit_depth : frame. bit_depth as u32 ,
1308+ color_trc : frame. color_trc ,
12841309 } ) ;
12851310 } else if let Some ( vs) = & mut self . video_state {
12861311 vs. color_space = frame. color_space ;
12871312 vs. color_range = frame. color_range ;
12881313 vs. bit_depth = frame. bit_depth as u32 ;
1314+ vs. color_trc = frame. color_trc ;
12891315 }
12901316
12911317 if let Some ( vs) = & self . video_state {
@@ -1312,7 +1338,7 @@ impl<'a> VulkanEngine<'a> {
13121338 color_space : frame. color_space ,
13131339 color_range : frame. color_range ,
13141340 bit_depth : frame. bit_depth as u32 ,
1315- _pad : 0 ,
1341+ color_trc : frame . color_trc ,
13161342 viewport_width : 1920.0 ,
13171343 viewport_height : 1080.0 ,
13181344 video_width : frame. width as f32 ,
@@ -2808,7 +2834,7 @@ impl<'a> VulkanEngine<'a> {
28082834 color_space : vs. color_space ,
28092835 color_range : vs. color_range ,
28102836 bit_depth : vs. bit_depth ,
2811- _pad : 0 ,
2837+ color_trc : vs . color_trc ,
28122838 viewport_width : v_vp_w,
28132839 viewport_height : v_vp_h,
28142840 video_width : vs. width as f32 ,
0 commit comments