diff options
50 files changed, 221 insertions, 115 deletions
diff --git a/.github/workflows/windows-selfhosted.yml b/.github/workflows/windows-selfhosted.yml index 2c82a2fa8..ce2c82010 100644 --- a/.github/workflows/windows-selfhosted.yml +++ b/.github/workflows/windows-selfhosted.yml @@ -37,13 +37,13 @@ jobs: .\make-slang-tag-version.bat MSBuild.exe slang.sln -v:m -m -property:Configuration=${{matrix.configuration}} -property:Platform=${{matrix.platform}} -maxcpucount:12 - - name: test-spirv-direct + - name: test-glsl run: | $ErrorActionPreference = "SilentlyContinue" where.exe spirv-dis spirv-dis --version $env:SLANG_RUN_SPIRV_VALIDATION='1' - .\bin\windows-${{matrix.testPlatform}}\${{matrix.configuration}}\slang-test.exe tests/ -use-test-server -server-count 8 -emit-spirv-directly -expected-failure-list tests/expected-failure.txt -api vk 2>&1 + .\bin\windows-${{matrix.testPlatform}}\${{matrix.configuration}}\slang-test.exe tests/ -use-test-server -server-count 8 -emit-spirv-via-glsl -expected-failure-list tests/expected-failure.txt -api vk 2>&1 - name: test run: | @@ -706,11 +706,7 @@ extern "C" /* When set, will generate SPIRV directly rather than via glslang. */ SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY = 1 << 10, }; -#if defined(SLANG_CONFIG_DEFAULT_SPIRV_DIRECT) constexpr static SlangTargetFlags kDefaultTargetFlags = SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY; -#else - constexpr static SlangTargetFlags kDefaultTargetFlags = 0; -#endif /*! @brief Options to control floating-point precision guarantees for a target. diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index 16b143529..1002fb163 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -1961,7 +1961,7 @@ extension __TextureImpl<T,Shape,isArray,0,sampleCount,$(access),isShadow, 0,form case spirv: return spirv_asm { - OpImageWrite $this $location $newValue; + OpImageWrite $this $location __convertTexel(newValue); }; } } @@ -2073,7 +2073,7 @@ extension __TextureImpl<T,Shape,isArray,1,sampleCount,$(access),isShadow, 0,form case spirv: return spirv_asm { - OpImageWrite $this $location $newValue Sample $sampleIndex; + OpImageWrite $this $location __convertTexel(newValue) Sample $sampleIndex; }; } } @@ -10650,7 +10650,7 @@ ${{{{ case hlsl: __intrinsic_asm "($0)[$1] = $2"; case glsl: __intrinsic_asm "imageStore($0, int($1), $V2)"; case spirv: spirv_asm { - OpImageWrite $this $index $newValue; + OpImageWrite $this $index __convertTexel(newValue); }; } } diff --git a/source/slang/slang-ast-expr.h b/source/slang/slang-ast-expr.h index 56ac83f80..cf873bf0d 100644 --- a/source/slang/slang-ast-expr.h +++ b/source/slang/slang-ast-expr.h @@ -683,6 +683,7 @@ public: SampledType, // __sampledType(T), this becomes a 4 vector of the component type of T ImageType, // __imageType(texture), returns the equivalaent OpTypeImage of a given texture typed value. SampledImageType, // __sampledImageType(texture), returns the equivalent OpTypeSampledImage of a given texture typed value. + ConvertTexel, // __convertTexel(value), converts `value` to the native texel type of a texture. TruncateMarker, // __truncate, an invented instruction which coerces to the result type by truncating the element count EntryPoint, // __entryPoint, a placeholder for the id of a referencing entryPoint. BuiltinVar, diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index 29747b7d5..a399ea389 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -4415,6 +4415,7 @@ namespace Slang || operand.flavor == SPIRVAsmOperand::SlangValueAddr || operand.flavor == SPIRVAsmOperand::ImageType || operand.flavor == SPIRVAsmOperand::SampledImageType + || operand.flavor == SPIRVAsmOperand::ConvertTexel || operand.flavor == SPIRVAsmOperand::RayPayloadFromLocation || operand.flavor == SPIRVAsmOperand::RayAttributeFromLocation || operand.flavor == SPIRVAsmOperand::RayCallableFromLocation) diff --git a/source/slang/slang-compiler-options.h b/source/slang/slang-compiler-options.h index ea2bbf070..270e789ab 100644 --- a/source/slang/slang-compiler-options.h +++ b/source/slang/slang-compiler-options.h @@ -336,7 +336,9 @@ namespace Slang bool shouldEmitSPIRVDirectly() { - return getBoolOption(CompilerOptionName::EmitSpirvDirectly); + if (getBoolOption(CompilerOptionName::EmitSpirvViaGLSL)) + return false; + return true; } bool shouldUseScalarLayout() diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index 266c503ae..fc4bc355b 100755 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -2402,6 +2402,11 @@ namespace Slang HLSLToVulkanLayoutOptions* getHLSLToVulkanLayoutOptions() { return m_targetReq->getHLSLToVulkanLayoutOptions(); } + bool shouldEmitSPIRVDirectly() + { + return isKhronosTarget(m_targetReq) && getOptionSet().shouldEmitSPIRVDirectly(); + } + private: RefPtr<IRModule> createIRModuleForLayout(DiagnosticSink* sink); diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index 3a551f301..06e5f0766 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -1867,7 +1867,7 @@ struct SPIRVEmitContext setImageFormatCapabilityAndExtension(SpvImageFormatUnknown, SpvCapabilityShader); return emitOpTypeImage( assignee, - dropVector((IRType*)sampledType), + getVectorElementType((IRType*)sampledType), dim, SpvLiteralInteger::from32(ImageOpConstants::unknownDepthImage), SpvLiteralInteger::from32(0), @@ -2018,12 +2018,12 @@ struct SPIRVEmitContext // // The op itself // - + auto sampledElementType = getSPIRVSampledElementType(sampledType); if (inst->isCombined()) { auto imageType = emitOpTypeImage( nullptr, - dropVector((IRType*)sampledType), + sampledElementType, dim, SpvLiteralInteger::from32(depth), SpvLiteralInteger::from32(arrayed), @@ -2038,7 +2038,7 @@ struct SPIRVEmitContext return emitOpTypeImage( assignee, - dropVector((IRType*)sampledType), + sampledElementType, dim, SpvLiteralInteger::from32(depth), SpvLiteralInteger::from32(arrayed), @@ -4827,20 +4827,13 @@ struct SPIRVEmitContext } } - IRType* dropVector(IRType* t) - { - if(const auto v = as<IRVectorType>(t)) - return v->getElementType(); - return t; - }; - SpvInst* emitIntCast(SpvInstParent* parent, IRIntCast* inst) { const auto fromTypeV = inst->getOperand(0)->getDataType(); const auto toTypeV = inst->getDataType(); SLANG_ASSERT(!as<IRVectorType>(fromTypeV) == !as<IRVectorType>(toTypeV)); - const auto fromType = dropVector(fromTypeV); - const auto toType = dropVector(toTypeV); + const auto fromType = getVectorElementType(fromTypeV); + const auto toType = getVectorElementType(toTypeV); if (as<IRBoolType>(fromType)) { @@ -4906,8 +4899,8 @@ struct SPIRVEmitContext const auto fromTypeV = inst->getOperand(0)->getDataType(); const auto toTypeV = inst->getDataType(); SLANG_ASSERT(!as<IRVectorType>(fromTypeV) == !as<IRVectorType>(toTypeV)); - const auto fromType = dropVector(fromTypeV); - const auto toType = dropVector(toTypeV); + const auto fromType = getVectorElementType(fromTypeV); + const auto toType = getVectorElementType(toTypeV); SLANG_ASSERT(isFloatingType(fromType)); SLANG_ASSERT(isFloatingType(toType)); SLANG_ASSERT(!isTypeEqual(fromType, toType)); @@ -4920,8 +4913,8 @@ struct SPIRVEmitContext const auto fromTypeV = inst->getOperand(0)->getDataType(); const auto toTypeV = inst->getDataType(); SLANG_ASSERT(!as<IRVectorType>(fromTypeV) == !as<IRVectorType>(toTypeV)); - const auto fromType = dropVector(fromTypeV); - const auto toType = dropVector(toTypeV); + const auto fromType = getVectorElementType(fromTypeV); + const auto toType = getVectorElementType(toTypeV); SLANG_ASSERT(isFloatingType(toType)); if (isIntegralType(fromType)) @@ -4956,8 +4949,8 @@ struct SPIRVEmitContext const auto fromTypeV = inst->getOperand(0)->getDataType(); const auto toTypeV = inst->getDataType(); SLANG_ASSERT(!as<IRVectorType>(fromTypeV) == !as<IRVectorType>(toTypeV)); - const auto fromType = dropVector(fromTypeV); - const auto toType = dropVector(toTypeV); + const auto fromType = getVectorElementType(fromTypeV); + const auto toType = getVectorElementType(toTypeV); SLANG_ASSERT(isFloatingType(fromType)); if (as<IRBoolType>(toType)) @@ -5175,7 +5168,7 @@ struct SPIRVEmitContext SpvInst* emitVectorOrScalarArithmetic(SpvInstParent* parent, IRInst* instToRegister, IRInst* type, IROp op, UInt operandCount, ArrayView<IRInst*> operands) { - IRType* elementType = dropVector(operands[0]->getDataType()); + IRType* elementType = getVectorElementType(operands[0]->getDataType()); IRBasicType* basicType = as<IRBasicType>(elementType); bool isFloatingPoint = false; bool isBool = false; @@ -5813,7 +5806,7 @@ struct SPIRVEmitContext // Make a 4 vector of the component type IRBuilder builder(m_irModule); const auto elementType = cast<IRType>(operand->getValue()); - const auto sampledType = builder.getVectorType(dropVector(elementType), 4); + const auto sampledType = builder.getVectorType(getSPIRVSampledElementType(getVectorElementType(elementType)), 4); emitOperand(ensureInst(sampledType)); break; } @@ -5867,7 +5860,7 @@ struct SPIRVEmitContext // Make a 4 vector of the component type IRBuilder builder(m_irModule); const auto elementType = cast<IRType>(operand->getValue()); - return builder.getVectorType(dropVector(elementType), 4); + return builder.getVectorType(getVectorElementType(elementType), 4); } case kIROp_SPIRVAsmOperandEnum: case kIROp_SPIRVAsmOperandLiteral: @@ -5884,9 +5877,22 @@ struct SPIRVEmitContext const auto toIdOperand = spvInst->getSPIRVOperands()[1]; const auto fromType = getSlangType(spvInst->getSPIRVOperands()[2]); const auto fromIdOperand = spvInst->getSPIRVOperands()[3]; - - // The component types must be the same - SLANG_ASSERT(isTypeEqual(dropVector(toType), dropVector(fromType))); + auto fromElementType = getSPIRVSampledElementType(fromType); + SpvInst* fromSpvInst = nullptr; + // If the component types are not the same, convert them to be so. + if (!isTypeEqual(getVectorElementType(toType), fromElementType)) + { + auto newFromType = replaceVectorElementType(fromType, getVectorElementType(toType)); + fromSpvInst = emitInstCustomOperandFunc( + parent, + nullptr, + SpvOpFConvert, + [&]() { + emitOperand(newFromType); + emitOperand(kResultID), + emitSpvAsmOperand(fromIdOperand); + }); + } // If we don't need truncation, but a different result ID is // expected, then just unify them in the idMap @@ -5901,7 +5907,7 @@ struct SPIRVEmitContext [&](){ emitOperand(toType); emitSpvAsmOperand(toIdOperand); - emitSpvAsmOperand(fromIdOperand); + fromSpvInst ? emitOperand(fromSpvInst) : emitSpvAsmOperand(fromIdOperand); } ); } @@ -5915,7 +5921,7 @@ struct SPIRVEmitContext [&](){ emitOperand(toType); emitSpvAsmOperand(toIdOperand); - emitSpvAsmOperand(fromIdOperand); + fromSpvInst ? emitOperand(fromSpvInst) : emitSpvAsmOperand(fromIdOperand); emitOperand(SpvLiteralInteger::from32(0)); } ); @@ -5930,7 +5936,7 @@ struct SPIRVEmitContext [&](){ emitOperand(toType); emitSpvAsmOperand(toIdOperand); - emitSpvAsmOperand(fromIdOperand); + fromSpvInst ? emitOperand(fromSpvInst) : emitSpvAsmOperand(fromIdOperand); } ); } @@ -5950,7 +5956,7 @@ struct SPIRVEmitContext [&](){ emitOperand(toType); emitSpvAsmOperand(toIdOperand); - emitSpvAsmOperand(fromIdOperand); + fromSpvInst ? emitOperand(fromSpvInst) : emitSpvAsmOperand(fromIdOperand); emitOperand(emitOpUndef(parent, nullptr, fromVector)); for(Int32 i = 0; i < toVectorSize; ++i) emitOperand(SpvLiteralInteger::from32(i)); diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp index f492167a2..77164dae3 100644 --- a/source/slang/slang-emit.cpp +++ b/source/slang/slang-emit.cpp @@ -967,9 +967,9 @@ Result linkAndOptimizeIR( // bit_cast on basic types. lowerBitCast(targetProgram, irModule, sink); - bool emitSpirvDirectly = targetProgram->getOptionSet().shouldEmitSPIRVDirectly(); + bool emitSpirvDirectly = targetProgram->shouldEmitSPIRVDirectly(); - if (isKhronosTarget(targetRequest) && emitSpirvDirectly) + if (emitSpirvDirectly) { performIntrinsicFunctionInlining(irModule); eliminateDeadCode(irModule); diff --git a/source/slang/slang-ir-autodiff-fwd.cpp b/source/slang/slang-ir-autodiff-fwd.cpp index 0e934eeb5..91a0586b7 100644 --- a/source/slang/slang-ir-autodiff-fwd.cpp +++ b/source/slang/slang-ir-autodiff-fwd.cpp @@ -1930,6 +1930,7 @@ InstPair ForwardDiffTranscriber::transcribeInstImpl(IRBuilder* builder, IRInst* case kIROp_SPIRVAsmOperandBuiltinVar: case kIROp_SPIRVAsmOperandGLSL450Set: case kIROp_SPIRVAsmOperandDebugPrintfSet: + case kIROp_SPIRVAsmOperandConvertTexel: case kIROp_SPIRVAsmOperandId: case kIROp_SPIRVAsmOperandResult: case kIROp_SPIRVAsmOperandTruncate: diff --git a/source/slang/slang-ir-inst-defs.h b/source/slang/slang-ir-inst-defs.h index ca4c8359a..47a2d2f7e 100644 --- a/source/slang/slang-ir-inst-defs.h +++ b/source/slang/slang-ir-inst-defs.h @@ -1183,6 +1183,7 @@ INST(SPIRVAsmInst, SPIRVAsmInst, 1, 0) // This isn't hoistable, as we sometimes need to change the used value and // instructions around the specific asm block INST(SPIRVAsmOperandInst, SPIRVAsmOperandInst, 1, 0) + INST(SPIRVAsmOperandConvertTexel, SPIRVAsmOperandConvertTexel, 1, 0) //a late resolving type to handle the case of ray objects (resolving late due to constexpr data requirment) INST(SPIRVAsmOperandRayPayloadFromLocation, SPIRVAsmOperandRayPayloadFromLocation, 1, 0) INST(SPIRVAsmOperandRayAttributeFromLocation, SPIRVAsmOperandRayAttributeFromLocation, 1, 0) @@ -1196,7 +1197,6 @@ INST(SPIRVAsmInst, SPIRVAsmInst, 1, 0) // A reference to the glsl450 instruction set. INST(SPIRVAsmOperandGLSL450Set, SPIRVAsmOperandGLSL450Set, 0, HOISTABLE) INST(SPIRVAsmOperandDebugPrintfSet, SPIRVAsmOperandDebugPrintfSet, 0, HOISTABLE) - // A string which is given a unique ID in the backend, used to refer to // results of other instrucions in the same asm block INST(SPIRVAsmOperandId, SPIRVAsmOperandId, 1, HOISTABLE) diff --git a/source/slang/slang-ir-insts.h b/source/slang/slang-ir-insts.h index 2d2fd4511..067a0cc2f 100644 --- a/source/slang/slang-ir-insts.h +++ b/source/slang/slang-ir-insts.h @@ -4227,6 +4227,7 @@ public: IRSPIRVAsmOperand* emitSPIRVAsmOperandLiteral(IRInst* literal); IRSPIRVAsmOperand* emitSPIRVAsmOperandInst(IRInst* inst); IRSPIRVAsmOperand* createSPIRVAsmOperandInst(IRInst* inst); + IRSPIRVAsmOperand* emitSPIRVAsmOperandConvertTexel(IRInst* inst); IRSPIRVAsmOperand* emitSPIRVAsmOperandRayPayloadFromLocation(IRInst* inst); IRSPIRVAsmOperand* emitSPIRVAsmOperandRayAttributeFromLocation(IRInst* inst); IRSPIRVAsmOperand* emitSPIRVAsmOperandRayCallableFromLocation(IRInst* inst); diff --git a/source/slang/slang-ir-lower-buffer-element-type.cpp b/source/slang/slang-ir-lower-buffer-element-type.cpp index 7deb5f151..e9fbfc0d1 100644 --- a/source/slang/slang-ir-lower-buffer-element-type.cpp +++ b/source/slang/slang-ir-lower-buffer-element-type.cpp @@ -231,7 +231,7 @@ namespace Slang { // For spirv, we always want to lower all matrix types, because matrix types // are considered abstract types. - if (!target->getOptionSet().shouldEmitSPIRVDirectly()) + if (!target->shouldEmitSPIRVDirectly()) { // For other targets, we only lower the matrix types if they differ from the default // matrix layout. @@ -280,7 +280,7 @@ namespace Slang // For spirv backend, we always want to lower all array types, even if the element type // comes out the same. This is because different layout rules may have different array // stride requirements. - if (!target->getOptionSet().shouldEmitSPIRVDirectly()) + if (!target->shouldEmitSPIRVDirectly()) { if (!loweredInnerTypeInfo.convertLoweredToOriginal) { @@ -327,7 +327,7 @@ namespace Slang // For spirv backend, we always want to lower all array types, even if the element type // comes out the same. This is because different layout rules may have different array // stride requirements. - if (!target->getOptionSet().shouldEmitSPIRVDirectly()) + if (!target->shouldEmitSPIRVDirectly()) { // For non-spirv target, we skip lowering this type if all field types are unchanged. if (isTrivial) @@ -404,7 +404,7 @@ namespace Slang return info; } - if (target->getOptionSet().shouldEmitSPIRVDirectly()) + if (target->shouldEmitSPIRVDirectly()) { switch (target->getTargetReq()->getTarget()) { @@ -838,7 +838,7 @@ namespace Slang return IRTypeLayoutRules::getNatural(); // If we are just emitting GLSL, we can just use the general layout rule. - if (!target->getOptionSet().shouldEmitSPIRVDirectly()) + if (!target->shouldEmitSPIRVDirectly()) return IRTypeLayoutRules::getNatural(); // If the user specified a scalar buffer layout, then just use that. diff --git a/source/slang/slang-ir-spirv-legalize.cpp b/source/slang/slang-ir-spirv-legalize.cpp index 65ad29a9a..23980e583 100644 --- a/source/slang/slang-ir-spirv-legalize.cpp +++ b/source/slang/slang-ir-spirv-legalize.cpp @@ -1598,6 +1598,33 @@ struct SPIRVLegalizationContext : public SourceEmitterBase return (as<IRSPIRVAsmInst>(inst) || as<IRSPIRVAsmOperand>(inst)); } + void processConvertTexel(IRInst* asmBlockInst, IRInst* inst) + { + // If we see `__convertTexel(x)`, we need to return a vector<__sampledElementType(x), 4>. + IRInst* operand = inst->getOperand(0); + auto elementType = getSPIRVSampledElementType(operand->getDataType()); + auto valueElementType = getVectorElementType(operand->getDataType()); + IRBuilder builder(inst); + builder.setInsertBefore(asmBlockInst); + if (elementType != valueElementType) + { + auto floatCastType = replaceVectorElementType(operand->getDataType(), elementType); + operand = builder.emitCast(floatCastType, operand); + } + auto vecType = builder.getVectorType(elementType, 4); + if (vecType != operand->getDataType()) + { + if (!as<IRVectorType>(operand->getDataType())) + operand = builder.emitMakeVectorFromScalar(vecType, operand); + else + operand = builder.emitVectorReshape(vecType, operand); + } + builder.setInsertBefore(inst); + auto spvAsmOperand = builder.emitSPIRVAsmOperandInst(operand); + inst->replaceUsesWith(spvAsmOperand); + inst->removeAndDeallocate(); + } + void processSPIRVAsm(IRSPIRVAsm* inst) { // Move anything that is not an spirv instruction to the outer parent. @@ -1605,6 +1632,8 @@ struct SPIRVLegalizationContext : public SourceEmitterBase { if (!isAsmInst(child)) child->insertBefore(inst); + else if (child->getOp() == kIROp_SPIRVAsmOperandConvertTexel) + processConvertTexel(inst, child); } } diff --git a/source/slang/slang-ir-util.cpp b/source/slang/slang-ir-util.cpp index eaf254190..f7a93dca6 100644 --- a/source/slang/slang-ir-util.cpp +++ b/source/slang/slang-ir-util.cpp @@ -1544,6 +1544,27 @@ void hoistInstOutOfASMBlocks(IRBlock* block) } } +IRType* getSPIRVSampledElementType(IRInst* sampledType) +{ + auto sampledElementType = getVectorElementType((IRType*)sampledType); + if (sampledElementType->getOp() == kIROp_HalfType) + { + IRBuilder builder(sampledType); + sampledElementType = builder.getBasicType(BaseType::Float); + } + return sampledElementType; +} + +IRType* replaceVectorElementType(IRType* originalVectorType, IRType* t) +{ + if (auto orignalVectorType = as<IRVectorType>(originalVectorType)) + { + IRBuilder builder(originalVectorType); + return builder.getVectorType(t, orignalVectorType->getElementCount()); + } + return t; +} + IRParam* getParamAt(IRBlock* block, UIndex ii) { UIndex index = 0; diff --git a/source/slang/slang-ir-util.h b/source/slang/slang-ir-util.h index fba1e784e..9046f3974 100644 --- a/source/slang/slang-ir-util.h +++ b/source/slang/slang-ir-util.h @@ -313,6 +313,10 @@ static void overAllBlocks(IRModule* module, F f) void hoistInstOutOfASMBlocks(IRBlock* block); +IRType* getSPIRVSampledElementType(IRInst* sampledType); + +IRType* replaceVectorElementType(IRType* originalVectorType, IRType* t); + inline bool isCompositeType(IRType* type) { switch (type->getOp()) diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index 7cdc8ecfa..4ea3755f8 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -3773,7 +3773,12 @@ namespace Slang return nullptr; } - static int _getTypeStyleId(IRType* type) + enum class TypeCastStyle + { + Unknown = -1, + Int, Float, Bool, Ptr, Void + }; + static TypeCastStyle _getTypeStyleId(IRType* type) { if (auto vectorType = as<IRVectorType>(type)) { @@ -3787,22 +3792,24 @@ namespace Slang switch (style) { case kIROp_IntType: - return 0; + return TypeCastStyle::Int; case kIROp_FloatType: - return 1; + case kIROp_HalfType: + case kIROp_DoubleType: + return TypeCastStyle::Float; case kIROp_BoolType: - return 2; + return TypeCastStyle::Bool; case kIROp_PtrType: case kIROp_InOutType: case kIROp_OutType: case kIROp_RawPointerType: case kIROp_RefType: case kIROp_ConstRefType: - return 3; + return TypeCastStyle::Ptr; case kIROp_VoidType: - return 4; + return TypeCastStyle::Void; default: - return -1; + return TypeCastStyle::Unknown; } } @@ -3814,14 +3821,14 @@ namespace Slang auto toStyle = _getTypeStyleId(type); auto fromStyle = _getTypeStyleId(value->getDataType()); - if (fromStyle == kIROp_VoidType) + if (fromStyle == TypeCastStyle::Void) { // We shouldn't be casting from void to other types. SLANG_UNREACHABLE("cast from void type"); } - SLANG_RELEASE_ASSERT(toStyle != -1); - SLANG_RELEASE_ASSERT(fromStyle != -1); + SLANG_RELEASE_ASSERT(toStyle != TypeCastStyle::Unknown); + SLANG_RELEASE_ASSERT(fromStyle != TypeCastStyle::Unknown); struct OpSeq { @@ -3845,7 +3852,7 @@ namespace Slang /* From Ptr */ {kIROp_CastPtrToInt, {kIROp_CastPtrToInt, kIROp_CastIntToFloat}, kIROp_CastPtrToBool, kIROp_BitCast, kIROp_CastToVoid}, }; - auto op = opMap[fromStyle][toStyle]; + auto op = opMap[(int)fromStyle][(int)toStyle]; if (op.op0 == kIROp_Nop) return value; auto t = type; @@ -5896,6 +5903,18 @@ namespace Slang ); return i; } + IRSPIRVAsmOperand* IRBuilder::emitSPIRVAsmOperandConvertTexel(IRInst* inst) + { + SLANG_ASSERT(as<IRSPIRVAsm>(m_insertLoc.getParent())); + auto i = createInst<IRSPIRVAsmOperand>( + this, + kIROp_SPIRVAsmOperandConvertTexel, + inst->getFullType(), + inst + ); + addInst(i); + return i; + } IRSPIRVAsmOperand* IRBuilder::emitSPIRVAsmOperandRayPayloadFromLocation(IRInst* inst) { SLANG_ASSERT(as<IRSPIRVAsm>(m_insertLoc.getParent())); diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index 52b3e64d4..a600963a7 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -4118,6 +4118,16 @@ struct ExprLoweringVisitorBase : public ExprVisitor<Derived, LoweredValInfo> { return builder->emitSPIRVAsmOperandTruncate(); } + case SPIRVAsmOperand::ConvertTexel: + { + IRInst* i; + { + IRBuilderInsertLocScope insertScope(builder); + builder->setInsertBefore(spirvAsmInst); + i = getSimpleVal(context, lowerRValueExpr(context, operand.expr)); + } + return builder->emitSPIRVAsmOperandConvertTexel(i); + } case SPIRVAsmOperand::EntryPoint: { return builder->emitSPIRVAsmOperandEntryPoint(); diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp index 8a5c52e0e..9d9e8039b 100644 --- a/source/slang/slang-options.cpp +++ b/source/slang/slang-options.cpp @@ -407,21 +407,15 @@ void initCommandOptions(CommandOptions& options) { OptionKind::EnableEffectAnnotations, "-enable-effect-annotations", nullptr, "Enables support for legacy effect annotation syntax."}, -#if defined(SLANG_CONFIG_DEFAULT_SPIRV_DIRECT) { OptionKind::EmitSpirvViaGLSL, "-emit-spirv-via-glsl", nullptr, "Generate SPIR-V output by compiling generated GLSL with glslang" }, { OptionKind::EmitSpirvDirectly, "-emit-spirv-directly", nullptr, "Generate SPIR-V output direclty (default)" }, -#else - { OptionKind::EmitSpirvViaGLSL, "-emit-spirv-via-glsl", nullptr, - "Generate SPIR-V output by compiling generated GLSL with glslang (default)" }, - { OptionKind::EmitSpirvDirectly, "-emit-spirv-directly", nullptr, - "Generate SPIR-V output direclty rather than by compiling generated GLSL with glslang" }, { OptionKind::SPIRVCoreGrammarJSON, "-spirv-core-grammar", nullptr, "A path to a specific spirv.core.grammar.json to use when generating SPIR-V output" }, { OptionKind::IncompleteLibrary, "-incomplete-library", nullptr, "Allow generating code from incomplete libraries with unresolved external functions" }, -#endif + }; _addOptions(makeConstArrayView(targetOpts), options); diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index 2c304a663..9e0a94cae 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -7248,6 +7248,13 @@ namespace Slang parser->ReadMatchingToken(TokenType::RParent); return SPIRVAsmOperand{ SPIRVAsmOperand::SampledImageType, Token{}, typeExpr }; } + else if (AdvanceIf(parser, "__convertTexel")) + { + parser->ReadToken(TokenType::LParent); + const auto texelExpr = parser->ParseExpression(); + parser->ReadMatchingToken(TokenType::RParent); + return SPIRVAsmOperand{ SPIRVAsmOperand::ConvertTexel, Token{}, texelExpr }; + } // The pseudo-operand for component truncation else if(parser->LookAheadToken("__truncate")) { diff --git a/source/slang/slang-type-layout.cpp b/source/slang/slang-type-layout.cpp index 00f365ac3..ebb789876 100644 --- a/source/slang/slang-type-layout.cpp +++ b/source/slang/slang-type-layout.cpp @@ -1796,7 +1796,7 @@ bool isCUDATarget(TargetRequest* targetReq) SourceLanguage getIntermediateSourceLanguageForTarget(TargetProgram* targetProgram) { // If we are emitting directly, there is no intermediate source language - if (targetProgram->getOptionSet().shouldEmitSPIRVDirectly()) + if (targetProgram->shouldEmitSPIRVDirectly()) { return SourceLanguage::Unknown; } diff --git a/tests/compute/half-texture.slang b/tests/compute/half-texture.slang index bdf98cb77..ca51df3cc 100644 --- a/tests/compute/half-texture.slang +++ b/tests/compute/half-texture.slang @@ -1,4 +1,5 @@ -//TEST:SIMPLE(filecheck=CHECK): -target spirv -entry computeMain -profile cs_6_2 +//TEST:SIMPLE(filecheck=CHECK_SPIRV): -target spirv -entry computeMain -profile cs_6_2 -emit-spirv-via-glsl +//TEST:SIMPLE(filecheck=CHECK_SPIRV): -target spirv -entry computeMain -profile cs_6_2 -emit-spirv-directly //TEST:CROSS_COMPILE: -target dxil-assembly -entry computeMain -profile cs_6_2 //TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], stride=16):out @@ -26,14 +27,14 @@ void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) half2 h2 = halfTexture2.Sample(s, uv); half4 h4 = halfTexture4.Sample(s, uv); #else - // CHECK: {{.*}} = OpImageRead - // CHECK: {{.*}} = OpFConvert %half + // CHECK_SPIRV: {{.*}} = OpImageRead + // CHECK_SPIRV: {{.*}} = OpFConvert half h = halfTexture[pos2]; - // CHECK: {{.*}} = OpImageRead - // CHECK: {{.*}} = OpFConvert %v2half + // CHECK_SPIRV: {{.*}} = OpImageRead + // CHECK_SPIRV: {{.*}} = OpFConvert half2 h2 = halfTexture2[pos2]; - // CHECK: {{.*}} = OpImageRead - // CHECK: {{.*}} = OpFConvert %v4half + // CHECK_SPIRV: {{.*}} = OpImageRead + // CHECK_SPIRV: {{.*}} = OpFConvert half4 h4 = halfTexture4[pos2]; #endif // Store a results diff --git a/tests/compute/nonuniformres-array-of-textures.slang b/tests/compute/nonuniformres-array-of-textures.slang index 32eccdbdc..a7f3e05bd 100644 --- a/tests/compute/nonuniformres-array-of-textures.slang +++ b/tests/compute/nonuniformres-array-of-textures.slang @@ -1,6 +1,6 @@ //TEST:SIMPLE(filecheck=CHECK0):-target glsl -entry main -stage compute //TEST:SIMPLE(filecheck=CHECK1):-target hlsl -entry main -stage compute -//TEST:SIMPLE(filecheck=CHECK2):-target spirv -entry main -stage compute +//TEST:SIMPLE(filecheck=CHECK2):-target spirv -entry main -stage compute -emit-spirv-via-glsl //TEST:SIMPLE(filecheck=CHECK3):-target spirv -entry main -stage compute -emit-spirv-directly Texture2D<float> textures[2]; diff --git a/tests/compute/nonuniformres-atomic.slang b/tests/compute/nonuniformres-atomic.slang index 113517006..95ae502dc 100644 --- a/tests/compute/nonuniformres-atomic.slang +++ b/tests/compute/nonuniformres-atomic.slang @@ -1,6 +1,6 @@ //TEST:SIMPLE(filecheck=CHECK0):-target glsl -entry main -stage compute //TEST:SIMPLE(filecheck=CHECK1):-target hlsl -entry main -stage compute -//TEST:SIMPLE(filecheck=CHECK2):-target spirv -entry main -stage compute +//TEST:SIMPLE(filecheck=CHECK2):-target spirv -entry main -stage compute -emit-spirv-via-glsl //TEST:SIMPLE(filecheck=CHECK3):-target spirv -entry main -stage compute -emit-spirv-directly RWTexture2D<uint> texArray[2]; diff --git a/tests/compute/nonuniformres-nested-rwstructuredbuf.slang b/tests/compute/nonuniformres-nested-rwstructuredbuf.slang index 3c99ea205..b188a2c52 100644 --- a/tests/compute/nonuniformres-nested-rwstructuredbuf.slang +++ b/tests/compute/nonuniformres-nested-rwstructuredbuf.slang @@ -1,6 +1,6 @@ //TEST:SIMPLE(filecheck=CHECK0):-target glsl -entry main -stage compute //TEST:SIMPLE(filecheck=CHECK1):-target hlsl -entry main -stage compute -//TEST:SIMPLE(filecheck=CHECK2):-target spirv -entry main -stage compute +//TEST:SIMPLE(filecheck=CHECK2):-target spirv -entry main -stage compute -emit-spirv-via-glsl //TEST:SIMPLE(filecheck=CHECK3):-target spirv -entry main -stage compute -emit-spirv-directly RWStructuredBuffer<int> buffer[]; diff --git a/tests/compute/unbounded-array-of-array-syntax.slang b/tests/compute/unbounded-array-of-array-syntax.slang index 35316d114..10c4d277f 100644 --- a/tests/compute/unbounded-array-of-array-syntax.slang +++ b/tests/compute/unbounded-array-of-array-syntax.slang @@ -1,7 +1,7 @@ //IGNORE_TEST:CPU_REFLECTION: -profile cs_5_0 -entry computeMain -target cpp //DISABLED_TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute //TEST:CROSS_COMPILE:-target dxbc-assembly -entry computeMain -profile cs_5_1 -//TEST:SIMPLE(filecheck=CHECK):-target spirv-assembly -entry computeMain -profile cs_5_1 +//TEST:SIMPLE(filecheck=CHECK):-target spirv-assembly -entry computeMain -profile cs_5_1 -emit-spirv-via-glsl //DISABLED_TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute //TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0], stride=4):out,name outputBuffer diff --git a/tests/cross-compile/glsl-generic-in.slang b/tests/cross-compile/glsl-generic-in.slang index a43f33c21..a743c32cb 100644 --- a/tests/cross-compile/glsl-generic-in.slang +++ b/tests/cross-compile/glsl-generic-in.slang @@ -1,7 +1,10 @@ -//TEST:SIMPLE(filecheck=CHECK): -target spirv-assembly -entry main -profile vs_5_0 -// CHECK: vIn_field_v0_0 = OpVariable %_ptr_Input_v4float Input -// CHECK: %vIn_field_v1_0 = OpVariable %_ptr_Input_v2float Input -// CHECK: %vIn_p0_0 = OpVariable %_ptr_Input_v3float Input +//TEST:SIMPLE(filecheck=CHECK): -target spirv-assembly -entry main -profile vs_5_0 -emit-spirv-directly +//TEST:SIMPLE(filecheck=CHECK): -target spirv-assembly -entry main -profile vs_5_0 -emit-spirv-via-glsl + +// CHECK: vIn_field_v0{{.*}} = OpVariable %_ptr_Input_v4float Input +// CHECK: %vIn_field_v1{{.*}}= OpVariable %_ptr_Input_v2float Input +// CHECK: %vIn_p0{{.*}}= OpVariable %_ptr_Input_v3float Input + interface IField { float get(); diff --git a/tests/cross-compile/glslang-error.glsl b/tests/cross-compile/glslang-error.glsl index c7d709442..eb59b72f6 100644 --- a/tests/cross-compile/glslang-error.glsl +++ b/tests/cross-compile/glslang-error.glsl @@ -1,4 +1,4 @@ -//TEST(glslang):SIMPLE:-pass-through glslang -target spirv -entry compute -stage compute -profile sm_5_1 +//TEST(glslang):SIMPLE:-pass-through glslang -target spirv -entry compute -stage compute -profile sm_5_1 -emit-spirv-via-glsl #version 450 void main() diff --git a/tests/diagnostics/local-line.slang b/tests/diagnostics/local-line.slang index 532307a8f..ecf6a70bf 100644 --- a/tests/diagnostics/local-line.slang +++ b/tests/diagnostics/local-line.slang @@ -1,9 +1,9 @@ -//TEST:SIMPLE_LINE:-entry computeMain -target spirv -stage compute +//TEST:SIMPLE_LINE:-entry computeMain -target spirv -stage compute -emit-spirv-via-glsl //TEST:SIMPLE_LINE:-entry computeMain -target dxil -profile cs_6_0 //TEST:SIMPLE_LINE:-entry computeMain -target dxbc -stage compute //TEST:SIMPLE_LINE:-entry computeMain -target dll -stage compute //TEST:SIMPLE_LINE:-entry computeMain -target ptx -stage compute -//TEST:SIMPLE_LINE(filecheck=CHECK):-entry computeMain -target spirv -stage compute +//TEST:SIMPLE_LINE(filecheck=CHECK):-entry computeMain -target spirv -stage compute -emit-spirv-via-glsl //TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer RWStructuredBuffer<int> outputBuffer; diff --git a/tests/diagnostics/syntax-error-intrinsic.slang b/tests/diagnostics/syntax-error-intrinsic.slang index dde54b2ad..d6867dd07 100644 --- a/tests/diagnostics/syntax-error-intrinsic.slang +++ b/tests/diagnostics/syntax-error-intrinsic.slang @@ -4,7 +4,7 @@ // the downstream compiler being present is a requirement, so we mark as a 'TEST' so that // those tests are made. -//TEST:SIMPLE_LINE:-entry computeMain -target spirv +//TEST:SIMPLE_LINE:-entry computeMain -target spirv -emit-spirv-via-glsl //TEST:SIMPLE_LINE:-entry computeMain -target dxil -profile cs_6_0 //TEST:SIMPLE_LINE:-entry computeMain -target dxbc //TEST:SIMPLE_LINE:-entry computeMain -target dll diff --git a/tests/diagnostics/syntax-error-op-line-2.slang b/tests/diagnostics/syntax-error-op-line-2.slang index 994e875a1..5e13399d7 100644 --- a/tests/diagnostics/syntax-error-op-line-2.slang +++ b/tests/diagnostics/syntax-error-op-line-2.slang @@ -4,7 +4,7 @@ // the downstream compiler being present is a requirement, so we mark as a 'TEST' so that // those tests are made. -//TEST:SIMPLE_LINE:-entry computeMain -target spirv +//TEST:SIMPLE_LINE:-entry computeMain -target spirv -emit-spirv-via-glsl //TEST:SIMPLE_LINE:-entry computeMain -target dxil -profile cs_6_0 //TEST:SIMPLE_LINE:-entry computeMain -target dxbc //TEST:SIMPLE_LINE:-entry computeMain -target dll diff --git a/tests/diagnostics/syntax-error-op-line-3.slang b/tests/diagnostics/syntax-error-op-line-3.slang index d8b1fa600..5486b8603 100644 --- a/tests/diagnostics/syntax-error-op-line-3.slang +++ b/tests/diagnostics/syntax-error-op-line-3.slang @@ -4,7 +4,7 @@ // the downstream compiler being present is a requirement, so we mark as a 'TEST' so that // those tests are made. -//TEST:SIMPLE_LINE:-entry computeMain -target spirv +//TEST:SIMPLE_LINE:-entry computeMain -target spirv -emit-spirv-via-glsl //TEST:SIMPLE_LINE:-entry computeMain -target dxil -profile cs_6_0 //TEST:SIMPLE_LINE:-entry computeMain -target dxbc //TEST:SIMPLE_LINE:-entry computeMain -target dll diff --git a/tests/diagnostics/syntax-error-op-line.slang b/tests/diagnostics/syntax-error-op-line.slang index eab15e4a4..24ebaccd7 100644 --- a/tests/diagnostics/syntax-error-op-line.slang +++ b/tests/diagnostics/syntax-error-op-line.slang @@ -4,7 +4,7 @@ // the downstream compiler being present is a requirement, so we mark as a 'TEST' so that // those tests are made. -//TEST:SIMPLE_LINE:-entry computeMain -target spirv +//TEST:SIMPLE_LINE:-entry computeMain -target spirv -emit-spirv-via-glsl //TEST:SIMPLE_LINE:-entry computeMain -target dxil -profile cs_6_0 //TEST:SIMPLE_LINE:-entry computeMain -target dxbc //TEST:SIMPLE_LINE:-entry computeMain -target dll diff --git a/tests/feature/source-embed/source-embed-1.slang b/tests/feature/source-embed/source-embed-1.slang index 75b360a23..ecacaed9b 100644 --- a/tests/feature/source-embed/source-embed-1.slang +++ b/tests/feature/source-embed/source-embed-1.slang @@ -1,4 +1,4 @@ -//TEST:SIMPLE(filecheck=CHECK):-target spirv -entry computeMain -profile cs_6_3 -line-directive-mode none -source-embed-style default +//TEST:SIMPLE(filecheck=CHECK):-target spirv -entry computeMain -profile cs_6_3 -line-directive-mode none -source-embed-style default -emit-spirv-via-glsl //TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer RWStructuredBuffer<int> outputBuffer; diff --git a/tests/glsl-intrinsic/intrinsic-texture.slang b/tests/glsl-intrinsic/intrinsic-texture.slang index 4cf50abe1..4f3ba22c9 100644 --- a/tests/glsl-intrinsic/intrinsic-texture.slang +++ b/tests/glsl-intrinsic/intrinsic-texture.slang @@ -1,13 +1,14 @@ #version 450 core #extension GL_EXT_texture_shadow_lod : enable -//TEST:SIMPLE(filecheck=CHECK_GLSL): -allow-glsl -stage fragment -entry computeMain -target glsl -//TEST:SIMPLE(filecheck=CHECK_SPV): -allow-glsl -stage fragment -entry computeMain -target spirv -//TEST:SIMPLE(filecheck=CHECK_CUDA): -allow-glsl -stage fragment -entry computeMain -target cuda +//TEST:SIMPLE(filecheck=CHECK_GLSL): -allow-glsl -stage compute -entry computeMain -target glsl +// TODO: test direct to spirv backend. +//TEST:SIMPLE(filecheck=CHECK_SPV): -allow-glsl -emit-spirv-via-glsl -stage compute -entry computeMain -target spirv +//TEST:SIMPLE(filecheck=CHECK_CUDA): -allow-glsl -stage compute -entry computeMain -target cuda // Disabling following targets because they are currently causing compile errors. -//DISABLE_TEST:SIMPLE(filecheck=CHECK_HLSL): -allow-glsl -stage fragment -entry computeMain -target hlsl -//DISABLE_TEST:SIMPLE(filecheck=CHECK_CPP): -allow-glsl -stage fragment -entry computeMain -target cpp +//DISABLE_TEST:SIMPLE(filecheck=CHECK_HLSL): -allow-glsl -stage compute -entry computeMain -target hlsl +//DISABLE_TEST:SIMPLE(filecheck=CHECK_CPP): -allow-glsl -stage compute -entry computeMain -target cpp // "Offset" family of texture functions in GLSL requires offset parameter to be a constant value. // It appears that slangc removes the constant-ness of constant values. diff --git a/tests/gpu-feature/texture/query/footprint/nv-shader-texture-footprint-simple.slang b/tests/gpu-feature/texture/query/footprint/nv-shader-texture-footprint-simple.slang index e25cd4208..c5852e989 100644 --- a/tests/gpu-feature/texture/query/footprint/nv-shader-texture-footprint-simple.slang +++ b/tests/gpu-feature/texture/query/footprint/nv-shader-texture-footprint-simple.slang @@ -1,4 +1,4 @@ -//TEST:SIMPLE(filecheck=SPIRV):-target spirv-assembly -entry fragmentMain -stage fragment +//TEST:SIMPLE(filecheck=SPIRV):-target spirv-assembly -entry fragmentMain -stage fragment -emit-spirv-via-glsl //DISABLED_TEST:SIMPLE(filecheck=SPIRV):-target spirv-assembly -entry fragmentMain -stage fragment -DENABLE_CLAMP -emit-spirv-directly //DISABLED_TEST:SIMPLE(filecheck=DXIL):-target dxil-assembly -entry fragmentMain -stage fragment //TEST:SIMPLE(filecheck=HLSL):-target hlsl -entry fragmentMain -stage fragment diff --git a/tests/gpu-feature/texture/query/footprint/nv-shader-texture-footprint.slang b/tests/gpu-feature/texture/query/footprint/nv-shader-texture-footprint.slang index d24b14b57..d775dd187 100644 --- a/tests/gpu-feature/texture/query/footprint/nv-shader-texture-footprint.slang +++ b/tests/gpu-feature/texture/query/footprint/nv-shader-texture-footprint.slang @@ -1,4 +1,4 @@ -//TEST:SIMPLE(filecheck=SPIRV):-target spirv-assembly -entry fragmentMain -stage fragment -DENABLE_CLAMP +//TEST:SIMPLE(filecheck=SPIRV):-target spirv-assembly -emit-spirv-via-glsl -entry fragmentMain -stage fragment -DENABLE_CLAMP //DISABLED_TEST:SIMPLE(filecheck=SPIRV):-target spirv-assembly -entry fragmentMain -stage fragment -DENABLE_CLAMP -emit-spirv-directly //DISABLED_TEST:SIMPLE(filecheck=DXIL):-target dxil-assembly -entry fragmentMain -stage fragment diff --git a/tests/hlsl-intrinsic/ray-tracing/rt-pipeline-intrinsics-ahit.slang b/tests/hlsl-intrinsic/ray-tracing/rt-pipeline-intrinsics-ahit.slang index d98b3881a..387c96ef0 100644 --- a/tests/hlsl-intrinsic/ray-tracing/rt-pipeline-intrinsics-ahit.slang +++ b/tests/hlsl-intrinsic/ray-tracing/rt-pipeline-intrinsics-ahit.slang @@ -1,4 +1,4 @@ -//TEST:SIMPLE(filecheck=SPIRV):-target spirv-assembly -entry main -stage anyhit -profile glsl_460+GL_EXT_ray_tracing +//TEST:SIMPLE(filecheck=SPIRV):-target spirv-assembly -entry main -stage anyhit -profile glsl_460+GL_EXT_ray_tracing -emit-spirv-via-glsl // Motion rays not supported on HLSL impl currently, so disable with NOMOTION define: //TEST:SIMPLE(filecheck=DXIL):-target dxil-assembly -entry main -stage anyhit -profile sm_6_5 -DNOMOTION diff --git a/tests/hlsl-intrinsic/ray-tracing/rt-pipeline-intrinsics-chit.slang b/tests/hlsl-intrinsic/ray-tracing/rt-pipeline-intrinsics-chit.slang index 13712797f..a4ab4a5f1 100644 --- a/tests/hlsl-intrinsic/ray-tracing/rt-pipeline-intrinsics-chit.slang +++ b/tests/hlsl-intrinsic/ray-tracing/rt-pipeline-intrinsics-chit.slang @@ -1,4 +1,4 @@ -//TEST:SIMPLE(filecheck=SPIRV):-target spirv-assembly -entry main -stage closesthit -profile glsl_460+GL_EXT_ray_tracing +//TEST:SIMPLE(filecheck=SPIRV):-target spirv-assembly -entry main -stage closesthit -profile glsl_460+GL_EXT_ray_tracing -emit-spirv-via-glsl // Motion rays not supported on HLSL impl currently, so disable with NOMOTION define: //TEST:SIMPLE(filecheck=DXIL):-target dxil-assembly -entry main -stage closesthit -profile sm_6_5 -DNOMOTION diff --git a/tests/hlsl-intrinsic/ray-tracing/rt-pipeline-intrinsics-int.slang b/tests/hlsl-intrinsic/ray-tracing/rt-pipeline-intrinsics-int.slang index fa2fedee6..fdf0e1a54 100644 --- a/tests/hlsl-intrinsic/ray-tracing/rt-pipeline-intrinsics-int.slang +++ b/tests/hlsl-intrinsic/ray-tracing/rt-pipeline-intrinsics-int.slang @@ -1,4 +1,4 @@ -//TEST:SIMPLE(filecheck=SPIRV):-target spirv-assembly -entry main -stage intersection -profile glsl_460+GL_EXT_ray_tracing +//TEST:SIMPLE(filecheck=SPIRV):-target spirv-assembly -entry main -stage intersection -profile glsl_460+GL_EXT_ray_tracing -emit-spirv-via-glsl // Motion rays not supported on HLSL impl currently, so disable with NOMOTION define: //TEST:SIMPLE(filecheck=DXIL):-target dxil-assembly -entry main -stage intersection -profile sm_6_5 -DNOMOTION diff --git a/tests/hlsl-intrinsic/ray-tracing/rt-pipeline-intrinsics-miss.slang b/tests/hlsl-intrinsic/ray-tracing/rt-pipeline-intrinsics-miss.slang index 08b45f5d1..ae4243f6e 100644 --- a/tests/hlsl-intrinsic/ray-tracing/rt-pipeline-intrinsics-miss.slang +++ b/tests/hlsl-intrinsic/ray-tracing/rt-pipeline-intrinsics-miss.slang @@ -1,4 +1,4 @@ -//TEST:SIMPLE(filecheck=SPIRV):-target spirv-assembly -entry main -stage miss -profile glsl_460+GL_EXT_ray_tracing +//TEST:SIMPLE(filecheck=SPIRV):-target spirv-assembly -emit-spirv-via-glsl -entry main -stage miss -profile glsl_460+GL_EXT_ray_tracing -emit-spirv-via-glsl // Motion rays not supported on HLSL impl currently, so disable with NOMOTION define: //TEST:SIMPLE(filecheck=DXIL):-target dxil-assembly -entry main -stage miss -profile sm_6_5 -DNOMOTION diff --git a/tests/hlsl-intrinsic/ray-tracing/rt-pipeline-intrinsics-rgen.slang b/tests/hlsl-intrinsic/ray-tracing/rt-pipeline-intrinsics-rgen.slang index ccad7bbd9..a6adc2475 100644 --- a/tests/hlsl-intrinsic/ray-tracing/rt-pipeline-intrinsics-rgen.slang +++ b/tests/hlsl-intrinsic/ray-tracing/rt-pipeline-intrinsics-rgen.slang @@ -1,4 +1,4 @@ -//TEST:SIMPLE(filecheck=SPIRV):-target spirv-assembly -entry main -stage raygeneration -profile glsl_460+GL_EXT_ray_tracing +//TEST:SIMPLE(filecheck=SPIRV):-target spirv-assembly -entry main -stage raygeneration -profile glsl_460+GL_EXT_ray_tracing -emit-spirv-via-glsl // Motion rays not supported on HLSL impl currently, so disable with NOMOTION define: //TEST:SIMPLE(filecheck=DXIL):-target dxil-assembly -entry main -stage raygeneration -profile sm_6_5 -DNOMOTION diff --git a/tests/pipeline/rasterization/mesh/hello.slang b/tests/pipeline/rasterization/mesh/hello.slang index 54a50079d..8a64805c0 100644 --- a/tests/pipeline/rasterization/mesh/hello.slang +++ b/tests/pipeline/rasterization/mesh/hello.slang @@ -2,16 +2,18 @@ // Test that a simple mesh shader compiles -//TEST:CROSS_COMPILE(filecheck=SPIRV):-target spirv-assembly -entry main -stage mesh -profile glsl_450+spirv_1_4 -//TEST:CROSS_COMPILE(filecheck=DXIL):-target dxil-assembly -entry main -stage mesh -profile sm_6_6 +//TEST:SIMPLE(filecheck=SPIRV):-target spirv-assembly -entry main -stage mesh -profile glsl_450+spirv_1_4 +//TEST:SIMPLE(filecheck=DXIL):-target dxil-assembly -entry main -stage mesh -profile sm_6_6 // DXIL: call void @dx.op.setMeshOutputCounts // DXIL: call void @dx.op.storeVertexOutput.f32 // DXIL: call void @dx.op.emitIndices // SPIRV: OpEntryPoint MeshEXT %main -// SPIRV: OpExecutionMode %main OutputVertices 3 -// SPIRV: OpExecutionMode %main OutputPrimitivesNV 1 -// SPIRV: OpExecutionMode %main OutputTrianglesNV + +// SPIRV-DAG: OpExecutionMode %main OutputVertices 3 +// SPIRV-DAG: OpExecutionMode %main OutputPrimitivesNV 1 +// SPIRV-DAG: OpExecutionMode %main OutputTrianglesNV + // SPIRV: OpSetMeshOutputsEXT const static float2 positions[3] = { diff --git a/tests/pipeline/rasterization/mesh/primitive-output.slang b/tests/pipeline/rasterization/mesh/primitive-output.slang index c83574d85..683fe19d1 100644 --- a/tests/pipeline/rasterization/mesh/primitive-output.slang +++ b/tests/pipeline/rasterization/mesh/primitive-output.slang @@ -2,7 +2,6 @@ // Test that a simple mesh shader compiles -//TEST:CROSS_COMPILE:-target spirv -profile glsl_450+spirv_1_4 -entry main -stage mesh //TEST:SIMPLE(filecheck=SPV_CHECK):-target spirv -profile glsl_450+spirv_1_4 -entry main -stage mesh //SPV_CHECK-NOT: SPV_NV_mesh_shader diff --git a/tests/slang-extension/atomic-float-byte-address-buffer-cross.slang b/tests/slang-extension/atomic-float-byte-address-buffer-cross.slang index 307394e1a..f7ae69365 100644 --- a/tests/slang-extension/atomic-float-byte-address-buffer-cross.slang +++ b/tests/slang-extension/atomic-float-byte-address-buffer-cross.slang @@ -1,6 +1,7 @@ // atomic-float-byte-address-buffer-cross.slang -//TEST:SIMPLE(filecheck=CHECK): -profile cs_6_5 -entry computeMain -target spirv-assembly +//TEST:SIMPLE(filecheck=CHECK_SPV): -profile cs_6_5 -entry computeMain -target spirv-assembly +//TEST:SIMPLE(filecheck=CHECK): -profile cs_6_5 -entry computeMain -target spirv-assembly -emit-spirv-via-glsl // We can't do this test, because it relies on nvAPI //DISABLE_TEST:CROSS_COMPILE: -profile cs_6_5 -entry computeMain -target dxil diff --git a/tests/vkray/anyhit.slang b/tests/vkray/anyhit.slang index 4cbff4a17..eebc2405d 100644 --- a/tests/vkray/anyhit.slang +++ b/tests/vkray/anyhit.slang @@ -5,7 +5,7 @@ // where we cannot infer the required SPIR-V version from the code // (and glslang doesn't include any such inference ability). -//TEST:SIMPLE(filecheck=CHECK): -profile glsl_460+spirv_1_4 -stage anyhit -entry main -target spirv-assembly +//TEST:SIMPLE(filecheck=CHECK): -profile glsl_460+spirv_1_4 -stage anyhit -entry main -target spirv-assembly -emit-spirv-via-glsl struct SphereHitAttributes { diff --git a/tests/vkray/callable.slang b/tests/vkray/callable.slang index 0f96266f6..711175e4d 100644 --- a/tests/vkray/callable.slang +++ b/tests/vkray/callable.slang @@ -1,6 +1,6 @@ // callable.slang -//TEST:SIMPLE(filecheck=CHECK): -profile glsl_460+spirv_1_4 -stage callable -entry main -target spirv-assembly +//TEST:SIMPLE(filecheck=CHECK): -profile glsl_460+spirv_1_4 -stage callable -entry main -target spirv-assembly -emit-spirv-via-glsl import callable_shared; diff --git a/tools/slang-test/options.cpp b/tools/slang-test/options.cpp index 3fb71dd4a..895b7e2bb 100644 --- a/tools/slang-test/options.cpp +++ b/tools/slang-test/options.cpp @@ -290,9 +290,9 @@ static bool _isSubCommand(const char* arg) { optionsOut->skipApiDetection = true; } - else if (strcmp(arg, "-emit-spirv-directly") == 0) + else if (strcmp(arg, "-emit-spirv-via-glsl") == 0) { - optionsOut->emitSPIRVDirectly = true; + optionsOut->emitSPIRVDirectly = false; } else if (strcmp(arg, "-expected-failure-list") == 0) { diff --git a/tools/slang-test/options.h b/tools/slang-test/options.h index 398334e46..ae4d02234 100644 --- a/tools/slang-test/options.h +++ b/tools/slang-test/options.h @@ -115,7 +115,7 @@ struct Options // Maximum number of test servers to run. int serverCount = 1; - bool emitSPIRVDirectly = false; + bool emitSPIRVDirectly = true; Slang::HashSet<Slang::String> expectedFailureList; diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp index eca103339..28e9e6e2e 100644 --- a/tools/slang-test/slang-test-main.cpp +++ b/tools/slang-test/slang-test-main.cpp @@ -2643,6 +2643,7 @@ static TestResult generateExpectedOutput(TestContext* const context, const TestI default: { expectedCmdLine.addArg(filePath + ".glsl"); + expectedCmdLine.addArg("-emit-spirv-via-glsl"); expectedCmdLine.addArg("-pass-through"); expectedCmdLine.addArg("glslang"); break; @@ -2688,6 +2689,7 @@ TestResult generateActualOutput(TestContext* const context, const TestInput& inp CommandLine actualCmdLine; _initSlangCompiler(context, actualCmdLine); actualCmdLine.addArg(filePath); + actualCmdLine.addArg("-emit-spirv-via-glsl"); const auto& args = input.testOptions->args; @@ -3029,9 +3031,9 @@ static void _addRenderTestOptions(const Options& options, CommandLine& ioCmdLine ioCmdLine.addArg("-adapter"); ioCmdLine.addArg(options.adapter); } - if (options.emitSPIRVDirectly) + if (!options.emitSPIRVDirectly) { - ioCmdLine.addArg("-emit-spirv-directly"); + ioCmdLine.addArg("-emit-spirv-via-glsl"); } } |
