1
0
mirror of https://github.com/Yours3lf/rpi-vk-driver.git synced 2024-11-28 10:24:15 +01:00

loader stuff is now fully functional

This commit is contained in:
Unknown 2019-10-01 19:23:52 +01:00
parent 1e9d774483
commit 8c017a932c
13 changed files with 293 additions and 256 deletions

View File

@ -983,6 +983,24 @@ VKAPI_ATTR VkResult VKAPI_CALL rpi_vkGetPhysicalDeviceSurfacePresentModesKHR(
uint32_t* pPresentModeCount, uint32_t* pPresentModeCount,
VkPresentModeKHR* pPresentModes); VkPresentModeKHR* pPresentModes);
VKAPI_ATTR VkResult VKAPI_CALL rpi_vkGetSwapchainImagesKHR(
VkDevice device,
VkSwapchainKHR swapchain,
uint32_t* pSwapchainImageCount,
VkImage* pSwapchainImages);
VKAPI_ATTR VkResult VKAPI_CALL rpi_vkAcquireNextImageKHR(
VkDevice device,
VkSwapchainKHR swapchain,
uint64_t timeout,
VkSemaphore semaphore,
VkFence fence,
uint32_t* pImageIndex);
VKAPI_ATTR VkResult VKAPI_CALL rpi_vkQueuePresentKHR(
VkQueue queue,
const VkPresentInfoKHR* pPresentInfo);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -387,6 +387,10 @@ VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL rpi_vkGetInstanceProcAddr(
RETFUNC(vkGetPhysicalDeviceSurfaceFormatsKHR); RETFUNC(vkGetPhysicalDeviceSurfaceFormatsKHR);
RETFUNC(vkGetPhysicalDeviceSurfacePresentModesKHR); RETFUNC(vkGetPhysicalDeviceSurfacePresentModesKHR);
RETFUNC(vkGetSwapchainImagesKHR);
RETFUNC(vkAcquireNextImageKHR);
RETFUNC(vkQueuePresentKHR);
return 0; return 0;
} }

View File

@ -38,28 +38,6 @@ typedef struct LoaderTrampoline
LoaderTerminator* loaderTerminator; LoaderTerminator* loaderTerminator;
} LoaderTrampoline; } LoaderTrampoline;
//we need something like the other platforms to create surfaces on the RPI
//so I created this little "extension"
//full spec in this file ;)
typedef enum VkRpiSurfaceCreateFlagsEXT {
//reserved
VK_RPI_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
} VkRpiSurfaceCreateFlagsEXT;
typedef struct VkRpiSurfaceCreateInfoEXT {
VkStructureType sType;
const void* pNext;
VkRpiSurfaceCreateFlagsEXT flags; //reserved
//maybe include some other stuff dunno
} VkRpiSurfaceCreateInfoEXT;
typedef enum VkRpiAssemblyMappingTypeEXT {
VK_RPI_ASSEMBLY_MAPPING_TYPE_DESCRIPTOR = 0,
VK_RPI_ASSEMBLY_MAPPING_TYPE_PUSH_CONSTANT = 1,
VK_RPI_ASSEMBLY_MAPPING_TYPE_MAX
} VkRpiAssemblyMappingTypeEXT;
/* /*
* assembly to vulkan resource mapping * assembly to vulkan resource mapping
* *
@ -87,6 +65,18 @@ typedef enum VkRpiAssemblyMappingTypeEXT {
* *
*/ */
typedef enum VkRpiSurfaceCreateFlagsEXT {
//reserved
VK_RPI_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
} VkRpiSurfaceCreateFlagsEXT;
typedef enum VkRpiAssemblyMappingTypeEXT {
VK_RPI_ASSEMBLY_MAPPING_TYPE_DESCRIPTOR = 0,
VK_RPI_ASSEMBLY_MAPPING_TYPE_PUSH_CONSTANT = 1,
VK_RPI_ASSEMBLY_MAPPING_TYPE_MAX
} VkRpiAssemblyMappingTypeEXT;
//defines mapping for a single uniform FIFO read to a Vulkan resource //defines mapping for a single uniform FIFO read to a Vulkan resource
typedef struct VkRpiAssemblyMappingEXT { typedef struct VkRpiAssemblyMappingEXT {
VkRpiAssemblyMappingTypeEXT mappingType; VkRpiAssemblyMappingTypeEXT mappingType;
@ -98,12 +88,26 @@ typedef struct VkRpiAssemblyMappingEXT {
VkShaderStageFlagBits shaderStage; VkShaderStageFlagBits shaderStage;
} VkRpiAssemblyMappingEXT; } VkRpiAssemblyMappingEXT;
//we need something like the other platforms to create surfaces on the RPI
//so I created this little "extension"
//full spec in this file ;)
typedef struct VkRpiSurfaceCreateInfoEXT {
VkStructureType sType;
const void* pNext;
VkRpiSurfaceCreateFlagsEXT flags; //reserved
const VkAllocationCallbacks* pAllocator;
VkSurfaceKHR* pSurface;
} VkRpiSurfaceCreateInfoEXT;
typedef struct VkRpiShaderModuleAssemblyCreateInfoEXT { typedef struct VkRpiShaderModuleAssemblyCreateInfoEXT {
VkStructureType sType; VkStructureType sType;
const void* pNext; const void* pNext;
char** asmStrings; char** asmStrings;
VkRpiAssemblyMappingEXT* mappings; VkRpiAssemblyMappingEXT* mappings;
uint32_t numMappings; uint32_t numMappings;
const VkAllocationCallbacks* pAllocator;
VkShaderModule* pShaderModule;
} VkRpiShaderModuleAssemblyCreateInfoEXT; } VkRpiShaderModuleAssemblyCreateInfoEXT;
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -12,18 +12,17 @@ extern "C" {
/* /*
* Implementation of our RPI specific "extension" * Implementation of our RPI specific "extension"
*/ */
VkResult rpi_vkCreateRpiSurfaceEXT( VkResult rpi_vkCreateRpiSurfaceEXT(VkPhysicalDevice physicalDevice)
VkPhysicalDevice physicalDevice)
{ {
assert(physicalDevice); assert(physicalDevice);
//TODO use allocator! //TODO use allocator!
_physicalDevice* ptr = physicalDevice; _physicalDevice* ptr = physicalDevice;
VkSurfaceKHR* surfPtr = ptr->customData; VkRpiSurfaceCreateInfoEXT* ci = ptr->customData;
VkSurfaceKHR surfRes = (VkSurfaceKHR)modeset_create(controlFd); VkSurfaceKHR surfRes = (VkSurfaceKHR)modeset_create(controlFd);
*surfPtr = surfRes; *ci->pSurface = surfRes;
return VK_SUCCESS; return VK_SUCCESS;
} }
@ -33,15 +32,17 @@ VkResult rpi_vkCreateRpiSurfaceEXT(
//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
//TODO make sure instance has threaded fs if shader contains thread switch //TODO make sure instance has threaded fs if shader contains thread switch
VkResult rpi_vkCreateShaderModuleFromRpiAssemblyEXT(VkPhysicalDevice physicalDevice, VkResult rpi_vkCreateShaderModuleFromRpiAssemblyEXT(VkPhysicalDevice physicalDevice)
VkRpiShaderModuleAssemblyCreateInfoEXT* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkShaderModule* pShaderModule)
{ {
assert(physicalDevice); assert(physicalDevice);
assert(pCreateInfo);
assert(pShaderModule); _physicalDevice* ptr = physicalDevice;
assert(pCreateInfo->asmStrings); VkRpiShaderModuleAssemblyCreateInfoEXT* ci = ptr->customData;
const const VkAllocationCallbacks* pAllocator = ci->pAllocator;
assert(ci);
assert(ci->pShaderModule);
assert(ci->asmStrings);
_shaderModule* shader = ALLOCATE(sizeof(_shaderModule), 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); _shaderModule* shader = ALLOCATE(sizeof(_shaderModule), 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
@ -54,9 +55,9 @@ VkResult rpi_vkCreateShaderModuleFromRpiAssemblyEXT(VkPhysicalDevice
for(int c = 0; c < RPI_ASSEMBLY_TYPE_MAX; ++c) for(int c = 0; c < RPI_ASSEMBLY_TYPE_MAX; ++c)
{ {
if(pCreateInfo->asmStrings[c]) if(ci->asmStrings[c])
{ {
uint32_t numInstructions = get_num_instructions(pCreateInfo->asmStrings[c]); uint32_t numInstructions = get_num_instructions(ci->asmStrings[c]);
uint32_t size = sizeof(uint64_t)*numInstructions; uint32_t size = sizeof(uint64_t)*numInstructions;
//TODO this alloc feels kinda useless, we just copy the data anyway to kernel space //TODO this alloc feels kinda useless, we just copy the data anyway to kernel space
//why not map kernel space mem to user space instead? //why not map kernel space mem to user space instead?
@ -67,9 +68,9 @@ VkResult rpi_vkCreateShaderModuleFromRpiAssemblyEXT(VkPhysicalDevice
} }
//need to create a temporary copy as the assembly algorithm is destructive //need to create a temporary copy as the assembly algorithm is destructive
uint32_t stringLength = strlen(pCreateInfo->asmStrings[c]); uint32_t stringLength = strlen(ci->asmStrings[c]);
char* tmpShaderStr = ALLOCATE(stringLength+1, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); char* tmpShaderStr = ALLOCATE(stringLength+1, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
memcpy(tmpShaderStr, pCreateInfo->asmStrings[c], stringLength+1); memcpy(tmpShaderStr, ci->asmStrings[c], stringLength+1);
assemble_qpu_asm(tmpShaderStr, shader->instructions[c]); assemble_qpu_asm(tmpShaderStr, shader->instructions[c]);
@ -119,21 +120,21 @@ VkResult rpi_vkCreateShaderModuleFromRpiAssemblyEXT(VkPhysicalDevice
} }
} }
shader->numMappings = pCreateInfo->numMappings; shader->numMappings = ci->numMappings;
if(pCreateInfo->numMappings > 0) if(ci->numMappings > 0)
{ {
shader->mappings = ALLOCATE(sizeof(VkRpiAssemblyMappingEXT)*pCreateInfo->numMappings, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); shader->mappings = ALLOCATE(sizeof(VkRpiAssemblyMappingEXT)*ci->numMappings, 1, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if(!shader->mappings) if(!shader->mappings)
{ {
return VK_ERROR_OUT_OF_HOST_MEMORY; return VK_ERROR_OUT_OF_HOST_MEMORY;
} }
memcpy(shader->mappings, pCreateInfo->mappings, sizeof(VkRpiAssemblyMappingEXT)*pCreateInfo->numMappings); memcpy(shader->mappings, ci->mappings, sizeof(VkRpiAssemblyMappingEXT)*ci->numMappings);
} }
*pShaderModule = shader; *ci->pShaderModule = shader;
return VK_SUCCESS; return VK_SUCCESS;
} }

View File

@ -13,11 +13,7 @@ extern VkResult rpi_vkCreateRpiSurfaceEXT(
//extension that allows developers to submit QPU assembly directly and thus hand optimise code //extension that allows developers to submit QPU assembly directly and thus hand optimise code
extern VkResult rpi_vkCreateShaderModuleFromRpiAssemblyEXT( extern VkResult rpi_vkCreateShaderModuleFromRpiAssemblyEXT(
VkPhysicalDevice physicalDevice, VkPhysicalDevice physicalDevice);
VkRpiShaderModuleAssemblyCreateInfoEXT* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkShaderModule* pShaderModule
);
//TODO performance counters / perfmon //TODO performance counters / perfmon

View File

@ -158,42 +158,6 @@ void mainLoop() {
} }
} }
VkBool32 debugCallback(
VkDebugReportFlagsEXT flags,
VkDebugReportObjectTypeEXT objectType,
uint64_t object,
size_t location,
int32_t messageCode,
const char* pLayerPrefix,
const char* pMessage,
void* pUserData)
{
std::cerr << "Debug callback: ";
if(flags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT)
std::cerr << "info ";
if(flags & VK_DEBUG_REPORT_WARNING_BIT_EXT)
std::cerr << "warn ";
if(flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT)
std::cerr << "perf ";
if(flags & VK_DEBUG_REPORT_ERROR_BIT_EXT)
std::cerr << "error ";
if(flags & VK_DEBUG_REPORT_DEBUG_BIT_EXT)
std::cerr << "debug ";
std::cerr << std::endl
<< "object type: " << objectType
<< " object: " << object
<< " location: " << location
<< " message code: " << messageCode << std::endl
<< " layer prefix: " << pLayerPrefix << std::endl
<< " message: " << pMessage
<< std::endl;
}
void createInstance() { void createInstance() {
VkApplicationInfo appInfo = {}; VkApplicationInfo appInfo = {};
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
@ -226,11 +190,6 @@ void createInstance() {
std::cout << "\t" << extension.extensionName << std::endl; std::cout << "\t" << extension.extensionName << std::endl;
} }
VkDebugReportCallbackCreateInfoEXT debugCallbackInfo = {};
debugCallbackInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT;
debugCallbackInfo.flags = 0xffffffff;
debugCallbackInfo.pfnCallback = (PFN_vkDebugReportCallbackEXT)debugCallback;
const char* enabledExtensions[] = { const char* enabledExtensions[] = {
"VK_KHR_surface", "VK_KHR_surface",
"VK_KHR_display" "VK_KHR_display"
@ -238,13 +197,13 @@ void createInstance() {
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 = 0;
createInfo.pApplicationInfo = &appInfo; createInfo.pApplicationInfo = &appInfo;
createInfo.enabledExtensionCount = sizeof(enabledExtensions) / sizeof(const char*); createInfo.enabledExtensionCount = sizeof(enabledExtensions) / sizeof(const char*);
createInfo.ppEnabledExtensionNames = enabledExtensions; createInfo.ppEnabledExtensionNames = enabledExtensions;
createInfo.enabledLayerCount = 0; createInfo.enabledLayerCount = 0;
createInfo.ppEnabledLayerNames = 0; createInfo.ppEnabledLayerNames = 0;
//
// Initialize Vulkan instance // Initialize Vulkan instance
VkResult res; VkResult res;
if ((res = vkCreateInstance(&createInfo, nullptr, &instance)) != VK_SUCCESS) { if ((res = vkCreateInstance(&createInfo, nullptr, &instance)) != VK_SUCCESS) {
@ -264,7 +223,11 @@ void createWindowSurface() {
LoaderTrampoline* trampoline = (LoaderTrampoline*)physicalDevice; LoaderTrampoline* trampoline = (LoaderTrampoline*)physicalDevice;
VkRpiPhysicalDevice* realPhysicalDevice = trampoline->loaderTerminator->physicalDevice; VkRpiPhysicalDevice* realPhysicalDevice = trampoline->loaderTerminator->physicalDevice;
realPhysicalDevice->customData = (uintptr_t)&windowSurface;
VkRpiSurfaceCreateInfoEXT ci = {};
ci.pSurface = &windowSurface;
realPhysicalDevice->customData = (uintptr_t)&ci;
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;
@ -876,15 +839,6 @@ void CreateFramebuffer()
void CreateShaders() void CreateShaders()
{ {
typedef VkResult (VKAPI_PTR *PFN_vkCreateShaderModuleFromRpiAssemblyEXT)(
VkDevice device,
VkRpiShaderModuleAssemblyCreateInfoEXT* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkShaderModule* pShaderModule
);
PFN_vkCreateShaderModuleFromRpiAssemblyEXT vkCreateShaderModuleFromRpiAssemblyEXT = (PFN_vkCreateShaderModuleFromRpiAssemblyEXT)vkGetInstanceProcAddr(instance, "vkCreateShaderModuleFromRpiAssemblyEXT");
char vs_asm_code[] = char vs_asm_code[] =
///0x40000000 = 2.0 ///0x40000000 = 2.0
///uni = 1.0 ///uni = 1.0
@ -1102,12 +1056,20 @@ void CreateShaders()
} }
}; };
VkRpiShaderModuleAssemblyCreateInfoEXT shaderModuleCreateInfo; VkRpiShaderModuleAssemblyCreateInfoEXT shaderModuleCreateInfo = {};
shaderModuleCreateInfo.asmStrings = asm_strings; shaderModuleCreateInfo.asmStrings = asm_strings;
shaderModuleCreateInfo.mappings = mappings; shaderModuleCreateInfo.mappings = mappings;
shaderModuleCreateInfo.numMappings = sizeof(mappings) / sizeof(VkRpiAssemblyMappingEXT); shaderModuleCreateInfo.numMappings = sizeof(mappings) / sizeof(VkRpiAssemblyMappingEXT);
shaderModuleCreateInfo.pShaderModule = &shaderModule;
VkResult res = vkCreateShaderModuleFromRpiAssemblyEXT(device, &shaderModuleCreateInfo, 0, &shaderModule); LoaderTrampoline* trampoline = (LoaderTrampoline*)physicalDevice;
VkRpiPhysicalDevice* realPhysicalDevice = trampoline->loaderTerminator->physicalDevice;
realPhysicalDevice->customData = (uintptr_t)&shaderModuleCreateInfo;
PFN_vkCreateShaderModuleFromRpiAssemblyEXT vkCreateShaderModuleFromRpiAssemblyEXT = (PFN_vkCreateShaderModuleFromRpiAssemblyEXT)vkGetInstanceProcAddr(instance, "vkCreateShaderModuleFromRpiAssemblyEXT");
VkResult res = vkCreateShaderModuleFromRpiAssemblyEXT(physicalDevice);
assert(shaderModule); assert(shaderModule);
} }

View File

@ -74,8 +74,8 @@ void run() {
void setupVulkan() { void setupVulkan() {
createInstance(); createInstance();
createWindowSurface();
findPhysicalDevice(); findPhysicalDevice();
createWindowSurface();
checkSwapChainSupport(); checkSwapChainSupport();
findQueueFamilies(); findQueueFamilies();
createLogicalDevice(); createLogicalDevice();
@ -146,13 +146,17 @@ void createInstance() {
std::cout << "\t" << extension.extensionName << std::endl; std::cout << "\t" << extension.extensionName << std::endl;
} }
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 = 0;
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;
@ -167,15 +171,20 @@ void createInstance() {
} }
void createWindowSurface() { void createWindowSurface() {
typedef VkResult (VKAPI_PTR *PFN_vkCreateRpiSurfaceEXT)( PFN_vkCreateRpiSurfaceEXT vkCreateRpiSurfaceEXT = 0;
VkInstance instance, vkCreateRpiSurfaceEXT = (PFN_vkCreateRpiSurfaceEXT)vkGetInstanceProcAddr(instance, "vkCreateRpiSurfaceEXT");
const VkRpiSurfaceCreateInfoEXT* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkSurfaceKHR* pSurface);
PFN_vkCreateRpiSurfaceEXT vkCreateRpiSurfaceEXT = (PFN_vkCreateRpiSurfaceEXT)vkGetInstanceProcAddr(instance, "vkCreateRpiSurfaceEXT"); windowSurface = 0;
//
LoaderTrampoline* trampoline = (LoaderTrampoline*)physicalDevice;
VkRpiPhysicalDevice* realPhysicalDevice = trampoline->loaderTerminator->physicalDevice;
if (vkCreateRpiSurfaceEXT(instance, 0, 0, &windowSurface) != VK_SUCCESS) { VkRpiSurfaceCreateInfoEXT ci = {};
ci.pSurface = &windowSurface;
realPhysicalDevice->customData = (uintptr_t)&ci;
if (vkCreateRpiSurfaceEXT(physicalDevice) != VK_SUCCESS) {
std::cerr << "failed to create window surface!" << std::endl; std::cerr << "failed to create window surface!" << std::endl;
assert(0); assert(0);
} }

View File

@ -137,8 +137,8 @@ void run() {
void setupVulkan() { void setupVulkan() {
createInstance(); createInstance();
createWindowSurface();
findPhysicalDevice(); findPhysicalDevice();
createWindowSurface();
checkSwapChainSupport(); checkSwapChainSupport();
findQueueFamilies(); findQueueFamilies();
createLogicalDevice(); createLogicalDevice();
@ -196,13 +196,17 @@ void createInstance() {
std::cout << "\t" << extension.extensionName << std::endl; std::cout << "\t" << extension.extensionName << std::endl;
} }
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 = 0;
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;
@ -217,16 +221,20 @@ void createInstance() {
} }
void createWindowSurface() { void createWindowSurface() {
typedef VkResult (VKAPI_PTR *PFN_vkCreateRpiSurfaceEXT)( PFN_vkCreateRpiSurfaceEXT vkCreateRpiSurfaceEXT = 0;
VkInstance instance, vkCreateRpiSurfaceEXT = (PFN_vkCreateRpiSurfaceEXT)vkGetInstanceProcAddr(instance, "vkCreateRpiSurfaceEXT");
const VkRpiSurfaceCreateInfoEXT* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkSurfaceKHR* pSurface);
PFN_vkCreateRpiSurfaceEXT vkCreateRpiSurfaceEXT = (PFN_vkCreateRpiSurfaceEXT)vkGetInstanceProcAddr(instance, "vkCreateRpiSurfaceEXT"); windowSurface = 0;
LoaderTrampoline* trampoline = (LoaderTrampoline*)physicalDevice;
VkRpiPhysicalDevice* realPhysicalDevice = trampoline->loaderTerminator->physicalDevice;
if (vkCreateRpiSurfaceEXT(instance, 0, 0, &windowSurface) != VK_SUCCESS) { VkRpiSurfaceCreateInfoEXT ci = {};
ci.pSurface = &windowSurface;
realPhysicalDevice->customData = (uintptr_t)&ci;
if (vkCreateRpiSurfaceEXT(physicalDevice) != VK_SUCCESS) {
std::cerr << "failed to create window surface!" << std::endl; std::cerr << "failed to create window surface!" << std::endl;
assert(0); assert(0);
} }
@ -967,15 +975,6 @@ void CreateFramebuffer()
void CreateShaders() void CreateShaders()
{ {
typedef VkResult (VKAPI_PTR *PFN_vkCreateShaderModuleFromRpiAssemblyEXT)(
VkDevice device,
VkRpiShaderModuleAssemblyCreateInfoEXT* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkShaderModule* pShaderModule
);
PFN_vkCreateShaderModuleFromRpiAssemblyEXT vkCreateShaderModuleFromRpiAssemblyEXT = (PFN_vkCreateShaderModuleFromRpiAssemblyEXT)vkGetInstanceProcAddr(instance, "vkCreateShaderModuleFromRpiAssemblyEXT");
char vs_asm_code[] = char vs_asm_code[] =
///0x40000000 = 2.0 ///0x40000000 = 2.0
///uni = 1.0 ///uni = 1.0
@ -1174,12 +1173,20 @@ void CreateShaders()
} }
}; };
VkRpiShaderModuleAssemblyCreateInfoEXT shaderModuleCreateInfo; VkRpiShaderModuleAssemblyCreateInfoEXT shaderModuleCreateInfo = {};
shaderModuleCreateInfo.asmStrings = asm_strings; shaderModuleCreateInfo.asmStrings = asm_strings;
shaderModuleCreateInfo.mappings = mappings; shaderModuleCreateInfo.mappings = mappings;
shaderModuleCreateInfo.numMappings = sizeof(mappings) / sizeof(VkRpiAssemblyMappingEXT); shaderModuleCreateInfo.numMappings = sizeof(mappings) / sizeof(VkRpiAssemblyMappingEXT);
shaderModuleCreateInfo.pShaderModule = &shaderModule;
VkResult res = vkCreateShaderModuleFromRpiAssemblyEXT(device, &shaderModuleCreateInfo, 0, &shaderModule); LoaderTrampoline* trampoline = (LoaderTrampoline*)physicalDevice;
VkRpiPhysicalDevice* realPhysicalDevice = trampoline->loaderTerminator->physicalDevice;
realPhysicalDevice->customData = (uintptr_t)&shaderModuleCreateInfo;
PFN_vkCreateShaderModuleFromRpiAssemblyEXT vkCreateShaderModuleFromRpiAssemblyEXT = (PFN_vkCreateShaderModuleFromRpiAssemblyEXT)vkGetInstanceProcAddr(instance, "vkCreateShaderModuleFromRpiAssemblyEXT");
VkResult res = vkCreateShaderModuleFromRpiAssemblyEXT(physicalDevice);
assert(shaderModule); assert(shaderModule);
} }

View File

@ -131,8 +131,8 @@ void run() {
void setupVulkan() { void setupVulkan() {
createInstance(); createInstance();
createWindowSurface();
findPhysicalDevice(); findPhysicalDevice();
createWindowSurface();
checkSwapChainSupport(); checkSwapChainSupport();
findQueueFamilies(); findQueueFamilies();
createLogicalDevice(); createLogicalDevice();
@ -189,13 +189,17 @@ void createInstance() {
std::cout << "\t" << extension.extensionName << std::endl; std::cout << "\t" << extension.extensionName << std::endl;
} }
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 = 0;
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;
@ -210,17 +214,20 @@ void createInstance() {
} }
void createWindowSurface() { void createWindowSurface() {
typedef VkResult (VKAPI_PTR *PFN_vkCreateRpiSurfaceEXT)( PFN_vkCreateRpiSurfaceEXT vkCreateRpiSurfaceEXT = 0;
VkInstance instance, vkCreateRpiSurfaceEXT = (PFN_vkCreateRpiSurfaceEXT)vkGetInstanceProcAddr(instance, "vkCreateRpiSurfaceEXT");
const VkRpiSurfaceCreateInfoEXT* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkSurfaceKHR* pSurface);
PFN_vkCreateRpiSurfaceEXT vkCreateRpiSurfaceEXT = (PFN_vkCreateRpiSurfaceEXT)vkGetInstanceProcAddr(instance, "vkCreateRpiSurfaceEXT"); windowSurface = 0;
LoaderTrampoline* trampoline = (LoaderTrampoline*)physicalDevice;
VkRpiPhysicalDevice* realPhysicalDevice = trampoline->loaderTerminator->physicalDevice;
VkRpiSurfaceCreateInfoEXT ci = {};
ci.pSurface = &windowSurface;
if (vkCreateRpiSurfaceEXT(instance, 0, 0, &windowSurface) != VK_SUCCESS) { realPhysicalDevice->customData = (uintptr_t)&ci;
if (vkCreateRpiSurfaceEXT(physicalDevice) != VK_SUCCESS) {
std::cerr << "failed to create window surface!" << std::endl; std::cerr << "failed to create window surface!" << std::endl;
assert(0); assert(0);
} }
@ -816,16 +823,6 @@ void CreateFramebuffer()
void CreateShaders() void CreateShaders()
{ {
typedef VkResult (VKAPI_PTR *PFN_vkCreateShaderModuleFromRpiAssemblyEXT)(
VkDevice device,
VkRpiShaderModuleAssemblyCreateInfoEXT* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkShaderModule* pShaderModule
);
PFN_vkCreateShaderModuleFromRpiAssemblyEXT vkCreateShaderModuleFromRpiAssemblyEXT = (PFN_vkCreateShaderModuleFromRpiAssemblyEXT)vkGetInstanceProcAddr(instance, "vkCreateShaderModuleFromRpiAssemblyEXT");
char vs_asm_code[] = char vs_asm_code[] =
///0x40000000 = 2.0 ///0x40000000 = 2.0
///uni = 1.0 ///uni = 1.0
@ -1006,12 +1003,20 @@ void CreateShaders()
} }
}; };
VkRpiShaderModuleAssemblyCreateInfoEXT shaderModuleCreateInfo; VkRpiShaderModuleAssemblyCreateInfoEXT shaderModuleCreateInfo = {};
shaderModuleCreateInfo.asmStrings = asm_strings; shaderModuleCreateInfo.asmStrings = asm_strings;
shaderModuleCreateInfo.mappings = mappings; shaderModuleCreateInfo.mappings = mappings;
shaderModuleCreateInfo.numMappings = sizeof(mappings) / sizeof(VkRpiAssemblyMappingEXT); shaderModuleCreateInfo.numMappings = sizeof(mappings) / sizeof(VkRpiAssemblyMappingEXT);
shaderModuleCreateInfo.pShaderModule = &shaderModule;
VkResult res = vkCreateShaderModuleFromRpiAssemblyEXT(device, &shaderModuleCreateInfo, 0, &shaderModule); LoaderTrampoline* trampoline = (LoaderTrampoline*)physicalDevice;
VkRpiPhysicalDevice* realPhysicalDevice = trampoline->loaderTerminator->physicalDevice;
realPhysicalDevice->customData = (uintptr_t)&shaderModuleCreateInfo;
PFN_vkCreateShaderModuleFromRpiAssemblyEXT vkCreateShaderModuleFromRpiAssemblyEXT = (PFN_vkCreateShaderModuleFromRpiAssemblyEXT)vkGetInstanceProcAddr(instance, "vkCreateShaderModuleFromRpiAssemblyEXT");
VkResult res = vkCreateShaderModuleFromRpiAssemblyEXT(physicalDevice);
assert(shaderModule); assert(shaderModule);
} }

View File

@ -139,8 +139,8 @@ void run() {
void setupVulkan() { void setupVulkan() {
createInstance(); createInstance();
createWindowSurface();
findPhysicalDevice(); findPhysicalDevice();
createWindowSurface();
checkSwapChainSupport(); checkSwapChainSupport();
findQueueFamilies(); findQueueFamilies();
createLogicalDevice(); createLogicalDevice();
@ -198,13 +198,17 @@ void createInstance() {
std::cout << "\t" << extension.extensionName << std::endl; std::cout << "\t" << extension.extensionName << std::endl;
} }
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 = 0;
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;
@ -219,16 +223,20 @@ void createInstance() {
} }
void createWindowSurface() { void createWindowSurface() {
typedef VkResult (VKAPI_PTR *PFN_vkCreateRpiSurfaceEXT)( PFN_vkCreateRpiSurfaceEXT vkCreateRpiSurfaceEXT = 0;
VkInstance instance, vkCreateRpiSurfaceEXT = (PFN_vkCreateRpiSurfaceEXT)vkGetInstanceProcAddr(instance, "vkCreateRpiSurfaceEXT");
const VkRpiSurfaceCreateInfoEXT* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkSurfaceKHR* pSurface);
PFN_vkCreateRpiSurfaceEXT vkCreateRpiSurfaceEXT = (PFN_vkCreateRpiSurfaceEXT)vkGetInstanceProcAddr(instance, "vkCreateRpiSurfaceEXT"); windowSurface = 0;
LoaderTrampoline* trampoline = (LoaderTrampoline*)physicalDevice;
VkRpiPhysicalDevice* realPhysicalDevice = trampoline->loaderTerminator->physicalDevice;
if (vkCreateRpiSurfaceEXT(instance, 0, 0, &windowSurface) != VK_SUCCESS) { VkRpiSurfaceCreateInfoEXT ci = {};
ci.pSurface = &windowSurface;
realPhysicalDevice->customData = (uintptr_t)&ci;
if (vkCreateRpiSurfaceEXT(physicalDevice) != VK_SUCCESS) {
std::cerr << "failed to create window surface!" << std::endl; std::cerr << "failed to create window surface!" << std::endl;
assert(0); assert(0);
} }
@ -968,15 +976,6 @@ void CreateFramebuffer()
void CreateShaders() void CreateShaders()
{ {
typedef VkResult (VKAPI_PTR *PFN_vkCreateShaderModuleFromRpiAssemblyEXT)(
VkDevice device,
VkRpiShaderModuleAssemblyCreateInfoEXT* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkShaderModule* pShaderModule
);
PFN_vkCreateShaderModuleFromRpiAssemblyEXT vkCreateShaderModuleFromRpiAssemblyEXT = (PFN_vkCreateShaderModuleFromRpiAssemblyEXT)vkGetInstanceProcAddr(instance, "vkCreateShaderModuleFromRpiAssemblyEXT");
char vs_asm_code[] = char vs_asm_code[] =
///0x40000000 = 2.0 ///0x40000000 = 2.0
///uni = 1.0 ///uni = 1.0
@ -1186,17 +1185,26 @@ void CreateShaders()
} }
}; };
VkRpiShaderModuleAssemblyCreateInfoEXT shaderModuleCreateInfo; VkRpiShaderModuleAssemblyCreateInfoEXT shaderModuleCreateInfo = {};
shaderModuleCreateInfo.asmStrings = asm_strings; shaderModuleCreateInfo.asmStrings = asm_strings;
shaderModuleCreateInfo.mappings = mappings; shaderModuleCreateInfo.mappings = mappings;
shaderModuleCreateInfo.numMappings = sizeof(mappings) / sizeof(VkRpiAssemblyMappingEXT); shaderModuleCreateInfo.numMappings = sizeof(mappings) / sizeof(VkRpiAssemblyMappingEXT);
shaderModuleCreateInfo.pShaderModule = &shaderModule1;
VkResult res = vkCreateShaderModuleFromRpiAssemblyEXT(device, &shaderModuleCreateInfo, 0, &shaderModule1); LoaderTrampoline* trampoline = (LoaderTrampoline*)physicalDevice;
VkRpiPhysicalDevice* realPhysicalDevice = trampoline->loaderTerminator->physicalDevice;
realPhysicalDevice->customData = (uintptr_t)&shaderModuleCreateInfo;
PFN_vkCreateShaderModuleFromRpiAssemblyEXT vkCreateShaderModuleFromRpiAssemblyEXT = (PFN_vkCreateShaderModuleFromRpiAssemblyEXT)vkGetInstanceProcAddr(instance, "vkCreateShaderModuleFromRpiAssemblyEXT");
VkResult res = vkCreateShaderModuleFromRpiAssemblyEXT(physicalDevice);
assert(shaderModule1); assert(shaderModule1);
shaderModuleCreateInfo.pShaderModule = &shaderModule2;
asm_strings[2] = (char*)fs_asm_code2; asm_strings[2] = (char*)fs_asm_code2;
res = vkCreateShaderModuleFromRpiAssemblyEXT(device, &shaderModuleCreateInfo, 0, &shaderModule2); res = vkCreateShaderModuleFromRpiAssemblyEXT(physicalDevice);
assert(shaderModule2); assert(shaderModule2);
} }

View File

@ -101,6 +101,7 @@ char* readPPM(const char* fileName)
((uint8_t*)&ppm_magic)[1] = '6'; ((uint8_t*)&ppm_magic)[1] = '6';
FILE* fd = fopen(fileName, "rb"); FILE* fd = fopen(fileName, "rb");
assert(fd);
fseek (fd , 0 , SEEK_END); fseek (fd , 0 , SEEK_END);
uint32_t fsize = ftell(fd); uint32_t fsize = ftell(fd);
rewind(fd); rewind(fd);
@ -205,8 +206,8 @@ void run() {
void setupVulkan() { void setupVulkan() {
createInstance(); createInstance();
createWindowSurface();
findPhysicalDevice(); findPhysicalDevice();
createWindowSurface();
checkSwapChainSupport(); checkSwapChainSupport();
findQueueFamilies(); findQueueFamilies();
createLogicalDevice(); createLogicalDevice();
@ -264,13 +265,17 @@ void createInstance() {
std::cout << "\t" << extension.extensionName << std::endl; std::cout << "\t" << extension.extensionName << std::endl;
} }
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 = 0;
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;
@ -285,16 +290,20 @@ void createInstance() {
} }
void createWindowSurface() { void createWindowSurface() {
typedef VkResult (VKAPI_PTR *PFN_vkCreateRpiSurfaceEXT)( PFN_vkCreateRpiSurfaceEXT vkCreateRpiSurfaceEXT = 0;
VkInstance instance, vkCreateRpiSurfaceEXT = (PFN_vkCreateRpiSurfaceEXT)vkGetInstanceProcAddr(instance, "vkCreateRpiSurfaceEXT");
const VkRpiSurfaceCreateInfoEXT* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkSurfaceKHR* pSurface);
PFN_vkCreateRpiSurfaceEXT vkCreateRpiSurfaceEXT = (PFN_vkCreateRpiSurfaceEXT)vkGetInstanceProcAddr(instance, "vkCreateRpiSurfaceEXT"); windowSurface = 0;
LoaderTrampoline* trampoline = (LoaderTrampoline*)physicalDevice;
VkRpiPhysicalDevice* realPhysicalDevice = trampoline->loaderTerminator->physicalDevice;
if (vkCreateRpiSurfaceEXT(instance, 0, 0, &windowSurface) != VK_SUCCESS) { VkRpiSurfaceCreateInfoEXT ci = {};
ci.pSurface = &windowSurface;
realPhysicalDevice->customData = (uintptr_t)&ci;
if (vkCreateRpiSurfaceEXT(physicalDevice) != VK_SUCCESS) {
std::cerr << "failed to create window surface!" << std::endl; std::cerr << "failed to create window surface!" << std::endl;
assert(0); assert(0);
} }
@ -936,15 +945,6 @@ void CreateFramebuffer()
void CreateShaders() void CreateShaders()
{ {
typedef VkResult (VKAPI_PTR *PFN_vkCreateShaderModuleFromRpiAssemblyEXT)(
VkDevice device,
VkRpiShaderModuleAssemblyCreateInfoEXT* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkShaderModule* pShaderModule
);
PFN_vkCreateShaderModuleFromRpiAssemblyEXT vkCreateShaderModuleFromRpiAssemblyEXT = (PFN_vkCreateShaderModuleFromRpiAssemblyEXT)vkGetInstanceProcAddr(instance, "vkCreateShaderModuleFromRpiAssemblyEXT");
char vs_asm_code[] = char vs_asm_code[] =
///0x40000000 = 2.0 ///0x40000000 = 2.0
///uni = 1.0 ///uni = 1.0
@ -1245,19 +1245,28 @@ void CreateShaders()
} }
}; };
VkRpiShaderModuleAssemblyCreateInfoEXT shaderModuleCreateInfo; VkRpiShaderModuleAssemblyCreateInfoEXT shaderModuleCreateInfo = {};
shaderModuleCreateInfo.asmStrings = blit_asm_strings; shaderModuleCreateInfo.asmStrings = blit_asm_strings;
shaderModuleCreateInfo.mappings = blit_mappings; shaderModuleCreateInfo.mappings = blit_mappings;
shaderModuleCreateInfo.numMappings = sizeof(blit_mappings) / sizeof(VkRpiAssemblyMappingEXT); shaderModuleCreateInfo.numMappings = sizeof(blit_mappings) / sizeof(VkRpiAssemblyMappingEXT);
shaderModuleCreateInfo.pShaderModule = &blitShaderModule;
VkResult res = vkCreateShaderModuleFromRpiAssemblyEXT(device, &shaderModuleCreateInfo, 0, &blitShaderModule); LoaderTrampoline* trampoline = (LoaderTrampoline*)physicalDevice;
VkRpiPhysicalDevice* realPhysicalDevice = trampoline->loaderTerminator->physicalDevice;
realPhysicalDevice->customData = (uintptr_t)&shaderModuleCreateInfo;
PFN_vkCreateShaderModuleFromRpiAssemblyEXT vkCreateShaderModuleFromRpiAssemblyEXT = (PFN_vkCreateShaderModuleFromRpiAssemblyEXT)vkGetInstanceProcAddr(instance, "vkCreateShaderModuleFromRpiAssemblyEXT");
VkResult res = vkCreateShaderModuleFromRpiAssemblyEXT(physicalDevice);
assert(blitShaderModule); assert(blitShaderModule);
shaderModuleCreateInfo.asmStrings = sample_asm_strings; shaderModuleCreateInfo.asmStrings = sample_asm_strings;
shaderModuleCreateInfo.mappings = sample_mappings; shaderModuleCreateInfo.mappings = sample_mappings;
shaderModuleCreateInfo.numMappings = sizeof(sample_mappings) / sizeof(VkRpiAssemblyMappingEXT); shaderModuleCreateInfo.numMappings = sizeof(sample_mappings) / sizeof(VkRpiAssemblyMappingEXT);
shaderModuleCreateInfo.pShaderModule = &sampleShaderModule;
res = vkCreateShaderModuleFromRpiAssemblyEXT(device, &shaderModuleCreateInfo, 0, &sampleShaderModule); res = vkCreateShaderModuleFromRpiAssemblyEXT(physicalDevice);
assert(sampleShaderModule); assert(sampleShaderModule);
//exit(-1); //exit(-1);

View File

@ -129,8 +129,8 @@ void run() {
void setupVulkan() { void setupVulkan() {
createInstance(); createInstance();
createWindowSurface();
findPhysicalDevice(); findPhysicalDevice();
createWindowSurface();
checkSwapChainSupport(); checkSwapChainSupport();
findQueueFamilies(); findQueueFamilies();
createLogicalDevice(); createLogicalDevice();
@ -187,13 +187,17 @@ void createInstance() {
std::cout << "\t" << extension.extensionName << std::endl; std::cout << "\t" << extension.extensionName << std::endl;
} }
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 = 0;
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;
@ -208,15 +212,20 @@ void createInstance() {
} }
void createWindowSurface() { void createWindowSurface() {
typedef VkResult (VKAPI_PTR *PFN_vkCreateRpiSurfaceEXT)( PFN_vkCreateRpiSurfaceEXT vkCreateRpiSurfaceEXT = 0;
VkInstance instance, vkCreateRpiSurfaceEXT = (PFN_vkCreateRpiSurfaceEXT)vkGetInstanceProcAddr(instance, "vkCreateRpiSurfaceEXT");
const VkRpiSurfaceCreateInfoEXT* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkSurfaceKHR* pSurface);
PFN_vkCreateRpiSurfaceEXT vkCreateRpiSurfaceEXT = (PFN_vkCreateRpiSurfaceEXT)vkGetInstanceProcAddr(instance, "vkCreateRpiSurfaceEXT"); windowSurface = 0;
if (vkCreateRpiSurfaceEXT(instance, 0, 0, &windowSurface) != VK_SUCCESS) { LoaderTrampoline* trampoline = (LoaderTrampoline*)physicalDevice;
VkRpiPhysicalDevice* realPhysicalDevice = trampoline->loaderTerminator->physicalDevice;
VkRpiSurfaceCreateInfoEXT ci = {};
ci.pSurface = &windowSurface;
realPhysicalDevice->customData = (uintptr_t)&ci;
if (vkCreateRpiSurfaceEXT(physicalDevice) != VK_SUCCESS) {
std::cerr << "failed to create window surface!" << std::endl; std::cerr << "failed to create window surface!" << std::endl;
assert(0); assert(0);
} }
@ -810,16 +819,6 @@ void CreateFramebuffer()
void CreateShaders() void CreateShaders()
{ {
typedef VkResult (VKAPI_PTR *PFN_vkCreateShaderModuleFromRpiAssemblyEXT)(
VkDevice device,
VkRpiShaderModuleAssemblyCreateInfoEXT* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkShaderModule* pShaderModule
);
PFN_vkCreateShaderModuleFromRpiAssemblyEXT vkCreateShaderModuleFromRpiAssemblyEXT = (PFN_vkCreateShaderModuleFromRpiAssemblyEXT)vkGetInstanceProcAddr(instance, "vkCreateShaderModuleFromRpiAssemblyEXT");
char vs_asm_code[] = char vs_asm_code[] =
///0x40000000 = 2.0 ///0x40000000 = 2.0
///uni = 1.0 ///uni = 1.0
@ -1000,12 +999,20 @@ void CreateShaders()
} }
}; };
VkRpiShaderModuleAssemblyCreateInfoEXT shaderModuleCreateInfo; VkRpiShaderModuleAssemblyCreateInfoEXT shaderModuleCreateInfo = {};
shaderModuleCreateInfo.asmStrings = asm_strings; shaderModuleCreateInfo.asmStrings = asm_strings;
shaderModuleCreateInfo.mappings = mappings; shaderModuleCreateInfo.mappings = mappings;
shaderModuleCreateInfo.numMappings = sizeof(mappings) / sizeof(VkRpiAssemblyMappingEXT); shaderModuleCreateInfo.numMappings = sizeof(mappings) / sizeof(VkRpiAssemblyMappingEXT);
shaderModuleCreateInfo.pShaderModule = &shaderModule;
VkResult res = vkCreateShaderModuleFromRpiAssemblyEXT(device, &shaderModuleCreateInfo, 0, &shaderModule); LoaderTrampoline* trampoline = (LoaderTrampoline*)physicalDevice;
VkRpiPhysicalDevice* realPhysicalDevice = trampoline->loaderTerminator->physicalDevice;
realPhysicalDevice->customData = (uintptr_t)&shaderModuleCreateInfo;
PFN_vkCreateShaderModuleFromRpiAssemblyEXT vkCreateShaderModuleFromRpiAssemblyEXT = (PFN_vkCreateShaderModuleFromRpiAssemblyEXT)vkGetInstanceProcAddr(instance, "vkCreateShaderModuleFromRpiAssemblyEXT");
VkResult res = vkCreateShaderModuleFromRpiAssemblyEXT(physicalDevice);
assert(shaderModule); assert(shaderModule);
} }

View File

@ -129,8 +129,8 @@ void run() {
void setupVulkan() { void setupVulkan() {
createInstance(); createInstance();
createWindowSurface();
findPhysicalDevice(); findPhysicalDevice();
createWindowSurface();
checkSwapChainSupport(); checkSwapChainSupport();
findQueueFamilies(); findQueueFamilies();
createLogicalDevice(); createLogicalDevice();
@ -187,13 +187,17 @@ void createInstance() {
std::cout << "\t" << extension.extensionName << std::endl; std::cout << "\t" << extension.extensionName << std::endl;
} }
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 = 0;
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;
@ -208,16 +212,20 @@ void createInstance() {
} }
void createWindowSurface() { void createWindowSurface() {
typedef VkResult (VKAPI_PTR *PFN_vkCreateRpiSurfaceEXT)( PFN_vkCreateRpiSurfaceEXT vkCreateRpiSurfaceEXT = 0;
VkInstance instance, vkCreateRpiSurfaceEXT = (PFN_vkCreateRpiSurfaceEXT)vkGetInstanceProcAddr(instance, "vkCreateRpiSurfaceEXT");
const VkRpiSurfaceCreateInfoEXT* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkSurfaceKHR* pSurface);
PFN_vkCreateRpiSurfaceEXT vkCreateRpiSurfaceEXT = (PFN_vkCreateRpiSurfaceEXT)vkGetInstanceProcAddr(instance, "vkCreateRpiSurfaceEXT"); windowSurface = 0;
LoaderTrampoline* trampoline = (LoaderTrampoline*)physicalDevice;
VkRpiPhysicalDevice* realPhysicalDevice = trampoline->loaderTerminator->physicalDevice;
if (vkCreateRpiSurfaceEXT(instance, 0, 0, &windowSurface) != VK_SUCCESS) { VkRpiSurfaceCreateInfoEXT ci = {};
ci.pSurface = &windowSurface;
realPhysicalDevice->customData = (uintptr_t)&ci;
if (vkCreateRpiSurfaceEXT(physicalDevice) != VK_SUCCESS) {
std::cerr << "failed to create window surface!" << std::endl; std::cerr << "failed to create window surface!" << std::endl;
assert(0); assert(0);
} }
@ -811,15 +819,6 @@ void CreateFramebuffer()
void CreateShaders() void CreateShaders()
{ {
typedef VkResult (VKAPI_PTR *PFN_vkCreateShaderModuleFromRpiAssemblyEXT)(
VkDevice device,
VkRpiShaderModuleAssemblyCreateInfoEXT* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkShaderModule* pShaderModule
);
PFN_vkCreateShaderModuleFromRpiAssemblyEXT vkCreateShaderModuleFromRpiAssemblyEXT = (PFN_vkCreateShaderModuleFromRpiAssemblyEXT)vkGetInstanceProcAddr(instance, "vkCreateShaderModuleFromRpiAssemblyEXT");
/** /**
//FS prog reading tex with varyings //FS prog reading tex with varyings
0x100049e0203e303e nop nop, r0, r0 ; fmul r0, vary, ra15 //mul by w 0x100049e0203e303e nop nop, r0, r0 ; fmul r0, vary, ra15 //mul by w
@ -1062,12 +1061,20 @@ void CreateShaders()
} }
}; };
VkRpiShaderModuleAssemblyCreateInfoEXT shaderModuleCreateInfo; VkRpiShaderModuleAssemblyCreateInfoEXT shaderModuleCreateInfo = {};
shaderModuleCreateInfo.asmStrings = asm_strings; shaderModuleCreateInfo.asmStrings = asm_strings;
shaderModuleCreateInfo.mappings = mappings; shaderModuleCreateInfo.mappings = mappings;
shaderModuleCreateInfo.numMappings = sizeof(mappings) / sizeof(VkRpiAssemblyMappingEXT); shaderModuleCreateInfo.numMappings = sizeof(mappings) / sizeof(VkRpiAssemblyMappingEXT);
shaderModuleCreateInfo.pShaderModule = &shaderModule;
VkResult res = vkCreateShaderModuleFromRpiAssemblyEXT(device, &shaderModuleCreateInfo, 0, &shaderModule); LoaderTrampoline* trampoline = (LoaderTrampoline*)physicalDevice;
VkRpiPhysicalDevice* realPhysicalDevice = trampoline->loaderTerminator->physicalDevice;
realPhysicalDevice->customData = (uintptr_t)&shaderModuleCreateInfo;
PFN_vkCreateShaderModuleFromRpiAssemblyEXT vkCreateShaderModuleFromRpiAssemblyEXT = (PFN_vkCreateShaderModuleFromRpiAssemblyEXT)vkGetInstanceProcAddr(instance, "vkCreateShaderModuleFromRpiAssemblyEXT");
VkResult res = vkCreateShaderModuleFromRpiAssemblyEXT(physicalDevice);
assert(shaderModule); assert(shaderModule);
} }