mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-19 06:09:01 +00:00
Import Vulkan resources via named NT handle (#1895)
Add coverage to import Vulkan resources (memory and semaphore) in Windows via named NT handles. If no name is given during resource creation, then use NT handles for import. If a name is given, have an option to either use that name or get the NT handle and use that for import. Resolves KhronosGroup/OpenCL-Docs#943
This commit is contained in:
@@ -607,19 +607,20 @@ clExternalMemory::clExternalMemory(
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
log_info("Opaque file descriptors are not supported on Windows\n");
|
log_info("Opaque file descriptors are not supported on Windows\n");
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
#endif
|
#else
|
||||||
fd = (int)deviceMemory->getHandle(externalMemoryHandleType);
|
fd = (int)deviceMemory->getHandle(externalMemoryHandleType);
|
||||||
err = check_external_memory_handle_type(
|
err = check_external_memory_handle_type(
|
||||||
devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR);
|
devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR);
|
||||||
extMemProperties.push_back(
|
extMemProperties.push_back(
|
||||||
(cl_mem_properties)CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR);
|
(cl_mem_properties)CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR);
|
||||||
extMemProperties.push_back((cl_mem_properties)fd);
|
extMemProperties.push_back((cl_mem_properties)fd);
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT:
|
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT:
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
|
log_info("Opaque NT handles are only supported on Windows\n");
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
#else
|
#else
|
||||||
log_info(" Opaque NT handles are only supported on Windows\n");
|
|
||||||
handle = deviceMemory->getHandle(externalMemoryHandleType);
|
handle = deviceMemory->getHandle(externalMemoryHandleType);
|
||||||
err = check_external_memory_handle_type(
|
err = check_external_memory_handle_type(
|
||||||
devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR);
|
devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR);
|
||||||
@@ -628,11 +629,35 @@ clExternalMemory::clExternalMemory(
|
|||||||
extMemProperties.push_back((cl_mem_properties)handle);
|
extMemProperties.push_back((cl_mem_properties)handle);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT:
|
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT_NAME: {
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
|
log_info("Opaque NT handles are only supported on Windows\n");
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
#else
|
#else
|
||||||
|
const std::wstring &name = deviceMemory->getName();
|
||||||
|
if (name.size())
|
||||||
|
{
|
||||||
|
err = check_external_memory_handle_type(
|
||||||
|
devList[0],
|
||||||
|
CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_NAME_KHR);
|
||||||
|
extMemProperties.push_back(
|
||||||
|
(cl_mem_properties)
|
||||||
|
CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_NAME_KHR);
|
||||||
|
extMemProperties.push_back((cl_mem_properties)name.c_str());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Unsupported operation: import via "
|
||||||
|
"name but no name provided\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT:
|
||||||
|
#ifndef _WIN32
|
||||||
log_info("Opaque D3DKMT handles are only supported on Windows\n");
|
log_info("Opaque D3DKMT handles are only supported on Windows\n");
|
||||||
|
ASSERT(0);
|
||||||
|
#else
|
||||||
handle = deviceMemory->getHandle(externalMemoryHandleType);
|
handle = deviceMemory->getHandle(externalMemoryHandleType);
|
||||||
err = check_external_memory_handle_type(
|
err = check_external_memory_handle_type(
|
||||||
devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR);
|
devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR);
|
||||||
@@ -643,13 +668,13 @@ clExternalMemory::clExternalMemory(
|
|||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ASSERT(0);
|
|
||||||
log_error("Unsupported external memory handle type\n");
|
log_error("Unsupported external memory handle type\n");
|
||||||
|
ASSERT(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (CL_SUCCESS != err)
|
if (CL_SUCCESS != err)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Unsupported external memory type\n ");
|
throw std::runtime_error("Unsupported external memory type\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
extMemProperties.push_back(
|
extMemProperties.push_back(
|
||||||
@@ -664,7 +689,7 @@ clExternalMemory::clExternalMemory(
|
|||||||
if (CL_SUCCESS != err)
|
if (CL_SUCCESS != err)
|
||||||
{
|
{
|
||||||
log_error("clCreateBufferWithProperties failed with %d\n", err);
|
log_error("clCreateBufferWithProperties failed with %d\n", err);
|
||||||
throw std::runtime_error("clCreateBufferWithProperties failed ");
|
throw std::runtime_error("clCreateBufferWithProperties failed\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
clExternalMemoryImage::clExternalMemoryImage(
|
clExternalMemoryImage::clExternalMemoryImage(
|
||||||
@@ -704,7 +729,6 @@ clExternalMemoryImage::clExternalMemoryImage(
|
|||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT:
|
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT:
|
||||||
log_info("Opaque NT handles are only supported on Windows\n");
|
|
||||||
handle = deviceMemory.getHandle(externalMemoryHandleType);
|
handle = deviceMemory.getHandle(externalMemoryHandleType);
|
||||||
errcode_ret = check_external_memory_handle_type(
|
errcode_ret = check_external_memory_handle_type(
|
||||||
devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR);
|
devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR);
|
||||||
@@ -712,8 +736,26 @@ clExternalMemoryImage::clExternalMemoryImage(
|
|||||||
(cl_mem_properties)CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR);
|
(cl_mem_properties)CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR);
|
||||||
extMemProperties1.push_back((cl_mem_properties)handle);
|
extMemProperties1.push_back((cl_mem_properties)handle);
|
||||||
break;
|
break;
|
||||||
|
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT_NAME: {
|
||||||
|
const std::wstring &name = deviceMemory.getName();
|
||||||
|
if (name.size())
|
||||||
|
{
|
||||||
|
errcode_ret = check_external_memory_handle_type(
|
||||||
|
devList[0],
|
||||||
|
CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_NAME_KHR);
|
||||||
|
extMemProperties1.push_back(
|
||||||
|
(cl_mem_properties)
|
||||||
|
CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_NAME_KHR);
|
||||||
|
extMemProperties1.push_back((cl_mem_properties)name.c_str());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Unsupported operation: import via "
|
||||||
|
"name but no name provided\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT:
|
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT:
|
||||||
log_info("Opaque D3DKMT handles are only supported on Windows\n");
|
|
||||||
handle = deviceMemory.getHandle(externalMemoryHandleType);
|
handle = deviceMemory.getHandle(externalMemoryHandleType);
|
||||||
errcode_ret = check_external_memory_handle_type(
|
errcode_ret = check_external_memory_handle_type(
|
||||||
devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR);
|
devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR);
|
||||||
@@ -733,14 +775,15 @@ clExternalMemoryImage::clExternalMemoryImage(
|
|||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
ASSERT(0);
|
|
||||||
log_error("Unsupported external memory handle type\n");
|
log_error("Unsupported external memory handle type\n");
|
||||||
|
ASSERT(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (CL_SUCCESS != errcode_ret)
|
if (CL_SUCCESS != errcode_ret)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Unsupported external memory type\n ");
|
throw std::runtime_error("Unsupported external memory type\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set cl_image_desc
|
// Set cl_image_desc
|
||||||
size_t clImageFormatSize;
|
size_t clImageFormatSize;
|
||||||
cl_image_desc image_desc;
|
cl_image_desc image_desc;
|
||||||
@@ -753,7 +796,7 @@ clExternalMemoryImage::clExternalMemoryImage(
|
|||||||
&VulkanImageCreateInfo, image2D.getSize(), &img_format, &image_desc);
|
&VulkanImageCreateInfo, image2D.getSize(), &img_format, &image_desc);
|
||||||
if (CL_SUCCESS != errcode_ret)
|
if (CL_SUCCESS != errcode_ret)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("getCLImageInfoFromVkImageInfo failed!!!");
|
throw std::runtime_error("getCLImageInfoFromVkImageInfo failed\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// If OpenCL will assume linear, query the Vulkan image's row pitch,
|
// If OpenCL will assume linear, query the Vulkan image's row pitch,
|
||||||
@@ -776,7 +819,7 @@ clExternalMemoryImage::clExternalMemoryImage(
|
|||||||
&image_desc, NULL, &errcode_ret);
|
&image_desc, NULL, &errcode_ret);
|
||||||
if (CL_SUCCESS != errcode_ret)
|
if (CL_SUCCESS != errcode_ret)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("clCreateImageWithProperties failed!!!");
|
throw std::runtime_error("clCreateImageWithProperties failed\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -824,21 +867,24 @@ clExternalImportableSemaphore::clExternalImportableSemaphore(
|
|||||||
switch (externalSemaphoreHandleType)
|
switch (externalSemaphoreHandleType)
|
||||||
{
|
{
|
||||||
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD:
|
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD:
|
||||||
|
#ifdef _WIN32
|
||||||
|
log_info("Opaque file descriptors are not supported on Windows\n");
|
||||||
|
ASSERT(0);
|
||||||
|
#else
|
||||||
fd = (int)semaphore.getHandle(externalSemaphoreHandleType);
|
fd = (int)semaphore.getHandle(externalSemaphoreHandleType);
|
||||||
err = check_external_semaphore_handle_type(
|
err = check_external_semaphore_handle_type(
|
||||||
devList[0], CL_SEMAPHORE_HANDLE_OPAQUE_FD_KHR);
|
devList[0], CL_SEMAPHORE_HANDLE_OPAQUE_FD_KHR);
|
||||||
sema_props.push_back(
|
sema_props.push_back(
|
||||||
(cl_semaphore_properties_khr)CL_SEMAPHORE_HANDLE_OPAQUE_FD_KHR);
|
(cl_semaphore_properties_khr)CL_SEMAPHORE_HANDLE_OPAQUE_FD_KHR);
|
||||||
sema_props.push_back((cl_semaphore_properties_khr)fd);
|
sema_props.push_back((cl_semaphore_properties_khr)fd);
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_NT:
|
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_NT:
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
|
log_info("Opaque NT handles are only supported on Windows\n");
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
#else
|
#else
|
||||||
log_info(" Opaque NT handles are only supported on Windows\n");
|
handle = semaphore.getHandle(externalSemaphoreHandleType);
|
||||||
handle = semaphore.getName().size()
|
|
||||||
? NULL
|
|
||||||
: semaphore.getHandle(externalSemaphoreHandleType);
|
|
||||||
err = check_external_semaphore_handle_type(
|
err = check_external_semaphore_handle_type(
|
||||||
devList[0], CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KHR);
|
devList[0], CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KHR);
|
||||||
sema_props.push_back((cl_semaphore_properties_khr)
|
sema_props.push_back((cl_semaphore_properties_khr)
|
||||||
@@ -846,11 +892,34 @@ clExternalImportableSemaphore::clExternalImportableSemaphore(
|
|||||||
sema_props.push_back((cl_semaphore_properties_khr)handle);
|
sema_props.push_back((cl_semaphore_properties_khr)handle);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT:
|
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_NT_NAME: {
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
|
log_info("Opaque NT handles are only supported on Windows\n");
|
||||||
|
ASSERT(0);
|
||||||
|
#else
|
||||||
|
const std::wstring &name = semaphore.getName();
|
||||||
|
if (name.size())
|
||||||
|
{
|
||||||
|
err = check_external_semaphore_handle_type(
|
||||||
|
devList[0], CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_NAME_KHR);
|
||||||
|
sema_props.push_back(
|
||||||
|
(cl_semaphore_properties_khr)
|
||||||
|
CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_NAME_KHR);
|
||||||
|
sema_props.push_back((cl_semaphore_properties_khr)name.c_str());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Unsupported operation: import via "
|
||||||
|
"name but no name provided\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT:
|
||||||
|
#ifndef _WIN32
|
||||||
|
log_info("Opaque D3DKMT handles are only supported on Windows\n");
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
#else
|
#else
|
||||||
log_info(" Opaque D3DKMT handles are only supported on Windows\n");
|
|
||||||
handle = semaphore.getHandle(externalSemaphoreHandleType);
|
handle = semaphore.getHandle(externalSemaphoreHandleType);
|
||||||
err = check_external_semaphore_handle_type(
|
err = check_external_semaphore_handle_type(
|
||||||
devList[0], CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KMT_KHR);
|
devList[0], CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KMT_KHR);
|
||||||
@@ -868,8 +937,8 @@ clExternalImportableSemaphore::clExternalImportableSemaphore(
|
|||||||
sema_props.push_back(static_cast<cl_semaphore_properties_khr>(-1));
|
sema_props.push_back(static_cast<cl_semaphore_properties_khr>(-1));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ASSERT(0);
|
|
||||||
log_error("Unsupported external memory handle type\n");
|
log_error("Unsupported external memory handle type\n");
|
||||||
|
ASSERT(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (CL_SUCCESS != err)
|
if (CL_SUCCESS != err)
|
||||||
|
|||||||
@@ -1976,35 +1976,51 @@ public:
|
|||||||
~WindowsSecurityAttributes();
|
~WindowsSecurityAttributes();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
WindowsSecurityAttributes::WindowsSecurityAttributes()
|
WindowsSecurityAttributes::WindowsSecurityAttributes()
|
||||||
{
|
{
|
||||||
|
#define CHECK(ok, msg) \
|
||||||
|
if (!ok) \
|
||||||
|
{ \
|
||||||
|
throw std::runtime_error(msg); \
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL ok;
|
||||||
|
HANDLE tokenHandle;
|
||||||
|
|
||||||
|
ok = OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &tokenHandle);
|
||||||
|
CHECK(ok, "Failed to open process access token");
|
||||||
|
|
||||||
|
DWORD tokenInformationLength = 0;
|
||||||
|
GetTokenInformation(tokenHandle, TokenDefaultDacl, NULL, 0,
|
||||||
|
&tokenInformationLength);
|
||||||
|
CHECK(tokenInformationLength,
|
||||||
|
"Failed to retrieve TokenDefaultDacl info buffer length");
|
||||||
|
|
||||||
m_winPSecurityDescriptor = (PSECURITY_DESCRIPTOR)calloc(
|
m_winPSecurityDescriptor = (PSECURITY_DESCRIPTOR)calloc(
|
||||||
1, SECURITY_DESCRIPTOR_MIN_LENGTH + 2 * sizeof(void **));
|
1, SECURITY_DESCRIPTOR_MIN_LENGTH + tokenInformationLength);
|
||||||
// CHECK_NEQ(m_winPSecurityDescriptor, (PSECURITY_DESCRIPTOR)NULL);
|
assert(m_winPSecurityDescriptor != (PSECURITY_DESCRIPTOR)NULL);
|
||||||
PSID *ppSID = (PSID *)((PBYTE)m_winPSecurityDescriptor
|
|
||||||
+ SECURITY_DESCRIPTOR_MIN_LENGTH);
|
TOKEN_DEFAULT_DACL *pTokenDefaultDacl =
|
||||||
PACL *ppACL = (PACL *)((PBYTE)ppSID + sizeof(PSID *));
|
reinterpret_cast<TOKEN_DEFAULT_DACL *>(
|
||||||
InitializeSecurityDescriptor(m_winPSecurityDescriptor,
|
(PBYTE)m_winPSecurityDescriptor + SECURITY_DESCRIPTOR_MIN_LENGTH);
|
||||||
SECURITY_DESCRIPTOR_REVISION);
|
ok = GetTokenInformation(tokenHandle, TokenDefaultDacl, pTokenDefaultDacl,
|
||||||
SID_IDENTIFIER_AUTHORITY sidIdentifierAuthority =
|
tokenInformationLength, &tokenInformationLength);
|
||||||
SECURITY_WORLD_SID_AUTHORITY;
|
CHECK(ok, "Failed to retrieve TokenDefaultDacl info of access token");
|
||||||
AllocateAndInitializeSid(&sidIdentifierAuthority, 1, SECURITY_WORLD_RID, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, ppSID);
|
ok = InitializeSecurityDescriptor(m_winPSecurityDescriptor,
|
||||||
EXPLICIT_ACCESS explicitAccess;
|
SECURITY_DESCRIPTOR_REVISION);
|
||||||
ZeroMemory(&explicitAccess, sizeof(EXPLICIT_ACCESS));
|
CHECK(ok, "Failed to init security descriptor");
|
||||||
explicitAccess.grfAccessPermissions =
|
|
||||||
STANDARD_RIGHTS_ALL | SPECIFIC_RIGHTS_ALL;
|
ok = SetSecurityDescriptorDacl(m_winPSecurityDescriptor, TRUE,
|
||||||
explicitAccess.grfAccessMode = SET_ACCESS;
|
pTokenDefaultDacl->DefaultDacl, FALSE);
|
||||||
explicitAccess.grfInheritance = INHERIT_ONLY;
|
CHECK(ok, "Failed to set DACL info for given security descriptor");
|
||||||
explicitAccess.Trustee.TrusteeForm = TRUSTEE_IS_SID;
|
|
||||||
explicitAccess.Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
|
|
||||||
explicitAccess.Trustee.ptstrName = (LPTSTR)*ppSID;
|
|
||||||
SetEntriesInAcl(1, &explicitAccess, NULL, ppACL);
|
|
||||||
SetSecurityDescriptorDacl(m_winPSecurityDescriptor, TRUE, *ppACL, FALSE);
|
|
||||||
m_winSecurityAttributes.nLength = sizeof(m_winSecurityAttributes);
|
m_winSecurityAttributes.nLength = sizeof(m_winSecurityAttributes);
|
||||||
m_winSecurityAttributes.lpSecurityDescriptor = m_winPSecurityDescriptor;
|
m_winSecurityAttributes.lpSecurityDescriptor = m_winPSecurityDescriptor;
|
||||||
m_winSecurityAttributes.bInheritHandle = TRUE;
|
m_winSecurityAttributes.bInheritHandle = TRUE;
|
||||||
|
|
||||||
|
CloseHandle(tokenHandle);
|
||||||
|
#undef CHECK_WIN
|
||||||
}
|
}
|
||||||
|
|
||||||
SECURITY_ATTRIBUTES *WindowsSecurityAttributes::operator&()
|
SECURITY_ATTRIBUTES *WindowsSecurityAttributes::operator&()
|
||||||
@@ -2014,17 +2030,6 @@ SECURITY_ATTRIBUTES *WindowsSecurityAttributes::operator&()
|
|||||||
|
|
||||||
WindowsSecurityAttributes::~WindowsSecurityAttributes()
|
WindowsSecurityAttributes::~WindowsSecurityAttributes()
|
||||||
{
|
{
|
||||||
PSID *ppSID = (PSID *)((PBYTE)m_winPSecurityDescriptor
|
|
||||||
+ SECURITY_DESCRIPTOR_MIN_LENGTH);
|
|
||||||
PACL *ppACL = (PACL *)((PBYTE)ppSID + sizeof(PSID *));
|
|
||||||
if (*ppSID)
|
|
||||||
{
|
|
||||||
FreeSid(*ppSID);
|
|
||||||
}
|
|
||||||
if (*ppACL)
|
|
||||||
{
|
|
||||||
LocalFree(*ppACL);
|
|
||||||
}
|
|
||||||
free(m_winPSecurityDescriptor);
|
free(m_winPSecurityDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2039,8 +2044,9 @@ VulkanDeviceMemory::VulkanDeviceMemory(const VulkanDeviceMemory &deviceMemory)
|
|||||||
VulkanDeviceMemory::VulkanDeviceMemory(
|
VulkanDeviceMemory::VulkanDeviceMemory(
|
||||||
const VulkanDevice &device, uint64_t size,
|
const VulkanDevice &device, uint64_t size,
|
||||||
const VulkanMemoryType &memoryType,
|
const VulkanMemoryType &memoryType,
|
||||||
VulkanExternalMemoryHandleType externalMemoryHandleType, const void *name)
|
VulkanExternalMemoryHandleType externalMemoryHandleType,
|
||||||
: m_device(device), m_size(size), m_isDedicated(false)
|
const std::wstring name)
|
||||||
|
: m_device(device), m_size(size), m_isDedicated(false), m_name(name)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
WindowsSecurityAttributes winSecurityAttributes;
|
WindowsSecurityAttributes winSecurityAttributes;
|
||||||
@@ -2052,8 +2058,15 @@ VulkanDeviceMemory::VulkanDeviceMemory(
|
|||||||
vkExportMemoryWin32HandleInfoKHR.pAttributes = &winSecurityAttributes;
|
vkExportMemoryWin32HandleInfoKHR.pAttributes = &winSecurityAttributes;
|
||||||
vkExportMemoryWin32HandleInfoKHR.dwAccess =
|
vkExportMemoryWin32HandleInfoKHR.dwAccess =
|
||||||
DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE;
|
DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE;
|
||||||
vkExportMemoryWin32HandleInfoKHR.name = (LPCWSTR)name;
|
vkExportMemoryWin32HandleInfoKHR.name = NULL;
|
||||||
|
|
||||||
|
if (externalMemoryHandleType
|
||||||
|
== VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT_NAME)
|
||||||
|
{
|
||||||
|
vkExportMemoryWin32HandleInfoKHR.name = (LPCWSTR)m_name.c_str();
|
||||||
|
externalMemoryHandleType =
|
||||||
|
VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
VkExportMemoryAllocateInfoKHR vkExportMemoryAllocateInfoKHR = {};
|
VkExportMemoryAllocateInfoKHR vkExportMemoryAllocateInfoKHR = {};
|
||||||
@@ -2083,9 +2096,10 @@ VulkanDeviceMemory::VulkanDeviceMemory(
|
|||||||
VulkanDeviceMemory::VulkanDeviceMemory(
|
VulkanDeviceMemory::VulkanDeviceMemory(
|
||||||
const VulkanDevice &device, const VulkanImage &image,
|
const VulkanDevice &device, const VulkanImage &image,
|
||||||
const VulkanMemoryType &memoryType,
|
const VulkanMemoryType &memoryType,
|
||||||
VulkanExternalMemoryHandleType externalMemoryHandleType, const void *name)
|
VulkanExternalMemoryHandleType externalMemoryHandleType,
|
||||||
|
const std::wstring name)
|
||||||
: m_device(device), m_size(image.getSize()),
|
: m_device(device), m_size(image.getSize()),
|
||||||
m_isDedicated(image.isDedicated())
|
m_isDedicated(image.isDedicated()), m_name(name)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
WindowsSecurityAttributes winSecurityAttributes;
|
WindowsSecurityAttributes winSecurityAttributes;
|
||||||
@@ -2097,8 +2111,15 @@ VulkanDeviceMemory::VulkanDeviceMemory(
|
|||||||
vkExportMemoryWin32HandleInfoKHR.pAttributes = &winSecurityAttributes;
|
vkExportMemoryWin32HandleInfoKHR.pAttributes = &winSecurityAttributes;
|
||||||
vkExportMemoryWin32HandleInfoKHR.dwAccess =
|
vkExportMemoryWin32HandleInfoKHR.dwAccess =
|
||||||
DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE;
|
DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE;
|
||||||
vkExportMemoryWin32HandleInfoKHR.name = (LPCWSTR)name;
|
vkExportMemoryWin32HandleInfoKHR.name = NULL;
|
||||||
|
|
||||||
|
if (externalMemoryHandleType
|
||||||
|
== VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT_NAME)
|
||||||
|
{
|
||||||
|
vkExportMemoryWin32HandleInfoKHR.name = (LPCWSTR)m_name.c_str();
|
||||||
|
externalMemoryHandleType =
|
||||||
|
VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
VkExportMemoryAllocateInfoKHR vkExportMemoryAllocateInfoKHR = {};
|
VkExportMemoryAllocateInfoKHR vkExportMemoryAllocateInfoKHR = {};
|
||||||
@@ -2145,9 +2166,10 @@ VulkanDeviceMemory::VulkanDeviceMemory(
|
|||||||
VulkanDeviceMemory::VulkanDeviceMemory(
|
VulkanDeviceMemory::VulkanDeviceMemory(
|
||||||
const VulkanDevice &device, const VulkanBuffer &buffer,
|
const VulkanDevice &device, const VulkanBuffer &buffer,
|
||||||
const VulkanMemoryType &memoryType,
|
const VulkanMemoryType &memoryType,
|
||||||
VulkanExternalMemoryHandleType externalMemoryHandleType, const void *name)
|
VulkanExternalMemoryHandleType externalMemoryHandleType,
|
||||||
|
const std::wstring name)
|
||||||
: m_device(device), m_size(buffer.getSize()),
|
: m_device(device), m_size(buffer.getSize()),
|
||||||
m_isDedicated(buffer.isDedicated())
|
m_isDedicated(buffer.isDedicated()), m_name(name)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
WindowsSecurityAttributes winSecurityAttributes;
|
WindowsSecurityAttributes winSecurityAttributes;
|
||||||
@@ -2159,8 +2181,15 @@ VulkanDeviceMemory::VulkanDeviceMemory(
|
|||||||
vkExportMemoryWin32HandleInfoKHR.pAttributes = &winSecurityAttributes;
|
vkExportMemoryWin32HandleInfoKHR.pAttributes = &winSecurityAttributes;
|
||||||
vkExportMemoryWin32HandleInfoKHR.dwAccess =
|
vkExportMemoryWin32HandleInfoKHR.dwAccess =
|
||||||
DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE;
|
DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE;
|
||||||
vkExportMemoryWin32HandleInfoKHR.name = (LPCWSTR)name;
|
vkExportMemoryWin32HandleInfoKHR.name = NULL;
|
||||||
|
|
||||||
|
if (externalMemoryHandleType
|
||||||
|
== VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT_NAME)
|
||||||
|
{
|
||||||
|
vkExportMemoryWin32HandleInfoKHR.name = (LPCWSTR)m_name.c_str();
|
||||||
|
externalMemoryHandleType =
|
||||||
|
VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
VkExportMemoryAllocateInfoKHR vkExportMemoryAllocateInfoKHR = {};
|
VkExportMemoryAllocateInfoKHR vkExportMemoryAllocateInfoKHR = {};
|
||||||
@@ -2291,6 +2320,8 @@ void VulkanDeviceMemory::bindImage(const VulkanImage &image, uint64_t offset)
|
|||||||
vkBindImageMemory(m_device, image, m_vkDeviceMemory, offset);
|
vkBindImageMemory(m_device, image, m_vkDeviceMemory, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::wstring &VulkanDeviceMemory::getName() const { return m_name; }
|
||||||
|
|
||||||
VulkanDeviceMemory::operator VkDeviceMemory() const { return m_vkDeviceMemory; }
|
VulkanDeviceMemory::operator VkDeviceMemory() const { return m_vkDeviceMemory; }
|
||||||
|
|
||||||
////////////////////////////////////
|
////////////////////////////////////
|
||||||
@@ -2318,8 +2349,15 @@ VulkanSemaphore::VulkanSemaphore(
|
|||||||
vkExportSemaphoreWin32HandleInfoKHR.pAttributes = &winSecurityAttributes;
|
vkExportSemaphoreWin32HandleInfoKHR.pAttributes = &winSecurityAttributes;
|
||||||
vkExportSemaphoreWin32HandleInfoKHR.dwAccess =
|
vkExportSemaphoreWin32HandleInfoKHR.dwAccess =
|
||||||
DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE;
|
DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE;
|
||||||
vkExportSemaphoreWin32HandleInfoKHR.name =
|
vkExportSemaphoreWin32HandleInfoKHR.name = NULL;
|
||||||
m_name.size() ? (LPCWSTR)m_name.c_str() : NULL;
|
|
||||||
|
if (externalSemaphoreHandleType
|
||||||
|
== VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_NT_NAME)
|
||||||
|
{
|
||||||
|
vkExportSemaphoreWin32HandleInfoKHR.name = (LPCWSTR)m_name.c_str();
|
||||||
|
externalSemaphoreHandleType =
|
||||||
|
VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_NT;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
VkExportSemaphoreCreateInfoKHR vkExportSemaphoreCreateInfoKHR = {};
|
VkExportSemaphoreCreateInfoKHR vkExportSemaphoreCreateInfoKHR = {};
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "vulkan_list_map.hpp"
|
#include "vulkan_list_map.hpp"
|
||||||
#include "vulkan_api_list.hpp"
|
#include "vulkan_api_list.hpp"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
class VulkanInstance {
|
class VulkanInstance {
|
||||||
friend const VulkanInstance &getVulkanInstance();
|
friend const VulkanInstance &getVulkanInstance();
|
||||||
@@ -581,7 +582,7 @@ protected:
|
|||||||
VkDeviceMemory m_vkDeviceMemory;
|
VkDeviceMemory m_vkDeviceMemory;
|
||||||
uint64_t m_size;
|
uint64_t m_size;
|
||||||
bool m_isDedicated;
|
bool m_isDedicated;
|
||||||
|
const std::wstring m_name;
|
||||||
|
|
||||||
VulkanDeviceMemory(const VulkanDeviceMemory &deviceMemory);
|
VulkanDeviceMemory(const VulkanDeviceMemory &deviceMemory);
|
||||||
|
|
||||||
@@ -590,17 +591,17 @@ public:
|
|||||||
const VulkanMemoryType &memoryType,
|
const VulkanMemoryType &memoryType,
|
||||||
VulkanExternalMemoryHandleType externalMemoryHandleType =
|
VulkanExternalMemoryHandleType externalMemoryHandleType =
|
||||||
VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_NONE,
|
VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_NONE,
|
||||||
const void *name = NULL);
|
const std::wstring name = L"");
|
||||||
VulkanDeviceMemory(const VulkanDevice &device, const VulkanImage &image,
|
VulkanDeviceMemory(const VulkanDevice &device, const VulkanImage &image,
|
||||||
const VulkanMemoryType &memoryType,
|
const VulkanMemoryType &memoryType,
|
||||||
VulkanExternalMemoryHandleType externalMemoryHandleType =
|
VulkanExternalMemoryHandleType externalMemoryHandleType =
|
||||||
VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_NONE,
|
VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_NONE,
|
||||||
const void *name = NULL);
|
const std::wstring name = L"");
|
||||||
VulkanDeviceMemory(const VulkanDevice &device, const VulkanBuffer &buffer,
|
VulkanDeviceMemory(const VulkanDevice &device, const VulkanBuffer &buffer,
|
||||||
const VulkanMemoryType &memoryType,
|
const VulkanMemoryType &memoryType,
|
||||||
VulkanExternalMemoryHandleType externalMemoryHandleType =
|
VulkanExternalMemoryHandleType externalMemoryHandleType =
|
||||||
VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_NONE,
|
VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_NONE,
|
||||||
const void *name = NULL);
|
const std::wstring name = L"");
|
||||||
virtual ~VulkanDeviceMemory();
|
virtual ~VulkanDeviceMemory();
|
||||||
uint64_t getSize() const;
|
uint64_t getSize() const;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@@ -615,6 +616,7 @@ public:
|
|||||||
void unmap();
|
void unmap();
|
||||||
void bindBuffer(const VulkanBuffer &buffer, uint64_t offset = 0);
|
void bindBuffer(const VulkanBuffer &buffer, uint64_t offset = 0);
|
||||||
void bindImage(const VulkanImage &image, uint64_t offset = 0);
|
void bindImage(const VulkanImage &image, uint64_t offset = 0);
|
||||||
|
const std::wstring &getName() const;
|
||||||
operator VkDeviceMemory() const;
|
operator VkDeviceMemory() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#define VULKAN_MIN_BUFFER_OFFSET_COPY_ALIGNMENT 4
|
#define VULKAN_MIN_BUFFER_OFFSET_COPY_ALIGNMENT 4
|
||||||
#define VULKAN_REMAINING_MIP_LEVELS VK_REMAINING_MIP_LEVELS
|
#define VULKAN_REMAINING_MIP_LEVELS VK_REMAINING_MIP_LEVELS
|
||||||
#define VULKAN_REMAINING_ARRAY_LAYERS VK_REMAINING_ARRAY_LAYERS
|
#define VULKAN_REMAINING_ARRAY_LAYERS VK_REMAINING_ARRAY_LAYERS
|
||||||
|
#define VULKAN_HANDLE_TYPE_OPAQUE_WIN32_NT_NAME_BIT 0x10000000
|
||||||
|
|
||||||
class VulkanInstance;
|
class VulkanInstance;
|
||||||
class VulkanPhysicalDevice;
|
class VulkanPhysicalDevice;
|
||||||
@@ -159,7 +160,9 @@ enum VulkanExternalMemoryHandleType
|
|||||||
VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR,
|
VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR,
|
||||||
VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT_KMT =
|
VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT_KMT =
|
||||||
VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR
|
VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR
|
||||||
| VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR
|
| VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR,
|
||||||
|
VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT_NAME =
|
||||||
|
VULKAN_HANDLE_TYPE_OPAQUE_WIN32_NT_NAME_BIT
|
||||||
};
|
};
|
||||||
|
|
||||||
enum VulkanExternalSemaphoreHandleType
|
enum VulkanExternalSemaphoreHandleType
|
||||||
@@ -172,7 +175,9 @@ enum VulkanExternalSemaphoreHandleType
|
|||||||
VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT =
|
VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT =
|
||||||
VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR,
|
VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR,
|
||||||
VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD =
|
VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD =
|
||||||
VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
|
VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR,
|
||||||
|
VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_NT_NAME =
|
||||||
|
VULKAN_HANDLE_TYPE_OPAQUE_WIN32_NT_NAME_BIT
|
||||||
};
|
};
|
||||||
|
|
||||||
enum VulkanBufferUsage
|
enum VulkanBufferUsage
|
||||||
|
|||||||
Reference in New Issue
Block a user