gfx-rs / wgpu

A cross-platform, safe, pure-Rust graphics API.
https://wgpu.rs
Apache License 2.0
12.25k stars 898 forks source link

[msl-out] WGSL shader passes validation but compiling the metal shader times out? #4456

Open superdump opened 2 years ago

superdump commented 2 years ago

In bevy we are developing a preprocessor to enable modular reuse of shader code. I reworked the code to split types, bindings, and functions into separate files, and that was working. Then I made another change to pass all bindings as arguments to functions so that the order of importing/defining functions and bindings doesn't matter. The result for the main pbr shader is that it passes WGSL validation but the metal shader compiler seems to hang as I see this output when debugging in Xcode (note that it may have compiled multiple shaders and the earlier warnings about unused variables may be from those):

[Metal Diagnostics Warning] Application Deployment Target Version ((null)) does not match OS Version (12.1) - diagnostics may be missing debug information2021-12-26 12:25:36.896673+0100 3d_scene[86558:3643596] Metal GPU Frame Capture Enabled
2021-12-26 12:25:36.896849+0100 3d_scene[86558:3643596] Metal API Validation Enabled
2021-12-26 12:25:36.896872+0100 3d_scene[86558:3643596] Metal GPU Validation Enabled
2021-12-26T11:25:36.910744Z  INFO bevy_render::renderer: AdapterInfo { name: "Apple M1 Max", vendor: 0, device: 0, device_type: DiscreteGpu, backend: Metal }
2021-12-26 12:25:36.937232+0100 3d_scene[86558:3643596] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x15275bdd0> F8BB1C28-BAE8-11D6-9C31-00039315CD46
2021-12-26 12:25:36.945448+0100 3d_scene[86558:3643596]  HALC_ProxyObjectMap::_CopyObjectByObjectID: failed to create the local object
2021-12-26 12:25:36.945482+0100 3d_scene[86558:3643596]  HALC_ShellDevice::RebuildControlList: couldn't find the control object
2021-12-26 12:25:37.583423+0100 3d_scene[86558:3644325] [Metal Compiler Warning] Warning: Compilation succeeded with: 

program_source:174:25: warning: unused variable 'in'
    const FragmentInput in = { is_front, varyings_1.world_position, varyings_1.world_normal, varyings_1.uv };
                        ^
program_source:11:29: warning: unused variable 'POINT_LIGHT_FLAGS_SHADOWS_ENABLED_BIT'
constexpr constant unsigned POINT_LIGHT_FLAGS_SHADOWS_ENABLED_BIT = 1u;
                            ^
program_source:12:29: warning: unused variable 'DIRECTIONAL_LIGHT_FLAGS_SHADOWS_ENABLED_BIT'
constexpr constant unsigned DIRECTIONAL_LIGHT_FLAGS_SHADOWS_ENABLED_BIT = 1u;
                            ^
program_source:13:29: warning: unused variable 'MESH_FLAGS_SHADOW_RECEIVER_BIT'
constexpr constant unsigned MESH_FLAGS_SHADOW_RECEIVER_BIT = 1u;
                            ^
2021-12-26 12:25:38.316383+0100 3d_scene[86558:3644325] [Metal Compiler Warning] Warning: Compilation succeeded with: 

program_source:22:29: warning: unused variable 'STANDARD_MATERIAL_FLAGS_ALPHA_MODE_BLEND'
constexpr constant unsigned STANDARD_MATERIAL_FLAGS_ALPHA_MODE_BLEND = 256u;
                            ^
2021-12-26 12:26:30.994340+0100 3d_scene[86558:3644325] Compiler failed with XPC_ERROR_CONNECTION_INTERRUPTED
2021-12-26 12:26:30.994415+0100 3d_scene[86558:3644325] MTLCompiler: Compilation failed with XPC_ERROR_CONNECTION_INTERRUPTED on 1 try
2021-12-26 12:27:28.095478+0100 3d_scene[86558:3644325] Compiler failed with XPC_ERROR_CONNECTION_INTERRUPTED
2021-12-26 12:27:28.095541+0100 3d_scene[86558:3644325] MTLCompiler: Compilation failed with XPC_ERROR_CONNECTION_INTERRUPTED on 2 try
2021-12-26 12:28:23.404635+0100 3d_scene[86558:3644325] Compiler failed with XPC_ERROR_CONNECTION_INTERRUPTED
2021-12-26 12:28:23.404709+0100 3d_scene[86558:3644325] MTLCompiler: Compilation failed with XPC_ERROR_CONNECTION_INTERRUPTED on 3 try
2021-12-26 12:29:20.633830+0100 3d_scene[86558:3644325] Compiler failed with XPC_ERROR_CONNECTION_INTERRUPTED
2021-12-26 12:29:20.633897+0100 3d_scene[86558:3644325] MTLCompiler: Compilation failed with XPC_ERROR_CONNECTION_INTERRUPTED on 1 try
2021-12-26 12:30:12.197414+0100 3d_scene[86558:3644325] Compiler failed with XPC_ERROR_CONNECTION_INTERRUPTED
2021-12-26 12:30:12.197509+0100 3d_scene[86558:3644325] MTLCompiler: Compilation failed with XPC_ERROR_CONNECTION_INTERRUPTED on 2 try
2021-12-26 12:31:05.392055+0100 3d_scene[86558:3644325] Compiler failed with XPC_ERROR_CONNECTION_INTERRUPTED
2021-12-26 12:31:05.392122+0100 3d_scene[86558:3644325] MTLCompiler: Compilation failed with XPC_ERROR_CONNECTION_INTERRUPTED on 3 try
2021-12-26T11:31:05.392412Z ERROR wgpu::backend::direct: Handling wgpu errors as fatal by default    
thread 'TaskPool (3)' panicked at 'wgpu error: Validation Error

Caused by:
    In Device::create_render_pipeline
      note: label = `pbr_opaque_mesh_pipeline`
    Internal error in VERTEX | FRAGMENT | VERTEX_FRAGMENT shader: new_render_pipeline_state: "Compiler encountered an internal error"

', /Users/roberts/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-0.12.0/src/backend/direct.rs:2273:5

Here is the full preprocessed WGSL shader: test.txt

Using naga 0.8.0 on macOS 12.1 with Xcode 13.2.1.

superdump commented 2 years ago

Wait... I saw MTLCompiler and started writing the ticket as I thought that was for compiling the shaders. But then when I looked back at the output in Xcode, it had actually terminated to lldb and showed that the error was with create_render_pipeline. Should this be a wgpu issue?