allow debugger to be created before the instance and attached to it

later
This commit is contained in:
Greg Wells
2025-05-25 07:32:05 -04:00
parent 5b6360f26f
commit 6c4bd6a572
7 changed files with 55 additions and 22 deletions

View File

@@ -114,6 +114,9 @@ gnReturnCode gnCreateDebuggerFn(gnDebugger* debugger, gnInstance* instance, cons
}
}
instance->instance->instanceMessageCount = 0;
free(instance->instance->instanceMessages);
const char* layers[] = {
"VK_LAYER_KHRONOS_validation"
};
@@ -154,5 +157,5 @@ gnReturnCode gnCreateDebuggerFn(gnDebugger* debugger, gnInstance* instance, cons
}
void gnDestroyDebuggerFn(gnDebugger* debugger) {
vk_destroyDebugUtilsMessengerEXT(*debugger->debugger->instance, debugger->debugger->debugMessenger, NULL);
vk_destroyDebugUtilsMessengerEXT(debugger->instance->instance->vk_instance, debugger->debugger->debugMessenger, NULL);
}

View File

@@ -4,7 +4,6 @@
typedef struct gnPlatformDebugger_t {
VkDebugUtilsMessengerEXT debugMessenger;
VkInstance* instance;
} gnPlatformDebugger;
#ifdef __cplusplus

View File

@@ -30,18 +30,25 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL vk_debuggerDebugCallback(
}
gnInstance* instance = (gnInstance*)pUserData;
instance->instance->instanceMessageCount++;
if (instance->instance->instanceMessageCount == 1) {
instance->instance->instanceMessages = malloc(sizeof(struct gnInstanceMessage) * instance->instance->instanceMessageCount);
if (instance->debugger) {
instance->debugger->info.callback(
severity, type, data, instance->debugger->info.userData
);
} else {
instance->instance->instanceMessageCount++;
if (instance->instance->instanceMessageCount == 1) {
instance->instance->instanceMessages = malloc(sizeof(struct gnInstanceMessage) * instance->instance->instanceMessageCount);
}
else {
instance->instance->instanceMessages = realloc(instance->instance->instanceMessages, sizeof(struct gnInstanceMessage) * instance->instance->instanceMessageCount);
}
instance->instance->instanceMessages[instance->instance->instanceMessageCount - 1] = (struct gnInstanceMessage){
.data = data,
.severity = severity,
.type = type
};
}
else {
instance->instance->instanceMessages = realloc(instance->instance->instanceMessages, sizeof(struct gnInstanceMessage) * instance->instance->instanceMessageCount);
}
instance->instance->instanceMessages[instance->instance->instanceMessageCount - 1] = (struct gnInstanceMessage){
.data = data,
.severity = severity,
.type = type
};
return VK_FALSE;
}