From ce58c13ffab34b0725af2d7394ca901426609f6c Mon Sep 17 00:00:00 2001 From: ROCm CI Service Account <66695075+rocm-ci@users.noreply.github.com> Date: Sat, 8 Jul 2023 20:53:51 +0530 Subject: [PATCH] SWDEV-403382 - fix errors for vulkan test (#341) Change-Id: Icfe4c0cf1745c18caeae419e66544b6770f33e70 [ROCm/hip-tests commit: c67e5dae232519a5fe59caa4012d37a7c90ca955] --- .../catch/unit/vulkan_interop/vulkan_test.cc | 13 +-- .../catch/unit/vulkan_interop/vulkan_test.hh | 80 ++++++++++++++++++- 2 files changed, 87 insertions(+), 6 deletions(-) diff --git a/projects/hip-tests/catch/unit/vulkan_interop/vulkan_test.cc b/projects/hip-tests/catch/unit/vulkan_interop/vulkan_test.cc index 4252916177..9bb61eff31 100644 --- a/projects/hip-tests/catch/unit/vulkan_interop/vulkan_test.cc +++ b/projects/hip-tests/catch/unit/vulkan_interop/vulkan_test.cc @@ -24,6 +24,8 @@ THE SOFTWARE. #include #include + + VkFence VulkanTest::CreateFence() { VkFence fence; VkFenceCreateInfo fence_create_info = {}; @@ -80,7 +82,7 @@ hipExternalMemoryHandleDesc VulkanTest::BuildMemoryDescriptor(VkDeviceMemory vk_ hipExternalMemoryHandleDesc mem_handle_desc = {}; mem_handle_desc.type = VulkanMemHandleTypeToHIPHandleType(); #ifdef _WIN64 - mem_handle_desc.handle.win32.handle = GetMemoryHandle(ck_mem); + mem_handle_desc.handle.win32.handle = GetMemoryHandle(vk_mem); #else mem_handle_desc.handle.fd = GetMemoryHandle(vk_mem); #endif @@ -170,7 +172,7 @@ bool VulkanTest::CheckExtensionSupport(std::vector expected_extensi std::back_inserter(supported_extensions), [](const auto& p) { return p.extensionName; }); - constexpr auto p = [](const char* l, const char* r) { return strcmp(l, r) < 0; }; + auto p = [](const char* l, const char* r) { return strcmp(l, r) < 0; }; std::sort(expected_extensions.begin(), expected_extensions.end(), p); std::sort(supported_extensions.begin(), supported_extensions.end(), p); @@ -328,7 +330,7 @@ int VulkanTest::GetSemaphoreHandle(VkSemaphore semaphore) { #ifdef _WIN64 HANDLE VulkanTest::GetMemoryHandle(VkDeviceMemory memory) { - Handle handle = 0; + HANDLE handle = 0; VkMemoryGetWin32HandleInfoKHR vkMemoryGetWin32HandleInfoKHR = {}; vkMemoryGetWin32HandleInfoKHR.sType = VK_STRUCTURE_TYPE_MEMORY_GET_WIN32_HANDLE_INFO_KHR; @@ -336,7 +338,7 @@ VulkanTest::GetMemoryHandle(VkDeviceMemory memory) { vkMemoryGetWin32HandleInfoKHR.handleType = _mem_handle_type; PFN_vkGetMemoryWin32HandleKHR fpGetMemoryWin32HandleKHR = - (PFN_vkGetMemoryWin32HandleKHR)vkGetDeviceProcAddr(m_device, "vkGetMemoryWin32HandleKHR"); + (PFN_vkGetMemoryWin32HandleKHR)vkGetDeviceProcAddr(_device, "vkGetMemoryWin32HandleKHR"); if (!fpGetMemoryWin32HandleKHR) { throw std::runtime_error("Failed to retrieve vkGetMemoryWin32HandleKHR"); @@ -407,4 +409,5 @@ hipExternalSemaphore_t ImportBinarySemaphore(VulkanTest& vkt) { HIP_CHECK(hipImportExternalSemaphore(&hip_ext_semaphore, &sem_handle_desc)); return hip_ext_semaphore; -} \ No newline at end of file +} + diff --git a/projects/hip-tests/catch/unit/vulkan_interop/vulkan_test.hh b/projects/hip-tests/catch/unit/vulkan_interop/vulkan_test.hh index e223e8cd2b..82123958f6 100644 --- a/projects/hip-tests/catch/unit/vulkan_interop/vulkan_test.hh +++ b/projects/hip-tests/catch/unit/vulkan_interop/vulkan_test.hh @@ -20,12 +20,24 @@ THE SOFTWARE. #pragma once #include -#include + #ifdef _WIN64 + +#include +#include #include + +#include +#include +#include +#include +#include + #endif +#include +#include #include #include @@ -39,6 +51,72 @@ THE SOFTWARE. } \ } +#ifdef _WIN64 +class WindowsSecurityAttributes +{ +protected: + SECURITY_ATTRIBUTES m_winSecurityAttributes; + PSECURITY_DESCRIPTOR m_winPSecurityDescriptor; + +public: +WindowsSecurityAttributes::WindowsSecurityAttributes() +{ + m_winPSecurityDescriptor = (PSECURITY_DESCRIPTOR)calloc(1, SECURITY_DESCRIPTOR_MIN_LENGTH + 2 * sizeof(void **)); + if (!m_winPSecurityDescriptor) { + throw std::runtime_error("Failed to allocate memory for security descriptor"); + } + + PSID *ppSID = (PSID *)((PBYTE)m_winPSecurityDescriptor + SECURITY_DESCRIPTOR_MIN_LENGTH); + PACL *ppACL = (PACL *)((PBYTE)ppSID + sizeof(PSID *)); + + InitializeSecurityDescriptor(m_winPSecurityDescriptor, SECURITY_DESCRIPTOR_REVISION); + + SID_IDENTIFIER_AUTHORITY sidIdentifierAuthority = SECURITY_WORLD_SID_AUTHORITY; + AllocateAndInitializeSid(&sidIdentifierAuthority, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, ppSID); + + EXPLICIT_ACCESS explicitAccess; + ZeroMemory(&explicitAccess, sizeof(EXPLICIT_ACCESS)); + explicitAccess.grfAccessPermissions = STANDARD_RIGHTS_ALL | SPECIFIC_RIGHTS_ALL; + explicitAccess.grfAccessMode = SET_ACCESS; + explicitAccess.grfInheritance = INHERIT_ONLY; + 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.lpSecurityDescriptor = m_winPSecurityDescriptor; + m_winSecurityAttributes.bInheritHandle = TRUE; +} + +SECURITY_ATTRIBUTES * +WindowsSecurityAttributes::operator&() +{ + return &m_winSecurityAttributes; +} + +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); +} +}; + + +#endif /* _WIN64 */ + + class VulkanTest { public: VulkanTest(bool enable_validation)