Po-Hsien Wang | 00777b2 | 2019-04-24 16:37:09 -0700 | [diff] [blame] | 1 | // Copyright 2019 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef __VKBENCH_TESTBASE_H__ |
| 6 | #define __VKBENCH_TESTBASE_H__ |
| 7 | |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | #include <vulkan/vulkan.hpp> |
| 11 | |
| 12 | #include "utils.h" |
| 13 | |
| 14 | namespace vkbench { |
| 15 | class testBase { |
| 16 | public: |
| 17 | virtual ~testBase() = default; |
| 18 | // Name of test. |
| 19 | virtual const char* Name() const = 0; |
| 20 | // Description of the test. |
| 21 | virtual const char* Desp() const = 0; |
| 22 | // Unit for formatted measurement. |
| 23 | virtual const char* Unit() const = 0; |
| 24 | // Given time elapse per iteration, format it into meaningful numbers. |
| 25 | virtual double FormatMeasurement(double time) { return time; } |
| 26 | |
| 27 | // Vulkan initialization for allocating universal resources. Must be called |
| 28 | // before TestInitialization. |
| 29 | virtual void VkInitialization(); |
| 30 | // Test related resources allocation. The resources allocated here would be |
| 31 | // shared by all TestRun iterations. Time spent here will not be recorded. |
| 32 | virtual void TestInitialization(){} |
| 33 | // Test configuration before running the test. This will run once before |
| 34 | // each TestRun loop. Time spent here will be recorded. |
| 35 | virtual void TestSetup(){} |
| 36 | // Test body. Time spent will be recorded. |
| 37 | virtual bool TestRun() = 0; |
| 38 | // Test cleanup after looping TestRun. Time spent here will be recorded. |
| 39 | virtual void TestCleanup() = 0; |
| 40 | // Free and Destroy any resources allocated during TestInitialization. Time |
| 41 | // spent here will not be recorded. |
| 42 | virtual void TestDestroy() = 0; |
| 43 | // Free and Destroy any general vulkan resources |
| 44 | virtual void VkDestroy(); |
| 45 | |
| 46 | protected: |
| 47 | // Vulkan general method. |
| 48 | virtual bool CreateInstance(); |
| 49 | virtual bool ChoosePhysical_device_(); |
| 50 | virtual bool CreateLogicalDevice(); |
| 51 | virtual bool CreateCommandPool(); |
| 52 | |
| 53 | // Vulkan handles |
| 54 | const std::vector<const char*> kValidation_layers_ = { |
| 55 | "VK_LAYER_LUNARG_standard_validation", "VK_LAYER_GOOGLE_threading"}; |
| 56 | bool enable_validation_layer_ = false; |
| 57 | |
| 58 | vk::DebugUtilsMessengerEXT debug_messenger_; |
| 59 | vk::Instance instance_; |
| 60 | vk::PhysicalDevice physical_device_; |
| 61 | vk::Device device_; |
| 62 | vk::Queue gfx_queue_; |
| 63 | vk::CommandPool cmd_pool_; |
| 64 | uint32_t gfx_queue_idx_ = -1; |
| 65 | }; |
| 66 | |
| 67 | } // namespace vkbench |
| 68 | #endif |