Skip to content

MSL: Workaround Metal 3.1 regression bug on recursive input structs.#2217

Merged
HansKristian-Work merged 1 commit intoKhronosGroup:mainfrom
billhollings:metal-3-1-regression-fix
Oct 16, 2023
Merged

MSL: Workaround Metal 3.1 regression bug on recursive input structs.#2217
HansKristian-Work merged 1 commit intoKhronosGroup:mainfrom
billhollings:metal-3-1-regression-fix

Conversation

@billhollings
Copy link
Copy Markdown
Contributor

Metal 3.1 introduced a Metal regression bug which causes an infinite recursion crash during Metal's analysis of an entry point input structure that itself contains internal recursion. This patch works around this by replacing the recursive input declaration with a alternate variable of type void*, and then casting to the correct type at the top of the entry point function.

  • Add CompilerMSL::Options::replace_recursive_inputs to enable replacing recursive input.
  • Add Compiler::type_contains_recursion() to determine if a struct contains internal recursion, and add custom Decorations to mark such structs, to short-cut future similar checks.
  • Replace recursive input struct declarations with void*, and emit a recast to correct type at top of entry function.
  • Add unit test.
  • Compiler::type_is_top_level_block() remove hardcode reference to spirv_cross namespace, as it interferes with configurable namespaces (unrelated).

@HansKristian-Work This Metal regression surfaced quite recently, as macOS Sonoma was rolled out. This is a fairly simple patch fix that, if at all possible, it would be great to get this pulled in by Mon Oct 16, so it can be included in the upcoming Vulkan SDK release.

Copy link
Copy Markdown
Contributor

@cdavis5e cdavis5e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I have one small comment, though. And I'd probably wait for H-K to give his OK before merging.

Comment thread main.cpp Outdated
@HansKristian-Work
Copy link
Copy Markdown
Contributor

Deadline for the next SDK has already passed, btw.

Comment thread main.cpp Outdated
Comment thread spirv_cross.cpp Outdated
Comment thread spirv_cross.cpp Outdated
Comment thread spirv_cross.cpp Outdated
Comment thread spirv_cross.hpp Outdated
Comment thread spirv_msl.hpp
Comment thread spirv_cross.cpp
@HansKristian-Work
Copy link
Copy Markdown
Contributor

If MoltenVK has a different SDK deadline from SPIRV-Cross and it can reference a different SPIRV-Cross commit locally, it would make sense to just push up a frozen branch that MVK can reference in the short-term. SPIRV-Cross upstream shouldn't need to block what ships in MVK SDKs.

@KarenGhavam-lunarG
Copy link
Copy Markdown

If I can get a new spirv cross commit on Monday morning we can use that for the sdk

Metal 3.1 introduced a Metal regression bug which causes an infinite recursion
crash during Metal's analysis of an entry point input structure that itself
contains internal recursion. This patch works around this by replacing the
recursive input declaration with a alternate variable of type void*, and
then casting to the correct type at the top of the entry point function.

- Add CompilerMSL::Options::replace_recursive_inputs to enable
  replacing recursive input.
- Add Compiler::type_contains_recursion() to determine if a struct
  contains internal recursion, and add custom Decorations to mark
  such structs, to short-cut future similar checks.
- Replace recursive input struct declarations with void*,
  and emit a recast to correct type at top of entry function.
- Add unit test.
- Compiler::type_is_top_level_block() remove hardcode reference to spirv_cross
  namespace, as it interferes with configurable namespaces (unrelated).
@billhollings
Copy link
Copy Markdown
Contributor Author

billhollings commented Oct 14, 2023

If MoltenVK has a different SDK deadline from SPIRV-Cross and it can reference a different SPIRV-Cross commit locally, it would make sense to just push up a frozen branch that MVK can reference in the short-term. SPIRV-Cross upstream shouldn't need to block what ships in MVK SDKs.

All good points.

I was unaware that SPIRV-Cross had an SDK delivery date at all. MoltenVK typically uses the SPIRV-Cross main HEAD at time of MoltenVK SDK release, and this has worked so far.

I guess having a MoltenVK branch on SPIRV-Cross would give us options when something like this comes up, without rushing the main branch. However, this situation has proven extremely rare so far, and maintaining a separate MoltenVK branch feels like it could potentially become a maintenance nightmare for all of us down the road, if it deviates far from the main branch, by accumulating updates that don't quickly make it into the main branch.

If we can fit this into main by Monday this time, that would be best. If not, I can create that SPIRV-Cross branch as an emergency temporary measure for this release, but I'd want to merge it back into the main branch soon.

Either way, we can have further discussions about whether a dual-branch is needed, and how it can be made effective.

And, regardless of future activity, I do appreciate that this situation has proven awkward this time, and I appreciate the rapid review and discussion.

@HansKristian-Work HansKristian-Work merged commit 2d072c6 into KhronosGroup:main Oct 16, 2023
@billhollings billhollings deleted the metal-3-1-regression-fix branch November 2, 2023 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants