@Test public void testRemoveUnused() throws Exception { final String emptyShader = "void main() { }"; final PipelineInfo pipelineInfo = new PipelineInfo(); pipelineInfo.addUniform("unused", BasicType.FLOAT, Optional.empty(), Collections.singletonList(10.0)); final ShaderJob shaderJob = new GlslShaderJob(Optional.empty(), pipelineInfo, ParseHelper.parse(emptyShader)); assertEquals(1, shaderJob.getPipelineInfo().getNumUniforms()); List<RemoveRedundantUniformMetadataReductionOpportunity> ops = RemoveRedundantUniformMetadataReductionOpportunities .findOpportunities(shaderJob, new ReducerContext(false, ShadingLanguageVersion.ESSL_100, new RandomWrapper(0), new IdGenerator())); assertEquals(1, ops.size()); ops.get(0).applyReduction(); CompareAsts.assertEqualAsts(emptyShader, shaderJob.getFragmentShader().get()); assertEquals(0, shaderJob.getPipelineInfo().getNumUniforms()); }
static List<RemoveRedundantUniformMetadataReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { final List<String> canBeRemoved = new ArrayList<>(shaderJob.getPipelineInfo().getUniformNames()); for (TranslationUnit tu : shaderJob.getShaders()) { new StandardVisitor() { @Override public void visitVariablesDeclaration(VariablesDeclaration variablesDeclaration) { super.visitVariablesDeclaration(variablesDeclaration); if (variablesDeclaration.getBaseType().hasQualifier(TypeQualifier.UNIFORM)) { for (VariableDeclInfo vdi : variablesDeclaration.getDeclInfos()) { canBeRemoved.remove(vdi.getName()); } } } }.visit(tu); } return canBeRemoved .stream() .map(item -> new RemoveRedundantUniformMetadataReductionOpportunity(item, shaderJob.getPipelineInfo(), new VisitationDepth(0)) ).collect(Collectors.toList()); }
RemoveRedundantUniformMetadataReductionOpportunities { static List<RemoveRedundantUniformMetadataReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { final List<String> canBeRemoved = new ArrayList<>(shaderJob.getPipelineInfo().getUniformNames()); for (TranslationUnit tu : shaderJob.getShaders()) { new StandardVisitor() { @Override public void visitVariablesDeclaration(VariablesDeclaration variablesDeclaration) { super.visitVariablesDeclaration(variablesDeclaration); if (variablesDeclaration.getBaseType().hasQualifier(TypeQualifier.UNIFORM)) { for (VariableDeclInfo vdi : variablesDeclaration.getDeclInfos()) { canBeRemoved.remove(vdi.getName()); } } } }.visit(tu); } return canBeRemoved .stream() .map(item -> new RemoveRedundantUniformMetadataReductionOpportunity(item, shaderJob.getPipelineInfo(), new VisitationDepth(0)) ).collect(Collectors.toList()); } }
RemoveRedundantUniformMetadataReductionOpportunities { static List<RemoveRedundantUniformMetadataReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { final List<String> canBeRemoved = new ArrayList<>(shaderJob.getPipelineInfo().getUniformNames()); for (TranslationUnit tu : shaderJob.getShaders()) { new StandardVisitor() { @Override public void visitVariablesDeclaration(VariablesDeclaration variablesDeclaration) { super.visitVariablesDeclaration(variablesDeclaration); if (variablesDeclaration.getBaseType().hasQualifier(TypeQualifier.UNIFORM)) { for (VariableDeclInfo vdi : variablesDeclaration.getDeclInfos()) { canBeRemoved.remove(vdi.getName()); } } } }.visit(tu); } return canBeRemoved .stream() .map(item -> new RemoveRedundantUniformMetadataReductionOpportunity(item, shaderJob.getPipelineInfo(), new VisitationDepth(0)) ).collect(Collectors.toList()); } private  RemoveRedundantUniformMetadataReductionOpportunities(); }
RemoveRedundantUniformMetadataReductionOpportunities { static List<RemoveRedundantUniformMetadataReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { final List<String> canBeRemoved = new ArrayList<>(shaderJob.getPipelineInfo().getUniformNames()); for (TranslationUnit tu : shaderJob.getShaders()) { new StandardVisitor() { @Override public void visitVariablesDeclaration(VariablesDeclaration variablesDeclaration) { super.visitVariablesDeclaration(variablesDeclaration); if (variablesDeclaration.getBaseType().hasQualifier(TypeQualifier.UNIFORM)) { for (VariableDeclInfo vdi : variablesDeclaration.getDeclInfos()) { canBeRemoved.remove(vdi.getName()); } } } }.visit(tu); } return canBeRemoved .stream() .map(item -> new RemoveRedundantUniformMetadataReductionOpportunity(item, shaderJob.getPipelineInfo(), new VisitationDepth(0)) ).collect(Collectors.toList()); } private  RemoveRedundantUniformMetadataReductionOpportunities();  }
RemoveRedundantUniformMetadataReductionOpportunities { static List<RemoveRedundantUniformMetadataReductionOpportunity> findOpportunities( ShaderJob shaderJob, ReducerContext context) { final List<String> canBeRemoved = new ArrayList<>(shaderJob.getPipelineInfo().getUniformNames()); for (TranslationUnit tu : shaderJob.getShaders()) { new StandardVisitor() { @Override public void visitVariablesDeclaration(VariablesDeclaration variablesDeclaration) { super.visitVariablesDeclaration(variablesDeclaration); if (variablesDeclaration.getBaseType().hasQualifier(TypeQualifier.UNIFORM)) { for (VariableDeclInfo vdi : variablesDeclaration.getDeclInfos()) { canBeRemoved.remove(vdi.getName()); } } } }.visit(tu); } return canBeRemoved .stream() .map(item -> new RemoveRedundantUniformMetadataReductionOpportunity(item, shaderJob.getPipelineInfo(), new VisitationDepth(0)) ).collect(Collectors.toList()); } private  RemoveRedundantUniformMetadataReductionOpportunities();   }