KhronosGroup / GLSL

GLSL Shading Language Specification and Extensions
Other
346 stars 101 forks source link

Argument variable using out keyword causes unexpected behaviour #238

Open bogrundtman opened 5 months ago

bogrundtman commented 5 months ago

When a variable is used with the out keyword in a function argument then it seems to trigger an if statement right below the function call even though the if statement should never execute.

This fragment shader turns the screen WHITE

#version 450
layout(location = 0) out vec4 out_color;
void empty_function(out vec3 color) {}

void main() {
    vec3 color = vec3(0, 0, 0);
    empty_function(color);              // When commenting out this line the if statement does not execute and the screen turns BLACK
    if (false) {color = vec3(1,1,1);}

    out_color = vec4(color, 1);
}

When involving another variable and taking the maximum of the two (In this case the screen would turn WHITE if the if statement executed) the issue seems to disappear.

This fragment shader turns the screen BLACK

#version 450
layout(location = 0) out vec4 out_color;
void empty_function(out vec3 color) {}

void main() {
    vec3 color = vec3(0, 0, 0);
    vec3 actual_color = vec3(0, 0, 0);
    empty_function(color);
    if (false) {actual_color = vec3(1,1,1);}

    out_color = vec4(max(color, actual_color), 1);
}

Info

Hardware: Intel Iris Xe Graphics API: Vulkan 1.3.283

glslc --version

shaderc v2023.8 v2024.0
spirv-tools v2024.1 v2022.4-451-g04896c46
glslang 11.1.0-937-gd73712b8

Target: SPIR-V 1.0