color-management: use more consistent naming
This commit is contained in:
parent
32db933242
commit
83e79b68e6
65 changed files with 439 additions and 510 deletions
31
src/gfx_apis/vulkan/eotfs.rs
Normal file
31
src/gfx_apis/vulkan/eotfs.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
use crate::cmm::cmm_eotf::Eotf;
|
||||
|
||||
pub const EOTF_LINEAR: u32 = 1;
|
||||
pub const EOTF_ST2084_PQ: u32 = 2;
|
||||
pub const EOTF_GAMMA24: u32 = 3;
|
||||
pub const EOTF_GAMMA22: u32 = 4;
|
||||
pub const EOTF_GAMMA28: u32 = 5;
|
||||
pub const EOTF_ST240: u32 = 6;
|
||||
pub const EOTF_LOG100: u32 = 8;
|
||||
pub const EOTF_LOG316: u32 = 9;
|
||||
pub const EOTF_ST428: u32 = 10;
|
||||
|
||||
pub trait EotfExt: Sized {
|
||||
fn to_vulkan(self) -> u32;
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@ pub(super) struct PipelineCreateInfo {
|
|||
pub(super) src_has_alpha: bool,
|
||||
pub(super) has_alpha_mult: bool,
|
||||
pub(super) eotf: u32,
|
||||
pub(super) oetf: u32,
|
||||
pub(super) inv_eotf: u32,
|
||||
pub(super) descriptor_set_layouts: ArrayVec<Rc<VulkanDescriptorSetLayout>, 2>,
|
||||
pub(super) has_color_management_data: bool,
|
||||
}
|
||||
|
|
@ -91,7 +91,7 @@ impl VulkanDevice {
|
|||
frag_spec_entry(&(info.src_has_alpha as u32).to_ne_bytes());
|
||||
frag_spec_entry(&(info.has_alpha_mult as u32).to_ne_bytes());
|
||||
frag_spec_entry(&info.eotf.to_ne_bytes());
|
||||
frag_spec_entry(&info.oetf.to_ne_bytes());
|
||||
frag_spec_entry(&info.inv_eotf.to_ne_bytes());
|
||||
frag_spec_entry(&(info.has_color_management_data as u32).to_ne_bytes());
|
||||
let frag_spec = SpecializationInfo::default()
|
||||
.map_entries(&frag_spec_entries)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use {
|
|||
async_engine::{AsyncEngine, SpawnedFuture},
|
||||
cmm::{
|
||||
cmm_description::{ColorDescription, LinearColorDescription, LinearColorDescriptionId},
|
||||
cmm_transfer_function::TransferFunction,
|
||||
cmm_eotf::Eotf,
|
||||
cmm_transform::ColorMatrix,
|
||||
},
|
||||
cpu_worker::PendingJob,
|
||||
|
|
@ -19,6 +19,7 @@ use {
|
|||
descriptor::VulkanDescriptorSetLayout,
|
||||
descriptor_buffer::VulkanDescriptorBufferWriter,
|
||||
device::VulkanDevice,
|
||||
eotfs::{EOTF_LINEAR, EotfExt},
|
||||
fence::VulkanFence,
|
||||
image::{QueueFamily, QueueState, QueueTransfer, VulkanImage, VulkanImageMemory},
|
||||
pipeline::{PipelineCreateInfo, VulkanPipeline},
|
||||
|
|
@ -30,7 +31,6 @@ use {
|
|||
OUT_FRAG, OUT_VERT, OutPushConstants, TEX_FRAG, TEX_VERT, TexColorManagementData,
|
||||
TexPushConstants, TexVertex, VulkanShader,
|
||||
},
|
||||
transfer_functions::{TF_LINEAR, TransferFunctionExt},
|
||||
},
|
||||
io_uring::IoUring,
|
||||
rect::{Rect, Region},
|
||||
|
|
@ -78,10 +78,8 @@ pub struct VulkanRenderer {
|
|||
pub(super) formats: Rc<AHashMap<u32, GfxFormat>>,
|
||||
pub(super) device: Rc<VulkanDevice>,
|
||||
pub(super) fill_pipelines: CopyHashMap<vk::Format, FillPipelines>,
|
||||
pub(super) tex_pipelines:
|
||||
StaticMap<TransferFunction, CopyHashMap<vk::Format, Rc<TexPipelines>>>,
|
||||
pub(super) out_pipelines:
|
||||
StaticMap<TransferFunction, CopyHashMap<OutPipelineKey, Rc<VulkanPipeline>>>,
|
||||
pub(super) tex_pipelines: StaticMap<Eotf, CopyHashMap<vk::Format, Rc<TexPipelines>>>,
|
||||
pub(super) out_pipelines: StaticMap<Eotf, CopyHashMap<OutPipelineKey, Rc<VulkanPipeline>>>,
|
||||
pub(super) gfx_command_buffers: CachedCommandBuffers,
|
||||
pub(super) transfer_command_buffers: Option<CachedCommandBuffers>,
|
||||
pub(super) wait_semaphores: Stack<Rc<VulkanSemaphore>>,
|
||||
|
|
@ -247,20 +245,20 @@ type FillPipelines = Rc<StaticMap<TexSourceType, Rc<VulkanPipeline>>>;
|
|||
struct TexPipelineKey {
|
||||
tex_copy_type: TexCopyType,
|
||||
tex_source_type: TexSourceType,
|
||||
eotf: TransferFunction,
|
||||
eotf: Eotf,
|
||||
has_color_management_data: bool,
|
||||
}
|
||||
|
||||
pub(super) struct TexPipelines {
|
||||
format: vk::Format,
|
||||
oetf: TransferFunction,
|
||||
eotf: Eotf,
|
||||
pipelines: CopyHashMap<TexPipelineKey, Rc<VulkanPipeline>>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub(super) struct OutPipelineKey {
|
||||
format: vk::Format,
|
||||
eotf: TransferFunction,
|
||||
eotf: Eotf,
|
||||
}
|
||||
|
||||
impl VulkanDevice {
|
||||
|
|
@ -417,8 +415,8 @@ impl VulkanRenderer {
|
|||
src_has_alpha,
|
||||
has_alpha_mult: false,
|
||||
// all transformations are applied in the compositor
|
||||
eotf: TF_LINEAR,
|
||||
oetf: TF_LINEAR,
|
||||
eotf: EOTF_LINEAR,
|
||||
inv_eotf: EOTF_LINEAR,
|
||||
descriptor_set_layouts: Default::default(),
|
||||
has_color_management_data: false,
|
||||
};
|
||||
|
|
@ -437,13 +435,13 @@ impl VulkanRenderer {
|
|||
format: vk::Format,
|
||||
target_cd: &ColorDescription,
|
||||
) -> Rc<TexPipelines> {
|
||||
let pipelines = &self.tex_pipelines[target_cd.transfer_function];
|
||||
let pipelines = &self.tex_pipelines[target_cd.eotf];
|
||||
match pipelines.get(&format) {
|
||||
Some(pl) => pl,
|
||||
_ => {
|
||||
let pl = Rc::new(TexPipelines {
|
||||
format,
|
||||
oetf: target_cd.transfer_function,
|
||||
eotf: target_cd.eotf,
|
||||
pipelines: Default::default(),
|
||||
});
|
||||
pipelines.set(format, pl.clone());
|
||||
|
|
@ -463,7 +461,7 @@ impl VulkanRenderer {
|
|||
let key = TexPipelineKey {
|
||||
tex_copy_type,
|
||||
tex_source_type,
|
||||
eotf: tex_cd.transfer_function,
|
||||
eotf: tex_cd.eotf,
|
||||
has_color_management_data,
|
||||
};
|
||||
if let Some(pl) = pipelines.pipelines.get(&key) {
|
||||
|
|
@ -490,7 +488,7 @@ impl VulkanRenderer {
|
|||
src_has_alpha,
|
||||
has_alpha_mult,
|
||||
eotf: key.eotf.to_vulkan(),
|
||||
oetf: pipelines.oetf.to_vulkan(),
|
||||
inv_eotf: pipelines.eotf.to_vulkan(),
|
||||
descriptor_set_layouts: self.tex_descriptor_set_layouts.clone(),
|
||||
has_color_management_data,
|
||||
};
|
||||
|
|
@ -507,9 +505,9 @@ impl VulkanRenderer {
|
|||
) -> Result<Rc<VulkanPipeline>, VulkanError> {
|
||||
let key = OutPipelineKey {
|
||||
format,
|
||||
eotf: bb_cd.transfer_function,
|
||||
eotf: bb_cd.eotf,
|
||||
};
|
||||
let pipelines = &self.out_pipelines[fb_cd.transfer_function];
|
||||
let pipelines = &self.out_pipelines[fb_cd.eotf];
|
||||
if let Some(pl) = pipelines.get(&key) {
|
||||
return Ok(pl);
|
||||
}
|
||||
|
|
@ -525,7 +523,7 @@ impl VulkanRenderer {
|
|||
src_has_alpha: true,
|
||||
has_alpha_mult: false,
|
||||
eotf: key.eotf.to_vulkan(),
|
||||
oetf: fb_cd.transfer_function.to_vulkan(),
|
||||
inv_eotf: fb_cd.eotf.to_vulkan(),
|
||||
descriptor_set_layouts,
|
||||
has_color_management_data: false,
|
||||
})?;
|
||||
|
|
@ -725,7 +723,7 @@ impl VulkanRenderer {
|
|||
RenderPass::BlendBuffer => blend_cd,
|
||||
RenderPass::FrameBuffer => fb_cd,
|
||||
};
|
||||
let tf = target_cd.transfer_function;
|
||||
let tf = target_cd.eotf;
|
||||
let color = memory
|
||||
.color_transforms
|
||||
.apply_to_color(&fr.cd, target_cd, fr.color);
|
||||
|
|
@ -1047,7 +1045,7 @@ impl VulkanRenderer {
|
|||
.apply_to_color(clear_cd, target_cd, *clear);
|
||||
let clear_value = ClearValue {
|
||||
color: ClearColorValue {
|
||||
float32: color.to_array(target_cd.transfer_function),
|
||||
float32: color.to_array(target_cd.eotf),
|
||||
},
|
||||
};
|
||||
let use_load_clear = clear_rects.len() == 1 && {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef TRANSFER_FUNCTIONS_GLSL
|
||||
#define TRANSFER_FUNCTIONS_GLSL
|
||||
#ifndef EOTFS_GLSL
|
||||
#define EOTFS_GLSL
|
||||
|
||||
#include "frag_spec_const.glsl"
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ vec3 eotf_st2084_pq(vec3 c) {
|
|||
return pow(num / den, vec3(1.0 / 0.1593017578125));
|
||||
}
|
||||
|
||||
vec3 oetf_st2084_pq(vec3 c) {
|
||||
vec3 inv_eotf_st2084_pq(vec3 c) {
|
||||
c = clamp(c, 0.0, 1.0);
|
||||
vec3 num = vec3(0.8359375) + vec3(18.8515625) * pow(c, vec3(0.1593017578125));
|
||||
vec3 den = vec3(1.0) + vec3(18.6875) * pow(c, vec3(0.1593017578125));
|
||||
|
|
@ -36,7 +36,7 @@ vec3 eotf_st240(vec3 c) {
|
|||
);
|
||||
}
|
||||
|
||||
vec3 oetf_st240(vec3 c) {
|
||||
vec3 inv_eotf_st240(vec3 c) {
|
||||
return mix(
|
||||
vec3(4.0) * c,
|
||||
vec3(1.1115) * pow(c, vec3(0.45)) - vec3(0.1115),
|
||||
|
|
@ -48,7 +48,7 @@ vec3 eotf_log100(vec3 c) {
|
|||
return pow(vec3(10), vec3(2.0) * (c - vec3(1.0)));
|
||||
}
|
||||
|
||||
vec3 oetf_log100(vec3 c) {
|
||||
vec3 inv_eotf_log100(vec3 c) {
|
||||
c = clamp(c, 0.0, 1.0);
|
||||
return mix(
|
||||
vec3(0.0),
|
||||
|
|
@ -61,7 +61,7 @@ vec3 eotf_log316(vec3 c) {
|
|||
return pow(vec3(10), vec3(2.5) * (c - vec3(1.0)));
|
||||
}
|
||||
|
||||
vec3 oetf_log316(vec3 c) {
|
||||
vec3 inv_eotf_log316(vec3 c) {
|
||||
c = clamp(c, 0.0, 1.0);
|
||||
return mix(
|
||||
vec3(0.0),
|
||||
|
|
@ -75,7 +75,7 @@ vec3 eotf_st428(vec3 c) {
|
|||
return pow(c, vec3(2.6)) * vec3(52.37 / 48.0);
|
||||
}
|
||||
|
||||
vec3 oetf_st428(vec3 c) {
|
||||
vec3 inv_eotf_st428(vec3 c) {
|
||||
c = max(c, 0.0);
|
||||
return pow(vec3(48.0) * c / vec3(52.37), vec3(1.0 / 2.6));
|
||||
}
|
||||
|
|
@ -95,17 +95,17 @@ vec3 apply_eotf(vec3 c) {
|
|||
}
|
||||
}
|
||||
|
||||
vec3 apply_oetf(vec3 c) {
|
||||
switch (oetf) {
|
||||
vec3 apply_inv_eotf(vec3 c) {
|
||||
switch (inv_eotf) {
|
||||
case TF_LINEAR: return c;
|
||||
case TF_ST2084_PQ: return oetf_st2084_pq(c);
|
||||
case TF_ST2084_PQ: return inv_eotf_st2084_pq(c);
|
||||
case TF_GAMMA24: return sign(c) * pow(abs(c), vec3(1.0 / 2.4));
|
||||
case TF_GAMMA22: return sign(c) * pow(abs(c), vec3(1.0 / 2.2));
|
||||
case TF_GAMMA28: return sign(c) * pow(abs(c), vec3(1.0 / 2.8));
|
||||
case TF_ST240: return oetf_st240(c);
|
||||
case TF_LOG100: return oetf_log100(c);
|
||||
case TF_LOG316: return oetf_log316(c);
|
||||
case TF_ST428: return oetf_st428(c);
|
||||
case TF_ST240: return inv_eotf_st240(c);
|
||||
case TF_LOG100: return inv_eotf_log100(c);
|
||||
case TF_LOG316: return inv_eotf_log316(c);
|
||||
case TF_ST428: return inv_eotf_st428(c);
|
||||
default: return c;
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
layout(constant_id = 0) const bool src_has_alpha = false;
|
||||
layout(constant_id = 1) const bool has_alpha_multiplier = false;
|
||||
layout(constant_id = 2) const uint eotf = 0;
|
||||
layout(constant_id = 3) const uint oetf = 0;
|
||||
layout(constant_id = 3) const uint inv_eotf = 0;
|
||||
layout(constant_id = 4) const bool has_matrix = false;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#extension GL_EXT_samplerless_texture_functions : require
|
||||
|
||||
#include "frag_spec_const.glsl"
|
||||
#include "transfer_functions.glsl"
|
||||
#include "eotfs.glsl"
|
||||
#include "out.common.glsl"
|
||||
|
||||
layout(set = 0, binding = 0) uniform texture2D in_color;
|
||||
|
|
@ -10,10 +10,10 @@ layout(location = 0) out vec4 out_color;
|
|||
|
||||
void main() {
|
||||
vec4 c = texelFetch(in_color, ivec2(gl_FragCoord.xy), 0);
|
||||
if (eotf != oetf) {
|
||||
if (eotf != inv_eotf) {
|
||||
c.rgb /= mix(c.a, 1.0, c.a == 0.0);
|
||||
c.rgb = apply_eotf(c.rgb);
|
||||
c.rgb = apply_oetf(c.rgb);
|
||||
c.rgb = apply_inv_eotf(c.rgb);
|
||||
c.rgb *= c.a;
|
||||
}
|
||||
out_color = c;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#extension GL_EXT_scalar_block_layout : require
|
||||
|
||||
#include "frag_spec_const.glsl"
|
||||
#include "transfer_functions.glsl"
|
||||
#include "eotfs.glsl"
|
||||
#include "tex.common.glsl"
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler sam;
|
||||
|
|
@ -16,7 +16,7 @@ layout(location = 0) out vec4 out_color;
|
|||
|
||||
void main() {
|
||||
vec4 c = textureLod(sampler2D(tex, sam), tex_pos, 0);
|
||||
if (eotf != oetf || has_matrix) {
|
||||
if (eotf != inv_eotf || has_matrix) {
|
||||
vec3 rgb = c.rgb;
|
||||
if (src_has_alpha) {
|
||||
rgb /= mix(c.a, 1.0, c.a == 0.0);
|
||||
|
|
@ -25,7 +25,7 @@ void main() {
|
|||
if (has_matrix) {
|
||||
rgb = (cm_data.matrix * vec4(rgb, 1.0)).rgb;
|
||||
}
|
||||
rgb = apply_oetf(rgb);
|
||||
rgb = apply_inv_eotf(rgb);
|
||||
if (src_has_alpha) {
|
||||
rgb *= c.a;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +0,0 @@
|
|||
use crate::cmm::cmm_transfer_function::TransferFunction;
|
||||
|
||||
pub const TF_LINEAR: u32 = 1;
|
||||
pub const TF_ST2084_PQ: u32 = 2;
|
||||
pub const TF_GAMMA24: u32 = 3;
|
||||
pub const TF_GAMMA22: u32 = 4;
|
||||
pub const TF_GAMMA28: u32 = 5;
|
||||
pub const TF_ST240: u32 = 6;
|
||||
pub const TF_LOG100: u32 = 8;
|
||||
pub const TF_LOG316: u32 = 9;
|
||||
pub const TF_ST428: u32 = 10;
|
||||
|
||||
pub trait TransferFunctionExt: Sized {
|
||||
fn to_vulkan(self) -> u32;
|
||||
}
|
||||
|
||||
impl TransferFunctionExt for TransferFunction {
|
||||
fn to_vulkan(self) -> u32 {
|
||||
match self {
|
||||
TransferFunction::Linear => TF_LINEAR,
|
||||
TransferFunction::St2084Pq => TF_ST2084_PQ,
|
||||
TransferFunction::Bt1886 => TF_GAMMA24,
|
||||
TransferFunction::Gamma22 => TF_GAMMA22,
|
||||
TransferFunction::Gamma28 => TF_GAMMA28,
|
||||
TransferFunction::St240 => TF_ST240,
|
||||
TransferFunction::Log100 => TF_LOG100,
|
||||
TransferFunction::Log316 => TF_LOG316,
|
||||
TransferFunction::St428 => TF_ST428,
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue