blob: d805808d3508ad7046649735f666af63838e0a67 [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 Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060071#include <vkDbg.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 Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060097 case VK_DBG_MSG_ERROR:
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
120#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
121
122static const Vertex g_vbData[] =
123{
124 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
125 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
126 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
127 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
128 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
129 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
130
131 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
132 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
133 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
134 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
135 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
136 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
137
138 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
139 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.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( 1.f, 1.f, 0.f ) },
143 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
144
145 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
146 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
147 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
148 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
149 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
150 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
151
152 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
153 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
154 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
155 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
156 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
157 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
158
159 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
160 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
161 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
162 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
163 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
164 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
165};
166
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600167static const Vertex g_vb_solid_face_colors_Data[] =
168{
169 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
170 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
171 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
172 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
173 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
174 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
175
176 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
177 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
178 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
179 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
180 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
181 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
182
183 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
184 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
185 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
186 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
187 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
188 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
189
190 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
191 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
192 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
193 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
194 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
195 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
196
197 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
198 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
199 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
200 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
201 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
202 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
203
204 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
205 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
206 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
207 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
208 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
209 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
210};
211
Tony Barbour6918cd52015-04-09 12:58:51 -0600212class VkRenderTest : public VkRenderFramework
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -0600213{
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600214public:
Cody Northrop7ad4aaf2014-10-09 21:25:22 -0600215
Tony Barboure2c58df2014-11-25 13:18:32 -0700216 void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbour6918cd52015-04-09 12:58:51 -0600217 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer);
218 void GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600219 void InitDepthStencil();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600220 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate);
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600221
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600222 VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer);
223 VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer);
Cody Northropee6586d2014-10-09 19:55:56 -0600224
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600225protected:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600226 VkImage m_texture;
227 VkImageView m_textureView;
228 VkImageViewAttachInfo m_textureViewInfo;
Tony Barbourd1c35722015-04-16 15:59:00 -0600229 VkDeviceMemory m_textureMem;
Cody Northrop7d2035d2014-10-06 15:42:00 -0600230
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600231 VkSampler m_sampler;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600232
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600233
234 virtual void SetUp() {
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600235
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600236 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600237 this->app_info.pNext = NULL;
Chia-I Wuf1a5a742014-12-27 15:16:07 +0800238 this->app_info.pAppName = "render_tests";
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600239 this->app_info.appVersion = 1;
Chia-I Wuf1a5a742014-12-27 15:16:07 +0800240 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600241 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600242 this->app_info.apiVersion = VK_API_VERSION;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600243
Cody Northrop7d2035d2014-10-06 15:42:00 -0600244 memset(&m_textureViewInfo, 0, sizeof(m_textureViewInfo));
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600245 m_textureViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO;
Cody Northrop7d2035d2014-10-06 15:42:00 -0600246
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600247 InitFramework();
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600248 }
249
250 virtual void TearDown() {
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600251 // Clean up resources before we reset
252 ShutdownFramework();
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600253 }
254};
255
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600256VkResult VkRenderTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600257{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600258 VkResult result;
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600259
260 result = cmdBuffer.BeginCommandBuffer();
261
262 /*
263 * For render test all drawing happens in a single render pass
264 * on a single command buffer.
265 */
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600266 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600267 cmdBuffer.BeginRenderPass(renderPass(), framebuffer());
268 }
269
270 return result;
271}
272
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600273VkResult VkRenderTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600274{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600275 VkResult result;
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600276
277 cmdBuffer.EndRenderPass(renderPass());
278
279 result = cmdBuffer.EndCommandBuffer();
280
281 return result;
282}
283
284
Tony Barbour6918cd52015-04-09 12:58:51 -0600285void VkRenderTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet)
Tony Barbour22e32a12015-01-08 17:08:28 -0700286{
Tony Barbour1c45ce02015-03-27 17:03:18 -0600287 if (m_depthStencil->Initialized()) {
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600288 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Tony Barbour1c45ce02015-03-27 17:03:18 -0600289 } else {
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600290 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour1c45ce02015-03-27 17:03:18 -0600291 }
292
Jeremy Hayesd65ae082015-01-14 16:17:08 -0700293 cmdBuffer->PrepareAttachments();
Tony Barbourd1c35722015-04-16 15:59:00 -0600294 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_RASTER, m_stateRaster);
295 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_VIEWPORT, m_stateViewport);
296 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_COLOR_BLEND, m_colorBlend);
297 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_DEPTH_STENCIL, m_stateDepthStencil);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600298 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
299 pipelineobj.CreateVKPipeline(descriptorSet);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600300 cmdBuffer->BindPipeline(pipelineobj);
Chia-I Wu53f07d72015-03-28 15:23:55 +0800301 cmdBuffer->BindDescriptorSet(descriptorSet);
Tony Barbour22e32a12015-01-08 17:08:28 -0700302}
Tony Barboure2c58df2014-11-25 13:18:32 -0700303
Tony Barbour6918cd52015-04-09 12:58:51 -0600304void VkRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
305 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer)
Tony Barbour664accc2015-01-09 12:55:14 -0700306{
307 int i;
308 glm::mat4 MVP;
309 int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600310 VkResult err;
Tony Barbour664accc2015-01-09 12:55:14 -0700311
312 for (i = 0; i < 8; i++) {
313 void *pData = constantBuffer->map();
314
315 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
316 MVP = Projection * View * Model;
317 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
318
319 constantBuffer->unmap();
320
321 // submit the command buffer to the universal queue
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600322 cmdBuffer->QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -0700323
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600324 err = vkQueueWaitIdle( m_device->m_queue );
325 ASSERT_VK_SUCCESS( err );
Tony Barbour664accc2015-01-09 12:55:14 -0700326
327 // Wait for work to finish before cleaning up.
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600328 vkDeviceWaitIdle(m_device->device());
Tony Barbour664accc2015-01-09 12:55:14 -0700329
Courtney Goeltzenleuchterb4337c12015-03-05 16:47:18 -0700330 assert(m_renderTargets.size() == 1);
Tony Barbour664accc2015-01-09 12:55:14 -0700331 RecordImage(m_renderTargets[0]);
332 }
333}
Courtney Goeltzenleuchterc55471f2014-10-13 13:03:31 -0600334
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600335void dumpMatrix(const char *note, glm::mat4 MVP)
336{
Chia-I Wu6f184292014-12-15 23:57:34 +0800337 int i;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600338
339 printf("%s: \n", note);
340 for (i=0; i<4; i++) {
341 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
342 }
343 printf("\n");
344 fflush(stdout);
345}
346
347void dumpVec4(const char *note, glm::vec4 vector)
348{
349 printf("%s: \n", note);
350 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
351 printf("\n");
352 fflush(stdout);
353}
354
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600355struct vktriangle_vs_uniform {
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600356 // Must start with MVP
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600357 float mvp[4][4];
358 float position[3][4];
359 float color[3][4];
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600360};
361
Tony Barbour6918cd52015-04-09 12:58:51 -0600362void VkRenderTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600363{
Tobin Ehlis6663f492014-11-10 12:29:12 -0700364#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600365 vkDbgRegisterMsgCallback(inst, myDbgFunc, NULL);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700366#endif
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600367 // Create identity matrix
368 int i;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600369 struct vktriangle_vs_uniform data;
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600370
371 glm::mat4 Projection = glm::mat4(1.0f);
372 glm::mat4 View = glm::mat4(1.0f);
373 glm::mat4 Model = glm::mat4(1.0f);
374 glm::mat4 MVP = Projection * View * Model;
375 const int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600376 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600377 memcpy(&data.mvp, &MVP[0][0], matrixSize);
378
379 static const Vertex tri_data[] =
380 {
381 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
382 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
383 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
384 };
385
386 for (i=0; i<3; i++) {
387 data.position[i][0] = tri_data[i].posX;
388 data.position[i][1] = tri_data[i].posY;
389 data.position[i][2] = tri_data[i].posZ;
390 data.position[i][3] = tri_data[i].posW;
391 data.color[i][0] = tri_data[i].r;
392 data.color[i][1] = tri_data[i].g;
393 data.color[i][2] = tri_data[i].b;
394 data.color[i][3] = tri_data[i].a;
395 }
396
Tony Barboure2c58df2014-11-25 13:18:32 -0700397 ASSERT_NO_FATAL_FAILURE(InitState());
398 ASSERT_NO_FATAL_FAILURE(InitViewport());
399
Tony Barbour6918cd52015-04-09 12:58:51 -0600400 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barboure2c58df2014-11-25 13:18:32 -0700401
Tony Barbour6918cd52015-04-09 12:58:51 -0600402 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
403 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -0700404
Tony Barbour6918cd52015-04-09 12:58:51 -0600405 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -0700406 pipelineobj.AddShader(&vs);
407 pipelineobj.AddShader(&ps);
408
Tony Barbour6918cd52015-04-09 12:58:51 -0600409 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600410 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -0700411
Tony Barbourd726a172015-01-09 16:12:35 -0700412 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -0600413 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourd726a172015-01-09 16:12:35 -0700414 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -0700415
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600416 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourd726a172015-01-09 16:12:35 -0700417
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600418 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourd726a172015-01-09 16:12:35 -0700419#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600420 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourd726a172015-01-09 16:12:35 -0700421 pDSDumpDot((char*)"triTest2.dot");
422#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600423
Tony Barbourd726a172015-01-09 16:12:35 -0700424 // render triangle
425 cmdBuffer.Draw(0, 3, 0, 1);
426
427 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600428 EndCommandBuffer(cmdBuffer);
429
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600430 cmdBuffer.QueueCommandBuffer();
Tony Barbourd726a172015-01-09 16:12:35 -0700431
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600432 RecordImages(m_renderTargets);
Tony Barbourd726a172015-01-09 16:12:35 -0700433
434 if (rotate)
Tobin Ehlis976fc162015-03-26 08:23:25 -0600435 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
Tony Barbourd726a172015-01-09 16:12:35 -0700436
Tobin Ehlisca915872014-11-18 11:28:33 -0700437#ifdef PRINT_OBJECTS
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600438 //uint64_t objTrackGetObjectCount(VK_OBJECT_TYPE type)
439 OBJ_TRACK_GET_OBJECT_COUNT pObjTrackGetObjectCount = (OBJ_TRACK_GET_OBJECT_COUNT)vkGetProcAddr(gpu(), (char*)"objTrackGetObjectCount");
440 uint64_t numObjects = pObjTrackGetObjectCount(VK_OBJECT_TYPE_ANY);
441 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlisca915872014-11-18 11:28:33 -0700442 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600443 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlisca915872014-11-18 11:28:33 -0700444 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600445 pObjTrackGetObjs(VK_OBJECT_TYPE_ANY, numObjects, pObjNodeArray);
Tobin Ehlisca915872014-11-18 11:28:33 -0700446 for (i=0; i < numObjects; i++) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600447 printf("Object %i of type %s has objID (%p) and %lu uses\n", i, string_VK_OBJECT_TYPE(pObjNodeArray[i].objType), pObjNodeArray[i].pObj, pObjNodeArray[i].numUses);
Tobin Ehlisca915872014-11-18 11:28:33 -0700448 }
449 free(pObjNodeArray);
450#endif
Tony Barboure2c58df2014-11-25 13:18:32 -0700451
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600452}
453
Tony Barbour6918cd52015-04-09 12:58:51 -0600454TEST_F(VkRenderTest, VKTriangle_FragColor)
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600455{
456 static const char *vertShaderText =
457 "#version 140\n"
458 "#extension GL_ARB_separate_shader_objects : enable\n"
459 "#extension GL_ARB_shading_language_420pack : enable\n"
460 "\n"
461 "layout(binding = 0) uniform buf {\n"
462 " mat4 MVP;\n"
463 " vec4 position[3];\n"
464 " vec4 color[3];\n"
465 "} ubuf;\n"
466 "\n"
467 "layout (location = 0) out vec4 outColor;\n"
468 "\n"
469 "void main() \n"
470 "{\n"
471 " outColor = ubuf.color[gl_VertexID];\n"
472 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
473 "}\n";
474
475 static const char *fragShaderText =
476 "#version 140\n"
477 "#extension GL_ARB_separate_shader_objects : enable\n"
478 "#extension GL_ARB_shading_language_420pack : enable\n"
479 "\n"
480 "layout (location = 0) in vec4 inColor;\n"
481 "\n"
482 "void main()\n"
483 "{\n"
484 " gl_FragColor = inColor;\n"
485 "}\n";
486
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600487 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
488 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600489}
490
Tony Barbour6918cd52015-04-09 12:58:51 -0600491TEST_F(VkRenderTest, VKTriangle_OutputLocation)
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600492{
493 static const char *vertShaderText =
494 "#version 140\n"
495 "#extension GL_ARB_separate_shader_objects : enable\n"
496 "#extension GL_ARB_shading_language_420pack : enable\n"
497 "\n"
498 "layout(binding = 0) uniform buf {\n"
499 " mat4 MVP;\n"
500 " vec4 position[3];\n"
501 " vec4 color[3];\n"
502 "} ubuf;\n"
503 "\n"
504 "layout (location = 0) out vec4 outColor;\n"
505 "\n"
506 "void main() \n"
507 "{\n"
508 " outColor = ubuf.color[gl_VertexID];\n"
509 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
510 "}\n";
511
512 static const char *fragShaderText =
513 "#version 140\n"
514 "#extension GL_ARB_separate_shader_objects : enable\n"
515 "#extension GL_ARB_shading_language_420pack : enable\n"
516 "\n"
517 "layout (location = 0) in vec4 inColor;\n"
518 "layout (location = 0) out vec4 outColor;\n"
519 "\n"
520 "void main()\n"
521 "{\n"
522 " outColor = inColor;\n"
523 "}\n";
524
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600525 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 -0600526
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600527 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600528}
Tony Barbour0dd968a2015-04-02 15:48:24 -0600529#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 -0600530TEST_F(VkRenderTest, SPV_VKTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -0700531{
Tony Barbour6918cd52015-04-09 12:58:51 -0600532 bool saved_use_spv = VkTestFramework::m_use_spv;
Tony Barboure2c58df2014-11-25 13:18:32 -0700533
534 static const char *vertShaderText =
535 "#version 140\n"
536 "#extension GL_ARB_separate_shader_objects : enable\n"
537 "#extension GL_ARB_shading_language_420pack : enable\n"
538 "\n"
539 "layout(binding = 0) uniform buf {\n"
540 " mat4 MVP;\n"
541 " vec4 position[3];\n"
542 " vec4 color[3];\n"
543 "} ubuf;\n"
544 "\n"
545 "layout (location = 0) out vec4 outColor;\n"
546 "\n"
547 "void main() \n"
548 "{\n"
549 " outColor = ubuf.color[gl_VertexID];\n"
550 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
551 "}\n";
552
553 static const char *fragShaderText =
554 "#version 140\n"
555 "#extension GL_ARB_separate_shader_objects : enable\n"
556 "#extension GL_ARB_shading_language_420pack : enable\n"
557 "\n"
558 "layout (location = 0) in vec4 inColor;\n"
559 "\n"
560 "void main()\n"
561 "{\n"
562 " gl_FragColor = inColor;\n"
563 "}\n";
564
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600565 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 -0700566
Tony Barbour6918cd52015-04-09 12:58:51 -0600567 VkTestFramework::m_use_spv = true;
Tony Barboure2c58df2014-11-25 13:18:32 -0700568
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600569 VKTriangleTest(vertShaderText, fragShaderText, true);
Tony Barboure2c58df2014-11-25 13:18:32 -0700570
Tony Barbour6918cd52015-04-09 12:58:51 -0600571 VkTestFramework::m_use_spv = saved_use_spv;
Tony Barboure2c58df2014-11-25 13:18:32 -0700572}
Tony Barbour0dd968a2015-04-02 15:48:24 -0600573#endif
Tony Barbour6918cd52015-04-09 12:58:51 -0600574TEST_F(VkRenderTest, GreenTriangle)
Cody Northropd1a256b2014-10-09 21:26:47 -0600575{
576 static const char *vertShaderText =
577 "#version 130\n"
578 "vec2 vertices[3];\n"
579 "void main() {\n"
580 " vertices[0] = vec2(-1.0, -1.0);\n"
581 " vertices[1] = vec2( 1.0, -1.0);\n"
582 " vertices[2] = vec2( 0.0, 1.0);\n"
583 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
584 "}\n";
Courtney Goeltzenleuchter538062a2014-10-09 15:40:19 -0600585
Cody Northropd1a256b2014-10-09 21:26:47 -0600586 static const char *fragShaderText =
587 "#version 130\n"
Cody Northropd1a256b2014-10-09 21:26:47 -0600588 "void main() {\n"
Steve Kc53f8632014-10-10 08:54:29 -0600589 " gl_FragColor = vec4(0,1,0,1);\n"
Cody Northropd1a256b2014-10-09 21:26:47 -0600590 "}\n";
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600591
Courtney Goeltzenleuchter9fb62492014-10-27 13:09:23 -0600592 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
593
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600594 VKTriangleTest(vertShaderText, fragShaderText, false);
Cody Northropd1a256b2014-10-09 21:26:47 -0600595}
Tony Barbour0dd968a2015-04-02 15:48:24 -0600596#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 -0600597TEST_F(VkRenderTest, SPV_GreenTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -0700598{
Tony Barbour6918cd52015-04-09 12:58:51 -0600599 bool saved_use_spv = VkTestFramework::m_use_spv;
Tony Barboure2c58df2014-11-25 13:18:32 -0700600
601 static const char *vertShaderText =
602 "#version 130\n"
603 "vec2 vertices[3];\n"
604 "void main() {\n"
605 " vertices[0] = vec2(-1.0, -1.0);\n"
606 " vertices[1] = vec2( 1.0, -1.0);\n"
607 " vertices[2] = vec2( 0.0, 1.0);\n"
608 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
609 "}\n";
610
611 static const char *fragShaderText =
612 "#version 130\n"
613 "void main() {\n"
614 " gl_FragColor = vec4(0,1,0,1);\n"
615 "}\n";
616
Cody Northrop3bfd27c2015-03-17 15:55:58 -0600617 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barboure2c58df2014-11-25 13:18:32 -0700618
Tony Barbour6918cd52015-04-09 12:58:51 -0600619 VkTestFramework::m_use_spv = true;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600620 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbour6918cd52015-04-09 12:58:51 -0600621 VkTestFramework::m_use_spv = saved_use_spv;
Tony Barboure2c58df2014-11-25 13:18:32 -0700622}
Tony Barbour0dd968a2015-04-02 15:48:24 -0600623#endif
Tony Barbour6918cd52015-04-09 12:58:51 -0600624TEST_F(VkRenderTest, YellowTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -0700625{
626 static const char *vertShaderText =
627 "#version 130\n"
628 "void main() {\n"
629 " vec2 vertices[3];"
630 " vertices[0] = vec2(-0.5, -0.5);\n"
631 " vertices[1] = vec2( 0.5, -0.5);\n"
632 " vertices[2] = vec2( 0.5, 0.5);\n"
633 " vec4 colors[3];\n"
634 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
635 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
636 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
637 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
638 "}\n";
639
640 static const char *fragShaderText =
641 "#version 130\n"
642 "void main() {\n"
643 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
644 "}\n";
645
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600646 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barboure2c58df2014-11-25 13:18:32 -0700647}
648
Tony Barbour6918cd52015-04-09 12:58:51 -0600649TEST_F(VkRenderTest, QuadWithVertexFetch)
Cody Northropee6586d2014-10-09 19:55:56 -0600650{
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600651 static const char *vertShaderText =
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600652 "#version 140\n"
653 "#extension GL_ARB_separate_shader_objects : enable\n"
654 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700655 //XYZ1( -1, -1, -1 )
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600656 "layout (location = 0) in vec4 pos;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700657 //XYZ1( 0.f, 0.f, 0.f )
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600658 "layout (location = 1) in vec4 inColor;\n"
659 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600660 "void main() {\n"
Cody Northrop66594a72014-10-10 14:49:36 -0600661 " outColor = inColor;\n"
Cody Northrop7ad4aaf2014-10-09 21:25:22 -0600662 " gl_Position = pos;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600663 "}\n";
664
Cody Northropee6586d2014-10-09 19:55:56 -0600665
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600666 static const char *fragShaderText =
Cody Northropd43c52e2014-12-05 15:44:14 -0700667 "#version 140\n"
668 "#extension GL_ARB_separate_shader_objects : enable\n"
669 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600670 "layout (location = 0) in vec4 color;\n"
Cody Northropd43c52e2014-12-05 15:44:14 -0700671 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600672 "void main() {\n"
Cody Northropd43c52e2014-12-05 15:44:14 -0700673 " outColor = color;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600674 "}\n";
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600675
Tony Barboure2c58df2014-11-25 13:18:32 -0700676
677
678 ASSERT_NO_FATAL_FAILURE(InitState());
679 ASSERT_NO_FATAL_FAILURE(InitViewport());
680
Tony Barbour6918cd52015-04-09 12:58:51 -0600681 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000682 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -0700683
Tony Barbour6918cd52015-04-09 12:58:51 -0600684 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
685 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -0700686
Tony Barbour6918cd52015-04-09 12:58:51 -0600687 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -0700688 pipelineobj.AddShader(&vs);
689 pipelineobj.AddShader(&ps);
690
Tony Barbour6918cd52015-04-09 12:58:51 -0600691 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600692 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -0600693
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600694#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600695 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600696 MESH_BIND_ID, // binding ID
Tony Barboure2c58df2014-11-25 13:18:32 -0700697 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600698 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barboure2c58df2014-11-25 13:18:32 -0700699 };
700
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600701 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600702 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
703 vi_attribs[0].location = 0; // location, position
Tony Barbourd1c35722015-04-16 15:59:00 -0600704 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600705 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
706 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
707 vi_attribs[1].location = 1; // location, color
Tony Barbourd1c35722015-04-16 15:59:00 -0600708 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600709 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 -0700710
711 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
712 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600713 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barboure2c58df2014-11-25 13:18:32 -0700714
Tony Barbour1fde6942015-01-09 10:06:53 -0700715 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -0600716 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1fde6942015-01-09 10:06:53 -0700717 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -0700718
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600719 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600720
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600721 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour1fde6942015-01-09 10:06:53 -0700722
Tony Barbour1fde6942015-01-09 10:06:53 -0700723 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
724
725 // render two triangles
726 cmdBuffer.Draw(0, 6, 0, 1);
727
728 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600729 EndCommandBuffer(cmdBuffer);
730
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600731 cmdBuffer.QueueCommandBuffer();
Tony Barbour1fde6942015-01-09 10:06:53 -0700732
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600733 RecordImages(m_renderTargets);
Tobin Ehlisd806c8e2014-10-07 14:41:29 -0600734}
735
Tony Barbour6918cd52015-04-09 12:58:51 -0600736TEST_F(VkRenderTest, TriangleMRT)
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800737{
738 static const char *vertShaderText =
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600739 "#version 140\n"
740 "#extension GL_ARB_separate_shader_objects : enable\n"
741 "#extension GL_ARB_shading_language_420pack : enable\n"
742 "layout (location = 0) in vec4 pos;\n"
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800743 "void main() {\n"
744 " gl_Position = pos;\n"
745 "}\n";
746
747 static const char *fragShaderText =
748 "#version 130\n"
749 "void main() {\n"
750 " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
751 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
752 "}\n";
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600753 const float vb_data[][2] = {
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800754 { -1.0f, -1.0f },
755 { 1.0f, -1.0f },
756 { -1.0f, 1.0f }
757 };
758
759 ASSERT_NO_FATAL_FAILURE(InitState());
760 ASSERT_NO_FATAL_FAILURE(InitViewport());
761
Tony Barbour6918cd52015-04-09 12:58:51 -0600762 VkConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000763 meshBuffer.BufferMemoryBarrier();
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800764
Tony Barbour6918cd52015-04-09 12:58:51 -0600765 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
766 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800767
Tony Barbour6918cd52015-04-09 12:58:51 -0600768 VkPipelineObj pipelineobj(m_device);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800769 pipelineobj.AddShader(&vs);
770 pipelineobj.AddShader(&ps);
771
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600772#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600773 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600774 MESH_BUF_ID, // Binding ID
775 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600776 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800777 };
778
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600779 VkVertexInputAttributeDescription vi_attrib;
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600780 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
781 vi_attrib.location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -0600782 vi_attrib.format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600783 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800784
785 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
786 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600787 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800788
Tony Barbour6918cd52015-04-09 12:58:51 -0600789 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600790 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800791
Courtney Goeltzenleuchterb4337c12015-03-05 16:47:18 -0700792 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800793
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600794 VkPipelineCbAttachmentState att = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600795 att.blendEnable = VK_FALSE;
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800796 att.format = m_render_target_fmt;
797 att.channelWriteMask = 0xf;
Tony Barbourf52346d2015-01-16 14:27:35 -0700798 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800799
Tony Barbour6918cd52015-04-09 12:58:51 -0600800 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1fde6942015-01-09 10:06:53 -0700801
Tony Barbour304ec8b2015-01-07 14:31:52 -0700802 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
803 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barbour1fde6942015-01-09 10:06:53 -0700804
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600805 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour304ec8b2015-01-07 14:31:52 -0700806
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600807 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour1fde6942015-01-09 10:06:53 -0700808
Tony Barbour304ec8b2015-01-07 14:31:52 -0700809 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour304ec8b2015-01-07 14:31:52 -0700810#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600811 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour304ec8b2015-01-07 14:31:52 -0700812 pDSDumpDot((char*)"triTest2.dot");
813#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600814
Tony Barbour304ec8b2015-01-07 14:31:52 -0700815 // render triangle
816 cmdBuffer.Draw(0, 3, 0, 1);
817
818 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600819 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600820 cmdBuffer.QueueCommandBuffer();
Tony Barbour304ec8b2015-01-07 14:31:52 -0700821
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600822 RecordImages(m_renderTargets);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800823}
824
Tony Barbour6918cd52015-04-09 12:58:51 -0600825TEST_F(VkRenderTest, QuadWithIndexedVertexFetch)
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700826{
827 static const char *vertShaderText =
828 "#version 140\n"
829 "#extension GL_ARB_separate_shader_objects : enable\n"
830 "#extension GL_ARB_shading_language_420pack : enable\n"
831 "layout(location = 0) in vec4 pos;\n"
832 "layout(location = 1) in vec4 inColor;\n"
833 "layout(location = 0) out vec4 outColor;\n"
834 "void main() {\n"
835 " outColor = inColor;\n"
836 " gl_Position = pos;\n"
837 "}\n";
838
839
840 static const char *fragShaderText =
841 "#version 140\n"
842 "#extension GL_ARB_separate_shader_objects : enable\n"
843 "#extension GL_ARB_shading_language_420pack : enable\n"
844 "layout(location = 0) in vec4 color;\n"
845 "void main() {\n"
846 " gl_FragColor = color;\n"
847 "}\n";
848
849 const Vertex g_vbData[] =
850 {
851 // first tri
852 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
853 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
854 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
855
856 // second tri
857 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
858 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
859 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
860 };
861
862 const uint16_t g_idxData[6] = {
863 0, 1, 2,
864 3, 4, 5,
865 };
866
867 ASSERT_NO_FATAL_FAILURE(InitState());
868 ASSERT_NO_FATAL_FAILURE(InitViewport());
869
Tony Barbour6918cd52015-04-09 12:58:51 -0600870 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000871 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700872
Tony Barbour6918cd52015-04-09 12:58:51 -0600873 VkIndexBufferObj indexBuffer(m_device);
Tony Barbourd1c35722015-04-16 15:59:00 -0600874 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), VK_INDEX_TYPE_UINT16, g_idxData);
Mark Lobodzinski49a6b4b2015-02-16 14:24:23 -0600875 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700876
Tony Barbour6918cd52015-04-09 12:58:51 -0600877 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
878 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700879
Tony Barbour6918cd52015-04-09 12:58:51 -0600880 VkPipelineObj pipelineobj(m_device);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700881 pipelineobj.AddShader(&vs);
882 pipelineobj.AddShader(&ps);
883
Tony Barbour6918cd52015-04-09 12:58:51 -0600884 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600885 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
886 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, indexBuffer);
Tony Barbour831062d2015-04-02 15:43:15 -0600887
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700888
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600889#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600890 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600891 MESH_BIND_ID, // binding ID
892 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600893 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700894 };
895
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600896 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600897 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
898 vi_attribs[0].location = 0; // layout location of vertex attribute
Tony Barbourd1c35722015-04-16 15:59:00 -0600899 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600900 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
901 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
902 vi_attribs[1].location = 1; // layout location of vertex attribute
Tony Barbourd1c35722015-04-16 15:59:00 -0600903 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600904 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700905
906 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
907 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700908
909 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -0600910 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourad8f1542014-12-17 11:16:05 -0700911 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600912 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour1fde6942015-01-09 10:06:53 -0700913
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600914 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700915
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700916#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600917 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlisf27eba72014-12-16 17:34:50 -0700918 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700919#endif
Tony Barbour22e32a12015-01-08 17:08:28 -0700920
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600921 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600922 cmdBuffer.BindIndexBuffer(&indexBuffer, 0);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700923
924 // render two triangles
Tony Barbourad8f1542014-12-17 11:16:05 -0700925 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700926
927 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600928 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600929 cmdBuffer.QueueCommandBuffer();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700930
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600931 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700932}
933
Tony Barbour6918cd52015-04-09 12:58:51 -0600934TEST_F(VkRenderTest, GreyandRedCirclesonBlue)
GregF3156cb02014-12-02 15:41:44 -0700935{
936 // This tests gl_FragCoord
Tony Barboure2c58df2014-11-25 13:18:32 -0700937
GregF3156cb02014-12-02 15:41:44 -0700938 static const char *vertShaderText =
939 "#version 140\n"
940 "#extension GL_ARB_separate_shader_objects : enable\n"
941 "#extension GL_ARB_shading_language_420pack : enable\n"
942 "layout (location = 0) in vec4 pos;\n"
943 "layout (location = 0) out vec4 outColor;\n"
944 "layout (location = 1) out vec4 outColor2;\n"
945 "void main() {\n"
946 " gl_Position = pos;\n"
947 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
948 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
949 "}\n";
950
951 static const char *fragShaderText =
GregF3156cb02014-12-02 15:41:44 -0700952 "#version 330\n"
953 "#extension GL_ARB_separate_shader_objects : enable\n"
954 "#extension GL_ARB_shading_language_420pack : enable\n"
955 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
956 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
957 "layout (location = 0) in vec4 color;\n"
958 "layout (location = 1) in vec4 color2;\n"
959 "void main() {\n"
960 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
961 " float dist_squared = dot(pos, pos);\n"
962 " gl_FragColor = (dist_squared < 400.0)\n"
963 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
964 " : color2;\n"
965 "}\n";
966
967 ASSERT_NO_FATAL_FAILURE(InitState());
968 ASSERT_NO_FATAL_FAILURE(InitViewport());
969
Tony Barbour6918cd52015-04-09 12:58:51 -0600970 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000971 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -0700972
Tony Barbour6918cd52015-04-09 12:58:51 -0600973 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
974 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF3156cb02014-12-02 15:41:44 -0700975
Tony Barbour6918cd52015-04-09 12:58:51 -0600976 VkPipelineObj pipelineobj(m_device);
GregF3156cb02014-12-02 15:41:44 -0700977 pipelineobj.AddShader(&vs);
978 pipelineobj.AddShader(&ps);
979
Tony Barbour6918cd52015-04-09 12:58:51 -0600980 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600981 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -0600982
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600983#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600984 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600985 MESH_BIND_ID, // binding ID
986 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600987 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF3156cb02014-12-02 15:41:44 -0700988 };
989
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600990 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600991 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
992 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -0600993 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600994 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF3156cb02014-12-02 15:41:44 -0700995
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600996 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF3156cb02014-12-02 15:41:44 -0700997 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600998 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF3156cb02014-12-02 15:41:44 -0700999
Tony Barbour664accc2015-01-09 12:55:14 -07001000 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06001001 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07001002 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1003
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001004 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07001005
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001006 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001007
1008 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1009#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001010 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001011 pDSDumpDot((char*)"triTest2.dot");
1012#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001013
Tony Barbour664accc2015-01-09 12:55:14 -07001014 // render triangle
1015 cmdBuffer.Draw(0, 6, 0, 1);
1016
1017 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001018 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001019 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001020
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001021 RecordImages(m_renderTargets);
GregF3156cb02014-12-02 15:41:44 -07001022}
1023
Tony Barbour6918cd52015-04-09 12:58:51 -06001024TEST_F(VkRenderTest, RedCirclesonBlue)
GregF3156cb02014-12-02 15:41:44 -07001025{
1026 // This tests that we correctly handle unread fragment inputs
1027
1028 static const char *vertShaderText =
1029 "#version 140\n"
1030 "#extension GL_ARB_separate_shader_objects : enable\n"
1031 "#extension GL_ARB_shading_language_420pack : enable\n"
1032 "layout (location = 0) in vec4 pos;\n"
1033 "layout (location = 0) out vec4 outColor;\n"
1034 "layout (location = 1) out vec4 outColor2;\n"
1035 "void main() {\n"
1036 " gl_Position = pos;\n"
1037 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1038 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1039 "}\n";
1040
1041 static const char *fragShaderText =
GregF3156cb02014-12-02 15:41:44 -07001042 "#version 330\n"
1043 "#extension GL_ARB_separate_shader_objects : enable\n"
1044 "#extension GL_ARB_shading_language_420pack : enable\n"
1045 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1046 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1047 "layout (location = 0) in vec4 color;\n"
1048 "layout (location = 1) in vec4 color2;\n"
1049 "void main() {\n"
1050 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1051 " float dist_squared = dot(pos, pos);\n"
1052 " gl_FragColor = (dist_squared < 400.0)\n"
1053 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1054 " : color2;\n"
1055 "}\n";
1056
1057 ASSERT_NO_FATAL_FAILURE(InitState());
1058 ASSERT_NO_FATAL_FAILURE(InitViewport());
1059
Tony Barbour6918cd52015-04-09 12:58:51 -06001060 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001061 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001062
Tony Barbour6918cd52015-04-09 12:58:51 -06001063 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1064 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF3156cb02014-12-02 15:41:44 -07001065
Tony Barbour6918cd52015-04-09 12:58:51 -06001066 VkPipelineObj pipelineobj(m_device);
GregF3156cb02014-12-02 15:41:44 -07001067 pipelineobj.AddShader(&vs);
1068 pipelineobj.AddShader(&ps);
1069
Tony Barbour6918cd52015-04-09 12:58:51 -06001070 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001071 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001072
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001073#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001074 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001075 MESH_BIND_ID, // binding ID
1076 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001077 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF3156cb02014-12-02 15:41:44 -07001078 };
1079
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001080 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001081 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1082 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001083 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001084 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF3156cb02014-12-02 15:41:44 -07001085
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001086 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF3156cb02014-12-02 15:41:44 -07001087 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001088 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF3156cb02014-12-02 15:41:44 -07001089
Tony Barbour664accc2015-01-09 12:55:14 -07001090 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06001091 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07001092 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1093
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001094 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07001095
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001096 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001097
1098 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1099#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001100 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001101 pDSDumpDot((char*)"triTest2.dot");
1102#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001103 // render two triangles
Tony Barbour664accc2015-01-09 12:55:14 -07001104 cmdBuffer.Draw(0, 6, 0, 1);
1105
1106 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001107 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001108 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001109
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001110 RecordImages(m_renderTargets);
GregF3156cb02014-12-02 15:41:44 -07001111}
1112
Tony Barbour6918cd52015-04-09 12:58:51 -06001113TEST_F(VkRenderTest, GreyCirclesonBlueFade)
GregF3156cb02014-12-02 15:41:44 -07001114{
1115 // This tests reading gl_ClipDistance from FS
1116
1117 static const char *vertShaderText =
1118 "#version 330\n"
1119 "#extension GL_ARB_separate_shader_objects : enable\n"
1120 "#extension GL_ARB_shading_language_420pack : enable\n"
1121 "out gl_PerVertex {\n"
1122 " vec4 gl_Position;\n"
1123 " float gl_ClipDistance[1];\n"
1124 "};\n"
1125 "layout (location = 0) in vec4 pos;\n"
1126 "layout (location = 0) out vec4 outColor;\n"
1127 "layout (location = 1) out vec4 outColor2;\n"
1128 "void main() {\n"
1129 " gl_Position = pos;\n"
1130 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1131 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1132 " float dists[3];\n"
1133 " dists[0] = 0.0;\n"
1134 " dists[1] = 1.0;\n"
1135 " dists[2] = 1.0;\n"
1136 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1137 "}\n";
1138
1139
1140 static const char *fragShaderText =
1141 //"#version 140\n"
1142 "#version 330\n"
1143 "#extension GL_ARB_separate_shader_objects : enable\n"
1144 "#extension GL_ARB_shading_language_420pack : enable\n"
1145 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1146 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1147 "layout (location = 0) in vec4 color;\n"
1148 "layout (location = 1) in vec4 color2;\n"
1149 "void main() {\n"
1150 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1151 " float dist_squared = dot(pos, pos);\n"
1152 " gl_FragColor = (dist_squared < 400.0)\n"
1153 " ? color * gl_ClipDistance[0]\n"
1154 " : color2;\n"
1155 "}\n";
1156
1157 ASSERT_NO_FATAL_FAILURE(InitState());
1158 ASSERT_NO_FATAL_FAILURE(InitViewport());
1159
Tony Barbour6918cd52015-04-09 12:58:51 -06001160 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001161 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001162
Tony Barbour6918cd52015-04-09 12:58:51 -06001163 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1164 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF3156cb02014-12-02 15:41:44 -07001165
Tony Barbour6918cd52015-04-09 12:58:51 -06001166 VkPipelineObj pipelineobj(m_device);
GregF3156cb02014-12-02 15:41:44 -07001167 pipelineobj.AddShader(&vs);
1168 pipelineobj.AddShader(&ps);
1169
Tony Barbour6918cd52015-04-09 12:58:51 -06001170 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001171 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001172
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001173#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001174 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001175 MESH_BIND_ID, // binding ID
1176 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001177 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF3156cb02014-12-02 15:41:44 -07001178 };
1179
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001180 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001181 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1182 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001183 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001184 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF3156cb02014-12-02 15:41:44 -07001185
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001186 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF3156cb02014-12-02 15:41:44 -07001187 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001188 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF3156cb02014-12-02 15:41:44 -07001189
Tony Barbour664accc2015-01-09 12:55:14 -07001190 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06001191 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07001192 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF3156cb02014-12-02 15:41:44 -07001193
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001194 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07001195
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001196 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001197
1198 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1199#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001200 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001201 pDSDumpDot((char*)"triTest2.dot");
1202#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001203
1204 // render two triangles
Tony Barbour664accc2015-01-09 12:55:14 -07001205 cmdBuffer.Draw(0, 6, 0, 1);
1206
1207 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001208 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001209 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001210
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001211 RecordImages(m_renderTargets);
GregF3156cb02014-12-02 15:41:44 -07001212}
Tony Barboure2c58df2014-11-25 13:18:32 -07001213
Tony Barbour6918cd52015-04-09 12:58:51 -06001214TEST_F(VkRenderTest, GreyCirclesonBlueDiscard)
GregF42226582014-12-02 17:19:34 -07001215{
1216 static const char *vertShaderText =
1217 "#version 140\n"
1218 "#extension GL_ARB_separate_shader_objects : enable\n"
1219 "#extension GL_ARB_shading_language_420pack : enable\n"
1220 "layout (location = 0) in vec4 pos;\n"
1221 "layout (location = 0) out vec4 outColor;\n"
1222 "layout (location = 1) out vec4 outColor2;\n"
1223 "void main() {\n"
1224 " gl_Position = pos;\n"
1225 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1226 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1227 "}\n";
1228
1229
1230 static const char *fragShaderText =
GregF42226582014-12-02 17:19:34 -07001231 "#version 330\n"
1232 "#extension GL_ARB_separate_shader_objects : enable\n"
1233 "#extension GL_ARB_shading_language_420pack : enable\n"
1234 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1235 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1236 "layout (location = 0) in vec4 color;\n"
1237 "layout (location = 1) in vec4 color2;\n"
1238 "void main() {\n"
1239 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1240 " float dist_squared = dot(pos, pos);\n"
1241 " if (dist_squared < 100.0)\n"
1242 " discard;\n"
1243 " gl_FragColor = (dist_squared < 400.0)\n"
1244 " ? color\n"
1245 " : color2;\n"
1246 "}\n";
1247
1248 ASSERT_NO_FATAL_FAILURE(InitState());
1249 ASSERT_NO_FATAL_FAILURE(InitViewport());
1250
Tony Barbour6918cd52015-04-09 12:58:51 -06001251 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001252 meshBuffer.BufferMemoryBarrier();
GregF42226582014-12-02 17:19:34 -07001253
Tony Barbour6918cd52015-04-09 12:58:51 -06001254 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1255 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF42226582014-12-02 17:19:34 -07001256
Tony Barbour6918cd52015-04-09 12:58:51 -06001257 VkPipelineObj pipelineobj(m_device);
GregF42226582014-12-02 17:19:34 -07001258 pipelineobj.AddShader(&vs);
1259 pipelineobj.AddShader(&ps);
1260
Tony Barbour6918cd52015-04-09 12:58:51 -06001261 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001262 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001263
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001264#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001265 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001266 MESH_BIND_ID, // binding ID
1267 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001268 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF42226582014-12-02 17:19:34 -07001269 };
1270
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001271 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001272 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1273 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001274 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001275 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF42226582014-12-02 17:19:34 -07001276
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001277 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF42226582014-12-02 17:19:34 -07001278 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001279 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF42226582014-12-02 17:19:34 -07001280
Tony Barbour664accc2015-01-09 12:55:14 -07001281 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06001282 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07001283 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1284
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001285 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07001286
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001287 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001288
1289 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1290#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001291 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001292 pDSDumpDot((char*)"triTest2.dot");
1293#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001294
1295 // render two triangles
Tony Barbour664accc2015-01-09 12:55:14 -07001296 cmdBuffer.Draw(0, 6, 0, 1);
1297
1298 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001299 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001300 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001301
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001302 RecordImages(m_renderTargets);
GregF42226582014-12-02 17:19:34 -07001303}
1304
1305
Tony Barbour6918cd52015-04-09 12:58:51 -06001306TEST_F(VkRenderTest, TriangleVSUniform)
Cody Northrop66594a72014-10-10 14:49:36 -06001307{
1308 static const char *vertShaderText =
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001309 "#version 140\n"
1310 "#extension GL_ARB_separate_shader_objects : enable\n"
1311 "#extension GL_ARB_shading_language_420pack : enable\n"
1312 "\n"
1313 "layout(binding = 0) uniform buf {\n"
1314 " mat4 MVP;\n"
1315 "} ubuf;\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001316 "void main() {\n"
1317 " vec2 vertices[3];"
1318 " vertices[0] = vec2(-0.5, -0.5);\n"
1319 " vertices[1] = vec2( 0.5, -0.5);\n"
1320 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001321 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001322 "}\n";
1323
1324 static const char *fragShaderText =
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001325 "#version 130\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001326 "void main() {\n"
Cody Northropbb38ad32014-10-10 15:45:00 -06001327 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001328 "}\n";
1329
Tony Barboure2c58df2014-11-25 13:18:32 -07001330 ASSERT_NO_FATAL_FAILURE(InitState());
1331 ASSERT_NO_FATAL_FAILURE(InitViewport());
1332
Courtney Goeltzenleuchterfdcfb9f2014-10-10 18:04:39 -06001333 // Create identity matrix
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001334 glm::mat4 Projection = glm::mat4(1.0f);
1335 glm::mat4 View = glm::mat4(1.0f);
1336 glm::mat4 Model = glm::mat4(1.0f);
1337 glm::mat4 MVP = Projection * View * Model;
1338 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1339
Tony Barbour6918cd52015-04-09 12:58:51 -06001340 VkConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1341 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1342 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001343
Tony Barbour6918cd52015-04-09 12:58:51 -06001344 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07001345 pipelineobj.AddShader(&vs);
1346 pipelineobj.AddShader(&ps);
1347
1348 // Create descriptor set and attach the constant buffer to it
Tony Barbour6918cd52015-04-09 12:58:51 -06001349 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001350 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07001351
Tony Barbour664accc2015-01-09 12:55:14 -07001352 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06001353 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07001354 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07001355
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001356 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07001357
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001358 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001359
1360 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1361#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001362 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001363 pDSDumpDot((char*)"triTest2.dot");
1364#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001365
1366 // render two triangles
Tony Barbour664accc2015-01-09 12:55:14 -07001367 cmdBuffer.Draw(0, 6, 0, 1);
1368
1369 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001370 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001371 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001372
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001373 RecordImages(m_renderTargets);
Tony Barbour664accc2015-01-09 12:55:14 -07001374
1375 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001376}
1377
Tony Barbour6918cd52015-04-09 12:58:51 -06001378TEST_F(VkRenderTest, MixTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07001379{
1380 // This tests location applied to varyings. Notice that we have switched foo
1381 // and bar in the FS. The triangle should be blended with red, green and blue
1382 // corners.
1383 static const char *vertShaderText =
1384 "#version 140\n"
1385 "#extension GL_ARB_separate_shader_objects : enable\n"
1386 "#extension GL_ARB_shading_language_420pack : enable\n"
1387 "layout (location=0) out vec4 bar;\n"
1388 "layout (location=1) out vec4 foo;\n"
1389 "layout (location=2) out float scale;\n"
1390 "vec2 vertices[3];\n"
1391 "void main() {\n"
1392 " vertices[0] = vec2(-1.0, -1.0);\n"
1393 " vertices[1] = vec2( 1.0, -1.0);\n"
1394 " vertices[2] = vec2( 0.0, 1.0);\n"
1395 "vec4 colors[3];\n"
1396 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1397 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1398 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1399 " foo = colors[gl_VertexID % 3];\n"
1400 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1401 " scale = 1.0;\n"
1402 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1403 "}\n";
1404
1405 static const char *fragShaderText =
1406 "#version 140\n"
1407 "#extension GL_ARB_separate_shader_objects : enable\n"
1408 "#extension GL_ARB_shading_language_420pack : enable\n"
1409 "layout (location = 1) in vec4 bar;\n"
1410 "layout (location = 0) in vec4 foo;\n"
1411 "layout (location = 2) in float scale;\n"
1412 "void main() {\n"
1413 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
1414 "}\n";
1415
1416 ASSERT_NO_FATAL_FAILURE(InitState());
1417 ASSERT_NO_FATAL_FAILURE(InitViewport());
1418
Tony Barbour6918cd52015-04-09 12:58:51 -06001419 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1420 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001421
Tony Barbour6918cd52015-04-09 12:58:51 -06001422 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07001423 pipelineobj.AddShader(&vs);
1424 pipelineobj.AddShader(&ps);
1425
Tony Barbour6918cd52015-04-09 12:58:51 -06001426 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour831062d2015-04-02 15:43:15 -06001427 descriptorSet.AppendDummy();
Tony Barboure2c58df2014-11-25 13:18:32 -07001428
Tony Barbour664accc2015-01-09 12:55:14 -07001429 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06001430 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07001431 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1432
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001433 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07001434
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001435 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001436
1437#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001438 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001439 pDSDumpDot((char*)"triTest2.dot");
1440#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001441
Tony Barbour664accc2015-01-09 12:55:14 -07001442 // render triangle
1443 cmdBuffer.Draw(0, 3, 0, 1);
1444
1445 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001446 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001447 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001448
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001449 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001450}
1451
Tony Barbour6918cd52015-04-09 12:58:51 -06001452TEST_F(VkRenderTest, QuadVertFetchAndVertID)
Tony Barboure2c58df2014-11-25 13:18:32 -07001453{
1454 // This tests that attributes work in the presence of gl_VertexID
1455
1456 static const char *vertShaderText =
1457 "#version 140\n"
1458 "#extension GL_ARB_separate_shader_objects : enable\n"
1459 "#extension GL_ARB_shading_language_420pack : enable\n"
1460 //XYZ1( -1, -1, -1 )
1461 "layout (location = 0) in vec4 pos;\n"
1462 //XYZ1( 0.f, 0.f, 0.f )
1463 "layout (location = 1) in vec4 inColor;\n"
1464 "layout (location = 0) out vec4 outColor;\n"
1465 "void main() {\n"
1466 " outColor = inColor;\n"
1467 " vec4 vertices[3];"
1468 " vertices[gl_VertexID % 3] = pos;\n"
1469 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1470 "}\n";
1471
1472
1473 static const char *fragShaderText =
1474 "#version 140\n"
1475 "#extension GL_ARB_separate_shader_objects : enable\n"
1476 "#extension GL_ARB_shading_language_420pack : enable\n"
1477 "layout (location = 0) in vec4 color;\n"
1478 "void main() {\n"
1479 " gl_FragColor = color;\n"
1480 "}\n";
1481
1482 ASSERT_NO_FATAL_FAILURE(InitState());
1483 ASSERT_NO_FATAL_FAILURE(InitViewport());
1484
Tony Barbour6918cd52015-04-09 12:58:51 -06001485 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001486 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07001487
Tony Barbour6918cd52015-04-09 12:58:51 -06001488 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1489 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001490
Tony Barbour6918cd52015-04-09 12:58:51 -06001491 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07001492 pipelineobj.AddShader(&vs);
1493 pipelineobj.AddShader(&ps);
1494
Tony Barbour6918cd52015-04-09 12:58:51 -06001495 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001496 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001497
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001498#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001499 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001500 MESH_BUF_ID, // Binding ID
1501 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001502 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barboure2c58df2014-11-25 13:18:32 -07001503 };
1504
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001505 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001506 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1507 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001508 vi_attribs[0].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001509 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1510 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1511 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001512 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001513 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -07001514
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001515 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001516 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001517 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barboure2c58df2014-11-25 13:18:32 -07001518
Tony Barbour664accc2015-01-09 12:55:14 -07001519 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06001520 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07001521 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1522
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001523 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07001524
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001525 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001526
1527 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1528#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001529 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001530 pDSDumpDot((char*)"triTest2.dot");
1531#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001532
1533 // render two triangles
Tony Barbour664accc2015-01-09 12:55:14 -07001534 cmdBuffer.Draw(0, 6, 0, 1);
1535
1536 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001537 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001538 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001539
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001540 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001541}
1542
Tony Barbour6918cd52015-04-09 12:58:51 -06001543TEST_F(VkRenderTest, QuadSparseVertFetch)
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001544{
1545 // This tests that attributes work in the presence of gl_VertexID
1546
1547 static const char *vertShaderText =
1548 "#version 140\n"
1549 "#extension GL_ARB_separate_shader_objects : enable\n"
1550 "#extension GL_ARB_shading_language_420pack : enable\n"
1551 //XYZ1( -1, -1, -1 )
1552 "layout (location = 1) in vec4 pos;\n"
1553 "layout (location = 4) in vec4 inColor;\n"
1554 //XYZ1( 0.f, 0.f, 0.f )
1555 "layout (location = 0) out vec4 outColor;\n"
1556 "void main() {\n"
1557 " outColor = inColor;\n"
1558 " gl_Position = pos;\n"
1559 "}\n";
1560
1561
1562 static const char *fragShaderText =
1563 "#version 140\n"
1564 "#extension GL_ARB_separate_shader_objects : enable\n"
1565 "#extension GL_ARB_shading_language_420pack : enable\n"
1566 "layout (location = 0) in vec4 color;\n"
1567 "void main() {\n"
1568 " gl_FragColor = color;\n"
1569 "}\n";
1570
1571 ASSERT_NO_FATAL_FAILURE(InitState());
1572 ASSERT_NO_FATAL_FAILURE(InitViewport());
1573
1574 struct VDATA
1575 {
1576 float t1, t2, t3, t4; // filler data
1577 float posX, posY, posZ, posW; // Position data
1578 float r, g, b, a; // Color
1579 };
1580 const struct VDATA vData[] =
1581 {
1582 { XYZ1(0, 0, 0), XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
1583 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1584 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1585 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1586 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1587 { XYZ1(0, 0, 0), XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
1588 };
1589
Tony Barbour6918cd52015-04-09 12:58:51 -06001590 VkConstantBufferObj meshBuffer(m_device,sizeof(vData)/sizeof(vData[0]),sizeof(vData[0]), vData);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001591 meshBuffer.BufferMemoryBarrier();
1592
Tony Barbour6918cd52015-04-09 12:58:51 -06001593 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1594 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001595
Tony Barbour6918cd52015-04-09 12:58:51 -06001596 VkPipelineObj pipelineobj(m_device);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001597 pipelineobj.AddShader(&vs);
1598 pipelineobj.AddShader(&ps);
1599
Tony Barbour6918cd52015-04-09 12:58:51 -06001600 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001601 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001602
1603#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001604 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001605 MESH_BUF_ID, // Binding ID
1606 sizeof(vData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001607 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001608 };
1609
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001610 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001611 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1612 vi_attribs[0].location = 4;
Tony Barbourd1c35722015-04-16 15:59:00 -06001613 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001614 vi_attribs[0].offsetInBytes = sizeof(float) * 4 * 2; // Offset of first element in bytes from base of vertex
1615 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1616 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001617 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001618 vi_attribs[1].offsetInBytes = sizeof(float) * 4 * 1; // Offset of first element in bytes from base of vertex
1619
1620 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
1621 pipelineobj.AddVertexInputBindings(&vi_binding, 1);
1622 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
1623
1624 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06001625 VkCommandBufferObj cmdBuffer(m_device);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001626 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1627
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001628 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001629
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001630 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001631
1632 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BUF_ID);
1633#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001634 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001635 pDSDumpDot((char*)"triTest2.dot");
1636#endif
1637
1638 // render two triangles
1639 cmdBuffer.Draw(0, 6, 0, 1);
1640
1641 // finalize recording of the command buffer
1642 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001643 cmdBuffer.QueueCommandBuffer();
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001644
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001645 RecordImages(m_renderTargets);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001646}
1647
Tony Barbour6918cd52015-04-09 12:58:51 -06001648TEST_F(VkRenderTest, TriVertFetchDeadAttr)
Tony Barboure2c58df2014-11-25 13:18:32 -07001649{
1650 // This tests that attributes work in the presence of gl_VertexID
1651 // and a dead attribute in position 0. Draws a triangle with yellow,
1652 // red and green corners, starting at top and going clockwise.
1653
1654 static const char *vertShaderText =
1655 "#version 140\n"
1656 "#extension GL_ARB_separate_shader_objects : enable\n"
1657 "#extension GL_ARB_shading_language_420pack : enable\n"
1658 //XYZ1( -1, -1, -1 )
1659 "layout (location = 0) in vec4 pos;\n"
1660 //XYZ1( 0.f, 0.f, 0.f )
1661 "layout (location = 1) in vec4 inColor;\n"
1662 "layout (location = 0) out vec4 outColor;\n"
1663 "void main() {\n"
1664 " outColor = inColor;\n"
1665 " vec2 vertices[3];"
1666 " vertices[0] = vec2(-1.0, -1.0);\n"
1667 " vertices[1] = vec2( 1.0, -1.0);\n"
1668 " vertices[2] = vec2( 0.0, 1.0);\n"
1669 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1670 "}\n";
1671
1672
1673 static const char *fragShaderText =
1674 "#version 140\n"
1675 "#extension GL_ARB_separate_shader_objects : enable\n"
1676 "#extension GL_ARB_shading_language_420pack : enable\n"
1677 "layout (location = 0) in vec4 color;\n"
1678 "void main() {\n"
1679 " gl_FragColor = color;\n"
1680 "}\n";
1681
1682 ASSERT_NO_FATAL_FAILURE(InitState());
1683 ASSERT_NO_FATAL_FAILURE(InitViewport());
1684
Tony Barbour6918cd52015-04-09 12:58:51 -06001685 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001686 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07001687
Tony Barbour6918cd52015-04-09 12:58:51 -06001688 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1689 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001690
Tony Barbour6918cd52015-04-09 12:58:51 -06001691 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07001692 pipelineobj.AddShader(&vs);
1693 pipelineobj.AddShader(&ps);
1694
Tony Barbour6918cd52015-04-09 12:58:51 -06001695 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001696 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001697
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001698#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001699 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001700 MESH_BUF_ID, // Binding ID
1701 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001702 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barboure2c58df2014-11-25 13:18:32 -07001703 };
1704
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001705 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001706 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1707 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001708 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001709 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1710 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1711 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001712 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001713 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -07001714
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001715 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001716 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001717 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barboure2c58df2014-11-25 13:18:32 -07001718
Tony Barbour664accc2015-01-09 12:55:14 -07001719 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06001720 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07001721 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07001722
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001723 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07001724
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001725 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001726
1727 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1728#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001729 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001730 pDSDumpDot((char*)"triTest2.dot");
1731#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001732
1733 // render two triangles
Tony Barbour664accc2015-01-09 12:55:14 -07001734 cmdBuffer.Draw(0, 6, 0, 1);
1735
1736 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001737 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001738 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001739
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001740 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001741}
1742
Tony Barbour6918cd52015-04-09 12:58:51 -06001743TEST_F(VkRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001744{
1745 static const char *vertShaderText =
1746 "#version 140\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001747 "#extension GL_ARB_separate_shader_objects : enable\n"
1748 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001749 "layout (std140) uniform bufferVals {\n"
1750 " mat4 mvp;\n"
1751 "} myBufferVals;\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001752 "layout (location = 0) in vec4 pos;\n"
1753 "layout (location = 1) in vec4 inColor;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001754 "out vec4 outColor;\n"
1755 "void main() {\n"
1756 " outColor = inColor;\n"
1757 " gl_Position = myBufferVals.mvp * pos;\n"
1758 "}\n";
1759
1760 static const char *fragShaderText =
1761 "#version 130\n"
1762 "in vec4 color;\n"
1763 "void main() {\n"
1764 " gl_FragColor = color;\n"
1765 "}\n";
Tony Barboure2c58df2014-11-25 13:18:32 -07001766 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001767
Tony Barboure2c58df2014-11-25 13:18:32 -07001768 glm::mat4 View = glm::lookAt(
1769 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1770 glm::vec3(0,0,0), // and looks at the origin
1771 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
1772 );
1773
1774 glm::mat4 Model = glm::mat4(1.0f);
1775
1776 glm::mat4 MVP = Projection * View * Model;
1777
1778 ASSERT_NO_FATAL_FAILURE(InitState());
1779 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour1c45ce02015-03-27 17:03:18 -06001780 m_depthStencil->Init(m_device, m_width, m_height);
Tony Barboure2c58df2014-11-25 13:18:32 -07001781
Tony Barbour6918cd52015-04-09 12:58:51 -06001782 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 -07001783 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1784
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001785 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barboure2c58df2014-11-25 13:18:32 -07001786
Tony Barbour6918cd52015-04-09 12:58:51 -06001787 VkConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1788 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1789 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001790
Tony Barbour6918cd52015-04-09 12:58:51 -06001791 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07001792 pipelineobj.AddShader(&vs);
1793 pipelineobj.AddShader(&ps);
1794
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001795 VkPipelineDsStateCreateInfo ds_state;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001796 ds_state.depthTestEnable = VK_TRUE;
1797 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbourd1c35722015-04-16 15:59:00 -06001798 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001799 ds_state.depthBoundsEnable = VK_FALSE;
1800 ds_state.stencilTestEnable = VK_FALSE;
1801 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
1802 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
1803 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbourd1c35722015-04-16 15:59:00 -06001804 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
1805 ds_state.format = VK_FORMAT_D32_SFLOAT;
Tony Barbourf52346d2015-01-16 14:27:35 -07001806 ds_state.front = ds_state.back;
1807 pipelineobj.SetDepthStencil(&ds_state);
1808
Tony Barbour6918cd52015-04-09 12:58:51 -06001809 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001810 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07001811
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001812#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001813 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001814 MESH_BUF_ID, // Binding ID
1815 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001816 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001817 };
Tony Barboure2c58df2014-11-25 13:18:32 -07001818
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001819 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001820 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1821 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001822 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001823 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1824 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1825 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001826 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001827 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -07001828
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001829 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001830 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001831 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barboure2c58df2014-11-25 13:18:32 -07001832
Tony Barbour1c45ce02015-03-27 17:03:18 -06001833 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour1c45ce02015-03-27 17:03:18 -06001834
Tony Barbour6918cd52015-04-09 12:58:51 -06001835 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour1fde6942015-01-09 10:06:53 -07001836 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07001837
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001838 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001839 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barboure2c58df2014-11-25 13:18:32 -07001840
Tony Barbour1fde6942015-01-09 10:06:53 -07001841 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1842#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001843 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour1fde6942015-01-09 10:06:53 -07001844 pDSDumpDot((char*)"triTest2.dot");
1845#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001846
1847 // render triangles
Tony Barbour1fde6942015-01-09 10:06:53 -07001848 cmdBuffer.Draw(0, 36, 0, 1);
1849
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001850
Tony Barbour1fde6942015-01-09 10:06:53 -07001851 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001852 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001853 cmdBuffer.QueueCommandBuffer();
Tony Barbour1fde6942015-01-09 10:06:53 -07001854
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001855 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001856}
1857
Tony Barbour6918cd52015-04-09 12:58:51 -06001858TEST_F(VkRenderTest, VSTexture)
Tony Barboure2c58df2014-11-25 13:18:32 -07001859{
1860 // The expected result from this test is a green and red triangle;
1861 // one red vertex on the left, two green vertices on the right.
1862 static const char *vertShaderText =
1863 "#version 130\n"
1864 "out vec4 texColor;\n"
1865 "uniform sampler2D surface;\n"
1866 "void main() {\n"
1867 " vec2 vertices[3];"
1868 " vertices[0] = vec2(-0.5, -0.5);\n"
1869 " vertices[1] = vec2( 0.5, -0.5);\n"
1870 " vertices[2] = vec2( 0.5, 0.5);\n"
1871 " vec2 positions[3];"
1872 " positions[0] = vec2( 0.0, 0.0);\n"
1873 " positions[1] = vec2( 0.25, 0.1);\n"
1874 " positions[2] = vec2( 0.1, 0.25);\n"
1875 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1876 " texColor = textureLod(surface, samplePos, 0.0);\n"
1877 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1878 "}\n";
1879
1880 static const char *fragShaderText =
1881 "#version 130\n"
1882 "in vec4 texColor;\n"
1883 "void main() {\n"
1884 " gl_FragColor = texColor;\n"
1885 "}\n";
1886
1887 ASSERT_NO_FATAL_FAILURE(InitState());
1888 ASSERT_NO_FATAL_FAILURE(InitViewport());
1889
Tony Barbour6918cd52015-04-09 12:58:51 -06001890 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1891 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
1892 VkSamplerObj sampler(m_device);
1893 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07001894
Tony Barbour6918cd52015-04-09 12:58:51 -06001895 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07001896 pipelineobj.AddShader(&vs);
1897 pipelineobj.AddShader(&ps);
1898
Tony Barbour6918cd52015-04-09 12:58:51 -06001899 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08001900 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07001901
Tony Barbour664accc2015-01-09 12:55:14 -07001902 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06001903 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07001904 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07001905
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001906 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07001907
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001908 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001909
1910#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001911 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001912 pDSDumpDot((char*)"triTest2.dot");
1913#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001914
Tony Barbour664accc2015-01-09 12:55:14 -07001915 // render triangle
1916 cmdBuffer.Draw(0, 3, 0, 1);
1917
1918 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001919 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001920 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001921
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001922 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001923}
Tony Barbour6918cd52015-04-09 12:58:51 -06001924TEST_F(VkRenderTest, TexturedTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07001925{
1926 // The expected result from this test is a red and green checkered triangle
1927 static const char *vertShaderText =
1928 "#version 140\n"
1929 "#extension GL_ARB_separate_shader_objects : enable\n"
1930 "#extension GL_ARB_shading_language_420pack : enable\n"
1931 "layout (location = 0) out vec2 samplePos;\n"
1932 "void main() {\n"
1933 " vec2 vertices[3];"
1934 " vertices[0] = vec2(-0.5, -0.5);\n"
1935 " vertices[1] = vec2( 0.5, -0.5);\n"
1936 " vertices[2] = vec2( 0.5, 0.5);\n"
1937 " vec2 positions[3];"
1938 " positions[0] = vec2( 0.0, 0.0);\n"
1939 " positions[1] = vec2( 1.0, 0.0);\n"
1940 " positions[2] = vec2( 1.0, 1.0);\n"
1941 " samplePos = positions[gl_VertexID % 3];\n"
1942 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1943 "}\n";
1944
1945 static const char *fragShaderText =
1946 "#version 140\n"
1947 "#extension GL_ARB_separate_shader_objects : enable\n"
1948 "#extension GL_ARB_shading_language_420pack : enable\n"
1949 "layout (location = 0) in vec2 samplePos;\n"
1950 "layout (binding = 0) uniform sampler2D surface;\n"
1951 "layout (location=0) out vec4 outColor;\n"
1952 "void main() {\n"
1953 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1954 " outColor = texColor;\n"
1955 "}\n";
1956
1957 ASSERT_NO_FATAL_FAILURE(InitState());
1958 ASSERT_NO_FATAL_FAILURE(InitViewport());
1959
Tony Barbour6918cd52015-04-09 12:58:51 -06001960 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1961 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
1962 VkSamplerObj sampler(m_device);
1963 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07001964
Tony Barbour6918cd52015-04-09 12:58:51 -06001965 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07001966 pipelineobj.AddShader(&vs);
1967 pipelineobj.AddShader(&ps);
1968
Tony Barbour6918cd52015-04-09 12:58:51 -06001969 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08001970 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07001971
Tony Barbour664accc2015-01-09 12:55:14 -07001972 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06001973 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07001974 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1975
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001976 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07001977
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001978 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001979
1980#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001981 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001982 pDSDumpDot((char*)"triTest2.dot");
1983#endif
1984 // render triangle
1985 cmdBuffer.Draw(0, 3, 0, 1);
1986
1987 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001988 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001989 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001990
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001991 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001992}
Tony Barbour6918cd52015-04-09 12:58:51 -06001993TEST_F(VkRenderTest, TexturedTriangleClip)
Tony Barboure2c58df2014-11-25 13:18:32 -07001994{
1995 // The expected result from this test is a red and green checkered triangle
1996 static const char *vertShaderText =
1997 "#version 330\n"
1998 "#extension GL_ARB_separate_shader_objects : enable\n"
1999 "#extension GL_ARB_shading_language_420pack : enable\n"
2000 "layout (location = 0) out vec2 samplePos;\n"
2001 "out gl_PerVertex {\n"
2002 " vec4 gl_Position;\n"
2003 " float gl_ClipDistance[1];\n"
2004 "};\n"
2005 "void main() {\n"
2006 " vec2 vertices[3];"
2007 " vertices[0] = vec2(-0.5, -0.5);\n"
2008 " vertices[1] = vec2( 0.5, -0.5);\n"
2009 " vertices[2] = vec2( 0.5, 0.5);\n"
2010 " vec2 positions[3];"
2011 " positions[0] = vec2( 0.0, 0.0);\n"
2012 " positions[1] = vec2( 1.0, 0.0);\n"
2013 " positions[2] = vec2( 1.0, 1.0);\n"
2014 " float dists[3];\n"
2015 " dists[0] = 1.0;\n"
2016 " dists[1] = 1.0;\n"
2017 " dists[2] = -1.0;\n"
2018 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2019 " samplePos = positions[gl_VertexID % 3];\n"
2020 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2021 "}\n";
2022
2023 static const char *fragShaderText =
2024 "#version 140\n"
2025 "#extension GL_ARB_separate_shader_objects : enable\n"
2026 "#extension GL_ARB_shading_language_420pack : enable\n"
2027 "layout (location = 0) in vec2 samplePos;\n"
2028 "layout (binding = 0) uniform sampler2D surface;\n"
2029 "layout (location=0) out vec4 outColor;\n"
2030 "void main() {\n"
2031 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2032 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2033 " outColor = texColor;\n"
2034 "}\n";
2035
2036
2037 ASSERT_NO_FATAL_FAILURE(InitState());
2038 ASSERT_NO_FATAL_FAILURE(InitViewport());
2039
Tony Barbour6918cd52015-04-09 12:58:51 -06002040 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2041 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2042 VkSamplerObj sampler(m_device);
2043 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002044
Tony Barbour6918cd52015-04-09 12:58:51 -06002045 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002046 pipelineobj.AddShader(&vs);
2047 pipelineobj.AddShader(&ps);
2048
Tony Barbour6918cd52015-04-09 12:58:51 -06002049 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002050 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002051
Tony Barbour664accc2015-01-09 12:55:14 -07002052 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06002053 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07002054 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2055
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002056 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07002057
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002058 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002059
2060#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002061 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002062 pDSDumpDot((char*)"triTest2.dot");
2063#endif
2064 // render triangle
2065 cmdBuffer.Draw(0, 3, 0, 1);
2066
2067 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002068 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002069 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002070
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002071 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002072}
Tony Barbour6918cd52015-04-09 12:58:51 -06002073TEST_F(VkRenderTest, FSTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07002074{
2075 // The expected result from this test is a red and green checkered triangle
2076 static const char *vertShaderText =
2077 "#version 140\n"
2078 "#extension GL_ARB_separate_shader_objects : enable\n"
2079 "#extension GL_ARB_shading_language_420pack : enable\n"
2080 "layout (location = 0) out vec2 samplePos;\n"
2081 "void main() {\n"
2082 " vec2 vertices[3];"
2083 " vertices[0] = vec2(-0.5, -0.5);\n"
2084 " vertices[1] = vec2( 0.5, -0.5);\n"
2085 " vertices[2] = vec2( 0.5, 0.5);\n"
2086 " vec2 positions[3];"
2087 " positions[0] = vec2( 0.0, 0.0);\n"
2088 " positions[1] = vec2( 1.0, 0.0);\n"
2089 " positions[2] = vec2( 1.0, 1.0);\n"
2090 " samplePos = positions[gl_VertexID % 3];\n"
2091 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2092 "}\n";
2093
2094 static const char *fragShaderText =
2095 "#version 140\n"
2096 "#extension GL_ARB_separate_shader_objects : enable\n"
2097 "#extension GL_ARB_shading_language_420pack : enable\n"
2098 "layout (location = 0) in vec2 samplePos;\n"
2099 "layout (binding = 0) uniform sampler2D surface;\n"
2100 "layout (location=0) out vec4 outColor;\n"
2101 "void main() {\n"
2102 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2103 " outColor = texColor;\n"
2104 "}\n";
2105
2106 ASSERT_NO_FATAL_FAILURE(InitState());
2107 ASSERT_NO_FATAL_FAILURE(InitViewport());
2108
Tony Barbour6918cd52015-04-09 12:58:51 -06002109 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2110 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2111 VkSamplerObj sampler(m_device);
2112 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002113
Tony Barbour6918cd52015-04-09 12:58:51 -06002114 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002115 pipelineobj.AddShader(&vs);
2116 pipelineobj.AddShader(&ps);
2117
Tony Barbour6918cd52015-04-09 12:58:51 -06002118 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002119 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002120
Tony Barbour664accc2015-01-09 12:55:14 -07002121 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06002122 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07002123 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2124
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002125 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07002126
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002127 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002128
2129#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002130 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002131 pDSDumpDot((char*)"triTest2.dot");
2132#endif
2133 // render triangle
2134 cmdBuffer.Draw(0, 3, 0, 1);
2135
2136 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002137 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002138 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002139
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002140 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002141}
Tony Barbour6918cd52015-04-09 12:58:51 -06002142TEST_F(VkRenderTest, SamplerBindingsTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07002143{
2144 // This test sets bindings on the samplers
2145 // For now we are asserting that sampler and texture pairs
2146 // march in lock step, and are set via GLSL binding. This can
2147 // and will probably change.
2148 // The sampler bindings should match the sampler and texture slot
2149 // number set up by the application.
2150 // This test will result in a blue triangle
2151 static const char *vertShaderText =
2152 "#version 140\n"
2153 "#extension GL_ARB_separate_shader_objects : enable\n"
2154 "#extension GL_ARB_shading_language_420pack : enable\n"
2155 "layout (location = 0) out vec4 samplePos;\n"
2156 "void main() {\n"
2157 " vec2 vertices[3];"
2158 " vertices[0] = vec2(-0.5, -0.5);\n"
2159 " vertices[1] = vec2( 0.5, -0.5);\n"
2160 " vertices[2] = vec2( 0.5, 0.5);\n"
2161 " vec2 positions[3];"
2162 " positions[0] = vec2( 0.0, 0.0);\n"
2163 " positions[1] = vec2( 1.0, 0.0);\n"
2164 " positions[2] = vec2( 1.0, 1.0);\n"
2165 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2166 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2167 "}\n";
2168
2169 static const char *fragShaderText =
2170 "#version 140\n"
2171 "#extension GL_ARB_separate_shader_objects : enable\n"
2172 "#extension GL_ARB_shading_language_420pack : enable\n"
2173 "layout (location = 0) in vec4 samplePos;\n"
2174 "layout (binding = 0) uniform sampler2D surface0;\n"
2175 "layout (binding = 1) uniform sampler2D surface1;\n"
2176 "layout (binding = 12) uniform sampler2D surface2;\n"
2177 "void main() {\n"
2178 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
2179 "}\n";
2180
2181 ASSERT_NO_FATAL_FAILURE(InitState());
2182 ASSERT_NO_FATAL_FAILURE(InitViewport());
2183
Tony Barbour6918cd52015-04-09 12:58:51 -06002184 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2185 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002186
Tony Barbour6918cd52015-04-09 12:58:51 -06002187 VkSamplerObj sampler1(m_device);
2188 VkSamplerObj sampler2(m_device);
2189 VkSamplerObj sampler3(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002190
Tony Barbourebc093f2015-04-01 16:38:10 -06002191 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
Tony Barbour6918cd52015-04-09 12:58:51 -06002192 VkTextureObj texture1(m_device, tex_colors); // Red
Tony Barbourebc093f2015-04-01 16:38:10 -06002193 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
Tony Barbour6918cd52015-04-09 12:58:51 -06002194 VkTextureObj texture2(m_device, tex_colors); // Green
Tony Barbourebc093f2015-04-01 16:38:10 -06002195 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
Tony Barbour6918cd52015-04-09 12:58:51 -06002196 VkTextureObj texture3(m_device, tex_colors); // Blue
Tony Barboure2c58df2014-11-25 13:18:32 -07002197
Tony Barbour6918cd52015-04-09 12:58:51 -06002198 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002199 pipelineobj.AddShader(&vs);
2200 pipelineobj.AddShader(&ps);
2201
Tony Barbour6918cd52015-04-09 12:58:51 -06002202 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002203 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2204 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2205 for (int i = 0; i < 10; i++)
2206 descriptorSet.AppendDummy();
2207 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barboure2c58df2014-11-25 13:18:32 -07002208
Tony Barbour664accc2015-01-09 12:55:14 -07002209 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06002210 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07002211 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2212
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002213 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07002214
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002215 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002216
2217#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002218 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002219 pDSDumpDot((char*)"triTest2.dot");
2220#endif
2221 // render triangle
2222 cmdBuffer.Draw(0, 3, 0, 1);
2223
2224 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002225 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002226 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002227
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002228 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002229}
2230
Tony Barbour6918cd52015-04-09 12:58:51 -06002231TEST_F(VkRenderTest, TriangleVSUniformBlock)
Tony Barboure2c58df2014-11-25 13:18:32 -07002232{
2233 // The expected result from this test is a blue triangle
2234
2235 static const char *vertShaderText =
2236 "#version 140\n"
2237 "#extension GL_ARB_separate_shader_objects : enable\n"
2238 "#extension GL_ARB_shading_language_420pack : enable\n"
2239 "layout (location = 0) out vec4 outColor;\n"
2240 "layout (std140, binding = 0) uniform bufferVals {\n"
2241 " vec4 red;\n"
2242 " vec4 green;\n"
2243 " vec4 blue;\n"
2244 " vec4 white;\n"
2245 "} myBufferVals;\n"
2246 "void main() {\n"
2247 " vec2 vertices[3];"
2248 " vertices[0] = vec2(-0.5, -0.5);\n"
2249 " vertices[1] = vec2( 0.5, -0.5);\n"
2250 " vertices[2] = vec2( 0.5, 0.5);\n"
2251 " outColor = myBufferVals.blue;\n"
2252 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2253 "}\n";
2254
2255 static const char *fragShaderText =
2256 "#version 140\n"
2257 "#extension GL_ARB_separate_shader_objects : enable\n"
2258 "#extension GL_ARB_shading_language_420pack : enable\n"
2259 "layout (location = 0) in vec4 inColor;\n"
2260 "void main() {\n"
2261 " gl_FragColor = inColor;\n"
2262 "}\n";
2263
2264 ASSERT_NO_FATAL_FAILURE(InitState());
2265 ASSERT_NO_FATAL_FAILURE(InitViewport());
2266
Tony Barbour6918cd52015-04-09 12:58:51 -06002267 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2268 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002269
2270 // Let's populate our buffer with the following:
2271 // vec4 red;
2272 // vec4 green;
2273 // vec4 blue;
2274 // vec4 white;
2275 const int valCount = 4 * 4;
2276 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2277 0.0, 1.0, 0.0, 1.0,
2278 0.0, 0.0, 1.0, 1.0,
2279 1.0, 1.0, 1.0, 1.0 };
2280
Tony Barbour6918cd52015-04-09 12:58:51 -06002281 VkConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002282
Tony Barbour6918cd52015-04-09 12:58:51 -06002283 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002284 pipelineobj.AddShader(&vs);
2285 pipelineobj.AddShader(&ps);
2286
Tony Barbour6918cd52015-04-09 12:58:51 -06002287 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002288 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, colorBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002289
Tony Barbour664accc2015-01-09 12:55:14 -07002290 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06002291 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07002292 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2293
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002294 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07002295
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002296 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002297
2298#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002299 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002300 pDSDumpDot((char*)"triTest2.dot");
2301#endif
2302 // render triangle
2303 cmdBuffer.Draw(0, 3, 0, 1);
2304
2305 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002306 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002307 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002308
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002309 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002310}
2311
Tony Barbour6918cd52015-04-09 12:58:51 -06002312TEST_F(VkRenderTest, TriangleFSUniformBlockBinding)
Tony Barboure2c58df2014-11-25 13:18:32 -07002313{
2314 // This test allows the shader to select which buffer it is
2315 // pulling from using layout binding qualifier.
2316 // There are corresponding changes in the compiler stack that
2317 // will select the buffer using binding directly.
2318 // The binding number should match the slot number set up by
2319 // the application.
2320 // The expected result from this test is a purple triangle
2321
2322 static const char *vertShaderText =
2323 "#version 140\n"
2324 "#extension GL_ARB_separate_shader_objects : enable\n"
2325 "#extension GL_ARB_shading_language_420pack : enable\n"
2326 "void main() {\n"
2327 " vec2 vertices[3];"
2328 " vertices[0] = vec2(-0.5, -0.5);\n"
2329 " vertices[1] = vec2( 0.5, -0.5);\n"
2330 " vertices[2] = vec2( 0.5, 0.5);\n"
2331 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2332 "}\n";
2333
2334 static const char *fragShaderText =
2335 "#version 140\n"
2336 "#extension GL_ARB_separate_shader_objects : enable\n"
2337 "#extension GL_ARB_shading_language_420pack : enable\n"
2338 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2339 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2340 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wu11078b02015-01-04 16:27:24 +08002341 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
Tony Barboure2c58df2014-11-25 13:18:32 -07002342 "void main() {\n"
2343 " gl_FragColor = myBlueVal.color;\n"
2344 " gl_FragColor += myRedVal.color;\n"
2345 "}\n";
2346
2347 ASSERT_NO_FATAL_FAILURE(InitState());
2348 ASSERT_NO_FATAL_FAILURE(InitViewport());
2349
Tony Barbour6918cd52015-04-09 12:58:51 -06002350 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2351 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002352
2353 // We're going to create a number of uniform buffers, and then allow
2354 // the shader to select which it wants to read from with a binding
2355
2356 // Let's populate the buffers with a single color each:
2357 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2358 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2359 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wu11078b02015-01-04 16:27:24 +08002360 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barboure2c58df2014-11-25 13:18:32 -07002361
2362 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2363 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2364 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2365 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2366
2367 const int redCount = sizeof(redVals) / sizeof(float);
2368 const int greenCount = sizeof(greenVals) / sizeof(float);
2369 const int blueCount = sizeof(blueVals) / sizeof(float);
2370 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2371
Tony Barbour6918cd52015-04-09 12:58:51 -06002372 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002373
Tony Barbour6918cd52015-04-09 12:58:51 -06002374 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002375
Tony Barbour6918cd52015-04-09 12:58:51 -06002376 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002377
Tony Barbour6918cd52015-04-09 12:58:51 -06002378 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002379
Tony Barbour6918cd52015-04-09 12:58:51 -06002380 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002381 pipelineobj.AddShader(&vs);
2382 pipelineobj.AddShader(&ps);
2383
Tony Barbour6918cd52015-04-09 12:58:51 -06002384 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002385 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2386 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2387 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2388 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002389
Tony Barbour664accc2015-01-09 12:55:14 -07002390 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06002391 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07002392 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002393
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002394 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07002395
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002396 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002397
2398#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002399 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002400 pDSDumpDot((char*)"triTest2.dot");
2401#endif
2402 // render triangle
2403 cmdBuffer.Draw(0, 3, 0, 1);
2404
2405 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002406 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002407 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002408
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002409 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002410}
2411
Tony Barbour6918cd52015-04-09 12:58:51 -06002412TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBinding)
Tony Barboure2c58df2014-11-25 13:18:32 -07002413{
2414 // This test is the same as TriangleFSUniformBlockBinding, but
2415 // it does not provide an instance name.
2416 // The expected result from this test is a purple triangle
2417
2418 static const char *vertShaderText =
2419 "#version 140\n"
2420 "#extension GL_ARB_separate_shader_objects : enable\n"
2421 "#extension GL_ARB_shading_language_420pack : enable\n"
2422 "void main() {\n"
2423 " vec2 vertices[3];"
2424 " vertices[0] = vec2(-0.5, -0.5);\n"
2425 " vertices[1] = vec2( 0.5, -0.5);\n"
2426 " vertices[2] = vec2( 0.5, 0.5);\n"
2427 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2428 "}\n";
2429
2430 static const char *fragShaderText =
2431 "#version 430\n"
2432 "#extension GL_ARB_separate_shader_objects : enable\n"
2433 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002434 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2435 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2436 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wu11078b02015-01-04 16:27:24 +08002437 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northropd43c52e2014-12-05 15:44:14 -07002438 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002439 "void main() {\n"
Cody Northropd43c52e2014-12-05 15:44:14 -07002440 " outColor = blue;\n"
2441 " outColor += red;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002442 "}\n";
2443 ASSERT_NO_FATAL_FAILURE(InitState());
2444 ASSERT_NO_FATAL_FAILURE(InitViewport());
2445
Tony Barbour6918cd52015-04-09 12:58:51 -06002446 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2447 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002448
2449 // We're going to create a number of uniform buffers, and then allow
2450 // the shader to select which it wants to read from with a binding
2451
2452 // Let's populate the buffers with a single color each:
2453 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2454 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2455 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2456 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2457
2458 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2459 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2460 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2461 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2462
2463 const int redCount = sizeof(redVals) / sizeof(float);
2464 const int greenCount = sizeof(greenVals) / sizeof(float);
2465 const int blueCount = sizeof(blueVals) / sizeof(float);
2466 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2467
Tony Barbour6918cd52015-04-09 12:58:51 -06002468 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002469
Tony Barbour6918cd52015-04-09 12:58:51 -06002470 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002471
Tony Barbour6918cd52015-04-09 12:58:51 -06002472 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002473
Tony Barbour6918cd52015-04-09 12:58:51 -06002474 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002475
Tony Barbour6918cd52015-04-09 12:58:51 -06002476 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002477 pipelineobj.AddShader(&vs);
2478 pipelineobj.AddShader(&ps);
2479
Tony Barbour6918cd52015-04-09 12:58:51 -06002480 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002481 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2482 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2483 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2484 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002485
Tony Barbour664accc2015-01-09 12:55:14 -07002486 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06002487 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07002488 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2489
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002490 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07002491
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002492 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002493
2494#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002495 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002496 pDSDumpDot((char*)"triTest2.dot");
2497#endif
2498 // render triangle
2499 cmdBuffer.Draw(0, 3, 0, 1);
2500
2501 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002502 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002503 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002504
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002505 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002506}
2507
Tony Barbour6918cd52015-04-09 12:58:51 -06002508TEST_F(VkRenderTest, CubeWithVertexFetchAndMVPAndTexture)
Tony Barboure2c58df2014-11-25 13:18:32 -07002509{
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 "layout (std140, binding=0) uniform bufferVals {\n"
2515 " mat4 mvp;\n"
2516 "} myBufferVals;\n"
2517 "layout (location=0) in vec4 pos;\n"
2518 "layout (location=0) out vec2 UV;\n"
2519 "void main() {\n"
2520 " vec2 positions[3];"
2521 " positions[0] = vec2( 0.0, 0.0);\n"
2522 " positions[1] = vec2( 0.25, 0.1);\n"
2523 " positions[2] = vec2( 0.1, 0.25);\n"
2524 " UV = positions[gl_VertexID % 3];\n"
2525 " gl_Position = myBufferVals.mvp * pos;\n"
2526 "}\n";
2527
2528 static const char *fragShaderText =
2529 "#version 140\n"
2530 "#extension GL_ARB_separate_shader_objects : enable\n"
2531 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wu11078b02015-01-04 16:27:24 +08002532 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002533 "layout (location=0) out vec4 outColor;\n"
2534 "layout (location=0) in vec2 UV;\n"
2535 "void main() {\n"
2536 " outColor= textureLod(surface, UV, 0.0);\n"
2537 "}\n";
2538 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2539
2540 glm::mat4 View = glm::lookAt(
2541 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2542 glm::vec3(0,0,0), // and looks at the origin
2543 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2544 );
2545
2546 glm::mat4 Model = glm::mat4(1.0f);
2547
2548 glm::mat4 MVP = Projection * View * Model;
2549
2550
2551 ASSERT_NO_FATAL_FAILURE(InitState());
2552 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour1c45ce02015-03-27 17:03:18 -06002553 m_depthStencil->Init(m_device, m_width, m_height);
Tony Barboure2c58df2014-11-25 13:18:32 -07002554
Tony Barbour6918cd52015-04-09 12:58:51 -06002555 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 -07002556 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00002557 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07002558
Mark Lobodzinski17caf572015-01-29 08:55:56 -06002559 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barboure2c58df2014-11-25 13:18:32 -07002560
Tony Barbour6918cd52015-04-09 12:58:51 -06002561 VkConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2562 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2563 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2564 VkSamplerObj sampler(m_device);
2565 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002566
Tony Barbour6918cd52015-04-09 12:58:51 -06002567 VkPipelineObj pipelineobj(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002568 pipelineobj.AddShader(&vs);
2569 pipelineobj.AddShader(&ps);
2570
Tony Barbour6918cd52015-04-09 12:58:51 -06002571 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002572 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mvpBuffer);
Chia-I Wu11078b02015-01-04 16:27:24 +08002573 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002574
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002575#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002576 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002577 MESH_BIND_ID, // binding ID
2578 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002579 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002580 };
Tony Barboure2c58df2014-11-25 13:18:32 -07002581
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002582 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002583 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2584 vi_attribs[0].location = 0; // location
Tony Barbourd1c35722015-04-16 15:59:00 -06002585 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002586 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2587 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2588 vi_attribs[1].location = 1; // location
Tony Barbourd1c35722015-04-16 15:59:00 -06002589 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002590 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -07002591
Tony Barboure2c58df2014-11-25 13:18:32 -07002592 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002593 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2594 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barboure2c58df2014-11-25 13:18:32 -07002595
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002596 VkPipelineDsStateCreateInfo ds_state;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002597 ds_state.depthTestEnable = VK_TRUE;
2598 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbourd1c35722015-04-16 15:59:00 -06002599 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002600 ds_state.depthBoundsEnable = VK_FALSE;
2601 ds_state.stencilTestEnable = VK_FALSE;
2602 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
2603 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
2604 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbourd1c35722015-04-16 15:59:00 -06002605 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
2606 ds_state.format = VK_FORMAT_D32_SFLOAT;
Tony Barbourf52346d2015-01-16 14:27:35 -07002607 ds_state.front = ds_state.back;
2608 pipelineobj.SetDepthStencil(&ds_state);
2609
Tony Barbour1c45ce02015-03-27 17:03:18 -06002610 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour6918cd52015-04-09 12:58:51 -06002611 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07002612 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002613
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002614 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002615
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002616 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002617
2618 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2619#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002620 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002621 pDSDumpDot((char*)"triTest2.dot");
2622#endif
2623 // render triangle
2624 cmdBuffer.Draw(0, 36, 0, 1);
2625
2626 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002627 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002628 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002629
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002630 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002631}
Cody Northropf1990a92014-12-09 11:17:01 -07002632
Tony Barbour6918cd52015-04-09 12:58:51 -06002633TEST_F(VkRenderTest, TriangleMixedSamplerUniformBlockBinding)
Cody Northropf1990a92014-12-09 11:17:01 -07002634{
2635 // This test mixes binding slots of textures and buffers, ensuring
2636 // that sparse and overlapping assignments work.
Cody Northropb110b4f2014-12-09 13:59:39 -07002637 // The expected result from this test is a purple triangle, although
Cody Northropf1990a92014-12-09 11:17:01 -07002638 // you can modify it to move the desired result around.
2639
2640 static const char *vertShaderText =
2641 "#version 140\n"
2642 "#extension GL_ARB_separate_shader_objects : enable\n"
2643 "#extension GL_ARB_shading_language_420pack : enable\n"
2644 "void main() {\n"
2645 " vec2 vertices[3];"
2646 " vertices[0] = vec2(-0.5, -0.5);\n"
2647 " vertices[1] = vec2( 0.5, -0.5);\n"
2648 " vertices[2] = vec2( 0.5, 0.5);\n"
2649 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2650 "}\n";
2651
2652 static const char *fragShaderText =
2653 "#version 430\n"
2654 "#extension GL_ARB_separate_shader_objects : enable\n"
2655 "#extension GL_ARB_shading_language_420pack : enable\n"
2656 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wu11078b02015-01-04 16:27:24 +08002657 "layout (binding = 3) uniform sampler2D surface1;\n"
2658 "layout (binding = 1) uniform sampler2D surface2;\n"
2659 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002660
Cody Northropb110b4f2014-12-09 13:59:39 -07002661
Chia-I Wu11078b02015-01-04 16:27:24 +08002662 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2663 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2664 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2665 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropf1990a92014-12-09 11:17:01 -07002666 "layout (location = 0) out vec4 outColor;\n"
2667 "void main() {\n"
Cody Northropb110b4f2014-12-09 13:59:39 -07002668 " outColor = red * vec4(0.00001);\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002669 " outColor += white * vec4(0.00001);\n"
2670 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropb110b4f2014-12-09 13:59:39 -07002671 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002672 "}\n";
2673 ASSERT_NO_FATAL_FAILURE(InitState());
2674 ASSERT_NO_FATAL_FAILURE(InitViewport());
2675
Tony Barbour6918cd52015-04-09 12:58:51 -06002676 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2677 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northropf1990a92014-12-09 11:17:01 -07002678
Cody Northropf1990a92014-12-09 11:17:01 -07002679 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2680 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2681 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2682 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2683
2684 const int redCount = sizeof(redVals) / sizeof(float);
2685 const int greenCount = sizeof(greenVals) / sizeof(float);
2686 const int blueCount = sizeof(blueVals) / sizeof(float);
2687 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2688
Tony Barbour6918cd52015-04-09 12:58:51 -06002689 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2690 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2691 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2692 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropf1990a92014-12-09 11:17:01 -07002693
Tony Barbourebc093f2015-04-01 16:38:10 -06002694 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour6918cd52015-04-09 12:58:51 -06002695 VkSamplerObj sampler0(m_device);
2696 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbourebc093f2015-04-01 16:38:10 -06002697 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour6918cd52015-04-09 12:58:51 -06002698 VkSamplerObj sampler2(m_device);
2699 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbourebc093f2015-04-01 16:38:10 -06002700 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour6918cd52015-04-09 12:58:51 -06002701 VkSamplerObj sampler4(m_device);
2702 VkTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropb110b4f2014-12-09 13:59:39 -07002703
2704 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2705 // TODO: Get back here ASAP and understand why.
Tony Barbourebc093f2015-04-01 16:38:10 -06002706 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour6918cd52015-04-09 12:58:51 -06002707 VkSamplerObj sampler7(m_device);
2708 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropf1990a92014-12-09 11:17:01 -07002709
Tony Barbour6918cd52015-04-09 12:58:51 -06002710 VkPipelineObj pipelineobj(m_device);
Cody Northropf1990a92014-12-09 11:17:01 -07002711 pipelineobj.AddShader(&vs);
2712 pipelineobj.AddShader(&ps);
2713
Tony Barbour6918cd52015-04-09 12:58:51 -06002714 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002715 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2716 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2717 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2718 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002719 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
Chia-I Wu11078b02015-01-04 16:27:24 +08002720 // swap blue and green
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002721 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2722 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2723 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropf1990a92014-12-09 11:17:01 -07002724
Tony Barbour664accc2015-01-09 12:55:14 -07002725 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06002726 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07002727 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropf1990a92014-12-09 11:17:01 -07002728
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002729 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07002730
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002731 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002732
2733#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002734 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002735 pDSDumpDot((char*)"triTest2.dot");
2736#endif
2737 // render triangle
2738 cmdBuffer.Draw(0, 3, 0, 1);
2739
2740 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002741 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002742 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002743
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002744 RecordImages(m_renderTargets);
Cody Northropf1990a92014-12-09 11:17:01 -07002745}
2746
Tony Barbour6918cd52015-04-09 12:58:51 -06002747TEST_F(VkRenderTest, TriangleMatchingSamplerUniformBlockBinding)
Cody Northropbd531de2014-12-09 19:08:54 -07002748{
2749 // This test matches binding slots of textures and buffers, requiring
2750 // the driver to give them distinct number spaces.
2751 // The expected result from this test is a red triangle, although
2752 // you can modify it to move the desired result around.
2753
2754 static const char *vertShaderText =
2755 "#version 140\n"
2756 "#extension GL_ARB_separate_shader_objects : enable\n"
2757 "#extension GL_ARB_shading_language_420pack : enable\n"
2758 "void main() {\n"
2759 " vec2 vertices[3];"
2760 " vertices[0] = vec2(-0.5, -0.5);\n"
2761 " vertices[1] = vec2( 0.5, -0.5);\n"
2762 " vertices[2] = vec2( 0.5, 0.5);\n"
2763 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2764 "}\n";
2765
2766 static const char *fragShaderText =
2767 "#version 430\n"
2768 "#extension GL_ARB_separate_shader_objects : enable\n"
2769 "#extension GL_ARB_shading_language_420pack : enable\n"
2770 "layout (binding = 0) uniform sampler2D surface0;\n"
2771 "layout (binding = 1) uniform sampler2D surface1;\n"
2772 "layout (binding = 2) uniform sampler2D surface2;\n"
2773 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wu11078b02015-01-04 16:27:24 +08002774 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2775 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2776 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2777 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropbd531de2014-12-09 19:08:54 -07002778 "layout (location = 0) out vec4 outColor;\n"
2779 "void main() {\n"
2780 " outColor = red;// * vec4(0.00001);\n"
2781 " outColor += white * vec4(0.00001);\n"
2782 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2783 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2784 "}\n";
2785 ASSERT_NO_FATAL_FAILURE(InitState());
2786 ASSERT_NO_FATAL_FAILURE(InitViewport());
2787
Tony Barbour6918cd52015-04-09 12:58:51 -06002788 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2789 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northropbd531de2014-12-09 19:08:54 -07002790
2791 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2792 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2793 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2794 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2795
2796 const int redCount = sizeof(redVals) / sizeof(float);
2797 const int greenCount = sizeof(greenVals) / sizeof(float);
2798 const int blueCount = sizeof(blueVals) / sizeof(float);
2799 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2800
Tony Barbour6918cd52015-04-09 12:58:51 -06002801 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2802 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2803 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2804 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropbd531de2014-12-09 19:08:54 -07002805
Tony Barbourebc093f2015-04-01 16:38:10 -06002806 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour6918cd52015-04-09 12:58:51 -06002807 VkSamplerObj sampler0(m_device);
2808 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbourebc093f2015-04-01 16:38:10 -06002809 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour6918cd52015-04-09 12:58:51 -06002810 VkSamplerObj sampler2(m_device);
2811 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbourebc093f2015-04-01 16:38:10 -06002812 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour6918cd52015-04-09 12:58:51 -06002813 VkSamplerObj sampler4(m_device);
2814 VkTextureObj texture4(m_device, tex_colors); // Light Green
Tony Barbourebc093f2015-04-01 16:38:10 -06002815 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour6918cd52015-04-09 12:58:51 -06002816 VkSamplerObj sampler7(m_device);
2817 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropbd531de2014-12-09 19:08:54 -07002818
Tony Barbour6918cd52015-04-09 12:58:51 -06002819 VkPipelineObj pipelineobj(m_device);
Cody Northropbd531de2014-12-09 19:08:54 -07002820 pipelineobj.AddShader(&vs);
2821 pipelineobj.AddShader(&ps);
2822
Tony Barbour6918cd52015-04-09 12:58:51 -06002823 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002824 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2825 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2826 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2827 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002828 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2829 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2830 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2831 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropbd531de2014-12-09 19:08:54 -07002832
Tony Barbour664accc2015-01-09 12:55:14 -07002833 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06002834 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour664accc2015-01-09 12:55:14 -07002835 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropbd531de2014-12-09 19:08:54 -07002836
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002837 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour664accc2015-01-09 12:55:14 -07002838
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002839 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002840
2841#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002842 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002843 pDSDumpDot((char*)"triTest2.dot");
2844#endif
2845 // render triangle
2846 cmdBuffer.Draw(0, 3, 0, 1);
2847
2848 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002849 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06002850 cmdBuffer.QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002851
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002852 RecordImages(m_renderTargets);
Cody Northropbd531de2014-12-09 19:08:54 -07002853}
2854
Tony Barbour6918cd52015-04-09 12:58:51 -06002855TEST_F(VkRenderTest, TriangleUniformBufferLayout)
Cody Northrop04ad1202014-12-17 15:26:33 -07002856{
2857 // This test populates a buffer with a variety of different data
2858 // types, then reads them out with a shader.
2859 // The expected result from this test is a green triangle
2860
2861 static const char *vertShaderText =
2862 "#version 140\n"
2863 "#extension GL_ARB_separate_shader_objects : enable\n"
2864 "#extension GL_ARB_shading_language_420pack : enable\n"
2865 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2866 " vec4 fRed;\n"
2867 " vec4 fGreen;\n"
2868 " layout(row_major) mat4 worldToProj;\n"
2869 " layout(row_major) mat4 projToWorld;\n"
2870 " layout(row_major) mat4 worldToView;\n"
2871 " layout(row_major) mat4 viewToProj;\n"
2872 " layout(row_major) mat4 worldToShadow[4];\n"
2873 " float fZero;\n"
2874 " float fOne;\n"
2875 " float fTwo;\n"
2876 " float fThree;\n"
2877 " vec3 fZeroZeroZero;\n"
2878 " float fFour;\n"
2879 " vec3 fZeroZeroOne;\n"
2880 " float fFive;\n"
2881 " vec3 fZeroOneZero;\n"
2882 " float fSix;\n"
2883 " float fSeven;\n"
2884 " float fEight;\n"
2885 " float fNine;\n"
2886 " vec2 fZeroZero;\n"
2887 " vec2 fZeroOne;\n"
2888 " vec4 fBlue;\n"
2889 " vec2 fOneZero;\n"
2890 " vec2 fOneOne;\n"
2891 " vec3 fZeroOneOne;\n"
2892 " float fTen;\n"
2893 " float fEleven;\n"
2894 " float fTwelve;\n"
2895 " vec3 fOneZeroZero;\n"
2896 " vec4 uvOffsets[4];\n"
2897 "};\n"
2898 "layout (location = 0) out vec4 color;"
2899 "void main() {\n"
2900
2901 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2902 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2903 " \n"
2904
2905 // do some exact comparisons, even though we should
2906 // really have an epsilon involved.
2907 " vec4 outColor = right;\n"
2908 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
2909 " outColor = wrong;\n"
2910 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
2911 " outColor = wrong;\n"
2912 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
2913 " outColor = wrong;\n"
2914
2915 " color = outColor;\n"
2916
2917 // generic position stuff
2918 " vec2 vertices;\n"
2919 " int vertexSelector = gl_VertexID;\n"
2920 " if (vertexSelector == 0)\n"
2921 " vertices = vec2(-0.5, -0.5);\n"
2922 " else if (vertexSelector == 1)\n"
2923 " vertices = vec2( 0.5, -0.5);\n"
2924 " else if (vertexSelector == 2)\n"
2925 " vertices = vec2( 0.5, 0.5);\n"
2926 " else\n"
2927 " vertices = vec2( 0.0, 0.0);\n"
2928 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
2929 "}\n";
2930
2931 static const char *fragShaderText =
2932 "#version 140\n"
2933 "#extension GL_ARB_separate_shader_objects : enable\n"
2934 "#extension GL_ARB_shading_language_420pack : enable\n"
2935 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2936 " vec4 fRed;\n"
2937 " vec4 fGreen;\n"
2938 " layout(row_major) mat4 worldToProj;\n"
2939 " layout(row_major) mat4 projToWorld;\n"
2940 " layout(row_major) mat4 worldToView;\n"
2941 " layout(row_major) mat4 viewToProj;\n"
2942 " layout(row_major) mat4 worldToShadow[4];\n"
2943 " float fZero;\n"
2944 " float fOne;\n"
2945 " float fTwo;\n"
2946 " float fThree;\n"
2947 " vec3 fZeroZeroZero;\n"
2948 " float fFour;\n"
2949 " vec3 fZeroZeroOne;\n"
2950 " float fFive;\n"
2951 " vec3 fZeroOneZero;\n"
2952 " float fSix;\n"
2953 " float fSeven;\n"
2954 " float fEight;\n"
2955 " float fNine;\n"
2956 " vec2 fZeroZero;\n"
2957 " vec2 fZeroOne;\n"
2958 " vec4 fBlue;\n"
2959 " vec2 fOneZero;\n"
2960 " vec2 fOneOne;\n"
2961 " vec3 fZeroOneOne;\n"
2962 " float fTen;\n"
2963 " float fEleven;\n"
2964 " float fTwelve;\n"
2965 " vec3 fOneZeroZero;\n"
2966 " vec4 uvOffsets[4];\n"
2967 "};\n"
2968 "layout (location = 0) in vec4 color;\n"
2969 "void main() {\n"
2970 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2971 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2972 " \n"
2973
2974 // start with VS value to ensure it passed
2975 " vec4 outColor = color;\n"
2976
2977 // do some exact comparisons, even though we should
2978 // really have an epsilon involved.
2979 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
2980 " outColor = wrong;\n"
2981 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
2982 " outColor = wrong;\n"
2983 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
2984 " outColor = wrong;\n"
2985 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
2986 " outColor = wrong;\n"
2987 " if (fTwo != 2.0)\n"
2988 " outColor = wrong;\n"
2989 " if (fOneOne != vec2(1.0, 1.0))\n"
2990 " outColor = wrong;\n"
2991 " if (fTen != 10.0)\n"
2992 " outColor = wrong;\n"
2993 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
2994 " outColor = wrong;\n"
2995 " \n"
2996 " gl_FragColor = outColor;\n"
2997 "}\n";
2998
2999
3000 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3001 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3002 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3003 0.0, 1.0, 0.0, 1.0, // align
3004 0.0, 0.0, 1.0, 1.0, // align
3005 0.0, 0.0, 0.0, 1.0, // align
3006 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3007 0.0, 2.0, 0.0, 2.0, // align
3008 0.0, 0.0, 2.0, 2.0, // align
3009 0.0, 0.0, 0.0, 2.0, // align
3010 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3011 0.0, 3.0, 0.0, 3.0, // align
3012 0.0, 0.0, 3.0, 3.0, // align
3013 0.0, 0.0, 0.0, 3.0, // align
3014 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3015 0.0, 4.0, 0.0, 4.0, // align
3016 0.0, 0.0, 4.0, 4.0, // align
3017 0.0, 0.0, 0.0, 4.0, // align
3018 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3019 0.0, 5.0, 0.0, 5.0, // align
3020 0.0, 0.0, 5.0, 5.0, // align
3021 0.0, 0.0, 0.0, 5.0, // align
3022 6.0, 0.0, 0.0, 6.0, // align
3023 0.0, 6.0, 0.0, 6.0, // align
3024 0.0, 0.0, 6.0, 6.0, // align
3025 0.0, 0.0, 0.0, 6.0, // align
3026 7.0, 0.0, 0.0, 7.0, // align
3027 0.0, 7.0, 0.0, 7.0, // align
3028 0.0, 0.0, 7.0, 7.0, // align
3029 0.0, 0.0, 0.0, 7.0, // align
3030 8.0, 0.0, 0.0, 8.0, // align
3031 0.0, 8.0, 0.0, 8.0, // align
3032 0.0, 0.0, 8.0, 8.0, // align
3033 0.0, 0.0, 0.0, 8.0, // align
3034 0.0, // float fZero; // align
3035 1.0, // float fOne; // pack
3036 2.0, // float fTwo; // pack
3037 3.0, // float fThree; // pack
3038 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3039 4.0, // float fFour; // pack
3040 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3041 5.0, // float fFive; // pack
3042 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3043 6.0, // float fSix; // pack
3044 7.0, // float fSeven; // align
3045 8.0, // float fEight; // pack
3046 9.0, // float fNine; // pack
3047 0.0, // BUFFER
3048 0.0, 0.0, // vec2 fZeroZero; // align
3049 0.0, 1.0, // vec2 fZeroOne; // pack
3050 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3051 1.0, 0.0, // vec2 fOneZero; // align
3052 1.0, 1.0, // vec2 fOneOne; // pack
3053 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3054 10.0, // float fTen; // pack
3055 11.0, // float fEleven; // align
3056 12.0, // float fTwelve; // pack
3057 0.0, 0.0, // BUFFER
3058 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3059 0.0, // BUFFER
3060 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3061 0.5, 0.6, 0.7, 0.8, // align
3062 0.9, 1.0, 1.1, 1.2, // align
3063 1.3, 1.4, 1.5, 1.6, // align
3064 };
3065
3066 ASSERT_NO_FATAL_FAILURE(InitState());
3067 ASSERT_NO_FATAL_FAILURE(InitViewport());
3068
3069 const int constCount = sizeof(mixedVals) / sizeof(float);
3070
Tony Barbour6918cd52015-04-09 12:58:51 -06003071 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3072 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop04ad1202014-12-17 15:26:33 -07003073
Tony Barbour6918cd52015-04-09 12:58:51 -06003074 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop04ad1202014-12-17 15:26:33 -07003075
Tony Barbour6918cd52015-04-09 12:58:51 -06003076 VkPipelineObj pipelineobj(m_device);
Cody Northrop04ad1202014-12-17 15:26:33 -07003077 pipelineobj.AddShader(&vs);
3078 pipelineobj.AddShader(&ps);
3079
Tony Barbour6918cd52015-04-09 12:58:51 -06003080 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003081 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
Cody Northrop04ad1202014-12-17 15:26:33 -07003082
3083 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour6918cd52015-04-09 12:58:51 -06003084 VkCommandBufferObj cmdBuffer(m_device);
Cody Northrop04ad1202014-12-17 15:26:33 -07003085 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3086
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003087 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Cody Northrop04ad1202014-12-17 15:26:33 -07003088
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06003089 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Cody Northrop04ad1202014-12-17 15:26:33 -07003090
3091#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003092 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop04ad1202014-12-17 15:26:33 -07003093 pDSDumpDot((char*)"triTest2.dot");
3094#endif
3095 // render triangle
3096 cmdBuffer.Draw(0, 3, 0, 1);
3097
3098 // finalize recording of the command buffer
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06003099 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06003100 cmdBuffer.QueueCommandBuffer();
Cody Northrop04ad1202014-12-17 15:26:33 -07003101
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06003102 RecordImages(m_renderTargets);
Cody Northrop04ad1202014-12-17 15:26:33 -07003103}
3104
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06003105int main(int argc, char **argv) {
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06003106 int result;
3107
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06003108 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -06003109 VkTestFramework::InitArgs(&argc, argv);
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06003110
Chia-I Wu6f184292014-12-15 23:57:34 +08003111 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchtera0f74c52014-10-08 08:46:51 -06003112
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06003113 result = RUN_ALL_TESTS();
3114
Tony Barbour6918cd52015-04-09 12:58:51 -06003115 VkTestFramework::Finish();
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06003116 return result;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06003117}