summaryrefslogtreecommitdiff
path: root/source/slang/slang-emit-metal.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-04-24 16:23:35 -0700
committerGitHub <noreply@github.com>2024-04-24 16:23:35 -0700
commitd3ed08ec3073c3cb9ac24fa3670784dd6e97a164 (patch)
tree8589874c7dd2c1698a5dcbe22d7a2bd74fa29abf /source/slang/slang-emit-metal.cpp
parentfc4c242442510fb97c3cfbf04d7582ebbc3bb0ed (diff)
Parameter layout and reflection for Metal bindings. (#4022)
Diffstat (limited to 'source/slang/slang-emit-metal.cpp')
-rw-r--r--source/slang/slang-emit-metal.cpp74
1 files changed, 27 insertions, 47 deletions
diff --git a/source/slang/slang-emit-metal.cpp b/source/slang/slang-emit-metal.cpp
index 459104ac9..3773b7c2a 100644
--- a/source/slang/slang-emit-metal.cpp
+++ b/source/slang/slang-emit-metal.cpp
@@ -37,44 +37,6 @@ void MetalSourceEmitter::_emitHLSLDecorationSingleInt(const char* name, IRFunc*
m_writer->emit(")]]\n");
}
-void MetalSourceEmitter::_emitHLSLRegisterSemantic(LayoutResourceKind kind, EmitVarChain* chain, IRInst* inst, char const* uniformSemanticSpelling)
-{
- // Metal does not use explicit binding.
- SLANG_UNUSED(kind);
- SLANG_UNUSED(chain);
- SLANG_UNUSED(inst);
- SLANG_UNUSED(uniformSemanticSpelling);
-}
-
-void MetalSourceEmitter::_emitHLSLRegisterSemantics(EmitVarChain* chain, IRInst* inst, char const* uniformSemanticSpelling)
-{
- // TODO: implement.
- SLANG_UNUSED(chain);
- SLANG_UNUSED(inst);
- SLANG_UNUSED(uniformSemanticSpelling);
-}
-
-void MetalSourceEmitter::_emitHLSLRegisterSemantics(IRVarLayout* varLayout, IRInst* inst, char const* uniformSemanticSpelling)
-{
- // TODO: implement.
- SLANG_UNUSED(varLayout);
- SLANG_UNUSED(inst);
- SLANG_UNUSED(uniformSemanticSpelling);
-}
-
-void MetalSourceEmitter::_emitHLSLParameterGroupFieldLayoutSemantics(EmitVarChain* chain)
-{
- // TODO: implement.
- SLANG_UNUSED(chain);
-}
-
-void MetalSourceEmitter::_emitHLSLParameterGroupFieldLayoutSemantics(IRVarLayout* fieldLayout, EmitVarChain* inChain)
-{
- // TODO: implement.
- SLANG_UNUSED(fieldLayout);
- SLANG_UNUSED(inChain);
-}
-
void MetalSourceEmitter::_emitHLSLParameterGroup(IRGlobalParam* varDecl, IRUniformParameterGroupType* type)
{
// Metal does not allow shader parameters declared as global variables, so we shouldn't see this.
@@ -139,17 +101,34 @@ void MetalSourceEmitter::_emitHLSLTextureType(IRTextureTypeBase* texType)
m_writer->emit(">");
}
-void MetalSourceEmitter::_emitHLSLSubpassInputType(IRSubpassInputType* subpassType)
-{
- SLANG_UNUSED(subpassType);
-}
-
-void MetalSourceEmitter::emitLayoutSemanticsImpl(IRInst* inst, char const* uniformSemanticSpelling)
+void MetalSourceEmitter::emitFuncParamLayoutImpl(IRInst* param)
{
- auto layout = getVarLayout(inst);
- if (layout)
+ auto layoutDecoration = param->findDecoration<IRLayoutDecoration>();
+ if (!layoutDecoration)
+ return;
+ auto layout = as<IRVarLayout>(layoutDecoration->getLayout());
+ if (!layout)
+ return;
+ for (auto rr : layout->getOffsetAttrs())
{
- _emitHLSLRegisterSemantics(layout, inst, uniformSemanticSpelling);
+ switch (rr->getResourceKind())
+ {
+ case LayoutResourceKind::MetalTexture:
+ m_writer->emit(" [[texture(");
+ m_writer->emit(rr->getOffset());
+ m_writer->emit(")]]");
+ break;
+ case LayoutResourceKind::MetalBuffer:
+ m_writer->emit(" [[buffer(");
+ m_writer->emit(rr->getOffset());
+ m_writer->emit(")]]");
+ break;
+ case LayoutResourceKind::SamplerState:
+ m_writer->emit(" [[sampler(");
+ m_writer->emit(rr->getOffset());
+ m_writer->emit(")]]");
+ break;
+ }
}
}
@@ -647,6 +626,7 @@ void MetalSourceEmitter::_emitStageAccessSemantic(IRStageAccessDecoration* decor
void MetalSourceEmitter::emitSimpleFuncParamImpl(IRParam* param)
{
Super::emitSimpleFuncParamImpl(param);
+ emitFuncParamLayoutImpl(param);
}
static UnownedStringSlice _getInterpolationModifierText(IRInterpolationMode mode)