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 // Add a required property bit. 104 // A property bit is represented by a string of form "<structure>.<property>", where 105 // the structure name matches the Vulkan spec, but without the leading "VkPhysicalDevice". 106 void addPropertyRequirement(const std::string &requirement); 107 108 void addImageRequirement(vk::VkImageCreateInfo info); 109 void addBufferRequirement(BufferRequirement req); setCheckSupportCallback(std::function<void (Context &,std::string)> func)110 void setCheckSupportCallback(std::function<void(Context &, std::string)> func) 111 { 112 m_checkSupportCallback = func; 113 } 114 115 virtual bool validateRequirements() override; 116 getRunnerType(void) const117 tcu::TestRunnerType getRunnerType(void) const override 118 { 119 return tcu::RUNNERTYPE_AMBER; 120 } 121 122 protected: 123 bool parse(const std::string &readFilename); 124 125 amber::Recipe *m_recipe; 126 vk::SpirVAsmBuildOptions m_asm_options; 127 128 std::string m_readFilename; 129 130 // Instance and device extensions required by the test. 131 // We don't differentiate between the two: We consider the requirement 132 // satisfied if the string is registered as either an instance or device 133 // extension. Use a set for consistent ordering. 134 std::set<std::string> m_required_extensions; 135 136 // Features required by the test. 137 // A feature bit is represented by a string of form "<structure>.<feature>", where 138 // the structure name matches the Vulkan spec, but without the leading "VkPhysicalDevice". 139 // An example entry is: "VariablePointerFeatures.variablePointers". 140 // Use a set for consistent ordering. 141 std::set<std::string> m_required_features; 142 143 // Properties required by the test. 144 // A property bit is represented by a string of form "<structure>.<property>", where 145 // the structure name matches the Vulkan spec, but without the leading "VkPhysicalDevice". 146 std::set<std::string> m_required_properties; 147 148 std::vector<vk::VkImageCreateInfo> m_imageRequirements; 149 std::vector<BufferRequirement> m_bufferRequirements; 150 std::function<void(Context &, std::string)> m_checkSupportCallback = nullptr; 151 }; 152 153 AmberTestCase *createAmberTestCase( 154 tcu::TestContext &testCtx, const char *name, const char *category, const std::string &filename, 155 const std::vector<std::string> requirements = std::vector<std::string>(), 156 const std::vector<vk::VkImageCreateInfo> imageRequirements = std::vector<vk::VkImageCreateInfo>(), 157 const std::vector<BufferRequirement> bufferRequirements = std::vector<BufferRequirement>()); 158 159 AmberTestCase *createAmberTestCase( 160 tcu::TestContext &testCtx, const char *name, const char *description, const char *category, 161 const std::string &filename, const std::vector<std::string> requirements = std::vector<std::string>(), 162 const std::vector<vk::VkImageCreateInfo> imageRequirements = std::vector<vk::VkImageCreateInfo>(), 163 const std::vector<BufferRequirement> bufferRequirements = std::vector<BufferRequirement>()); 164 165 void createAmberTestsFromIndexFile(tcu::TestContext &testCtx, tcu::TestCaseGroup *group, const std::string filename, 166 const char *category); 167 168 } // namespace cts_amber 169 } // namespace vkt 170 171 #endif // _VKTAMBERTESTCASE_HPP 172