get rid of most uses of g_max_frames_in_flight

This commit is contained in:
jacekpoz 2024-09-25 19:43:21 +02:00
parent 46a00f9466
commit 5683cc0228
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8
9 changed files with 30 additions and 31 deletions

View file

@ -3,8 +3,8 @@
#include <ptk_vk/init.h>
#include <ptk_vk/utils.h>
PTK_OPTION(VkCommandBufferList) vk_allocate_command_buffers(VkDevice dev, VkCommandPool command_pool) {
VkCommandBufferList ret = PTK_LIST_NEW(VkCommandBuffer, /* TODO: get rid of this */g_max_frames_in_flight);
PTK_OPTION(VkCommandBufferList) vk_allocate_command_buffers(VkDevice dev, VkCommandPool command_pool, uint32_t max_frames_in_flight) {
VkCommandBufferList ret = PTK_LIST_NEW(VkCommandBuffer, max_frames_in_flight);
VK_TRY(PTK_OPTION_NONE(VkCommandBufferList),
vkAllocateCommandBuffers(

View file

@ -12,6 +12,6 @@ PTK_LIST_DEFINE(VkCommandBuffer);
typedef PTK_LIST(VkCommandBuffer) VkCommandBufferList;
PTK_OPTION_DEFINE(VkCommandBufferList);
PTK_OPTION(VkCommandBufferList) vk_allocate_command_buffers(VkDevice dev, VkCommandPool command_pool);
PTK_OPTION(VkCommandBufferList) vk_allocate_command_buffers(VkDevice dev, VkCommandPool command_pool, uint32_t max_frames_in_flight);
#endif // PTK_PTK_VK_COMMAND_BUFFERS_H_

View file

@ -32,7 +32,7 @@ PTK_OPTION(VkDescriptorSetLayout) vk_create_descriptor_set_layout(VkDevice dev)
return PTK_OPTION_SOME(VkDescriptorSetLayout, ret);
}
PTK_OPTION(VkDescriptorPool) vk_create_descriptor_pool(VkDevice dev) {
PTK_OPTION(VkDescriptorPool) vk_create_descriptor_pool(VkDevice dev, uint32_t max_frames_in_flight) {
VkDescriptorPool ret;
VK_TRY(PTK_OPTION_NONE(VkDescriptorPool),
@ -42,11 +42,11 @@ PTK_OPTION(VkDescriptorPool) vk_create_descriptor_pool(VkDevice dev) {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
.pNext = NULL,
.flags = 0,
.maxSets = /* TODO: get rid of this */g_max_frames_in_flight,
.maxSets = max_frames_in_flight,
.poolSizeCount = 1,
.pPoolSizes = &(VkDescriptorPoolSize){
.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.descriptorCount = g_max_frames_in_flight,
.descriptorCount = max_frames_in_flight,
},
},
NULL,
@ -59,13 +59,13 @@ PTK_OPTION(VkDescriptorPool) vk_create_descriptor_pool(VkDevice dev) {
PTK_LIST_DEFINE(VkDescriptorSetLayout);
PTK_OPTION(VkDescriptorSetList) vk_create_descriptor_sets(VkDevice dev, VkDescriptorSetLayout descriptor_set_layout, VkDescriptorPool descriptor_pool, PTK_LIST(VkBuffer) uniform_buffers) {
PTK_LIST(VkDescriptorSetLayout) layouts = PTK_LIST_NEW(VkDescriptorSetLayout, g_max_frames_in_flight);
for (size_t i = 0; i < g_max_frames_in_flight; ++i) {
PTK_OPTION(VkDescriptorSetList) vk_create_descriptor_sets(VkDevice dev, VkDescriptorSetLayout descriptor_set_layout, VkDescriptorPool descriptor_pool, PTK_LIST(VkBuffer) uniform_buffers, uint32_t max_frames_in_flight) {
PTK_LIST(VkDescriptorSetLayout) layouts = PTK_LIST_NEW(VkDescriptorSetLayout, max_frames_in_flight);
for (size_t i = 0; i < max_frames_in_flight; ++i) {
PTK_LIST_ADD(VkDescriptorSetLayout, layouts, descriptor_set_layout);
}
VkDescriptorSetList ret = PTK_LIST_NEW(VkDescriptorSet, g_max_frames_in_flight);
VkDescriptorSetList ret = PTK_LIST_NEW(VkDescriptorSet, max_frames_in_flight);
VK_TRY(PTK_OPTION_NONE(VkDescriptorSetList),
vkAllocateDescriptorSets(
@ -81,7 +81,7 @@ PTK_OPTION(VkDescriptorSetList) vk_create_descriptor_sets(VkDevice dev, VkDescri
)
);
for (size_t i = 0; i < g_max_frames_in_flight; ++i) {
for (size_t i = 0; i < max_frames_in_flight; ++i) {
vkUpdateDescriptorSets(
dev,
1,

View file

@ -18,7 +18,7 @@ typedef PTK_LIST(VkDescriptorSet) VkDescriptorSetList;
PTK_OPTION_DEFINE(VkDescriptorSetList);
PTK_OPTION(VkDescriptorSetLayout) vk_create_descriptor_set_layout(VkDevice dev);
PTK_OPTION(VkDescriptorPool) vk_create_descriptor_pool(VkDevice dev);
PTK_OPTION(VkDescriptorSetList) vk_create_descriptor_sets(VkDevice dev, VkDescriptorSetLayout descriptor_set_layout, VkDescriptorPool descriptor_pool, PTK_LIST(VkBuffer) uniform_buffers);
PTK_OPTION(VkDescriptorPool) vk_create_descriptor_pool(VkDevice dev, uint32_t max_frames_in_flight);
PTK_OPTION(VkDescriptorSetList) vk_create_descriptor_sets(VkDevice dev, VkDescriptorSetLayout descriptor_set_layout, VkDescriptorPool descriptor_pool, PTK_LIST(VkBuffer) uniform_buffers, uint32_t max_frames_in_flight);
#endif // PTK_PTK_VK_DESCRIPTORS_H_

View file

@ -290,7 +290,7 @@ bool vk_init(GLFWwindow *window, const size_t width, const size_t height, const
m_index_buffer = index_buffer_stuff_opt.value.buffer;
m_index_buffer_memory = index_buffer_stuff_opt.value.buffer_memory;
PTK_OPTION(UniformBufferStuff) uniform_buffer_stuff_opt = vk_create_uniform_buffers(g_dev, g_physical_dev);
PTK_OPTION(UniformBufferStuff) uniform_buffer_stuff_opt = vk_create_uniform_buffers(g_dev, g_physical_dev, g_max_frames_in_flight);
if (!uniform_buffer_stuff_opt.exists) {
PTK_ERR("failed creating uniform buffers");
@ -301,7 +301,7 @@ bool vk_init(GLFWwindow *window, const size_t width, const size_t height, const
m_uniform_buffer_memories = uniform_buffer_stuff_opt.value.buffer_memories;
m_uniform_buffers_mapped = uniform_buffer_stuff_opt.value.buffers_mapped;
PTK_OPTION(VkDescriptorPool) descriptor_pool_opt = vk_create_descriptor_pool(g_dev);
PTK_OPTION(VkDescriptorPool) descriptor_pool_opt = vk_create_descriptor_pool(g_dev, g_max_frames_in_flight);
if (!descriptor_pool_opt.exists) {
PTK_ERR("failed creating descriptor pool");
@ -310,7 +310,7 @@ bool vk_init(GLFWwindow *window, const size_t width, const size_t height, const
m_descriptor_pool = descriptor_pool_opt.value;
PTK_OPTION(VkDescriptorSetList) descriptor_sets_opt = vk_create_descriptor_sets(g_dev, m_descriptor_set_layout, m_descriptor_pool, m_uniform_buffers);
PTK_OPTION(VkDescriptorSetList) descriptor_sets_opt = vk_create_descriptor_sets(g_dev, m_descriptor_set_layout, m_descriptor_pool, m_uniform_buffers, g_max_frames_in_flight);
if (!descriptor_sets_opt.exists) {
PTK_ERR("failed creating descriptor sets");
@ -319,7 +319,7 @@ bool vk_init(GLFWwindow *window, const size_t width, const size_t height, const
m_descriptor_sets = descriptor_sets_opt.value;
PTK_OPTION(VkCommandBufferList) command_buffers_opt = vk_allocate_command_buffers(g_dev, m_command_pool);
PTK_OPTION(VkCommandBufferList) command_buffers_opt = vk_allocate_command_buffers(g_dev, m_command_pool, g_max_frames_in_flight);
if (!command_buffers_opt.exists) {
PTK_ERR("failed allocating command buffers");
@ -328,7 +328,7 @@ bool vk_init(GLFWwindow *window, const size_t width, const size_t height, const
g_command_buffers = command_buffers_opt.value;
PTK_OPTION(SyncObjects) sync_objects_opt = vk_create_sync_objects(g_dev);
PTK_OPTION(SyncObjects) sync_objects_opt = vk_create_sync_objects(g_dev, g_max_frames_in_flight);
if (!sync_objects_opt.exists) {
PTK_ERR("failed creating sync objects");

View file

@ -3,11 +3,11 @@
#include <ptk_vk/init.h>
#include <ptk_vk/utils.h>
PTK_OPTION(SyncObjects) vk_create_sync_objects(VkDevice dev) {
PTK_OPTION(SyncObjects) vk_create_sync_objects(VkDevice dev, uint32_t max_frames_in_flight) {
SyncObjects ret = {
.image_available_semaphores = PTK_LIST_NEW(VkSemaphore, /* TODO: get rid of this */g_max_frames_in_flight),
.render_finished_semaphores = PTK_LIST_NEW(VkSemaphore, g_max_frames_in_flight),
.in_flight_fences = PTK_LIST_NEW(VkFence, g_max_frames_in_flight),
.image_available_semaphores = PTK_LIST_NEW(VkSemaphore, max_frames_in_flight),
.render_finished_semaphores = PTK_LIST_NEW(VkSemaphore, max_frames_in_flight),
.in_flight_fences = PTK_LIST_NEW(VkFence, max_frames_in_flight),
};
const VkSemaphoreCreateInfo semaphore_info = {
@ -16,7 +16,7 @@ PTK_OPTION(SyncObjects) vk_create_sync_objects(VkDevice dev) {
.flags = 0,
};
for (size_t i = 0; i < g_max_frames_in_flight; ++i) {
for (size_t i = 0; i < max_frames_in_flight; ++i) {
VK_TRY(PTK_OPTION_NONE(SyncObjects),
vkCreateSemaphore(dev, &semaphore_info, NULL, &ret.image_available_semaphores.data[i])
);

View file

@ -19,6 +19,6 @@ typedef struct {
PTK_OPTION_DEFINE(SyncObjects);
PTK_OPTION(SyncObjects) vk_create_sync_objects(VkDevice dev);
PTK_OPTION(SyncObjects) vk_create_sync_objects(VkDevice dev, uint32_t max_frames_in_flight);
#endif // PTK_PTK_VK_SYNC_OBJECTS_H_

View file

@ -7,16 +7,16 @@
#include <ptk_log.h>
PTK_OPTION(UniformBufferStuff) vk_create_uniform_buffers(VkDevice dev, VkPhysicalDevice physical_dev) {
PTK_OPTION(UniformBufferStuff) vk_create_uniform_buffers(VkDevice dev, VkPhysicalDevice physical_dev, uint32_t max_frames_in_flight) {
const VkDeviceSize buffer_size = sizeof(UniformBufferObject);
UniformBufferStuff ret = {
.buffers = PTK_LIST_NEW(VkBuffer, /* TODO: get rid of this */g_max_frames_in_flight),
.buffer_memories = PTK_LIST_NEW(VkDeviceMemory, g_max_frames_in_flight),
.buffers_mapped = PTK_LIST_NEW(voidptr, g_max_frames_in_flight),
.buffers = PTK_LIST_NEW(VkBuffer, max_frames_in_flight),
.buffer_memories = PTK_LIST_NEW(VkDeviceMemory, max_frames_in_flight),
.buffers_mapped = PTK_LIST_NEW(voidptr, max_frames_in_flight),
};
for (size_t i = 0; i < g_max_frames_in_flight; ++i) {
for (size_t i = 0; i < max_frames_in_flight; ++i) {
PTK_OPTION(BufferStuff) uniform_buffer_stuff_opt = create_buffer(
dev,
physical_dev,

View file

@ -27,6 +27,5 @@ typedef struct {
PTK_OPTION_DEFINE(UniformBufferStuff);
PTK_OPTION(UniformBufferStuff) vk_create_uniform_buffers(VkDevice dev, VkPhysicalDevice physical_dev);
PTK_OPTION(UniformBufferStuff) vk_create_uniform_buffers(VkDevice dev, VkPhysicalDevice physical_dev, uint32_t max_frames_in_flight);
#endif // PTK_PTK_VK_UNIFORM_BUFFERS_H_