blob: 5dfc8166ff63ba781125f53ae61d99ddf98e3584 [file] [log] [blame]
Po-Hsien Wang00777b22019-04-24 16:37:09 -07001// 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
Po-Hsien Wang00777b22019-04-24 16:37:09 -07008#include <vector>
9#include <vulkan/vulkan.hpp>
10
Po-Hsien Wanga956e652020-11-11 16:29:04 -080011#include "filepath.h"
Po-Hsien Wanga0e1c312020-09-24 22:06:52 +080012#include "vkBase.h"
Po-Hsien Wanga956e652020-11-11 16:29:04 -080013#include "utils.h"
Po-Hsien Wang00777b22019-04-24 16:37:09 -070014
15namespace vkbench {
16class testBase {
17 public:
Po-Hsien Wang42e116c2020-06-09 16:10:27 -070018 virtual ~testBase() {}
Po-Hsien Wang00777b22019-04-24 16:37:09 -070019 // Name of test.
20 virtual const char* Name() const = 0;
21 // Description of the test.
22 virtual const char* Desp() const = 0;
23 // Unit for formatted measurement.
24 virtual const char* Unit() const = 0;
25 // Given time elapse per iteration, format it into meaningful numbers.
26 virtual double FormatMeasurement(double time) { return time; }
27
Po-Hsien Wanga0e1c312020-09-24 22:06:52 +080028 // SaveImage saves the rendered image to file_name.
Po-Hsien Wanga956e652020-11-11 16:29:04 -080029 virtual void SaveImage(FilePath file_path) const {
Po-Hsien Wanga0e1c312020-09-24 22:06:52 +080030 throw std::runtime_error("Not Implemented!");
31 };
32
Po-Hsien Wang00777b22019-04-24 16:37:09 -070033 // Test related resources allocation. The resources allocated here would be
Po-Hsien Wang42e116c2020-06-09 16:10:27 -070034 // shared by all Run iterations. Time spent here will not be recorded.
35 virtual void Initialize() {}
Po-Hsien Wang00777b22019-04-24 16:37:09 -070036 // Test configuration before running the test. This will run once before
Po-Hsien Wang42e116c2020-06-09 16:10:27 -070037 // each Run loop. Time spent here will be recorded.
38 virtual void Setup() {}
Po-Hsien Wang00777b22019-04-24 16:37:09 -070039 // Test body. Time spent will be recorded.
Po-Hsien Wang42e116c2020-06-09 16:10:27 -070040 virtual void Run() = 0;
41 // Test cleanup after looping Run. Time spent here will be recorded.
Po-Hsien Wanga956e652020-11-11 16:29:04 -080042 virtual void Cleanup(){};
Po-Hsien Wang42e116c2020-06-09 16:10:27 -070043 // Free and Destroy any resources allocated during Initialize. Time
Po-Hsien Wang00777b22019-04-24 16:37:09 -070044 // spent here will not be recorded.
Po-Hsien Wang42e116c2020-06-09 16:10:27 -070045 virtual void Destroy() = 0;
Po-Hsien Wang00777b22019-04-24 16:37:09 -070046
Po-Hsien Wanga0e1c312020-09-24 22:06:52 +080047 vkbench::vkBase* vk;
Po-Hsien Wang00777b22019-04-24 16:37:09 -070048};
49
50} // namespace vkbench
51#endif