From 8326248542c2196b4a4ba80f068adb8a0edd6006 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Thu, 28 Sep 2023 02:46:03 +0800 Subject: 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 --- source/slang/slang-emit-spirv.cpp | 62 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 3 deletions(-) (limited to 'source/slang/slang-emit-spirv.cpp') 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(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(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(decoration); + emitOpExecutionModeOutputVertices( + getSection(SpvLogicalSectionID::ExecutionModes), + decoration, + dstID, + SpvLiteralInteger::from32(int32_t(c->getMaxSize()->getValue())) + ); + } + break; + + case kIROp_PrimitivesDecoration: + { + const auto c = cast(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()) + { + 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; } -- cgit v1.2.3