Color Management: Use preprocessor for gamma 2.2 vs piecewise sRGB

The referenced commit introduced the use of gamma 2.2 or piecewise sRGB
for the backbuffer blit depending on the operating system. This commit
switches from a push constant for this to a preprocessor define.

Ref 5d72498154

Pull Request: https://projects.blender.org/blender/blender/pulls/146170
This commit is contained in:
Christoph Neuhauser
2025-09-12 18:30:25 +02:00
parent 2898ef0a5c
commit 092affc573
4 changed files with 17 additions and 15 deletions

View File

@@ -17,12 +17,11 @@ float srgb_to_linearrgb(float c)
vec3 nonlinear_to_linear_scrgb(vec3 c)
{
if (use_gamma22) {
return pow(c, vec3(2.2f));
}
else {
return vec3(srgb_to_linearrgb(c.r), srgb_to_linearrgb(c.g), srgb_to_linearrgb(c.b));
}
#ifdef USE_GAMMA22
return pow(c, vec3(2.2f));
#else
return vec3(srgb_to_linearrgb(c.r), srgb_to_linearrgb(c.g), srgb_to_linearrgb(c.b));
#endif
}
void main()

View File

@@ -14,3 +14,9 @@ COMPUTE_SOURCE("vk_backbuffer_blit_comp.glsl")
ADDITIONAL_INFO(gpu_srgb_to_framebuffer_space)
DO_STATIC_COMPILATION()
GPU_SHADER_CREATE_END()
GPU_SHADER_CREATE_INFO(vk_backbuffer_blit_gamma22)
ADDITIONAL_INFO(vk_backbuffer_blit)
DEFINE("USE_GAMMA22")
DO_STATIC_COMPILATION()
GPU_SHADER_CREATE_END()

View File

@@ -394,12 +394,6 @@ void VKContext::swap_buffer_draw_handler(const GHOST_VulkanSwapChainData &swap_c
Shader *shader = device.vk_backbuffer_blit_sh_get();
GPU_shader_bind(shader);
GPU_shader_uniform_1f(shader, "sdr_scale", swap_chain_data.sdr_scale);
/* See display_as_extended_srgb in libocio_display_processor.cc for details on this choice. */
#if defined(_WIN32) || defined(__APPLE__)
GPU_shader_uniform_1b(shader, "use_gamma22", false);
#else
GPU_shader_uniform_1b(shader, "use_gamma22", true);
#endif
VKStateManager &state_manager = state_manager_get();
state_manager.image_bind(color_attachment, 0);
state_manager.image_bind(&swap_chain_texture, 1);

View File

@@ -451,9 +451,12 @@ class VKDevice : public NonCopyable {
Shader *vk_backbuffer_blit_sh_get()
{
if (vk_backbuffer_blit_sh_ == nullptr) {
vk_backbuffer_blit_sh_ = GPU_shader_create_from_info_name("vk_backbuffer_blit");
}
/* See display_as_extended_srgb in libocio_display_processor.cc for details on this choice. */
#if defined(_WIN32) || defined(__APPLE__)
vk_backbuffer_blit_sh_ = GPU_shader_create_from_info_name("vk_backbuffer_blit");
#else
vk_backbuffer_blit_sh_ = GPU_shader_create_from_info_name("vk_backbuffer_blit_gamma22");
#endif
return vk_backbuffer_blit_sh_;
}