-
Notifications
You must be signed in to change notification settings - Fork 172
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
Precompiled SPIR-V import support #5048
base: master
Are you sure you want to change the base?
Conversation
Adds appropriate linkage and function declaration syntax for SPIR-V functions that are declared, to be imported from another SPIR-V module. Unlike DXIL, stripping the Slang IR for a function down to a declaration requires retaining a block of parameters, as the function declaration must be emitted to SPIR-V with the same parameters as a definition. Because that thwarts the logic in Slang to tell the difference between a declaration and definition, and explicit decoration is introduced to explicitly mark functions which need to be treated as declarations during emit phase. Fixes shader-slang#4992
Unify spirv and dxil paths more by using function type instead of parameter ops when emitting spirv function declarations. This allows for SPIR-V function declarations to be emitted from Slang IR function declarations. The previous implementation required that Slang IR function declarations retain blocks with OpParams in them, though that both complicated function declaration emission and created asymmetry between DXIL and SPIR-V paths. To further ensure function parameters are correctly emitted for SPIR-V function declarations, add a second parameter to a test case using a different type, as spirv-val will complain when the parameter list is incorrect.
for (UInt pp = 0; pp < paramCount; ++pp) | ||
{ | ||
auto paramType = funcType->getParamType(pp); | ||
emitOpFunctionParameter(spvFunc, nullptr, paramType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to make sure to emit necessary decorations for pointer-typed parameters as well. Need to call maybeEmitPointerDecoration
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the implementation, it's for PhysicalStorageBuffer pointers and I'm unclear how to write a test case for that. What function parameter would I define in Slang that corresponds to that in spir-v?
I'm currently trying to find a test case that hits this path for function definitions to model after.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nm, I believe I have a test case now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exporting this shows an "Alias" decoration applied from the function definition side.
public int normalFunc(int a, const float *b)
{
return a - floor(*b);
}
Trying to replicate that on the import side function declaration.
Adds appropriate linkage and function declaration syntax for SPIR-V functions that are declared, to be imported from another SPIR-V module.
Unlike DXIL, stripping the Slang IR for a function down to a declaration requires retaining a block of parameters, as the function declaration must be emitted to SPIR-V with the same parameters as a definition. Because that thwarts the logic in Slang to tell the difference between a declaration and definition, and explicit decoration is introduced to explicitly mark functions which need to be treated as declarations during emit phase.
Fixes #4992