vktTestCase.cpp revision bd0311e17f335ca7e184f35e2d2ca1c826364039
112edbd9c94d5380368146b99cfdf24b811c5f46bPyry Haulos/*------------------------------------------------------------------------- 2846cc3ce8e721a972ef38c44e24da49ea96110caPyry Haulos * Vulkan Conformance Tests 3846cc3ce8e721a972ef38c44e24da49ea96110caPyry Haulos * ------------------------ 412edbd9c94d5380368146b99cfdf24b811c5f46bPyry Haulos * 5846cc3ce8e721a972ef38c44e24da49ea96110caPyry Haulos * Copyright (c) 2015 Google Inc. 612edbd9c94d5380368146b99cfdf24b811c5f46bPyry Haulos * 7846cc3ce8e721a972ef38c44e24da49ea96110caPyry Haulos * Permission is hereby granted, free of charge, to any person obtaining a 8846cc3ce8e721a972ef38c44e24da49ea96110caPyry Haulos * copy of this software and/or associated documentation files (the 9846cc3ce8e721a972ef38c44e24da49ea96110caPyry Haulos * "Materials"), to deal in the Materials without restriction, including 10846cc3ce8e721a972ef38c44e24da49ea96110caPyry Haulos * without limitation the rights to use, copy, modify, merge, publish, 11846cc3ce8e721a972ef38c44e24da49ea96110caPyry Haulos * distribute, sublicense, and/or sell copies of the Materials, and to 12846cc3ce8e721a972ef38c44e24da49ea96110caPyry Haulos * permit persons to whom the Materials are furnished to do so, subject to 13846cc3ce8e721a972ef38c44e24da49ea96110caPyry Haulos * the following conditions: 1412edbd9c94d5380368146b99cfdf24b811c5f46bPyry Haulos * 15846cc3ce8e721a972ef38c44e24da49ea96110caPyry Haulos * The above copyright notice(s) and this permission notice shall be 16846cc3ce8e721a972ef38c44e24da49ea96110caPyry Haulos * included in all copies or substantial portions of the Materials. 1712edbd9c94d5380368146b99cfdf24b811c5f46bPyry Haulos * 18846cc3ce8e721a972ef38c44e24da49ea96110caPyry Haulos * The Materials are Confidential Information as defined by the 19846cc3ce8e721a972ef38c44e24da49ea96110caPyry Haulos * Khronos Membership Agreement until designated non-confidential by 20846cc3ce8e721a972ef38c44e24da49ea96110caPyry Haulos * Khronos, at which point this condition clause shall be removed. 21846cc3ce8e721a972ef38c44e24da49ea96110caPyry Haulos * 22846cc3ce8e721a972ef38c44e24da49ea96110caPyry Haulos * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23846cc3ce8e721a972ef38c44e24da49ea96110caPyry Haulos * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24846cc3ce8e721a972ef38c44e24da49ea96110caPyry Haulos * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 25846cc3ce8e721a972ef38c44e24da49ea96110caPyry Haulos * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 26846cc3ce8e721a972ef38c44e24da49ea96110caPyry Haulos * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 27846cc3ce8e721a972ef38c44e24da49ea96110caPyry Haulos * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 28846cc3ce8e721a972ef38c44e24da49ea96110caPyry Haulos * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 2912edbd9c94d5380368146b99cfdf24b811c5f46bPyry Haulos * 3012edbd9c94d5380368146b99cfdf24b811c5f46bPyry Haulos *//*! 3112edbd9c94d5380368146b99cfdf24b811c5f46bPyry Haulos * \file 3212edbd9c94d5380368146b99cfdf24b811c5f46bPyry Haulos * \brief Vulkan test case base classes 3312edbd9c94d5380368146b99cfdf24b811c5f46bPyry Haulos *//*--------------------------------------------------------------------*/ 3412edbd9c94d5380368146b99cfdf24b811c5f46bPyry Haulos 3512edbd9c94d5380368146b99cfdf24b811c5f46bPyry Haulos#include "vktTestCase.hpp" 3612edbd9c94d5380368146b99cfdf24b811c5f46bPyry Haulos 3732675035be2a05886457025598f90c131d83c670Pyry Haulos#include "vkRef.hpp" 3832675035be2a05886457025598f90c131d83c670Pyry Haulos#include "vkQueryUtil.hpp" 3932675035be2a05886457025598f90c131d83c670Pyry Haulos#include "vkDeviceUtil.hpp" 40bd0311e17f335ca7e184f35e2d2ca1c826364039Jarkko Pöyry#include "vkMemUtil.hpp" 4132675035be2a05886457025598f90c131d83c670Pyry Haulos#include "vkPlatform.hpp" 4232675035be2a05886457025598f90c131d83c670Pyry Haulos 4332675035be2a05886457025598f90c131d83c670Pyry Haulos#include "deMemory.h" 4432675035be2a05886457025598f90c131d83c670Pyry Haulos 4512edbd9c94d5380368146b99cfdf24b811c5f46bPyry Haulosnamespace vkt 4612edbd9c94d5380368146b99cfdf24b811c5f46bPyry Haulos{ 4712edbd9c94d5380368146b99cfdf24b811c5f46bPyry Haulos 4832675035be2a05886457025598f90c131d83c670Pyry Haulos// Default device utilities 4932675035be2a05886457025598f90c131d83c670Pyry Haulos 5032675035be2a05886457025598f90c131d83c670Pyry Haulosusing std::vector; 5132675035be2a05886457025598f90c131d83c670Pyry Haulosusing namespace vk; 5232675035be2a05886457025598f90c131d83c670Pyry Haulos 53fa8d8350fe202ecc4697be1d08f2047c90e91332Jarkko Pöyrystatic deUint32 findQueueFamilyIndexWithCaps (const InstanceInterface& vkInstance, VkPhysicalDevice physicalDevice, VkQueueFlags requiredCaps) 5432675035be2a05886457025598f90c131d83c670Pyry Haulos{ 55b1a7d2198497be32dfc22386f99945656ff4080ePyry Haulos const vector<VkPhysicalDeviceQueueProperties> queueProps = getPhysicalDeviceQueueProperties(vkInstance, physicalDevice); 5632675035be2a05886457025598f90c131d83c670Pyry Haulos 5732675035be2a05886457025598f90c131d83c670Pyry Haulos for (size_t queueNdx = 0; queueNdx < queueProps.size(); queueNdx++) 5832675035be2a05886457025598f90c131d83c670Pyry Haulos { 5932675035be2a05886457025598f90c131d83c670Pyry Haulos if ((queueProps[queueNdx].queueFlags & requiredCaps) == requiredCaps) 6032675035be2a05886457025598f90c131d83c670Pyry Haulos return (deUint32)queueNdx; 6132675035be2a05886457025598f90c131d83c670Pyry Haulos } 6232675035be2a05886457025598f90c131d83c670Pyry Haulos 6332675035be2a05886457025598f90c131d83c670Pyry Haulos TCU_THROW(NotSupportedError, "No matching queue found"); 6432675035be2a05886457025598f90c131d83c670Pyry Haulos} 6532675035be2a05886457025598f90c131d83c670Pyry Haulos 6632675035be2a05886457025598f90c131d83c670Pyry Haulosstruct DeviceCreateInfoHelper 6732675035be2a05886457025598f90c131d83c670Pyry Haulos{ 68b1a7d2198497be32dfc22386f99945656ff4080ePyry Haulos VkPhysicalDeviceFeatures enabledFeatures; 6932675035be2a05886457025598f90c131d83c670Pyry Haulos VkDeviceQueueCreateInfo queueInfo; 7032675035be2a05886457025598f90c131d83c670Pyry Haulos VkDeviceCreateInfo deviceInfo; 7132675035be2a05886457025598f90c131d83c670Pyry Haulos 7232675035be2a05886457025598f90c131d83c670Pyry Haulos DeviceCreateInfoHelper (deUint32 queueIndex) 7332675035be2a05886457025598f90c131d83c670Pyry Haulos { 74b1a7d2198497be32dfc22386f99945656ff4080ePyry Haulos deMemset(&enabledFeatures, 0, sizeof(enabledFeatures)); 75b1a7d2198497be32dfc22386f99945656ff4080ePyry Haulos deMemset(&queueInfo, 0, sizeof(queueInfo)); 76b1a7d2198497be32dfc22386f99945656ff4080ePyry Haulos deMemset(&deviceInfo, 0, sizeof(deviceInfo)); 7732675035be2a05886457025598f90c131d83c670Pyry Haulos 78b1a7d2198497be32dfc22386f99945656ff4080ePyry Haulos // \todo [2015-07-09 pyry] What's the policy for enabling features? 79b1a7d2198497be32dfc22386f99945656ff4080ePyry Haulos // * Enable all supported by default, and expose that to test cases 80b1a7d2198497be32dfc22386f99945656ff4080ePyry Haulos // * More limited enabled set could be used for verifying that tests behave correctly 81b1a7d2198497be32dfc22386f99945656ff4080ePyry Haulos 82b1a7d2198497be32dfc22386f99945656ff4080ePyry Haulos queueInfo.queueFamilyIndex = queueIndex; 8332675035be2a05886457025598f90c131d83c670Pyry Haulos queueInfo.queueCount = 1u; 8432675035be2a05886457025598f90c131d83c670Pyry Haulos 8532675035be2a05886457025598f90c131d83c670Pyry Haulos deviceInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; 8632675035be2a05886457025598f90c131d83c670Pyry Haulos deviceInfo.pNext = DE_NULL; 8732675035be2a05886457025598f90c131d83c670Pyry Haulos deviceInfo.queueRecordCount = 1u; 8832675035be2a05886457025598f90c131d83c670Pyry Haulos deviceInfo.pRequestedQueues = &queueInfo; 8932675035be2a05886457025598f90c131d83c670Pyry Haulos deviceInfo.extensionCount = 0u; 9032675035be2a05886457025598f90c131d83c670Pyry Haulos deviceInfo.ppEnabledExtensionNames = DE_NULL; 91b1a7d2198497be32dfc22386f99945656ff4080ePyry Haulos deviceInfo.pEnabledFeatures = &enabledFeatures; 9232675035be2a05886457025598f90c131d83c670Pyry Haulos deviceInfo.flags = 0u; 9332675035be2a05886457025598f90c131d83c670Pyry Haulos } 9432675035be2a05886457025598f90c131d83c670Pyry Haulos}; 9532675035be2a05886457025598f90c131d83c670Pyry Haulos 9632675035be2a05886457025598f90c131d83c670Pyry Haulosclass DefaultDevice 9732675035be2a05886457025598f90c131d83c670Pyry Haulos{ 9832675035be2a05886457025598f90c131d83c670Pyry Haulospublic: 99fa8d8350fe202ecc4697be1d08f2047c90e91332Jarkko Pöyry DefaultDevice (const PlatformInterface& vkPlatform, const tcu::CommandLine& cmdLine); 100fa8d8350fe202ecc4697be1d08f2047c90e91332Jarkko Pöyry ~DefaultDevice (void); 10132675035be2a05886457025598f90c131d83c670Pyry Haulos 102fa8d8350fe202ecc4697be1d08f2047c90e91332Jarkko Pöyry VkInstance getInstance (void) const { return *m_instance; } 103fa8d8350fe202ecc4697be1d08f2047c90e91332Jarkko Pöyry const InstanceInterface& getInstanceInterface (void) const { return m_instanceInterface; } 104b1a7d2198497be32dfc22386f99945656ff4080ePyry Haulos 105fa8d8350fe202ecc4697be1d08f2047c90e91332Jarkko Pöyry VkPhysicalDevice getPhysicalDevice (void) const { return m_physicalDevice; } 106b1a7d2198497be32dfc22386f99945656ff4080ePyry Haulos 107fa8d8350fe202ecc4697be1d08f2047c90e91332Jarkko Pöyry VkDevice getDevice (void) const { return *m_device; } 108fa8d8350fe202ecc4697be1d08f2047c90e91332Jarkko Pöyry const DeviceInterface& getDeviceInterface (void) const { return m_deviceInterface; } 109b1a7d2198497be32dfc22386f99945656ff4080ePyry Haulos 110fa8d8350fe202ecc4697be1d08f2047c90e91332Jarkko Pöyry deUint32 getUniversalQueueFamilyIndex (void) const { return m_universalQueueFamilyIndex; } 111fa8d8350fe202ecc4697be1d08f2047c90e91332Jarkko Pöyry VkQueue getUniversalQueue (void) const; 11232675035be2a05886457025598f90c131d83c670Pyry Haulos 11332675035be2a05886457025598f90c131d83c670Pyry Haulosprivate: 114b1a7d2198497be32dfc22386f99945656ff4080ePyry Haulos const Unique<VkInstance> m_instance; 115b1a7d2198497be32dfc22386f99945656ff4080ePyry Haulos const InstanceDriver m_instanceInterface; 116b1a7d2198497be32dfc22386f99945656ff4080ePyry Haulos 11732675035be2a05886457025598f90c131d83c670Pyry Haulos const VkPhysicalDevice m_physicalDevice; 118b1a7d2198497be32dfc22386f99945656ff4080ePyry Haulos 119fa8d8350fe202ecc4697be1d08f2047c90e91332Jarkko Pöyry const deUint32 m_universalQueueFamilyIndex; 12032675035be2a05886457025598f90c131d83c670Pyry Haulos const DeviceCreateInfoHelper m_deviceCreateInfo; 121b1a7d2198497be32dfc22386f99945656ff4080ePyry Haulos 122b1a7d2198497be32dfc22386f99945656ff4080ePyry Haulos const Unique<VkDevice> m_device; 123b1a7d2198497be32dfc22386f99945656ff4080ePyry Haulos const DeviceDriver m_deviceInterface; 12432675035be2a05886457025598f90c131d83c670Pyry Haulos}; 12532675035be2a05886457025598f90c131d83c670Pyry Haulos 12632675035be2a05886457025598f90c131d83c670Pyry HaulosDefaultDevice::DefaultDevice (const PlatformInterface& vkPlatform, const tcu::CommandLine& cmdLine) 127fa8d8350fe202ecc4697be1d08f2047c90e91332Jarkko Pöyry : m_instance (createDefaultInstance(vkPlatform)) 128fa8d8350fe202ecc4697be1d08f2047c90e91332Jarkko Pöyry , m_instanceInterface (vkPlatform, *m_instance) 129fa8d8350fe202ecc4697be1d08f2047c90e91332Jarkko Pöyry , m_physicalDevice (chooseDevice(m_instanceInterface, *m_instance, cmdLine)) 130fa8d8350fe202ecc4697be1d08f2047c90e91332Jarkko Pöyry , m_universalQueueFamilyIndex (findQueueFamilyIndexWithCaps(m_instanceInterface, m_physicalDevice, VK_QUEUE_GRAPHICS_BIT|VK_QUEUE_COMPUTE_BIT|VK_QUEUE_DMA_BIT)) 131fa8d8350fe202ecc4697be1d08f2047c90e91332Jarkko Pöyry , m_deviceCreateInfo (m_universalQueueFamilyIndex) 132fa8d8350fe202ecc4697be1d08f2047c90e91332Jarkko Pöyry , m_device (createDevice(m_instanceInterface, m_physicalDevice, &m_deviceCreateInfo.deviceInfo)) 133fa8d8350fe202ecc4697be1d08f2047c90e91332Jarkko Pöyry , m_deviceInterface (m_instanceInterface, *m_device) 13432675035be2a05886457025598f90c131d83c670Pyry Haulos{ 13532675035be2a05886457025598f90c131d83c670Pyry Haulos} 13632675035be2a05886457025598f90c131d83c670Pyry Haulos 13732675035be2a05886457025598f90c131d83c670Pyry HaulosDefaultDevice::~DefaultDevice (void) 13832675035be2a05886457025598f90c131d83c670Pyry Haulos{ 13932675035be2a05886457025598f90c131d83c670Pyry Haulos} 14032675035be2a05886457025598f90c131d83c670Pyry Haulos 14132675035be2a05886457025598f90c131d83c670Pyry HaulosVkQueue DefaultDevice::getUniversalQueue (void) const 14232675035be2a05886457025598f90c131d83c670Pyry Haulos{ 14332675035be2a05886457025598f90c131d83c670Pyry Haulos VkQueue queue = 0; 144fa8d8350fe202ecc4697be1d08f2047c90e91332Jarkko Pöyry VK_CHECK(m_deviceInterface.getDeviceQueue(*m_device, m_universalQueueFamilyIndex, 0, &queue)); 14532675035be2a05886457025598f90c131d83c670Pyry Haulos return queue; 14632675035be2a05886457025598f90c131d83c670Pyry Haulos} 14732675035be2a05886457025598f90c131d83c670Pyry Haulos 148bd0311e17f335ca7e184f35e2d2ca1c826364039Jarkko Pöyry// Allocator utilities 149bd0311e17f335ca7e184f35e2d2ca1c826364039Jarkko Pöyry 150bd0311e17f335ca7e184f35e2d2ca1c826364039Jarkko Pöyryvk::Allocator* createAllocator (DefaultDevice* device) 151bd0311e17f335ca7e184f35e2d2ca1c826364039Jarkko Pöyry{ 152bd0311e17f335ca7e184f35e2d2ca1c826364039Jarkko Pöyry const VkPhysicalDeviceMemoryProperties memoryProperties = vk::getPhysicalDeviceMemoryProperties(device->getInstanceInterface(), device->getPhysicalDevice()); 153bd0311e17f335ca7e184f35e2d2ca1c826364039Jarkko Pöyry 154bd0311e17f335ca7e184f35e2d2ca1c826364039Jarkko Pöyry // \todo [2015-07-24 jarkko] support allocator selection/configuration from command line (or compile time) 155bd0311e17f335ca7e184f35e2d2ca1c826364039Jarkko Pöyry return new SimpleAllocator(device->getDeviceInterface(), device->getDevice(), memoryProperties); 156bd0311e17f335ca7e184f35e2d2ca1c826364039Jarkko Pöyry} 157bd0311e17f335ca7e184f35e2d2ca1c826364039Jarkko Pöyry 15832675035be2a05886457025598f90c131d83c670Pyry Haulos// Context 15932675035be2a05886457025598f90c131d83c670Pyry Haulos 16032675035be2a05886457025598f90c131d83c670Pyry HaulosContext::Context (tcu::TestContext& testCtx, 16132675035be2a05886457025598f90c131d83c670Pyry Haulos const vk::PlatformInterface& platformInterface, 16232675035be2a05886457025598f90c131d83c670Pyry Haulos vk::ProgramCollection<vk::ProgramBinary>& progCollection) 16332675035be2a05886457025598f90c131d83c670Pyry Haulos : m_testCtx (testCtx) 16432675035be2a05886457025598f90c131d83c670Pyry Haulos , m_platformInterface (platformInterface) 16532675035be2a05886457025598f90c131d83c670Pyry Haulos , m_progCollection (progCollection) 16632675035be2a05886457025598f90c131d83c670Pyry Haulos , m_device (new DefaultDevice(m_platformInterface, testCtx.getCommandLine())) 167bd0311e17f335ca7e184f35e2d2ca1c826364039Jarkko Pöyry , m_allocator (createAllocator(m_device.get())) 16832675035be2a05886457025598f90c131d83c670Pyry Haulos{ 16932675035be2a05886457025598f90c131d83c670Pyry Haulos} 17032675035be2a05886457025598f90c131d83c670Pyry Haulos 17132675035be2a05886457025598f90c131d83c670Pyry HaulosContext::~Context (void) 17232675035be2a05886457025598f90c131d83c670Pyry Haulos{ 17332675035be2a05886457025598f90c131d83c670Pyry Haulos} 17432675035be2a05886457025598f90c131d83c670Pyry Haulos 175fa8d8350fe202ecc4697be1d08f2047c90e91332Jarkko Pöyryvk::VkInstance Context::getInstance (void) const { return m_device->getInstance(); } 176fa8d8350fe202ecc4697be1d08f2047c90e91332Jarkko Pöyryconst vk::InstanceInterface& Context::getInstanceInterface (void) const { return m_device->getInstanceInterface(); } 177fa8d8350fe202ecc4697be1d08f2047c90e91332Jarkko Pöyryvk::VkPhysicalDevice Context::getPhysicalDevice (void) const { return m_device->getPhysicalDevice(); } 178fa8d8350fe202ecc4697be1d08f2047c90e91332Jarkko Pöyryvk::VkDevice Context::getDevice (void) const { return m_device->getDevice(); } 179fa8d8350fe202ecc4697be1d08f2047c90e91332Jarkko Pöyryconst vk::DeviceInterface& Context::getDeviceInterface (void) const { return m_device->getDeviceInterface(); } 180fa8d8350fe202ecc4697be1d08f2047c90e91332Jarkko PöyrydeUint32 Context::getUniversalQueueFamilyIndex (void) const { return m_device->getUniversalQueueFamilyIndex(); } 181fa8d8350fe202ecc4697be1d08f2047c90e91332Jarkko Pöyryvk::VkQueue Context::getUniversalQueue (void) const { return m_device->getUniversalQueue(); } 182bd0311e17f335ca7e184f35e2d2ca1c826364039Jarkko Pöyryvk::Allocator& Context::getDefaultAllocator (void) const { return *m_allocator; } 18332675035be2a05886457025598f90c131d83c670Pyry Haulos 18432675035be2a05886457025598f90c131d83c670Pyry Haulos// TestCase 18532675035be2a05886457025598f90c131d83c670Pyry Haulos 18612edbd9c94d5380368146b99cfdf24b811c5f46bPyry Haulosvoid TestCase::initPrograms (vk::ProgramCollection<glu::ProgramSources>&) const 18712edbd9c94d5380368146b99cfdf24b811c5f46bPyry Haulos{ 18812edbd9c94d5380368146b99cfdf24b811c5f46bPyry Haulos} 18912edbd9c94d5380368146b99cfdf24b811c5f46bPyry Haulos 19012edbd9c94d5380368146b99cfdf24b811c5f46bPyry Haulos} // vkt 191