@Test public void testUniformsGetRemoved() throws Exception { final String program = "#version 310 es\n" + "\n" + "#ifdef GL_ES\n" + "#ifdef GL_FRAGMENT_PRECISION_HIGH\n" + "precision highp float;\n" + "precision highp int;\n" + "#else\n" + "precision mediump float;\n" + "precision mediump int;\n" + "#endif\n" + "#endif\n" + "\n" + "#ifndef REDUCER\n" + "#define _GLF_ZERO(X, Y) (Y)\n" + "#define _GLF_ONE(X, Y) (Y)\n" + "#define _GLF_FALSE(X, Y) (Y)\n" + "#define _GLF_TRUE(X, Y) (Y)\n" + "#define _GLF_IDENTITY(X, Y) (Y)\n" + "#define _GLF_DEAD(X) (X)\n" + "#define _GLF_FUZZED(X) (X)\n" + "#define _GLF_WRAPPED_LOOP(X) X\n" + "#define _GLF_WRAPPED_IF_TRUE(X) X\n" + "#define _GLF_WRAPPED_IF_FALSE(X) X\n" + "#define _GLF_SWITCH(X) X\n" + "#endif\n" + "\n" + " + "\n" + "layout(set=0,binding=0) uniform buf0 {\n" + " vec2 injectionSwitch;\n" + "} ;\n" + "void main() { }"; final TranslationUnit tu = ParseHelper.parse(program); final String json = "{ \"injectionSwitch\": { \"args\": [ 1.0, 2.0 ], " + " \"func\": \"glUniform2f\", \"binding\": 0 } }"; final ShaderJob shaderJob = new GlslShaderJob(Optional.empty(), new PipelineInfo(json), tu); shaderJob.removeUniformBindings(); List<IReductionOpportunity> ops = ReductionOpportunities.getReductionOpportunities( MakeShaderJobFromFragmentShader.make(tu), new ReducerContext(false, ShadingLanguageVersion.GLSL_440, new RandomWrapper(0), new IdGenerator()), fileOps); assertEquals(1, ops.size()); assertTrue(ops.get(0) instanceof VariableDeclReductionOpportunity); ops.get(0).applyReduction(); shaderJob.makeUniformBindings(Optional.empty()); CompareAsts.assertEqualAsts("#version 310 es\nvoid main() { }", tu); }
public static List<IReductionOpportunity> getReductionOpportunities( ShaderJob shaderJob, ReducerContext context, ShaderJobFileOperations fileOps) { final List<IReductionOpportunity> opportunities = new ArrayList<>(); for (IReductionOpportunityFinder<?> ros : Arrays.asList( IReductionOpportunityFinder.loopMergeFinder(), IReductionOpportunityFinder.removeStructFieldFinder(), IReductionOpportunityFinder.destructifyFinder(), IReductionOpportunityFinder.inlineStructFieldFinder(), IReductionOpportunityFinder.outlinedStatementFinder(), IReductionOpportunityFinder.variableDeclFinder(), IReductionOpportunityFinder.globalVariablesDeclarationFinder(), IReductionOpportunityFinder.globalPrecisionDeclarationFinder(), IReductionOpportunityFinder.unwrapFinder(), IReductionOpportunityFinder.unswitchifyFinder(), IReductionOpportunityFinder.vectorizationFinder(), IReductionOpportunityFinder.functionFinder(), IReductionOpportunityFinder.stmtFinder(), IReductionOpportunityFinder.exprToConstantFinder(), IReductionOpportunityFinder.compoundExprToSubExprFinder(), IReductionOpportunityFinder.mutationFinder(), IReductionOpportunityFinder.flattenControlFlowFinder(), IReductionOpportunityFinder.inlineInitializerFinder(), IReductionOpportunityFinder.inlineFunctionFinder(), IReductionOpportunityFinder.liveFragColorWriteFinder(), IReductionOpportunityFinder.unusedParamFinder(), IReductionOpportunityFinder.foldConstantFinder(), IReductionOpportunityFinder.inlineUniformFinder(), IReductionOpportunityFinder.redundantUniformMetadataFinder(), IReductionOpportunityFinder.variableDeclToExprFinder(), IReductionOpportunityFinder.switchToLoopFinder(), IReductionOpportunityFinder.globalVariableDeclToExprFinder())) { final List<? extends IReductionOpportunity> currentOpportunities = ros .findOpportunities(shaderJob, context); if (ReductionDriver.DEBUG_REDUCER) { opportunities.addAll(currentOpportunities.stream() .map(item -> new CheckValidReductionOpportunityDecorator(item, shaderJob, context.getShadingLanguageVersion(), fileOps)) .collect(Collectors.toList())); } else { opportunities.addAll(currentOpportunities); } } return opportunities; }
ReductionOpportunities { public static List<IReductionOpportunity> getReductionOpportunities( ShaderJob shaderJob, ReducerContext context, ShaderJobFileOperations fileOps) { final List<IReductionOpportunity> opportunities = new ArrayList<>(); for (IReductionOpportunityFinder<?> ros : Arrays.asList( IReductionOpportunityFinder.loopMergeFinder(), IReductionOpportunityFinder.removeStructFieldFinder(), IReductionOpportunityFinder.destructifyFinder(), IReductionOpportunityFinder.inlineStructFieldFinder(), IReductionOpportunityFinder.outlinedStatementFinder(), IReductionOpportunityFinder.variableDeclFinder(), IReductionOpportunityFinder.globalVariablesDeclarationFinder(), IReductionOpportunityFinder.globalPrecisionDeclarationFinder(), IReductionOpportunityFinder.unwrapFinder(), IReductionOpportunityFinder.unswitchifyFinder(), IReductionOpportunityFinder.vectorizationFinder(), IReductionOpportunityFinder.functionFinder(), IReductionOpportunityFinder.stmtFinder(), IReductionOpportunityFinder.exprToConstantFinder(), IReductionOpportunityFinder.compoundExprToSubExprFinder(), IReductionOpportunityFinder.mutationFinder(), IReductionOpportunityFinder.flattenControlFlowFinder(), IReductionOpportunityFinder.inlineInitializerFinder(), IReductionOpportunityFinder.inlineFunctionFinder(), IReductionOpportunityFinder.liveFragColorWriteFinder(), IReductionOpportunityFinder.unusedParamFinder(), IReductionOpportunityFinder.foldConstantFinder(), IReductionOpportunityFinder.inlineUniformFinder(), IReductionOpportunityFinder.redundantUniformMetadataFinder(), IReductionOpportunityFinder.variableDeclToExprFinder(), IReductionOpportunityFinder.switchToLoopFinder(), IReductionOpportunityFinder.globalVariableDeclToExprFinder())) { final List<? extends IReductionOpportunity> currentOpportunities = ros .findOpportunities(shaderJob, context); if (ReductionDriver.DEBUG_REDUCER) { opportunities.addAll(currentOpportunities.stream() .map(item -> new CheckValidReductionOpportunityDecorator(item, shaderJob, context.getShadingLanguageVersion(), fileOps)) .collect(Collectors.toList())); } else { opportunities.addAll(currentOpportunities); } } return opportunities; } }
ReductionOpportunities { public static List<IReductionOpportunity> getReductionOpportunities( ShaderJob shaderJob, ReducerContext context, ShaderJobFileOperations fileOps) { final List<IReductionOpportunity> opportunities = new ArrayList<>(); for (IReductionOpportunityFinder<?> ros : Arrays.asList( IReductionOpportunityFinder.loopMergeFinder(), IReductionOpportunityFinder.removeStructFieldFinder(), IReductionOpportunityFinder.destructifyFinder(), IReductionOpportunityFinder.inlineStructFieldFinder(), IReductionOpportunityFinder.outlinedStatementFinder(), IReductionOpportunityFinder.variableDeclFinder(), IReductionOpportunityFinder.globalVariablesDeclarationFinder(), IReductionOpportunityFinder.globalPrecisionDeclarationFinder(), IReductionOpportunityFinder.unwrapFinder(), IReductionOpportunityFinder.unswitchifyFinder(), IReductionOpportunityFinder.vectorizationFinder(), IReductionOpportunityFinder.functionFinder(), IReductionOpportunityFinder.stmtFinder(), IReductionOpportunityFinder.exprToConstantFinder(), IReductionOpportunityFinder.compoundExprToSubExprFinder(), IReductionOpportunityFinder.mutationFinder(), IReductionOpportunityFinder.flattenControlFlowFinder(), IReductionOpportunityFinder.inlineInitializerFinder(), IReductionOpportunityFinder.inlineFunctionFinder(), IReductionOpportunityFinder.liveFragColorWriteFinder(), IReductionOpportunityFinder.unusedParamFinder(), IReductionOpportunityFinder.foldConstantFinder(), IReductionOpportunityFinder.inlineUniformFinder(), IReductionOpportunityFinder.redundantUniformMetadataFinder(), IReductionOpportunityFinder.variableDeclToExprFinder(), IReductionOpportunityFinder.switchToLoopFinder(), IReductionOpportunityFinder.globalVariableDeclToExprFinder())) { final List<? extends IReductionOpportunity> currentOpportunities = ros .findOpportunities(shaderJob, context); if (ReductionDriver.DEBUG_REDUCER) { opportunities.addAll(currentOpportunities.stream() .map(item -> new CheckValidReductionOpportunityDecorator(item, shaderJob, context.getShadingLanguageVersion(), fileOps)) .collect(Collectors.toList())); } else { opportunities.addAll(currentOpportunities); } } return opportunities; } private  ReductionOpportunities(); }
ReductionOpportunities { public static List<IReductionOpportunity> getReductionOpportunities( ShaderJob shaderJob, ReducerContext context, ShaderJobFileOperations fileOps) { final List<IReductionOpportunity> opportunities = new ArrayList<>(); for (IReductionOpportunityFinder<?> ros : Arrays.asList( IReductionOpportunityFinder.loopMergeFinder(), IReductionOpportunityFinder.removeStructFieldFinder(), IReductionOpportunityFinder.destructifyFinder(), IReductionOpportunityFinder.inlineStructFieldFinder(), IReductionOpportunityFinder.outlinedStatementFinder(), IReductionOpportunityFinder.variableDeclFinder(), IReductionOpportunityFinder.globalVariablesDeclarationFinder(), IReductionOpportunityFinder.globalPrecisionDeclarationFinder(), IReductionOpportunityFinder.unwrapFinder(), IReductionOpportunityFinder.unswitchifyFinder(), IReductionOpportunityFinder.vectorizationFinder(), IReductionOpportunityFinder.functionFinder(), IReductionOpportunityFinder.stmtFinder(), IReductionOpportunityFinder.exprToConstantFinder(), IReductionOpportunityFinder.compoundExprToSubExprFinder(), IReductionOpportunityFinder.mutationFinder(), IReductionOpportunityFinder.flattenControlFlowFinder(), IReductionOpportunityFinder.inlineInitializerFinder(), IReductionOpportunityFinder.inlineFunctionFinder(), IReductionOpportunityFinder.liveFragColorWriteFinder(), IReductionOpportunityFinder.unusedParamFinder(), IReductionOpportunityFinder.foldConstantFinder(), IReductionOpportunityFinder.inlineUniformFinder(), IReductionOpportunityFinder.redundantUniformMetadataFinder(), IReductionOpportunityFinder.variableDeclToExprFinder(), IReductionOpportunityFinder.switchToLoopFinder(), IReductionOpportunityFinder.globalVariableDeclToExprFinder())) { final List<? extends IReductionOpportunity> currentOpportunities = ros .findOpportunities(shaderJob, context); if (ReductionDriver.DEBUG_REDUCER) { opportunities.addAll(currentOpportunities.stream() .map(item -> new CheckValidReductionOpportunityDecorator(item, shaderJob, context.getShadingLanguageVersion(), fileOps)) .collect(Collectors.toList())); } else { opportunities.addAll(currentOpportunities); } } return opportunities; } private  ReductionOpportunities(); static List<IReductionOpportunity> getReductionOpportunities(
      ShaderJob shaderJob,
      ReducerContext context,
      ShaderJobFileOperations fileOps); }
ReductionOpportunities { public static List<IReductionOpportunity> getReductionOpportunities( ShaderJob shaderJob, ReducerContext context, ShaderJobFileOperations fileOps) { final List<IReductionOpportunity> opportunities = new ArrayList<>(); for (IReductionOpportunityFinder<?> ros : Arrays.asList( IReductionOpportunityFinder.loopMergeFinder(), IReductionOpportunityFinder.removeStructFieldFinder(), IReductionOpportunityFinder.destructifyFinder(), IReductionOpportunityFinder.inlineStructFieldFinder(), IReductionOpportunityFinder.outlinedStatementFinder(), IReductionOpportunityFinder.variableDeclFinder(), IReductionOpportunityFinder.globalVariablesDeclarationFinder(), IReductionOpportunityFinder.globalPrecisionDeclarationFinder(), IReductionOpportunityFinder.unwrapFinder(), IReductionOpportunityFinder.unswitchifyFinder(), IReductionOpportunityFinder.vectorizationFinder(), IReductionOpportunityFinder.functionFinder(), IReductionOpportunityFinder.stmtFinder(), IReductionOpportunityFinder.exprToConstantFinder(), IReductionOpportunityFinder.compoundExprToSubExprFinder(), IReductionOpportunityFinder.mutationFinder(), IReductionOpportunityFinder.flattenControlFlowFinder(), IReductionOpportunityFinder.inlineInitializerFinder(), IReductionOpportunityFinder.inlineFunctionFinder(), IReductionOpportunityFinder.liveFragColorWriteFinder(), IReductionOpportunityFinder.unusedParamFinder(), IReductionOpportunityFinder.foldConstantFinder(), IReductionOpportunityFinder.inlineUniformFinder(), IReductionOpportunityFinder.redundantUniformMetadataFinder(), IReductionOpportunityFinder.variableDeclToExprFinder(), IReductionOpportunityFinder.switchToLoopFinder(), IReductionOpportunityFinder.globalVariableDeclToExprFinder())) { final List<? extends IReductionOpportunity> currentOpportunities = ros .findOpportunities(shaderJob, context); if (ReductionDriver.DEBUG_REDUCER) { opportunities.addAll(currentOpportunities.stream() .map(item -> new CheckValidReductionOpportunityDecorator(item, shaderJob, context.getShadingLanguageVersion(), fileOps)) .collect(Collectors.toList())); } else { opportunities.addAll(currentOpportunities); } } return opportunities; } private  ReductionOpportunities(); static List<IReductionOpportunity> getReductionOpportunities(
      ShaderJob shaderJob,
      ReducerContext context,
      ShaderJobFileOperations fileOps);  }