Skip to content

Commit

Permalink
Update loom and gradlew + unfinished work
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatMG393 committed Jan 17, 2025
1 parent 9727d25 commit e747fb8
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 84 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id "io.freefair.lombok" version "8.2.2"
id "fabric-loom" version "1.6-SNAPSHOT"
id "legacy-looming" version "1.6-SNAPSHOT" // Version must be the same as fabric-loom's
id "fabric-loom" version "1.9-SNAPSHOT"
id "legacy-looming" version "1.9-SNAPSHOT" // Version must be the same as fabric-loom's
}

base.archivesName = project.archives_base_name
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
6 changes: 1 addition & 5 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ pluginManagement {
name = "legacy-fabric"
url = "https://repo.legacyfabric.net/repository/legacyfabric/"
}
maven {
name = 'Ornithe Snapshots'
url = 'https://maven.ornithemc.net/snapshots'
}
gradlePluginPortal()
}
}

rootProject.name = 'Legacy VulkanMod'
rootProject.name = 'LegacyVulkanMod'
3 changes: 1 addition & 2 deletions src/main/java/com/thatmg393/legacyvkm/LegacyVulkanMod.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.thatmg393.legacyvkm;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.*;

import com.thatmg393.legacyvkm.utils.Platform;
import com.thatmg393.vulkan.Vulkan;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/thatmg393/vulkan/Vulkan.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ private void setupSurface(long windowPtr) {
try (MemoryStack stack = MemoryStack.stackPush()) {
LongBuffer surfacePtr = stack.longs(VK_NULL_HANDLE);

GLFW.glfwWindowHint(GLFW.GLFW_CLIENT_API, GLFW.GLFW_NO_API);
ResultChecker.checkResult(GLFWVulkan.glfwCreateWindowSurface(vkInstance, windowPtr, null, surfacePtr), "Failed to create a Vulkan window");

this.surfacePtr = surfacePtr.get(0);
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/com/thatmg393/vulkan/image/base/BaseImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.lwjgl.system.MemoryStack;

import com.thatmg393.vulkan.image.utils.ImageUtils;
import com.thatmg393.vulkan.vma.VMAManager;
import com.thatmg393.vulkan.vma.VMAImage;

import lombok.Getter;
import lombok.experimental.SuperBuilder;
Expand All @@ -30,19 +30,20 @@ protected void initImage() {
LongBuffer id = stack.mallocLong(1);
PointerBuffer allocation = stack.pointers(0L);

VMAManager.getInstance().createImage(
builder.getWidth(), builder.getHeight(),
builder.getMipLevels(), builder.getFormat(),
builder.getTiling(), builder.getUsage(),
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
stack.ints(0), // Graphics Queue
id, allocation
VMAImage.getInstance().create(
new VMAImage.Builder(
builder.getWidth(), builder.getHeight(), 1,
builder.getMipLevels(), builder.getFormat(), builder.getTiling(),
builder.getUsage(),
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
stack.ints(0), id, allocation
)
);

this.id = id.get(0);
this.allocation = allocation.get(0);

VMAManager.getInstance().addImage(this);
VMAImage.getInstance().addImage(this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public synchronized void add(CommandBuffer obj) {
commandBuffers.add(obj);
}

@Override
public synchronized void waitAll() {
SyncFences.getInstance().waitAll();
commandBuffers.forEach(CommandPool.CommandBuffer::reset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public synchronized void add(Long obj) {
fences.put(index++, obj);
}

@Override
public synchronized void waitAll() {
if (index == 0) return;
vkWaitForFences(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
// Don't forget to add 'synchronized'!
public abstract class Synchronization<T> {
public abstract void add(T obj);
public abstract void waitAll();
}
6 changes: 1 addition & 5 deletions src/main/java/com/thatmg393/vulkan/utils/ResultChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ public class ResultChecker {
public static void checkResult(int code, CharSequence failMessage) {
if (code != VkResult.VK_SUCCESS) {
throw new RuntimeException(
"Fatal error: " + code + " (" + codeToString(code) + ") " + failMessage
"Fatal error: " + code + " (" + VkResult.decode(code) + ") " + failMessage
);
}
}

public static String codeToString(int code) {
return VkResult.decode(code);
}
}
84 changes: 84 additions & 0 deletions src/main/java/com/thatmg393/vulkan/vma/VMAImage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.thatmg393.vulkan.vma;

import static org.lwjgl.util.vma.Vma.*;
import static org.lwjgl.vulkan.VK10.*;

import java.nio.*;
import java.util.HashMap;

import org.lwjgl.PointerBuffer;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.util.vma.VmaAllocationCreateInfo;
import org.lwjgl.vulkan.VkImageCreateInfo;

import com.thatmg393.vulkan.image.base.BaseImage;
import com.thatmg393.vulkan.utils.ResultChecker;
import com.thatmg393.vulkan.vma.base.*;

import lombok.*;

public class VMAImage extends BaseVMAFeature<VMAImage.Builder> {
@Getter
private static final VMAImage instance = new VMAImage();

private VMAImage() { }

@AllArgsConstructor
public static class Builder extends BaseFeatureBuilder {
private int width, height, depth;
private byte mipLevels;
private int format, tiling, usage, memoryFlags;

private IntBuffer queueFamily;
private LongBuffer imagePtr;
private PointerBuffer imageMemoryPtr;
}

private final HashMap<Long, BaseImage<? extends BaseImage.Builder>> images = new HashMap<>();

@Override
public void create(Builder params) {
try (MemoryStack stack = MemoryStack.stackPush()) {
VkImageCreateInfo vici = VkImageCreateInfo.calloc(stack);
vici.sType$Default();
vici.imageType(VK_IMAGE_TYPE_2D);
vici.mipLevels(params.mipLevels);
vici.format(params.format);
vici.tiling(params.tiling);
vici.usage(params.usage);
vici.arrayLayers(1);
vici.initialLayout(VK_IMAGE_LAYOUT_UNDEFINED);
vici.samples(VK_SAMPLE_COUNT_1_BIT);
vici.sharingMode(VK_SHARING_MODE_EXCLUSIVE);
vici.pQueueFamilyIndices(params.queueFamily);
vici.extent((e) -> {
e.width(params.width);
e.height(params.height);
e.depth(params.depth);
});

VmaAllocationCreateInfo vaci = VmaAllocationCreateInfo.calloc(stack);
vaci.requiredFlags(params.memoryFlags);

ResultChecker.checkResult(
vmaCreateImage(
VMAManager.getInstance().getVmaInstance(), vici, vaci, params.imagePtr, params.imageMemoryPtr, null
),
"Failed to create image"
);
}
}

@Override
public void destroy(long id) {
BaseImage<?> image = images.remove(id);

try (MemoryStack stack = MemoryStack.stackPush()) {
vmaDestroyImage(VMAManager.getInstance().getVmaInstance(), id, image.getAllocation());
}
}

public void addImage(BaseImage<? extends BaseImage.Builder> image) {
images.putIfAbsent(image.getId(), image);
}
}
66 changes: 7 additions & 59 deletions src/main/java/com/thatmg393/vulkan/vma/VMAManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,16 @@
import static org.lwjgl.util.vma.Vma.*;
import static org.lwjgl.vulkan.VK10.*;

import java.nio.IntBuffer;
import java.nio.LongBuffer;
import java.util.HashMap;

import org.lwjgl.PointerBuffer;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.util.vma.Vma;
import org.lwjgl.util.vma.VmaAllocationCreateInfo;
import org.lwjgl.util.vma.VmaAllocatorCreateInfo;
import org.lwjgl.util.vma.VmaVulkanFunctions;
import org.lwjgl.vulkan.VK11;
import org.lwjgl.vulkan.VkBufferCreateInfo;
import org.lwjgl.vulkan.VkImageCreateInfo;
import org.lwjgl.vulkan.VkPhysicalDevice;
import org.lwjgl.util.vma.*;
import org.lwjgl.vulkan.*;

import com.thatmg393.vulkan.Vulkan;
import com.thatmg393.vulkan.buffer.base.BaseBuffer;
import com.thatmg393.vulkan.gpu.GPU;
import com.thatmg393.vulkan.gpu.GPUManager;
import com.thatmg393.vulkan.image.base.BaseImage;
import com.thatmg393.vulkan.utils.ResultChecker;

import lombok.Getter;
Expand All @@ -33,8 +23,8 @@ public class VMAManager {

private VMAManager() { }

private final HashMap<Long, BaseImage<? extends BaseImage.Builder>> images = new HashMap<>();
private long VMAInstance = 0;
@Getter
private long vmaInstance;

public void initializeVMA(VkPhysicalDevice physicalDevice) {
try (MemoryStack stack = MemoryStack.stackPush()) {
Expand All @@ -54,7 +44,7 @@ public void initializeVMA(VkPhysicalDevice physicalDevice) {

ResultChecker.checkResult(Vma.vmaCreateAllocator(vai, vmaPtr), "Failed to create VMA");

VMAInstance = vmaPtr.get(0);
vmaInstance = vmaPtr.get(0);
}
}

Expand All @@ -70,7 +60,7 @@ public void createBuffer(long size, int usage, int memoryFlags, LongBuffer buffe

ResultChecker.checkResult(
vmaCreateBuffer(
getVMA(), vbci, vaci, bufferPtr, memoryAllocPtr, null
getVmaInstance(), vbci, vaci, bufferPtr, memoryAllocPtr, null
),
"Failed to create buffer"
);
Expand All @@ -91,48 +81,6 @@ public void createBuffer(BaseBuffer buffer, int size, int memoryFlags) {
}

public void mapBuffer(long allocation, PointerBuffer data) {
vmaMapMemory(getVMA(), allocation, data);
}

public void addImage(BaseImage<? extends BaseImage.Builder> image) {
images.putIfAbsent(image.getId(), image);
}

public void createImage(
int width, int height,
int mipLevels, int format, int tiling, int usage, int memoryFlags,
IntBuffer queueFamily, LongBuffer pImage, PointerBuffer pImageMemory
) {
try (MemoryStack stack = MemoryStack.stackPush()) {
VkImageCreateInfo vici = VkImageCreateInfo.calloc(stack);
vici.sType$Default();
vici.imageType(VK_IMAGE_TYPE_2D);
vici.mipLevels(mipLevels);
vici.format(format);
vici.tiling(tiling);
vici.usage(usage);
vici.arrayLayers(1);
vici.initialLayout(VK_IMAGE_LAYOUT_UNDEFINED);
vici.samples(VK_SAMPLE_COUNT_1_BIT);
vici.sharingMode(VK_SHARING_MODE_EXCLUSIVE);
vici.pQueueFamilyIndices(queueFamily);
vici.extent((e) -> {
e.width(width); e.height(height); e.depth(1);
});

VmaAllocationCreateInfo vaci = VmaAllocationCreateInfo.calloc(stack);
vaci.requiredFlags(memoryFlags);

ResultChecker.checkResult(
vmaCreateImage(
getVMA(), vici, vaci, pImage, pImageMemory, null
),
"Failed to create image"
);
}
}

private final long getVMA() {
return this.VMAInstance;
vmaMapMemory(getVmaInstance(), allocation, data);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.thatmg393.vulkan.vma.base;

public class BaseFeatureBuilder { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.thatmg393.vulkan.vma.base;

public abstract class BaseVMAFeature<T extends BaseFeatureBuilder> {
public abstract void create(T params);
public abstract void destroy(long id);
}

0 comments on commit e747fb8

Please sign in to comment.