summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-06-18 11:38:30 -0400
committerGitHub <noreply@github.com>2020-06-18 11:38:30 -0400
commit5a86cd4880f8f086631352cb5d67d60c58c087f4 (patch)
tree2f65acc5158f4c6632f299de6f4600f20b93c35a /source
parent31ae3467242995ab822a29c4148c2e86df2f1eb8 (diff)
Improvements around C++ code generation (#1396)
* * Remove UniformState and UniformEntryPointParams types * Put all output C++ source in an anonymous namespace * If SLANG_PRELUDE_NAMESPACE is set, make what it defines available in generated file. * Fix signature issue in performance-profile.slang * Context -> KernelContext to avoid ambiguity. * Fix issues around dynamic dispatch and anonymous namespace. * Fix typo.
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-emit-cpp.cpp43
-rw-r--r--source/slang/slang-emit-cuda.cpp4
2 files changed, 33 insertions, 14 deletions
diff --git a/source/slang/slang-emit-cpp.cpp b/source/slang/slang-emit-cpp.cpp
index c31ef3bc7..53a110632 100644
--- a/source/slang/slang-emit-cpp.cpp
+++ b/source/slang/slang-emit-cpp.cpp
@@ -1612,7 +1612,7 @@ void CPPSourceEmitter::_emitWitnessTableDefinitions()
m_writer->emit(",\n");
else
isFirstEntry = false;
- m_writer->emit("&Context::");
+ m_writer->emit("&KernelContext::");
m_writer->emit(getName(funcVal));
}
else
@@ -1660,7 +1660,7 @@ void CPPSourceEmitter::_maybeEmitWitnessTableTypeDefinition(
else
isFirstEntry = false;
emitType(funcVal->getResultType());
- m_writer->emit(" (Context::*");
+ m_writer->emit(" (KernelContext::*");
m_writer->emit(getName(entry->requirementKey.get()));
m_writer->emit(")");
m_writer->emit("(");
@@ -2134,6 +2134,20 @@ void CPPSourceEmitter::emitPreprocessorDirectivesImpl()
writer->emit("\n");
+
+ if (m_target == CodeGenTarget::CPPSource)
+ {
+ // Put all into an anonymous namespace
+ // This includes any generated types, and generated intrinsics
+
+ m_writer->emit("namespace { // anonymous \n\n");
+ m_writer->emit("#ifdef SLANG_PRELUDE_NAMESPACE\n");
+ m_writer->emit("using namespace SLANG_PRELUDE_NAMESPACE;\n");
+ m_writer->emit("#endif\n\n");
+
+ m_writer->emit("struct KernelContext;\n\n");
+ }
+
if (m_target == CodeGenTarget::CSource)
{
// For C output we need to emit type definitions.
@@ -2169,7 +2183,6 @@ void CPPSourceEmitter::emitPreprocessorDirectivesImpl()
{
_maybeEmitSpecializedOperationDefinition(intrinsic);
}
-
}
}
@@ -2293,14 +2306,14 @@ void CPPSourceEmitter::_emitEntryPointDefinitionStart(IRFunc* func, IRGlobalPara
m_writer->emit("(");
m_writer->emit(varyingTypeName);
- m_writer->emit("* varyingInput, UniformEntryPointParams* params, UniformState* uniformState)");
+ m_writer->emit("* varyingInput, void* params, void* uniformState)");
emitSemantics(func);
m_writer->emit("\n{\n");
m_writer->indent();
// Initialize when constructing so that globals are zeroed
- m_writer->emit("Context context = {};\n");
- m_writer->emit("context.uniformState = uniformState;\n");
+ m_writer->emit("KernelContext context = {};\n");
+ m_writer->emit("context.uniformState = (UniformState*)uniformState;\n");
if (entryPointGlobalParams)
{
@@ -2590,11 +2603,11 @@ void CPPSourceEmitter::emitModuleImpl(IRModule* module)
List<EmitAction> actions;
computeEmitActions(module, actions);
-
+
_emitForwardDeclarations(actions);
IRGlobalParam* entryPointGlobalParams = nullptr;
-
+
// Output the global parameters in a 'UniformState' structure
{
m_writer->emit("struct UniformState\n{\n");
@@ -2605,15 +2618,14 @@ void CPPSourceEmitter::emitModuleImpl(IRModule* module)
m_writer->dedent();
m_writer->emit("\n};\n\n");
}
-
+
// Output the 'Context' which will be used for execution
{
- m_writer->emit("struct Context\n{\n");
+ m_writer->emit("struct KernelContext\n{\n");
m_writer->indent();
m_writer->emit("UniformState* uniformState;\n");
-
m_writer->emit("uint3 dispatchThreadID;\n");
//if (m_semanticUsedFlags & SemanticUsedFlag::GroupID)
@@ -2659,12 +2671,19 @@ void CPPSourceEmitter::emitModuleImpl(IRModule* module)
}
m_writer->dedent();
- m_writer->emit("};\n\n");
+ m_writer->emit("};\n\n");
}
// Emit all witness table definitions.
_emitWitnessTableDefinitions();
+ if (m_target == CodeGenTarget::CPPSource)
+ {
+ // Need to close the anonymous namespace when outputting for C++
+
+ m_writer->emit("} // anonymous\n\n");
+ }
+
// Finally we need to output dll entry points
for (auto action : actions)
diff --git a/source/slang/slang-emit-cuda.cpp b/source/slang/slang-emit-cuda.cpp
index 25b06027d..06bbbea96 100644
--- a/source/slang/slang-emit-cuda.cpp
+++ b/source/slang/slang-emit-cuda.cpp
@@ -866,10 +866,10 @@ void CUDASourceEmitter::emitModuleImpl(IRModule* module)
//
// At the binary level, our generated CUDA compute kernels will take
// two pointer parameters: the first points to the per-entry-point
- // `uniform` parameter data, and the second poinst to the global-scope
+ // `uniform` parameter data, and the second points to the global-scope
// parameter data (if any).
//
- m_writer->emit("(UniformEntryPointParams* entryPointShaderParameters, UniformState* uniformState)");
+ m_writer->emit("(void* entryPointShaderParameters, void* uniformState)");
}
else
{