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 pipeline compile fails with "Compiler encountered an internal error." #2363

Open
squidbus opened this issue Oct 4, 2024 · 2 comments
Labels
Answered A question was answered Metal improvement required An improvement to Metal is required to resolve this issue. Question SPIRV-Cross Please re-submit to SPRIV-Cross

Comments

@squidbus
Copy link
Contributor

squidbus commented Oct 4, 2024

The below compute shader and pipeline are producing the following error from vkCreateComputePipelines:

[mvk-error] VK_ERROR_INITIALIZATION_FAILED: Compute pipeline compile failed (Error code 3):
Compiler encountered an internal error.

The crash report for MTLCompilerService says the following:

unable to legalize instruction: %62:_(s32), %63:_(s1) = 145 %59:_, %55:_
Context:
%62:_(s32), %63:_(s1) = 145 %59:_, %55:_
%59:_(s32) = 181 %58:_(s32)
%55:_(s32) = 90 %57:_(p64) :: (dereferenceable load (s32) from `i32 addrspace(64)* bitcast (i8 addrspace(64)* getelementptr inbounds ([28 x i8], [28 x i8] addrspace(64)* @memorycache0, i32 0, i32 8) to i32 addrspace(64)*)`, !tbaa !50, !alias.scope !54, !noalias !61, addrspace 64)
%58:_(s32) = 19 $r10
%57:_(p64) = 193 %7:_, %17:_(s64)
%7:_(p64) = 71 @memorycache0
%17:_(s64) = 120 i64 8
(in function: agc.main)

Compute shader (SPIR-V and generated MSL included): https://gist.github.com/squidbus/50273067f4bd89752473c04683524a93

Pipeline:

  • Push Descriptor Layout:
    • Uniform Buffer at Binding 0
    • Uniform Texel Buffer at Binding 1
    • Storage Image at Binding 2
  • Push Constants: Offset = 0, Size = 104

System: M3 Max w/ macOS 15.1 Beta 5 (and macOS 15)

This seems to be coming from the last line with the image write, as if I replace the coordinates argument with a fixed zero vector it compiles.

Note that there is no error if I use the command line shader compiler, only when compiling a pipeline at runtime.

I have a feeling this may be triggering a Metal compiler bug, but I felt it would be worth reporting here for a look, in case it could be worked around in the SPIR-V to Metal translation for better compatibility.

@cdavis5e
Copy link
Collaborator

cdavis5e commented Oct 5, 2024

This is a Metal compiler bug--more specifically, a bug in the AGX backend. I can't see anything wrong with the generated code.

This needs to be reported upstream to Apple. In the meantime, if you want a workaround in SPIRV-Cross, this issue should probably be filed there.

@cdavis5e cdavis5e added Question SPIRV-Cross Please re-submit to SPRIV-Cross Answered A question was answered Metal improvement required An improvement to Metal is required to resolve this issue. labels Oct 5, 2024
@squidbus
Copy link
Contributor Author

squidbus commented Oct 5, 2024

Okay, I've reported this to SPIRV-Cross as well here: KhronosGroup/SPIRV-Cross#2385

I will try to report to Apple but I'm not sure how much traction feedback reports get.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Answered A question was answered Metal improvement required An improvement to Metal is required to resolve this issue. Question SPIRV-Cross Please re-submit to SPRIV-Cross
Projects
None yet
Development

No branches or pull requests

2 participants