Skip to content

Commit 21c01a1

Browse files
authored
Fix terrible performance on Intel (#1718)
1 parent 83a26b2 commit 21c01a1

6 files changed

Lines changed: 30 additions & 1 deletion

File tree

glsm/src/main/java/com/gtnewhorizons/angelica/glsm/GLStateManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ public static void flushDeferredVertexAttribs() {
188188

189189
@Getter private static Vendor VENDOR;
190190

191+
@Getter private static boolean windows;
192+
191193
// This setting varies depending on driver, so it gets queried at runtime
192194
public static int DEFAULT_DRAW_BUFFER = 0x0405; // GL_BACK
193195

@@ -528,6 +530,10 @@ static void init(Runnable initCallback) {
528530
final String glVendor = RENDER_BACKEND.getString(GL11.GL_VENDOR);
529531
VENDOR = Vendor.getVendor(glVendor.toLowerCase());
530532

533+
final String os = System.getProperty("os.name").toLowerCase();
534+
535+
windows = os.contains("win");
536+
531537
// The initial mask value should be defined as all 1's. However, some drivers have it set to 0's.
532538
// To ensure consistency & correctness across all drivers, we're setting them to 0xFF.
533539
RENDER_BACKEND.stencilFunc(stencilState.getFuncFront(), stencilState.getRefFront(), 0xFF);

glsm/src/main/java/com/gtnewhorizons/angelica/glsm/RenderSystem.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.gtnewhorizons.angelica.glsm.dsa.DSAEXT;
88
import com.gtnewhorizons.angelica.glsm.dsa.DSAUnsupported;
99
import com.gtnewhorizons.angelica.glsm.ffp.ShaderManager;
10+
import com.gtnewhorizons.angelica.glsm.hooks.GLSMInitConfig;
1011
import com.gtnewhorizons.angelica.glsm.texture.TextureInfoCache;
1112
import org.jetbrains.annotations.Nullable;
1213
import org.joml.Matrix4f;
@@ -61,7 +62,13 @@ public static void initRenderer() {
6162
if (rendererInitialized) return;
6263
rendererInitialized = true;
6364
try {
64-
if (GLStateManager.capabilities.OpenGL45) {
65+
if (GLStateManager.vendorIsIntel() && GLStateManager.isWindows()) {
66+
dsaState = new DSAUnsupported();
67+
GLStateManager.LOGGER.info("Detected Intel drivers on Windows, disabling DSA.");
68+
} else if (!GLStateManager.getInitConfig().isDSAEnabled()) {
69+
dsaState = new DSAUnsupported();
70+
GLStateManager.LOGGER.info("enableDSA is set to false, disabling DSA.");
71+
} else if (GLStateManager.capabilities.OpenGL45) {
6572
dsaState = (Runtime.version().feature() > 8 && GLStateManager.capabilities.GL_EXT_direct_state_access) ? new DSAEXT() : new DSACore();
6673
GLStateManager.LOGGER.info("OpenGL 4.5 detected, enabling DSA.");
6774
}

glsm/src/main/java/com/gtnewhorizons/angelica/glsm/hooks/GLSMInitConfig.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public final class GLSMInitConfig {
1515
private final int displayWidth;
1616
private final int displayHeight;
1717
private final Runnable postInitCallback;
18+
private final boolean enableDSA;
1819

1920
private GLSMInitConfig(Builder builder) {
2021
this.lwjglDebug = builder.lwjglDebug;
@@ -26,6 +27,7 @@ private GLSMInitConfig(Builder builder) {
2627
this.displayWidth = builder.displayWidth;
2728
this.displayHeight = builder.displayHeight;
2829
this.postInitCallback = builder.postInitCallback;
30+
this.enableDSA = builder.enableDSA;
2931
}
3032

3133
public static Builder builder() {
@@ -41,6 +43,7 @@ public static Builder builder() {
4143
public int getDisplayWidth() { return displayWidth; }
4244
public int getDisplayHeight() { return displayHeight; }
4345
public Runnable getPostInitCallback() { return postInitCallback; }
46+
public boolean isDSAEnabled() { return enableDSA; }
4447

4548
public static final class Builder {
4649
private boolean lwjglDebug = false;
@@ -52,6 +55,7 @@ public static final class Builder {
5255
private int displayWidth = 0;
5356
private int displayHeight = 0;
5457
private Runnable postInitCallback = null;
58+
private boolean enableDSA = false;
5559

5660
private Builder() {}
5761

@@ -96,6 +100,11 @@ public Builder postInitCallback(Runnable callback) {
96100
return this;
97101
}
98102

103+
public Builder enableDSA(boolean enableDSA) {
104+
this.enableDSA = enableDSA;
105+
return this;
106+
}
107+
99108
public GLSMInitConfig build() {
100109
return new GLSMInitConfig(this);
101110
}

src/main/java/com/gtnewhorizons/angelica/config/AngelicaConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ public class AngelicaConfig {
6363
@Config.RequiresMcRestart
6464
public static boolean enableVAO;
6565

66+
@Config.Comment("Enables DSA (Direct State Access) for faster bindings. Disable if you notice terrible performance.")
67+
@Config.DefaultBoolean(true)
68+
@Config.RequiresMcRestart
69+
public static boolean enableDSA;
70+
6671
@Config.Comment("Enable NotFine features")
6772
@Config.DefaultBoolean(true)
6873
@Config.RequiresMcRestart

src/main/java/com/gtnewhorizons/angelica/glsm/RenderSystem.java

Whitespace-only changes.

src/mixin/java/com/gtnewhorizons/angelica/mixins/early/angelica/startup/MixinInitGLStateManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.gtnewhorizons.angelica.AngelicaMod;
44
import com.gtnewhorizons.angelica.client.rendering.TextureTracker;
5+
import com.gtnewhorizons.angelica.config.AngelicaConfig;
56
import com.gtnewhorizons.angelica.glsm.streaming.TessellatorStreamingDrawer;
67
import com.gtnewhorizons.angelica.compat.DriverCompatabilityCheck;
78
import com.gtnewhorizons.angelica.glsm.GLStateManager;
@@ -31,6 +32,7 @@ public class MixinInitGLStateManager {
3132
.streamingUploadStrategy(ClientProxy.options().advanced.streamingUploadStrategy)
3233
.framebufferSupported(OpenGlHelper.framebufferSupported)
3334
.fboEnabled(mc.gameSettings.fboEnable)
35+
.enableDSA(AngelicaConfig.enableDSA)
3436
.directDrawer(TessellatorStreamingDrawer::drawDirect)
3537
.streamingDrawerDestroy(TessellatorStreamingDrawer::destroy)
3638
.postInitCallback(SelectionBoxRenderer::init)

0 commit comments

Comments
 (0)