xref: /aosp_15_r20/external/deqp/external/vulkancts/modules/vulkan/amber/vktAmberDepthTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2020 Valve Corporation.
6  * Copyright (c) 2020 The Khronos Group Inc.
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 Amber tests in the GLSL group.
23  *//*--------------------------------------------------------------------*/
24 
25 #include "vktAmberDepthTests.hpp"
26 #include "vktAmberTestCase.hpp"
27 #include "vktCustomInstancesDevices.hpp"
28 #include "vktTestGroupUtil.hpp"
29 
30 #include "vkQueryUtil.hpp"
31 
32 #include "tcuCommandLine.hpp"
33 
34 #include <vector>
35 #include <utility>
36 #include <string>
37 
38 namespace vkt
39 {
40 namespace cts_amber
41 {
42 
43 using namespace vk;
44 
45 de::SharedPtr<Move<vk::VkDevice>> g_singletonDeviceDepthGroup;
46 
47 class DepthTestCase : public AmberTestCase
48 {
49     bool m_useCustomDevice;
50 
51 public:
DepthTestCase(tcu::TestContext & testCtx,const char * name,bool useCustomDevice,const std::string & readFilename)52     DepthTestCase(tcu::TestContext &testCtx, const char *name, bool useCustomDevice, const std::string &readFilename)
53         : AmberTestCase(testCtx, name, "", readFilename)
54         , m_useCustomDevice(useCustomDevice)
55     {
56     }
57 
createInstance(Context & ctx) const58     TestInstance *createInstance(Context &ctx) const
59     {
60         // Create a custom device to ensure that VK_EXT_depth_range_unrestricted is not enabled
61         if (!g_singletonDeviceDepthGroup && m_useCustomDevice)
62         {
63             const float queuePriority = 1.0f;
64 
65             // Create a universal queue that supports graphics and compute
66             const VkDeviceQueueCreateInfo queueParams = {
67                 VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // sType
68                 DE_NULL,                                    // pNext
69                 0u,                                         // flags
70                 ctx.getUniversalQueueFamilyIndex(),         // queueFamilyIndex
71                 1u,                                         // queueCount
72                 &queuePriority                              // pQueuePriorities
73             };
74 
75             const char *ext = "VK_EXT_depth_clamp_zero_one";
76 
77             VkPhysicalDeviceFeatures2 features2 = initVulkanStructure();
78 
79             VkPhysicalDeviceDepthClampZeroOneFeaturesEXT clampParams = {
80                 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLAMP_ZERO_ONE_FEATURES_EXT, // sType
81                 DE_NULL,                                                             // pNext
82                 VK_TRUE,                                                             // depthClampZeroOne
83             };
84 
85             features2.pNext = &clampParams;
86 
87             const auto &vki           = ctx.getInstanceInterface();
88             const auto physicalDevice = ctx.getPhysicalDevice();
89 
90             ctx.requireInstanceFunctionality("VK_KHR_get_physical_device_properties2");
91             vki.getPhysicalDeviceFeatures2(physicalDevice, &features2);
92 
93             const VkDeviceCreateInfo deviceCreateInfo = {
94                 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, // sType
95                 &features2,                           // pNext
96                 (VkDeviceCreateFlags)0u,              // flags
97                 1,                                    // queueRecordCount
98                 &queueParams,                         // pRequestedQueues
99                 0,                                    // layerCount
100                 DE_NULL,                              // ppEnabledLayerNames
101                 1,                                    // enabledExtensionCount
102                 &ext,                                 // ppEnabledExtensionNames
103                 DE_NULL,                              // pEnabledFeatures
104             };
105 
106             const bool validation = ctx.getTestContext().getCommandLine().isValidationEnabled();
107             Move<VkDevice> device = createCustomDevice(validation, ctx.getPlatformInterface(), ctx.getInstance(), vki,
108                                                        physicalDevice, &deviceCreateInfo);
109 
110             g_singletonDeviceDepthGroup = de::SharedPtr<Move<VkDevice>>(new Move<VkDevice>(device));
111         }
112         return new AmberTestInstance(ctx, m_recipe, m_useCustomDevice ? g_singletonDeviceDepthGroup->get() : nullptr);
113     }
114 };
115 
116 struct TestInfo
117 {
118     std::string name;
119     std::vector<std::string> base_required_features;
120     bool unrestricted;
121 };
122 
createDepthTestCase(tcu::TestContext & testCtx,const TestInfo & testInfo,const char * category,const std::string & filename)123 DepthTestCase *createDepthTestCase(tcu::TestContext &testCtx, const TestInfo &testInfo, const char *category,
124                                    const std::string &filename)
125 
126 {
127     // shader_test files are saved in <path>/external/vulkancts/data/vulkan/amber/<categoryname>/
128     std::string readFilename("vulkan/amber/");
129     readFilename.append(category);
130     readFilename.append("/");
131     readFilename.append(filename);
132 
133     DepthTestCase *testCase = new DepthTestCase(testCtx, testInfo.name.c_str(), !testInfo.unrestricted, readFilename);
134 
135     for (auto req : testInfo.base_required_features)
136         testCase->addRequirement(req);
137 
138     if (testInfo.unrestricted)
139         testCase->addRequirement("VK_EXT_depth_range_unrestricted");
140 
141     return testCase;
142 }
143 
createTests(tcu::TestCaseGroup * g)144 static void createTests(tcu::TestCaseGroup *g)
145 {
146     static const std::vector<TestInfo> tests = {
147         {"fs_clamp",
148          {"VK_EXT_depth_clamp_zero_one", "Features.fragmentStoresAndAtomics", "Features.depthClamp"},
149          false},
150         {"out_of_range", {"VK_EXT_depth_clamp_zero_one"}, false},
151         {"ez_fs_clamp",
152          {"VK_EXT_depth_clamp_zero_one", "Features.fragmentStoresAndAtomics", "Features.depthClamp"},
153          false},
154         {"bias_fs_clamp",
155          {"VK_EXT_depth_clamp_zero_one", "Features.fragmentStoresAndAtomics", "Features.depthClamp"},
156          false},
157         {"bias_outside_range", {"VK_EXT_depth_clamp_zero_one", "Features.fragmentStoresAndAtomics"}, false},
158         {"bias_outside_range_fs_clamp", {"VK_EXT_depth_clamp_zero_one", "Features.fragmentStoresAndAtomics"}, false},
159 
160         // Rerun any tests that will get different results with VK_EXT_depth_range_unrestricted
161         {"out_of_range_unrestricted", {"VK_EXT_depth_clamp_zero_one"}, true},
162         {"bias_outside_range_fs_clamp_unrestricted",
163          {"VK_EXT_depth_clamp_zero_one", "Features.fragmentStoresAndAtomics"},
164          true},
165     };
166 
167     tcu::TestContext &testCtx = g->getTestContext();
168 
169     for (const auto &test : tests)
170     {
171         g->addChild(createDepthTestCase(testCtx, test, g->getName(), test.name + ".amber"));
172     }
173 }
174 
cleanupGroup(tcu::TestCaseGroup *)175 static void cleanupGroup(tcu::TestCaseGroup *)
176 {
177     // Destroy custom device object
178     g_singletonDeviceDepthGroup.clear();
179 }
180 
createAmberDepthGroup(tcu::TestContext & testCtx,const std::string & name)181 tcu::TestCaseGroup *createAmberDepthGroup(tcu::TestContext &testCtx, const std::string &name)
182 {
183     return createTestGroup(testCtx, name.c_str(), createTests, cleanupGroup);
184 }
185 
186 } // namespace cts_amber
187 } // namespace vkt
188