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 #ifdef CTS_USES_VULKANSC 75 de::SharedPtr<vk::ResourceInterface> resourceInterface, 76 #endif // CTS_USES_VULKANSC 77 const tcu::CommandLine& cmdLine); 78 79 vk::VkQueue getProtectedQueue (const vk::DeviceInterface& vk, 80 vk::VkDevice device, 81 const deUint32 queueFamilyIndex, 82 const deUint32 queueIdx); 83 84 de::MovePtr<vk::ImageWithMemory> createImage2D (ProtectedContext& context, 85 ProtectionMode protectionMode, 86 const deUint32 queueFamilyIdx, 87 deUint32 width, 88 deUint32 height, 89 vk::VkFormat format, 90 vk::VkImageUsageFlags usageFlags); 91 de::MovePtr<vk::BufferWithMemory> makeBuffer (ProtectedContext& context, 92 ProtectionMode protectionMode, 93 const deUint32 queueFamilyIdx, 94 deUint32 size, 95 vk::VkBufferUsageFlags flags, 96 vk::MemoryRequirement memReq); 97 98 vk::Move<vk::VkImageView> createImageView (ProtectedContext& context, 99 vk::VkImage image, 100 vk::VkFormat format); 101 vk::Move<vk::VkRenderPass> createRenderPass (ProtectedContext& context, 102 vk::VkFormat format); 103 vk::Move<vk::VkFramebuffer> createFramebuffer (ProtectedContext& context, 104 deUint32 width, 105 deUint32 height, 106 vk::VkRenderPass renderPass, 107 vk::VkImageView colorImageView); 108 vk::Move<vk::VkPipelineLayout> createPipelineLayout (ProtectedContext& context, 109 deUint32 layoutCount, 110 vk::VkDescriptorSetLayout* setLayouts); 111 112 typedef vk::VkCommandBufferInheritanceInfo CmdBuffInheritance; 113 enum CmdBufferType { 114 CMD_BUFFER_PRIMARY, 115 CMD_BUFFER_SECONDARY, 116 }; 117 118 const char* getCmdBufferTypeStr (const CmdBufferType cmdBufferType); 119 void beginSecondaryCommandBuffer (const vk::DeviceInterface& vk, 120 const vk::VkCommandBuffer secondaryCmdBuffer, 121 const CmdBuffInheritance secCmdBufInheritInfo); 122 123 vk::VkResult queueSubmit (ProtectedContext& context, 124 ProtectionMode protectionMode, 125 vk::VkQueue queue, 126 vk::VkCommandBuffer cmdBuffer, 127 vk::VkFence fence, 128 deUint64 timeout); 129 130 vk::Move<vk::VkSampler> makeSampler (const vk::DeviceInterface& vk, 131 const vk::VkDevice& device); 132 vk::Move<vk::VkCommandPool> makeCommandPool (const vk::DeviceInterface& vk, 133 const vk::VkDevice& device, 134 ProtectionMode protectionMode, 135 const deUint32 queueFamilyIdx); 136 137 vk::Move<vk::VkPipeline> makeGraphicsPipeline (const vk::DeviceInterface& vk, 138 const vk::VkDevice device, 139 const vk::VkPipelineLayout pipelineLayout, 140 const vk::VkRenderPass renderPass, 141 const vk::VkShaderModule vertexShaderModule, 142 const vk::VkShaderModule fragmentShaderModule, 143 const VertexBindings& vertexBindings, 144 const VertexAttribs& vertexAttribs, 145 const tcu::UVec2& renderSize, 146 const vk::VkPrimitiveTopology topology, 147 const vk::VkPipelineCreateFlags flags = 0); 148 149 void clearImage (ProtectedContext& ctx, 150 vk::VkImage image); 151 152 void uploadImage (ProtectedContext& ctx, 153 vk::VkImage image, 154 const tcu::Texture2D& texture2D); 155 156 void copyToProtectedImage (ProtectedContext& ctx, 157 vk::VkImage srcImage, 158 vk::VkImage dstImage, 159 vk::VkImageLayout dstImageLayout, 160 deUint32 width, 161 deUint32 height, 162 ProtectionMode protectionMode = PROTECTION_ENABLED); 163 164 void fillWithRandomColorTiles (const tcu::PixelBufferAccess& dst, 165 const tcu::Vec4& minVal, 166 const tcu::Vec4& maxVal, 167 deUint32 seed); 168 169 void fillWithUniqueColors (const tcu::PixelBufferAccess& dst, 170 deUint32 seed); 171 172 } // ProtectedMem 173 } // vkt 174 175 #endif // _VKTPROTECTEDMEMUTILS_HPP 176