Skip to content

Commit

Permalink
wineopenxr: change instance type to session type
Browse files Browse the repository at this point in the history
Graphics in OpenXR are bound by their sessions, not by their instances.

ValveSoftware#7424
  • Loading branch information
Supreeeme authored and ivyl committed May 23, 2024
1 parent 1df6335 commit 0efcd7d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
24 changes: 9 additions & 15 deletions wineopenxr/openxr.c
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ XrResult WINAPI wine_xrCreateInstance(const XrInstanceCreateInfo *createInfo, Xr
{
XrResult res;
struct wine_XrInstance *wine_instance;
uint32_t i, j, count, type = 0;
uint32_t i, j, count = 0;
XrInstanceCreateInfo our_createInfo;
const char *ext_name;
char **new_list;
Expand All @@ -773,15 +773,6 @@ XrResult WINAPI wine_xrCreateInstance(const XrInstanceCreateInfo *createInfo, Xr
WINE_TRACE("Incoming extensions:\n");
for(i = 0; i < createInfo->enabledExtensionCount; ++i){
WINE_TRACE(" -%s\n", createInfo->enabledExtensionNames[i]);
if(!strcmp(createInfo->enabledExtensionNames[i], "XR_KHR_D3D11_enable")){
type = INSTANCE_TYPE_D3D11;
}else if(!strcmp(createInfo->enabledExtensionNames[i], "XR_KHR_D3D12_enable")){
type = INSTANCE_TYPE_D3D12;
}else if(!strcmp(createInfo->enabledExtensionNames[i], "XR_KHR_vulkan_enable")){
type = INSTANCE_TYPE_VULKAN;
}else if(!strcmp(createInfo->enabledExtensionNames[i], "XR_KHR_opengl_enable")){
type = INSTANCE_TYPE_OPENGL;
}
}

new_list = heap_alloc(createInfo->enabledExtensionCount * sizeof(*new_list));
Expand Down Expand Up @@ -833,7 +824,6 @@ XrResult WINAPI wine_xrCreateInstance(const XrInstanceCreateInfo *createInfo, Xr
ALL_XR_INSTANCE_FUNCS()
#undef USE_XR_FUNC

wine_instance->instance_type = type;
*instance = (XrInstance)wine_instance;

cleanup:
Expand Down Expand Up @@ -934,6 +924,7 @@ XrResult WINAPI wine_xrCreateSession(XrInstance instance, const XrSessionCreateI
XrResult res;
XrSessionCreateInfo our_create_info;
XrGraphicsBindingVulkanKHR our_vk_binding;
uint32_t session_type = 0;

WINE_TRACE("%p, %p, %p\n", instance, createInfo, session);

Expand All @@ -951,6 +942,7 @@ XrResult WINAPI wine_xrCreateSession(XrInstance instance, const XrSessionCreateI
our_create_info = *createInfo;
our_create_info.next = &our_vk_binding;
createInfo = &our_create_info;
session_type = SESSION_TYPE_VULKAN;

break;
}
Expand Down Expand Up @@ -988,6 +980,7 @@ XrResult WINAPI wine_xrCreateSession(XrInstance instance, const XrSessionCreateI
our_create_info = *createInfo;
our_create_info.next = &our_vk_binding;
createInfo = &our_create_info;
session_type = SESSION_TYPE_D3D11;

break;
}
Expand All @@ -1007,6 +1000,7 @@ XrResult WINAPI wine_xrCreateSession(XrInstance instance, const XrSessionCreateI
}

wine_session->wine_instance = wine_instance;
wine_session->session_type = session_type;

EnterCriticalSection(&session_list_lock);

Expand Down Expand Up @@ -1964,7 +1958,7 @@ XrResult WINAPI wine_xrEnumerateSwapchainFormats(XrSession session, uint32_t for

WINE_TRACE("%p, %u, %p, %p\n", session, formatCapacityInput, formatCountOutput, formats);

if (wine_session->wine_instance->instance_type != INSTANCE_TYPE_D3D11)
if (wine_session->session_type != SESSION_TYPE_D3D11)
return xrEnumerateSwapchainFormats(wine_session->session, formatCapacityInput, formatCountOutput, formats);

res = xrEnumerateSwapchainFormats(wine_session->session, 0, &real_format_count, NULL);
Expand Down Expand Up @@ -2012,7 +2006,7 @@ XrResult WINAPI wine_xrCreateSwapchain(XrSession session, const XrSwapchainCreat
wine_swapchain = heap_alloc_zero(sizeof(*wine_swapchain));
wine_swapchain->create_info = *createInfo;

if(wine_session->wine_instance->instance_type == INSTANCE_TYPE_D3D11){
if(wine_session->session_type == SESSION_TYPE_D3D11){
our_createInfo = *createInfo;
our_createInfo.format = map_format_dxgi_to_vulkan(createInfo->format);
if(our_createInfo.format == VK_FORMAT_UNDEFINED){
Expand Down Expand Up @@ -2091,7 +2085,7 @@ XrResult WINAPI wine_xrEnumerateSwapchainImages(XrSwapchain swapchain, uint32_t
WINE_TRACE("%p, %u, %p, %p\n", swapchain, imageCapacityInput, imageCountOutput, images);

if(images){
if(wine_instance->instance_type == INSTANCE_TYPE_D3D11){
if(wine_swapchain->wine_session->session_type == SESSION_TYPE_D3D11){
our_images = heap_alloc(sizeof(*our_images) * imageCapacityInput);
for(i = 0; i < imageCapacityInput; ++i){
our_images[i].type = XR_TYPE_SWAPCHAIN_IMAGE_VULKAN_KHR;
Expand All @@ -2103,7 +2097,7 @@ XrResult WINAPI wine_xrEnumerateSwapchainImages(XrSwapchain swapchain, uint32_t
res = xrEnumerateSwapchainImages(wine_swapchain->swapchain, imageCapacityInput, imageCountOutput, images);

if(images && res == XR_SUCCESS){
if(wine_instance->instance_type == INSTANCE_TYPE_D3D11){
if(wine_swapchain->wine_session->session_type == SESSION_TYPE_D3D11){
XrSwapchainImageD3D11KHR *their_d3d11;
D3D11_TEXTURE2D_DESC1 desc;

Expand Down
10 changes: 5 additions & 5 deletions wineopenxr/openxr_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

#include "wine/list.h"

#define INSTANCE_TYPE_VULKAN 1
#define INSTANCE_TYPE_OPENGL 2
#define INSTANCE_TYPE_D3D11 3
#define INSTANCE_TYPE_D3D12 4
#define SESSION_TYPE_VULKAN 1
#define SESSION_TYPE_OPENGL 2
#define SESSION_TYPE_D3D11 3
#define SESSION_TYPE_D3D12 4

struct IDXGIVkInteropDevice2;
typedef struct IDXGIVkInteropDevice2 IDXGIVkInteropDevice2;
Expand All @@ -17,7 +17,6 @@ typedef struct wine_XrInstance {
VkInstance vk_instance;
VkPhysicalDevice vk_phys_dev;

uint32_t instance_type;
XrSystemId systemId;

IDXGIVkInteropDevice2 *dxvk_device;
Expand All @@ -36,6 +35,7 @@ typedef struct wine_XrSession {
XrSession session;
struct wine_XrInstance *wine_instance;

uint32_t session_type;
struct list entry;

uint32_t composition_layer_count;
Expand Down

0 comments on commit 0efcd7d

Please sign in to comment.