From 76652fa43813d2c4b2ec8ea53d903a9cc892c1f6 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Wed, 23 May 2018 12:35:43 -0400 Subject: When outputing a vector type with a size of 1 in GLSL, it needs to be output as the underlying type. For example vector should be output as float in GLSL. (#572) --- source/slang/emit.cpp | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'source') diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index edb5d5cb2..a6460bf10 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -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; -- cgit v1.2.3