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