Skip to content

Commit 76652fa

Browse files
jsmall-zzzTim Foley
authored and
Tim Foley
committed
When outputing a vector type with a size of 1 in GLSL, it needs to be output as the underlying type. For example vector<float,1> should be output as float in GLSL. (shader-slang#572)
1 parent 10190da commit 76652fa

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

source/slang/emit.cpp

+30-3
Original file line numberDiff line numberDiff line change
@@ -972,9 +972,36 @@ struct EmitVisitor
972972
case CodeGenTarget::GLSL_Vulkan:
973973
case CodeGenTarget::GLSL_Vulkan_OneDesc:
974974
{
975-
emitGLSLTypePrefix(vecType->getElementType());
976-
Emit("vec");
977-
EmitVal(vecType->getElementCount());
975+
// Need to special case if there is a single element in the vector
976+
// as there is no such thing in glsl as vec1
977+
IRInst* elementCountInst = vecType->getElementCount();
978+
979+
if (elementCountInst->op != kIROp_IntLit)
980+
{
981+
SLANG_DIAGNOSE_UNEXPECTED(getSink(), SourceLoc(), "Expecting an integral size for vector size");
982+
return;
983+
}
984+
985+
const IRConstant* irConst = (const IRConstant*)elementCountInst;
986+
const IRIntegerValue elementCount = irConst->u.intVal;
987+
if (elementCount <= 0)
988+
{
989+
SLANG_DIAGNOSE_UNEXPECTED(getSink(), SourceLoc(), "Vector size must be greater than 0");
990+
return;
991+
}
992+
993+
auto* elementType = vecType->getElementType();
994+
995+
if (elementCount > 1)
996+
{
997+
emitGLSLTypePrefix(elementType);
998+
Emit("vec");
999+
emit(elementCount);
1000+
}
1001+
else
1002+
{
1003+
emitSimpleTypeImpl(elementType);
1004+
}
9781005
}
9791006
break;
9801007

0 commit comments

Comments
 (0)