@Test public void testStructDonation() throws Exception { final ShaderJobFileOperations fileOps = new ShaderJobFileOperations(); final String usesStruct = "struct A { int x; }; void main() { { A a = A(1); a.x = 2; } }"; final File donorsFolder = temporaryFolder.newFolder(); for (int i = 0; i < 10; i++) { final File donor = new File( Paths.get(donorsFolder.getAbsolutePath(), "donor" + i + ".frag").toString()); fileOps.writeStringToFile(donor, usesStruct); } final String reference = "void main() { ; { ; ; ; }; ; { ; ; ; }; ; ; ; ; ; ; }"; final TranslationUnit tu = ParseHelper.parse(reference); new DonateLiveCodeTransformation(TransformationProbabilities .likelyDonateLiveCode()::donateLiveCodeAtStmt, donorsFolder, GenerationParams.normal(ShaderKind.FRAGMENT, true), false) .apply(tu, TransformationProbabilities.likelyDonateLiveCode(), new RandomWrapper(0), GenerationParams.normal(ShaderKind.FRAGMENT, true)); }
private static Namespace parse(String[] args) throws ArgumentParserException { ArgumentParser parser = ArgumentParsers.newArgumentParser("Generate") .defaultHelp(true) .description("Generate a shader."); parser.addArgument("reference-json") .help("Input reference shader json file.") .type(File.class); parser.addArgument("donors") .help("Path of folder of donor shaders.") .type(File.class); parser.addArgument("output") .help("Output shader job file file (.json).") .type(File.class); addGeneratorCommonArguments(parser); return parser.parseArgs(args); }
Generate { private static Namespace parse(String[] args) throws ArgumentParserException { ArgumentParser parser = ArgumentParsers.newArgumentParser("Generate") .defaultHelp(true) .description("Generate a shader."); parser.addArgument("reference-json") .help("Input reference shader json file.") .type(File.class); parser.addArgument("donors") .help("Path of folder of donor shaders.") .type(File.class); parser.addArgument("output") .help("Output shader job file file (.json).") .type(File.class); addGeneratorCommonArguments(parser); return parser.parseArgs(args); } }
Generate { private static Namespace parse(String[] args) throws ArgumentParserException { ArgumentParser parser = ArgumentParsers.newArgumentParser("Generate") .defaultHelp(true) .description("Generate a shader."); parser.addArgument("reference-json") .help("Input reference shader json file.") .type(File.class); parser.addArgument("donors") .help("Path of folder of donor shaders.") .type(File.class); parser.addArgument("output") .help("Output shader job file file (.json).") .type(File.class); addGeneratorCommonArguments(parser); return parser.parseArgs(args); }  }
Generate { private static Namespace parse(String[] args) throws ArgumentParserException { ArgumentParser parser = ArgumentParsers.newArgumentParser("Generate") .defaultHelp(true) .description("Generate a shader."); parser.addArgument("reference-json") .help("Input reference shader json file.") .type(File.class); parser.addArgument("donors") .help("Path of folder of donor shaders.") .type(File.class); parser.addArgument("output") .help("Output shader job file file (.json).") .type(File.class); addGeneratorCommonArguments(parser); return parser.parseArgs(args); }  static void addGeneratorCommonArguments(ArgumentParser parser); static StringBuilder generateVariant(ShaderJob shaderJob,
                                              GeneratorArguments args,
                                              IRandom random); @SuppressWarnings("deprecation") static void generateVariant(ShaderJobFileOperations fileOps,
                                     File referenceShaderJobFile,
                                     File outputShaderJobFile,
                                     GeneratorArguments generatorArguments,
                                     IRandom random,
                                     boolean writeProbabilities); static void main(String[] args); static void mainHelper(String[] args); static GeneratorArguments getGeneratorArguments(
      Namespace ns); static EnabledTransformations getTransformationDisablingFlags(Namespace ns); static void randomiseUnsetUniforms(TranslationUnit tu, PipelineInfo pipelineInfo,
        IRandom generator); static void addInjectionSwitchIfNotPresent(TranslationUnit tu); static void setInjectionSwitch(PipelineInfo pipelineInfo); }
Generate { private static Namespace parse(String[] args) throws ArgumentParserException { ArgumentParser parser = ArgumentParsers.newArgumentParser("Generate") .defaultHelp(true) .description("Generate a shader."); parser.addArgument("reference-json") .help("Input reference shader json file.") .type(File.class); parser.addArgument("donors") .help("Path of folder of donor shaders.") .type(File.class); parser.addArgument("output") .help("Output shader job file file (.json).") .type(File.class); addGeneratorCommonArguments(parser); return parser.parseArgs(args); }  static void addGeneratorCommonArguments(ArgumentParser parser); static StringBuilder generateVariant(ShaderJob shaderJob,
                                              GeneratorArguments args,
                                              IRandom random); @SuppressWarnings("deprecation") static void generateVariant(ShaderJobFileOperations fileOps,
                                     File referenceShaderJobFile,
                                     File outputShaderJobFile,
                                     GeneratorArguments generatorArguments,
                                     IRandom random,
                                     boolean writeProbabilities); static void main(String[] args); static void mainHelper(String[] args); static GeneratorArguments getGeneratorArguments(
      Namespace ns); static EnabledTransformations getTransformationDisablingFlags(Namespace ns); static void randomiseUnsetUniforms(TranslationUnit tu, PipelineInfo pipelineInfo,
        IRandom generator); static void addInjectionSwitchIfNotPresent(TranslationUnit tu); static void setInjectionSwitch(PipelineInfo pipelineInfo);  }