Repository navigation
Fixed forward function declarations not getting global resources added. - #163
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…X12 and Metal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… being used to initialize a constant,.
filipppavlov
approved these changes
Nov 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Forward declared function callbacks are used by the CORTAO shaders to allow the user to include the CORTAO headers, then implement the callbacks using the defines and resources from the header.
Metal does not have global resources; instead the resources must be passed in as function parameters (similar to e.g. HLSL vertex attributes). The Metal effect compiler automatically adds these parameters as needed, both to function definitions and to call sites. However, the compiler fails to do this for forward declared functions, causing the CORTAO shaders to fail to compile, as the unmodified forward declared callbacks don't match what the updated call sites expect.
This PR adds an extra step to the compilation after the parameters have been added. This step finds all forward declared functions (NT_FUNCTION_HEADER type nodes) that don't match their eventual function implementation (because the implementation got a new parameter). These forward declarations are updated to match their implementations. In addition, the forward declarations are moved to right after the global variable definitions so that they always occur before any usage.
This PR includes a test that verifies that all APIs correctly handle forward-declared functions both with and without various types of global resources.
Edge case for static initializers
Moving all forward declarations to after the globals would break this. Fortunately, static constant initializers cannot reference any global resources (as there are none available at compile time), so the fix only moves forward declarations that have globals added to them. There is a test covering this and verifying that this works as intended.
Linked issue (optional)
Testing
AI assistance