Bug 369474

Summary: OCIO - Krita could not initialize OpenGL canvas
Product: [Applications] krita Reporter: HPetrus <haigpetrus>
Component: OpenGL CanvasAssignee: Krita Bugs <krita-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: alvin, halla
Priority: NOR    
Version First Reported In: 3.0.1   
Target Milestone: ---   
Platform: macOS (DMG)   
OS: macOS   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description HPetrus 2016-09-28 12:50:37 UTC
Right after initial launch of 3.0.1.90, when I enable Use OpenColorIO, I get the error message:

Krita could not initialize the OpenGL canvas:
Failed to add fragment shader source from file: highq_downscale.frag
 Krita will disable OpenGL and close now.

The canvas then goes blank/transparent.  When disabling OpenColorIO, the canvas returns to last state, as it was left, as before.

Upon second start-up, this issue disappears (apparently).

Reproducible: Sometimes

Steps to Reproduce:
1.  Install/start up Krita on OSX Sierra
2.  Create and draw on canvas
3.  Turn on OpenColorIO and choose colour engine

Actual Results:  
Error message, as described above.

Expected Results:  
Colour model should appear immediately, as on most recent stable Linux version.
Comment 1 Halla Rempt 2016-10-03 09:16:54 UTC
The weird thing is, it doesn't seem to be reproducible on El Capitan.
Comment 2 Halla Rempt 2016-10-10 07:10:31 UTC
I've got something similar, on closing Krita after changing the canvas to opengl:

QOpenGLShader::compile(Fragment): ERROR: 0:14: Invalid call of undeclared identifier 'texture3D'

*** Problematic Fragment shader source code ***
#version 150 core
#define lowp
#define mediump
#define highp
#line 2
#define DIRECT_LOD_FETCH
#define HIGHQ_SCALING
#define USE_OCIO

// Generated by OpenColorIO

vec4 OCIODisplay(in vec4 inPixel, 
    const sampler3D lut3d) 
{
vec4 out_pixel = inPixel; 
// OSX segfault work-around: Force a no-op sampling of the 3d lut.
texture3D(lut3d, 0.984375 * out_pixel.rgb + 0.0078125).rgb;
return out_pixel;
}


/*
 * shader for handling scaling
 */
uniform sampler2D texture0;

#ifdef USE_OCIO
uniform sampler3D texture1;
#endif

in vec4 v_textureCoordinate;
out vec4 fragColor;

const float eps = 1e-6;

#if defined HIGHQ_SCALING || defined DIRECT_LOD_FETCH
uniform float viewportScale;
#endif /* defined HIGHQ_SCALING || defined DIRECT_LOD_FETCH */

#ifdef DIRECT_LOD_FETCH
uniform float fixedLodLevel;
#endif

#ifdef HIGHQ_SCALING

uniform float texelSize;

vec4 filterPureLinear8(sampler2D texture, vec2 texcoord)
{
    float newTexelSize = texelSize / viewportScale;
    float support = 0.5 * newTexelSize;
    float step = texelSize * 1.0;

    float offset = support - 0.5*texelSize;

    float level = 0.0;


    if (viewportScale < 0.03125) {
        level = 4.0;
    } else if (viewportScale < 0.0625) {
        level = 3.0;
    } else if (viewportScale < 0.125) {
        level = 2.0;
    } else if (viewportScale < 0.25) {
        level = 1.0;
    }

/*
    vec4 p1 = textureLod(texture, vec2(texcoord.x - offset, texcoord.y - offset), level);
    vec4 p2 = 2.0*textureLod(texture, vec2(texcoord.x         , texcoord.y - offset), level);
    vec4 p3 = textureLod(texture, vec2(texcoord.x + offset, texcoord.y - offset), level);

    vec4 p4 = 2.0*textureLod(texture, vec2(texcoord.x - offset, texcoord.y), level);
    vec4 p5 = 5.0*textureLod(texture, vec2(texcoord.x         , texcoord.y), level);
    vec4 p6 = 2.0*textureLod(texture, vec2(texcoord.x + offset, texcoord.y), level);

    vec4 p7 = textureLod(texture, vec2(texcoord.x - offset, texcoord.y + offset), level);
    vec4 p8 = 2.0*textureLod(texture, vec2(texcoord.x         , texcoord.y + offset), level);
    vec4 p9 = textureLod(texture, vec2(texcoord.x + offset, texcoord.y + offset), level);

    return (p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9) / 17.0;
*/

    vec4 p1 = textureLod(texture, vec2(texcoord.x - offset, texcoord.y - offset), level);
    vec4 p2 = textureLod(texture, vec2(texcoord.x + offset, texcoord.y - offset), level);

    vec4 p3 = vec4(4.0) * textureLod(texture, vec2(texcoord.x, texcoord.y), level);

    vec4 p4 = textureLod(texture, vec2(texcoord.x - offset, texcoord.y + offset), level);
    vec4 p5 = textureLod(texture, vec2(texcoord.x + offset, texcoord.y + offset), level);

    vec4 p6 = vec4(3.0) * textureLod(texture, vec2(texcoord.x, texcoord.y), level + 1.0);

    return (p1 + p2 + p3 + p4 + p5 + p6) / vec4(11.0);

}

#endif /* HIGHQ_SCALING */

void main() {
    vec4 col;

#if defined HIGHQ_SCALING || defined DIRECT_LOD_FETCH

    if (viewportScale < 0.5 - eps) {

#ifdef DIRECT_LOD_FETCH

        if (fixedLodLevel > eps) {
            col = textureLod(texture0, v_textureCoordinate.st, fixedLodLevel);
        } else

#endif /* DIRECT_LOD_FETCH */

        {

#ifdef HIGHQ_SCALING
            col = filterPureLinear8(texture0, v_textureCoordinate.st);
#else /* HIGHQ_SCALING */
            col = texture(texture0, v_textureCoordinate.st);
#endif /* HIGHQ_SCALING */

        }
    } else

#endif /* defined HIGHQ_SCALING || defined DIRECT_LOD_FETCH */

    {
#ifdef DIRECT_LOD_FETCH

        if (fixedLodLevel > eps) {
            col = textureLod(texture0, v_textureCoordinate.st, fixedLodLevel);
        } else

#endif /* DIRECT_LOD_FETCH */
        {
            col = texture(texture0, v_textureCoordinate.st);
        }
    }

#ifdef USE_OCIO
    fragColor = OCIODisplay(col, texture1);
#else /* USE_OCIO */
    fragColor = col;
#endif /* USE_OCIO */

}

***
Shader Compilation Failure:  "Failed to add fragment shader source from file: highq_downscale.frag"
Segmentation fault: 11
Comment 3 Alvin Wong 2017-09-20 03:08:59 UTC
Is this fixed in 3.2.1? I remember Dmitry fixed some bugs related to OCIO.
Comment 4 Halla Rempt 2017-09-20 07:58:58 UTC
Oh yes, should've been fixed for ages.