From af70651a4843b16dd24e14b5cedffe399ebeb862 Mon Sep 17 00:00:00 2001 From: Yong He Date: Sat, 20 Aug 2022 01:03:06 -0700 Subject: Call `gfx` in slang program. (#2370) --- source/slang/slang-emit-c-like.cpp | 44 +++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) (limited to 'source/slang/slang-emit-c-like.cpp') diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp index 226e29764..e98c8c6f3 100644 --- a/source/slang/slang-emit-c-like.cpp +++ b/source/slang/slang-emit-c-like.cpp @@ -3378,16 +3378,25 @@ void CLikeSourceEmitter::ensureInstOperandsRec(ComputeEmitActionsContext* ctx, I auto requiredLevel = EmitAction::Definition; switch (inst->getOp()) { - case kIROp_InterfaceType: - requiredLevel = EmitAction::ForwardDeclaration; - break; - case kIROp_COMWitnessDecoration: + case kIROp_NativePtrType: requiredLevel = EmitAction::ForwardDeclaration; break; default: break; } + if (auto comWitnessDecoration = as(inst)) + { + // A COMWitnessDecoration marks the interface inheritance of a class. + // We need to make sure the implemented interface is emited before the class. + // The witness table itself doesn't matter. + if (auto witnessTable = as(comWitnessDecoration->getWitnessTable())) + { + ensureInstOperand(ctx, witnessTable->getConformanceType(), requiredLevel); + } + requiredLevel = EmitAction::ForwardDeclaration; + } + for(UInt ii = 0; ii < operandCount; ++ii) { // TODO: there are some special cases we can add here, @@ -3415,13 +3424,26 @@ void CLikeSourceEmitter::ensureGlobalInst(ComputeEmitActionsContext* ctx, IRInst { case kIROp_Generic: return; - + case kIROp_ThisType: + return; default: break; } if (as(inst)) return; + // Certain inst ops will always emit as definition. + switch (inst->getOp()) + { + case kIROp_NativePtrType: + // Pointer type will have their value type emited as forward declaration, + // but the pointer type itself should be considered emitted as definition. + requiredLevel = EmitAction::Level::Definition; + break; + default: + break; + } + // Have we already processed this instruction? EmitAction::Level existingLevel; if(ctx->mapInstToLevel.TryGetValue(inst, existingLevel)) @@ -3457,7 +3479,9 @@ void CLikeSourceEmitter::ensureGlobalInst(ComputeEmitActionsContext* ctx, IRInst switch (inst->getOp()) { case kIROp_InterfaceRequirementEntry: + { return; + } default: break; @@ -3496,6 +3520,16 @@ void CLikeSourceEmitter::emitForwardDeclaration(IRInst* inst) m_writer->emit(getName(inst)); m_writer->emit(";\n"); break; + case kIROp_InterfaceType: + { + if (inst->findDecoration()) + { + m_writer->emit("struct "); + m_writer->emit(getName(inst)); + m_writer->emit(";\n"); + } + break; + } default: SLANG_UNREACHABLE("emit forward declaration"); } -- cgit v1.2.3