blob: 818f1cea7763a2b9fd14faa11d1fe5a5c1d04d0d [file] [log] [blame]
Michael Lentinee6c6dd52015-11-03 16:20:30 -08001// VK tests
2//
Karl Schultz1fa32a82016-02-04 11:33:21 -07003// Copyright (c) 2015-2016 The Khronos Group Inc.
4// Copyright (c) 2015-2016 Valve Corporation
5// Copyright (c) 2015-2016 LunarG, Inc.
6// Copyright (c) 2015-2016 Google, Inc.
Michael Lentinee6c6dd52015-11-03 16:20:30 -08007//
Karl Schultz1fa32a82016-02-04 11:33:21 -07008// Permission is hereby granted, free of charge, to any person obtaining a copy
9// of this software and/or associated documentation files (the "Materials"), to
10// deal in the Materials without restriction, including without limitation the
11// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12// sell copies of the Materials, and to permit persons to whom the Materials are
13// furnished to do so, subject to the following conditions:
Michael Lentinee6c6dd52015-11-03 16:20:30 -080014//
Karl Schultz1fa32a82016-02-04 11:33:21 -070015// The above copyright notice(s) and this permission notice shall be included in
16// all copies or substantial portions of the Materials.
Michael Lentinee6c6dd52015-11-03 16:20:30 -080017//
Karl Schultz1fa32a82016-02-04 11:33:21 -070018// THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Michael Lentinee6c6dd52015-11-03 16:20:30 -080019// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Karl Schultz1fa32a82016-02-04 11:33:21 -070020// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21//
22// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
23// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
25// USE OR OTHER DEALINGS IN THE MATERIALS.
Michael Lentinee6c6dd52015-11-03 16:20:30 -080026
27#include "vktestframeworkandroid.h"
Cody Northrop50537d02016-03-08 22:25:52 -070028#include "shaderc/shaderc.hpp"
29#include <android/log.h>
Michael Lentinee6c6dd52015-11-03 16:20:30 -080030
31VkTestFramework::VkTestFramework() {}
32VkTestFramework::~VkTestFramework() {}
33
Cody Northrop50537d02016-03-08 22:25:52 -070034bool VkTestFramework::m_use_glsl = false;
Michael Lentinee6c6dd52015-11-03 16:20:30 -080035
Michael Lentinef7f34d92015-12-09 08:44:25 -080036VkFormat VkTestFramework::GetFormat(VkInstance instance, vk_testing::Device *device)
37{
38 VkFormatProperties format_props;
39 vkGetPhysicalDeviceFormatProperties(device->phy().handle(), VK_FORMAT_B8G8R8A8_UNORM, &format_props);
40 if (format_props.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT ||
41 format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT)
42 {
43 return VK_FORMAT_B8G8R8A8_UNORM;
44 }
45 vkGetPhysicalDeviceFormatProperties(device->phy().handle(), VK_FORMAT_R8G8B8A8_UNORM, &format_props);
46 if (format_props.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT ||
47 format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT)
48 {
49 return VK_FORMAT_R8G8B8A8_UNORM;
50 }
51 printf("Error - device does not support VK_FORMAT_B8G8R8A8_UNORM nor VK_FORMAT_R8G8B8A8_UNORM - exiting\n");
52 exit(0);
53}
54
Michael Lentinee6c6dd52015-11-03 16:20:30 -080055
56void VkTestFramework::InitArgs(int *argc, char *argv[]) {}
57void VkTestFramework::Finish() {}
58
59void TestEnvironment::SetUp()
60{
61 vk_testing::set_error_callback(test_error_callback);
62}
63
64void TestEnvironment::TearDown() {}
Cody Northrop50537d02016-03-08 22:25:52 -070065
66
67// Android specific helper functions for shaderc.
68struct shader_type_mapping {
69 VkShaderStageFlagBits vkshader_type;
70 shaderc_shader_kind shaderc_type;
71};
72
73static const shader_type_mapping shader_map_table[] = {
74 {
75 VK_SHADER_STAGE_VERTEX_BIT,
76 shaderc_glsl_vertex_shader
77 },
78 {
79 VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
80 shaderc_glsl_tess_control_shader
81 },
82 {
83 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
84 shaderc_glsl_tess_evaluation_shader
85 },
86 {
87 VK_SHADER_STAGE_GEOMETRY_BIT,
88 shaderc_glsl_geometry_shader
89 },
90 {
91 VK_SHADER_STAGE_FRAGMENT_BIT,
92 shaderc_glsl_fragment_shader
93 },
94 {
95 VK_SHADER_STAGE_COMPUTE_BIT,
96 shaderc_glsl_compute_shader
97 },
98};
99
100shaderc_shader_kind MapShadercType(VkShaderStageFlagBits vkShader) {
101 for (auto shader : shader_map_table) {
102 if (shader.vkshader_type == vkShader) {
103 return shader.shaderc_type;
104 }
105 }
106 assert(false);
107 return shaderc_glsl_infer_from_source;
108}
109
110// Compile a given string containing GLSL into SPIR-V
111// Return value of false means an error was encountered
112bool VkTestFramework::GLSLtoSPV(const VkShaderStageFlagBits shader_type,
113 const char *pshader,
114 std::vector<unsigned int> &spirv) {
115
116 // On Android, use shaderc instead.
117 shaderc::Compiler compiler;
118 shaderc::SpvCompilationResult result = compiler.CompileGlslToSpv(pshader, strlen(pshader),
119 MapShadercType(shader_type),
120 "shader");
121 if (result.GetCompilationStatus() != shaderc_compilation_status_success) {
122 __android_log_print(ANDROID_LOG_ERROR,
123 "VkLayerValidationTest",
124 "GLSLtoSPV compilation failed");
125 return false;
126 }
127
128 for (auto iter = result.begin(); iter != result.end(); iter++) {
129 spirv.push_back(*iter);
130 }
131
132 return true;
133}