1 #ifndef _VKTPROTECTEDMEMUTILS_HPP 2 #define _VKTPROTECTEDMEMUTILS_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 Utility methods 25 *//*--------------------------------------------------------------------*/ 26 27 #include "deUniquePtr.hpp" 28 #include "vktTestCase.hpp" 29 #include "vktCustomInstancesDevices.hpp" 30 #include "vkDefs.hpp" 31 #include "vkRefUtil.hpp" 32 #include "vkMemUtil.hpp" 33 #include "vkDeviceUtil.hpp" 34 #include "vkPlatform.hpp" 35 #include "vkBufferWithMemory.hpp" 36 #include "vkImageWithMemory.hpp" 37 #include "vkCmdUtil.hpp" 38 #include "tcuVector.hpp" 39 #include "tcuTextureUtil.hpp" 40 41 // enable the define to disable protected memory 42 //#define NOT_PROTECTED 1 43 44 namespace vkt 45 { 46 namespace ProtectedMem 47 { 48 49 class ProtectedContext; 50 51 enum ProtectionMode { 52 PROTECTION_DISABLED = 0, 53 PROTECTION_ENABLED = 1, 54 }; 55 56 typedef std::vector<vk::VkVertexInputBindingDescription> VertexBindings; 57 typedef std::vector<vk::VkVertexInputAttributeDescription> VertexAttribs; 58 59 void checkProtectedQueueSupport (Context& context); 60 61 CustomInstance makeProtectedMemInstance (vkt::Context& context, 62 const std::vector<std::string>& extraExtensions = std::vector<std::string>()); 63 deUint32 chooseProtectedMemQueueFamilyIndex (const vk::InstanceDriver& vkd, 64 vk::VkPhysicalDevice physicalDevice, 65 vk::VkSurfaceKHR surface = DE_NULL); 66 67 vk::Move<vk::VkDevice> makeProtectedMemDevice (const vk::PlatformInterface& vkp, 68 vk::VkInstance instance, 69 const vk::InstanceDriver& vkd, 70 vk::VkPhysicalDevice physicalDevice, 71 const deUint32 queueFamilyIndex, 72 const deUint32 apiVersion, 73 const std::vector<std::string>& extraExtensions, 74 bool validationEnabled); 75 vk::VkQueue getProtectedQueue (const vk::DeviceInterface& vk, 76 vk::VkDevice device, 77 const deUint32 queueFamilyIndex, 78 const deUint32 queueIdx); 79 80 de::MovePtr<vk::ImageWithMemory> createImage2D (ProtectedContext& context, 81 ProtectionMode protectionMode, 82 const deUint32 queueFamilyIdx, 83 deUint32 width, 84 deUint32 height, 85 vk::VkFormat format, 86 vk::VkImageUsageFlags usageFlags); 87 de::MovePtr<vk::BufferWithMemory> makeBuffer (ProtectedContext& context, 88 ProtectionMode protectionMode, 89 const deUint32 queueFamilyIdx, 90 deUint32 size, 91 vk::VkBufferUsageFlags flags, 92 vk::MemoryRequirement memReq); 93 94 vk::Move<vk::VkImageView> createImageView (ProtectedContext& context, 95 vk::VkImage image, 96 vk::VkFormat format); 97 vk::Move<vk::VkRenderPass> createRenderPass (ProtectedContext& context, 98 vk::VkFormat format); 99 vk::Move<vk::VkFramebuffer> createFramebuffer (ProtectedContext& context, 100 deUint32 width, 101 deUint32 height, 102 vk::VkRenderPass renderPass, 103 vk::VkImageView colorImageView); 104 vk::Move<vk::VkPipelineLayout> createPipelineLayout (ProtectedContext& context, 105 deUint32 layoutCount, 106 vk::VkDescriptorSetLayout* setLayouts); 107 108 typedef vk::VkCommandBufferInheritanceInfo CmdBuffInheritance; 109 enum CmdBufferType { 110 CMD_BUFFER_PRIMARY, 111 CMD_BUFFER_SECONDARY, 112 }; 113 114 const char* getCmdBufferTypeStr (const CmdBufferType cmdBufferType); 115 void beginSecondaryCommandBuffer (const vk::DeviceInterface& vk, 116 const vk::VkCommandBuffer secondaryCmdBuffer, 117 const CmdBuffInheritance secCmdBufInheritInfo); 118 119 vk::VkResult queueSubmit (ProtectedContext& context, 120 ProtectionMode protectionMode, 121 vk::VkQueue queue, 122 vk::VkCommandBuffer cmdBuffer, 123 vk::VkFence fence, 124 deUint64 timeout); 125 126 vk::Move<vk::VkPipeline> makeComputePipeline (const vk::DeviceInterface& vk, 127 const vk::VkDevice device, 128 const vk::VkPipelineLayout pipelineLayout, 129 const vk::VkShaderModule shaderModule, 130 const vk::VkSpecializationInfo* specInfo); 131 132 vk::Move<vk::VkSampler> makeSampler (const vk::DeviceInterface& vk, 133 const vk::VkDevice& device); 134 vk::Move<vk::VkCommandPool> makeCommandPool (const vk::DeviceInterface& vk, 135 const vk::VkDevice& device, 136 ProtectionMode protectionMode, 137 const deUint32 queueFamilyIdx); 138 139 vk::Move<vk::VkPipeline> makeGraphicsPipeline (const vk::DeviceInterface& vk, 140 const vk::VkDevice device, 141 const vk::VkPipelineLayout pipelineLayout, 142 const vk::VkRenderPass renderPass, 143 const vk::VkShaderModule vertexShaderModule, 144 const vk::VkShaderModule fragmentShaderModule, 145 const VertexBindings& vertexBindings, 146 const VertexAttribs& vertexAttribs, 147 const tcu::UVec2& renderSize, 148 const vk::VkPrimitiveTopology topology); 149 150 vk::Move<vk::VkPipeline> makeGraphicsPipeline (const vk::DeviceInterface& vk, 151 const vk::VkDevice device, 152 const vk::VkPipelineLayout pipelineLayout, 153 const vk::VkRenderPass renderPass, 154 const vk::VkShaderModule vertexShaderModule, 155 const vk::VkShaderModule fragmentShaderModule, 156 const VertexBindings& vertexBindings, 157 const VertexAttribs& vertexAttribs, 158 const tcu::UVec2& renderSize, 159 const vk::VkPrimitiveTopology topology); 160 161 void clearImage (ProtectedContext& ctx, 162 vk::VkImage image); 163 164 void uploadImage (ProtectedContext& ctx, 165 vk::VkImage image, 166 const tcu::Texture2D& texture2D); 167 168 void copyToProtectedImage (ProtectedContext& ctx, 169 vk::VkImage srcImage, 170 vk::VkImage dstImage, 171 vk::VkImageLayout dstImageLayout, 172 deUint32 width, 173 deUint32 height); 174 175 void fillWithRandomColorTiles (const tcu::PixelBufferAccess& dst, 176 const tcu::Vec4& minVal, 177 const tcu::Vec4& maxVal, 178 deUint32 seed); 179 180 void fillWithUniqueColors (const tcu::PixelBufferAccess& dst, 181 deUint32 seed); 182 183 } // ProtectedMem 184 } // vkt 185 186 #endif // _VKTPROTECTEDMEMUTILS_HPP 187