@Test public void misc3() throws Exception { final String shader = "void f()\n" + "{\n" + " vec4 GLF_merged3_0_1_1_1_1_1_2_2_25PQGLF_merged2_0_1_1_1_1_1PQ;\n" + " GLF_merged3_0_1_1_1_1_1_2_2_25PQGLF_merged2_0_1_1_1_1_1PQ.x;\n" + " GLF_merged3_0_1_1_1_1_1_2_2_25PQGLF_merged2_0_1_1_1_1_1PQ.y;\n" + " GLF_merged3_0_1_1_1_1_1_2_2_25PQGLF_merged2_0_1_1_1_1_1PQ.zw;\n" + "}\n"; final String expected1 = "void f()\n" + "{\n" + " float P;\n" + " vec4 GLF_merged3_0_1_1_1_1_1_2_2_25PQGLF_merged2_0_1_1_1_1_1PQ;\n" + " P;\n" + " GLF_merged3_0_1_1_1_1_1_2_2_25PQGLF_merged2_0_1_1_1_1_1PQ.y;\n" + " GLF_merged3_0_1_1_1_1_1_2_2_25PQGLF_merged2_0_1_1_1_1_1PQ.zw;\n" + "}\n"; final String expected2 = "void f()\n" + "{\n" + " float Q;\n" + " float P;\n" + " vec4 GLF_merged3_0_1_1_1_1_1_2_2_25PQGLF_merged2_0_1_1_1_1_1PQ;\n" + " P;\n" + " Q;\n" + " GLF_merged3_0_1_1_1_1_1_2_2_25PQGLF_merged2_0_1_1_1_1_1PQ.zw;\n" + "}\n"; final String expected3 = "void f()\n" + "{\n" + " vec2 GLF_merged2_0_1_1_1_1_1PQ;\n" + " float Q;\n" + " float P;\n" + " vec4 GLF_merged3_0_1_1_1_1_1_2_2_25PQGLF_merged2_0_1_1_1_1_1PQ;\n" + " P;\n" + " Q;\n" + " GLF_merged2_0_1_1_1_1_1PQ;\n" + "}\n"; final TranslationUnit tu = ParseHelper.parse(shader); final IRandom cannedRandom = new ZeroCannedRandom(); List<VectorizationReductionOpportunity> ops = VectorizationReductionOpportunities .findOpportunities(MakeShaderJobFromFragmentShader.make(tu), new ReducerContext(false, ShadingLanguageVersion.GLSL_440, cannedRandom, new IdGenerator())); assertEquals(3, ops.size()); ops.stream().filter(item -> item.getComponentName().equals("P")).findAny().get() .applyReduction(); assertEquals(PrettyPrinterVisitor.prettyPrintAsString(ParseHelper.parse(expected1)), PrettyPrinterVisitor.prettyPrintAsString(tu)); ops.stream().filter(item -> item.getComponentName().equals("Q")).findAny().get() .applyReduction(); assertEquals(PrettyPrinterVisitor.prettyPrintAsString(ParseHelper.parse(expected2)), PrettyPrinterVisitor.prettyPrintAsString(tu)); ops.stream().filter(item -> item.getComponentName().equals("GLF_merged2_0_1_1_1_1_1PQ")) .findAny().get().applyReduction(); assertEquals(PrettyPrinterVisitor.prettyPrintAsString(ParseHelper.parse(expected3)), PrettyPrinterVisitor.prettyPrintAsString(tu)); ops = VectorizationReductionOpportunities .findOpportunities(MakeShaderJobFromFragmentShader.make(tu), new ReducerContext(false, ShadingLanguageVersion.GLSL_440, cannedRandom, new IdGenerator())); assertEquals(0, ops.size()); }
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);  }