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

Validation: Unexpected varying type Array in GLSL vertex shaders using gl builtin output #2168

Closed
lyricwulf opened this issue Nov 8, 2021 · 2 comments
Labels
area: validation Issues related to validation, diagnostics, and error handling needs information Further information is requested

Comments

@lyricwulf
Copy link

lyricwulf commented Nov 8, 2021

Description
When creating a vertex shader module from GLSL -> SpirV (using shaderc) causes warning (before #1983 was an error which did not affect program execution), when shader accesss (r/w/rw) any of the builtin gl_Position, gl_PointSize, gl_ClipDistance, gl_CullDistance.
wgpu_core::validation: Unexpected varying type: Array { base: [1], size: Constant([n]), stride: 4 }
This may be related to #1427. The reason I am opening a new issue is because I am hoping with the additional information this may be able to be fixed on the validation side.

Repro steps

  1. Create a vertex shader in GLSL and compile to .spv using shaderc (must use builtin as mentioned above).
  2. Create a ShaderModule using the .spv as SpirV code.

Additional notes

  • The offending SpirV op is OpTypeArray when using GL builtin gl_PerVertex interface block This warning can be circumvented by a redeclaration of gl_PerVertex before compiling to SpirV. Specifically, the effect this has on SpirV is removing the following block
	     %uint = OpTypeInt 32 0	
           %uint_1 = OpConstant %uint 1	
%_arr_float_uint_1 = OpTypeArray %float %uint_1	
     %gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
  • The warning does not appear if the GLSL shader contains none of the builtin outputs mentioned above. This is because there is no builtin declaration if none of the builtin outputs are used.
  • The warning can be suppressed if the built-in output block is redeclared in GLSL without gl_ClipDistance and gl_CullDistance. This is how I am resolving the warning in my own projects:
out gl_PerVertex {
  vec4 gl_Position; //optional
  float gl_PointSize; //optional
};

Minimal reproducible code:

#version 460

void main() {
    gl_Position = vec4(0);
}

Minimal workaround code:

#version 460

out gl_PerVertex {
  vec4 gl_Position;
};

void main() {
    gl_Position = vec4(0);
}

Platform
Win 11/Linux, Dx12/Vulkan/Gl, wgpu 0.8~0.11

@kvark
Copy link
Member

kvark commented Nov 9, 2021

Thank you for the extra information on working around it!
I don't know how the validator is supposed to fix this. It doesn't support arrays in this position, and the incoming SPIR-V does have arrays. Perhaps, we could put something in spv-in frontend instead to ignore those.

@kvark kvark added area: validation Issues related to validation, diagnostics, and error handling needs information Further information is requested labels Nov 9, 2021
@cwfitzgerald
Copy link
Member

Closing in favor of the older issue, but thank you for the additional info!

@cwfitzgerald cwfitzgerald closed this as not planned Won't fix, can't repro, duplicate, stale Jun 4, 2022
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 needs information Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants