summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorOmniscient <17525998+omnisci3nce@users.noreply.github.com>2024-05-04 13:02:31 +1000
committerOmniscient <17525998+omnisci3nce@users.noreply.github.com>2024-05-04 13:02:31 +1000
commit74fd8a8424aeaccfaf7985f4ad2129fd54ae9fba (patch)
tree93323955154c3bc59d3a19744bafe2e4afd430f0 /src
parent8c714a082e4b8069b6f1c29e83e09f406f1c965a (diff)
swapchain support
Diffstat (limited to 'src')
-rw-r--r--src/renderer/backends/backend_opengl.c2
-rw-r--r--src/renderer/backends/backend_vulkan.c22
-rw-r--r--src/renderer/backends/vulkan_helpers.h173
-rw-r--r--src/systems/text.h1
4 files changed, 104 insertions, 94 deletions
diff --git a/src/renderer/backends/backend_opengl.c b/src/renderer/backends/backend_opengl.c
index 7fc277f..4cd97b5 100644
--- a/src/renderer/backends/backend_opengl.c
+++ b/src/renderer/backends/backend_opengl.c
@@ -6,8 +6,6 @@
#include "file.h"
#include "log.h"
#include "maths_types.h"
-// #include "render_types.h"
-#include "cleanroom/types.h"
#include "ral.h"
#if CEL_REND_BACKEND_OPENGL
diff --git a/src/renderer/backends/backend_vulkan.c b/src/renderer/backends/backend_vulkan.c
index 900b592..08e62bf 100644
--- a/src/renderer/backends/backend_vulkan.c
+++ b/src/renderer/backends/backend_vulkan.c
@@ -26,6 +26,7 @@ typedef struct vulkan_context {
VkInstance instance;
VkAllocationCallbacks* allocator;
VkSurfaceKHR surface;
+ vulkan_swapchain_support_info swapchain_support;
arena temp_arena;
gpu_device* device;
@@ -181,6 +182,9 @@ bool gpu_device_create(gpu_device* out_device) {
}
TRACE("Physical device selected");
+ // vulkan_device_query_swapchain_support(out_device->physical_device, context.surface,
+ // &context.swapchain_support);
+
// Logical device
create_logical_device(out_device);
// VkDeviceQueueCreateInfo queue_create_info = {};
@@ -432,6 +436,10 @@ bool select_physical_device(gpu_device* out_device) {
return false;
}
+ vkGetPhysicalDeviceProperties(out_device->physical_device, &out_device->properties);
+ vkGetPhysicalDeviceFeatures(out_device->physical_device, &out_device->features);
+ vkGetPhysicalDeviceMemoryProperties(out_device->physical_device, &out_device->memory);
+
return true;
}
@@ -449,7 +457,10 @@ bool is_physical_device_suitable(VkPhysicalDevice device) {
queue_family_indices indices = find_queue_families(device);
- return indices.has_graphics && indices.has_present;
+ vulkan_device_query_swapchain_support(device, context.surface, &context.swapchain_support);
+
+ return indices.has_graphics && indices.has_present && context.swapchain_support.mode_count > 0 &&
+ context.swapchain_support.format_count > 0;
}
queue_family_indices find_queue_families(VkPhysicalDevice device) {
@@ -480,8 +491,17 @@ queue_family_indices find_queue_families(VkPhysicalDevice device) {
return indices;
}
+const char* bool_str(bool input) { return input ? "True" : "False"; }
+
bool create_logical_device(gpu_device* out_device) {
queue_family_indices indices = find_queue_families(out_device->physical_device);
+ INFO(" %s | %s | %s | %s | %s", bool_str(indices.has_graphics), bool_str(indices.has_present),
+ bool_str(indices.has_compute), bool_str(indices.has_transfer),
+ out_device->properties.deviceName);
+ TRACE("Graphics Family queue index: %d", indices.graphics_family_index);
+ TRACE("Present Family queue index: %d", indices.present_family_index);
+ TRACE("Compute Family queue index: %d", indices.compute_family_index);
+ TRACE("Transfer Family queue index: %d", indices.transfer_family_index);
// Queues
f32 prio_one = 1.0;
diff --git a/src/renderer/backends/vulkan_helpers.h b/src/renderer/backends/vulkan_helpers.h
index d91b4a9..03ee814 100644
--- a/src/renderer/backends/vulkan_helpers.h
+++ b/src/renderer/backends/vulkan_helpers.h
@@ -40,13 +40,6 @@ typedef struct vulkan_physical_device_requirements {
bool discrete_gpu;
} vulkan_physical_device_requirements;
-typedef struct vulkan_physical_device_queue_family_info {
- u32 graphics_family_index;
- u32 present_family_index;
- u32 compute_family_index;
- u32 transfer_family_index;
-} vulkan_physical_device_queue_family_info;
-
#define VULKAN_MAX_DEFAULT 32
typedef struct vulkan_swapchain_support_info {
@@ -85,89 +78,89 @@ void vulkan_device_query_swapchain_support(VkPhysicalDevice device, VkSurfaceKHR
}
}
-static bool physical_device_meets_requirements(
- VkPhysicalDevice device, VkSurfaceKHR surface, const VkPhysicalDeviceProperties* properties,
- const VkPhysicalDeviceFeatures* features,
- const vulkan_physical_device_requirements* requirements,
- vulkan_physical_device_queue_family_info* out_queue_info,
- vulkan_swapchain_support_info* out_swapchain_support) {
- // TODO: pass in an arena
-
- out_queue_info->graphics_family_index = -1;
- out_queue_info->present_family_index = -1;
- out_queue_info->compute_family_index = -1;
- out_queue_info->transfer_family_index = -1;
-
- if (requirements->discrete_gpu) {
- if (properties->deviceType != VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) {
- TRACE("Device is not a physical GPU. Skipping.");
- return false;
- }
- }
-
- u32 queue_family_count = 0;
- vkGetPhysicalDeviceQueueFamilyProperties(device, &queue_family_count, 0);
- VkQueueFamilyProperties queue_families[queue_family_count];
- vkGetPhysicalDeviceQueueFamilyProperties(device, &queue_family_count, queue_families);
-
- INFO("Graphics | Present | Compute | Transfer | Name");
- u8 min_transfer_score = 255;
- for (u32 i = 0; i < queue_family_count; i++) {
- u8 current_transfer_score = 0;
-
- // Graphics queue
- if (queue_families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
- out_queue_info->graphics_family_index = i;
- current_transfer_score++;
- }
-
- // Compute queue
- if (queue_families[i].queueFlags & VK_QUEUE_COMPUTE_BIT) {
- out_queue_info->compute_family_index = i;
- current_transfer_score++;
- }
-
- // Transfer queue
- if (queue_families[i].queueFlags & VK_QUEUE_TRANSFER_BIT) {
- // always take the lowest score transfer index
- if (current_transfer_score <= min_transfer_score) {
- min_transfer_score = current_transfer_score;
- out_queue_info->transfer_family_index = i;
- }
- }
-
- // Present Queue
- VkBool32 supports_present = VK_FALSE;
- vkGetPhysicalDeviceSurfaceSupportKHR(device, i, surface, &supports_present);
- if (supports_present) {
- out_queue_info->present_family_index = i;
- }
- }
-
- INFO(" %d | %d | %d | %d | %s",
- out_queue_info->graphics_family_index != -1, out_queue_info->present_family_index != -1,
- out_queue_info->compute_family_index != -1, out_queue_info->transfer_family_index != -1,
- properties->deviceName);
- TRACE("Graphics Family queue index: %d", out_queue_info->graphics_family_index);
- TRACE("Present Family queue index: %d", out_queue_info->present_family_index);
- TRACE("Compute Family queue index: %d", out_queue_info->compute_family_index);
- TRACE("Transfer Family queue index: %d", out_queue_info->transfer_family_index);
-
- if ((!requirements->graphics ||
- (requirements->graphics && out_queue_info->graphics_family_index != -1))) {
- INFO("Physical device meets our requirements! Proceed.");
-
- vulkan_device_query_swapchain_support(
- device, surface, out_swapchain_support
-
- // TODO: error handling i.e. format count = 0 or present mode = 0
-
- );
- return true;
- }
-
- return false;
-}
+// static bool physical_device_meets_requirements(
+// VkPhysicalDevice device, VkSurfaceKHR surface, const VkPhysicalDeviceProperties* properties,
+// const VkPhysicalDeviceFeatures* features,
+// const vulkan_physical_device_requirements* requirements,
+// vulkan_physical_device_queue_family_info* out_queue_info,
+// vulkan_swapchain_support_info* out_swapchain_support) {
+// // TODO: pass in an arena
+
+// out_queue_info->graphics_family_index = -1;
+// out_queue_info->present_family_index = -1;
+// out_queue_info->compute_family_index = -1;
+// out_queue_info->transfer_family_index = -1;
+
+// if (requirements->discrete_gpu) {
+// if (properties->deviceType != VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) {
+// TRACE("Device is not a physical GPU. Skipping.");
+// return false;
+// }
+// }
+
+// u32 queue_family_count = 0;
+// vkGetPhysicalDeviceQueueFamilyProperties(device, &queue_family_count, 0);
+// VkQueueFamilyProperties queue_families[queue_family_count];
+// vkGetPhysicalDeviceQueueFamilyProperties(device, &queue_family_count, queue_families);
+
+// INFO("Graphics | Present | Compute | Transfer | Name");
+// u8 min_transfer_score = 255;
+// for (u32 i = 0; i < queue_family_count; i++) {
+// u8 current_transfer_score = 0;
+
+// // Graphics queue
+// if (queue_families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
+// out_queue_info->graphics_family_index = i;
+// current_transfer_score++;
+// }
+
+// // Compute queue
+// if (queue_families[i].queueFlags & VK_QUEUE_COMPUTE_BIT) {
+// out_queue_info->compute_family_index = i;
+// current_transfer_score++;
+// }
+
+// // Transfer queue
+// if (queue_families[i].queueFlags & VK_QUEUE_TRANSFER_BIT) {
+// // always take the lowest score transfer index
+// if (current_transfer_score <= min_transfer_score) {
+// min_transfer_score = current_transfer_score;
+// out_queue_info->transfer_family_index = i;
+// }
+// }
+
+// // Present Queue
+// VkBool32 supports_present = VK_FALSE;
+// vkGetPhysicalDeviceSurfaceSupportKHR(device, i, surface, &supports_present);
+// if (supports_present) {
+// out_queue_info->present_family_index = i;
+// }
+// }
+
+// INFO(" %d | %d | %d | %d | %s",
+// out_queue_info->graphics_family_index != -1, out_queue_info->present_family_index != -1,
+// out_queue_info->compute_family_index != -1, out_queue_info->transfer_family_index != -1,
+// properties->deviceName);
+// TRACE("Graphics Family queue index: %d", out_queue_info->graphics_family_index);
+// TRACE("Present Family queue index: %d", out_queue_info->present_family_index);
+// TRACE("Compute Family queue index: %d", out_queue_info->compute_family_index);
+// TRACE("Transfer Family queue index: %d", out_queue_info->transfer_family_index);
+
+// if ((!requirements->graphics ||
+// (requirements->graphics && out_queue_info->graphics_family_index != -1))) {
+// INFO("Physical device meets our requirements! Proceed.");
+
+// vulkan_device_query_swapchain_support(
+// device, surface, out_swapchain_support
+
+// // TODO: error handling i.e. format count = 0 or present mode = 0
+
+// );
+// return true;
+// }
+
+// return false;
+// }
VKAPI_ATTR VkBool32 VKAPI_CALL vk_debug_callback(
VkDebugUtilsMessageSeverityFlagBitsEXT severity, VkDebugUtilsMessageTypeFlagsEXT flags,
diff --git a/src/systems/text.h b/src/systems/text.h
index dc396f0..f40cfd6 100644
--- a/src/systems/text.h
+++ b/src/systems/text.h
@@ -5,7 +5,6 @@
#include <stb_truetype.h>
-#include "cleanroom/types.h"
#include "darray.h"
#include "defines.h"
#include "ral.h"