mirror of
https://github.com/Yours3lf/rpi-vk-driver.git
synced 2025-02-26 23:54:17 +01:00
finally the trampoline walking works
can successfully call my custom extension TODO: need to make the assembly loader work too
This commit is contained in:
parent
2d8132011e
commit
1e9d774483
@ -4,6 +4,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define VK_NO_PROTOTYPES
|
||||||
#include <vulkan/vulkan.h>
|
#include <vulkan/vulkan.h>
|
||||||
|
|
||||||
VKAPI_ATTR VkResult VKAPI_CALL rpi_vkCreateInstance(
|
VKAPI_ATTR VkResult VKAPI_CALL rpi_vkCreateInstance(
|
||||||
@ -948,6 +949,40 @@ VKAPI_ATTR void VKAPI_CALL rpi_vkGetDescriptorSetLayoutSupport(
|
|||||||
const VkDescriptorSetLayoutCreateInfo* pCreateInfo,
|
const VkDescriptorSetLayoutCreateInfo* pCreateInfo,
|
||||||
VkDescriptorSetLayoutSupport* pSupport);
|
VkDescriptorSetLayoutSupport* pSupport);
|
||||||
|
|
||||||
|
VKAPI_ATTR void VKAPI_CALL rpi_vkDestroySurfaceKHR(
|
||||||
|
VkInstance instance,
|
||||||
|
VkSurfaceKHR surface,
|
||||||
|
const VkAllocationCallbacks* pAllocator);
|
||||||
|
|
||||||
|
VKAPI_ATTR VkResult VKAPI_CALL rpi_vkCreateSwapchainKHR(
|
||||||
|
VkDevice device,
|
||||||
|
const VkSwapchainCreateInfoKHR* pCreateInfo,
|
||||||
|
const VkAllocationCallbacks* pAllocator,
|
||||||
|
VkSwapchainKHR* pSwapchain);
|
||||||
|
|
||||||
|
VKAPI_ATTR VkResult VKAPI_CALL rpi_vkGetPhysicalDeviceSurfaceSupportKHR(
|
||||||
|
VkPhysicalDevice physicalDevice,
|
||||||
|
uint32_t queueFamilyIndex,
|
||||||
|
VkSurfaceKHR surface,
|
||||||
|
VkBool32* pSupported);
|
||||||
|
|
||||||
|
VKAPI_ATTR VkResult VKAPI_CALL rpi_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
|
||||||
|
VkPhysicalDevice physicalDevice,
|
||||||
|
VkSurfaceKHR surface,
|
||||||
|
VkSurfaceCapabilitiesKHR* pSurfaceCapabilities);
|
||||||
|
|
||||||
|
VKAPI_ATTR VkResult VKAPI_CALL rpi_vkGetPhysicalDeviceSurfaceFormatsKHR(
|
||||||
|
VkPhysicalDevice physicalDevice,
|
||||||
|
VkSurfaceKHR surface,
|
||||||
|
uint32_t* pSurfaceFormatCount,
|
||||||
|
VkSurfaceFormatKHR* pSurfaceFormats);
|
||||||
|
|
||||||
|
VKAPI_ATTR VkResult VKAPI_CALL rpi_vkGetPhysicalDeviceSurfacePresentModesKHR(
|
||||||
|
VkPhysicalDevice physicalDevice,
|
||||||
|
VkSurfaceKHR surface,
|
||||||
|
uint32_t* pPresentModeCount,
|
||||||
|
VkPresentModeKHR* pPresentModes);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -380,6 +380,13 @@ VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL rpi_vkGetInstanceProcAddr(
|
|||||||
RETFUNC(vkGetDescriptorSetLayoutSupport);
|
RETFUNC(vkGetDescriptorSetLayoutSupport);
|
||||||
RETFUNC(vkBindBufferMemory2);
|
RETFUNC(vkBindBufferMemory2);
|
||||||
|
|
||||||
|
RETFUNC(vkDestroySurfaceKHR);
|
||||||
|
RETFUNC(vkCreateSwapchainKHR);
|
||||||
|
RETFUNC(vkGetPhysicalDeviceSurfaceSupportKHR);
|
||||||
|
RETFUNC(vkGetPhysicalDeviceSurfaceCapabilitiesKHR);
|
||||||
|
RETFUNC(vkGetPhysicalDeviceSurfaceFormatsKHR);
|
||||||
|
RETFUNC(vkGetPhysicalDeviceSurfacePresentModesKHR);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#define VK_NO_PROTOTYPES
|
||||||
#include <vulkan/vulkan.h>
|
#include <vulkan/vulkan.h>
|
||||||
|
|
||||||
//https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#features-limits
|
//https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#features-limits
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#define VK_NO_PROTOTYPES
|
||||||
#include <vulkan/vulkan.h>
|
#include <vulkan/vulkan.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -8,15 +9,35 @@ extern "C" {
|
|||||||
|
|
||||||
typedef VkResult (*PFN_vkCreateRpiSurfaceEXT)(
|
typedef VkResult (*PFN_vkCreateRpiSurfaceEXT)(
|
||||||
VkPhysicalDevice physicalDevice);
|
VkPhysicalDevice physicalDevice);
|
||||||
typedef VkResult (*PFN__vkCreateShaderModuleFromRpiAssemblyEXT)(
|
typedef VkResult (*PFN_vkCreateShaderModuleFromRpiAssemblyEXT)(
|
||||||
VkPhysicalDevice physicalDevice);
|
VkPhysicalDevice physicalDevice);
|
||||||
|
|
||||||
|
// Sooo we're not really getting the REAL VkPhysicalDevice from the Loader
|
||||||
|
// But rather a Trampoline object that points to a Terminator that finally points to
|
||||||
|
// The real object
|
||||||
|
// Therefore if we would like to pass on information in our VkPhysicalDevice object
|
||||||
|
// We need to walk this chain...
|
||||||
typedef struct VkRpiPhysicalDevice
|
typedef struct VkRpiPhysicalDevice
|
||||||
{
|
{
|
||||||
void* dummy;
|
uintptr_t loaderData;
|
||||||
void* customData;
|
uintptr_t customData;
|
||||||
} VkRpiPhysicalDevice;
|
} VkRpiPhysicalDevice;
|
||||||
|
|
||||||
|
typedef struct LoaderTerminator
|
||||||
|
{
|
||||||
|
uintptr_t a;
|
||||||
|
uintptr_t b;
|
||||||
|
uint8_t c;
|
||||||
|
VkRpiPhysicalDevice* physicalDevice;
|
||||||
|
} LoaderTerminator;
|
||||||
|
|
||||||
|
typedef struct LoaderTrampoline
|
||||||
|
{
|
||||||
|
uintptr_t a;
|
||||||
|
uintptr_t b;
|
||||||
|
LoaderTerminator* loaderTerminator;
|
||||||
|
} LoaderTrampoline;
|
||||||
|
|
||||||
//we need something like the other platforms to create surfaces on the RPI
|
//we need something like the other platforms to create surfaces on the RPI
|
||||||
//so I created this little "extension"
|
//so I created this little "extension"
|
||||||
//full spec in this file ;)
|
//full spec in this file ;)
|
||||||
|
@ -9,6 +9,25 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Implementation of our RPI specific "extension"
|
||||||
|
*/
|
||||||
|
VkResult rpi_vkCreateRpiSurfaceEXT(
|
||||||
|
VkPhysicalDevice physicalDevice)
|
||||||
|
{
|
||||||
|
assert(physicalDevice);
|
||||||
|
|
||||||
|
//TODO use allocator!
|
||||||
|
|
||||||
|
_physicalDevice* ptr = physicalDevice;
|
||||||
|
VkSurfaceKHR* surfPtr = ptr->customData;
|
||||||
|
VkSurfaceKHR surfRes = (VkSurfaceKHR)modeset_create(controlFd);
|
||||||
|
|
||||||
|
*surfPtr = surfRes;
|
||||||
|
|
||||||
|
return VK_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
//TODO collect shader performance data
|
//TODO collect shader performance data
|
||||||
//eg number of texture samples etc.
|
//eg number of texture samples etc.
|
||||||
//TODO check if shader has flow control and make sure instance also has flow control
|
//TODO check if shader has flow control and make sure instance also has flow control
|
||||||
@ -119,22 +138,6 @@ VkResult rpi_vkCreateShaderModuleFromRpiAssemblyEXT(VkPhysicalDevice
|
|||||||
return VK_SUCCESS;
|
return VK_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Implementation of our RPI specific "extension"
|
|
||||||
*/
|
|
||||||
VkResult rpi_vkCreateRpiSurfaceEXT(
|
|
||||||
VkPhysicalDevice physicalDevice)
|
|
||||||
{
|
|
||||||
assert(physicalDevice);
|
|
||||||
|
|
||||||
//TODO use allocator!
|
|
||||||
|
|
||||||
_physicalDevice* ptr = physicalDevice;
|
|
||||||
*(VkSurfaceKHR*)ptr->customData = (VkSurfaceKHR)modeset_create(controlFd);
|
|
||||||
|
|
||||||
return VK_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
29
driver/wsi.c
29
driver/wsi.c
@ -5,13 +5,26 @@
|
|||||||
|
|
||||||
#include "declarations.h"
|
#include "declarations.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
VKAPI_ATTR VkResult VKAPI_CALL rpi_vkCreateDisplayPlaneSurfaceKHR(
|
||||||
|
VkInstance instance,
|
||||||
|
const VkDisplaySurfaceCreateInfoKHR* pCreateInfo,
|
||||||
|
const VkAllocationCallbacks* pAllocator,
|
||||||
|
VkSurfaceKHR* pSurface)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "vkCreateDisplayPlaneSurfaceKHR\n");
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkDestroySurfaceKHR
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkDestroySurfaceKHR
|
||||||
* Destroying a VkSurfaceKHR merely severs the connection between Vulkan and the native surface,
|
* Destroying a VkSurfaceKHR merely severs the connection between Vulkan and the native surface,
|
||||||
* and does not imply destroying the native surface, closing a window, or similar behavior
|
* and does not imply destroying the native surface, closing a window, or similar behavior
|
||||||
* (but we'll do so anyways...)
|
* (but we'll do so anyways...)
|
||||||
*/
|
*/
|
||||||
VKAPI_ATTR void VKAPI_CALL vkDestroySurfaceKHR(
|
VKAPI_ATTR void VKAPI_CALL rpi_vkDestroySurfaceKHR(
|
||||||
VkInstance instance,
|
VkInstance instance,
|
||||||
VkSurfaceKHR surface,
|
VkSurfaceKHR surface,
|
||||||
const VkAllocationCallbacks* pAllocator)
|
const VkAllocationCallbacks* pAllocator)
|
||||||
@ -36,7 +49,7 @@ VKAPI_ATTR void VKAPI_CALL vkDestroySurfaceKHR(
|
|||||||
*
|
*
|
||||||
* capabilities the specified device supports for a swapchain created for the surface
|
* capabilities the specified device supports for a swapchain created for the surface
|
||||||
*/
|
*/
|
||||||
VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
|
VKAPI_ATTR VkResult VKAPI_CALL rpi_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
|
||||||
VkPhysicalDevice physicalDevice,
|
VkPhysicalDevice physicalDevice,
|
||||||
VkSurfaceKHR surface,
|
VkSurfaceKHR surface,
|
||||||
VkSurfaceCapabilitiesKHR* pSurfaceCapabilities)
|
VkSurfaceCapabilitiesKHR* pSurfaceCapabilities)
|
||||||
@ -71,7 +84,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
|
|||||||
* at most pSurfaceFormatCount structures will be written. If pSurfaceFormatCount is smaller than the number of format pairs supported for the given surface,
|
* at most pSurfaceFormatCount structures will be written. If pSurfaceFormatCount is smaller than the number of format pairs supported for the given surface,
|
||||||
* VK_INCOMPLETE will be returned instead of VK_SUCCESS to indicate that not all the available values were returned.
|
* VK_INCOMPLETE will be returned instead of VK_SUCCESS to indicate that not all the available values were returned.
|
||||||
*/
|
*/
|
||||||
VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceFormatsKHR(
|
VKAPI_ATTR VkResult VKAPI_CALL rpi_vkGetPhysicalDeviceSurfaceFormatsKHR(
|
||||||
VkPhysicalDevice physicalDevice,
|
VkPhysicalDevice physicalDevice,
|
||||||
VkSurfaceKHR surface,
|
VkSurfaceKHR surface,
|
||||||
uint32_t* pSurfaceFormatCount,
|
uint32_t* pSurfaceFormatCount,
|
||||||
@ -116,7 +129,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceFormatsKHR(
|
|||||||
* If pPresentModeCount is smaller than the number of presentation modes supported for the given surface, VK_INCOMPLETE will be returned instead of
|
* If pPresentModeCount is smaller than the number of presentation modes supported for the given surface, VK_INCOMPLETE will be returned instead of
|
||||||
* VK_SUCCESS to indicate that not all the available values were returned.
|
* VK_SUCCESS to indicate that not all the available values were returned.
|
||||||
*/
|
*/
|
||||||
VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfacePresentModesKHR(
|
VKAPI_ATTR VkResult VKAPI_CALL rpi_vkGetPhysicalDeviceSurfacePresentModesKHR(
|
||||||
VkPhysicalDevice physicalDevice,
|
VkPhysicalDevice physicalDevice,
|
||||||
VkSurfaceKHR surface,
|
VkSurfaceKHR surface,
|
||||||
uint32_t* pPresentModeCount,
|
uint32_t* pPresentModeCount,
|
||||||
@ -156,7 +169,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfacePresentModesKHR(
|
|||||||
/*
|
/*
|
||||||
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCreateSwapchainKHR
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCreateSwapchainKHR
|
||||||
*/
|
*/
|
||||||
VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
|
VKAPI_ATTR VkResult VKAPI_CALL rpi_vkCreateSwapchainKHR(
|
||||||
VkDevice device,
|
VkDevice device,
|
||||||
const VkSwapchainCreateInfoKHR* pCreateInfo,
|
const VkSwapchainCreateInfoKHR* pCreateInfo,
|
||||||
const VkAllocationCallbacks* pAllocator,
|
const VkAllocationCallbacks* pAllocator,
|
||||||
@ -404,7 +417,7 @@ VKAPI_ATTR void VKAPI_CALL rpi_vkDestroySwapchainKHR(
|
|||||||
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkGetPhysicalDeviceSurfaceSupportKHR
|
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkGetPhysicalDeviceSurfaceSupportKHR
|
||||||
* does this queue family support presentation to this surface?
|
* does this queue family support presentation to this surface?
|
||||||
*/
|
*/
|
||||||
VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceSupportKHR(
|
VKAPI_ATTR VkResult VKAPI_CALL rpi_vkGetPhysicalDeviceSurfaceSupportKHR(
|
||||||
VkPhysicalDevice physicalDevice,
|
VkPhysicalDevice physicalDevice,
|
||||||
uint32_t queueFamilyIndex,
|
uint32_t queueFamilyIndex,
|
||||||
VkSurfaceKHR surface,
|
VkSurfaceKHR surface,
|
||||||
@ -422,3 +435,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceSupportKHR(
|
|||||||
*pSupported = VK_TRUE;
|
*pSupported = VK_TRUE;
|
||||||
return VK_SUCCESS;
|
return VK_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@ -231,14 +231,17 @@ void createInstance() {
|
|||||||
debugCallbackInfo.flags = 0xffffffff;
|
debugCallbackInfo.flags = 0xffffffff;
|
||||||
debugCallbackInfo.pfnCallback = (PFN_vkDebugReportCallbackEXT)debugCallback;
|
debugCallbackInfo.pfnCallback = (PFN_vkDebugReportCallbackEXT)debugCallback;
|
||||||
|
|
||||||
|
const char* enabledExtensions[] = {
|
||||||
|
"VK_KHR_surface",
|
||||||
|
"VK_KHR_display"
|
||||||
|
};
|
||||||
|
|
||||||
VkInstanceCreateInfo createInfo = {};
|
VkInstanceCreateInfo createInfo = {};
|
||||||
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
||||||
createInfo.pNext = &debugCallbackInfo;
|
createInfo.pNext = &debugCallbackInfo;
|
||||||
createInfo.pApplicationInfo = &appInfo;
|
createInfo.pApplicationInfo = &appInfo;
|
||||||
//createInfo.enabledExtensionCount = glfwExtensionCount;
|
createInfo.enabledExtensionCount = sizeof(enabledExtensions) / sizeof(const char*);
|
||||||
createInfo.enabledExtensionCount = 0;
|
createInfo.ppEnabledExtensionNames = enabledExtensions;
|
||||||
//createInfo.ppEnabledExtensionNames = glfwExtensions;
|
|
||||||
createInfo.ppEnabledExtensionNames = 0;
|
|
||||||
createInfo.enabledLayerCount = 0;
|
createInfo.enabledLayerCount = 0;
|
||||||
createInfo.ppEnabledLayerNames = 0;
|
createInfo.ppEnabledLayerNames = 0;
|
||||||
|
|
||||||
@ -257,8 +260,11 @@ void createWindowSurface() {
|
|||||||
PFN_vkCreateRpiSurfaceEXT vkCreateRpiSurfaceEXT = 0;
|
PFN_vkCreateRpiSurfaceEXT vkCreateRpiSurfaceEXT = 0;
|
||||||
vkCreateRpiSurfaceEXT = (PFN_vkCreateRpiSurfaceEXT)vkGetInstanceProcAddr(instance, "vkCreateRpiSurfaceEXT");
|
vkCreateRpiSurfaceEXT = (PFN_vkCreateRpiSurfaceEXT)vkGetInstanceProcAddr(instance, "vkCreateRpiSurfaceEXT");
|
||||||
|
|
||||||
VkRpiPhysicalDevice* ptr = (VkRpiPhysicalDevice*)physicalDevice;
|
windowSurface = 0;
|
||||||
ptr->customData = &windowSurface;
|
|
||||||
|
LoaderTrampoline* trampoline = (LoaderTrampoline*)physicalDevice;
|
||||||
|
VkRpiPhysicalDevice* realPhysicalDevice = trampoline->loaderTerminator->physicalDevice;
|
||||||
|
realPhysicalDevice->customData = (uintptr_t)&windowSurface;
|
||||||
|
|
||||||
if (vkCreateRpiSurfaceEXT(physicalDevice) != VK_SUCCESS) {
|
if (vkCreateRpiSurfaceEXT(physicalDevice) != VK_SUCCESS) {
|
||||||
std::cerr << "failed to create window surface!" << std::endl;
|
std::cerr << "failed to create window surface!" << std::endl;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user