blob: c73600f7a0f91ba548f08704a45e177e62b72596 [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 Barbour6918cd52015-04-09 12:58:51 -060062 VkTestFramework();
63 ~VkTestFramework();
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -060064
Tony Barbour7b60e492016-02-02 14:43:55 -070065 VkFormat GetFormat(VkInstance instance, vk_testing::Device *device);
Karl Schultz6addd812016-02-02 17:17:23 -070066 static bool optionMatch(const char *option, char *optionLine);
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -060067 static void InitArgs(int *argc, char *argv[]);
68 static void Finish();
69
Karl Schultz9d09ee92018-10-19 14:31:49 -060070 bool GLSLtoSPV(const VkShaderStageFlagBits shader_type, const char *pshader, std::vector<unsigned int> &spv,
71 bool debug = false);
Karl Schultz23707622018-08-22 10:20:33 -060072 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 -070073 static bool m_canonicalize_spv;
74 static bool m_strip_spv;
75 static bool m_do_everything_spv;
Tobin Ehlis72888642017-11-15 09:43:56 -070076 static bool m_devsim_layer;
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -060077
Karl Schultz6addd812016-02-02 17:17:23 -070078 char **ReadFileData(const char *fileName);
79 void FreeFileData(char **data);
Courtney Goeltzenleuchter8bc46f42014-10-21 15:24:51 -060080
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070081 private:
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -060082 int m_compile_options;
83 int m_num_shader_strings;
84 TBuiltInResource Resources;
Karl Schultz6addd812016-02-02 17:17:23 -070085 void SetMessageOptions(EShMessages &messages);
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -060086 void ProcessConfigFile();
Karl Schultz6addd812016-02-02 17:17:23 -070087 EShLanguage FindLanguage(const std::string &name);
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060088 EShLanguage FindLanguage(const VkShaderStageFlagBits shader_type);
Courtney Goeltzenleuchter9818f782014-10-03 09:53:32 -060089 std::string ConfigFile;
Karl Schultz6addd812016-02-02 17:17:23 -070090 bool SetConfigFile(const std::string &name);
91 static int m_width;
92 static int m_height;
93 string m_testName;
Courtney Goeltzenleuchter30e9dc42014-09-04 16:24:19 -060094};
95
Karl Schultz6addd812016-02-02 17:17:23 -070096class TestEnvironment : public ::testing::Environment {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070097 public:
Karl Schultz6addd812016-02-02 17:17:23 -070098 void SetUp();
Courtney Goeltzenleuchtera0f74c52014-10-08 08:46:51 -060099
Karl Schultz6addd812016-02-02 17:17:23 -0700100 void TearDown();
Courtney Goeltzenleuchtera0f74c52014-10-08 08:46:51 -0600101};
102
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700103#endif // VKTESTFRAMEWORK_H