summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorJerran Schmidt <jerrans@nvidia.com>2025-06-27 02:33:16 +1000
committerGitHub <noreply@github.com>2025-06-26 16:33:16 +0000
commit83c7b7c7716c31596d9e2829d4afa708ce23a182 (patch)
treef2a152b41273399e015d476aaca60278fa10928c /source
parentbf94fc3f5b73033334db28846580f16df42d6a85 (diff)
Fix for OpUConvert producing invalid opcode when to/from signs differ (#7398)
* Fix for OpUConvert outputting scalar type for mixed sign vector type conversions * Fix compiler warning * Added regression test for UConvert vector fix * Formatting * getUnsignedType helper * Formatting * Fix for addtional int types * Helper function to convert signed type to unsigned type
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-emit-spirv.cpp8
-rw-r--r--source/slang/slang-ir-util.cpp39
-rw-r--r--source/slang/slang-ir-util.h2
3 files changed, 44 insertions, 5 deletions
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp
index 7bd20649b..82fb39d7d 100644
--- a/source/slang/slang-emit-spirv.cpp
+++ b/source/slang/slang-emit-spirv.cpp
@@ -7319,11 +7319,9 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
// Perform unsigned conversion first to an unsigned integer of the same width as the
// result then perform bit cast to the signed result type. This is done because SPIRV's
// unsigned conversion (`OpUConvert`) requires result type to be unsigned.
- auto unsignedV = emitOpUConvert(
- parent,
- nullptr,
- builder.getType(getOppositeSignIntTypeOp(toType->getOp())),
- inst->getOperand(0));
+ auto builderType = getUnsignedTypeFromSignedType(&builder, toTypeV);
+
+ auto unsignedV = emitOpUConvert(parent, nullptr, builderType, inst->getOperand(0));
return emitOpBitcast(parent, inst, toTypeV, unsignedV);
}
else if (fromInfo.isSigned)
diff --git a/source/slang/slang-ir-util.cpp b/source/slang/slang-ir-util.cpp
index a2ec15661..497281114 100644
--- a/source/slang/slang-ir-util.cpp
+++ b/source/slang/slang-ir-util.cpp
@@ -2348,6 +2348,45 @@ bool isInstHoistable(IROp op, IRType* type, IRInst* const* fixedArgs)
isSpecConstOpHoistable(op, type, fixedArgs);
}
+IRType* getUnsignedTypeFromSignedType(IRBuilder* builder, IRType* type)
+{
+ SLANG_RELEASE_ASSERT(isSignedType(type));
+
+ auto elementType = getVectorOrCoopMatrixElementType(type);
+
+ IROp op = type->getOp();
+ switch (op)
+ {
+ case kIROp_MatrixType:
+ {
+ auto unsignedTypeOp = getOppositeSignIntTypeOp(elementType->getOp());
+ auto matType = as<IRMatrixType>(type);
+ SLANG_RELEASE_ASSERT(matType);
+ return builder->getMatrixType(
+ builder->getType(unsignedTypeOp),
+ matType->getRowCount(),
+ matType->getColumnCount(),
+ matType->getLayout());
+ }
+ case kIROp_VectorType:
+ {
+ auto unsignedTypeOp = getOppositeSignIntTypeOp(elementType->getOp());
+ auto vecType = as<IRVectorType>(type);
+ SLANG_RELEASE_ASSERT(vecType);
+ return builder->getVectorType(
+ builder->getType(unsignedTypeOp),
+ vecType->getElementCount());
+ }
+ case kIROp_IntType:
+ case kIROp_Int16Type:
+ case kIROp_Int64Type:
+ case kIROp_Int8Type:
+ return builder->getType(getOppositeSignIntTypeOp(elementType->getOp()));
+ default:
+ return type;
+ }
+}
+
bool isSignedType(IRType* type)
{
switch (type->getOp())
diff --git a/source/slang/slang-ir-util.h b/source/slang/slang-ir-util.h
index dccdf5457..edb8fdf09 100644
--- a/source/slang/slang-ir-util.h
+++ b/source/slang/slang-ir-util.h
@@ -418,6 +418,8 @@ constexpr bool anyOf(Range&& range, Predicate&& pred)
return false;
}
+IRType* getUnsignedTypeFromSignedType(IRBuilder* builder, IRType* type);
+
bool isSignedType(IRType* type);
} // namespace Slang