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