diff options
| -rw-r--r-- | source/slang/slang-check-conversion.cpp | 2 | ||||
| -rw-r--r-- | source/slang/slang-check-decl.cpp | 12 | ||||
| -rw-r--r-- | source/slang/slang-check-impl.h | 3 | ||||
| -rw-r--r-- | tests/bugs/half-coercion.slang | 10 |
4 files changed, 26 insertions, 1 deletions
diff --git a/source/slang/slang-check-conversion.cpp b/source/slang/slang-check-conversion.cpp index 0c06fb113..74151a4bb 100644 --- a/source/slang/slang-check-conversion.cpp +++ b/source/slang/slang-check-conversion.cpp @@ -1327,7 +1327,7 @@ bool SemanticsVisitor::_coerce( // For general types of implicit conversions, we issue a warning, unless `fromExpr` // is a known constant and we know it won't cause a problem. bool shouldEmitGeneralWarning = true; - if (isScalarIntegerType(toType)) + if (isScalarIntegerType(toType) || isHalfType(toType)) { if (auto intVal = tryFoldIntegerConstantExpression( fromExpr, diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index eeb75e3fd..a666d9df3 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -7421,6 +7421,15 @@ bool SemanticsVisitor::isScalarIntegerType(Type* type) return isIntegerBaseType(baseType) || baseType == BaseType::Bool; } +bool SemanticsVisitor::isHalfType(Type* type) +{ + auto basicType = as<BasicExpressionType>(type); + if (!basicType) + return false; + auto baseType = basicType->getBaseType(); + return baseType == BaseType::Half; +} + bool SemanticsVisitor::isValidCompileTimeConstantType(Type* type) { return isScalarIntegerType(type) || isEnumType(type); @@ -7466,6 +7475,9 @@ bool SemanticsVisitor::isIntValueInRangeOfType(IntegerLiteralValue value, Type* #endif return value >= std::numeric_limits<int64_t>::min() && value <= std::numeric_limits<int64_t>::max(); + + case BaseType::Half: + return value >= -2048 && value <= 2048; default: return false; } diff --git a/source/slang/slang-check-impl.h b/source/slang/slang-check-impl.h index 460e87cb9..0dfa75631 100644 --- a/source/slang/slang-check-impl.h +++ b/source/slang/slang-check-impl.h @@ -1967,6 +1967,9 @@ public: /// Is `type` a scalar integer type. bool isScalarIntegerType(Type* type); + /// Is `type` a scalar half type. + bool isHalfType(Type* type); + /// Is `type` something we allow as compile time constants, i.e. scalar integer and enum types. bool isValidCompileTimeConstantType(Type* type); diff --git a/tests/bugs/half-coercion.slang b/tests/bugs/half-coercion.slang new file mode 100644 index 000000000..43a12cf89 --- /dev/null +++ b/tests/bugs/half-coercion.slang @@ -0,0 +1,10 @@ +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): -target spirv + +// CHECK-NOT: warning + +RWStructuredBuffer<half> output; +[numthreads(1,1,1)] +void computeMain() +{ + output[0] = 0; // coercion from 0 to half should not result in a warning. +}
\ No newline at end of file |
