1 #ifndef _VKTPROTECTEDMEMCONTEXT_HPP 2 #define _VKTPROTECTEDMEMCONTEXT_HPP 3 /*------------------------------------------------------------------------ 4 * Vulkan Conformance Tests 5 * ------------------------ 6 * 7 * Copyright (c) 2017 The Khronos Group Inc. 8 * Copyright (c) 2017 Samsung Electronics Co., Ltd. 9 * 10 * Licensed under the Apache License, Version 2.0 (the "License"); 11 * you may not use this file except in compliance with the License. 12 * You may obtain a copy of the License at 13 * 14 * http://www.apache.org/licenses/LICENSE-2.0 15 * 16 * Unless required by applicable law or agreed to in writing, software 17 * distributed under the License is distributed on an "AS IS" BASIS, 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 * See the License for the specific language governing permissions and 20 * limitations under the License. 21 * 22 *//*! 23 * \file 24 * \brief Protected Memory image validator helper 25 *//*--------------------------------------------------------------------*/ 26 27 #include "tcuVector.hpp" 28 #include "vkDefs.hpp" 29 #include "vktTestCase.hpp" 30 #include "vktCustomInstancesDevices.hpp" 31 32 #include "vktProtectedMemUtils.hpp" 33 #include "tcuCommandLine.hpp" 34 #include "vkMemUtil.hpp" 35 #include "vkWsiUtil.hpp" 36 37 namespace vkt 38 { 39 namespace ProtectedMem 40 { 41 42 class ProtectedContext 43 { 44 public: 45 ProtectedContext(Context &ctx, const std::vector<std::string> instanceExtensions = std::vector<std::string>(), 46 const std::vector<std::string> deviceExtensions = std::vector<std::string>()); 47 48 ProtectedContext(Context &ctx, vk::wsi::Type wsiType, vk::wsi::Display &display, vk::wsi::Window &window, 49 const std::vector<std::string> instanceExtensions = std::vector<std::string>(), 50 const std::vector<std::string> deviceExtensions = std::vector<std::string>()); 51 getDeviceInterface(void) const52 const vk::DeviceInterface &getDeviceInterface(void) const 53 { 54 return m_deviceDriver; 55 } getDevice(void) const56 vk::VkDevice getDevice(void) const 57 { 58 return *m_device; 59 } getDeviceDriver(void) const60 const vk::DeviceDriver &getDeviceDriver(void) const 61 { 62 return m_deviceDriver; 63 } getPhysicalDevice(void) const64 vk::VkPhysicalDevice getPhysicalDevice(void) const 65 { 66 return m_phyDevice; 67 } getQueue(void) const68 vk::VkQueue getQueue(void) const 69 { 70 return m_queue; 71 } getQueueFamilyIndex(void) const72 uint32_t getQueueFamilyIndex(void) const 73 { 74 return m_queueFamilyIndex; 75 } 76 getTestContext(void) const77 tcu::TestContext &getTestContext(void) const 78 { 79 return m_context.getTestContext(); 80 } getBinaryCollection(void) const81 vk::BinaryCollection &getBinaryCollection(void) const 82 { 83 return m_context.getBinaryCollection(); 84 } getDefaultAllocator(void) const85 vk::Allocator &getDefaultAllocator(void) const 86 { 87 return *m_allocator; 88 } 89 getInstanceDriver(void) const90 const vk::InstanceDriver &getInstanceDriver(void) const 91 { 92 return m_vki; 93 } getInstance(void) const94 vk::VkInstance getInstance(void) const 95 { 96 return m_instance; 97 } getSurface(void) const98 const vk::VkSurfaceKHR getSurface(void) const 99 { 100 return *m_surface; 101 } 102 103 private: createAllocator(void)104 vk::Allocator *createAllocator(void) 105 { 106 const vk::VkPhysicalDeviceMemoryProperties memoryProperties = 107 vk::getPhysicalDeviceMemoryProperties(m_vki, m_phyDevice); 108 109 // \todo [2015-07-24 jarkko] support allocator selection/configuration from command line (or compile time) 110 return new vk::SimpleAllocator(getDeviceInterface(), getDevice(), memoryProperties); 111 } 112 113 Context &m_context; 114 const vk::PlatformInterface &m_interface; 115 CustomInstance m_instance; 116 const vk::InstanceDriver &m_vki; 117 vk::VkPhysicalDevice m_phyDevice; 118 const vk::Move<vk::VkSurfaceKHR> m_surface; 119 uint32_t m_queueFamilyIndex; 120 vk::Move<vk::VkDevice> m_device; 121 vk::DeviceDriver m_deviceDriver; 122 const de::UniquePtr<vk::Allocator> m_allocator; 123 vk::VkQueue m_queue; 124 }; 125 126 class ProtectedTestInstance : public TestInstance 127 { 128 public: ProtectedTestInstance(Context & ctx)129 ProtectedTestInstance(Context &ctx) : TestInstance(ctx), m_protectedContext(ctx) 130 { 131 } ProtectedTestInstance(Context & ctx,const std::vector<std::string> & deviceExtensions)132 ProtectedTestInstance(Context &ctx, const std::vector<std::string> &deviceExtensions) 133 : TestInstance(ctx) 134 , m_protectedContext(ctx, {}, deviceExtensions) 135 { 136 } 137 138 protected: 139 ProtectedContext m_protectedContext; 140 }; 141 142 } // namespace ProtectedMem 143 } // namespace vkt 144 145 #endif // _VKTPROTECTEDMEMCONTEXT_HPP 146