xref: /aosp_15_r20/external/deqp/external/vulkancts/modules/vulkan/protected_memory/vktProtectedMemUtils.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
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 {
53     PROTECTION_DISABLED = 0,
54     PROTECTION_ENABLED  = 1,
55 };
56 
57 typedef std::vector<vk::VkVertexInputBindingDescription> VertexBindings;
58 typedef std::vector<vk::VkVertexInputAttributeDescription> VertexAttribs;
59 
60 void checkProtectedQueueSupport(Context &context);
61 
62 CustomInstance makeProtectedMemInstance(vkt::Context &context,
63                                         const std::vector<std::string> &extraExtensions = std::vector<std::string>());
64 uint32_t chooseProtectedMemQueueFamilyIndex(const vk::InstanceDriver &vkd, vk::VkPhysicalDevice physicalDevice,
65                                             vk::VkSurfaceKHR surface = DE_NULL);
66 
67 vk::Move<vk::VkDevice> makeProtectedMemDevice(const vk::PlatformInterface &vkp, vk::VkInstance instance,
68                                               const vk::InstanceDriver &vkd, vk::VkPhysicalDevice physicalDevice,
69                                               const uint32_t queueFamilyIndex, const uint32_t apiVersion,
70                                               const std::vector<std::string> &extraExtensions,
71 #ifdef CTS_USES_VULKANSC
72                                               de::SharedPtr<vk::ResourceInterface> resourceInterface,
73 #endif // CTS_USES_VULKANSC
74                                               const tcu::CommandLine &cmdLine);
75 
76 vk::VkQueue getProtectedQueue(const vk::DeviceInterface &vk, vk::VkDevice device, const uint32_t queueFamilyIndex,
77                               const uint32_t queueIdx);
78 
79 de::MovePtr<vk::ImageWithMemory> createImage2D(ProtectedContext &context, ProtectionMode protectionMode,
80                                                const uint32_t queueFamilyIdx, uint32_t width, uint32_t height,
81                                                vk::VkFormat format, vk::VkImageUsageFlags usageFlags);
82 de::MovePtr<vk::BufferWithMemory> makeBuffer(ProtectedContext &context, ProtectionMode protectionMode,
83                                              const uint32_t queueFamilyIdx, uint32_t size, vk::VkBufferUsageFlags flags,
84                                              vk::MemoryRequirement memReq);
85 
86 vk::Move<vk::VkImageView> createImageView(ProtectedContext &context, vk::VkImage image, vk::VkFormat format);
87 vk::Move<vk::VkRenderPass> createRenderPass(ProtectedContext &context, vk::VkFormat format);
88 vk::Move<vk::VkFramebuffer> createFramebuffer(ProtectedContext &context, uint32_t width, uint32_t height,
89                                               vk::VkRenderPass renderPass, vk::VkImageView colorImageView);
90 vk::Move<vk::VkPipelineLayout> createPipelineLayout(ProtectedContext &context, uint32_t layoutCount,
91                                                     vk::VkDescriptorSetLayout *setLayouts);
92 
93 typedef vk::VkCommandBufferInheritanceInfo CmdBuffInheritance;
94 enum CmdBufferType
95 {
96     CMD_BUFFER_PRIMARY,
97     CMD_BUFFER_SECONDARY,
98 };
99 
100 const char *getCmdBufferTypeStr(const CmdBufferType cmdBufferType);
101 void beginSecondaryCommandBuffer(const vk::DeviceInterface &vk, const vk::VkCommandBuffer secondaryCmdBuffer,
102                                  const CmdBuffInheritance secCmdBufInheritInfo);
103 
104 vk::VkResult queueSubmit(ProtectedContext &context, ProtectionMode protectionMode, vk::VkQueue queue,
105                          vk::VkCommandBuffer cmdBuffer, vk::VkFence fence, uint64_t timeout);
106 
107 vk::Move<vk::VkSampler> makeSampler(const vk::DeviceInterface &vk, const vk::VkDevice &device);
108 vk::Move<vk::VkCommandPool> makeCommandPool(const vk::DeviceInterface &vk, const vk::VkDevice &device,
109                                             ProtectionMode protectionMode, const uint32_t queueFamilyIdx);
110 
111 vk::Move<vk::VkPipeline> makeGraphicsPipeline(const vk::DeviceInterface &vk, const vk::VkDevice device,
112                                               const vk::VkPipelineLayout pipelineLayout,
113                                               const vk::VkRenderPass renderPass,
114                                               const vk::VkShaderModule vertexShaderModule,
115                                               const vk::VkShaderModule fragmentShaderModule,
116                                               const VertexBindings &vertexBindings, const VertexAttribs &vertexAttribs,
117                                               const tcu::UVec2 &renderSize, const vk::VkPrimitiveTopology topology,
118                                               const vk::VkPipelineCreateFlags flags = 0);
119 
120 void clearImage(ProtectedContext &ctx, vk::VkImage image);
121 
122 void uploadImage(ProtectedContext &ctx, vk::VkImage image, const tcu::Texture2D &texture2D);
123 
124 void copyToProtectedImage(ProtectedContext &ctx, vk::VkImage srcImage, vk::VkImage dstImage,
125                           vk::VkImageLayout dstImageLayout, uint32_t width, uint32_t height,
126                           ProtectionMode protectionMode = PROTECTION_ENABLED);
127 
128 void fillWithRandomColorTiles(const tcu::PixelBufferAccess &dst, const tcu::Vec4 &minVal, const tcu::Vec4 &maxVal,
129                               uint32_t seed);
130 
131 void fillWithUniqueColors(const tcu::PixelBufferAccess &dst, uint32_t seed);
132 
133 } // namespace ProtectedMem
134 } // namespace vkt
135 
136 #endif // _VKTPROTECTEDMEMUTILS_HPP
137