@Test public void testDoNotRemoveUsedMultipleShaders() throws Exception { final String minimalVertexShader = "uniform float used_in_vertex_only; void main() { " + "used_in_vertex_only; }"; final String minimalFragmentShader = "uniform float used_in_fragment_only; void main() { " + "used_in_fragment_only; }"; final PipelineInfo pipelineInfo = new PipelineInfo(); pipelineInfo.addUniform("used_in_vertex_only", BasicType.FLOAT, Optional.empty(), Collections.singletonList(10.0)); pipelineInfo.addUniform("used_in_fragment_only", BasicType.FLOAT, Optional.empty(), Collections.singletonList(20.0)); final ShaderJob shaderJob = new GlslShaderJob(Optional.empty(), pipelineInfo, ParseHelper.parse(minimalVertexShader, ShaderKind.VERTEX), ParseHelper.parse(minimalFragmentShader, ShaderKind.FRAGMENT)); assertEquals(2, shaderJob.getPipelineInfo().getNumUniforms()); List<RemoveRedundantUniformMetadataReductionOpportunity> ops = RemoveRedundantUniformMetadataReductionOpportunities .findOpportunities(shaderJob, new ReducerContext(false, ShadingLanguageVersion.ESSL_100, new RandomWrapper(0), new IdGenerator())); assertEquals(0, ops.size()); }
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();   }