xref: /aosp_15_r20/external/deqp/external/vulkancts/modules/vulkan/amber/vktAmberTestCase.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _VKTAMBERTESTCASE_HPP
2 #define _VKTAMBERTESTCASE_HPP
3 /*------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2019 Google LLC
8  * Copyright (c) 2019 The Khronos Group Inc.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  *//*!
23  * \file
24  * \brief Functional tests using amber
25  *//*--------------------------------------------------------------------*/
26 
27 #include <string>
28 #include <set>
29 #include <functional>
30 #include "tcuDefs.hpp"
31 #include "tcuTestCase.hpp"
32 #include "vkSpirVProgram.hpp"
33 #include "vktTestCase.hpp"
34 
35 namespace amber
36 {
37 class Recipe;
38 }
39 
40 namespace vkt
41 {
42 namespace cts_amber
43 {
44 
45 struct BufferRequirement
46 {
47     vk::VkFormat m_format;
48     vk::VkFormatFeatureFlags m_featureFlags;
49 };
50 
51 class AmberTestInstance : public TestInstance
52 {
53 public:
AmberTestInstance(Context & context,amber::Recipe * recipe,vk::VkDevice customDevice)54     AmberTestInstance(Context &context, amber::Recipe *recipe, vk::VkDevice customDevice)
55         : TestInstance(context)
56         , m_recipe(recipe)
57         , m_customDevice(customDevice)
58     {
59     }
60 
61     virtual tcu::TestStatus iterate(void);
62 
63 private:
64     amber::Recipe *m_recipe;
65     vk::VkDevice m_customDevice;
66 };
67 
68 class AmberTestCase : public TestCase
69 {
70 public:
71     AmberTestCase(tcu::TestContext &testCtx, const char *name, const char *description,
72                   const std::string &readFilename);
73 
74     virtual ~AmberTestCase(void);
75 
76     TestInstance *createInstance(Context &ctx) const override;
77 
78     // Check that the Vulkan implementation supports this test.
79     // We have the principle that client code in dEQP should independently
80     // determine if the test should be supported:
81     //  - If any of the extensions registered via |addRequirement| is not
82     //    supported then throw a NotSupported exception.
83     //  - Otherwise, we do a secondary quick check depending on code inside
84     //    Amber itself: if the Amber test says it is not supported, then
85     //    throw an internal error exception.
86     // A function pointer for a custom checkSupport function can also be
87     // provided for a more sophisticated support check.
88     void checkSupport(Context &ctx) const override;
89 
90     // If the test case uses SPIR-V Assembly, use these build options.
91     // Otherwise, defaults to target Vulkan 1.0, SPIR-V 1.0.
92     void setSpirVAsmBuildOptions(const vk::SpirVAsmBuildOptions &asm_options);
93     void delayedInit(void) override;
94     void initPrograms(vk::SourceCollections &programCollection) const override;
95 
96     // Add a required instance extension, device extension, or feature bit.
97     // A feature bit is represented by a string of form "<structure>.<feature>", where
98     // the structure name matches the Vulkan spec, but without the leading "VkPhysicalDevice".
99     // An example entry is: "VariablePointerFeatures.variablePointers".
100     // An instance or device extension will not have a period in its name.
101     void addRequirement(const std::string &requirement);
102 
103     void addImageRequirement(vk::VkImageCreateInfo info);
104     void addBufferRequirement(BufferRequirement req);
setCheckSupportCallback(std::function<void (Context &,std::string)> func)105     void setCheckSupportCallback(std::function<void(Context &, std::string)> func)
106     {
107         m_checkSupportCallback = func;
108     }
109 
110     virtual bool validateRequirements() override;
111 
getRunnerType(void) const112     tcu::TestRunnerType getRunnerType(void) const override
113     {
114         return tcu::RUNNERTYPE_AMBER;
115     }
116 
117 protected:
118     bool parse(const std::string &readFilename);
119 
120     amber::Recipe *m_recipe;
121     vk::SpirVAsmBuildOptions m_asm_options;
122 
123     std::string m_readFilename;
124 
125     // Instance and device extensions required by the test.
126     // We don't differentiate between the two:  We consider the requirement
127     // satisfied if the string is registered as either an instance or device
128     // extension.  Use a set for consistent ordering.
129     std::set<std::string> m_required_extensions;
130 
131     // Features required by the test.
132     // A feature bit is represented by a string of form "<structure>.<feature>", where
133     // the structure name matches the Vulkan spec, but without the leading "VkPhysicalDevice".
134     // An example entry is: "VariablePointerFeatures.variablePointers".
135     // Use a set for consistent ordering.
136     std::set<std::string> m_required_features;
137 
138     std::vector<vk::VkImageCreateInfo> m_imageRequirements;
139     std::vector<BufferRequirement> m_bufferRequirements;
140     std::function<void(Context &, std::string)> m_checkSupportCallback = nullptr;
141 };
142 
143 AmberTestCase *createAmberTestCase(
144     tcu::TestContext &testCtx, const char *name, const char *category, const std::string &filename,
145     const std::vector<std::string> requirements                = std::vector<std::string>(),
146     const std::vector<vk::VkImageCreateInfo> imageRequirements = std::vector<vk::VkImageCreateInfo>(),
147     const std::vector<BufferRequirement> bufferRequirements    = std::vector<BufferRequirement>());
148 
149 AmberTestCase *createAmberTestCase(
150     tcu::TestContext &testCtx, const char *name, const char *description, const char *category,
151     const std::string &filename, const std::vector<std::string> requirements = std::vector<std::string>(),
152     const std::vector<vk::VkImageCreateInfo> imageRequirements = std::vector<vk::VkImageCreateInfo>(),
153     const std::vector<BufferRequirement> bufferRequirements    = std::vector<BufferRequirement>());
154 
155 void createAmberTestsFromIndexFile(tcu::TestContext &testCtx, tcu::TestCaseGroup *group, const std::string filename,
156                                    const char *category);
157 
158 } // namespace cts_amber
159 } // namespace vkt
160 
161 #endif // _VKTAMBERTESTCASE_HPP
162