more usage of PTK_LIST and PTK_ARRAY

This commit is contained in:
jacekpoz 2024-09-08 12:53:37 +02:00
parent 59f4ed89d4
commit 5c8a21b375
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8
2 changed files with 25 additions and 31 deletions

View file

@ -15,4 +15,10 @@
.size = sizeof((T []) __VA_ARGS__) / sizeof(T),\
}
#define PTK_ARRAY_EMPTY(T) \
(PTK_ARRAY(T)){\
.data = NULL,\
.size = 0,\
}
#endif // PTK_PTK_ARRAY_H_

View file

@ -25,6 +25,13 @@ PTK_ARRAY_DEFINE(VkVertexInputAttributeDescription);
PTK_LIST_DEFINE(VkExtensionProperties);
PTK_LIST_DEFINE(VkQueueFamilyProperties);
PTK_OPTION_DEFINE(VkShaderModule);
PTK_LIST_DEFINE(VkBuffer);
PTK_LIST_DEFINE(VkDeviceMemory);
typedef void *voidptr;
PTK_LIST_DEFINE(voidptr);
PTK_LIST_DEFINE(VkDescriptorSet);
typedef const char *constcharptr;
PTK_ARRAY_DEFINE(constcharptr);
#ifdef DEBUG
PTK_LIST_DEFINE(VkLayerProperties);
@ -118,11 +125,6 @@ static PTK_ARRAY(VkVertexInputAttributeDescription) m_vertex_attribute_descripti
static VkBuffer m_vertex_buffer;
static VkDeviceMemory m_vertex_buffer_memory;
PTK_LIST_DEFINE(VkBuffer);
PTK_LIST_DEFINE(VkDeviceMemory);
typedef void *voidptr;
PTK_LIST_DEFINE(voidptr);
typedef struct {
PtkSize initial_window_size;
PtkSize window_size;
@ -134,18 +136,15 @@ static PTK_LIST(VkBuffer) m_uniform_buffers;
static PTK_LIST(VkDeviceMemory) m_uniform_buffers_memory;
static PTK_LIST(voidptr) m_uniform_buffers_mapped;
PTK_LIST_DEFINE(VkDescriptorSet);
static VkDescriptorPool m_descriptor_pool;
static PTK_LIST(VkDescriptorSet) m_descriptor_sets;
#ifdef DEBUG
static const uint32_t g_validation_layer_count = 1;
static const char * const g_validation_layers[] = {
static const PTK_ARRAY(constcharptr) m_validation_layers = PTK_ARRAY_NEW(constcharptr, {
"VK_LAYER_KHRONOS_validation"
};
});
bool check_validation_layers(const char * const *validation_layers, const uint32_t validation_layer_count) {
bool check_validation_layers(const PTK_ARRAY(constcharptr) validation_layers) {
PTK_LIST(VkLayerProperties) available_layers;
vkEnumerateInstanceLayerProperties(&available_layers.allocated, NULL);
@ -154,8 +153,8 @@ bool check_validation_layers(const char * const *validation_layers, const uint32
vkEnumerateInstanceLayerProperties(&available_layers.allocated, available_layers.data);
PTK_LIST_FILLED(available_layers);
for (size_t i = 0; i < validation_layer_count; ++i) {
const char *layer_name = validation_layers[i];
for (size_t i = 0; i < validation_layers.size; ++i) {
const char *layer_name = validation_layers.data[i];
bool layer_found = false;
@ -173,19 +172,16 @@ bool check_validation_layers(const char * const *validation_layers, const uint32
return true;
}
#else
static const PTK_ARRAY(constcharptr) m_validation_layers = PTK_ARRAY_EMPTY(constcharptr);
#endif
bool create_vk_instance(const char *title, const PtkVersion version) {
#ifdef DEBUG
if (!check_validation_layers(g_validation_layers, g_validation_layer_count)) {
if (!check_validation_layers(m_validation_layers)) {
PTK_ERR("couldn't find requested validation layer");
return false;
}
const uint32_t enabled_layer_count = g_validation_layer_count;
const char * const *enabled_layer_names = g_validation_layers;
#else
const uint32_t enabled_layer_count = 0;
const char * const *enabled_layer_names = NULL;
#endif
uint32_t extension_count = 0;
@ -206,8 +202,8 @@ bool create_vk_instance(const char *title, const PtkVersion version) {
.engineVersion = VK_MAKE_API_VERSION(0, PTK_VERSION_MAJOR, PTK_VERSION_MINOR, PTK_VERSION_PATCH),
.apiVersion = VK_API_VERSION_1_3,
},
.enabledLayerCount = enabled_layer_count,
.ppEnabledLayerNames = enabled_layer_names,
.enabledLayerCount = m_validation_layers.size,
.ppEnabledLayerNames = m_validation_layers.data,
.enabledExtensionCount = extension_count,
.ppEnabledExtensionNames = extension_names,
},
@ -458,14 +454,6 @@ bool create_logical_dev(void) {
};
}
#ifdef DEBUG
const uint32_t enabled_layer_count = g_validation_layer_count;
const char * const *enabled_layer_names = g_validation_layers;
#else
const uint32_t enabled_layer_count = 0;
const char * const *enabled_layer_names = NULL;
#endif
VK_TRY(false,
vkCreateDevice(
m_physical_dev,
@ -475,8 +463,8 @@ bool create_logical_dev(void) {
.flags = 0,
.queueCreateInfoCount = m_queue_family_count,
.pQueueCreateInfos = queue_create_infos,
.enabledLayerCount = enabled_layer_count,
.ppEnabledLayerNames = enabled_layer_names,
.enabledLayerCount = m_validation_layers.size,
.ppEnabledLayerNames = m_validation_layers.data,
.enabledExtensionCount = m_device_extension_count,
.ppEnabledExtensionNames = m_device_extensions,
.pEnabledFeatures = &(VkPhysicalDeviceFeatures){0},