@Test public void inlineRegressionTest() throws Exception { String program = "precision mediump float;\n" + "struct _GLF_struct_D {\n" + " bool _f0;\n" + " mat4 _f1;\n" + "};\n" + "struct _GLF_struct_F {\n" + " float GLF_live41j0;\n" + " _GLF_struct_D _f1;\n" + "};\n" + "struct _GLF_struct_B {\n" + " _GLF_struct_F _f0;\n" + "};\n" + "struct _GLF_struct_A {\n" + " float _f0;\n" + " _GLF_struct_B _f1;\n" + "};\n" + "float f()\n" + "{\n" + " return 0.0;\n" + "}\n" + "void main()\n" + "{\n" + " _GLF_struct_A _GLF_struct_replacement_838 = _GLF_struct_A(1.0, " + "_GLF_struct_B(_GLF_struct_F(f(), _GLF_struct_D(true, mat4(1.0)))));\n" + "}\n"; TranslationUnit tu = ParseHelper.parse(program).clone(); List<InlineStructifiedFieldReductionOpportunity> ops = InlineStructifiedFieldReductionOpportunities .findOpportunities(MakeShaderJobFromFragmentShader.make(tu), new ReducerContext(false, ShadingLanguageVersion.ESSL_100, new RandomWrapper(0), new IdGenerator())); assertEquals(3, ops.size()); File tempFile = testFolder.newFile("temp.frag"); for (InlineStructifiedFieldReductionOpportunity op : ops) { if (!op.getOuterStructName().equals("_GLF_struct_B")) { continue; } op.applyReduction(); final File shaderJobFile = testFolder.newFile("temp.json"); fileOps.writeShaderJobFile(new GlslShaderJob(Optional.empty(), new PipelineInfo(), tu), shaderJobFile); assertTrue(fileOps.areShadersValid(shaderJobFile, false)); break; } }
static List<InlineStructifiedFieldReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item)) .reduce(Arrays.asList(), ListConcat::concatenate); }
InlineStructifiedFieldReductionOpportunities extends ScopeTrackingVisitor { static List<InlineStructifiedFieldReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item)) .reduce(Arrays.asList(), ListConcat::concatenate); } }
InlineStructifiedFieldReductionOpportunities extends ScopeTrackingVisitor { static List<InlineStructifiedFieldReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  InlineStructifiedFieldReductionOpportunities(TranslationUnit tu); }
InlineStructifiedFieldReductionOpportunities extends ScopeTrackingVisitor { static List<InlineStructifiedFieldReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  InlineStructifiedFieldReductionOpportunities(TranslationUnit tu); @Override void visitDeclarationStmt(DeclarationStmt declarationStmt); void findInliningOpportunities(StructNameType structType); }
InlineStructifiedFieldReductionOpportunities extends ScopeTrackingVisitor { static List<InlineStructifiedFieldReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { return shaderJob.getShaders() .stream() .map(item -> findOpportunitiesForShader(item)) .reduce(Arrays.asList(), ListConcat::concatenate); } private  InlineStructifiedFieldReductionOpportunities(TranslationUnit tu); @Override void visitDeclarationStmt(DeclarationStmt declarationStmt); void findInliningOpportunities(StructNameType structType);  }