mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-03 08:00:50 +00:00
vulkan: mingw support
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@119 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -1,12 +1,18 @@
|
|||||||
# $Id$
|
# $Id$
|
||||||
|
|
||||||
|
ifeq ($(TARGET),)
|
||||||
TARGET = $(shell uname -s)
|
TARGET = $(shell uname -s)
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CC),)
|
||||||
CC = gcc
|
CC = gcc
|
||||||
|
endif
|
||||||
|
|
||||||
CFLAGS = -Wall -Wextra -Iinclude
|
CFLAGS = -Wall -Wextra -Iinclude
|
||||||
LDFLAGS =
|
LDFLAGS =
|
||||||
LIBS =
|
LIBS =
|
||||||
ifeq (${DEBUG},1)
|
|
||||||
|
ifeq ($(DEBUG),1)
|
||||||
CFLAGS += -g
|
CFLAGS += -g
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -32,6 +38,7 @@ UNIX = 1
|
|||||||
VULKAN = 1
|
VULKAN = 1
|
||||||
else ifeq ($(TARGET),Windows)
|
else ifeq ($(TARGET),Windows)
|
||||||
WINDOWS = 1
|
WINDOWS = 1
|
||||||
|
VULKAN = 1
|
||||||
else
|
else
|
||||||
$(error Add your platform definition)
|
$(error Add your platform definition)
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -14,10 +14,11 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
struct _MwLL {
|
struct _MwLL {
|
||||||
HWND hWnd;
|
HINSTANCE hInstance;
|
||||||
HDC hDC;
|
HWND hWnd;
|
||||||
void* user;
|
HDC hDC;
|
||||||
int copy_buffer;
|
void* user;
|
||||||
|
int copy_buffer;
|
||||||
|
|
||||||
MwLLHandler handler;
|
MwLLHandler handler;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ MwLL MwLLCreate(MwLL parent, int x, int y, int width, int height) {
|
|||||||
|
|
||||||
r->copy_buffer = 1;
|
r->copy_buffer = 1;
|
||||||
r->hWnd = CreateWindow(parent == NULL ? "milsko" : "STATIC", "Milsko", parent == NULL ? (WS_OVERLAPPEDWINDOW) : (WS_CHILD | WS_VISIBLE), x, y, width, height, parent == NULL ? NULL : parent->hWnd, 0, wc.hInstance, NULL);
|
r->hWnd = CreateWindow(parent == NULL ? "milsko" : "STATIC", "Milsko", parent == NULL ? (WS_OVERLAPPEDWINDOW) : (WS_CHILD | WS_VISIBLE), x, y, width, height, parent == NULL ? NULL : parent->hWnd, 0, wc.hInstance, NULL);
|
||||||
|
r->hInstance = wc.hInstance;
|
||||||
|
|
||||||
u->ll = r;
|
u->ll = r;
|
||||||
if(parent == NULL) {
|
if(parent == NULL) {
|
||||||
|
|||||||
@@ -20,11 +20,22 @@
|
|||||||
#endif
|
#endif
|
||||||
#include <vulkan/vulkan.h>
|
#include <vulkan/vulkan.h>
|
||||||
#include <vulkan/vulkan_core.h>
|
#include <vulkan/vulkan_core.h>
|
||||||
#include <vulkan/vk_enum_string_helper.h>
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
#include <dlfcn.h>
|
||||||
#include <vulkan/vulkan_xlib.h>
|
#include <vulkan/vulkan_xlib.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#include <vulkan/vulkan_win32.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// MinGW's copy of vulkan string helpers is just straight up busted.
|
||||||
|
#ifndef __MINGW32__
|
||||||
|
#include <vulkan/vk_enum_string_helper.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "../external/stb_ds.h"
|
#include "../external/stb_ds.h"
|
||||||
@@ -36,12 +47,21 @@ MwVulkanConfig vulkan_config = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// convienence macro for handling vulkan errors
|
// convienence macro for handling vulkan errors
|
||||||
|
#ifndef __MINGW32__
|
||||||
#define VK_CMD(func) \
|
#define VK_CMD(func) \
|
||||||
vk_res = func; \
|
vk_res = func; \
|
||||||
if(vk_res != VK_SUCCESS) { \
|
if(vk_res != VK_SUCCESS) { \
|
||||||
setLastError("Vulkan error (%s:%d): %s\n", __FILE__, __LINE__, string_VkResult(vk_res)); \
|
setLastError("Vulkan error (%s:%d): %s\n", __FILE__, __LINE__, string_VkResult(vk_res)); \
|
||||||
return MwEerror; \
|
return MwEerror; \
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
#define VK_CMD(func) \
|
||||||
|
vk_res = func; \
|
||||||
|
if(vk_res != VK_SUCCESS) { \
|
||||||
|
setLastError("Vulkan error (%s:%d): (error %d)\n", __FILE__, __LINE__, vk_res); \
|
||||||
|
return MwEerror; \
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// convienence macro for loading a vulkan function pointer into memory
|
// convienence macro for loading a vulkan function pointer into memory
|
||||||
#define LOAD_VK_FUNCTION(name) \
|
#define LOAD_VK_FUNCTION(name) \
|
||||||
@@ -59,7 +79,11 @@ const char** enabledExtensions;
|
|||||||
const char** enabledLayers;
|
const char** enabledLayers;
|
||||||
|
|
||||||
typedef struct vulkan {
|
typedef struct vulkan {
|
||||||
void* vulkanLibrary;
|
#ifdef _WIN32
|
||||||
|
HMODULE vulkanLibrary;
|
||||||
|
#else
|
||||||
|
void* vulkanLibrary;
|
||||||
|
#endif
|
||||||
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
|
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
|
||||||
VkInstance vkInstance;
|
VkInstance vkInstance;
|
||||||
VkSurfaceKHR vkSurface;
|
VkSurfaceKHR vkSurface;
|
||||||
@@ -135,18 +159,28 @@ static MwErrorEnum vulkan_instance_setup(MwWidget handle, vulkan_t* o) {
|
|||||||
|
|
||||||
VkResult vk_res;
|
VkResult vk_res;
|
||||||
|
|
||||||
// TODO: support for whatever win32's equivalants to dlopen/dlsym are
|
// Load Vulkan and any other function pointers we need.
|
||||||
|
#ifndef _WIN32
|
||||||
o->vulkanLibrary = dlopen("libvulkan.so", RTLD_LAZY | RTLD_GLOBAL);
|
o->vulkanLibrary = dlopen("libvulkan.so", RTLD_LAZY | RTLD_GLOBAL);
|
||||||
o->vkGetInstanceProcAddr = dlsym(o->vulkanLibrary, "vkGetInstanceProcAddr");
|
o->vkGetInstanceProcAddr = dlsym(o->vulkanLibrary, "vkGetInstanceProcAddr");
|
||||||
VK_ASSERT(o->vkGetInstanceProcAddr);
|
VK_ASSERT(o->vkGetInstanceProcAddr);
|
||||||
|
|
||||||
// Load in any other function pointers we need.
|
|
||||||
_vkEnumerateInstanceExtensionProperties = dlsym(o->vulkanLibrary, "vkEnumerateInstanceExtensionProperties");
|
_vkEnumerateInstanceExtensionProperties = dlsym(o->vulkanLibrary, "vkEnumerateInstanceExtensionProperties");
|
||||||
VK_ASSERT(_vkEnumerateInstanceExtensionProperties);
|
VK_ASSERT(_vkEnumerateInstanceExtensionProperties);
|
||||||
_vkEnumerateInstanceLayerProperties = dlsym(o->vulkanLibrary, "vkEnumerateInstanceLayerProperties");
|
_vkEnumerateInstanceLayerProperties = dlsym(o->vulkanLibrary, "vkEnumerateInstanceLayerProperties");
|
||||||
VK_ASSERT(_vkEnumerateInstanceLayerProperties);
|
VK_ASSERT(_vkEnumerateInstanceLayerProperties);
|
||||||
_vkCreateInstance = dlsym(o->vulkanLibrary, "vkCreateInstance");
|
_vkCreateInstance = dlsym(o->vulkanLibrary, "vkCreateInstance");
|
||||||
VK_ASSERT(_vkCreateInstance);
|
VK_ASSERT(_vkCreateInstance);
|
||||||
|
#else
|
||||||
|
o->vulkanLibrary = LoadLibrary("vulkan-1.dll");
|
||||||
|
o->vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)(void*)GetProcAddress(o->vulkanLibrary, "vkGetInstanceProcAddr");
|
||||||
|
VK_ASSERT(o->vkGetInstanceProcAddr);
|
||||||
|
_vkEnumerateInstanceExtensionProperties = (PFN_vkEnumerateInstanceExtensionProperties)(void*)GetProcAddress(o->vulkanLibrary, "vkEnumerateInstanceExtensionProperties");
|
||||||
|
VK_ASSERT(_vkEnumerateInstanceExtensionProperties);
|
||||||
|
_vkEnumerateInstanceLayerProperties = (PFN_vkEnumerateInstanceLayerProperties)(void*)GetProcAddress(o->vulkanLibrary, "vkEnumerateInstanceLayerProperties");
|
||||||
|
VK_ASSERT(_vkEnumerateInstanceLayerProperties);
|
||||||
|
_vkCreateInstance = (PFN_vkCreateInstance)(void*)GetProcAddress(o->vulkanLibrary, "vkCreateInstance");
|
||||||
|
VK_ASSERT(_vkCreateInstance);
|
||||||
|
#endif
|
||||||
|
|
||||||
// setup enabled extensions
|
// setup enabled extensions
|
||||||
arrput(enabledExtensions, VK_KHR_SURFACE_EXTENSION_NAME);
|
arrput(enabledExtensions, VK_KHR_SURFACE_EXTENSION_NAME);
|
||||||
|
|||||||
Reference in New Issue
Block a user