Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ dependencies {
}
})

compileOnly("io.github.llamalad7:mixinextras-common:0.3.5")
annotationProcessor("io.github.llamalad7:mixinextras-common:0.3.5")
compileOnly("io.github.llamalad7:mixinextras-common:0.4.1")
annotationProcessor("io.github.llamalad7:mixinextras-common:0.4.1")

compileOnly("net.fabricmc:sponge-mixin:0.13.2+mixin.0.8.5")
compileOnly("net.fabricmc:fabric-loader:${BuildConfig.FABRIC_LOADER_VERSION}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ protected MixinConfig() {

this.addMixinRule("features.render.immediate", true);
this.addMixinRule("features.render.immediate.buffer_builder", true);
this.addMixinRule("features.render.immediate.buffer_upload", true);
this.addMixinRule("features.render.immediate.matrix_stack", true);

this.addMixinRule("features.render.model", true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package net.caffeinemc.mods.sodium.mixin.features.render.immediate.buffer_upload;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import com.mojang.blaze3d.opengl.GlBuffer;

@Mixin(GlBuffer.class)
public interface GlBufferAccessor {

@Accessor
void setInitialized(boolean value);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package net.caffeinemc.mods.sodium.mixin.features.render.immediate.buffer_upload;

import java.nio.ByteBuffer;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.llamalad7.mixinextras.injector.ModifyReceiver;
import com.llamalad7.mixinextras.sugar.Cancellable;
import com.llamalad7.mixinextras.sugar.Local;
import com.mojang.blaze3d.buffers.GpuBuffer;
import com.mojang.blaze3d.systems.CommandEncoder;
import com.mojang.blaze3d.vertex.VertexFormat;

/**
* Fixes an issue where buffer uploads can be slow on some systems due to Vanilla using {@code glBufferSubData} in 1.21.5 (MC-295893).
*/
@Mixin(VertexFormat.class)
public class VertexFormatMixin {

@ModifyReceiver(method = { "uploadImmediateVertexBuffer", "uploadImmediateIndexBuffer" }, at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/buffers/GpuBuffer;size()I"), require = 2)
private GpuBuffer replaceBufferData(GpuBuffer gpuBuffer, ByteBuffer data, @Local CommandEncoder commandEncoder, @Cancellable CallbackInfoReturnable<GpuBuffer> cir) {
//Setting the initialized field to false forces the glBufferSubData path to be skipped in GlCommandEncoder
((GlBufferAccessor) gpuBuffer).setInitialized(false);
//Update the size of the GpuBuffer
gpuBuffer.size = data.remaining();

//Write the data and cancel the method
commandEncoder.writeToBuffer(gpuBuffer, data, 0);
cir.setReturnValue(gpuBuffer);

return gpuBuffer;
}
}
2 changes: 2 additions & 0 deletions common/src/main/resources/sodium-common.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
"features.render.immediate.buffer_builder.intrinsics.BufferBuilderMixin",
"features.render.immediate.buffer_builder.sorting.MeshDataMixin",
"features.render.immediate.buffer_builder.sorting.VertexSortingMixin",
"features.render.immediate.buffer_upload.GlBufferAccessor",
"features.render.immediate.buffer_upload.VertexFormatMixin",
"features.render.immediate.matrix_stack.VertexConsumerMixin",
"features.render.model.ItemBlockRenderTypesMixin",
"features.render.model.item.ItemRendererMixin",
Expand Down