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:
Jozufozu 2024-04-29 23:52:59 -07:00
parent 15184b8ccd
commit e40f50f4f7
6 changed files with 46 additions and 19 deletions

View file

@ -54,6 +54,12 @@ public class IndirectPrograms extends AtomicReferenceCounted {
private static List<String> getExtensions(GlslVersion glslVersion) { private static List<String> getExtensions(GlslVersion glslVersion) {
List<String> extensions = new ArrayList<>(); 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) { if (glslVersion.compareTo(GlslVersion.V430) < 0) {
extensions.add("GL_ARB_shader_storage_buffer_object"); extensions.add("GL_ARB_shader_storage_buffer_object");
} }
@ -105,8 +111,8 @@ public class IndirectPrograms extends AtomicReferenceCounted {
return CULL.program() return CULL.program()
.link(CULL.shader(GlCompat.MAX_GLSL_VERSION, ShaderType.COMPUTE) .link(CULL.shader(GlCompat.MAX_GLSL_VERSION, ShaderType.COMPUTE)
.nameMapper(instanceType -> "culling/" + ResourceUtil.toDebugFileNameNoExtension(instanceType.cullShader())) .nameMapper(instanceType -> "culling/" + ResourceUtil.toDebugFileNameNoExtension(instanceType.cullShader()))
.enableExtensions(EXTENSIONS) .requireExtensions(EXTENSIONS)
.enableExtensions(COMPUTE_EXTENSIONS) .requireExtensions(COMPUTE_EXTENSIONS)
.define("_FLW_SUBGROUP_SIZE", GlCompat.SUBGROUP_SIZE) .define("_FLW_SUBGROUP_SIZE", GlCompat.SUBGROUP_SIZE)
.withResource(CULL_SHADER_API_IMPL) .withResource(CULL_SHADER_API_IMPL)
.withComponent(InstanceStructComponent::new) .withComponent(InstanceStructComponent::new)
@ -127,8 +133,8 @@ public class IndirectPrograms extends AtomicReferenceCounted {
return UTIL.program() return UTIL.program()
.link(UTIL.shader(GlCompat.MAX_GLSL_VERSION, ShaderType.COMPUTE) .link(UTIL.shader(GlCompat.MAX_GLSL_VERSION, ShaderType.COMPUTE)
.nameMapper(resourceLocation -> "utilities/" + ResourceUtil.toDebugFileNameNoExtension(resourceLocation)) .nameMapper(resourceLocation -> "utilities/" + ResourceUtil.toDebugFileNameNoExtension(resourceLocation))
.enableExtensions(EXTENSIONS) .requireExtensions(EXTENSIONS)
.enableExtensions(COMPUTE_EXTENSIONS) .requireExtensions(COMPUTE_EXTENSIONS)
.define("_FLW_SUBGROUP_SIZE", GlCompat.SUBGROUP_SIZE) .define("_FLW_SUBGROUP_SIZE", GlCompat.SUBGROUP_SIZE)
.withResource(s -> s)) .withResource(s -> s))
.harness("utilities", sources); .harness("utilities", sources);

View file

@ -1,5 +1,6 @@
package com.jozufozu.flywheel.backend.compile; package com.jozufozu.flywheel.backend.compile;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; 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.api.instance.InstanceType;
import com.jozufozu.flywheel.backend.gl.GlCompat; import com.jozufozu.flywheel.backend.gl.GlCompat;
import com.jozufozu.flywheel.backend.gl.shader.GlProgram; 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.ShaderSources;
import com.jozufozu.flywheel.backend.glsl.SourceComponent; import com.jozufozu.flywheel.backend.glsl.SourceComponent;
import com.jozufozu.flywheel.backend.util.AtomicReferenceCounted; import com.jozufozu.flywheel.backend.util.AtomicReferenceCounted;
public class InstancingPrograms extends AtomicReferenceCounted { public class InstancingPrograms extends AtomicReferenceCounted {
private static final List<String> EXTENSIONS = getExtensions(GlCompat.MAX_GLSL_VERSION);
@Nullable @Nullable
private static InstancingPrograms instance; private static InstancingPrograms instance;
@ -23,6 +27,14 @@ public class InstancingPrograms extends AtomicReferenceCounted {
this.pipeline = pipeline; 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) { static void reload(ShaderSources sources, ImmutableList<PipelineProgramKey> pipelineKeys, List<SourceComponent> vertexComponents, List<SourceComponent> fragmentComponents) {
if (!GlCompat.SUPPORTS_INSTANCING) { if (!GlCompat.SUPPORTS_INSTANCING) {
return; return;
@ -30,7 +42,7 @@ public class InstancingPrograms extends AtomicReferenceCounted {
InstancingPrograms newInstance = null; InstancingPrograms newInstance = null;
var pipelineCompiler = PipelineCompiler.create(sources, Pipelines.INSTANCING, vertexComponents, fragmentComponents); var pipelineCompiler = PipelineCompiler.create(sources, Pipelines.INSTANCING, vertexComponents, fragmentComponents, EXTENSIONS);
try { try {
var pipelineResult = pipelineCompiler.compileAndReportErrors(pipelineKeys); var pipelineResult = pipelineCompiler.compileAndReportErrors(pipelineKeys);

View file

@ -37,7 +37,7 @@ public final class PipelineCompiler {
.nameLowerCase(); .nameLowerCase();
return "pipeline/" + pipeline.compilerMarker() + "/" + instance + "_" + context; return "pipeline/" + pipeline.compilerMarker() + "/" + instance + "_" + context;
}) })
.enableExtensions(extensions) .requireExtensions(extensions)
.onCompile((key, comp) -> key.contextShader() .onCompile((key, comp) -> key.contextShader()
.onCompile(comp)) .onCompile(comp))
.withResource(API_IMPL_VERT) .withResource(API_IMPL_VERT)
@ -55,7 +55,7 @@ public final class PipelineCompiler {
.nameLowerCase(); .nameLowerCase();
return "pipeline/" + pipeline.compilerMarker() + "/" + context; return "pipeline/" + pipeline.compilerMarker() + "/" + context;
}) })
.enableExtensions(extensions) .requireExtensions(extensions)
.enableExtension("GL_ARB_conservative_depth") .enableExtension("GL_ARB_conservative_depth")
.onCompile((key, comp) -> key.contextShader() .onCompile((key, comp) -> key.contextShader()
.onCompile(comp)) .onCompile(comp))
@ -91,8 +91,4 @@ public final class PipelineCompiler {
}) })
.harness(pipeline.compilerMarker(), sources); .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());
}
} }

View file

@ -64,6 +64,12 @@ public class Compilation {
.append(" : enable\n"); .append(" : enable\n");
} }
public void requireExtension(String ext) {
fullSource.append("#extension ")
.append(ext)
.append(" : require\n");
}
public void define(String key, String value) { public void define(String key, String value) {
fullSource.append("#define ") fullSource.append("#define ")
.append(key) .append(key)

View file

@ -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 @Nullable
private GlShader compile(K key, ShaderCache compiler, SourceLoader loader) { private GlShader compile(K key, ShaderCache compiler, SourceLoader loader) {
var components = new ArrayList<SourceComponent>(); var components = new ArrayList<SourceComponent>();

View file

@ -111,25 +111,24 @@ public final class GlCompat {
} }
private static boolean isInstancingSupported() { private static boolean isInstancingSupported() {
if (!CAPABILITIES.OpenGL33) { if (CAPABILITIES.OpenGL33) {
return false; return true;
} }
return true; return CAPABILITIES.GL_ARB_shader_bit_encoding;
} }
private static boolean isIndirectSupported() { 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) { if (CAPABILITIES.OpenGL46) {
return true; return true;
} }
return CAPABILITIES.GL_ARB_compute_shader return CAPABILITIES.GL_ARB_compute_shader
&& CAPABILITIES.GL_ARB_direct_state_access && CAPABILITIES.GL_ARB_direct_state_access
&& CAPABILITIES.GL_ARB_gpu_shader5
&& CAPABILITIES.GL_ARB_multi_bind && CAPABILITIES.GL_ARB_multi_bind
&& CAPABILITIES.GL_ARB_multi_draw_indirect && CAPABILITIES.GL_ARB_multi_draw_indirect
&& CAPABILITIES.GL_ARB_shader_draw_parameters && 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;
} }
} }