1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
4 *
5 * Copyright (c) 2022 The Khronos Group Inc.
6 * Copyright (c) 2022 Google LLC
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 invocations tests
23 *//*--------------------------------------------------------------------*/
24
25 #include "vktDrawShaderInvocationTests.hpp"
26 #include "vktTestGroupUtil.hpp"
27 #include "amber/vktAmberTestCase.hpp"
28
29 #include "tcuTestCase.hpp"
30
31 using namespace vk;
32
33 namespace vkt
34 {
35 namespace Draw
36 {
37 namespace
38 {
39
40 enum TestType
41 {
42 EXT,
43 CORE,
44 CORE_MEM_MODEL,
45 };
46
checkSupport(Context & context,TestType type)47 void checkSupport(Context &context, TestType type)
48 {
49 if ((context.getSubgroupProperties().supportedOperations & VK_SUBGROUP_FEATURE_QUAD_BIT) == 0u)
50 TCU_THROW(NotSupportedError, "Device does not support subgroup quad operations");
51
52 #ifndef CTS_USES_VULKANSC
53 if (!context.getShaderDemoteToHelperInvocationFeatures().shaderDemoteToHelperInvocation)
54 TCU_THROW(NotSupportedError, "demoteToHelperInvocation not supported.");
55 #else
56 if (!context.getShaderDemoteToHelperInvocationFeaturesEXT().shaderDemoteToHelperInvocation)
57 TCU_THROW(NotSupportedError, "demoteToHelperInvocation not supported.");
58 #endif
59
60 // EXT test requires that the extension be supported, because OpIsHelperInvocationEXT was not promoted to core.
61 if (type == EXT && !context.isDeviceFunctionalitySupported("VK_EXT_shader_demote_to_helper_invocation"))
62 TCU_THROW(NotSupportedError, "VK_EXT_shader_demote_to_helper_invocation not supported.");
63
64 // CORE and CORE_MEM_MODEL tests require SPIR-V 1.6, but this is checked automatically.
65
66 if (type == CORE_MEM_MODEL && !context.getVulkanMemoryModelFeatures().vulkanMemoryModel)
67 TCU_THROW(NotSupportedError, "Vulkan memory model not supported.");
68 }
69
checkExtTestSupport(Context & context,std::string testName)70 void checkExtTestSupport(Context &context, std::string testName)
71 {
72 DE_UNREF(testName);
73 checkSupport(context, EXT);
74 }
checkCoreTestSupport(Context & context,std::string testName)75 void checkCoreTestSupport(Context &context, std::string testName)
76 {
77 DE_UNREF(testName);
78 checkSupport(context, CORE);
79 }
checkMemModelTestSupport(Context & context,std::string testName)80 void checkMemModelTestSupport(Context &context, std::string testName)
81 {
82 DE_UNREF(testName);
83 checkSupport(context, CORE_MEM_MODEL);
84 }
85
createTests(tcu::TestCaseGroup * testGroup)86 void createTests(tcu::TestCaseGroup *testGroup)
87 {
88 tcu::TestContext &testCtx = testGroup->getTestContext();
89 static const char dataDir[] = "draw/shader_invocation";
90
91 struct caseDef
92 {
93 const char *name;
94 const char *file;
95 std::function<void(Context &, std::string)> supportFunc;
96 } cases[] = {
97 {"helper_invocation", "helper_invocation.amber", checkExtTestSupport},
98 {"helper_invocation_volatile", "helper_invocation_volatile.amber", checkCoreTestSupport},
99 {"helper_invocation_volatile_mem_model", "helper_invocation_volatile_mem_model.amber",
100 checkMemModelTestSupport},
101 };
102
103 for (unsigned i = 0; i < sizeof(cases) / sizeof(caseDef); i++)
104 {
105 cts_amber::AmberTestCase *testCase =
106 cts_amber::createAmberTestCase(testCtx, cases[i].name, dataDir, cases[i].file);
107 testCase->setCheckSupportCallback(cases[i].supportFunc);
108 testGroup->addChild(testCase);
109 }
110 }
111
112 } // namespace
113
createShaderInvocationTests(tcu::TestContext & testCtx)114 tcu::TestCaseGroup *createShaderInvocationTests(tcu::TestContext &testCtx)
115 {
116 return createTestGroup(testCtx, "shader_invocation", createTests);
117 }
118
119 } // namespace Draw
120 } // namespace vkt
121