From 2051815bcc1ce26d9123d48d7c28762aa2c46f07 Mon Sep 17 00:00:00 2001 From: John Kessenich <cepheus@frii.com> Date: Wed, 12 Apr 2017 14:56:52 -0600 Subject: [PATCH] HLSL: Fix #803: Add shape conversions to the constant-initializer path. --- Test/baseResults/hlsl.shapeConv.frag.out | 27 ++++++++++++++++++------ Test/hlsl.shapeConv.frag | 4 +++- glslang/Include/revision.h | 2 +- hlsl/hlslParseHelper.cpp | 5 ++++- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/Test/baseResults/hlsl.shapeConv.frag.out b/Test/baseResults/hlsl.shapeConv.frag.out index 775549f13..a26b81927 100755 --- a/Test/baseResults/hlsl.shapeConv.frag.out +++ b/Test/baseResults/hlsl.shapeConv.frag.out @@ -108,8 +108,14 @@ gl_FragCoord origin is upper left 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:33 Branch: Return with expression +0:33 component-wise multiply ( temp 4-component vector of float) +0:33 'input' ( in 4-component vector of float) +0:33 Constant: +0:33 3.000000 +0:33 3.000000 +0:33 3.000000 +0:33 3.000000 0:? Linker Objects @@ -226,13 +232,19 @@ gl_FragCoord origin is upper left 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:33 Branch: Return with expression +0:33 component-wise multiply ( temp 4-component vector of float) +0:33 'input' ( in 4-component vector of float) +0:33 Constant: +0:33 3.000000 +0:33 3.000000 +0:33 3.000000 +0:33 3.000000 0:? Linker Objects // Module Version 10000 // Generated by (magic number): 80001 -// Id's are bound by 85 +// Id's are bound by 88 Capability Shader 1: ExtInstImport "GLSL.std.450" @@ -282,6 +294,8 @@ gl_FragCoord origin is upper left 56: TypeInt 32 0 57: 56(int) Constant 0 62: TypeVector 41(bool) 4 + 83: 6(float) Constant 1077936128 + 84: 7(fvec4) ConstantComposite 83 83 83 83 4(main): 2 Function None 3 5: Label Return @@ -343,5 +357,6 @@ gl_FragCoord origin is upper left 80: 6(float) Load 70(f1) 81: 22(fvec3) CompositeConstruct 80 80 80 82: 7(fvec4) Load 11(input) - ReturnValue 82 + 85: 7(fvec4) FMul 82 84 + ReturnValue 85 FunctionEnd diff --git a/Test/hlsl.shapeConv.frag b/Test/hlsl.shapeConv.frag index adb170eab..16a204574 100644 --- a/Test/hlsl.shapeConv.frag +++ b/Test/hlsl.shapeConv.frag @@ -28,5 +28,7 @@ float4 PixelShaderFunction(float4 input, float f) : COLOR0 f1.x; f1.xxx; - return input; + const float4 f4 = 3.0; + + return input * f4; } diff --git a/glslang/Include/revision.h b/glslang/Include/revision.h index 73ac8a611..5c9566b81 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.1995" +#define GLSLANG_REVISION "Overload400-PrecQual.1996" #define GLSLANG_DATE "12-Apr-2017" diff --git a/hlsl/hlslParseHelper.cpp b/hlsl/hlslParseHelper.cpp index a92ecdf61..a2a490ca7 100755 --- a/hlsl/hlslParseHelper.cpp +++ b/hlsl/hlslParseHelper.cpp @@ -6438,7 +6438,10 @@ TIntermNode* HlslParseContext::executeInitializer(const TSourceLoc& loc, TInterm // Compile-time tagging of the variable with its constant value... initializer = intermediate.addConversion(EOpAssign, variable->getType(), initializer); - if (! initializer || ! initializer->getAsConstantUnion() || variable->getType() != initializer->getType()) { + if (initializer != nullptr && variable->getType() != initializer->getType()) + initializer = intermediate.addShapeConversion(EOpAssign, variable->getType(), initializer); + if (initializer == nullptr || !initializer->getAsConstantUnion() || + variable->getType() != initializer->getType()) { error(loc, "non-matching or non-convertible constant type for const initializer", variable->getType().getStorageQualifierString(), ""); variable->getWritableType().getQualifier().storage = EvqTemporary; -- GitLab