mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-02-03 16:54:57 +01:00
Willing and able
- Refine capabilities checks - To compile with glsl 150: - Instancing needs ARB_shader_bit_encoding - Indirect needs gpu_shader5 and shading_language_420pack - Require extensions instead of just enable, probably doesn't make a difference since we check for their presence first but require aligns with our intent better
This commit is contained in:
parent
15184b8ccd
commit
e40f50f4f7
6 changed files with 46 additions and 19 deletions
|
@ -54,6 +54,12 @@ public class IndirectPrograms extends AtomicReferenceCounted {
|
|||
|
||||
private static List<String> getExtensions(GlslVersion glslVersion) {
|
||||
List<String> extensions = new ArrayList<>();
|
||||
if (glslVersion.compareTo(GlslVersion.V400) < 0) {
|
||||
extensions.add("GL_ARB_gpu_shader5");
|
||||
}
|
||||
if (glslVersion.compareTo(GlslVersion.V420) < 0) {
|
||||
extensions.add("GL_ARB_shading_language_420pack");
|
||||
}
|
||||
if (glslVersion.compareTo(GlslVersion.V430) < 0) {
|
||||
extensions.add("GL_ARB_shader_storage_buffer_object");
|
||||
}
|
||||
|
@ -105,8 +111,8 @@ public class IndirectPrograms extends AtomicReferenceCounted {
|
|||
return CULL.program()
|
||||
.link(CULL.shader(GlCompat.MAX_GLSL_VERSION, ShaderType.COMPUTE)
|
||||
.nameMapper(instanceType -> "culling/" + ResourceUtil.toDebugFileNameNoExtension(instanceType.cullShader()))
|
||||
.enableExtensions(EXTENSIONS)
|
||||
.enableExtensions(COMPUTE_EXTENSIONS)
|
||||
.requireExtensions(EXTENSIONS)
|
||||
.requireExtensions(COMPUTE_EXTENSIONS)
|
||||
.define("_FLW_SUBGROUP_SIZE", GlCompat.SUBGROUP_SIZE)
|
||||
.withResource(CULL_SHADER_API_IMPL)
|
||||
.withComponent(InstanceStructComponent::new)
|
||||
|
@ -127,8 +133,8 @@ public class IndirectPrograms extends AtomicReferenceCounted {
|
|||
return UTIL.program()
|
||||
.link(UTIL.shader(GlCompat.MAX_GLSL_VERSION, ShaderType.COMPUTE)
|
||||
.nameMapper(resourceLocation -> "utilities/" + ResourceUtil.toDebugFileNameNoExtension(resourceLocation))
|
||||
.enableExtensions(EXTENSIONS)
|
||||
.enableExtensions(COMPUTE_EXTENSIONS)
|
||||
.requireExtensions(EXTENSIONS)
|
||||
.requireExtensions(COMPUTE_EXTENSIONS)
|
||||
.define("_FLW_SUBGROUP_SIZE", GlCompat.SUBGROUP_SIZE)
|
||||
.withResource(s -> s))
|
||||
.harness("utilities", sources);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.jozufozu.flywheel.backend.compile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -9,11 +10,14 @@ import com.google.common.collect.ImmutableList;
|
|||
import com.jozufozu.flywheel.api.instance.InstanceType;
|
||||
import com.jozufozu.flywheel.backend.gl.GlCompat;
|
||||
import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
|
||||
import com.jozufozu.flywheel.backend.glsl.GlslVersion;
|
||||
import com.jozufozu.flywheel.backend.glsl.ShaderSources;
|
||||
import com.jozufozu.flywheel.backend.glsl.SourceComponent;
|
||||
import com.jozufozu.flywheel.backend.util.AtomicReferenceCounted;
|
||||
|
||||
public class InstancingPrograms extends AtomicReferenceCounted {
|
||||
private static final List<String> EXTENSIONS = getExtensions(GlCompat.MAX_GLSL_VERSION);
|
||||
|
||||
@Nullable
|
||||
private static InstancingPrograms instance;
|
||||
|
||||
|
@ -23,6 +27,14 @@ public class InstancingPrograms extends AtomicReferenceCounted {
|
|||
this.pipeline = pipeline;
|
||||
}
|
||||
|
||||
private static List<String> getExtensions(GlslVersion glslVersion) {
|
||||
List<String> extensions = new ArrayList<>();
|
||||
if (glslVersion.compareTo(GlslVersion.V330) < 0) {
|
||||
extensions.add("GL_ARB_shader_bit_encoding");
|
||||
}
|
||||
return extensions;
|
||||
}
|
||||
|
||||
static void reload(ShaderSources sources, ImmutableList<PipelineProgramKey> pipelineKeys, List<SourceComponent> vertexComponents, List<SourceComponent> fragmentComponents) {
|
||||
if (!GlCompat.SUPPORTS_INSTANCING) {
|
||||
return;
|
||||
|
@ -30,7 +42,7 @@ public class InstancingPrograms extends AtomicReferenceCounted {
|
|||
|
||||
InstancingPrograms newInstance = null;
|
||||
|
||||
var pipelineCompiler = PipelineCompiler.create(sources, Pipelines.INSTANCING, vertexComponents, fragmentComponents);
|
||||
var pipelineCompiler = PipelineCompiler.create(sources, Pipelines.INSTANCING, vertexComponents, fragmentComponents, EXTENSIONS);
|
||||
|
||||
try {
|
||||
var pipelineResult = pipelineCompiler.compileAndReportErrors(pipelineKeys);
|
||||
|
|
|
@ -37,7 +37,7 @@ public final class PipelineCompiler {
|
|||
.nameLowerCase();
|
||||
return "pipeline/" + pipeline.compilerMarker() + "/" + instance + "_" + context;
|
||||
})
|
||||
.enableExtensions(extensions)
|
||||
.requireExtensions(extensions)
|
||||
.onCompile((key, comp) -> key.contextShader()
|
||||
.onCompile(comp))
|
||||
.withResource(API_IMPL_VERT)
|
||||
|
@ -55,7 +55,7 @@ public final class PipelineCompiler {
|
|||
.nameLowerCase();
|
||||
return "pipeline/" + pipeline.compilerMarker() + "/" + context;
|
||||
})
|
||||
.enableExtensions(extensions)
|
||||
.requireExtensions(extensions)
|
||||
.enableExtension("GL_ARB_conservative_depth")
|
||||
.onCompile((key, comp) -> key.contextShader()
|
||||
.onCompile(comp))
|
||||
|
@ -91,8 +91,4 @@ public final class PipelineCompiler {
|
|||
})
|
||||
.harness(pipeline.compilerMarker(), sources);
|
||||
}
|
||||
|
||||
static CompilationHarness<PipelineProgramKey> create(ShaderSources sources, Pipeline pipeline, List<SourceComponent> vertexComponents, List<SourceComponent> fragmentComponents) {
|
||||
return create(sources, pipeline, vertexComponents, fragmentComponents, Collections.emptyList());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,6 +64,12 @@ public class Compilation {
|
|||
.append(" : enable\n");
|
||||
}
|
||||
|
||||
public void requireExtension(String ext) {
|
||||
fullSource.append("#extension ")
|
||||
.append(ext)
|
||||
.append(" : require\n");
|
||||
}
|
||||
|
||||
public void define(String key, String value) {
|
||||
fullSource.append("#define ")
|
||||
.append(key)
|
||||
|
|
|
@ -113,6 +113,14 @@ public class Compile<K> {
|
|||
});
|
||||
}
|
||||
|
||||
public ShaderCompiler<K> requireExtensions(Collection<String> extensions) {
|
||||
return onCompile(($, ctx) -> {
|
||||
for (String extension : extensions) {
|
||||
ctx.requireExtension(extension);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private GlShader compile(K key, ShaderCache compiler, SourceLoader loader) {
|
||||
var components = new ArrayList<SourceComponent>();
|
||||
|
|
|
@ -111,25 +111,24 @@ public final class GlCompat {
|
|||
}
|
||||
|
||||
private static boolean isInstancingSupported() {
|
||||
if (!CAPABILITIES.OpenGL33) {
|
||||
return false;
|
||||
if (CAPABILITIES.OpenGL33) {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
return CAPABILITIES.GL_ARB_shader_bit_encoding;
|
||||
}
|
||||
|
||||
private static boolean isIndirectSupported() {
|
||||
// The GL requirement cannot be lower because GL_ARB_compute_shader requires at least GL 4.2.
|
||||
if (!CAPABILITIES.OpenGL42) {
|
||||
return false;
|
||||
}
|
||||
if (CAPABILITIES.OpenGL46) {
|
||||
return true;
|
||||
}
|
||||
return CAPABILITIES.GL_ARB_compute_shader
|
||||
&& CAPABILITIES.GL_ARB_direct_state_access
|
||||
&& CAPABILITIES.GL_ARB_gpu_shader5
|
||||
&& CAPABILITIES.GL_ARB_multi_bind
|
||||
&& CAPABILITIES.GL_ARB_multi_draw_indirect
|
||||
&& CAPABILITIES.GL_ARB_shader_draw_parameters
|
||||
&& CAPABILITIES.GL_ARB_shader_storage_buffer_object;
|
||||
&& CAPABILITIES.GL_ARB_shader_storage_buffer_object
|
||||
&& CAPABILITIES.GL_ARB_shading_language_420pack
|
||||
&& CAPABILITIES.GL_ARB_vertex_attrib_binding;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue