Fix device creation and start exporting vk fns

This commit is contained in:
hodasemi 2023-01-10 18:56:41 +01:00
parent 39c28af575
commit faa70a2382
3 changed files with 147 additions and 3 deletions

View file

@ -40,3 +40,22 @@ impl VkDeviceHandles {
}
}
}
macro_rules! cmp_device_fn {
($name:ident, {$([$fns:ident, $fn_name:ident],)*}) => {
match $name {
$(
stringify!($fn_name) => return unsafe {
mem::transmute(
device_fns()
.$fns
.$fn_name,
)
},
)*
_ => ()
}
}
}

View file

@ -10,6 +10,16 @@ pub fn set_instance_fns(handles: VkInstanceHandles) {
unsafe { INSTANCE_FN_HANDLES = Some(handles) };
}
pub fn replace_device_proc_addr(proc_addr: PFN_vkGetDeviceProcAddr) {
unsafe {
INSTANCE_FN_HANDLES
.as_mut()
.unwrap()
.instance_functions
.vkGetDeviceProcAddr = proc_addr
};
}
pub struct VkInstanceHandles {
pub instance: VkInstance,
@ -52,7 +62,7 @@ impl VkInstanceHandles {
}
}
macro_rules! cmp_vk_fn {
macro_rules! cmp_instance_fn {
($name:ident, {$([$fns:ident, $fn_name:ident],)*}) => {
match $name {
$(

View file

@ -3,6 +3,8 @@ pub mod structs;
#[macro_use]
mod instance_handles;
#[macro_use]
mod device_handles;
use std::{fs::OpenOptions, io::Write, mem, os::raw::c_char, ptr};
@ -67,7 +69,7 @@ fn get_function(function_name: *const c_char) -> PFN_vkVoidFunction {
let s = func_string.as_str();
cmp_vk_fn!(s, {
cmp_instance_fn!(s, {
[debug_utils_messenger_functions, vkCreateDebugUtilsMessengerEXT],
[debug_utils_messenger_functions, vkDestroyDebugUtilsMessengerEXT],
[debug_report_callback_functions, vkCreateDebugReportCallbackEXT],
@ -109,6 +111,116 @@ fn get_function(function_name: *const c_char) -> PFN_vkVoidFunction {
}
);
cmp_device_fn!(s, {
[device_functions, vkGetDeviceQueue],
[device_functions, vkQueueSubmit],
[device_functions, vkQueueWaitIdle],
[device_functions, vkDeviceWaitIdle],
[device_functions, vkAllocateMemory],
[device_functions, vkFreeMemory],
[device_functions, vkMapMemory],
[device_functions, vkUnmapMemory],
[device_functions, vkBindBufferMemory],
[device_functions, vkBindImageMemory],
[device_functions, vkGetBufferMemoryRequirements],
[device_functions, vkGetImageMemoryRequirements],
[device_functions, vkCreateFence],
[device_functions, vkDestroyFence],
[device_functions, vkResetFences],
[device_functions, vkWaitForFences],
[device_functions, vkCreateSemaphore],
[device_functions, vkDestroySemaphore],
[device_functions, vkCreateEvent],
[device_functions, vkDestroyEvent],
[device_functions, vkGetEventStatus],
[device_functions, vkSetEvent],
[device_functions, vkResetEvent],
[device_functions, vkCreateBuffer],
[device_functions, vkDestroyBuffer],
[device_functions, vkCreateBufferView],
[device_functions, vkDestroyBufferView],
[device_functions, vkCreateImage],
[device_functions, vkDestroyImage],
[device_functions, vkGetImageSubresourceLayout],
[device_functions, vkCreateImageView],
[device_functions, vkDestroyImageView],
[device_functions, vkCreateShaderModule],
[device_functions, vkDestroyShaderModule],
[device_functions, vkCreatePipelineCache],
[device_functions, vkDestroyPipelineCache],
[device_functions, vkGetPipelineCacheData],
[device_functions, vkMergePipelineCaches],
[device_functions, vkCreateGraphicsPipelines],
[device_functions, vkCreateComputePipelines],
[device_functions, vkDestroyPipeline],
[device_functions, vkCreatePipelineLayout],
[device_functions, vkDestroyPipelineLayout],
[device_functions, vkCreateSampler],
[device_functions, vkDestroySampler],
[device_functions, vkCreateDescriptorSetLayout],
[device_functions, vkDestroyDescriptorSetLayout],
[device_functions, vkCreateDescriptorPool],
[device_functions, vkDestroyDescriptorPool],
[device_functions, vkResetDescriptorPool],
[device_functions, vkAllocateDescriptorSets],
[device_functions, vkFreeDescriptorSets],
[device_functions, vkUpdateDescriptorSets],
[device_functions, vkCreateFramebuffer],
[device_functions, vkDestroyFramebuffer],
[device_functions, vkCreateRenderPass],
[device_functions, vkDestroyRenderPass],
[device_functions, vkCreateCommandPool],
[device_functions, vkDestroyCommandPool],
[device_functions, vkResetCommandPool],
[device_functions, vkAllocateCommandBuffers],
[device_functions, vkFreeCommandBuffers],
[device_functions, vkBeginCommandBuffer],
[device_functions, vkEndCommandBuffer],
[device_functions, vkResetCommandBuffer],
[device_functions, vkCmdBindPipeline],
[device_functions, vkCmdSetViewport],
[device_functions, vkCmdSetScissor],
[device_functions, vkCmdSetLineWidth],
[device_functions, vkCmdSetDepthBias],
[device_functions, vkCmdSetBlendConstants],
[device_functions, vkCmdSetDepthBounds],
[device_functions, vkCmdSetStencilCompareMask],
[device_functions, vkCmdSetStencilWriteMask],
[device_functions, vkCmdSetStencilReference],
[device_functions, vkCmdBindDescriptorSets],
[device_functions, vkCmdBindIndexBuffer],
[device_functions, vkCmdBindVertexBuffers],
[device_functions, vkCmdDraw],
[device_functions, vkCmdDispatch],
[device_functions, vkCmdCopyBuffer],
[device_functions, vkCmdCopyImage],
[device_functions, vkCmdBlitImage],
[device_functions, vkCmdCopyBufferToImage],
[device_functions, vkCmdCopyImageToBuffer],
[device_functions, vkCmdUpdateBuffer],
[device_functions, vkCmdFillBuffer],
[device_functions, vkCmdClearColorImage],
[device_functions, vkCmdClearDepthStencilImage],
[device_functions, vkCmdClearAttachments],
[device_functions, vkCmdResolveImage],
[device_functions, vkCmdSetEvent],
[device_functions, vkCmdResetEvent],
[device_functions, vkCmdWaitEvents],
[device_functions, vkCmdPipelineBarrier],
[device_functions, vkCmdPushConstants],
[device_functions, vkCmdBeginRenderPass],
[device_functions, vkCmdNextSubpass],
[device_functions, vkCmdEndRenderPass],
[device_functions, vkCmdExecuteCommands],
[device_functions, vkTrimCommandPool],
[device_functions, vkGetBufferDeviceAddress],
[device_wsi_functions, vkCreateSwapchainKHR],
[device_wsi_functions, vkDestroySwapchainKHR],
[device_wsi_functions, vkAcquireNextImageKHR],
[device_wsi_functions, vkQueuePresentKHR],
[device_wsi_functions, vkGetSwapchainImagesKHR],
});
match s {
"vkCreateDevice" => Functions::CreateDevice(create_device),
"vkDestroyDevice" => Functions::DestroyDevice(destroy_device),
@ -195,8 +307,11 @@ extern "system" fn create_device(
}
};
chain_info.advance_layer_info();
replace_device_proc_addr(chain_info.layer_info().next_device_proc_addr);
let instance = instance_fns();
chain_info.advance_layer_info();
let result = unsafe {
instance
.instance_functions