summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2023-10-22 21:18:13 +0300
committerkartofen <mladenovnasko0@gmail.com>2023-10-22 21:18:13 +0300
commite9bd321c8bd6bdb6aa7305c6da8b33e8cac462f7 (patch)
tree14d1e8993b68520dcfedfd6939b84c1af1330376
parent7e555eeadd1f295db7700b8bde884fcb92bb2b8d (diff)
renamed device.c/.h to graphics
-rw-r--r--src/graphics.c (renamed from src/device.c)211
-rw-r--r--src/graphics.h (renamed from src/device.h)16
-rw-r--r--src/main.c27
3 files changed, 125 insertions, 129 deletions
diff --git a/src/device.c b/src/graphics.c
index 5934270..8da9c43 100644
--- a/src/device.c
+++ b/src/graphics.c
@@ -2,10 +2,9 @@
#include <errno.h>
#include <vulkan/vulkan.h>
-#include "device.h"
+#include "graphics.h"
#include "common.h"
-// TODO: rename device.c/.h
// TODO: add more error checking
// TODO: add log output
// TODO: check for memory leaks
@@ -57,19 +56,19 @@ struct swap_chain_support_details {
// 0 - success; 1 - error; (sometimes -1 - fatal error)
// -- Major Functions ---
-static int create_instance(device_t device, struct device_info *info);
-static int create_surface(device_t device, struct device_info *info);
-static int create_physical_device(device_t device, struct device_info *info);
-static int create_logical_device(device_t device, struct device_info *info);
-static int create_pipeline(device_t device, struct device_info *info);
-static int create_swap_chain(device_t device, struct device_info *info);
-static int create_command_pool(device_t device, struct device_info *info);
-static int create_sync_objects(device_t device, struct device_info *info);
-
-static void destroy_swap_chain(device_t device);
-static void destroy_pipeline(device_t device);
-// static void destroy_command_pool(device_t device);
-static void destroy_sync_objects(device_t device);
+static int create_instance(graphics_t graphics, struct graphics_info *info);
+static int create_surface(graphics_t graphics, struct graphics_info *info);
+static int create_physical_device(graphics_t graphics, struct graphics_info *info);
+static int create_logical_device(graphics_t graphics, struct graphics_info *info);
+static int create_pipeline(graphics_t graphics, struct graphics_info *info);
+static int create_swap_chain(graphics_t graphics, struct graphics_info *info);
+static int create_command_pool(graphics_t graphics, struct graphics_info *info);
+static int create_sync_objects(graphics_t graphics, struct graphics_info *info);
+
+static void destroy_swap_chain(graphics_t graphics);
+static void destroy_pipeline(graphics_t graphics);
+// static void destroy_command_pool(graphics_t graphics);
+static void destroy_sync_objects(graphics_t graphics);
// --- Helper Functions ---
static char *str_VkResult(VkResult result);
@@ -78,20 +77,20 @@ static bool device_is_suitable(VkPhysicalDevice phy_device, VkSurfaceKHR surface
static bool device_has_extension_support(VkPhysicalDevice phy_device);
static int device_queue_families(VkPhysicalDevice phy_device, VkSurfaceKHR surface, struct queue_family_idx *queue_family);
-#define PPLN device->pipeline
+#define PPLN graphics->pipeline
static int pipeline_load_shader_module(VkDevice device, char *path, VkShaderModule *module);
-#define SWCH device->swap_chain
+#define SWCH graphics->swap_chain
static int swap_chain_support(VkPhysicalDevice phy_device, VkSurfaceKHR surface, struct swap_chain_support_details *details);
static void swap_chain_free_support_details(struct swap_chain_support_details *details);
static int swap_chain_choose_format(VkSurfaceFormatKHR* formats, u32 nformats, VkSurfaceFormatKHR *format);
static int swap_chain_choose_present_mode(VkPresentModeKHR *modes, u32 nmodes, VkPresentModeKHR *mode);
static int swap_chain_get_extent(VkSurfaceCapabilitiesKHR capabilities, VkExtent2D *extent);
-#define CMND device->command
-static int command_buffer_record(device_t device, u32 image_index);
+#define CMND graphics->command
+static int command_buffer_record(graphics_t graphics, u32 image_index);
-#define SYNC device->sync
+#define SYNC graphics->sync
F_LOAD_FILE_ALIGNED(u32) // from config.h
@@ -99,7 +98,7 @@ F_LOAD_FILE_ALIGNED(u32) // from config.h
#ifdef DEBUG
static bool instance_has_validation_layers(const char * const *layers, u32 nlayers);
-static int create_debug_messenger(device_t device, struct device_info* info);
+static int create_debug_messenger(graphics_t graphics, struct graphics_info* info);
static void debug_messenger_populate_info(VkDebugUtilsMessengerCreateInfoEXT *info);
static VKAPI_ATTR VkBool32 VKAPI_CALL debug_messenger_callback(
@@ -120,13 +119,13 @@ void DestroyDebugUtilsMessengerEXT(
const VkAllocationCallbacks* pAllocator);
#endif
-#define CCHECK(f) FCHECK(f, device, info)
+#define CCHECK(f) FCHECK(f, graphics, info)
-device_t device_create(struct device_info *info)
+graphics_t graphics_create(struct graphics_info *info)
{
- device_t device = xmalloc(sizeof(struct device));
- device->instance = VK_NULL_HANDLE;
- device->logical_device = VK_NULL_HANDLE;
+ graphics_t graphics = xmalloc(sizeof(struct graphics));
+ graphics->instance = VK_NULL_HANDLE;
+ graphics->logical_device = VK_NULL_HANDLE;
PPLN.pipeline = VK_NULL_HANDLE;
@@ -154,61 +153,61 @@ device_t device_create(struct device_info *info)
CCHECK(create_command_pool);
CCHECK(create_sync_objects);
- return device;
+ return graphics;
fail:
- device_destroy(device);
+ graphics_destroy(graphics);
return NULL;
}
-void device_destroy(device_t device)
+void graphics_destroy(graphics_t graphics)
{
- if(!device) return;
+ if(!graphics) return;
- vkDeviceWaitIdle(device->logical_device);
+ vkDeviceWaitIdle(graphics->logical_device);
- destroy_sync_objects(device);
+ destroy_sync_objects(graphics);
- vkDestroyCommandPool(device->logical_device, CMND.pool, NULL);
+ vkDestroyCommandPool(graphics->logical_device, CMND.pool, NULL);
- destroy_swap_chain(device);
- destroy_pipeline(device);
+ destroy_swap_chain(graphics);
+ destroy_pipeline(graphics);
- vkDestroyDevice(device->logical_device, NULL);
+ vkDestroyDevice(graphics->logical_device, NULL);
#ifdef DEBUG
- DestroyDebugUtilsMessengerEXT(device->instance, device->debug_messenger, NULL);
+ DestroyDebugUtilsMessengerEXT(graphics->instance, graphics->debug_messenger, NULL);
#endif
- vkDestroySurfaceKHR(device->instance, device->surface, NULL);
- vkDestroyInstance(device->instance, NULL);
+ vkDestroySurfaceKHR(graphics->instance, graphics->surface, NULL);
+ vkDestroyInstance(graphics->instance, NULL);
- free(device);
+ free(graphics);
}
-int device_draw_frame(device_t device)
+int graphics_draw_frame(graphics_t graphics)
{
int ret = 1;
// wait for the previous frame to finish
- vkWaitForFences(device->logical_device, 1, &SYNC.fence_inflight, VK_TRUE, UINT64_MAX);
+ vkWaitForFences(graphics->logical_device, 1, &SYNC.fence_inflight, VK_TRUE, UINT64_MAX);
// aquire the next image the form the swap chain
u32 image_index;
- VkResult res = vkAcquireNextImageKHR(device->logical_device, SWCH.swap_chain, UINT64_MAX, SYNC.semph_image_available, VK_NULL_HANDLE, &image_index);
+ VkResult res = vkAcquireNextImageKHR(graphics->logical_device, SWCH.swap_chain, UINT64_MAX, SYNC.semph_image_available, VK_NULL_HANDLE, &image_index);
// recreate the swap chain on resize
if(res == VK_ERROR_OUT_OF_DATE_KHR) {
- destroy_swap_chain(device);
- create_swap_chain(device, NULL);
+ destroy_swap_chain(graphics);
+ create_swap_chain(graphics, NULL);
ret = 0; goto exit;
}
- vkResetFences(device->logical_device, 1, &SYNC.fence_inflight);
+ vkResetFences(graphics->logical_device, 1, &SYNC.fence_inflight);
// reset the command buffer
vkResetCommandBuffer(CMND.buffer, 0);
- command_buffer_record(device, image_index);
+ command_buffer_record(graphics, image_index);
// prepare the queue submit info
VkSubmitInfo submit_info = {0};
@@ -228,7 +227,7 @@ int device_draw_frame(device_t device)
submit_info.pSignalSemaphores = signal_semphs;
// submit the graphics work
- VCHECK(vkQueueSubmit, device->graphics_queue, 1, &submit_info, SYNC.fence_inflight);
+ VCHECK(vkQueueSubmit, graphics->graphics_queue, 1, &submit_info, SYNC.fence_inflight);
// prepare the graphics info
VkPresentInfoKHR present_info = {0};
@@ -244,7 +243,7 @@ int device_draw_frame(device_t device)
present_info.pResults = NULL; // Optional
- vkQueuePresentKHR(device->present_queue, &present_info);
+ vkQueuePresentKHR(graphics->present_queue, &present_info);
ret = 0;
@@ -252,7 +251,7 @@ exit:
return ret;
}
-static int create_instance(device_t device, struct device_info *info)
+static int create_instance(graphics_t graphics, struct graphics_info *info)
{
int ret = 1;
@@ -306,7 +305,7 @@ static int create_instance(device_t device, struct device_info *info)
create_info.enabledLayerCount = 0;
#endif
- VCHECK(vkCreateInstance, &create_info, NULL, &device->instance);
+ VCHECK(vkCreateInstance, &create_info, NULL, &graphics->instance);
ret = 0;
exit:
@@ -316,9 +315,9 @@ exit:
return ret;
}
-static int create_surface(device_t device, struct device_info *info)
+static int create_surface(graphics_t graphics, struct graphics_info *info)
{
- if(info->surface_func(device->instance, &device->surface)) {
+ if(info->surface_func(graphics->instance, &graphics->surface)) {
err("Couldn't create a VkSurfaceKHR");
return 1;
}
@@ -326,15 +325,15 @@ static int create_surface(device_t device, struct device_info *info)
return 0;
}
-static int create_physical_device(device_t device, struct device_info *info)
+static int create_physical_device(graphics_t graphics, struct graphics_info *info)
{
(void)info;
int ret = 1;
- device->physical_device = VK_NULL_HANDLE;
+ graphics->physical_device = VK_NULL_HANDLE;
u32 dev_count = 0;
- vkEnumeratePhysicalDevices(device->instance, &dev_count, NULL);
+ vkEnumeratePhysicalDevices(graphics->instance, &dev_count, NULL);
if(dev_count == 0) {
err("No physical devices could be found!");
@@ -342,18 +341,18 @@ static int create_physical_device(device_t device, struct device_info *info)
}
VkPhysicalDevice *devices = xcalloc(dev_count, sizeof(*devices));
- vkEnumeratePhysicalDevices(device->instance, &dev_count, devices);
+ vkEnumeratePhysicalDevices(graphics->instance, &dev_count, devices);
for(u32 i = 0; i < dev_count; i++) {
- if(device_is_suitable(devices[i], device->surface)) {
- device->physical_device = devices[i];
+ if(device_is_suitable(devices[i], graphics->surface)) {
+ graphics->physical_device = devices[i];
break;
}
}
free(devices);
- if(device->physical_device == VK_NULL_HANDLE) {
+ if(graphics->physical_device == VK_NULL_HANDLE) {
err("No suitable physical device could be found");
goto exit;
}
@@ -363,14 +362,14 @@ exit:
return ret;
}
-static int create_logical_device(device_t device, struct device_info *info)
+static int create_logical_device(graphics_t graphics, struct graphics_info *info)
{
(void)info;
int ret = 1;
// queue family data
struct queue_family_idx indices = {0};
- device_queue_families(device->physical_device, device->surface, &indices);
+ device_queue_families(graphics->physical_device, graphics->surface, &indices);
// queue infos
u32 unique_queue_family_count = 0;
@@ -422,23 +421,23 @@ static int create_logical_device(device_t device, struct device_info *info)
// so i wont bother adding them
create_info.enabledLayerCount = 0;
- VCHECK(vkCreateDevice, device->physical_device, &create_info, NULL, &device->logical_device);
+ VCHECK(vkCreateDevice, graphics->physical_device, &create_info, NULL, &graphics->logical_device);
- vkGetDeviceQueue(device->logical_device, indices.graphics_family, 0, &device->graphics_queue);
- vkGetDeviceQueue(device->logical_device, indices.present_family, 0, &device->present_queue);
+ vkGetDeviceQueue(graphics->logical_device, indices.graphics_family, 0, &graphics->graphics_queue);
+ vkGetDeviceQueue(graphics->logical_device, indices.present_family, 0, &graphics->present_queue);
ret = 0;
exit:
return ret;
}
-static int create_swap_chain(device_t device, struct device_info *info)
+static int create_swap_chain(graphics_t graphics, struct graphics_info *info)
{
(void)info;
int ret = 1;
struct swap_chain_support_details details;
- swap_chain_support(device->physical_device, device->surface, &details);
+ swap_chain_support(graphics->physical_device, graphics->surface, &details);
VkSurfaceFormatKHR surface_format;
VkPresentModeKHR present_mode;
@@ -457,7 +456,7 @@ static int create_swap_chain(device_t device, struct device_info *info)
VkSwapchainCreateInfoKHR create_info = {0};
create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
- create_info.surface = device->surface;
+ create_info.surface = graphics->surface;
create_info.minImageCount = image_count;
create_info.imageFormat = surface_format.format;
create_info.imageColorSpace = surface_format.colorSpace;
@@ -466,7 +465,7 @@ static int create_swap_chain(device_t device, struct device_info *info)
create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
struct queue_family_idx indices = {0};
- device_queue_families(device->physical_device, device->surface, &indices);
+ device_queue_families(graphics->physical_device, graphics->surface, &indices);
u32 queue_indices[] = { indices.graphics_family, indices.present_family };
@@ -489,19 +488,19 @@ static int create_swap_chain(device_t device, struct device_info *info)
create_info.oldSwapchain = NULL;
- VCHECK(vkCreateSwapchainKHR, device->logical_device, &create_info, NULL, &SWCH.swap_chain);
+ VCHECK(vkCreateSwapchainKHR, graphics->logical_device, &create_info, NULL, &SWCH.swap_chain);
// Get the Images
SWCH.image_format = surface_format.format;
SWCH.extent = extent;
- vkGetSwapchainImagesKHR(device->logical_device, SWCH.swap_chain, &SWCH.nimages, NULL);
+ vkGetSwapchainImagesKHR(graphics->logical_device, SWCH.swap_chain, &SWCH.nimages, NULL);
SWCH.images = xcalloc(SWCH.nimages, sizeof(*SWCH.images));
SWCH.image_views = xcalloc(SWCH.nimages, sizeof(SWCH.image_views));
SWCH.framebuffers = xcalloc(SWCH.nimages, sizeof(*SWCH.framebuffers));
- vkGetSwapchainImagesKHR(device->logical_device, SWCH.swap_chain, &SWCH.nimages, SWCH.images);
+ vkGetSwapchainImagesKHR(graphics->logical_device, SWCH.swap_chain, &SWCH.nimages, SWCH.images);
for(u32 i = 0; i < SWCH.nimages; i++)
{
@@ -523,7 +522,7 @@ static int create_swap_chain(device_t device, struct device_info *info)
create_info.subresourceRange.baseArrayLayer = 0;
create_info.subresourceRange.layerCount = 1;
- VCHECK(vkCreateImageView, device->logical_device, &create_info, NULL, &SWCH.image_views[i]);
+ VCHECK(vkCreateImageView, graphics->logical_device, &create_info, NULL, &SWCH.image_views[i]);
}
for(u32 i = 0; i < SWCH.nimages; i++)
@@ -541,7 +540,7 @@ static int create_swap_chain(device_t device, struct device_info *info)
framebuffer_info.height = SWCH.extent.height;
framebuffer_info.layers = 1;
- VCHECK(vkCreateFramebuffer, device->logical_device, &framebuffer_info, NULL, &SWCH.framebuffers[i]);
+ VCHECK(vkCreateFramebuffer, graphics->logical_device, &framebuffer_info, NULL, &SWCH.framebuffers[i]);
}
ret = 0;
@@ -550,11 +549,11 @@ exit:
return ret;
}
-static void destroy_swap_chain(device_t device)
+static void destroy_swap_chain(graphics_t graphics)
{
for(u32 i = 0; i < SWCH.nimages; i++) {
- vkDestroyImageView(device->logical_device, SWCH.image_views[i], NULL);
- vkDestroyFramebuffer(device->logical_device, SWCH.framebuffers[i], NULL);
+ vkDestroyImageView(graphics->logical_device, SWCH.image_views[i], NULL);
+ vkDestroyFramebuffer(graphics->logical_device, SWCH.framebuffers[i], NULL);
}
if(SWCH.nimages != 0) {
@@ -563,10 +562,10 @@ static void destroy_swap_chain(device_t device)
free(SWCH.framebuffers);
}
- vkDestroySwapchainKHR(device->logical_device, SWCH.swap_chain, NULL);
+ vkDestroySwapchainKHR(graphics->logical_device, SWCH.swap_chain, NULL);
}
-static int create_pipeline(device_t device, struct device_info *info)
+static int create_pipeline(graphics_t graphics, struct graphics_info *info)
{
(void)info;
int ret = 1;
@@ -575,8 +574,8 @@ static int create_pipeline(device_t device, struct device_info *info)
VkShaderModule vert_shader = VK_NULL_HANDLE;
VkShaderModule frag_shader = VK_NULL_HANDLE;
- pipeline_load_shader_module(device->logical_device, "shaders/shader1.vert.spv", &vert_shader);
- pipeline_load_shader_module(device->logical_device, "shaders/shader1.frag.spv", &frag_shader);
+ pipeline_load_shader_module(graphics->logical_device, "shaders/shader1.vert.spv", &vert_shader);
+ pipeline_load_shader_module(graphics->logical_device, "shaders/shader1.frag.spv", &frag_shader);
VkPipelineShaderStageCreateInfo vert_stage = {0};
vert_stage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
@@ -670,14 +669,14 @@ static int create_pipeline(device_t device, struct device_info *info)
pipeline_layout_info.pushConstantRangeCount = 0; // Optional
pipeline_layout_info.pPushConstantRanges = NULL; // Optional
- VCHECK(vkCreatePipelineLayout, device->logical_device, &pipeline_layout_info, NULL, &PPLN.layout);
+ VCHECK(vkCreatePipelineLayout, graphics->logical_device, &pipeline_layout_info, NULL, &PPLN.layout);
// get the required format
// currently the only to do that
// TOOD: fix this
VkSurfaceFormatKHR surface_format;
struct swap_chain_support_details details;
- swap_chain_support(device->physical_device, device->surface, &details);
+ swap_chain_support(graphics->physical_device, graphics->surface, &details);
swap_chain_choose_format(details.formats, details.nformats, &surface_format);
swap_chain_free_support_details(&details);
@@ -718,7 +717,7 @@ static int create_pipeline(device_t device, struct device_info *info)
render_pass_info.dependencyCount = 1;
render_pass_info.pDependencies = &dependency;
- VCHECK(vkCreateRenderPass, device->logical_device, &render_pass_info, NULL, &PPLN.render_pass);
+ VCHECK(vkCreateRenderPass, graphics->logical_device, &render_pass_info, NULL, &PPLN.render_pass);
// Finally Create the Pipeline
VkGraphicsPipelineCreateInfo pipeline_info = {0};
@@ -742,36 +741,36 @@ static int create_pipeline(device_t device, struct device_info *info)
pipeline_info.basePipelineHandle = VK_NULL_HANDLE; // Optional
pipeline_info.basePipelineIndex = -1; // Optional
- VCHECK(vkCreateGraphicsPipelines, device->logical_device, VK_NULL_HANDLE, 1, &pipeline_info, NULL, &PPLN.pipeline);
+ VCHECK(vkCreateGraphicsPipelines, graphics->logical_device, VK_NULL_HANDLE, 1, &pipeline_info, NULL, &PPLN.pipeline);
ret = 0;
exit:
- vkDestroyShaderModule(device->logical_device, frag_shader, NULL);
- vkDestroyShaderModule(device->logical_device, vert_shader, NULL);
+ vkDestroyShaderModule(graphics->logical_device, frag_shader, NULL);
+ vkDestroyShaderModule(graphics->logical_device, vert_shader, NULL);
return ret;
}
-static void destroy_pipeline(device_t device)
+static void destroy_pipeline(graphics_t graphics)
{
- vkDestroyPipeline(device->logical_device, PPLN.pipeline, NULL);
- vkDestroyPipelineLayout(device->logical_device, PPLN.layout, NULL);
- vkDestroyRenderPass(device->logical_device, PPLN.render_pass, NULL);
+ vkDestroyPipeline(graphics->logical_device, PPLN.pipeline, NULL);
+ vkDestroyPipelineLayout(graphics->logical_device, PPLN.layout, NULL);
+ vkDestroyRenderPass(graphics->logical_device, PPLN.render_pass, NULL);
}
-static int create_command_pool(device_t device, struct device_info *info)
+static int create_command_pool(graphics_t graphics, struct graphics_info *info)
{
(void)info;
int ret = 1;
struct queue_family_idx indices;
- device_queue_families(device->physical_device, device->surface, &indices);
+ device_queue_families(graphics->physical_device, graphics->surface, &indices);
VkCommandPoolCreateInfo pool_info = {0};
pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
pool_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
pool_info.queueFamilyIndex = indices.graphics_family;
- VCHECK(vkCreateCommandPool, device->logical_device, &pool_info, NULL, &CMND.pool);
+ VCHECK(vkCreateCommandPool, graphics->logical_device, &pool_info, NULL, &CMND.pool);
// allocate the command buffer(s)
VkCommandBufferAllocateInfo allocate_info = {0};
@@ -780,14 +779,14 @@ static int create_command_pool(device_t device, struct device_info *info)
allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
allocate_info.commandBufferCount = 1;
- VCHECK(vkAllocateCommandBuffers, device->logical_device, &allocate_info, &CMND.buffer);
+ VCHECK(vkAllocateCommandBuffers, graphics->logical_device, &allocate_info, &CMND.buffer);
ret = 0;
exit:
return ret;
}
-static int create_sync_objects(device_t device, struct device_info *info)
+static int create_sync_objects(graphics_t graphics, struct graphics_info *info)
{
(void)info;
int ret = 1;
@@ -799,20 +798,20 @@ static int create_sync_objects(device_t device, struct device_info *info)
fence_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
fence_info.flags = VK_FENCE_CREATE_SIGNALED_BIT;
- VCHECK(vkCreateSemaphore, device->logical_device, &semph_info, NULL, &SYNC.semph_image_available);
- VCHECK(vkCreateSemaphore, device->logical_device, &semph_info, NULL, &SYNC.semph_render_finished);
- VCHECK(vkCreateFence, device->logical_device, &fence_info, NULL, &SYNC.fence_inflight);
+ VCHECK(vkCreateSemaphore, graphics->logical_device, &semph_info, NULL, &SYNC.semph_image_available);
+ VCHECK(vkCreateSemaphore, graphics->logical_device, &semph_info, NULL, &SYNC.semph_render_finished);
+ VCHECK(vkCreateFence, graphics->logical_device, &fence_info, NULL, &SYNC.fence_inflight);
ret = 0;
exit:
return ret;
}
-static void destroy_sync_objects(device_t device)
+static void destroy_sync_objects(graphics_t graphics)
{
- vkDestroySemaphore(device->logical_device, SYNC.semph_image_available, NULL);
- vkDestroySemaphore(device->logical_device, SYNC.semph_render_finished, NULL);
- vkDestroyFence(device->logical_device, SYNC.fence_inflight, NULL);
+ vkDestroySemaphore(graphics->logical_device, SYNC.semph_image_available, NULL);
+ vkDestroySemaphore(graphics->logical_device, SYNC.semph_render_finished, NULL);
+ vkDestroyFence(graphics->logical_device, SYNC.fence_inflight, NULL);
}
static int device_queue_families(VkPhysicalDevice phy_device, VkSurfaceKHR surface, struct queue_family_idx *queue_family)
@@ -974,7 +973,7 @@ exit:
return ret;
}
-static int command_buffer_record(device_t device, u32 image_index)
+static int command_buffer_record(graphics_t graphics, u32 image_index)
{
int ret = 1;
@@ -1085,7 +1084,7 @@ static bool instance_has_validation_layers(const char * const *layers, u32 nlaye
return true;
}
-static int create_debug_messenger(device_t device, struct device_info *info)
+static int create_debug_messenger(graphics_t graphics, struct graphics_info *info)
{
(void)info;
int ret = 1;
@@ -1093,7 +1092,7 @@ static int create_debug_messenger(device_t device, struct device_info *info)
VkDebugUtilsMessengerCreateInfoEXT cinfo = {0};
debug_messenger_populate_info(&cinfo);
- VCHECK(CreateDebugUtilsMessengerEXT, device->instance, &cinfo, NULL, &device->debug_messenger);
+ VCHECK(CreateDebugUtilsMessengerEXT, graphics->instance, &cinfo, NULL, &graphics->debug_messenger);
ret = 0;
exit:
diff --git a/src/device.h b/src/graphics.h
index b28c806..52e511e 100644
--- a/src/device.h
+++ b/src/graphics.h
@@ -1,5 +1,5 @@
-#ifndef DEVICE_H
-#define DEVICE_H
+#ifndef GRAPHICS_H
+#define GRAPHICS_H
#include <stdint.h>
#include <stdbool.h>
@@ -13,7 +13,7 @@
typedef uint32_t u32;
-typedef struct device {
+typedef struct graphics {
VkInstance instance;
VkDebugUtilsMessengerEXT debug_messenger;
@@ -54,9 +54,9 @@ typedef struct device {
VkFence fence_inflight;
} sync;
-} * device_t;
+} * graphics_t;
-struct device_info {
+struct graphics_info {
char *name;
u32 version;
@@ -66,8 +66,8 @@ struct device_info {
int (*surface_func)(VkInstance instance, VkSurfaceKHR *surface);
};
-device_t device_create(struct device_info *info);
-void device_destroy(device_t device);
-int device_draw_frame(device_t device);
+graphics_t graphics_create(struct graphics_info *info);
+void graphics_destroy(graphics_t device);
+int graphics_draw_frame(graphics_t device);
#endif
diff --git a/src/main.c b/src/main.c
index 8fd7345..0f35679 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,15 +1,12 @@
#include <stdio.h>
#include <stdlib.h>
-#include "device.h"
+#include "graphics.h"
#include "window.h"
#include "common.h"
-// TODO: rename device.c/.h
-// to graphics.c/.h
-
window_t window;
-device_t device;
+graphics_t graphics;
int _create_surface(VkInstance instance, VkSurfaceKHR *surface);
@@ -44,18 +41,18 @@ int main(void)
window_extension_info(window, &ext_count, (const char **)extensions);
// populate the device info
- struct device_info dev_info = {0};
- dev_info.name = "Test App";
- dev_info.version = MAKE_VERSION(1, 0, 0);
+ struct graphics_info grph_info = {0};
+ grph_info.name = "Test App";
+ grph_info.version = MAKE_VERSION(1, 0, 0);
- dev_info.ext_count = ext_count;
- dev_info.extensions = (const char * const *)extensions;
+ grph_info.ext_count = ext_count;
+ grph_info.extensions = (const char * const *)extensions;
- dev_info.surface_func = _create_surface;
+ grph_info.surface_func = _create_surface;
// create the device
- device = device_create(&dev_info);
- if(!device) {
+ graphics = graphics_create(&grph_info);
+ if(!graphics) {
err("device_create: failed");
if(extensions) free(extensions);
goto f3;
@@ -72,12 +69,12 @@ int main(void)
break;
}
- device_draw_frame(device);
+ graphics_draw_frame(graphics);
}
ret = 0;
- device_destroy(device);
+ graphics_destroy(graphics);
f3: window_destroy(window);
f2: SDL_Quit();
f1: return ret;