@@ -1867,7 +1867,7 @@ struct SPIRVEmitContext
1867
1867
setImageFormatCapabilityAndExtension(SpvImageFormatUnknown, SpvCapabilityShader);
1868
1868
return emitOpTypeImage(
1869
1869
assignee,
1870
- dropVector ((IRType*)sampledType),
1870
+ getVectorElementType ((IRType*)sampledType),
1871
1871
dim,
1872
1872
SpvLiteralInteger::from32(ImageOpConstants::unknownDepthImage),
1873
1873
SpvLiteralInteger::from32(0),
@@ -2018,12 +2018,12 @@ struct SPIRVEmitContext
2018
2018
//
2019
2019
// The op itself
2020
2020
//
2021
-
2021
+ auto sampledElementType = getSPIRVSampledElementType(sampledType);
2022
2022
if (inst->isCombined())
2023
2023
{
2024
2024
auto imageType = emitOpTypeImage(
2025
2025
nullptr,
2026
- dropVector((IRType*)sampledType) ,
2026
+ sampledElementType ,
2027
2027
dim,
2028
2028
SpvLiteralInteger::from32(depth),
2029
2029
SpvLiteralInteger::from32(arrayed),
@@ -2038,7 +2038,7 @@ struct SPIRVEmitContext
2038
2038
2039
2039
return emitOpTypeImage(
2040
2040
assignee,
2041
- dropVector((IRType*)sampledType) ,
2041
+ sampledElementType ,
2042
2042
dim,
2043
2043
SpvLiteralInteger::from32(depth),
2044
2044
SpvLiteralInteger::from32(arrayed),
@@ -4827,20 +4827,13 @@ struct SPIRVEmitContext
4827
4827
}
4828
4828
}
4829
4829
4830
- IRType* dropVector(IRType* t)
4831
- {
4832
- if(const auto v = as<IRVectorType>(t))
4833
- return v->getElementType();
4834
- return t;
4835
- };
4836
-
4837
4830
SpvInst* emitIntCast(SpvInstParent* parent, IRIntCast* inst)
4838
4831
{
4839
4832
const auto fromTypeV = inst->getOperand(0)->getDataType();
4840
4833
const auto toTypeV = inst->getDataType();
4841
4834
SLANG_ASSERT(!as<IRVectorType>(fromTypeV) == !as<IRVectorType>(toTypeV));
4842
- const auto fromType = dropVector (fromTypeV);
4843
- const auto toType = dropVector (toTypeV);
4835
+ const auto fromType = getVectorElementType (fromTypeV);
4836
+ const auto toType = getVectorElementType (toTypeV);
4844
4837
4845
4838
if (as<IRBoolType>(fromType))
4846
4839
{
@@ -4906,8 +4899,8 @@ struct SPIRVEmitContext
4906
4899
const auto fromTypeV = inst->getOperand(0)->getDataType();
4907
4900
const auto toTypeV = inst->getDataType();
4908
4901
SLANG_ASSERT(!as<IRVectorType>(fromTypeV) == !as<IRVectorType>(toTypeV));
4909
- const auto fromType = dropVector (fromTypeV);
4910
- const auto toType = dropVector (toTypeV);
4902
+ const auto fromType = getVectorElementType (fromTypeV);
4903
+ const auto toType = getVectorElementType (toTypeV);
4911
4904
SLANG_ASSERT(isFloatingType(fromType));
4912
4905
SLANG_ASSERT(isFloatingType(toType));
4913
4906
SLANG_ASSERT(!isTypeEqual(fromType, toType));
@@ -4920,8 +4913,8 @@ struct SPIRVEmitContext
4920
4913
const auto fromTypeV = inst->getOperand(0)->getDataType();
4921
4914
const auto toTypeV = inst->getDataType();
4922
4915
SLANG_ASSERT(!as<IRVectorType>(fromTypeV) == !as<IRVectorType>(toTypeV));
4923
- const auto fromType = dropVector (fromTypeV);
4924
- const auto toType = dropVector (toTypeV);
4916
+ const auto fromType = getVectorElementType (fromTypeV);
4917
+ const auto toType = getVectorElementType (toTypeV);
4925
4918
SLANG_ASSERT(isFloatingType(toType));
4926
4919
4927
4920
if (isIntegralType(fromType))
@@ -4956,8 +4949,8 @@ struct SPIRVEmitContext
4956
4949
const auto fromTypeV = inst->getOperand(0)->getDataType();
4957
4950
const auto toTypeV = inst->getDataType();
4958
4951
SLANG_ASSERT(!as<IRVectorType>(fromTypeV) == !as<IRVectorType>(toTypeV));
4959
- const auto fromType = dropVector (fromTypeV);
4960
- const auto toType = dropVector (toTypeV);
4952
+ const auto fromType = getVectorElementType (fromTypeV);
4953
+ const auto toType = getVectorElementType (toTypeV);
4961
4954
SLANG_ASSERT(isFloatingType(fromType));
4962
4955
4963
4956
if (as<IRBoolType>(toType))
@@ -5175,7 +5168,7 @@ struct SPIRVEmitContext
5175
5168
5176
5169
SpvInst* emitVectorOrScalarArithmetic(SpvInstParent* parent, IRInst* instToRegister, IRInst* type, IROp op, UInt operandCount, ArrayView<IRInst*> operands)
5177
5170
{
5178
- IRType* elementType = dropVector (operands[0]->getDataType());
5171
+ IRType* elementType = getVectorElementType (operands[0]->getDataType());
5179
5172
IRBasicType* basicType = as<IRBasicType>(elementType);
5180
5173
bool isFloatingPoint = false;
5181
5174
bool isBool = false;
@@ -5813,7 +5806,7 @@ struct SPIRVEmitContext
5813
5806
// Make a 4 vector of the component type
5814
5807
IRBuilder builder(m_irModule);
5815
5808
const auto elementType = cast<IRType>(operand->getValue());
5816
- const auto sampledType = builder.getVectorType(dropVector( elementType), 4);
5809
+ const auto sampledType = builder.getVectorType(getSPIRVSampledElementType(getVectorElementType( elementType) ), 4);
5817
5810
emitOperand(ensureInst(sampledType));
5818
5811
break;
5819
5812
}
@@ -5867,7 +5860,7 @@ struct SPIRVEmitContext
5867
5860
// Make a 4 vector of the component type
5868
5861
IRBuilder builder(m_irModule);
5869
5862
const auto elementType = cast<IRType>(operand->getValue());
5870
- return builder.getVectorType(dropVector (elementType), 4);
5863
+ return builder.getVectorType(getVectorElementType (elementType), 4);
5871
5864
}
5872
5865
case kIROp_SPIRVAsmOperandEnum:
5873
5866
case kIROp_SPIRVAsmOperandLiteral:
@@ -5884,9 +5877,22 @@ struct SPIRVEmitContext
5884
5877
const auto toIdOperand = spvInst->getSPIRVOperands()[1];
5885
5878
const auto fromType = getSlangType(spvInst->getSPIRVOperands()[2]);
5886
5879
const auto fromIdOperand = spvInst->getSPIRVOperands()[3];
5887
-
5888
- // The component types must be the same
5889
- SLANG_ASSERT(isTypeEqual(dropVector(toType), dropVector(fromType)));
5880
+ auto fromElementType = getSPIRVSampledElementType(fromType);
5881
+ SpvInst* fromSpvInst = nullptr;
5882
+ // If the component types are not the same, convert them to be so.
5883
+ if (!isTypeEqual(getVectorElementType(toType), fromElementType))
5884
+ {
5885
+ auto newFromType = replaceVectorElementType(fromType, getVectorElementType(toType));
5886
+ fromSpvInst = emitInstCustomOperandFunc(
5887
+ parent,
5888
+ nullptr,
5889
+ SpvOpFConvert,
5890
+ [&]() {
5891
+ emitOperand(newFromType);
5892
+ emitOperand(kResultID),
5893
+ emitSpvAsmOperand(fromIdOperand);
5894
+ });
5895
+ }
5890
5896
5891
5897
// If we don't need truncation, but a different result ID is
5892
5898
// expected, then just unify them in the idMap
@@ -5901,7 +5907,7 @@ struct SPIRVEmitContext
5901
5907
[&](){
5902
5908
emitOperand(toType);
5903
5909
emitSpvAsmOperand(toIdOperand);
5904
- emitSpvAsmOperand(fromIdOperand);
5910
+ fromSpvInst ? emitOperand(fromSpvInst) : emitSpvAsmOperand(fromIdOperand);
5905
5911
}
5906
5912
);
5907
5913
}
@@ -5915,7 +5921,7 @@ struct SPIRVEmitContext
5915
5921
[&](){
5916
5922
emitOperand(toType);
5917
5923
emitSpvAsmOperand(toIdOperand);
5918
- emitSpvAsmOperand(fromIdOperand);
5924
+ fromSpvInst ? emitOperand(fromSpvInst) : emitSpvAsmOperand(fromIdOperand);
5919
5925
emitOperand(SpvLiteralInteger::from32(0));
5920
5926
}
5921
5927
);
@@ -5930,7 +5936,7 @@ struct SPIRVEmitContext
5930
5936
[&](){
5931
5937
emitOperand(toType);
5932
5938
emitSpvAsmOperand(toIdOperand);
5933
- emitSpvAsmOperand(fromIdOperand);
5939
+ fromSpvInst ? emitOperand(fromSpvInst) : emitSpvAsmOperand(fromIdOperand);
5934
5940
}
5935
5941
);
5936
5942
}
@@ -5950,7 +5956,7 @@ struct SPIRVEmitContext
5950
5956
[&](){
5951
5957
emitOperand(toType);
5952
5958
emitSpvAsmOperand(toIdOperand);
5953
- emitSpvAsmOperand(fromIdOperand);
5959
+ fromSpvInst ? emitOperand(fromSpvInst) : emitSpvAsmOperand(fromIdOperand);
5954
5960
emitOperand(emitOpUndef(parent, nullptr, fromVector));
5955
5961
for(Int32 i = 0; i < toVectorSize; ++i)
5956
5962
emitOperand(SpvLiteralInteger::from32(i));
0 commit comments