Updates
This commit is contained in:
parent
6e0b69947c
commit
0e181376b4
5 changed files with 51 additions and 65 deletions
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
description = "Portfolio hugo configuration";
|
description = "LWJGL configuration";
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
|
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
|
||||||
|
@ -21,16 +21,14 @@
|
||||||
config.allowUnfree = true;
|
config.allowUnfree = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
buildInputs = with pkgs; [ vulkan-headers vulkan-loader vulkan-validation-layers renderdoc ];
|
librairies = with pkgs; [ vulkan-headers vulkan-loader vulkan-validation-layers renderdoc ];
|
||||||
|
|
||||||
java = pkgs.jdk22;
|
java = pkgs.jdk22;
|
||||||
|
|
||||||
mkCustomShell = { extraPkgs ? [] }: pkgs.mkShell {
|
mkCustomShell = { extraPkgs ? [] }: pkgs.mkShell {
|
||||||
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath buildInputs;
|
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath librairies;
|
||||||
VK_LAYER_PATH = "${pkgs.vulkan-validation-layers}/share/vulkan/explicit_layer.d:${pkgs.renderdoc}/share/vulkan/implicit_layer.d";
|
VK_LAYER_PATH = "${pkgs.vulkan-validation-layers}/share/vulkan/explicit_layer.d:${pkgs.renderdoc}/share/vulkan/implicit_layer.d";
|
||||||
|
|
||||||
JAVA_HOME = java;
|
|
||||||
|
|
||||||
packages = with pkgs; [
|
packages = with pkgs; [
|
||||||
java
|
java
|
||||||
maven
|
maven
|
||||||
|
|
|
@ -8,7 +8,6 @@ import org.tinylog.Logger;
|
||||||
import fr.mrdev023.vulkan_java.vk.utils.SuitablePhysicalDeviceFinder;
|
import fr.mrdev023.vulkan_java.vk.utils.SuitablePhysicalDeviceFinder;
|
||||||
|
|
||||||
import java.nio.*;
|
import java.nio.*;
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import static fr.mrdev023.vulkan_java.vk.VulkanError.vkCheck;
|
import static fr.mrdev023.vulkan_java.vk.VulkanError.vkCheck;
|
||||||
import static org.lwjgl.vulkan.VK11.*;
|
import static org.lwjgl.vulkan.VK11.*;
|
||||||
|
@ -17,6 +16,7 @@ public class Device {
|
||||||
|
|
||||||
private final PhysicalDevice physicalDevice;
|
private final PhysicalDevice physicalDevice;
|
||||||
private final VkDevice vkDevice;
|
private final VkDevice vkDevice;
|
||||||
|
private final Queue.PresentQueue presentQueue;
|
||||||
private final Queue.GraphicsQueue graphicsQueue;
|
private final Queue.GraphicsQueue graphicsQueue;
|
||||||
private final Queue.ComputeQueue computeQueue;
|
private final Queue.ComputeQueue computeQueue;
|
||||||
private final Queue.TransferQueue transferQueue;
|
private final Queue.TransferQueue transferQueue;
|
||||||
|
@ -25,17 +25,10 @@ public class Device {
|
||||||
this.physicalDevice = physicalDeviceMatch.physicalDevice;
|
this.physicalDevice = physicalDeviceMatch.physicalDevice;
|
||||||
|
|
||||||
try (MemoryStack stack = MemoryStack.stackPush()) {
|
try (MemoryStack stack = MemoryStack.stackPush()) {
|
||||||
// Define required extensions
|
var extensions = physicalDeviceMatch.validatorResult.deviceExtensionsResult.matchingExtensions;
|
||||||
Set<String> deviceExtensions = getDeviceExtensions();
|
PointerBuffer requiredExtensions = stack.mallocPointer(extensions.size());
|
||||||
boolean usePortability = deviceExtensions
|
for (String extension : extensions) {
|
||||||
.contains(KHRPortabilitySubset.VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME)
|
requiredExtensions.put(stack.ASCII(extension));
|
||||||
&& VulkanUtils.getOS() == VulkanUtils.OSType.MACOS;
|
|
||||||
|
|
||||||
int numExtensions = usePortability ? 2 : 1;
|
|
||||||
PointerBuffer requiredExtensions = stack.mallocPointer(numExtensions);
|
|
||||||
requiredExtensions.put(stack.ASCII(KHRSwapchain.VK_KHR_SWAPCHAIN_EXTENSION_NAME));
|
|
||||||
if (usePortability) {
|
|
||||||
requiredExtensions.put(stack.ASCII(KHRPortabilitySubset.VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME));
|
|
||||||
}
|
}
|
||||||
requiredExtensions.flip();
|
requiredExtensions.flip();
|
||||||
|
|
||||||
|
@ -66,9 +59,13 @@ public class Device {
|
||||||
"Failed to create device");
|
"Failed to create device");
|
||||||
vkDevice = new VkDevice(pp.get(0), physicalDevice.getVkPhysicalDevice(), deviceCreateInfo);
|
vkDevice = new VkDevice(pp.get(0), physicalDevice.getVkPhysicalDevice(), deviceCreateInfo);
|
||||||
|
|
||||||
// graphicsQueue = new Queue.GraphicsQueue(this, physicalDeviceMatch.graphicsQueueFamilyIndex, 0);
|
// graphicsQueue = new Queue.GraphicsQueue(this,
|
||||||
// computeQueue = new Queue.ComputeQueue(this, physicalDeviceMatch.computeQueueFamilyIndex, 1);
|
// physicalDeviceMatch.graphicsQueueFamilyIndex, 0);
|
||||||
// transferQueue = new Queue.TransferQueue(this, physicalDeviceMatch.transferQueueFamilyIndex, 2);
|
// computeQueue = new Queue.ComputeQueue(this,
|
||||||
|
// physicalDeviceMatch.computeQueueFamilyIndex, 1);
|
||||||
|
// transferQueue = new Queue.TransferQueue(this,
|
||||||
|
// physicalDeviceMatch.transferQueueFamilyIndex, 2);
|
||||||
|
presentQueue = null;
|
||||||
graphicsQueue = null;
|
graphicsQueue = null;
|
||||||
computeQueue = null;
|
computeQueue = null;
|
||||||
transferQueue = null;
|
transferQueue = null;
|
||||||
|
@ -82,36 +79,6 @@ public class Device {
|
||||||
vkDestroyDevice(vkDevice, null);
|
vkDestroyDevice(vkDevice, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<String> getDeviceExtensions() throws VulkanError {
|
|
||||||
Set<String> deviceExtensions = new HashSet<>();
|
|
||||||
try (MemoryStack stack = MemoryStack.stackPush()) {
|
|
||||||
// Get the number of device extensions
|
|
||||||
IntBuffer numExtensionsBuf = stack.callocInt(1);
|
|
||||||
int result = vkEnumerateDeviceExtensionProperties(physicalDevice.getVkPhysicalDevice(), (String) null,
|
|
||||||
numExtensionsBuf,
|
|
||||||
null);
|
|
||||||
vkCheck(result, "Failed to enumerate device extension properties");
|
|
||||||
|
|
||||||
int numExtensions = numExtensionsBuf.get(0);
|
|
||||||
Logger.debug("Vulkan device supported extensions ({}):", numExtensions);
|
|
||||||
|
|
||||||
// Get the device extensions
|
|
||||||
VkExtensionProperties.Buffer propsBuff = VkExtensionProperties.calloc(numExtensions, stack);
|
|
||||||
result = vkEnumerateDeviceExtensionProperties(physicalDevice.getVkPhysicalDevice(), (String) null,
|
|
||||||
numExtensionsBuf,
|
|
||||||
propsBuff);
|
|
||||||
vkCheck(result, "Failed to enumerate device extension properties");
|
|
||||||
|
|
||||||
for (int i = 0; i < numExtensions; i++) {
|
|
||||||
VkExtensionProperties props = propsBuff.get(i);
|
|
||||||
String extensionName = props.extensionNameString();
|
|
||||||
deviceExtensions.add(extensionName);
|
|
||||||
Logger.debug("\t - {}", extensionName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return deviceExtensions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PhysicalDevice getPhysicalDevice() {
|
public PhysicalDevice getPhysicalDevice() {
|
||||||
return physicalDevice;
|
return physicalDevice;
|
||||||
}
|
}
|
||||||
|
@ -124,6 +91,10 @@ public class Device {
|
||||||
vkDeviceWaitIdle(vkDevice);
|
vkDeviceWaitIdle(vkDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Queue.PresentQueue getPresentQueue() {
|
||||||
|
return presentQueue;
|
||||||
|
}
|
||||||
|
|
||||||
public Queue.GraphicsQueue getGraphicsQueue() {
|
public Queue.GraphicsQueue getGraphicsQueue() {
|
||||||
return graphicsQueue;
|
return graphicsQueue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,12 @@ public class Queue {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class PresentQueue extends Queue {
|
||||||
|
public PresentQueue(Device device, int queueFamilyIndex, int queueIndex) {
|
||||||
|
super(device, queueFamilyIndex, queueIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class ComputeQueue extends Queue {
|
public static class ComputeQueue extends Queue {
|
||||||
public ComputeQueue(Device device, int queueFamilyIndex, int queueIndex) {
|
public ComputeQueue(Device device, int queueFamilyIndex, int queueIndex) {
|
||||||
super(device, queueFamilyIndex, queueIndex);
|
super(device, queueFamilyIndex, queueIndex);
|
||||||
|
|
|
@ -8,6 +8,7 @@ import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.lwjgl.vulkan.KHRDynamicRendering;
|
import org.lwjgl.vulkan.KHRDynamicRendering;
|
||||||
|
import org.lwjgl.vulkan.KHRPortabilitySubset;
|
||||||
import org.lwjgl.vulkan.KHRSwapchain;
|
import org.lwjgl.vulkan.KHRSwapchain;
|
||||||
import org.lwjgl.vulkan.VK10;
|
import org.lwjgl.vulkan.VK10;
|
||||||
|
|
||||||
|
@ -28,13 +29,19 @@ public class Vulkan {
|
||||||
instance = new Instance(true);
|
instance = new Instance(true);
|
||||||
surface = new Surface(instance, Display.getWindow());
|
surface = new Surface(instance, Display.getWindow());
|
||||||
|
|
||||||
|
var extensions = Set.of(KHRDynamicRendering.VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME,
|
||||||
|
KHRSwapchain.VK_KHR_SWAPCHAIN_EXTENSION_NAME);
|
||||||
|
if (VulkanUtils.getOS() == VulkanUtils.OSType.MACOS) {
|
||||||
|
extensions.add(KHRPortabilitySubset.VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
var physicalDeviceCompatibilityValidator = new PhysicalDeviceCompatibilityValidator(
|
var physicalDeviceCompatibilityValidator = new PhysicalDeviceCompatibilityValidator(
|
||||||
VK10.VK_QUEUE_GRAPHICS_BIT | VK10.VK_QUEUE_COMPUTE_BIT | VK10.VK_QUEUE_TRANSFER_BIT,
|
VK10.VK_QUEUE_GRAPHICS_BIT | VK10.VK_QUEUE_COMPUTE_BIT | VK10.VK_QUEUE_TRANSFER_BIT,
|
||||||
Set.of(KHRDynamicRendering.VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME, KHRSwapchain.VK_KHR_SWAPCHAIN_EXTENSION_NAME),
|
extensions,
|
||||||
Optional.of(surface)
|
Optional.of(surface));
|
||||||
);
|
|
||||||
|
|
||||||
var physicalDeviceMatch = SuitablePhysicalDeviceFinder.findBestPhysicalDevice(instance, physicalDeviceCompatibilityValidator);
|
var physicalDeviceMatch = SuitablePhysicalDeviceFinder.findBestPhysicalDevice(instance,
|
||||||
|
physicalDeviceCompatibilityValidator);
|
||||||
if (physicalDeviceMatch == null) {
|
if (physicalDeviceMatch == null) {
|
||||||
throw new RuntimeException("No suitable physical device found");
|
throw new RuntimeException("No suitable physical device found");
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,10 +18,12 @@ public class QueueFamilyRequirementsValidator {
|
||||||
/**
|
/**
|
||||||
* Validate the queue family requirements of the physical device.
|
* Validate the queue family requirements of the physical device.
|
||||||
*
|
*
|
||||||
* <i>Note: This method return a Result to adapt the requirements to the physical device properties after the validation.</i>
|
* <i>Note: This method return a Result to adapt the requirements to the
|
||||||
|
* physical device properties after the validation.</i>
|
||||||
*
|
*
|
||||||
* @param physicalDevice The physical device to validate the requirements for.
|
* @param physicalDevice The physical device to validate the requirements for.
|
||||||
* @return A result object containing the validation results and whether the physical device is suitable.
|
* @return A result object containing the validation results and whether the
|
||||||
|
* physical device is suitable.
|
||||||
*/
|
*/
|
||||||
public Result validate(PhysicalDevice physicalDevice) {
|
public Result validate(PhysicalDevice physicalDevice) {
|
||||||
var vkQueueFamilyProps = physicalDevice.getVkQueueFamilyProps();
|
var vkQueueFamilyProps = physicalDevice.getVkQueueFamilyProps();
|
||||||
|
@ -31,8 +33,7 @@ public class QueueFamilyRequirementsValidator {
|
||||||
requirement -> requirement,
|
requirement -> requirement,
|
||||||
requirement -> Optional.empty(),
|
requirement -> Optional.empty(),
|
||||||
(a, b) -> a,
|
(a, b) -> a,
|
||||||
HashMap::new
|
HashMap::new));
|
||||||
));
|
|
||||||
|
|
||||||
for (int i = 0; i < vkQueueFamilyProps.capacity(); i++) {
|
for (int i = 0; i < vkQueueFamilyProps.capacity(); i++) {
|
||||||
var vkQueueFamilyProp = vkQueueFamilyProps.get(i);
|
var vkQueueFamilyProp = vkQueueFamilyProps.get(i);
|
||||||
|
@ -42,11 +43,14 @@ public class QueueFamilyRequirementsValidator {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (requirement.isFamilySuitable(physicalDevice, vkQueueFamilyProp, i)) {
|
if (requirement.isFamilySuitable(physicalDevice, vkQueueFamilyProp, i)) {
|
||||||
result.put(requirement, Optional.of(i));
|
result.put(requirement, Optional.of(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (result.values().stream().allMatch(Optional::isPresent)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isSuitable = result.values().stream().allMatch(Optional::isPresent);
|
boolean isSuitable = result.values().stream().allMatch(Optional::isPresent);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue