Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try out Architectury #295

Closed
wants to merge 12 commits into from
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# gradle

.gradle/
/build/
fabric/build
common/build
forge/build
out/
classes/

Expand Down Expand Up @@ -31,3 +33,5 @@ bin/
# fabric

run/

.architectury-transformer/
126 changes: 33 additions & 93 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
plugins {
id 'fabric-loom' version '0.12-SNAPSHOT'
id 'maven-publish'
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.3-SNAPSHOT" apply false
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group
architectury {
minecraft = rootProject.minecraft_version
}

project.ext.lwjglVersion = "3.3.1"
project.ext.jomlVersion = "1.10.4"
Expand All @@ -17,102 +15,44 @@ project.ext.linuxNatives = "natives-linux"
project.ext.macosNatives = "natives-macos"
project.ext.macosArmNatives = "natives-macos-arm64"

dependencies {
// include(implementation("org.lwjgl:lwjgl:$lwjglVersion"))
// include(implementation("org.lwjgl:lwjgl-glfw:$lwjglVersion"))
// include(runtimeOnly("org.lwjgl:lwjgl-glfw:$lwjglVersion:$winNatives"))
// include(runtimeOnly("org.lwjgl:lwjgl-glfw:$lwjglVersion:$linuxNatives"))
// include(implementation("org.lwjgl:lwjgl-stb:$lwjglVersion"))
// include(runtimeOnly("org.lwjgl:lwjgl-stb:$lwjglVersion:$winNatives"))
// include(runtimeOnly("org.lwjgl:lwjgl-stb:$lwjglVersion:$linuxNatives"))
// include(implementation("org.lwjgl:lwjgl-openal:$lwjglVersion"))
// include(runtimeOnly("org.lwjgl:lwjgl-openal:$lwjglVersion:$winNatives"))
// include(runtimeOnly("org.lwjgl:lwjgl-openal:$lwjglVersion:$linuxNatives"))
// include(runtimeOnly("org.lwjgl:lwjgl:$lwjglVersion:$winNatives"))
// include(runtimeOnly("org.lwjgl:lwjgl:$lwjglVersion:$linuxNatives"))

include(implementation("org.lwjgl:lwjgl-vulkan:$lwjglVersion"))
include(implementation("org.lwjgl:lwjgl-vma:$lwjglVersion"))
// include(implementation("org.joml:joml:${jomlVersion}"))
include(runtimeOnly("org.lwjgl:lwjgl-vma:$lwjglVersion:$winNatives"))
include(runtimeOnly("org.lwjgl:lwjgl-vma:$lwjglVersion:$linuxNatives"))
subprojects {
apply plugin: "java"
apply plugin: "architectury-plugin"
apply plugin: "dev.architectury.loom"
apply plugin: "maven-publish"

include(implementation("org.lwjgl:lwjgl-shaderc:$lwjglVersion"))
include(runtimeOnly("org.lwjgl:lwjgl-shaderc:$lwjglVersion:$winNatives"))
include(runtimeOnly("org.lwjgl:lwjgl-shaderc:$lwjglVersion:$linuxNatives"))
archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group

//MacOS
// include(runtimeOnly("org.lwjgl:lwjgl-vulkan:$lwjglVersion:$macosNatives"))
// include(runtimeOnly("org.lwjgl:lwjgl-vulkan:$lwjglVersion:$macosArmNatives"))
// include(runtimeOnly("org.lwjgl:lwjgl-vma:$lwjglVersion:$macosNatives"))
// include(runtimeOnly("org.lwjgl:lwjgl-vma:$lwjglVersion:$macosArmNatives"))
// include(runtimeOnly("org.lwjgl:lwjgl-shaderc:$lwjglVersion:$macosNatives"))
// include(runtimeOnly("org.lwjgl:lwjgl-shaderc:$lwjglVersion:$macosArmNatives"))

// implementation("org.openjdk.jol:jol-core:0.17")
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
options.release = 17
}

repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
}

dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings loom.officialMojangMappings()
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
}
java {
withSourcesJar()
}

processResources {
inputs.property "version", project.version
loom {
silentMojangMappingsLicense()
}

filesMatching("fabric.mod.json") {
expand "version": project.version
}
}
dependencies {
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}"
// The following line declares the mojmap mappings, you may use other mappings as well
mappings loom.officialMojangMappings()

tasks.withType(JavaCompile).configureEach {
// Minecraft 1.18 (1.18-pre2) upwards uses Java 17.
it.options.release = 17
}
}

loom {
accessWidenerPath = file("src/main/resources/vulkanmod.accesswidener")
}
allprojects {
apply plugin: "architectury-plugin"

java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
}

jar {
/*jar {
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}"}
}
}

// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}

// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
// Notice: This block does NOT have the same function as the block in the top level.
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
}
}*/
35 changes: 35 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
architectury {
common(rootProject.enabled_platforms.split(","))
}

loom {
accessWidenerPath = file("src/main/resources/vulkanmod.accesswidener")
}

dependencies {
// We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies
// Do NOT use other classes from fabric loader
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
// Remove the next line if you don't want to depend on the API
modApi "dev.architectury:architectury:${rootProject.architectury_version}"

include(implementation("org.lwjgl:lwjgl-vulkan:$lwjglVersion"))
include(implementation("org.lwjgl:lwjgl-vma:$lwjglVersion"))
include(runtimeOnly("org.lwjgl:lwjgl-vma:$lwjglVersion:$winNatives"))
include(runtimeOnly("org.lwjgl:lwjgl-vma:$lwjglVersion:$linuxNatives"))

include(implementation("org.lwjgl:lwjgl-shaderc:$lwjglVersion"))
include(runtimeOnly("org.lwjgl:lwjgl-shaderc:$lwjglVersion:$winNatives"))
include(runtimeOnly("org.lwjgl:lwjgl-shaderc:$lwjglVersion:$linuxNatives"))

include(implementation("com.google.code.findbugs:jsr305:3.0.2"))
}

publishing {
publications {
mavenCommon(MavenPublication) {
artifactId = rootProject.archives_base_name
from components.java
}
}
}
Original file line number Diff line number Diff line change
@@ -1,40 +1,21 @@
package net.vulkanmod;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.vulkanmod.config.Config;
import net.vulkanmod.config.VideoResolution;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.nio.file.Path;

public class Initializer implements ClientModInitializer {
public class Initializer {
public static final Logger LOGGER = LogManager.getLogger("VulkanMod");

private static String VERSION;
public static Config CONFIG;

@Override
public void onInitializeClient() {

VERSION = FabricLoader.getInstance()
.getModContainer("vulkanmod")
.get()
.getMetadata()
.getVersion().getFriendlyString();

public static Config CONFIG = loadConfig(VulkanModExpectPlatform.getConfigDirectory().resolve("vulkanmod_settings.json"));
public static final String MODID = "vulkanmod";
public static void onInitializeClient() {
VERSION = VulkanModExpectPlatform.getVersion();
LOGGER.info("== VulkanMod ==");

VideoResolution.init();

var configPath = FabricLoader.getInstance()
.getConfigDir()
.resolve("vulkanmod_settings.json");

CONFIG = loadConfig(configPath);

}

private static Config loadConfig(Path path) {
Expand All @@ -49,4 +30,4 @@ private static Config loadConfig(Path path) {
public static String getVersion() {
return VERSION;
}
}
}
19 changes: 19 additions & 0 deletions common/src/main/java/net/vulkanmod/VulkanModExpectPlatform.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package net.vulkanmod;

import dev.architectury.injectables.annotations.ExpectPlatform;

import java.nio.file.Path;

public class VulkanModExpectPlatform {

@ExpectPlatform
public static Path getConfigDirectory() {
// Just throw an error, the content should get replaced at runtime.
throw new AssertionError();
}

@ExpectPlatform
public static String getVersion() {
throw new AssertionError();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class Config {
public int advCulling = 2;
public boolean indirectDraw = false;
public boolean uniqueOpaqueLayer = true;
public boolean entityCulling = true;

private static Path path;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,17 @@ Enable Gui optimizations (Stats bar, Chat, Debug Hud)
Use a culling algorithm that might improve performance by
reducing the number of non visible chunk sections rendered.
""")),
new SwitchOption("Entity Culling",
value -> config.entityCulling = value,
() -> config.entityCulling)
.setTooltip(Component.nullToEmpty("""
Enables culling for entities on non visible sections.""")),
new SwitchOption("Indirect Draw",
value -> config.indirectDraw = value,
() -> config.indirectDraw)
.setTooltip(Component.nullToEmpty("""
Reduces CPU overhead but increases GPU overhead.
Enabling it might help in CPU limited systems.""")),
Enabling it might help in CPU limited systems."""))
};

}
Expand Down
14 changes: 14 additions & 0 deletions common/src/main/java/net/vulkanmod/gl/Util.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.vulkanmod.gl;

import net.vulkanmod.vulkan.shader.SPIRVUtils;

public class Util {

public static SPIRVUtils.ShaderKind extToShaderKind(String in) {
return switch (in) {
case ".vsh" -> SPIRVUtils.ShaderKind.VERTEX_SHADER;
case ".fsh" -> SPIRVUtils.ShaderKind.FRAGMENT_SHADER;
default -> throw new RuntimeException("unknown shader type: " + in);
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package net.vulkanmod.interfaces;

import net.vulkanmod.vulkan.shader.GraphicsPipeline;

public interface ShaderMixed {

GraphicsPipeline getPipeline();
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ private GLCapabilities redirect2() {
return null;
}

@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lorg/lwjgl/glfw/GLFW;glfwCreateWindow(IILjava/lang/CharSequence;JJ)J"))
/* @Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lorg/lwjgl/glfw/GLFW;glfwCreateWindow(IILjava/lang/CharSequence;JJ)J"))
private void vulkanHint(WindowEventHandler windowEventHandler, ScreenManager screenManager, DisplayData displayData, String string, String string2, CallbackInfo ci) {
GLFW.glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
// GLFW.glfwWindowHint(GLFW_AUTO_ICONIFY, GLFW_FALSE);
// GLFW.glfwWindowHint(GLFW_FOCUSED, GLFW_FALSE);
}
}*/

@Inject(method = "<init>", at = @At(value = "RETURN"))
private void getHandle(WindowEventHandler windowEventHandler, ScreenManager screenManager, DisplayData displayData, String string, String string2, CallbackInfo ci) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.phys.Vec3;
import net.vulkanmod.Initializer;
import net.vulkanmod.render.chunk.WorldRenderer;
import net.vulkanmod.render.profiling.Profiler2;
import net.vulkanmod.vulkan.util.Pair;
Expand Down Expand Up @@ -54,9 +55,6 @@ public abstract class LevelRendererMixin {

private WorldRenderer worldRenderer;

@Unique
private static boolean ENTITIES_OPT = true;

@Unique
private Object2ReferenceOpenHashMap<Class<? extends Entity>, ObjectArrayList<Pair<Entity, MultiBufferSource>>> entitiesMap = new Object2ReferenceOpenHashMap<>();

Expand Down Expand Up @@ -89,8 +87,6 @@ private void renderBlockEntities(PoseStack poseStack, float f, long l, boolean b
private void setupRender(Camera camera, Frustum frustum, boolean isCapturedFrustum, boolean spectator) {
this.worldRenderer.setupRenderer(camera, frustum, isCapturedFrustum, spectator);

ENTITIES_OPT = true;
// ENTITIES_OPT = false;
entitiesMap.clear();
}

Expand Down Expand Up @@ -200,7 +196,7 @@ private void popProfiler3(PoseStack poseStack, float f, long l, boolean bl, Came
*/
@Overwrite
private void renderEntity(Entity entity, double d, double e, double f, float g, PoseStack poseStack, MultiBufferSource multiBufferSource) {
if(!ENTITIES_OPT) {
if(!Initializer.CONFIG.entityCulling) {
double h = Mth.lerp((double)g, entity.xOld, entity.getX());
double i = Mth.lerp((double)g, entity.yOld, entity.getY());
double j = Mth.lerp((double)g, entity.zOld, entity.getZ());
Expand All @@ -226,7 +222,7 @@ private void renderEntity(Entity entity, double d, double e, double f, float g,
shift = At.Shift.AFTER, ordinal = 0)
)
private void renderEntities(PoseStack poseStack, float partialTicks, long l, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, CallbackInfo ci) {
if(!ENTITIES_OPT)
if(!Initializer.CONFIG.entityCulling)
return;

Vec3 cameraPos = WorldRenderer.getCameraPos();
Expand Down
Loading