Skip to content

Commit

Permalink
Merge branch '1.21.1/stable' into spriteutil
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr authored Feb 9, 2025
2 parents d906802 + 410a730 commit 9f8de5b
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 19 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/BuildConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object BuildConfig {
val PARCHMENT_VERSION: String? = "2024.11.17"

// https://semver.org/
var MOD_VERSION: String = "0.6.7-rc.1"
var MOD_VERSION: String = "0.6.7"

fun createVersionString(project: Project): String {
val builder = StringBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import org.jetbrains.annotations.Nullable;
import org.joml.Vector3f;

import java.util.Iterator;

public class BlockRenderer extends AbstractBlockRenderContext {
private final ColorProviderRegistry colorProviderRegistry;
private final int[] vertexColors = new int[4];
Expand All @@ -55,6 +57,7 @@ public class BlockRenderer extends AbstractBlockRenderContext {
@Nullable
private ColorProvider<BlockState> colorProvider;
private TranslucentGeometryCollector collector;
private boolean allowDowngrade;

public BlockRenderer(ColorProviderRegistry colorRegistry, LightPipelineProvider lighters) {
this.colorProviderRegistry = colorRegistry;
Expand Down Expand Up @@ -99,9 +102,20 @@ public void renderModel(BakedModel model, BlockState state, BlockPos pos, BlockP
modelData = PlatformModelAccess.getInstance().getModelData(slice, model, state, pos, slice.getPlatformModelData(pos));

Iterable<RenderType> renderTypes = PlatformModelAccess.getInstance().getModelRenderTypes(level, model, state, pos, random, modelData);
this.allowDowngrade = true;

Iterator<RenderType> it = renderTypes.iterator();
var defaultType = ItemBlockRenderTypes.getChunkRenderType(state);

while (it.hasNext()) {
this.type = it.next();

// TODO: This can be removed once we have a better solution for https://github.com/CaffeineMC/sodium/issues/2868
// If the model contains any materials that are not the default, we can't allow the block to be downgraded. This avoids a potentially incorrect render order if there are overlapping quads.
if (it.hasNext() || this.type != defaultType) {
this.allowDowngrade = false;
}

for (RenderType type : renderTypes) {
this.type = type;
((FabricBakedModel) model).emitBlockQuads(this.level, state, pos, this.randomSupplier, this);
}

Expand Down Expand Up @@ -228,7 +242,7 @@ private boolean validateQuadUVs(TextureAtlasSprite atlasSprite) {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import net.caffeinemc.mods.sodium.client.render.chunk.RenderSection;
import net.caffeinemc.mods.sodium.client.render.chunk.RenderSectionFlags;
import net.caffeinemc.mods.sodium.client.render.chunk.region.RenderRegion;
import net.caffeinemc.mods.sodium.client.render.viewport.CameraTransform;
import net.caffeinemc.mods.sodium.client.util.iterator.ByteArrayIterator;
import net.caffeinemc.mods.sodium.client.util.iterator.ByteIterator;
import net.caffeinemc.mods.sodium.client.util.iterator.ReversibleByteArrayIterator;
import net.minecraft.core.SectionPos;
import net.minecraft.util.Mth;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -43,10 +43,10 @@ public void reset(int frame) {
// clamping the relative camera position to the region bounds means there can only be very few different distances
private static final int SORTING_HISTOGRAM_SIZE = RenderRegion.REGION_WIDTH + RenderRegion.REGION_HEIGHT + RenderRegion.REGION_LENGTH - 2;

public void sortSections(CameraTransform transform, int[] sortItems) {
var cameraX = Mth.clamp((transform.intX >> 4) - this.region.getChunkX(), 0, RenderRegion.REGION_WIDTH - 1);
var cameraY = Mth.clamp((transform.intY >> 4) - this.region.getChunkY(), 0, RenderRegion.REGION_HEIGHT - 1);
var cameraZ = Mth.clamp((transform.intZ >> 4) - this.region.getChunkZ(), 0, RenderRegion.REGION_LENGTH - 1);
public void sortSections(SectionPos cameraPos, int[] sortItems) {
var cameraX = Mth.clamp(cameraPos.getX() - this.region.getChunkX(), 0, RenderRegion.REGION_WIDTH - 1);
var cameraY = Mth.clamp(cameraPos.getY() - this.region.getChunkY(), 0, RenderRegion.REGION_HEIGHT - 1);
var cameraZ = Mth.clamp(cameraPos.getZ() - this.region.getChunkZ(), 0, RenderRegion.REGION_LENGTH - 1);

int[] histogram = new int[SORTING_HISTOGRAM_SIZE];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import net.caffeinemc.mods.sodium.client.render.chunk.region.RenderRegion;
import net.caffeinemc.mods.sodium.client.render.viewport.Viewport;

import java.util.*;
import java.util.ArrayDeque;
import java.util.EnumMap;
import java.util.Map;
import java.util.Queue;

/**
* The visible chunk collector is passed to the occlusion graph search culler to
Expand Down Expand Up @@ -67,10 +70,10 @@ private void addToRebuildLists(RenderSection section) {

public SortedRenderLists createRenderLists(Viewport viewport) {
// sort the regions by distance to fix rare region ordering bugs
var transform = viewport.getTransform();
var cameraX = transform.intX >> (4 + RenderRegion.REGION_WIDTH_SH);
var cameraY = transform.intY >> (4 + RenderRegion.REGION_HEIGHT_SH);
var cameraZ = transform.intZ >> (4 + RenderRegion.REGION_LENGTH_SH);
var sectionPos = viewport.getChunkCoord();
var cameraX = sectionPos.getX() >> RenderRegion.REGION_WIDTH_SH;
var cameraY = sectionPos.getY() >> RenderRegion.REGION_HEIGHT_SH;
var cameraZ = sectionPos.getZ() >> RenderRegion.REGION_LENGTH_SH;
var size = this.sortedRenderLists.size();

if (sortItems.length < size) {
Expand All @@ -95,7 +98,7 @@ public SortedRenderLists createRenderLists(Viewport viewport) {
}

for (var list : sorted) {
list.sortSections(transform, sortItems);
list.sortSections(sectionPos, sortItems);
}

return new SortedRenderLists(sorted);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,58 @@
* failing checks will crash the game and prompt the user for intervention.
*/
class BugChecks {
/**
* Some older drivers for Intel Gen7 Graphics on Windows are defective and will never return from
* a call to <pre>glClientWaitSync</pre>. As there is no way to recover the main thread after the
* deadlock occurs, trying to work around this seems to be impossible. Updating the driver to version
* 15.33.53.5161 resolves the problem, and is the currently recommended solution.
* <a href="https://github.com/CaffeineMC/sodium/issues/899">GitHub Issue</a>
*/
public static final boolean ISSUE_899 = configureCheck("issue899", true);

/**
* Since version 526.47 of the NVIDIA Graphics Driver, the OpenGL user-mode driver will attempt to detect
* Minecraft with hard-coded logic in the driver, and enable broken optimizations (referred to as "Threaded
* Optimizations"). This will cause crashes during framebuffer initialization (and some draw calls) for unclear
* reasons, especially on systems with hybrid graphics. Furthermore, performance is often severely degraded
* due to bubbles in the NVIDIA command submission thread, especially when other mods query context state.
* <p>
* Sodium can prevent the detection of Minecraft and the enablement of these unstable optimizations, but the logic
* is extensive and depends heavily on the exact operating system and graphics driver version used. Some older
* graphics driver versions have no workaround available presently.
* <a href="https://github.com/CaffeineMC/sodium/issues/1486">GitHub Issue</a>
*/
public static final boolean ISSUE_1486 = configureCheck("issue1486", true);

/**
* Older versions of the RivaTuner Statistics Server will attempt to use legacy OpenGL functions in a Core
* profile, which causes either a crash or excessive log spam, depending on the OpenGL implementation. This is
* because RivaTuner relies on replacing the OpenGL context immediately after the application initializes it,
* but does so improperly when a No Error Context is used. This problem can't be avoided by simply configuring
* RivaTuner to not inject into Minecraft, as it *always* injects first to modify the context, and *then* disables
* itself.
* <a href="https://github.com/CaffeineMC/sodium/issues/2048">GitHub Issue</a>
*/
public static final boolean ISSUE_2048 = configureCheck("issue2048", true);

/**
* LWJGL does not provide API stability guarantees for other libraries using it to create their own C bindings.
* Because of this, the game will crash due to breaking method/type signature changes very early at startup. We
* should not be using these "internal" classes in LWJGL, but the amount of work involved doing everything ourselves
* is astronomical. When Minecraft ships a version of OpenJDK with the Foreign Function & Memory API, we can replace
* our dependency on LWJGL and remove this check.
* <a href="https://github.com/CaffeineMC/sodium/issues/2561">GitHub Issue</a>
*/
public static final boolean ISSUE_2561 = configureCheck("issue2561", true);

/**
* ASUS's GPU Tweak III does not correctly restore OpenGL context state after rendering its in-game overlay,
* which frequently causes graphical corruption, excessive log file spam, and crashes. These problems are
* actually reproducible without any mods installed, but it seems to be exacerbated with Sodium due to how different
* the rendering pipeline is. This problem can be avoided by configuring the application to not inject into
* Minecraft (or Java applications).
* <a href="https://github.com/CaffeineMC/sodium/issues/2637">GitHub Issue</a>
*/
public static final boolean ISSUE_2637 = configureCheck("issue2637", true);

private static boolean configureCheck(String name, boolean defaultValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ public enum GraphicsAdapterVendor {
// Intel Gen 8 - ig8icd
// Intel Gen 9, 9.5 - ig9icd
// Intel Gen 11 - ig11icd
// Intel Gen 12 - ig12icd (UHD Graphics, with early drivers)
// igxelpicd (Xe-LP; integrated)
// igxehpicd (Xe-HP; dedicated)
// Intel Xe - ig12icd (Xe-LP; early drivers) or igxelpicd (Xe-LP; later drivers), and igxehpicd (Xe-HP)
// Intel Xe2 - igxe2lpicd (Xe2-LP) and igxe2lpicd (Xe2-HP)
private static final Pattern INTEL_ICD_PATTERN =
Pattern.compile("ig(4|7|75|8|9|11|12|xelp|xehp)icd(32|64)\\.dll", Pattern.CASE_INSENSITIVE);
Pattern.compile("ig(4|7|75|8|9|11|12|(xe(2)?(hp|lp)))icd(32|64)\\.dll", Pattern.CASE_INSENSITIVE);

private static final Pattern NVIDIA_ICD_PATTERN =
Pattern.compile("nvoglv(32|64)\\.dll", Pattern.CASE_INSENSITIVE);
Expand Down

0 comments on commit 9f8de5b

Please sign in to comment.