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 { class Recipe; } 36 37 namespace vkt 38 { 39 namespace cts_amber 40 { 41 42 struct BufferRequirement 43 { 44 vk::VkFormat m_format; 45 vk::VkFormatFeatureFlags m_featureFlags; 46 }; 47 48 class AmberTestInstance : public TestInstance 49 { 50 public: AmberTestInstance(Context& context, amber::Recipe* recipe, vk::VkDevice customDevice)51 AmberTestInstance (Context& context, 52 amber::Recipe* recipe, 53 vk::VkDevice customDevice) 54 : TestInstance(context), m_recipe(recipe), m_customDevice(customDevice) 55 { 56 } 57 58 virtual tcu::TestStatus iterate (void); 59 60 private: 61 amber::Recipe* m_recipe; 62 vk::VkDevice m_customDevice; 63 }; 64 65 class AmberTestCase : public TestCase 66 { 67 public: 68 AmberTestCase (tcu::TestContext& testCtx, 69 const char* name, 70 const char* description, 71 const std::string& readFilename); 72 73 virtual ~AmberTestCase (void); 74 75 TestInstance* createInstance (Context& ctx) const override; 76 77 // Check that the Vulkan implementation supports this test. 78 // We have the principle that client code in dEQP should independently 79 // determine if the test should be supported: 80 // - If any of the extensions registered via |addRequirement| is not 81 // supported then throw a NotSupported exception. 82 // - Otherwise, we do a secondary sanity check depending on code inside 83 // Amber itself: if the Amber test says it is not supported, then 84 // throw an internal error exception. 85 // A function pointer for a custom checkSupport function can also be 86 // provided for a more sophisticated support check. 87 void checkSupport (Context& ctx) const override; 88 89 // If the test case uses SPIR-V Assembly, use these build options. 90 // Otherwise, defaults to target Vulkan 1.0, SPIR-V 1.0. 91 void setSpirVAsmBuildOptions(const vk::SpirVAsmBuildOptions& asm_options); 92 void delayedInit (void) override; 93 void initPrograms (vk::SourceCollections& programCollection) const override; 94 95 // Add a required instance extension, device extension, or feature bit. 96 // A feature bit is represented by a string of form "<structure>.<feature>", where 97 // the structure name matches the Vulkan spec, but without the leading "VkPhysicalDevice". 98 // An example entry is: "VariablePointerFeatures.variablePointers". 99 // An instance or device extension will not have a period in its name. 100 void addRequirement(const std::string& requirement); 101 102 void addImageRequirement(vk::VkImageCreateInfo info); 103 void addBufferRequirement(BufferRequirement req); setCheckSupportCallback(std::function<void(Context&, std::string)> func)104 void setCheckSupportCallback(std::function<void(Context&, std::string)> func) { m_checkSupportCallback = func; } 105 106 virtual bool validateRequirements() override; 107 108 tcu::TestRunnerType getRunnerType (void) const override { return tcu::RUNNERTYPE_AMBER; } 109 110 protected: 111 bool parse (const std::string& readFilename); 112 113 amber::Recipe* m_recipe; 114 vk::SpirVAsmBuildOptions m_asm_options; 115 116 std::string m_readFilename; 117 118 // Instance and device extensions required by the test. 119 // We don't differentiate between the two: We consider the requirement 120 // satisfied if the string is registered as either an instance or device 121 // extension. Use a set for consistent ordering. 122 std::set<std::string> m_required_extensions; 123 124 // Features required by the test. 125 // A feature bit is represented by a string of form "<structure>.<feature>", where 126 // the structure name matches the Vulkan spec, but without the leading "VkPhysicalDevice". 127 // An example entry is: "VariablePointerFeatures.variablePointers". 128 // Use a set for consistent ordering. 129 std::set<std::string> m_required_features; 130 131 std::vector<vk::VkImageCreateInfo> m_imageRequirements; 132 std::vector<BufferRequirement> m_bufferRequirements; 133 std::function<void(Context&, std::string)> m_checkSupportCallback = nullptr; 134 }; 135 136 AmberTestCase* createAmberTestCase (tcu::TestContext& testCtx, 137 const char* name, 138 const char* description, 139 const char* category, 140 const std::string& filename, 141 const std::vector<std::string> requirements = std::vector<std::string>(), 142 const std::vector<vk::VkImageCreateInfo> imageRequirements = std::vector<vk::VkImageCreateInfo>(), 143 const std::vector<BufferRequirement> bufferRequirements = std::vector<BufferRequirement>()); 144 145 void createAmberTestsFromIndexFile (tcu::TestContext& testCtx, 146 tcu::TestCaseGroup* group, 147 const std::string filename, 148 const char* category); 149 150 } // cts_amber 151 } // vkt 152 153 #endif // _VKTAMBERTESTCASE_HPP 154