Geeks3D Forums

Tech Forums => Geeks3D's GPU Tools => Topic started by: CK on October 25, 2018, 10:05:28 AM

Title: GPU Caps Viewer 1.39: Vulkan - Shadertoy > Seascape: uninitialized out variable
Post by: CK on October 25, 2018, 10:05:28 AM
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;
}


Title: Re: GPU Caps Viewer 1.39: Vulkan - Shadertoy > Seascape: uninitialized out variable
Post by: JeGX on October 26, 2018, 03:40:11 PM
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:
Code: [Select]
// tracing
vec3 p = vec3(0.0);
heightMapTracing(ori,dir,p);

Title: Re: GPU Caps Viewer 1.39: Vulkan - Shadertoy > Seascape: uninitialized out variable
Post by: CK on November 14, 2018, 09:04:48 AM
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.
Title: Re: GPU Caps Viewer 1.39: Vulkan - Shadertoy > Seascape: uninitialized out variable
Post by: JeGX on November 14, 2018, 10:42:53 AM
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.
Title: Re: GPU Caps Viewer 1.39: Vulkan - Shadertoy > Seascape: uninitialized out variable
Post by: CK on November 19, 2018, 08:36:09 AM
I've checked 1.40.1. Looks good.
Thanks!