1 #ifndef _VKTPROTECTEDMEMUTILS_HPP
2 #define _VKTPROTECTEDMEMUTILS_HPP
3 /*------------------------------------------------------------------------
4 * Vulkan Conformance Tests
5 * ------------------------
7 * Copyright (c) 2017 The Khronos Group Inc.
8 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
14 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 * \brief Protected Memory Utility methods
25 *//*--------------------------------------------------------------------*/
27 #include "deUniquePtr.hpp"
28 #include "vktTestCase.hpp"
29 #include "vktCustomInstancesDevices.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"
41 // enable the define to disable protected memory
42 //#define NOT_PROTECTED 1
46 namespace ProtectedMem
49 class ProtectedContext;
52 PROTECTION_DISABLED = 0,
53 PROTECTION_ENABLED = 1,
56 typedef std::vector<vk::VkVertexInputBindingDescription> VertexBindings;
57 typedef std::vector<vk::VkVertexInputAttributeDescription> VertexAttribs;
59 void checkProtectedQueueSupport (Context& context);
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);
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,
77 const deUint32 queueFamilyIndex,
78 const deUint32 queueIdx);
80 de::MovePtr<vk::ImageWithMemory> createImage2D (ProtectedContext& context,
81 ProtectionMode protectionMode,
82 const deUint32 queueFamilyIdx,
86 vk::VkImageUsageFlags usageFlags);
87 de::MovePtr<vk::BufferWithMemory> makeBuffer (ProtectedContext& context,
88 ProtectionMode protectionMode,
89 const deUint32 queueFamilyIdx,
91 vk::VkBufferUsageFlags flags,
92 vk::MemoryRequirement memReq);
94 vk::Move<vk::VkImageView> createImageView (ProtectedContext& context,
97 vk::Move<vk::VkRenderPass> createRenderPass (ProtectedContext& context,
99 vk::Move<vk::VkFramebuffer> createFramebuffer (ProtectedContext& context,
102 vk::VkRenderPass renderPass,
103 vk::VkImageView colorImageView);
104 vk::Move<vk::VkPipelineLayout> createPipelineLayout (ProtectedContext& context,
105 deUint32 layoutCount,
106 vk::VkDescriptorSetLayout* setLayouts);
108 typedef vk::VkCommandBufferInheritanceInfo CmdBuffInheritance;
111 CMD_BUFFER_SECONDARY,
114 const char* getCmdBufferTypeStr (const CmdBufferType cmdBufferType);
115 void beginSecondaryCommandBuffer (const vk::DeviceInterface& vk,
116 const vk::VkCommandBuffer secondaryCmdBuffer,
117 const CmdBuffInheritance secCmdBufInheritInfo);
119 vk::VkResult queueSubmit (ProtectedContext& context,
120 ProtectionMode protectionMode,
122 vk::VkCommandBuffer cmdBuffer,
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);
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);
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);
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);
161 void clearImage (ProtectedContext& ctx,
164 void uploadImage (ProtectedContext& ctx,
166 const tcu::Texture2D& texture2D);
168 void copyToProtectedImage (ProtectedContext& ctx,
169 vk::VkImage srcImage,
170 vk::VkImage dstImage,
171 vk::VkImageLayout dstImageLayout,
175 void fillWithRandomColorTiles (const tcu::PixelBufferAccess& dst,
176 const tcu::Vec4& minVal,
177 const tcu::Vec4& maxVal,
183 #endif // _VKTPROTECTEDMEMUTILS_HPP