summaryrefslogtreecommitdiffstats
path: root/source/slang
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang')
-rw-r--r--source/slang/slang-emit-c-like.cpp11
-rw-r--r--source/slang/slang-emit-cpp.cpp65
-rw-r--r--source/slang/slang-emit-cpp.h3
-rw-r--r--source/slang/slang-emit-cuda.cpp10
-rw-r--r--source/slang/slang-emit-cuda.h2
-rw-r--r--source/slang/slang-emit.cpp2
6 files changed, 49 insertions, 44 deletions
diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp
index 8ef18242a..f234b0be6 100644
--- a/source/slang/slang-emit-c-like.cpp
+++ b/source/slang/slang-emit-c-like.cpp
@@ -3837,7 +3837,6 @@ void CLikeSourceEmitter::ensureGlobalInst(ComputeEmitActionsContext* ctx, IRInst
// Skip certain instructions that don't affect output.
switch(inst->op)
{
- case kIROp_InterfaceRequirementEntry:
case kIROp_Generic:
return;
@@ -3877,6 +3876,16 @@ void CLikeSourceEmitter::ensureGlobalInst(ComputeEmitActionsContext* ctx, IRInst
}
ctx->mapInstToLevel[inst] = requiredLevel;
+
+ // Skip instructions that don't correspond to an independent entity in output.
+ switch (inst->op)
+ {
+ case kIROp_InterfaceRequirementEntry:
+ return;
+
+ default:
+ break;
+ }
ctx->actions->add(action);
}
diff --git a/source/slang/slang-emit-cpp.cpp b/source/slang/slang-emit-cpp.cpp
index 3c6a25135..88afead1a 100644
--- a/source/slang/slang-emit-cpp.cpp
+++ b/source/slang/slang-emit-cpp.cpp
@@ -1604,6 +1604,11 @@ void CPPSourceEmitter::emitParamTypeImpl(IRType* type, String const& name)
emitType(type, name);
}
+void CPPSourceEmitter::emitGlobalRTTISymbolPrefix()
+{
+ m_writer->emit("SLANG_PRELUDE_SHARED_LIB_EXPORT");
+}
+
void CPPSourceEmitter::emitWitnessTable(IRWitnessTable* witnessTable)
{
auto interfaceType = cast<IRInterfaceType>(witnessTable->getConformanceType());
@@ -1613,10 +1618,11 @@ void CPPSourceEmitter::emitWitnessTable(IRWitnessTable* witnessTable)
return;
auto witnessTableItems = witnessTable->getChildren();
- _maybeEmitWitnessTableTypeDefinition(interfaceType);
// Declare a global variable for the witness table.
- m_writer->emit("extern \"C\" { SLANG_PRELUDE_SHARED_LIB_EXPORT extern ");
+ m_writer->emit("extern \"C\" { ");
+ emitGlobalRTTISymbolPrefix();
+ m_writer->emit(" extern ");
emitSimpleType(interfaceType);
m_writer->emit(" ");
m_writer->emit(getName(witnessTable));
@@ -1638,7 +1644,8 @@ void CPPSourceEmitter::_emitWitnessTableDefinitions()
List<IRWitnessTableEntry*> sortedWitnessTableEntries = getSortedWitnessTableEntries(witnessTable);
m_writer->emit("extern \"C\"\n{\n");
m_writer->indent();
- m_writer->emit("SLANG_PRELUDE_SHARED_LIB_EXPORT\n");
+ emitGlobalRTTISymbolPrefix();
+ m_writer->emit("\n");
emitSimpleType(interfaceType);
m_writer->emit(" ");
m_writer->emit(getName(witnessTable));
@@ -1689,44 +1696,9 @@ void CPPSourceEmitter::_emitWitnessTableDefinitions()
void CPPSourceEmitter::emitInterface(IRInterfaceType* interfaceType)
{
- // The current IRInterfaceType defintion does not contain
- // sufficient info for emitting a witness table struct by itself
- // Instead, it defines the order of entries in a witness table.
- // Therefore, we emit a forward declaration here, and actual definition
- // for the witness table type during emitWitnessTable.
- SLANG_UNUSED(interfaceType);
- m_writer->emit("struct ");
- emitSimpleType(interfaceType);
- m_writer->emit(";\n");
-}
-
-void CPPSourceEmitter::emitRTTIObject(IRRTTIObject* rttiObject)
-{
- // Declare the type info object as `extern "C"` first.
- m_writer->emit("extern \"C\"{ SLANG_PRELUDE_SHARED_LIB_EXPORT extern TypeInfo ");
- m_writer->emit(getName(rttiObject));
- m_writer->emit("; }\n");
-
- // Now actually define the object.
- m_writer->emit("extern \"C\" { SLANG_PRELUDE_SHARED_LIB_EXPORT TypeInfo ");
- m_writer->emit(getName(rttiObject));
- m_writer->emit(" = {");
- auto typeSizeDecoration = rttiObject->findDecoration<IRRTTITypeSizeDecoration>();
- SLANG_ASSERT(typeSizeDecoration);
- m_writer->emit(typeSizeDecoration->getTypeSize());
- m_writer->emit("}; }\n");
-}
-
-
- /// Emits witness table type definition given a sorted list of witness tables
- /// acoording to the order defined by `interfaceType`.
- ///
-void CPPSourceEmitter::_maybeEmitWitnessTableTypeDefinition(
- IRInterfaceType* interfaceType)
-{
- if (m_interfaceTypesEmitted.Contains(interfaceType))
+ // Skip built-in interfaces.
+ if (isBuiltin(interfaceType))
return;
- m_interfaceTypesEmitted.Add(interfaceType);
m_writer->emit("struct ");
emitSimpleType(interfaceType);
@@ -1777,6 +1749,19 @@ void CPPSourceEmitter::_maybeEmitWitnessTableTypeDefinition(
m_writer->emit("};\n");
}
+void CPPSourceEmitter::emitRTTIObject(IRRTTIObject* rttiObject)
+{
+ m_writer->emit("extern \"C\" { ");
+ emitGlobalRTTISymbolPrefix();
+ m_writer->emit(" TypeInfo ");
+ m_writer->emit(getName(rttiObject));
+ m_writer->emit(" = {");
+ auto typeSizeDecoration = rttiObject->findDecoration<IRRTTITypeSizeDecoration>();
+ SLANG_ASSERT(typeSizeDecoration);
+ m_writer->emit(typeSizeDecoration->getTypeSize());
+ m_writer->emit("}; }\n");
+}
+
bool CPPSourceEmitter::tryEmitGlobalParamImpl(IRGlobalParam* varDecl, IRType* varType)
{
SLANG_UNUSED(varDecl);
diff --git a/source/slang/slang-emit-cpp.h b/source/slang/slang-emit-cpp.h
index 3b7acd953..b1ca7475f 100644
--- a/source/slang/slang-emit-cpp.h
+++ b/source/slang/slang-emit-cpp.h
@@ -65,6 +65,7 @@ protected:
virtual void emitSimpleFuncImpl(IRFunc* func) SLANG_OVERRIDE;
virtual void emitOperandImpl(IRInst* inst, EmitOpInfo const& outerPrec) SLANG_OVERRIDE;
virtual void emitParamTypeImpl(IRType* type, String const& name) SLANG_OVERRIDE;
+ virtual void emitGlobalRTTISymbolPrefix();
virtual void emitWitnessTable(IRWitnessTable* witnessTable) SLANG_OVERRIDE;
virtual void emitInterface(IRInterfaceType* interfaceType) SLANG_OVERRIDE;
virtual void emitRTTIObject(IRRTTIObject* rttiObject) SLANG_OVERRIDE;
@@ -78,8 +79,6 @@ protected:
virtual SlangResult calcFuncName(const HLSLIntrinsic* specOp, StringBuilder& out);
virtual SlangResult calcScalarFuncName(HLSLIntrinsic::Op op, IRBasicType* type, StringBuilder& outBuilder);
- // Emits a struct of function pointers defined in `interfaceType`.
- void _maybeEmitWitnessTableTypeDefinition(IRInterfaceType* interfaceType);
void _maybeEmitSpecializedOperationDefinition(const HLSLIntrinsic* specOp);
void _emitForwardDeclarations(const List<EmitAction>& actions);
diff --git a/source/slang/slang-emit-cuda.cpp b/source/slang/slang-emit-cuda.cpp
index acd913865..ecc3eb68b 100644
--- a/source/slang/slang-emit-cuda.cpp
+++ b/source/slang/slang-emit-cuda.cpp
@@ -300,7 +300,7 @@ String CUDASourceEmitter::generateEntryPointNameImpl(IREntryPointDecoration* ent
// > The input PTX should include one or more NVIDIA OptiX programs.
// > The type of program affects how the program can be used during
// > the execution of the pipeline. These program types are specified
- // by prefixing the program’s name with the following:
+ // by prefixing the program name with the following:
//
// > Program type Function name prefix
CASE( RayGeneration, __raygen__);
@@ -322,6 +322,11 @@ String CUDASourceEmitter::generateEntryPointNameImpl(IREntryPointDecoration* ent
return globalSymbolName;
}
+void CUDASourceEmitter::emitGlobalRTTISymbolPrefix()
+{
+ m_writer->emit("__device__");
+}
+
void CUDASourceEmitter::emitCall(const HLSLIntrinsic* specOp, IRInst* inst, const IRUse* operands, int numOperands, const EmitOpInfo& inOuterPrec)
{
switch (specOp->op)
@@ -740,6 +745,9 @@ void CUDASourceEmitter::emitModuleImpl(IRModule* module)
// TODO(JS): We may need to generate types (for example for matrices)
CLikeSourceEmitter::emitModuleImpl(module);
+
+ // Emit all witness table definitions.
+ _emitWitnessTableDefinitions();
}
diff --git a/source/slang/slang-emit-cuda.h b/source/slang/slang-emit-cuda.h
index 156d5fab1..18c6e86a2 100644
--- a/source/slang/slang-emit-cuda.h
+++ b/source/slang/slang-emit-cuda.h
@@ -59,6 +59,8 @@ protected:
virtual void emitFunctionPreambleImpl(IRInst* inst) SLANG_OVERRIDE;
virtual String generateEntryPointNameImpl(IREntryPointDecoration* entryPointDecor) SLANG_OVERRIDE;
+ virtual void emitGlobalRTTISymbolPrefix() SLANG_OVERRIDE;
+
virtual void emitLoopControlDecorationImpl(IRLoopControlDecoration* decl) SLANG_OVERRIDE;
virtual void handleCallExprDecorationsImpl(IRInst* funcValue) SLANG_OVERRIDE;
diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp
index 09e5c9b2d..4b7b13e4f 100644
--- a/source/slang/slang-emit.cpp
+++ b/source/slang/slang-emit.cpp
@@ -310,6 +310,7 @@ Result linkAndOptimizeIR(
switch (target)
{
case CodeGenTarget::CPPSource:
+ case CodeGenTarget::CUDASource:
// For targets that supports dynamic dispatch, we need to lower the
// generics / interface types to ordinary functions and types using
// function pointers.
@@ -666,6 +667,7 @@ Result linkAndOptimizeIR(
switch (target)
{
case CodeGenTarget::CPPSource:
+ case CodeGenTarget::CUDASource:
break;
default:
// For all targets that don't support true dynamic dispatch through