diff options
| author | Yong He <yonghe@outlook.com> | 2024-04-23 12:14:21 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-23 12:14:21 -0700 |
| commit | f1de1817ca10e34ec6a844100f10f0de3340c9f2 (patch) | |
| tree | 63e631a3c546107f450ab5153e630c5b4a0dc33a /source/slang/slang-emit-spirv.cpp | |
| parent | 0d9206855888d694e0b8f91be4524b57293773d6 (diff) | |
Switch to direct-to-spirv backend as default. (#4002)
* Switch to direct-to-spirv backend as default.
* Fix slang-test.
* Fix.
* Fix.
Diffstat (limited to 'source/slang/slang-emit-spirv.cpp')
| -rw-r--r-- | source/slang/slang-emit-spirv.cpp | 64 |
1 files changed, 35 insertions, 29 deletions
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)); |
