Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compute shader throwing validation errors not present in Vulkan #4534

Closed
spencerkohan opened this issue Oct 11, 2022 · 5 comments
Closed

Compute shader throwing validation errors not present in Vulkan #4534

spencerkohan opened this issue Oct 11, 2022 · 5 comments
Labels
area: validation Issues related to validation, diagnostics, and error handling naga Shader Translator type: enhancement New feature or request

Comments

@spencerkohan
Copy link

I'm attempting to create a module from the following shader:

#version 450
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;

layout(set = 0, binding = 0) uniform texture2D input_image;
layout(set = 0, binding = 1) uniform sampler input_sampler;
layout(set = 1, binding = 0, rgba8) uniform writeonly image2D output_image;

void main() {

    ivec2 textureSize = imageSize(output_image);
    if (gl_GlobalInvocationID.x >= textureSize.x || gl_GlobalInvocationID.y >= textureSize.y) {
        return;
    }

    ivec2 index = ivec2(gl_GlobalInvocationID.xy);
    vec2 uv = index / textureSize;

    vec4 value = texture(
        sampler2D(input_image, input_sampler),
        uv
    );

    imageStore(output_image, index, value);
}

This shader works perfectly on Vulkan, but throws a few validation errors when used with naga.

The firs is related to early return:

Function [1] 'main' is invalid
    Required uniformity of control flow for IMPLICIT_LEVEL in [31] is not fulfilled because of Return

And if I comment out that section, I get a second error:

Entry point main at Compute is invalid
Uses operations forbidden at this stage

By process of elimination, it seems to come down to the texture sampling:

vec4 value = texture(
    sampler2D(input_image, input_sampler),
    uv
);

Are these known issues, and is there any documentation about how naga's GLSL deviates from the standard?

@cwfitzgerald
Copy link
Member

Both of these issues are technically not allowed in normal GLSL either, but compilers don't tell you about them.

Calling texture is technically not allowed in compute shaders because there are no quads (2x2 pixel structures which fragment shaders use for derivatives) to do UV derivatives with. It also isn't allowed where only some members of a quad hit the call to texture - all 4 members of the quad have to hit the point of derivatives.

@spencerkohan
Copy link
Author

Oh interesting.

I've been able to get this to work exactly as expected by converting it to SPIR-V via Spirv-Cross before loading it - does SPIR-V have a different approach to sampling textures?

@JCapucho
Copy link

Spirv-cross seems to convert the texture call to a textureLoad call with the third argument as 0.

@JCapucho
Copy link

The first error I'm not sure but it might be related to the uniform analysis #4320

@JCapucho JCapucho added area: validation Issues related to validation, diagnostics, and error handling type: enhancement New feature or request labels Oct 21, 2022
@cwfitzgerald cwfitzgerald transferred this issue from gfx-rs/naga Oct 25, 2023
@cwfitzgerald cwfitzgerald added the naga Shader Translator label Oct 25, 2023
@teoxoy
Copy link
Member

teoxoy commented Nov 3, 2023

Let's track this in #4369.

@teoxoy teoxoy closed this as not planned Won't fix, can't repro, duplicate, stale Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: validation Issues related to validation, diagnostics, and error handling naga Shader Translator type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants