xref: /aosp_15_r20/external/OpenCL-CTS/test_conformance/common/vulkan_wrapper/vulkan_utility.hpp (revision 6467f958c7de8070b317fc65bcb0f6472e388d82)
1 //
2 // Copyright (c) 2022 The Khronos Group Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //    http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #ifndef _vulkan_utility_hpp_
18 #define _vulkan_utility_hpp_
19 
20 #include "vulkan_wrapper_types.hpp"
21 #include <vector>
22 #include <ostream>
23 #include <string.h>
24 #include <map>
25 #include "../../../test_common/harness/testHarness.h"
26 
27 #define STRING_(str) #str
28 #define STRING(str) STRING_(str)
29 
30 #define ROUND_UP(n, multiple)                                                  \
31     (((n) + (multiple)-1) - ((((n) + (multiple)-1)) % (multiple)))
32 
33 const VulkanInstance& getVulkanInstance();
34 const VulkanPhysicalDevice& getVulkanPhysicalDevice();
35 const VulkanQueueFamily&
36 getVulkanQueueFamily(uint32_t queueFlags = VULKAN_QUEUE_FLAG_GRAPHICS
37                          | VULKAN_QUEUE_FLAG_COMPUTE);
38 const VulkanMemoryType&
39 getVulkanMemoryType(const VulkanDevice& device,
40                     VulkanMemoryTypeProperty memoryTypeProperty);
41 bool checkVkSupport();
42 const VulkanQueueFamilyList& getEmptyVulkanQueueFamilyList();
43 const VulkanDescriptorSetLayoutList& getEmptyVulkanDescriptorSetLayoutList();
44 const VulkanQueueFamilyToQueueCountMap&
45 getDefaultVulkanQueueFamilyToQueueCountMap();
46 const std::vector<VulkanExternalMemoryHandleType>
47 getSupportedVulkanExternalMemoryHandleTypeList();
48 const std::vector<VulkanExternalSemaphoreHandleType>
49 getSupportedVulkanExternalSemaphoreHandleTypeList();
50 const std::vector<VulkanFormat> getSupportedVulkanFormatList();
51 
52 uint32_t getVulkanFormatElementSize(VulkanFormat format);
53 const char* getVulkanFormatGLSLFormat(VulkanFormat format);
54 const char* getVulkanFormatGLSLTypePrefix(VulkanFormat format);
55 cl_external_semaphore_handle_type_khr getCLSemaphoreTypeFromVulkanType(
56     VulkanExternalSemaphoreHandleType vulkanExternalSemaphoreHandleType);
57 
58 std::string prepareVulkanShader(
59     std::string shaderCode,
60     const std::map<std::string, std::string>& patternToSubstituteMap);
61 
62 std::ostream& operator<<(std::ostream& os,
63                          VulkanMemoryTypeProperty memoryTypeProperty);
64 std::ostream&
65 operator<<(std::ostream& os,
66            VulkanExternalMemoryHandleType externalMemoryHandleType);
67 std::ostream&
68 operator<<(std::ostream& os,
69            VulkanExternalSemaphoreHandleType externalSemaphoreHandleType);
70 std::ostream& operator<<(std::ostream& os, VulkanFormat format);
71 
72 std::vector<char> readFile(const std::string& filename);
73 #endif // _vulkan_utility_hpp_
74