summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2018-05-23 12:35:43 -0400
committerTim Foley <tfoleyNV@users.noreply.github.com>2018-05-23 09:35:43 -0700
commit76652fa43813d2c4b2ec8ea53d903a9cc892c1f6 (patch)
treec3b3d19f78f7fb3eaeb16f74fca21909a57c6e26 /source
parent10190da440cd1c85c62c3d537f83893802deaff6 (diff)
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. (#572)
Diffstat (limited to 'source')
-rw-r--r--source/slang/emit.cpp33
1 files changed, 30 insertions, 3 deletions
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;