Skip to content

Commit

Permalink
Refactor Queue System
Browse files Browse the repository at this point in the history
  • Loading branch information
thr3343 committed Oct 6, 2024
1 parent f51bfa5 commit 5f24f80
Show file tree
Hide file tree
Showing 12 changed files with 323 additions and 323 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import net.vulkanmod.vulkan.memory.StagingBuffer;
import net.vulkanmod.vulkan.queue.CommandPool;
import net.vulkanmod.vulkan.queue.Queue;
import net.vulkanmod.vulkan.queue.TransferQueue;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.vulkan.VkBufferMemoryBarrier;
import org.lwjgl.vulkan.VkCommandBuffer;
import org.lwjgl.vulkan.VkMemoryBarrier;

import java.nio.ByteBuffer;

import static net.vulkanmod.vulkan.queue.Queue.TransferQueue;
import static org.lwjgl.vulkan.VK10.*;

public class UploadManager {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/vulkanmod/vulkan/Vulkan.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.vulkanmod.vulkan.memory.MemoryTypes;
import net.vulkanmod.vulkan.memory.StagingBuffer;
import net.vulkanmod.vulkan.queue.Queue;
import net.vulkanmod.vulkan.queue.QueueFamilyIndices;
import net.vulkanmod.vulkan.shader.Pipeline;
import net.vulkanmod.vulkan.util.VUtil;
import net.vulkanmod.vulkan.util.VkResult;
Expand All @@ -22,7 +23,6 @@
import java.util.*;

import static java.util.stream.Collectors.toSet;
import static net.vulkanmod.vulkan.queue.Queue.getQueueFamilies;
import static net.vulkanmod.vulkan.util.VUtil.asPointerBuffer;
import static org.lwjgl.glfw.GLFWVulkan.glfwCreateWindowSurface;
import static org.lwjgl.glfw.GLFWVulkan.glfwGetRequiredInstanceExtensions;
Expand Down Expand Up @@ -345,11 +345,11 @@ private static void createCommandPool() {

try (MemoryStack stack = stackPush()) {

Queue.QueueFamilyIndices queueFamilyIndices = getQueueFamilies();


VkCommandPoolCreateInfo poolInfo = VkCommandPoolCreateInfo.calloc(stack);
poolInfo.sType(VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO);
poolInfo.queueFamilyIndex(queueFamilyIndices.graphicsFamily);
poolInfo.queueFamilyIndex(QueueFamilyIndices.graphicsFamily);
poolInfo.flags(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);

LongBuffer pCommandPool = stack.mallocLong(1);
Expand Down
42 changes: 12 additions & 30 deletions src/main/java/net/vulkanmod/vulkan/device/DeviceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.List;

import static java.util.stream.Collectors.toSet;
import static net.vulkanmod.vulkan.queue.Queue.findQueueFamilies;
import static net.vulkanmod.vulkan.util.VUtil.asPointerBuffer;
import static org.lwjgl.glfw.GLFWVulkan.glfwGetRequiredInstanceExtensions;
import static org.lwjgl.system.MemoryStack.stackGet;
Expand All @@ -38,11 +37,6 @@ public abstract class DeviceManager {

public static SurfaceProperties surfaceProperties;

static GraphicsQueue graphicsQueue;
static PresentQueue presentQueue;
static TransferQueue transferQueue;
static ComputeQueue computeQueue;

public static void init(VkInstance instance) {
try {
DeviceManager.getSuitableDevices(instance);
Expand Down Expand Up @@ -106,7 +100,7 @@ public static void pickPhysicalDevice() {
Initializer.CONFIG.device = -1;
}

physicalDevice = DeviceManager.device.physicalDevice;
QueueFamilyIndices.findQueueFamilies(physicalDevice = DeviceManager.device.physicalDevice);

// Get device properties
deviceProperties = device.properties;
Expand Down Expand Up @@ -154,9 +148,7 @@ else if (!otherDevices.isEmpty())
public static void createLogicalDevice() {
try (MemoryStack stack = stackPush()) {

net.vulkanmod.vulkan.queue.Queue.QueueFamilyIndices indices = findQueueFamilies(physicalDevice);

int[] uniqueQueueFamilies = indices.unique();
int[] uniqueQueueFamilies = QueueFamilyIndices.unique();

VkDeviceQueueCreateInfo.Buffer queueCreateInfos = VkDeviceQueueCreateInfo.calloc(uniqueQueueFamilies.length, stack);

Expand Down Expand Up @@ -221,11 +213,6 @@ public static void createLogicalDevice() {
Vulkan.checkResult(res, "Failed to create logical device");

vkDevice = new VkDevice(pDevice.get(0), physicalDevice, createInfo, VK_API_VERSION_1_2);

graphicsQueue = new GraphicsQueue(stack, indices.graphicsFamily);
transferQueue = new TransferQueue(stack, indices.transferFamily);
presentQueue = new PresentQueue(stack, indices.presentFamily);
computeQueue = new ComputeQueue(stack, indices.computeFamily);
}
}

Expand All @@ -250,7 +237,7 @@ private static PointerBuffer getRequiredExtensions() {

private static boolean isDeviceSuitable(VkPhysicalDevice device) {
try (MemoryStack stack = stackPush()) {
Queue.QueueFamilyIndices indices = findQueueFamilies(device);


VkExtensionProperties.Buffer availableExtensions = getAvailableExtension(stack, device);
boolean extensionsSupported = availableExtensions.stream()
Expand All @@ -269,7 +256,7 @@ private static boolean isDeviceSuitable(VkPhysicalDevice device) {
vkGetPhysicalDeviceFeatures(device, supportedFeatures);
boolean anisotropicFilterSupported = supportedFeatures.samplerAnisotropy();

return indices.isSuitable() && extensionsSupported && swapChainAdequate;
return extensionsSupported && swapChainAdequate;
}
}

Expand Down Expand Up @@ -348,27 +335,22 @@ public static String getAvailableDevicesInfo() {
}

public static void destroy() {
graphicsQueue.cleanUp();
transferQueue.cleanUp();
computeQueue.cleanUp();
Queue.GraphicsQueue.cleanUp();
Queue.TransferQueue.cleanUp();

vkDestroyDevice(vkDevice, null);
}

public static GraphicsQueue getGraphicsQueue() {
return graphicsQueue;
}

public static PresentQueue getPresentQueue() {
return presentQueue;
public static Queue getGraphicsQueue() {
return Queue.GraphicsQueue;
}

public static TransferQueue getTransferQueue() {
return transferQueue;
public static Queue getPresentQueue() {
return Queue.PresentQueue;
}

public static ComputeQueue getComputeQueue() {
return computeQueue;
public static Queue getTransferQueue() {
return Queue.TransferQueue;
}

public static SurfaceProperties querySurfaceProperties(VkPhysicalDevice device, MemoryStack stack) {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/net/vulkanmod/vulkan/framebuffer/SwapChain.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.vulkanmod.vulkan.Vulkan;
import net.vulkanmod.vulkan.device.DeviceManager;
import net.vulkanmod.vulkan.queue.Queue;
import net.vulkanmod.vulkan.queue.QueueFamilyIndices;
import net.vulkanmod.vulkan.texture.VulkanImage;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.vulkan.*;
Expand Down Expand Up @@ -112,11 +113,11 @@ private void createSwapChain() {
createInfo.imageArrayLayers(1);
createInfo.imageUsage(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT);

Queue.QueueFamilyIndices indices = Queue.getQueueFamilies();

if (indices.graphicsFamily != indices.presentFamily) {

if (QueueFamilyIndices.graphicsFamily != QueueFamilyIndices.presentFamily) {
createInfo.imageSharingMode(VK_SHARING_MODE_CONCURRENT);
createInfo.pQueueFamilyIndices(stack.ints(indices.graphicsFamily, indices.presentFamily));
createInfo.pQueueFamilyIndices(stack.ints(QueueFamilyIndices.graphicsFamily, QueueFamilyIndices.presentFamily));
} else {
createInfo.imageSharingMode(VK_SHARING_MODE_EXCLUSIVE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import net.vulkanmod.vulkan.Vulkan;
import net.vulkanmod.vulkan.device.DeviceManager;
import net.vulkanmod.vulkan.queue.CommandPool;
import net.vulkanmod.vulkan.queue.TransferQueue;

import java.nio.ByteBuffer;

import static net.vulkanmod.vulkan.queue.Queue.TransferQueue;
import static org.lwjgl.vulkan.VK10.VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT;

public class IndirectBuffer extends Buffer {
Expand Down
13 changes: 4 additions & 9 deletions src/main/java/net/vulkanmod/vulkan/queue/CommandPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,18 @@
import static org.lwjgl.vulkan.VK10.*;

public class CommandPool {
long id;
final long id;

private final List<CommandBuffer> commandBuffers = new ObjectArrayList<>();
private final java.util.Queue<CommandBuffer> availableCmdBuffers = new ArrayDeque<>();

CommandPool(int queueFamilyIndex) {
this.createCommandPool(queueFamilyIndex);
}

public void createCommandPool(int familyIndex) {

try (MemoryStack stack = stackPush()) {

VkCommandPoolCreateInfo poolInfo = VkCommandPoolCreateInfo.calloc(stack);
poolInfo.sType(VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO);
poolInfo.queueFamilyIndex(familyIndex);
poolInfo.queueFamilyIndex(queueFamilyIndex);
poolInfo.flags(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);

LongBuffer pCommandPool = stack.mallocLong(1);
Expand Down Expand Up @@ -67,7 +63,6 @@ public CommandBuffer beginCommands() {
vkCreateFence(Vulkan.getVkDevice(), fenceInfo, null, pFence);

CommandBuffer commandBuffer = new CommandBuffer(new VkCommandBuffer(pCommandBuffer.get(i), Vulkan.getVkDevice()), pFence.get(0));
commandBuffer.handle = new VkCommandBuffer(pCommandBuffer.get(i), Vulkan.getVkDevice());
commandBuffers.add(commandBuffer);
availableCmdBuffers.add(commandBuffer);
}
Expand Down Expand Up @@ -120,8 +115,8 @@ public void cleanUp() {
}

public class CommandBuffer {
VkCommandBuffer handle;
long fence;
final VkCommandBuffer handle;
final long fence;
boolean submitted;
boolean recording;

Expand Down
10 changes: 0 additions & 10 deletions src/main/java/net/vulkanmod/vulkan/queue/ComputeQueue.java

This file was deleted.

48 changes: 0 additions & 48 deletions src/main/java/net/vulkanmod/vulkan/queue/GraphicsQueue.java

This file was deleted.

10 changes: 0 additions & 10 deletions src/main/java/net/vulkanmod/vulkan/queue/PresentQueue.java

This file was deleted.

Loading

0 comments on commit 5f24f80

Please sign in to comment.