blob: 0ac0e8e52ac8297845fc38742b099989a919aaca [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
Karl Schultz7b024b42018-08-30 16:18:18 -06002 * Copyright (c) 2015-2019 The Khronos Group Inc.
3 * Copyright (c) 2015-2019 Valve Corporation
4 * Copyright (c) 2015-2019 LunarG, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07005 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06006 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -07009 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060010 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070011 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060012 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
Karl Schultz6addd812016-02-02 17:17:23 -070017 *
18 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
19 * Author: Tony Barbour <tony@LunarG.com>
20 */
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -060021
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060022#ifndef VKTESTFRAMEWORK_H
23#define VKTESTFRAMEWORK_H
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -060024
GregF5af3f772015-09-22 13:58:21 -060025#include "SPIRV/GLSL.std.450.h"
Karl Schultz23707622018-08-22 10:20:33 -060026#include "spirv-tools/libspirv.h"
Mark Lobodzinskic6a62142016-09-07 16:35:55 -060027#include "glslang/Public/ShaderLang.h"
Cody Northrop054a4702015-03-17 14:54:35 -060028#include "icd-spv.h"
Chia-I Wua6bc0ce2014-12-29 14:38:28 +080029#include "test_common.h"
Tony Barbour96db8822015-02-25 12:28:39 -070030#include "test_environment.h"
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -060031
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -060032#include <fstream>
Mark Lobodzinskic6a62142016-09-07 16:35:55 -060033#include <iostream>
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -060034#include <list>
Mark Lobodzinskic6a62142016-09-07 16:35:55 -060035#include <stdbool.h>
36#include <stdio.h>
37#include <stdlib.h>
38#include <string.h>
Courtney Goeltzenleuchterc5e00a12014-10-27 13:04:37 -060039
Tony Barbour3d69c9e2015-05-20 16:53:31 -060040#ifdef _WIN32
Courtney Goeltzenleuchter8e52a122015-12-16 16:03:43 -070041#ifndef WIN32_LEAN_AND_MEAN
Tony Barbour3d69c9e2015-05-20 16:53:31 -060042#define WIN32_LEAN_AND_MEAN
Courtney Goeltzenleuchter8e52a122015-12-16 16:03:43 -070043#endif
Tony Barbour3d69c9e2015-05-20 16:53:31 -060044#include <windows.h>
45#endif
46
Tony Barbourf20f87b2015-04-22 09:02:32 -060047#if defined(NDEBUG) && defined(__GNUC__)
48#define U_ASSERT_ONLY __attribute__((unused))
49#else
50#define U_ASSERT_ONLY
51#endif
52
Courtney Goeltzenleuchterc5e00a12014-10-27 13:04:37 -060053// Can be used by tests to record additional details / description of test
54#define TEST_DESCRIPTION(desc) RecordProperty("description", desc)
55
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -060056using namespace std;
57
Tony Barbour6918cd52015-04-09 12:58:51 -060058class VkImageObj;
Chia-I Wua6bc0ce2014-12-29 14:38:28 +080059
Karl Schultz6addd812016-02-02 17:17:23 -070060class VkTestFramework : public ::testing::Test {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070061 public:
Tony Barbour7b60e492016-02-02 14:43:55 -070062 VkFormat GetFormat(VkInstance instance, vk_testing::Device *device);
Karl Schultz6addd812016-02-02 17:17:23 -070063 static bool optionMatch(const char *option, char *optionLine);
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -060064 static void InitArgs(int *argc, char *argv[]);
65 static void Finish();
66
Karl Schultz9d09ee92018-10-19 14:31:49 -060067 bool GLSLtoSPV(const VkShaderStageFlagBits shader_type, const char *pshader, std::vector<unsigned int> &spv,
68 bool debug = false);
Karl Schultz23707622018-08-22 10:20:33 -060069 bool ASMtoSPV(const spv_target_env target_env, const uint32_t options, const char *pasm, std::vector<unsigned int> &spv);
Karl Schultz6addd812016-02-02 17:17:23 -070070 static bool m_canonicalize_spv;
71 static bool m_strip_spv;
72 static bool m_do_everything_spv;
Tobin Ehlis72888642017-11-15 09:43:56 -070073 static bool m_devsim_layer;
Mark Lobodzinski2cf94fd2019-03-18 14:53:33 -060074 static bool m_khronos_layer_disable;
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -060075
Karl Schultz6addd812016-02-02 17:17:23 -070076 char **ReadFileData(const char *fileName);
77 void FreeFileData(char **data);
Courtney Goeltzenleuchter8bc46f42014-10-21 15:24:51 -060078
Petr Kraus13b625d2019-03-25 15:29:47 +010079 protected:
80 VkTestFramework();
81 virtual ~VkTestFramework() = 0;
82
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070083 private:
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -060084 int m_compile_options;
85 int m_num_shader_strings;
86 TBuiltInResource Resources;
Karl Schultz6addd812016-02-02 17:17:23 -070087 void SetMessageOptions(EShMessages &messages);
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -060088 void ProcessConfigFile();
Karl Schultz6addd812016-02-02 17:17:23 -070089 EShLanguage FindLanguage(const std::string &name);
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060090 EShLanguage FindLanguage(const VkShaderStageFlagBits shader_type);
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -060091 std::string ConfigFile;
Karl Schultz6addd812016-02-02 17:17:23 -070092 bool SetConfigFile(const std::string &name);
93 static int m_width;
94 static int m_height;
95 string m_testName;
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -060096};
97
Karl Schultz6addd812016-02-02 17:17:23 -070098class TestEnvironment : public ::testing::Environment {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070099 public:
Karl Schultz6addd812016-02-02 17:17:23 -0700100 void SetUp();
Courtney Goeltzenleuchtera0f74c52014-10-08 08:46:51 -0600101
Karl Schultz6addd812016-02-02 17:17:23 -0700102 void TearDown();
Courtney Goeltzenleuchtera0f74c52014-10-08 08:46:51 -0600103};
104
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700105#endif // VKTESTFRAMEWORK_H