From a4261598be7e3229a6280002eaced96d8cb3ced6 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 23 Jan 2019 19:54:21 -0800 Subject: Fixing GLSL sign function. fixes #602 --- source/slang/emit.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'source/slang/emit.cpp') diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index 0aebf6153..914aea7fd 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -3488,7 +3488,23 @@ struct EmitVisitor emit("."); operandIndex++; } - + // fixing issue #602 for GLSL sign function: https://github.com/shader-slang/slang/issues/602 + bool glslSignFix = ctx->shared->target == CodeGenTarget::GLSL && name == "sign"; + if (glslSignFix) + { + if (auto vectorType = as(inst->getDataType())) + { + emit("ivec"); + emit(as(vectorType->getElementCount())->value.intVal); + emit("("); + } + else if (auto scalarType = as(inst->getDataType())) + { + emit("int("); + } + else + glslSignFix = false; + } emit(name); emit("("); bool first = true; @@ -3499,7 +3515,8 @@ struct EmitVisitor first = false; } emit(")"); - + if (glslSignFix) + emit(")"); maybeCloseParens(needClose); } -- cgit v1.2.3