Split device and instance get proc addr

This commit is contained in:
hodasemi 2023-01-11 06:20:07 +01:00
parent 785bf7ac9e
commit 8b1e936a50

View file

@ -31,9 +31,9 @@ pub extern "C" fn vkNegotiateLoaderLayerInterfaceVersion(
) -> VkResult {
File::create(LOG_FILE).unwrap();
write_log("======================================================");
write_log("================= New Negotiation ====================");
write_log("======================================================");
write_log(" ==================================================================");
write_log(" ======================= New Negotiation ==========================");
write_log(" ==================================================================");
unsafe {
*pVersionStruct = VkNegotiateLayerInterface {
@ -54,18 +54,6 @@ extern "system" fn get_device_proc_addr(
_device: VkDevice,
function_name: *const c_char,
) -> PFN_vkVoidFunction {
get_function(function_name)
}
#[no_mangle]
extern "system" fn get_instance_proc_addr(
_instance: VkInstance,
function_name: *const c_char,
) -> PFN_vkVoidFunction {
get_function(function_name)
}
fn get_function(function_name: *const c_char) -> PFN_vkVoidFunction {
let func_string = match VkString::try_from(function_name) {
Ok(func) => func,
Err(_) => {
@ -266,39 +254,241 @@ fn get_function(function_name: *const c_char) -> PFN_vkVoidFunction {
_ => (),
};
if let Some(vk_fn) = load_vk_fn(&func_string) {
return vk_fn;
unsafe {
if is_device_fns_initialized() {
let device_fn = instance_fns()
.instance_functions
.vkGetDeviceProcAddr(device_fns().device, func_string.as_ptr());
if mem::transmute::<PFN_vkVoidFunction, *const c_void>(device_fn) != ptr::null() {
return device_fn;
}
}
}
write_log(format!("\trequested fn: {}", s));
write_log(format!("\trequested fn: {} in device proc addr", s));
write_log(format!("\t-> not found"));
Functions::Null.convert()
}
fn load_vk_fn(name: &VkString) -> Option<PFN_vkVoidFunction> {
#[no_mangle]
extern "system" fn get_instance_proc_addr(
_instance: VkInstance,
function_name: *const c_char,
) -> PFN_vkVoidFunction {
let func_string = match VkString::try_from(function_name) {
Ok(func) => func,
Err(_) => {
write_log("Err: failed creating string");
return Functions::Null.convert();
}
};
let s = func_string.as_str();
cmp_instance_fn!(s, {
[debug_utils_messenger_functions, vkCreateDebugUtilsMessengerEXT],
[debug_utils_messenger_functions, vkDestroyDebugUtilsMessengerEXT],
[debug_report_callback_functions, vkCreateDebugReportCallbackEXT],
[debug_report_callback_functions, vkDestroyDebugReportCallbackEXT],
[instance_functions, vkEnumeratePhysicalDevices],
[instance_functions, vkGetPhysicalDeviceFeatures],
[instance_functions, vkGetPhysicalDeviceFormatProperties],
[instance_functions, vkGetPhysicalDeviceImageFormatProperties],
[instance_functions, vkGetPhysicalDeviceProperties],
[instance_functions, vkGetPhysicalDeviceQueueFamilyProperties],
[instance_functions, vkGetPhysicalDeviceMemoryProperties],
[instance_functions, vkEnumerateDeviceExtensionProperties],
// [instance_functions, vkEnumerateDeviceLayerProperties],
[instance_functions, vkGetPhysicalDeviceSparseImageFormatProperties],
// [instance_functions, vkEnumeratePhysicalDeviceGroups],
[physical_device_properties2_functions, vkGetPhysicalDeviceFeatures2KHR],
[physical_device_properties2_functions, vkGetPhysicalDeviceProperties2KHR],
[physical_device_properties2_functions, vkGetPhysicalDeviceFormatProperties2KHR],
[physical_device_properties2_functions, vkGetPhysicalDeviceFeatures2KHR],
[physical_device_properties2_functions, vkGetPhysicalDeviceFeatures2KHR],
[instance_wsi_functions, vkDestroySurfaceKHR],
[instance_wsi_functions, vkGetPhysicalDeviceSurfaceSupportKHR],
[instance_wsi_functions, vkGetPhysicalDeviceSurfaceCapabilitiesKHR],
[instance_wsi_functions, vkGetPhysicalDeviceSurfaceFormatsKHR],
[instance_wsi_functions, vkGetPhysicalDeviceSurfacePresentModesKHR],
[instance_wsi_functions, vkGetPhysicalDeviceDisplayPropertiesKHR],
[instance_wsi_functions, vkGetPhysicalDeviceDisplayPlanePropertiesKHR],
[instance_wsi_functions, vkGetDisplayPlaneSupportedDisplaysKHR],
[instance_wsi_functions, vkGetDisplayModePropertiesKHR],
[instance_wsi_functions, vkCreateDisplayModeKHR],
[instance_wsi_functions, vkGetDisplayPlaneCapabilitiesKHR],
[instance_wsi_functions, vkCreateDisplayPlaneSurfaceKHR],
[instance_wsi_functions, vkCreateXlibSurfaceKHR],
[instance_wsi_functions, vkGetPhysicalDeviceXlibPresentationSupportKHR],
[instance_wsi_functions, vkCreateXcbSurfaceKHR],
[instance_wsi_functions, vkGetPhysicalDeviceXcbPresentationSupportKHR],
[instance_wsi_functions, vkCreateWaylandSurfaceKHR],
[instance_wsi_functions, vkGetPhysicalDeviceWaylandPresentationSupportKHR],
}
);
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_functions, vkGetBufferMemoryRequirements2],
[device_functions, vkGetImageMemoryRequirements2],
[device_functions, vkBindBufferMemory2],
[device_functions, vkBindImageMemory2],
[device_wsi_functions, vkCreateSwapchainKHR],
[device_wsi_functions, vkDestroySwapchainKHR],
[device_wsi_functions, vkAcquireNextImageKHR],
[device_wsi_functions, vkQueuePresentKHR],
[device_wsi_functions, vkGetSwapchainImagesKHR],
[acceleration_structure_functions, vkBuildAccelerationStructuresKHR],
[acceleration_structure_functions, vkCmdBuildAccelerationStructuresIndirectKHR],
[acceleration_structure_functions, vkCmdBuildAccelerationStructuresKHR],
[acceleration_structure_functions, vkCmdCopyAccelerationStructureKHR],
[acceleration_structure_functions, vkCmdCopyAccelerationStructureToMemoryKHR],
[acceleration_structure_functions, vkCmdCopyMemoryToAccelerationStructureKHR],
[acceleration_structure_functions, vkCmdWriteAccelerationStructuresPropertiesKHR],
[acceleration_structure_functions, vkCopyAccelerationStructureKHR],
[acceleration_structure_functions, vkCopyAccelerationStructureToMemoryKHR],
[acceleration_structure_functions, vkCopyMemoryToAccelerationStructureKHR],
[acceleration_structure_functions, vkCreateAccelerationStructureKHR],
[acceleration_structure_functions, vkDestroyAccelerationStructureKHR],
[acceleration_structure_functions, vkGetAccelerationStructureBuildSizesKHR],
[acceleration_structure_functions, vkGetAccelerationStructureDeviceAddressKHR],
[acceleration_structure_functions, vkGetDeviceAccelerationStructureCompatibilityKHR],
[acceleration_structure_functions, vkWriteAccelerationStructuresPropertiesKHR],
[ray_tracing_pipeline_functions, vkCmdSetRayTracingPipelineStackSizeKHR],
[ray_tracing_pipeline_functions, vkCmdTraceRaysIndirectKHR],
[ray_tracing_pipeline_functions, vkCmdTraceRaysKHR],
[ray_tracing_pipeline_functions, vkCreateRayTracingPipelinesKHR],
[ray_tracing_pipeline_functions, vkGetRayTracingCaptureReplayShaderGroupHandlesKHR],
[ray_tracing_pipeline_functions, vkGetRayTracingShaderGroupHandlesKHR],
[ray_tracing_pipeline_functions, vkGetRayTracingShaderGroupStackSizeKHR],
[maintenance3_functions, vkGetDescriptorSetLayoutSupport],
}
);
match s {
"vkCreateDevice" => return Functions::CreateDevice(create_device).convert(),
"vkDestroyDevice" => return Functions::DestroyDevice(destroy_device).convert(),
"vkCreateInstance" => return Functions::CreateInstance(create_instance).convert(),
"vkDestroyInstance" => return Functions::DestroyInstance(destroy_instance).convert(),
_ => (),
};
unsafe {
if is_instance_fns_initialized() {
let instance_fn = instance_fns()
.static_functions
.vkGetInstanceProcAddr(instance_fns().instance, name.as_ptr());
let instance_fn = instance_fns()
.static_functions
.vkGetInstanceProcAddr(instance_fns().instance, func_string.as_ptr());
if mem::transmute::<PFN_vkVoidFunction, *const c_void>(instance_fn) != ptr::null() {
return Some(instance_fn);
}
if mem::transmute::<PFN_vkVoidFunction, *const c_void>(instance_fn) != ptr::null() {
return instance_fn;
}
if is_device_fns_initialized() {
let device_fn = instance_fns()
.instance_functions
.vkGetDeviceProcAddr(device_fns().device, name.as_ptr());
if mem::transmute::<PFN_vkVoidFunction, *const c_void>(device_fn) != ptr::null() {
return Some(device_fn);
}
}
return None;
}
write_log(format!("\trequested fn: {} in instance proc addr", s));
write_log(format!("\t-> not found"));
Functions::Null.convert()
}
extern "system" fn create_instance(