GPU Caps Viewer 1.39: Vulkan - Shadertoy > Seascape: uninitialized out variable

Started by CK, October 25, 2018, 10:05:28 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

CK

There seem to be an uninitialized out variable in one of the shaders (s01-ps.frag).
It causes ugly black rectangles on sky on Intel graphics.

Part of the shader with proposed change:

float heightMapTracing(vec3 ori, vec3 dir, out vec3 p) { 
    float tm = 0.0;
    float tx = 1000.0;   
    float hx = map(ori + dir * tx);
    p = vec3(0.0f, 0.0f, 0.0f); // <= proposed change
    if(hx > 0.0) return tx;   
    float hm = map(ori + dir * tm);   
    float tmid = 0.0;
    for(int i = 0; i < NUM_STEPS; i++) {
        tmid = mix(tm,tx, hm/(hm-hx));                   
        p = ori + dir * tmid;                   
       float hmid = map(p);
      if(hmid < 0.0) {
           tx = tmid;
            hx = hmid;
        } else {
            tm = tmid;
            hm = hmid;
        }
    }
    return tmid;
}



JeGX

Thanks for your fix. I tested on an Intel HD 630 and it works. I didn't touch the heightMapTracing() function, I only initialized p at creation:

// tracing
vec3 p = vec3(0.0);
heightMapTracing(ori,dir,p);



CK

I must admit I just looked at you fix without actually trying it  :(
But now, in 1.40.0.0 it still does not work for me.

One more modification needed in this fix is changing "out vec3 p" to "inout vec3 p" in heightMapTracing declaration.
Otherwise the externally initialized p is overwritten with random one (uninitialized) from withing the heightMapTracing.

One more thing - when I edit the glsl code and start the demo spirv is not generated - even when I completely delete it (black screen in such case). I must manually generate spirv. In 1.39.0.0 I did not notice such problem.

JeGX

I still have the issue on my GTX 1080 as well and indeed changing "out vec3 p" by "inout vec3 p" fixed the glitch.  Will be released in GPU Caps 1.40.1.0... 

For the spirv file, the demo tries to load spirv files. So if a spirv file is missing, the loading fails. I generate the spirv files manually as you did. The shaders are loaded in lines 95 and 96 of the main01.xml file.