summaryrefslogtreecommitdiff
path: root/source/slang/slang-emit-hlsl.cpp
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2022-11-16 09:49:06 +0800
committerGitHub <noreply@github.com>2022-11-16 09:49:06 +0800
commit1643471da0d6239177d11b0301c26d1adf95c0fb (patch)
tree9b8fddf92a5f817541e055a2657f9b0a00f90069 /source/slang/slang-emit-hlsl.cpp
parent4917d71100aafcc38a81cd99d2a44a4cb3a89a0c (diff)
Mesh shader support (#2464)
* Add gdb generated files to .gitignore * Switch to c++17 TODO: Ellie update coding style doc * WIP mesh shaders * Add MeshOutputType and mesh output decorations * Lift array type layout creation out of _createTypeLayout in preparation for sharing it elsewhere * Initial pass at GLSL legalization for mesh shaders * Create output types for builtin mesh outputs This should be rendered as an out paramter block * Handle writes to member fields in mesh shader output * Per primitive output from mesh shaders * Add mesh shader tests * Redeclare mesh output builtins * Remove unused instruction * Emit explicit mesh output max max size * Add unimplemented warning for array members in mesh output * Implement mesh output splitting for GLSL in terms of getSubscriptVal * Allow HLSL syntax for mesh output modifiers * Improve error messages for mesh output * Add test for HLSL style mesh output syntax * Emit explicit mesh output indices max size * HLSL generation support for mesh shaders * Better errors for mesh shader misuse * Neaten comments * Regenerate vs2019 project files * Fix build on vs2019 * Retreat on c++17 Will make the change in a separate PR * slang-glslang binary dep 11.10.0 -> 11.12.0-32 * Fixes for msvc compiler * Update msvc project
Diffstat (limited to 'source/slang/slang-emit-hlsl.cpp')
-rw-r--r--source/slang/slang-emit-hlsl.cpp38
1 files changed, 35 insertions, 3 deletions
diff --git a/source/slang/slang-emit-hlsl.cpp b/source/slang/slang-emit-hlsl.cpp
index 187115232..8891f06a6 100644
--- a/source/slang/slang-emit-hlsl.cpp
+++ b/source/slang/slang-emit-hlsl.cpp
@@ -313,9 +313,7 @@ void HLSLSourceEmitter::emitEntryPointAttributesImpl(IRFunc* irFunc, IREntryPoin
}
}
- switch (stage)
- {
- case Stage::Compute:
+ auto emitNumThreadsAttribute = [&]()
{
Int sizeAlongAxis[kThreadGroupAxisCount];
getComputeThreadGroupSize(irFunc, sizeAlongAxis);
@@ -327,6 +325,13 @@ void HLSLSourceEmitter::emitEntryPointAttributesImpl(IRFunc* irFunc, IREntryPoin
m_writer->emit(sizeAlongAxis[ii]);
}
m_writer->emit(")]\n");
+ };
+
+ switch (stage)
+ {
+ case Stage::Compute:
+ {
+ emitNumThreadsAttribute();
}
break;
case Stage::Geometry:
@@ -406,6 +411,18 @@ void HLSLSourceEmitter::emitEntryPointAttributesImpl(IRFunc* irFunc, IREntryPoin
}
break;
}
+ case Stage::Mesh:
+ {
+ emitNumThreadsAttribute();
+ if (auto decor = irFunc->findDecoration<IROutputTopologyDecoration>())
+ {
+ // TODO: Ellie validate here/elsewhere, what's allowed here is
+ // different from the tesselator
+ // The naming here is plural, so add an 's'
+ _emitHLSLDecorationSingleString("outputtopology", irFunc, decor->getTopology());
+ }
+ break;
+ }
// TODO: There are other stages that will need this kind of handling.
default:
break;
@@ -1052,6 +1069,7 @@ void HLSLSourceEmitter::_emitPrefixTypeAttr(IRAttr* attr)
void HLSLSourceEmitter::emitSimpleFuncParamImpl(IRParam* param)
{
emitRateQualifiers(param);
+ emitMeshOutputModifiers(param);
if (auto decor = param->findDecoration<IRGeometryInputPrimitiveTypeDecoration>())
{
@@ -1104,6 +1122,20 @@ void HLSLSourceEmitter::emitInterpolationModifiersImpl(IRInst* varInst, IRType*
}
}
+void HLSLSourceEmitter::emitMeshOutputModifiersImpl(IRInst* varInst)
+{
+ if(auto modifier = varInst->findDecoration<IRMeshOutputDecoration>())
+ {
+ const char* s =
+ as<IRVerticesDecoration>(modifier) ? "vertices "
+ : as<IRIndicesDecoration>(modifier) ? "indices "
+ : as<IRPrimitivesDecoration>(modifier) ? "primitives "
+ : nullptr;
+ SLANG_EXPECT(s, "Unhandled type of mesh output decoration");
+ m_writer->emit(s);
+ }
+}
+
void HLSLSourceEmitter::emitVarDecorationsImpl(IRInst* varDecl)
{
if (varDecl->findDecoration<IRGloballyCoherentDecoration>())