Skip to content

Commit

Permalink
When outputing a vector type with a size of 1 in GLSL, it needs to be…
Browse files Browse the repository at this point in the history
… output as the underlying type. For example vector<float,1> should be output as float in GLSL. (#572)
  • Loading branch information
jsmall-zzz authored and Tim Foley committed May 23, 2018
1 parent 10190da commit 76652fa
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions source/slang/emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -972,9 +972,36 @@ struct EmitVisitor
case CodeGenTarget::GLSL_Vulkan:
case CodeGenTarget::GLSL_Vulkan_OneDesc:
{
emitGLSLTypePrefix(vecType->getElementType());
Emit("vec");
EmitVal(vecType->getElementCount());
// Need to special case if there is a single element in the vector
// as there is no such thing in glsl as vec1
IRInst* elementCountInst = vecType->getElementCount();

if (elementCountInst->op != kIROp_IntLit)
{
SLANG_DIAGNOSE_UNEXPECTED(getSink(), SourceLoc(), "Expecting an integral size for vector size");
return;
}

const IRConstant* irConst = (const IRConstant*)elementCountInst;
const IRIntegerValue elementCount = irConst->u.intVal;
if (elementCount <= 0)
{
SLANG_DIAGNOSE_UNEXPECTED(getSink(), SourceLoc(), "Vector size must be greater than 0");
return;
}

auto* elementType = vecType->getElementType();

if (elementCount > 1)
{
emitGLSLTypePrefix(elementType);
Emit("vec");
emit(elementCount);
}
else
{
emitSimpleTypeImpl(elementType);
}
}
break;

Expand Down

0 comments on commit 76652fa

Please sign in to comment.