Skip to content

Commit

Permalink
To bug or not to bug
Browse files Browse the repository at this point in the history
- Disable the debug stuff in the frag shader with compile flags
- Also disable discard and conservative depth with CutoutShaders.OFF
  • Loading branch information
Jozufozu committed Sep 22, 2024
1 parent 897c350 commit 36b0ad4
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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;
Expand Down Expand Up @@ -151,7 +152,7 @@ public static void kill() {
}

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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;
Expand Down Expand Up @@ -74,7 +75,7 @@ public static void kill() {
}

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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;

Expand All @@ -39,12 +40,18 @@ static CompilationHarness<PipelineProgramKey> create(ShaderSources sources, Pipe
.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()
Expand All @@ -69,13 +76,24 @@ static CompilationHarness<PipelineProgramKey> create(ShaderSources sources, Pipe

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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
* @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) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,8 @@ private static void writePackedFrustumPlanes(long ptr, Matrix4f m) {
MemoryUtil.memPutFloat(ptr + 88, nzW);
MemoryUtil.memPutFloat(ptr + 92, pzW);
}

public static boolean debugOn() {
return debugMode != DebugMode.OFF.ordinal();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -67,6 +71,7 @@ void _flw_main() {
color *= lightColor;
}

#ifdef _FLW_DEBUG
switch (_flw_debugMode) {
case 1u:
color = vec4(flw_vertexNormal * .5 + .5, 1.);
Expand All @@ -87,6 +92,7 @@ void _flw_main() {
color = vec4(vec3(diffuseFactor), 1.);
break;
}
#endif

_flw_outputColor = flw_fogFilter(color);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
}

0 comments on commit 36b0ad4

Please sign in to comment.