From fa4578473a4c8cce66f2188d6be2708ff5fb73d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bernon?= Date: Tue, 26 Sep 2023 22:18:46 +0200 Subject: [PATCH] vrclient: Split IVRSystem helpers to vrsystem_manual.c. CW-Bug-Id: #22729 --- vrclient_x64/Makefile.in | 1 + vrclient_x64/vrclient_x64/vrclient_main.c | 89 +++++++++----------- vrclient_x64/vrclient_x64/vrclient_private.h | 6 ++ vrclient_x64/vrclient_x64/vrsystem_manual.c | 37 ++++++++ 4 files changed, 86 insertions(+), 47 deletions(-) create mode 100644 vrclient_x64/vrclient_x64/vrsystem_manual.c diff --git a/vrclient_x64/Makefile.in b/vrclient_x64/Makefile.in index b01ab196..e7b6b3d2 100644 --- a/vrclient_x64/Makefile.in +++ b/vrclient_x64/Makefile.in @@ -8,6 +8,7 @@ EXTRADEFS = -DWINE_NO_LONG_TYPES -DGNUC C_SRCS = \ vrclient_x64/flatapi.c \ vrclient_x64/vrclient_main.c \ + vrclient_x64/vrsystem_manual.c \ vrclient_x64/winIVRApplications.c \ vrclient_x64/winIVRChaperone.c \ vrclient_x64/winIVRChaperoneSetup.c \ diff --git a/vrclient_x64/vrclient_x64/vrclient_main.c b/vrclient_x64/vrclient_x64/vrclient_main.c index b1e3fe68..06f6c555 100644 --- a/vrclient_x64/vrclient_x64/vrclient_main.c +++ b/vrclient_x64/vrclient_x64/vrclient_main.c @@ -369,11 +369,11 @@ void *CDECL VRClientCoreFactory(const char *name, int *return_code) return create_win_interface(name, vrclient_VRClientCoreFactory(name, return_code)); } -static VkDevice_T *(WINAPI *get_native_VkDevice)(VkDevice_T *); -static VkInstance_T *(WINAPI *get_native_VkInstance)(VkInstance_T *); -static VkPhysicalDevice_T *(WINAPI *get_native_VkPhysicalDevice)(VkPhysicalDevice_T *); -static VkPhysicalDevice_T *(WINAPI *get_wrapped_VkPhysicalDevice)(VkInstance_T *, VkPhysicalDevice_T *); -static VkQueue_T *(WINAPI *get_native_VkQueue)(VkQueue_T *); +static VkDevice_T *(WINAPI *p_get_native_VkDevice)( VkDevice_T * ); +static VkInstance_T *(WINAPI *p_get_native_VkInstance)( VkInstance_T * ); +static VkPhysicalDevice_T *(WINAPI *p_get_native_VkPhysicalDevice)( VkPhysicalDevice_T * ); +static VkPhysicalDevice_T *(WINAPI *p_get_wrapped_VkPhysicalDevice)( VkInstance_T *, VkPhysicalDevice_T * ); +static VkQueue_T *(WINAPI *p_get_native_VkQueue)( VkQueue_T * ); static void *get_winevulkan_unix_lib_handle(HMODULE hvulkan) { @@ -418,12 +418,12 @@ static void load_vk_unwrappers(void) return; } -#define L(name) \ - if (!(name = dlsym(unix_handle, "__wine_"#name))) \ - {\ - ERR("%s not found.\n", #name);\ - dlclose(unix_handle);\ - return;\ +#define L( name ) \ + if (!(p_##name = dlsym( unix_handle, "__wine_" #name ))) \ + { \ + ERR( "%s not found.\n", #name ); \ + dlclose( unix_handle ); \ + return; \ } L(get_native_VkDevice); @@ -436,6 +436,36 @@ static void load_vk_unwrappers(void) dlclose(unix_handle); } +VkDevice_T *get_native_VkDevice( VkDevice_T *device ) +{ + load_vk_unwrappers(); + return p_get_native_VkDevice( device ); +} + +VkInstance_T *get_native_VkInstance( VkInstance_T *instance ) +{ + load_vk_unwrappers(); + return p_get_native_VkInstance( instance ); +} + +VkPhysicalDevice_T *get_native_VkPhysicalDevice( VkPhysicalDevice_T *device ) +{ + load_vk_unwrappers(); + return p_get_native_VkPhysicalDevice( device ); +} + +VkPhysicalDevice_T *get_wrapped_VkPhysicalDevice( VkInstance_T *instance, VkPhysicalDevice_T *device ) +{ + load_vk_unwrappers(); + return p_get_wrapped_VkPhysicalDevice( instance, device ); +} + +VkQueue_T *get_native_VkQueue( VkQueue_T *queue ) +{ + load_vk_unwrappers(); + return p_get_native_VkQueue( queue ); +} + static bool is_hmd_present_reg(void) { DWORD type, value, wait_status, size; @@ -672,33 +702,6 @@ void ivrsystem_016_get_output_device( cpp_func(linux_side, out_device, type); } -void ivrsystem_get_output_device( - void (*cpp_func)(void *, uint64_t *, ETextureType, VkInstance_T *), - void *linux_side, uint64_t *out_device, ETextureType type, - VkInstance_T *wrapped_instance, unsigned int version) -{ - switch(type){ - case TextureType_Vulkan: - { - VkInstance_T *native_instance; - - load_vk_unwrappers(); - - native_instance = get_native_VkInstance(wrapped_instance); - - cpp_func(linux_side, out_device, type, native_instance); - - *out_device = (uint64_t)(intptr_t)get_wrapped_VkPhysicalDevice(wrapped_instance, - (VkPhysicalDevice_T *)(intptr_t)*out_device); - - return; - } - default: - cpp_func(linux_side, out_device, type, wrapped_instance); - return; - } -} - struct submit_data { void *linux_side; @@ -781,8 +784,6 @@ static Texture_t vrclient_translate_texture_dxvk(const Texture_t *texture, struc dxvk_surface->lpVtbl->GetVulkanImageInfo(dxvk_surface, &image_handle, image_layout, image_info); - load_vk_unwrappers(); - vkdata->m_nImage = (uint64_t)image_handle; vkdata->m_pDevice = get_native_VkDevice(vkdata->m_pDevice); vkdata->m_pPhysicalDevice = get_native_VkPhysicalDevice(vkdata->m_pPhysicalDevice); @@ -899,8 +900,6 @@ static EVROverlayError ivroverlay_set_overlay_texture_vulkan( struct VRVulkanTextureData_t our_vkdata, *their_vkdata; Texture_t our_texture; - load_vk_unwrappers(); - their_vkdata = texture->handle; our_vkdata = *their_vkdata; @@ -926,9 +925,7 @@ static EVRCompositorError ivrcompositor_submit_vulkan( VRTextureWithDepth_t our_depth; VRTextureWithPose_t our_pose; Texture_t our_texture; - void *tex = texture; - - load_vk_unwrappers(); + const void *tex = texture; their_vkdata = texture->handle; @@ -1281,8 +1278,6 @@ uint32_t ivrcompositor_get_vulkan_device_extensions_required( { uint32_t ret; - load_vk_unwrappers(); - phys_dev = get_native_VkPhysicalDevice(phys_dev); ret = cpp_func(linux_side, phys_dev, value, bufsize); diff --git a/vrclient_x64/vrclient_x64/vrclient_private.h b/vrclient_x64/vrclient_x64/vrclient_private.h index 5c5d331f..bfb7fc66 100644 --- a/vrclient_x64/vrclient_x64/vrclient_private.h +++ b/vrclient_x64/vrclient_x64/vrclient_private.h @@ -188,4 +188,10 @@ EVRInputError ivrinput_get_digital_action_data( void *linux_side, VRActionHandle_t action_handle, void *action_data, uint32_t action_data_size, VRInputValueHandle_t restrict_to_device, unsigned int version); +extern VkDevice_T *get_native_VkDevice( VkDevice_T *device ); +extern VkInstance_T *get_native_VkInstance( VkInstance_T *instance ); +extern VkPhysicalDevice_T *get_native_VkPhysicalDevice( VkPhysicalDevice_T *device ); +extern VkPhysicalDevice_T *get_wrapped_VkPhysicalDevice( VkInstance_T *instance, VkPhysicalDevice_T *device ); +extern VkQueue_T *get_native_VkQueue( VkQueue_T *queue ); + #endif /* __cplusplus */ diff --git a/vrclient_x64/vrclient_x64/vrsystem_manual.c b/vrclient_x64/vrclient_x64/vrsystem_manual.c new file mode 100644 index 00000000..7b69347b --- /dev/null +++ b/vrclient_x64/vrclient_x64/vrsystem_manual.c @@ -0,0 +1,37 @@ +#include +#include +#include + +#include "windef.h" +#include "winbase.h" + +#include "wine/debug.h" +#include "vrclient_defs.h" +#include "vrclient_private.h" + +#include "flatapi.h" + +#include "struct_converters.h" + +void ivrsystem_get_output_device( void (*cpp_func)( void *, uint64_t *, ETextureType, VkInstance_T * ), + void *linux_side, uint64_t *out_device, ETextureType type, + VkInstance_T *wrapped_instance, unsigned int version ) +{ + switch (type) + { + case TextureType_Vulkan: + { + VkInstance_T *native_instance; + + native_instance = get_native_VkInstance( wrapped_instance ); + + cpp_func( linux_side, out_device, type, native_instance ); + + *out_device = (uint64_t)(intptr_t) + get_wrapped_VkPhysicalDevice( wrapped_instance, (VkPhysicalDevice_T *)(intptr_t)*out_device ); + + return; + } + default: cpp_func( linux_side, out_device, type, wrapped_instance ); return; + } +}