Skip to content

Commit 19b7689

Browse files
committed
Vulkan compiler, Unify use of enum to set name of input/output when compiling
1 parent 5f0844a commit 19b7689

File tree

3 files changed

+32
-34
lines changed

3 files changed

+32
-34
lines changed

graphics-by-opengl-j2se/src/main/java/com/nucleus/vulkan/GLSLCompiler.java

+9-17
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.nucleus.io.StreamUtils;
1414
import com.nucleus.spirv.SpirvBinary;
1515
import com.nucleus.spirv.SpirvBinary.SpirvStream;
16+
import com.nucleus.vulkan.structs.ShaderModuleCreateInfo.Type;
1617

1718
/**
1819
* Used to compile GLSL to SPIR-V in runtime.
@@ -24,16 +25,6 @@ public class GLSLCompiler {
2425
private static final String TARGET_CLASSES = "target/classes/";
2526
private static final String DESTINATION_RESOURCES = "src/main/resources/";
2627

27-
public enum Stage {
28-
vert(),
29-
tesc(),
30-
tese(),
31-
geom(),
32-
frag(),
33-
comp();
34-
35-
}
36-
3728
private static GLSLCompiler compiler = new GLSLCompiler();
3829

3930
/**
@@ -59,26 +50,27 @@ public static GLSLCompiler getInstance() {
5950
public synchronized void compileShaders(String path, ArrayList<String> folders)
6051
throws IOException, URISyntaxException {
6152
ByteBuffer buffer = BufferUtils.createByteBuffer(16000);
62-
compileStage(path, folders, buffer, Stage.vert);
63-
compileStage(path, folders, buffer, Stage.geom);
64-
compileStage(path, folders, buffer, Stage.frag);
53+
compileStage(path, folders, buffer, Type.VERTEX);
54+
compileStage(path, folders, buffer, Type.GEOMETRY);
55+
compileStage(path, folders, buffer, Type.FRAGMENT);
6556
}
6657

67-
public void compileStage(String path, ArrayList<String> folders, ByteBuffer buffer, Stage stage)
58+
public void compileStage(String path, ArrayList<String> folders, ByteBuffer buffer, Type type)
6859
throws IOException, URISyntaxException {
6960
for (String folder : folders) {
7061
ArrayList<String> currentFolder = new ArrayList<String>();
7162
currentFolder.add(folder);
72-
String stageSuffix = "." + stage.name();
63+
// Get the mime for the shader type/stage - ie the glsl sourcefiles to compile
64+
String stageSuffix = "." + type.stage;
7365
ArrayList<String> filenames = FileUtils.getInstance().listFiles(path, currentFolder,
7466
new String[] { stageSuffix });
7567

7668
String name = null;
7769
String output = null;
7870
for (String filename : filenames) {
7971
String filePath = FileUtils.getInstance().getFilePath(path + filename, folder);
80-
name = filename.substring(0, filename.length() - (stage.name().length() + 1));
81-
output = name + "_" + stage.name() + ".spv";
72+
name = filename.substring(0, filename.length() - (type.fileName.length() + 1));
73+
output = name + type.fileName;
8274
String cmd = "glslc " + filename + " -o -";
8375
buffer.clear();
8476
SpirvBinary binary = compile(

graphics-by-opengl-j2se/src/main/java/com/nucleus/vulkan/VulkanGraphicsPipeline.java

+9-12
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,10 @@
2323
import com.nucleus.shader.ShaderVariable.VariableType;
2424
import com.nucleus.shader.VariableIndexer;
2525
import com.nucleus.vulkan.structs.ShaderModuleCreateInfo;
26+
import com.nucleus.vulkan.structs.ShaderModuleCreateInfo.Type;
2627

2728
public class VulkanGraphicsPipeline implements GraphicsPipeline<ShaderBinary> {
2829

29-
/**
30-
* Shader type sourcename
31-
*/
32-
public static final String FRAGMENT_TYPE = "_fs";
33-
public static final String VERTEX_TYPE = "_vs";
34-
public static final String GEOMETRY_TYPE = "_gs";
35-
public static final String COMPUTE_TYPE = "_cs";
36-
3730
private Vulkan10Wrapper vulkan;
3831

3932
public VulkanGraphicsPipeline(Vulkan10Wrapper vulkan) {
@@ -123,16 +116,20 @@ public ShaderBinary getShaderSource(Renderers version, Categorizer function, Sha
123116
switch (type) {
124117
case VERTEX:
125118
return new ShaderModuleCreateInfo(ShaderBinary.PROGRAM_DIRECTORY + sourceNameVersion,
126-
function.getShaderSourceName(type), VERTEX_TYPE, type);
119+
function.getShaderSourceName(type), Type.VERTEX.fileName,
120+
type);
127121
case FRAGMENT:
128122
return new ShaderModuleCreateInfo(ShaderBinary.PROGRAM_DIRECTORY + sourceNameVersion,
129-
function.getShaderSourceName(type), FRAGMENT_TYPE, type);
123+
function.getShaderSourceName(type), Type.FRAGMENT.fileName,
124+
type);
130125
case COMPUTE:
131126
return new ShaderModuleCreateInfo(ShaderBinary.PROGRAM_DIRECTORY + sourceNameVersion,
132-
function.getShaderSourceName(type), COMPUTE_TYPE, type);
127+
function.getShaderSourceName(type), Type.COMPUTE.fileName,
128+
type);
133129
case GEOMETRY:
134130
return new ShaderModuleCreateInfo(ShaderBinary.PROGRAM_DIRECTORY + sourceNameVersion,
135-
function.getShaderSourceName(type), GEOMETRY_TYPE, type);
131+
function.getShaderSourceName(type), Type.GEOMETRY.fileName,
132+
type);
136133

137134
default:
138135
throw new IllegalArgumentException("Not implemented for type: " + type);

graphics-by-opengl-j2se/src/main/java/com/nucleus/vulkan/structs/ShaderModuleCreateInfo.java

+14-5
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,20 @@
1717
public class ShaderModuleCreateInfo extends ShaderBinary {
1818

1919
public enum Type {
20-
VERTEX(),
21-
FRAGMENT(),
22-
GEOMETRY(),
23-
TESSELATION(),
24-
COMPUTE();
20+
VERTEX("vert", "_vert.spv"),
21+
TESSELATION_CONTROL("tesc", "_tesc.spv"),
22+
TESSELATION("tese", "_tese.spv"),
23+
GEOMETRY("geom", "_geom.spv"),
24+
FRAGMENT("frag", "_frag.spv"),
25+
COMPUTE("comp", "_comp.spv");
26+
27+
public final String stage;
28+
public final String fileName;
29+
30+
Type(String stage, String fileName) {
31+
this.stage = stage;
32+
this.fileName = fileName;
33+
}
2534
}
2635

2736
/**

0 commit comments

Comments
 (0)