diff --git a/Test/baseResults/constFold.frag.out b/Test/baseResults/constFold.frag.out index f5c3e9c571cd80889f7597a456f595234aac7655..2e784688035c8bfaacd9252e895119625c035004 100644 --- a/Test/baseResults/constFold.frag.out +++ b/Test/baseResults/constFold.frag.out @@ -374,6 +374,18 @@ ERROR: node is still EOpNull! 0:? 1 (const int) 0:? 9.000000 0:? false (const bool) +0:? 'cval1' (const bool) +0:? true (const bool) +0:? 'cval2' (const bool) +0:? false (const bool) +0:? 'cval3' (const bool) +0:? false (const bool) +0:? 'cval4' (const bool) +0:? true (const bool) +0:? 'cval5' (const bool) +0:? false (const bool) +0:? 'cval6' (const bool) +0:? true (const bool) Linked fragment stage: @@ -744,4 +756,16 @@ ERROR: node is still EOpNull! 0:? 1 (const int) 0:? 9.000000 0:? false (const bool) +0:? 'cval1' (const bool) +0:? true (const bool) +0:? 'cval2' (const bool) +0:? false (const bool) +0:? 'cval3' (const bool) +0:? false (const bool) +0:? 'cval4' (const bool) +0:? true (const bool) +0:? 'cval5' (const bool) +0:? false (const bool) +0:? 'cval6' (const bool) +0:? true (const bool) diff --git a/Test/constFold.frag b/Test/constFold.frag index 97c3b2b6b5404a2532964d5a5e81e620fb79ef64..730607885cc087eb376979998d35d071545a084c 100644 --- a/Test/constFold.frag +++ b/Test/constFold.frag @@ -138,4 +138,11 @@ const cag a0[3] = cag[3](cag(3, 2.0, true), cag(1, 5.0, true), cag(1, 9.0, false void foo4() { int a = int(a0[2].f); -} \ No newline at end of file +} + +const bool cval1 = all(bvec4(true, true, true, true)); +const bool cval2 = all(bvec4(false, false, false, false)); +const bool cval3 = all(bvec4(true, true, false, true)); +const bool cval4 = any(bvec4(true, true, true, true)); +const bool cval5 = any(bvec4(false, false, false, false)); +const bool cval6 = any(bvec4(false, true, false, false)); diff --git a/glslang/MachineIndependent/Constant.cpp b/glslang/MachineIndependent/Constant.cpp index 03033bce821cac2334f1c19d3d7dbbc3347488c0..4adfd4704ef8d05aff25388a8730bb364e325da5 100644 --- a/glslang/MachineIndependent/Constant.cpp +++ b/glslang/MachineIndependent/Constant.cpp @@ -399,6 +399,27 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TType& returnType) break; } + case EOpAny: + { + bool result = false; + for (int i = 0; i < objectSize; i++) { + if (unionArray[i].getBConst()) + result = true; + } + newConstArray[0].setBConst(result); + break; + } + case EOpAll: + { + bool result = true; + for (int i = 0; i < objectSize; i++) { + if (! unionArray[i].getBConst()) + result = false; + } + newConstArray[0].setBConst(result); + break; + } + // TODO: 3.0 Functionality: unary constant folding: the rest of the ops have to be fleshed out case EOpPackSnorm2x16: @@ -412,11 +433,8 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TType& returnType) case EOpDeterminant: case EOpMatrixInverse: case EOpTranspose: - - case EOpAny: - case EOpAll: return 0; - + default: assert(componentWise); break;