adding surface creation
This commit is contained in:
@@ -1,45 +0,0 @@
|
|||||||
name: Windows
|
|
||||||
|
|
||||||
on:
|
|
||||||
repository_dispatch:
|
|
||||||
types: [create-pull-request]
|
|
||||||
pull_request:
|
|
||||||
push:
|
|
||||||
paths-ignore:
|
|
||||||
- '.gitignore'
|
|
||||||
- 'LICENSE'
|
|
||||||
- 'README.md'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [windows-x86_64, macos-x86_64, ubuntu-latest]
|
|
||||||
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
if: "!contains(github.event.head_commit.message, 'ci skip')"
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Get current date as package key
|
|
||||||
id: cache_key
|
|
||||||
shell: bash
|
|
||||||
run: echo "key=$(date +'%W')" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v6
|
|
||||||
|
|
||||||
- name: Set xmake env
|
|
||||||
run: echo "XMAKE_GLOBALDIR=${{ runner.workspace }}/xmake-global" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Setup xmake
|
|
||||||
uses: xmake-io/github-action-setup-xmake@v1
|
|
||||||
with:
|
|
||||||
xmake-version: branch@master
|
|
||||||
actions-cache-folder: .xmake-cache-W${{ steps.cache_key.outputs.key }}
|
|
||||||
|
|
||||||
- name: Update xmake repository
|
|
||||||
run: cd sandbox && xmake repo --update
|
|
||||||
|
|
||||||
- name: Build test
|
|
||||||
run: cd sandbox && xmake --yes
|
|
||||||
211
kvf.h
211
kvf.h
@@ -55,6 +55,46 @@
|
|||||||
#define VK_NO_PROTOTYPES
|
#define VK_NO_PROTOTYPES
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef KVF_NO_KHR
|
||||||
|
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||||
|
#include <vulkan/vulkan_android.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
||||||
|
#include <vulkan/vulkan_wayland.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
||||||
|
typedef struct HINSTANCE__* HINSTANCE;
|
||||||
|
typedef struct HWND__* HWND;
|
||||||
|
typedef struct HMONITOR__* HMONITOR;
|
||||||
|
typedef void* HANDLE;
|
||||||
|
typedef /*_Null_terminated_*/ const wchar_t* LPCWSTR;
|
||||||
|
typedef unsigned long DWORD;
|
||||||
|
typedef struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES;
|
||||||
|
#include <vulkan/vulkan_win32.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef VK_USE_PLATFORM_XCB_KHR
|
||||||
|
struct xcb_connection_t;
|
||||||
|
typedef uint32_t xcb_window_t;
|
||||||
|
typedef uint32_t xcb_visualid_t;
|
||||||
|
#include <vulkan/vulkan_xcb.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef VK_USE_PLATFORM_METAL_EXT
|
||||||
|
#include <vulkan/vulkan_metal.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
||||||
|
typedef struct _XDisplay Display;
|
||||||
|
typedef unsigned long XID;
|
||||||
|
typedef XID Window;
|
||||||
|
typedef unsigned long VisualID;
|
||||||
|
#include <vulkan/vulkan_xlib.h>
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <vulkan/vulkan_core.h>
|
#include <vulkan/vulkan_core.h>
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@@ -82,6 +122,18 @@ typedef enum
|
|||||||
KVF_IMAGE_OTHER = 4,
|
KVF_IMAGE_OTHER = 4,
|
||||||
} KvfImageType;
|
} KvfImageType;
|
||||||
|
|
||||||
|
#ifndef KVF_NO_KHR
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
KVF_SURFACE_ANDROID = 0,
|
||||||
|
KVF_SURFACE_XLIB = 1,
|
||||||
|
KVF_SURFACE_XCB = 2,
|
||||||
|
KVF_SURFACE_WAYLAND = 3,
|
||||||
|
KVF_SURFACE_WINDOWS = 4,
|
||||||
|
KVF_SURFACE_METAL = 5,
|
||||||
|
} KvfSurfaceType;
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef void (*KvfErrorCallback)(const char* message);
|
typedef void (*KvfErrorCallback)(const char* message);
|
||||||
|
|
||||||
#ifdef KVF_IMPL_VK_NO_PROTOTYPES
|
#ifdef KVF_IMPL_VK_NO_PROTOTYPES
|
||||||
@@ -148,6 +200,33 @@ void kvfDestroySemaphore(VkDevice device, VkSemaphore semaphore);
|
|||||||
uint32_t kvfGetSwapchainMinImagesCount(VkSwapchainKHR swapchain);
|
uint32_t kvfGetSwapchainMinImagesCount(VkSwapchainKHR swapchain);
|
||||||
VkExtent2D kvfGetSwapchainImagesSize(VkSwapchainKHR swapchain);
|
VkExtent2D kvfGetSwapchainImagesSize(VkSwapchainKHR swapchain);
|
||||||
void kvfDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain);
|
void kvfDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For Windows:
|
||||||
|
* - instance_handle -> HINSTANCE
|
||||||
|
* - window_handle -> HWND window handle
|
||||||
|
*
|
||||||
|
* For Wayland:
|
||||||
|
* - instance_handle -> wl_display
|
||||||
|
* - window_handle -> wl_surface
|
||||||
|
*
|
||||||
|
* For XLIB:
|
||||||
|
* - instance_handle -> Display
|
||||||
|
* - window_handle -> Window
|
||||||
|
*
|
||||||
|
* For XCB:
|
||||||
|
* - instance_handle -> xcb_connection_t
|
||||||
|
* - window_handle -> xcb_window_t
|
||||||
|
*
|
||||||
|
* For Metal:
|
||||||
|
* - instance_handle -> ignored
|
||||||
|
* - window_handle -> CAMetalLayer
|
||||||
|
*
|
||||||
|
* For Android:
|
||||||
|
* - instance_handle -> ignored
|
||||||
|
* - window_handle -> ANativeWindow
|
||||||
|
*/
|
||||||
|
VkSurfaceKHR kvfCreateSurfaceKHR(VkInstance instance, KvfSurfaceType type, void* instance_handle, void* window_handle);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
VkImage kvfCreateImage(VkDevice device, uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, KvfImageType type);
|
VkImage kvfCreateImage(VkDevice device, uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, KvfImageType type);
|
||||||
@@ -333,6 +412,46 @@ int32_t kvfFindMemoryType(VkPhysicalDevice physical_device, uint32_t type_filter
|
|||||||
KVF_DEFINE_VULKAN_FUNCTION_PROTOTYPE(vkDestroySwapchainKHR);
|
KVF_DEFINE_VULKAN_FUNCTION_PROTOTYPE(vkDestroySwapchainKHR);
|
||||||
KVF_DEFINE_VULKAN_FUNCTION_PROTOTYPE(vkGetSwapchainImagesKHR);
|
KVF_DEFINE_VULKAN_FUNCTION_PROTOTYPE(vkGetSwapchainImagesKHR);
|
||||||
KVF_DEFINE_VULKAN_FUNCTION_PROTOTYPE(vkQueuePresentKHR);
|
KVF_DEFINE_VULKAN_FUNCTION_PROTOTYPE(vkQueuePresentKHR);
|
||||||
|
|
||||||
|
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||||
|
#ifdef VK_KHR_android_surface
|
||||||
|
AK_VULKAN_INSTANCE_FUNCTION(vkCreateAndroidSurfaceKHR)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef VK_USE_PLATFORM_XCB_KHR
|
||||||
|
#ifdef VK_KHR_xcb_surface
|
||||||
|
KVF_DEFINE_VULKAN_FUNCTION_PROTOTYPE(vkCreateXcbSurfaceKHR)
|
||||||
|
KVF_DEFINE_VULKAN_FUNCTION_PROTOTYPE(vkGetPhysicalDeviceXcbPresentationSupportKHR)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
||||||
|
#ifdef VK_KHR_xlib_surface
|
||||||
|
KVF_DEFINE_VULKAN_FUNCTION_PROTOTYPE(vkCreateXlibSurfaceKHR)
|
||||||
|
KVF_DEFINE_VULKAN_FUNCTION_PROTOTYPE(vkGetPhysicalDeviceXlibPresentationSupportKHR)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
||||||
|
#ifdef VK_KHR_wayland_surface
|
||||||
|
KVF_DEFINE_VULKAN_FUNCTION_PROTOTYPE(vkCreateWaylandSurfaceKHR)
|
||||||
|
KVF_DEFINE_VULKAN_FUNCTION_PROTOTYPE(vkGetPhysicalDeviceWaylandPresentationSupportKHR)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
||||||
|
#ifdef VK_KHR_win32_surface
|
||||||
|
KVF_DEFINE_VULKAN_FUNCTION_PROTOTYPE(vkCreateWin32SurfaceKHR)
|
||||||
|
KVF_DEFINE_VULKAN_FUNCTION_PROTOTYPE(vkGetPhysicalDeviceWin32PresentationSupportKHR)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef VK_USE_PLATFORM_METAL_EXT
|
||||||
|
#ifdef VK_EXT_metal_surface
|
||||||
|
KVF_DEFINE_VULKAN_FUNCTION_PROTOTYPE(vkCreateMetalSurfaceEXT)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
@@ -2093,6 +2212,98 @@ void kvfDestroySemaphore(VkDevice device, VkSemaphore semaphore)
|
|||||||
KVF_ASSERT(device != VK_NULL_HANDLE);
|
KVF_ASSERT(device != VK_NULL_HANDLE);
|
||||||
__kvfDestroySwapchain(device, swapchain);
|
__kvfDestroySwapchain(device, swapchain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VkSurfaceKHR kvfCreateSurfaceKHR(VkInstance instance, KvfSurfaceType type, void* instance_handle, void* window_handle)
|
||||||
|
{
|
||||||
|
VkSurfaceKHR surface = VK_NULL_HANDLE;
|
||||||
|
switch(type)
|
||||||
|
{
|
||||||
|
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||||
|
case: KVF_SURFACE_ANDROID:
|
||||||
|
{
|
||||||
|
VkAndroidSurfaceCreateInfoKHR create_info = {0};
|
||||||
|
create_info.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
|
||||||
|
create_info.pNext = nullptr;
|
||||||
|
create_info.flags = 0;
|
||||||
|
create_info.window = (ANativeWindow*)window_handle;
|
||||||
|
kvfCheckVk(KVF_GET_DEVICE_FUNCTION(vkCreateAndroidSurfaceKHR)(instance, &create_info, NULL, &surface));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
||||||
|
case: KVF_SURFACE_XLIB:
|
||||||
|
{
|
||||||
|
VkXlibSurfaceCreateInfoKHR create_info = {0};
|
||||||
|
create_info.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR;
|
||||||
|
create_info.pNext = nullptr;
|
||||||
|
create_info.flags = 0;
|
||||||
|
create_info.dpy = (Display*)instance_handle;
|
||||||
|
create_info.window = *(Window*)window_handle;
|
||||||
|
kvfCheckVk(KVF_GET_DEVICE_FUNCTION(vkCreateXlibSurfaceKHR)(instance, &create_info, NULL, &surface));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef VK_USE_PLATFORM_XCB_KHR
|
||||||
|
case: KVF_SURFACE_XCB:
|
||||||
|
{
|
||||||
|
VkXcbSurfaceCreateInfoKHR create_info = {0};
|
||||||
|
create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
|
||||||
|
create_info.pNext = nullptr;
|
||||||
|
create_info.flags = 0;
|
||||||
|
create_info.connection = (xcb_connection_t*)instance_handle;
|
||||||
|
create_info.window = (*xcb_window_t*)window_handle;
|
||||||
|
kvfCheckVk(KVF_GET_DEVICE_FUNCTION(vkCreateXcbSurfaceKHR)(instance, &create_info, NULL, &surface));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
||||||
|
case: KVF_SURFACE_WAYLAND:
|
||||||
|
{
|
||||||
|
VkWaylandSurfaceCreateInfoKHR create_info = {0};
|
||||||
|
create_info.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR;
|
||||||
|
create_info.pNext = nullptr;
|
||||||
|
create_info.flags = 0;
|
||||||
|
create_info.display = (wl_display*)instance_handle;
|
||||||
|
create_info.surface = (wl_surface*)window_handle;
|
||||||
|
kvfCheckVk(KVF_GET_DEVICE_FUNCTION(vkCreateWaylandSurfaceKHR)(instance, &create_info, NULL, &surface));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
||||||
|
case: KVF_SURFACE_WINDOWS:
|
||||||
|
{
|
||||||
|
VkWin32SurfaceCreateInfoKHR create_info = {0};
|
||||||
|
create_info.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
|
||||||
|
create_info.pNext = nullptr;
|
||||||
|
create_info.flags = 0;
|
||||||
|
create_info.hinstance = (HINSTANCE)instance_handle;
|
||||||
|
create_info.hwnd = (HWND)window_handle;
|
||||||
|
kvfCheckVk(KVF_GET_DEVICE_FUNCTION(vkCreateWin32SurfaceKHR)(instance, &create_info, NULL, &surface));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef VK_USE_PLATFORM_METAL_EXT
|
||||||
|
case: KVF_SURFACE_METAL:
|
||||||
|
{
|
||||||
|
VkMetalSurfaceCreateInfoEXT create_info = {0};
|
||||||
|
create_info.sType = VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_KHR;
|
||||||
|
create_info.pNext = nullptr;
|
||||||
|
create_info.flags = 0;
|
||||||
|
create_info.pLayer = (CAMetalLayer*)window_handle;
|
||||||
|
kvfCheckVk(KVF_GET_DEVICE_FUNCTION(vkCreateMetalSurfaceEXT)(instance, &create_info, NULL, &surface));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
return surface;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
VkImage kvfCreateImage(VkDevice device, uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, KvfImageType type)
|
VkImage kvfCreateImage(VkDevice device, uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, KvfImageType type)
|
||||||
|
|||||||
10
sandbox/Makefile
git.filemode.normal_file
10
sandbox/Makefile
git.filemode.normal_file
@@ -0,0 +1,10 @@
|
|||||||
|
NAME = ./test
|
||||||
|
|
||||||
|
CC = clang
|
||||||
|
|
||||||
|
all : $(NAME)
|
||||||
|
|
||||||
|
$(NAME):
|
||||||
|
$(CC) -o $(NAME) main.c -lvulkan -lSDL2 -g
|
||||||
|
|
||||||
|
.PHONY: all
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
add_requires("libsdl2", { configs = { sdlmain = false } })
|
|
||||||
add_requires("vulkan-headers")
|
|
||||||
|
|
||||||
target("test")
|
|
||||||
set_kind("binary")
|
|
||||||
add_linkdirs("./")
|
|
||||||
add_files("main.c", { languages = "c99" })
|
|
||||||
add_defines("SDL_MAIN_HANDLED")
|
|
||||||
add_packages("libsdl2", "vulkan-headers")
|
|
||||||
add_syslinks("vulkan")
|
|
||||||
target_end()
|
|
||||||
Reference in New Issue
Block a user