3

Somehow a very simple test of depth values between the gbuffer depth texture and the current frag depth of a forward rendering pass causes a hard crash. I feel like there must be something I'm missing here. NOTE: the framebuffer where the frag shader is being used is multisampled. Here's the crashing frag shader:

#version 330
out vec4 out_Color;
in vec2 TexCoords;
uniform sampler2D gDepth;//depth attachment from gBuffer render passs

void main() {   
float z1 = texture(gDepth, TexCoords).r;//depth from gbuffer depth, a float32 texture
float z2 = gl_FragCoord.z;

    if(z1 < z2) { //MANUAL Z TEST -- this single line causes a huge crash at run time

        out_Color = vec4(1, 0, 0, 1);//color rejected frags red as a diagnostic
        return; 
    }
    else{
         out_Color = vec4(0,0,1,1);//else, frags are colored blue
    }
}

This is all from code that works fine otherwise, and I've diagnosed this problem down to this single line. My graphics card is somewhat recent Nvidia card (Geforce GT 710), and I am using glew and wgl. If I can do z-testing here I can bump up my frame rate by quite a bit

Here's a photo of rendering a scene using z1 and z2: The unaltered scene

z1 rendered

z2 rendered

EDIT: I forgot to mention that that FBO where the frag shader is being used is multisampled.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Jeff Strom
  • 141
  • 1
  • 6
  • 2
    Because these are the comments, I get to shout stupid things over breakfast coffee and hope they help in finding the culprit :) Test: if you remove the z1 < z2 test, but replace it with any other line that refers to z1, does it still crash? The float32 lookup looks much more likely to be the root cause, maybe it's optimized out if you don't refer to z1? – Paul-Jan Nov 15 '19 at 06:45
  • 1
    I'm also suspicious of the float32 lookup, but if I write a line that references it, it works alright. My new code is: float z1 = texture(gDepth, fs_in.TexCoords).r; float z2 = gl_FragCoord.z; float x = z1 * 1.0; and it runs okay. – Jeff Strom Nov 15 '19 at 06:50
  • 1
    However, if I add back in the z1 < z2 test, there is still a crash. Even if I make the depth buffer data type GL_UNSIGNED_BYTE and switch it to GL_DEPTH_COMPONENT format. – Jeff Strom Nov 15 '19 at 06:59
  • Did you try updating the GPU driver? This is exactly the kind of stuff that happens due to driver bugs. Also try removing the "return" statement. – Tara Dec 06 '20 at 01:50

0 Answers0