blob: 34f9e750d3323cba343b62be7ad6bc3bdcc988d3 [file] [log] [blame]
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06001//
Courtney Goeltzenleuchterfcbe16f2015-10-29 13:50:34 -06002// Copyright (C) 2015 Valve Corporation
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -06003//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included
12// in all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060021//
22// Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
23// Author: Tony Barbour <tony@LunarG.com>
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -060024
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060025#ifndef VKTESTFRAMEWORK_H
26#define VKTESTFRAMEWORK_H
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -060027
Courtney Goeltzenleuchter58f3eff2015-10-07 13:28:58 -060028//#include "gtest-1.7.0/include/gtest/gtest.h"
Cody Northrop5a95b472015-06-03 13:01:54 -060029#include "glslang/Public/ShaderLang.h"
GregF5af3f772015-09-22 13:58:21 -060030#include "SPIRV/GLSL.std.450.h"
Cody Northrop054a4702015-03-17 14:54:35 -060031#include "icd-spv.h"
Chia-I Wua6bc0ce2014-12-29 14:38:28 +080032#include "test_common.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060033#include "vktestbinding.h"
Tony Barbour96db8822015-02-25 12:28:39 -070034#include "test_environment.h"
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -060035
36#include <stdlib.h>
37#include <stdio.h>
38#include <stdbool.h>
39#include <string.h>
40#include <iostream>
41#include <fstream>
42#include <list>
Courtney Goeltzenleuchterc5e00a12014-10-27 13:04:37 -060043
Tony Barbour3d69c9e2015-05-20 16:53:31 -060044#ifdef _WIN32
Courtney Goeltzenleuchter8e52a122015-12-16 16:03:43 -070045#ifndef WIN32_LEAN_AND_MEAN
Tony Barbour3d69c9e2015-05-20 16:53:31 -060046#define WIN32_LEAN_AND_MEAN
Courtney Goeltzenleuchter8e52a122015-12-16 16:03:43 -070047#endif
Tony Barbour3d69c9e2015-05-20 16:53:31 -060048#include <windows.h>
49#endif
50
Tony Barbourf20f87b2015-04-22 09:02:32 -060051#if defined(NDEBUG) && defined(__GNUC__)
52#define U_ASSERT_ONLY __attribute__((unused))
53#else
54#define U_ASSERT_ONLY
55#endif
56
Courtney Goeltzenleuchterc5e00a12014-10-27 13:04:37 -060057// Can be used by tests to record additional details / description of test
58#define TEST_DESCRIPTION(desc) RecordProperty("description", desc)
59
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -060060using namespace std;
61
Tony Barbour6918cd52015-04-09 12:58:51 -060062class VkImageObj;
Chia-I Wua6bc0ce2014-12-29 14:38:28 +080063
Tony Barbour96db8822015-02-25 12:28:39 -070064
Tony Barbour6918cd52015-04-09 12:58:51 -060065class VkTestImageRecord
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -060066{
67public:
Tony Barbour6918cd52015-04-09 12:58:51 -060068 VkTestImageRecord();
69 VkTestImageRecord(const VkTestImageRecord &);
70 ~VkTestImageRecord();
71 VkTestImageRecord &operator=(const VkTestImageRecord &rhs);
72 int operator==(const VkTestImageRecord &rhs) const;
73 int operator<(const VkTestImageRecord &rhs) const;
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -060074
Tony Barbour96db8822015-02-25 12:28:39 -070075 string m_title;
76 int m_width;
77 int m_height;
78 void *m_data;
Tony Barbour96db8822015-02-25 12:28:39 -070079 unsigned m_data_size;
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -060080};
81
Tony Barbour6918cd52015-04-09 12:58:51 -060082class VkTestFramework : public ::testing::Test
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -060083{
84public:
Tony Barbour6918cd52015-04-09 12:58:51 -060085 VkTestFramework();
86 ~VkTestFramework();
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -060087
Cody Northrop50a2a4b2015-06-03 16:49:20 -060088 static bool optionMatch(const char* option, char* optionLine);
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -060089 static void InitArgs(int *argc, char *argv[]);
90 static void Finish();
91
Tony Barbour6918cd52015-04-09 12:58:51 -060092 void WritePPM( const char *basename, VkImageObj *image );
93 void Show(const char *comment, VkImageObj *image);
94 void Compare(const char *comment, VkImageObj *image);
95 void RecordImage(VkImageObj * image);
96 void RecordImages(vector<VkImageObj *> image);
Tony Barbour2d6d54e2015-12-03 16:05:11 -070097 VkFormat GetFormat(VkInstance instance, vk_testing::Device *device);
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060098 bool GLSLtoSPV(const VkShaderStageFlagBits shader_type,
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -060099 const char *pshader,
Cody Northrop3bfd27c2015-03-17 15:55:58 -0600100 std::vector<unsigned int> &spv);
Cody Northrop50a2a4b2015-06-03 16:49:20 -0600101 static bool m_use_glsl;
Cody Northrop5a95b472015-06-03 13:01:54 -0600102 static bool m_canonicalize_spv;
103 static bool m_strip_spv;
104 static bool m_do_everything_spv;
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600105
Courtney Goeltzenleuchter8bc46f42014-10-21 15:24:51 -0600106 char** ReadFileData(const char* fileName);
107 void FreeFileData(char** data);
108
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600109private:
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -0600110 int m_compile_options;
111 int m_num_shader_strings;
112 TBuiltInResource Resources;
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -0600113 void SetMessageOptions(EShMessages& messages);
114 void ProcessConfigFile();
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -0600115 EShLanguage FindLanguage(const std::string& name);
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -0600116 EShLanguage FindLanguage(const VkShaderStageFlagBits shader_type);
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -0600117 std::string ConfigFile;
118 bool SetConfigFile(const std::string& name);
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600119
Tony Barbour96db8822015-02-25 12:28:39 -0700120 static bool m_show_images;
121 static bool m_save_images;
122 static bool m_compare_images;
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600123
Courtney Goeltzenleuchterd6079ec2015-04-22 10:09:35 -0600124 static std::list<VkTestImageRecord> m_images;
Tony Barbour6918cd52015-04-09 12:58:51 -0600125 static std::list<VkTestImageRecord>::iterator m_display_image;
Tony Barbour96db8822015-02-25 12:28:39 -0700126 static int m_display_image_idx;
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600127
Tony Barbour96db8822015-02-25 12:28:39 -0700128 static int m_width; // Window width
129 static int m_height; // Window height
Tony Barbour247bf372014-10-30 14:29:04 -0600130
Tony Barbour96db8822015-02-25 12:28:39 -0700131 int m_frameNum;
132 string m_testName;
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -0600133};
134
Courtney Goeltzenleuchtera0f74c52014-10-08 08:46:51 -0600135class TestEnvironment : public ::testing::Environment
136{
137 public:
138 void SetUp();
139
140 void TearDown();
141};
142
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600143#endif // VKTESTFRAMEWORK_H