Skip to content

Commit

Permalink
vrclient: Substitute Win32 extensions in GetVulkanDeviceExtensionsReq…
Browse files Browse the repository at this point in the history
…uired().

CW-Bug-Id: #24553
  • Loading branch information
Paul Gofman committed Dec 5, 2024
1 parent 322e048 commit 8c3e86c
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion vrclient_x64/unix_vrcompositor_manual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#pragma makedep unix
#endif

WINE_DEFAULT_DEBUG_CHANNEL(vrclient);

static u_VRVulkanTextureData_t *unwrap_texture_vkdata( const w_VRVulkanTextureData_t *w_vkdata, u_VRVulkanTextureData_t *u_vkdata )
{
if (!w_vkdata) return NULL;
Expand Down Expand Up @@ -112,8 +114,60 @@ static u_Texture_t *unwrap_submit_texture_data( const w_VRTextureWithPoseAndDept
template <typename Params, typename Iface>
NTSTATUS get_vulkan_device_extensions_required( Params *params, Iface *iface )
{
static const struct
{
const char *unix_ext;
const char *win_ext;
}
exts[] =
{
{ "VK_KHR_external_memory_fd", "VK_KHR_external_memory_win32" },
{ "VK_KHR_external_semaphore_fd", "VK_KHR_external_semaphore_win32" },
};
VkPhysicalDevice_T *host_device = p_get_native_VkPhysicalDevice( params->pPhysicalDevice );
params->_ret = (uint32_t)iface->GetVulkanDeviceExtensionsRequired( host_device, params->pchValue, params->unBufferSize );
char buffer[2048], *p, *end, *next;
uint32_t i, len;

len = iface->GetVulkanDeviceExtensionsRequired( host_device, buffer, sizeof(buffer) );
if (!len || len > sizeof(buffer))
{
ERR( "len %u.\n", len );
params->_ret = 0;
return 0;
}

p = buffer;
end = p + strlen(p);
while (1)
{
while (isspace(*p)) ++p;
if (!*p) break;
next = p + 1;
while (*next && !isspace(*next)) ++next;
for (i = 0; i < ARRAY_SIZE(exts); ++i)
{
len = strlen( exts[i].unix_ext );
if (len == next - p && !memcmp( p, exts[i].unix_ext, len ))
{
len = strlen( exts[i].win_ext );
if (end - next + 1 + len + (p - buffer) > sizeof(buffer))
{
ERR( "buffer overflow.\n" );
params->_ret = 0;
return 0;
}
memmove( p + len, next, end - next + 1 );
memcpy( p, exts[i].win_ext, len );
end = p + len + (end - next);
next = p + len;
break;
}
}
p = next;
}
params->_ret = end - buffer + 1;
if (params->pchValue && params->unBufferSize >= params->_ret)
memcpy( params->pchValue, buffer, params->_ret );
return 0;
}

Expand Down

0 comments on commit 8c3e86c

Please sign in to comment.