From 066a1766c12fd42bf2191842f1857c2a320942dd Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Sun, 25 Oct 2020 16:38:35 +0200 Subject: [PATCH] initial commit --- .gitignore | 4 ++ Makefile | 21 +++++++ src/ggfx_vk.c | 181 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/gphgfx.h | 26 +++++++++ test.c | 11 ++++ 5 files changed, 243 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 src/ggfx_vk.c create mode 100644 src/gphgfx.h create mode 100644 test.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0932ecf --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.o +*.d +*.swp +test diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6060218 --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +src = $(wildcard src/*.c) test.c +obj = $(src:.c=.o) +dep = $(obj:.o=.d) +bin = test + +CFLAGS = -pedantic -Wall -g -MMD -Isrc +LDFLAGS = -lvulkan -lm + +$(bin): $(obj) + $(CC) -o $@ $(obj) $(LDFLAGS) + +-include $(dep) + +.PHONY: clean +clean: + rm -f $(obj) $(bin) + + +.PHONY: cleandep +cleandep: + rm -f $(dep) diff --git a/src/ggfx_vk.c b/src/ggfx_vk.c new file mode 100644 index 0000000..dd8b832 --- /dev/null +++ b/src/ggfx_vk.c @@ -0,0 +1,181 @@ +#include +#include +#include +#include +#include +#include "gphgfx.h" + +#define VER_MAJOR 0 +#define VER_MINOR 1 + +static const char *vk_strerror(VkResult res); + +static VkInstance vk; + +int ggfx_init(const char *appname, unsigned int flags) +{ + VkResult res; + VkInstanceCreateInfo iinf = {0}; + VkApplicationInfo appinf = {0}; + VkLayerProperties *lprop = 0; + VkExtensionProperties *iext; + uint32_t i, j, num_inst_layers, num_inst_ext, lprop_count, iext_count; + char **inst_layers = 0, **inst_ext = 0; + + static const char *debug_layers[] = { + "VK_LAYER_LUNARG_device_limits", + "VK_LAYER_LUNARG_image", + "VK_LAYER_LUNARG_object_tracker", + "VK_LAYER_LUNARG_core_validation", + "VK_LAYER_LUNARG_parameter_validation", + "VK_LAYER_LUNARG_swapchain", + "VK_LAYER_GOOGLE_threading", + "VK_LAYER_GOOGLE_unique_objects", + 0 + }; + static const char *extensions[] = { + "VK_KHR_surface", + "VK_KHR_xlib_surface", + 0 + }; + + vkEnumerateInstanceLayerProperties(&lprop_count, 0); + if(lprop_count > 0) { + if(!(lprop = malloc(lprop_count * sizeof *lprop))) { + perror("ggfx_init: failed to allocate layer property list"); + return -1; + } + vkEnumerateInstanceLayerProperties(&lprop_count, lprop); + + if(flags & GGFX_INIT_DEBUG) { + if(!(inst_layers = malloc(lprop_count * sizeof *inst_layers))) { + perror("ggfx_init: failed to allocate layer properties"); + return -1; + } + } + + printf("%d available instance layers\n", lprop_count); + num_inst_layers = 0; + for(i=0; i 0) { + if(!(iext = malloc(iext_count * sizeof *iext))) { + perror("ggfx_init: failed to allocate instance extensions property list"); + return -1; + } + vkEnumerateInstanceExtensionProperties(0, &iext_count, iext); + + if(!(inst_ext = malloc(iext_count * sizeof *inst_ext))) { + perror("ggfx_init: failed to allocate instance extension properties"); + return -1; + } + + printf("%d available instance extensions\n", iext_count); + num_inst_ext = 0; + for(i=0; i