diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2023-09-28 02:46:03 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-27 11:46:03 -0700 |
| commit | 8326248542c2196b4a4ba80f068adb8a0edd6006 (patch) | |
| tree | b8fc963b827547c1d13cd2aee4510abf16eaf702 /source/slang/slang-emit-spirv.cpp | |
| parent | 771b3ef47d48f5277ac9f23ee8a49548a430d107 (diff) | |
WIP Mesh shaders for SPIR-V (#3226)
* SPIR-V impl for SetMeshOutputCounts and DispatchMesh
* Unsightly fix for legalization ordering differences between GLSL and SPIR-V
* spelling
* Start a new block after terminating one in the OpEmitMeshTasksExt SPIR-V asm block
* Emit mesh shader decorations in SPIR-V
* Mesh and task shader stages for spir-v
* Output explicit gl builtins for spir-v
* Be more hygenic when SOAizing mesh outputs
* Do not create builtin paramter block for spirv mesh outputs
* Pass mesh payloads around by ref
* comment
* less expected failure
* remove unused
* Add spirv op
* Correct type query for default flat modifier
---------
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/slang/slang-emit-spirv.cpp')
| -rw-r--r-- | source/slang/slang-emit-spirv.cpp | 62 |
1 files changed, 59 insertions, 3 deletions
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index 14fe2e17b..6a223ae4f 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -1769,7 +1769,6 @@ struct SPIRVEmitContext { bool needDefaultSetBindingDecoration = false; bool hasExplicitSetBinding = false; - bool isInput = false; for (auto rr : layout->getOffsetAttrs()) { UInt index = rr->getOffset(); @@ -1786,7 +1785,6 @@ struct SPIRVEmitContext varInst, SpvLiteralInteger::from32(int32_t(index)) ); - isInput = true; break; case LayoutResourceKind::VaryingOutput: emitOpDecorateLocation( @@ -1872,7 +1870,8 @@ struct SPIRVEmitContext && layout->getStage() == Stage::Fragment && layout->usesResourceKind(LayoutResourceKind::VaryingInput)) { - if (isIntegralScalarOrCompositeType(var->getDataType())) + const auto ptrType = as<IRPtrTypeBase>(var->getDataType()); + if (ptrType && isIntegralScalarOrCompositeType(ptrType->getValueType())) emitOpDecorate(getSection(SpvLogicalSectionID::Annotations), nullptr, varInst, SpvDecorationFlat); } } @@ -2683,6 +2682,44 @@ struct SPIRVEmitContext ); } break; + + case kIROp_OutputTopologyDecoration: + { + const auto o = cast<IROutputTopologyDecoration>(decoration); + const auto t = o->getTopology()->getStringSlice(); + const auto m = + t == "triangle" ? SpvExecutionModeOutputTrianglesEXT + : t == "line" ? SpvExecutionModeOutputLinesEXT + : t == "point" ? SpvExecutionModeOutputPoints + : SpvExecutionModeMax; + SLANG_ASSERT(m != SpvExecutionModeMax); + emitOpExecutionMode(getSection(SpvLogicalSectionID::ExecutionModes), decoration, dstID, m); + } + break; + + case kIROp_VerticesDecoration: + { + const auto c = cast<IRVerticesDecoration>(decoration); + emitOpExecutionModeOutputVertices( + getSection(SpvLogicalSectionID::ExecutionModes), + decoration, + dstID, + SpvLiteralInteger::from32(int32_t(c->getMaxSize()->getValue())) + ); + } + break; + + case kIROp_PrimitivesDecoration: + { + const auto c = cast<IRPrimitivesDecoration>(decoration); + emitOpExecutionModeOutputPrimitivesEXT( + getSection(SpvLogicalSectionID::ExecutionModes), + decoration, + dstID, + SpvLiteralInteger::from32(int32_t(c->getMaxSize()->getValue())) + ); + } + break; // ... } } @@ -2822,6 +2859,8 @@ struct SPIRVEmitContext CASE(Geometry, Geometry); CASE(Fragment, Fragment); CASE(Compute, GLCompute); + CASE(Mesh, MeshEXT); + CASE(Amplification, TaskEXT); // TODO: Extended execution models for ray tracing, etc. @@ -3038,6 +3077,23 @@ struct SPIRVEmitContext SLANG_UNREACHABLE("Unimplemented system value in spirv emit."); } } + + // + // These are system-value variables which require redeclaration in + // GLSL, SPIR-V makes no such distinction so we can use similar logic + // to above. + // + if(const auto linkageDecoration = inst->findDecoration<IRLinkageDecoration>()) + { + const auto name = linkageDecoration->getMangledName(); + if(name == "gl_PrimitiveTriangleIndicesEXT") + return getBuiltinGlobalVar(inst->getFullType(), SpvBuiltInPrimitiveTriangleIndicesEXT); + if(name == "gl_PrimitiveLineIndicesEXT") + return getBuiltinGlobalVar(inst->getFullType(), SpvBuiltInPrimitiveLineIndicesEXT); + if(name == "gl_PrimitivePointIndicesEXT") + return getBuiltinGlobalVar(inst->getFullType(), SpvBuiltInPrimitivePointIndicesEXT); + } + return nullptr; } |
