blob: 76f02a1fc6e7693cc29b52e4c75c52efe041eeee [file] [log] [blame]
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001// VK tests
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -06002//
3// Copyright (C) 2014 LunarG, Inc.
4//
5// Permission is hereby granted, free of charge, to any person obtaining a
6// copy of this software and associated documentation files (the "Software"),
7// to deal in the Software without restriction, including without limitation
8// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9// and/or sell copies of the Software, and to permit persons to whom the
10// Software is furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included
13// in all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21// DEALINGS IN THE SOFTWARE.
22
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060023#ifndef VKTESTFRAMEWORK_H
24#define VKTESTFRAMEWORK_H
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060025
26#include "gtest-1.7.0/include/gtest/gtest.h"
Courtney Goeltzenleuchter94192032014-10-03 09:53:32 -060027#include "ShaderLang.h"
28#include "GLSL450Lib.h"
Cody Northropd4e020a2015-03-17 14:54:35 -060029#include "icd-spv.h"
Chia-I Wu13ecdcd2014-12-29 14:38:28 +080030#include "test_common.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060031#include "vktestbinding.h"
Tony Barbouref20d322015-02-25 12:28:39 -070032#include "test_environment.h"
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060033
34#include <stdlib.h>
35#include <stdio.h>
36#include <stdbool.h>
37#include <string.h>
38#include <iostream>
39#include <fstream>
40#include <list>
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060041#include <vkWsiX11Ext.h>
Courtney Goeltzenleuchter28d33962014-10-27 13:04:37 -060042
43// Can be used by tests to record additional details / description of test
44#define TEST_DESCRIPTION(desc) RecordProperty("description", desc)
45
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060046using namespace std;
47
Tony Barbour01999182015-04-09 12:58:51 -060048class VkImageObj;
Chia-I Wu13ecdcd2014-12-29 14:38:28 +080049
Tony Barbouref20d322015-02-25 12:28:39 -070050
Tony Barbour01999182015-04-09 12:58:51 -060051class VkTestImageRecord
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060052{
53public:
Tony Barbour01999182015-04-09 12:58:51 -060054 VkTestImageRecord();
55 VkTestImageRecord(const VkTestImageRecord &);
56 ~VkTestImageRecord();
57 VkTestImageRecord &operator=(const VkTestImageRecord &rhs);
58 int operator==(const VkTestImageRecord &rhs) const;
59 int operator<(const VkTestImageRecord &rhs) const;
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060060
Tony Barbouref20d322015-02-25 12:28:39 -070061 string m_title;
62 int m_width;
63 int m_height;
64 void *m_data;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060065 VkImage m_presentableImage;
66 VkGpuMemory m_presentableMemory;
Tony Barbouref20d322015-02-25 12:28:39 -070067 unsigned m_data_size;
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060068};
69
Tony Barbour01999182015-04-09 12:58:51 -060070class VkTestFramework : public ::testing::Test
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060071{
72public:
Tony Barbour01999182015-04-09 12:58:51 -060073 VkTestFramework();
74 ~VkTestFramework();
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060075
76 static void InitArgs(int *argc, char *argv[]);
77 static void Finish();
78
Tony Barbour01999182015-04-09 12:58:51 -060079 void WritePPM( const char *basename, VkImageObj *image );
80 void Show(const char *comment, VkImageObj *image);
81 void Compare(const char *comment, VkImageObj *image);
82 void RecordImage(VkImageObj * image);
83 void RecordImages(vector<VkImageObj *> image);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060084 bool GLSLtoSPV(const VkPipelineShaderStage shader_type,
Courtney Goeltzenleuchter94192032014-10-03 09:53:32 -060085 const char *pshader,
Cody Northropacfb0492015-03-17 15:55:58 -060086 std::vector<unsigned int> &spv);
87 static bool m_use_spv;
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060088
Courtney Goeltzenleuchter5c25faa2014-10-21 15:24:51 -060089 char** ReadFileData(const char* fileName);
90 void FreeFileData(char** data);
91
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060092private:
Courtney Goeltzenleuchter94192032014-10-03 09:53:32 -060093 int m_compile_options;
94 int m_num_shader_strings;
95 TBuiltInResource Resources;
Courtney Goeltzenleuchter94192032014-10-03 09:53:32 -060096 void SetMessageOptions(EShMessages& messages);
97 void ProcessConfigFile();
Courtney Goeltzenleuchter94192032014-10-03 09:53:32 -060098 EShLanguage FindLanguage(const std::string& name);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060099 EShLanguage FindLanguage(const VkPipelineShaderStage shader_type);
Courtney Goeltzenleuchter94192032014-10-03 09:53:32 -0600100 std::string ConfigFile;
101 bool SetConfigFile(const std::string& name);
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -0600102
Tony Barbouref20d322015-02-25 12:28:39 -0700103 static bool m_show_images;
104 static bool m_save_images;
105 static bool m_compare_images;
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -0600106
Tony Barbour01999182015-04-09 12:58:51 -0600107 static std::list<VkTestImageRecord> m_images;
108 static std::list<VkTestImageRecord>::iterator m_display_image;
Tony Barbouref20d322015-02-25 12:28:39 -0700109 static int m_display_image_idx;
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -0600110
Tony Barbouref20d322015-02-25 12:28:39 -0700111 static int m_width; // Window width
112 static int m_height; // Window height
Tony Barbour32f368c2014-10-30 14:29:04 -0600113
Tony Barbouref20d322015-02-25 12:28:39 -0700114 int m_frameNum;
115 string m_testName;
Tony Barbour32f368c2014-10-30 14:29:04 -0600116
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -0600117};
118
Tony Barbouref20d322015-02-25 12:28:39 -0700119
Tony Barbour01999182015-04-09 12:58:51 -0600120class TestFrameworkVkPresent
Tony Barbouref20d322015-02-25 12:28:39 -0700121{
122public:
Tony Barbour01999182015-04-09 12:58:51 -0600123 TestFrameworkVkPresent();
Tony Barbouref20d322015-02-25 12:28:39 -0700124
125 void Run();
Tony Barbour01999182015-04-09 12:58:51 -0600126 void InitPresentFramework(std::list<VkTestImageRecord> &imagesIn);
Tony Barbour0c9f29c2015-04-02 15:52:36 -0600127 void CreateMyWindow();
Tony Barbouref20d322015-02-25 12:28:39 -0700128 void CreatePresentableImages();
129 void TearDown();
130
131protected:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600132 vk_testing::Device &m_device;
133 vk_testing::Queue &m_queue;
134 vk_testing::CmdBuffer m_cmdbuf;
Tony Barbouref20d322015-02-25 12:28:39 -0700135
136private:
137 xcb_window_t m_window;
138 xcb_intern_atom_reply_t *m_atom_wm_delete_window;
Tony Barbour01999182015-04-09 12:58:51 -0600139 std::list<VkTestImageRecord> m_images;
Tony Barbouref20d322015-02-25 12:28:39 -0700140
141 bool m_quit;
142 bool m_pause;
143
144 uint32_t m_width;
145 uint32_t m_height;
146
Tony Barbour01999182015-04-09 12:58:51 -0600147 std::list<VkTestImageRecord>::iterator m_display_image;
Tony Barbouref20d322015-02-25 12:28:39 -0700148
149 void Display();
150 void HandleEvent(xcb_generic_event_t *event);
151};
152
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -0600153class TestEnvironment : public ::testing::Environment
154{
155 public:
156 void SetUp();
157
158 void TearDown();
159};
160
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600161#endif // VKTESTFRAMEWORK_H