Commit 6fddb6d
Changed files (6)
libgogvk/gog_instance.c
@@ -0,0 +1,59 @@
+#include "gog_instance.h"
+#include <stdlib.h>
+
+gog_result gog_instance_audit(gog_instance* gog) {
+ vkEnumeratePhysicalDevices(gog->vk_instance, &gog->device_c, NULL);
+ VkPhysicalDevice* phys_devs = alloca(sizeof(VkPhysicalDevice) * gog->device_c);
+ vkEnumeratePhysicalDevices(gog->vk_instance, &gog->device_c, phys_devs);
+
+ gog->devices = malloc(sizeof(gog_device) * gog->device_c);
+
+ for (uint32_t i = 0; i < gog->device_c; i++) {
+ gog_device* d = &gog->devices[i];
+ d->physical = phys_devs[i];
+ d->logical = VK_NULL_HANDLE;
+
+ vkGetPhysicalDeviceProperties(d->physical, &d->props);
+ vkGetPhysicalDeviceFeatures(d->physical, &d->features);
+
+ VkPhysicalDeviceMemoryProperties mem;
+ vkGetPhysicalDeviceMemoryProperties(d->physical, &mem);
+ uint64_t vram_bytes = 0;
+ for (uint32_t m = 0; m < mem.memoryHeapCount; m++) {
+ if (mem.memoryHeaps[m].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT)
+ vram_bytes += mem.memoryHeaps[m].size;
+ }
+ d->specs.vram_mb = (uint32_t)(vram_bytes / (1024 * 1024));
+ d->specs.performance = d->props.limits.maxComputeWorkGroupInvocations +
+ ((d->props.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) ? 1000 : 0);
+
+ /* Find Queues */
+ uint32_t q_count = 0;
+ vkGetPhysicalDeviceQueueFamilyProperties(d->physical, &q_count, NULL);
+ VkQueueFamilyProperties* q_props = alloca(sizeof(VkQueueFamilyProperties) * q_count);
+ vkGetPhysicalDeviceQueueFamilyProperties(d->physical, &q_count, q_props);
+
+ for (uint32_t j = 0; j < q_count; j++) {
+ if (q_props[j].queueFlags & VK_QUEUE_GRAPHICS_BIT) d->queues.graphics = j;
+ if (q_props[j].queueFlags & VK_QUEUE_COMPUTE_BIT) d->queues.compute = j;
+
+ if (gog->vk_surface != VK_NULL_HANDLE) {
+ VkBool32 present = VK_FALSE;
+ vkGetPhysicalDeviceSurfaceSupportKHR(d->physical, j, gog->vk_surface, &present);
+ if (present) d->queues.present = j;
+ }
+ }
+ }
+ return GET_GOG_RESULT(GOG_SUCCES, 0);
+}
+
+void gog_instance_destroy(gog_instance* gog) {
+ if (!gog) return;
+ for (uint32_t i = 0; i < gog->device_c; i++) {
+ if (gog->devices[i].logical != VK_NULL_HANDLE) {
+ vkDeviceWaitIdle(gog->devices[i].logical);
+ vkDestroyDevice(gog->devices[i].logical, NULL);
+ }
+ }
+ free(gog->devices);
+}
libgogvk/gog_instance.h
@@ -0,0 +1,39 @@
+#ifndef GOG_INSTANCE_H
+#define GOG_INSTANCE_H
+
+#include <vulkan/vulkan_core.h>
+#include "gogerr.h"
+
+typedef struct {
+ VkPhysicalDevice physical;
+ VkDevice logical;
+ struct {
+ uint32_t performance;
+ uint32_t vram_mb;
+ } specs;
+ struct {
+ uint32_t graphics;
+ uint32_t compute;
+ uint32_t present;
+ VkQueue graphics_q;
+ VkQueue compute_q;
+ VkQueue present_q;
+ } queues;
+
+ VkPhysicalDeviceProperties props;
+ VkPhysicalDeviceFeatures features;
+} gog_device;
+
+typedef struct {
+ VkInstance vk_instance;
+ VkSurfaceKHR vk_surface;
+
+ gog_device* devices;
+ uint32_t device_c;
+} gog_instance;
+
+gog_result gog_instance_audit(gog_instance* gog);
+gog_result gog_device_open(gog_device* dev, VkSurfaceKHR surface);
+void gog_instance_destroy(gog_instance* gog);
+
+#endif
libgogvk/gog_pipeline.h
@@ -121,8 +121,7 @@ typedef struct{
typedef struct {
- gog_pipeline_type type;
-
+ gog_canvas * canvas;
gog_descriptor_set* resource;
gog_push_constants* push_constants;
libgogvk.a
Binary file
main.c
@@ -4,23 +4,61 @@
#include <stdio.h>
#include <vulkan/vulkan_core.h>
#include <SDL2/SDL.h>
-#include "libgogvk/gogvid.h"
-#include "libgogvk/gogerr.h"
-
-int main()
-{
- SDL_Event e;
- gog_graphics_hndl gh;
- gog_graphics_init(&gh);
- while(1)
- {
- SDL_PollEvent(&e);
- if(e.type==SDL_QUIT)
- {
- break;
- }
+#include "libgogvk/gog_instance.h"
+#include <stdio.h>
+
+int main() {
+ VkApplicationInfo app_i = {
+ .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
+ .pApplicationName = "GOG Headless Test",
+ .apiVersion = VK_API_VERSION_1_3
+ };
+
+ VkInstanceCreateInfo inst_ci = {
+ .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
+ .pApplicationInfo = &app_i,
+ .enabledExtensionCount = 0, // No window extensions for now!
+ .ppEnabledExtensionNames = NULL
+ };
+
+ VkInstance vk_inst;
+ if (vkCreateInstance(&inst_ci, NULL, &vk_inst) != VK_SUCCESS) {
+ printf("Failed to create Vulkan Instance. Is the SDK installed?\n");
+ return -1;
+ }
+
+ gog_instance gog = {
+ .vk_instance = vk_inst,
+ .vk_surface = VK_NULL_HANDLE // No window target
+ };
+
+ gog_instance_audit(&gog);
+
+ printf("\n--- GOG HARDWARE AUDIT ---\n");
+ printf("Found %u device(s):\n", gog.device_c);
+
+ for (uint32_t i = 0; i < gog.device_c; i++) {
+ gog_device* d = &gog.devices[i];
+ printf("\n[%u] %s\n", i, d->props.deviceName);
+ printf(" Type: %s\n", (d->props.deviceType == 2) ? "Discrete" : "Integrated/Other");
+ printf(" Perf Metric: %u\n", d->specs.performance);
+ printf(" VRAM: %u MB\n", d->specs.vram_mb);
+ printf(" Graphics Q: Family %u\n", d->queues.graphics);
+ printf(" Compute Q: Family %u\n", d->queues.compute);
+ }
+
+ /* 5. Test Activation (Open the first one) */
+ if (gog.device_c > 0) {
+ printf("\nTesting Activation on Device [0]...\n");
+ // Note: Use your gog_device_open function here
+ // If success:
+ printf("Device [0] logical handle: %p\n", (void*)gog.devices[0].logical);
}
- vkDestroyInstance(gh.vk_instance, NULL);
- SDL_DestroyWindow(gh.sdl_window_p);
- SDL_Quit();
+
+ /* 6. Cleanup */
+ gog_instance_destroy(&gog);
+ vkDestroyInstance(vk_inst, NULL);
+
+ printf("\nTest Complete.\n");
+ return 0;
}
makefile
@@ -2,7 +2,7 @@ CC=gcc
CFLAGS=-Wall -Wextra -O2 -I./libgogvk `sdl2-config --cflags`
LIBS=-lvulkan `sdl2-config --libs`
-LIB_SRC=./libgogvk/gogvid.c ./libgogvk/gog_pipeline.c
+LIB_SRC=./libgogvk/gog_instance.c ./libgogvk/gog_pipeline.c
LIB_OBJ=$(LIB_SRC:.c=.o)
MAIN_SRC=main.c