vsg-dev / VulkanSceneGraph

Vulkan & C++17 based Scene Graph Project
http://www.vulkanscenegraph.org
MIT License
1.29k stars 206 forks source link

glslang compilation error when using uvec2 in GLSL code #1077

Closed asafran closed 2 months ago

asafran commented 8 months ago

Describe the bug glslang compilation error when using uvec2 in GLSL code

To Reproduce Steps to reproduce the behavior:

  1. Clone and build vsgFramework
  2. Modify any GLSL shader used in the example. Add any code (e.g. from https://www.khronos.org/opengl/wiki/Core_Language_(GLSL)#Examples) contains uvec2 initialization: const uvec2 range = uvec2(2, 5);
  3. Set VSG_FILE_PATH and run example (I used vsgtexturearray) using modified GLSL shader
  4. See error:
    
    Warning: 
    ----  Fragment Shader  ---- 

Warning: 1: #version 450 2: #extension GL_ARB_separate_shader_objects : enable 3: 4: layout(constant_id = 0) const uint numBaseTextures = 1; 5: 6: layout(set = 0, binding = 1) uniform sampler2D baseTextureSampler[numBaseTextures]; 7: 8: layout(set = 1, binding = 0) uniform TileSettings { 9: uint tileIndex; 10: } tileSettings; 11: 12: layout(location = 0) in vec3 fragColor; 13: layout(location = 1) in vec2 fragTexCoord; 14: 15: layout(location = 0) out vec4 outColor; 16: 17: const uvec2 range = uvec2(2, 5); 18: 19: void main() { 20: outColor = texture(baseTextureSampler[tileSettings.tileIndex], fragTexCoord); 21: }

Warning: GLSL source failed to parse. Warning: glslang info log: ERROR: 0:17: 'constructor' : can't convert ERROR: 0:17: ' const 2-component vector of uint' : cannot construct with these arguments ERROR: 0:17: 'const' : non-matching or non-convertible constant type for const initializer ERROR: 0:17: '' : compilation terminated ERROR: 4 compilation errors. No code generated.

info: glslang debug info log:

Warning: -------- Segmentation fault (core dumped)



**Expected behavior**
Successful compilation of the GLSL code

**Desktop (please complete the following information):**
 - OS: Fedora Linux 39
 - Version master 081c88acb19671d12b1ef565110bb5dedb9be1fc
robertosfield commented 8 months ago

The VSG builds glslang as part of the VSG itself to compile GLSL shaders to SPIR-V, so either the version of glslang we are including has a problem, or glslang requires an option enabled to support uvec's.

Could you try out glslangValidator on the shader?

robertosfield commented 8 months ago

Yesterday evening I tried out uvec2 with shaders on my laptop and reproduced the issue, I tried glslangValidator from VulkanSDK 1.2.268 and 1.3.275 and both acceoted my uvec2 code, I then checked the glslang version used in each case.

The VSG's glslang is 12.0.0 which was drawn from glslang master last year, while the VulkanSDK versions were 10.x. and 11.x versions respectively, so it could be there was a regression between 11.x and 12.x. The VSG uses a branch from glslang so I there is changes the upstream glslang has resolved this regression and we just need to merge updates.

I have other tasks to tackle to today so can't spend time right away investigating this further.

robertosfield commented 4 months ago

@asafran I have created a branch of the VSG that links to glslang as an external dependency rather than then building a fork of glslang directly into VSG library. I've written up some details on the discussion therad #1199. Could you test of the new external_glslang branch with modern version of gslang (14.1 or later) to see if the issue uvec2 issue is resolved. Thanks.