Skip to content

Commit

Permalink
Disable material downgrading on Intel Gen8 and older
Browse files Browse the repository at this point in the history
Fixes #2830
  • Loading branch information
jellysquid3 committed Oct 23, 2024
1 parent 37dc5f6 commit 93cdb01
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.caffeinemc.mods.sodium.api.util.ColorABGR;
import net.caffeinemc.mods.sodium.api.util.ColorARGB;
import net.caffeinemc.mods.sodium.client.compatibility.workarounds.Workarounds;
import net.caffeinemc.mods.sodium.client.model.color.ColorProvider;
import net.caffeinemc.mods.sodium.client.model.color.ColorProviderRegistry;
import net.caffeinemc.mods.sodium.client.model.light.LightMode;
Expand Down Expand Up @@ -184,6 +185,7 @@ private void bufferQuad(MutableQuadViewImpl quad, float[] brightnesses, Material

// attempt render pass downgrade if possible
var pass = material.pass;

var downgradedPass = attemptPassDowngrade(atlasSprite, pass);
if (downgradedPass != null) {
pass = downgradedPass;
Expand Down Expand Up @@ -225,7 +227,11 @@ private boolean validateQuadUVs(TextureAtlasSprite atlasSprite) {
return true;
}

private TerrainRenderPass attemptPassDowngrade(TextureAtlasSprite sprite, TerrainRenderPass pass) {
private @Nullable TerrainRenderPass attemptPassDowngrade(TextureAtlasSprite sprite, TerrainRenderPass pass) {
if (Workarounds.isWorkaroundEnabled(Workarounds.Reference.INTEL_DEPTH_BUFFER_COMPARISON_UNRELIABLE)) {
return null;
}

boolean attemptDowngrade = true;
boolean hasNonOpaqueVertex = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class RenderTargetMixin {
*/
@Inject(method = "blitToScreen(IIZ)V", at = @At("HEAD"), cancellable = true)
public void blitToScreen(int width, int height, boolean disableBlend, CallbackInfo ci) {
if (Workarounds.isWorkaroundEnabled(Workarounds.Reference.INTEL_FRAMEBUFFER_BLIT_UNSUPPORTED)) {
if (Workarounds.isWorkaroundEnabled(Workarounds.Reference.INTEL_FRAMEBUFFER_BLIT_CRASH_WHEN_UNFOCUSED)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ private static Set<Reference> findNecessaryWorkarounds() {
workarounds.add(Reference.NVIDIA_THREADED_OPTIMIZATIONS);
}

if (checkIntelFramebufferBlitBug()) {
workarounds.add(Reference.INTEL_FRAMEBUFFER_BLIT_UNSUPPORTED);
if (isUsingIntelGen8OrOlder()) {
workarounds.add(Reference.INTEL_FRAMEBUFFER_BLIT_CRASH_WHEN_UNFOCUSED);
workarounds.add(Reference.INTEL_DEPTH_BUFFER_COMPARISON_UNRELIABLE);
}

if (operatingSystem == OsUtils.OperatingSystem.LINUX) {
Expand All @@ -64,7 +65,7 @@ private static Set<Reference> findNecessaryWorkarounds() {
return Collections.unmodifiableSet(workarounds);
}

private static boolean checkIntelFramebufferBlitBug() {
private static boolean isUsingIntelGen8OrOlder() {
if (OsUtils.getOs() != OsUtils.OperatingSystem.WIN) {
return false;
}
Expand Down Expand Up @@ -109,10 +110,18 @@ public enum Reference {
NO_ERROR_CONTEXT_UNSUPPORTED,

/**
* Intel's graphics driver for Gen 7.5 GPUs seems to be faulty and causes a crash when calling
* Intel's graphics driver for Gen8 and older seems to be faulty and causes a crash when calling
* glFramebufferBlit after the window loses focus.
* <a href="https://github.com/CaffeineMC/sodium-fabric/issues/2727">GitHub Issue</a>
*/
INTEL_FRAMEBUFFER_BLIT_UNSUPPORTED
INTEL_FRAMEBUFFER_BLIT_CRASH_WHEN_UNFOCUSED,

/**
* Intel's graphics driver for Gen8 and older does not respect depth comparison rules per the OpenGL
* specification, causing block model overlays to Z-fight when the overlay is on a different render pass than
* the base model.
* <a href="https://github.com/CaffeineMC/sodium-fabric/issues/2830">GitHub Issue</a>
*/
INTEL_DEPTH_BUFFER_COMPARISON_UNRELIABLE
}
}

0 comments on commit 93cdb01

Please sign in to comment.