Fix: Cycles display without OpenColorIO not working for Metal

Cycles fallback display shader previously did not use viewport.
This would crash or cause the display not to show when using
GPU backends other than OpenGL, if another display shader
was unavailable.

Now use ShaderCreateInfo for Cycles fallback display.

Authored by Apple: Michael Parkin-White

Ref #96261

Pull Request #104987
This commit is contained in:
Jason Fielder
2023-02-23 14:25:08 +01:00
committed by Brecht Van Lommel
parent fcdfc0a85b
commit 4bfe4e5d49
5 changed files with 32 additions and 35 deletions

View File

@@ -54,44 +54,10 @@ int BlenderDisplayShader::get_tex_coord_attrib_location()
/* --------------------------------------------------------------------
* BlenderFallbackDisplayShader.
*/
/* TODO move shaders to standalone .glsl file. */
static const char *FALLBACK_VERTEX_SHADER =
"uniform vec2 fullscreen;\n"
"in vec2 texCoord;\n"
"in vec2 pos;\n"
"out vec2 texCoord_interp;\n"
"\n"
"vec2 normalize_coordinates()\n"
"{\n"
" return (vec2(2.0) * (pos / fullscreen)) - vec2(1.0);\n"
"}\n"
"\n"
"void main()\n"
"{\n"
" gl_Position = vec4(normalize_coordinates(), 0.0, 1.0);\n"
" texCoord_interp = texCoord;\n"
"}\n\0";
static const char *FALLBACK_FRAGMENT_SHADER =
"uniform sampler2D image_texture;\n"
"in vec2 texCoord_interp;\n"
"out vec4 fragColor;\n"
"\n"
"void main()\n"
"{\n"
" fragColor = texture(image_texture, texCoord_interp);\n"
"}\n\0";
static GPUShader *compile_fallback_shader(void)
{
/* NOTE: Compilation errors are logged to console. */
GPUShader *shader = GPU_shader_create(FALLBACK_VERTEX_SHADER,
FALLBACK_FRAGMENT_SHADER,
nullptr,
nullptr,
nullptr,
"FallbackCyclesBlitShader");
GPUShader *shader = GPU_shader_create_from_info_name("gpu_shader_cycles_display_fallback");
return shader;
}

View File

@@ -498,6 +498,9 @@ set(GLSL_SRC
shaders/gpu_shader_gpencil_stroke_frag.glsl
shaders/gpu_shader_gpencil_stroke_geom.glsl
shaders/gpu_shader_display_fallback_vert.glsl
shaders/gpu_shader_display_fallback_frag.glsl
shaders/gpu_shader_cfg_world_clip_lib.glsl
shaders/gpu_shader_colorspace_lib.glsl

View File

@@ -0,0 +1,5 @@
void main()
{
fragColor = texture(image_texture, texCoord_interp);
}

View File

@@ -0,0 +1,11 @@
vec2 normalize_coordinates()
{
return (vec2(2.0) * (pos / fullscreen)) - vec2(1.0);
}
void main()
{
gl_Position = vec4(normalize_coordinates(), 0.0, 1.0);
texCoord_interp = texCoord;
}

View File

@@ -22,3 +22,15 @@ GPU_SHADER_CREATE_INFO(gpu_shader_2D_image_overlays_merge)
.vertex_source("gpu_shader_2D_image_vert.glsl")
.fragment_source("gpu_shader_image_overlays_merge_frag.glsl")
.do_static_compilation(true);
/* Cycles display driver fallback shader. */
GPU_SHADER_CREATE_INFO(gpu_shader_cycles_display_fallback)
.vertex_in(0, Type::VEC2, "pos")
.vertex_in(1, Type::VEC2, "texCoord")
.vertex_out(smooth_tex_coord_interp_iface)
.fragment_out(0, Type::VEC4, "fragColor")
.push_constant(Type::VEC2, "fullscreen")
.sampler(0, ImageType::FLOAT_2D, "image_texture")
.vertex_source("gpu_shader_display_fallback_vert.glsl")
.fragment_source("gpu_shader_display_fallback_frag.glsl")
.do_static_compilation(true);