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
103 changes: 54 additions & 49 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,57 +16,59 @@ repositories {

dependencies {}

tasks.register("createModule") {
if (!project.hasProperty('id')) {
throw new GradleException("Id property is required. Use -Pid=<id> to specify the version.")
}
String id = project.property("id")
if (id.matches("[A-Z]+")) {
throw new GradleException("Id cannot be all uppercase.")
}
String underlinedId = id.replace('-', '_')
String mod_id = "anvillib_$underlinedId"
String bigHumpName = id.split('-').collect { it.substring(0, 1).toUpperCase() + it.substring(1) }.join()
String mod_name = "AnvilLib-$bigHumpName"
String class_name = "AnvilLib$bigHumpName"
File buildGradle = file("module.$id/build.gradle")
File gradleProperties = file("module.$id/gradle.properties")
File mainClass = file("module.$id/src/main/java/dev/anvilcraft/lib/v2/$underlinedId/${class_name}.java")
File packageInfo = file("module.$id/src/main/java/dev/anvilcraft/lib/v2/$underlinedId/package-info.java")
File modInfoPath = file("module.$id/src/main/resources/META-INF/")
File mixinConfig = file("module.$id/src/main/resources/${mod_id}.mixins.json")
buildGradle.parentFile.mkdirs()
mainClass.parentFile.mkdirs()
modInfoPath.mkdirs()
buildGradle.createNewFile()
gradleProperties.createNewFile()
mainClass.createNewFile()
mixinConfig.createNewFile()
copy {
from file("module.main/src/main/resources/META-INF/neoforge.mods.toml")
into modInfoPath
}
copy {
from file("module.main/src/main/resources/icon.png")
into file("module.$id/src/main/resources/")
}
class CreateModuleTask extends DefaultTask {
@TaskAction
void onCreateModule() {
if (!project.hasProperty('id')) {
throw new GradleException("Id property is required. Use -Pid=<id> to specify the version.")
}
String id = project.property("id")
if (id.matches("[A-Z]+")) {
throw new GradleException("Id cannot be all uppercase.")
}
String underlinedId = id.replace('-', '_')
String mod_id = "anvillib_$underlinedId"
String bigHumpName = id.split('-').collect { it.substring(0, 1).toUpperCase() + it.substring(1) }.join()
String mod_name = "AnvilLib-$bigHumpName"
String class_name = "AnvilLib$bigHumpName"
File buildGradle = file("module.$id/build.gradle")
File gradleProperties = file("module.$id/gradle.properties")
File mainClass = file("module.$id/src/main/java/dev/anvilcraft/lib/v2/$underlinedId/${class_name}.java")
File packageInfo = file("module.$id/src/main/java/dev/anvilcraft/lib/v2/$underlinedId/package-info.java")
File modInfoPath = file("module.$id/src/main/resources/META-INF/")
File mixinConfig = file("module.$id/src/main/resources/${mod_id}.mixins.json")
buildGradle.parentFile.mkdirs()
mainClass.parentFile.mkdirs()
modInfoPath.mkdirs()
buildGradle.createNewFile()
gradleProperties.createNewFile()
mainClass.createNewFile()
mixinConfig.createNewFile()
copy {
from file("module.main/src/main/resources/META-INF/neoforge.mods.toml")
into modInfoPath
}
copy {
from file("module.main/src/main/resources/icon.png")
into file("module.$id/src/main/resources/")
}

buildGradle.write(
"""
buildGradle.write(
"""
dependencies {
}
""".stripIndent().trim()
)
gradleProperties.write(
"""
)
gradleProperties.write(
"""
## Mod Properties
mod_id=$mod_id
mod_name=$mod_name
mod_description=
""".stripIndent().trim()
)
mainClass.write(
"""
)
mainClass.write(
"""
package dev.anvilcraft.lib.v2.$underlinedId;

import net.minecraft.resources.Identifier;
Expand All @@ -82,17 +84,17 @@ tasks.register("createModule") {
}
}
""".stripIndent().trim()
)
packageInfo.write(
"""
)
packageInfo.write(
"""
@NullMarked
package dev.anvilcraft.lib.v2.$underlinedId;

import org.jspecify.annotations.NullMarked;
""".stripIndent().trim()
)
mixinConfig.write(
"""
)
mixinConfig.write(
"""
{
"required": true,
"minVersion": "0.8",
Expand All @@ -108,9 +110,12 @@ tasks.register("createModule") {
}
}
""".stripIndent().trim()
)
)
}
}

tasks.register("createModule", CreateModuleTask)

subprojects {
if (it.name == "renderdoc-loader-internal") return
if (it.name == "anvillib-sync-processor-neoforge-26.1") return
Expand Down
4 changes: 4 additions & 0 deletions module.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ neoForge {
client()
systemProperty('neoforge.enabledGameTestNamespaces', project.mod_id)
systemProperty("neoforge.disableGlValidation", "true")
jvmArgument("-XX:+UseParallelGC")
jvmArgument("-XX:+UnlockDiagnosticVMOptions")
jvmArgument("-XX:+DebugNonSafepoints")
programArgument("--renderDebugLabels")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package dev.anvilcraft.lib.v2.rendering;

import dev.anvilcraft.lib.v2.rendering.event.RegisterComputePipelinesEvent;
import dev.anvilcraft.lib.v2.rendering.extension.blaze3d.compute.pipeline.ALRComputePipeline;
import net.minecraft.client.renderer.ShaderDefines;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;

@EventBusSubscriber(Dist.CLIENT)
public class ALRComputePipelines {
public static final ALRComputePipeline FFX_SPD_DOWNSAMPLE_PASS = ALRComputePipeline.builder()
.withName(AnvilLibRendering.location("ffx_spd_downsample_pass"))
.withShader(AnvilLibRendering.location("compute/ffx_spd_downsample_pass.csh"))
.withDefines(
ShaderDefines.builder()
// .define("SPD_MAX_MIP_LEVELS", 5) // minium required value in spec of GL_MAX_IMAGE_UNITS is 8, spd use one for input tex, one for mid tex
.define("FFX_SPD_OPTION_DOWNSAMPLE_FILTER", "2") // use max for HZB
.define("FFX_SPD_OPTION_WAVE_INTEROP_LDS", ALROptions.SPD_OPTION_WAVE_INTEROP_LDS ? 0 : 1) // weird inverted
.build()
)
.withUniformBlock("cbFSR1")
.withTexture("r_input_downsample_src")
.withShaderStorage("rw_internal_global_atomic")
.withReadWriteImage("rw_input_downsample_src_mid_mip")
.withArrayOfImage("rw_input_downsample_src_mips", true, true, 13)
.build();

public static final ALRComputePipeline FFX_SPD_DOWNSAMPLE_PASS_BINDLESS = ALRComputePipeline.builder()
.withName(AnvilLibRendering.location("ffx_spd_downsample_pass"))
.withShader(AnvilLibRendering.location("compute/ffx_spd_downsample_pass_bindless.csh"))
.withDefines(
ShaderDefines.builder()
// .define("SPD_MAX_MIP_LEVELS", 4) // minium required value in spec of GL_MAX_IMAGE_UNITS is 8, spd use one for input tex
.define("FFX_SPD_OPTION_DOWNSAMPLE_FILTER", "2") // use max for HZB
.define("FFX_SPD_OPTION_WAVE_INTEROP_LDS", ALROptions.SPD_OPTION_WAVE_INTEROP_LDS ? 0 : 1) // weird inverted
.build()
)
.withUniformBlock("cbFSR1")
.withTexture("r_input_downsample_src")
.withShaderStorage("rw_internal_global_atomic")
.withReadWriteImage("rw_input_downsample_src_mid_mip")
.withBindlessArrayOfImage("rw_input_downsample_src_mips", true, true, 13)
.build();

public static final ALRComputePipeline DEPTH_CONVERT = ALRComputePipeline.builder()
.withName(AnvilLibRendering.location("depth_convert"))
.withShader(AnvilLibRendering.location("compute/depth_convert.csh"))
.withUniformBlock("ConvertParam")
.withTexture("Input")
.withWriteOnlyImage("Output")
.build();

@SubscribeEvent
public static void on(RegisterComputePipelinesEvent event) {
event.registerPipeline(FFX_SPD_DOWNSAMPLE_PASS);
event.registerPipeline(DEPTH_CONVERT);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package dev.anvilcraft.lib.v2.rendering;

import dev.anvilcraft.lib.v2.rendering.debug.OcclusionCullingDebugEntry;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.client.event.RegisterDebugEntriesEvent;

@EventBusSubscriber
public class ALRDebugEntries {


@SubscribeEvent
public static void on(RegisterDebugEntriesEvent event) {
event.register(OcclusionCullingDebugEntry.LOCATION, new OcclusionCullingDebugEntry());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package dev.anvilcraft.lib.v2.rendering;

import com.mojang.blaze3d.systems.RenderSystem;
import dev.anvilcraft.lib.v2.rendering.optimization.occlusion.OcclusionCuller;
import org.jspecify.annotations.Nullable;

public class ALROptimizations {
private static OcclusionCuller occlusionCuller;

public static OcclusionCuller getOcclusionCuller() {
if (occlusionCuller == null) {
occlusionCuller = OcclusionCuller.createInstance(RenderSystem.getDevice());
}
return occlusionCuller;
}

public static void create() {
occlusionCuller = OcclusionCuller.createInstance(RenderSystem.getDevice());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package dev.anvilcraft.lib.v2.rendering;

import org.jspecify.annotations.Nullable;

@SuppressWarnings("SameParameterValue")
public class ALROptions {
public static final boolean SPD_OPTION_WAVE_INTEROP_LDS = getPropertyBoolean("alrSpdOptionUseWaveInteropLds");
public static final boolean OCCLUSION_QUERY_USE_FRUSTUM_PRE_PASS = getPropertyBoolean("alrOcclusionQueryUseFrustumPrePass", false);
public static final String OCCLUSION_CULLING_FORCE_IMPL = getProperty("alrOcclusionCullingForceImplementation", null);

private static String getProperty(String key, @Nullable String defaultValue) {
return System.getProperty(key, defaultValue);
}

private static boolean getPropertyBoolean(String key, boolean defaultValue) {
String prop = System.getProperty(key);
if (prop == null) {
return defaultValue;
}
return !"false".equals(prop);
}

private static boolean getPropertyBoolean(String key) {
String prop = System.getProperty(key);
return !"false".equals(prop);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@

import com.mojang.blaze3d.pipeline.BlendFunction;
import com.mojang.blaze3d.pipeline.ColorTargetState;
import com.mojang.blaze3d.pipeline.DepthStencilState;
import com.mojang.blaze3d.pipeline.RenderPipeline;
import com.mojang.blaze3d.platform.CompareOp;
import com.mojang.blaze3d.shaders.UniformType;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.VertexFormat;
import com.mojang.blaze3d.vertex.VertexFormatElement;
import dev.anvilcraft.lib.v2.rendering.bloom.TransformsUbo;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.client.event.RegisterRenderPipelinesEvent;
import org.jetbrains.annotations.ApiStatus;

import java.util.Optional;

@EventBusSubscriber(Dist.CLIENT)
public class ALRPipelines {
public static final RenderPipeline.Snippet POST_PASS = RenderPipeline.builder()
Expand Down Expand Up @@ -76,6 +81,17 @@ public class ALRPipelines {
.withCull(false)
.build();

public static final RenderPipeline OCCLUSION_QUERY = RenderPipeline.builder()
.withLocation(AnvilLibRendering.location("occlusion_query"))
.withVertexFormat(DefaultVertexFormat.POSITION, VertexFormat.Mode.QUADS)
.withUniform("Transforms", UniformType.UNIFORM_BUFFER)
.withVertexShader(AnvilLibRendering.location("core/occlusion_query"))
.withFragmentShader(AnvilLibRendering.location("core/occlusion_query"))
.withColorTargetState(new ColorTargetState(Optional.empty(), ColorTargetState.WRITE_NONE))
.withDepthStencilState(new DepthStencilState(CompareOp.LESS_THAN_OR_EQUAL, false))
.withCull(false)
.build();


@ApiStatus.Internal
@SubscribeEvent
Expand All @@ -86,5 +102,7 @@ public static void on(RegisterRenderPipelinesEvent event) {
event.registerPipeline(UPSAMPLE);

event.registerPipeline(SDF_GRAPHICS);

event.registerPipeline(OCCLUSION_QUERY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import lombok.extern.slf4j.Slf4j;
import net.minecraft.resources.Identifier;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.EventPriority;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
Expand All @@ -17,6 +18,7 @@
import net.neoforged.neoforge.client.event.RegisterPictureInPictureRenderersEvent;
import net.neoforged.neoforge.client.event.RenderFrameEvent;
import net.neoforged.neoforge.client.event.RenderLevelStageEvent;
import net.neoforged.neoforge.client.event.SubmitCustomGeometryEvent;
import org.jetbrains.annotations.ApiStatus;

@Slf4j
Expand All @@ -40,6 +42,12 @@ public static void on(RenderFrameEvent.Pre event) {
CachedBlockEntityRenderingPipeline.getInstance().runTasks();
}
ALRPostEffects.getBloomPostEffect().beginFrame();
ALROptimizations.getOcclusionCuller().beginRenderingFrame();
}

@SubscribeEvent(priority = EventPriority.LOWEST)
public static void on(SubmitCustomGeometryEvent event) {
ALROptimizations.getOcclusionCuller().processFeatures(event.getLevelRenderState().cameraRenderState);
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import dev.anvilcraft.lib.v2.rendering.foundation.buffers.object.ShaderBufferObjectUsage;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.ApiStatus;

@Setter
@Getter
@ApiStatus.Internal
public class BloomParametersUbo extends BufferObject<BloomParametersUbo> {

public static final BufferObjectLayoutDefinition<BloomParametersUbo> DEFINITION = BufferObjectLayoutDefinition.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import dev.anvilcraft.lib.v2.rendering.foundation.buffers.object.ShaderBufferObjectUsage;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.ApiStatus;
import org.joml.Vector2f;

@Getter
@Setter
@ApiStatus.Internal
public class BloomPipelineParametersUbo extends BufferObject<BloomPipelineParametersUbo> {

public static final BufferObjectLayoutDefinition<BloomPipelineParametersUbo> DEFINITION = BufferObjectLayoutDefinition.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import dev.anvilcraft.lib.v2.rendering.foundation.buffers.object.ShaderBufferObjectUsage;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.ApiStatus;
import org.joml.Matrix4f;

@Setter
@Getter
@ApiStatus.Internal
public class TransformsUbo extends BufferObject<TransformsUbo> {

public static final BufferObjectLayoutDefinition<TransformsUbo> DEFINITION = BufferObjectLayoutDefinition.create(
Expand Down
Loading
Loading