blob: a0d052497f4415e77535d7e1489cd589bbc3f72b [file] [log] [blame]
/*-------------------------------------------------------------------------
* Vulkan Conformance Tests
* ------------------------
*
* Copyright (c) 2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* \brief Vulkan external memory API tests
*//*--------------------------------------------------------------------*/
#include "vktApiExternalMemoryTests.hpp"
#include "vktTestCaseUtil.hpp"
#include "vkRefUtil.hpp"
#include "vkDeviceUtil.hpp"
#include "vkQueryUtil.hpp"
#include "vkPlatform.hpp"
#include "vkMemUtil.hpp"
#include "vkApiVersion.hpp"
#include "tcuTestLog.hpp"
#include "deUniquePtr.hpp"
#include "deStringUtil.hpp"
#include "deRandom.hpp"
#include "deMemory.h"
#include "vktExternalMemoryUtil.hpp"
#if (DE_OS == DE_OS_ANDROID) || (DE_OS == DE_OS_UNIX)
# include <unistd.h>
# include <fcntl.h>
# include <errno.h>
# include <sys/types.h>
# include <sys/socket.h>
#endif
#if (DE_OS == DE_OS_WIN32)
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# include <Dxgi1_2.h>
#endif
using tcu::TestLog;
using namespace vkt::ExternalMemoryUtil;
namespace vkt
{
namespace api
{
namespace
{
std::string getFormatCaseName (vk::VkFormat format)
{
return de::toLower(de::toString(getFormatStr(format)).substr(10));
}
vk::VkMemoryDedicatedRequirements getMemoryDedicatedRequirements (const vk::DeviceInterface& vkd,
vk::VkDevice device,
vk::VkBuffer buffer)
{
const vk::VkBufferMemoryRequirementsInfo2 requirementInfo =
{
vk::VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2,
DE_NULL,
buffer
};
vk::VkMemoryDedicatedRequirements dedicatedRequirements =
{
vk::VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS,
DE_NULL,
VK_FALSE,
VK_FALSE
};
vk::VkMemoryRequirements2 requirements =
{
vk::VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2,
&dedicatedRequirements,
{ 0u, 0u, 0u }
};
vkd.getBufferMemoryRequirements2(device, &requirementInfo, &requirements);
return dedicatedRequirements;
}
vk::VkMemoryDedicatedRequirements getMemoryDedicatedRequirements (const vk::DeviceInterface& vkd,
vk::VkDevice device,
vk::VkImage image)
{
const vk::VkImageMemoryRequirementsInfo2 requirementInfo =
{
vk::VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2,
DE_NULL,
image
};
vk::VkMemoryDedicatedRequirements dedicatedRequirements =
{
vk::VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS,
DE_NULL,
VK_FALSE,
VK_FALSE
};
vk::VkMemoryRequirements2 requirements =
{
vk::VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2,
&dedicatedRequirements,
{ 0u, 0u, 0u }
};
vkd.getImageMemoryRequirements2(device, &requirementInfo, &requirements);
return dedicatedRequirements;
}
void writeHostMemory (const vk::DeviceInterface& vkd,
vk::VkDevice device,
vk::VkDeviceMemory memory,
size_t size,
const void* data)
{
void* const ptr = vk::mapMemory(vkd, device, memory, 0, size, 0);
deMemcpy(ptr, data, size);
flushMappedMemoryRange(vkd, device, memory, 0, size);
vkd.unmapMemory(device, memory);
}
void checkHostMemory (const vk::DeviceInterface& vkd,
vk::VkDevice device,
vk::VkDeviceMemory memory,
size_t size,
const void* data)
{
void* const ptr = vk::mapMemory(vkd, device, memory, 0, size, 0);
invalidateMappedMemoryRange(vkd, device, memory, 0, size);
if (deMemCmp(ptr, data, size) != 0)
TCU_FAIL("Memory contents don't match");
vkd.unmapMemory(device, memory);
}
std::vector<deUint8> genTestData (deUint32 seed, size_t size)
{
de::Random rng (seed);
std::vector<deUint8> data (size);
for (size_t ndx = 0; ndx < size; ndx++)
{
data[ndx] = rng.getUint8();
}
return data;
}
deUint32 chooseQueueFamilyIndex (const vk::InstanceInterface& vki,
vk::VkPhysicalDevice device,
vk::VkQueueFlags requireFlags)
{
const std::vector<vk::VkQueueFamilyProperties> properties (vk::getPhysicalDeviceQueueFamilyProperties(vki, device));
for (deUint32 queueFamilyIndex = 0; queueFamilyIndex < (deUint32)properties.size(); queueFamilyIndex++)
{
if ((properties[queueFamilyIndex].queueFlags & requireFlags) == requireFlags)
return queueFamilyIndex;
}
TCU_THROW(NotSupportedError, "Queue type not supported");
}
std::vector<std::string> getInstanceExtensions (const deUint32 instanceVersion,
const vk::VkExternalSemaphoreHandleTypeFlags externalSemaphoreTypes,
const vk::VkExternalMemoryHandleTypeFlags externalMemoryTypes,
const vk::VkExternalFenceHandleTypeFlags externalFenceTypes)
{
std::vector<std::string> instanceExtensions;
if (!vk::isCoreInstanceExtension(instanceVersion, "VK_KHR_get_physical_device_properties2"))
instanceExtensions.push_back("VK_KHR_get_physical_device_properties2");
if (externalSemaphoreTypes != 0)
if (!vk::isCoreInstanceExtension(instanceVersion, "VK_KHR_external_semaphore_capabilities"))
instanceExtensions.push_back("VK_KHR_external_semaphore_capabilities");
if (externalMemoryTypes != 0)
if (!vk::isCoreInstanceExtension(instanceVersion, "VK_KHR_external_memory_capabilities"))
instanceExtensions.push_back("VK_KHR_external_memory_capabilities");
if (externalFenceTypes != 0)
if (!vk::isCoreInstanceExtension(instanceVersion, "VK_KHR_external_fence_capabilities"))
instanceExtensions.push_back("VK_KHR_external_fence_capabilities");
return instanceExtensions;
}
vk::Move<vk::VkInstance> createInstance (const vk::PlatformInterface& vkp,
const deUint32 version,
const vk::VkExternalSemaphoreHandleTypeFlags externalSemaphoreTypes,
const vk::VkExternalMemoryHandleTypeFlags externalMemoryTypes,
const vk::VkExternalFenceHandleTypeFlags externalFenceTypes)
{
try
{
return vk::createDefaultInstance(vkp, version, std::vector<std::string>(), getInstanceExtensions(version, externalSemaphoreTypes, externalMemoryTypes, externalFenceTypes));
}
catch (const vk::Error& error)
{
if (error.getError() == vk::VK_ERROR_EXTENSION_NOT_PRESENT)
TCU_THROW(NotSupportedError, "Required extensions not supported");
throw;
}
}
vk::Move<vk::VkDevice> createDevice (const deUint32 apiVersion,
const vk::PlatformInterface& vkp,
vk::VkInstance instance,
const vk::InstanceInterface& vki,
vk::VkPhysicalDevice physicalDevice,
const vk::VkExternalSemaphoreHandleTypeFlags externalSemaphoreTypes,
const vk::VkExternalMemoryHandleTypeFlags externalMemoryTypes,
const vk::VkExternalFenceHandleTypeFlags externalFenceTypes,
deUint32 queueFamilyIndex,
bool useDedicatedAllocs = false)
{
bool useExternalSemaphore = false;
bool useExternalFence = false;
bool useExternalMemory = false;
std::vector<const char*> deviceExtensions;
if ((externalSemaphoreTypes
& (vk::VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT
| vk::VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT)) != 0)
{
deviceExtensions.push_back("VK_KHR_external_semaphore_fd");
useExternalSemaphore = true;
}
if ((externalFenceTypes
& (vk::VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
| vk::VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT)) != 0)
{
deviceExtensions.push_back("VK_KHR_external_fence_fd");
useExternalFence = true;
}
if (useDedicatedAllocs)
{
if (!vk::isCoreDeviceExtension(apiVersion, "VK_KHR_dedicated_allocation"))
deviceExtensions.push_back("VK_KHR_dedicated_allocation");
if (!vk::isCoreDeviceExtension(apiVersion, "VK_KHR_get_memory_requirements2"))
deviceExtensions.push_back("VK_KHR_get_memory_requirements2");
}
if ((externalMemoryTypes
& vk::VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT) != 0)
{
deviceExtensions.push_back("VK_KHR_external_memory_fd");
useExternalMemory = true;
}
if ((externalSemaphoreTypes
& (vk::VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT
| vk::VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT)) != 0)
{
deviceExtensions.push_back("VK_KHR_external_semaphore_win32");
useExternalSemaphore = true;
}
if ((externalFenceTypes
& (vk::VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_BIT
| vk::VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT)) != 0)
{
deviceExtensions.push_back("VK_KHR_external_fence_win32");
useExternalFence = true;
}
if ((externalMemoryTypes
& (vk::VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT
| vk::VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT
| vk::VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_BIT
| vk::VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_KMT_BIT
| vk::VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_HEAP_BIT
| vk::VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_RESOURCE_BIT)) != 0)
{
deviceExtensions.push_back("VK_KHR_external_memory_win32");
useExternalMemory = true;
}
if ((externalMemoryTypes
& vk::VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID) != 0)
{
deviceExtensions.push_back("VK_ANDROID_external_memory_android_hardware_buffer");
useExternalMemory = true;
if (!vk::isCoreDeviceExtension(apiVersion, "VK_KHR_sampler_ycbcr_conversion"))
deviceExtensions.push_back("VK_KHR_sampler_ycbcr_conversion");
if (!vk::isCoreDeviceExtension(apiVersion, "VK_EXT_queue_family_foreign"))
deviceExtensions.push_back("VK_EXT_queue_family_foreign");
}
if (useExternalSemaphore)
{
if (!vk::isCoreDeviceExtension(apiVersion, "VK_KHR_external_semaphore"))
deviceExtensions.push_back("VK_KHR_external_semaphore");
}
if (useExternalFence)
{
if (!vk::isCoreDeviceExtension(apiVersion, "VK_KHR_external_fence"))
deviceExtensions.push_back("VK_KHR_external_fence");
}
if (useExternalMemory)
{
if (!vk::isCoreDeviceExtension(apiVersion, "VK_KHR_external_memory"))
deviceExtensions.push_back("VK_KHR_external_memory");
}
const float priority = 0.5f;
const vk::VkDeviceQueueCreateInfo queues[] =
{
{
vk::VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
DE_NULL,
0u,
queueFamilyIndex,
1u,
&priority
}
};
const vk::VkDeviceCreateInfo deviceCreateInfo =
{
vk::VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
DE_NULL,
0u,
DE_LENGTH_OF_ARRAY(queues),
queues,
0u,
DE_NULL,
(deUint32)deviceExtensions.size(),
deviceExtensions.empty() ? DE_NULL : &deviceExtensions[0],
DE_NULL
};
try
{
return vk::createDevice(vkp, instance, vki, physicalDevice, &deviceCreateInfo);
}
catch (const vk::Error& error)
{
if (error.getError() == vk::VK_ERROR_EXTENSION_NOT_PRESENT)
TCU_THROW(NotSupportedError, "Required extensions not supported");
throw;
}
}
vk::VkQueue getQueue (const vk::DeviceInterface& vkd,
vk::VkDevice device,
deUint32 queueFamilyIndex)
{
vk::VkQueue queue;
vkd.getDeviceQueue(device, queueFamilyIndex, 0, &queue);
return queue;
}
void checkSemaphoreSupport (const vk::InstanceInterface& vki,
vk::VkPhysicalDevice device,
vk::VkExternalSemaphoreHandleTypeFlagBits externalType)
{
const vk::VkPhysicalDeviceExternalSemaphoreInfo info =
{
vk::VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_SEMAPHORE_INFO,
DE_NULL,
externalType
};
vk::VkExternalSemaphoreProperties properties =
{
vk::VK_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_PROPERTIES,
DE_NULL,
0u,
0u,
0u
};
vki.getPhysicalDeviceExternalSemaphoreProperties(device, &info, &properties);
if ((properties.externalSemaphoreFeatures & vk::VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT) == 0)
TCU_THROW(NotSupportedError, "Semaphore doesn't support exporting in external type");
if ((properties.externalSemaphoreFeatures & vk::VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT) == 0)
TCU_THROW(NotSupportedError, "Semaphore doesn't support importing in external type");
}
void checkFenceSupport (const vk::InstanceInterface& vki,
vk::VkPhysicalDevice device,
vk::VkExternalFenceHandleTypeFlagBits externalType)
{
const vk::VkPhysicalDeviceExternalFenceInfo info =
{
vk::VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_FENCE_INFO,
DE_NULL,
externalType
};
vk::VkExternalFenceProperties properties =
{
vk::VK_STRUCTURE_TYPE_EXTERNAL_FENCE_PROPERTIES,
DE_NULL,
0u,
0u,
0u
};
vki.getPhysicalDeviceExternalFenceProperties(device, &info, &properties);
if ((properties.externalFenceFeatures & vk::VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT) == 0)
TCU_THROW(NotSupportedError, "Fence doesn't support exporting in external type");
if ((properties.externalFenceFeatures & vk::VK_EXTERNAL_FENCE_FEATURE_IMPORTABLE_BIT) == 0)
TCU_THROW(NotSupportedError, "Fence doesn't support importing in external type");
}
void checkBufferSupport (const vk::InstanceInterface& vki,
vk::VkPhysicalDevice device,
vk::VkExternalMemoryHandleTypeFlagBits externalType,
vk::VkBufferViewCreateFlags createFlag,
vk::VkBufferUsageFlags usageFlag,
bool dedicated)
{
const vk::VkPhysicalDeviceExternalBufferInfo info =
{
vk::VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_BUFFER_INFO,
DE_NULL,
createFlag,
usageFlag,
externalType
};
vk::VkExternalBufferProperties properties =
{
vk::VK_STRUCTURE_TYPE_EXTERNAL_BUFFER_PROPERTIES,
DE_NULL,
{ 0u, 0u, 0u }
};
vki.getPhysicalDeviceExternalBufferProperties(device, &info, &properties);
if ((properties.externalMemoryProperties.externalMemoryFeatures & vk::VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT) == 0)
TCU_THROW(NotSupportedError, "External handle type doesn't support exporting buffer");
if ((properties.externalMemoryProperties.externalMemoryFeatures & vk::VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT) == 0)
TCU_THROW(NotSupportedError, "External handle type doesn't support importing buffer");
if (!dedicated && (properties.externalMemoryProperties.externalMemoryFeatures & vk::VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT) != 0)
TCU_THROW(NotSupportedError, "External handle type requires dedicated allocation");
}
void checkImageSupport (const vk::InstanceInterface& vki,
vk::VkPhysicalDevice device,
vk::VkExternalMemoryHandleTypeFlagBits externalType,
vk::VkImageViewCreateFlags createFlag,
vk::VkImageUsageFlags usageFlag,
vk::VkFormat format,
vk::VkImageTiling tiling,
bool dedicated)
{
const vk::VkPhysicalDeviceExternalImageFormatInfo externalInfo =
{
vk::VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO,
DE_NULL,
externalType
};
const vk::VkPhysicalDeviceImageFormatInfo2 info =
{
vk::VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2,
&externalInfo,
format,
vk::VK_IMAGE_TYPE_2D,
tiling,
usageFlag,
createFlag,
};
vk::VkExternalImageFormatProperties externalProperties =
{
vk::VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES,
DE_NULL,
{ 0u, 0u, 0u }
};
vk::VkImageFormatProperties2 properties =
{
vk::VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2,
&externalProperties,
{
{ 0u, 0u, 0u },
0u,
0u,
0u,
0u
}
};
vki.getPhysicalDeviceImageFormatProperties2(device, &info, &properties);
if ((externalProperties.externalMemoryProperties.externalMemoryFeatures & vk::VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT) == 0)
TCU_THROW(NotSupportedError, "External handle type doesn't support exporting image");
if ((externalProperties.externalMemoryProperties.externalMemoryFeatures & vk::VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT) == 0)
TCU_THROW(NotSupportedError, "External handle type doesn't support importing image");
if (!dedicated && (externalProperties.externalMemoryProperties.externalMemoryFeatures & vk::VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT) != 0)
TCU_THROW(NotSupportedError, "External handle type requires dedicated allocation");
}
void submitDummySignal (const vk::DeviceInterface& vkd,
vk::VkQueue queue,
vk::VkSemaphore semaphore)
{
const vk::VkSubmitInfo submit =
{
vk::VK_STRUCTURE_TYPE_SUBMIT_INFO,
DE_NULL,
0u,
DE_NULL,
DE_NULL,
0u,
DE_NULL,
1u,
&semaphore
};
VK_CHECK(vkd.queueSubmit(queue, 1, &submit, (vk::VkFence)0u));
}
void submitDummySignalAndGetSemaphoreNative ( const vk::DeviceInterface& vk,
vk::VkDevice device,
vk::VkQueue queue,
deUint32 queueFamilyIndex,
vk::VkSemaphore semaphore,
vk::VkExternalSemaphoreHandleTypeFlagBits externalType,
NativeHandle& nativeHandle)
{
const vk::Unique<vk::VkCommandPool> cmdPool(createCommandPool(vk, device, vk::VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, queueFamilyIndex, DE_NULL));
const vk::Unique<vk::VkCommandBuffer> cmdBuffer(allocateCommandBuffer(vk, device, *cmdPool, vk::VK_COMMAND_BUFFER_LEVEL_PRIMARY));
const vk::VkEventCreateInfo eventCreateInfo =
{
vk::VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
DE_NULL,
0u
};
const vk::Unique<vk::VkEvent> event(createEvent(vk, device, &eventCreateInfo, DE_NULL));
const vk::VkCommandBufferBeginInfo cmdBufferBeginInfo =
{
vk::VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
DE_NULL,
vk::VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
DE_NULL,
};
VK_CHECK(vk.beginCommandBuffer(*cmdBuffer, &cmdBufferBeginInfo));
/*
The submitDummySignal function calls vkQueueSubmit with an empty VkSubmitInfo structure and a
VkSemaphore to be signalled when the work is finished. Because there is no work in the submission, vkQueueSubmit
may signal the semaphore immediately. When a semaphore's file descriptor is obtained using vkGetFenceFdKHR, if the
handle type is VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR, vkGetFenceFdKHR is allowed to return -1 if the fence
is already signalled, instead of a file descriptor, . In order to make sure that a valid file descriptor is returned
we use vkCmdWaitEvents to make sure that vkQueueSubmit doesn't signal the fence.
*/
vk.cmdWaitEvents(*cmdBuffer, 1, &event.get(), vk::VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, vk::VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0, DE_NULL, 0, DE_NULL, 0, DE_NULL);
vk.endCommandBuffer(*cmdBuffer);
const vk::VkSubmitInfo submit =
{
vk::VK_STRUCTURE_TYPE_SUBMIT_INFO,
DE_NULL,
0u,
DE_NULL,
DE_NULL,
1u,
&cmdBuffer.get(),
1u,
&semaphore
};
VK_CHECK(vk.queueSubmit(queue, 1, &submit, (vk::VkFence)0u));
getSemaphoreNative(vk, device, semaphore, externalType, nativeHandle);
VK_CHECK(vk.setEvent(device, *event));
VK_CHECK(vk.queueWaitIdle(queue));
}
void submitDummyWait (const vk::DeviceInterface& vkd,
vk::VkQueue queue,
vk::VkSemaphore semaphore)
{
const vk::VkPipelineStageFlags stage = vk::VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
const vk::VkSubmitInfo submit =
{
vk::VK_STRUCTURE_TYPE_SUBMIT_INFO,
DE_NULL,
1u,
&semaphore,
&stage,
0u,
DE_NULL,
0u,
DE_NULL,
};
VK_CHECK(vkd.queueSubmit(queue, 1, &submit, (vk::VkFence)0u));
}
void submitDummySignal (const vk::DeviceInterface& vkd,
vk::VkQueue queue,
vk::VkFence fence)
{
const vk::VkSubmitInfo submit =
{
vk::VK_STRUCTURE_TYPE_SUBMIT_INFO,
DE_NULL,
0u,
DE_NULL,
DE_NULL,
0u,
DE_NULL,
0u,
DE_NULL
};
VK_CHECK(vkd.queueSubmit(queue, 1, &submit, fence));
}
void submitDummySignalAndGetFenceNative ( const vk::DeviceInterface& vk,
vk::VkDevice device,
vk::VkQueue queue,
deUint32 queueFamilyIndex,
vk::VkFence fence,
vk::VkExternalFenceHandleTypeFlagBits externalType,
NativeHandle& nativeHandle)
{
const vk::Unique<vk::VkCommandPool> cmdPool(createCommandPool(vk, device, vk::VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, queueFamilyIndex, DE_NULL));
const vk::Unique<vk::VkCommandBuffer> cmdBuffer(allocateCommandBuffer(vk, device, *cmdPool, vk::VK_COMMAND_BUFFER_LEVEL_PRIMARY));
const vk::VkEventCreateInfo eventCreateInfo =
{
vk::VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
DE_NULL,
0u
};
const vk::Unique<vk::VkEvent> event(createEvent(vk, device, &eventCreateInfo, DE_NULL));
const vk::VkCommandBufferBeginInfo cmdBufferBeginInfo =
{
vk::VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
DE_NULL,
vk::VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
DE_NULL,
};
VK_CHECK(vk.beginCommandBuffer(*cmdBuffer, &cmdBufferBeginInfo));
/*
The submitDummySignal function calls vkQueueSubmit with an empty VkSubmitInfo structure and a
VkFence to be signalled when the work is finished. Because there is no work in the submission, vkQueueSubmit
could signal the fence immediately. When a fence's file descriptor is obtained using vkGetFenceFdKHR, if the
handle type is VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR, vkGetFenceFdKHR is allowed to return -1 instead of a
file descriptor, if the fence is already signalled. In order to make sure that a valid file descriptor is returned
we use vkCmdWaitEvents to make sure that vkQueueSubmit doesn't signal the fence.
*/
vk.cmdWaitEvents(*cmdBuffer, 1, &event.get(), vk::VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, vk::VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0, DE_NULL, 0, DE_NULL, 0, DE_NULL);
vk.endCommandBuffer(*cmdBuffer);
const vk::VkSubmitInfo submit =
{
vk::VK_STRUCTURE_TYPE_SUBMIT_INFO,
DE_NULL,
0u,
DE_NULL,
DE_NULL,
1u,
&cmdBuffer.get(),
0u,
DE_NULL
};
VK_CHECK(vk.queueSubmit(queue, 1, &submit, fence));
getFenceNative(vk, device, fence, externalType, nativeHandle);
VK_CHECK(vk.setEvent(device, *event));
VK_CHECK(vk.queueWaitIdle(queue));
}
tcu::TestStatus testSemaphoreQueries (Context& context, vk::VkExternalSemaphoreHandleTypeFlagBits externalType)
{
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), externalType, 0u, 0u));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice device (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
TestLog& log = context.getTestContext().getLog();
const vk::VkPhysicalDeviceExternalSemaphoreInfo info =
{
vk::VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_SEMAPHORE_INFO,
DE_NULL,
externalType
};
vk::VkExternalSemaphoreProperties properties =
{
vk::VK_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_PROPERTIES,
DE_NULL,
0u,
0u,
0u
};
vki.getPhysicalDeviceExternalSemaphoreProperties(device, &info, &properties);
log << TestLog::Message << properties << TestLog::EndMessage;
TCU_CHECK(properties.pNext == DE_NULL);
TCU_CHECK(properties.sType == vk::VK_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_PROPERTIES);
return tcu::TestStatus::pass("Pass");
}
struct SemaphoreTestConfig
{
SemaphoreTestConfig (vk::VkExternalSemaphoreHandleTypeFlagBits externalType_,
Permanence permanence_)
: externalType (externalType_)
, permanence (permanence_)
{
}
vk::VkExternalSemaphoreHandleTypeFlagBits externalType;
Permanence permanence;
};
tcu::TestStatus testSemaphoreWin32Create (Context& context,
const SemaphoreTestConfig config)
{
#if (DE_OS == DE_OS_WIN32)
const Transference transference (getHandelTypeTransferences(config.externalType));
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), config.externalType, 0u, 0u));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice physicalDevice (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
const deUint32 queueFamilyIndex (chooseQueueFamilyIndex(vki, physicalDevice, 0u));
checkSemaphoreSupport(vki, physicalDevice, config.externalType);
{
const vk::Unique<vk::VkDevice> device (createDevice(context.getUsedApiVersion(), vkp, *instance, vki, physicalDevice, config.externalType, 0u, 0u, queueFamilyIndex));
const vk::DeviceDriver vkd (vkp, *instance, *device);
const vk::VkQueue queue (getQueue(vkd, *device, queueFamilyIndex));
const vk::VkExportSemaphoreWin32HandleInfoKHR win32ExportInfo =
{
vk::VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_WIN32_HANDLE_INFO_KHR,
DE_NULL,
(vk::pt::Win32SecurityAttributesPtr)DE_NULL,
DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE,
DE_NULL
};
const vk::VkExportSemaphoreCreateInfo exportCreateInfo=
{
vk::VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_CREATE_INFO,
&win32ExportInfo,
(vk::VkExternalMemoryHandleTypeFlags)config.externalType
};
const vk::VkSemaphoreCreateInfo createInfo =
{
vk::VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
&exportCreateInfo,
0u
};
const vk::Unique<vk::VkSemaphore> semaphore (vk::createSemaphore(vkd, *device, &createInfo));
if (transference == TRANSFERENCE_COPY)
submitDummySignal(vkd, queue, *semaphore);
NativeHandle handleA;
getSemaphoreNative(vkd, *device, *semaphore, config.externalType, handleA);
{
const vk::VkSemaphoreImportFlags flags = config.permanence == PERMANENCE_TEMPORARY ? vk::VK_SEMAPHORE_IMPORT_TEMPORARY_BIT : (vk::VkSemaphoreImportFlagBits)0u;
const vk::Unique<vk::VkSemaphore> semaphoreA (createAndImportSemaphore(vkd, *device, config.externalType, handleA, flags));
if (transference == TRANSFERENCE_COPY)
submitDummyWait(vkd, queue, *semaphoreA);
else if (transference == TRANSFERENCE_REFERENCE)
{
submitDummySignal(vkd, queue, *semaphore);
submitDummyWait(vkd, queue, *semaphoreA);
}
else
DE_FATAL("Unknown transference.");
VK_CHECK(vkd.queueWaitIdle(queue));
}
return tcu::TestStatus::pass("Pass");
}
#else
DE_UNREF(context);
DE_UNREF(config);
TCU_THROW(NotSupportedError, "Platform doesn't support win32 handles");
#endif
}
tcu::TestStatus testSemaphoreImportTwice (Context& context,
const SemaphoreTestConfig config)
{
const Transference transference (getHandelTypeTransferences(config.externalType));
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), config.externalType, 0u, 0u));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice physicalDevice (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
const deUint32 queueFamilyIndex (chooseQueueFamilyIndex(vki, physicalDevice, 0u));
checkSemaphoreSupport(vki, physicalDevice, config.externalType);
{
const vk::Unique<vk::VkDevice> device (createDevice(context.getUsedApiVersion(), vkp, *instance, vki, physicalDevice, config.externalType, 0u, 0u, queueFamilyIndex));
const vk::DeviceDriver vkd (vkp, *instance, *device);
const vk::VkQueue queue (getQueue(vkd, *device, queueFamilyIndex));
const vk::Unique<vk::VkSemaphore> semaphore (createExportableSemaphore(vkd, *device, config.externalType));
NativeHandle handleA;
if (transference == TRANSFERENCE_COPY)
submitDummySignalAndGetSemaphoreNative(vkd, *device, queue, queueFamilyIndex, *semaphore, config.externalType, handleA);
else
getSemaphoreNative(vkd, *device, *semaphore, config.externalType, handleA);
{
NativeHandle handleB (handleA);
const vk::VkSemaphoreImportFlags flags = config.permanence == PERMANENCE_TEMPORARY ? vk::VK_SEMAPHORE_IMPORT_TEMPORARY_BIT : (vk::VkSemaphoreImportFlagBits)0u;
const vk::Unique<vk::VkSemaphore> semaphoreA (createAndImportSemaphore(vkd, *device, config.externalType, handleA, flags));
const vk::Unique<vk::VkSemaphore> semaphoreB (createAndImportSemaphore(vkd, *device, config.externalType, handleB, flags));
if (transference == TRANSFERENCE_COPY)
submitDummyWait(vkd, queue, *semaphoreA);
else if (transference == TRANSFERENCE_REFERENCE)
{
submitDummySignal(vkd, queue, *semaphoreA);
submitDummyWait(vkd, queue, *semaphoreB);
}
else
DE_FATAL("Unknown transference.");
VK_CHECK(vkd.queueWaitIdle(queue));
}
return tcu::TestStatus::pass("Pass");
}
}
tcu::TestStatus testSemaphoreImportReimport (Context& context,
const SemaphoreTestConfig config)
{
const Transference transference (getHandelTypeTransferences(config.externalType));
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), config.externalType, 0u, 0u));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice physicalDevice (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
const deUint32 queueFamilyIndex (chooseQueueFamilyIndex(vki, physicalDevice, 0u));
checkSemaphoreSupport(vki, physicalDevice, config.externalType);
{
const vk::Unique<vk::VkDevice> device (createDevice(context.getUsedApiVersion(), vkp, *instance, vki, physicalDevice, config.externalType, 0u, 0u, queueFamilyIndex));
const vk::DeviceDriver vkd (vkp, *instance, *device);
const vk::VkQueue queue (getQueue(vkd, *device, queueFamilyIndex));
const vk::Unique<vk::VkSemaphore> semaphoreA (createExportableSemaphore(vkd, *device, config.externalType));
NativeHandle handleA;
if (transference == TRANSFERENCE_COPY)
submitDummySignalAndGetSemaphoreNative(vkd, *device, queue, queueFamilyIndex, *semaphoreA, config.externalType, handleA);
else
getSemaphoreNative(vkd, *device, *semaphoreA, config.externalType, handleA);
NativeHandle handleB (handleA);
const vk::VkSemaphoreImportFlags flags = config.permanence == PERMANENCE_TEMPORARY ? vk::VK_SEMAPHORE_IMPORT_TEMPORARY_BIT : (vk::VkSemaphoreImportFlagBits)0u;
const vk::Unique<vk::VkSemaphore> semaphoreB (createAndImportSemaphore(vkd, *device, config.externalType, handleA, flags));
importSemaphore(vkd, *device, *semaphoreB, config.externalType, handleB, flags);
if (transference == TRANSFERENCE_COPY)
submitDummyWait(vkd, queue, *semaphoreB);
else if (transference == TRANSFERENCE_REFERENCE)
{
submitDummySignal(vkd, queue, *semaphoreA);
submitDummyWait(vkd, queue, *semaphoreB);
}
else
DE_FATAL("Unknown transference.");
VK_CHECK(vkd.queueWaitIdle(queue));
return tcu::TestStatus::pass("Pass");
}
}
tcu::TestStatus testSemaphoreSignalExportImportWait (Context& context,
const SemaphoreTestConfig config)
{
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), config.externalType, 0u, 0u));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice physicalDevice (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
const deUint32 queueFamilyIndex (chooseQueueFamilyIndex(vki, physicalDevice, 0u));
checkSemaphoreSupport(vki, physicalDevice, config.externalType);
{
const vk::Unique<vk::VkDevice> device (createDevice(context.getUsedApiVersion(), vkp, *instance, vki, physicalDevice, config.externalType, 0u, 0u, queueFamilyIndex));
const vk::DeviceDriver vkd (vkp, *instance, *device);
const vk::VkQueue queue (getQueue(vkd, *device, queueFamilyIndex));
const vk::Unique<vk::VkSemaphore> semaphoreA (createExportableSemaphore(vkd, *device, config.externalType));
{
NativeHandle handle;
submitDummySignalAndGetSemaphoreNative(vkd, *device, queue, queueFamilyIndex, *semaphoreA, config.externalType, handle);
{
const vk::VkSemaphoreImportFlags flags = config.permanence == PERMANENCE_TEMPORARY ? vk::VK_SEMAPHORE_IMPORT_TEMPORARY_BIT : (vk::VkSemaphoreImportFlagBits)0u;
const vk::Unique<vk::VkSemaphore> semaphoreB (createAndImportSemaphore(vkd, *device, config.externalType, handle, flags));
submitDummyWait(vkd, queue, *semaphoreB);
VK_CHECK(vkd.queueWaitIdle(queue));
}
}
return tcu::TestStatus::pass("Pass");
}
}
tcu::TestStatus testSemaphoreExportSignalImportWait (Context& context,
const SemaphoreTestConfig config)
{
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), config.externalType, 0u, 0u));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice physicalDevice (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
const deUint32 queueFamilyIndex (chooseQueueFamilyIndex(vki, physicalDevice, 0u));
const vk::VkSemaphoreImportFlags flags = config.permanence == PERMANENCE_TEMPORARY ? vk::VK_SEMAPHORE_IMPORT_TEMPORARY_BIT : (vk::VkSemaphoreImportFlagBits)0u;
DE_ASSERT(getHandelTypeTransferences(config.externalType) == TRANSFERENCE_REFERENCE);
checkSemaphoreSupport(vki, physicalDevice, config.externalType);
{
const vk::Unique<vk::VkDevice> device (createDevice(context.getUsedApiVersion(), vkp, *instance, vki, physicalDevice, config.externalType, 0u, 0u, queueFamilyIndex));
const vk::DeviceDriver vkd (vkp, *instance, *device);
const vk::VkQueue queue (getQueue(vkd, *device, queueFamilyIndex));
const vk::Unique<vk::VkSemaphore> semaphoreA (createExportableSemaphore(vkd, *device, config.externalType));
NativeHandle handle;
getSemaphoreNative(vkd, *device, *semaphoreA, config.externalType, handle);
submitDummySignal(vkd, queue, *semaphoreA);
{
{
const vk::Unique<vk::VkSemaphore> semaphoreB (createAndImportSemaphore(vkd, *device, config.externalType, handle, flags));
submitDummyWait(vkd, queue, *semaphoreB);
VK_CHECK(vkd.queueWaitIdle(queue));
}
}
return tcu::TestStatus::pass("Pass");
}
}
tcu::TestStatus testSemaphoreExportImportSignalWait (Context& context,
const SemaphoreTestConfig config)
{
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), config.externalType, 0u, 0u));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice physicalDevice (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
const deUint32 queueFamilyIndex (chooseQueueFamilyIndex(vki, physicalDevice, 0u));
DE_ASSERT(getHandelTypeTransferences(config.externalType) == TRANSFERENCE_REFERENCE);
checkSemaphoreSupport(vki, physicalDevice, config.externalType);
{
const vk::VkSemaphoreImportFlags flags = config.permanence == PERMANENCE_TEMPORARY ? vk::VK_SEMAPHORE_IMPORT_TEMPORARY_BIT : (vk::VkSemaphoreImportFlagBits)0u;
const vk::Unique<vk::VkDevice> device (createDevice(context.getUsedApiVersion(), vkp, *instance, vki, physicalDevice, config.externalType, 0u, 0u, queueFamilyIndex));
const vk::DeviceDriver vkd (vkp, *instance, *device);
const vk::VkQueue queue (getQueue(vkd, *device, queueFamilyIndex));
const vk::Unique<vk::VkSemaphore> semaphoreA (createExportableSemaphore(vkd, *device, config.externalType));
NativeHandle handle;
submitDummySignalAndGetSemaphoreNative(vkd, *device, queue, queueFamilyIndex, *semaphoreA, config.externalType, handle);
const vk::Unique<vk::VkSemaphore> semaphoreB (createAndImportSemaphore(vkd, *device, config.externalType, handle, flags));
submitDummySignal(vkd, queue, *semaphoreA);
submitDummyWait(vkd, queue, *semaphoreB);
VK_CHECK(vkd.queueWaitIdle(queue));
return tcu::TestStatus::pass("Pass");
}
}
tcu::TestStatus testSemaphoreSignalImport (Context& context,
const SemaphoreTestConfig config)
{
const Transference transference (getHandelTypeTransferences(config.externalType));
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), config.externalType, 0u, 0u));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice physicalDevice (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
const deUint32 queueFamilyIndex (chooseQueueFamilyIndex(vki, physicalDevice, 0u));
checkSemaphoreSupport(vki, physicalDevice, config.externalType);
{
const vk::VkSemaphoreImportFlags flags = config.permanence == PERMANENCE_TEMPORARY ? vk::VK_SEMAPHORE_IMPORT_TEMPORARY_BIT : (vk::VkSemaphoreImportFlagBits)0u;
const vk::Unique<vk::VkDevice> device (createDevice(context.getUsedApiVersion(), vkp, *instance, vki, physicalDevice, config.externalType, 0u, 0u, queueFamilyIndex));
const vk::DeviceDriver vkd (vkp, *instance, *device);
const vk::VkQueue queue (getQueue(vkd, *device, queueFamilyIndex));
const vk::Unique<vk::VkSemaphore> semaphoreA (createExportableSemaphore(vkd, *device, config.externalType));
const vk::Unique<vk::VkSemaphore> semaphoreB (createSemaphore(vkd, *device));
NativeHandle handle;
submitDummySignal(vkd, queue, *semaphoreB);
VK_CHECK(vkd.queueWaitIdle(queue));
if (transference == TRANSFERENCE_COPY)
submitDummySignalAndGetSemaphoreNative(vkd, *device, queue, queueFamilyIndex, *semaphoreA, config.externalType, handle);
else
getSemaphoreNative(vkd, *device, *semaphoreA, config.externalType, handle);
importSemaphore(vkd, *device, *semaphoreB, config.externalType, handle, flags);
if (transference == TRANSFERENCE_COPY)
submitDummyWait(vkd, queue, *semaphoreB);
else if (transference == TRANSFERENCE_REFERENCE)
{
submitDummySignal(vkd, queue, *semaphoreA);
submitDummyWait(vkd, queue, *semaphoreB);
}
else
DE_FATAL("Unknown transference.");
VK_CHECK(vkd.queueWaitIdle(queue));
return tcu::TestStatus::pass("Pass");
}
}
tcu::TestStatus testSemaphoreSignalWaitImport (Context& context,
const SemaphoreTestConfig config)
{
const Transference transference (getHandelTypeTransferences(config.externalType));
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), config.externalType, 0u, 0u));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice physicalDevice (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
const deUint32 queueFamilyIndex (chooseQueueFamilyIndex(vki, physicalDevice, 0u));
checkSemaphoreSupport(vki, physicalDevice, config.externalType);
{
const vk::VkSemaphoreImportFlags flags = config.permanence == PERMANENCE_TEMPORARY ? vk::VK_SEMAPHORE_IMPORT_TEMPORARY_BIT : (vk::VkSemaphoreImportFlagBits)0u;
const vk::Unique<vk::VkDevice> device (createDevice(context.getUsedApiVersion(), vkp, *instance, vki, physicalDevice, config.externalType, 0u, 0u, queueFamilyIndex));
const vk::DeviceDriver vkd (vkp, *instance, *device);
const vk::VkQueue queue (getQueue(vkd, *device, queueFamilyIndex));
const vk::Unique<vk::VkSemaphore> semaphoreA (createExportableSemaphore(vkd, *device, config.externalType));
const vk::Unique<vk::VkSemaphore> semaphoreB (createSemaphore(vkd, *device));
NativeHandle handle;
if (transference == TRANSFERENCE_COPY)
submitDummySignalAndGetSemaphoreNative(vkd, *device, queue, queueFamilyIndex, *semaphoreA, config.externalType, handle);
else
getSemaphoreNative(vkd, *device, *semaphoreA, config.externalType, handle);
submitDummySignal(vkd, queue, *semaphoreB);
submitDummyWait(vkd, queue, *semaphoreB);
VK_CHECK(vkd.queueWaitIdle(queue));
importSemaphore(vkd, *device, *semaphoreB, config.externalType, handle, flags);
if (transference == TRANSFERENCE_COPY)
submitDummyWait(vkd, queue, *semaphoreB);
else if (transference == TRANSFERENCE_REFERENCE)
{
submitDummySignal(vkd, queue, *semaphoreA);
submitDummyWait(vkd, queue, *semaphoreB);
}
else
DE_FATAL("Unknown transference.");
VK_CHECK(vkd.queueWaitIdle(queue));
return tcu::TestStatus::pass("Pass");
}
}
tcu::TestStatus testSemaphoreMultipleExports (Context& context,
const SemaphoreTestConfig config)
{
const size_t exportCount = 4 * 1024;
const Transference transference (getHandelTypeTransferences(config.externalType));
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), config.externalType, 0u, 0u));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice physicalDevice (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
const deUint32 queueFamilyIndex (chooseQueueFamilyIndex(vki, physicalDevice, 0u));
checkSemaphoreSupport(vki, physicalDevice, config.externalType);
{
const vk::Unique<vk::VkDevice> device (createDevice(context.getUsedApiVersion(), vkp, *instance, vki, physicalDevice, config.externalType, 0u, 0u, queueFamilyIndex));
const vk::DeviceDriver vkd (vkp, *instance, *device);
const vk::VkQueue queue (getQueue(vkd, *device, queueFamilyIndex));
const vk::Unique<vk::VkSemaphore> semaphore (createExportableSemaphore(vkd, *device, config.externalType));
for (size_t exportNdx = 0; exportNdx < exportCount; exportNdx++)
{
NativeHandle handle;
if (transference == TRANSFERENCE_COPY)
submitDummySignalAndGetSemaphoreNative(vkd, *device, queue, queueFamilyIndex, *semaphore, config.externalType, handle);
else
getSemaphoreNative(vkd, *device, *semaphore, config.externalType, handle);
}
submitDummySignal(vkd, queue, *semaphore);
submitDummyWait(vkd, queue, *semaphore);
VK_CHECK(vkd.queueWaitIdle(queue));
}
return tcu::TestStatus::pass("Pass");
}
tcu::TestStatus testSemaphoreMultipleImports (Context& context,
const SemaphoreTestConfig config)
{
const size_t importCount = 4 * 1024;
const Transference transference (getHandelTypeTransferences(config.externalType));
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), config.externalType, 0u, 0u));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice physicalDevice (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
const deUint32 queueFamilyIndex (chooseQueueFamilyIndex(vki, physicalDevice, 0u));
checkSemaphoreSupport(vki, physicalDevice, config.externalType);
{
const vk::VkSemaphoreImportFlags flags = config.permanence == PERMANENCE_TEMPORARY ? vk::VK_SEMAPHORE_IMPORT_TEMPORARY_BIT : (vk::VkSemaphoreImportFlagBits)0u;
const vk::Unique<vk::VkDevice> device (createDevice(context.getUsedApiVersion(), vkp, *instance, vki, physicalDevice, config.externalType, 0u, 0u, queueFamilyIndex));
const vk::DeviceDriver vkd (vkp, *instance, *device);
const vk::VkQueue queue (getQueue(vkd, *device, queueFamilyIndex));
const vk::Unique<vk::VkSemaphore> semaphoreA (createExportableSemaphore(vkd, *device, config.externalType));
NativeHandle handleA;
if (transference == TRANSFERENCE_COPY)
submitDummySignalAndGetSemaphoreNative(vkd, *device, queue, queueFamilyIndex, *semaphoreA, config.externalType, handleA);
else
getSemaphoreNative(vkd, *device, *semaphoreA, config.externalType, handleA);
for (size_t importNdx = 0; importNdx < importCount; importNdx++)
{
NativeHandle handleB (handleA);
const vk::Unique<vk::VkSemaphore> semaphoreB (createAndImportSemaphore(vkd, *device, config.externalType, handleB, flags));
}
if (transference == TRANSFERENCE_COPY)
{
importSemaphore(vkd, *device, *semaphoreA, config.externalType, handleA, flags);
submitDummyWait(vkd, queue, *semaphoreA);
}
else if (transference == TRANSFERENCE_REFERENCE)
{
submitDummySignal(vkd, queue, *semaphoreA);
submitDummyWait(vkd, queue, *semaphoreA);
}
else
DE_FATAL("Unknown transference.");
VK_CHECK(vkd.queueWaitIdle(queue));
}
return tcu::TestStatus::pass("Pass");
}
tcu::TestStatus testSemaphoreTransference (Context& context,
const SemaphoreTestConfig config)
{
const Transference transference (getHandelTypeTransferences(config.externalType));
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), config.externalType, 0u, 0u));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice physicalDevice (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
const deUint32 queueFamilyIndex (chooseQueueFamilyIndex(vki, physicalDevice, 0u));
checkSemaphoreSupport(vki, physicalDevice, config.externalType);
{
const vk::VkSemaphoreImportFlags flags = config.permanence == PERMANENCE_TEMPORARY ? vk::VK_SEMAPHORE_IMPORT_TEMPORARY_BIT : (vk::VkSemaphoreImportFlagBits)0u;
const vk::Unique<vk::VkDevice> device (createDevice(context.getUsedApiVersion(), vkp, *instance, vki, physicalDevice, config.externalType, 0u, 0u, queueFamilyIndex));
const vk::DeviceDriver vkd (vkp, *instance, *device);
const vk::VkQueue queue (getQueue(vkd, *device, queueFamilyIndex));
const vk::Unique<vk::VkSemaphore> semaphoreA (createExportableSemaphore(vkd, *device, config.externalType));
NativeHandle handle;
submitDummySignalAndGetSemaphoreNative(vkd, *device, queue, queueFamilyIndex, *semaphoreA, config.externalType, handle);
{
const vk::Unique<vk::VkSemaphore> semaphoreB (createAndImportSemaphore(vkd, *device, config.externalType, handle, flags));
if (config.permanence == PERMANENCE_PERMANENT)
{
if (transference == TRANSFERENCE_COPY)
{
submitDummySignal(vkd, queue, *semaphoreA);
submitDummyWait(vkd, queue, *semaphoreB);
VK_CHECK(vkd.queueWaitIdle(queue));
submitDummySignal(vkd, queue, *semaphoreB);
submitDummyWait(vkd, queue, *semaphoreA);
submitDummyWait(vkd, queue, *semaphoreB);
VK_CHECK(vkd.queueWaitIdle(queue));
}
else if (transference== TRANSFERENCE_REFERENCE)
{
submitDummyWait(vkd, queue, *semaphoreB);
VK_CHECK(vkd.queueWaitIdle(queue));
submitDummySignal(vkd, queue, *semaphoreA);
submitDummyWait(vkd, queue, *semaphoreB);
submitDummySignal(vkd, queue, *semaphoreB);
submitDummyWait(vkd, queue, *semaphoreA);
VK_CHECK(vkd.queueWaitIdle(queue));
}
else
DE_FATAL("Unknown transference.");
}
else if (config.permanence == PERMANENCE_TEMPORARY)
{
if (transference == TRANSFERENCE_COPY)
{
submitDummySignal(vkd, queue, *semaphoreA);
submitDummyWait(vkd, queue, *semaphoreB);
VK_CHECK(vkd.queueWaitIdle(queue));
submitDummySignal(vkd, queue, *semaphoreB);
submitDummyWait(vkd, queue, *semaphoreA);
submitDummyWait(vkd, queue, *semaphoreB);
VK_CHECK(vkd.queueWaitIdle(queue));
}
else if (transference== TRANSFERENCE_REFERENCE)
{
submitDummyWait(vkd, queue, *semaphoreB);
VK_CHECK(vkd.queueWaitIdle(queue));
submitDummySignal(vkd, queue, *semaphoreA);
submitDummySignal(vkd, queue, *semaphoreB);
submitDummyWait(vkd, queue, *semaphoreB);
submitDummyWait(vkd, queue, *semaphoreA);
VK_CHECK(vkd.queueWaitIdle(queue));
}
else
DE_FATAL("Unknown transference.");
}
else
DE_FATAL("Unknown permanence.");
}
return tcu::TestStatus::pass("Pass");
}
}
tcu::TestStatus testSemaphoreFdDup (Context& context,
const SemaphoreTestConfig config)
{
#if (DE_OS == DE_OS_ANDROID) || (DE_OS == DE_OS_UNIX)
const Transference transference (getHandelTypeTransferences(config.externalType));
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), config.externalType, 0u, 0u));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice physicalDevice (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
const deUint32 queueFamilyIndex (chooseQueueFamilyIndex(vki, physicalDevice, 0u));
checkSemaphoreSupport(vki, physicalDevice, config.externalType);
{
const vk::VkSemaphoreImportFlags flags = config.permanence == PERMANENCE_TEMPORARY ? vk::VK_SEMAPHORE_IMPORT_TEMPORARY_BIT : (vk::VkSemaphoreImportFlagBits)0u;
const vk::Unique<vk::VkDevice> device (createDevice(context.getUsedApiVersion(), vkp, *instance, vki, physicalDevice, config.externalType, 0u, 0u, queueFamilyIndex));
const vk::DeviceDriver vkd (vkp, *instance, *device);
const vk::VkQueue queue (getQueue(vkd, *device, queueFamilyIndex));
TestLog& log = context.getTestContext().getLog();
const vk::Unique<vk::VkSemaphore> semaphoreA (createExportableSemaphore(vkd, *device, config.externalType));
{
NativeHandle fd;
if (transference == TRANSFERENCE_COPY)
submitDummySignalAndGetSemaphoreNative(vkd, *device, queue, queueFamilyIndex, *semaphoreA, config.externalType, fd);
else
getSemaphoreNative(vkd, *device, *semaphoreA, config.externalType, fd);
NativeHandle newFd (dup(fd.getFd()));
if (newFd.getFd() < 0)
log << TestLog::Message << "dup() failed: '" << strerror(errno) << "'" << TestLog::EndMessage;
TCU_CHECK_MSG(newFd.getFd() >= 0, "Failed to call dup() for semaphores fd");
{
const vk::Unique<vk::VkSemaphore> semaphoreB (createAndImportSemaphore(vkd, *device, config.externalType, newFd, flags));
if (transference == TRANSFERENCE_COPY)
submitDummyWait(vkd, queue, *semaphoreB);
else if (transference == TRANSFERENCE_REFERENCE)
{
submitDummySignal(vkd, queue, *semaphoreA);
submitDummyWait(vkd, queue, *semaphoreB);
}
else
DE_FATAL("Unknown permanence.");
VK_CHECK(vkd.queueWaitIdle(queue));
}
}
return tcu::TestStatus::pass("Pass");
}
#else
DE_UNREF(context);
DE_UNREF(config);
TCU_THROW(NotSupportedError, "Platform doesn't support dup()");
#endif
}
tcu::TestStatus testSemaphoreFdDup2 (Context& context,
const SemaphoreTestConfig config)
{
#if (DE_OS == DE_OS_ANDROID) || (DE_OS == DE_OS_UNIX)
const Transference transference (getHandelTypeTransferences(config.externalType));
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), config.externalType, 0u, 0u));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice physicalDevice (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
const deUint32 queueFamilyIndex (chooseQueueFamilyIndex(vki, physicalDevice, 0u));
checkSemaphoreSupport(vki, physicalDevice, config.externalType);
{
const vk::VkSemaphoreImportFlags flags = config.permanence == PERMANENCE_TEMPORARY ? vk::VK_SEMAPHORE_IMPORT_TEMPORARY_BIT : (vk::VkSemaphoreImportFlagBits)0u;
const vk::Unique<vk::VkDevice> device (createDevice(context.getUsedApiVersion(), vkp, *instance, vki, physicalDevice, config.externalType, 0u, 0u, queueFamilyIndex));
const vk::DeviceDriver vkd (vkp, *instance, *device);
const vk::VkQueue queue (getQueue(vkd, *device, queueFamilyIndex));
TestLog& log = context.getTestContext().getLog();
const vk::Unique<vk::VkSemaphore> semaphoreA (createExportableSemaphore(vkd, *device, config.externalType));
const vk::Unique<vk::VkSemaphore> semaphoreB (createExportableSemaphore(vkd, *device, config.externalType));
{
NativeHandle fd, secondFd;
if (transference == TRANSFERENCE_COPY)
{
submitDummySignalAndGetSemaphoreNative(vkd, *device, queue, queueFamilyIndex, *semaphoreA, config.externalType, fd);
submitDummySignalAndGetSemaphoreNative(vkd, *device, queue, queueFamilyIndex, *semaphoreB, config.externalType, secondFd);
}
else
{
getSemaphoreNative(vkd, *device, *semaphoreA, config.externalType, fd);
getSemaphoreNative(vkd, *device, *semaphoreB, config.externalType, secondFd);
}
int newFd (dup2(fd.getFd(), secondFd.getFd()));
if (newFd < 0)
log << TestLog::Message << "dup2() failed: '" << strerror(errno) << "'" << TestLog::EndMessage;
TCU_CHECK_MSG(newFd >= 0, "Failed to call dup2() for fences fd");
{
const vk::Unique<vk::VkSemaphore> semaphoreC (createAndImportSemaphore(vkd, *device, config.externalType, secondFd, flags));
if (transference == TRANSFERENCE_COPY)
submitDummyWait(vkd, queue, *semaphoreC);
else if (transference == TRANSFERENCE_REFERENCE)
{
submitDummySignal(vkd, queue, *semaphoreA);
submitDummyWait(vkd, queue, *semaphoreC);
}
else
DE_FATAL("Unknown permanence.");
VK_CHECK(vkd.queueWaitIdle(queue));
}
}
return tcu::TestStatus::pass("Pass");
}
#else
DE_UNREF(context);
DE_UNREF(config);
TCU_THROW(NotSupportedError, "Platform doesn't support dup2()");
#endif
}
tcu::TestStatus testSemaphoreFdDup3 (Context& context,
const SemaphoreTestConfig config)
{
#if (DE_OS == DE_OS_UNIX) && defined(_GNU_SOURCE)
const Transference transference (getHandelTypeTransferences(config.externalType));
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), config.externalType, 0u, 0u));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice physicalDevice (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
const deUint32 queueFamilyIndex (chooseQueueFamilyIndex(vki, physicalDevice, 0u));
checkSemaphoreSupport(vki, physicalDevice, config.externalType);
{
const vk::Unique<vk::VkDevice> device (createDevice(context.getUsedApiVersion(), vkp, *instance, vki, physicalDevice, config.externalType, 0u, 0u, queueFamilyIndex));
const vk::DeviceDriver vkd (vkp, *instance, *device);
const vk::VkQueue queue (getQueue(vkd, *device, queueFamilyIndex));
TestLog& log = context.getTestContext().getLog();
const vk::Unique<vk::VkSemaphore> semaphoreA (createExportableSemaphore(vkd, *device, config.externalType));
const vk::Unique<vk::VkSemaphore> semaphoreB (createExportableSemaphore(vkd, *device, config.externalType));
{
NativeHandle fd, secondFd;
if (transference == TRANSFERENCE_COPY)
{
submitDummySignalAndGetSemaphoreNative(vkd, *device, queue, queueFamilyIndex, *semaphoreA, config.externalType, fd);
submitDummySignalAndGetSemaphoreNative(vkd, *device, queue, queueFamilyIndex, *semaphoreB, config.externalType, secondFd);
}
else
{
getSemaphoreNative(vkd, *device, *semaphoreA, config.externalType, fd);
getSemaphoreNative(vkd, *device, *semaphoreB, config.externalType, secondFd);
}
const vk::VkSemaphoreImportFlags flags = config.permanence == PERMANENCE_TEMPORARY ? vk::VK_SEMAPHORE_IMPORT_TEMPORARY_BIT : (vk::VkSemaphoreImportFlagBits)0u;
const int newFd (dup3(fd.getFd(), secondFd.getFd(), 0));
if (newFd < 0)
log << TestLog::Message << "dup3() failed: '" << strerror(errno) << "'" << TestLog::EndMessage;
TCU_CHECK_MSG(newFd >= 0, "Failed to call dup3() for fences fd");
{
const vk::Unique<vk::VkSemaphore> semaphoreC (createAndImportSemaphore(vkd, *device, config.externalType, secondFd, flags));
if (transference == TRANSFERENCE_COPY)
submitDummyWait(vkd, queue, *semaphoreC);
else if (transference == TRANSFERENCE_REFERENCE)
{
submitDummySignal(vkd, queue, *semaphoreA);
submitDummyWait(vkd, queue, *semaphoreC);
}
else
DE_FATAL("Unknown permanence.");
VK_CHECK(vkd.queueWaitIdle(queue));
}
}
return tcu::TestStatus::pass("Pass");
}
#else
DE_UNREF(context);
DE_UNREF(config);
TCU_THROW(NotSupportedError, "Platform doesn't support dup3()");
#endif
}
tcu::TestStatus testSemaphoreFdSendOverSocket (Context& context,
const SemaphoreTestConfig config)
{
#if (DE_OS == DE_OS_ANDROID) || (DE_OS == DE_OS_UNIX)
const Transference transference (getHandelTypeTransferences(config.externalType));
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), config.externalType, 0u, 0u));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice physicalDevice (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
const deUint32 queueFamilyIndex (chooseQueueFamilyIndex(vki, physicalDevice, 0u));
checkSemaphoreSupport(vki, physicalDevice, config.externalType);
{
const vk::Unique<vk::VkDevice> device (createDevice(context.getUsedApiVersion(), vkp, *instance, vki, physicalDevice, config.externalType, 0u, 0u, queueFamilyIndex));
const vk::DeviceDriver vkd (vkp, *instance, *device);
const vk::VkQueue queue (getQueue(vkd, *device, queueFamilyIndex));
TestLog& log = context.getTestContext().getLog();
const vk::Unique<vk::VkSemaphore> semaphore (createExportableSemaphore(vkd, *device, config.externalType));
NativeHandle fd;
if (transference == TRANSFERENCE_COPY)
submitDummySignalAndGetSemaphoreNative(vkd, *device, queue, queueFamilyIndex, *semaphore, config.externalType, fd);
else
getSemaphoreNative(vkd, *device, *semaphore, config.externalType, fd);
{
int sv[2];
if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv) != 0)
{
log << TestLog::Message << "Failed to create socket pair: '" << strerror(errno) << "'" << TestLog::EndMessage;
TCU_FAIL("Failed to create socket pair");
}
{
const NativeHandle srcSocket (sv[0]);
const NativeHandle dstSocket (sv[1]);
std::string sendData ("deqp");
// Send FD
{
const int fdRaw (fd.getFd());
msghdr msg;
cmsghdr* cmsg;
char buffer[CMSG_SPACE(sizeof(int))];
iovec iov = { &sendData[0], sendData.length()};
deMemset(&msg, 0, sizeof(msg));
msg.msg_control = buffer;
msg.msg_controllen = sizeof(buffer);
msg.msg_iovlen = 1;
msg.msg_iov = &iov;
cmsg = CMSG_FIRSTHDR(&msg);
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
deMemcpy(CMSG_DATA(cmsg), &fdRaw, sizeof(int));
msg.msg_controllen = cmsg->cmsg_len;
if (sendmsg(srcSocket.getFd(), &msg, 0) < 0)
{
log << TestLog::Message << "Failed to send fd over socket: '" << strerror(errno) << "'" << TestLog::EndMessage;
TCU_FAIL("Failed to send fd over socket");
}
}
// Recv FD
{
msghdr msg;
char buffer[CMSG_SPACE(sizeof(int))];
std::string recvData (4, '\0');
iovec iov = { &recvData[0], recvData.length() };
deMemset(&msg, 0, sizeof(msg));
msg.msg_control = buffer;
msg.msg_controllen = sizeof(buffer);
msg.msg_iovlen = 1;
msg.msg_iov = &iov;
const ssize_t bytes = recvmsg(dstSocket.getFd(), &msg, 0);
if (bytes < 0)
{
log << TestLog::Message << "Failed to recv fd over socket: '" << strerror(errno) << "'" << TestLog::EndMessage;
TCU_FAIL("Failed to recv fd over socket");
}
else if (bytes != (ssize_t)sendData.length())
{
TCU_FAIL("recvmsg() returned unpexpected number of bytes");
}
else
{
const vk::VkSemaphoreImportFlags flags = config.permanence == PERMANENCE_TEMPORARY ? vk::VK_SEMAPHORE_IMPORT_TEMPORARY_BIT : (vk::VkSemaphoreImportFlagBits)0u;
const cmsghdr* const cmsg = CMSG_FIRSTHDR(&msg);
int newFd_;
deMemcpy(&newFd_, CMSG_DATA(cmsg), sizeof(int));
NativeHandle newFd (newFd_);
TCU_CHECK(cmsg->cmsg_level == SOL_SOCKET);
TCU_CHECK(cmsg->cmsg_type == SCM_RIGHTS);
TCU_CHECK(cmsg->cmsg_len == CMSG_LEN(sizeof(int)));
TCU_CHECK(recvData == sendData);
TCU_CHECK_MSG(newFd.getFd() >= 0, "Didn't receive valid fd from socket");
{
const vk::Unique<vk::VkSemaphore> newSemaphore (createAndImportSemaphore(vkd, *device, config.externalType, newFd, flags));
if (transference == TRANSFERENCE_COPY)
submitDummyWait(vkd, queue, *newSemaphore);
else if (transference == TRANSFERENCE_REFERENCE)
{
submitDummySignal(vkd, queue, *newSemaphore);
submitDummyWait(vkd, queue, *newSemaphore);
}
else
DE_FATAL("Unknown permanence.");
VK_CHECK(vkd.queueWaitIdle(queue));
}
}
}
}
}
}
return tcu::TestStatus::pass("Pass");
#else
DE_UNREF(context);
DE_UNREF(config);
TCU_THROW(NotSupportedError, "Platform doesn't support sending file descriptors over socket");
#endif
}
tcu::TestStatus testFenceQueries (Context& context, vk::VkExternalFenceHandleTypeFlagBits externalType)
{
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), 0u, 0u, externalType));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice device (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
TestLog& log = context.getTestContext().getLog();
const vk::VkPhysicalDeviceExternalFenceInfo info =
{
vk::VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_FENCE_INFO,
DE_NULL,
externalType
};
vk::VkExternalFenceProperties properties =
{
vk::VK_STRUCTURE_TYPE_EXTERNAL_FENCE_PROPERTIES,
DE_NULL,
0u,
0u,
0u
};
vki.getPhysicalDeviceExternalFenceProperties(device, &info, &properties);
log << TestLog::Message << properties << TestLog::EndMessage;
TCU_CHECK(properties.pNext == DE_NULL);
TCU_CHECK(properties.sType == vk::VK_STRUCTURE_TYPE_EXTERNAL_FENCE_PROPERTIES);
return tcu::TestStatus::pass("Pass");
}
struct FenceTestConfig
{
FenceTestConfig (vk::VkExternalFenceHandleTypeFlagBits externalType_,
Permanence permanence_)
: externalType (externalType_)
, permanence (permanence_)
{
}
vk::VkExternalFenceHandleTypeFlagBits externalType;
Permanence permanence;
};
tcu::TestStatus testFenceWin32Create (Context& context,
const FenceTestConfig config)
{
#if (DE_OS == DE_OS_WIN32)
const Transference transference (getHandelTypeTransferences(config.externalType));
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), 0u, 0u, config.externalType));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice physicalDevice (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
const deUint32 queueFamilyIndex (chooseQueueFamilyIndex(vki, physicalDevice, 0u));
checkFenceSupport(vki, physicalDevice, config.externalType);
{
const vk::Unique<vk::VkDevice> device (createDevice(context.getUsedApiVersion(), vkp, *instance, vki, physicalDevice, 0u, 0u, config.externalType, queueFamilyIndex));
const vk::DeviceDriver vkd (vkp, *instance, *device);
const vk::VkQueue queue (getQueue(vkd, *device, queueFamilyIndex));
const vk::VkExportFenceWin32HandleInfoKHR win32ExportInfo =
{
vk::VK_STRUCTURE_TYPE_EXPORT_FENCE_WIN32_HANDLE_INFO_KHR,
DE_NULL,
(vk::pt::Win32SecurityAttributesPtr)DE_NULL,
DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE,
DE_NULL
};
const vk::VkExportFenceCreateInfo exportCreateInfo=
{
vk::VK_STRUCTURE_TYPE_EXPORT_FENCE_CREATE_INFO,
&win32ExportInfo,
(vk::VkExternalFenceHandleTypeFlags)config.externalType
};
const vk::VkFenceCreateInfo createInfo =
{
vk::VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
&exportCreateInfo,
0u
};
const vk::Unique<vk::VkFence> fence (vk::createFence(vkd, *device, &createInfo));
if (transference == TRANSFERENCE_COPY)
submitDummySignal(vkd, queue, *fence);
NativeHandle handleA;
getFenceNative(vkd, *device, *fence, config.externalType, handleA);
{
const vk::VkFenceImportFlags flags = config.permanence == PERMANENCE_TEMPORARY ? vk::VK_FENCE_IMPORT_TEMPORARY_BIT : (vk::VkFenceImportFlagBits)0u;
const vk::Unique<vk::VkFence> fenceA (createAndImportFence(vkd, *device, config.externalType, handleA, flags));
if (transference == TRANSFERENCE_COPY)
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceA, VK_TRUE, ~0ull));
else if (transference == TRANSFERENCE_REFERENCE)
{
submitDummySignal(vkd, queue, *fence);
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceA, VK_TRUE, ~0ull));
}
else
DE_FATAL("Unknown transference.");
VK_CHECK(vkd.queueWaitIdle(queue));
}
return tcu::TestStatus::pass("Pass");
}
#else
DE_UNREF(context);
DE_UNREF(config);
TCU_THROW(NotSupportedError, "Platform doesn't support win32 handles");
#endif
}
tcu::TestStatus testFenceImportTwice (Context& context,
const FenceTestConfig config)
{
const Transference transference (getHandelTypeTransferences(config.externalType));
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), 0u, 0u, config.externalType));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice physicalDevice (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
const deUint32 queueFamilyIndex (chooseQueueFamilyIndex(vki, physicalDevice, 0u));
checkFenceSupport(vki, physicalDevice, config.externalType);
{
const vk::Unique<vk::VkDevice> device (createDevice(context.getUsedApiVersion(), vkp, *instance, vki, physicalDevice, 0u, 0u, config.externalType, queueFamilyIndex));
const vk::DeviceDriver vkd (vkp, *instance, *device);
const vk::VkQueue queue (getQueue(vkd, *device, queueFamilyIndex));
const vk::Unique<vk::VkFence> fence (createExportableFence(vkd, *device, config.externalType));
NativeHandle handleA;
if (transference == TRANSFERENCE_COPY)
submitDummySignalAndGetFenceNative(vkd, *device, queue, queueFamilyIndex, *fence, config.externalType, handleA);
else
getFenceNative(vkd, *device, *fence, config.externalType, handleA);
{
NativeHandle handleB (handleA);
const vk::VkFenceImportFlags flags = config.permanence == PERMANENCE_TEMPORARY ? vk::VK_FENCE_IMPORT_TEMPORARY_BIT : (vk::VkFenceImportFlagBits)0u;
const vk::Unique<vk::VkFence> fenceA (createAndImportFence(vkd, *device, config.externalType, handleA, flags));
const vk::Unique<vk::VkFence> fenceB (createAndImportFence(vkd, *device, config.externalType, handleB, flags));
if (transference == TRANSFERENCE_COPY)
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceA, VK_TRUE, ~0ull));
else if (transference == TRANSFERENCE_REFERENCE)
{
submitDummySignal(vkd, queue, *fenceA);
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceB, VK_TRUE, ~0ull));
}
else
DE_FATAL("Unknown transference.");
VK_CHECK(vkd.queueWaitIdle(queue));
}
return tcu::TestStatus::pass("Pass");
}
}
tcu::TestStatus testFenceImportReimport (Context& context,
const FenceTestConfig config)
{
const Transference transference (getHandelTypeTransferences(config.externalType));
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), 0u, 0u, config.externalType));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice physicalDevice (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
const deUint32 queueFamilyIndex (chooseQueueFamilyIndex(vki, physicalDevice, 0u));
checkFenceSupport(vki, physicalDevice, config.externalType);
{
const vk::Unique<vk::VkDevice> device (createDevice(context.getUsedApiVersion(), vkp, *instance, vki, physicalDevice, 0u, 0u, config.externalType, queueFamilyIndex));
const vk::DeviceDriver vkd (vkp, *instance, *device);
const vk::VkQueue queue (getQueue(vkd, *device, queueFamilyIndex));
const vk::Unique<vk::VkFence> fenceA (createExportableFence(vkd, *device, config.externalType));
NativeHandle handleA;
if (transference == TRANSFERENCE_COPY)
submitDummySignalAndGetFenceNative(vkd, *device, queue, queueFamilyIndex, *fenceA, config.externalType, handleA);
else
getFenceNative(vkd, *device, *fenceA, config.externalType, handleA);
NativeHandle handleB (handleA);
const vk::VkFenceImportFlags flags = config.permanence == PERMANENCE_TEMPORARY ? vk::VK_FENCE_IMPORT_TEMPORARY_BIT : (vk::VkFenceImportFlagBits)0u;
const vk::Unique<vk::VkFence> fenceB (createAndImportFence(vkd, *device, config.externalType, handleA, flags));
importFence(vkd, *device, *fenceB, config.externalType, handleB, flags);
if (transference == TRANSFERENCE_COPY)
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceB, VK_TRUE, ~0ull));
else if (transference == TRANSFERENCE_REFERENCE)
{
submitDummySignal(vkd, queue, *fenceA);
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceB, VK_TRUE, ~0ull));
}
else
DE_FATAL("Unknown transference.");
VK_CHECK(vkd.queueWaitIdle(queue));
return tcu::TestStatus::pass("Pass");
}
}
tcu::TestStatus testFenceSignalExportImportWait (Context& context,
const FenceTestConfig config)
{
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), 0u, 0u, config.externalType));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice physicalDevice (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
const deUint32 queueFamilyIndex (chooseQueueFamilyIndex(vki, physicalDevice, 0u));
checkFenceSupport(vki, physicalDevice, config.externalType);
{
const vk::Unique<vk::VkDevice> device (createDevice(context.getUsedApiVersion(), vkp, *instance, vki, physicalDevice, 0u, 0u, config.externalType, queueFamilyIndex));
const vk::DeviceDriver vkd (vkp, *instance, *device);
const vk::VkQueue queue (getQueue(vkd, *device, queueFamilyIndex));
const vk::Unique<vk::VkFence> fenceA (createExportableFence(vkd, *device, config.externalType));
{
NativeHandle handle;
submitDummySignalAndGetFenceNative(vkd, *device, queue, queueFamilyIndex, *fenceA, config.externalType, handle);
{
const vk::VkFenceImportFlags flags = config.permanence == PERMANENCE_TEMPORARY ? vk::VK_FENCE_IMPORT_TEMPORARY_BIT : (vk::VkFenceImportFlagBits)0u;
const vk::Unique<vk::VkFence> fenceB (createAndImportFence(vkd, *device, config.externalType, handle, flags));
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceB, VK_TRUE, ~0ull));
VK_CHECK(vkd.queueWaitIdle(queue));
}
}
return tcu::TestStatus::pass("Pass");
}
}
tcu::TestStatus testFenceExportSignalImportWait (Context& context,
const FenceTestConfig config)
{
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), 0u, 0u, config.externalType));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice physicalDevice (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
const deUint32 queueFamilyIndex (chooseQueueFamilyIndex(vki, physicalDevice, 0u));
const vk::VkFenceImportFlags flags = config.permanence == PERMANENCE_TEMPORARY ? vk::VK_FENCE_IMPORT_TEMPORARY_BIT : (vk::VkFenceImportFlagBits)0u;
DE_ASSERT(getHandelTypeTransferences(config.externalType) == TRANSFERENCE_REFERENCE);
checkFenceSupport(vki, physicalDevice, config.externalType);
{
const vk::Unique<vk::VkDevice> device (createDevice(context.getUsedApiVersion(), vkp, *instance, vki, physicalDevice, 0u, 0u, config.externalType, queueFamilyIndex));
const vk::DeviceDriver vkd (vkp, *instance, *device);
const vk::VkQueue queue (getQueue(vkd, *device, queueFamilyIndex));
const vk::Unique<vk::VkFence> fenceA (createExportableFence(vkd, *device, config.externalType));
NativeHandle handle;
getFenceNative(vkd, *device, *fenceA, config.externalType, handle);
submitDummySignal(vkd, queue, *fenceA);
{
{
const vk::Unique<vk::VkFence> fenceB (createAndImportFence(vkd, *device, config.externalType, handle, flags));
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceB, VK_TRUE, ~0ull));
VK_CHECK(vkd.queueWaitIdle(queue));
}
}
return tcu::TestStatus::pass("Pass");
}
}
tcu::TestStatus testFenceExportImportSignalWait (Context& context,
const FenceTestConfig config)
{
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), 0u, 0u, config.externalType));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice physicalDevice (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
const deUint32 queueFamilyIndex (chooseQueueFamilyIndex(vki, physicalDevice, 0u));
DE_ASSERT(getHandelTypeTransferences(config.externalType) == TRANSFERENCE_REFERENCE);
checkFenceSupport(vki, physicalDevice, config.externalType);
{
const vk::VkFenceImportFlags flags = config.permanence == PERMANENCE_TEMPORARY ? vk::VK_FENCE_IMPORT_TEMPORARY_BIT : (vk::VkFenceImportFlagBits)0u;
const vk::Unique<vk::VkDevice> device (createDevice(context.getUsedApiVersion(), vkp, *instance, vki, physicalDevice, 0u, 0u, config.externalType, queueFamilyIndex));
const vk::DeviceDriver vkd (vkp, *instance, *device);
const vk::VkQueue queue (getQueue(vkd, *device, queueFamilyIndex));
const vk::Unique<vk::VkFence> fenceA (createExportableFence(vkd, *device, config.externalType));
NativeHandle handle;
getFenceNative(vkd, *device, *fenceA, config.externalType, handle);
const vk::Unique<vk::VkFence> fenceB (createAndImportFence(vkd, *device, config.externalType, handle, flags));
submitDummySignal(vkd, queue, *fenceA);
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceB, VK_TRUE, ~0ull));
VK_CHECK(vkd.queueWaitIdle(queue));
return tcu::TestStatus::pass("Pass");
}
}
tcu::TestStatus testFenceSignalImport (Context& context,
const FenceTestConfig config)
{
const Transference transference (getHandelTypeTransferences(config.externalType));
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), 0u, 0u, config.externalType));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice physicalDevice (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
const deUint32 queueFamilyIndex (chooseQueueFamilyIndex(vki, physicalDevice, 0u));
checkFenceSupport(vki, physicalDevice, config.externalType);
{
const vk::VkFenceImportFlags flags = config.permanence == PERMANENCE_TEMPORARY ? vk::VK_FENCE_IMPORT_TEMPORARY_BIT : (vk::VkFenceImportFlagBits)0u;
const vk::Unique<vk::VkDevice> device (createDevice(context.getUsedApiVersion(), vkp, *instance, vki, physicalDevice, 0u, 0u, config.externalType, queueFamilyIndex));
const vk::DeviceDriver vkd (vkp, *instance, *device);
const vk::VkQueue queue (getQueue(vkd, *device, queueFamilyIndex));
const vk::Unique<vk::VkFence> fenceA (createExportableFence(vkd, *device, config.externalType));
const vk::Unique<vk::VkFence> fenceB (createFence(vkd, *device));
NativeHandle handle;
submitDummySignal(vkd, queue, *fenceB);
VK_CHECK(vkd.queueWaitIdle(queue));
if (transference == TRANSFERENCE_COPY)
submitDummySignalAndGetFenceNative(vkd, *device, queue, queueFamilyIndex, *fenceA, config.externalType, handle);
else
getFenceNative(vkd, *device, *fenceA, config.externalType, handle);
importFence(vkd, *device, *fenceB, config.externalType, handle, flags);
if (transference == TRANSFERENCE_COPY)
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceB, VK_TRUE, ~0ull));
else if (transference == TRANSFERENCE_REFERENCE)
{
submitDummySignal(vkd, queue, *fenceA);
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceB, VK_TRUE, ~0ull));
}
else
DE_FATAL("Unknown transference.");
VK_CHECK(vkd.queueWaitIdle(queue));
return tcu::TestStatus::pass("Pass");
}
}
tcu::TestStatus testFenceReset (Context& context,
const FenceTestConfig config)
{
const Transference transference (getHandelTypeTransferences(config.externalType));
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), 0u, 0u, config.externalType));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice physicalDevice (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
const deUint32 queueFamilyIndex (chooseQueueFamilyIndex(vki, physicalDevice, 0u));
checkFenceSupport(vki, physicalDevice, config.externalType);
{
const vk::VkFenceImportFlags flags = config.permanence == PERMANENCE_TEMPORARY ? vk::VK_FENCE_IMPORT_TEMPORARY_BIT : (vk::VkFenceImportFlagBits)0u;
const vk::Unique<vk::VkDevice> device (createDevice(context.getUsedApiVersion(), vkp, *instance, vki, physicalDevice, 0u, 0u, config.externalType, queueFamilyIndex));
const vk::DeviceDriver vkd (vkp, *instance, *device);
const vk::VkQueue queue (getQueue(vkd, *device, queueFamilyIndex));
const vk::Unique<vk::VkFence> fenceA (createExportableFence(vkd, *device, config.externalType));
const vk::Unique<vk::VkFence> fenceB (createFence(vkd, *device));
const vk::Unique<vk::VkFence> fenceC (createFence(vkd, *device));
NativeHandle handle;
submitDummySignal(vkd, queue, *fenceB);
VK_CHECK(vkd.queueWaitIdle(queue));
submitDummySignalAndGetFenceNative(vkd, *device, queue, queueFamilyIndex, *fenceA, config.externalType, handle);
NativeHandle handleB (handle);
importFence(vkd, *device, *fenceB, config.externalType, handleB, flags);
importFence(vkd, *device, *fenceC, config.externalType, handle, flags);
VK_CHECK(vkd.queueWaitIdle(queue));
VK_CHECK(vkd.resetFences(*device, 1u, &*fenceB));
if (config.permanence == PERMANENCE_TEMPORARY || transference == TRANSFERENCE_COPY)
{
// vkResetFences() should restore fenceBs prior payload and reset that no affecting fenceCs payload
// or fenceB should be separate copy of the payload and not affect fenceC
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceC, VK_TRUE, ~0ull));
// vkResetFences() should have restored fenceBs prior state and should be now reset
// or fenceB should have it's separate payload
submitDummySignal(vkd, queue, *fenceB);
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceB, VK_TRUE, ~0ull));
}
else if (config.permanence == PERMANENCE_PERMANENT)
{
DE_ASSERT(transference == TRANSFERENCE_REFERENCE);
// Reset fences should have reset all of the fences
submitDummySignal(vkd, queue, *fenceC);
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceA, VK_TRUE, ~0ull));
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceB, VK_TRUE, ~0ull));
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceC, VK_TRUE, ~0ull));
}
else
DE_FATAL("Unknown permanence");
VK_CHECK(vkd.queueWaitIdle(queue));
return tcu::TestStatus::pass("Pass");
}
}
tcu::TestStatus testFenceSignalWaitImport (Context& context,
const FenceTestConfig config)
{
const Transference transference (getHandelTypeTransferences(config.externalType));
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), 0u, 0u, config.externalType));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice physicalDevice (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
const deUint32 queueFamilyIndex (chooseQueueFamilyIndex(vki, physicalDevice, 0u));
checkFenceSupport(vki, physicalDevice, config.externalType);
{
const vk::VkFenceImportFlags flags = config.permanence == PERMANENCE_TEMPORARY ? vk::VK_FENCE_IMPORT_TEMPORARY_BIT : (vk::VkFenceImportFlagBits)0u;
const vk::Unique<vk::VkDevice> device (createDevice(context.getUsedApiVersion(), vkp, *instance, vki, physicalDevice, 0u, 0u, config.externalType, queueFamilyIndex));
const vk::DeviceDriver vkd (vkp, *instance, *device);
const vk::VkQueue queue (getQueue(vkd, *device, queueFamilyIndex));
const vk::Unique<vk::VkFence> fenceA (createExportableFence(vkd, *device, config.externalType));
const vk::Unique<vk::VkFence> fenceB (createFence(vkd, *device));
NativeHandle handle;
if (transference == TRANSFERENCE_COPY)
submitDummySignalAndGetFenceNative(vkd, *device, queue, queueFamilyIndex, *fenceA, config.externalType, handle);
else
getFenceNative(vkd, *device, *fenceA, config.externalType, handle);
submitDummySignal(vkd, queue, *fenceB);
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceB, VK_TRUE, ~0ull));
VK_CHECK(vkd.queueWaitIdle(queue));
importFence(vkd, *device, *fenceB, config.externalType, handle, flags);
if (transference == TRANSFERENCE_COPY)
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceB, VK_TRUE, ~0ull));
else if (transference == TRANSFERENCE_REFERENCE)
{
submitDummySignal(vkd, queue, *fenceA);
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceB, VK_TRUE, ~0ull));
}
else
DE_FATAL("Unknown transference.");
VK_CHECK(vkd.queueWaitIdle(queue));
return tcu::TestStatus::pass("Pass");
}
}
tcu::TestStatus testFenceMultipleExports (Context& context,
const FenceTestConfig config)
{
const size_t exportCount = 4 * 1024;
const Transference transference (getHandelTypeTransferences(config.externalType));
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), 0u, 0u, config.externalType));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice physicalDevice (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
const deUint32 queueFamilyIndex (chooseQueueFamilyIndex(vki, physicalDevice, 0u));
checkFenceSupport(vki, physicalDevice, config.externalType);
{
const vk::Unique<vk::VkDevice> device (createDevice(context.getUsedApiVersion(), vkp, *instance, vki, physicalDevice, 0u, 0u, config.externalType, queueFamilyIndex));
const vk::DeviceDriver vkd (vkp, *instance, *device);
const vk::VkQueue queue (getQueue(vkd, *device, queueFamilyIndex));
const vk::Unique<vk::VkFence> fence (createExportableFence(vkd, *device, config.externalType));
for (size_t exportNdx = 0; exportNdx < exportCount; exportNdx++)
{
NativeHandle handle;
if (transference == TRANSFERENCE_COPY)
submitDummySignalAndGetFenceNative(vkd, *device, queue, queueFamilyIndex, *fence, config.externalType, handle);
else
getFenceNative(vkd, *device, *fence, config.externalType, handle);
}
submitDummySignal(vkd, queue, *fence);
VK_CHECK(vkd.waitForFences(*device, 1u, &*fence, VK_TRUE, ~0ull));
VK_CHECK(vkd.queueWaitIdle(queue));
}
return tcu::TestStatus::pass("Pass");
}
tcu::TestStatus testFenceMultipleImports (Context& context,
const FenceTestConfig config)
{
const size_t importCount = 4 * 1024;
const Transference transference (getHandelTypeTransferences(config.externalType));
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), 0u, 0u, config.externalType));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice physicalDevice (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
const deUint32 queueFamilyIndex (chooseQueueFamilyIndex(vki, physicalDevice, 0u));
checkFenceSupport(vki, physicalDevice, config.externalType);
{
const vk::VkFenceImportFlags flags = config.permanence == PERMANENCE_TEMPORARY ? vk::VK_FENCE_IMPORT_TEMPORARY_BIT : (vk::VkFenceImportFlagBits)0u;
const vk::Unique<vk::VkDevice> device (createDevice(context.getUsedApiVersion(), vkp, *instance, vki, physicalDevice, 0u, 0u, config.externalType, queueFamilyIndex));
const vk::DeviceDriver vkd (vkp, *instance, *device);
const vk::VkQueue queue (getQueue(vkd, *device, queueFamilyIndex));
const vk::Unique<vk::VkFence> fenceA (createExportableFence(vkd, *device, config.externalType));
NativeHandle handleA;
if (transference == TRANSFERENCE_COPY)
submitDummySignalAndGetFenceNative(vkd, *device, queue, queueFamilyIndex, *fenceA, config.externalType, handleA);
else
getFenceNative(vkd, *device, *fenceA, config.externalType, handleA);
for (size_t importNdx = 0; importNdx < importCount; importNdx++)
{
NativeHandle handleB (handleA);
const vk::Unique<vk::VkFence> fenceB (createAndImportFence(vkd, *device, config.externalType, handleB, flags));
}
if (transference == TRANSFERENCE_COPY)
{
importFence(vkd, *device, *fenceA, config.externalType, handleA, flags);
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceA, VK_TRUE, ~0ull));
}
else if (transference == TRANSFERENCE_REFERENCE)
{
submitDummySignal(vkd, queue, *fenceA);
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceA, VK_TRUE, ~0ull));
}
else
DE_FATAL("Unknown transference.");
VK_CHECK(vkd.queueWaitIdle(queue));
}
return tcu::TestStatus::pass("Pass");
}
tcu::TestStatus testFenceTransference (Context& context,
const FenceTestConfig config)
{
const Transference transference (getHandelTypeTransferences(config.externalType));
const vk::PlatformInterface& vkp (context.getPlatformInterface());
const vk::Unique<vk::VkInstance> instance (createInstance(vkp, context.getUsedApiVersion(), 0u, 0u, config.externalType));
const vk::InstanceDriver vki (vkp, *instance);
const vk::VkPhysicalDevice physicalDevice (vk::chooseDevice(vki, *instance, context.getTestContext().getCommandLine()));
const deUint32 queueFamilyIndex (chooseQueueFamilyIndex(vki, physicalDevice, 0u));
checkFenceSupport(vki, physicalDevice, config.externalType);
{
const vk::VkFenceImportFlags flags = config.permanence == PERMANENCE_TEMPORARY ? vk::VK_FENCE_IMPORT_TEMPORARY_BIT : (vk::VkFenceImportFlagBits)0u;
const vk::Unique<vk::VkDevice> device (createDevice(context.getUsedApiVersion(), vkp, *instance, vki, physicalDevice, 0u, 0u, config.externalType, queueFamilyIndex));
const vk::DeviceDriver vkd (vkp, *instance, *device);
const vk::VkQueue queue (getQueue(vkd, *device, queueFamilyIndex));
const vk::Unique<vk::VkFence> fenceA (createExportableFence(vkd, *device, config.externalType));
NativeHandle handle;
submitDummySignalAndGetFenceNative(vkd, *device, queue, queueFamilyIndex, *fenceA, config.externalType, handle);
{
const vk::Unique<vk::VkFence> fenceB (createAndImportFence(vkd, *device, config.externalType, handle, flags));
if (config.permanence == PERMANENCE_PERMANENT)
{
if (transference == TRANSFERENCE_COPY)
{
submitDummySignal(vkd, queue, *fenceA);
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceB, VK_TRUE, ~0ull));
VK_CHECK(vkd.queueWaitIdle(queue));
VK_CHECK(vkd.resetFences(*device, 1u, &*fenceB));
submitDummySignal(vkd, queue, *fenceB);
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceA, VK_TRUE, ~0ull));
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceB, VK_TRUE, ~0ull));
VK_CHECK(vkd.queueWaitIdle(queue));
}
else if (transference== TRANSFERENCE_REFERENCE)
{
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceB, VK_TRUE, ~0ull));
VK_CHECK(vkd.queueWaitIdle(queue));
VK_CHECK(vkd.resetFences(*device, 1u, &*fenceB));
submitDummySignal(vkd, queue, *fenceA);
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceB, VK_TRUE, ~0ull));
VK_CHECK(vkd.resetFences(*device, 1u, &*fenceA));
submitDummySignal(vkd, queue, *fenceB);
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceA, VK_TRUE, ~0ull));
VK_CHECK(vkd.queueWaitIdle(queue));
}
else
DE_FATAL("Unknown transference.");
}
else if (config.permanence == PERMANENCE_TEMPORARY)
{
if (transference == TRANSFERENCE_COPY)
{
submitDummySignal(vkd, queue, *fenceA);
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceB, VK_TRUE, ~0ull));
VK_CHECK(vkd.queueWaitIdle(queue));
VK_CHECK(vkd.resetFences(*device, 1u, &*fenceB));
submitDummySignal(vkd, queue, *fenceB);
VK_CHECK(vkd.waitForFences(*device, 1u, &*fenceA, VK_TRUE, ~0ull));
VK_CHECK(vkd.waitForFence