diff --git a/src/cmm/cmm_eotf.rs b/src/cmm/cmm_eotf.rs index b8980cca..6811928b 100644 --- a/src/cmm/cmm_eotf.rs +++ b/src/cmm/cmm_eotf.rs @@ -1,6 +1,4 @@ -use linearize::Linearize; - -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Linearize)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] pub enum Eotf { Linear, St2084Pq, diff --git a/src/gfx_apis/vulkan/eotfs.rs b/src/gfx_apis/vulkan/eotfs.rs index db5a6da4..12f799df 100644 --- a/src/gfx_apis/vulkan/eotfs.rs +++ b/src/gfx_apis/vulkan/eotfs.rs @@ -1,4 +1,4 @@ -use crate::cmm::cmm_eotf::Eotf; +use {crate::cmm::cmm_eotf::Eotf, linearize::Linearize}; pub const EOTF_LINEAR: u32 = 1; pub const EOTF_ST2084_PQ: u32 = 2; @@ -10,22 +10,60 @@ pub const EOTF_LOG100: u32 = 8; pub const EOTF_LOG316: u32 = 9; pub const EOTF_ST428: u32 = 10; +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Linearize)] +pub enum VulkanEotf { + Linear, + St2084Pq, + Bt1886, + Gamma22, + Gamma28, + St240, + Log100, + Log316, + St428, +} + pub trait EotfExt: Sized { - fn to_vulkan(self) -> u32; + fn to_vulkan(self) -> VulkanEotf; } impl EotfExt for Eotf { - fn to_vulkan(self) -> u32 { - match self { - Eotf::Linear => EOTF_LINEAR, - Eotf::St2084Pq => EOTF_ST2084_PQ, - Eotf::Bt1886 => EOTF_GAMMA24, - Eotf::Gamma22 => EOTF_GAMMA22, - Eotf::Gamma28 => EOTF_GAMMA28, - Eotf::St240 => EOTF_ST240, - Eotf::Log100 => EOTF_LOG100, - Eotf::Log316 => EOTF_LOG316, - Eotf::St428 => EOTF_ST428, + fn to_vulkan(self) -> VulkanEotf { + macro_rules! map { + ($($name:ident,)*) => { + match self { + $( + Self::$name { .. } => VulkanEotf::$name, + )* + } + }; + } + map! { + Linear, + St2084Pq, + Bt1886, + Gamma22, + Gamma28, + St240, + Log100, + Log316, + St428, + } + } +} + +impl VulkanEotf { + pub fn to_vulkan(self) -> u32 { + match self { + Self::Linear => EOTF_LINEAR, + Self::St2084Pq => EOTF_ST2084_PQ, + Self::Bt1886 => EOTF_GAMMA24, + Self::Gamma22 => EOTF_GAMMA22, + Self::Gamma28 => EOTF_GAMMA28, + Self::St240 => EOTF_ST240, + Self::Log100 => EOTF_LOG100, + Self::Log316 => EOTF_LOG316, + Self::St428 => EOTF_ST428, } } } diff --git a/src/gfx_apis/vulkan/renderer.rs b/src/gfx_apis/vulkan/renderer.rs index 6c1f6455..2d87821a 100644 --- a/src/gfx_apis/vulkan/renderer.rs +++ b/src/gfx_apis/vulkan/renderer.rs @@ -3,7 +3,6 @@ use { async_engine::{AsyncEngine, SpawnedFuture}, cmm::{ cmm_description::{ColorDescription, LinearColorDescription, LinearColorDescriptionId}, - cmm_eotf::Eotf, cmm_transform::ColorMatrix, }, cpu_worker::PendingJob, @@ -19,7 +18,7 @@ use { descriptor::VulkanDescriptorSetLayout, descriptor_buffer::VulkanDescriptorBufferWriter, device::VulkanDevice, - eotfs::{EOTF_LINEAR, EotfExt}, + eotfs::{EOTF_LINEAR, EotfExt, VulkanEotf}, fence::VulkanFence, image::{QueueFamily, QueueState, QueueTransfer, VulkanImage, VulkanImageMemory}, pipeline::{PipelineCreateInfo, VulkanPipeline}, @@ -78,8 +77,9 @@ pub struct VulkanRenderer { pub(super) formats: Rc>, pub(super) device: Rc, pub(super) fill_pipelines: CopyHashMap, - pub(super) tex_pipelines: StaticMap>>, - pub(super) out_pipelines: StaticMap>>, + pub(super) tex_pipelines: StaticMap>>, + pub(super) out_pipelines: + StaticMap>>, pub(super) gfx_command_buffers: CachedCommandBuffers, pub(super) transfer_command_buffers: Option, pub(super) wait_semaphores: Stack>, @@ -246,20 +246,20 @@ type FillPipelines = Rc>>; struct TexPipelineKey { tex_copy_type: TexCopyType, tex_source_type: TexSourceType, - eotf: Eotf, + eotf: VulkanEotf, has_color_management_data: bool, } pub(super) struct TexPipelines { format: vk::Format, - eotf: Eotf, + eotf: VulkanEotf, pipelines: CopyHashMap>, } #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] pub(super) struct OutPipelineKey { format: vk::Format, - eotf: Eotf, + eotf: VulkanEotf, has_color_management_data: bool, } @@ -437,13 +437,14 @@ impl VulkanRenderer { format: vk::Format, target_cd: &ColorDescription, ) -> Rc { - let pipelines = &self.tex_pipelines[target_cd.eotf]; + let eotf = target_cd.eotf.to_vulkan(); + let pipelines = &self.tex_pipelines[eotf]; match pipelines.get(&format) { Some(pl) => pl, _ => { let pl = Rc::new(TexPipelines { format, - eotf: target_cd.eotf, + eotf, pipelines: Default::default(), }); pipelines.set(format, pl.clone()); @@ -463,7 +464,7 @@ impl VulkanRenderer { let key = TexPipelineKey { tex_copy_type, tex_source_type, - eotf: tex_cd.eotf, + eotf: tex_cd.eotf.to_vulkan(), has_color_management_data, }; if let Some(pl) = pipelines.pipelines.get(&key) { @@ -508,10 +509,11 @@ impl VulkanRenderer { ) -> Result, VulkanError> { let key = OutPipelineKey { format, - eotf: bb_cd.eotf, + eotf: bb_cd.eotf.to_vulkan(), has_color_management_data, }; - let pipelines = &self.out_pipelines[fb_cd.eotf]; + let fb_eotf = fb_cd.eotf.to_vulkan(); + let pipelines = &self.out_pipelines[fb_eotf]; if let Some(pl) = pipelines.get(&key) { return Ok(pl); } @@ -527,7 +529,7 @@ impl VulkanRenderer { src_has_alpha: true, has_alpha_mult: false, eotf: key.eotf.to_vulkan(), - inv_eotf: fb_cd.eotf.to_vulkan(), + inv_eotf: fb_eotf.to_vulkan(), descriptor_set_layouts, has_color_management_data, })?;