blob: df9c5a0e9ab90c39a7c4dc0a6656ff2db5daa4c7 [file] [log] [blame]
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06001// Copyright 2005, Google Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14// * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060031// VK tests
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060032//
33// Copyright (C) 2014 LunarG, Inc.
34//
35// Permission is hereby granted, free of charge, to any person obtaining a
36// copy of this software and associated documentation files (the "Software"),
37// to deal in the Software without restriction, including without limitation
38// the rights to use, copy, modify, merge, publish, distribute, sublicense,
39// and/or sell copies of the Software, and to permit persons to whom the
40// Software is furnished to do so, subject to the following conditions:
41//
42// The above copyright notice and this permission notice shall be included
43// in all copies or substantial portions of the Software.
44//
45// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
48// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
49// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
50// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
51// DEALINGS IN THE SOFTWARE.
52
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060053// Basic rendering tests
54
55#include <stdlib.h>
56#include <stdio.h>
57#include <stdbool.h>
58#include <string.h>
Courtney Goeltzenleuchterda91b952014-08-21 17:34:22 -060059#include <iostream>
60#include <fstream>
61using namespace std;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060062
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060063#include <vulkan.h>
Tobin Ehlis11e52132014-11-28 11:17:19 -070064#ifdef DUMP_STATE_DOT
65#include "../layers/draw_state.h"
66#endif
Tobin Ehlisca915872014-11-18 11:28:33 -070067#ifdef PRINT_OBJECTS
68#include "../layers/object_track.h"
69#endif
Tobin Ehlis6663f492014-11-10 12:29:12 -070070#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060071#include <vk_debug_report_lunarg.h>
Tobin Ehlis6663f492014-11-10 12:29:12 -070072#endif
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060073#include "gtest-1.7.0/include/gtest/gtest.h"
74
Cody Northrop054a4702015-03-17 14:54:35 -060075#include "icd-spv.h"
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060076
Courtney Goeltzenleuchterfdcfb9f2014-10-10 18:04:39 -060077#define GLM_FORCE_RADIANS
78#include "glm/glm.hpp"
79#include <glm/gtc/matrix_transform.hpp>
80
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060081#include "vkrenderframework.h"
Tobin Ehlis6663f492014-11-10 12:29:12 -070082#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060083void VKAPI myDbgFunc(
84 VK_DBG_MSG_TYPE msgType,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060085 VkValidationLevel validationLevel,
Mike Stroyanb050c682015-04-17 12:36:38 -060086 VkObject srcObject,
Mark Lobodzinski17caf572015-01-29 08:55:56 -060087 size_t location,
88 int32_t msgCode,
89 const char* pMsg,
90 void* pUserData)
Tobin Ehlis6663f492014-11-10 12:29:12 -070091{
Tobin Ehlisca915872014-11-18 11:28:33 -070092 switch (msgType)
93 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060094 case VK_DBG_MSG_WARNING:
Tobin Ehlisca915872014-11-18 11:28:33 -070095 printf("CALLBACK WARNING : %s\n", pMsg);
96 break;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060097 case VK_DBG_REPORT_ERROR_BIT:
Tobin Ehlisca915872014-11-18 11:28:33 -070098 printf("CALLBACK ERROR : %s\n", pMsg);
99 break;
100 default:
101 printf("EATING Msg of type %u\n", msgType);
102 break;
103 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700104}
105#endif
Tony Barboure2c58df2014-11-25 13:18:32 -0700106
107
108#undef ASSERT_NO_FATAL_FAILURE
109#define ASSERT_NO_FATAL_FAILURE(x) x
110
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600111//--------------------------------------------------------------------------------------
112// Mesh and VertexFormat Data
113//--------------------------------------------------------------------------------------
114struct Vertex
115{
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600116 float posX, posY, posZ, posW; // Position data
117 float r, g, b, a; // Color
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600118};
119
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600120struct VertexUV
121{
122 float posX, posY, posZ, posW; // Position data
123 float u, v; // texture u,v
124};
125
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600126#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600127#define UV(_u_, _v_) (_u_), (_v_)
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600128
129static const Vertex g_vbData[] =
130{
131 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
132 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
133 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
134 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
135 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
136 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
137
138 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
139 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
140 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
141 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
142 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
143 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
144
145 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
146 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
147 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
148 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
149 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
150 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
151
152 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
153 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
154 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
155 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
156 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
157 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
158
159 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
160 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
161 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
162 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
163 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
164 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
165
166 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
167 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
168 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
169 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
170 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
171 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
172};
173
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600174static const Vertex g_vb_solid_face_colors_Data[] =
175{
176 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600177 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600178 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
179 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600180 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
181 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600182
183 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
184 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600185 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
186 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600187 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600188 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600189
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600190 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
191 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
192 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
193 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
194 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
195 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600196
197 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
198 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
199 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
200 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
201 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
202 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
203
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600204 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600205 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600206 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
207 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600208 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
209 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
210
211 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
212 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
213 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
214 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
215 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
216 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
217};
218
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600219static const VertexUV g_vb_texture_Data[] =
220{
221 { XYZ1( -1, -1, -1 ), UV( 0.f, 0.f ) },
222 { XYZ1( -1, 1, 1 ), UV( 1.f, 1.f ) },
223 { XYZ1( -1, -1, 1 ), UV( 1.f, 0.f ) },
224 { XYZ1( -1, 1, 1 ), UV( 1.f, 1.f ) },
225 { XYZ1( -1, -1, -1 ), UV( 0.f, 0.f ) },
226 { XYZ1( -1, 1, -1 ), UV( 0.f, 1.f ) },
227
228 { XYZ1( -1, -1, -1 ), UV( 1.f, 0.f ) },
229 { XYZ1( 1, -1, -1 ), UV( 0.f, 0.f ) },
230 { XYZ1( 1, 1, -1 ), UV( 0.f, 1.f ) },
231 { XYZ1( -1, -1, -1 ), UV( 1.f, 0.f ) },
232 { XYZ1( 1, 1, -1 ), UV( 0.f, 1.f ) },
233 { XYZ1( -1, 1, -1 ), UV( 1.f, 1.f ) },
234
235 { XYZ1( -1, -1, -1 ), UV( 1.f, 1.f ) },
236 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
237 { XYZ1( 1, -1, -1 ), UV( 1.f, 0.f ) },
238 { XYZ1( -1, -1, -1 ), UV( 1.f, 1.f ) },
239 { XYZ1( -1, -1, 1 ), UV( 0.f, 1.f ) },
240 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
241
242 { XYZ1( -1, 1, -1 ), UV( 1.f, 1.f ) },
243 { XYZ1( 1, 1, 1 ), UV( 0.f, 0.f ) },
244 { XYZ1( -1, 1, 1 ), UV( 0.f, 1.f ) },
245 { XYZ1( -1, 1, -1 ), UV( 1.f, 1.f ) },
246 { XYZ1( 1, 1, -1 ), UV( 1.f, 0.f ) },
247 { XYZ1( 1, 1, 1 ), UV( 0.f, 0.f ) },
248
249 { XYZ1( 1, 1, -1 ), UV( 1.f, 1.f ) },
250 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
251 { XYZ1( 1, 1, 1 ), UV( 0.f, 1.f ) },
252 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
253 { XYZ1( 1, 1, -1 ), UV( 1.f, 1.f ) },
254 { XYZ1( 1, -1, -1 ), UV( 1.f, 0.f ) },
255
256 { XYZ1( -1, 1, 1 ), UV( 0.f, 1.f ) },
257 { XYZ1( 1, 1, 1 ), UV( 1.f, 1.f ) },
258 { XYZ1( -1, -1, 1 ), UV( 0.f, 0.f ) },
259 { XYZ1( -1, -1, 1 ), UV( 0.f, 0.f ) },
260 { XYZ1( 1, 1, 1 ), UV( 1.f, 1.f ) },
261 { XYZ1( 1, -1, 1 ), UV( 1.f, 0.f ) },
262};
263
Tony Barbour6918cd52015-04-09 12:58:51 -0600264class VkRenderTest : public VkRenderFramework
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -0600265{
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600266public:
Cody Northrop7ad4aaf2014-10-09 21:25:22 -0600267
Tony Barboure2c58df2014-11-25 13:18:32 -0700268 void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbour6918cd52015-04-09 12:58:51 -0600269 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer);
270 void GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600271 void InitDepthStencil();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600272 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate);
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600273
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600274 VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer);
275 VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer);
Cody Northropee6586d2014-10-09 19:55:56 -0600276
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600277protected:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600278 VkImage m_texture;
279 VkImageView m_textureView;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800280 VkDescriptorInfo m_descriptorInfo;
Tony Barbourd1c35722015-04-16 15:59:00 -0600281 VkDeviceMemory m_textureMem;
Cody Northrop7d2035d2014-10-06 15:42:00 -0600282
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600283 VkSampler m_sampler;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600284
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600285
286 virtual void SetUp() {
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600287
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600288 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600289 this->app_info.pNext = NULL;
Chia-I Wuf1a5a742014-12-27 15:16:07 +0800290 this->app_info.pAppName = "render_tests";
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600291 this->app_info.appVersion = 1;
Chia-I Wuf1a5a742014-12-27 15:16:07 +0800292 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600293 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600294 this->app_info.apiVersion = VK_API_VERSION;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600295
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800296 memset(&m_descriptorInfo, 0, sizeof(m_descriptorInfo));
Cody Northrop7d2035d2014-10-06 15:42:00 -0600297
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600298 InitFramework();
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600299 }
300
301 virtual void TearDown() {
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600302 // Clean up resources before we reset
303 ShutdownFramework();
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600304 }
305};
306
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600307VkResult VkRenderTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600308{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600309 VkResult result;
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600310
311 result = cmdBuffer.BeginCommandBuffer();
312
313 /*
314 * For render test all drawing happens in a single render pass
315 * on a single command buffer.
316 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200317 if (VK_SUCCESS == result && renderPass()) {
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600318 cmdBuffer.BeginRenderPass(renderPass(), framebuffer());
319 }
320
321 return result;
322}
323
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600324VkResult VkRenderTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600325{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600326 VkResult result;
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600327
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200328 if (renderPass()) {
329 cmdBuffer.EndRenderPass(renderPass());
330 }
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600331
332 result = cmdBuffer.EndCommandBuffer();
333
334 return result;
335}
336
337
Tony Barbour6918cd52015-04-09 12:58:51 -0600338void VkRenderTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet)
Tony Barbour22e32a12015-01-08 17:08:28 -0700339{
Tony Barbour1c45ce02015-03-27 17:03:18 -0600340 if (m_depthStencil->Initialized()) {
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600341 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Tony Barbour1c45ce02015-03-27 17:03:18 -0600342 } else {
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600343 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour1c45ce02015-03-27 17:03:18 -0600344 }
345
Jeremy Hayesd65ae082015-01-14 16:17:08 -0700346 cmdBuffer->PrepareAttachments();
Tony Barbourd1c35722015-04-16 15:59:00 -0600347 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_RASTER, m_stateRaster);
348 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_VIEWPORT, m_stateViewport);
349 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_COLOR_BLEND, m_colorBlend);
350 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_DEPTH_STENCIL, m_stateDepthStencil);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600351 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
352 pipelineobj.CreateVKPipeline(descriptorSet);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600353 cmdBuffer->BindPipeline(pipelineobj);
Chia-I Wu53f07d72015-03-28 15:23:55 +0800354 cmdBuffer->BindDescriptorSet(descriptorSet);
Tony Barbour22e32a12015-01-08 17:08:28 -0700355}
Tony Barboure2c58df2014-11-25 13:18:32 -0700356
Tony Barbour6918cd52015-04-09 12:58:51 -0600357void VkRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
358 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer)
Tony Barbour664accc2015-01-09 12:55:14 -0700359{
360 int i;
361 glm::mat4 MVP;
362 int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600363 VkResult err;
Tony Barbour664accc2015-01-09 12:55:14 -0700364
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600365 /* Only do 3 positions to avoid back face cull */
366 for (i = 0; i < 3; i++) {
Tony Barbour664accc2015-01-09 12:55:14 -0700367 void *pData = constantBuffer->map();
368
369 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
370 MVP = Projection * View * Model;
371 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
372
373 constantBuffer->unmap();
374
375 // submit the command buffer to the universal queue
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600376 cmdBuffer->QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -0700377
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600378 err = vkQueueWaitIdle( m_device->m_queue );
379 ASSERT_VK_SUCCESS( err );
Tony Barbour664accc2015-01-09 12:55:14 -0700380
381 // Wait for work to finish before cleaning up.
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600382 vkDeviceWaitIdle(m_device->device());
Tony Barbour664accc2015-01-09 12:55:14 -0700383
Courtney Goeltzenleuchterb4337c12015-03-05 16:47:18 -0700384 assert(m_renderTargets.size() == 1);
Tony Barbour664accc2015-01-09 12:55:14 -0700385 RecordImage(m_renderTargets[0]);
386 }
387}
Courtney Goeltzenleuchterc55471f2014-10-13 13:03:31 -0600388
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600389void dumpMatrix(const char *note, glm::mat4 MVP)
390{
Chia-I Wu6f184292014-12-15 23:57:34 +0800391 int i;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600392
393 printf("%s: \n", note);
394 for (i=0; i<4; i++) {
395 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
396 }
397 printf("\n");
398 fflush(stdout);
399}
400
401void dumpVec4(const char *note, glm::vec4 vector)
402{
403 printf("%s: \n", note);
404 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
405 printf("\n");
406 fflush(stdout);
407}
408
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600409struct vktriangle_vs_uniform {
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600410 // Must start with MVP
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600411 float mvp[4][4];
412 float position[3][4];
413 float color[3][4];
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600414};
415
Tony Barbour6918cd52015-04-09 12:58:51 -0600416void VkRenderTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600417{
Tobin Ehlis6663f492014-11-10 12:29:12 -0700418#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600419 vkDbgRegisterMsgCallback(inst, myDbgFunc, NULL);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700420#endif
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600421 // Create identity matrix
422 int i;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600423 struct vktriangle_vs_uniform data;
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600424
425 glm::mat4 Projection = glm::mat4(1.0f);
426 glm::mat4 View = glm::mat4(1.0f);
427 glm::mat4 Model = glm::mat4(1.0f);
428 glm::mat4 MVP = Projection * View * Model;
429 const int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600430 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600431 memcpy(&data.mvp, &MVP[0][0], matrixSize);
432
433 static const Vertex tri_data[] =
434 {
435 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
436 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
437 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
438 };
439
440 for (i=0; i<3; i++) {
441 data.position[i][0] = tri_data[i].posX;
442 data.position[i][1] = tri_data[i].posY;
443 data.position[i][2] = tri_data[i].posZ;
444 data.position[i][3] = tri_data[i].posW;
445 data.color[i][0] = tri_data[i].r;
446 data.color[i][1] = tri_data[i].g;
447 data.color[i][2] = tri_data[i].b;
448 data.color[i][3] = tri_data[i].a;
449 }
450
Tony Barboure2c58df2014-11-25 13:18:32 -0700451 ASSERT_NO_FATAL_FAILURE(InitState());
452 ASSERT_NO_FATAL_FAILURE(InitViewport());
453
Tony Barbour6918cd52015-04-09 12:58:51 -0600454 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barboure2c58df2014-11-25 13:18:32 -0700455
Tony Barbour6918cd52015-04-09 12:58:51 -0600456 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
457 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -0700458
Tony Barbour6918cd52015-04-09 12:58:51 -0600459 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -0700460 pipelineobj.AddShader(&vs);
461 pipelineobj.AddShader(&ps);
462
Tony Barbour6918cd52015-04-09 12:58:51 -0600463 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600464 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -0700465
Tony Barbourd726a172015-01-09 16:12:35 -0700466 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -0600467 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourd726a172015-01-09 16:12:35 -0700468 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -0700469
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600470 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourd726a172015-01-09 16:12:35 -0700471
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600472 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourd726a172015-01-09 16:12:35 -0700473#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600474 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourd726a172015-01-09 16:12:35 -0700475 pDSDumpDot((char*)"triTest2.dot");
476#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600477
Tony Barbourd726a172015-01-09 16:12:35 -0700478 // render triangle
479 cmdBuffer.Draw(0, 3, 0, 1);
480
481 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600482 EndCommandBuffer(cmdBuffer);
483
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600484 cmdBuffer.QueueCommandBuffer();
Tony Barbourd726a172015-01-09 16:12:35 -0700485
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600486 RecordImages(m_renderTargets);
Tony Barbourd726a172015-01-09 16:12:35 -0700487
488 if (rotate)
Tobin Ehlis976fc162015-03-26 08:23:25 -0600489 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
Tony Barbourd726a172015-01-09 16:12:35 -0700490
Tobin Ehlisca915872014-11-18 11:28:33 -0700491#ifdef PRINT_OBJECTS
Mark Lobodzinski7c75b852015-05-05 15:01:37 -0500492 //uint64_t objTrackGetObjectCount(VkObjectType type)
493 OBJ_TRACK_GET_OBJECTS_COUNT pObjTrackGetObjectsCount = (OBJ_TRACK_GET_OBJECTS_COUNT)vkGetProcAddr(gpu(), (char*)"objTrackGetObjectsCount");
494 uint64_t numObjects = pObjTrackGetObjectsCount();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600495 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlisca915872014-11-18 11:28:33 -0700496 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600497 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlisca915872014-11-18 11:28:33 -0700498 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
Mark Lobodzinski7c75b852015-05-05 15:01:37 -0500499 pObjTrackGetObjs(numObjects, pObjNodeArray);
Tobin Ehlisca915872014-11-18 11:28:33 -0700500 for (i=0; i < numObjects; i++) {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600501 printf("Object %i of type %s has objID (%p) and %lu uses\n", i, string_VkObjectType(pObjNodeArray[i].objType), pObjNodeArray[i].pObj, pObjNodeArray[i].numUses);
Tobin Ehlisca915872014-11-18 11:28:33 -0700502 }
503 free(pObjNodeArray);
504#endif
Tony Barboure2c58df2014-11-25 13:18:32 -0700505
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600506}
507
Tony Barbour6918cd52015-04-09 12:58:51 -0600508TEST_F(VkRenderTest, VKTriangle_FragColor)
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600509{
510 static const char *vertShaderText =
511 "#version 140\n"
512 "#extension GL_ARB_separate_shader_objects : enable\n"
513 "#extension GL_ARB_shading_language_420pack : enable\n"
514 "\n"
515 "layout(binding = 0) uniform buf {\n"
516 " mat4 MVP;\n"
517 " vec4 position[3];\n"
518 " vec4 color[3];\n"
519 "} ubuf;\n"
520 "\n"
521 "layout (location = 0) out vec4 outColor;\n"
522 "\n"
523 "void main() \n"
524 "{\n"
525 " outColor = ubuf.color[gl_VertexID];\n"
526 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
527 "}\n";
528
529 static const char *fragShaderText =
530 "#version 140\n"
531 "#extension GL_ARB_separate_shader_objects : enable\n"
532 "#extension GL_ARB_shading_language_420pack : enable\n"
533 "\n"
534 "layout (location = 0) in vec4 inColor;\n"
GregFaae75242015-06-03 18:40:50 -0600535 "layout (location = 0) out vec4 uFragColor;\n"
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600536 "\n"
537 "void main()\n"
538 "{\n"
GregFaae75242015-06-03 18:40:50 -0600539 " uFragColor = inColor;\n"
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600540 "}\n";
541
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600542 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
543 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600544}
545
Tony Barbour6918cd52015-04-09 12:58:51 -0600546TEST_F(VkRenderTest, VKTriangle_OutputLocation)
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600547{
548 static const char *vertShaderText =
549 "#version 140\n"
550 "#extension GL_ARB_separate_shader_objects : enable\n"
551 "#extension GL_ARB_shading_language_420pack : enable\n"
552 "\n"
553 "layout(binding = 0) uniform buf {\n"
554 " mat4 MVP;\n"
555 " vec4 position[3];\n"
556 " vec4 color[3];\n"
557 "} ubuf;\n"
558 "\n"
559 "layout (location = 0) out vec4 outColor;\n"
560 "\n"
561 "void main() \n"
562 "{\n"
563 " outColor = ubuf.color[gl_VertexID];\n"
564 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
565 "}\n";
566
567 static const char *fragShaderText =
568 "#version 140\n"
569 "#extension GL_ARB_separate_shader_objects : enable\n"
570 "#extension GL_ARB_shading_language_420pack : enable\n"
571 "\n"
572 "layout (location = 0) in vec4 inColor;\n"
573 "layout (location = 0) out vec4 outColor;\n"
574 "\n"
575 "void main()\n"
576 "{\n"
577 " outColor = inColor;\n"
578 "}\n";
579
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600580 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to output location 0, which should be the same as gl_FragColor");
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600581
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600582 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600583}
Tony Barbour0dd968a2015-04-02 15:48:24 -0600584#ifndef _WIN32 // Implicit (for now at least) in WIN32 is that we are using the Nvidia driver and it won't consume SPIRV yet
Tony Barbour6918cd52015-04-09 12:58:51 -0600585TEST_F(VkRenderTest, SPV_VKTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -0700586{
Tony Barboure2c58df2014-11-25 13:18:32 -0700587 static const char *vertShaderText =
588 "#version 140\n"
589 "#extension GL_ARB_separate_shader_objects : enable\n"
590 "#extension GL_ARB_shading_language_420pack : enable\n"
591 "\n"
592 "layout(binding = 0) uniform buf {\n"
593 " mat4 MVP;\n"
594 " vec4 position[3];\n"
595 " vec4 color[3];\n"
596 "} ubuf;\n"
597 "\n"
598 "layout (location = 0) out vec4 outColor;\n"
599 "\n"
600 "void main() \n"
601 "{\n"
602 " outColor = ubuf.color[gl_VertexID];\n"
603 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
604 "}\n";
605
606 static const char *fragShaderText =
607 "#version 140\n"
608 "#extension GL_ARB_separate_shader_objects : enable\n"
609 "#extension GL_ARB_shading_language_420pack : enable\n"
610 "\n"
611 "layout (location = 0) in vec4 inColor;\n"
GregFaae75242015-06-03 18:40:50 -0600612 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700613 "\n"
614 "void main()\n"
615 "{\n"
GregFaae75242015-06-03 18:40:50 -0600616 " outColor = inColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700617 "}\n";
618
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600619 TEST_DESCRIPTION("VK-style shaders, but force test framework to compile shader to SPV and pass SPV to driver.");
Tony Barboure2c58df2014-11-25 13:18:32 -0700620
Cody Northrop50a2a4b2015-06-03 16:49:20 -0600621 ScopedUseGlsl useGlsl(false);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600622 VKTriangleTest(vertShaderText, fragShaderText, true);
Tony Barboure2c58df2014-11-25 13:18:32 -0700623}
Tony Barbour0dd968a2015-04-02 15:48:24 -0600624#endif
Tony Barbour6918cd52015-04-09 12:58:51 -0600625TEST_F(VkRenderTest, GreenTriangle)
Cody Northropd1a256b2014-10-09 21:26:47 -0600626{
627 static const char *vertShaderText =
628 "#version 130\n"
629 "vec2 vertices[3];\n"
630 "void main() {\n"
631 " vertices[0] = vec2(-1.0, -1.0);\n"
632 " vertices[1] = vec2( 1.0, -1.0);\n"
633 " vertices[2] = vec2( 0.0, 1.0);\n"
634 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
635 "}\n";
Courtney Goeltzenleuchter538062a2014-10-09 15:40:19 -0600636
Cody Northropd1a256b2014-10-09 21:26:47 -0600637 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -0600638 "#version 140\n"
639 "#extension GL_ARB_separate_shader_objects : enable\n"
640 "#extension GL_ARB_shading_language_420pack : enable\n"
641 "layout (location = 0) out vec4 outColor;\n"
Cody Northropd1a256b2014-10-09 21:26:47 -0600642 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600643 " outColor = vec4(0,1,0,1);\n"
Cody Northropd1a256b2014-10-09 21:26:47 -0600644 "}\n";
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600645
Courtney Goeltzenleuchter9fb62492014-10-27 13:09:23 -0600646 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
647
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600648 VKTriangleTest(vertShaderText, fragShaderText, false);
Cody Northropd1a256b2014-10-09 21:26:47 -0600649}
Tony Barbour0dd968a2015-04-02 15:48:24 -0600650#ifndef _WIN32 // Implicit (for now at least) in WIN32 is that we are using the Nvidia driver and it won't consume SPIRV yet
Tony Barbour6918cd52015-04-09 12:58:51 -0600651TEST_F(VkRenderTest, SPV_GreenTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -0700652{
Tony Barboure2c58df2014-11-25 13:18:32 -0700653 static const char *vertShaderText =
654 "#version 130\n"
655 "vec2 vertices[3];\n"
656 "void main() {\n"
657 " vertices[0] = vec2(-1.0, -1.0);\n"
658 " vertices[1] = vec2( 1.0, -1.0);\n"
659 " vertices[2] = vec2( 0.0, 1.0);\n"
660 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
661 "}\n";
662
663 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -0600664 "#version 140\n"
665 "#extension GL_ARB_separate_shader_objects : enable\n"
666 "#extension GL_ARB_shading_language_420pack : enable\n"
667 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700668 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600669 " outColor = vec4(0,1,0,1);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700670 "}\n";
671
Cody Northrop3bfd27c2015-03-17 15:55:58 -0600672 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barboure2c58df2014-11-25 13:18:32 -0700673
Cody Northrop50a2a4b2015-06-03 16:49:20 -0600674 ScopedUseGlsl useGlsl(false);
675
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600676 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barboure2c58df2014-11-25 13:18:32 -0700677}
Tony Barbour0dd968a2015-04-02 15:48:24 -0600678#endif
Tony Barbour6918cd52015-04-09 12:58:51 -0600679TEST_F(VkRenderTest, YellowTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -0700680{
681 static const char *vertShaderText =
682 "#version 130\n"
683 "void main() {\n"
684 " vec2 vertices[3];"
685 " vertices[0] = vec2(-0.5, -0.5);\n"
686 " vertices[1] = vec2( 0.5, -0.5);\n"
687 " vertices[2] = vec2( 0.5, 0.5);\n"
688 " vec4 colors[3];\n"
689 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
690 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
691 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
692 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
693 "}\n";
694
695 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -0600696 "#version 140\n"
697 "#extension GL_ARB_separate_shader_objects : enable\n"
698 "#extension GL_ARB_shading_language_420pack : enable\n"
699 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700700 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600701 " outColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700702 "}\n";
703
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600704 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barboure2c58df2014-11-25 13:18:32 -0700705}
706
Tony Barbour6918cd52015-04-09 12:58:51 -0600707TEST_F(VkRenderTest, QuadWithVertexFetch)
Cody Northropee6586d2014-10-09 19:55:56 -0600708{
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600709 static const char *vertShaderText =
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600710 "#version 140\n"
711 "#extension GL_ARB_separate_shader_objects : enable\n"
712 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700713 //XYZ1( -1, -1, -1 )
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600714 "layout (location = 0) in vec4 pos;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700715 //XYZ1( 0.f, 0.f, 0.f )
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600716 "layout (location = 1) in vec4 inColor;\n"
717 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600718 "void main() {\n"
Cody Northrop66594a72014-10-10 14:49:36 -0600719 " outColor = inColor;\n"
Cody Northrop7ad4aaf2014-10-09 21:25:22 -0600720 " gl_Position = pos;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600721 "}\n";
722
Cody Northropee6586d2014-10-09 19:55:56 -0600723
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600724 static const char *fragShaderText =
Cody Northropd43c52e2014-12-05 15:44:14 -0700725 "#version 140\n"
726 "#extension GL_ARB_separate_shader_objects : enable\n"
727 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600728 "layout (location = 0) in vec4 color;\n"
Cody Northropd43c52e2014-12-05 15:44:14 -0700729 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600730 "void main() {\n"
Cody Northropd43c52e2014-12-05 15:44:14 -0700731 " outColor = color;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600732 "}\n";
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600733
Tony Barboure2c58df2014-11-25 13:18:32 -0700734
735
736 ASSERT_NO_FATAL_FAILURE(InitState());
737 ASSERT_NO_FATAL_FAILURE(InitViewport());
738
Tony Barbour6918cd52015-04-09 12:58:51 -0600739 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000740 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -0700741
Tony Barbour6918cd52015-04-09 12:58:51 -0600742 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
743 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -0700744
Tony Barbour6918cd52015-04-09 12:58:51 -0600745 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -0700746 pipelineobj.AddShader(&vs);
747 pipelineobj.AddShader(&ps);
748
Tony Barbour6918cd52015-04-09 12:58:51 -0600749 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600750 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -0600751
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600752#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600753 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600754 MESH_BIND_ID, // binding ID
Tony Barboure2c58df2014-11-25 13:18:32 -0700755 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600756 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barboure2c58df2014-11-25 13:18:32 -0700757 };
758
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600759 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600760 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
761 vi_attribs[0].location = 0; // location, position
Tony Barbourd1c35722015-04-16 15:59:00 -0600762 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600763 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
764 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
765 vi_attribs[1].location = 1; // location, color
Tony Barbourd1c35722015-04-16 15:59:00 -0600766 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600767 vi_attribs[1].offsetInBytes = 1*sizeof(float)*4; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -0700768
769 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
770 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600771 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barboure2c58df2014-11-25 13:18:32 -0700772
Tony Barbour1fde6942015-01-09 10:06:53 -0700773 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -0600774 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1fde6942015-01-09 10:06:53 -0700775 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -0700776
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600777 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600778
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600779 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour1fde6942015-01-09 10:06:53 -0700780
Tony Barbour1fde6942015-01-09 10:06:53 -0700781 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
782
783 // render two triangles
784 cmdBuffer.Draw(0, 6, 0, 1);
785
786 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600787 EndCommandBuffer(cmdBuffer);
788
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600789 cmdBuffer.QueueCommandBuffer();
Tony Barbour1fde6942015-01-09 10:06:53 -0700790
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600791 RecordImages(m_renderTargets);
Tobin Ehlisd806c8e2014-10-07 14:41:29 -0600792}
793
Tony Barbour6918cd52015-04-09 12:58:51 -0600794TEST_F(VkRenderTest, TriangleMRT)
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800795{
796 static const char *vertShaderText =
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600797 "#version 140\n"
798 "#extension GL_ARB_separate_shader_objects : enable\n"
799 "#extension GL_ARB_shading_language_420pack : enable\n"
800 "layout (location = 0) in vec4 pos;\n"
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800801 "void main() {\n"
802 " gl_Position = pos;\n"
803 "}\n";
804
805 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -0600806 "#version 140\n"
807 "#extension GL_ARB_separate_shader_objects : enable\n"
808 "#extension GL_ARB_shading_language_420pack : enable\n"
809 "layout (location = 0) out vec4 uFragData0;\n"
810 "layout (location = 1) out vec4 uFragData1;\n"
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800811 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600812 " uFragData0 = vec4(1.0, 0.0, 0.0, 1.0);\n"
813 " uFragData1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800814 "}\n";
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600815 const float vb_data[][2] = {
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800816 { -1.0f, -1.0f },
817 { 1.0f, -1.0f },
818 { -1.0f, 1.0f }
819 };
820
821 ASSERT_NO_FATAL_FAILURE(InitState());
822 ASSERT_NO_FATAL_FAILURE(InitViewport());
823
Tony Barbour6918cd52015-04-09 12:58:51 -0600824 VkConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000825 meshBuffer.BufferMemoryBarrier();
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800826
Tony Barbour6918cd52015-04-09 12:58:51 -0600827 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
828 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800829
Tony Barbour6918cd52015-04-09 12:58:51 -0600830 VkPipelineObj pipelineobj(m_device);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800831 pipelineobj.AddShader(&vs);
832 pipelineobj.AddShader(&ps);
833
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600834#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600835 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600836 MESH_BUF_ID, // Binding ID
837 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600838 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800839 };
840
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600841 VkVertexInputAttributeDescription vi_attrib;
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600842 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
843 vi_attrib.location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -0600844 vi_attrib.format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600845 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800846
847 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
848 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600849 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800850
Tony Barbour6918cd52015-04-09 12:58:51 -0600851 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600852 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800853
Courtney Goeltzenleuchterb4337c12015-03-05 16:47:18 -0700854 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800855
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600856 VkPipelineCbAttachmentState att = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600857 att.blendEnable = VK_FALSE;
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800858 att.format = m_render_target_fmt;
859 att.channelWriteMask = 0xf;
Tony Barbourf52346d2015-01-16 14:27:35 -0700860 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800861
Tony Barbour6918cd52015-04-09 12:58:51 -0600862 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1fde6942015-01-09 10:06:53 -0700863
Tony Barbour304ec8b2015-01-07 14:31:52 -0700864 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
865 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barbour1fde6942015-01-09 10:06:53 -0700866
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600867 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour304ec8b2015-01-07 14:31:52 -0700868
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600869 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour1fde6942015-01-09 10:06:53 -0700870
Tony Barbour304ec8b2015-01-07 14:31:52 -0700871 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour304ec8b2015-01-07 14:31:52 -0700872#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600873 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour304ec8b2015-01-07 14:31:52 -0700874 pDSDumpDot((char*)"triTest2.dot");
875#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600876
Tony Barbour304ec8b2015-01-07 14:31:52 -0700877 // render triangle
878 cmdBuffer.Draw(0, 3, 0, 1);
879
880 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600881 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600882 cmdBuffer.QueueCommandBuffer();
Tony Barbour304ec8b2015-01-07 14:31:52 -0700883
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600884 RecordImages(m_renderTargets);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800885}
886
Tony Barbour6918cd52015-04-09 12:58:51 -0600887TEST_F(VkRenderTest, QuadWithIndexedVertexFetch)
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700888{
889 static const char *vertShaderText =
890 "#version 140\n"
891 "#extension GL_ARB_separate_shader_objects : enable\n"
892 "#extension GL_ARB_shading_language_420pack : enable\n"
893 "layout(location = 0) in vec4 pos;\n"
894 "layout(location = 1) in vec4 inColor;\n"
895 "layout(location = 0) out vec4 outColor;\n"
896 "void main() {\n"
897 " outColor = inColor;\n"
898 " gl_Position = pos;\n"
899 "}\n";
900
901
902 static const char *fragShaderText =
903 "#version 140\n"
904 "#extension GL_ARB_separate_shader_objects : enable\n"
905 "#extension GL_ARB_shading_language_420pack : enable\n"
906 "layout(location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -0600907 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700908 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600909 " outColor = color;\n"
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700910 "}\n";
911
912 const Vertex g_vbData[] =
913 {
914 // first tri
915 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
916 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
917 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
918
919 // second tri
920 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
921 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
922 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
923 };
924
925 const uint16_t g_idxData[6] = {
926 0, 1, 2,
927 3, 4, 5,
928 };
929
930 ASSERT_NO_FATAL_FAILURE(InitState());
931 ASSERT_NO_FATAL_FAILURE(InitViewport());
932
Tony Barbour6918cd52015-04-09 12:58:51 -0600933 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000934 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700935
Tony Barbour6918cd52015-04-09 12:58:51 -0600936 VkIndexBufferObj indexBuffer(m_device);
Tony Barbourd1c35722015-04-16 15:59:00 -0600937 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), VK_INDEX_TYPE_UINT16, g_idxData);
Mark Lobodzinski49a6b4b2015-02-16 14:24:23 -0600938 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700939
Tony Barbour6918cd52015-04-09 12:58:51 -0600940 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
941 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700942
Tony Barbour6918cd52015-04-09 12:58:51 -0600943 VkPipelineObj pipelineobj(m_device);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700944 pipelineobj.AddShader(&vs);
945 pipelineobj.AddShader(&ps);
946
Tony Barbour6918cd52015-04-09 12:58:51 -0600947 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600948 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
949 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, indexBuffer);
Tony Barbour831062d2015-04-02 15:43:15 -0600950
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700951
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600952#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600953 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600954 MESH_BIND_ID, // binding ID
955 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600956 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700957 };
958
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600959 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600960 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
961 vi_attribs[0].location = 0; // layout location of vertex attribute
Tony Barbourd1c35722015-04-16 15:59:00 -0600962 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600963 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
964 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
965 vi_attribs[1].location = 1; // layout location of vertex attribute
Tony Barbourd1c35722015-04-16 15:59:00 -0600966 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600967 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700968
969 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
970 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700971
972 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -0600973 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourad8f1542014-12-17 11:16:05 -0700974 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600975 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour1fde6942015-01-09 10:06:53 -0700976
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600977 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700978
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700979#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600980 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlisf27eba72014-12-16 17:34:50 -0700981 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700982#endif
Tony Barbour22e32a12015-01-08 17:08:28 -0700983
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600984 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600985 cmdBuffer.BindIndexBuffer(&indexBuffer, 0);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700986
987 // render two triangles
Tony Barbourad8f1542014-12-17 11:16:05 -0700988 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700989
990 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600991 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600992 cmdBuffer.QueueCommandBuffer();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700993
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600994 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700995}
996
Tony Barbour6918cd52015-04-09 12:58:51 -0600997TEST_F(VkRenderTest, GreyandRedCirclesonBlue)
GregF3156cb02014-12-02 15:41:44 -0700998{
999 // This tests gl_FragCoord
Tony Barboure2c58df2014-11-25 13:18:32 -07001000
GregF3156cb02014-12-02 15:41:44 -07001001 static const char *vertShaderText =
1002 "#version 140\n"
1003 "#extension GL_ARB_separate_shader_objects : enable\n"
1004 "#extension GL_ARB_shading_language_420pack : enable\n"
1005 "layout (location = 0) in vec4 pos;\n"
1006 "layout (location = 0) out vec4 outColor;\n"
1007 "layout (location = 1) out vec4 outColor2;\n"
1008 "void main() {\n"
1009 " gl_Position = pos;\n"
1010 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1011 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1012 "}\n";
1013
1014 static const char *fragShaderText =
GregF3156cb02014-12-02 15:41:44 -07001015 "#version 330\n"
1016 "#extension GL_ARB_separate_shader_objects : enable\n"
1017 "#extension GL_ARB_shading_language_420pack : enable\n"
1018 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1019 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1020 "layout (location = 0) in vec4 color;\n"
1021 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001022 "layout (location = 0) out vec4 outColor;\n"
GregF3156cb02014-12-02 15:41:44 -07001023 "void main() {\n"
1024 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1025 " float dist_squared = dot(pos, pos);\n"
GregFaae75242015-06-03 18:40:50 -06001026 " outColor = (dist_squared < 400.0)\n"
GregF3156cb02014-12-02 15:41:44 -07001027 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1028 " : color2;\n"
1029 "}\n";
1030
1031 ASSERT_NO_FATAL_FAILURE(InitState());
1032 ASSERT_NO_FATAL_FAILURE(InitViewport());
1033
Tony Barbour6918cd52015-04-09 12:58:51 -06001034 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001035 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001036
Tony Barbour6918cd52015-04-09 12:58:51 -06001037 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1038 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF3156cb02014-12-02 15:41:44 -07001039
Tony Barbour6918cd52015-04-09 12:58:51 -06001040 VkPipelineObj pipelineobj(m_device);
GregF3156cb02014-12-02 15:41:44 -07001041 pipelineobj.AddShader(&vs);
1042 pipelineobj.AddShader(&ps);
1043
Tony Barbour6918cd52015-04-09 12:58:51 -06001044 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001045 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001046
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001047#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001048 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001049 MESH_BIND_ID, // binding ID
1050 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001051 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF3156cb02014-12-02 15:41:44 -07001052 };
1053
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001054 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001055 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1056 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001057 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001058 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF3156cb02014-12-02 15:41:44 -07001059
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001060 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF3156cb02014-12-02 15:41:44 -07001061 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001062 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF3156cb02014-12-02 15:41:44 -07001063
Tony Barbour664accc2015-01-09 12:55:14 -07001064 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06001065 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07001066 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1067
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001068 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07001069
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001070 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001071
1072 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1073#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001074 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001075 pDSDumpDot((char*)"triTest2.dot");
1076#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001077
Tony Barbour664accc2015-01-09 12:55:14 -07001078 // render triangle
1079 cmdBuffer.Draw(0, 6, 0, 1);
1080
1081 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001082 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001083 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001084
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001085 RecordImages(m_renderTargets);
GregF3156cb02014-12-02 15:41:44 -07001086}
1087
Tony Barbour6918cd52015-04-09 12:58:51 -06001088TEST_F(VkRenderTest, RedCirclesonBlue)
GregF3156cb02014-12-02 15:41:44 -07001089{
1090 // This tests that we correctly handle unread fragment inputs
1091
1092 static const char *vertShaderText =
1093 "#version 140\n"
1094 "#extension GL_ARB_separate_shader_objects : enable\n"
1095 "#extension GL_ARB_shading_language_420pack : enable\n"
1096 "layout (location = 0) in vec4 pos;\n"
1097 "layout (location = 0) out vec4 outColor;\n"
1098 "layout (location = 1) out vec4 outColor2;\n"
1099 "void main() {\n"
1100 " gl_Position = pos;\n"
1101 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1102 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1103 "}\n";
1104
1105 static const char *fragShaderText =
GregF3156cb02014-12-02 15:41:44 -07001106 "#version 330\n"
1107 "#extension GL_ARB_separate_shader_objects : enable\n"
1108 "#extension GL_ARB_shading_language_420pack : enable\n"
1109 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1110 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1111 "layout (location = 0) in vec4 color;\n"
1112 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001113 "layout (location = 0) out vec4 outColor;\n"
GregF3156cb02014-12-02 15:41:44 -07001114 "void main() {\n"
1115 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1116 " float dist_squared = dot(pos, pos);\n"
GregFaae75242015-06-03 18:40:50 -06001117 " outColor = (dist_squared < 400.0)\n"
GregF3156cb02014-12-02 15:41:44 -07001118 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1119 " : color2;\n"
1120 "}\n";
1121
1122 ASSERT_NO_FATAL_FAILURE(InitState());
1123 ASSERT_NO_FATAL_FAILURE(InitViewport());
1124
Tony Barbour6918cd52015-04-09 12:58:51 -06001125 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001126 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001127
Tony Barbour6918cd52015-04-09 12:58:51 -06001128 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1129 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF3156cb02014-12-02 15:41:44 -07001130
Tony Barbour6918cd52015-04-09 12:58:51 -06001131 VkPipelineObj pipelineobj(m_device);
GregF3156cb02014-12-02 15:41:44 -07001132 pipelineobj.AddShader(&vs);
1133 pipelineobj.AddShader(&ps);
1134
Tony Barbour6918cd52015-04-09 12:58:51 -06001135 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001136 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001137
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001138#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001139 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001140 MESH_BIND_ID, // binding ID
1141 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001142 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF3156cb02014-12-02 15:41:44 -07001143 };
1144
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001145 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001146 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1147 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001148 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001149 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF3156cb02014-12-02 15:41:44 -07001150
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001151 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF3156cb02014-12-02 15:41:44 -07001152 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001153 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF3156cb02014-12-02 15:41:44 -07001154
Tony Barbour664accc2015-01-09 12:55:14 -07001155 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06001156 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07001157 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1158
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001159 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07001160
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001161 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001162
1163 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1164#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001165 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001166 pDSDumpDot((char*)"triTest2.dot");
1167#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001168 // render two triangles
Tony Barbour664accc2015-01-09 12:55:14 -07001169 cmdBuffer.Draw(0, 6, 0, 1);
1170
1171 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001172 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001173 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001174
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001175 RecordImages(m_renderTargets);
GregF3156cb02014-12-02 15:41:44 -07001176}
1177
Tony Barbour6918cd52015-04-09 12:58:51 -06001178TEST_F(VkRenderTest, GreyCirclesonBlueFade)
GregF3156cb02014-12-02 15:41:44 -07001179{
1180 // This tests reading gl_ClipDistance from FS
1181
1182 static const char *vertShaderText =
GregFaae75242015-06-03 18:40:50 -06001183 //"#version 140\n"
GregF3156cb02014-12-02 15:41:44 -07001184 "#version 330\n"
1185 "#extension GL_ARB_separate_shader_objects : enable\n"
1186 "#extension GL_ARB_shading_language_420pack : enable\n"
1187 "out gl_PerVertex {\n"
1188 " vec4 gl_Position;\n"
1189 " float gl_ClipDistance[1];\n"
1190 "};\n"
1191 "layout (location = 0) in vec4 pos;\n"
1192 "layout (location = 0) out vec4 outColor;\n"
1193 "layout (location = 1) out vec4 outColor2;\n"
1194 "void main() {\n"
1195 " gl_Position = pos;\n"
1196 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1197 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1198 " float dists[3];\n"
1199 " dists[0] = 0.0;\n"
1200 " dists[1] = 1.0;\n"
1201 " dists[2] = 1.0;\n"
1202 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1203 "}\n";
1204
1205
1206 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -06001207 "#version 140\n"
1208 //"#version 330\n"
GregF3156cb02014-12-02 15:41:44 -07001209 "#extension GL_ARB_separate_shader_objects : enable\n"
1210 "#extension GL_ARB_shading_language_420pack : enable\n"
1211 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1212 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1213 "layout (location = 0) in vec4 color;\n"
1214 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001215 "layout (location = 0) out vec4 uFragColor;\n"
GregF3156cb02014-12-02 15:41:44 -07001216 "void main() {\n"
1217 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1218 " float dist_squared = dot(pos, pos);\n"
GregFaae75242015-06-03 18:40:50 -06001219 " uFragColor = (dist_squared < 400.0)\n"
GregF3156cb02014-12-02 15:41:44 -07001220 " ? color * gl_ClipDistance[0]\n"
1221 " : color2;\n"
1222 "}\n";
1223
1224 ASSERT_NO_FATAL_FAILURE(InitState());
1225 ASSERT_NO_FATAL_FAILURE(InitViewport());
1226
Tony Barbour6918cd52015-04-09 12:58:51 -06001227 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001228 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001229
Tony Barbour6918cd52015-04-09 12:58:51 -06001230 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1231 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF3156cb02014-12-02 15:41:44 -07001232
Tony Barbour6918cd52015-04-09 12:58:51 -06001233 VkPipelineObj pipelineobj(m_device);
GregF3156cb02014-12-02 15:41:44 -07001234 pipelineobj.AddShader(&vs);
1235 pipelineobj.AddShader(&ps);
1236
Tony Barbour6918cd52015-04-09 12:58:51 -06001237 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001238 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001239
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001240#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001241 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001242 MESH_BIND_ID, // binding ID
1243 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001244 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF3156cb02014-12-02 15:41:44 -07001245 };
1246
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001247 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001248 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1249 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001250 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001251 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF3156cb02014-12-02 15:41:44 -07001252
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001253 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF3156cb02014-12-02 15:41:44 -07001254 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001255 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF3156cb02014-12-02 15:41:44 -07001256
Tony Barbour664accc2015-01-09 12:55:14 -07001257 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06001258 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07001259 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF3156cb02014-12-02 15:41:44 -07001260
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001261 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07001262
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001263 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001264
1265 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1266#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001267 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001268 pDSDumpDot((char*)"triTest2.dot");
1269#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001270
1271 // render two triangles
Tony Barbour664accc2015-01-09 12:55:14 -07001272 cmdBuffer.Draw(0, 6, 0, 1);
1273
1274 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001275 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001276 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001277
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001278 RecordImages(m_renderTargets);
GregF3156cb02014-12-02 15:41:44 -07001279}
Tony Barboure2c58df2014-11-25 13:18:32 -07001280
Tony Barbour6918cd52015-04-09 12:58:51 -06001281TEST_F(VkRenderTest, GreyCirclesonBlueDiscard)
GregF42226582014-12-02 17:19:34 -07001282{
1283 static const char *vertShaderText =
1284 "#version 140\n"
1285 "#extension GL_ARB_separate_shader_objects : enable\n"
1286 "#extension GL_ARB_shading_language_420pack : enable\n"
1287 "layout (location = 0) in vec4 pos;\n"
1288 "layout (location = 0) out vec4 outColor;\n"
1289 "layout (location = 1) out vec4 outColor2;\n"
1290 "void main() {\n"
1291 " gl_Position = pos;\n"
1292 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1293 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1294 "}\n";
1295
1296
1297 static const char *fragShaderText =
GregF42226582014-12-02 17:19:34 -07001298 "#version 330\n"
1299 "#extension GL_ARB_separate_shader_objects : enable\n"
1300 "#extension GL_ARB_shading_language_420pack : enable\n"
1301 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1302 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1303 "layout (location = 0) in vec4 color;\n"
1304 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001305 "layout (location = 0) out vec4 outColor;\n"
GregF42226582014-12-02 17:19:34 -07001306 "void main() {\n"
1307 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1308 " float dist_squared = dot(pos, pos);\n"
1309 " if (dist_squared < 100.0)\n"
1310 " discard;\n"
GregFaae75242015-06-03 18:40:50 -06001311 " outColor = (dist_squared < 400.0)\n"
GregF42226582014-12-02 17:19:34 -07001312 " ? color\n"
1313 " : color2;\n"
1314 "}\n";
1315
1316 ASSERT_NO_FATAL_FAILURE(InitState());
1317 ASSERT_NO_FATAL_FAILURE(InitViewport());
1318
Tony Barbour6918cd52015-04-09 12:58:51 -06001319 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001320 meshBuffer.BufferMemoryBarrier();
GregF42226582014-12-02 17:19:34 -07001321
Tony Barbour6918cd52015-04-09 12:58:51 -06001322 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1323 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF42226582014-12-02 17:19:34 -07001324
Tony Barbour6918cd52015-04-09 12:58:51 -06001325 VkPipelineObj pipelineobj(m_device);
GregF42226582014-12-02 17:19:34 -07001326 pipelineobj.AddShader(&vs);
1327 pipelineobj.AddShader(&ps);
1328
Tony Barbour6918cd52015-04-09 12:58:51 -06001329 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001330 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001331
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001332#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001333 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001334 MESH_BIND_ID, // binding ID
1335 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001336 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF42226582014-12-02 17:19:34 -07001337 };
1338
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001339 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001340 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1341 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001342 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001343 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF42226582014-12-02 17:19:34 -07001344
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001345 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF42226582014-12-02 17:19:34 -07001346 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001347 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF42226582014-12-02 17:19:34 -07001348
Tony Barbour664accc2015-01-09 12:55:14 -07001349 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06001350 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07001351 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1352
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001353 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07001354
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001355 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001356
1357 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1358#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001359 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001360 pDSDumpDot((char*)"triTest2.dot");
1361#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001362
1363 // render two triangles
Tony Barbour664accc2015-01-09 12:55:14 -07001364 cmdBuffer.Draw(0, 6, 0, 1);
1365
1366 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001367 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001368 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001369
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001370 RecordImages(m_renderTargets);
GregF42226582014-12-02 17:19:34 -07001371}
1372
1373
Tony Barbour6918cd52015-04-09 12:58:51 -06001374TEST_F(VkRenderTest, TriangleVSUniform)
Cody Northrop66594a72014-10-10 14:49:36 -06001375{
1376 static const char *vertShaderText =
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001377 "#version 140\n"
1378 "#extension GL_ARB_separate_shader_objects : enable\n"
1379 "#extension GL_ARB_shading_language_420pack : enable\n"
1380 "\n"
1381 "layout(binding = 0) uniform buf {\n"
1382 " mat4 MVP;\n"
1383 "} ubuf;\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001384 "void main() {\n"
1385 " vec2 vertices[3];"
1386 " vertices[0] = vec2(-0.5, -0.5);\n"
1387 " vertices[1] = vec2( 0.5, -0.5);\n"
1388 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001389 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001390 "}\n";
1391
1392 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -06001393 "#version 140\n"
1394 "#extension GL_ARB_separate_shader_objects : enable\n"
1395 "#extension GL_ARB_shading_language_420pack : enable\n"
1396 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001397 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001398 " outColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001399 "}\n";
1400
Tony Barboure2c58df2014-11-25 13:18:32 -07001401 ASSERT_NO_FATAL_FAILURE(InitState());
1402 ASSERT_NO_FATAL_FAILURE(InitViewport());
1403
Courtney Goeltzenleuchterfdcfb9f2014-10-10 18:04:39 -06001404 // Create identity matrix
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001405 glm::mat4 Projection = glm::mat4(1.0f);
1406 glm::mat4 View = glm::mat4(1.0f);
1407 glm::mat4 Model = glm::mat4(1.0f);
1408 glm::mat4 MVP = Projection * View * Model;
1409 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1410
Tony Barbour6918cd52015-04-09 12:58:51 -06001411 VkConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1412 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1413 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001414
Tony Barbour6918cd52015-04-09 12:58:51 -06001415 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07001416 pipelineobj.AddShader(&vs);
1417 pipelineobj.AddShader(&ps);
1418
1419 // Create descriptor set and attach the constant buffer to it
Tony Barbour6918cd52015-04-09 12:58:51 -06001420 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001421 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07001422
Tony Barbour664accc2015-01-09 12:55:14 -07001423 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06001424 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07001425 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07001426
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001427 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07001428
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001429 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001430
1431 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1432#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001433 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001434 pDSDumpDot((char*)"triTest2.dot");
1435#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001436
1437 // render two triangles
Tony Barbour664accc2015-01-09 12:55:14 -07001438 cmdBuffer.Draw(0, 6, 0, 1);
1439
1440 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001441 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001442 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001443
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001444 RecordImages(m_renderTargets);
Tony Barbour664accc2015-01-09 12:55:14 -07001445
1446 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001447}
1448
Tony Barbour6918cd52015-04-09 12:58:51 -06001449TEST_F(VkRenderTest, MixTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07001450{
1451 // This tests location applied to varyings. Notice that we have switched foo
1452 // and bar in the FS. The triangle should be blended with red, green and blue
1453 // corners.
1454 static const char *vertShaderText =
1455 "#version 140\n"
1456 "#extension GL_ARB_separate_shader_objects : enable\n"
1457 "#extension GL_ARB_shading_language_420pack : enable\n"
1458 "layout (location=0) out vec4 bar;\n"
1459 "layout (location=1) out vec4 foo;\n"
1460 "layout (location=2) out float scale;\n"
1461 "vec2 vertices[3];\n"
1462 "void main() {\n"
1463 " vertices[0] = vec2(-1.0, -1.0);\n"
1464 " vertices[1] = vec2( 1.0, -1.0);\n"
1465 " vertices[2] = vec2( 0.0, 1.0);\n"
1466 "vec4 colors[3];\n"
1467 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1468 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1469 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1470 " foo = colors[gl_VertexID % 3];\n"
1471 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1472 " scale = 1.0;\n"
1473 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1474 "}\n";
1475
1476 static const char *fragShaderText =
1477 "#version 140\n"
1478 "#extension GL_ARB_separate_shader_objects : enable\n"
1479 "#extension GL_ARB_shading_language_420pack : enable\n"
1480 "layout (location = 1) in vec4 bar;\n"
1481 "layout (location = 0) in vec4 foo;\n"
1482 "layout (location = 2) in float scale;\n"
GregFaae75242015-06-03 18:40:50 -06001483 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001484 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001485 " outColor = bar * scale + foo * (1.0-scale);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001486 "}\n";
1487
1488 ASSERT_NO_FATAL_FAILURE(InitState());
1489 ASSERT_NO_FATAL_FAILURE(InitViewport());
1490
Tony Barbour6918cd52015-04-09 12:58:51 -06001491 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1492 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001493
Tony Barbour6918cd52015-04-09 12:58:51 -06001494 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07001495 pipelineobj.AddShader(&vs);
1496 pipelineobj.AddShader(&ps);
1497
Tony Barbour6918cd52015-04-09 12:58:51 -06001498 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour831062d2015-04-02 15:43:15 -06001499 descriptorSet.AppendDummy();
Tony Barboure2c58df2014-11-25 13:18:32 -07001500
Tony Barbour664accc2015-01-09 12:55:14 -07001501 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06001502 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07001503 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1504
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001505 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07001506
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001507 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001508
1509#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001510 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001511 pDSDumpDot((char*)"triTest2.dot");
1512#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001513
Tony Barbour664accc2015-01-09 12:55:14 -07001514 // render triangle
1515 cmdBuffer.Draw(0, 3, 0, 1);
1516
1517 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001518 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001519 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001520
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001521 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001522}
1523
Tony Barbour6918cd52015-04-09 12:58:51 -06001524TEST_F(VkRenderTest, QuadVertFetchAndVertID)
Tony Barboure2c58df2014-11-25 13:18:32 -07001525{
1526 // This tests that attributes work in the presence of gl_VertexID
1527
1528 static const char *vertShaderText =
1529 "#version 140\n"
1530 "#extension GL_ARB_separate_shader_objects : enable\n"
1531 "#extension GL_ARB_shading_language_420pack : enable\n"
1532 //XYZ1( -1, -1, -1 )
1533 "layout (location = 0) in vec4 pos;\n"
1534 //XYZ1( 0.f, 0.f, 0.f )
1535 "layout (location = 1) in vec4 inColor;\n"
1536 "layout (location = 0) out vec4 outColor;\n"
1537 "void main() {\n"
1538 " outColor = inColor;\n"
1539 " vec4 vertices[3];"
1540 " vertices[gl_VertexID % 3] = pos;\n"
1541 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1542 "}\n";
1543
1544
1545 static const char *fragShaderText =
1546 "#version 140\n"
1547 "#extension GL_ARB_separate_shader_objects : enable\n"
1548 "#extension GL_ARB_shading_language_420pack : enable\n"
1549 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06001550 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001551 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001552 " outColor = color;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001553 "}\n";
1554
1555 ASSERT_NO_FATAL_FAILURE(InitState());
1556 ASSERT_NO_FATAL_FAILURE(InitViewport());
1557
Tony Barbour6918cd52015-04-09 12:58:51 -06001558 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001559 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07001560
Tony Barbour6918cd52015-04-09 12:58:51 -06001561 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1562 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001563
Tony Barbour6918cd52015-04-09 12:58:51 -06001564 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07001565 pipelineobj.AddShader(&vs);
1566 pipelineobj.AddShader(&ps);
1567
Tony Barbour6918cd52015-04-09 12:58:51 -06001568 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001569 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001570
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001571#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001572 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001573 MESH_BUF_ID, // Binding ID
1574 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001575 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barboure2c58df2014-11-25 13:18:32 -07001576 };
1577
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001578 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001579 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1580 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001581 vi_attribs[0].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001582 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1583 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1584 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001585 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001586 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -07001587
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001588 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001589 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001590 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barboure2c58df2014-11-25 13:18:32 -07001591
Tony Barbour664accc2015-01-09 12:55:14 -07001592 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06001593 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07001594 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1595
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001596 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07001597
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001598 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001599
1600 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1601#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001602 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001603 pDSDumpDot((char*)"triTest2.dot");
1604#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001605
1606 // render two triangles
Tony Barbour664accc2015-01-09 12:55:14 -07001607 cmdBuffer.Draw(0, 6, 0, 1);
1608
1609 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001610 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001611 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001612
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001613 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001614}
1615
Tony Barbour6918cd52015-04-09 12:58:51 -06001616TEST_F(VkRenderTest, QuadSparseVertFetch)
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001617{
1618 // This tests that attributes work in the presence of gl_VertexID
1619
1620 static const char *vertShaderText =
1621 "#version 140\n"
1622 "#extension GL_ARB_separate_shader_objects : enable\n"
1623 "#extension GL_ARB_shading_language_420pack : enable\n"
1624 //XYZ1( -1, -1, -1 )
1625 "layout (location = 1) in vec4 pos;\n"
1626 "layout (location = 4) in vec4 inColor;\n"
1627 //XYZ1( 0.f, 0.f, 0.f )
1628 "layout (location = 0) out vec4 outColor;\n"
1629 "void main() {\n"
1630 " outColor = inColor;\n"
1631 " gl_Position = pos;\n"
1632 "}\n";
1633
1634
1635 static const char *fragShaderText =
1636 "#version 140\n"
1637 "#extension GL_ARB_separate_shader_objects : enable\n"
1638 "#extension GL_ARB_shading_language_420pack : enable\n"
1639 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06001640 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001641 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001642 " outColor = color;\n"
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001643 "}\n";
1644
1645 ASSERT_NO_FATAL_FAILURE(InitState());
1646 ASSERT_NO_FATAL_FAILURE(InitViewport());
1647
1648 struct VDATA
1649 {
1650 float t1, t2, t3, t4; // filler data
1651 float posX, posY, posZ, posW; // Position data
1652 float r, g, b, a; // Color
1653 };
1654 const struct VDATA vData[] =
1655 {
1656 { XYZ1(0, 0, 0), XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
1657 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1658 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1659 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1660 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1661 { XYZ1(0, 0, 0), XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
1662 };
1663
Tony Barbour6918cd52015-04-09 12:58:51 -06001664 VkConstantBufferObj meshBuffer(m_device,sizeof(vData)/sizeof(vData[0]),sizeof(vData[0]), vData);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001665 meshBuffer.BufferMemoryBarrier();
1666
Tony Barbour6918cd52015-04-09 12:58:51 -06001667 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1668 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001669
Tony Barbour6918cd52015-04-09 12:58:51 -06001670 VkPipelineObj pipelineobj(m_device);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001671 pipelineobj.AddShader(&vs);
1672 pipelineobj.AddShader(&ps);
1673
Tony Barbour6918cd52015-04-09 12:58:51 -06001674 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001675 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001676
1677#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001678 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001679 MESH_BUF_ID, // Binding ID
1680 sizeof(vData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001681 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001682 };
1683
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001684 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001685 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1686 vi_attribs[0].location = 4;
Tony Barbourd1c35722015-04-16 15:59:00 -06001687 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001688 vi_attribs[0].offsetInBytes = sizeof(float) * 4 * 2; // Offset of first element in bytes from base of vertex
1689 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1690 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001691 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001692 vi_attribs[1].offsetInBytes = sizeof(float) * 4 * 1; // Offset of first element in bytes from base of vertex
1693
1694 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
1695 pipelineobj.AddVertexInputBindings(&vi_binding, 1);
1696 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
1697
1698 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06001699 VkCommandBufferObj cmdBuffer(m_device);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001700 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1701
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001702 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001703
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001704 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001705
1706 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BUF_ID);
1707#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001708 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001709 pDSDumpDot((char*)"triTest2.dot");
1710#endif
1711
1712 // render two triangles
1713 cmdBuffer.Draw(0, 6, 0, 1);
1714
1715 // finalize recording of the command buffer
1716 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001717 cmdBuffer.QueueCommandBuffer();
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001718
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001719 RecordImages(m_renderTargets);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001720}
1721
Tony Barbour6918cd52015-04-09 12:58:51 -06001722TEST_F(VkRenderTest, TriVertFetchDeadAttr)
Tony Barboure2c58df2014-11-25 13:18:32 -07001723{
1724 // This tests that attributes work in the presence of gl_VertexID
1725 // and a dead attribute in position 0. Draws a triangle with yellow,
1726 // red and green corners, starting at top and going clockwise.
1727
1728 static const char *vertShaderText =
1729 "#version 140\n"
1730 "#extension GL_ARB_separate_shader_objects : enable\n"
1731 "#extension GL_ARB_shading_language_420pack : enable\n"
1732 //XYZ1( -1, -1, -1 )
1733 "layout (location = 0) in vec4 pos;\n"
1734 //XYZ1( 0.f, 0.f, 0.f )
1735 "layout (location = 1) in vec4 inColor;\n"
1736 "layout (location = 0) out vec4 outColor;\n"
1737 "void main() {\n"
1738 " outColor = inColor;\n"
1739 " vec2 vertices[3];"
1740 " vertices[0] = vec2(-1.0, -1.0);\n"
1741 " vertices[1] = vec2( 1.0, -1.0);\n"
1742 " vertices[2] = vec2( 0.0, 1.0);\n"
1743 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1744 "}\n";
1745
1746
1747 static const char *fragShaderText =
1748 "#version 140\n"
1749 "#extension GL_ARB_separate_shader_objects : enable\n"
1750 "#extension GL_ARB_shading_language_420pack : enable\n"
1751 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06001752 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001753 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001754 " outColor = color;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001755 "}\n";
1756
1757 ASSERT_NO_FATAL_FAILURE(InitState());
1758 ASSERT_NO_FATAL_FAILURE(InitViewport());
1759
Tony Barbour6918cd52015-04-09 12:58:51 -06001760 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001761 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07001762
Tony Barbour6918cd52015-04-09 12:58:51 -06001763 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1764 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001765
Tony Barbour6918cd52015-04-09 12:58:51 -06001766 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07001767 pipelineobj.AddShader(&vs);
1768 pipelineobj.AddShader(&ps);
1769
Tony Barbour6918cd52015-04-09 12:58:51 -06001770 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001771 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001772
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001773#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001774 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001775 MESH_BUF_ID, // Binding ID
1776 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001777 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barboure2c58df2014-11-25 13:18:32 -07001778 };
1779
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001780 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001781 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1782 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001783 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001784 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1785 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1786 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001787 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001788 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -07001789
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001790 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001791 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001792 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barboure2c58df2014-11-25 13:18:32 -07001793
Tony Barbour664accc2015-01-09 12:55:14 -07001794 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06001795 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07001796 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07001797
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001798 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07001799
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001800 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001801
1802 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1803#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001804 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001805 pDSDumpDot((char*)"triTest2.dot");
1806#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001807
1808 // render two triangles
Tony Barbour664accc2015-01-09 12:55:14 -07001809 cmdBuffer.Draw(0, 6, 0, 1);
1810
1811 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001812 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001813 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001814
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001815 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001816}
1817
Tony Barbour6918cd52015-04-09 12:58:51 -06001818TEST_F(VkRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001819{
1820 static const char *vertShaderText =
1821 "#version 140\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001822 "#extension GL_ARB_separate_shader_objects : enable\n"
1823 "#extension GL_ARB_shading_language_420pack : enable\n"
GregFaae75242015-06-03 18:40:50 -06001824 "layout (std140, binding = 0) uniform bufferVals {\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001825 " mat4 mvp;\n"
1826 "} myBufferVals;\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001827 "layout (location = 0) in vec4 pos;\n"
1828 "layout (location = 1) in vec4 inColor;\n"
Cody Northrop8a3bb132015-06-16 17:32:04 -06001829 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001830 "void main() {\n"
1831 " outColor = inColor;\n"
1832 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06001833 " gl_Position.y = -gl_Position.y;\n"
1834 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001835 "}\n";
1836
1837 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -06001838 "#version 140\n"
1839 "#extension GL_ARB_separate_shader_objects : enable\n"
1840 "#extension GL_ARB_shading_language_420pack : enable\n"
1841 "layout (location = 0) in vec4 color;\n"
1842 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001843 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001844 " outColor = color;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001845 "}\n";
Tony Barboure2c58df2014-11-25 13:18:32 -07001846 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001847
Tony Barboure2c58df2014-11-25 13:18:32 -07001848 glm::mat4 View = glm::lookAt(
1849 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1850 glm::vec3(0,0,0), // and looks at the origin
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06001851 glm::vec3(0,-1,0) // Head is up (set to 0,-1,0 to look upside-down)
Tony Barboure2c58df2014-11-25 13:18:32 -07001852 );
1853
1854 glm::mat4 Model = glm::mat4(1.0f);
1855
1856 glm::mat4 MVP = Projection * View * Model;
1857
1858 ASSERT_NO_FATAL_FAILURE(InitState());
1859 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour7ea6aa22015-05-22 09:44:58 -06001860 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height);
Tony Barboure2c58df2014-11-25 13:18:32 -07001861
Tony Barbour6918cd52015-04-09 12:58:51 -06001862 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
Tony Barboure2c58df2014-11-25 13:18:32 -07001863 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1864
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001865 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barboure2c58df2014-11-25 13:18:32 -07001866
Tony Barbour6918cd52015-04-09 12:58:51 -06001867 VkConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1868 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1869 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001870
Tony Barbour6918cd52015-04-09 12:58:51 -06001871 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07001872 pipelineobj.AddShader(&vs);
1873 pipelineobj.AddShader(&ps);
1874
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001875 VkPipelineDsStateCreateInfo ds_state;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001876 ds_state.depthTestEnable = VK_TRUE;
1877 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbourd1c35722015-04-16 15:59:00 -06001878 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001879 ds_state.depthBoundsEnable = VK_FALSE;
1880 ds_state.stencilTestEnable = VK_FALSE;
1881 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
1882 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
1883 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbourd1c35722015-04-16 15:59:00 -06001884 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
1885 ds_state.format = VK_FORMAT_D32_SFLOAT;
Tony Barbourf52346d2015-01-16 14:27:35 -07001886 ds_state.front = ds_state.back;
1887 pipelineobj.SetDepthStencil(&ds_state);
1888
Tony Barbour6918cd52015-04-09 12:58:51 -06001889 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001890 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07001891
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001892#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001893 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001894 MESH_BUF_ID, // Binding ID
1895 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001896 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001897 };
Tony Barboure2c58df2014-11-25 13:18:32 -07001898
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001899 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001900 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1901 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001902 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001903 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1904 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1905 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001906 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001907 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -07001908
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001909 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001910 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001911 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barboure2c58df2014-11-25 13:18:32 -07001912
Tony Barbour1c45ce02015-03-27 17:03:18 -06001913 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour1c45ce02015-03-27 17:03:18 -06001914
Tony Barbour6918cd52015-04-09 12:58:51 -06001915 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1fde6942015-01-09 10:06:53 -07001916 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07001917
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001918 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001919 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barboure2c58df2014-11-25 13:18:32 -07001920
Tony Barbour1fde6942015-01-09 10:06:53 -07001921 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1922#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001923 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour1fde6942015-01-09 10:06:53 -07001924 pDSDumpDot((char*)"triTest2.dot");
1925#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001926
1927 // render triangles
Tony Barbour1fde6942015-01-09 10:06:53 -07001928 cmdBuffer.Draw(0, 36, 0, 1);
1929
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001930
Tony Barbour1fde6942015-01-09 10:06:53 -07001931 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001932 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001933 cmdBuffer.QueueCommandBuffer();
Tony Barbour1fde6942015-01-09 10:06:53 -07001934
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001935 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001936}
1937
Tony Barbour6918cd52015-04-09 12:58:51 -06001938TEST_F(VkRenderTest, VSTexture)
Tony Barboure2c58df2014-11-25 13:18:32 -07001939{
1940 // The expected result from this test is a green and red triangle;
1941 // one red vertex on the left, two green vertices on the right.
1942 static const char *vertShaderText =
Cody Northrop8a3bb132015-06-16 17:32:04 -06001943 "#version 140\n"
1944 "#extension GL_ARB_separate_shader_objects : enable\n"
1945 "#extension GL_ARB_shading_language_420pack : enable\n"
1946 "layout (location = 0) out vec4 texColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001947 "uniform sampler2D surface;\n"
1948 "void main() {\n"
1949 " vec2 vertices[3];"
1950 " vertices[0] = vec2(-0.5, -0.5);\n"
1951 " vertices[1] = vec2( 0.5, -0.5);\n"
1952 " vertices[2] = vec2( 0.5, 0.5);\n"
1953 " vec2 positions[3];"
1954 " positions[0] = vec2( 0.0, 0.0);\n"
1955 " positions[1] = vec2( 0.25, 0.1);\n"
1956 " positions[2] = vec2( 0.1, 0.25);\n"
1957 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1958 " texColor = textureLod(surface, samplePos, 0.0);\n"
1959 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1960 "}\n";
1961
1962 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -06001963 "#version 140\n"
1964 "#extension GL_ARB_separate_shader_objects : enable\n"
1965 "#extension GL_ARB_shading_language_420pack : enable\n"
1966 "layout (location = 0) in vec4 texColor;\n"
1967 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001968 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001969 " outColor = texColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001970 "}\n";
1971
1972 ASSERT_NO_FATAL_FAILURE(InitState());
1973 ASSERT_NO_FATAL_FAILURE(InitViewport());
1974
Tony Barbour6918cd52015-04-09 12:58:51 -06001975 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1976 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
1977 VkSamplerObj sampler(m_device);
1978 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07001979
Tony Barbour6918cd52015-04-09 12:58:51 -06001980 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07001981 pipelineobj.AddShader(&vs);
1982 pipelineobj.AddShader(&ps);
1983
Tony Barbour6918cd52015-04-09 12:58:51 -06001984 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08001985 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07001986
Tony Barbour664accc2015-01-09 12:55:14 -07001987 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06001988 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07001989 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07001990
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001991 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07001992
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001993 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001994
1995#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001996 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001997 pDSDumpDot((char*)"triTest2.dot");
1998#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001999
Tony Barbour664accc2015-01-09 12:55:14 -07002000 // render triangle
2001 cmdBuffer.Draw(0, 3, 0, 1);
2002
2003 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002004 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002005 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002006
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002007 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002008}
GregFaae75242015-06-03 18:40:50 -06002009
2010
2011
Tony Barbour6918cd52015-04-09 12:58:51 -06002012TEST_F(VkRenderTest, TexturedTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07002013{
2014 // The expected result from this test is a red and green checkered triangle
2015 static const char *vertShaderText =
2016 "#version 140\n"
2017 "#extension GL_ARB_separate_shader_objects : enable\n"
2018 "#extension GL_ARB_shading_language_420pack : enable\n"
2019 "layout (location = 0) out vec2 samplePos;\n"
2020 "void main() {\n"
2021 " vec2 vertices[3];"
2022 " vertices[0] = vec2(-0.5, -0.5);\n"
2023 " vertices[1] = vec2( 0.5, -0.5);\n"
2024 " vertices[2] = vec2( 0.5, 0.5);\n"
2025 " vec2 positions[3];"
2026 " positions[0] = vec2( 0.0, 0.0);\n"
2027 " positions[1] = vec2( 1.0, 0.0);\n"
2028 " positions[2] = vec2( 1.0, 1.0);\n"
2029 " samplePos = positions[gl_VertexID % 3];\n"
2030 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2031 "}\n";
2032
2033 static const char *fragShaderText =
2034 "#version 140\n"
2035 "#extension GL_ARB_separate_shader_objects : enable\n"
2036 "#extension GL_ARB_shading_language_420pack : enable\n"
2037 "layout (location = 0) in vec2 samplePos;\n"
2038 "layout (binding = 0) uniform sampler2D surface;\n"
2039 "layout (location=0) out vec4 outColor;\n"
2040 "void main() {\n"
2041 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2042 " outColor = texColor;\n"
2043 "}\n";
2044
2045 ASSERT_NO_FATAL_FAILURE(InitState());
2046 ASSERT_NO_FATAL_FAILURE(InitViewport());
2047
Tony Barbour6918cd52015-04-09 12:58:51 -06002048 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2049 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2050 VkSamplerObj sampler(m_device);
2051 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002052
Tony Barbour6918cd52015-04-09 12:58:51 -06002053 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002054 pipelineobj.AddShader(&vs);
2055 pipelineobj.AddShader(&ps);
2056
Tony Barbour6918cd52015-04-09 12:58:51 -06002057 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002058 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002059
Tony Barbour664accc2015-01-09 12:55:14 -07002060 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06002061 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07002062 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2063
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002064 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07002065
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002066 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002067
2068#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002069 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002070 pDSDumpDot((char*)"triTest2.dot");
2071#endif
2072 // render triangle
2073 cmdBuffer.Draw(0, 3, 0, 1);
2074
2075 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002076 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002077 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002078
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002079 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002080}
Tony Barbour6918cd52015-04-09 12:58:51 -06002081TEST_F(VkRenderTest, TexturedTriangleClip)
Tony Barboure2c58df2014-11-25 13:18:32 -07002082{
2083 // The expected result from this test is a red and green checkered triangle
2084 static const char *vertShaderText =
2085 "#version 330\n"
2086 "#extension GL_ARB_separate_shader_objects : enable\n"
2087 "#extension GL_ARB_shading_language_420pack : enable\n"
2088 "layout (location = 0) out vec2 samplePos;\n"
2089 "out gl_PerVertex {\n"
2090 " vec4 gl_Position;\n"
2091 " float gl_ClipDistance[1];\n"
2092 "};\n"
2093 "void main() {\n"
2094 " vec2 vertices[3];"
2095 " vertices[0] = vec2(-0.5, -0.5);\n"
2096 " vertices[1] = vec2( 0.5, -0.5);\n"
2097 " vertices[2] = vec2( 0.5, 0.5);\n"
2098 " vec2 positions[3];"
2099 " positions[0] = vec2( 0.0, 0.0);\n"
2100 " positions[1] = vec2( 1.0, 0.0);\n"
2101 " positions[2] = vec2( 1.0, 1.0);\n"
2102 " float dists[3];\n"
2103 " dists[0] = 1.0;\n"
2104 " dists[1] = 1.0;\n"
2105 " dists[2] = -1.0;\n"
2106 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2107 " samplePos = positions[gl_VertexID % 3];\n"
2108 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2109 "}\n";
2110
2111 static const char *fragShaderText =
2112 "#version 140\n"
2113 "#extension GL_ARB_separate_shader_objects : enable\n"
2114 "#extension GL_ARB_shading_language_420pack : enable\n"
2115 "layout (location = 0) in vec2 samplePos;\n"
2116 "layout (binding = 0) uniform sampler2D surface;\n"
2117 "layout (location=0) out vec4 outColor;\n"
2118 "void main() {\n"
2119 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2120 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2121 " outColor = texColor;\n"
2122 "}\n";
2123
2124
2125 ASSERT_NO_FATAL_FAILURE(InitState());
2126 ASSERT_NO_FATAL_FAILURE(InitViewport());
2127
Tony Barbour6918cd52015-04-09 12:58:51 -06002128 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2129 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2130 VkSamplerObj sampler(m_device);
2131 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002132
Tony Barbour6918cd52015-04-09 12:58:51 -06002133 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002134 pipelineobj.AddShader(&vs);
2135 pipelineobj.AddShader(&ps);
2136
Tony Barbour6918cd52015-04-09 12:58:51 -06002137 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002138 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002139
Tony Barbour664accc2015-01-09 12:55:14 -07002140 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06002141 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07002142 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2143
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002144 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07002145
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002146 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002147
2148#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002149 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002150 pDSDumpDot((char*)"triTest2.dot");
2151#endif
2152 // render triangle
2153 cmdBuffer.Draw(0, 3, 0, 1);
2154
2155 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002156 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002157 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002158
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002159 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002160}
GregFaae75242015-06-03 18:40:50 -06002161
Tony Barbour6918cd52015-04-09 12:58:51 -06002162TEST_F(VkRenderTest, FSTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07002163{
2164 // The expected result from this test is a red and green checkered triangle
2165 static const char *vertShaderText =
2166 "#version 140\n"
2167 "#extension GL_ARB_separate_shader_objects : enable\n"
2168 "#extension GL_ARB_shading_language_420pack : enable\n"
2169 "layout (location = 0) out vec2 samplePos;\n"
2170 "void main() {\n"
2171 " vec2 vertices[3];"
2172 " vertices[0] = vec2(-0.5, -0.5);\n"
2173 " vertices[1] = vec2( 0.5, -0.5);\n"
2174 " vertices[2] = vec2( 0.5, 0.5);\n"
2175 " vec2 positions[3];"
2176 " positions[0] = vec2( 0.0, 0.0);\n"
2177 " positions[1] = vec2( 1.0, 0.0);\n"
2178 " positions[2] = vec2( 1.0, 1.0);\n"
2179 " samplePos = positions[gl_VertexID % 3];\n"
2180 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2181 "}\n";
2182
2183 static const char *fragShaderText =
2184 "#version 140\n"
2185 "#extension GL_ARB_separate_shader_objects : enable\n"
2186 "#extension GL_ARB_shading_language_420pack : enable\n"
2187 "layout (location = 0) in vec2 samplePos;\n"
2188 "layout (binding = 0) uniform sampler2D surface;\n"
2189 "layout (location=0) out vec4 outColor;\n"
2190 "void main() {\n"
2191 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2192 " outColor = texColor;\n"
2193 "}\n";
2194
2195 ASSERT_NO_FATAL_FAILURE(InitState());
2196 ASSERT_NO_FATAL_FAILURE(InitViewport());
2197
Tony Barbour6918cd52015-04-09 12:58:51 -06002198 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2199 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2200 VkSamplerObj sampler(m_device);
2201 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002202
Tony Barbour6918cd52015-04-09 12:58:51 -06002203 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002204 pipelineobj.AddShader(&vs);
2205 pipelineobj.AddShader(&ps);
2206
Tony Barbour6918cd52015-04-09 12:58:51 -06002207 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002208 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002209
Tony Barbour664accc2015-01-09 12:55:14 -07002210 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06002211 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07002212 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2213
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002214 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07002215
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002216 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002217
2218#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002219 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002220 pDSDumpDot((char*)"triTest2.dot");
2221#endif
2222 // render triangle
2223 cmdBuffer.Draw(0, 3, 0, 1);
2224
2225 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002226 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002227 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002228
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002229 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002230}
Tony Barbour6918cd52015-04-09 12:58:51 -06002231TEST_F(VkRenderTest, SamplerBindingsTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07002232{
2233 // This test sets bindings on the samplers
2234 // For now we are asserting that sampler and texture pairs
2235 // march in lock step, and are set via GLSL binding. This can
2236 // and will probably change.
2237 // The sampler bindings should match the sampler and texture slot
2238 // number set up by the application.
2239 // This test will result in a blue triangle
2240 static const char *vertShaderText =
2241 "#version 140\n"
2242 "#extension GL_ARB_separate_shader_objects : enable\n"
2243 "#extension GL_ARB_shading_language_420pack : enable\n"
2244 "layout (location = 0) out vec4 samplePos;\n"
2245 "void main() {\n"
2246 " vec2 vertices[3];"
2247 " vertices[0] = vec2(-0.5, -0.5);\n"
2248 " vertices[1] = vec2( 0.5, -0.5);\n"
2249 " vertices[2] = vec2( 0.5, 0.5);\n"
2250 " vec2 positions[3];"
2251 " positions[0] = vec2( 0.0, 0.0);\n"
2252 " positions[1] = vec2( 1.0, 0.0);\n"
2253 " positions[2] = vec2( 1.0, 1.0);\n"
2254 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2255 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2256 "}\n";
2257
2258 static const char *fragShaderText =
2259 "#version 140\n"
2260 "#extension GL_ARB_separate_shader_objects : enable\n"
2261 "#extension GL_ARB_shading_language_420pack : enable\n"
2262 "layout (location = 0) in vec4 samplePos;\n"
2263 "layout (binding = 0) uniform sampler2D surface0;\n"
2264 "layout (binding = 1) uniform sampler2D surface1;\n"
2265 "layout (binding = 12) uniform sampler2D surface2;\n"
GregFaae75242015-06-03 18:40:50 -06002266 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002267 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06002268 " outColor = textureLod(surface2, samplePos.xy, 0.0);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002269 "}\n";
2270
2271 ASSERT_NO_FATAL_FAILURE(InitState());
2272 ASSERT_NO_FATAL_FAILURE(InitViewport());
2273
Tony Barbour6918cd52015-04-09 12:58:51 -06002274 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2275 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002276
Tony Barbour6918cd52015-04-09 12:58:51 -06002277 VkSamplerObj sampler1(m_device);
2278 VkSamplerObj sampler2(m_device);
2279 VkSamplerObj sampler3(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002280
Tony Barbourebc093f2015-04-01 16:38:10 -06002281 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
Tony Barbour6918cd52015-04-09 12:58:51 -06002282 VkTextureObj texture1(m_device, tex_colors); // Red
Tony Barbourebc093f2015-04-01 16:38:10 -06002283 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
Tony Barbour6918cd52015-04-09 12:58:51 -06002284 VkTextureObj texture2(m_device, tex_colors); // Green
Tony Barbourebc093f2015-04-01 16:38:10 -06002285 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
Tony Barbour6918cd52015-04-09 12:58:51 -06002286 VkTextureObj texture3(m_device, tex_colors); // Blue
Tony Barboure2c58df2014-11-25 13:18:32 -07002287
Tony Barbour6918cd52015-04-09 12:58:51 -06002288 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002289 pipelineobj.AddShader(&vs);
2290 pipelineobj.AddShader(&ps);
2291
Tony Barbour6918cd52015-04-09 12:58:51 -06002292 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002293 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2294 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2295 for (int i = 0; i < 10; i++)
2296 descriptorSet.AppendDummy();
2297 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barboure2c58df2014-11-25 13:18:32 -07002298
Tony Barbour664accc2015-01-09 12:55:14 -07002299 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06002300 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07002301 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2302
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002303 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07002304
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002305 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002306
2307#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002308 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002309 pDSDumpDot((char*)"triTest2.dot");
2310#endif
2311 // render triangle
2312 cmdBuffer.Draw(0, 3, 0, 1);
2313
2314 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002315 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002316 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002317
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002318 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002319}
2320
Tony Barbour6918cd52015-04-09 12:58:51 -06002321TEST_F(VkRenderTest, TriangleVSUniformBlock)
Tony Barboure2c58df2014-11-25 13:18:32 -07002322{
2323 // The expected result from this test is a blue triangle
2324
2325 static const char *vertShaderText =
2326 "#version 140\n"
2327 "#extension GL_ARB_separate_shader_objects : enable\n"
2328 "#extension GL_ARB_shading_language_420pack : enable\n"
2329 "layout (location = 0) out vec4 outColor;\n"
2330 "layout (std140, binding = 0) uniform bufferVals {\n"
2331 " vec4 red;\n"
2332 " vec4 green;\n"
2333 " vec4 blue;\n"
2334 " vec4 white;\n"
2335 "} myBufferVals;\n"
2336 "void main() {\n"
2337 " vec2 vertices[3];"
2338 " vertices[0] = vec2(-0.5, -0.5);\n"
2339 " vertices[1] = vec2( 0.5, -0.5);\n"
2340 " vertices[2] = vec2( 0.5, 0.5);\n"
2341 " outColor = myBufferVals.blue;\n"
2342 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2343 "}\n";
2344
2345 static const char *fragShaderText =
2346 "#version 140\n"
2347 "#extension GL_ARB_separate_shader_objects : enable\n"
2348 "#extension GL_ARB_shading_language_420pack : enable\n"
2349 "layout (location = 0) in vec4 inColor;\n"
GregFaae75242015-06-03 18:40:50 -06002350 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002351 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06002352 " outColor = inColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002353 "}\n";
2354
2355 ASSERT_NO_FATAL_FAILURE(InitState());
2356 ASSERT_NO_FATAL_FAILURE(InitViewport());
2357
Tony Barbour6918cd52015-04-09 12:58:51 -06002358 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2359 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002360
2361 // Let's populate our buffer with the following:
2362 // vec4 red;
2363 // vec4 green;
2364 // vec4 blue;
2365 // vec4 white;
2366 const int valCount = 4 * 4;
2367 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2368 0.0, 1.0, 0.0, 1.0,
2369 0.0, 0.0, 1.0, 1.0,
2370 1.0, 1.0, 1.0, 1.0 };
2371
Tony Barbour6918cd52015-04-09 12:58:51 -06002372 VkConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002373
Tony Barbour6918cd52015-04-09 12:58:51 -06002374 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002375 pipelineobj.AddShader(&vs);
2376 pipelineobj.AddShader(&ps);
2377
Tony Barbour6918cd52015-04-09 12:58:51 -06002378 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002379 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, colorBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002380
Tony Barbour664accc2015-01-09 12:55:14 -07002381 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06002382 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07002383 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2384
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002385 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07002386
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002387 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002388
2389#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002390 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002391 pDSDumpDot((char*)"triTest2.dot");
2392#endif
2393 // render triangle
2394 cmdBuffer.Draw(0, 3, 0, 1);
2395
2396 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002397 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002398 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002399
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002400 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002401}
2402
Tony Barbour6918cd52015-04-09 12:58:51 -06002403TEST_F(VkRenderTest, TriangleFSUniformBlockBinding)
Tony Barboure2c58df2014-11-25 13:18:32 -07002404{
2405 // This test allows the shader to select which buffer it is
2406 // pulling from using layout binding qualifier.
2407 // There are corresponding changes in the compiler stack that
2408 // will select the buffer using binding directly.
2409 // The binding number should match the slot number set up by
2410 // the application.
2411 // The expected result from this test is a purple triangle
2412
2413 static const char *vertShaderText =
2414 "#version 140\n"
2415 "#extension GL_ARB_separate_shader_objects : enable\n"
2416 "#extension GL_ARB_shading_language_420pack : enable\n"
2417 "void main() {\n"
2418 " vec2 vertices[3];"
2419 " vertices[0] = vec2(-0.5, -0.5);\n"
2420 " vertices[1] = vec2( 0.5, -0.5);\n"
2421 " vertices[2] = vec2( 0.5, 0.5);\n"
2422 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2423 "}\n";
2424
2425 static const char *fragShaderText =
2426 "#version 140\n"
2427 "#extension GL_ARB_separate_shader_objects : enable\n"
2428 "#extension GL_ARB_shading_language_420pack : enable\n"
2429 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2430 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2431 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wu11078b02015-01-04 16:27:24 +08002432 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
GregFaae75242015-06-03 18:40:50 -06002433 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002434 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06002435 " outColor = myBlueVal.color;\n"
2436 " outColor += myRedVal.color;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002437 "}\n";
2438
2439 ASSERT_NO_FATAL_FAILURE(InitState());
2440 ASSERT_NO_FATAL_FAILURE(InitViewport());
2441
Tony Barbour6918cd52015-04-09 12:58:51 -06002442 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2443 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002444
2445 // We're going to create a number of uniform buffers, and then allow
2446 // the shader to select which it wants to read from with a binding
2447
2448 // Let's populate the buffers with a single color each:
2449 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2450 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2451 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wu11078b02015-01-04 16:27:24 +08002452 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barboure2c58df2014-11-25 13:18:32 -07002453
2454 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2455 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2456 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2457 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2458
2459 const int redCount = sizeof(redVals) / sizeof(float);
2460 const int greenCount = sizeof(greenVals) / sizeof(float);
2461 const int blueCount = sizeof(blueVals) / sizeof(float);
2462 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2463
Tony Barbour6918cd52015-04-09 12:58:51 -06002464 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002465
Tony Barbour6918cd52015-04-09 12:58:51 -06002466 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002467
Tony Barbour6918cd52015-04-09 12:58:51 -06002468 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002469
Tony Barbour6918cd52015-04-09 12:58:51 -06002470 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002471
Tony Barbour6918cd52015-04-09 12:58:51 -06002472 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002473 pipelineobj.AddShader(&vs);
2474 pipelineobj.AddShader(&ps);
2475
Tony Barbour6918cd52015-04-09 12:58:51 -06002476 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002477 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2478 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2479 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2480 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002481
Tony Barbour664accc2015-01-09 12:55:14 -07002482 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06002483 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07002484 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002485
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002486 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07002487
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002488 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002489
2490#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002491 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002492 pDSDumpDot((char*)"triTest2.dot");
2493#endif
2494 // render triangle
2495 cmdBuffer.Draw(0, 3, 0, 1);
2496
2497 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002498 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002499 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002500
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002501 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002502}
2503
Tony Barbour6918cd52015-04-09 12:58:51 -06002504TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBinding)
Tony Barboure2c58df2014-11-25 13:18:32 -07002505{
2506 // This test is the same as TriangleFSUniformBlockBinding, but
2507 // it does not provide an instance name.
2508 // The expected result from this test is a purple triangle
2509
2510 static const char *vertShaderText =
2511 "#version 140\n"
2512 "#extension GL_ARB_separate_shader_objects : enable\n"
2513 "#extension GL_ARB_shading_language_420pack : enable\n"
2514 "void main() {\n"
2515 " vec2 vertices[3];"
2516 " vertices[0] = vec2(-0.5, -0.5);\n"
2517 " vertices[1] = vec2( 0.5, -0.5);\n"
2518 " vertices[2] = vec2( 0.5, 0.5);\n"
2519 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2520 "}\n";
2521
2522 static const char *fragShaderText =
2523 "#version 430\n"
2524 "#extension GL_ARB_separate_shader_objects : enable\n"
2525 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002526 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2527 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2528 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wu11078b02015-01-04 16:27:24 +08002529 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northropd43c52e2014-12-05 15:44:14 -07002530 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002531 "void main() {\n"
Cody Northropd43c52e2014-12-05 15:44:14 -07002532 " outColor = blue;\n"
2533 " outColor += red;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002534 "}\n";
2535 ASSERT_NO_FATAL_FAILURE(InitState());
2536 ASSERT_NO_FATAL_FAILURE(InitViewport());
2537
Tony Barbour6918cd52015-04-09 12:58:51 -06002538 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2539 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002540
2541 // We're going to create a number of uniform buffers, and then allow
2542 // the shader to select which it wants to read from with a binding
2543
2544 // Let's populate the buffers with a single color each:
2545 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2546 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2547 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2548 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2549
2550 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2551 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2552 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2553 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2554
2555 const int redCount = sizeof(redVals) / sizeof(float);
2556 const int greenCount = sizeof(greenVals) / sizeof(float);
2557 const int blueCount = sizeof(blueVals) / sizeof(float);
2558 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2559
Tony Barbour6918cd52015-04-09 12:58:51 -06002560 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002561
Tony Barbour6918cd52015-04-09 12:58:51 -06002562 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002563
Tony Barbour6918cd52015-04-09 12:58:51 -06002564 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002565
Tony Barbour6918cd52015-04-09 12:58:51 -06002566 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002567
Tony Barbour6918cd52015-04-09 12:58:51 -06002568 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002569 pipelineobj.AddShader(&vs);
2570 pipelineobj.AddShader(&ps);
2571
Tony Barbour6918cd52015-04-09 12:58:51 -06002572 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002573 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2574 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2575 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2576 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002577
Tony Barbour664accc2015-01-09 12:55:14 -07002578 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06002579 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07002580 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2581
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002582 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07002583
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002584 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002585
2586#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002587 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002588 pDSDumpDot((char*)"triTest2.dot");
2589#endif
2590 // render triangle
2591 cmdBuffer.Draw(0, 3, 0, 1);
2592
2593 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002594 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002595 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002596
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002597 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002598}
2599
Tony Barbour6918cd52015-04-09 12:58:51 -06002600TEST_F(VkRenderTest, CubeWithVertexFetchAndMVPAndTexture)
Tony Barboure2c58df2014-11-25 13:18:32 -07002601{
2602 static const char *vertShaderText =
2603 "#version 140\n"
2604 "#extension GL_ARB_separate_shader_objects : enable\n"
2605 "#extension GL_ARB_shading_language_420pack : enable\n"
2606 "layout (std140, binding=0) uniform bufferVals {\n"
2607 " mat4 mvp;\n"
2608 "} myBufferVals;\n"
2609 "layout (location=0) in vec4 pos;\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002610 "layout (location=1) in vec2 input_uv;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002611 "layout (location=0) out vec2 UV;\n"
2612 "void main() {\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002613 " UV = input_uv;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002614 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002615 " gl_Position.y = -gl_Position.y;\n"
2616 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002617 "}\n";
2618
2619 static const char *fragShaderText =
2620 "#version 140\n"
2621 "#extension GL_ARB_separate_shader_objects : enable\n"
2622 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wu11078b02015-01-04 16:27:24 +08002623 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002624 "layout (location=0) out vec4 outColor;\n"
2625 "layout (location=0) in vec2 UV;\n"
2626 "void main() {\n"
2627 " outColor= textureLod(surface, UV, 0.0);\n"
2628 "}\n";
2629 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2630
2631 glm::mat4 View = glm::lookAt(
2632 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2633 glm::vec3(0,0,0), // and looks at the origin
2634 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2635 );
2636
2637 glm::mat4 Model = glm::mat4(1.0f);
2638
2639 glm::mat4 MVP = Projection * View * Model;
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002640 int num_verts = sizeof(g_vb_texture_Data) / sizeof(g_vb_texture_Data[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002641
2642
2643 ASSERT_NO_FATAL_FAILURE(InitState());
2644 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour7ea6aa22015-05-22 09:44:58 -06002645 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height);
Tony Barboure2c58df2014-11-25 13:18:32 -07002646
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002647 VkConstantBufferObj meshBuffer(m_device, num_verts,
2648 sizeof(g_vb_texture_Data[0]), g_vb_texture_Data);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00002649 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07002650
Mark Lobodzinski17caf572015-01-29 08:55:56 -06002651 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barboure2c58df2014-11-25 13:18:32 -07002652
Tony Barbour6918cd52015-04-09 12:58:51 -06002653 VkConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2654 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2655 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2656 VkSamplerObj sampler(m_device);
2657 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002658
Tony Barbour6918cd52015-04-09 12:58:51 -06002659 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002660 pipelineobj.AddShader(&vs);
2661 pipelineobj.AddShader(&ps);
2662
Tony Barbour6918cd52015-04-09 12:58:51 -06002663 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002664 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mvpBuffer);
Chia-I Wu11078b02015-01-04 16:27:24 +08002665 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002666
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002667#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002668 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002669 MESH_BIND_ID, // binding ID
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002670 sizeof(g_vb_texture_Data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002671 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002672 };
Tony Barboure2c58df2014-11-25 13:18:32 -07002673
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002674 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002675 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2676 vi_attribs[0].location = 0; // location
Tony Barbourd1c35722015-04-16 15:59:00 -06002677 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002678 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2679 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2680 vi_attribs[1].location = 1; // location
2681 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
2682 vi_attribs[1].offsetInBytes = 16; // Offset of uv components
Tony Barboure2c58df2014-11-25 13:18:32 -07002683
Tony Barboure2c58df2014-11-25 13:18:32 -07002684 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002685 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2686 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barboure2c58df2014-11-25 13:18:32 -07002687
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002688 VkPipelineDsStateCreateInfo ds_state;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002689 ds_state.depthTestEnable = VK_TRUE;
2690 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbourd1c35722015-04-16 15:59:00 -06002691 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002692 ds_state.depthBoundsEnable = VK_FALSE;
2693 ds_state.stencilTestEnable = VK_FALSE;
2694 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
2695 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
2696 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbourd1c35722015-04-16 15:59:00 -06002697 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
2698 ds_state.format = VK_FORMAT_D32_SFLOAT;
Tony Barbourf52346d2015-01-16 14:27:35 -07002699 ds_state.front = ds_state.back;
2700 pipelineobj.SetDepthStencil(&ds_state);
2701
Tony Barbour1c45ce02015-03-27 17:03:18 -06002702 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour6918cd52015-04-09 12:58:51 -06002703 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07002704 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002705
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002706 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002707
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002708 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002709
2710 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2711#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002712 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002713 pDSDumpDot((char*)"triTest2.dot");
2714#endif
2715 // render triangle
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002716 cmdBuffer.Draw(0, num_verts, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07002717
2718 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002719 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002720 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002721
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002722 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002723 RotateTriangleVSUniform(Projection, View, Model, &mvpBuffer, &cmdBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002724}
Cody Northropf1990a92014-12-09 11:17:01 -07002725
Tony Barbour6918cd52015-04-09 12:58:51 -06002726TEST_F(VkRenderTest, TriangleMixedSamplerUniformBlockBinding)
Cody Northropf1990a92014-12-09 11:17:01 -07002727{
2728 // This test mixes binding slots of textures and buffers, ensuring
2729 // that sparse and overlapping assignments work.
Cody Northropb110b4f2014-12-09 13:59:39 -07002730 // The expected result from this test is a purple triangle, although
Cody Northropf1990a92014-12-09 11:17:01 -07002731 // you can modify it to move the desired result around.
2732
2733 static const char *vertShaderText =
2734 "#version 140\n"
2735 "#extension GL_ARB_separate_shader_objects : enable\n"
2736 "#extension GL_ARB_shading_language_420pack : enable\n"
2737 "void main() {\n"
2738 " vec2 vertices[3];"
2739 " vertices[0] = vec2(-0.5, -0.5);\n"
2740 " vertices[1] = vec2( 0.5, -0.5);\n"
2741 " vertices[2] = vec2( 0.5, 0.5);\n"
2742 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2743 "}\n";
2744
2745 static const char *fragShaderText =
2746 "#version 430\n"
2747 "#extension GL_ARB_separate_shader_objects : enable\n"
2748 "#extension GL_ARB_shading_language_420pack : enable\n"
2749 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wu11078b02015-01-04 16:27:24 +08002750 "layout (binding = 3) uniform sampler2D surface1;\n"
2751 "layout (binding = 1) uniform sampler2D surface2;\n"
2752 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002753
Cody Northropb110b4f2014-12-09 13:59:39 -07002754
Chia-I Wu11078b02015-01-04 16:27:24 +08002755 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2756 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2757 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2758 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropf1990a92014-12-09 11:17:01 -07002759 "layout (location = 0) out vec4 outColor;\n"
2760 "void main() {\n"
Cody Northropb110b4f2014-12-09 13:59:39 -07002761 " outColor = red * vec4(0.00001);\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002762 " outColor += white * vec4(0.00001);\n"
2763 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropb110b4f2014-12-09 13:59:39 -07002764 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002765 "}\n";
2766 ASSERT_NO_FATAL_FAILURE(InitState());
2767 ASSERT_NO_FATAL_FAILURE(InitViewport());
2768
Tony Barbour6918cd52015-04-09 12:58:51 -06002769 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2770 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northropf1990a92014-12-09 11:17:01 -07002771
Cody Northropf1990a92014-12-09 11:17:01 -07002772 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2773 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2774 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2775 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2776
2777 const int redCount = sizeof(redVals) / sizeof(float);
2778 const int greenCount = sizeof(greenVals) / sizeof(float);
2779 const int blueCount = sizeof(blueVals) / sizeof(float);
2780 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2781
Tony Barbour6918cd52015-04-09 12:58:51 -06002782 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2783 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2784 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2785 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropf1990a92014-12-09 11:17:01 -07002786
Tony Barbourebc093f2015-04-01 16:38:10 -06002787 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour6918cd52015-04-09 12:58:51 -06002788 VkSamplerObj sampler0(m_device);
2789 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbourebc093f2015-04-01 16:38:10 -06002790 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour6918cd52015-04-09 12:58:51 -06002791 VkSamplerObj sampler2(m_device);
2792 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbourebc093f2015-04-01 16:38:10 -06002793 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour6918cd52015-04-09 12:58:51 -06002794 VkSamplerObj sampler4(m_device);
2795 VkTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropb110b4f2014-12-09 13:59:39 -07002796
2797 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2798 // TODO: Get back here ASAP and understand why.
Tony Barbourebc093f2015-04-01 16:38:10 -06002799 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour6918cd52015-04-09 12:58:51 -06002800 VkSamplerObj sampler7(m_device);
2801 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropf1990a92014-12-09 11:17:01 -07002802
Tony Barbour6918cd52015-04-09 12:58:51 -06002803 VkPipelineObj pipelineobj(m_device);
Cody Northropf1990a92014-12-09 11:17:01 -07002804 pipelineobj.AddShader(&vs);
2805 pipelineobj.AddShader(&ps);
2806
Tony Barbour6918cd52015-04-09 12:58:51 -06002807 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002808 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2809 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2810 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2811 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002812 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
Chia-I Wu11078b02015-01-04 16:27:24 +08002813 // swap blue and green
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002814 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2815 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2816 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropf1990a92014-12-09 11:17:01 -07002817
Tony Barbour664accc2015-01-09 12:55:14 -07002818 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06002819 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07002820 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropf1990a92014-12-09 11:17:01 -07002821
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002822 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07002823
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002824 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002825
2826#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002827 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002828 pDSDumpDot((char*)"triTest2.dot");
2829#endif
2830 // render triangle
2831 cmdBuffer.Draw(0, 3, 0, 1);
2832
2833 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002834 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002835 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002836
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002837 RecordImages(m_renderTargets);
Cody Northropf1990a92014-12-09 11:17:01 -07002838}
2839
Tony Barbour6918cd52015-04-09 12:58:51 -06002840TEST_F(VkRenderTest, TriangleMatchingSamplerUniformBlockBinding)
Cody Northropbd531de2014-12-09 19:08:54 -07002841{
2842 // This test matches binding slots of textures and buffers, requiring
2843 // the driver to give them distinct number spaces.
2844 // The expected result from this test is a red triangle, although
2845 // you can modify it to move the desired result around.
2846
2847 static const char *vertShaderText =
2848 "#version 140\n"
2849 "#extension GL_ARB_separate_shader_objects : enable\n"
2850 "#extension GL_ARB_shading_language_420pack : enable\n"
2851 "void main() {\n"
2852 " vec2 vertices[3];"
2853 " vertices[0] = vec2(-0.5, -0.5);\n"
2854 " vertices[1] = vec2( 0.5, -0.5);\n"
2855 " vertices[2] = vec2( 0.5, 0.5);\n"
2856 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2857 "}\n";
2858
2859 static const char *fragShaderText =
2860 "#version 430\n"
2861 "#extension GL_ARB_separate_shader_objects : enable\n"
2862 "#extension GL_ARB_shading_language_420pack : enable\n"
2863 "layout (binding = 0) uniform sampler2D surface0;\n"
2864 "layout (binding = 1) uniform sampler2D surface1;\n"
2865 "layout (binding = 2) uniform sampler2D surface2;\n"
2866 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wu11078b02015-01-04 16:27:24 +08002867 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2868 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2869 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2870 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropbd531de2014-12-09 19:08:54 -07002871 "layout (location = 0) out vec4 outColor;\n"
2872 "void main() {\n"
2873 " outColor = red;// * vec4(0.00001);\n"
2874 " outColor += white * vec4(0.00001);\n"
2875 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2876 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2877 "}\n";
2878 ASSERT_NO_FATAL_FAILURE(InitState());
2879 ASSERT_NO_FATAL_FAILURE(InitViewport());
2880
Tony Barbour6918cd52015-04-09 12:58:51 -06002881 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2882 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northropbd531de2014-12-09 19:08:54 -07002883
2884 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2885 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2886 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2887 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2888
2889 const int redCount = sizeof(redVals) / sizeof(float);
2890 const int greenCount = sizeof(greenVals) / sizeof(float);
2891 const int blueCount = sizeof(blueVals) / sizeof(float);
2892 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2893
Tony Barbour6918cd52015-04-09 12:58:51 -06002894 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2895 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2896 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2897 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropbd531de2014-12-09 19:08:54 -07002898
Tony Barbourebc093f2015-04-01 16:38:10 -06002899 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour6918cd52015-04-09 12:58:51 -06002900 VkSamplerObj sampler0(m_device);
2901 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbourebc093f2015-04-01 16:38:10 -06002902 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour6918cd52015-04-09 12:58:51 -06002903 VkSamplerObj sampler2(m_device);
2904 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbourebc093f2015-04-01 16:38:10 -06002905 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour6918cd52015-04-09 12:58:51 -06002906 VkSamplerObj sampler4(m_device);
2907 VkTextureObj texture4(m_device, tex_colors); // Light Green
Tony Barbourebc093f2015-04-01 16:38:10 -06002908 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour6918cd52015-04-09 12:58:51 -06002909 VkSamplerObj sampler7(m_device);
2910 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropbd531de2014-12-09 19:08:54 -07002911
Tony Barbour6918cd52015-04-09 12:58:51 -06002912 VkPipelineObj pipelineobj(m_device);
Cody Northropbd531de2014-12-09 19:08:54 -07002913 pipelineobj.AddShader(&vs);
2914 pipelineobj.AddShader(&ps);
2915
Tony Barbour6918cd52015-04-09 12:58:51 -06002916 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002917 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2918 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2919 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2920 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002921 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2922 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2923 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2924 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropbd531de2014-12-09 19:08:54 -07002925
Tony Barbour664accc2015-01-09 12:55:14 -07002926 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06002927 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07002928 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropbd531de2014-12-09 19:08:54 -07002929
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002930 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07002931
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002932 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002933
2934#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002935 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002936 pDSDumpDot((char*)"triTest2.dot");
2937#endif
2938 // render triangle
2939 cmdBuffer.Draw(0, 3, 0, 1);
2940
2941 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002942 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002943 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002944
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002945 RecordImages(m_renderTargets);
Cody Northropbd531de2014-12-09 19:08:54 -07002946}
2947
Tony Barbour6918cd52015-04-09 12:58:51 -06002948TEST_F(VkRenderTest, TriangleUniformBufferLayout)
Cody Northrop04ad1202014-12-17 15:26:33 -07002949{
2950 // This test populates a buffer with a variety of different data
2951 // types, then reads them out with a shader.
2952 // The expected result from this test is a green triangle
2953
2954 static const char *vertShaderText =
2955 "#version 140\n"
2956 "#extension GL_ARB_separate_shader_objects : enable\n"
2957 "#extension GL_ARB_shading_language_420pack : enable\n"
2958 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2959 " vec4 fRed;\n"
2960 " vec4 fGreen;\n"
2961 " layout(row_major) mat4 worldToProj;\n"
2962 " layout(row_major) mat4 projToWorld;\n"
2963 " layout(row_major) mat4 worldToView;\n"
2964 " layout(row_major) mat4 viewToProj;\n"
2965 " layout(row_major) mat4 worldToShadow[4];\n"
2966 " float fZero;\n"
2967 " float fOne;\n"
2968 " float fTwo;\n"
2969 " float fThree;\n"
2970 " vec3 fZeroZeroZero;\n"
2971 " float fFour;\n"
2972 " vec3 fZeroZeroOne;\n"
2973 " float fFive;\n"
2974 " vec3 fZeroOneZero;\n"
2975 " float fSix;\n"
2976 " float fSeven;\n"
2977 " float fEight;\n"
2978 " float fNine;\n"
2979 " vec2 fZeroZero;\n"
2980 " vec2 fZeroOne;\n"
2981 " vec4 fBlue;\n"
2982 " vec2 fOneZero;\n"
2983 " vec2 fOneOne;\n"
2984 " vec3 fZeroOneOne;\n"
2985 " float fTen;\n"
2986 " float fEleven;\n"
2987 " float fTwelve;\n"
2988 " vec3 fOneZeroZero;\n"
2989 " vec4 uvOffsets[4];\n"
2990 "};\n"
2991 "layout (location = 0) out vec4 color;"
2992 "void main() {\n"
2993
2994 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2995 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2996 " \n"
2997
2998 // do some exact comparisons, even though we should
2999 // really have an epsilon involved.
3000 " vec4 outColor = right;\n"
3001 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3002 " outColor = wrong;\n"
3003 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3004 " outColor = wrong;\n"
3005 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3006 " outColor = wrong;\n"
3007
3008 " color = outColor;\n"
3009
3010 // generic position stuff
3011 " vec2 vertices;\n"
3012 " int vertexSelector = gl_VertexID;\n"
3013 " if (vertexSelector == 0)\n"
3014 " vertices = vec2(-0.5, -0.5);\n"
3015 " else if (vertexSelector == 1)\n"
3016 " vertices = vec2( 0.5, -0.5);\n"
3017 " else if (vertexSelector == 2)\n"
3018 " vertices = vec2( 0.5, 0.5);\n"
3019 " else\n"
3020 " vertices = vec2( 0.0, 0.0);\n"
3021 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3022 "}\n";
3023
3024 static const char *fragShaderText =
3025 "#version 140\n"
3026 "#extension GL_ARB_separate_shader_objects : enable\n"
3027 "#extension GL_ARB_shading_language_420pack : enable\n"
3028 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3029 " vec4 fRed;\n"
3030 " vec4 fGreen;\n"
3031 " layout(row_major) mat4 worldToProj;\n"
3032 " layout(row_major) mat4 projToWorld;\n"
3033 " layout(row_major) mat4 worldToView;\n"
3034 " layout(row_major) mat4 viewToProj;\n"
3035 " layout(row_major) mat4 worldToShadow[4];\n"
3036 " float fZero;\n"
3037 " float fOne;\n"
3038 " float fTwo;\n"
3039 " float fThree;\n"
3040 " vec3 fZeroZeroZero;\n"
3041 " float fFour;\n"
3042 " vec3 fZeroZeroOne;\n"
3043 " float fFive;\n"
3044 " vec3 fZeroOneZero;\n"
3045 " float fSix;\n"
3046 " float fSeven;\n"
3047 " float fEight;\n"
3048 " float fNine;\n"
3049 " vec2 fZeroZero;\n"
3050 " vec2 fZeroOne;\n"
3051 " vec4 fBlue;\n"
3052 " vec2 fOneZero;\n"
3053 " vec2 fOneOne;\n"
3054 " vec3 fZeroOneOne;\n"
3055 " float fTen;\n"
3056 " float fEleven;\n"
3057 " float fTwelve;\n"
3058 " vec3 fOneZeroZero;\n"
3059 " vec4 uvOffsets[4];\n"
3060 "};\n"
3061 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06003062 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop04ad1202014-12-17 15:26:33 -07003063 "void main() {\n"
3064 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3065 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3066 " \n"
3067
3068 // start with VS value to ensure it passed
3069 " vec4 outColor = color;\n"
3070
3071 // do some exact comparisons, even though we should
3072 // really have an epsilon involved.
3073 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3074 " outColor = wrong;\n"
3075 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3076 " outColor = wrong;\n"
3077 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3078 " outColor = wrong;\n"
3079 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3080 " outColor = wrong;\n"
3081 " if (fTwo != 2.0)\n"
3082 " outColor = wrong;\n"
3083 " if (fOneOne != vec2(1.0, 1.0))\n"
3084 " outColor = wrong;\n"
3085 " if (fTen != 10.0)\n"
3086 " outColor = wrong;\n"
3087 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3088 " outColor = wrong;\n"
3089 " \n"
GregFaae75242015-06-03 18:40:50 -06003090 " uFragColor = outColor;\n"
Cody Northrop04ad1202014-12-17 15:26:33 -07003091 "}\n";
3092
3093
3094 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3095 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3096 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3097 0.0, 1.0, 0.0, 1.0, // align
3098 0.0, 0.0, 1.0, 1.0, // align
3099 0.0, 0.0, 0.0, 1.0, // align
3100 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3101 0.0, 2.0, 0.0, 2.0, // align
3102 0.0, 0.0, 2.0, 2.0, // align
3103 0.0, 0.0, 0.0, 2.0, // align
3104 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3105 0.0, 3.0, 0.0, 3.0, // align
3106 0.0, 0.0, 3.0, 3.0, // align
3107 0.0, 0.0, 0.0, 3.0, // align
3108 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3109 0.0, 4.0, 0.0, 4.0, // align
3110 0.0, 0.0, 4.0, 4.0, // align
3111 0.0, 0.0, 0.0, 4.0, // align
3112 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3113 0.0, 5.0, 0.0, 5.0, // align
3114 0.0, 0.0, 5.0, 5.0, // align
3115 0.0, 0.0, 0.0, 5.0, // align
3116 6.0, 0.0, 0.0, 6.0, // align
3117 0.0, 6.0, 0.0, 6.0, // align
3118 0.0, 0.0, 6.0, 6.0, // align
3119 0.0, 0.0, 0.0, 6.0, // align
3120 7.0, 0.0, 0.0, 7.0, // align
3121 0.0, 7.0, 0.0, 7.0, // align
3122 0.0, 0.0, 7.0, 7.0, // align
3123 0.0, 0.0, 0.0, 7.0, // align
3124 8.0, 0.0, 0.0, 8.0, // align
3125 0.0, 8.0, 0.0, 8.0, // align
3126 0.0, 0.0, 8.0, 8.0, // align
3127 0.0, 0.0, 0.0, 8.0, // align
3128 0.0, // float fZero; // align
3129 1.0, // float fOne; // pack
3130 2.0, // float fTwo; // pack
3131 3.0, // float fThree; // pack
3132 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3133 4.0, // float fFour; // pack
3134 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3135 5.0, // float fFive; // pack
3136 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3137 6.0, // float fSix; // pack
3138 7.0, // float fSeven; // align
3139 8.0, // float fEight; // pack
3140 9.0, // float fNine; // pack
3141 0.0, // BUFFER
3142 0.0, 0.0, // vec2 fZeroZero; // align
3143 0.0, 1.0, // vec2 fZeroOne; // pack
3144 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3145 1.0, 0.0, // vec2 fOneZero; // align
3146 1.0, 1.0, // vec2 fOneOne; // pack
3147 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3148 10.0, // float fTen; // pack
3149 11.0, // float fEleven; // align
3150 12.0, // float fTwelve; // pack
3151 0.0, 0.0, // BUFFER
3152 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3153 0.0, // BUFFER
3154 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3155 0.5, 0.6, 0.7, 0.8, // align
3156 0.9, 1.0, 1.1, 1.2, // align
3157 1.3, 1.4, 1.5, 1.6, // align
3158 };
3159
3160 ASSERT_NO_FATAL_FAILURE(InitState());
3161 ASSERT_NO_FATAL_FAILURE(InitViewport());
3162
3163 const int constCount = sizeof(mixedVals) / sizeof(float);
3164
Tony Barbour6918cd52015-04-09 12:58:51 -06003165 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3166 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop04ad1202014-12-17 15:26:33 -07003167
Tony Barbour6918cd52015-04-09 12:58:51 -06003168 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop04ad1202014-12-17 15:26:33 -07003169
Tony Barbour6918cd52015-04-09 12:58:51 -06003170 VkPipelineObj pipelineobj(m_device);
Cody Northrop04ad1202014-12-17 15:26:33 -07003171 pipelineobj.AddShader(&vs);
3172 pipelineobj.AddShader(&ps);
3173
Tony Barbour6918cd52015-04-09 12:58:51 -06003174 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003175 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
Cody Northrop04ad1202014-12-17 15:26:33 -07003176
3177 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06003178 VkCommandBufferObj cmdBuffer(m_device);
Cody Northrop04ad1202014-12-17 15:26:33 -07003179 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3180
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003181 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Cody Northrop04ad1202014-12-17 15:26:33 -07003182
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06003183 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Cody Northrop04ad1202014-12-17 15:26:33 -07003184
3185#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003186 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop04ad1202014-12-17 15:26:33 -07003187 pDSDumpDot((char*)"triTest2.dot");
3188#endif
3189 // render triangle
3190 cmdBuffer.Draw(0, 3, 0, 1);
3191
3192 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06003193 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06003194 cmdBuffer.QueueCommandBuffer();
Cody Northrop04ad1202014-12-17 15:26:33 -07003195
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06003196 RecordImages(m_renderTargets);
Cody Northrop04ad1202014-12-17 15:26:33 -07003197}
3198
Cody Northrop95638152015-05-07 14:39:12 -06003199TEST_F(VkRenderTest, TextureGather)
3200{
3201 // This test introduces textureGather and textureGatherOffset
3202 // Each call is compared against an expected inline color result
3203 // Green triangle means everything worked as expected
3204 // Red means something went wrong
3205
3206 // disable SPV until texture gather is turned on in LunarGLASS
Cody Northrop50a2a4b2015-06-03 16:49:20 -06003207 ScopedUseGlsl useGlsl(true);
Cody Northrop95638152015-05-07 14:39:12 -06003208
3209 static const char *vertShaderText =
3210 "#version 140\n"
3211 "#extension GL_ARB_separate_shader_objects : enable\n"
3212 "#extension GL_ARB_shading_language_420pack : enable\n"
3213 "void main() {\n"
3214 " vec2 vertices[3];"
3215 " vertices[0] = vec2(-0.5, -0.5);\n"
3216 " vertices[1] = vec2( 0.5, -0.5);\n"
3217 " vertices[2] = vec2( 0.5, 0.5);\n"
3218 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
3219 "}\n";
3220
3221 static const char *fragShaderText =
3222 "#version 430\n"
3223 "#extension GL_ARB_separate_shader_objects : enable\n"
3224 "#extension GL_ARB_shading_language_420pack : enable\n"
3225 "layout (binding = 0) uniform sampler2D surface0;\n"
3226 "layout (binding = 1) uniform sampler2D surface1;\n"
3227 "layout (binding = 2) uniform sampler2D surface2;\n"
3228 "layout (binding = 3) uniform sampler2D surface3;\n"
3229 "layout (location = 0) out vec4 outColor;\n"
3230 "void main() {\n"
3231
3232 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3233 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3234
3235 " vec4 color = right;\n"
3236
3237 // Grab a normal texture sample to ensure it can work in conjuntion
3238 // with textureGather (there are some intracacies in the backend)
3239 " vec4 sampledColor = textureLod(surface2, vec2(0.5), 0.0);\n"
3240 " if (sampledColor != vec4(0.0, 0.0, 1.0, 1.0))\n"
3241 " color = wrong;\n"
3242
3243 " vec4 gatheredColor = textureGather(surface0, vec2(0.5), 0);\n"
3244 // This just grabbed four red components from a red surface
3245 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3246 " color = wrong;\n"
3247
3248 // Yes, this is using an offset of 0, we don't have enough fine grained
3249 // control of the texture contents here.
3250 " gatheredColor = textureGatherOffset(surface1, vec2(0.5), ivec2(0, 0), 1);\n"
3251 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3252 " color = wrong;\n"
3253
3254 " outColor = color;\n"
3255
3256 "}\n";
3257
3258 ASSERT_NO_FATAL_FAILURE(InitState());
3259 ASSERT_NO_FATAL_FAILURE(InitViewport());
3260
3261 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3262 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3263
3264 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
3265 VkSamplerObj sampler0(m_device);
3266 VkTextureObj texture0(m_device, tex_colors); // Red
3267 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
3268 VkSamplerObj sampler1(m_device);
3269 VkTextureObj texture1(m_device, tex_colors); // Green
3270 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
3271 VkSamplerObj sampler2(m_device);
3272 VkTextureObj texture2(m_device, tex_colors); // Blue
3273 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
3274 VkSamplerObj sampler3(m_device);
3275 VkTextureObj texture3(m_device, tex_colors); // Red and Blue
3276
3277 VkPipelineObj pipelineobj(m_device);
3278 pipelineobj.AddShader(&vs);
3279 pipelineobj.AddShader(&ps);
3280
3281 VkDescriptorSetObj descriptorSet(m_device);
3282 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3283 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
3284 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3285 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
3286
3287 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3288 VkCommandBufferObj cmdBuffer(m_device);
3289 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3290
3291 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3292
3293 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3294
3295 // render triangle
3296 cmdBuffer.Draw(0, 3, 0, 1);
3297
3298 // finalize recording of the command buffer
3299 EndCommandBuffer(cmdBuffer);
3300 cmdBuffer.QueueCommandBuffer();
3301
3302 RecordImages(m_renderTargets);
Cody Northrop95638152015-05-07 14:39:12 -06003303}
3304
Cody Northrop475663c2015-04-15 11:19:06 -06003305TEST_F(VkRenderTest, GeometryShaderHelloWorld)
3306{
3307 // This test introduces a geometry shader that simply
3308 // changes the color of each vertex to red, green, blue
3309
3310 static const char *vertShaderText =
3311 "#version 140\n"
3312 "#extension GL_ARB_separate_shader_objects : enable\n"
3313 "#extension GL_ARB_shading_language_420pack : enable\n"
3314 "layout (location = 0) out vec4 color;"
3315 "void main() {\n"
3316
3317 // VS writes out red
3318 " color = vec4(1.0, 0.0, 0.0, 1.0);\n"
3319
3320 // generic position stuff
3321 " vec2 vertices;\n"
3322 " int vertexSelector = gl_VertexID;\n"
3323 " if (vertexSelector == 0)\n"
3324 " vertices = vec2(-0.5, -0.5);\n"
3325 " else if (vertexSelector == 1)\n"
3326 " vertices = vec2( 0.5, -0.5);\n"
3327 " else if (vertexSelector == 2)\n"
3328 " vertices = vec2( 0.5, 0.5);\n"
3329 " else\n"
3330 " vertices = vec2( 0.0, 0.0);\n"
3331 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3332
3333 "}\n";
3334
3335 static const char *geomShaderText =
3336 "#version 330\n"
3337 "#extension GL_ARB_separate_shader_objects : enable\n"
3338 "#extension GL_ARB_shading_language_420pack : enable\n"
3339 "layout( triangles ) in;\n"
3340 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3341 "layout( location = 0 ) in vec4 inColor[3];\n"
3342 "layout( location = 0 ) out vec4 outColor;\n"
3343 "void main()\n"
3344 "{\n"
3345
3346 // first vertex, pass through red
3347 " gl_Position = gl_in[0].gl_Position;\n"
3348 " outColor = inColor[0];\n"
3349 " EmitVertex();\n"
3350
3351 // second vertex, green
3352 " gl_Position = gl_in[1].gl_Position;\n"
3353 " outColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3354 " EmitVertex();\n"
3355
3356 // third vertex, blue
3357 " gl_Position = gl_in[2].gl_Position;\n"
3358 " outColor = vec4(0.0, 0.0, 1.0, 1.0);\n"
3359 " EmitVertex();\n"
3360
3361 // done
3362 " EndPrimitive();\n"
3363 "}\n";
3364
3365
3366 static const char *fragShaderText =
3367 "#version 140\n"
3368 "#extension GL_ARB_separate_shader_objects : enable\n"
3369 "#extension GL_ARB_shading_language_420pack : enable\n"
3370 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06003371 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003372 "void main() {\n"
3373 // pass through
GregFaae75242015-06-03 18:40:50 -06003374 " outColor = color;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003375 "}\n";
3376
3377
3378
3379 ASSERT_NO_FATAL_FAILURE(InitState());
3380 ASSERT_NO_FATAL_FAILURE(InitViewport());
3381
3382 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3383 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3384 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3385
3386 VkPipelineObj pipelineobj(m_device);
3387 pipelineobj.AddShader(&vs);
3388 pipelineobj.AddShader(&gs);
3389 pipelineobj.AddShader(&ps);
3390
3391 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3392 VkCommandBufferObj cmdBuffer(m_device);
3393 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3394
3395 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3396
3397 VkDescriptorSetObj descriptorSet(m_device);
3398
3399 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3400
3401 // render triangle
3402 cmdBuffer.Draw(0, 3, 0, 1);
3403
3404 // finalize recording of the command buffer
3405 EndCommandBuffer(cmdBuffer);
3406 cmdBuffer.QueueCommandBuffer();
3407
3408 RecordImages(m_renderTargets);
3409}
3410
3411TEST_F(VkRenderTest, GSUniformBufferLayout)
3412{
3413 // This test is just like TriangleUniformBufferLayout but adds
3414 // geometry as a stage that also does UBO lookups
3415 // The expected result from this test is a green triangle
3416
3417 static const char *vertShaderText =
3418 "#version 140\n"
3419 "#extension GL_ARB_separate_shader_objects : enable\n"
3420 "#extension GL_ARB_shading_language_420pack : enable\n"
3421 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3422 " vec4 fRed;\n"
3423 " vec4 fGreen;\n"
3424 " layout(row_major) mat4 worldToProj;\n"
3425 " layout(row_major) mat4 projToWorld;\n"
3426 " layout(row_major) mat4 worldToView;\n"
3427 " layout(row_major) mat4 viewToProj;\n"
3428 " layout(row_major) mat4 worldToShadow[4];\n"
3429 " float fZero;\n"
3430 " float fOne;\n"
3431 " float fTwo;\n"
3432 " float fThree;\n"
3433 " vec3 fZeroZeroZero;\n"
3434 " float fFour;\n"
3435 " vec3 fZeroZeroOne;\n"
3436 " float fFive;\n"
3437 " vec3 fZeroOneZero;\n"
3438 " float fSix;\n"
3439 " float fSeven;\n"
3440 " float fEight;\n"
3441 " float fNine;\n"
3442 " vec2 fZeroZero;\n"
3443 " vec2 fZeroOne;\n"
3444 " vec4 fBlue;\n"
3445 " vec2 fOneZero;\n"
3446 " vec2 fOneOne;\n"
3447 " vec3 fZeroOneOne;\n"
3448 " float fTen;\n"
3449 " float fEleven;\n"
3450 " float fTwelve;\n"
3451 " vec3 fOneZeroZero;\n"
3452 " vec4 uvOffsets[4];\n"
3453 "};\n"
3454 "layout (location = 0) out vec4 color;"
3455 "void main() {\n"
3456
3457 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3458 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3459 " \n"
3460
3461 // do some exact comparisons, even though we should
3462 // really have an epsilon involved.
3463 " vec4 outColor = right;\n"
3464 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3465 " outColor = wrong;\n"
3466 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3467 " outColor = wrong;\n"
3468 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3469 " outColor = wrong;\n"
3470
3471 " color = outColor;\n"
3472
3473 // generic position stuff
3474 " vec2 vertices;\n"
3475 " int vertexSelector = gl_VertexID;\n"
3476 " if (vertexSelector == 0)\n"
3477 " vertices = vec2(-0.5, -0.5);\n"
3478 " else if (vertexSelector == 1)\n"
3479 " vertices = vec2( 0.5, -0.5);\n"
3480 " else if (vertexSelector == 2)\n"
3481 " vertices = vec2( 0.5, 0.5);\n"
3482 " else\n"
3483 " vertices = vec2( 0.0, 0.0);\n"
3484 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3485 "}\n";
3486
3487 static const char *geomShaderText =
3488 "#version 330\n"
3489 "#extension GL_ARB_separate_shader_objects : enable\n"
3490 "#extension GL_ARB_shading_language_420pack : enable\n"
3491
3492 // GS layout stuff
3493 "layout( triangles ) in;\n"
3494 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3495
3496 // Between stage IO
3497 "layout( location = 0 ) in vec4 inColor[3];\n"
3498 "layout( location = 0 ) out vec4 color;\n"
3499
3500 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3501 " vec4 fRed;\n"
3502 " vec4 fGreen;\n"
3503 " layout(row_major) mat4 worldToProj;\n"
3504 " layout(row_major) mat4 projToWorld;\n"
3505 " layout(row_major) mat4 worldToView;\n"
3506 " layout(row_major) mat4 viewToProj;\n"
3507 " layout(row_major) mat4 worldToShadow[4];\n"
3508 " float fZero;\n"
3509 " float fOne;\n"
3510 " float fTwo;\n"
3511 " float fThree;\n"
3512 " vec3 fZeroZeroZero;\n"
3513 " float fFour;\n"
3514 " vec3 fZeroZeroOne;\n"
3515 " float fFive;\n"
3516 " vec3 fZeroOneZero;\n"
3517 " float fSix;\n"
3518 " float fSeven;\n"
3519 " float fEight;\n"
3520 " float fNine;\n"
3521 " vec2 fZeroZero;\n"
3522 " vec2 fZeroOne;\n"
3523 " vec4 fBlue;\n"
3524 " vec2 fOneZero;\n"
3525 " vec2 fOneOne;\n"
3526 " vec3 fZeroOneOne;\n"
3527 " float fTen;\n"
3528 " float fEleven;\n"
3529 " float fTwelve;\n"
3530 " vec3 fOneZeroZero;\n"
3531 " vec4 uvOffsets[4];\n"
3532 "};\n"
3533
3534 "void main()\n"
3535 "{\n"
3536
3537 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3538 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3539
3540 // Each vertex will validate it can read VS output
3541 // then check a few values from the UBO
3542
3543 // first vertex
3544 " vec4 outColor = inColor[0];\n"
3545
3546 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3547 " outColor = wrong;\n"
3548 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3549 " outColor = wrong;\n"
3550 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3551 " outColor = wrong;\n"
3552 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3553 " outColor = wrong;\n"
3554
3555 " gl_Position = gl_in[0].gl_Position;\n"
3556 " color = outColor;\n"
3557 " EmitVertex();\n"
3558
3559 // second vertex
3560 " outColor = inColor[1];\n"
3561
3562 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3563 " outColor = wrong;\n"
3564 " if (fSix != 6.0)\n"
3565 " outColor = wrong;\n"
3566 " if (fOneOne != vec2(1.0, 1.0))\n"
3567 " outColor = wrong;\n"
3568
3569 " gl_Position = gl_in[1].gl_Position;\n"
3570 " color = outColor;\n"
3571 " EmitVertex();\n"
3572
3573 // third vertex
3574 " outColor = inColor[2];\n"
3575
3576 " if (fSeven != 7.0)\n"
3577 " outColor = wrong;\n"
3578 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3579 " outColor = wrong;\n"
3580
3581 " gl_Position = gl_in[2].gl_Position;\n"
3582 " color = outColor;\n"
3583 " EmitVertex();\n"
3584
3585 // done
3586 " EndPrimitive();\n"
3587 "}\n";
3588
3589 static const char *fragShaderText =
3590 "#version 140\n"
3591 "#extension GL_ARB_separate_shader_objects : enable\n"
3592 "#extension GL_ARB_shading_language_420pack : enable\n"
3593 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3594 " vec4 fRed;\n"
3595 " vec4 fGreen;\n"
3596 " layout(row_major) mat4 worldToProj;\n"
3597 " layout(row_major) mat4 projToWorld;\n"
3598 " layout(row_major) mat4 worldToView;\n"
3599 " layout(row_major) mat4 viewToProj;\n"
3600 " layout(row_major) mat4 worldToShadow[4];\n"
3601 " float fZero;\n"
3602 " float fOne;\n"
3603 " float fTwo;\n"
3604 " float fThree;\n"
3605 " vec3 fZeroZeroZero;\n"
3606 " float fFour;\n"
3607 " vec3 fZeroZeroOne;\n"
3608 " float fFive;\n"
3609 " vec3 fZeroOneZero;\n"
3610 " float fSix;\n"
3611 " float fSeven;\n"
3612 " float fEight;\n"
3613 " float fNine;\n"
3614 " vec2 fZeroZero;\n"
3615 " vec2 fZeroOne;\n"
3616 " vec4 fBlue;\n"
3617 " vec2 fOneZero;\n"
3618 " vec2 fOneOne;\n"
3619 " vec3 fZeroOneOne;\n"
3620 " float fTen;\n"
3621 " float fEleven;\n"
3622 " float fTwelve;\n"
3623 " vec3 fOneZeroZero;\n"
3624 " vec4 uvOffsets[4];\n"
3625 "};\n"
3626 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06003627 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003628 "void main() {\n"
3629 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3630 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3631 " \n"
3632
3633 // start with GS value to ensure it passed
3634 " vec4 outColor = color;\n"
3635
3636 // do some exact comparisons, even though we should
3637 // really have an epsilon involved.
3638 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3639 " outColor = wrong;\n"
3640 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3641 " outColor = wrong;\n"
3642 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3643 " outColor = wrong;\n"
3644 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3645 " outColor = wrong;\n"
3646 " if (fTwo != 2.0)\n"
3647 " outColor = wrong;\n"
3648 " if (fOneOne != vec2(1.0, 1.0))\n"
3649 " outColor = wrong;\n"
3650 " if (fTen != 10.0)\n"
3651 " outColor = wrong;\n"
3652 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3653 " outColor = wrong;\n"
3654 " \n"
GregFaae75242015-06-03 18:40:50 -06003655 " uFragColor = outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003656 "}\n";
3657
3658
3659 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3660 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3661 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3662 0.0, 1.0, 0.0, 1.0, // align
3663 0.0, 0.0, 1.0, 1.0, // align
3664 0.0, 0.0, 0.0, 1.0, // align
3665 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3666 0.0, 2.0, 0.0, 2.0, // align
3667 0.0, 0.0, 2.0, 2.0, // align
3668 0.0, 0.0, 0.0, 2.0, // align
3669 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3670 0.0, 3.0, 0.0, 3.0, // align
3671 0.0, 0.0, 3.0, 3.0, // align
3672 0.0, 0.0, 0.0, 3.0, // align
3673 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3674 0.0, 4.0, 0.0, 4.0, // align
3675 0.0, 0.0, 4.0, 4.0, // align
3676 0.0, 0.0, 0.0, 4.0, // align
3677 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3678 0.0, 5.0, 0.0, 5.0, // align
3679 0.0, 0.0, 5.0, 5.0, // align
3680 0.0, 0.0, 0.0, 5.0, // align
3681 6.0, 0.0, 0.0, 6.0, // align
3682 0.0, 6.0, 0.0, 6.0, // align
3683 0.0, 0.0, 6.0, 6.0, // align
3684 0.0, 0.0, 0.0, 6.0, // align
3685 7.0, 0.0, 0.0, 7.0, // align
3686 0.0, 7.0, 0.0, 7.0, // align
3687 0.0, 0.0, 7.0, 7.0, // align
3688 0.0, 0.0, 0.0, 7.0, // align
3689 8.0, 0.0, 0.0, 8.0, // align
3690 0.0, 8.0, 0.0, 8.0, // align
3691 0.0, 0.0, 8.0, 8.0, // align
3692 0.0, 0.0, 0.0, 8.0, // align
3693 0.0, // float fZero; // align
3694 1.0, // float fOne; // pack
3695 2.0, // float fTwo; // pack
3696 3.0, // float fThree; // pack
3697 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3698 4.0, // float fFour; // pack
3699 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3700 5.0, // float fFive; // pack
3701 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3702 6.0, // float fSix; // pack
3703 7.0, // float fSeven; // align
3704 8.0, // float fEight; // pack
3705 9.0, // float fNine; // pack
3706 0.0, // BUFFER
3707 0.0, 0.0, // vec2 fZeroZero; // align
3708 0.0, 1.0, // vec2 fZeroOne; // pack
3709 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3710 1.0, 0.0, // vec2 fOneZero; // align
3711 1.0, 1.0, // vec2 fOneOne; // pack
3712 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3713 10.0, // float fTen; // pack
3714 11.0, // float fEleven; // align
3715 12.0, // float fTwelve; // pack
3716 0.0, 0.0, // BUFFER
3717 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3718 0.0, // BUFFER
3719 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3720 0.5, 0.6, 0.7, 0.8, // align
3721 0.9, 1.0, 1.1, 1.2, // align
3722 1.3, 1.4, 1.5, 1.6, // align
3723 };
3724
3725
3726
3727 ASSERT_NO_FATAL_FAILURE(InitState());
3728 ASSERT_NO_FATAL_FAILURE(InitViewport());
3729
3730 const int constCount = sizeof(mixedVals) / sizeof(float);
3731
3732 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3733 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3734 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3735
3736 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
3737
3738 VkPipelineObj pipelineobj(m_device);
3739 pipelineobj.AddShader(&vs);
3740 pipelineobj.AddShader(&gs);
3741 pipelineobj.AddShader(&ps);
3742
3743 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3744 VkCommandBufferObj cmdBuffer(m_device);
3745 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3746
3747 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3748
3749 VkDescriptorSetObj descriptorSet(m_device);
3750 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
3751
3752 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3753
3754 // render triangle
3755 cmdBuffer.Draw(0, 3, 0, 1);
3756
3757 // finalize recording of the command buffer
3758 EndCommandBuffer(cmdBuffer);
3759 cmdBuffer.QueueCommandBuffer();
3760
3761 RecordImages(m_renderTargets);
3762}
3763
3764TEST_F(VkRenderTest, GSPositions)
3765{
3766 // This test adds more inputs from the vertex shader and perturbs positions
3767 // Expected result is white triangle with weird positions
3768
3769 static const char *vertShaderText =
3770 "#version 140\n"
3771 "#extension GL_ARB_separate_shader_objects : enable\n"
3772 "#extension GL_ARB_shading_language_420pack : enable\n"
3773
3774 "layout(location = 0) out vec3 out_a;\n"
3775 "layout(location = 1) out vec3 out_b;\n"
3776 "layout(location = 2) out vec3 out_c;\n"
3777
3778 "void main() {\n"
3779
3780 // write a solid color to each
3781 " out_a = vec3(1.0, 0.0, 0.0);\n"
3782 " out_b = vec3(0.0, 1.0, 0.0);\n"
3783 " out_c = vec3(0.0, 0.0, 1.0);\n"
3784
3785 // generic position stuff
3786 " vec2 vertices;\n"
3787 " int vertexSelector = gl_VertexID;\n"
3788 " if (vertexSelector == 0)\n"
3789 " vertices = vec2(-0.5, -0.5);\n"
3790 " else if (vertexSelector == 1)\n"
3791 " vertices = vec2( 0.5, -0.5);\n"
3792 " else if (vertexSelector == 2)\n"
3793 " vertices = vec2( 0.5, 0.5);\n"
3794 " else\n"
3795 " vertices = vec2( 0.0, 0.0);\n"
3796 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3797
3798 "}\n";
3799
3800 static const char *geomShaderText =
3801 "#version 330\n"
3802 "#extension GL_ARB_separate_shader_objects : enable\n"
3803 "#extension GL_ARB_shading_language_420pack : enable\n"
3804 "layout( triangles ) in;\n"
3805 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3806
3807 "layout(location = 0) in vec3 in_a[3];\n"
3808 "layout(location = 1) in vec3 in_b[3];\n"
3809 "layout(location = 2) in vec3 in_c[3];\n"
3810
3811 "layout(location = 0) out vec3 out_a;\n"
3812 "layout(location = 1) out vec3 out_b;\n"
3813 "layout(location = 2) out vec3 out_c;\n"
3814
3815 "void main()\n"
3816 "{\n"
3817
3818 " gl_Position = gl_in[0].gl_Position;\n"
3819 " gl_Position.xy *= vec2(0.75);\n"
3820 " out_a = in_a[0];\n"
3821 " out_b = in_b[0];\n"
3822 " out_c = in_c[0];\n"
3823 " EmitVertex();\n"
3824
3825 " gl_Position = gl_in[1].gl_Position;\n"
3826 " gl_Position.xy *= vec2(1.5);\n"
3827 " out_a = in_a[1];\n"
3828 " out_b = in_b[1];\n"
3829 " out_c = in_c[1];\n"
3830 " EmitVertex();\n"
3831
3832 " gl_Position = gl_in[2].gl_Position;\n"
3833 " gl_Position.xy *= vec2(-0.1);\n"
3834 " out_a = in_a[2];\n"
3835 " out_b = in_b[2];\n"
3836 " out_c = in_c[2];\n"
3837 " EmitVertex();\n"
3838
3839 " EndPrimitive();\n"
3840 "}\n";
3841
3842
3843 static const char *fragShaderText =
3844 "#version 140\n"
3845 "#extension GL_ARB_separate_shader_objects : enable\n"
3846 "#extension GL_ARB_shading_language_420pack : enable\n"
3847
3848 "layout(location = 0) in vec3 in_a;\n"
3849 "layout(location = 1) in vec3 in_b;\n"
3850 "layout(location = 2) in vec3 in_c;\n"
GregFaae75242015-06-03 18:40:50 -06003851 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003852
3853 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06003854 " outColor = vec4(in_a.x, in_b.y, in_c.z, 1.0);\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003855 "}\n";
3856
3857
3858
3859 ASSERT_NO_FATAL_FAILURE(InitState());
3860 ASSERT_NO_FATAL_FAILURE(InitViewport());
3861
3862 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3863 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3864 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3865
3866 VkPipelineObj pipelineobj(m_device);
3867 pipelineobj.AddShader(&vs);
3868 pipelineobj.AddShader(&gs);
3869 pipelineobj.AddShader(&ps);
3870
3871 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3872 VkCommandBufferObj cmdBuffer(m_device);
3873 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3874
3875 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3876
3877 VkDescriptorSetObj descriptorSet(m_device);
3878
3879 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3880
3881 // render triangle
3882 cmdBuffer.Draw(0, 3, 0, 1);
3883
3884 // finalize recording of the command buffer
3885 EndCommandBuffer(cmdBuffer);
3886 cmdBuffer.QueueCommandBuffer();
3887
3888 RecordImages(m_renderTargets);
3889}
3890
3891TEST_F(VkRenderTest, GSTriStrip)
3892{
3893 // This test emits multiple multiple triangles using a GS
3894 // Correct result is an multicolor circle
3895
3896 static const char *vertShaderText =
3897 "#version 140\n"
3898 "#extension GL_ARB_separate_shader_objects : enable\n"
3899 "#extension GL_ARB_shading_language_420pack : enable\n"
3900
3901 "void main() {\n"
3902
3903 // generic position stuff
3904 " vec2 vertices;\n"
3905 " int vertexSelector = gl_VertexID;\n"
3906 " if (vertexSelector == 0)\n"
3907 " vertices = vec2(-0.5, -0.5);\n"
3908 " else if (vertexSelector == 1)\n"
3909 " vertices = vec2( 0.5, -0.5);\n"
3910 " else if (vertexSelector == 2)\n"
3911 " vertices = vec2( 0.5, 0.5);\n"
3912 " else\n"
3913 " vertices = vec2( 0.0, 0.0);\n"
3914 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3915
3916 "}\n";
3917
3918 static const char *geomShaderText =
3919 "#version 330\n"
3920 "#extension GL_ARB_separate_shader_objects : enable\n"
3921 "#extension GL_ARB_shading_language_420pack : enable\n"
3922 "layout( triangles ) in;\n"
3923 "layout( triangle_strip, max_vertices = 18 ) out;\n"
3924
3925 "layout(location = 0) out vec4 outColor;\n"
3926
3927 "void main()\n"
3928 "{\n"
3929 // init with first position to get zw
3930 " gl_Position = gl_in[0].gl_Position;\n"
3931
3932 " vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3933 " vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
3934 " vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
3935 " vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
3936
3937 // different color per tri
3938 " vec4[6] colors = { red, white, \n"
3939 " yellow, white, \n"
3940 " blue, white }; \n"
3941
3942 // fan out the triangles
3943 " vec2[18] positions = { vec2(0.0, 0.0), vec2(-0.5, 0.0), vec2(-0.25, -0.5), \n"
3944 " vec2(0.0, 0.0), vec2(-0.25, -0.5), vec2( 0.25, -0.5), \n"
3945 " vec2(0.0, 0.0), vec2( 0.25, -0.5), vec2( 0.5, 0.0), \n"
3946 " vec2(0.0, 0.0), vec2( 0.5, 0.0), vec2( 0.25, 0.5), \n"
3947 " vec2(0.0, 0.0), vec2( 0.25, 0.5), vec2(-0.25, 0.5), \n"
3948 " vec2(0.0, 0.0), vec2(-0.25, 0.5), vec2(-0.5, 0.0) }; \n"
3949
3950 // make a triangle list of 6
3951 " for (int i = 0; i < 6; ++i) { \n"
3952 " outColor = colors[i]; \n"
3953 " for (int j = 0; j < 3; ++j) { \n"
3954 " gl_Position.xy = positions[i * 3 + j]; \n"
3955 " EmitVertex(); \n"
3956 " } \n"
3957 " EndPrimitive();\n"
3958 " } \n"
3959
3960 "}\n";
3961
3962
3963 static const char *fragShaderText =
3964 "#version 150\n"
3965 "#extension GL_ARB_separate_shader_objects : enable\n"
3966 "#extension GL_ARB_shading_language_420pack : enable\n"
3967
3968
3969 "layout(binding = 0) uniform windowDimensions {\n"
3970 " vec4 dimensions;\n"
3971 "};\n"
3972
3973 "layout(location = 0) in vec4 inColor;\n"
3974 "layout(origin_upper_left) in vec4 gl_FragCoord;\n"
GregFaae75242015-06-03 18:40:50 -06003975 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003976
3977 "void main() {\n"
3978
3979 // discard to make a nice circle
3980 " vec2 pos = abs(gl_FragCoord.xy) - vec2(dimensions.x, dimensions.y) / 2;\n"
3981 " float dist = sqrt(dot(pos, pos));\n"
3982 " if (dist > 50.0)\n"
3983 " discard;\n"
3984
GregFaae75242015-06-03 18:40:50 -06003985 " outColor = inColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003986
3987 "}\n";
3988
3989
3990
3991 ASSERT_NO_FATAL_FAILURE(InitState());
3992 ASSERT_NO_FATAL_FAILURE(InitViewport());
3993
3994 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3995 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3996 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3997
3998 VkPipelineObj pipelineobj(m_device);
3999 pipelineobj.AddShader(&vs);
4000 pipelineobj.AddShader(&gs);
4001 pipelineobj.AddShader(&ps);
4002
4003 const float dimensions[4] = { VkRenderFramework::m_width, VkRenderFramework::m_height , 0.0, 0.0};
4004
4005 VkConstantBufferObj windowDimensions(m_device, sizeof(dimensions) / sizeof(dimensions[0]), sizeof(dimensions[0]), (const void*) dimensions);
4006
4007 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4008 VkCommandBufferObj cmdBuffer(m_device);
4009 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
4010
4011 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
4012
4013 VkDescriptorSetObj descriptorSet(m_device);
4014 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, windowDimensions);
4015
4016 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
4017
4018 // render triangle
4019 cmdBuffer.Draw(0, 3, 0, 1);
4020
4021 // finalize recording of the command buffer
4022 EndCommandBuffer(cmdBuffer);
4023 cmdBuffer.QueueCommandBuffer();
4024
4025 RecordImages(m_renderTargets);
4026}
4027
Chris Forbese182fe02015-06-15 09:32:35 +12004028TEST_F(VkRenderTest, RenderPassLoadOpClear)
4029{
4030 ASSERT_NO_FATAL_FAILURE(InitState());
4031 ASSERT_NO_FATAL_FAILURE(InitViewport());
4032
4033 /* clear via load op to full green */
4034 m_clear_via_load_op = true;
4035 m_clear_color.useRawValue = false;
4036 m_clear_color.color.floatColor[0] = 0;
4037 m_clear_color.color.floatColor[1] = 1;
4038 m_clear_color.color.floatColor[2] = 0;
4039 m_clear_color.color.floatColor[3] = 0;
4040 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4041
4042 VkCommandBufferObj cmdBuffer(m_device);
4043 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
4044 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
4045 /* This command buffer contains ONLY the load op! */
4046 EndCommandBuffer(cmdBuffer);
4047 cmdBuffer.QueueCommandBuffer();
4048
4049 RecordImages(m_renderTargets);
4050}
4051
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06004052int main(int argc, char **argv) {
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004053 int result;
4054
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06004055 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -06004056 VkTestFramework::InitArgs(&argc, argv);
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004057
Chia-I Wu6f184292014-12-15 23:57:34 +08004058 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchtera0f74c52014-10-08 08:46:51 -06004059
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004060 result = RUN_ALL_TESTS();
4061
Tony Barbour6918cd52015-04-09 12:58:51 -06004062 VkTestFramework::Finish();
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004063 return result;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06004064}