To bug or not to bug

- Disable the debug stuff in the frag shader with compile flags
- Also disable discard and conservative depth with CutoutShaders.OFF
This commit is contained in:
Jozufozu 2024-09-22 15:51:37 -07:00
parent 897c350f41
commit 36b0ad4cf9
7 changed files with 40 additions and 6 deletions

View File

@ -15,6 +15,7 @@ import dev.engine_room.flywheel.backend.compile.component.InstanceStructComponen
import dev.engine_room.flywheel.backend.compile.component.SsboInstanceComponent;
import dev.engine_room.flywheel.backend.compile.core.CompilationHarness;
import dev.engine_room.flywheel.backend.compile.core.Compile;
import dev.engine_room.flywheel.backend.engine.uniform.FrameUniforms;
import dev.engine_room.flywheel.backend.engine.uniform.Uniforms;
import dev.engine_room.flywheel.backend.gl.GlCompat;
import dev.engine_room.flywheel.backend.gl.shader.GlProgram;
@ -151,7 +152,7 @@ public class IndirectPrograms extends AtomicReferenceCounted {
}
public GlProgram getIndirectProgram(InstanceType<?> instanceType, ContextShader contextShader, LightShader light, CutoutShader cutout, MaterialShaders shaders) {
return pipeline.get(new PipelineProgramKey(instanceType, contextShader, light, cutout, shaders));
return pipeline.get(new PipelineProgramKey(instanceType, contextShader, light, cutout, shaders, FrameUniforms.debugOn()));
}
public GlProgram getCullingProgram(InstanceType<?> instanceType) {

View File

@ -11,6 +11,7 @@ import dev.engine_room.flywheel.api.material.CutoutShader;
import dev.engine_room.flywheel.api.material.LightShader;
import dev.engine_room.flywheel.api.material.MaterialShaders;
import dev.engine_room.flywheel.backend.compile.core.CompilationHarness;
import dev.engine_room.flywheel.backend.engine.uniform.FrameUniforms;
import dev.engine_room.flywheel.backend.gl.GlCompat;
import dev.engine_room.flywheel.backend.gl.shader.GlProgram;
import dev.engine_room.flywheel.backend.glsl.GlslVersion;
@ -74,7 +75,7 @@ public class InstancingPrograms extends AtomicReferenceCounted {
}
public GlProgram get(InstanceType<?> instanceType, ContextShader contextShader, LightShader light, CutoutShader cutout, MaterialShaders materialShaders) {
return pipeline.get(new PipelineProgramKey(instanceType, contextShader, light, cutout, materialShaders));
return pipeline.get(new PipelineProgramKey(instanceType, contextShader, light, cutout, materialShaders, FrameUniforms.debugOn()));
}
@Override

View File

@ -16,6 +16,7 @@ import dev.engine_room.flywheel.backend.gl.shader.GlProgram;
import dev.engine_room.flywheel.backend.gl.shader.ShaderType;
import dev.engine_room.flywheel.backend.glsl.ShaderSources;
import dev.engine_room.flywheel.backend.glsl.SourceComponent;
import dev.engine_room.flywheel.lib.material.CutoutShaders;
import dev.engine_room.flywheel.lib.util.ResourceUtil;
import net.minecraft.resources.ResourceLocation;
@ -39,12 +40,18 @@ public final class PipelineCompiler {
.vertexSource());
var context = key.contextShader()
.nameLowerCase();
return "pipeline/" + pipeline.compilerMarker() + "/" + instance + "/" + material + "_" + context;
var debug = key.debugEnabled() ? "_debug" : "";
return "pipeline/" + pipeline.compilerMarker() + "/" + instance + "/" + material + "_" + context + debug;
})
.requireExtensions(extensions)
.onCompile((key, comp) -> key.contextShader()
.onCompile(comp))
.onCompile((key, comp) -> lightSmoothness.onCompile(comp))
.onCompile((key, comp) -> {
if (key.debugEnabled()) {
comp.define("_FLW_DEBUG");
}
})
.withResource(API_IMPL_VERT)
.withComponent(key -> new InstanceStructComponent(key.instanceType()))
.withResource(key -> key.instanceType()
@ -69,13 +76,24 @@ public final class PipelineCompiler {
var light = ResourceUtil.toDebugFileNameNoExtension(key.light()
.source());
return "pipeline/" + pipeline.compilerMarker() + "/frag/" + material + "/" + light + "_" + cutout + "_" + context;
var debug = key.debugEnabled() ? "_debug" : "";
return "pipeline/" + pipeline.compilerMarker() + "/frag/" + material + "/" + light + "_" + cutout + "_" + context + debug;
})
.requireExtensions(extensions)
.enableExtension("GL_ARB_conservative_depth")
.onCompile((key, comp) -> key.contextShader()
.onCompile(comp))
.onCompile((key, comp) -> lightSmoothness.onCompile(comp))
.onCompile((key, comp) -> {
if (key.debugEnabled()) {
comp.define("_FLW_DEBUG");
}
})
.onCompile((key, comp) -> {
if (key.cutout() != CutoutShaders.OFF) {
comp.define("_FLW_USE_DISCARD");
}
})
.withResource(API_IMPL_FRAG)
.withResource(key -> key.materialShaders()
.fragmentSource())

View File

@ -13,5 +13,5 @@ import dev.engine_room.flywheel.api.material.MaterialShaders;
* @param light The light shader to use.
*/
public record PipelineProgramKey(InstanceType<?> instanceType, ContextShader contextShader, LightShader light,
CutoutShader cutout, MaterialShaders materialShaders) {
CutoutShader cutout, MaterialShaders materialShaders, boolean debugEnabled) {
}

View File

@ -315,4 +315,8 @@ public final class FrameUniforms extends UniformWriter {
MemoryUtil.memPutFloat(ptr + 88, nzW);
MemoryUtil.memPutFloat(ptr + 92, pzW);
}
public static boolean debugOn() {
return debugMode != DebugMode.OFF.ordinal();
}
}

View File

@ -3,7 +3,7 @@
#include "flywheel:internal/colorizer.glsl"
// optimize discard usage
#ifdef GL_ARB_conservative_depth
#if defined(GL_ARB_conservative_depth) && defined(_FLW_USE_DISCARD)
layout (depth_greater) out float gl_FragDepth;
#endif
@ -13,7 +13,9 @@ uniform sampler2D _flw_crumblingTex;
in vec2 _flw_crumblingTexCoord;
#endif
#ifdef _FLW_DEBUG
flat in uint _flw_instanceID;
#endif
out vec4 _flw_outputColor;
@ -49,9 +51,11 @@ void _flw_main() {
vec4 color = flw_fragColor;
#ifdef _FLW_USE_DISCARD
if (flw_discardPredicate(color)) {
discard;
}
#endif
float diffuseFactor = _flw_diffuseFactor();
color.rgb *= diffuseFactor;
@ -67,6 +71,7 @@ void _flw_main() {
color *= lightColor;
}
#ifdef _FLW_DEBUG
switch (_flw_debugMode) {
case 1u:
color = vec4(flw_vertexNormal * .5 + .5, 1.);
@ -87,6 +92,7 @@ void _flw_main() {
color = vec4(vec3(diffuseFactor), 1.);
break;
}
#endif
_flw_outputColor = flw_fogFilter(color);
}

View File

@ -71,7 +71,9 @@ mat4 _flw_modelMatrix;
mat3 _flw_normalMatrix;
#endif
#ifdef _FLW_DEBUG
flat out uint _flw_instanceID;
#endif
void _flw_main(in FlwInstance instance, in uint stableInstanceID) {
_flw_layoutVertex();
@ -93,5 +95,7 @@ void _flw_main(in FlwInstance instance, in uint stableInstanceID) {
gl_Position = flw_viewProjection * flw_vertexPos;
#ifdef _FLW_DEBUG
_flw_instanceID = stableInstanceID;
#endif
}