Shader behavior on unitialized variable (maybe bug)

Nvidia 750
driver version Linux 460.39 (latest today updated) it does have bug
Windows driver version 461.40 (latest today updated) it does have bug

I did not test it on other Nvidia GPU, but base on the first bug - this bug should work on every Nvidia GPU that supports Vulkan except RTX 2xxx and 3xxx

the bug is - that “shader noise generated by bug from not initialized variable react to outside activity
(on everything from simple mouse moving to panels/menu popup on other window/OS UI or other app activity)
so this “bug” in theory can be used to detect “user activity outside window”

this bug similar to other my bug that already fixed, but it act 1:1 the same

repeating bug in Vulkan-Samples where shader code does not have any dynamic uniforms but the image still change by outside activity (if it uniform-leak then it leaks from other applications that use GPU)

minimal shader code:

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    fragColor-= fragColor; //not initialized variable
    fragColor-=  max(0., length(fragCoord/iResolution.xy)-.8 ); 
    fragColor = sqrt(1.-fragColor);
}

minimal exe and linux build to test (warning its my own application, you may not trust this)

Bug required atleast one application that use same gpu as bug-noise shader, launch browser ot anything else on same Nvidia GPU where noise-shader launched (if you have multiple GPU setup and OS launched on other GPU)

bug screenshot from khronos Vulkan-Samples

Steps to launch this shader in Khronos example:

  1. clone and build github.com/KhronosGroup/Vulkan-Samples
  2. edit shader code Vulkan-Samples/shaders/texture_loading/texture.frag to this:
#version 450
/* Copyright (c) 2019, Sascha Willems
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 the "License";
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

layout (binding = 1) uniform sampler2D samplerColor;

layout (location = 0) in vec2 inUV;
layout (location = 1) in float inLodBias;
layout (location = 2) in vec3 inNormal;
layout (location = 3) in vec3 inViewVec;
layout (location = 4) in vec3 inLightVec;

layout (location = 0) out vec4 outFragColor;

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    fragColor-= fragColor; //not initialized variable
    fragColor-=  max(0., length(fragCoord/vec2(512.))-.8 ); 
    fragColor = sqrt(1.-fragColor);
}

void main() 
{
	mainImage(outFragColor,inUV*vec2(512.));
}

  1. launch ./build/app/bin/x86_64/vulkan_samples --sample texture_loading

P.S. if someone launch my exe or Vulkan-Sample with this shader, please tell your result does this bug works for you or it is not, thanks.

youtube links
my video result from original shader
second video result from modifier shader, in this version I almost can read color of “other window activity”(look color change of noise and background window)

Is this pipeline using per-sample shading? If so, we have a known bug with the fragCoord.zw inputs being undefined, which will be fixed soon. Try initializing the .zw.

thanks for reply

changing .wz or any other 3 values dont fix this bug
each component of fragColor.xyzw has its own “noise”

on screenshot changed .zw to 1. it adds blue color

even this code of changing yzw and then using x

    fragColor.yzw = vec3(1.);
    fragColor = vec4(fragColor.x);

display noise from .x component

initializing .zw before use, full shader code

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    fragColor.zw=vec2(0.);
    fragColor-= fragColor; //not initialized variable
    fragColor-=  max(0., length(fragCoord/iResolution.xy)-.8 ); 
    fragColor = sqrt(1.-fragColor);
}

result

Is this pipeline using per-sample shading?

this my example same as Khronos sample use just two triangles and single vertex and fragment shader on this triangles

Thanks for the additional detail. I’ll look in more detail this week.

When I first read the bug report I jumped to the wrong conclusion regarding “fragCoord”. I see now that wasn’t referring to the gl_FragCoord builtin, but rather that was just a parameter to the mainImage() function. Sorry, that was a silly oversight.

Now that I fully understand the issue, I have created an internal bug report that is being investigated. This behavior shouldn’t be happening and it will be fixed in a future driver update. Many thanks for reporting this to us.