Skip to content

Support dual-source blend outputs in Metal #8007

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 37 additions & 5 deletions source/slang/slang-ir-legalize-varying-params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3283,11 +3283,43 @@ class LegalizeMetalEntryPointContext : public LegalizeShaderEntryPointContext
}
case SystemValueSemanticName::Target:
{
result.systemValueName =
(StringBuilder()
<< "color(" << (semanticIndex.getLength() != 0 ? semanticIndex : toSlice("0"))
<< ")")
.produceString();
// For dual-source blend support: check for vk::location and vk::index
int location = semanticIndex.getLength() != 0 ? stringToInt(semanticIndex) : 0;
int index = 0;

// Check if this field has layout information with space (index) data
if (parentVar)
{
// First check for glslLocation decoration to get the correct location
if (auto glslLocationDecor = parentVar->findDecoration<IRGLSLLocationDecoration>())
{
location = (int)getIntVal(glslLocationDecor->getLocation());
}

// Look for layout with space information (vk::index)
if (auto varLayout = findVarLayout(parentVar))
{
// Check each offset attribute to find one with space information
for (auto offsetAttr : varLayout->getOffsetAttrs())
{
// Space information represents the vk::index value
if (offsetAttr->getSpace() != 0)
{
index = (int)offsetAttr->getSpace();
break;
}
}
}
}

// Generate Metal color attribute with location and optional index
StringBuilder sb;
sb << "color(" << location << ")";
if (index != 0)
{
sb << ", index(" << index << ")";
}
result.systemValueName = sb.produceString();
result.permittedTypes = permittedTypes_sv_target;

break;
Expand Down
Loading