@Test public void misc4() throws Exception { final String shader = "void f()\n" + "{\n" + " vec4 GLF_merged3_0_1_1_1_1_1_3_1_1abc;\n" + " GLF_merged3_0_1_1_1_1_1_3_1_1abc.x = 2.0;\n" + " GLF_merged3_0_1_1_1_1_1_3_1_1abc.y = 3.0;\n" + " GLF_merged3_0_1_1_1_1_1_3_1_1abc.w = 1.0;\n" + "}\n"; final String expected1 = "void f()\n" + "{\n" + " float a;\n" + " vec4 GLF_merged3_0_1_1_1_1_1_3_1_1abc;\n" + " a = 2.0;\n" + " GLF_merged3_0_1_1_1_1_1_3_1_1abc.y = 3.0;\n" + " GLF_merged3_0_1_1_1_1_1_3_1_1abc.w = 1.0;\n" + "}\n"; final String expected2 = "void f()\n" + "{\n" + " float c;\n" + " float a;\n" + " vec4 GLF_merged3_0_1_1_1_1_1_3_1_1abc;\n" + " a = 2.0;\n" + " GLF_merged3_0_1_1_1_1_1_3_1_1abc.y = 3.0;\n" + " c = 1.0;\n" + "}\n"; final String expected3 = "void f()\n" + "{\n" + " float b;\n" + " float c;\n" + " float a;\n" + " vec4 GLF_merged3_0_1_1_1_1_1_3_1_1abc;\n" + " a = 2.0;\n" + " b = 3.0;\n" + " c = 1.0;\n" + "}\n"; final TranslationUnit tu = ParseHelper.parse(shader); final IRandom cannedRandom = new CannedRandom(2); final List<VectorizationReductionOpportunity> ops = VectorizationReductionOpportunities .findOpportunities(MakeShaderJobFromFragmentShader.make(tu), new ReducerContext(false, ShadingLanguageVersion.GLSL_440, cannedRandom, new IdGenerator())); ops.stream().filter(item -> item.getComponentName().equals("a")).findAny().get() .applyReduction(); assertEquals(PrettyPrinterVisitor.prettyPrintAsString(ParseHelper.parse(expected1)), PrettyPrinterVisitor.prettyPrintAsString(tu)); ops.stream().filter(item -> item.getComponentName().equals("c")).findAny().get() .applyReduction(); assertEquals(PrettyPrinterVisitor.prettyPrintAsString(ParseHelper.parse(expected2)), PrettyPrinterVisitor.prettyPrintAsString(tu)); ops.stream().filter(item -> item.getComponentName().equals("b")).findAny().get() .applyReduction(); assertEquals(PrettyPrinterVisitor.prettyPrintAsString(ParseHelper.parse(expected3)), PrettyPrinterVisitor.prettyPrintAsString(tu)); }
static List<VectorizationReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); }
VectorizationReductionOpportunities extends ReductionOpportunitiesBase<VectorizationReductionOpportunity> { static List<VectorizationReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } }
VectorizationReductionOpportunities extends ReductionOpportunitiesBase<VectorizationReductionOpportunity> { static List<VectorizationReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  VectorizationReductionOpportunities(
        TranslationUnit tu,
        ReducerContext context); }
VectorizationReductionOpportunities extends ReductionOpportunitiesBase<VectorizationReductionOpportunity> { static List<VectorizationReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  VectorizationReductionOpportunities(
        TranslationUnit tu,
        ReducerContext context); @Override void visitVariablesDeclaration(VariablesDeclaration variablesDeclaration); @Override void visitVariableDeclInfo(VariableDeclInfo variableDeclInfo); }
VectorizationReductionOpportunities extends ReductionOpportunitiesBase<VectorizationReductionOpportunity> { static List<VectorizationReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item, context)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  VectorizationReductionOpportunities(
        TranslationUnit tu,
        ReducerContext context); @Override void visitVariablesDeclaration(VariablesDeclaration variablesDeclaration); @Override void visitVariableDeclInfo(VariableDeclInfo variableDeclInfo);  }