From e7b6de334f320429462a0257e2191ccf3cbc9a0d Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 24 Jan 2024 15:36:49 -0800 Subject: [SPIRV] Support `globallycoherent` and `[vk::index()]`. (#3488) * [SPIRV] Support `globallycoherent` modifier. * Fix. * Disable executable cooperative vector tests. * Update expected failure. * [SPIRV] Emit varying output index decoration. * Add test. * Update tests. * Fix test. * Emit `SpvExecutionModeEarlyFragmentTests`. * Lower `StructuredBuffer`. * Support globallycoherent on ByteAddressBuffer. --------- Co-authored-by: Yong He --- source/slang/slang-emit-spirv.cpp | 95 ++++++++++++++++++++++++++++----------- 1 file changed, 69 insertions(+), 26 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 a2a0bff58..4e11a7d86 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -1836,6 +1836,14 @@ struct SPIRVEmitContext varInst, SpvLiteralInteger::from32(int32_t(index)) ); + if (space != 0) + { + emitOpDecorateIndex( + getSection(SpvLogicalSectionID::Annotations), + nullptr, + varInst, + SpvLiteralInteger::from32(int32_t(space))); + } break; case LayoutResourceKind::VaryingOutput: emitOpDecorateLocation( @@ -1844,6 +1852,14 @@ struct SPIRVEmitContext varInst, SpvLiteralInteger::from32(int32_t(index)) ); + if (space != 0) + { + emitOpDecorateIndex( + getSection(SpvLogicalSectionID::Annotations), + nullptr, + varInst, + SpvLiteralInteger::from32(int32_t(space))); + } break; case LayoutResourceKind::SpecializationConstant: @@ -1988,6 +2004,7 @@ struct SPIRVEmitContext if(layout) emitVarLayout(globalVar, varInst, layout); maybeEmitName(varInst, globalVar); + emitDecorations(globalVar, getID(varInst)); return varInst; } @@ -2743,10 +2760,6 @@ struct SPIRVEmitContext default: break; } - if (entryPointDecor->getProfile().getStage() == Stage::Fragment) - { - maybeEmitEntryPointDepthReplacingExecutionMode(entryPoint, referencedBuiltinIRVars); - } } // Add remaining builtin variables that does not have a corresponding IR global var/param. // These variables could be added from SPIRV ASM blocks. @@ -2769,7 +2782,19 @@ struct SPIRVEmitContext { case Stage::Fragment: //OpExecutionMode %main OriginUpperLeft - emitInst(getSection(SpvLogicalSectionID::ExecutionModes), nullptr, SpvOpExecutionMode, dstID, SpvExecutionModeOriginUpperLeft); + emitOpExecutionMode(getSection(SpvLogicalSectionID::ExecutionModes), nullptr, dstID, SpvExecutionModeOriginUpperLeft); + maybeEmitEntryPointDepthReplacingExecutionMode(entryPoint, referencedBuiltinIRVars); + for (auto decor : entryPoint->getDecorations()) + { + switch (decor->getOp()) + { + case kIROp_EarlyDepthStencilDecoration: + emitOpExecutionMode(getSection(SpvLogicalSectionID::ExecutionModes), nullptr, dstID, SpvExecutionModeEarlyFragmentTests); + break; + default: + break; + } + } break; case Stage::Geometry: requireSPIRVCapability(SpvCapabilityGeometry); @@ -2787,7 +2812,6 @@ struct SPIRVEmitContext } } break; - // > OpExecutionMode // [3.6. Execution Mode]: LocalSize @@ -2937,6 +2961,12 @@ struct SPIRVEmitContext dstID, SpvLiteralInteger::from32(int32_t(getIntVal(decoration->getOperand(0))))); break; + case kIROp_GloballyCoherentDecoration: + emitOpDecorate(getSection(SpvLogicalSectionID::Annotations), + decoration, + dstID, + SpvDecorationCoherent); + break; // ... } @@ -3007,14 +3037,40 @@ struct SPIRVEmitContext int32_t id = 0; for (auto field : structType->getFields()) { - if (auto fieldNameDecor = field->getKey()->findDecoration()) + for (auto decor : field->getKey()->getDecorations()) { - emitOpMemberName( - getSection(SpvLogicalSectionID::DebugNames), - nullptr, - spvStructID, - id, - fieldNameDecor->getName()); + if (auto fieldNameDecor = as(decor)) + { + emitOpMemberName( + getSection(SpvLogicalSectionID::DebugNames), + nullptr, + spvStructID, + id, + fieldNameDecor->getName()); + } + else if (as(decor)) + { + emitOpMemberDecorate( + getSection(SpvLogicalSectionID::Annotations), + decor, + spvStructID, + SpvLiteralInteger::from32(id), + SpvDecorationCoherent + ); + } + else if (auto semanticDecor = field->getKey()->findDecoration()) + { + if (shouldEmitSPIRVReflectionInfo()) + { + emitOpMemberDecorateString( + getSection(SpvLogicalSectionID::Annotations), + nullptr, + spvStructID, + SpvLiteralInteger::from32(id), + SpvDecorationUserSemantic, + semanticDecor->getSemanticName()); + } + } } IRIntegerValue offset = 0; @@ -3090,19 +3146,6 @@ struct SPIRVEmitContext SpvLiteralInteger::from32(id), SpvLiteralInteger::from32((int32_t)matrixStride)); } - if (shouldEmitSPIRVReflectionInfo()) - { - if (auto semanticDecor = field->getKey()->findDecoration()) - { - emitOpMemberDecorateString( - getSection(SpvLogicalSectionID::Annotations), - nullptr, - spvStructID, - SpvLiteralInteger::from32(id), - SpvDecorationUserSemantic, - semanticDecor->getSemanticName()); - } - } id++; } } -- cgit v1.2.3