blob: 5e1039be52205c10dddae3dd1a1e42a18eecd761 [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 Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060031//
Courtney Goeltzenleuchterfcbe16f2015-10-29 13:50:34 -060032// Copyright (C) 2015 Valve Corporation
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060033//
34// Permission is hereby granted, free of charge, to any person obtaining a
35// copy of this software and associated documentation files (the "Software"),
36// to deal in the Software without restriction, including without limitation
37// the rights to use, copy, modify, merge, publish, distribute, sublicense,
38// and/or sell copies of the Software, and to permit persons to whom the
39// Software is furnished to do so, subject to the following conditions:
40//
41// The above copyright notice and this permission notice shall be included
42// in all copies or substantial portions of the Software.
43//
44// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
45// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
46// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
47// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
48// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
49// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
50// DEALINGS IN THE SOFTWARE.
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060051//
52// Author: Chia-I Wu <olvaffe@gmail.com>
53// Author: Cody Northrop <cody@lunarg.com>
54// Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
55// Author: GregF <greg@LunarG.com>
56// Author: Tobin Ehlis <tobin@lunarg.com>
57// Author: Tony Barbour <tony@LunarG.com>
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060058
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060059// Basic rendering tests
60
61#include <stdlib.h>
62#include <stdio.h>
63#include <stdbool.h>
64#include <string.h>
Courtney Goeltzenleuchterda91b952014-08-21 17:34:22 -060065#include <iostream>
66#include <fstream>
67using namespace std;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060068
David Pinedo9316d3b2015-11-06 12:54:48 -070069#include <vulkan/vulkan.h>
Tobin Ehlis11e52132014-11-28 11:17:19 -070070#ifdef DUMP_STATE_DOT
71#include "../layers/draw_state.h"
72#endif
Tobin Ehlisca915872014-11-18 11:28:33 -070073#ifdef PRINT_OBJECTS
74#include "../layers/object_track.h"
75#endif
Tobin Ehlis6663f492014-11-10 12:29:12 -070076#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070077#include <vulkan/vk_ext_debug_report.h>
Tobin Ehlis6663f492014-11-10 12:29:12 -070078#endif
Courtney Goeltzenleuchter58f3eff2015-10-07 13:28:58 -060079#include "test_common.h"
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060080
Cody Northrop054a4702015-03-17 14:54:35 -060081#include "icd-spv.h"
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060082
Courtney Goeltzenleuchterfdcfb9f2014-10-10 18:04:39 -060083#define GLM_FORCE_RADIANS
84#include "glm/glm.hpp"
85#include <glm/gtc/matrix_transform.hpp>
86
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060087#include "vkrenderframework.h"
Tobin Ehlis6663f492014-11-10 12:29:12 -070088#ifdef DEBUG_CALLBACK
Chia-I Wu9ab61502015-11-06 06:42:02 +080089VKAPI_ATTR void VKAPI_CALL myDbgFunc(
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060090 VK_DBG_MSG_TYPE msgType,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060091 VkValidationLevel validationLevel,
Mike Stroyanb050c682015-04-17 12:36:38 -060092 VkObject srcObject,
Mark Lobodzinski17caf572015-01-29 08:55:56 -060093 size_t location,
94 int32_t msgCode,
95 const char* pMsg,
96 void* pUserData)
Tobin Ehlis6663f492014-11-10 12:29:12 -070097{
Tobin Ehlisca915872014-11-18 11:28:33 -070098 switch (msgType)
99 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600100 case VK_DBG_MSG_WARNING:
Tobin Ehlisca915872014-11-18 11:28:33 -0700101 printf("CALLBACK WARNING : %s\n", pMsg);
102 break;
Courtney Goeltzenleuchterfd4830c2015-11-25 10:30:56 -0700103 case VK_DEBUG_REPORT_ERROR_BIT:
Tobin Ehlisca915872014-11-18 11:28:33 -0700104 printf("CALLBACK ERROR : %s\n", pMsg);
105 break;
106 default:
107 printf("EATING Msg of type %u\n", msgType);
108 break;
109 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700110}
111#endif
Tony Barboure2c58df2014-11-25 13:18:32 -0700112
113
114#undef ASSERT_NO_FATAL_FAILURE
115#define ASSERT_NO_FATAL_FAILURE(x) x
116
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600117//--------------------------------------------------------------------------------------
118// Mesh and VertexFormat Data
119//--------------------------------------------------------------------------------------
120struct Vertex
121{
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600122 float posX, posY, posZ, posW; // Position data
123 float r, g, b, a; // Color
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600124};
125
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600126struct VertexUV
127{
128 float posX, posY, posZ, posW; // Position data
129 float u, v; // texture u,v
130};
131
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600132#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600133#define UV(_u_, _v_) (_u_), (_v_)
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600134
135static const Vertex g_vbData[] =
136{
137 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
138 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
139 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
140 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
141 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
142 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
143
144 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
145 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
146 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
147 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
148 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
149 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
150
151 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
152 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
153 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
154 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
155 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
156 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
157
158 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
159 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
160 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
161 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
162 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
163 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
164
165 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
166 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
167 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
168 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
169 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
170 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
171
172 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
173 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
174 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
175 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
176 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
177 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
178};
179
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600180static const Vertex g_vb_solid_face_colors_Data[] =
181{
182 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600183 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600184 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
185 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600186 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
187 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600188
189 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
190 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600191 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
192 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600193 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600194 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600195
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600196 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
197 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
198 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
199 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
200 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
201 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600202
203 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
204 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
205 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
206 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
207 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
208 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
209
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600210 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600211 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600212 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
213 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600214 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
215 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
216
217 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
218 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
219 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
220 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
221 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
222 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
223};
224
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600225static const VertexUV g_vb_texture_Data[] =
226{
227 { XYZ1( -1, -1, -1 ), UV( 0.f, 0.f ) },
228 { XYZ1( -1, 1, 1 ), UV( 1.f, 1.f ) },
229 { XYZ1( -1, -1, 1 ), UV( 1.f, 0.f ) },
230 { XYZ1( -1, 1, 1 ), UV( 1.f, 1.f ) },
231 { XYZ1( -1, -1, -1 ), UV( 0.f, 0.f ) },
232 { XYZ1( -1, 1, -1 ), UV( 0.f, 1.f ) },
233
234 { XYZ1( -1, -1, -1 ), UV( 1.f, 0.f ) },
235 { XYZ1( 1, -1, -1 ), UV( 0.f, 0.f ) },
236 { XYZ1( 1, 1, -1 ), UV( 0.f, 1.f ) },
237 { XYZ1( -1, -1, -1 ), UV( 1.f, 0.f ) },
238 { XYZ1( 1, 1, -1 ), UV( 0.f, 1.f ) },
239 { XYZ1( -1, 1, -1 ), UV( 1.f, 1.f ) },
240
241 { XYZ1( -1, -1, -1 ), UV( 1.f, 1.f ) },
242 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
243 { XYZ1( 1, -1, -1 ), UV( 1.f, 0.f ) },
244 { XYZ1( -1, -1, -1 ), UV( 1.f, 1.f ) },
245 { XYZ1( -1, -1, 1 ), UV( 0.f, 1.f ) },
246 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
247
248 { XYZ1( -1, 1, -1 ), UV( 1.f, 1.f ) },
249 { XYZ1( 1, 1, 1 ), UV( 0.f, 0.f ) },
250 { XYZ1( -1, 1, 1 ), UV( 0.f, 1.f ) },
251 { XYZ1( -1, 1, -1 ), UV( 1.f, 1.f ) },
252 { XYZ1( 1, 1, -1 ), UV( 1.f, 0.f ) },
253 { XYZ1( 1, 1, 1 ), UV( 0.f, 0.f ) },
254
255 { XYZ1( 1, 1, -1 ), UV( 1.f, 1.f ) },
256 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
257 { XYZ1( 1, 1, 1 ), UV( 0.f, 1.f ) },
258 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
259 { XYZ1( 1, 1, -1 ), UV( 1.f, 1.f ) },
260 { XYZ1( 1, -1, -1 ), UV( 1.f, 0.f ) },
261
262 { XYZ1( -1, 1, 1 ), UV( 0.f, 1.f ) },
263 { XYZ1( 1, 1, 1 ), UV( 1.f, 1.f ) },
264 { XYZ1( -1, -1, 1 ), UV( 0.f, 0.f ) },
265 { XYZ1( -1, -1, 1 ), UV( 0.f, 0.f ) },
266 { XYZ1( 1, 1, 1 ), UV( 1.f, 1.f ) },
267 { XYZ1( 1, -1, 1 ), UV( 1.f, 0.f ) },
268};
269
Tony Barbour6918cd52015-04-09 12:58:51 -0600270class VkRenderTest : public VkRenderFramework
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -0600271{
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600272public:
Cody Northrop7ad4aaf2014-10-09 21:25:22 -0600273
Tony Barboure2c58df2014-11-25 13:18:32 -0700274 void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800275 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *commandBuffer);
276 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600277 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet)
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800278 { GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet); }
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600279 void InitDepthStencil();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600280 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate);
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600281
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800282 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
283 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer, VkCommandBufferBeginInfo *beginInfo);
284 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600285 /* Convenience functions that use built-in command buffer */
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800286 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
287 VkResult BeginCommandBuffer(VkCommandBufferBeginInfo *beginInfo) { return BeginCommandBuffer(*m_commandBuffer, beginInfo); }
288 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600289 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800290 { m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance); }
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600291 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance)
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800292 { m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); }
293 void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); }
Tony Barbourfe3351b2015-07-28 10:17:20 -0600294 void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
295 VkConstantBufferObj *constantBuffer)
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800296 {RotateTriangleVSUniform(Projection, View, Model, constantBuffer, m_commandBuffer); }
Tony Barbourfe3351b2015-07-28 10:17:20 -0600297 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding)
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800298 { m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding); }
Tony Barbourfe3351b2015-07-28 10:17:20 -0600299 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset)
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800300 { m_commandBuffer->BindIndexBuffer(indexBuffer, offset); }
Tony Barbourfe3351b2015-07-28 10:17:20 -0600301
302
Cody Northropee6586d2014-10-09 19:55:56 -0600303
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600304protected:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600305 VkImage m_texture;
306 VkImageView m_textureView;
Tony Barbourd1c35722015-04-16 15:59:00 -0600307 VkDeviceMemory m_textureMem;
Cody Northrop7d2035d2014-10-06 15:42:00 -0600308
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600309 VkSampler m_sampler;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600310
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600311
312 virtual void SetUp() {
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600313
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600314 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600315 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800316 this->app_info.pApplicationName = "render_tests";
317 this->app_info.applicationVersion = 1;
Chia-I Wuf1a5a742014-12-27 15:16:07 +0800318 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600319 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600320 this->app_info.apiVersion = VK_API_VERSION;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600321
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600322 InitFramework();
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600323 }
324
325 virtual void TearDown() {
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600326 // Clean up resources before we reset
327 ShutdownFramework();
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600328 }
329};
330
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800331VkResult VkRenderTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer)
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600332{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600333 VkResult result;
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600334
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800335 result = commandBuffer.BeginCommandBuffer();
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600336
337 /*
338 * For render test all drawing happens in a single render pass
339 * on a single command buffer.
340 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200341 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800342 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600343 }
344
345 return result;
346}
347
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800348VkResult VkRenderTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer, VkCommandBufferBeginInfo *beginInfo)
Tobin Ehlisf1878c72015-08-18 14:24:32 -0600349{
350 VkResult result;
351
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800352 result = commandBuffer.BeginCommandBuffer(beginInfo);
Tobin Ehlisf1878c72015-08-18 14:24:32 -0600353
354 /*
355 * For render test all drawing happens in a single render pass
356 * on a single command buffer.
357 */
358 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800359 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tobin Ehlisf1878c72015-08-18 14:24:32 -0600360 }
361
362 return result;
363}
364
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800365VkResult VkRenderTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer)
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600366{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600367 VkResult result;
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600368
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200369 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800370 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200371 }
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600372
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800373 result = commandBuffer.EndCommandBuffer();
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600374
375 return result;
376}
377
378
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800379void VkRenderTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet)
Tony Barbour22e32a12015-01-08 17:08:28 -0700380{
Tony Barbour71bd4b32015-07-21 17:00:26 -0600381 if (!m_clear_via_load_op) {
382 if (m_depthStencil->Initialized()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800383 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Tony Barbour71bd4b32015-07-21 17:00:26 -0600384 } else {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800385 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour71bd4b32015-07-21 17:00:26 -0600386 }
Tony Barbour1c45ce02015-03-27 17:03:18 -0600387 }
388
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800389 commandBuffer->PrepareAttachments();
Jon Ashburn19d3bf12015-12-30 14:06:55 -0700390 commandBuffer->SetViewport(0, m_viewports.size(), m_viewports.data());
391 commandBuffer->SetScissor(0, m_scissors.size(), m_scissors.data());
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600392
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800393 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Cody Northrop29a08f22015-08-27 10:20:35 -0600394 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
395 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800396 commandBuffer->BindPipeline(pipelineobj);
397 commandBuffer->BindDescriptorSet(descriptorSet);
Tony Barbour22e32a12015-01-08 17:08:28 -0700398}
Tony Barboure2c58df2014-11-25 13:18:32 -0700399
Tony Barbour6918cd52015-04-09 12:58:51 -0600400void VkRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800401 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *commandBuffer)
Tony Barbour664accc2015-01-09 12:55:14 -0700402{
403 int i;
404 glm::mat4 MVP;
405 int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600406 VkResult err;
Tony Barbour664accc2015-01-09 12:55:14 -0700407
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600408 /* Only do 3 positions to avoid back face cull */
409 for (i = 0; i < 3; i++) {
Chia-I Wu681d7a02015-07-03 13:44:34 +0800410 void *pData = constantBuffer->memory().map();
Tony Barbour664accc2015-01-09 12:55:14 -0700411
412 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
413 MVP = Projection * View * Model;
414 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
415
Chia-I Wu681d7a02015-07-03 13:44:34 +0800416 constantBuffer->memory().unmap();
Tony Barbour664accc2015-01-09 12:55:14 -0700417
418 // submit the command buffer to the universal queue
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800419 commandBuffer->QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -0700420
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600421 err = vkQueueWaitIdle( m_device->m_queue );
422 ASSERT_VK_SUCCESS( err );
Tony Barbour664accc2015-01-09 12:55:14 -0700423
424 // Wait for work to finish before cleaning up.
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600425 vkDeviceWaitIdle(m_device->device());
Tony Barbour664accc2015-01-09 12:55:14 -0700426
Courtney Goeltzenleuchterb4337c12015-03-05 16:47:18 -0700427 assert(m_renderTargets.size() == 1);
Tony Barbour664accc2015-01-09 12:55:14 -0700428 RecordImage(m_renderTargets[0]);
429 }
430}
Courtney Goeltzenleuchterc55471f2014-10-13 13:03:31 -0600431
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600432void dumpMatrix(const char *note, glm::mat4 MVP)
433{
Chia-I Wu6f184292014-12-15 23:57:34 +0800434 int i;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600435
436 printf("%s: \n", note);
437 for (i=0; i<4; i++) {
438 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
439 }
440 printf("\n");
441 fflush(stdout);
442}
443
444void dumpVec4(const char *note, glm::vec4 vector)
445{
446 printf("%s: \n", note);
447 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
448 printf("\n");
449 fflush(stdout);
450}
451
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600452struct vktriangle_vs_uniform {
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600453 // Must start with MVP
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600454 float mvp[4][4];
455 float position[3][4];
456 float color[3][4];
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600457};
458
Tony Barbour6918cd52015-04-09 12:58:51 -0600459void VkRenderTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600460{
Tobin Ehlis6663f492014-11-10 12:29:12 -0700461#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600462 vkDbgRegisterMsgCallback(inst, myDbgFunc, NULL);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700463#endif
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600464 // Create identity matrix
465 int i;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600466 struct vktriangle_vs_uniform data;
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600467
468 glm::mat4 Projection = glm::mat4(1.0f);
469 glm::mat4 View = glm::mat4(1.0f);
470 glm::mat4 Model = glm::mat4(1.0f);
471 glm::mat4 MVP = Projection * View * Model;
472 const int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600473 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600474 memcpy(&data.mvp, &MVP[0][0], matrixSize);
475
476 static const Vertex tri_data[] =
477 {
478 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
479 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
480 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
481 };
482
483 for (i=0; i<3; i++) {
484 data.position[i][0] = tri_data[i].posX;
485 data.position[i][1] = tri_data[i].posY;
486 data.position[i][2] = tri_data[i].posZ;
487 data.position[i][3] = tri_data[i].posW;
488 data.color[i][0] = tri_data[i].r;
489 data.color[i][1] = tri_data[i].g;
490 data.color[i][2] = tri_data[i].b;
491 data.color[i][3] = tri_data[i].a;
492 }
493
Tony Barboure2c58df2014-11-25 13:18:32 -0700494 ASSERT_NO_FATAL_FAILURE(InitState());
495 ASSERT_NO_FATAL_FAILURE(InitViewport());
496
Tony Barbour6918cd52015-04-09 12:58:51 -0600497 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barboure2c58df2014-11-25 13:18:32 -0700498
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -0600499 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
500 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -0700501
Tony Barbour6918cd52015-04-09 12:58:51 -0600502 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800503 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -0700504 pipelineobj.AddShader(&vs);
505 pipelineobj.AddShader(&ps);
506
Tony Barbour6918cd52015-04-09 12:58:51 -0600507 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600508 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -0700509
Tony Barbourd726a172015-01-09 16:12:35 -0700510 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf1878c72015-08-18 14:24:32 -0600511
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800512 VkCommandBufferBeginInfo cbBeginInfo;
513 memset(&cbBeginInfo, 0, sizeof(VkCommandBufferBeginInfo));
514 cbBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Courtney Goeltzenleuchter04bb5f82015-10-21 18:11:04 -0600515 cbBeginInfo.flags = 0;
Tobin Ehlisf1878c72015-08-18 14:24:32 -0600516 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barboure2c58df2014-11-25 13:18:32 -0700517
Tony Barbourfe3351b2015-07-28 10:17:20 -0600518 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourd726a172015-01-09 16:12:35 -0700519#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600520 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourd726a172015-01-09 16:12:35 -0700521 pDSDumpDot((char*)"triTest2.dot");
522#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600523
Tony Barbourd726a172015-01-09 16:12:35 -0700524 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600525 Draw(3, 1, 0, 0);
Tony Barbourd726a172015-01-09 16:12:35 -0700526
527 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600528 ASSERT_VK_SUCCESS(EndCommandBuffer());
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600529
Tony Barbourfe3351b2015-07-28 10:17:20 -0600530 QueueCommandBuffer();
Tony Barbourd726a172015-01-09 16:12:35 -0700531
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600532 RecordImages(m_renderTargets);
Tony Barbourd726a172015-01-09 16:12:35 -0700533
534 if (rotate)
Tony Barbourfe3351b2015-07-28 10:17:20 -0600535 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer);
Tony Barbourd726a172015-01-09 16:12:35 -0700536
Tobin Ehlisca915872014-11-18 11:28:33 -0700537#ifdef PRINT_OBJECTS
Mark Lobodzinski7c75b852015-05-05 15:01:37 -0500538 OBJ_TRACK_GET_OBJECTS_COUNT pObjTrackGetObjectsCount = (OBJ_TRACK_GET_OBJECTS_COUNT)vkGetProcAddr(gpu(), (char*)"objTrackGetObjectsCount");
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600539 uint64_t numObjects = pObjTrackGetObjectsCount(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600540 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlisca915872014-11-18 11:28:33 -0700541 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600542 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlisca915872014-11-18 11:28:33 -0700543 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600544 pObjTrackGetObjs(m_device, numObjects, pObjNodeArray);
Tobin Ehlisca915872014-11-18 11:28:33 -0700545 for (i=0; i < numObjects; i++) {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600546 printf("Object %i of type %s has objID (%p) and %lu uses\n", i, string_VkObjectType(pObjNodeArray[i].objType), pObjNodeArray[i].pObj, pObjNodeArray[i].numUses);
Tobin Ehlisca915872014-11-18 11:28:33 -0700547 }
548 free(pObjNodeArray);
549#endif
Tony Barboure2c58df2014-11-25 13:18:32 -0700550
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600551}
552
Tony Barbour6918cd52015-04-09 12:58:51 -0600553TEST_F(VkRenderTest, VKTriangle_FragColor)
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600554{
555 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -0700556 "#version 400\n"
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600557 "#extension GL_ARB_separate_shader_objects : enable\n"
558 "#extension GL_ARB_shading_language_420pack : enable\n"
559 "\n"
560 "layout(binding = 0) uniform buf {\n"
561 " mat4 MVP;\n"
562 " vec4 position[3];\n"
563 " vec4 color[3];\n"
564 "} ubuf;\n"
565 "\n"
566 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure804d202016-01-05 13:37:45 -0700567 "out gl_PerVertex {\n"
568 " vec4 gl_Position;\n"
569 "};\n"
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600570 "\n"
571 "void main() \n"
572 "{\n"
573 " outColor = ubuf.color[gl_VertexID];\n"
574 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
575 "}\n";
576
577 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -0700578 "#version 400\n"
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600579 "#extension GL_ARB_separate_shader_objects : enable\n"
580 "#extension GL_ARB_shading_language_420pack : enable\n"
581 "\n"
582 "layout (location = 0) in vec4 inColor;\n"
GregFaae75242015-06-03 18:40:50 -0600583 "layout (location = 0) out vec4 uFragColor;\n"
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600584 "\n"
585 "void main()\n"
586 "{\n"
GregFaae75242015-06-03 18:40:50 -0600587 " uFragColor = inColor;\n"
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600588 "}\n";
589
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600590 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
591 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600592}
593
Tony Barbour6918cd52015-04-09 12:58:51 -0600594TEST_F(VkRenderTest, VKTriangle_OutputLocation)
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600595{
596 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -0700597 "#version 400\n"
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600598 "#extension GL_ARB_separate_shader_objects : enable\n"
599 "#extension GL_ARB_shading_language_420pack : enable\n"
600 "\n"
601 "layout(binding = 0) uniform buf {\n"
602 " mat4 MVP;\n"
603 " vec4 position[3];\n"
604 " vec4 color[3];\n"
605 "} ubuf;\n"
606 "\n"
607 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure804d202016-01-05 13:37:45 -0700608 "out gl_PerVertex {\n"
609 " vec4 gl_Position;\n"
610 "};\n"
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600611 "\n"
612 "void main() \n"
613 "{\n"
614 " outColor = ubuf.color[gl_VertexID];\n"
615 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
616 "}\n";
617
618 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -0700619 "#version 400\n"
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600620 "#extension GL_ARB_separate_shader_objects : enable\n"
621 "#extension GL_ARB_shading_language_420pack : enable\n"
622 "\n"
623 "layout (location = 0) in vec4 inColor;\n"
624 "layout (location = 0) out vec4 outColor;\n"
625 "\n"
626 "void main()\n"
627 "{\n"
628 " outColor = inColor;\n"
629 "}\n";
630
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600631 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 -0600632
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600633 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600634}
Cody Northrop6922da12015-06-23 13:25:51 -0600635
Tony Barbour6918cd52015-04-09 12:58:51 -0600636TEST_F(VkRenderTest, SPV_VKTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -0700637{
Tony Barboure2c58df2014-11-25 13:18:32 -0700638 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -0700639 "#version 400\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700640 "#extension GL_ARB_separate_shader_objects : enable\n"
641 "#extension GL_ARB_shading_language_420pack : enable\n"
642 "\n"
643 "layout(binding = 0) uniform buf {\n"
644 " mat4 MVP;\n"
645 " vec4 position[3];\n"
646 " vec4 color[3];\n"
647 "} ubuf;\n"
648 "\n"
649 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure804d202016-01-05 13:37:45 -0700650 "out gl_PerVertex {\n"
651 " vec4 gl_Position;\n"
652 "};\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700653 "\n"
654 "void main() \n"
655 "{\n"
656 " outColor = ubuf.color[gl_VertexID];\n"
657 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
658 "}\n";
659
660 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -0700661 "#version 400\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700662 "#extension GL_ARB_separate_shader_objects : enable\n"
663 "#extension GL_ARB_shading_language_420pack : enable\n"
664 "\n"
665 "layout (location = 0) in vec4 inColor;\n"
GregFaae75242015-06-03 18:40:50 -0600666 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700667 "\n"
668 "void main()\n"
669 "{\n"
GregFaae75242015-06-03 18:40:50 -0600670 " outColor = inColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700671 "}\n";
672
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600673 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 -0700674
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600675 VKTriangleTest(vertShaderText, fragShaderText, true);
Tony Barboure2c58df2014-11-25 13:18:32 -0700676}
Courtney Goeltzenleuchter538062a2014-10-09 15:40:19 -0600677
Tony Barbour6918cd52015-04-09 12:58:51 -0600678TEST_F(VkRenderTest, SPV_GreenTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -0700679{
Tony Barboure2c58df2014-11-25 13:18:32 -0700680 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -0700681 "#version 400\n"
682 "#extension GL_ARB_separate_shader_objects : enable\n"
683 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700684 "vec2 vertices[3];\n"
Tony Barboure804d202016-01-05 13:37:45 -0700685 "out gl_PerVertex {\n"
686 " vec4 gl_Position;\n"
687 "};\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700688 "void main() {\n"
689 " vertices[0] = vec2(-1.0, -1.0);\n"
690 " vertices[1] = vec2( 1.0, -1.0);\n"
691 " vertices[2] = vec2( 0.0, 1.0);\n"
692 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
693 "}\n";
694
695 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -0700696 "#version 400\n"
GregFaae75242015-06-03 18:40:50 -0600697 "#extension GL_ARB_separate_shader_objects : enable\n"
698 "#extension GL_ARB_shading_language_420pack : enable\n"
699 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700700 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600701 " outColor = vec4(0,1,0,1);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700702 "}\n";
703
Cody Northrop3bfd27c2015-03-17 15:55:58 -0600704 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barboure2c58df2014-11-25 13:18:32 -0700705
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600706 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barboure2c58df2014-11-25 13:18:32 -0700707}
Cody Northrop6922da12015-06-23 13:25:51 -0600708
Tony Barbour6918cd52015-04-09 12:58:51 -0600709TEST_F(VkRenderTest, YellowTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -0700710{
711 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -0700712 "#version 400\n"
713 "#extension GL_ARB_separate_shader_objects : enable\n"
714 "#extension GL_ARB_shading_language_420pack : enable\n"
715 "out gl_PerVertex {\n"
716 " vec4 gl_Position;\n"
717 "};\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700718 "void main() {\n"
719 " vec2 vertices[3];"
720 " vertices[0] = vec2(-0.5, -0.5);\n"
721 " vertices[1] = vec2( 0.5, -0.5);\n"
722 " vertices[2] = vec2( 0.5, 0.5);\n"
723 " vec4 colors[3];\n"
724 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
725 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
726 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
727 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
728 "}\n";
729
730 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -0700731 "#version 400\n"
GregFaae75242015-06-03 18:40:50 -0600732 "#extension GL_ARB_separate_shader_objects : enable\n"
733 "#extension GL_ARB_shading_language_420pack : enable\n"
734 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700735 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600736 " outColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700737 "}\n";
738
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600739 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barboure2c58df2014-11-25 13:18:32 -0700740}
741
Tony Barbour6918cd52015-04-09 12:58:51 -0600742TEST_F(VkRenderTest, QuadWithVertexFetch)
Cody Northropee6586d2014-10-09 19:55:56 -0600743{
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600744 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -0700745 "#version 400\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600746 "#extension GL_ARB_separate_shader_objects : enable\n"
747 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700748 //XYZ1( -1, -1, -1 )
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600749 "layout (location = 0) in vec4 pos;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700750 //XYZ1( 0.f, 0.f, 0.f )
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600751 "layout (location = 1) in vec4 inColor;\n"
752 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure804d202016-01-05 13:37:45 -0700753 "out gl_PerVertex {\n"
754 " vec4 gl_Position;\n"
755 "};\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600756 "void main() {\n"
Cody Northrop66594a72014-10-10 14:49:36 -0600757 " outColor = inColor;\n"
Cody Northrop7ad4aaf2014-10-09 21:25:22 -0600758 " gl_Position = pos;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600759 "}\n";
760
Cody Northropee6586d2014-10-09 19:55:56 -0600761
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600762 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -0700763 "#version 400\n"
Cody Northropd43c52e2014-12-05 15:44:14 -0700764 "#extension GL_ARB_separate_shader_objects : enable\n"
765 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600766 "layout (location = 0) in vec4 color;\n"
Cody Northropd43c52e2014-12-05 15:44:14 -0700767 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600768 "void main() {\n"
Cody Northropd43c52e2014-12-05 15:44:14 -0700769 " outColor = color;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600770 "}\n";
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600771
Tony Barboure2c58df2014-11-25 13:18:32 -0700772
773
774 ASSERT_NO_FATAL_FAILURE(InitState());
775 ASSERT_NO_FATAL_FAILURE(InitViewport());
776
Tony Barbour6918cd52015-04-09 12:58:51 -0600777 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000778 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -0700779
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -0600780 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
781 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -0700782
Tony Barbour6918cd52015-04-09 12:58:51 -0600783 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800784 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -0700785 pipelineobj.AddShader(&vs);
786 pipelineobj.AddShader(&ps);
787
Tony Barbour6918cd52015-04-09 12:58:51 -0600788 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -0600789
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600790#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600791 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600792 MESH_BIND_ID, // binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800793 sizeof(g_vbData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800794 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
Tony Barboure2c58df2014-11-25 13:18:32 -0700795 };
796
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600797 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600798 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
799 vi_attribs[0].location = 0; // location, position
Tony Barbourd1c35722015-04-16 15:59:00 -0600800 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800801 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600802 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
803 vi_attribs[1].location = 1; // location, color
Tony Barbourd1c35722015-04-16 15:59:00 -0600804 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800805 vi_attribs[1].offset = 1*sizeof(float)*4; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -0700806
807 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
808 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barboure2c58df2014-11-25 13:18:32 -0700809
Tony Barbour1fde6942015-01-09 10:06:53 -0700810 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600811 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure2c58df2014-11-25 13:18:32 -0700812
Tony Barbourfe3351b2015-07-28 10:17:20 -0600813 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600814
Tony Barbourfe3351b2015-07-28 10:17:20 -0600815 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour1fde6942015-01-09 10:06:53 -0700816
817 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600818 Draw(6, 1, 0, 0);
Tony Barbour1fde6942015-01-09 10:06:53 -0700819
820 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600821 ASSERT_VK_SUCCESS(EndCommandBuffer());
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600822
Tony Barbourfe3351b2015-07-28 10:17:20 -0600823 QueueCommandBuffer();
Tony Barbour1fde6942015-01-09 10:06:53 -0700824
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600825 RecordImages(m_renderTargets);
Tobin Ehlisd806c8e2014-10-07 14:41:29 -0600826}
827
Tony Barbour6918cd52015-04-09 12:58:51 -0600828TEST_F(VkRenderTest, TriangleMRT)
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800829{
830 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -0700831 "#version 400\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600832 "#extension GL_ARB_separate_shader_objects : enable\n"
833 "#extension GL_ARB_shading_language_420pack : enable\n"
834 "layout (location = 0) in vec4 pos;\n"
Tony Barboure804d202016-01-05 13:37:45 -0700835 "out gl_PerVertex {\n"
836 " vec4 gl_Position;\n"
837 "};\n"
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800838 "void main() {\n"
839 " gl_Position = pos;\n"
840 "}\n";
841
842 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -0700843 "#version 400\n"
GregFaae75242015-06-03 18:40:50 -0600844 "#extension GL_ARB_separate_shader_objects : enable\n"
845 "#extension GL_ARB_shading_language_420pack : enable\n"
846 "layout (location = 0) out vec4 uFragData0;\n"
847 "layout (location = 1) out vec4 uFragData1;\n"
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800848 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600849 " uFragData0 = vec4(1.0, 0.0, 0.0, 1.0);\n"
850 " uFragData1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800851 "}\n";
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600852 const float vb_data[][2] = {
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800853 { -1.0f, -1.0f },
854 { 1.0f, -1.0f },
855 { -1.0f, 1.0f }
856 };
857
858 ASSERT_NO_FATAL_FAILURE(InitState());
859 ASSERT_NO_FATAL_FAILURE(InitViewport());
860
Tony Barbour6918cd52015-04-09 12:58:51 -0600861 VkConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000862 meshBuffer.BufferMemoryBarrier();
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800863
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -0600864 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
865 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800866
Tony Barbour6918cd52015-04-09 12:58:51 -0600867 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800868 pipelineobj.AddColorAttachment();
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800869 pipelineobj.AddShader(&vs);
870 pipelineobj.AddShader(&ps);
871
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600872#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600873 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600874 MESH_BUF_ID, // Binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800875 sizeof(vb_data[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800876 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800877 };
878
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600879 VkVertexInputAttributeDescription vi_attrib;
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600880 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
881 vi_attrib.location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -0600882 vi_attrib.format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800883 vi_attrib.offset = 0; // Offset of first element in bytes from base of vertex
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800884
885 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
886 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800887
Tony Barbour6918cd52015-04-09 12:58:51 -0600888 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800889
Courtney Goeltzenleuchterb4337c12015-03-05 16:47:18 -0700890 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800891
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600892 VkPipelineColorBlendAttachmentState att = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600893 att.blendEnable = VK_FALSE;
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800894 att.colorWriteMask = 0xf;
Tony Barbourf52346d2015-01-16 14:27:35 -0700895 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800896
Tony Barbourfe3351b2015-07-28 10:17:20 -0600897 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour1fde6942015-01-09 10:06:53 -0700898
Tony Barbourfe3351b2015-07-28 10:17:20 -0600899 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour1fde6942015-01-09 10:06:53 -0700900
Tony Barbourfe3351b2015-07-28 10:17:20 -0600901 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour304ec8b2015-01-07 14:31:52 -0700902#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600903 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour304ec8b2015-01-07 14:31:52 -0700904 pDSDumpDot((char*)"triTest2.dot");
905#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600906
Tony Barbour304ec8b2015-01-07 14:31:52 -0700907 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600908 Draw(3, 1, 0, 0);
Tony Barbour304ec8b2015-01-07 14:31:52 -0700909
910 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600911 ASSERT_VK_SUCCESS(EndCommandBuffer());
912 QueueCommandBuffer();
Tony Barbour304ec8b2015-01-07 14:31:52 -0700913
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600914 RecordImages(m_renderTargets);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800915}
916
Tony Barbour6918cd52015-04-09 12:58:51 -0600917TEST_F(VkRenderTest, QuadWithIndexedVertexFetch)
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700918{
919 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -0700920 "#version 400\n"
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700921 "#extension GL_ARB_separate_shader_objects : enable\n"
922 "#extension GL_ARB_shading_language_420pack : enable\n"
923 "layout(location = 0) in vec4 pos;\n"
924 "layout(location = 1) in vec4 inColor;\n"
925 "layout(location = 0) out vec4 outColor;\n"
Tony Barboure804d202016-01-05 13:37:45 -0700926 "out gl_PerVertex {\n"
927 " vec4 gl_Position;\n"
928 "};\n"
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700929 "void main() {\n"
930 " outColor = inColor;\n"
931 " gl_Position = pos;\n"
932 "}\n";
933
934
935 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -0700936 "#version 400\n"
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700937 "#extension GL_ARB_separate_shader_objects : enable\n"
938 "#extension GL_ARB_shading_language_420pack : enable\n"
939 "layout(location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -0600940 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700941 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600942 " outColor = color;\n"
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700943 "}\n";
944
945 const Vertex g_vbData[] =
946 {
947 // first tri
948 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
949 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
950 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
951
952 // second tri
953 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
954 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
955 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
956 };
957
958 const uint16_t g_idxData[6] = {
959 0, 1, 2,
960 3, 4, 5,
961 };
962
963 ASSERT_NO_FATAL_FAILURE(InitState());
964 ASSERT_NO_FATAL_FAILURE(InitViewport());
965
Tony Barbour6918cd52015-04-09 12:58:51 -0600966 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000967 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700968
Tony Barbour6918cd52015-04-09 12:58:51 -0600969 VkIndexBufferObj indexBuffer(m_device);
Tony Barbourd1c35722015-04-16 15:59:00 -0600970 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), VK_INDEX_TYPE_UINT16, g_idxData);
Mark Lobodzinski49a6b4b2015-02-16 14:24:23 -0600971 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700972
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -0600973 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
974 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700975
Tony Barbour6918cd52015-04-09 12:58:51 -0600976 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800977 pipelineobj.AddColorAttachment();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700978 pipelineobj.AddShader(&vs);
979 pipelineobj.AddShader(&ps);
980
Tony Barbour6918cd52015-04-09 12:58:51 -0600981 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour831062d2015-04-02 15:43:15 -0600982
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700983
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600984#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600985 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600986 MESH_BIND_ID, // binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800987 sizeof(g_vbData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800988 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700989 };
990
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600991 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600992 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
993 vi_attribs[0].location = 0; // layout location of vertex attribute
Tony Barbourd1c35722015-04-16 15:59:00 -0600994 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800995 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600996 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
997 vi_attribs[1].location = 1; // layout location of vertex attribute
Tony Barbourd1c35722015-04-16 15:59:00 -0600998 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800999 vi_attribs[1].offset = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001000
1001 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1002 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001003
1004 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001005 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour1fde6942015-01-09 10:06:53 -07001006
Tony Barbourfe3351b2015-07-28 10:17:20 -06001007 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001008
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001009#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");
Tobin Ehlisf27eba72014-12-16 17:34:50 -07001011 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001012#endif
Tony Barbour22e32a12015-01-08 17:08:28 -07001013
Tony Barbourfe3351b2015-07-28 10:17:20 -06001014 BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
1015 BindIndexBuffer(&indexBuffer, 0);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001016
1017 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001018 DrawIndexed(6, 1, 0, 0, 0);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001019
1020 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001021 ASSERT_VK_SUCCESS(EndCommandBuffer());
1022 QueueCommandBuffer();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001023
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001024 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001025}
1026
Tony Barbour6918cd52015-04-09 12:58:51 -06001027TEST_F(VkRenderTest, GreyandRedCirclesonBlue)
GregF3156cb02014-12-02 15:41:44 -07001028{
1029 // This tests gl_FragCoord
Tony Barboure2c58df2014-11-25 13:18:32 -07001030
GregF3156cb02014-12-02 15:41:44 -07001031 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07001032 "#version 400\n"
GregF3156cb02014-12-02 15:41:44 -07001033 "#extension GL_ARB_separate_shader_objects : enable\n"
1034 "#extension GL_ARB_shading_language_420pack : enable\n"
1035 "layout (location = 0) in vec4 pos;\n"
1036 "layout (location = 0) out vec4 outColor;\n"
1037 "layout (location = 1) out vec4 outColor2;\n"
Tony Barboure804d202016-01-05 13:37:45 -07001038 "out gl_PerVertex {\n"
1039 " vec4 gl_Position;\n"
1040 "};\n"
GregF3156cb02014-12-02 15:41:44 -07001041 "void main() {\n"
1042 " gl_Position = pos;\n"
1043 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1044 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1045 "}\n";
1046
1047 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07001048 "#version 400\n"
GregF3156cb02014-12-02 15:41:44 -07001049 "#extension GL_ARB_separate_shader_objects : enable\n"
1050 "#extension GL_ARB_shading_language_420pack : enable\n"
1051 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1052 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1053 "layout (location = 0) in vec4 color;\n"
1054 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001055 "layout (location = 0) out vec4 outColor;\n"
GregF3156cb02014-12-02 15:41:44 -07001056 "void main() {\n"
1057 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1058 " float dist_squared = dot(pos, pos);\n"
GregFaae75242015-06-03 18:40:50 -06001059 " outColor = (dist_squared < 400.0)\n"
GregF3156cb02014-12-02 15:41:44 -07001060 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1061 " : color2;\n"
1062 "}\n";
1063
1064 ASSERT_NO_FATAL_FAILURE(InitState());
1065 ASSERT_NO_FATAL_FAILURE(InitViewport());
1066
Tony Barbour6918cd52015-04-09 12:58:51 -06001067 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001068 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001069
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001070 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1071 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
GregF3156cb02014-12-02 15:41:44 -07001072
Tony Barbour6918cd52015-04-09 12:58:51 -06001073 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001074 pipelineobj.AddColorAttachment();
GregF3156cb02014-12-02 15:41:44 -07001075 pipelineobj.AddShader(&vs);
1076 pipelineobj.AddShader(&ps);
1077
Tony Barbour6918cd52015-04-09 12:58:51 -06001078 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001079
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001080#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001081 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001082 MESH_BIND_ID, // binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001083 sizeof(g_vbData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001084 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
GregF3156cb02014-12-02 15:41:44 -07001085 };
1086
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001087 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001088 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1089 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001090 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001091 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
GregF3156cb02014-12-02 15:41:44 -07001092
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001093 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF3156cb02014-12-02 15:41:44 -07001094 pipelineobj.AddVertexInputBindings(&vi_binding,1);
GregF3156cb02014-12-02 15:41:44 -07001095
Tony Barbour664accc2015-01-09 12:55:14 -07001096 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour664accc2015-01-09 12:55:14 -07001097
Tony Barbourfe3351b2015-07-28 10:17:20 -06001098 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001099
Tony Barbourfe3351b2015-07-28 10:17:20 -06001100 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001101
Tony Barbourfe3351b2015-07-28 10:17:20 -06001102 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001103#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001104 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001105 pDSDumpDot((char*)"triTest2.dot");
1106#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001107
Tony Barbour664accc2015-01-09 12:55:14 -07001108 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001109 Draw(6, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001110
1111 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001112 EndCommandBuffer();
1113 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001114
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001115 RecordImages(m_renderTargets);
GregF3156cb02014-12-02 15:41:44 -07001116}
1117
Tony Barbour6918cd52015-04-09 12:58:51 -06001118TEST_F(VkRenderTest, RedCirclesonBlue)
GregF3156cb02014-12-02 15:41:44 -07001119{
1120 // This tests that we correctly handle unread fragment inputs
1121
1122 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07001123 "#version 400\n"
GregF3156cb02014-12-02 15:41:44 -07001124 "#extension GL_ARB_separate_shader_objects : enable\n"
1125 "#extension GL_ARB_shading_language_420pack : enable\n"
1126 "layout (location = 0) in vec4 pos;\n"
1127 "layout (location = 0) out vec4 outColor;\n"
1128 "layout (location = 1) out vec4 outColor2;\n"
Tony Barboure804d202016-01-05 13:37:45 -07001129 "out gl_PerVertex {\n"
1130 " vec4 gl_Position;\n"
1131 "};\n"
GregF3156cb02014-12-02 15:41:44 -07001132 "void main() {\n"
1133 " gl_Position = pos;\n"
1134 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1135 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1136 "}\n";
1137
1138 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07001139 "#version 400\n"
GregF3156cb02014-12-02 15:41:44 -07001140 "#extension GL_ARB_separate_shader_objects : enable\n"
1141 "#extension GL_ARB_shading_language_420pack : enable\n"
1142 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1143 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1144 "layout (location = 0) in vec4 color;\n"
1145 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001146 "layout (location = 0) out vec4 outColor;\n"
GregF3156cb02014-12-02 15:41:44 -07001147 "void main() {\n"
1148 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1149 " float dist_squared = dot(pos, pos);\n"
GregFaae75242015-06-03 18:40:50 -06001150 " outColor = (dist_squared < 400.0)\n"
GregF3156cb02014-12-02 15:41:44 -07001151 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1152 " : color2;\n"
1153 "}\n";
1154
1155 ASSERT_NO_FATAL_FAILURE(InitState());
1156 ASSERT_NO_FATAL_FAILURE(InitViewport());
1157
Tony Barbour6918cd52015-04-09 12:58:51 -06001158 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001159 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001160
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001161 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1162 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
GregF3156cb02014-12-02 15:41:44 -07001163
Tony Barbour6918cd52015-04-09 12:58:51 -06001164 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001165 pipelineobj.AddColorAttachment();
GregF3156cb02014-12-02 15:41:44 -07001166 pipelineobj.AddShader(&vs);
1167 pipelineobj.AddShader(&ps);
1168
Tony Barbour6918cd52015-04-09 12:58:51 -06001169 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001170
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001171#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001172 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001173 MESH_BIND_ID, // binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001174 sizeof(g_vbData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001175 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
GregF3156cb02014-12-02 15:41:44 -07001176 };
1177
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001178 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001179 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1180 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001181 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001182 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
GregF3156cb02014-12-02 15:41:44 -07001183
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001184 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF3156cb02014-12-02 15:41:44 -07001185 pipelineobj.AddVertexInputBindings(&vi_binding,1);
GregF3156cb02014-12-02 15:41:44 -07001186
Tony Barbour664accc2015-01-09 12:55:14 -07001187 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001188 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001189
Tony Barbourfe3351b2015-07-28 10:17:20 -06001190 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001191
Tony Barbourfe3351b2015-07-28 10:17:20 -06001192 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001193#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001194 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001195 pDSDumpDot((char*)"triTest2.dot");
1196#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001197 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001198 Draw(6, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001199
1200 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001201 EndCommandBuffer();
1202 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001203
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001204 RecordImages(m_renderTargets);
GregF3156cb02014-12-02 15:41:44 -07001205}
1206
Tony Barbour6918cd52015-04-09 12:58:51 -06001207TEST_F(VkRenderTest, GreyCirclesonBlueFade)
GregF3156cb02014-12-02 15:41:44 -07001208{
1209 // This tests reading gl_ClipDistance from FS
1210
1211 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07001212 "#version 400\n"
GregF3156cb02014-12-02 15:41:44 -07001213 "#extension GL_ARB_separate_shader_objects : enable\n"
1214 "#extension GL_ARB_shading_language_420pack : enable\n"
1215 "out gl_PerVertex {\n"
1216 " vec4 gl_Position;\n"
1217 " float gl_ClipDistance[1];\n"
1218 "};\n"
1219 "layout (location = 0) in vec4 pos;\n"
1220 "layout (location = 0) out vec4 outColor;\n"
1221 "layout (location = 1) out vec4 outColor2;\n"
1222 "void main() {\n"
1223 " gl_Position = pos;\n"
1224 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1225 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1226 " float dists[3];\n"
1227 " dists[0] = 0.0;\n"
1228 " dists[1] = 1.0;\n"
1229 " dists[2] = 1.0;\n"
1230 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1231 "}\n";
1232
1233
1234 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07001235 "#version 400\n"
GregF3156cb02014-12-02 15:41:44 -07001236 "#extension GL_ARB_separate_shader_objects : enable\n"
1237 "#extension GL_ARB_shading_language_420pack : enable\n"
1238 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1239 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1240 "layout (location = 0) in vec4 color;\n"
1241 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001242 "layout (location = 0) out vec4 uFragColor;\n"
GregF3156cb02014-12-02 15:41:44 -07001243 "void main() {\n"
1244 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1245 " float dist_squared = dot(pos, pos);\n"
GregFaae75242015-06-03 18:40:50 -06001246 " uFragColor = (dist_squared < 400.0)\n"
GregF3156cb02014-12-02 15:41:44 -07001247 " ? color * gl_ClipDistance[0]\n"
1248 " : color2;\n"
1249 "}\n";
1250
1251 ASSERT_NO_FATAL_FAILURE(InitState());
1252 ASSERT_NO_FATAL_FAILURE(InitViewport());
1253
Tony Barbour6918cd52015-04-09 12:58:51 -06001254 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001255 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001256
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001257 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1258 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
GregF3156cb02014-12-02 15:41:44 -07001259
Tony Barbour6918cd52015-04-09 12:58:51 -06001260 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001261 pipelineobj.AddColorAttachment();
GregF3156cb02014-12-02 15:41:44 -07001262 pipelineobj.AddShader(&vs);
1263 pipelineobj.AddShader(&ps);
1264
Tony Barbour6918cd52015-04-09 12:58:51 -06001265 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001266
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001267#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001268 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001269 MESH_BIND_ID, // binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001270 sizeof(g_vbData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001271 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
GregF3156cb02014-12-02 15:41:44 -07001272 };
1273
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001274 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001275 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1276 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001277 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001278 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
GregF3156cb02014-12-02 15:41:44 -07001279
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001280 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF3156cb02014-12-02 15:41:44 -07001281 pipelineobj.AddVertexInputBindings(&vi_binding,1);
GregF3156cb02014-12-02 15:41:44 -07001282
Tony Barbour664accc2015-01-09 12:55:14 -07001283 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
GregF3156cb02014-12-02 15:41:44 -07001284
Tony Barbourfe3351b2015-07-28 10:17:20 -06001285 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001286
Tony Barbourfe3351b2015-07-28 10:17:20 -06001287 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001288
Tony Barbourfe3351b2015-07-28 10:17:20 -06001289 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001290#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
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001296 Draw(6, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001297
1298 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001299 EndCommandBuffer();
1300 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001301
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001302 RecordImages(m_renderTargets);
GregF3156cb02014-12-02 15:41:44 -07001303}
Tony Barboure2c58df2014-11-25 13:18:32 -07001304
Tony Barbour6918cd52015-04-09 12:58:51 -06001305TEST_F(VkRenderTest, GreyCirclesonBlueDiscard)
GregF42226582014-12-02 17:19:34 -07001306{
1307 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07001308 "#version 400\n"
GregF42226582014-12-02 17:19:34 -07001309 "#extension GL_ARB_separate_shader_objects : enable\n"
1310 "#extension GL_ARB_shading_language_420pack : enable\n"
1311 "layout (location = 0) in vec4 pos;\n"
1312 "layout (location = 0) out vec4 outColor;\n"
1313 "layout (location = 1) out vec4 outColor2;\n"
Tony Barboure804d202016-01-05 13:37:45 -07001314 "out gl_PerVertex {\n"
1315 " vec4 gl_Position;\n"
1316 "};\n"
GregF42226582014-12-02 17:19:34 -07001317 "void main() {\n"
1318 " gl_Position = pos;\n"
1319 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1320 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1321 "}\n";
1322
1323
1324 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07001325 "#version 400\n"
GregF42226582014-12-02 17:19:34 -07001326 "#extension GL_ARB_separate_shader_objects : enable\n"
1327 "#extension GL_ARB_shading_language_420pack : enable\n"
1328 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1329 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1330 "layout (location = 0) in vec4 color;\n"
1331 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001332 "layout (location = 0) out vec4 outColor;\n"
GregF42226582014-12-02 17:19:34 -07001333 "void main() {\n"
1334 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1335 " float dist_squared = dot(pos, pos);\n"
1336 " if (dist_squared < 100.0)\n"
1337 " discard;\n"
GregFaae75242015-06-03 18:40:50 -06001338 " outColor = (dist_squared < 400.0)\n"
GregF42226582014-12-02 17:19:34 -07001339 " ? color\n"
1340 " : color2;\n"
1341 "}\n";
1342
1343 ASSERT_NO_FATAL_FAILURE(InitState());
1344 ASSERT_NO_FATAL_FAILURE(InitViewport());
1345
Tony Barbour6918cd52015-04-09 12:58:51 -06001346 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001347 meshBuffer.BufferMemoryBarrier();
GregF42226582014-12-02 17:19:34 -07001348
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001349 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1350 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
GregF42226582014-12-02 17:19:34 -07001351
Tony Barbour6918cd52015-04-09 12:58:51 -06001352 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001353 pipelineobj.AddColorAttachment();
GregF42226582014-12-02 17:19:34 -07001354 pipelineobj.AddShader(&vs);
1355 pipelineobj.AddShader(&ps);
1356
Tony Barbour6918cd52015-04-09 12:58:51 -06001357 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001358
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001359#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001360 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001361 MESH_BIND_ID, // binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001362 sizeof(g_vbData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001363 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
GregF42226582014-12-02 17:19:34 -07001364 };
1365
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001366 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001367 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1368 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001369 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001370 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
GregF42226582014-12-02 17:19:34 -07001371
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001372 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF42226582014-12-02 17:19:34 -07001373 pipelineobj.AddVertexInputBindings(&vi_binding,1);
GregF42226582014-12-02 17:19:34 -07001374
Tony Barbour664accc2015-01-09 12:55:14 -07001375 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour664accc2015-01-09 12:55:14 -07001376
Tony Barbourfe3351b2015-07-28 10:17:20 -06001377 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001378
Tony Barbourfe3351b2015-07-28 10:17:20 -06001379 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001380
Tony Barbourfe3351b2015-07-28 10:17:20 -06001381 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001382#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001383 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001384 pDSDumpDot((char*)"triTest2.dot");
1385#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001386
1387 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001388 Draw(6, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001389
1390 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001391 EndCommandBuffer();
1392 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001393
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001394 RecordImages(m_renderTargets);
GregF42226582014-12-02 17:19:34 -07001395}
1396
1397
Tony Barbour6918cd52015-04-09 12:58:51 -06001398TEST_F(VkRenderTest, TriangleVSUniform)
Cody Northrop66594a72014-10-10 14:49:36 -06001399{
1400 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07001401 "#version 400\n"
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001402 "#extension GL_ARB_separate_shader_objects : enable\n"
1403 "#extension GL_ARB_shading_language_420pack : enable\n"
1404 "\n"
1405 "layout(binding = 0) uniform buf {\n"
1406 " mat4 MVP;\n"
1407 "} ubuf;\n"
Tony Barboure804d202016-01-05 13:37:45 -07001408 "out gl_PerVertex {\n"
1409 " vec4 gl_Position;\n"
1410 "};\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001411 "void main() {\n"
1412 " vec2 vertices[3];"
1413 " vertices[0] = vec2(-0.5, -0.5);\n"
1414 " vertices[1] = vec2( 0.5, -0.5);\n"
1415 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001416 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001417 "}\n";
1418
1419 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07001420 "#version 400\n"
GregFaae75242015-06-03 18:40:50 -06001421 "#extension GL_ARB_separate_shader_objects : enable\n"
1422 "#extension GL_ARB_shading_language_420pack : enable\n"
1423 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001424 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001425 " outColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001426 "}\n";
1427
Tony Barboure2c58df2014-11-25 13:18:32 -07001428 ASSERT_NO_FATAL_FAILURE(InitState());
1429 ASSERT_NO_FATAL_FAILURE(InitViewport());
1430
Courtney Goeltzenleuchterfdcfb9f2014-10-10 18:04:39 -06001431 // Create identity matrix
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001432 glm::mat4 Projection = glm::mat4(1.0f);
1433 glm::mat4 View = glm::mat4(1.0f);
1434 glm::mat4 Model = glm::mat4(1.0f);
1435 glm::mat4 MVP = Projection * View * Model;
1436 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1437
Tony Barbour6918cd52015-04-09 12:58:51 -06001438 VkConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001439 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1440 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001441
Tony Barbour6918cd52015-04-09 12:58:51 -06001442 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001443 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001444 pipelineobj.AddShader(&vs);
1445 pipelineobj.AddShader(&ps);
1446
1447 // Create descriptor set and attach the constant buffer to it
Tony Barbour6918cd52015-04-09 12:58:51 -06001448 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001449 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07001450
Tony Barbour664accc2015-01-09 12:55:14 -07001451 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf1878c72015-08-18 14:24:32 -06001452
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001453 VkCommandBufferBeginInfo cbBeginInfo;
1454 memset(&cbBeginInfo, 0, sizeof(VkCommandBufferBeginInfo));
1455 cbBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Courtney Goeltzenleuchter04bb5f82015-10-21 18:11:04 -06001456 cbBeginInfo.flags = 0;
Tobin Ehlisf1878c72015-08-18 14:24:32 -06001457 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barboure2c58df2014-11-25 13:18:32 -07001458
Tony Barbourfe3351b2015-07-28 10:17:20 -06001459 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001460
Tony Barbour664accc2015-01-09 12:55:14 -07001461#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001462 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001463 pDSDumpDot((char*)"triTest2.dot");
1464#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001465
1466 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001467 Draw(6, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001468
1469 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001470 EndCommandBuffer();
1471 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001472
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001473 RecordImages(m_renderTargets);
Tony Barbour664accc2015-01-09 12:55:14 -07001474
Tony Barbourfe3351b2015-07-28 10:17:20 -06001475 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer);
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001476}
1477
Tony Barbour6918cd52015-04-09 12:58:51 -06001478TEST_F(VkRenderTest, MixTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07001479{
1480 // This tests location applied to varyings. Notice that we have switched foo
1481 // and bar in the FS. The triangle should be blended with red, green and blue
1482 // corners.
1483 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07001484 "#version 400\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001485 "#extension GL_ARB_separate_shader_objects : enable\n"
1486 "#extension GL_ARB_shading_language_420pack : enable\n"
1487 "layout (location=0) out vec4 bar;\n"
1488 "layout (location=1) out vec4 foo;\n"
1489 "layout (location=2) out float scale;\n"
Tony Barboure804d202016-01-05 13:37:45 -07001490 "out gl_PerVertex {\n"
1491 " vec4 gl_Position;\n"
1492 "};\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001493 "vec2 vertices[3];\n"
1494 "void main() {\n"
1495 " vertices[0] = vec2(-1.0, -1.0);\n"
1496 " vertices[1] = vec2( 1.0, -1.0);\n"
1497 " vertices[2] = vec2( 0.0, 1.0);\n"
1498 "vec4 colors[3];\n"
1499 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1500 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1501 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1502 " foo = colors[gl_VertexID % 3];\n"
1503 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1504 " scale = 1.0;\n"
1505 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1506 "}\n";
1507
1508 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07001509 "#version 400\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001510 "#extension GL_ARB_separate_shader_objects : enable\n"
1511 "#extension GL_ARB_shading_language_420pack : enable\n"
1512 "layout (location = 1) in vec4 bar;\n"
1513 "layout (location = 0) in vec4 foo;\n"
1514 "layout (location = 2) in float scale;\n"
GregFaae75242015-06-03 18:40:50 -06001515 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001516 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001517 " outColor = bar * scale + foo * (1.0-scale);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001518 "}\n";
1519
1520 ASSERT_NO_FATAL_FAILURE(InitState());
1521 ASSERT_NO_FATAL_FAILURE(InitViewport());
1522
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001523 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1524 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001525
Tony Barbour6918cd52015-04-09 12:58:51 -06001526 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001527 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001528 pipelineobj.AddShader(&vs);
1529 pipelineobj.AddShader(&ps);
1530
Tony Barbour6918cd52015-04-09 12:58:51 -06001531 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour831062d2015-04-02 15:43:15 -06001532 descriptorSet.AppendDummy();
Tony Barboure2c58df2014-11-25 13:18:32 -07001533
Tony Barbour664accc2015-01-09 12:55:14 -07001534 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour664accc2015-01-09 12:55:14 -07001535
Tony Barbourfe3351b2015-07-28 10:17:20 -06001536 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001537
Tony Barbourfe3351b2015-07-28 10:17:20 -06001538 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001539
1540#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001541 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001542 pDSDumpDot((char*)"triTest2.dot");
1543#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001544
Tony Barbour664accc2015-01-09 12:55:14 -07001545 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001546 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001547
1548 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001549 EndCommandBuffer();
1550 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001551
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001552 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001553}
1554
Tony Barbour6918cd52015-04-09 12:58:51 -06001555TEST_F(VkRenderTest, QuadVertFetchAndVertID)
Tony Barboure2c58df2014-11-25 13:18:32 -07001556{
1557 // This tests that attributes work in the presence of gl_VertexID
1558
1559 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07001560 "#version 400\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001561 "#extension GL_ARB_separate_shader_objects : enable\n"
1562 "#extension GL_ARB_shading_language_420pack : enable\n"
1563 //XYZ1( -1, -1, -1 )
1564 "layout (location = 0) in vec4 pos;\n"
1565 //XYZ1( 0.f, 0.f, 0.f )
1566 "layout (location = 1) in vec4 inColor;\n"
1567 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure804d202016-01-05 13:37:45 -07001568 "out gl_PerVertex {\n"
1569 " vec4 gl_Position;\n"
1570 "};\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001571 "void main() {\n"
1572 " outColor = inColor;\n"
1573 " vec4 vertices[3];"
1574 " vertices[gl_VertexID % 3] = pos;\n"
1575 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1576 "}\n";
1577
1578
1579 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07001580 "#version 400\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001581 "#extension GL_ARB_separate_shader_objects : enable\n"
1582 "#extension GL_ARB_shading_language_420pack : enable\n"
1583 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06001584 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001585 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001586 " outColor = color;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001587 "}\n";
1588
1589 ASSERT_NO_FATAL_FAILURE(InitState());
1590 ASSERT_NO_FATAL_FAILURE(InitViewport());
1591
Tony Barbour6918cd52015-04-09 12:58:51 -06001592 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001593 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07001594
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001595 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1596 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001597
Tony Barbour6918cd52015-04-09 12:58:51 -06001598 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001599 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001600 pipelineobj.AddShader(&vs);
1601 pipelineobj.AddShader(&ps);
1602
Tony Barbour6918cd52015-04-09 12:58:51 -06001603 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001604
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001605#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001606 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001607 MESH_BUF_ID, // Binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001608 sizeof(g_vbData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001609 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
Tony Barboure2c58df2014-11-25 13:18:32 -07001610 };
1611
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001612 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001613 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1614 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001615 vi_attribs[0].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001616 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001617 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1618 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001619 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001620 vi_attribs[1].offset = 16; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -07001621
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001622 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001623 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barboure2c58df2014-11-25 13:18:32 -07001624
Tony Barbour664accc2015-01-09 12:55:14 -07001625 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour664accc2015-01-09 12:55:14 -07001626
Tony Barbourfe3351b2015-07-28 10:17:20 -06001627 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001628
Tony Barbourfe3351b2015-07-28 10:17:20 -06001629 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001630
Tony Barbourfe3351b2015-07-28 10:17:20 -06001631 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001632#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001633 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001634 pDSDumpDot((char*)"triTest2.dot");
1635#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001636
1637 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001638 Draw(6, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001639
1640 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001641 EndCommandBuffer();
1642 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001643
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001644 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001645}
1646
Tony Barbour6918cd52015-04-09 12:58:51 -06001647TEST_F(VkRenderTest, QuadSparseVertFetch)
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001648{
1649 // This tests that attributes work in the presence of gl_VertexID
1650
1651 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07001652 "#version 400\n"
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001653 "#extension GL_ARB_separate_shader_objects : enable\n"
1654 "#extension GL_ARB_shading_language_420pack : enable\n"
1655 //XYZ1( -1, -1, -1 )
1656 "layout (location = 1) in vec4 pos;\n"
1657 "layout (location = 4) in vec4 inColor;\n"
1658 //XYZ1( 0.f, 0.f, 0.f )
1659 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure804d202016-01-05 13:37:45 -07001660 "out gl_PerVertex {\n"
1661 " vec4 gl_Position;\n"
1662 "};\n"
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001663 "void main() {\n"
1664 " outColor = inColor;\n"
1665 " gl_Position = pos;\n"
1666 "}\n";
1667
1668
1669 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07001670 "#version 400\n"
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001671 "#extension GL_ARB_separate_shader_objects : enable\n"
1672 "#extension GL_ARB_shading_language_420pack : enable\n"
1673 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06001674 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001675 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001676 " outColor = color;\n"
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001677 "}\n";
1678
1679 ASSERT_NO_FATAL_FAILURE(InitState());
1680 ASSERT_NO_FATAL_FAILURE(InitViewport());
1681
1682 struct VDATA
1683 {
1684 float t1, t2, t3, t4; // filler data
1685 float posX, posY, posZ, posW; // Position data
1686 float r, g, b, a; // Color
1687 };
1688 const struct VDATA vData[] =
1689 {
1690 { XYZ1(0, 0, 0), XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
1691 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1692 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1693 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1694 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1695 { XYZ1(0, 0, 0), XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
1696 };
1697
Tony Barbour6918cd52015-04-09 12:58:51 -06001698 VkConstantBufferObj meshBuffer(m_device,sizeof(vData)/sizeof(vData[0]),sizeof(vData[0]), vData);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001699 meshBuffer.BufferMemoryBarrier();
1700
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001701 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1702 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001703
Tony Barbour6918cd52015-04-09 12:58:51 -06001704 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001705 pipelineobj.AddColorAttachment();
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001706 pipelineobj.AddShader(&vs);
1707 pipelineobj.AddShader(&ps);
1708
Tony Barbour6918cd52015-04-09 12:58:51 -06001709 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001710
1711#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001712 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001713 MESH_BUF_ID, // Binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001714 sizeof(vData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001715 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001716 };
1717
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001718 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001719 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1720 vi_attribs[0].location = 4;
Tony Barbourd1c35722015-04-16 15:59:00 -06001721 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001722 vi_attribs[0].offset = sizeof(float) * 4 * 2; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001723 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1724 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001725 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001726 vi_attribs[1].offset = sizeof(float) * 4 * 1; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001727
1728 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
1729 pipelineobj.AddVertexInputBindings(&vi_binding, 1);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001730
1731 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001732
Tony Barbourfe3351b2015-07-28 10:17:20 -06001733 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001734
Tony Barbourfe3351b2015-07-28 10:17:20 -06001735 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001736
Tony Barbourfe3351b2015-07-28 10:17:20 -06001737 BindVertexBuffer(&meshBuffer, 0, MESH_BUF_ID);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001738#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001739 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001740 pDSDumpDot((char*)"triTest2.dot");
1741#endif
1742
1743 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001744 Draw(6, 1, 0, 0);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001745
1746 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001747 EndCommandBuffer();
1748 QueueCommandBuffer();
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001749
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001750 RecordImages(m_renderTargets);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001751}
1752
Tony Barbour6918cd52015-04-09 12:58:51 -06001753TEST_F(VkRenderTest, TriVertFetchDeadAttr)
Tony Barboure2c58df2014-11-25 13:18:32 -07001754{
1755 // This tests that attributes work in the presence of gl_VertexID
1756 // and a dead attribute in position 0. Draws a triangle with yellow,
1757 // red and green corners, starting at top and going clockwise.
1758
1759 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07001760 "#version 400\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001761 "#extension GL_ARB_separate_shader_objects : enable\n"
1762 "#extension GL_ARB_shading_language_420pack : enable\n"
1763 //XYZ1( -1, -1, -1 )
1764 "layout (location = 0) in vec4 pos;\n"
1765 //XYZ1( 0.f, 0.f, 0.f )
1766 "layout (location = 1) in vec4 inColor;\n"
1767 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure804d202016-01-05 13:37:45 -07001768 "out gl_PerVertex {\n"
1769 " vec4 gl_Position;\n"
1770 "};\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001771 "void main() {\n"
1772 " outColor = inColor;\n"
1773 " vec2 vertices[3];"
1774 " vertices[0] = vec2(-1.0, -1.0);\n"
1775 " vertices[1] = vec2( 1.0, -1.0);\n"
1776 " vertices[2] = vec2( 0.0, 1.0);\n"
1777 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1778 "}\n";
1779
1780
1781 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07001782 "#version 400\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001783 "#extension GL_ARB_separate_shader_objects : enable\n"
1784 "#extension GL_ARB_shading_language_420pack : enable\n"
1785 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06001786 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001787 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001788 " outColor = color;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001789 "}\n";
1790
1791 ASSERT_NO_FATAL_FAILURE(InitState());
1792 ASSERT_NO_FATAL_FAILURE(InitViewport());
1793
Tony Barbour6918cd52015-04-09 12:58:51 -06001794 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001795 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07001796
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001797 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1798 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001799
Tony Barbour6918cd52015-04-09 12:58:51 -06001800 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001801 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001802 pipelineobj.AddShader(&vs);
1803 pipelineobj.AddShader(&ps);
1804
Tony Barbour6918cd52015-04-09 12:58:51 -06001805 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001806
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001807#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001808 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001809 MESH_BUF_ID, // Binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001810 sizeof(g_vbData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001811 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
Tony Barboure2c58df2014-11-25 13:18:32 -07001812 };
1813
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001814 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001815 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1816 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001817 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001818 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001819 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1820 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001821 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001822 vi_attribs[1].offset = 16; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -07001823
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001824 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001825 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barboure2c58df2014-11-25 13:18:32 -07001826
Tony Barbour664accc2015-01-09 12:55:14 -07001827 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboure2c58df2014-11-25 13:18:32 -07001828
Tony Barbourfe3351b2015-07-28 10:17:20 -06001829 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001830
Tony Barbourfe3351b2015-07-28 10:17:20 -06001831 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001832
Tony Barbourfe3351b2015-07-28 10:17:20 -06001833 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001834#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001835 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001836 pDSDumpDot((char*)"triTest2.dot");
1837#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001838
1839 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001840 Draw(6, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001841
1842 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001843 EndCommandBuffer();
1844 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001845
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001846 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001847}
1848
Tony Barbour6918cd52015-04-09 12:58:51 -06001849TEST_F(VkRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001850{
1851 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07001852 "#version 400\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001853 "#extension GL_ARB_separate_shader_objects : enable\n"
1854 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06001855 "layout (std140, binding = 0) uniform bufferVals {\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001856 " mat4 mvp;\n"
1857 "} myBufferVals;\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001858 "layout (location = 0) in vec4 pos;\n"
1859 "layout (location = 1) in vec4 inColor;\n"
Cody Northrop8a3bb132015-06-16 17:32:04 -06001860 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure804d202016-01-05 13:37:45 -07001861 "out gl_PerVertex {\n"
1862 " vec4 gl_Position;\n"
1863 "};\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001864 "void main() {\n"
1865 " outColor = inColor;\n"
1866 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06001867 " gl_Position.y = -gl_Position.y;\n"
1868 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001869 "}\n";
1870
1871 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07001872 "#version 400\n"
GregFaae75242015-06-03 18:40:50 -06001873 "#extension GL_ARB_separate_shader_objects : enable\n"
1874 "#extension GL_ARB_shading_language_420pack : enable\n"
1875 "layout (location = 0) in vec4 color;\n"
1876 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001877 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001878 " outColor = color;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001879 "}\n";
Tony Barboure2c58df2014-11-25 13:18:32 -07001880 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001881
Tony Barboure2c58df2014-11-25 13:18:32 -07001882 glm::mat4 View = glm::lookAt(
1883 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1884 glm::vec3(0,0,0), // and looks at the origin
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06001885 glm::vec3(0,-1,0) // Head is up (set to 0,-1,0 to look upside-down)
Tony Barboure2c58df2014-11-25 13:18:32 -07001886 );
1887
1888 glm::mat4 Model = glm::mat4(1.0f);
1889
1890 glm::mat4 MVP = Projection * View * Model;
1891
1892 ASSERT_NO_FATAL_FAILURE(InitState());
1893 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wub4052042015-07-09 10:16:34 +08001894 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Chia-I Wu08accc62015-07-07 11:50:03 +08001895 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height, m_depth_stencil_fmt);
Tony Barboure2c58df2014-11-25 13:18:32 -07001896
Tony Barbour6918cd52015-04-09 12:58:51 -06001897 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 -07001898 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1899
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001900 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barboure2c58df2014-11-25 13:18:32 -07001901
Tony Barbour6918cd52015-04-09 12:58:51 -06001902 VkConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001903 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1904 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001905
Tony Barbour6918cd52015-04-09 12:58:51 -06001906 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001907 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001908 pipelineobj.AddShader(&vs);
1909 pipelineobj.AddShader(&ps);
1910
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001911 VkPipelineDepthStencilStateCreateInfo ds_state;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001912 ds_state.depthTestEnable = VK_TRUE;
1913 ds_state.depthWriteEnable = VK_TRUE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001914 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL;
Cody Northrop271ba752015-08-26 10:01:32 -06001915 ds_state.depthBoundsTestEnable = VK_FALSE;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001916 ds_state.stencilTestEnable = VK_FALSE;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001917 ds_state.back.depthFailOp = VK_STENCIL_OP_KEEP;
1918 ds_state.back.failOp = VK_STENCIL_OP_KEEP;
1919 ds_state.back.passOp = VK_STENCIL_OP_KEEP;
1920 ds_state.back.compareOp = VK_COMPARE_OP_ALWAYS;
Tony Barbourf52346d2015-01-16 14:27:35 -07001921 ds_state.front = ds_state.back;
1922 pipelineobj.SetDepthStencil(&ds_state);
1923
Tony Barbour6918cd52015-04-09 12:58:51 -06001924 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001925 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07001926
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001927#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001928 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001929 MESH_BUF_ID, // Binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001930 sizeof(g_vbData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001931 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001932 };
Tony Barboure2c58df2014-11-25 13:18:32 -07001933
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001934 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001935 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1936 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001937 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001938 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001939 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1940 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001941 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001942 vi_attribs[1].offset = 16; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -07001943
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001944 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001945 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barboure2c58df2014-11-25 13:18:32 -07001946
Tony Barbour1c45ce02015-03-27 17:03:18 -06001947 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour1c45ce02015-03-27 17:03:18 -06001948
Tony Barbourfe3351b2015-07-28 10:17:20 -06001949 ASSERT_VK_SUCCESS(BeginCommandBuffer());
1950 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barboure2c58df2014-11-25 13:18:32 -07001951
Tony Barbourfe3351b2015-07-28 10:17:20 -06001952 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour1fde6942015-01-09 10:06:53 -07001953#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001954 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour1fde6942015-01-09 10:06:53 -07001955 pDSDumpDot((char*)"triTest2.dot");
1956#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001957
1958 // render triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001959 Draw(36, 1, 0, 0);
Tony Barbour1fde6942015-01-09 10:06:53 -07001960
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001961
Tony Barbour1fde6942015-01-09 10:06:53 -07001962 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001963 EndCommandBuffer();
1964 QueueCommandBuffer();
Tony Barbour1fde6942015-01-09 10:06:53 -07001965
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001966 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001967}
1968
Tony Barbour6918cd52015-04-09 12:58:51 -06001969TEST_F(VkRenderTest, VSTexture)
Tony Barboure2c58df2014-11-25 13:18:32 -07001970{
1971 // The expected result from this test is a green and red triangle;
1972 // one red vertex on the left, two green vertices on the right.
1973 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07001974 "#version 400\n"
Cody Northrop8a3bb132015-06-16 17:32:04 -06001975 "#extension GL_ARB_separate_shader_objects : enable\n"
1976 "#extension GL_ARB_shading_language_420pack : enable\n"
1977 "layout (location = 0) out vec4 texColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001978 "uniform sampler2D surface;\n"
Tony Barboure804d202016-01-05 13:37:45 -07001979 "out gl_PerVertex {\n"
1980 " vec4 gl_Position;\n"
1981 "};\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001982 "void main() {\n"
1983 " vec2 vertices[3];"
1984 " vertices[0] = vec2(-0.5, -0.5);\n"
1985 " vertices[1] = vec2( 0.5, -0.5);\n"
1986 " vertices[2] = vec2( 0.5, 0.5);\n"
1987 " vec2 positions[3];"
1988 " positions[0] = vec2( 0.0, 0.0);\n"
1989 " positions[1] = vec2( 0.25, 0.1);\n"
1990 " positions[2] = vec2( 0.1, 0.25);\n"
1991 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1992 " texColor = textureLod(surface, samplePos, 0.0);\n"
1993 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1994 "}\n";
1995
1996 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07001997 "#version 400\n"
GregFaae75242015-06-03 18:40:50 -06001998 "#extension GL_ARB_separate_shader_objects : enable\n"
1999 "#extension GL_ARB_shading_language_420pack : enable\n"
2000 "layout (location = 0) in vec4 texColor;\n"
2001 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002002 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06002003 " outColor = texColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002004 "}\n";
2005
2006 ASSERT_NO_FATAL_FAILURE(InitState());
2007 ASSERT_NO_FATAL_FAILURE(InitViewport());
2008
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002009 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2010 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbour6918cd52015-04-09 12:58:51 -06002011 VkSamplerObj sampler(m_device);
2012 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002013
Tony Barbour6918cd52015-04-09 12:58:51 -06002014 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002015 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002016 pipelineobj.AddShader(&vs);
2017 pipelineobj.AddShader(&ps);
2018
Tony Barbour6918cd52015-04-09 12:58:51 -06002019 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002020 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002021
Tony Barbour664accc2015-01-09 12:55:14 -07002022 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002023 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure2c58df2014-11-25 13:18:32 -07002024
Tony Barbourfe3351b2015-07-28 10:17:20 -06002025 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002026
2027#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002028 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002029 pDSDumpDot((char*)"triTest2.dot");
2030#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002031
Tony Barbour664accc2015-01-09 12:55:14 -07002032 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002033 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002034
2035 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002036 EndCommandBuffer();
2037 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002038
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002039 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002040}
GregFaae75242015-06-03 18:40:50 -06002041
2042
2043
Tony Barbour6918cd52015-04-09 12:58:51 -06002044TEST_F(VkRenderTest, TexturedTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07002045{
2046 // The expected result from this test is a red and green checkered triangle
2047 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07002048 "#version 400\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002049 "#extension GL_ARB_separate_shader_objects : enable\n"
2050 "#extension GL_ARB_shading_language_420pack : enable\n"
2051 "layout (location = 0) out vec2 samplePos;\n"
Tony Barboure804d202016-01-05 13:37:45 -07002052 "out gl_PerVertex {\n"
2053 " vec4 gl_Position;\n"
2054 "};\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002055 "void main() {\n"
2056 " vec2 vertices[3];"
2057 " vertices[0] = vec2(-0.5, -0.5);\n"
2058 " vertices[1] = vec2( 0.5, -0.5);\n"
2059 " vertices[2] = vec2( 0.5, 0.5);\n"
2060 " vec2 positions[3];"
2061 " positions[0] = vec2( 0.0, 0.0);\n"
2062 " positions[1] = vec2( 1.0, 0.0);\n"
2063 " positions[2] = vec2( 1.0, 1.0);\n"
2064 " samplePos = positions[gl_VertexID % 3];\n"
2065 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2066 "}\n";
2067
2068 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07002069 "#version 400\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002070 "#extension GL_ARB_separate_shader_objects : enable\n"
2071 "#extension GL_ARB_shading_language_420pack : enable\n"
2072 "layout (location = 0) in vec2 samplePos;\n"
2073 "layout (binding = 0) uniform sampler2D surface;\n"
2074 "layout (location=0) out vec4 outColor;\n"
2075 "void main() {\n"
2076 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2077 " outColor = texColor;\n"
2078 "}\n";
2079
2080 ASSERT_NO_FATAL_FAILURE(InitState());
2081 ASSERT_NO_FATAL_FAILURE(InitViewport());
2082
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002083 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2084 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbour6918cd52015-04-09 12:58:51 -06002085 VkSamplerObj sampler(m_device);
2086 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002087
Tony Barbour6918cd52015-04-09 12:58:51 -06002088 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002089 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002090 pipelineobj.AddShader(&vs);
2091 pipelineobj.AddShader(&ps);
2092
Tony Barbour6918cd52015-04-09 12:58:51 -06002093 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002094 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002095
Tony Barbour664accc2015-01-09 12:55:14 -07002096 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002097 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002098
Tony Barbourfe3351b2015-07-28 10:17:20 -06002099 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002100
2101#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002102 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002103 pDSDumpDot((char*)"triTest2.dot");
2104#endif
2105 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002106 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002107
2108 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002109 EndCommandBuffer();
2110 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002111
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002112 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002113}
Tony Barbour6918cd52015-04-09 12:58:51 -06002114TEST_F(VkRenderTest, TexturedTriangleClip)
Tony Barboure2c58df2014-11-25 13:18:32 -07002115{
2116 // The expected result from this test is a red and green checkered triangle
2117 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07002118 "#version 400\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002119 "#extension GL_ARB_separate_shader_objects : enable\n"
2120 "#extension GL_ARB_shading_language_420pack : enable\n"
2121 "layout (location = 0) out vec2 samplePos;\n"
2122 "out gl_PerVertex {\n"
2123 " vec4 gl_Position;\n"
2124 " float gl_ClipDistance[1];\n"
2125 "};\n"
2126 "void main() {\n"
2127 " vec2 vertices[3];"
2128 " vertices[0] = vec2(-0.5, -0.5);\n"
2129 " vertices[1] = vec2( 0.5, -0.5);\n"
2130 " vertices[2] = vec2( 0.5, 0.5);\n"
2131 " vec2 positions[3];"
2132 " positions[0] = vec2( 0.0, 0.0);\n"
2133 " positions[1] = vec2( 1.0, 0.0);\n"
2134 " positions[2] = vec2( 1.0, 1.0);\n"
2135 " float dists[3];\n"
2136 " dists[0] = 1.0;\n"
2137 " dists[1] = 1.0;\n"
2138 " dists[2] = -1.0;\n"
2139 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2140 " samplePos = positions[gl_VertexID % 3];\n"
2141 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2142 "}\n";
2143
2144 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07002145 "#version 400\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002146 "#extension GL_ARB_separate_shader_objects : enable\n"
2147 "#extension GL_ARB_shading_language_420pack : enable\n"
2148 "layout (location = 0) in vec2 samplePos;\n"
2149 "layout (binding = 0) uniform sampler2D surface;\n"
2150 "layout (location=0) out vec4 outColor;\n"
2151 "void main() {\n"
2152 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2153 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2154 " outColor = texColor;\n"
2155 "}\n";
2156
2157
2158 ASSERT_NO_FATAL_FAILURE(InitState());
2159 ASSERT_NO_FATAL_FAILURE(InitViewport());
2160
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002161 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2162 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbour6918cd52015-04-09 12:58:51 -06002163 VkSamplerObj sampler(m_device);
2164 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002165
Tony Barbour6918cd52015-04-09 12:58:51 -06002166 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002167 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002168 pipelineobj.AddShader(&vs);
2169 pipelineobj.AddShader(&ps);
2170
Tony Barbour6918cd52015-04-09 12:58:51 -06002171 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002172 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002173
Tony Barbour664accc2015-01-09 12:55:14 -07002174 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002175 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002176
Tony Barbourfe3351b2015-07-28 10:17:20 -06002177 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002178
2179#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002180 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002181 pDSDumpDot((char*)"triTest2.dot");
2182#endif
2183 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002184 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002185
2186 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002187 EndCommandBuffer();
2188 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002189
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002190 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002191}
GregFaae75242015-06-03 18:40:50 -06002192
Tony Barbour6918cd52015-04-09 12:58:51 -06002193TEST_F(VkRenderTest, FSTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07002194{
2195 // The expected result from this test is a red and green checkered triangle
2196 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07002197 "#version 400\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002198 "#extension GL_ARB_separate_shader_objects : enable\n"
2199 "#extension GL_ARB_shading_language_420pack : enable\n"
2200 "layout (location = 0) out vec2 samplePos;\n"
Tony Barboure804d202016-01-05 13:37:45 -07002201 "out gl_PerVertex {\n"
2202 " vec4 gl_Position;\n"
2203 "};\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002204 "void main() {\n"
2205 " vec2 vertices[3];"
2206 " vertices[0] = vec2(-0.5, -0.5);\n"
2207 " vertices[1] = vec2( 0.5, -0.5);\n"
2208 " vertices[2] = vec2( 0.5, 0.5);\n"
2209 " vec2 positions[3];"
2210 " positions[0] = vec2( 0.0, 0.0);\n"
2211 " positions[1] = vec2( 1.0, 0.0);\n"
2212 " positions[2] = vec2( 1.0, 1.0);\n"
2213 " samplePos = positions[gl_VertexID % 3];\n"
2214 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2215 "}\n";
2216
2217 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07002218 "#version 400\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002219 "#extension GL_ARB_separate_shader_objects : enable\n"
2220 "#extension GL_ARB_shading_language_420pack : enable\n"
2221 "layout (location = 0) in vec2 samplePos;\n"
2222 "layout (binding = 0) uniform sampler2D surface;\n"
2223 "layout (location=0) out vec4 outColor;\n"
2224 "void main() {\n"
2225 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2226 " outColor = texColor;\n"
2227 "}\n";
2228
2229 ASSERT_NO_FATAL_FAILURE(InitState());
2230 ASSERT_NO_FATAL_FAILURE(InitViewport());
2231
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002232 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2233 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbour6918cd52015-04-09 12:58:51 -06002234 VkSamplerObj sampler(m_device);
2235 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002236
Tony Barbour6918cd52015-04-09 12:58:51 -06002237 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002238 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002239 pipelineobj.AddShader(&vs);
2240 pipelineobj.AddShader(&ps);
2241
Tony Barbour6918cd52015-04-09 12:58:51 -06002242 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002243 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002244
Tony Barbour664accc2015-01-09 12:55:14 -07002245 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002246 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002247
Tony Barbourfe3351b2015-07-28 10:17:20 -06002248 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002249
2250#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002251 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002252 pDSDumpDot((char*)"triTest2.dot");
2253#endif
2254 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002255 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002256
2257 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002258 EndCommandBuffer();
2259 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002260
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002261 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002262}
Tony Barbour6918cd52015-04-09 12:58:51 -06002263TEST_F(VkRenderTest, SamplerBindingsTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07002264{
2265 // This test sets bindings on the samplers
2266 // For now we are asserting that sampler and texture pairs
2267 // march in lock step, and are set via GLSL binding. This can
2268 // and will probably change.
2269 // The sampler bindings should match the sampler and texture slot
2270 // number set up by the application.
2271 // This test will result in a blue triangle
2272 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07002273 "#version 400\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002274 "#extension GL_ARB_separate_shader_objects : enable\n"
2275 "#extension GL_ARB_shading_language_420pack : enable\n"
2276 "layout (location = 0) out vec4 samplePos;\n"
Tony Barboure804d202016-01-05 13:37:45 -07002277 "out gl_PerVertex {\n"
2278 " vec4 gl_Position;\n"
2279 "};\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002280 "void main() {\n"
2281 " vec2 vertices[3];"
2282 " vertices[0] = vec2(-0.5, -0.5);\n"
2283 " vertices[1] = vec2( 0.5, -0.5);\n"
2284 " vertices[2] = vec2( 0.5, 0.5);\n"
2285 " vec2 positions[3];"
2286 " positions[0] = vec2( 0.0, 0.0);\n"
2287 " positions[1] = vec2( 1.0, 0.0);\n"
2288 " positions[2] = vec2( 1.0, 1.0);\n"
2289 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2290 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2291 "}\n";
2292
2293 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07002294 "#version 400\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002295 "#extension GL_ARB_separate_shader_objects : enable\n"
2296 "#extension GL_ARB_shading_language_420pack : enable\n"
2297 "layout (location = 0) in vec4 samplePos;\n"
2298 "layout (binding = 0) uniform sampler2D surface0;\n"
2299 "layout (binding = 1) uniform sampler2D surface1;\n"
2300 "layout (binding = 12) uniform sampler2D surface2;\n"
GregFaae75242015-06-03 18:40:50 -06002301 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002302 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06002303 " outColor = textureLod(surface2, samplePos.xy, 0.0);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002304 "}\n";
2305
2306 ASSERT_NO_FATAL_FAILURE(InitState());
2307 ASSERT_NO_FATAL_FAILURE(InitViewport());
2308
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002309 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2310 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002311
Tony Barbour6918cd52015-04-09 12:58:51 -06002312 VkSamplerObj sampler1(m_device);
2313 VkSamplerObj sampler2(m_device);
2314 VkSamplerObj sampler3(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002315
Tony Barbourebc093f2015-04-01 16:38:10 -06002316 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
Tony Barbour6918cd52015-04-09 12:58:51 -06002317 VkTextureObj texture1(m_device, tex_colors); // Red
Tony Barbourebc093f2015-04-01 16:38:10 -06002318 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
Tony Barbour6918cd52015-04-09 12:58:51 -06002319 VkTextureObj texture2(m_device, tex_colors); // Green
Tony Barbourebc093f2015-04-01 16:38:10 -06002320 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
Tony Barbour6918cd52015-04-09 12:58:51 -06002321 VkTextureObj texture3(m_device, tex_colors); // Blue
Tony Barboure2c58df2014-11-25 13:18:32 -07002322
Tony Barbour6918cd52015-04-09 12:58:51 -06002323 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002324 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002325 pipelineobj.AddShader(&vs);
2326 pipelineobj.AddShader(&ps);
2327
Tony Barbour6918cd52015-04-09 12:58:51 -06002328 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002329 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2330 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2331 for (int i = 0; i < 10; i++)
2332 descriptorSet.AppendDummy();
2333 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barboure2c58df2014-11-25 13:18:32 -07002334
Tony Barbour664accc2015-01-09 12:55:14 -07002335 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002336 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002337
Tony Barbourfe3351b2015-07-28 10:17:20 -06002338 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002339
2340#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002341 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002342 pDSDumpDot((char*)"triTest2.dot");
2343#endif
2344 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002345 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002346
2347 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002348 EndCommandBuffer();
2349 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002350
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002351 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002352}
2353
Tony Barbour6918cd52015-04-09 12:58:51 -06002354TEST_F(VkRenderTest, TriangleVSUniformBlock)
Tony Barboure2c58df2014-11-25 13:18:32 -07002355{
2356 // The expected result from this test is a blue triangle
2357
2358 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07002359 "#version 400\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002360 "#extension GL_ARB_separate_shader_objects : enable\n"
2361 "#extension GL_ARB_shading_language_420pack : enable\n"
2362 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002363 "layout (std140, binding = 0) uniform bufferVals {\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002364 " vec4 red;\n"
2365 " vec4 green;\n"
2366 " vec4 blue;\n"
2367 " vec4 white;\n"
2368 "} myBufferVals;\n"
Tony Barboure804d202016-01-05 13:37:45 -07002369 "out gl_PerVertex {\n"
2370 " vec4 gl_Position;\n"
2371 "};\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002372 "void main() {\n"
2373 " vec2 vertices[3];"
2374 " vertices[0] = vec2(-0.5, -0.5);\n"
2375 " vertices[1] = vec2( 0.5, -0.5);\n"
2376 " vertices[2] = vec2( 0.5, 0.5);\n"
2377 " outColor = myBufferVals.blue;\n"
2378 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2379 "}\n";
2380
2381 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07002382 "#version 400\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002383 "#extension GL_ARB_separate_shader_objects : enable\n"
2384 "#extension GL_ARB_shading_language_420pack : enable\n"
2385 "layout (location = 0) in vec4 inColor;\n"
GregFaae75242015-06-03 18:40:50 -06002386 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002387 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06002388 " outColor = inColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002389 "}\n";
2390
2391 ASSERT_NO_FATAL_FAILURE(InitState());
2392 ASSERT_NO_FATAL_FAILURE(InitViewport());
2393
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002394 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2395 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002396
2397 // Let's populate our buffer with the following:
2398 // vec4 red;
2399 // vec4 green;
2400 // vec4 blue;
2401 // vec4 white;
2402 const int valCount = 4 * 4;
2403 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2404 0.0, 1.0, 0.0, 1.0,
2405 0.0, 0.0, 1.0, 1.0,
2406 1.0, 1.0, 1.0, 1.0 };
2407
Tony Barbour6918cd52015-04-09 12:58:51 -06002408 VkConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002409
Tony Barbour6918cd52015-04-09 12:58:51 -06002410 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002411 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002412 pipelineobj.AddShader(&vs);
2413 pipelineobj.AddShader(&ps);
2414
Tony Barbour6918cd52015-04-09 12:58:51 -06002415 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002416 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, colorBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002417
Tony Barbour664accc2015-01-09 12:55:14 -07002418 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002419 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002420
Tony Barbourfe3351b2015-07-28 10:17:20 -06002421 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002422
2423#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002424 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002425 pDSDumpDot((char*)"triTest2.dot");
2426#endif
2427 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002428 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002429
2430 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002431 EndCommandBuffer();
2432 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002433
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002434 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002435}
2436
Tony Barbour6918cd52015-04-09 12:58:51 -06002437TEST_F(VkRenderTest, TriangleFSUniformBlockBinding)
Tony Barboure2c58df2014-11-25 13:18:32 -07002438{
2439 // This test allows the shader to select which buffer it is
2440 // pulling from using layout binding qualifier.
2441 // There are corresponding changes in the compiler stack that
2442 // will select the buffer using binding directly.
2443 // The binding number should match the slot number set up by
2444 // the application.
2445 // The expected result from this test is a purple triangle
2446
2447 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07002448 "#version 400\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002449 "#extension GL_ARB_separate_shader_objects : enable\n"
2450 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barboure804d202016-01-05 13:37:45 -07002451 "out gl_PerVertex {\n"
2452 " vec4 gl_Position;\n"
2453 "};\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002454 "void main() {\n"
2455 " vec2 vertices[3];"
2456 " vertices[0] = vec2(-0.5, -0.5);\n"
2457 " vertices[1] = vec2( 0.5, -0.5);\n"
2458 " vertices[2] = vec2( 0.5, 0.5);\n"
2459 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2460 "}\n";
2461
2462 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07002463 "#version 400\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002464 "#extension GL_ARB_separate_shader_objects : enable\n"
2465 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002466 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2467 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2468 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
2469 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
GregFaae75242015-06-03 18:40:50 -06002470 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002471 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06002472 " outColor = myBlueVal.color;\n"
2473 " outColor += myRedVal.color;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002474 "}\n";
2475
2476 ASSERT_NO_FATAL_FAILURE(InitState());
2477 ASSERT_NO_FATAL_FAILURE(InitViewport());
2478
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002479 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2480 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002481
2482 // We're going to create a number of uniform buffers, and then allow
2483 // the shader to select which it wants to read from with a binding
2484
2485 // Let's populate the buffers with a single color each:
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002486 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2487 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2488 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2489 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barboure2c58df2014-11-25 13:18:32 -07002490
2491 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2492 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2493 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2494 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2495
2496 const int redCount = sizeof(redVals) / sizeof(float);
2497 const int greenCount = sizeof(greenVals) / sizeof(float);
2498 const int blueCount = sizeof(blueVals) / sizeof(float);
2499 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2500
Tony Barbour6918cd52015-04-09 12:58:51 -06002501 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002502
Tony Barbour6918cd52015-04-09 12:58:51 -06002503 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002504
Tony Barbour6918cd52015-04-09 12:58:51 -06002505 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002506
Tony Barbour6918cd52015-04-09 12:58:51 -06002507 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002508
Tony Barbour6918cd52015-04-09 12:58:51 -06002509 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002510 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002511 pipelineobj.AddShader(&vs);
2512 pipelineobj.AddShader(&ps);
2513
Tony Barbour6918cd52015-04-09 12:58:51 -06002514 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002515 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2516 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2517 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2518 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002519
Tony Barbour664accc2015-01-09 12:55:14 -07002520 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002521 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure2c58df2014-11-25 13:18:32 -07002522
Tony Barbourfe3351b2015-07-28 10:17:20 -06002523 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002524
2525#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002526 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002527 pDSDumpDot((char*)"triTest2.dot");
2528#endif
2529 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002530 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002531
2532 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002533 EndCommandBuffer();
2534 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002535
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002536 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002537}
2538
Tony Barbour6918cd52015-04-09 12:58:51 -06002539TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBinding)
Tony Barboure2c58df2014-11-25 13:18:32 -07002540{
2541 // This test is the same as TriangleFSUniformBlockBinding, but
2542 // it does not provide an instance name.
2543 // The expected result from this test is a purple triangle
2544
2545 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07002546 "#version 400\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002547 "#extension GL_ARB_separate_shader_objects : enable\n"
2548 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barboure804d202016-01-05 13:37:45 -07002549 "out gl_PerVertex {\n"
2550 " vec4 gl_Position;\n"
2551 "};\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002552 "void main() {\n"
2553 " vec2 vertices[3];"
2554 " vertices[0] = vec2(-0.5, -0.5);\n"
2555 " vertices[1] = vec2( 0.5, -0.5);\n"
2556 " vertices[2] = vec2( 0.5, 0.5);\n"
2557 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2558 "}\n";
2559
2560 static const char *fragShaderText =
2561 "#version 430\n"
2562 "#extension GL_ARB_separate_shader_objects : enable\n"
2563 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002564 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2565 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2566 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2567 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northropd43c52e2014-12-05 15:44:14 -07002568 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002569 "void main() {\n"
Cody Northropd43c52e2014-12-05 15:44:14 -07002570 " outColor = blue;\n"
2571 " outColor += red;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002572 "}\n";
2573 ASSERT_NO_FATAL_FAILURE(InitState());
2574 ASSERT_NO_FATAL_FAILURE(InitViewport());
2575
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002576 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2577 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002578
2579 // We're going to create a number of uniform buffers, and then allow
2580 // the shader to select which it wants to read from with a binding
2581
2582 // Let's populate the buffers with a single color each:
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002583 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2584 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2585 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2586 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barboure2c58df2014-11-25 13:18:32 -07002587
2588 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2589 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2590 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2591 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2592
2593 const int redCount = sizeof(redVals) / sizeof(float);
2594 const int greenCount = sizeof(greenVals) / sizeof(float);
2595 const int blueCount = sizeof(blueVals) / sizeof(float);
2596 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2597
Tony Barbour6918cd52015-04-09 12:58:51 -06002598 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002599
Tony Barbour6918cd52015-04-09 12:58:51 -06002600 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002601
Tony Barbour6918cd52015-04-09 12:58:51 -06002602 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002603
Tony Barbour6918cd52015-04-09 12:58:51 -06002604 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002605
Tony Barbour6918cd52015-04-09 12:58:51 -06002606 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002607 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002608 pipelineobj.AddShader(&vs);
2609 pipelineobj.AddShader(&ps);
2610
Tony Barbour6918cd52015-04-09 12:58:51 -06002611 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002612 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2613 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2614 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2615 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002616
Tony Barbour664accc2015-01-09 12:55:14 -07002617 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002618 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002619
Tony Barbourfe3351b2015-07-28 10:17:20 -06002620 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002621
2622#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002623 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002624 pDSDumpDot((char*)"triTest2.dot");
2625#endif
2626 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002627 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002628
2629 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002630 EndCommandBuffer();
2631 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002632
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002633 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002634}
2635
GregF6084aec2015-07-01 16:11:09 -06002636TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBindingWithStruct)
2637{
2638 // This test is the same as TriangleFSUniformBlockBinding, but
2639 // it does not provide an instance name.
2640 // The expected result from this test is a purple triangle
2641
2642 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07002643 "#version 400\n"
GregF6084aec2015-07-01 16:11:09 -06002644 "#extension GL_ARB_separate_shader_objects : enable\n"
2645 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barboure804d202016-01-05 13:37:45 -07002646 "out gl_PerVertex {\n"
2647 " vec4 gl_Position;\n"
2648 "};\n"
GregF6084aec2015-07-01 16:11:09 -06002649 "void main() {\n"
2650 " vec2 vertices[3];"
2651 " vertices[0] = vec2(-0.5, -0.5);\n"
2652 " vertices[1] = vec2( 0.5, -0.5);\n"
2653 " vertices[2] = vec2( 0.5, 0.5);\n"
2654 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2655 "}\n";
2656
2657 static const char *fragShaderText =
2658 "#version 430\n"
2659 "#extension GL_ARB_separate_shader_objects : enable\n"
2660 "#extension GL_ARB_shading_language_420pack : enable\n"
2661 "\n"
2662 " struct PS_INPUT {\n"
2663 " vec2 member0;\n"
2664 " vec4 member1;\n"
2665 " vec4 member2;\n"
2666 " vec4 member3;\n"
2667 " vec4 member4;\n"
2668 " vec4 member5;\n"
2669 " vec4 member6;\n"
2670 " vec4 member7;\n"
2671 " vec4 member8;\n"
2672 " vec4 member9;\n"
2673 " };\n"
2674 "\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002675 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2676 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2677 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2678 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
GregF6084aec2015-07-01 16:11:09 -06002679 "layout (location = 0) out vec4 outColor;\n"
2680 "PS_INPUT MainFs()\n"
2681 "{\n"
2682 " PS_INPUT o;\n"
2683 " o.member9 = red;\n"
2684 " return o;\n"
2685 "}\n"
2686 "\n"
2687 "void main()\n"
2688 "{\n"
2689 " PS_INPUT o;\n"
2690 " o = MainFs();\n"
2691 " outColor = blue;"
2692 " outColor += o.member9;\n"
2693 "}\n";;
2694 ASSERT_NO_FATAL_FAILURE(InitState());
2695 ASSERT_NO_FATAL_FAILURE(InitViewport());
2696
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002697 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2698 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
GregF6084aec2015-07-01 16:11:09 -06002699
2700 // We're going to create a number of uniform buffers, and then allow
2701 // the shader to select which it wants to read from with a binding
2702
2703 // Let's populate the buffers with a single color each:
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002704 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2705 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2706 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2707 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
GregF6084aec2015-07-01 16:11:09 -06002708
2709 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2710 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2711 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2712 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2713
2714 const int redCount = sizeof(redVals) / sizeof(float);
2715 const int greenCount = sizeof(greenVals) / sizeof(float);
2716 const int blueCount = sizeof(blueVals) / sizeof(float);
2717 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2718
2719 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2720
2721 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2722
2723 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2724
2725 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
2726
2727 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002728 pipelineobj.AddColorAttachment();
GregF6084aec2015-07-01 16:11:09 -06002729 pipelineobj.AddShader(&vs);
2730 pipelineobj.AddShader(&ps);
2731
2732 VkDescriptorSetObj descriptorSet(m_device);
2733 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2734 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2735 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2736 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
2737
2738 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002739 ASSERT_VK_SUCCESS(BeginCommandBuffer());
GregF6084aec2015-07-01 16:11:09 -06002740
Tony Barbourfe3351b2015-07-28 10:17:20 -06002741 GenericDrawPreparation(pipelineobj, descriptorSet);
GregF6084aec2015-07-01 16:11:09 -06002742
2743#ifdef DUMP_STATE_DOT
2744 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
2745 pDSDumpDot((char*)"triTest2.dot");
2746#endif
2747 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002748 Draw(3, 1, 0, 0);
GregF6084aec2015-07-01 16:11:09 -06002749
2750 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002751 EndCommandBuffer();
2752 QueueCommandBuffer();
GregF6084aec2015-07-01 16:11:09 -06002753
2754 RecordImages(m_renderTargets);
2755}
2756
Tony Barbour6918cd52015-04-09 12:58:51 -06002757TEST_F(VkRenderTest, CubeWithVertexFetchAndMVPAndTexture)
Tony Barboure2c58df2014-11-25 13:18:32 -07002758{
2759 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07002760 "#version 400\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002761 "#extension GL_ARB_separate_shader_objects : enable\n"
2762 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002763 "layout (std140, binding=0) uniform bufferVals {\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002764 " mat4 mvp;\n"
2765 "} myBufferVals;\n"
2766 "layout (location=0) in vec4 pos;\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002767 "layout (location=1) in vec2 input_uv;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002768 "layout (location=0) out vec2 UV;\n"
Tony Barboure804d202016-01-05 13:37:45 -07002769 "out gl_PerVertex {\n"
2770 " vec4 gl_Position;\n"
2771 "};\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002772 "void main() {\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002773 " UV = input_uv;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002774 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002775 " gl_Position.y = -gl_Position.y;\n"
2776 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002777 "}\n";
2778
2779 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07002780 "#version 400\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002781 "#extension GL_ARB_separate_shader_objects : enable\n"
2782 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wu11078b02015-01-04 16:27:24 +08002783 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002784 "layout (location=0) out vec4 outColor;\n"
2785 "layout (location=0) in vec2 UV;\n"
2786 "void main() {\n"
2787 " outColor= textureLod(surface, UV, 0.0);\n"
2788 "}\n";
2789 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2790
2791 glm::mat4 View = glm::lookAt(
2792 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2793 glm::vec3(0,0,0), // and looks at the origin
2794 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2795 );
2796
2797 glm::mat4 Model = glm::mat4(1.0f);
2798
2799 glm::mat4 MVP = Projection * View * Model;
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002800 int num_verts = sizeof(g_vb_texture_Data) / sizeof(g_vb_texture_Data[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002801
2802
2803 ASSERT_NO_FATAL_FAILURE(InitState());
2804 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wub4052042015-07-09 10:16:34 +08002805 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Chia-I Wu08accc62015-07-07 11:50:03 +08002806 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height, m_depth_stencil_fmt);
Tony Barboure2c58df2014-11-25 13:18:32 -07002807
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002808 VkConstantBufferObj meshBuffer(m_device, num_verts,
2809 sizeof(g_vb_texture_Data[0]), g_vb_texture_Data);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00002810 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07002811
Mark Lobodzinski17caf572015-01-29 08:55:56 -06002812 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barboure2c58df2014-11-25 13:18:32 -07002813
Tony Barbour6918cd52015-04-09 12:58:51 -06002814 VkConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002815 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2816 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbour6918cd52015-04-09 12:58:51 -06002817 VkSamplerObj sampler(m_device);
2818 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002819
Tony Barbour6918cd52015-04-09 12:58:51 -06002820 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002821 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002822 pipelineobj.AddShader(&vs);
2823 pipelineobj.AddShader(&ps);
2824
Tony Barbour6918cd52015-04-09 12:58:51 -06002825 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002826 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mvpBuffer);
Chia-I Wu11078b02015-01-04 16:27:24 +08002827 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002828
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002829#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002830 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002831 MESH_BIND_ID, // binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08002832 sizeof(g_vb_texture_Data[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002833 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002834 };
Tony Barboure2c58df2014-11-25 13:18:32 -07002835
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002836 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002837 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2838 vi_attribs[0].location = 0; // location
Tony Barbourd1c35722015-04-16 15:59:00 -06002839 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08002840 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002841 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2842 vi_attribs[1].location = 1; // location
2843 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08002844 vi_attribs[1].offset = 16; // Offset of uv components
Tony Barboure2c58df2014-11-25 13:18:32 -07002845
Tony Barboure2c58df2014-11-25 13:18:32 -07002846 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002847 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barboure2c58df2014-11-25 13:18:32 -07002848
Tony Barbourdd6e32e2015-07-10 15:29:03 -06002849 VkPipelineDepthStencilStateCreateInfo ds_state;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002850 ds_state.depthTestEnable = VK_TRUE;
2851 ds_state.depthWriteEnable = VK_TRUE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002852 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL;
Cody Northrop271ba752015-08-26 10:01:32 -06002853 ds_state.depthBoundsTestEnable = VK_FALSE;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002854 ds_state.stencilTestEnable = VK_FALSE;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002855 ds_state.back.depthFailOp = VK_STENCIL_OP_KEEP;
2856 ds_state.back.failOp = VK_STENCIL_OP_KEEP;
2857 ds_state.back.passOp = VK_STENCIL_OP_KEEP;
2858 ds_state.back.compareOp = VK_COMPARE_OP_ALWAYS;
Tony Barbourf52346d2015-01-16 14:27:35 -07002859 ds_state.front = ds_state.back;
2860 pipelineobj.SetDepthStencil(&ds_state);
2861
Tony Barbour1c45ce02015-03-27 17:03:18 -06002862 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tobin Ehlisf1878c72015-08-18 14:24:32 -06002863
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002864 VkCommandBufferBeginInfo cbBeginInfo;
2865 memset(&cbBeginInfo, 0, sizeof(VkCommandBufferBeginInfo));
2866 cbBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Courtney Goeltzenleuchter04bb5f82015-10-21 18:11:04 -06002867 cbBeginInfo.flags = 0;
Tobin Ehlisf1878c72015-08-18 14:24:32 -06002868 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barboure2c58df2014-11-25 13:18:32 -07002869
Tony Barbourfe3351b2015-07-28 10:17:20 -06002870 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002871
Tony Barbourfe3351b2015-07-28 10:17:20 -06002872 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002873#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002874 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002875 pDSDumpDot((char*)"triTest2.dot");
2876#endif
2877 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002878 Draw(num_verts, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002879
2880 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002881 EndCommandBuffer();
2882 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002883
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002884 RecordImages(m_renderTargets);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002885 RotateTriangleVSUniform(Projection, View, Model, &mvpBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002886}
Cody Northropf1990a92014-12-09 11:17:01 -07002887
Tony Barbour6918cd52015-04-09 12:58:51 -06002888TEST_F(VkRenderTest, TriangleMixedSamplerUniformBlockBinding)
Cody Northropf1990a92014-12-09 11:17:01 -07002889{
2890 // This test mixes binding slots of textures and buffers, ensuring
2891 // that sparse and overlapping assignments work.
Cody Northropb110b4f2014-12-09 13:59:39 -07002892 // The expected result from this test is a purple triangle, although
Cody Northropf1990a92014-12-09 11:17:01 -07002893 // you can modify it to move the desired result around.
2894
2895 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07002896 "#version 400\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002897 "#extension GL_ARB_separate_shader_objects : enable\n"
2898 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barboure804d202016-01-05 13:37:45 -07002899 "out gl_PerVertex {\n"
2900 " vec4 gl_Position;\n"
2901 "};\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002902 "void main() {\n"
2903 " vec2 vertices[3];"
2904 " vertices[0] = vec2(-0.5, -0.5);\n"
2905 " vertices[1] = vec2( 0.5, -0.5);\n"
2906 " vertices[2] = vec2( 0.5, 0.5);\n"
2907 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2908 "}\n";
2909
2910 static const char *fragShaderText =
2911 "#version 430\n"
2912 "#extension GL_ARB_separate_shader_objects : enable\n"
2913 "#extension GL_ARB_shading_language_420pack : enable\n"
2914 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wu11078b02015-01-04 16:27:24 +08002915 "layout (binding = 3) uniform sampler2D surface1;\n"
2916 "layout (binding = 1) uniform sampler2D surface2;\n"
2917 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002918
Cody Northropb110b4f2014-12-09 13:59:39 -07002919
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002920 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2921 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2922 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2923 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropf1990a92014-12-09 11:17:01 -07002924 "layout (location = 0) out vec4 outColor;\n"
2925 "void main() {\n"
Cody Northropb110b4f2014-12-09 13:59:39 -07002926 " outColor = red * vec4(0.00001);\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002927 " outColor += white * vec4(0.00001);\n"
2928 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropb110b4f2014-12-09 13:59:39 -07002929 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002930 "}\n";
2931 ASSERT_NO_FATAL_FAILURE(InitState());
2932 ASSERT_NO_FATAL_FAILURE(InitViewport());
2933
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002934 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2935 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northropf1990a92014-12-09 11:17:01 -07002936
Cody Northropf1990a92014-12-09 11:17:01 -07002937 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2938 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2939 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2940 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2941
2942 const int redCount = sizeof(redVals) / sizeof(float);
2943 const int greenCount = sizeof(greenVals) / sizeof(float);
2944 const int blueCount = sizeof(blueVals) / sizeof(float);
2945 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2946
Tony Barbour6918cd52015-04-09 12:58:51 -06002947 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2948 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2949 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2950 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropf1990a92014-12-09 11:17:01 -07002951
Tony Barbourebc093f2015-04-01 16:38:10 -06002952 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour6918cd52015-04-09 12:58:51 -06002953 VkSamplerObj sampler0(m_device);
2954 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbourebc093f2015-04-01 16:38:10 -06002955 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour6918cd52015-04-09 12:58:51 -06002956 VkSamplerObj sampler2(m_device);
2957 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbourebc093f2015-04-01 16:38:10 -06002958 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour6918cd52015-04-09 12:58:51 -06002959 VkSamplerObj sampler4(m_device);
2960 VkTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropb110b4f2014-12-09 13:59:39 -07002961
2962 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2963 // TODO: Get back here ASAP and understand why.
Tony Barbourebc093f2015-04-01 16:38:10 -06002964 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour6918cd52015-04-09 12:58:51 -06002965 VkSamplerObj sampler7(m_device);
2966 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropf1990a92014-12-09 11:17:01 -07002967
Tony Barbour6918cd52015-04-09 12:58:51 -06002968 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002969 pipelineobj.AddColorAttachment();
Cody Northropf1990a92014-12-09 11:17:01 -07002970 pipelineobj.AddShader(&vs);
2971 pipelineobj.AddShader(&ps);
2972
Tony Barbour6918cd52015-04-09 12:58:51 -06002973 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002974 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2975 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2976 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2977 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002978 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
Chia-I Wu11078b02015-01-04 16:27:24 +08002979 // swap blue and green
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002980 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2981 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2982 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropf1990a92014-12-09 11:17:01 -07002983
Tony Barbour664accc2015-01-09 12:55:14 -07002984 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002985 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropf1990a92014-12-09 11:17:01 -07002986
Tony Barbourfe3351b2015-07-28 10:17:20 -06002987 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002988
2989#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002990 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002991 pDSDumpDot((char*)"triTest2.dot");
2992#endif
2993 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002994 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002995
2996 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002997 EndCommandBuffer();
2998 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002999
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06003000 RecordImages(m_renderTargets);
Cody Northropf1990a92014-12-09 11:17:01 -07003001}
3002
Tony Barbour6918cd52015-04-09 12:58:51 -06003003TEST_F(VkRenderTest, TriangleMatchingSamplerUniformBlockBinding)
Cody Northropbd531de2014-12-09 19:08:54 -07003004{
3005 // This test matches binding slots of textures and buffers, requiring
3006 // the driver to give them distinct number spaces.
3007 // The expected result from this test is a red triangle, although
3008 // you can modify it to move the desired result around.
3009
3010 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07003011 "#version 400\n"
Cody Northropbd531de2014-12-09 19:08:54 -07003012 "#extension GL_ARB_separate_shader_objects : enable\n"
3013 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barboure804d202016-01-05 13:37:45 -07003014 "out gl_PerVertex {\n"
3015 " vec4 gl_Position;\n"
3016 "};\n"
Cody Northropbd531de2014-12-09 19:08:54 -07003017 "void main() {\n"
3018 " vec2 vertices[3];"
3019 " vertices[0] = vec2(-0.5, -0.5);\n"
3020 " vertices[1] = vec2( 0.5, -0.5);\n"
3021 " vertices[2] = vec2( 0.5, 0.5);\n"
3022 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
3023 "}\n";
3024
3025 static const char *fragShaderText =
3026 "#version 430\n"
3027 "#extension GL_ARB_separate_shader_objects : enable\n"
3028 "#extension GL_ARB_shading_language_420pack : enable\n"
3029 "layout (binding = 0) uniform sampler2D surface0;\n"
3030 "layout (binding = 1) uniform sampler2D surface1;\n"
3031 "layout (binding = 2) uniform sampler2D surface2;\n"
3032 "layout (binding = 3) uniform sampler2D surface3;\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06003033 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
3034 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
3035 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
3036 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropbd531de2014-12-09 19:08:54 -07003037 "layout (location = 0) out vec4 outColor;\n"
3038 "void main() {\n"
3039 " outColor = red;// * vec4(0.00001);\n"
3040 " outColor += white * vec4(0.00001);\n"
3041 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
3042 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
3043 "}\n";
3044 ASSERT_NO_FATAL_FAILURE(InitState());
3045 ASSERT_NO_FATAL_FAILURE(InitViewport());
3046
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003047 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
3048 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northropbd531de2014-12-09 19:08:54 -07003049
3050 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
3051 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
3052 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
3053 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
3054
3055 const int redCount = sizeof(redVals) / sizeof(float);
3056 const int greenCount = sizeof(greenVals) / sizeof(float);
3057 const int blueCount = sizeof(blueVals) / sizeof(float);
3058 const int whiteCount = sizeof(whiteVals) / sizeof(float);
3059
Tony Barbour6918cd52015-04-09 12:58:51 -06003060 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
3061 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
3062 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
3063 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropbd531de2014-12-09 19:08:54 -07003064
Tony Barbourebc093f2015-04-01 16:38:10 -06003065 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour6918cd52015-04-09 12:58:51 -06003066 VkSamplerObj sampler0(m_device);
3067 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbourebc093f2015-04-01 16:38:10 -06003068 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour6918cd52015-04-09 12:58:51 -06003069 VkSamplerObj sampler2(m_device);
3070 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbourebc093f2015-04-01 16:38:10 -06003071 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour6918cd52015-04-09 12:58:51 -06003072 VkSamplerObj sampler4(m_device);
3073 VkTextureObj texture4(m_device, tex_colors); // Light Green
Tony Barbourebc093f2015-04-01 16:38:10 -06003074 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour6918cd52015-04-09 12:58:51 -06003075 VkSamplerObj sampler7(m_device);
3076 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropbd531de2014-12-09 19:08:54 -07003077
Tony Barbour6918cd52015-04-09 12:58:51 -06003078 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003079 pipelineobj.AddColorAttachment();
Cody Northropbd531de2014-12-09 19:08:54 -07003080 pipelineobj.AddShader(&vs);
3081 pipelineobj.AddShader(&ps);
3082
Tony Barbour6918cd52015-04-09 12:58:51 -06003083 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08003084 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3085 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3086 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
3087 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003088 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
3089 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
3090 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
3091 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropbd531de2014-12-09 19:08:54 -07003092
Tony Barbour664accc2015-01-09 12:55:14 -07003093 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003094 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropbd531de2014-12-09 19:08:54 -07003095
Tony Barbourfe3351b2015-07-28 10:17:20 -06003096 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07003097
3098#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003099 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07003100 pDSDumpDot((char*)"triTest2.dot");
3101#endif
3102 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003103 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07003104
3105 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003106 EndCommandBuffer();
3107 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07003108
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06003109 RecordImages(m_renderTargets);
Cody Northropbd531de2014-12-09 19:08:54 -07003110}
3111
Tony Barbour6918cd52015-04-09 12:58:51 -06003112TEST_F(VkRenderTest, TriangleUniformBufferLayout)
Cody Northrop04ad1202014-12-17 15:26:33 -07003113{
3114 // This test populates a buffer with a variety of different data
3115 // types, then reads them out with a shader.
3116 // The expected result from this test is a green triangle
3117
3118 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07003119 "#version 400\n"
Cody Northrop04ad1202014-12-17 15:26:33 -07003120 "#extension GL_ARB_separate_shader_objects : enable\n"
3121 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06003122 "layout (std140, binding = 0) uniform mixedBuffer {\n"
Cody Northrop04ad1202014-12-17 15:26:33 -07003123 " vec4 fRed;\n"
3124 " vec4 fGreen;\n"
3125 " layout(row_major) mat4 worldToProj;\n"
3126 " layout(row_major) mat4 projToWorld;\n"
3127 " layout(row_major) mat4 worldToView;\n"
3128 " layout(row_major) mat4 viewToProj;\n"
3129 " layout(row_major) mat4 worldToShadow[4];\n"
3130 " float fZero;\n"
3131 " float fOne;\n"
3132 " float fTwo;\n"
3133 " float fThree;\n"
3134 " vec3 fZeroZeroZero;\n"
3135 " float fFour;\n"
3136 " vec3 fZeroZeroOne;\n"
3137 " float fFive;\n"
3138 " vec3 fZeroOneZero;\n"
3139 " float fSix;\n"
3140 " float fSeven;\n"
3141 " float fEight;\n"
3142 " float fNine;\n"
3143 " vec2 fZeroZero;\n"
3144 " vec2 fZeroOne;\n"
3145 " vec4 fBlue;\n"
3146 " vec2 fOneZero;\n"
3147 " vec2 fOneOne;\n"
3148 " vec3 fZeroOneOne;\n"
3149 " float fTen;\n"
3150 " float fEleven;\n"
3151 " float fTwelve;\n"
3152 " vec3 fOneZeroZero;\n"
3153 " vec4 uvOffsets[4];\n"
3154 "};\n"
3155 "layout (location = 0) out vec4 color;"
Tony Barboure804d202016-01-05 13:37:45 -07003156 "out gl_PerVertex {\n"
3157 " vec4 gl_Position;\n"
3158 "};\n"
Cody Northrop04ad1202014-12-17 15:26:33 -07003159 "void main() {\n"
3160
3161 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3162 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3163 " \n"
3164
3165 // do some exact comparisons, even though we should
3166 // really have an epsilon involved.
3167 " vec4 outColor = right;\n"
3168 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3169 " outColor = wrong;\n"
3170 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3171 " outColor = wrong;\n"
3172 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3173 " outColor = wrong;\n"
3174
3175 " color = outColor;\n"
3176
3177 // generic position stuff
3178 " vec2 vertices;\n"
3179 " int vertexSelector = gl_VertexID;\n"
3180 " if (vertexSelector == 0)\n"
3181 " vertices = vec2(-0.5, -0.5);\n"
3182 " else if (vertexSelector == 1)\n"
3183 " vertices = vec2( 0.5, -0.5);\n"
3184 " else if (vertexSelector == 2)\n"
3185 " vertices = vec2( 0.5, 0.5);\n"
3186 " else\n"
3187 " vertices = vec2( 0.0, 0.0);\n"
3188 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3189 "}\n";
3190
3191 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07003192 "#version 400\n"
Cody Northrop04ad1202014-12-17 15:26:33 -07003193 "#extension GL_ARB_separate_shader_objects : enable\n"
3194 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06003195 "layout (std140, binding = 0) uniform mixedBuffer {\n"
Cody Northrop04ad1202014-12-17 15:26:33 -07003196 " vec4 fRed;\n"
3197 " vec4 fGreen;\n"
3198 " layout(row_major) mat4 worldToProj;\n"
3199 " layout(row_major) mat4 projToWorld;\n"
3200 " layout(row_major) mat4 worldToView;\n"
3201 " layout(row_major) mat4 viewToProj;\n"
3202 " layout(row_major) mat4 worldToShadow[4];\n"
3203 " float fZero;\n"
3204 " float fOne;\n"
3205 " float fTwo;\n"
3206 " float fThree;\n"
3207 " vec3 fZeroZeroZero;\n"
3208 " float fFour;\n"
3209 " vec3 fZeroZeroOne;\n"
3210 " float fFive;\n"
3211 " vec3 fZeroOneZero;\n"
3212 " float fSix;\n"
3213 " float fSeven;\n"
3214 " float fEight;\n"
3215 " float fNine;\n"
3216 " vec2 fZeroZero;\n"
3217 " vec2 fZeroOne;\n"
3218 " vec4 fBlue;\n"
3219 " vec2 fOneZero;\n"
3220 " vec2 fOneOne;\n"
3221 " vec3 fZeroOneOne;\n"
3222 " float fTen;\n"
3223 " float fEleven;\n"
3224 " float fTwelve;\n"
3225 " vec3 fOneZeroZero;\n"
3226 " vec4 uvOffsets[4];\n"
3227 "};\n"
3228 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06003229 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop04ad1202014-12-17 15:26:33 -07003230 "void main() {\n"
3231 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3232 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3233 " \n"
3234
3235 // start with VS value to ensure it passed
3236 " vec4 outColor = color;\n"
3237
3238 // do some exact comparisons, even though we should
3239 // really have an epsilon involved.
3240 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3241 " outColor = wrong;\n"
3242 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3243 " outColor = wrong;\n"
3244 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3245 " outColor = wrong;\n"
3246 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3247 " outColor = wrong;\n"
3248 " if (fTwo != 2.0)\n"
3249 " outColor = wrong;\n"
3250 " if (fOneOne != vec2(1.0, 1.0))\n"
3251 " outColor = wrong;\n"
3252 " if (fTen != 10.0)\n"
3253 " outColor = wrong;\n"
3254 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3255 " outColor = wrong;\n"
3256 " \n"
GregFaae75242015-06-03 18:40:50 -06003257 " uFragColor = outColor;\n"
Cody Northrop04ad1202014-12-17 15:26:33 -07003258 "}\n";
3259
3260
Cody Northropd2ad0342015-08-05 11:15:02 -06003261 const float mixedVals[196] = { 1.0f, 0.0f, 0.0f, 1.0f, // vec4 fRed; // align
3262 0.0f, 1.0f, 0.0f, 1.0f, // vec4 fGreen; // align
3263 1.0f, 0.0f, 0.0f, 1.0f, // layout(row_major) mat4 worldToProj;
3264 0.0f, 1.0f, 0.0f, 1.0f, // align
3265 0.0f, 0.0f, 1.0f, 1.0f, // align
3266 0.0f, 0.0f, 0.0f, 1.0f, // align
3267 2.0f, 0.0f, 0.0f, 2.0f, // layout(row_major) mat4 projToWorld;
3268 0.0f, 2.0f, 0.0f, 2.0f, // align
3269 0.0f, 0.0f, 2.0f, 2.0f, // align
3270 0.0f, 0.0f, 0.0f, 2.0f, // align
3271 3.0f, 0.0f, 0.0f, 3.0f, // layout(row_major) mat4 worldToView;
3272 0.0f, 3.0f, 0.0f, 3.0f, // align
3273 0.0f, 0.0f, 3.0f, 3.0f, // align
3274 0.0f, 0.0f, 0.0f, 3.0f, // align
3275 4.0f, 0.0f, 0.0f, 4.0f, // layout(row_major) mat4 viewToProj;
3276 0.0f, 4.0f, 0.0f, 4.0f, // align
3277 0.0f, 0.0f, 4.0f, 4.0f, // align
3278 0.0f, 0.0f, 0.0f, 4.0f, // align
3279 5.0f, 0.0f, 0.0f, 5.0f, // layout(row_major) mat4 worldToShadow[4];
3280 0.0f, 5.0f, 0.0f, 5.0f, // align
3281 0.0f, 0.0f, 5.0f, 5.0f, // align
3282 0.0f, 0.0f, 0.0f, 5.0f, // align
3283 6.0f, 0.0f, 0.0f, 6.0f, // align
3284 0.0f, 6.0f, 0.0f, 6.0f, // align
3285 0.0f, 0.0f, 6.0f, 6.0f, // align
3286 0.0f, 0.0f, 0.0f, 6.0f, // align
3287 7.0f, 0.0f, 0.0f, 7.0f, // align
3288 0.0f, 7.0f, 0.0f, 7.0f, // align
3289 0.0f, 0.0f, 7.0f, 7.0f, // align
3290 0.0f, 0.0f, 0.0f, 7.0f, // align
3291 8.0f, 0.0f, 0.0f, 8.0f, // align
3292 0.0f, 8.0f, 0.0f, 8.0f, // align
3293 0.0f, 0.0f, 8.0f, 8.0f, // align
3294 0.0f, 0.0f, 0.0f, 8.0f, // align
3295 0.0f, // float fZero; // align
3296 1.0f, // float fOne; // pack
3297 2.0f, // float fTwo; // pack
3298 3.0f, // float fThree; // pack
3299 0.0f, 0.0f, 0.0f, // vec3 fZeroZeroZero; // align
3300 4.0f, // float fFour; // pack
3301 0.0f, 0.0f, 1.0f, // vec3 fZeroZeroOne; // align
3302 5.0f, // float fFive; // pack
3303 0.0f, 1.0f, 0.0f, // vec3 fZeroOneZero; // align
3304 6.0f, // float fSix; // pack
3305 7.0f, // float fSeven; // align
3306 8.0f, // float fEight; // pack
3307 9.0f, // float fNine; // pack
3308 0.0f, // BUFFER
3309 0.0f, 0.0f, // vec2 fZeroZero; // align
3310 0.0f, 1.0f, // vec2 fZeroOne; // pack
3311 0.0f, 0.0f, 1.0f, 1.0f, // vec4 fBlue; // align
3312 1.0f, 0.0f, // vec2 fOneZero; // align
3313 1.0f, 1.0f, // vec2 fOneOne; // pack
3314 0.0f, 1.0f, 1.0f, // vec3 fZeroOneOne; // align
3315 10.0f, // float fTen; // pack
3316 11.0f, // float fEleven; // align
3317 12.0f, // float fTwelve; // pack
3318 0.0f, 0.0f, // BUFFER
3319 1.0f, 0.0f, 0.0f, // vec3 fOneZeroZero; // align
3320 0.0f, // BUFFER
3321 0.1f, 0.2f, 0.3f, 0.4f, // vec4 uvOffsets[4];
3322 0.5f, 0.6f, 0.7f, 0.8f, // align
3323 0.9f, 1.0f, 1.1f, 1.2f, // align
3324 1.3f, 1.4f, 1.5f, 1.6f, // align
Cody Northrop04ad1202014-12-17 15:26:33 -07003325 };
3326
3327 ASSERT_NO_FATAL_FAILURE(InitState());
3328 ASSERT_NO_FATAL_FAILURE(InitViewport());
3329
3330 const int constCount = sizeof(mixedVals) / sizeof(float);
3331
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003332 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
3333 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northrop04ad1202014-12-17 15:26:33 -07003334
Tony Barbour6918cd52015-04-09 12:58:51 -06003335 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop04ad1202014-12-17 15:26:33 -07003336
Tony Barbour6918cd52015-04-09 12:58:51 -06003337 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003338 pipelineobj.AddColorAttachment();
Cody Northrop04ad1202014-12-17 15:26:33 -07003339 pipelineobj.AddShader(&vs);
3340 pipelineobj.AddShader(&ps);
3341
Tony Barbour6918cd52015-04-09 12:58:51 -06003342 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003343 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
Cody Northrop04ad1202014-12-17 15:26:33 -07003344
3345 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003346 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop04ad1202014-12-17 15:26:33 -07003347
Tony Barbourfe3351b2015-07-28 10:17:20 -06003348 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop04ad1202014-12-17 15:26:33 -07003349
3350#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003351 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop04ad1202014-12-17 15:26:33 -07003352 pDSDumpDot((char*)"triTest2.dot");
3353#endif
3354 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003355 Draw(3, 1, 0, 0);
Cody Northrop04ad1202014-12-17 15:26:33 -07003356
3357 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003358 EndCommandBuffer();
3359 QueueCommandBuffer();
Cody Northrop04ad1202014-12-17 15:26:33 -07003360
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06003361 RecordImages(m_renderTargets);
Cody Northrop04ad1202014-12-17 15:26:33 -07003362}
3363
Cody Northrop95638152015-05-07 14:39:12 -06003364TEST_F(VkRenderTest, TextureGather)
3365{
3366 // This test introduces textureGather and textureGatherOffset
3367 // Each call is compared against an expected inline color result
3368 // Green triangle means everything worked as expected
3369 // Red means something went wrong
3370
Cody Northropc55900f2015-08-06 13:18:13 -06003371 // disable SPV until texture gather is turned on in glsl->SPV
3372 if (!m_use_glsl) {
3373 printf("Skipping test that requires GLSL path (TextureGather)\n");
3374 return;
3375 }
3376
Cody Northrop95638152015-05-07 14:39:12 -06003377 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07003378 "#version 400\n"
Cody Northrop95638152015-05-07 14:39:12 -06003379 "#extension GL_ARB_separate_shader_objects : enable\n"
3380 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barboure804d202016-01-05 13:37:45 -07003381 "out gl_PerVertex {\n"
3382 " vec4 gl_Position;\n"
3383 "};\n"
Cody Northrop95638152015-05-07 14:39:12 -06003384 "void main() {\n"
3385 " vec2 vertices[3];"
3386 " vertices[0] = vec2(-0.5, -0.5);\n"
3387 " vertices[1] = vec2( 0.5, -0.5);\n"
3388 " vertices[2] = vec2( 0.5, 0.5);\n"
3389 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
3390 "}\n";
3391
3392 static const char *fragShaderText =
3393 "#version 430\n"
3394 "#extension GL_ARB_separate_shader_objects : enable\n"
3395 "#extension GL_ARB_shading_language_420pack : enable\n"
3396 "layout (binding = 0) uniform sampler2D surface0;\n"
3397 "layout (binding = 1) uniform sampler2D surface1;\n"
3398 "layout (binding = 2) uniform sampler2D surface2;\n"
3399 "layout (binding = 3) uniform sampler2D surface3;\n"
3400 "layout (location = 0) out vec4 outColor;\n"
3401 "void main() {\n"
3402
3403 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3404 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3405
3406 " vec4 color = right;\n"
3407
3408 // Grab a normal texture sample to ensure it can work in conjuntion
3409 // with textureGather (there are some intracacies in the backend)
3410 " vec4 sampledColor = textureLod(surface2, vec2(0.5), 0.0);\n"
3411 " if (sampledColor != vec4(0.0, 0.0, 1.0, 1.0))\n"
3412 " color = wrong;\n"
3413
3414 " vec4 gatheredColor = textureGather(surface0, vec2(0.5), 0);\n"
3415 // This just grabbed four red components from a red surface
3416 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3417 " color = wrong;\n"
3418
3419 // Yes, this is using an offset of 0, we don't have enough fine grained
3420 // control of the texture contents here.
3421 " gatheredColor = textureGatherOffset(surface1, vec2(0.5), ivec2(0, 0), 1);\n"
3422 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3423 " color = wrong;\n"
3424
3425 " outColor = color;\n"
3426
3427 "}\n";
3428
3429 ASSERT_NO_FATAL_FAILURE(InitState());
3430 ASSERT_NO_FATAL_FAILURE(InitViewport());
3431
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003432 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
3433 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northrop95638152015-05-07 14:39:12 -06003434
3435 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
3436 VkSamplerObj sampler0(m_device);
3437 VkTextureObj texture0(m_device, tex_colors); // Red
3438 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
3439 VkSamplerObj sampler1(m_device);
3440 VkTextureObj texture1(m_device, tex_colors); // Green
3441 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
3442 VkSamplerObj sampler2(m_device);
3443 VkTextureObj texture2(m_device, tex_colors); // Blue
3444 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
3445 VkSamplerObj sampler3(m_device);
3446 VkTextureObj texture3(m_device, tex_colors); // Red and Blue
3447
3448 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003449 pipelineobj.AddColorAttachment();
Cody Northrop95638152015-05-07 14:39:12 -06003450 pipelineobj.AddShader(&vs);
3451 pipelineobj.AddShader(&ps);
3452
3453 VkDescriptorSetObj descriptorSet(m_device);
3454 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3455 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
3456 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3457 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
3458
3459 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003460 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop95638152015-05-07 14:39:12 -06003461
Tony Barbourfe3351b2015-07-28 10:17:20 -06003462 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop95638152015-05-07 14:39:12 -06003463
3464 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003465 Draw(3, 1, 0, 0);
Cody Northrop95638152015-05-07 14:39:12 -06003466
3467 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003468 EndCommandBuffer();
3469 QueueCommandBuffer();
Cody Northrop95638152015-05-07 14:39:12 -06003470
3471 RecordImages(m_renderTargets);
Cody Northrop95638152015-05-07 14:39:12 -06003472}
3473
Cody Northrop475663c2015-04-15 11:19:06 -06003474TEST_F(VkRenderTest, GeometryShaderHelloWorld)
3475{
3476 // This test introduces a geometry shader that simply
3477 // changes the color of each vertex to red, green, blue
3478
3479 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07003480 "#version 400\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003481 "#extension GL_ARB_separate_shader_objects : enable\n"
3482 "#extension GL_ARB_shading_language_420pack : enable\n"
3483 "layout (location = 0) out vec4 color;"
Tony Barboure804d202016-01-05 13:37:45 -07003484 "out gl_PerVertex {\n"
3485 " vec4 gl_Position;\n"
3486 "};\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003487 "void main() {\n"
3488
3489 // VS writes out red
3490 " color = vec4(1.0, 0.0, 0.0, 1.0);\n"
3491
3492 // generic position stuff
3493 " vec2 vertices;\n"
3494 " int vertexSelector = gl_VertexID;\n"
3495 " if (vertexSelector == 0)\n"
3496 " vertices = vec2(-0.5, -0.5);\n"
3497 " else if (vertexSelector == 1)\n"
3498 " vertices = vec2( 0.5, -0.5);\n"
3499 " else if (vertexSelector == 2)\n"
3500 " vertices = vec2( 0.5, 0.5);\n"
3501 " else\n"
3502 " vertices = vec2( 0.0, 0.0);\n"
3503 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3504
3505 "}\n";
3506
3507 static const char *geomShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07003508 "#version 400\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003509 "#extension GL_ARB_separate_shader_objects : enable\n"
3510 "#extension GL_ARB_shading_language_420pack : enable\n"
3511 "layout( triangles ) in;\n"
3512 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3513 "layout( location = 0 ) in vec4 inColor[3];\n"
3514 "layout( location = 0 ) out vec4 outColor;\n"
Tony Barboure804d202016-01-05 13:37:45 -07003515 "out gl_PerVertex {\n"
3516 " vec4 gl_Position;\n"
3517 "};\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003518 "void main()\n"
3519 "{\n"
3520
3521 // first vertex, pass through red
3522 " gl_Position = gl_in[0].gl_Position;\n"
3523 " outColor = inColor[0];\n"
3524 " EmitVertex();\n"
3525
3526 // second vertex, green
3527 " gl_Position = gl_in[1].gl_Position;\n"
3528 " outColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3529 " EmitVertex();\n"
3530
3531 // third vertex, blue
3532 " gl_Position = gl_in[2].gl_Position;\n"
3533 " outColor = vec4(0.0, 0.0, 1.0, 1.0);\n"
3534 " EmitVertex();\n"
3535
3536 // done
3537 " EndPrimitive();\n"
3538 "}\n";
3539
3540
3541 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07003542 "#version 400\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003543 "#extension GL_ARB_separate_shader_objects : enable\n"
3544 "#extension GL_ARB_shading_language_420pack : enable\n"
3545 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06003546 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003547 "void main() {\n"
3548 // pass through
GregFaae75242015-06-03 18:40:50 -06003549 " outColor = color;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003550 "}\n";
3551
3552
3553
3554 ASSERT_NO_FATAL_FAILURE(InitState());
3555 ASSERT_NO_FATAL_FAILURE(InitViewport());
3556
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003557 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3558 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY_BIT, this);
3559 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northrop475663c2015-04-15 11:19:06 -06003560
3561 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003562 pipelineobj.AddColorAttachment();
Cody Northrop475663c2015-04-15 11:19:06 -06003563 pipelineobj.AddShader(&vs);
3564 pipelineobj.AddShader(&gs);
3565 pipelineobj.AddShader(&ps);
3566
3567 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003568 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop475663c2015-04-15 11:19:06 -06003569
3570 VkDescriptorSetObj descriptorSet(m_device);
3571
Tony Barbourfe3351b2015-07-28 10:17:20 -06003572 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop475663c2015-04-15 11:19:06 -06003573
3574 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003575 Draw(3, 1, 0, 0);
Cody Northrop475663c2015-04-15 11:19:06 -06003576
3577 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003578 EndCommandBuffer();
3579 QueueCommandBuffer();
Cody Northrop475663c2015-04-15 11:19:06 -06003580
3581 RecordImages(m_renderTargets);
3582}
3583
3584TEST_F(VkRenderTest, GSUniformBufferLayout)
3585{
3586 // This test is just like TriangleUniformBufferLayout but adds
3587 // geometry as a stage that also does UBO lookups
3588 // The expected result from this test is a green triangle
3589
3590 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07003591 "#version 400\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003592 "#extension GL_ARB_separate_shader_objects : enable\n"
3593 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06003594 "layout (std140, binding = 0) uniform mixedBuffer {\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003595 " vec4 fRed;\n"
3596 " vec4 fGreen;\n"
3597 " layout(row_major) mat4 worldToProj;\n"
3598 " layout(row_major) mat4 projToWorld;\n"
3599 " layout(row_major) mat4 worldToView;\n"
3600 " layout(row_major) mat4 viewToProj;\n"
3601 " layout(row_major) mat4 worldToShadow[4];\n"
3602 " float fZero;\n"
3603 " float fOne;\n"
3604 " float fTwo;\n"
3605 " float fThree;\n"
3606 " vec3 fZeroZeroZero;\n"
3607 " float fFour;\n"
3608 " vec3 fZeroZeroOne;\n"
3609 " float fFive;\n"
3610 " vec3 fZeroOneZero;\n"
3611 " float fSix;\n"
3612 " float fSeven;\n"
3613 " float fEight;\n"
3614 " float fNine;\n"
3615 " vec2 fZeroZero;\n"
3616 " vec2 fZeroOne;\n"
3617 " vec4 fBlue;\n"
3618 " vec2 fOneZero;\n"
3619 " vec2 fOneOne;\n"
3620 " vec3 fZeroOneOne;\n"
3621 " float fTen;\n"
3622 " float fEleven;\n"
3623 " float fTwelve;\n"
3624 " vec3 fOneZeroZero;\n"
3625 " vec4 uvOffsets[4];\n"
3626 "};\n"
3627 "layout (location = 0) out vec4 color;"
Tony Barboure804d202016-01-05 13:37:45 -07003628 "out gl_PerVertex {\n"
3629 " vec4 gl_Position;\n"
3630 "};\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003631 "void main() {\n"
3632
3633 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3634 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3635 " \n"
3636
3637 // do some exact comparisons, even though we should
3638 // really have an epsilon involved.
3639 " vec4 outColor = right;\n"
3640 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3641 " outColor = wrong;\n"
3642 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3643 " outColor = wrong;\n"
3644 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3645 " outColor = wrong;\n"
3646
3647 " color = outColor;\n"
3648
3649 // generic position stuff
3650 " vec2 vertices;\n"
3651 " int vertexSelector = gl_VertexID;\n"
3652 " if (vertexSelector == 0)\n"
3653 " vertices = vec2(-0.5, -0.5);\n"
3654 " else if (vertexSelector == 1)\n"
3655 " vertices = vec2( 0.5, -0.5);\n"
3656 " else if (vertexSelector == 2)\n"
3657 " vertices = vec2( 0.5, 0.5);\n"
3658 " else\n"
3659 " vertices = vec2( 0.0, 0.0);\n"
3660 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3661 "}\n";
3662
3663 static const char *geomShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07003664 "#version 400\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003665 "#extension GL_ARB_separate_shader_objects : enable\n"
3666 "#extension GL_ARB_shading_language_420pack : enable\n"
3667
3668 // GS layout stuff
3669 "layout( triangles ) in;\n"
3670 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3671
3672 // Between stage IO
3673 "layout( location = 0 ) in vec4 inColor[3];\n"
3674 "layout( location = 0 ) out vec4 color;\n"
3675
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06003676 "layout (std140, binding = 0) uniform mixedBuffer {\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003677 " vec4 fRed;\n"
3678 " vec4 fGreen;\n"
3679 " layout(row_major) mat4 worldToProj;\n"
3680 " layout(row_major) mat4 projToWorld;\n"
3681 " layout(row_major) mat4 worldToView;\n"
3682 " layout(row_major) mat4 viewToProj;\n"
3683 " layout(row_major) mat4 worldToShadow[4];\n"
3684 " float fZero;\n"
3685 " float fOne;\n"
3686 " float fTwo;\n"
3687 " float fThree;\n"
3688 " vec3 fZeroZeroZero;\n"
3689 " float fFour;\n"
3690 " vec3 fZeroZeroOne;\n"
3691 " float fFive;\n"
3692 " vec3 fZeroOneZero;\n"
3693 " float fSix;\n"
3694 " float fSeven;\n"
3695 " float fEight;\n"
3696 " float fNine;\n"
3697 " vec2 fZeroZero;\n"
3698 " vec2 fZeroOne;\n"
3699 " vec4 fBlue;\n"
3700 " vec2 fOneZero;\n"
3701 " vec2 fOneOne;\n"
3702 " vec3 fZeroOneOne;\n"
3703 " float fTen;\n"
3704 " float fEleven;\n"
3705 " float fTwelve;\n"
3706 " vec3 fOneZeroZero;\n"
3707 " vec4 uvOffsets[4];\n"
3708 "};\n"
Tony Barboure804d202016-01-05 13:37:45 -07003709 "out gl_PerVertex {\n"
3710 " vec4 gl_Position;\n"
3711 "};\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003712 "void main()\n"
3713 "{\n"
3714
3715 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3716 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3717
3718 // Each vertex will validate it can read VS output
3719 // then check a few values from the UBO
3720
3721 // first vertex
3722 " vec4 outColor = inColor[0];\n"
3723
3724 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3725 " outColor = wrong;\n"
3726 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3727 " outColor = wrong;\n"
3728 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3729 " outColor = wrong;\n"
3730 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3731 " outColor = wrong;\n"
3732
3733 " gl_Position = gl_in[0].gl_Position;\n"
3734 " color = outColor;\n"
3735 " EmitVertex();\n"
3736
3737 // second vertex
3738 " outColor = inColor[1];\n"
3739
3740 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3741 " outColor = wrong;\n"
3742 " if (fSix != 6.0)\n"
3743 " outColor = wrong;\n"
3744 " if (fOneOne != vec2(1.0, 1.0))\n"
3745 " outColor = wrong;\n"
3746
3747 " gl_Position = gl_in[1].gl_Position;\n"
3748 " color = outColor;\n"
3749 " EmitVertex();\n"
3750
3751 // third vertex
3752 " outColor = inColor[2];\n"
3753
3754 " if (fSeven != 7.0)\n"
3755 " outColor = wrong;\n"
3756 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3757 " outColor = wrong;\n"
3758
3759 " gl_Position = gl_in[2].gl_Position;\n"
3760 " color = outColor;\n"
3761 " EmitVertex();\n"
3762
3763 // done
3764 " EndPrimitive();\n"
3765 "}\n";
3766
3767 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07003768 "#version 400\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003769 "#extension GL_ARB_separate_shader_objects : enable\n"
3770 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06003771 "layout (std140, binding = 0) uniform mixedBuffer {\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003772 " vec4 fRed;\n"
3773 " vec4 fGreen;\n"
3774 " layout(row_major) mat4 worldToProj;\n"
3775 " layout(row_major) mat4 projToWorld;\n"
3776 " layout(row_major) mat4 worldToView;\n"
3777 " layout(row_major) mat4 viewToProj;\n"
3778 " layout(row_major) mat4 worldToShadow[4];\n"
3779 " float fZero;\n"
3780 " float fOne;\n"
3781 " float fTwo;\n"
3782 " float fThree;\n"
3783 " vec3 fZeroZeroZero;\n"
3784 " float fFour;\n"
3785 " vec3 fZeroZeroOne;\n"
3786 " float fFive;\n"
3787 " vec3 fZeroOneZero;\n"
3788 " float fSix;\n"
3789 " float fSeven;\n"
3790 " float fEight;\n"
3791 " float fNine;\n"
3792 " vec2 fZeroZero;\n"
3793 " vec2 fZeroOne;\n"
3794 " vec4 fBlue;\n"
3795 " vec2 fOneZero;\n"
3796 " vec2 fOneOne;\n"
3797 " vec3 fZeroOneOne;\n"
3798 " float fTen;\n"
3799 " float fEleven;\n"
3800 " float fTwelve;\n"
3801 " vec3 fOneZeroZero;\n"
3802 " vec4 uvOffsets[4];\n"
3803 "};\n"
3804 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06003805 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003806 "void main() {\n"
3807 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3808 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3809 " \n"
3810
3811 // start with GS value to ensure it passed
3812 " vec4 outColor = color;\n"
3813
3814 // do some exact comparisons, even though we should
3815 // really have an epsilon involved.
3816 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3817 " outColor = wrong;\n"
3818 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3819 " outColor = wrong;\n"
3820 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3821 " outColor = wrong;\n"
3822 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3823 " outColor = wrong;\n"
3824 " if (fTwo != 2.0)\n"
3825 " outColor = wrong;\n"
3826 " if (fOneOne != vec2(1.0, 1.0))\n"
3827 " outColor = wrong;\n"
3828 " if (fTen != 10.0)\n"
3829 " outColor = wrong;\n"
3830 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3831 " outColor = wrong;\n"
3832 " \n"
GregFaae75242015-06-03 18:40:50 -06003833 " uFragColor = outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003834 "}\n";
3835
3836
Cody Northropd2ad0342015-08-05 11:15:02 -06003837 const float mixedVals[196] = { 1.0f, 0.0f, 0.0f, 1.0f, // vec4 fRed; // align
3838 0.0f, 1.0f, 0.0f, 1.0f, // vec4 fGreen; // align
3839 1.0f, 0.0f, 0.0f, 1.0f, // layout(row_major) mat4 worldToProj;
3840 0.0f, 1.0f, 0.0f, 1.0f, // align
3841 0.0f, 0.0f, 1.0f, 1.0f, // align
3842 0.0f, 0.0f, 0.0f, 1.0f, // align
3843 2.0f, 0.0f, 0.0f, 2.0f, // layout(row_major) mat4 projToWorld;
3844 0.0f, 2.0f, 0.0f, 2.0f, // align
3845 0.0f, 0.0f, 2.0f, 2.0f, // align
3846 0.0f, 0.0f, 0.0f, 2.0f, // align
3847 3.0f, 0.0f, 0.0f, 3.0f, // layout(row_major) mat4 worldToView;
3848 0.0f, 3.0f, 0.0f, 3.0f, // align
3849 0.0f, 0.0f, 3.0f, 3.0f, // align
3850 0.0f, 0.0f, 0.0f, 3.0f, // align
3851 4.0f, 0.0f, 0.0f, 4.0f, // layout(row_major) mat4 viewToProj;
3852 0.0f, 4.0f, 0.0f, 4.0f, // align
3853 0.0f, 0.0f, 4.0f, 4.0f, // align
3854 0.0f, 0.0f, 0.0f, 4.0f, // align
3855 5.0f, 0.0f, 0.0f, 5.0f, // layout(row_major) mat4 worldToShadow[4];
3856 0.0f, 5.0f, 0.0f, 5.0f, // align
3857 0.0f, 0.0f, 5.0f, 5.0f, // align
3858 0.0f, 0.0f, 0.0f, 5.0f, // align
3859 6.0f, 0.0f, 0.0f, 6.0f, // align
3860 0.0f, 6.0f, 0.0f, 6.0f, // align
3861 0.0f, 0.0f, 6.0f, 6.0f, // align
3862 0.0f, 0.0f, 0.0f, 6.0f, // align
3863 7.0f, 0.0f, 0.0f, 7.0f, // align
3864 0.0f, 7.0f, 0.0f, 7.0f, // align
3865 0.0f, 0.0f, 7.0f, 7.0f, // align
3866 0.0f, 0.0f, 0.0f, 7.0f, // align
3867 8.0f, 0.0f, 0.0f, 8.0f, // align
3868 0.0f, 8.0f, 0.0f, 8.0f, // align
3869 0.0f, 0.0f, 8.0f, 8.0f, // align
3870 0.0f, 0.0f, 0.0f, 8.0f, // align
3871 0.0f, // float fZero; // align
3872 1.0f, // float fOne; // pack
3873 2.0f, // float fTwo; // pack
3874 3.0f, // float fThree; // pack
3875 0.0f, 0.0f, 0.0f, // vec3 fZeroZeroZero; // align
3876 4.0f, // float fFour; // pack
3877 0.0f, 0.0f, 1.0f, // vec3 fZeroZeroOne; // align
3878 5.0f, // float fFive; // pack
3879 0.0f, 1.0f, 0.0f, // vec3 fZeroOneZero; // align
3880 6.0f, // float fSix; // pack
3881 7.0f, // float fSeven; // align
3882 8.0f, // float fEight; // pack
3883 9.0f, // float fNine; // pack
3884 0.0f, // BUFFER
3885 0.0f, 0.0f, // vec2 fZeroZero; // align
3886 0.0f, 1.0f, // vec2 fZeroOne; // pack
3887 0.0f, 0.0f, 1.0f, 1.0f, // vec4 fBlue; // align
3888 1.0f, 0.0f, // vec2 fOneZero; // align
3889 1.0f, 1.0f, // vec2 fOneOne; // pack
3890 0.0f, 1.0f, 1.0f, // vec3 fZeroOneOne; // align
3891 10.0f, // float fTen; // pack
3892 11.0f, // float fEleven; // align
3893 12.0f, // float fTwelve; // pack
3894 0.0f, 0.0f, // BUFFER
3895 1.0f, 0.0f, 0.0f, // vec3 fOneZeroZero; // align
3896 0.0f, // BUFFER
3897 0.1f, 0.2f, 0.3f, 0.4f, // vec4 uvOffsets[4];
3898 0.5f, 0.6f, 0.7f, 0.8f, // align
3899 0.9f, 1.0f, 1.1f, 1.2f, // align
3900 1.3f, 1.4f, 1.5f, 1.6f, // align
Cody Northrop475663c2015-04-15 11:19:06 -06003901 };
3902
3903
3904
3905 ASSERT_NO_FATAL_FAILURE(InitState());
3906 ASSERT_NO_FATAL_FAILURE(InitViewport());
3907
3908 const int constCount = sizeof(mixedVals) / sizeof(float);
3909
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003910 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3911 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY_BIT, this);
3912 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northrop475663c2015-04-15 11:19:06 -06003913
3914 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
3915
3916 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003917 pipelineobj.AddColorAttachment();
Cody Northrop475663c2015-04-15 11:19:06 -06003918 pipelineobj.AddShader(&vs);
3919 pipelineobj.AddShader(&gs);
3920 pipelineobj.AddShader(&ps);
3921
3922 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003923 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop475663c2015-04-15 11:19:06 -06003924
3925 VkDescriptorSetObj descriptorSet(m_device);
3926 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
3927
Tony Barbourfe3351b2015-07-28 10:17:20 -06003928 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop475663c2015-04-15 11:19:06 -06003929
3930 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003931 Draw(3, 1, 0, 0);
Cody Northrop475663c2015-04-15 11:19:06 -06003932
3933 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003934 EndCommandBuffer();
3935 QueueCommandBuffer();
Cody Northrop475663c2015-04-15 11:19:06 -06003936
3937 RecordImages(m_renderTargets);
3938}
3939
3940TEST_F(VkRenderTest, GSPositions)
3941{
3942 // This test adds more inputs from the vertex shader and perturbs positions
3943 // Expected result is white triangle with weird positions
3944
3945 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07003946 "#version 400\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003947 "#extension GL_ARB_separate_shader_objects : enable\n"
3948 "#extension GL_ARB_shading_language_420pack : enable\n"
3949
3950 "layout(location = 0) out vec3 out_a;\n"
3951 "layout(location = 1) out vec3 out_b;\n"
3952 "layout(location = 2) out vec3 out_c;\n"
Tony Barboure804d202016-01-05 13:37:45 -07003953 "out gl_PerVertex {\n"
3954 " vec4 gl_Position;\n"
3955 "};\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003956
3957 "void main() {\n"
3958
3959 // write a solid color to each
3960 " out_a = vec3(1.0, 0.0, 0.0);\n"
3961 " out_b = vec3(0.0, 1.0, 0.0);\n"
3962 " out_c = vec3(0.0, 0.0, 1.0);\n"
3963
3964 // generic position stuff
3965 " vec2 vertices;\n"
3966 " int vertexSelector = gl_VertexID;\n"
3967 " if (vertexSelector == 0)\n"
3968 " vertices = vec2(-0.5, -0.5);\n"
3969 " else if (vertexSelector == 1)\n"
3970 " vertices = vec2( 0.5, -0.5);\n"
3971 " else if (vertexSelector == 2)\n"
3972 " vertices = vec2( 0.5, 0.5);\n"
3973 " else\n"
3974 " vertices = vec2( 0.0, 0.0);\n"
3975 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3976
3977 "}\n";
3978
3979 static const char *geomShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07003980 "#version 400\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003981 "#extension GL_ARB_separate_shader_objects : enable\n"
3982 "#extension GL_ARB_shading_language_420pack : enable\n"
3983 "layout( triangles ) in;\n"
3984 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3985
3986 "layout(location = 0) in vec3 in_a[3];\n"
3987 "layout(location = 1) in vec3 in_b[3];\n"
3988 "layout(location = 2) in vec3 in_c[3];\n"
3989
3990 "layout(location = 0) out vec3 out_a;\n"
3991 "layout(location = 1) out vec3 out_b;\n"
3992 "layout(location = 2) out vec3 out_c;\n"
3993
Tony Barboure804d202016-01-05 13:37:45 -07003994 "out gl_PerVertex {\n"
3995 " vec4 gl_Position;\n"
3996 "};\n"
3997
Cody Northrop475663c2015-04-15 11:19:06 -06003998 "void main()\n"
3999 "{\n"
4000
4001 " gl_Position = gl_in[0].gl_Position;\n"
4002 " gl_Position.xy *= vec2(0.75);\n"
4003 " out_a = in_a[0];\n"
4004 " out_b = in_b[0];\n"
4005 " out_c = in_c[0];\n"
4006 " EmitVertex();\n"
4007
4008 " gl_Position = gl_in[1].gl_Position;\n"
4009 " gl_Position.xy *= vec2(1.5);\n"
4010 " out_a = in_a[1];\n"
4011 " out_b = in_b[1];\n"
4012 " out_c = in_c[1];\n"
4013 " EmitVertex();\n"
4014
4015 " gl_Position = gl_in[2].gl_Position;\n"
4016 " gl_Position.xy *= vec2(-0.1);\n"
4017 " out_a = in_a[2];\n"
4018 " out_b = in_b[2];\n"
4019 " out_c = in_c[2];\n"
4020 " EmitVertex();\n"
4021
4022 " EndPrimitive();\n"
4023 "}\n";
4024
4025
4026 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07004027 "#version 400\n"
Cody Northrop475663c2015-04-15 11:19:06 -06004028 "#extension GL_ARB_separate_shader_objects : enable\n"
4029 "#extension GL_ARB_shading_language_420pack : enable\n"
4030
4031 "layout(location = 0) in vec3 in_a;\n"
4032 "layout(location = 1) in vec3 in_b;\n"
4033 "layout(location = 2) in vec3 in_c;\n"
GregFaae75242015-06-03 18:40:50 -06004034 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06004035
4036 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06004037 " outColor = vec4(in_a.x, in_b.y, in_c.z, 1.0);\n"
Cody Northrop475663c2015-04-15 11:19:06 -06004038 "}\n";
4039
4040
4041
4042 ASSERT_NO_FATAL_FAILURE(InitState());
4043 ASSERT_NO_FATAL_FAILURE(InitViewport());
4044
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004045 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4046 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY_BIT, this);
4047 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northrop475663c2015-04-15 11:19:06 -06004048
4049 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004050 pipelineobj.AddColorAttachment();
Cody Northrop475663c2015-04-15 11:19:06 -06004051 pipelineobj.AddShader(&vs);
4052 pipelineobj.AddShader(&gs);
4053 pipelineobj.AddShader(&ps);
4054
4055 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004056 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop475663c2015-04-15 11:19:06 -06004057
4058 VkDescriptorSetObj descriptorSet(m_device);
4059
Tony Barbourfe3351b2015-07-28 10:17:20 -06004060 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop475663c2015-04-15 11:19:06 -06004061
4062 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06004063 Draw(3, 1, 0, 0);
Cody Northrop475663c2015-04-15 11:19:06 -06004064
4065 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06004066 EndCommandBuffer();
4067 QueueCommandBuffer();
Cody Northrop475663c2015-04-15 11:19:06 -06004068
4069 RecordImages(m_renderTargets);
4070}
4071
4072TEST_F(VkRenderTest, GSTriStrip)
4073{
4074 // This test emits multiple multiple triangles using a GS
4075 // Correct result is an multicolor circle
4076
4077 static const char *vertShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07004078 "#version 400\n"
Cody Northrop475663c2015-04-15 11:19:06 -06004079 "#extension GL_ARB_separate_shader_objects : enable\n"
4080 "#extension GL_ARB_shading_language_420pack : enable\n"
4081
Tony Barboure804d202016-01-05 13:37:45 -07004082 "out gl_PerVertex {\n"
4083 " vec4 gl_Position;\n"
4084 "};\n"
4085
Cody Northrop475663c2015-04-15 11:19:06 -06004086 "void main() {\n"
4087
4088 // generic position stuff
4089 " vec2 vertices;\n"
4090 " int vertexSelector = gl_VertexID;\n"
4091 " if (vertexSelector == 0)\n"
4092 " vertices = vec2(-0.5, -0.5);\n"
4093 " else if (vertexSelector == 1)\n"
4094 " vertices = vec2( 0.5, -0.5);\n"
4095 " else if (vertexSelector == 2)\n"
4096 " vertices = vec2( 0.5, 0.5);\n"
4097 " else\n"
4098 " vertices = vec2( 0.0, 0.0);\n"
4099 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
4100
4101 "}\n";
4102
4103 static const char *geomShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07004104 "#version 400\n"
Cody Northrop475663c2015-04-15 11:19:06 -06004105 "#extension GL_ARB_separate_shader_objects : enable\n"
4106 "#extension GL_ARB_shading_language_420pack : enable\n"
4107 "layout( triangles ) in;\n"
4108 "layout( triangle_strip, max_vertices = 18 ) out;\n"
4109
4110 "layout(location = 0) out vec4 outColor;\n"
4111
Tony Barboure804d202016-01-05 13:37:45 -07004112 "out gl_PerVertex {\n"
4113 " vec4 gl_Position;\n"
4114 "};\n"
4115
Cody Northrop475663c2015-04-15 11:19:06 -06004116 "void main()\n"
4117 "{\n"
4118 // init with first position to get zw
4119 " gl_Position = gl_in[0].gl_Position;\n"
4120
4121 " vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
4122 " vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
4123 " vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
4124 " vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
4125
4126 // different color per tri
4127 " vec4[6] colors = { red, white, \n"
4128 " yellow, white, \n"
4129 " blue, white }; \n"
4130
4131 // fan out the triangles
4132 " vec2[18] positions = { vec2(0.0, 0.0), vec2(-0.5, 0.0), vec2(-0.25, -0.5), \n"
4133 " vec2(0.0, 0.0), vec2(-0.25, -0.5), vec2( 0.25, -0.5), \n"
4134 " vec2(0.0, 0.0), vec2( 0.25, -0.5), vec2( 0.5, 0.0), \n"
4135 " vec2(0.0, 0.0), vec2( 0.5, 0.0), vec2( 0.25, 0.5), \n"
4136 " vec2(0.0, 0.0), vec2( 0.25, 0.5), vec2(-0.25, 0.5), \n"
4137 " vec2(0.0, 0.0), vec2(-0.25, 0.5), vec2(-0.5, 0.0) }; \n"
4138
4139 // make a triangle list of 6
4140 " for (int i = 0; i < 6; ++i) { \n"
4141 " outColor = colors[i]; \n"
4142 " for (int j = 0; j < 3; ++j) { \n"
4143 " gl_Position.xy = positions[i * 3 + j]; \n"
4144 " EmitVertex(); \n"
4145 " } \n"
4146 " EndPrimitive();\n"
4147 " } \n"
4148
4149 "}\n";
4150
4151
4152 static const char *fragShaderText =
Tony Barboure804d202016-01-05 13:37:45 -07004153 "#version 400\n"
Cody Northrop475663c2015-04-15 11:19:06 -06004154 "#extension GL_ARB_separate_shader_objects : enable\n"
4155 "#extension GL_ARB_shading_language_420pack : enable\n"
4156
4157
4158 "layout(binding = 0) uniform windowDimensions {\n"
4159 " vec4 dimensions;\n"
4160 "};\n"
4161
4162 "layout(location = 0) in vec4 inColor;\n"
4163 "layout(origin_upper_left) in vec4 gl_FragCoord;\n"
GregFaae75242015-06-03 18:40:50 -06004164 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06004165
4166 "void main() {\n"
4167
4168 // discard to make a nice circle
4169 " vec2 pos = abs(gl_FragCoord.xy) - vec2(dimensions.x, dimensions.y) / 2;\n"
4170 " float dist = sqrt(dot(pos, pos));\n"
4171 " if (dist > 50.0)\n"
4172 " discard;\n"
4173
GregFaae75242015-06-03 18:40:50 -06004174 " outColor = inColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06004175
4176 "}\n";
4177
4178
4179
4180 ASSERT_NO_FATAL_FAILURE(InitState());
4181 ASSERT_NO_FATAL_FAILURE(InitViewport());
4182
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004183 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4184 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY_BIT, this);
4185 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northrop475663c2015-04-15 11:19:06 -06004186
4187 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004188 pipelineobj.AddColorAttachment();
Cody Northrop475663c2015-04-15 11:19:06 -06004189 pipelineobj.AddShader(&vs);
4190 pipelineobj.AddShader(&gs);
4191 pipelineobj.AddShader(&ps);
4192
4193 const float dimensions[4] = { VkRenderFramework::m_width, VkRenderFramework::m_height , 0.0, 0.0};
4194
4195 VkConstantBufferObj windowDimensions(m_device, sizeof(dimensions) / sizeof(dimensions[0]), sizeof(dimensions[0]), (const void*) dimensions);
4196
4197 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004198 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop475663c2015-04-15 11:19:06 -06004199
4200 VkDescriptorSetObj descriptorSet(m_device);
4201 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, windowDimensions);
4202
Tony Barbourfe3351b2015-07-28 10:17:20 -06004203 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop475663c2015-04-15 11:19:06 -06004204
4205 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06004206 Draw(3, 1, 0, 0);
Cody Northrop475663c2015-04-15 11:19:06 -06004207
4208 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06004209 EndCommandBuffer();
4210 QueueCommandBuffer();
Cody Northrop475663c2015-04-15 11:19:06 -06004211
4212 RecordImages(m_renderTargets);
4213}
4214
Chris Forbese182fe02015-06-15 09:32:35 +12004215TEST_F(VkRenderTest, RenderPassLoadOpClear)
4216{
4217 ASSERT_NO_FATAL_FAILURE(InitState());
4218 ASSERT_NO_FATAL_FAILURE(InitViewport());
4219
4220 /* clear via load op to full green */
4221 m_clear_via_load_op = true;
Cody Northrop85789d52015-08-25 15:26:38 -06004222 m_clear_color.float32[0] = 0;
4223 m_clear_color.float32[1] = 1;
4224 m_clear_color.float32[2] = 0;
4225 m_clear_color.float32[3] = 0;
Chris Forbese182fe02015-06-15 09:32:35 +12004226 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004227 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Chris Forbese182fe02015-06-15 09:32:35 +12004228 /* This command buffer contains ONLY the load op! */
Tony Barbourfe3351b2015-07-28 10:17:20 -06004229 EndCommandBuffer();
4230 QueueCommandBuffer();
Chris Forbese182fe02015-06-15 09:32:35 +12004231
4232 RecordImages(m_renderTargets);
4233}
4234
Chris Forbesfa27b952015-06-24 12:05:30 +12004235TEST_F(VkRenderTest, RenderPassAttachmentClear)
4236{
4237 ASSERT_NO_FATAL_FAILURE(InitState());
4238 ASSERT_NO_FATAL_FAILURE(InitViewport());
4239
4240 /* clear via load op to full red */
4241 m_clear_via_load_op = true;
Cody Northrop85789d52015-08-25 15:26:38 -06004242 m_clear_color.float32[0] = 1;
4243 m_clear_color.float32[1] = 0;
4244 m_clear_color.float32[2] = 0;
4245 m_clear_color.float32[3] = 0;
Chris Forbesfa27b952015-06-24 12:05:30 +12004246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004247 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Chris Forbesfa27b952015-06-24 12:05:30 +12004248
4249 /* Load op has cleared to red */
4250
4251 /* Draw, draw, draw... */
4252
4253 /* Now, partway through this renderpass we want to clear the color
4254 * attachment again, this time to green.
4255 */
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004256 VkClearAttachment color_attachment;
4257 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4258 color_attachment.clearValue.color.float32[0] = 0;
4259 color_attachment.clearValue.color.float32[1] = 1;
4260 color_attachment.clearValue.color.float32[2] = 0;
4261 color_attachment.clearValue.color.float32[3] = 0;
4262 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004263 VkClearRect clear_rect = { { { 0, 0 }, { (int)m_width, (int)m_height } } };
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004264 vkCmdClearAttachments(m_commandBuffer->handle(), 1, &color_attachment,
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004265 1, &clear_rect);
Chris Forbesfa27b952015-06-24 12:05:30 +12004266
Tony Barbourfe3351b2015-07-28 10:17:20 -06004267 EndCommandBuffer();
4268 QueueCommandBuffer();
Chris Forbesfa27b952015-06-24 12:05:30 +12004269
4270 RecordImages(m_renderTargets);
4271}
4272
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06004273int main(int argc, char **argv) {
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004274 int result;
4275
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06004276 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -06004277 VkTestFramework::InitArgs(&argc, argv);
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004278
Chia-I Wu6f184292014-12-15 23:57:34 +08004279 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchtera0f74c52014-10-08 08:46:51 -06004280
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004281 result = RUN_ALL_TESTS();
4282
Tony Barbour6918cd52015-04-09 12:58:51 -06004283 VkTestFramework::Finish();
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004284 return result;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06004285}