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

Vulkan Forward+ shader fails to compile on Mac #86155

Closed
WindyDarian opened this issue Dec 14, 2023 · 3 comments · Fixed by #86219
Closed

Vulkan Forward+ shader fails to compile on Mac #86155

WindyDarian opened this issue Dec 14, 2023 · 3 comments · Fixed by #86219

Comments

@WindyDarian
Copy link
Contributor

Tested versions

Reproducible on custom build from main (4.3.dev aa5b6ed)
Unreproducible if set renderer to "Compatibility"
Unreproducible if undo ee1bf15 locally

System information

M1 Mac 14.2 , Vulkan SDK 1.3.268.1, Vulkan Forward+ renderer

Issue description

Vulkan validation error keeps popping up, notably

program_source:514:427: error: 'sampler' attribute parameter is out of bounds: must be between 0 and 15 and

VK_ERROR_INVALID_SHADER_NV: Fragment shader function could not be compiled into pipeline. See previous logged error.

--- Debug adapter server started ---
--- GDScript language server started on port 6005 ---
[LSP] Connection Taken
  drivers/vulkan/vulkan_context.cpp:267 - VALIDATION - Message Id Number: 0 | Message Id Name: 
  	VK_ERROR_INITIALIZATION_FAILED: Shader library compile failed (Error code 3):
  program_source:456:12: warning: unused variable 'vertex0' [-Wunused-variable]
      float3 vertex0 = vertex_interp;
             ^
  program_source:457:12: warning: unused variable 'eye_offset' [-Wunused-variable]
      float3 eye_offset = float3(0.0);
             ^
  program_source:458:12: warning: unused variable 'view' [-Wunused-variable]
      float3 view = -fast::normalize(vertex_interp);
             ^
  program_source:460:12: warning: unused variable 'backlight' [-Wunused-variable]
      float3 backlight = float3(0.0);
             ^
  program_source:461:12: warning: unused variable 'transmittance_color' [-Wunused-variable]
      float4 transmittance_color = float4(0.0, 0.0, 0.0, 1.0);
             ^
  program_source:462:11: warning: unused variable 'transmittance_depth' [-Wunused-variable]
      float transmittance_depth = 0.0;
            ^
  program_source:463:11: warning: unused variable 'transmittance_boost' [-Wunused-variable]
      float transmittance_boost = 0.0;
            ^
  program_source:466:12: warning: unused variable 'emission' [-Wunused-variable]
      float3 emission = float3(0.0);
             ^
  program_source:468:11: warning: unused variable 'rim' [-Wunused-variable]
      float rim = 0.0;
            ^
  program_source:469:11: warning: unused variable 'rim_tint' [-Wunused-variable]
      float rim_tint = 0.0;
            ^
  program_source:470:11: warning: unused variable 'clearcoat' [-Wunused-variable]
      float clearcoat = 0.0;
            ^
  program_source:471:11: warning: unused variable 'clearcoat_roughness' [-Wunused-variable]
      float clearcoat_roughness = 0.0;
            ^
  program_source:472:11: warning: unused variable 'anisotropy' [-Wunused-variable]
      float anisotropy = 0.0;
            ^
  program_source:473:12: warning: unused variable 'anisotropy_flow' [-Wunused-variable]
      float2 anisotropy_flow = float2(1.0, 0.0);
             ^
  program_source:474:11: warning: unused variable 'ao' [-Wunused-variable]
      float ao = 1.0;
            ^
  program_source:475:11: warning: unused variable 'ao_light_affect' [-Wunused-variable]
      float ao_light_affect = 0.0;
            ^
  program_source:477:12: warning: unused variable 'binormal' [-Wunused-variable]
      float3 binormal = float3(0.0);
             ^
  program_source:478:12: warning: unused variable 'tangent' [-Wunused-variable]
      float3 tangent = float3(0.0);
             ^
  program_source:479:12: warning: unused variable 'uv' [-Wunused-variable]
      float2 uv = uv_interp;
             ^
  program_source:480:12: warning: unused variable 'color' [-Wunused-variable]
      float4 color = color_interp;
             ^
  program_source:481:11: warning: unused variable 'normal_map_depth' [-Wunused-variable]
      float normal_map_depth = 1.0;
            ^
  program_source:482:12: warning: unused variable 'screen_uv' [-Wunused-variable]
      float2 screen_uv = gl_FragCoord.xy * scene_data.screen_pixel_size;
             ^
  program_source:483:11: warning: unused variable 'sss_strength' [-Wunused-variable]
      float sss_strength = 0.0;
            ^
  program_source:492:14: warning: unused variable 'read_view_matrix' [-Wunused-variable]
      float4x4 read_view_matrix = scene_data.view_matrix;
               ^
  program_source:493:12: warning: unused variable 'read_viewport_size' [-Wunused-variable]
      float2 read_viewport_size = scene_data.viewport_size;
             ^
  program_source:509:12: warning: unused variable 'specular_light' [-Wunused-variable]
      float3 specular_light = float3(0.0);
             ^
  program_source:510:12: warning: unused variable 'diffuse_light' [-Wunused-variable]
      float3 diffuse_light = float3(0.0);
             ^
  program_source:511:12: warning: unused variable 'ambient_light' [-Wunused-variable]
      float3 ambient_light = float3(0.0);
             ^
  program_source:514:427: error: 'sampler' attribute parameter is out of bounds: must be between 0 and 15
  fragment void main0(main0_in in [[stage_in]], constant SceneDataBlock& scene_data_block [[buffer(10)]], const device InstanceDataBuffer& instances [[buffer(12)]], constant MaterialUniforms& material [[buffer(16)]], texture2d<float> m_texture_albedo [[texture(32)]], texture2d<float> m_texture_metallic [[texture(33)]], texture2d<float> m_texture_roughness [[texture(34)]], sampler SAMPLER_LINEAR_WITH_MIPMAPS_REPEAT [[sampler(24)]], float4 gl_FragCoord [[position]])
                                                                                                                                                                                                                                                                                                                                                                                                                                            ^
  .
  	Objects - 1
  		Object[0] - VK_OBJECT_TYPE_PIPELINE_CACHE, Handle 4741973040
  drivers/vulkan/vulkan_context.cpp:267 - VALIDATION - Message Id Number: 0 | Message Id Name: 
  	VK_ERROR_INVALID_SHADER_NV: Fragment shader function could not be compiled into pipeline. See previous logged error.
  	Objects - 1
  		Object[0] - VK_OBJECT_TYPE_PIPELINE, Handle 11339407872
  vkCreateGraphicsPipelines failed with error -1000012000 for shader 'SceneForwardClusteredShaderRD:0'.
  servers/rendering/renderer_rd/pipeline_cache_rd.cpp:61 - Condition "pipeline.is_null()" is true. Returning: RID()
  This render pipeline requires (0) bytes of push constant data, supplied: (16)
  No render pipeline was set before attempting to draw.
  drivers/vulkan/vulkan_context.cpp:267 - VALIDATION - Message Id Number: 0 | Message Id Name: 
  	VK_ERROR_INITIALIZATION_FAILED: Shader library compile failed (Error code 3):
  program_source:498:12: warning: unused variable 'eye_offset' [-Wunused-variable]
      float3 eye_offset = float3(0.0);
             ^
  program_source:499:12: warning: unused variable 'view' [-Wunused-variable]
      float3 view = -fast::normalize(vertex_interp);
             ^
  program_source:501:12: warning: unused variable 'backlight' [-Wunused-variable]
      float3 backlight = float3(0.0);
             ^
  program_source:502:12: warning: unused variable 'transmittance_color' [-Wunused-variable]
      float4 transmittance_color = float4(0.0, 0.0, 0.0, 1.0);
             ^
  program_source:503:11: warning: unused variable 'transmittance_depth' [-Wunused-variable]
      float transmittance_depth = 0.0;
            ^
  program_source:504:11: warning: unused variable 'transmittance_boost' [-Wunused-variable]
      float transmittance_boost = 0.0;
            ^
  program_source:509:11: warning: unused variable 'rim' [-Wunused-variable]
      float rim = 0.0;
            ^
  program_source:510:11: warning: unused variable 'rim_tint' [-Wunused-variable]
      float rim_tint = 0.0;
            ^
  program_source:511:11: warning: unused variable 'clearcoat' [-Wunused-variable]
      float clearcoat = 0.0;
            ^
  program_source:512:11: warning: unused variable 'clearcoat_roughness' [-Wunused-variable]
      float clearcoat_roughness = 0.0;
            ^
  program_source:513:11: warning: unused variable 'anisotropy' [-Wunused-variable]
      float anisotropy = 0.0;
            ^
  program_source:514:12: warning: unused variable 'anisotropy_flow' [-Wunused-variable]
      float2 anisotropy_flow = float2(1.0, 0.0);
             ^
  program_source:516:11: warning: unused variable 'ao_light_affect' [-Wunused-variable]
      float ao_light_affect = 0.0;
            ^
  program_source:518:12: warning: unused variable 'binormal' [-Wunused-variable]
      float3 binormal = float3(0.0);
             ^
  program_source:519:12: warning: unused variable 'tangent' [-Wunused-variable]
      float3 tangent = float3(0.0);
             ^
  program_source:521:12: warning: unused variable 'uv' [-Wunused-variable]
      float2 uv = uv_interp;
             ^
  program_source:522:12: warning: unused variable 'color' [-Wunused-variable]
      float4 color = color_interp;
             ^
  program_source:523:11: warning: unused variable 'normal_map_depth' [-Wunused-variable]
      float normal_map_depth = 1.0;
            ^
  program_source:524:12: warning: unused variable 'screen_uv' [-Wunused-variable]
      float2 screen_uv = gl_FragCoord.xy * scene_data.screen_pixel_size;
             ^
  program_source:525:11: warning: unused variable 'sss_strength' [-Wunused-variable]
      float sss_strength = 0.0;
            ^
  program_source:534:14: warning: unused variable 'read_view_matrix' [-Wunused-variable]
      float4x4 read_view_matrix = scene_data.view_matrix;
               ^
  program_source:535:12: warning: unused variable 'read_viewport_size' [-Wunused-variable]
      float2 read_viewport_size = scene_data.viewport_size;
             ^
  program_source:707:744: error: 'sampler' attribute parameter is out of bounds: must be between 0 and 15
  fragment main0_out main0(main0_in in [[stage_in]], const device Decals& decals [[buffer(7)]], constant SceneDataBlock& scene_data_block [[buffer(10)]], constant ImplementationDataBlock& implementation_data_block [[buffer(11)]], const device InstanceDataBuffer& instances [[buffer(12)]], const device ClusterBuffer& cluster_buffer [[buffer(13)]], constant MaterialUniforms& material [[buffer(16)]], texture2d<float> decal_atlas [[texture(0)]], texture2d<float> decal_atlas_srgb [[texture(1)]], texture2d<float> m_texture_albedo [[texture(32)]], texture2d<float> m_texture_metallic [[texture(33)]], texture2d<float> m_texture_roughness [[texture(34)]], sampler decal_sampler [[sampler(13)]], sampler SAMPLER_LINEAR_WITH_MIPMAPS_REPEAT [[sampler(24)]], float4 gl_FragCoord [[position]])
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         ^
  .
  	Objects - 1
  		Object[0] - VK_OBJECT_TYPE_PIPELINE_CACHE, Handle 4741973040
  drivers/vulkan/vulkan_context.cpp:267 - VALIDATION - Message Id Number: 0 | Message Id Name: 
  	VK_ERROR_INVALID_SHADER_NV: Fragment shader function could not be compiled into pipeline. See previous logged error.
  	Objects - 1
  		Object[0] - VK_OBJECT_TYPE_PIPELINE, Handle 11380276224
  vkCreateGraphicsPipelines failed with error -1000012000 for shader 'SceneForwardClusteredShaderRD:9'.
  servers/rendering/renderer_rd/pipeline_cache_rd.cpp:61 - Condition "pipeline.is_null()" is true. Returning: RID()
  This render pipeline requires (0) bytes of push constant data, supplied: (16)
  No render pipeline was set before attempting to draw.
  drivers/vulkan/vulkan_context.cpp:267 - VALIDATION - Message Id Number: 0 | Message Id Name: 
  	VK_ERROR_INVALID_SHADER_NV: Fragment shader function could not be compiled into pipeline. See previous logged error.
  	Objects - 1
  		Object[0] - VK_OBJECT_TYPE_PIPELINE, Handle 4790395904
  vkCreateGraphicsPipelines failed with error -1000012000 for shader 'SceneForwardClusteredShaderRD:0'.
  servers/rendering/renderer_rd/pipeline_cache_rd.cpp:61 - Condition "pipeline.is_null()" is true. Returning: RID()
  This render pipeline requires (0) bytes of push constant data, supplied: (16)
  No render pipeline was set before attempting to draw.
...
image

Steps to reproduce

  1. Build Godot with platform=osx arch=arm64 dev_build=true and open launcher
  2. Create a blank project with Forward+ and open
  3. observe errors pop up

Minimal reproduction project (MRP)

godot_test.zip
(it's a blank project)

@clayjohn
Copy link
Member

It looks like your device only supports up to 16 samplers per stage. Which conflicts with #84637 which inadvertently created a situation where many more samplers are needed.

We are going to have to take another stab at #84637 to implement it in a way that uses less samplers

@bruvzg
Copy link
Member

bruvzg commented Dec 14, 2023

It looks like your device only supports up to 16 samplers per stage.

This is true for all Macs. The limit is hard-coded, probably a Metal limitation:

https://github.com/KhronosGroup/MoltenVK/blob/2cccfd516eaf40d81df4f241637ffc95f5c6fece/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm#L1723

@WindyDarian
Copy link
Contributor Author

Can confirm #86219 fixes the issue on my Mac. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants