xref: /aosp_15_r20/external/deqp/external/vulkancts/framework/vulkan/vkShaderObjectUtil.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2023 LunarG, Inc.
6  * Copyright (c) 2023 Nintendo
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  *//*!
21  * \file
22  * \brief Shader Object Test Case Utilities
23  *//*--------------------------------------------------------------------*/
24 
25 #include "vkShaderObjectUtil.hpp"
26 #include "vkQueryUtil.hpp"
27 
28 namespace vk
29 {
30 
31 #ifndef CTS_USES_VULKANSC
createShader(const DeviceInterface & vk,VkDevice device,const vk::VkShaderCreateInfoEXT & shaderCreateInfo)32 inline Move<VkShaderEXT> createShader(const DeviceInterface &vk, VkDevice device,
33                                       const vk::VkShaderCreateInfoEXT &shaderCreateInfo)
34 {
35     VkShaderEXT object;
36     VK_CHECK(vk.createShadersEXT(device, 1u, &shaderCreateInfo, DE_NULL, &object));
37     return Move<VkShaderEXT>(check<VkShaderEXT>(object), Deleter<VkShaderEXT>(vk, device, DE_NULL));
38 }
39 
removeUnsupportedShaderObjectExtensions(const vk::InstanceInterface & vki,const vk::VkPhysicalDevice physicalDevice,const std::vector<std::string> & deviceExtensions)40 std::vector<std::string> removeUnsupportedShaderObjectExtensions(const vk::InstanceInterface &vki,
41                                                                  const vk::VkPhysicalDevice physicalDevice,
42                                                                  const std::vector<std::string> &deviceExtensions)
43 {
44     std::vector<std::string> extensions = deviceExtensions;
45 
46     const auto extensionProperties = vk::enumerateDeviceExtensionProperties(vki, physicalDevice, DE_NULL);
47 
48     uint32_t discardRectanglesVersion = 0;
49     uint32_t scissorExclusiveVersion  = 0;
50     for (const auto &extProp : extensionProperties)
51     {
52         if (strcmp(extProp.extensionName, "VK_EXT_discard_rectangles") == 0)
53             discardRectanglesVersion = extProp.specVersion;
54 
55         if (strcmp(extProp.extensionName, "VK_NV_scissor_exclusive") == 0)
56             scissorExclusiveVersion = extProp.specVersion;
57     }
58 
59     if (discardRectanglesVersion < 2 &&
60         std::find(extensions.begin(), extensions.end(), "VK_EXT_discard_rectangles") != extensions.end())
61         extensions.erase(std::remove(extensions.begin(), extensions.end(), "VK_EXT_discard_rectangles"),
62                          extensions.end());
63     if (scissorExclusiveVersion < 2 &&
64         std::find(extensions.begin(), extensions.end(), "VK_NV_scissor_exclusive") != extensions.end())
65         extensions.erase(std::remove(extensions.begin(), extensions.end(), "VK_NV_scissor_exclusive"),
66                          extensions.end());
67 
68     return extensions;
69 }
70 #endif
71 
72 } // namespace vk
73