forked from CaffeineMC/sodium
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
759 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,4 +101,7 @@ public RenderRegion getRegion() { | |
return this.region; | ||
} | ||
|
||
public int size() { | ||
return this.size; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/me/jellysquid/mods/sodium/client/render/util/DeferredRenderTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package me.jellysquid.mods.sodium.client.render.util; | ||
|
||
import java.util.concurrent.ConcurrentLinkedDeque; | ||
|
||
public class DeferredRenderTask { | ||
private static final ConcurrentLinkedDeque<Runnable> queue = new ConcurrentLinkedDeque<>(); | ||
|
||
/** | ||
* Schedules a render task to be executed on the main render thread as soon as possible. This is often at the | ||
* start of the next frame. | ||
* @param runnable The task to be executed on the render thread | ||
*/ | ||
public static void schedule(Runnable runnable) { | ||
queue.add(runnable); | ||
} | ||
|
||
/** | ||
* Executes all currently pending render tasks. This should only be called from the main render thread! | ||
*/ | ||
public static void runAll() { | ||
RenderAsserts.validateCurrentThread(); | ||
|
||
Runnable runnable; | ||
|
||
while ((runnable = queue.poll()) != null) { | ||
try { | ||
runnable.run(); | ||
} catch (Throwable throwable) { | ||
throw new RuntimeException("Failed to execute deferred render task", throwable); | ||
} | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/me/jellysquid/mods/sodium/client/render/util/RenderAsserts.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package me.jellysquid.mods.sodium.client.render.util; | ||
|
||
import com.mojang.blaze3d.systems.RenderSystem; | ||
|
||
public class RenderAsserts { | ||
/** | ||
* Checks that the thread calling this function is the main render thread. This is useful for ensuring that OpenGL | ||
* APIs are not accessed from off-thread incorrectly, which is known to cause severe issues. | ||
* | ||
* @throws IllegalStateException If the current thread is not the main render thread | ||
* @return Always true, since an exception is thrown otherwise | ||
*/ | ||
public static boolean validateCurrentThread() { | ||
if (!RenderSystem.isOnRenderThread()) { | ||
throw new IllegalStateException("Accessing OpenGL functions from outside the main render thread is not supported when using Sodium"); | ||
} | ||
|
||
return true; | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
src/main/java/me/jellysquid/mods/sodium/client/util/workarounds/InGameChecks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package me.jellysquid.mods.sodium.client.util.workarounds; | ||
|
||
import me.jellysquid.mods.sodium.client.gui.console.Console; | ||
import me.jellysquid.mods.sodium.client.gui.console.message.MessageLevel; | ||
import net.minecraft.resource.ResourceManager; | ||
import net.minecraft.resource.ResourceType; | ||
import net.minecraft.text.MutableText; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Identifier; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class InGameChecks { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger("Sodium-InGameChecks"); | ||
private static final List<String> VSH_FSH_BLACKLIST = Arrays.asList( | ||
"rendertype_solid.vsh", "rendertype_solid.fsh", | ||
"rendertype_cutout_mipped.vsh", "rendertype_cutout_mipped.fsh", | ||
"rendertype_cutout.vsh", "rendertype_cutout.fsh", | ||
"rendertype_translucent.vsh", "rendertype_translucent.fsh", | ||
"rendertype_tripwire.vsh", "rendertype_tripwire.fsh" | ||
); | ||
private static final List<String> GLSL_BLACKLIST = Arrays.asList( | ||
"light.glsl", | ||
"fog.glsl" | ||
); | ||
|
||
/** | ||
* <a href="https://github.com/CaffeineMC/sodium-fabric/issues/1569">#1569</a> | ||
* Iterate through all active resource packs, and detect resource packs which contain files matching the blacklist. | ||
* An error message is shown for resource packs which replace terrain core shaders. | ||
* A warning is shown for resource packs which replace the default light.glsl and fog.glsl shaders. | ||
* Detailed information on shader files replaced by resource packs is printed in the client log. | ||
*/ | ||
public static void checkIfCoreShaderLoaded(ResourceManager manager) { | ||
HashMap<String, MessageLevel> detectedResourcePacks = new HashMap<>(); | ||
var customResourcePacks = manager.streamResourcePacks(); | ||
|
||
customResourcePacks.forEach(resourcePack -> { | ||
// Omit 'vanilla' and 'fabric' resource packs | ||
if (!resourcePack.getName().equals("vanilla") && !resourcePack.getName().equals("fabric")) { | ||
var resourcePackName = resourcePack.getName(); | ||
|
||
resourcePack.findResources(ResourceType.CLIENT_RESOURCES, Identifier.DEFAULT_NAMESPACE, "shaders", (path, ignored) -> { | ||
// Trim full shader file path to only contain the filename | ||
var shaderName = path.getPath().substring(path.getPath().lastIndexOf('/') + 1); | ||
if (VSH_FSH_BLACKLIST.contains(shaderName)) { | ||
|
||
if (!detectedResourcePacks.containsKey(resourcePackName)) { | ||
detectedResourcePacks.put(resourcePackName, MessageLevel.SEVERE); | ||
} else if (detectedResourcePacks.get(resourcePackName) == MessageLevel.WARN) { | ||
detectedResourcePacks.replace(resourcePackName, MessageLevel.SEVERE); | ||
} | ||
|
||
LOGGER.error("Resource pack '" + resourcePackName + "' replaces core shader '" + shaderName + "'"); | ||
} | ||
|
||
if (GLSL_BLACKLIST.contains(shaderName)) { | ||
|
||
if (!detectedResourcePacks.containsKey(resourcePackName)) { | ||
detectedResourcePacks.put(resourcePackName, MessageLevel.WARN); | ||
} | ||
|
||
LOGGER.warn("Resource pack '" + resourcePackName + "' replaces shader '" + shaderName + "'"); | ||
|
||
} | ||
}); | ||
} | ||
}); | ||
|
||
if (detectedResourcePacks.containsValue(MessageLevel.SEVERE)) { | ||
showConsoleMessage(Text.translatable("sodium.console.core_shaders_error"), MessageLevel.SEVERE); | ||
|
||
for (Map.Entry<String, MessageLevel> entry : detectedResourcePacks.entrySet()) { | ||
|
||
if (entry.getValue() == MessageLevel.SEVERE) { | ||
// Omit 'file/' prefix for the in-game message | ||
var message = entry.getKey().startsWith("file/") ? entry.getKey().substring(5) : entry.getKey(); | ||
showConsoleMessage(Text.literal(message), MessageLevel.SEVERE); | ||
} | ||
} | ||
} | ||
|
||
if (detectedResourcePacks.containsValue(MessageLevel.WARN)) { | ||
showConsoleMessage(Text.translatable("sodium.console.core_shaders_warn"), MessageLevel.WARN); | ||
|
||
for (Map.Entry<String, MessageLevel> entry : detectedResourcePacks.entrySet()) { | ||
|
||
if (entry.getValue() == MessageLevel.WARN) { | ||
// Omit 'file/' prefix for the in-game message | ||
var message = entry.getKey().startsWith("file/") ? entry.getKey().substring(5) : entry.getKey(); | ||
showConsoleMessage(Text.literal(message), MessageLevel.WARN); | ||
} | ||
} | ||
} | ||
|
||
if (!detectedResourcePacks.isEmpty()) { | ||
showConsoleMessage(Text.translatable("sodium.console.core_shaders_info"), MessageLevel.INFO); | ||
} | ||
} | ||
|
||
private static void showConsoleMessage(MutableText message, MessageLevel messageLevel) { | ||
Console.instance().logMessage(messageLevel, message, 20.0); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
.../jellysquid/mods/sodium/client/util/workarounds/platform/windows/WindowsModuleChecks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package me.jellysquid.mods.sodium.client.util.workarounds.platform.windows; | ||
|
||
import net.minecraft.util.Util; | ||
import net.minecraft.util.WinNativeModuleUtil; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.List; | ||
|
||
public class WindowsModuleChecks { | ||
private static final Logger LOGGER = LoggerFactory.getLogger("Sodium-Win32ModuleChecks"); | ||
|
||
public static void checkModules() { | ||
if (Util.getOperatingSystem() != Util.OperatingSystem.WINDOWS) { | ||
return; | ||
} | ||
|
||
LOGGER.warn("Checking for problematic loaded Win32 modules... (this may take a moment)"); | ||
|
||
List<WinNativeModuleUtil.NativeModule> modules; | ||
|
||
try { | ||
modules = WinNativeModuleUtil.collectNativeModules(); | ||
} catch (Throwable t) { | ||
LOGGER.warn("Failed to scan the currently loaded modules", t); | ||
return; | ||
} | ||
|
||
// RivaTuner hooks the wglCreateContext function, and leaves itself behind as a loaded module | ||
if (Boolean.parseBoolean(System.getProperty("sodium.checks.win32.rtss", "true")) && modules.stream().anyMatch(module -> module.path.equalsIgnoreCase("RTSSHooks64.dll"))) { | ||
LOGGER.error("------------------------------------------------------------------------------------------------------------"); | ||
LOGGER.error("READ ME! You appear to be using the RivaTuner Statistics Server (RTSS)!"); | ||
LOGGER.error(" * Rivatuner will cause extreme performance issues when using Sodium, and it will likely fill up your hard drive"); | ||
LOGGER.error(" with error logs."); | ||
LOGGER.error(" * You must fully disable (or uninstall) the RivaTuner Statistics Server."); | ||
LOGGER.error(" * If you don't remember installing RivaTuner, check to see if you have MSI Afterburner installed."); | ||
LOGGER.error(" * For more information on possible workarounds and alternatives to Rivatuner, see the following issue on GitHub:"); | ||
LOGGER.error(" https://github.com/CaffeineMC/sodium-fabric/issues/2048"); | ||
LOGGER.error(" * HINT: If you believe this is an error, then you can force the game to start anyways by adding the " + | ||
"following JVM argument."); | ||
LOGGER.error(" -Dsodium.checks.win32.rtss" + "=false"); | ||
LOGGER.error(" * NOTE: We will not provide support for any issues caused by using this option. You are on your own!"); | ||
LOGGER.error("------------------------------------------------------------------------------------------------------------"); | ||
|
||
throw new RuntimeException("RivaTuner Statistics Server (RTSS) is not compatible with Sodium, " + | ||
"see this issue for more details: https://github.com/CaffeineMC/sodium-fabric/issues/2048"); | ||
} | ||
} | ||
} |
Oops, something went wrong.