From 7d01bd6f0be8a22bc9046e1e64dc20d12fe8d0cc Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Fri, 2 Sep 2016 22:21:25 -0600 Subject: [PATCH] HLSL: Handle swizzles on vectors of size 1. Addresses issue #453. --- Test/baseResults/hlsl.shapeConv.frag.out | 27 ++++++++++++++++++++------- Test/hlsl.shapeConv.frag | 2 ++ glslang/Include/revision.h | 2 +- glslang/MachineIndependent/Intermediate.cpp | 3 ++- hlsl/hlslParseHelper.cpp | 9 +++++++++ 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/Test/baseResults/hlsl.shapeConv.frag.out b/Test/baseResults/hlsl.shapeConv.frag.out index cbf6228..c7fdf8d 100755 --- a/Test/baseResults/hlsl.shapeConv.frag.out +++ b/Test/baseResults/hlsl.shapeConv.frag.out @@ -101,8 +101,13 @@ gl_FragCoord origin is upper left 0:27 Construct float (temp 1-component vector of float) 0:27 'v' (temp 4-component vector of float) 0:27 'f1' (temp 1-component vector of float) -0:29 Branch: Return with expression -0:29 'input' (in 4-component vector of float) +0:28 Construct float (temp float) +0:28 'f1' (temp 1-component vector of float) +0:29 Construct vec3 (temp 3-component vector of float) +0:29 Construct float (temp float) +0:29 'f1' (temp 1-component vector of float) +0:31 Branch: Return with expression +0:31 'input' (in 4-component vector of float) 0:? Linker Objects @@ -211,13 +216,18 @@ gl_FragCoord origin is upper left 0:27 Construct float (temp 1-component vector of float) 0:27 'v' (temp 4-component vector of float) 0:27 'f1' (temp 1-component vector of float) -0:29 Branch: Return with expression -0:29 'input' (in 4-component vector of float) +0:28 Construct float (temp float) +0:28 'f1' (temp 1-component vector of float) +0:29 Construct vec3 (temp 3-component vector of float) +0:29 Construct float (temp float) +0:29 'f1' (temp 1-component vector of float) +0:31 Branch: Return with expression +0:31 'input' (in 4-component vector of float) 0:? Linker Objects // Module Version 10000 // Generated by (magic number): 80001 -// Id's are bound by 81 +// Id's are bound by 84 Capability Shader 1: ExtInstImport "GLSL.std.450" @@ -321,6 +331,9 @@ gl_FragCoord origin is upper left 75: 6(float) CompositeExtract 74 0 76: 6(float) Load 69(f1) 77: 41(bool) FOrdLessThan 75 76 - 78: 7(fvec4) Load 11(input) - ReturnValue 78 + 78: 6(float) Load 69(f1) + 79: 6(float) Load 69(f1) + 80: 22(fvec3) CompositeConstruct 79 79 79 + 81: 7(fvec4) Load 11(input) + ReturnValue 81 FunctionEnd diff --git a/Test/hlsl.shapeConv.frag b/Test/hlsl.shapeConv.frag index 3ecb33a..0485b4a 100644 --- a/Test/hlsl.shapeConv.frag +++ b/Test/hlsl.shapeConv.frag @@ -25,6 +25,8 @@ float4 PixelShaderFunction(float4 input, float f) : COLOR0 f1 == v; v < f1; + f1.x; + f1.xxx; return input; } diff --git a/glslang/Include/revision.h b/glslang/Include/revision.h index 86b4ab8..bd0738d 100644 --- a/glslang/Include/revision.h +++ b/glslang/Include/revision.h @@ -2,5 +2,5 @@ // For the version, it uses the latest git tag followed by the number of commits. // For the date, it uses the current date (when then script is run). -#define GLSLANG_REVISION "Overload400-PrecQual.1464" +#define GLSLANG_REVISION "Overload400-PrecQual.1465" #define GLSLANG_DATE "02-Sep-2016" diff --git a/glslang/MachineIndependent/Intermediate.cpp b/glslang/MachineIndependent/Intermediate.cpp index 3a5a3f6..676cf17 100644 --- a/glslang/MachineIndependent/Intermediate.cpp +++ b/glslang/MachineIndependent/Intermediate.cpp @@ -274,7 +274,8 @@ TIntermTyped* TIntermediate::addUnaryMath(TOperator op, TIntermTyped* child, TSo if (newType != EbtVoid) { child = addConversion(op, TType(newType, EvqTemporary, child->getVectorSize(), child->getMatrixCols(), - child->getMatrixRows()), + child->getMatrixRows(), + child->isVector()), child); if (child == 0) return 0; diff --git a/hlsl/hlslParseHelper.cpp b/hlsl/hlslParseHelper.cpp index f74591c..d8a9a8d 100755 --- a/hlsl/hlslParseHelper.cpp +++ b/hlsl/hlslParseHelper.cpp @@ -641,6 +641,15 @@ TIntermTyped* HlslParseContext::handleDotDereference(const TSourceLoc& loc, TInt return addConstructor(loc, base, type); } } + if (base->getVectorSize() == 1) { + TType scalarType(base->getBasicType(), EvqTemporary, 1); + if (fields.num == 1) + return addConstructor(loc, base, scalarType); + else { + TType vectorType(base->getBasicType(), EvqTemporary, fields.num); + return addConstructor(loc, addConstructor(loc, base, scalarType), vectorType); + } + } if (base->getType().getQualifier().isFrontEndConstant()) result = intermediate.foldSwizzle(base, fields, loc); -- 2.7.4