Skip to content

Commit

Permalink
images and stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatMG393 committed Aug 9, 2024
1 parent 044b9e2 commit eb204d3
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 35 deletions.
1 change: 1 addition & 0 deletions .idx/dev.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
pkgs.mesa-demos
pkgs.novnc
pkgs.hostname-debian
pkgs.turbovnc
];

idx = {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/thatmg393/legacyvkm/breeze3d/VDrawer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.thatmg393.legacyvkm.breeze3d;

public class VDrawer {
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.thatmg393.legacyvkm.impl.screen;
package com.thatmg393.legacyvkm.breeze3d;

public class Renderer {
public class VRenderer {
public void begin() {

}
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/com/thatmg393/legacyvkm/breeze3d/image/VTexture.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.thatmg393.legacyvkm.breeze3d.image;

import java.nio.LongBuffer;

import org.lwjgl.system.MemoryStack;
import org.lwjgl.vulkan.VkImageViewCreateInfo;

import com.thatmg393.legacyvkm.vulkan.image.base.BaseImage;

public class VTexture extends BaseImage {
private long mainImageView;

public VTexture(Builder builder) {
super(builder);
}

@Override
protected void initImage() {
super.initImage();

try (MemoryStack stack = MemoryStack.stackPush()) {
VkImageViewCreateInfo vivci = VkImageViewCreateInfo.calloc(stack);
vivci.sType$Default();

LongBuffer imageView = stack.mallocLong(1);
mainImageView = imageView.get(0);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.thatmg393.legacyvkm.breeze3d.passes;

public class RenderPass {

}
5 changes: 0 additions & 5 deletions src/main/java/com/thatmg393/legacyvkm/impl/screen/Drawer.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.thatmg393.legacyvkm.vulkan.image.base;

import static org.lwjgl.vulkan.VK10.*;

import java.nio.LongBuffer;

import org.lwjgl.PointerBuffer;
import org.lwjgl.system.MemoryStack;

import com.thatmg393.legacyvkm.vulkan.vma.VMAManager;

import lombok.*;

@Getter
public class BaseImage {
private final Builder builder;

private long id, allocation, sampler;

public BaseImage(Builder builder) {
this.builder = builder;
this.sampler = 0; // mipLevels and samplerFlags
}

protected void initImage() {
try (MemoryStack stack = MemoryStack.stackPush()) {
LongBuffer id = stack.mallocLong(1);
PointerBuffer allocation = stack.pointers(0L);

VMAManager.getInstance().createImage(
builder.width, builder.height,
builder.mipLevels, builder.format,
builder.tiling, builder.usage,
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
stack.ints(0), // Graphics Queue
id, allocation
);

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

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

@lombok.Builder(builderClassName = "InternalBuilder", builderMethodName = "internalBuilder", access = AccessLevel.PRIVATE, toBuilder = true, setterPrefix = "set", buildMethodName = "buildVulkanImage")
public static class Builder {
private final int width, height;

private int format = VK_FORMAT_R8G8B8A8_UNORM;
private int tiling = VK_IMAGE_TILING_OPTIMAL;
private int usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
private byte mipLevels = 1;
private byte samplerFlags = 0;

public static final Builder.InternalBuilder builder(int width, int height) {
return internalBuilder().setWidth(width).setHeight(height);
}
}
}

This file was deleted.

60 changes: 54 additions & 6 deletions src/main/java/com/thatmg393/legacyvkm/vulkan/vma/VMAManager.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
package com.thatmg393.legacyvkm.vulkan.vma;

import static org.lwjgl.util.vma.Vma.vmaCreateBuffer;
import static org.lwjgl.util.vma.Vma.vmaMapMemory;
import static org.lwjgl.vulkan.VK10.VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
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.VmaAllocationCreateInfo;
import org.lwjgl.util.vma.VmaAllocatorCreateInfo;
import org.lwjgl.vulkan.VkBufferCreateInfo;
import org.lwjgl.vulkan.VkImageCreateInfo;

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

import lombok.Builder;
import lombok.Getter;

public class VMAManager {
Expand All @@ -23,6 +28,8 @@ public class VMAManager {

private VMAManager() { }

private final HashMap<Long, BaseImage> images = new HashMap<>();

public void createBuffer(long size, int usage, int memoryFlags, LongBuffer bufferPtr, PointerBuffer memoryAllocPtr) {
try (MemoryStack stack = MemoryStack.stackPush()) {
VkBufferCreateInfo vbci = VkBufferCreateInfo.calloc(stack);
Expand All @@ -35,8 +42,7 @@ public void createBuffer(long size, int usage, int memoryFlags, LongBuffer buffe

ResultChecker.checkResult(
vmaCreateBuffer(
GPUManager.getInstance().getSelectedGPU().getVmaPtr(),
vbci, vaci, bufferPtr, memoryAllocPtr, null
getVMA(), vbci, vaci, bufferPtr, memoryAllocPtr, null
),
"Failed to create buffer"
);
Expand All @@ -57,6 +63,48 @@ public void createBuffer(BaseBuffer buffer, int size, int memoryFlags) {
}

public void mapBuffer(long allocation, PointerBuffer data) {
vmaMapMemory(GPUManager.getInstance().getSelectedGPU().getVmaPtr(), allocation, data);
vmaMapMemory(getVMA(), allocation, data);
}

public void addImage(BaseImage 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 GPUManager.getInstance().getSelectedGPU().getVmaPtr();
}
}

0 comments on commit eb204d3

Please sign in to comment.