almost improve physical dev module
draw function needs some help
This commit is contained in:
parent
7565731ef5
commit
402e45c766
8 changed files with 21 additions and 22 deletions
|
@ -197,7 +197,7 @@ int ptk_run(PtkHandle root) {
|
||||||
|
|
||||||
while (!glfwWindowShouldClose(m_window)) {
|
while (!glfwWindowShouldClose(m_window)) {
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
if (!vk_draw_frame(m_window, g_surface)) {
|
if (!vk_draw_frame(m_window, /*missing physical_dev*/ g_surface)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
bool g_framebuffer_resized = false;
|
bool g_framebuffer_resized = false;
|
||||||
uint32_t g_current_frame = 0;
|
uint32_t g_current_frame = 0;
|
||||||
|
|
||||||
bool vk_draw_frame(GLFWwindow *window, VkSurfaceKHR surface) {
|
bool vk_draw_frame(GLFWwindow *window, VkPhysicalDevice physical_dev, VkSurfaceKHR surface) {
|
||||||
vkWaitForFences(g_dev, 1, &g_in_flight_fences.data[g_current_frame], VK_TRUE, UINT64_MAX);
|
vkWaitForFences(g_dev, 1, &g_in_flight_fences.data[g_current_frame], VK_TRUE, UINT64_MAX);
|
||||||
|
|
||||||
uint32_t image_index;
|
uint32_t image_index;
|
||||||
|
@ -28,7 +28,7 @@ bool vk_draw_frame(GLFWwindow *window, VkSurfaceKHR surface) {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (acquire_next_image_result == VK_ERROR_OUT_OF_DATE_KHR) {
|
if (acquire_next_image_result == VK_ERROR_OUT_OF_DATE_KHR) {
|
||||||
if (!vk_recreate_swapchain(window, surface)) {
|
if (!vk_recreate_swapchain(window, physical_dev, surface)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -85,7 +85,7 @@ bool vk_draw_frame(GLFWwindow *window, VkSurfaceKHR surface) {
|
||||||
g_framebuffer_resized
|
g_framebuffer_resized
|
||||||
) {
|
) {
|
||||||
g_framebuffer_resized = false;
|
g_framebuffer_resized = false;
|
||||||
if (!vk_recreate_swapchain(window, surface)) {
|
if (!vk_recreate_swapchain(window, physical_dev, surface)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PTK_TRACE("recreated swapchain");
|
PTK_TRACE("recreated swapchain");
|
||||||
|
|
|
@ -14,6 +14,6 @@
|
||||||
extern bool g_framebuffer_resized;
|
extern bool g_framebuffer_resized;
|
||||||
extern uint32_t g_current_frame;
|
extern uint32_t g_current_frame;
|
||||||
|
|
||||||
bool vk_draw_frame(GLFWwindow *window, VkSurfaceKHR surface);
|
bool vk_draw_frame(GLFWwindow *window, VkPhysicalDevice physical_dev, VkSurfaceKHR surface);
|
||||||
|
|
||||||
#endif // PTK_PTK_VK_DRAW_H_
|
#endif // PTK_PTK_VK_DRAW_H_
|
||||||
|
|
|
@ -29,6 +29,7 @@ PTK_LIST_DEFINE(voidptr);
|
||||||
PTK_LIST_DEFINE(VkDescriptorSet);
|
PTK_LIST_DEFINE(VkDescriptorSet);
|
||||||
|
|
||||||
static VkInstance m_instance;
|
static VkInstance m_instance;
|
||||||
|
static VkPhysicalDevice m_physical_dev;
|
||||||
|
|
||||||
static GLFWwindow *m_window = NULL;
|
static GLFWwindow *m_window = NULL;
|
||||||
|
|
||||||
|
@ -420,7 +421,7 @@ bool create_command_pool(void) {
|
||||||
|
|
||||||
PTK_OPTION(uint32_t) find_memory_type(const uint32_t type_filter, const VkMemoryPropertyFlags props) {
|
PTK_OPTION(uint32_t) find_memory_type(const uint32_t type_filter, const VkMemoryPropertyFlags props) {
|
||||||
VkPhysicalDeviceMemoryProperties mem_props;
|
VkPhysicalDeviceMemoryProperties mem_props;
|
||||||
vkGetPhysicalDeviceMemoryProperties(g_physical_dev, &mem_props);
|
vkGetPhysicalDeviceMemoryProperties(m_physical_dev, &mem_props);
|
||||||
|
|
||||||
for (uint32_t i = 0; i < mem_props.memoryTypeCount; ++i) {
|
for (uint32_t i = 0; i < mem_props.memoryTypeCount; ++i) {
|
||||||
if (type_filter & (1 << i) && (mem_props.memoryTypes[i].propertyFlags & props) == props) {
|
if (type_filter & (1 << i) && (mem_props.memoryTypes[i].propertyFlags & props) == props) {
|
||||||
|
@ -882,19 +883,23 @@ bool vk_init(GLFWwindow *window, const size_t width, const size_t height, const
|
||||||
|
|
||||||
m_instance = instance_opt.value;
|
m_instance = instance_opt.value;
|
||||||
|
|
||||||
if (!vk_select_physical_dev(m_instance)) {
|
PTK_OPTION(VkPhysicalDevice) physical_dev_opt = vk_select_physical_dev(m_instance);
|
||||||
|
|
||||||
|
if (!physical_dev_opt.exists) {
|
||||||
PTK_ERR("failed selecting physical device");
|
PTK_ERR("failed selecting physical device");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_physical_dev = physical_dev_opt.value;
|
||||||
|
|
||||||
VK_TRY(false, glfwCreateWindowSurface(m_instance, m_window, NULL, &g_surface));
|
VK_TRY(false, glfwCreateWindowSurface(m_instance, m_window, NULL, &g_surface));
|
||||||
|
|
||||||
if (!vk_create_logical_dev(g_physical_dev, g_surface, m_validation_layers)) {
|
if (!vk_create_logical_dev(m_physical_dev, g_surface, m_validation_layers)) {
|
||||||
PTK_ERR("failed creating logical device");
|
PTK_ERR("failed creating logical device");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!vk_create_swapchain(m_window, g_dev, g_physical_dev, g_surface)) {
|
if (!vk_create_swapchain(m_window, g_dev, m_physical_dev, g_surface)) {
|
||||||
PTK_ERR("failed creating swapchain");
|
PTK_ERR("failed creating swapchain");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,14 +6,12 @@
|
||||||
|
|
||||||
#include <vulkan/vulkan.h>
|
#include <vulkan/vulkan.h>
|
||||||
|
|
||||||
VkPhysicalDevice g_physical_dev;
|
PTK_OPTION(VkPhysicalDevice) vk_select_physical_dev(const VkInstance instance) {
|
||||||
|
|
||||||
bool vk_select_physical_dev(const VkInstance instance) {
|
|
||||||
uint32_t dev_count = 0;
|
uint32_t dev_count = 0;
|
||||||
vkEnumeratePhysicalDevices(instance, &dev_count, NULL);
|
vkEnumeratePhysicalDevices(instance, &dev_count, NULL);
|
||||||
if (dev_count == 0) {
|
if (dev_count == 0) {
|
||||||
PTK_ERR("failed to find GPU with vulkan support");
|
PTK_ERR("failed to find GPU with vulkan support");
|
||||||
return false;
|
return PTK_OPTION_NONE(VkPhysicalDevice);
|
||||||
}
|
}
|
||||||
VkPhysicalDevice devs[dev_count];
|
VkPhysicalDevice devs[dev_count];
|
||||||
vkEnumeratePhysicalDevices(instance, &dev_count, devs);
|
vkEnumeratePhysicalDevices(instance, &dev_count, devs);
|
||||||
|
@ -75,7 +73,5 @@ bool vk_select_physical_dev(const VkInstance instance) {
|
||||||
|
|
||||||
PTK_DEBUG("total memory: %lu", dev_mem_totals[dev_best_index]);
|
PTK_DEBUG("total memory: %lu", dev_mem_totals[dev_best_index]);
|
||||||
|
|
||||||
g_physical_dev = devs[dev_best_index];
|
return PTK_OPTION_SOME(VkPhysicalDevice, devs[dev_best_index]);
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,8 @@
|
||||||
|
|
||||||
#include <ptk_option.h>
|
#include <ptk_option.h>
|
||||||
|
|
||||||
extern VkPhysicalDevice g_physical_dev;
|
|
||||||
|
|
||||||
PTK_OPTION_DEFINE(VkPhysicalDevice);
|
PTK_OPTION_DEFINE(VkPhysicalDevice);
|
||||||
|
|
||||||
bool vk_select_physical_dev(const VkInstance instance);
|
PTK_OPTION(VkPhysicalDevice) vk_select_physical_dev(const VkInstance instance);
|
||||||
|
|
||||||
#endif // PTK_PTK_VK_PHYSICAL_DEVICE_H_
|
#endif // PTK_PTK_VK_PHYSICAL_DEVICE_H_
|
||||||
|
|
|
@ -218,7 +218,7 @@ bool vk_create_swapchain(GLFWwindow *window, VkDevice dev, VkPhysicalDevice phys
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool vk_recreate_swapchain(GLFWwindow *window, VkSurfaceKHR surface) {
|
bool vk_recreate_swapchain(GLFWwindow *window, VkPhysicalDevice physical_dev, VkSurfaceKHR surface) {
|
||||||
int width = 0, height = 0;
|
int width = 0, height = 0;
|
||||||
glfwGetFramebufferSize(window, &width, &height);
|
glfwGetFramebufferSize(window, &width, &height);
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ bool vk_recreate_swapchain(GLFWwindow *window, VkSurfaceKHR surface) {
|
||||||
|
|
||||||
vk_cleanup_swapchain(g_dev);
|
vk_cleanup_swapchain(g_dev);
|
||||||
|
|
||||||
if (!vk_create_swapchain(window, g_dev, g_physical_dev, surface)) {
|
if (!vk_create_swapchain(window, g_dev, physical_dev, surface)) {
|
||||||
PTK_ERR("failed creating new swapchain");
|
PTK_ERR("failed creating new swapchain");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ bool vk_create_swapchain(GLFWwindow *window, VkDevice dev, VkPhysicalDevice phys
|
||||||
|
|
||||||
bool vk_create_image_views(VkDevice dev);
|
bool vk_create_image_views(VkDevice dev);
|
||||||
|
|
||||||
bool vk_recreate_swapchain(GLFWwindow *window, VkSurfaceKHR surface);
|
bool vk_recreate_swapchain(GLFWwindow *window, VkPhysicalDevice physical_dev, VkSurfaceKHR surface);
|
||||||
|
|
||||||
bool vk_create_framebuffers(void);
|
bool vk_create_framebuffers(void);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue