PrepareReference { public static void mainHelper(String[] args) throws ArgumentParserException, IOException, ParseTimeoutException, InterruptedException, GlslParserException { Namespace ns = parse(args); ShaderJobFileOperations fileOps = new ShaderJobFileOperations(); prepareReference( ns.get("reference"), ns.get("output"), ns.get("replace_float_literals"), ns.get("max_uniforms"), ns.get("vulkan"), fileOps); }  static void main(String[] args); static void mainHelper(String[] args); static void prepareReference(
      File referenceShaderJobFile,
      File outputShaderJobFile,
      boolean replaceFloatLiterals,
      int maxUniforms,
      boolean generateUniformBindings,
      ShaderJobFileOperations fileOps); static void prepareReference(ShaderJob shaderJob,
                                      boolean replaceFloatLiterals,
                                      int maxUniforms,
                                      boolean generateUniformBindings);  }
@Test public void testPreparedReferenceIsValid() throws Exception { final String json = "{ }"; final String vert = "#version 300 es\n" + "layout(location=0) in highp vec4 a_position;\n" + "void main() { gl_Position = a_position; }"; final String frag = "#version 300 es\n" + "layout(location=0) out highp vec4 _GLF_color;\n" + "void main() { _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); }"; final File jsonFile = temporaryFolder.newFile("shader.json"); final File vertFile = temporaryFolder.newFile("shader.vert"); final File fragFile = temporaryFolder.newFile("shader.frag"); final File output = temporaryFolder.newFile("output.json"); FileUtils.writeStringToFile(jsonFile, json, StandardCharsets.UTF_8); FileUtils.writeStringToFile(vertFile, vert, StandardCharsets.UTF_8); FileUtils.writeStringToFile(fragFile, frag, StandardCharsets.UTF_8); final ShaderJobFileOperations fileOps = new ShaderJobFileOperations(); PrepareReference.mainHelper(new String[] { jsonFile.getAbsolutePath(), output.getAbsolutePath() }); assertTrue(fileOps.areShadersValid(output, false)); }
@Test public void testPreparedComputeShaderNoBindingClash() throws Exception { final String json = "{\n" + " \"f\": {\n" + " \"func\": \"glUniform1f\",\n" + " \"args\": [\n" + " 1.0\n" + " ]\n" + " }\n" + "}\n"; final String comp = "#version 320 es\n" + "layout(std430, binding = 0) buffer doesNotMatter {\n" + " int result;\n" + " int data[];\n" + "} ;\n" + "layout(local_size_x = 16, local_size_y = 1) in;\n" + "uniform float f;\n" + "void main() { }"; final File jsonFile = temporaryFolder.newFile("shader.json"); final File compFile = temporaryFolder.newFile("shader.comp"); final File output = temporaryFolder.newFile("output.json"); FileUtils.writeStringToFile(jsonFile, json, StandardCharsets.UTF_8); FileUtils.writeStringToFile(compFile, comp, StandardCharsets.UTF_8); final ShaderJobFileOperations fileOps = new ShaderJobFileOperations(); PrepareReference.mainHelper(new String[] { jsonFile.getAbsolutePath(), output.getAbsolutePath(), "--vulkan" }); assertTrue(fileOps.areShadersValid(output, false, true)); final PipelineInfo pipelineInfo = new PipelineInfo(output); assertTrue(pipelineInfo.hasUniform("f")); assertEquals(1, pipelineInfo.getBinding("f")); }
@Test public void testPreparedComputeShaderNoBindingClash2() throws Exception { final String json = "{\n" + " \"f\": {\n" + " \"func\": \"glUniform1f\",\n" + " \"args\": [\n" + " 1.0\n" + " ]\n" + " },\n" + " \"g\": {\n" + " \"func\": \"glUniform1f\",\n" + " \"args\": [\n" + " 1.0\n" + " ]\n" + " }\n" + "}\n"; final String comp = "#version 320 es\n" + "layout(std430, binding = 1) buffer doesNotMatter {\n" + " int result;\n" + " int data[];\n" + "} ;\n" + "layout(local_size_x = 16, local_size_y = 1) in;\n" + "uniform float f;\n" + "uniform float g;\n" + "void main() { }"; final File jsonFile = temporaryFolder.newFile("shader.json"); final File compFile = temporaryFolder.newFile("shader.comp"); final File output = temporaryFolder.newFile("output.json"); FileUtils.writeStringToFile(jsonFile, json, StandardCharsets.UTF_8); FileUtils.writeStringToFile(compFile, comp, StandardCharsets.UTF_8); final ShaderJobFileOperations fileOps = new ShaderJobFileOperations(); PrepareReference.mainHelper(new String[] { jsonFile.getAbsolutePath(), output.getAbsolutePath(), "--vulkan" }); assertTrue(fileOps.areShadersValid(output, false)); final PipelineInfo pipelineInfo = new PipelineInfo(output); assertTrue(pipelineInfo.hasUniform("f")); assertTrue(pipelineInfo.hasUniform("g")); assertNotEquals(pipelineInfo.getBinding("f"), pipelineInfo.getBinding("g")); assertTrue(Arrays.asList(0, 2).contains(pipelineInfo.getBinding("f"))); assertTrue(Arrays.asList(0, 2).contains(pipelineInfo.getBinding("g"))); }