main
1#include "gog_instance.h"
2#include <stdlib.h>
3
4gog_result gog_instance_audit(gog_instance* gog) {
5 vkEnumeratePhysicalDevices(gog->vk_instance, &gog->device_c, NULL);
6 VkPhysicalDevice* phys_devs = alloca(sizeof(VkPhysicalDevice) * gog->device_c);
7 vkEnumeratePhysicalDevices(gog->vk_instance, &gog->device_c, phys_devs);
8
9 gog->devices = malloc(sizeof(gog_device) * gog->device_c);
10
11 for (uint32_t i = 0; i < gog->device_c; i++) {
12 gog_device* d = &gog->devices[i];
13 d->physical = phys_devs[i];
14 d->logical = VK_NULL_HANDLE;
15
16 vkGetPhysicalDeviceProperties(d->physical, &d->props);
17 vkGetPhysicalDeviceFeatures(d->physical, &d->features);
18
19 VkPhysicalDeviceMemoryProperties mem;
20 vkGetPhysicalDeviceMemoryProperties(d->physical, &mem);
21 uint64_t vram_bytes = 0;
22 for (uint32_t m = 0; m < mem.memoryHeapCount; m++) {
23 if (mem.memoryHeaps[m].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT)
24 vram_bytes += mem.memoryHeaps[m].size;
25 }
26 d->specs.vram_mb = (uint32_t)(vram_bytes / (1024 * 1024));
27 d->specs.performance = d->props.limits.maxComputeWorkGroupInvocations +
28 ((d->props.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) ? 1000 : 0);
29
30 /* Find Queues */
31 uint32_t q_count = 0;
32 vkGetPhysicalDeviceQueueFamilyProperties(d->physical, &q_count, NULL);
33 VkQueueFamilyProperties* q_props = alloca(sizeof(VkQueueFamilyProperties) * q_count);
34 vkGetPhysicalDeviceQueueFamilyProperties(d->physical, &q_count, q_props);
35
36 for (uint32_t j = 0; j < q_count; j++) {
37 if (q_props[j].queueFlags & VK_QUEUE_GRAPHICS_BIT) d->queues.graphics = j;
38 if (q_props[j].queueFlags & VK_QUEUE_COMPUTE_BIT) d->queues.compute = j;
39
40 if (gog->vk_surface != VK_NULL_HANDLE) {
41 VkBool32 present = VK_FALSE;
42 vkGetPhysicalDeviceSurfaceSupportKHR(d->physical, j, gog->vk_surface, &present);
43 if (present) d->queues.present = j;
44 }
45 }
46 }
47 return GET_GOG_RESULT(GOG_SUCCES, 0);
48}
49
50void gog_instance_destroy(gog_instance* gog) {
51 if (!gog) return;
52 for (uint32_t i = 0; i < gog->device_c; i++) {
53 if (gog->devices[i].logical != VK_NULL_HANDLE) {
54 vkDeviceWaitIdle(gog->devices[i].logical);
55 vkDestroyDevice(gog->devices[i].logical, NULL);
56 }
57 }
58 free(gog->devices);
59}