@@ -33,7 +33,6 @@ use bevy_light::{
3333 EnvironmentMapLight , IrradianceVolume , NotShadowCaster , NotShadowReceiver ,
3434 ShadowFilteringMethod , TransmittedShadowReceiver ,
3535} ;
36- use bevy_log:: warn_once;
3736use bevy_math:: { Affine3 , Affine3Ext , Rect , UVec2 , Vec3 , Vec4 } ;
3837use bevy_mesh:: {
3938 skinning:: SkinnedMesh , BaseMeshPipelineKey , Mesh , Mesh3d , MeshTag , MeshVertexBufferLayoutRef ,
@@ -101,7 +100,10 @@ use bevy_core_pipeline::tonemapping::{DebandDither, Tonemapping};
101100use bevy_render:: camera:: { DirtySpecializations , TemporalJitter } ;
102101use bevy_render:: prelude:: Msaa ;
103102use bevy_render:: sync_world:: { MainEntity , MainEntityHashMap } ;
104- use bevy_render:: view:: { ExtractedView , RenderShadowMapVisibleEntities , RenderVisibleEntities } ;
103+ use bevy_render:: view:: {
104+ color_target_format_from_code, color_target_format_to_code, ExtractedView ,
105+ RenderShadowMapVisibleEntities , RenderVisibleEntities ,
106+ } ;
105107use bevy_render:: RenderSystems :: PrepareAssets ;
106108use bevy_tasks:: ComputeTaskPool ;
107109
@@ -403,11 +405,8 @@ pub fn check_views_need_specialization(
403405 ) in views. iter_mut ( )
404406 {
405407 let is_hdr = view. texture_format == ViewTarget :: TEXTURE_FORMAT_HDR ;
406- let mut view_key =
407- MeshPipelineKey :: from_msaa_samples ( msaa. samples ( ) ) | MeshPipelineKey :: from_hdr ( is_hdr) ;
408- if !is_hdr {
409- view_key |= MeshPipelineKey :: sdr_color_attachment_format_bits ( view. texture_format ) ;
410- }
408+ let mut view_key = MeshPipelineKey :: from_msaa_samples ( msaa. samples ( ) )
409+ | MeshPipelineKey :: from_color_target_format ( view. texture_format ) ;
411410
412411 if normal_prepass {
413412 view_key |= MeshPipelineKey :: NORMAL_PREPASS ;
@@ -3043,7 +3042,6 @@ bitflags::bitflags! {
30433042 const MORPH_TARGETS = BaseMeshPipelineKey :: MORPH_TARGETS . bits( ) ;
30443043
30453044 // Flag bits
3046- const HDR = 1 << 0 ;
30473045 const TONEMAP_IN_SHADER = 1 << 1 ;
30483046 const DEBAND_DITHER = 1 << 2 ;
30493047 const DEPTH_PREPASS = 1 << 3 ;
@@ -3111,16 +3109,16 @@ bitflags::bitflags! {
31113109 const SCREEN_SPACE_SPECULAR_TRANSMISSION_MEDIUM = 1 << Self :: SCREEN_SPACE_SPECULAR_TRANSMISSION_SHIFT_BITS ;
31123110 const SCREEN_SPACE_SPECULAR_TRANSMISSION_HIGH = 2 << Self :: SCREEN_SPACE_SPECULAR_TRANSMISSION_SHIFT_BITS ;
31133111 const SCREEN_SPACE_SPECULAR_TRANSMISSION_ULTRA = 3 << Self :: SCREEN_SPACE_SPECULAR_TRANSMISSION_SHIFT_BITS ;
3114- const SDR_COLOR_ATTACHMENT_FORMAT_RESERVED_BITS = Self :: SDR_COLOR_ATTACHMENT_FORMAT_MASK_BITS
3115- << Self :: SDR_COLOR_ATTACHMENT_FORMAT_SHIFT_BITS ;
3112+ const COLOR_TARGET_FORMAT_RESERVED_BITS = Self :: COLOR_TARGET_FORMAT_MASK_BITS
3113+ << Self :: COLOR_TARGET_FORMAT_SHIFT_BITS ;
31163114 const ALL_RESERVED_BITS =
31173115 Self :: BLEND_RESERVED_BITS . bits( ) |
31183116 Self :: MSAA_RESERVED_BITS . bits( ) |
31193117 Self :: TONEMAP_METHOD_RESERVED_BITS . bits( ) |
31203118 Self :: SHADOW_FILTER_METHOD_RESERVED_BITS . bits( ) |
31213119 Self :: VIEW_PROJECTION_RESERVED_BITS . bits( ) |
31223120 Self :: SCREEN_SPACE_SPECULAR_TRANSMISSION_RESERVED_BITS . bits( ) |
3123- Self :: SDR_COLOR_ATTACHMENT_FORMAT_RESERVED_BITS . bits( ) ;
3121+ Self :: COLOR_TARGET_FORMAT_RESERVED_BITS . bits( ) ;
31243122 }
31253123}
31263124
@@ -3148,8 +3146,8 @@ impl MeshPipelineKey {
31483146 const SCREEN_SPACE_SPECULAR_TRANSMISSION_SHIFT_BITS : u64 =
31493147 Self :: VIEW_PROJECTION_MASK_BITS . count_ones ( ) as u64 + Self :: VIEW_PROJECTION_SHIFT_BITS ;
31503148
3151- const SDR_COLOR_ATTACHMENT_FORMAT_MASK_BITS : u64 = 0b11 ;
3152- const SDR_COLOR_ATTACHMENT_FORMAT_SHIFT_BITS : u64 =
3149+ const COLOR_TARGET_FORMAT_MASK_BITS : u64 = 0b1111 ;
3150+ const COLOR_TARGET_FORMAT_SHIFT_BITS : u64 =
31533151 Self :: SCREEN_SPACE_SPECULAR_TRANSMISSION_MASK_BITS . count_ones ( ) as u64
31543152 + Self :: SCREEN_SPACE_SPECULAR_TRANSMISSION_SHIFT_BITS ;
31553153
@@ -3159,48 +3157,22 @@ impl MeshPipelineKey {
31593157 Self :: from_bits_retain ( msaa_bits)
31603158 }
31613159
3162- pub fn from_hdr ( hdr : bool ) -> Self {
3163- if hdr {
3164- MeshPipelineKey :: HDR
3165- } else {
3166- MeshPipelineKey :: NONE
3167- }
3168- }
3169-
3170- /// Returns the bits for [`ExtractedView::texture_format`] for non-HDR views
3171- pub fn sdr_color_attachment_format_bits ( format : TextureFormat ) -> Self {
3172- let code: u64 = match format {
3173- TextureFormat :: Rgba8UnormSrgb => 0 ,
3174- TextureFormat :: Bgra8UnormSrgb => 1 ,
3175- TextureFormat :: Rgba8Unorm => 2 ,
3176- _ => {
3177- warn_once ! (
3178- "Unknown main pass format {:?}, mesh pipeline uses Rgba8UnormSrgb" ,
3179- format
3180- ) ;
3181- 0
3182- }
3183- } ;
3160+ /// Create a pipeline key from the view's color target format.
3161+ #[ inline]
3162+ pub fn from_color_target_format ( format : TextureFormat ) -> Self {
3163+ let code = color_target_format_to_code ( format) as u64 ;
31843164 Self :: from_bits_retain (
3185- ( code & Self :: SDR_COLOR_ATTACHMENT_FORMAT_MASK_BITS )
3186- << Self :: SDR_COLOR_ATTACHMENT_FORMAT_SHIFT_BITS ,
3165+ ( code & Self :: COLOR_TARGET_FORMAT_MASK_BITS )
3166+ << Self :: COLOR_TARGET_FORMAT_SHIFT_BITS ,
31873167 )
31883168 }
31893169
3190- /// Color format of the main pass color attachment for this pipeline key.
3191- pub fn main_pass_color_attachment_format ( & self ) -> TextureFormat {
3192- if self . contains ( MeshPipelineKey :: HDR ) {
3193- ViewTarget :: TEXTURE_FORMAT_HDR
3194- } else {
3195- let code = ( self . bits ( ) >> Self :: SDR_COLOR_ATTACHMENT_FORMAT_SHIFT_BITS )
3196- & Self :: SDR_COLOR_ATTACHMENT_FORMAT_MASK_BITS ;
3197- match code {
3198- 0 => TextureFormat :: Rgba8UnormSrgb ,
3199- 1 => TextureFormat :: Bgra8UnormSrgb ,
3200- 2 => TextureFormat :: Rgba8Unorm ,
3201- _ => TextureFormat :: Rgba8UnormSrgb ,
3202- }
3203- }
3170+ /// Color target format of the main pass for this pipeline key.
3171+ #[ inline]
3172+ pub fn color_target_format ( & self ) -> TextureFormat {
3173+ let code = ( ( self . bits ( ) >> Self :: COLOR_TARGET_FORMAT_SHIFT_BITS )
3174+ & Self :: COLOR_TARGET_FORMAT_MASK_BITS ) as u8 ;
3175+ color_target_format_from_code ( code)
32043176 }
32053177
32063178 pub fn msaa_samples ( & self ) -> u32 {
@@ -3658,7 +3630,7 @@ impl SpecializedMeshPipeline for MeshPipeline {
36583630 }
36593631 }
36603632
3661- let format = key. main_pass_color_attachment_format ( ) ;
3633+ let format = key. color_target_format ( ) ;
36623634
36633635 // This is defined here so that custom shaders that use something other than
36643636 // the mesh binding from bevy_pbr::mesh_bindings can easily make use of this
0 commit comments