Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions tools/clang/lib/SPIRV/SpirvEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2539,7 +2539,7 @@ SpirvInstruction *SpirvEmitter::getBaseOfMemberFunction(
SpirvInstruction *SpirvEmitter::processCall(const CallExpr *callExpr) {
const FunctionDecl *callee = getCalleeDefinition(callExpr);

// Note that we always want the defintion because Stmts/Exprs in the
// Note that we always want the definition because Stmts/Exprs in the
// function body references the parameters in the definition.
if (!callee) {
emitError("found undefined function", callExpr->getExprLoc());
Expand Down Expand Up @@ -2641,7 +2641,7 @@ SpirvInstruction *SpirvEmitter::processCall(const CallExpr *callExpr) {
const uint32_t argIndex = i + isOperatorOverloading;

// We want the argument variable here so that we can write back to it
// later. We will do the OpLoad of this argument manually. So ingore
// later. We will do the OpLoad of this argument manually. So ignore
// the LValueToRValue implicit cast here.
auto *arg = callExpr->getArg(argIndex)->IgnoreParenLValueCasts();
const auto *param = callee->getParamDecl(i);
Expand Down Expand Up @@ -7771,6 +7771,16 @@ SpirvInstruction *SpirvEmitter::castToFloat(SpirvInstruction *fromVal,
}

if (isFloatOrVecOfFloatType(fromType)) {
uint32_t fromCount = 0;
const bool fromIsVec = isVectorType(fromType, nullptr, &fromCount);
uint32_t toCount = 0;
const bool toIsVec = isVectorType(toFloatType, nullptr, &toCount);

if (fromIsVec != toIsVec || fromCount != toCount) {
emitError("casting from %0 to %1 unsupported", srcLoc) << fromType <<
toFloatType;
return nullptr;
}
// This is the case of float to float conversion with different bitwidths.
return convertBitwidth(fromVal, srcLoc, fromType, toFloatType, nullptr,
range);
Expand Down
18 changes: 18 additions & 0 deletions tools/clang/test/CodeGenSPIRV/cast.scalar-to-vec.implicit.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// RUN: %dxc -T cs_6_0 -E main

RWTexture2D<float> g_output;

void foo(inout float3 x)
{
x += float3(1, 2, 3);
}

// CHECK: error: casting from 'float' to 'float3' unsupported

[numthreads(1, 1, 1)]
void main(uint3 id : SV_DispatchThreadId)
{
float bar = 1;
foo(bar);
g_output[id.xy] = bar;
}
3 changes: 3 additions & 0 deletions tools/clang/unittests/SPIRV/CodeGenSpirvTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,9 @@ TEST_F(FileTest, CastFlatConversionLiteralInitializer) {
TEST_F(FileTest, CastFlatConversionDecomposeVector) {
runFileTest("cast.flat-conversion.vector.hlsl");
}
TEST_F(FileTest, CastImplicitScalarToVec) {
runFileTest("cast.scalar-to-vec.implicit.hlsl", Expect::Failure);
}
TEST_F(FileTest, CastExplicitVecToMat) {
runFileTest("cast.vec-to-mat.explicit.hlsl");
}
Expand Down