blob: 5b798130a01ab7283e5c027b20579799c0f4855f [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
David Pinedo9316d3b2015-11-06 12:54:48 -070077#include <vulkan/vk_debug_report_lunarg.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
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060089void VKAPI myDbgFunc(
90 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 Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600103 case VK_DBG_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();
390 commandBuffer->SetViewport(m_viewports.size(), m_viewports.data());
391 commandBuffer->SetScissor(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 =
556 "#version 140\n"
557 "#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"
567 "\n"
568 "void main() \n"
569 "{\n"
570 " outColor = ubuf.color[gl_VertexID];\n"
571 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
572 "}\n";
573
574 static const char *fragShaderText =
575 "#version 140\n"
576 "#extension GL_ARB_separate_shader_objects : enable\n"
577 "#extension GL_ARB_shading_language_420pack : enable\n"
578 "\n"
579 "layout (location = 0) in vec4 inColor;\n"
GregFaae75242015-06-03 18:40:50 -0600580 "layout (location = 0) out vec4 uFragColor;\n"
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600581 "\n"
582 "void main()\n"
583 "{\n"
GregFaae75242015-06-03 18:40:50 -0600584 " uFragColor = inColor;\n"
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600585 "}\n";
586
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600587 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
588 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600589}
590
Tony Barbour6918cd52015-04-09 12:58:51 -0600591TEST_F(VkRenderTest, VKTriangle_OutputLocation)
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600592{
593 static const char *vertShaderText =
594 "#version 140\n"
595 "#extension GL_ARB_separate_shader_objects : enable\n"
596 "#extension GL_ARB_shading_language_420pack : enable\n"
597 "\n"
598 "layout(binding = 0) uniform buf {\n"
599 " mat4 MVP;\n"
600 " vec4 position[3];\n"
601 " vec4 color[3];\n"
602 "} ubuf;\n"
603 "\n"
604 "layout (location = 0) out vec4 outColor;\n"
605 "\n"
606 "void main() \n"
607 "{\n"
608 " outColor = ubuf.color[gl_VertexID];\n"
609 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
610 "}\n";
611
612 static const char *fragShaderText =
613 "#version 140\n"
614 "#extension GL_ARB_separate_shader_objects : enable\n"
615 "#extension GL_ARB_shading_language_420pack : enable\n"
616 "\n"
617 "layout (location = 0) in vec4 inColor;\n"
618 "layout (location = 0) out vec4 outColor;\n"
619 "\n"
620 "void main()\n"
621 "{\n"
622 " outColor = inColor;\n"
623 "}\n";
624
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600625 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 -0600626
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600627 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600628}
Cody Northrop6922da12015-06-23 13:25:51 -0600629
Tony Barbour6918cd52015-04-09 12:58:51 -0600630TEST_F(VkRenderTest, SPV_VKTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -0700631{
Tony Barboure2c58df2014-11-25 13:18:32 -0700632 static const char *vertShaderText =
633 "#version 140\n"
634 "#extension GL_ARB_separate_shader_objects : enable\n"
635 "#extension GL_ARB_shading_language_420pack : enable\n"
636 "\n"
637 "layout(binding = 0) uniform buf {\n"
638 " mat4 MVP;\n"
639 " vec4 position[3];\n"
640 " vec4 color[3];\n"
641 "} ubuf;\n"
642 "\n"
643 "layout (location = 0) out vec4 outColor;\n"
644 "\n"
645 "void main() \n"
646 "{\n"
647 " outColor = ubuf.color[gl_VertexID];\n"
648 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
649 "}\n";
650
651 static const char *fragShaderText =
652 "#version 140\n"
653 "#extension GL_ARB_separate_shader_objects : enable\n"
654 "#extension GL_ARB_shading_language_420pack : enable\n"
655 "\n"
656 "layout (location = 0) in vec4 inColor;\n"
GregFaae75242015-06-03 18:40:50 -0600657 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700658 "\n"
659 "void main()\n"
660 "{\n"
GregFaae75242015-06-03 18:40:50 -0600661 " outColor = inColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700662 "}\n";
663
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600664 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 -0700665
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600666 VKTriangleTest(vertShaderText, fragShaderText, true);
Tony Barboure2c58df2014-11-25 13:18:32 -0700667}
Courtney Goeltzenleuchter538062a2014-10-09 15:40:19 -0600668
Tony Barbour6918cd52015-04-09 12:58:51 -0600669TEST_F(VkRenderTest, SPV_GreenTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -0700670{
Tony Barboure2c58df2014-11-25 13:18:32 -0700671 static const char *vertShaderText =
672 "#version 130\n"
673 "vec2 vertices[3];\n"
674 "void main() {\n"
675 " vertices[0] = vec2(-1.0, -1.0);\n"
676 " vertices[1] = vec2( 1.0, -1.0);\n"
677 " vertices[2] = vec2( 0.0, 1.0);\n"
678 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
679 "}\n";
680
681 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -0600682 "#version 140\n"
683 "#extension GL_ARB_separate_shader_objects : enable\n"
684 "#extension GL_ARB_shading_language_420pack : enable\n"
685 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700686 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600687 " outColor = vec4(0,1,0,1);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700688 "}\n";
689
Cody Northrop3bfd27c2015-03-17 15:55:58 -0600690 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barboure2c58df2014-11-25 13:18:32 -0700691
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600692 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barboure2c58df2014-11-25 13:18:32 -0700693}
Cody Northrop6922da12015-06-23 13:25:51 -0600694
Tony Barbour6918cd52015-04-09 12:58:51 -0600695TEST_F(VkRenderTest, YellowTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -0700696{
697 static const char *vertShaderText =
698 "#version 130\n"
699 "void main() {\n"
700 " vec2 vertices[3];"
701 " vertices[0] = vec2(-0.5, -0.5);\n"
702 " vertices[1] = vec2( 0.5, -0.5);\n"
703 " vertices[2] = vec2( 0.5, 0.5);\n"
704 " vec4 colors[3];\n"
705 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
706 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
707 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
708 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
709 "}\n";
710
711 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -0600712 "#version 140\n"
713 "#extension GL_ARB_separate_shader_objects : enable\n"
714 "#extension GL_ARB_shading_language_420pack : enable\n"
715 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700716 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600717 " outColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700718 "}\n";
719
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600720 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barboure2c58df2014-11-25 13:18:32 -0700721}
722
Tony Barbour6918cd52015-04-09 12:58:51 -0600723TEST_F(VkRenderTest, QuadWithVertexFetch)
Cody Northropee6586d2014-10-09 19:55:56 -0600724{
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600725 static const char *vertShaderText =
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600726 "#version 140\n"
727 "#extension GL_ARB_separate_shader_objects : enable\n"
728 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700729 //XYZ1( -1, -1, -1 )
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600730 "layout (location = 0) in vec4 pos;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700731 //XYZ1( 0.f, 0.f, 0.f )
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600732 "layout (location = 1) in vec4 inColor;\n"
733 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600734 "void main() {\n"
Cody Northrop66594a72014-10-10 14:49:36 -0600735 " outColor = inColor;\n"
Cody Northrop7ad4aaf2014-10-09 21:25:22 -0600736 " gl_Position = pos;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600737 "}\n";
738
Cody Northropee6586d2014-10-09 19:55:56 -0600739
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600740 static const char *fragShaderText =
Cody Northropd43c52e2014-12-05 15:44:14 -0700741 "#version 140\n"
742 "#extension GL_ARB_separate_shader_objects : enable\n"
743 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600744 "layout (location = 0) in vec4 color;\n"
Cody Northropd43c52e2014-12-05 15:44:14 -0700745 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600746 "void main() {\n"
Cody Northropd43c52e2014-12-05 15:44:14 -0700747 " outColor = color;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600748 "}\n";
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600749
Tony Barboure2c58df2014-11-25 13:18:32 -0700750
751
752 ASSERT_NO_FATAL_FAILURE(InitState());
753 ASSERT_NO_FATAL_FAILURE(InitViewport());
754
Tony Barbour6918cd52015-04-09 12:58:51 -0600755 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000756 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -0700757
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -0600758 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
759 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -0700760
Tony Barbour6918cd52015-04-09 12:58:51 -0600761 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800762 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -0700763 pipelineobj.AddShader(&vs);
764 pipelineobj.AddShader(&ps);
765
Tony Barbour6918cd52015-04-09 12:58:51 -0600766 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -0600767
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600768#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600769 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600770 MESH_BIND_ID, // binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800771 sizeof(g_vbData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800772 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
Tony Barboure2c58df2014-11-25 13:18:32 -0700773 };
774
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600775 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600776 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
777 vi_attribs[0].location = 0; // location, position
Tony Barbourd1c35722015-04-16 15:59:00 -0600778 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800779 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600780 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
781 vi_attribs[1].location = 1; // location, color
Tony Barbourd1c35722015-04-16 15:59:00 -0600782 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800783 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 -0700784
785 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
786 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barboure2c58df2014-11-25 13:18:32 -0700787
Tony Barbour1fde6942015-01-09 10:06:53 -0700788 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600789 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure2c58df2014-11-25 13:18:32 -0700790
Tony Barbourfe3351b2015-07-28 10:17:20 -0600791 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600792
Tony Barbourfe3351b2015-07-28 10:17:20 -0600793 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour1fde6942015-01-09 10:06:53 -0700794
795 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600796 Draw(6, 1, 0, 0);
Tony Barbour1fde6942015-01-09 10:06:53 -0700797
798 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600799 ASSERT_VK_SUCCESS(EndCommandBuffer());
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600800
Tony Barbourfe3351b2015-07-28 10:17:20 -0600801 QueueCommandBuffer();
Tony Barbour1fde6942015-01-09 10:06:53 -0700802
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600803 RecordImages(m_renderTargets);
Tobin Ehlisd806c8e2014-10-07 14:41:29 -0600804}
805
Tony Barbour6918cd52015-04-09 12:58:51 -0600806TEST_F(VkRenderTest, TriangleMRT)
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800807{
808 static const char *vertShaderText =
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600809 "#version 140\n"
810 "#extension GL_ARB_separate_shader_objects : enable\n"
811 "#extension GL_ARB_shading_language_420pack : enable\n"
812 "layout (location = 0) in vec4 pos;\n"
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800813 "void main() {\n"
814 " gl_Position = pos;\n"
815 "}\n";
816
817 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -0600818 "#version 140\n"
819 "#extension GL_ARB_separate_shader_objects : enable\n"
820 "#extension GL_ARB_shading_language_420pack : enable\n"
821 "layout (location = 0) out vec4 uFragData0;\n"
822 "layout (location = 1) out vec4 uFragData1;\n"
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800823 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600824 " uFragData0 = vec4(1.0, 0.0, 0.0, 1.0);\n"
825 " uFragData1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800826 "}\n";
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600827 const float vb_data[][2] = {
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800828 { -1.0f, -1.0f },
829 { 1.0f, -1.0f },
830 { -1.0f, 1.0f }
831 };
832
833 ASSERT_NO_FATAL_FAILURE(InitState());
834 ASSERT_NO_FATAL_FAILURE(InitViewport());
835
Tony Barbour6918cd52015-04-09 12:58:51 -0600836 VkConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000837 meshBuffer.BufferMemoryBarrier();
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800838
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -0600839 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
840 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800841
Tony Barbour6918cd52015-04-09 12:58:51 -0600842 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800843 pipelineobj.AddColorAttachment();
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800844 pipelineobj.AddShader(&vs);
845 pipelineobj.AddShader(&ps);
846
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600847#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600848 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600849 MESH_BUF_ID, // Binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800850 sizeof(vb_data[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800851 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800852 };
853
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600854 VkVertexInputAttributeDescription vi_attrib;
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600855 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
856 vi_attrib.location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -0600857 vi_attrib.format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800858 vi_attrib.offset = 0; // Offset of first element in bytes from base of vertex
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800859
860 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
861 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800862
Tony Barbour6918cd52015-04-09 12:58:51 -0600863 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800864
Courtney Goeltzenleuchterb4337c12015-03-05 16:47:18 -0700865 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800866
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600867 VkPipelineColorBlendAttachmentState att = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600868 att.blendEnable = VK_FALSE;
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800869 att.colorWriteMask = 0xf;
Tony Barbourf52346d2015-01-16 14:27:35 -0700870 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800871
Tony Barbourfe3351b2015-07-28 10:17:20 -0600872 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour1fde6942015-01-09 10:06:53 -0700873
Tony Barbourfe3351b2015-07-28 10:17:20 -0600874 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour1fde6942015-01-09 10:06:53 -0700875
Tony Barbourfe3351b2015-07-28 10:17:20 -0600876 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour304ec8b2015-01-07 14:31:52 -0700877#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600878 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour304ec8b2015-01-07 14:31:52 -0700879 pDSDumpDot((char*)"triTest2.dot");
880#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600881
Tony Barbour304ec8b2015-01-07 14:31:52 -0700882 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600883 Draw(3, 1, 0, 0);
Tony Barbour304ec8b2015-01-07 14:31:52 -0700884
885 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600886 ASSERT_VK_SUCCESS(EndCommandBuffer());
887 QueueCommandBuffer();
Tony Barbour304ec8b2015-01-07 14:31:52 -0700888
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600889 RecordImages(m_renderTargets);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800890}
891
Tony Barbour6918cd52015-04-09 12:58:51 -0600892TEST_F(VkRenderTest, QuadWithIndexedVertexFetch)
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700893{
894 static const char *vertShaderText =
895 "#version 140\n"
896 "#extension GL_ARB_separate_shader_objects : enable\n"
897 "#extension GL_ARB_shading_language_420pack : enable\n"
898 "layout(location = 0) in vec4 pos;\n"
899 "layout(location = 1) in vec4 inColor;\n"
900 "layout(location = 0) out vec4 outColor;\n"
901 "void main() {\n"
902 " outColor = inColor;\n"
903 " gl_Position = pos;\n"
904 "}\n";
905
906
907 static const char *fragShaderText =
908 "#version 140\n"
909 "#extension GL_ARB_separate_shader_objects : enable\n"
910 "#extension GL_ARB_shading_language_420pack : enable\n"
911 "layout(location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -0600912 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700913 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600914 " outColor = color;\n"
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700915 "}\n";
916
917 const Vertex g_vbData[] =
918 {
919 // first tri
920 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
921 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
922 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
923
924 // second tri
925 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
926 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
927 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
928 };
929
930 const uint16_t g_idxData[6] = {
931 0, 1, 2,
932 3, 4, 5,
933 };
934
935 ASSERT_NO_FATAL_FAILURE(InitState());
936 ASSERT_NO_FATAL_FAILURE(InitViewport());
937
Tony Barbour6918cd52015-04-09 12:58:51 -0600938 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000939 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700940
Tony Barbour6918cd52015-04-09 12:58:51 -0600941 VkIndexBufferObj indexBuffer(m_device);
Tony Barbourd1c35722015-04-16 15:59:00 -0600942 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), VK_INDEX_TYPE_UINT16, g_idxData);
Mark Lobodzinski49a6b4b2015-02-16 14:24:23 -0600943 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700944
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -0600945 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
946 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700947
Tony Barbour6918cd52015-04-09 12:58:51 -0600948 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800949 pipelineobj.AddColorAttachment();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700950 pipelineobj.AddShader(&vs);
951 pipelineobj.AddShader(&ps);
952
Tony Barbour6918cd52015-04-09 12:58:51 -0600953 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour831062d2015-04-02 15:43:15 -0600954
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700955
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600956#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600957 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600958 MESH_BIND_ID, // binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800959 sizeof(g_vbData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800960 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700961 };
962
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600963 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600964 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
965 vi_attribs[0].location = 0; // layout location of vertex attribute
Tony Barbourd1c35722015-04-16 15:59:00 -0600966 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800967 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600968 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
969 vi_attribs[1].location = 1; // layout location of vertex attribute
Tony Barbourd1c35722015-04-16 15:59:00 -0600970 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800971 vi_attribs[1].offset = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700972
973 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
974 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700975
976 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600977 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour1fde6942015-01-09 10:06:53 -0700978
Tony Barbourfe3351b2015-07-28 10:17:20 -0600979 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700980
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700981#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600982 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlisf27eba72014-12-16 17:34:50 -0700983 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700984#endif
Tony Barbour22e32a12015-01-08 17:08:28 -0700985
Tony Barbourfe3351b2015-07-28 10:17:20 -0600986 BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
987 BindIndexBuffer(&indexBuffer, 0);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700988
989 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600990 DrawIndexed(6, 1, 0, 0, 0);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700991
992 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600993 ASSERT_VK_SUCCESS(EndCommandBuffer());
994 QueueCommandBuffer();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700995
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600996 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700997}
998
Tony Barbour6918cd52015-04-09 12:58:51 -0600999TEST_F(VkRenderTest, GreyandRedCirclesonBlue)
GregF3156cb02014-12-02 15:41:44 -07001000{
1001 // This tests gl_FragCoord
Tony Barboure2c58df2014-11-25 13:18:32 -07001002
GregF3156cb02014-12-02 15:41:44 -07001003 static const char *vertShaderText =
1004 "#version 140\n"
1005 "#extension GL_ARB_separate_shader_objects : enable\n"
1006 "#extension GL_ARB_shading_language_420pack : enable\n"
1007 "layout (location = 0) in vec4 pos;\n"
1008 "layout (location = 0) out vec4 outColor;\n"
1009 "layout (location = 1) out vec4 outColor2;\n"
1010 "void main() {\n"
1011 " gl_Position = pos;\n"
1012 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1013 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1014 "}\n";
1015
1016 static const char *fragShaderText =
GregF3156cb02014-12-02 15:41:44 -07001017 "#version 330\n"
1018 "#extension GL_ARB_separate_shader_objects : enable\n"
1019 "#extension GL_ARB_shading_language_420pack : enable\n"
1020 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1021 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1022 "layout (location = 0) in vec4 color;\n"
1023 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001024 "layout (location = 0) out vec4 outColor;\n"
GregF3156cb02014-12-02 15:41:44 -07001025 "void main() {\n"
1026 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1027 " float dist_squared = dot(pos, pos);\n"
GregFaae75242015-06-03 18:40:50 -06001028 " outColor = (dist_squared < 400.0)\n"
GregF3156cb02014-12-02 15:41:44 -07001029 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1030 " : color2;\n"
1031 "}\n";
1032
1033 ASSERT_NO_FATAL_FAILURE(InitState());
1034 ASSERT_NO_FATAL_FAILURE(InitViewport());
1035
Tony Barbour6918cd52015-04-09 12:58:51 -06001036 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001037 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001038
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001039 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1040 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
GregF3156cb02014-12-02 15:41:44 -07001041
Tony Barbour6918cd52015-04-09 12:58:51 -06001042 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001043 pipelineobj.AddColorAttachment();
GregF3156cb02014-12-02 15:41:44 -07001044 pipelineobj.AddShader(&vs);
1045 pipelineobj.AddShader(&ps);
1046
Tony Barbour6918cd52015-04-09 12:58:51 -06001047 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001048
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001049#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001050 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001051 MESH_BIND_ID, // binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001052 sizeof(g_vbData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001053 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
GregF3156cb02014-12-02 15:41:44 -07001054 };
1055
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001056 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001057 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1058 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001059 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001060 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
GregF3156cb02014-12-02 15:41:44 -07001061
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001062 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF3156cb02014-12-02 15:41:44 -07001063 pipelineobj.AddVertexInputBindings(&vi_binding,1);
GregF3156cb02014-12-02 15:41:44 -07001064
Tony Barbour664accc2015-01-09 12:55:14 -07001065 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour664accc2015-01-09 12:55:14 -07001066
Tony Barbourfe3351b2015-07-28 10:17:20 -06001067 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001068
Tony Barbourfe3351b2015-07-28 10:17:20 -06001069 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001070
Tony Barbourfe3351b2015-07-28 10:17:20 -06001071 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001072#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001073 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001074 pDSDumpDot((char*)"triTest2.dot");
1075#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001076
Tony Barbour664accc2015-01-09 12:55:14 -07001077 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001078 Draw(6, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001079
1080 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001081 EndCommandBuffer();
1082 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001083
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001084 RecordImages(m_renderTargets);
GregF3156cb02014-12-02 15:41:44 -07001085}
1086
Tony Barbour6918cd52015-04-09 12:58:51 -06001087TEST_F(VkRenderTest, RedCirclesonBlue)
GregF3156cb02014-12-02 15:41:44 -07001088{
1089 // This tests that we correctly handle unread fragment inputs
1090
1091 static const char *vertShaderText =
1092 "#version 140\n"
1093 "#extension GL_ARB_separate_shader_objects : enable\n"
1094 "#extension GL_ARB_shading_language_420pack : enable\n"
1095 "layout (location = 0) in vec4 pos;\n"
1096 "layout (location = 0) out vec4 outColor;\n"
1097 "layout (location = 1) out vec4 outColor2;\n"
1098 "void main() {\n"
1099 " gl_Position = pos;\n"
1100 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1101 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1102 "}\n";
1103
1104 static const char *fragShaderText =
GregF3156cb02014-12-02 15:41:44 -07001105 "#version 330\n"
1106 "#extension GL_ARB_separate_shader_objects : enable\n"
1107 "#extension GL_ARB_shading_language_420pack : enable\n"
1108 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1109 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1110 "layout (location = 0) in vec4 color;\n"
1111 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001112 "layout (location = 0) out vec4 outColor;\n"
GregF3156cb02014-12-02 15:41:44 -07001113 "void main() {\n"
1114 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1115 " float dist_squared = dot(pos, pos);\n"
GregFaae75242015-06-03 18:40:50 -06001116 " outColor = (dist_squared < 400.0)\n"
GregF3156cb02014-12-02 15:41:44 -07001117 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1118 " : color2;\n"
1119 "}\n";
1120
1121 ASSERT_NO_FATAL_FAILURE(InitState());
1122 ASSERT_NO_FATAL_FAILURE(InitViewport());
1123
Tony Barbour6918cd52015-04-09 12:58:51 -06001124 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001125 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001126
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001127 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1128 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
GregF3156cb02014-12-02 15:41:44 -07001129
Tony Barbour6918cd52015-04-09 12:58:51 -06001130 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001131 pipelineobj.AddColorAttachment();
GregF3156cb02014-12-02 15:41:44 -07001132 pipelineobj.AddShader(&vs);
1133 pipelineobj.AddShader(&ps);
1134
Tony Barbour6918cd52015-04-09 12:58:51 -06001135 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001136
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001137#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001138 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001139 MESH_BIND_ID, // binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001140 sizeof(g_vbData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001141 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
GregF3156cb02014-12-02 15:41:44 -07001142 };
1143
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001144 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001145 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1146 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001147 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001148 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
GregF3156cb02014-12-02 15:41:44 -07001149
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001150 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF3156cb02014-12-02 15:41:44 -07001151 pipelineobj.AddVertexInputBindings(&vi_binding,1);
GregF3156cb02014-12-02 15:41:44 -07001152
Tony Barbour664accc2015-01-09 12:55:14 -07001153 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001154 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001155
Tony Barbourfe3351b2015-07-28 10:17:20 -06001156 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001157
Tony Barbourfe3351b2015-07-28 10:17:20 -06001158 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001159#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001160 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001161 pDSDumpDot((char*)"triTest2.dot");
1162#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001163 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001164 Draw(6, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001165
1166 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001167 EndCommandBuffer();
1168 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001169
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001170 RecordImages(m_renderTargets);
GregF3156cb02014-12-02 15:41:44 -07001171}
1172
Tony Barbour6918cd52015-04-09 12:58:51 -06001173TEST_F(VkRenderTest, GreyCirclesonBlueFade)
GregF3156cb02014-12-02 15:41:44 -07001174{
1175 // This tests reading gl_ClipDistance from FS
1176
1177 static const char *vertShaderText =
GregFaae75242015-06-03 18:40:50 -06001178 //"#version 140\n"
GregF3156cb02014-12-02 15:41:44 -07001179 "#version 330\n"
1180 "#extension GL_ARB_separate_shader_objects : enable\n"
1181 "#extension GL_ARB_shading_language_420pack : enable\n"
1182 "out gl_PerVertex {\n"
1183 " vec4 gl_Position;\n"
1184 " float gl_ClipDistance[1];\n"
1185 "};\n"
1186 "layout (location = 0) in vec4 pos;\n"
1187 "layout (location = 0) out vec4 outColor;\n"
1188 "layout (location = 1) out vec4 outColor2;\n"
1189 "void main() {\n"
1190 " gl_Position = pos;\n"
1191 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1192 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1193 " float dists[3];\n"
1194 " dists[0] = 0.0;\n"
1195 " dists[1] = 1.0;\n"
1196 " dists[2] = 1.0;\n"
1197 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1198 "}\n";
1199
1200
1201 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -06001202 "#version 140\n"
1203 //"#version 330\n"
GregF3156cb02014-12-02 15:41:44 -07001204 "#extension GL_ARB_separate_shader_objects : enable\n"
1205 "#extension GL_ARB_shading_language_420pack : enable\n"
1206 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1207 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1208 "layout (location = 0) in vec4 color;\n"
1209 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001210 "layout (location = 0) out vec4 uFragColor;\n"
GregF3156cb02014-12-02 15:41:44 -07001211 "void main() {\n"
1212 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1213 " float dist_squared = dot(pos, pos);\n"
GregFaae75242015-06-03 18:40:50 -06001214 " uFragColor = (dist_squared < 400.0)\n"
GregF3156cb02014-12-02 15:41:44 -07001215 " ? color * gl_ClipDistance[0]\n"
1216 " : color2;\n"
1217 "}\n";
1218
1219 ASSERT_NO_FATAL_FAILURE(InitState());
1220 ASSERT_NO_FATAL_FAILURE(InitViewport());
1221
Tony Barbour6918cd52015-04-09 12:58:51 -06001222 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001223 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001224
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001225 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1226 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
GregF3156cb02014-12-02 15:41:44 -07001227
Tony Barbour6918cd52015-04-09 12:58:51 -06001228 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001229 pipelineobj.AddColorAttachment();
GregF3156cb02014-12-02 15:41:44 -07001230 pipelineobj.AddShader(&vs);
1231 pipelineobj.AddShader(&ps);
1232
Tony Barbour6918cd52015-04-09 12:58:51 -06001233 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001234
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001235#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001236 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001237 MESH_BIND_ID, // binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001238 sizeof(g_vbData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001239 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
GregF3156cb02014-12-02 15:41:44 -07001240 };
1241
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001242 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001243 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1244 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001245 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001246 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
GregF3156cb02014-12-02 15:41:44 -07001247
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001248 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF3156cb02014-12-02 15:41:44 -07001249 pipelineobj.AddVertexInputBindings(&vi_binding,1);
GregF3156cb02014-12-02 15:41:44 -07001250
Tony Barbour664accc2015-01-09 12:55:14 -07001251 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
GregF3156cb02014-12-02 15:41:44 -07001252
Tony Barbourfe3351b2015-07-28 10:17:20 -06001253 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001254
Tony Barbourfe3351b2015-07-28 10:17:20 -06001255 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001256
Tony Barbourfe3351b2015-07-28 10:17:20 -06001257 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001258#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001259 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001260 pDSDumpDot((char*)"triTest2.dot");
1261#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001262
1263 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001264 Draw(6, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001265
1266 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001267 EndCommandBuffer();
1268 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001269
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001270 RecordImages(m_renderTargets);
GregF3156cb02014-12-02 15:41:44 -07001271}
Tony Barboure2c58df2014-11-25 13:18:32 -07001272
Tony Barbour6918cd52015-04-09 12:58:51 -06001273TEST_F(VkRenderTest, GreyCirclesonBlueDiscard)
GregF42226582014-12-02 17:19:34 -07001274{
1275 static const char *vertShaderText =
1276 "#version 140\n"
1277 "#extension GL_ARB_separate_shader_objects : enable\n"
1278 "#extension GL_ARB_shading_language_420pack : enable\n"
1279 "layout (location = 0) in vec4 pos;\n"
1280 "layout (location = 0) out vec4 outColor;\n"
1281 "layout (location = 1) out vec4 outColor2;\n"
1282 "void main() {\n"
1283 " gl_Position = pos;\n"
1284 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1285 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1286 "}\n";
1287
1288
1289 static const char *fragShaderText =
GregF42226582014-12-02 17:19:34 -07001290 "#version 330\n"
1291 "#extension GL_ARB_separate_shader_objects : enable\n"
1292 "#extension GL_ARB_shading_language_420pack : enable\n"
1293 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1294 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1295 "layout (location = 0) in vec4 color;\n"
1296 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001297 "layout (location = 0) out vec4 outColor;\n"
GregF42226582014-12-02 17:19:34 -07001298 "void main() {\n"
1299 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1300 " float dist_squared = dot(pos, pos);\n"
1301 " if (dist_squared < 100.0)\n"
1302 " discard;\n"
GregFaae75242015-06-03 18:40:50 -06001303 " outColor = (dist_squared < 400.0)\n"
GregF42226582014-12-02 17:19:34 -07001304 " ? color\n"
1305 " : color2;\n"
1306 "}\n";
1307
1308 ASSERT_NO_FATAL_FAILURE(InitState());
1309 ASSERT_NO_FATAL_FAILURE(InitViewport());
1310
Tony Barbour6918cd52015-04-09 12:58:51 -06001311 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001312 meshBuffer.BufferMemoryBarrier();
GregF42226582014-12-02 17:19:34 -07001313
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001314 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1315 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
GregF42226582014-12-02 17:19:34 -07001316
Tony Barbour6918cd52015-04-09 12:58:51 -06001317 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001318 pipelineobj.AddColorAttachment();
GregF42226582014-12-02 17:19:34 -07001319 pipelineobj.AddShader(&vs);
1320 pipelineobj.AddShader(&ps);
1321
Tony Barbour6918cd52015-04-09 12:58:51 -06001322 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001323
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001324#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001325 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001326 MESH_BIND_ID, // binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001327 sizeof(g_vbData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001328 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
GregF42226582014-12-02 17:19:34 -07001329 };
1330
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001331 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001332 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1333 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001334 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001335 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
GregF42226582014-12-02 17:19:34 -07001336
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001337 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF42226582014-12-02 17:19:34 -07001338 pipelineobj.AddVertexInputBindings(&vi_binding,1);
GregF42226582014-12-02 17:19:34 -07001339
Tony Barbour664accc2015-01-09 12:55:14 -07001340 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour664accc2015-01-09 12:55:14 -07001341
Tony Barbourfe3351b2015-07-28 10:17:20 -06001342 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001343
Tony Barbourfe3351b2015-07-28 10:17:20 -06001344 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001345
Tony Barbourfe3351b2015-07-28 10:17:20 -06001346 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001347#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001348 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001349 pDSDumpDot((char*)"triTest2.dot");
1350#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001351
1352 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001353 Draw(6, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001354
1355 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001356 EndCommandBuffer();
1357 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001358
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001359 RecordImages(m_renderTargets);
GregF42226582014-12-02 17:19:34 -07001360}
1361
1362
Tony Barbour6918cd52015-04-09 12:58:51 -06001363TEST_F(VkRenderTest, TriangleVSUniform)
Cody Northrop66594a72014-10-10 14:49:36 -06001364{
1365 static const char *vertShaderText =
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001366 "#version 140\n"
1367 "#extension GL_ARB_separate_shader_objects : enable\n"
1368 "#extension GL_ARB_shading_language_420pack : enable\n"
1369 "\n"
1370 "layout(binding = 0) uniform buf {\n"
1371 " mat4 MVP;\n"
1372 "} ubuf;\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001373 "void main() {\n"
1374 " vec2 vertices[3];"
1375 " vertices[0] = vec2(-0.5, -0.5);\n"
1376 " vertices[1] = vec2( 0.5, -0.5);\n"
1377 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001378 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001379 "}\n";
1380
1381 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -06001382 "#version 140\n"
1383 "#extension GL_ARB_separate_shader_objects : enable\n"
1384 "#extension GL_ARB_shading_language_420pack : enable\n"
1385 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001386 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001387 " outColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001388 "}\n";
1389
Tony Barboure2c58df2014-11-25 13:18:32 -07001390 ASSERT_NO_FATAL_FAILURE(InitState());
1391 ASSERT_NO_FATAL_FAILURE(InitViewport());
1392
Courtney Goeltzenleuchterfdcfb9f2014-10-10 18:04:39 -06001393 // Create identity matrix
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001394 glm::mat4 Projection = glm::mat4(1.0f);
1395 glm::mat4 View = glm::mat4(1.0f);
1396 glm::mat4 Model = glm::mat4(1.0f);
1397 glm::mat4 MVP = Projection * View * Model;
1398 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1399
Tony Barbour6918cd52015-04-09 12:58:51 -06001400 VkConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001401 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1402 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001403
Tony Barbour6918cd52015-04-09 12:58:51 -06001404 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001405 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001406 pipelineobj.AddShader(&vs);
1407 pipelineobj.AddShader(&ps);
1408
1409 // Create descriptor set and attach the constant buffer to it
Tony Barbour6918cd52015-04-09 12:58:51 -06001410 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001411 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07001412
Tony Barbour664accc2015-01-09 12:55:14 -07001413 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf1878c72015-08-18 14:24:32 -06001414
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001415 VkCommandBufferBeginInfo cbBeginInfo;
1416 memset(&cbBeginInfo, 0, sizeof(VkCommandBufferBeginInfo));
1417 cbBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Courtney Goeltzenleuchter04bb5f82015-10-21 18:11:04 -06001418 cbBeginInfo.flags = 0;
Tobin Ehlisf1878c72015-08-18 14:24:32 -06001419 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barboure2c58df2014-11-25 13:18:32 -07001420
Tony Barbourfe3351b2015-07-28 10:17:20 -06001421 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001422
Tony Barbour664accc2015-01-09 12:55:14 -07001423#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001424 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001425 pDSDumpDot((char*)"triTest2.dot");
1426#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001427
1428 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001429 Draw(6, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001430
1431 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001432 EndCommandBuffer();
1433 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001434
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001435 RecordImages(m_renderTargets);
Tony Barbour664accc2015-01-09 12:55:14 -07001436
Tony Barbourfe3351b2015-07-28 10:17:20 -06001437 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer);
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001438}
1439
Tony Barbour6918cd52015-04-09 12:58:51 -06001440TEST_F(VkRenderTest, MixTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07001441{
1442 // This tests location applied to varyings. Notice that we have switched foo
1443 // and bar in the FS. The triangle should be blended with red, green and blue
1444 // corners.
1445 static const char *vertShaderText =
1446 "#version 140\n"
1447 "#extension GL_ARB_separate_shader_objects : enable\n"
1448 "#extension GL_ARB_shading_language_420pack : enable\n"
1449 "layout (location=0) out vec4 bar;\n"
1450 "layout (location=1) out vec4 foo;\n"
1451 "layout (location=2) out float scale;\n"
1452 "vec2 vertices[3];\n"
1453 "void main() {\n"
1454 " vertices[0] = vec2(-1.0, -1.0);\n"
1455 " vertices[1] = vec2( 1.0, -1.0);\n"
1456 " vertices[2] = vec2( 0.0, 1.0);\n"
1457 "vec4 colors[3];\n"
1458 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1459 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1460 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1461 " foo = colors[gl_VertexID % 3];\n"
1462 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1463 " scale = 1.0;\n"
1464 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1465 "}\n";
1466
1467 static const char *fragShaderText =
1468 "#version 140\n"
1469 "#extension GL_ARB_separate_shader_objects : enable\n"
1470 "#extension GL_ARB_shading_language_420pack : enable\n"
1471 "layout (location = 1) in vec4 bar;\n"
1472 "layout (location = 0) in vec4 foo;\n"
1473 "layout (location = 2) in float scale;\n"
GregFaae75242015-06-03 18:40:50 -06001474 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001475 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001476 " outColor = bar * scale + foo * (1.0-scale);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001477 "}\n";
1478
1479 ASSERT_NO_FATAL_FAILURE(InitState());
1480 ASSERT_NO_FATAL_FAILURE(InitViewport());
1481
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001482 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1483 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001484
Tony Barbour6918cd52015-04-09 12:58:51 -06001485 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001486 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001487 pipelineobj.AddShader(&vs);
1488 pipelineobj.AddShader(&ps);
1489
Tony Barbour6918cd52015-04-09 12:58:51 -06001490 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour831062d2015-04-02 15:43:15 -06001491 descriptorSet.AppendDummy();
Tony Barboure2c58df2014-11-25 13:18:32 -07001492
Tony Barbour664accc2015-01-09 12:55:14 -07001493 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour664accc2015-01-09 12:55:14 -07001494
Tony Barbourfe3351b2015-07-28 10:17:20 -06001495 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001496
Tony Barbourfe3351b2015-07-28 10:17:20 -06001497 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001498
1499#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001500 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001501 pDSDumpDot((char*)"triTest2.dot");
1502#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001503
Tony Barbour664accc2015-01-09 12:55:14 -07001504 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001505 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001506
1507 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001508 EndCommandBuffer();
1509 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001510
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001511 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001512}
1513
Tony Barbour6918cd52015-04-09 12:58:51 -06001514TEST_F(VkRenderTest, QuadVertFetchAndVertID)
Tony Barboure2c58df2014-11-25 13:18:32 -07001515{
1516 // This tests that attributes work in the presence of gl_VertexID
1517
1518 static const char *vertShaderText =
1519 "#version 140\n"
1520 "#extension GL_ARB_separate_shader_objects : enable\n"
1521 "#extension GL_ARB_shading_language_420pack : enable\n"
1522 //XYZ1( -1, -1, -1 )
1523 "layout (location = 0) in vec4 pos;\n"
1524 //XYZ1( 0.f, 0.f, 0.f )
1525 "layout (location = 1) in vec4 inColor;\n"
1526 "layout (location = 0) out vec4 outColor;\n"
1527 "void main() {\n"
1528 " outColor = inColor;\n"
1529 " vec4 vertices[3];"
1530 " vertices[gl_VertexID % 3] = pos;\n"
1531 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1532 "}\n";
1533
1534
1535 static const char *fragShaderText =
1536 "#version 140\n"
1537 "#extension GL_ARB_separate_shader_objects : enable\n"
1538 "#extension GL_ARB_shading_language_420pack : enable\n"
1539 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06001540 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001541 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001542 " outColor = color;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001543 "}\n";
1544
1545 ASSERT_NO_FATAL_FAILURE(InitState());
1546 ASSERT_NO_FATAL_FAILURE(InitViewport());
1547
Tony Barbour6918cd52015-04-09 12:58:51 -06001548 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001549 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07001550
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001551 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1552 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001553
Tony Barbour6918cd52015-04-09 12:58:51 -06001554 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001555 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001556 pipelineobj.AddShader(&vs);
1557 pipelineobj.AddShader(&ps);
1558
Tony Barbour6918cd52015-04-09 12:58:51 -06001559 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001560
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001561#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001562 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001563 MESH_BUF_ID, // Binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001564 sizeof(g_vbData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001565 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
Tony Barboure2c58df2014-11-25 13:18:32 -07001566 };
1567
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001568 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001569 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1570 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001571 vi_attribs[0].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001572 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001573 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1574 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001575 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001576 vi_attribs[1].offset = 16; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -07001577
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001578 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001579 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barboure2c58df2014-11-25 13:18:32 -07001580
Tony Barbour664accc2015-01-09 12:55:14 -07001581 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour664accc2015-01-09 12:55:14 -07001582
Tony Barbourfe3351b2015-07-28 10:17:20 -06001583 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001584
Tony Barbourfe3351b2015-07-28 10:17:20 -06001585 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001586
Tony Barbourfe3351b2015-07-28 10:17:20 -06001587 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001588#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001589 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001590 pDSDumpDot((char*)"triTest2.dot");
1591#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001592
1593 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001594 Draw(6, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001595
1596 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001597 EndCommandBuffer();
1598 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001599
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001600 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001601}
1602
Tony Barbour6918cd52015-04-09 12:58:51 -06001603TEST_F(VkRenderTest, QuadSparseVertFetch)
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001604{
1605 // This tests that attributes work in the presence of gl_VertexID
1606
1607 static const char *vertShaderText =
1608 "#version 140\n"
1609 "#extension GL_ARB_separate_shader_objects : enable\n"
1610 "#extension GL_ARB_shading_language_420pack : enable\n"
1611 //XYZ1( -1, -1, -1 )
1612 "layout (location = 1) in vec4 pos;\n"
1613 "layout (location = 4) in vec4 inColor;\n"
1614 //XYZ1( 0.f, 0.f, 0.f )
1615 "layout (location = 0) out vec4 outColor;\n"
1616 "void main() {\n"
1617 " outColor = inColor;\n"
1618 " gl_Position = pos;\n"
1619 "}\n";
1620
1621
1622 static const char *fragShaderText =
1623 "#version 140\n"
1624 "#extension GL_ARB_separate_shader_objects : enable\n"
1625 "#extension GL_ARB_shading_language_420pack : enable\n"
1626 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06001627 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001628 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001629 " outColor = color;\n"
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001630 "}\n";
1631
1632 ASSERT_NO_FATAL_FAILURE(InitState());
1633 ASSERT_NO_FATAL_FAILURE(InitViewport());
1634
1635 struct VDATA
1636 {
1637 float t1, t2, t3, t4; // filler data
1638 float posX, posY, posZ, posW; // Position data
1639 float r, g, b, a; // Color
1640 };
1641 const struct VDATA vData[] =
1642 {
1643 { XYZ1(0, 0, 0), XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
1644 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1645 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1646 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1647 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1648 { XYZ1(0, 0, 0), XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
1649 };
1650
Tony Barbour6918cd52015-04-09 12:58:51 -06001651 VkConstantBufferObj meshBuffer(m_device,sizeof(vData)/sizeof(vData[0]),sizeof(vData[0]), vData);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001652 meshBuffer.BufferMemoryBarrier();
1653
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001654 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1655 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001656
Tony Barbour6918cd52015-04-09 12:58:51 -06001657 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001658 pipelineobj.AddColorAttachment();
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001659 pipelineobj.AddShader(&vs);
1660 pipelineobj.AddShader(&ps);
1661
Tony Barbour6918cd52015-04-09 12:58:51 -06001662 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001663
1664#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001665 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001666 MESH_BUF_ID, // Binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001667 sizeof(vData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001668 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001669 };
1670
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001671 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001672 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1673 vi_attribs[0].location = 4;
Tony Barbourd1c35722015-04-16 15:59:00 -06001674 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001675 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 -06001676 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1677 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001678 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001679 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 -06001680
1681 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
1682 pipelineobj.AddVertexInputBindings(&vi_binding, 1);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001683
1684 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001685
Tony Barbourfe3351b2015-07-28 10:17:20 -06001686 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001687
Tony Barbourfe3351b2015-07-28 10:17:20 -06001688 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001689
Tony Barbourfe3351b2015-07-28 10:17:20 -06001690 BindVertexBuffer(&meshBuffer, 0, MESH_BUF_ID);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001691#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001692 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001693 pDSDumpDot((char*)"triTest2.dot");
1694#endif
1695
1696 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001697 Draw(6, 1, 0, 0);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001698
1699 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001700 EndCommandBuffer();
1701 QueueCommandBuffer();
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001702
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001703 RecordImages(m_renderTargets);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001704}
1705
Tony Barbour6918cd52015-04-09 12:58:51 -06001706TEST_F(VkRenderTest, TriVertFetchDeadAttr)
Tony Barboure2c58df2014-11-25 13:18:32 -07001707{
1708 // This tests that attributes work in the presence of gl_VertexID
1709 // and a dead attribute in position 0. Draws a triangle with yellow,
1710 // red and green corners, starting at top and going clockwise.
1711
1712 static const char *vertShaderText =
1713 "#version 140\n"
1714 "#extension GL_ARB_separate_shader_objects : enable\n"
1715 "#extension GL_ARB_shading_language_420pack : enable\n"
1716 //XYZ1( -1, -1, -1 )
1717 "layout (location = 0) in vec4 pos;\n"
1718 //XYZ1( 0.f, 0.f, 0.f )
1719 "layout (location = 1) in vec4 inColor;\n"
1720 "layout (location = 0) out vec4 outColor;\n"
1721 "void main() {\n"
1722 " outColor = inColor;\n"
1723 " vec2 vertices[3];"
1724 " vertices[0] = vec2(-1.0, -1.0);\n"
1725 " vertices[1] = vec2( 1.0, -1.0);\n"
1726 " vertices[2] = vec2( 0.0, 1.0);\n"
1727 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1728 "}\n";
1729
1730
1731 static const char *fragShaderText =
1732 "#version 140\n"
1733 "#extension GL_ARB_separate_shader_objects : enable\n"
1734 "#extension GL_ARB_shading_language_420pack : enable\n"
1735 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06001736 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001737 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001738 " outColor = color;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001739 "}\n";
1740
1741 ASSERT_NO_FATAL_FAILURE(InitState());
1742 ASSERT_NO_FATAL_FAILURE(InitViewport());
1743
Tony Barbour6918cd52015-04-09 12:58:51 -06001744 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001745 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07001746
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001747 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1748 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001749
Tony Barbour6918cd52015-04-09 12:58:51 -06001750 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001751 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001752 pipelineobj.AddShader(&vs);
1753 pipelineobj.AddShader(&ps);
1754
Tony Barbour6918cd52015-04-09 12:58:51 -06001755 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001756
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001757#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001758 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001759 MESH_BUF_ID, // Binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001760 sizeof(g_vbData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001761 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
Tony Barboure2c58df2014-11-25 13:18:32 -07001762 };
1763
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001764 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001765 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1766 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001767 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001768 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001769 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1770 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001771 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001772 vi_attribs[1].offset = 16; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -07001773
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001774 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001775 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barboure2c58df2014-11-25 13:18:32 -07001776
Tony Barbour664accc2015-01-09 12:55:14 -07001777 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboure2c58df2014-11-25 13:18:32 -07001778
Tony Barbourfe3351b2015-07-28 10:17:20 -06001779 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001780
Tony Barbourfe3351b2015-07-28 10:17:20 -06001781 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001782
Tony Barbourfe3351b2015-07-28 10:17:20 -06001783 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001784#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001785 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001786 pDSDumpDot((char*)"triTest2.dot");
1787#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001788
1789 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001790 Draw(6, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001791
1792 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001793 EndCommandBuffer();
1794 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001795
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001796 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001797}
1798
Tony Barbour6918cd52015-04-09 12:58:51 -06001799TEST_F(VkRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001800{
1801 static const char *vertShaderText =
1802 "#version 140\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001803 "#extension GL_ARB_separate_shader_objects : enable\n"
1804 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06001805 "layout (std140, binding = 0) uniform bufferVals {\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001806 " mat4 mvp;\n"
1807 "} myBufferVals;\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001808 "layout (location = 0) in vec4 pos;\n"
1809 "layout (location = 1) in vec4 inColor;\n"
Cody Northrop8a3bb132015-06-16 17:32:04 -06001810 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001811 "void main() {\n"
1812 " outColor = inColor;\n"
1813 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06001814 " gl_Position.y = -gl_Position.y;\n"
1815 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001816 "}\n";
1817
1818 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -06001819 "#version 140\n"
1820 "#extension GL_ARB_separate_shader_objects : enable\n"
1821 "#extension GL_ARB_shading_language_420pack : enable\n"
1822 "layout (location = 0) in vec4 color;\n"
1823 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001824 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001825 " outColor = color;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001826 "}\n";
Tony Barboure2c58df2014-11-25 13:18:32 -07001827 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001828
Tony Barboure2c58df2014-11-25 13:18:32 -07001829 glm::mat4 View = glm::lookAt(
1830 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1831 glm::vec3(0,0,0), // and looks at the origin
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06001832 glm::vec3(0,-1,0) // Head is up (set to 0,-1,0 to look upside-down)
Tony Barboure2c58df2014-11-25 13:18:32 -07001833 );
1834
1835 glm::mat4 Model = glm::mat4(1.0f);
1836
1837 glm::mat4 MVP = Projection * View * Model;
1838
1839 ASSERT_NO_FATAL_FAILURE(InitState());
1840 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wub4052042015-07-09 10:16:34 +08001841 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Chia-I Wu08accc62015-07-07 11:50:03 +08001842 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height, m_depth_stencil_fmt);
Tony Barboure2c58df2014-11-25 13:18:32 -07001843
Tony Barbour6918cd52015-04-09 12:58:51 -06001844 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 -07001845 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1846
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001847 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barboure2c58df2014-11-25 13:18:32 -07001848
Tony Barbour6918cd52015-04-09 12:58:51 -06001849 VkConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001850 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1851 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001852
Tony Barbour6918cd52015-04-09 12:58:51 -06001853 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001854 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001855 pipelineobj.AddShader(&vs);
1856 pipelineobj.AddShader(&ps);
1857
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001858 VkPipelineDepthStencilStateCreateInfo ds_state;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001859 ds_state.depthTestEnable = VK_TRUE;
1860 ds_state.depthWriteEnable = VK_TRUE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001861 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL;
Cody Northrop271ba752015-08-26 10:01:32 -06001862 ds_state.depthBoundsTestEnable = VK_FALSE;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001863 ds_state.stencilTestEnable = VK_FALSE;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001864 ds_state.back.depthFailOp = VK_STENCIL_OP_KEEP;
1865 ds_state.back.failOp = VK_STENCIL_OP_KEEP;
1866 ds_state.back.passOp = VK_STENCIL_OP_KEEP;
1867 ds_state.back.compareOp = VK_COMPARE_OP_ALWAYS;
Tony Barbourf52346d2015-01-16 14:27:35 -07001868 ds_state.front = ds_state.back;
1869 pipelineobj.SetDepthStencil(&ds_state);
1870
Tony Barbour6918cd52015-04-09 12:58:51 -06001871 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001872 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07001873
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001874#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001875 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001876 MESH_BUF_ID, // Binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001877 sizeof(g_vbData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001878 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001879 };
Tony Barboure2c58df2014-11-25 13:18:32 -07001880
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001881 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001882 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1883 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001884 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001885 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001886 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1887 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001888 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001889 vi_attribs[1].offset = 16; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -07001890
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001891 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001892 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barboure2c58df2014-11-25 13:18:32 -07001893
Tony Barbour1c45ce02015-03-27 17:03:18 -06001894 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour1c45ce02015-03-27 17:03:18 -06001895
Tony Barbourfe3351b2015-07-28 10:17:20 -06001896 ASSERT_VK_SUCCESS(BeginCommandBuffer());
1897 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barboure2c58df2014-11-25 13:18:32 -07001898
Tony Barbourfe3351b2015-07-28 10:17:20 -06001899 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour1fde6942015-01-09 10:06:53 -07001900#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001901 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour1fde6942015-01-09 10:06:53 -07001902 pDSDumpDot((char*)"triTest2.dot");
1903#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001904
1905 // render triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001906 Draw(36, 1, 0, 0);
Tony Barbour1fde6942015-01-09 10:06:53 -07001907
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001908
Tony Barbour1fde6942015-01-09 10:06:53 -07001909 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001910 EndCommandBuffer();
1911 QueueCommandBuffer();
Tony Barbour1fde6942015-01-09 10:06:53 -07001912
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001913 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001914}
1915
Tony Barbour6918cd52015-04-09 12:58:51 -06001916TEST_F(VkRenderTest, VSTexture)
Tony Barboure2c58df2014-11-25 13:18:32 -07001917{
1918 // The expected result from this test is a green and red triangle;
1919 // one red vertex on the left, two green vertices on the right.
1920 static const char *vertShaderText =
Cody Northrop8a3bb132015-06-16 17:32:04 -06001921 "#version 140\n"
1922 "#extension GL_ARB_separate_shader_objects : enable\n"
1923 "#extension GL_ARB_shading_language_420pack : enable\n"
1924 "layout (location = 0) out vec4 texColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001925 "uniform sampler2D surface;\n"
1926 "void main() {\n"
1927 " vec2 vertices[3];"
1928 " vertices[0] = vec2(-0.5, -0.5);\n"
1929 " vertices[1] = vec2( 0.5, -0.5);\n"
1930 " vertices[2] = vec2( 0.5, 0.5);\n"
1931 " vec2 positions[3];"
1932 " positions[0] = vec2( 0.0, 0.0);\n"
1933 " positions[1] = vec2( 0.25, 0.1);\n"
1934 " positions[2] = vec2( 0.1, 0.25);\n"
1935 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1936 " texColor = textureLod(surface, samplePos, 0.0);\n"
1937 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1938 "}\n";
1939
1940 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -06001941 "#version 140\n"
1942 "#extension GL_ARB_separate_shader_objects : enable\n"
1943 "#extension GL_ARB_shading_language_420pack : enable\n"
1944 "layout (location = 0) in vec4 texColor;\n"
1945 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001946 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001947 " outColor = texColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001948 "}\n";
1949
1950 ASSERT_NO_FATAL_FAILURE(InitState());
1951 ASSERT_NO_FATAL_FAILURE(InitViewport());
1952
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001953 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1954 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbour6918cd52015-04-09 12:58:51 -06001955 VkSamplerObj sampler(m_device);
1956 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07001957
Tony Barbour6918cd52015-04-09 12:58:51 -06001958 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001959 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001960 pipelineobj.AddShader(&vs);
1961 pipelineobj.AddShader(&ps);
1962
Tony Barbour6918cd52015-04-09 12:58:51 -06001963 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08001964 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07001965
Tony Barbour664accc2015-01-09 12:55:14 -07001966 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001967 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure2c58df2014-11-25 13:18:32 -07001968
Tony Barbourfe3351b2015-07-28 10:17:20 -06001969 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001970
1971#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001972 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001973 pDSDumpDot((char*)"triTest2.dot");
1974#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001975
Tony Barbour664accc2015-01-09 12:55:14 -07001976 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001977 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001978
1979 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001980 EndCommandBuffer();
1981 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001982
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001983 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001984}
GregFaae75242015-06-03 18:40:50 -06001985
1986
1987
Tony Barbour6918cd52015-04-09 12:58:51 -06001988TEST_F(VkRenderTest, TexturedTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07001989{
1990 // The expected result from this test is a red and green checkered triangle
1991 static const char *vertShaderText =
1992 "#version 140\n"
1993 "#extension GL_ARB_separate_shader_objects : enable\n"
1994 "#extension GL_ARB_shading_language_420pack : enable\n"
1995 "layout (location = 0) out vec2 samplePos;\n"
1996 "void main() {\n"
1997 " vec2 vertices[3];"
1998 " vertices[0] = vec2(-0.5, -0.5);\n"
1999 " vertices[1] = vec2( 0.5, -0.5);\n"
2000 " vertices[2] = vec2( 0.5, 0.5);\n"
2001 " vec2 positions[3];"
2002 " positions[0] = vec2( 0.0, 0.0);\n"
2003 " positions[1] = vec2( 1.0, 0.0);\n"
2004 " positions[2] = vec2( 1.0, 1.0);\n"
2005 " samplePos = positions[gl_VertexID % 3];\n"
2006 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2007 "}\n";
2008
2009 static const char *fragShaderText =
2010 "#version 140\n"
2011 "#extension GL_ARB_separate_shader_objects : enable\n"
2012 "#extension GL_ARB_shading_language_420pack : enable\n"
2013 "layout (location = 0) in vec2 samplePos;\n"
2014 "layout (binding = 0) uniform sampler2D surface;\n"
2015 "layout (location=0) out vec4 outColor;\n"
2016 "void main() {\n"
2017 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2018 " outColor = texColor;\n"
2019 "}\n";
2020
2021 ASSERT_NO_FATAL_FAILURE(InitState());
2022 ASSERT_NO_FATAL_FAILURE(InitViewport());
2023
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002024 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2025 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbour6918cd52015-04-09 12:58:51 -06002026 VkSamplerObj sampler(m_device);
2027 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002028
Tony Barbour6918cd52015-04-09 12:58:51 -06002029 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002030 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002031 pipelineobj.AddShader(&vs);
2032 pipelineobj.AddShader(&ps);
2033
Tony Barbour6918cd52015-04-09 12:58:51 -06002034 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002035 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002036
Tony Barbour664accc2015-01-09 12:55:14 -07002037 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002038 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002039
Tony Barbourfe3351b2015-07-28 10:17:20 -06002040 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002041
2042#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002043 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002044 pDSDumpDot((char*)"triTest2.dot");
2045#endif
2046 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002047 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002048
2049 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002050 EndCommandBuffer();
2051 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002052
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002053 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002054}
Tony Barbour6918cd52015-04-09 12:58:51 -06002055TEST_F(VkRenderTest, TexturedTriangleClip)
Tony Barboure2c58df2014-11-25 13:18:32 -07002056{
2057 // The expected result from this test is a red and green checkered triangle
2058 static const char *vertShaderText =
2059 "#version 330\n"
2060 "#extension GL_ARB_separate_shader_objects : enable\n"
2061 "#extension GL_ARB_shading_language_420pack : enable\n"
2062 "layout (location = 0) out vec2 samplePos;\n"
2063 "out gl_PerVertex {\n"
2064 " vec4 gl_Position;\n"
2065 " float gl_ClipDistance[1];\n"
2066 "};\n"
2067 "void main() {\n"
2068 " vec2 vertices[3];"
2069 " vertices[0] = vec2(-0.5, -0.5);\n"
2070 " vertices[1] = vec2( 0.5, -0.5);\n"
2071 " vertices[2] = vec2( 0.5, 0.5);\n"
2072 " vec2 positions[3];"
2073 " positions[0] = vec2( 0.0, 0.0);\n"
2074 " positions[1] = vec2( 1.0, 0.0);\n"
2075 " positions[2] = vec2( 1.0, 1.0);\n"
2076 " float dists[3];\n"
2077 " dists[0] = 1.0;\n"
2078 " dists[1] = 1.0;\n"
2079 " dists[2] = -1.0;\n"
2080 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2081 " samplePos = positions[gl_VertexID % 3];\n"
2082 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2083 "}\n";
2084
2085 static const char *fragShaderText =
2086 "#version 140\n"
2087 "#extension GL_ARB_separate_shader_objects : enable\n"
2088 "#extension GL_ARB_shading_language_420pack : enable\n"
2089 "layout (location = 0) in vec2 samplePos;\n"
2090 "layout (binding = 0) uniform sampler2D surface;\n"
2091 "layout (location=0) out vec4 outColor;\n"
2092 "void main() {\n"
2093 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2094 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2095 " outColor = texColor;\n"
2096 "}\n";
2097
2098
2099 ASSERT_NO_FATAL_FAILURE(InitState());
2100 ASSERT_NO_FATAL_FAILURE(InitViewport());
2101
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002102 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2103 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbour6918cd52015-04-09 12:58:51 -06002104 VkSamplerObj sampler(m_device);
2105 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002106
Tony Barbour6918cd52015-04-09 12:58:51 -06002107 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002108 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002109 pipelineobj.AddShader(&vs);
2110 pipelineobj.AddShader(&ps);
2111
Tony Barbour6918cd52015-04-09 12:58:51 -06002112 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002113 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002114
Tony Barbour664accc2015-01-09 12:55:14 -07002115 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002116 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002117
Tony Barbourfe3351b2015-07-28 10:17:20 -06002118 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002119
2120#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002121 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002122 pDSDumpDot((char*)"triTest2.dot");
2123#endif
2124 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002125 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002126
2127 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002128 EndCommandBuffer();
2129 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002130
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002131 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002132}
GregFaae75242015-06-03 18:40:50 -06002133
Tony Barbour6918cd52015-04-09 12:58:51 -06002134TEST_F(VkRenderTest, FSTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07002135{
2136 // The expected result from this test is a red and green checkered triangle
2137 static const char *vertShaderText =
2138 "#version 140\n"
2139 "#extension GL_ARB_separate_shader_objects : enable\n"
2140 "#extension GL_ARB_shading_language_420pack : enable\n"
2141 "layout (location = 0) out vec2 samplePos;\n"
2142 "void main() {\n"
2143 " vec2 vertices[3];"
2144 " vertices[0] = vec2(-0.5, -0.5);\n"
2145 " vertices[1] = vec2( 0.5, -0.5);\n"
2146 " vertices[2] = vec2( 0.5, 0.5);\n"
2147 " vec2 positions[3];"
2148 " positions[0] = vec2( 0.0, 0.0);\n"
2149 " positions[1] = vec2( 1.0, 0.0);\n"
2150 " positions[2] = vec2( 1.0, 1.0);\n"
2151 " samplePos = positions[gl_VertexID % 3];\n"
2152 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2153 "}\n";
2154
2155 static const char *fragShaderText =
2156 "#version 140\n"
2157 "#extension GL_ARB_separate_shader_objects : enable\n"
2158 "#extension GL_ARB_shading_language_420pack : enable\n"
2159 "layout (location = 0) in vec2 samplePos;\n"
2160 "layout (binding = 0) uniform sampler2D surface;\n"
2161 "layout (location=0) out vec4 outColor;\n"
2162 "void main() {\n"
2163 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2164 " outColor = texColor;\n"
2165 "}\n";
2166
2167 ASSERT_NO_FATAL_FAILURE(InitState());
2168 ASSERT_NO_FATAL_FAILURE(InitViewport());
2169
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002170 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2171 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbour6918cd52015-04-09 12:58:51 -06002172 VkSamplerObj sampler(m_device);
2173 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002174
Tony Barbour6918cd52015-04-09 12:58:51 -06002175 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002176 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002177 pipelineobj.AddShader(&vs);
2178 pipelineobj.AddShader(&ps);
2179
Tony Barbour6918cd52015-04-09 12:58:51 -06002180 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002181 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002182
Tony Barbour664accc2015-01-09 12:55:14 -07002183 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002184 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002185
Tony Barbourfe3351b2015-07-28 10:17:20 -06002186 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002187
2188#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002189 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002190 pDSDumpDot((char*)"triTest2.dot");
2191#endif
2192 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002193 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002194
2195 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002196 EndCommandBuffer();
2197 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002198
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002199 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002200}
Tony Barbour6918cd52015-04-09 12:58:51 -06002201TEST_F(VkRenderTest, SamplerBindingsTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07002202{
2203 // This test sets bindings on the samplers
2204 // For now we are asserting that sampler and texture pairs
2205 // march in lock step, and are set via GLSL binding. This can
2206 // and will probably change.
2207 // The sampler bindings should match the sampler and texture slot
2208 // number set up by the application.
2209 // This test will result in a blue triangle
2210 static const char *vertShaderText =
2211 "#version 140\n"
2212 "#extension GL_ARB_separate_shader_objects : enable\n"
2213 "#extension GL_ARB_shading_language_420pack : enable\n"
2214 "layout (location = 0) out vec4 samplePos;\n"
2215 "void main() {\n"
2216 " vec2 vertices[3];"
2217 " vertices[0] = vec2(-0.5, -0.5);\n"
2218 " vertices[1] = vec2( 0.5, -0.5);\n"
2219 " vertices[2] = vec2( 0.5, 0.5);\n"
2220 " vec2 positions[3];"
2221 " positions[0] = vec2( 0.0, 0.0);\n"
2222 " positions[1] = vec2( 1.0, 0.0);\n"
2223 " positions[2] = vec2( 1.0, 1.0);\n"
2224 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2225 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2226 "}\n";
2227
2228 static const char *fragShaderText =
2229 "#version 140\n"
2230 "#extension GL_ARB_separate_shader_objects : enable\n"
2231 "#extension GL_ARB_shading_language_420pack : enable\n"
2232 "layout (location = 0) in vec4 samplePos;\n"
2233 "layout (binding = 0) uniform sampler2D surface0;\n"
2234 "layout (binding = 1) uniform sampler2D surface1;\n"
2235 "layout (binding = 12) uniform sampler2D surface2;\n"
GregFaae75242015-06-03 18:40:50 -06002236 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002237 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06002238 " outColor = textureLod(surface2, samplePos.xy, 0.0);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002239 "}\n";
2240
2241 ASSERT_NO_FATAL_FAILURE(InitState());
2242 ASSERT_NO_FATAL_FAILURE(InitViewport());
2243
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002244 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2245 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002246
Tony Barbour6918cd52015-04-09 12:58:51 -06002247 VkSamplerObj sampler1(m_device);
2248 VkSamplerObj sampler2(m_device);
2249 VkSamplerObj sampler3(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002250
Tony Barbourebc093f2015-04-01 16:38:10 -06002251 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
Tony Barbour6918cd52015-04-09 12:58:51 -06002252 VkTextureObj texture1(m_device, tex_colors); // Red
Tony Barbourebc093f2015-04-01 16:38:10 -06002253 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
Tony Barbour6918cd52015-04-09 12:58:51 -06002254 VkTextureObj texture2(m_device, tex_colors); // Green
Tony Barbourebc093f2015-04-01 16:38:10 -06002255 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
Tony Barbour6918cd52015-04-09 12:58:51 -06002256 VkTextureObj texture3(m_device, tex_colors); // Blue
Tony Barboure2c58df2014-11-25 13:18:32 -07002257
Tony Barbour6918cd52015-04-09 12:58:51 -06002258 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002259 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002260 pipelineobj.AddShader(&vs);
2261 pipelineobj.AddShader(&ps);
2262
Tony Barbour6918cd52015-04-09 12:58:51 -06002263 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002264 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2265 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2266 for (int i = 0; i < 10; i++)
2267 descriptorSet.AppendDummy();
2268 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barboure2c58df2014-11-25 13:18:32 -07002269
Tony Barbour664accc2015-01-09 12:55:14 -07002270 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002271 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002272
Tony Barbourfe3351b2015-07-28 10:17:20 -06002273 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002274
2275#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002276 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002277 pDSDumpDot((char*)"triTest2.dot");
2278#endif
2279 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002280 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002281
2282 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002283 EndCommandBuffer();
2284 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002285
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002286 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002287}
2288
Tony Barbour6918cd52015-04-09 12:58:51 -06002289TEST_F(VkRenderTest, TriangleVSUniformBlock)
Tony Barboure2c58df2014-11-25 13:18:32 -07002290{
2291 // The expected result from this test is a blue triangle
2292
2293 static const char *vertShaderText =
2294 "#version 140\n"
2295 "#extension GL_ARB_separate_shader_objects : enable\n"
2296 "#extension GL_ARB_shading_language_420pack : enable\n"
2297 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002298 "layout (std140, binding = 0) uniform bufferVals {\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002299 " vec4 red;\n"
2300 " vec4 green;\n"
2301 " vec4 blue;\n"
2302 " vec4 white;\n"
2303 "} myBufferVals;\n"
2304 "void main() {\n"
2305 " vec2 vertices[3];"
2306 " vertices[0] = vec2(-0.5, -0.5);\n"
2307 " vertices[1] = vec2( 0.5, -0.5);\n"
2308 " vertices[2] = vec2( 0.5, 0.5);\n"
2309 " outColor = myBufferVals.blue;\n"
2310 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2311 "}\n";
2312
2313 static const char *fragShaderText =
2314 "#version 140\n"
2315 "#extension GL_ARB_separate_shader_objects : enable\n"
2316 "#extension GL_ARB_shading_language_420pack : enable\n"
2317 "layout (location = 0) in vec4 inColor;\n"
GregFaae75242015-06-03 18:40:50 -06002318 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002319 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06002320 " outColor = inColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002321 "}\n";
2322
2323 ASSERT_NO_FATAL_FAILURE(InitState());
2324 ASSERT_NO_FATAL_FAILURE(InitViewport());
2325
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002326 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2327 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002328
2329 // Let's populate our buffer with the following:
2330 // vec4 red;
2331 // vec4 green;
2332 // vec4 blue;
2333 // vec4 white;
2334 const int valCount = 4 * 4;
2335 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2336 0.0, 1.0, 0.0, 1.0,
2337 0.0, 0.0, 1.0, 1.0,
2338 1.0, 1.0, 1.0, 1.0 };
2339
Tony Barbour6918cd52015-04-09 12:58:51 -06002340 VkConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002341
Tony Barbour6918cd52015-04-09 12:58:51 -06002342 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002343 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002344 pipelineobj.AddShader(&vs);
2345 pipelineobj.AddShader(&ps);
2346
Tony Barbour6918cd52015-04-09 12:58:51 -06002347 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002348 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, colorBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002349
Tony Barbour664accc2015-01-09 12:55:14 -07002350 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002351 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002352
Tony Barbourfe3351b2015-07-28 10:17:20 -06002353 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002354
2355#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002356 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002357 pDSDumpDot((char*)"triTest2.dot");
2358#endif
2359 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002360 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002361
2362 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002363 EndCommandBuffer();
2364 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002365
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002366 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002367}
2368
Tony Barbour6918cd52015-04-09 12:58:51 -06002369TEST_F(VkRenderTest, TriangleFSUniformBlockBinding)
Tony Barboure2c58df2014-11-25 13:18:32 -07002370{
2371 // This test allows the shader to select which buffer it is
2372 // pulling from using layout binding qualifier.
2373 // There are corresponding changes in the compiler stack that
2374 // will select the buffer using binding directly.
2375 // The binding number should match the slot number set up by
2376 // the application.
2377 // The expected result from this test is a purple triangle
2378
2379 static const char *vertShaderText =
2380 "#version 140\n"
2381 "#extension GL_ARB_separate_shader_objects : enable\n"
2382 "#extension GL_ARB_shading_language_420pack : enable\n"
2383 "void main() {\n"
2384 " vec2 vertices[3];"
2385 " vertices[0] = vec2(-0.5, -0.5);\n"
2386 " vertices[1] = vec2( 0.5, -0.5);\n"
2387 " vertices[2] = vec2( 0.5, 0.5);\n"
2388 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2389 "}\n";
2390
2391 static const char *fragShaderText =
2392 "#version 140\n"
2393 "#extension GL_ARB_separate_shader_objects : enable\n"
2394 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002395 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2396 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2397 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
2398 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
GregFaae75242015-06-03 18:40:50 -06002399 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002400 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06002401 " outColor = myBlueVal.color;\n"
2402 " outColor += myRedVal.color;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002403 "}\n";
2404
2405 ASSERT_NO_FATAL_FAILURE(InitState());
2406 ASSERT_NO_FATAL_FAILURE(InitViewport());
2407
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002408 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2409 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002410
2411 // We're going to create a number of uniform buffers, and then allow
2412 // the shader to select which it wants to read from with a binding
2413
2414 // Let's populate the buffers with a single color each:
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002415 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2416 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2417 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2418 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barboure2c58df2014-11-25 13:18:32 -07002419
2420 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2421 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2422 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2423 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2424
2425 const int redCount = sizeof(redVals) / sizeof(float);
2426 const int greenCount = sizeof(greenVals) / sizeof(float);
2427 const int blueCount = sizeof(blueVals) / sizeof(float);
2428 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2429
Tony Barbour6918cd52015-04-09 12:58:51 -06002430 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002431
Tony Barbour6918cd52015-04-09 12:58:51 -06002432 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002433
Tony Barbour6918cd52015-04-09 12:58:51 -06002434 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002435
Tony Barbour6918cd52015-04-09 12:58:51 -06002436 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002437
Tony Barbour6918cd52015-04-09 12:58:51 -06002438 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002439 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002440 pipelineobj.AddShader(&vs);
2441 pipelineobj.AddShader(&ps);
2442
Tony Barbour6918cd52015-04-09 12:58:51 -06002443 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002444 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2445 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2446 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2447 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002448
Tony Barbour664accc2015-01-09 12:55:14 -07002449 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002450 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure2c58df2014-11-25 13:18:32 -07002451
Tony Barbourfe3351b2015-07-28 10:17:20 -06002452 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002453
2454#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002455 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002456 pDSDumpDot((char*)"triTest2.dot");
2457#endif
2458 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002459 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002460
2461 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002462 EndCommandBuffer();
2463 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002464
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002465 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002466}
2467
Tony Barbour6918cd52015-04-09 12:58:51 -06002468TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBinding)
Tony Barboure2c58df2014-11-25 13:18:32 -07002469{
2470 // This test is the same as TriangleFSUniformBlockBinding, but
2471 // it does not provide an instance name.
2472 // The expected result from this test is a purple triangle
2473
2474 static const char *vertShaderText =
2475 "#version 140\n"
2476 "#extension GL_ARB_separate_shader_objects : enable\n"
2477 "#extension GL_ARB_shading_language_420pack : enable\n"
2478 "void main() {\n"
2479 " vec2 vertices[3];"
2480 " vertices[0] = vec2(-0.5, -0.5);\n"
2481 " vertices[1] = vec2( 0.5, -0.5);\n"
2482 " vertices[2] = vec2( 0.5, 0.5);\n"
2483 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2484 "}\n";
2485
2486 static const char *fragShaderText =
2487 "#version 430\n"
2488 "#extension GL_ARB_separate_shader_objects : enable\n"
2489 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002490 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2491 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2492 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2493 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northropd43c52e2014-12-05 15:44:14 -07002494 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002495 "void main() {\n"
Cody Northropd43c52e2014-12-05 15:44:14 -07002496 " outColor = blue;\n"
2497 " outColor += red;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002498 "}\n";
2499 ASSERT_NO_FATAL_FAILURE(InitState());
2500 ASSERT_NO_FATAL_FAILURE(InitViewport());
2501
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002502 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2503 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002504
2505 // We're going to create a number of uniform buffers, and then allow
2506 // the shader to select which it wants to read from with a binding
2507
2508 // Let's populate the buffers with a single color each:
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002509 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2510 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2511 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2512 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barboure2c58df2014-11-25 13:18:32 -07002513
2514 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2515 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2516 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2517 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2518
2519 const int redCount = sizeof(redVals) / sizeof(float);
2520 const int greenCount = sizeof(greenVals) / sizeof(float);
2521 const int blueCount = sizeof(blueVals) / sizeof(float);
2522 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2523
Tony Barbour6918cd52015-04-09 12:58:51 -06002524 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002525
Tony Barbour6918cd52015-04-09 12:58:51 -06002526 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002527
Tony Barbour6918cd52015-04-09 12:58:51 -06002528 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002529
Tony Barbour6918cd52015-04-09 12:58:51 -06002530 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002531
Tony Barbour6918cd52015-04-09 12:58:51 -06002532 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002533 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002534 pipelineobj.AddShader(&vs);
2535 pipelineobj.AddShader(&ps);
2536
Tony Barbour6918cd52015-04-09 12:58:51 -06002537 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002538 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2539 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2540 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2541 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002542
Tony Barbour664accc2015-01-09 12:55:14 -07002543 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002544 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002545
Tony Barbourfe3351b2015-07-28 10:17:20 -06002546 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002547
2548#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002549 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002550 pDSDumpDot((char*)"triTest2.dot");
2551#endif
2552 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002553 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002554
2555 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002556 EndCommandBuffer();
2557 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002558
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002559 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002560}
2561
GregF6084aec2015-07-01 16:11:09 -06002562TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBindingWithStruct)
2563{
2564 // This test is the same as TriangleFSUniformBlockBinding, but
2565 // it does not provide an instance name.
2566 // The expected result from this test is a purple triangle
2567
2568 static const char *vertShaderText =
2569 "#version 140\n"
2570 "#extension GL_ARB_separate_shader_objects : enable\n"
2571 "#extension GL_ARB_shading_language_420pack : enable\n"
2572 "void main() {\n"
2573 " vec2 vertices[3];"
2574 " vertices[0] = vec2(-0.5, -0.5);\n"
2575 " vertices[1] = vec2( 0.5, -0.5);\n"
2576 " vertices[2] = vec2( 0.5, 0.5);\n"
2577 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2578 "}\n";
2579
2580 static const char *fragShaderText =
2581 "#version 430\n"
2582 "#extension GL_ARB_separate_shader_objects : enable\n"
2583 "#extension GL_ARB_shading_language_420pack : enable\n"
2584 "\n"
2585 " struct PS_INPUT {\n"
2586 " vec2 member0;\n"
2587 " vec4 member1;\n"
2588 " vec4 member2;\n"
2589 " vec4 member3;\n"
2590 " vec4 member4;\n"
2591 " vec4 member5;\n"
2592 " vec4 member6;\n"
2593 " vec4 member7;\n"
2594 " vec4 member8;\n"
2595 " vec4 member9;\n"
2596 " };\n"
2597 "\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002598 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2599 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2600 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2601 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
GregF6084aec2015-07-01 16:11:09 -06002602 "layout (location = 0) out vec4 outColor;\n"
2603 "PS_INPUT MainFs()\n"
2604 "{\n"
2605 " PS_INPUT o;\n"
2606 " o.member9 = red;\n"
2607 " return o;\n"
2608 "}\n"
2609 "\n"
2610 "void main()\n"
2611 "{\n"
2612 " PS_INPUT o;\n"
2613 " o = MainFs();\n"
2614 " outColor = blue;"
2615 " outColor += o.member9;\n"
2616 "}\n";;
2617 ASSERT_NO_FATAL_FAILURE(InitState());
2618 ASSERT_NO_FATAL_FAILURE(InitViewport());
2619
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002620 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2621 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
GregF6084aec2015-07-01 16:11:09 -06002622
2623 // We're going to create a number of uniform buffers, and then allow
2624 // the shader to select which it wants to read from with a binding
2625
2626 // Let's populate the buffers with a single color each:
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002627 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2628 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2629 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2630 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
GregF6084aec2015-07-01 16:11:09 -06002631
2632 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2633 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2634 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2635 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2636
2637 const int redCount = sizeof(redVals) / sizeof(float);
2638 const int greenCount = sizeof(greenVals) / sizeof(float);
2639 const int blueCount = sizeof(blueVals) / sizeof(float);
2640 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2641
2642 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2643
2644 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2645
2646 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2647
2648 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
2649
2650 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002651 pipelineobj.AddColorAttachment();
GregF6084aec2015-07-01 16:11:09 -06002652 pipelineobj.AddShader(&vs);
2653 pipelineobj.AddShader(&ps);
2654
2655 VkDescriptorSetObj descriptorSet(m_device);
2656 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2657 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2658 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2659 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
2660
2661 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002662 ASSERT_VK_SUCCESS(BeginCommandBuffer());
GregF6084aec2015-07-01 16:11:09 -06002663
Tony Barbourfe3351b2015-07-28 10:17:20 -06002664 GenericDrawPreparation(pipelineobj, descriptorSet);
GregF6084aec2015-07-01 16:11:09 -06002665
2666#ifdef DUMP_STATE_DOT
2667 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
2668 pDSDumpDot((char*)"triTest2.dot");
2669#endif
2670 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002671 Draw(3, 1, 0, 0);
GregF6084aec2015-07-01 16:11:09 -06002672
2673 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002674 EndCommandBuffer();
2675 QueueCommandBuffer();
GregF6084aec2015-07-01 16:11:09 -06002676
2677 RecordImages(m_renderTargets);
2678}
2679
Tony Barbour6918cd52015-04-09 12:58:51 -06002680TEST_F(VkRenderTest, CubeWithVertexFetchAndMVPAndTexture)
Tony Barboure2c58df2014-11-25 13:18:32 -07002681{
2682 static const char *vertShaderText =
2683 "#version 140\n"
2684 "#extension GL_ARB_separate_shader_objects : enable\n"
2685 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002686 "layout (std140, binding=0) uniform bufferVals {\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002687 " mat4 mvp;\n"
2688 "} myBufferVals;\n"
2689 "layout (location=0) in vec4 pos;\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002690 "layout (location=1) in vec2 input_uv;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002691 "layout (location=0) out vec2 UV;\n"
2692 "void main() {\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002693 " UV = input_uv;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002694 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002695 " gl_Position.y = -gl_Position.y;\n"
2696 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002697 "}\n";
2698
2699 static const char *fragShaderText =
2700 "#version 140\n"
2701 "#extension GL_ARB_separate_shader_objects : enable\n"
2702 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wu11078b02015-01-04 16:27:24 +08002703 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002704 "layout (location=0) out vec4 outColor;\n"
2705 "layout (location=0) in vec2 UV;\n"
2706 "void main() {\n"
2707 " outColor= textureLod(surface, UV, 0.0);\n"
2708 "}\n";
2709 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2710
2711 glm::mat4 View = glm::lookAt(
2712 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2713 glm::vec3(0,0,0), // and looks at the origin
2714 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2715 );
2716
2717 glm::mat4 Model = glm::mat4(1.0f);
2718
2719 glm::mat4 MVP = Projection * View * Model;
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002720 int num_verts = sizeof(g_vb_texture_Data) / sizeof(g_vb_texture_Data[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002721
2722
2723 ASSERT_NO_FATAL_FAILURE(InitState());
2724 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wub4052042015-07-09 10:16:34 +08002725 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Chia-I Wu08accc62015-07-07 11:50:03 +08002726 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height, m_depth_stencil_fmt);
Tony Barboure2c58df2014-11-25 13:18:32 -07002727
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002728 VkConstantBufferObj meshBuffer(m_device, num_verts,
2729 sizeof(g_vb_texture_Data[0]), g_vb_texture_Data);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00002730 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07002731
Mark Lobodzinski17caf572015-01-29 08:55:56 -06002732 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barboure2c58df2014-11-25 13:18:32 -07002733
Tony Barbour6918cd52015-04-09 12:58:51 -06002734 VkConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002735 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2736 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbour6918cd52015-04-09 12:58:51 -06002737 VkSamplerObj sampler(m_device);
2738 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002739
Tony Barbour6918cd52015-04-09 12:58:51 -06002740 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002741 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002742 pipelineobj.AddShader(&vs);
2743 pipelineobj.AddShader(&ps);
2744
Tony Barbour6918cd52015-04-09 12:58:51 -06002745 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002746 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mvpBuffer);
Chia-I Wu11078b02015-01-04 16:27:24 +08002747 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002748
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002749#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002750 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002751 MESH_BIND_ID, // binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08002752 sizeof(g_vb_texture_Data[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002753 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002754 };
Tony Barboure2c58df2014-11-25 13:18:32 -07002755
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002756 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002757 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2758 vi_attribs[0].location = 0; // location
Tony Barbourd1c35722015-04-16 15:59:00 -06002759 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08002760 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002761 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2762 vi_attribs[1].location = 1; // location
2763 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08002764 vi_attribs[1].offset = 16; // Offset of uv components
Tony Barboure2c58df2014-11-25 13:18:32 -07002765
Tony Barboure2c58df2014-11-25 13:18:32 -07002766 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002767 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barboure2c58df2014-11-25 13:18:32 -07002768
Tony Barbourdd6e32e2015-07-10 15:29:03 -06002769 VkPipelineDepthStencilStateCreateInfo ds_state;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002770 ds_state.depthTestEnable = VK_TRUE;
2771 ds_state.depthWriteEnable = VK_TRUE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002772 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL;
Cody Northrop271ba752015-08-26 10:01:32 -06002773 ds_state.depthBoundsTestEnable = VK_FALSE;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002774 ds_state.stencilTestEnable = VK_FALSE;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002775 ds_state.back.depthFailOp = VK_STENCIL_OP_KEEP;
2776 ds_state.back.failOp = VK_STENCIL_OP_KEEP;
2777 ds_state.back.passOp = VK_STENCIL_OP_KEEP;
2778 ds_state.back.compareOp = VK_COMPARE_OP_ALWAYS;
Tony Barbourf52346d2015-01-16 14:27:35 -07002779 ds_state.front = ds_state.back;
2780 pipelineobj.SetDepthStencil(&ds_state);
2781
Tony Barbour1c45ce02015-03-27 17:03:18 -06002782 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tobin Ehlisf1878c72015-08-18 14:24:32 -06002783
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002784 VkCommandBufferBeginInfo cbBeginInfo;
2785 memset(&cbBeginInfo, 0, sizeof(VkCommandBufferBeginInfo));
2786 cbBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Courtney Goeltzenleuchter04bb5f82015-10-21 18:11:04 -06002787 cbBeginInfo.flags = 0;
Tobin Ehlisf1878c72015-08-18 14:24:32 -06002788 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barboure2c58df2014-11-25 13:18:32 -07002789
Tony Barbourfe3351b2015-07-28 10:17:20 -06002790 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002791
Tony Barbourfe3351b2015-07-28 10:17:20 -06002792 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002793#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002794 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002795 pDSDumpDot((char*)"triTest2.dot");
2796#endif
2797 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002798 Draw(num_verts, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002799
2800 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002801 EndCommandBuffer();
2802 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002803
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002804 RecordImages(m_renderTargets);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002805 RotateTriangleVSUniform(Projection, View, Model, &mvpBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002806}
Cody Northropf1990a92014-12-09 11:17:01 -07002807
Tony Barbour6918cd52015-04-09 12:58:51 -06002808TEST_F(VkRenderTest, TriangleMixedSamplerUniformBlockBinding)
Cody Northropf1990a92014-12-09 11:17:01 -07002809{
2810 // This test mixes binding slots of textures and buffers, ensuring
2811 // that sparse and overlapping assignments work.
Cody Northropb110b4f2014-12-09 13:59:39 -07002812 // The expected result from this test is a purple triangle, although
Cody Northropf1990a92014-12-09 11:17:01 -07002813 // you can modify it to move the desired result around.
2814
2815 static const char *vertShaderText =
2816 "#version 140\n"
2817 "#extension GL_ARB_separate_shader_objects : enable\n"
2818 "#extension GL_ARB_shading_language_420pack : enable\n"
2819 "void main() {\n"
2820 " vec2 vertices[3];"
2821 " vertices[0] = vec2(-0.5, -0.5);\n"
2822 " vertices[1] = vec2( 0.5, -0.5);\n"
2823 " vertices[2] = vec2( 0.5, 0.5);\n"
2824 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2825 "}\n";
2826
2827 static const char *fragShaderText =
2828 "#version 430\n"
2829 "#extension GL_ARB_separate_shader_objects : enable\n"
2830 "#extension GL_ARB_shading_language_420pack : enable\n"
2831 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wu11078b02015-01-04 16:27:24 +08002832 "layout (binding = 3) uniform sampler2D surface1;\n"
2833 "layout (binding = 1) uniform sampler2D surface2;\n"
2834 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002835
Cody Northropb110b4f2014-12-09 13:59:39 -07002836
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002837 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2838 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2839 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2840 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropf1990a92014-12-09 11:17:01 -07002841 "layout (location = 0) out vec4 outColor;\n"
2842 "void main() {\n"
Cody Northropb110b4f2014-12-09 13:59:39 -07002843 " outColor = red * vec4(0.00001);\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002844 " outColor += white * vec4(0.00001);\n"
2845 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropb110b4f2014-12-09 13:59:39 -07002846 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002847 "}\n";
2848 ASSERT_NO_FATAL_FAILURE(InitState());
2849 ASSERT_NO_FATAL_FAILURE(InitViewport());
2850
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002851 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2852 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northropf1990a92014-12-09 11:17:01 -07002853
Cody Northropf1990a92014-12-09 11:17:01 -07002854 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2855 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2856 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2857 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2858
2859 const int redCount = sizeof(redVals) / sizeof(float);
2860 const int greenCount = sizeof(greenVals) / sizeof(float);
2861 const int blueCount = sizeof(blueVals) / sizeof(float);
2862 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2863
Tony Barbour6918cd52015-04-09 12:58:51 -06002864 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2865 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2866 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2867 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropf1990a92014-12-09 11:17:01 -07002868
Tony Barbourebc093f2015-04-01 16:38:10 -06002869 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour6918cd52015-04-09 12:58:51 -06002870 VkSamplerObj sampler0(m_device);
2871 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbourebc093f2015-04-01 16:38:10 -06002872 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour6918cd52015-04-09 12:58:51 -06002873 VkSamplerObj sampler2(m_device);
2874 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbourebc093f2015-04-01 16:38:10 -06002875 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour6918cd52015-04-09 12:58:51 -06002876 VkSamplerObj sampler4(m_device);
2877 VkTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropb110b4f2014-12-09 13:59:39 -07002878
2879 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2880 // TODO: Get back here ASAP and understand why.
Tony Barbourebc093f2015-04-01 16:38:10 -06002881 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour6918cd52015-04-09 12:58:51 -06002882 VkSamplerObj sampler7(m_device);
2883 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropf1990a92014-12-09 11:17:01 -07002884
Tony Barbour6918cd52015-04-09 12:58:51 -06002885 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002886 pipelineobj.AddColorAttachment();
Cody Northropf1990a92014-12-09 11:17:01 -07002887 pipelineobj.AddShader(&vs);
2888 pipelineobj.AddShader(&ps);
2889
Tony Barbour6918cd52015-04-09 12:58:51 -06002890 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002891 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2892 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2893 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2894 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002895 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
Chia-I Wu11078b02015-01-04 16:27:24 +08002896 // swap blue and green
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002897 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2898 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2899 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropf1990a92014-12-09 11:17:01 -07002900
Tony Barbour664accc2015-01-09 12:55:14 -07002901 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002902 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropf1990a92014-12-09 11:17:01 -07002903
Tony Barbourfe3351b2015-07-28 10:17:20 -06002904 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002905
2906#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002907 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002908 pDSDumpDot((char*)"triTest2.dot");
2909#endif
2910 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002911 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002912
2913 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002914 EndCommandBuffer();
2915 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002916
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002917 RecordImages(m_renderTargets);
Cody Northropf1990a92014-12-09 11:17:01 -07002918}
2919
Tony Barbour6918cd52015-04-09 12:58:51 -06002920TEST_F(VkRenderTest, TriangleMatchingSamplerUniformBlockBinding)
Cody Northropbd531de2014-12-09 19:08:54 -07002921{
2922 // This test matches binding slots of textures and buffers, requiring
2923 // the driver to give them distinct number spaces.
2924 // The expected result from this test is a red triangle, although
2925 // you can modify it to move the desired result around.
2926
2927 static const char *vertShaderText =
2928 "#version 140\n"
2929 "#extension GL_ARB_separate_shader_objects : enable\n"
2930 "#extension GL_ARB_shading_language_420pack : enable\n"
2931 "void main() {\n"
2932 " vec2 vertices[3];"
2933 " vertices[0] = vec2(-0.5, -0.5);\n"
2934 " vertices[1] = vec2( 0.5, -0.5);\n"
2935 " vertices[2] = vec2( 0.5, 0.5);\n"
2936 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2937 "}\n";
2938
2939 static const char *fragShaderText =
2940 "#version 430\n"
2941 "#extension GL_ARB_separate_shader_objects : enable\n"
2942 "#extension GL_ARB_shading_language_420pack : enable\n"
2943 "layout (binding = 0) uniform sampler2D surface0;\n"
2944 "layout (binding = 1) uniform sampler2D surface1;\n"
2945 "layout (binding = 2) uniform sampler2D surface2;\n"
2946 "layout (binding = 3) uniform sampler2D surface3;\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002947 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2948 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2949 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2950 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropbd531de2014-12-09 19:08:54 -07002951 "layout (location = 0) out vec4 outColor;\n"
2952 "void main() {\n"
2953 " outColor = red;// * vec4(0.00001);\n"
2954 " outColor += white * vec4(0.00001);\n"
2955 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2956 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2957 "}\n";
2958 ASSERT_NO_FATAL_FAILURE(InitState());
2959 ASSERT_NO_FATAL_FAILURE(InitViewport());
2960
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002961 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2962 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northropbd531de2014-12-09 19:08:54 -07002963
2964 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2965 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2966 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2967 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2968
2969 const int redCount = sizeof(redVals) / sizeof(float);
2970 const int greenCount = sizeof(greenVals) / sizeof(float);
2971 const int blueCount = sizeof(blueVals) / sizeof(float);
2972 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2973
Tony Barbour6918cd52015-04-09 12:58:51 -06002974 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2975 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2976 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2977 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropbd531de2014-12-09 19:08:54 -07002978
Tony Barbourebc093f2015-04-01 16:38:10 -06002979 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour6918cd52015-04-09 12:58:51 -06002980 VkSamplerObj sampler0(m_device);
2981 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbourebc093f2015-04-01 16:38:10 -06002982 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour6918cd52015-04-09 12:58:51 -06002983 VkSamplerObj sampler2(m_device);
2984 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbourebc093f2015-04-01 16:38:10 -06002985 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour6918cd52015-04-09 12:58:51 -06002986 VkSamplerObj sampler4(m_device);
2987 VkTextureObj texture4(m_device, tex_colors); // Light Green
Tony Barbourebc093f2015-04-01 16:38:10 -06002988 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour6918cd52015-04-09 12:58:51 -06002989 VkSamplerObj sampler7(m_device);
2990 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropbd531de2014-12-09 19:08:54 -07002991
Tony Barbour6918cd52015-04-09 12:58:51 -06002992 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002993 pipelineobj.AddColorAttachment();
Cody Northropbd531de2014-12-09 19:08:54 -07002994 pipelineobj.AddShader(&vs);
2995 pipelineobj.AddShader(&ps);
2996
Tony Barbour6918cd52015-04-09 12:58:51 -06002997 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002998 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2999 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3000 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
3001 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003002 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
3003 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
3004 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
3005 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropbd531de2014-12-09 19:08:54 -07003006
Tony Barbour664accc2015-01-09 12:55:14 -07003007 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003008 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropbd531de2014-12-09 19:08:54 -07003009
Tony Barbourfe3351b2015-07-28 10:17:20 -06003010 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07003011
3012#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003013 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07003014 pDSDumpDot((char*)"triTest2.dot");
3015#endif
3016 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003017 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07003018
3019 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003020 EndCommandBuffer();
3021 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07003022
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06003023 RecordImages(m_renderTargets);
Cody Northropbd531de2014-12-09 19:08:54 -07003024}
3025
Tony Barbour6918cd52015-04-09 12:58:51 -06003026TEST_F(VkRenderTest, TriangleUniformBufferLayout)
Cody Northrop04ad1202014-12-17 15:26:33 -07003027{
3028 // This test populates a buffer with a variety of different data
3029 // types, then reads them out with a shader.
3030 // The expected result from this test is a green triangle
3031
3032 static const char *vertShaderText =
3033 "#version 140\n"
3034 "#extension GL_ARB_separate_shader_objects : enable\n"
3035 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06003036 "layout (std140, binding = 0) uniform mixedBuffer {\n"
Cody Northrop04ad1202014-12-17 15:26:33 -07003037 " vec4 fRed;\n"
3038 " vec4 fGreen;\n"
3039 " layout(row_major) mat4 worldToProj;\n"
3040 " layout(row_major) mat4 projToWorld;\n"
3041 " layout(row_major) mat4 worldToView;\n"
3042 " layout(row_major) mat4 viewToProj;\n"
3043 " layout(row_major) mat4 worldToShadow[4];\n"
3044 " float fZero;\n"
3045 " float fOne;\n"
3046 " float fTwo;\n"
3047 " float fThree;\n"
3048 " vec3 fZeroZeroZero;\n"
3049 " float fFour;\n"
3050 " vec3 fZeroZeroOne;\n"
3051 " float fFive;\n"
3052 " vec3 fZeroOneZero;\n"
3053 " float fSix;\n"
3054 " float fSeven;\n"
3055 " float fEight;\n"
3056 " float fNine;\n"
3057 " vec2 fZeroZero;\n"
3058 " vec2 fZeroOne;\n"
3059 " vec4 fBlue;\n"
3060 " vec2 fOneZero;\n"
3061 " vec2 fOneOne;\n"
3062 " vec3 fZeroOneOne;\n"
3063 " float fTen;\n"
3064 " float fEleven;\n"
3065 " float fTwelve;\n"
3066 " vec3 fOneZeroZero;\n"
3067 " vec4 uvOffsets[4];\n"
3068 "};\n"
3069 "layout (location = 0) out vec4 color;"
3070 "void main() {\n"
3071
3072 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3073 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3074 " \n"
3075
3076 // do some exact comparisons, even though we should
3077 // really have an epsilon involved.
3078 " vec4 outColor = right;\n"
3079 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3080 " outColor = wrong;\n"
3081 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3082 " outColor = wrong;\n"
3083 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3084 " outColor = wrong;\n"
3085
3086 " color = outColor;\n"
3087
3088 // generic position stuff
3089 " vec2 vertices;\n"
3090 " int vertexSelector = gl_VertexID;\n"
3091 " if (vertexSelector == 0)\n"
3092 " vertices = vec2(-0.5, -0.5);\n"
3093 " else if (vertexSelector == 1)\n"
3094 " vertices = vec2( 0.5, -0.5);\n"
3095 " else if (vertexSelector == 2)\n"
3096 " vertices = vec2( 0.5, 0.5);\n"
3097 " else\n"
3098 " vertices = vec2( 0.0, 0.0);\n"
3099 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3100 "}\n";
3101
3102 static const char *fragShaderText =
3103 "#version 140\n"
3104 "#extension GL_ARB_separate_shader_objects : enable\n"
3105 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06003106 "layout (std140, binding = 0) uniform mixedBuffer {\n"
Cody Northrop04ad1202014-12-17 15:26:33 -07003107 " vec4 fRed;\n"
3108 " vec4 fGreen;\n"
3109 " layout(row_major) mat4 worldToProj;\n"
3110 " layout(row_major) mat4 projToWorld;\n"
3111 " layout(row_major) mat4 worldToView;\n"
3112 " layout(row_major) mat4 viewToProj;\n"
3113 " layout(row_major) mat4 worldToShadow[4];\n"
3114 " float fZero;\n"
3115 " float fOne;\n"
3116 " float fTwo;\n"
3117 " float fThree;\n"
3118 " vec3 fZeroZeroZero;\n"
3119 " float fFour;\n"
3120 " vec3 fZeroZeroOne;\n"
3121 " float fFive;\n"
3122 " vec3 fZeroOneZero;\n"
3123 " float fSix;\n"
3124 " float fSeven;\n"
3125 " float fEight;\n"
3126 " float fNine;\n"
3127 " vec2 fZeroZero;\n"
3128 " vec2 fZeroOne;\n"
3129 " vec4 fBlue;\n"
3130 " vec2 fOneZero;\n"
3131 " vec2 fOneOne;\n"
3132 " vec3 fZeroOneOne;\n"
3133 " float fTen;\n"
3134 " float fEleven;\n"
3135 " float fTwelve;\n"
3136 " vec3 fOneZeroZero;\n"
3137 " vec4 uvOffsets[4];\n"
3138 "};\n"
3139 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06003140 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop04ad1202014-12-17 15:26:33 -07003141 "void main() {\n"
3142 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3143 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3144 " \n"
3145
3146 // start with VS value to ensure it passed
3147 " vec4 outColor = color;\n"
3148
3149 // do some exact comparisons, even though we should
3150 // really have an epsilon involved.
3151 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3152 " outColor = wrong;\n"
3153 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3154 " outColor = wrong;\n"
3155 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3156 " outColor = wrong;\n"
3157 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3158 " outColor = wrong;\n"
3159 " if (fTwo != 2.0)\n"
3160 " outColor = wrong;\n"
3161 " if (fOneOne != vec2(1.0, 1.0))\n"
3162 " outColor = wrong;\n"
3163 " if (fTen != 10.0)\n"
3164 " outColor = wrong;\n"
3165 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3166 " outColor = wrong;\n"
3167 " \n"
GregFaae75242015-06-03 18:40:50 -06003168 " uFragColor = outColor;\n"
Cody Northrop04ad1202014-12-17 15:26:33 -07003169 "}\n";
3170
3171
Cody Northropd2ad0342015-08-05 11:15:02 -06003172 const float mixedVals[196] = { 1.0f, 0.0f, 0.0f, 1.0f, // vec4 fRed; // align
3173 0.0f, 1.0f, 0.0f, 1.0f, // vec4 fGreen; // align
3174 1.0f, 0.0f, 0.0f, 1.0f, // layout(row_major) mat4 worldToProj;
3175 0.0f, 1.0f, 0.0f, 1.0f, // align
3176 0.0f, 0.0f, 1.0f, 1.0f, // align
3177 0.0f, 0.0f, 0.0f, 1.0f, // align
3178 2.0f, 0.0f, 0.0f, 2.0f, // layout(row_major) mat4 projToWorld;
3179 0.0f, 2.0f, 0.0f, 2.0f, // align
3180 0.0f, 0.0f, 2.0f, 2.0f, // align
3181 0.0f, 0.0f, 0.0f, 2.0f, // align
3182 3.0f, 0.0f, 0.0f, 3.0f, // layout(row_major) mat4 worldToView;
3183 0.0f, 3.0f, 0.0f, 3.0f, // align
3184 0.0f, 0.0f, 3.0f, 3.0f, // align
3185 0.0f, 0.0f, 0.0f, 3.0f, // align
3186 4.0f, 0.0f, 0.0f, 4.0f, // layout(row_major) mat4 viewToProj;
3187 0.0f, 4.0f, 0.0f, 4.0f, // align
3188 0.0f, 0.0f, 4.0f, 4.0f, // align
3189 0.0f, 0.0f, 0.0f, 4.0f, // align
3190 5.0f, 0.0f, 0.0f, 5.0f, // layout(row_major) mat4 worldToShadow[4];
3191 0.0f, 5.0f, 0.0f, 5.0f, // align
3192 0.0f, 0.0f, 5.0f, 5.0f, // align
3193 0.0f, 0.0f, 0.0f, 5.0f, // align
3194 6.0f, 0.0f, 0.0f, 6.0f, // align
3195 0.0f, 6.0f, 0.0f, 6.0f, // align
3196 0.0f, 0.0f, 6.0f, 6.0f, // align
3197 0.0f, 0.0f, 0.0f, 6.0f, // align
3198 7.0f, 0.0f, 0.0f, 7.0f, // align
3199 0.0f, 7.0f, 0.0f, 7.0f, // align
3200 0.0f, 0.0f, 7.0f, 7.0f, // align
3201 0.0f, 0.0f, 0.0f, 7.0f, // align
3202 8.0f, 0.0f, 0.0f, 8.0f, // align
3203 0.0f, 8.0f, 0.0f, 8.0f, // align
3204 0.0f, 0.0f, 8.0f, 8.0f, // align
3205 0.0f, 0.0f, 0.0f, 8.0f, // align
3206 0.0f, // float fZero; // align
3207 1.0f, // float fOne; // pack
3208 2.0f, // float fTwo; // pack
3209 3.0f, // float fThree; // pack
3210 0.0f, 0.0f, 0.0f, // vec3 fZeroZeroZero; // align
3211 4.0f, // float fFour; // pack
3212 0.0f, 0.0f, 1.0f, // vec3 fZeroZeroOne; // align
3213 5.0f, // float fFive; // pack
3214 0.0f, 1.0f, 0.0f, // vec3 fZeroOneZero; // align
3215 6.0f, // float fSix; // pack
3216 7.0f, // float fSeven; // align
3217 8.0f, // float fEight; // pack
3218 9.0f, // float fNine; // pack
3219 0.0f, // BUFFER
3220 0.0f, 0.0f, // vec2 fZeroZero; // align
3221 0.0f, 1.0f, // vec2 fZeroOne; // pack
3222 0.0f, 0.0f, 1.0f, 1.0f, // vec4 fBlue; // align
3223 1.0f, 0.0f, // vec2 fOneZero; // align
3224 1.0f, 1.0f, // vec2 fOneOne; // pack
3225 0.0f, 1.0f, 1.0f, // vec3 fZeroOneOne; // align
3226 10.0f, // float fTen; // pack
3227 11.0f, // float fEleven; // align
3228 12.0f, // float fTwelve; // pack
3229 0.0f, 0.0f, // BUFFER
3230 1.0f, 0.0f, 0.0f, // vec3 fOneZeroZero; // align
3231 0.0f, // BUFFER
3232 0.1f, 0.2f, 0.3f, 0.4f, // vec4 uvOffsets[4];
3233 0.5f, 0.6f, 0.7f, 0.8f, // align
3234 0.9f, 1.0f, 1.1f, 1.2f, // align
3235 1.3f, 1.4f, 1.5f, 1.6f, // align
Cody Northrop04ad1202014-12-17 15:26:33 -07003236 };
3237
3238 ASSERT_NO_FATAL_FAILURE(InitState());
3239 ASSERT_NO_FATAL_FAILURE(InitViewport());
3240
3241 const int constCount = sizeof(mixedVals) / sizeof(float);
3242
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003243 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
3244 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northrop04ad1202014-12-17 15:26:33 -07003245
Tony Barbour6918cd52015-04-09 12:58:51 -06003246 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop04ad1202014-12-17 15:26:33 -07003247
Tony Barbour6918cd52015-04-09 12:58:51 -06003248 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003249 pipelineobj.AddColorAttachment();
Cody Northrop04ad1202014-12-17 15:26:33 -07003250 pipelineobj.AddShader(&vs);
3251 pipelineobj.AddShader(&ps);
3252
Tony Barbour6918cd52015-04-09 12:58:51 -06003253 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003254 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
Cody Northrop04ad1202014-12-17 15:26:33 -07003255
3256 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003257 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop04ad1202014-12-17 15:26:33 -07003258
Tony Barbourfe3351b2015-07-28 10:17:20 -06003259 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop04ad1202014-12-17 15:26:33 -07003260
3261#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003262 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop04ad1202014-12-17 15:26:33 -07003263 pDSDumpDot((char*)"triTest2.dot");
3264#endif
3265 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003266 Draw(3, 1, 0, 0);
Cody Northrop04ad1202014-12-17 15:26:33 -07003267
3268 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003269 EndCommandBuffer();
3270 QueueCommandBuffer();
Cody Northrop04ad1202014-12-17 15:26:33 -07003271
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06003272 RecordImages(m_renderTargets);
Cody Northrop04ad1202014-12-17 15:26:33 -07003273}
3274
Cody Northrop95638152015-05-07 14:39:12 -06003275TEST_F(VkRenderTest, TextureGather)
3276{
3277 // This test introduces textureGather and textureGatherOffset
3278 // Each call is compared against an expected inline color result
3279 // Green triangle means everything worked as expected
3280 // Red means something went wrong
3281
Cody Northropc55900f2015-08-06 13:18:13 -06003282 // disable SPV until texture gather is turned on in glsl->SPV
3283 if (!m_use_glsl) {
3284 printf("Skipping test that requires GLSL path (TextureGather)\n");
3285 return;
3286 }
3287
Cody Northrop95638152015-05-07 14:39:12 -06003288 static const char *vertShaderText =
3289 "#version 140\n"
3290 "#extension GL_ARB_separate_shader_objects : enable\n"
3291 "#extension GL_ARB_shading_language_420pack : enable\n"
3292 "void main() {\n"
3293 " vec2 vertices[3];"
3294 " vertices[0] = vec2(-0.5, -0.5);\n"
3295 " vertices[1] = vec2( 0.5, -0.5);\n"
3296 " vertices[2] = vec2( 0.5, 0.5);\n"
3297 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
3298 "}\n";
3299
3300 static const char *fragShaderText =
3301 "#version 430\n"
3302 "#extension GL_ARB_separate_shader_objects : enable\n"
3303 "#extension GL_ARB_shading_language_420pack : enable\n"
3304 "layout (binding = 0) uniform sampler2D surface0;\n"
3305 "layout (binding = 1) uniform sampler2D surface1;\n"
3306 "layout (binding = 2) uniform sampler2D surface2;\n"
3307 "layout (binding = 3) uniform sampler2D surface3;\n"
3308 "layout (location = 0) out vec4 outColor;\n"
3309 "void main() {\n"
3310
3311 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3312 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3313
3314 " vec4 color = right;\n"
3315
3316 // Grab a normal texture sample to ensure it can work in conjuntion
3317 // with textureGather (there are some intracacies in the backend)
3318 " vec4 sampledColor = textureLod(surface2, vec2(0.5), 0.0);\n"
3319 " if (sampledColor != vec4(0.0, 0.0, 1.0, 1.0))\n"
3320 " color = wrong;\n"
3321
3322 " vec4 gatheredColor = textureGather(surface0, vec2(0.5), 0);\n"
3323 // This just grabbed four red components from a red surface
3324 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3325 " color = wrong;\n"
3326
3327 // Yes, this is using an offset of 0, we don't have enough fine grained
3328 // control of the texture contents here.
3329 " gatheredColor = textureGatherOffset(surface1, vec2(0.5), ivec2(0, 0), 1);\n"
3330 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3331 " color = wrong;\n"
3332
3333 " outColor = color;\n"
3334
3335 "}\n";
3336
3337 ASSERT_NO_FATAL_FAILURE(InitState());
3338 ASSERT_NO_FATAL_FAILURE(InitViewport());
3339
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003340 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
3341 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northrop95638152015-05-07 14:39:12 -06003342
3343 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
3344 VkSamplerObj sampler0(m_device);
3345 VkTextureObj texture0(m_device, tex_colors); // Red
3346 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
3347 VkSamplerObj sampler1(m_device);
3348 VkTextureObj texture1(m_device, tex_colors); // Green
3349 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
3350 VkSamplerObj sampler2(m_device);
3351 VkTextureObj texture2(m_device, tex_colors); // Blue
3352 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
3353 VkSamplerObj sampler3(m_device);
3354 VkTextureObj texture3(m_device, tex_colors); // Red and Blue
3355
3356 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003357 pipelineobj.AddColorAttachment();
Cody Northrop95638152015-05-07 14:39:12 -06003358 pipelineobj.AddShader(&vs);
3359 pipelineobj.AddShader(&ps);
3360
3361 VkDescriptorSetObj descriptorSet(m_device);
3362 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3363 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
3364 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3365 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
3366
3367 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003368 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop95638152015-05-07 14:39:12 -06003369
Tony Barbourfe3351b2015-07-28 10:17:20 -06003370 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop95638152015-05-07 14:39:12 -06003371
3372 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003373 Draw(3, 1, 0, 0);
Cody Northrop95638152015-05-07 14:39:12 -06003374
3375 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003376 EndCommandBuffer();
3377 QueueCommandBuffer();
Cody Northrop95638152015-05-07 14:39:12 -06003378
3379 RecordImages(m_renderTargets);
Cody Northrop95638152015-05-07 14:39:12 -06003380}
3381
Cody Northrop475663c2015-04-15 11:19:06 -06003382TEST_F(VkRenderTest, GeometryShaderHelloWorld)
3383{
3384 // This test introduces a geometry shader that simply
3385 // changes the color of each vertex to red, green, blue
3386
3387 static const char *vertShaderText =
3388 "#version 140\n"
3389 "#extension GL_ARB_separate_shader_objects : enable\n"
3390 "#extension GL_ARB_shading_language_420pack : enable\n"
3391 "layout (location = 0) out vec4 color;"
3392 "void main() {\n"
3393
3394 // VS writes out red
3395 " color = vec4(1.0, 0.0, 0.0, 1.0);\n"
3396
3397 // generic position stuff
3398 " vec2 vertices;\n"
3399 " int vertexSelector = gl_VertexID;\n"
3400 " if (vertexSelector == 0)\n"
3401 " vertices = vec2(-0.5, -0.5);\n"
3402 " else if (vertexSelector == 1)\n"
3403 " vertices = vec2( 0.5, -0.5);\n"
3404 " else if (vertexSelector == 2)\n"
3405 " vertices = vec2( 0.5, 0.5);\n"
3406 " else\n"
3407 " vertices = vec2( 0.0, 0.0);\n"
3408 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3409
3410 "}\n";
3411
3412 static const char *geomShaderText =
3413 "#version 330\n"
3414 "#extension GL_ARB_separate_shader_objects : enable\n"
3415 "#extension GL_ARB_shading_language_420pack : enable\n"
3416 "layout( triangles ) in;\n"
3417 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3418 "layout( location = 0 ) in vec4 inColor[3];\n"
3419 "layout( location = 0 ) out vec4 outColor;\n"
3420 "void main()\n"
3421 "{\n"
3422
3423 // first vertex, pass through red
3424 " gl_Position = gl_in[0].gl_Position;\n"
3425 " outColor = inColor[0];\n"
3426 " EmitVertex();\n"
3427
3428 // second vertex, green
3429 " gl_Position = gl_in[1].gl_Position;\n"
3430 " outColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3431 " EmitVertex();\n"
3432
3433 // third vertex, blue
3434 " gl_Position = gl_in[2].gl_Position;\n"
3435 " outColor = vec4(0.0, 0.0, 1.0, 1.0);\n"
3436 " EmitVertex();\n"
3437
3438 // done
3439 " EndPrimitive();\n"
3440 "}\n";
3441
3442
3443 static const char *fragShaderText =
3444 "#version 140\n"
3445 "#extension GL_ARB_separate_shader_objects : enable\n"
3446 "#extension GL_ARB_shading_language_420pack : enable\n"
3447 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06003448 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003449 "void main() {\n"
3450 // pass through
GregFaae75242015-06-03 18:40:50 -06003451 " outColor = color;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003452 "}\n";
3453
3454
3455
3456 ASSERT_NO_FATAL_FAILURE(InitState());
3457 ASSERT_NO_FATAL_FAILURE(InitViewport());
3458
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003459 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3460 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY_BIT, this);
3461 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northrop475663c2015-04-15 11:19:06 -06003462
3463 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003464 pipelineobj.AddColorAttachment();
Cody Northrop475663c2015-04-15 11:19:06 -06003465 pipelineobj.AddShader(&vs);
3466 pipelineobj.AddShader(&gs);
3467 pipelineobj.AddShader(&ps);
3468
3469 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003470 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop475663c2015-04-15 11:19:06 -06003471
3472 VkDescriptorSetObj descriptorSet(m_device);
3473
Tony Barbourfe3351b2015-07-28 10:17:20 -06003474 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop475663c2015-04-15 11:19:06 -06003475
3476 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003477 Draw(3, 1, 0, 0);
Cody Northrop475663c2015-04-15 11:19:06 -06003478
3479 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003480 EndCommandBuffer();
3481 QueueCommandBuffer();
Cody Northrop475663c2015-04-15 11:19:06 -06003482
3483 RecordImages(m_renderTargets);
3484}
3485
3486TEST_F(VkRenderTest, GSUniformBufferLayout)
3487{
3488 // This test is just like TriangleUniformBufferLayout but adds
3489 // geometry as a stage that also does UBO lookups
3490 // The expected result from this test is a green triangle
3491
3492 static const char *vertShaderText =
3493 "#version 140\n"
3494 "#extension GL_ARB_separate_shader_objects : enable\n"
3495 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06003496 "layout (std140, binding = 0) uniform mixedBuffer {\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003497 " vec4 fRed;\n"
3498 " vec4 fGreen;\n"
3499 " layout(row_major) mat4 worldToProj;\n"
3500 " layout(row_major) mat4 projToWorld;\n"
3501 " layout(row_major) mat4 worldToView;\n"
3502 " layout(row_major) mat4 viewToProj;\n"
3503 " layout(row_major) mat4 worldToShadow[4];\n"
3504 " float fZero;\n"
3505 " float fOne;\n"
3506 " float fTwo;\n"
3507 " float fThree;\n"
3508 " vec3 fZeroZeroZero;\n"
3509 " float fFour;\n"
3510 " vec3 fZeroZeroOne;\n"
3511 " float fFive;\n"
3512 " vec3 fZeroOneZero;\n"
3513 " float fSix;\n"
3514 " float fSeven;\n"
3515 " float fEight;\n"
3516 " float fNine;\n"
3517 " vec2 fZeroZero;\n"
3518 " vec2 fZeroOne;\n"
3519 " vec4 fBlue;\n"
3520 " vec2 fOneZero;\n"
3521 " vec2 fOneOne;\n"
3522 " vec3 fZeroOneOne;\n"
3523 " float fTen;\n"
3524 " float fEleven;\n"
3525 " float fTwelve;\n"
3526 " vec3 fOneZeroZero;\n"
3527 " vec4 uvOffsets[4];\n"
3528 "};\n"
3529 "layout (location = 0) out vec4 color;"
3530 "void main() {\n"
3531
3532 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3533 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3534 " \n"
3535
3536 // do some exact comparisons, even though we should
3537 // really have an epsilon involved.
3538 " vec4 outColor = right;\n"
3539 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3540 " outColor = wrong;\n"
3541 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3542 " outColor = wrong;\n"
3543 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3544 " outColor = wrong;\n"
3545
3546 " color = outColor;\n"
3547
3548 // generic position stuff
3549 " vec2 vertices;\n"
3550 " int vertexSelector = gl_VertexID;\n"
3551 " if (vertexSelector == 0)\n"
3552 " vertices = vec2(-0.5, -0.5);\n"
3553 " else if (vertexSelector == 1)\n"
3554 " vertices = vec2( 0.5, -0.5);\n"
3555 " else if (vertexSelector == 2)\n"
3556 " vertices = vec2( 0.5, 0.5);\n"
3557 " else\n"
3558 " vertices = vec2( 0.0, 0.0);\n"
3559 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3560 "}\n";
3561
3562 static const char *geomShaderText =
3563 "#version 330\n"
3564 "#extension GL_ARB_separate_shader_objects : enable\n"
3565 "#extension GL_ARB_shading_language_420pack : enable\n"
3566
3567 // GS layout stuff
3568 "layout( triangles ) in;\n"
3569 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3570
3571 // Between stage IO
3572 "layout( location = 0 ) in vec4 inColor[3];\n"
3573 "layout( location = 0 ) out vec4 color;\n"
3574
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06003575 "layout (std140, binding = 0) uniform mixedBuffer {\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003576 " vec4 fRed;\n"
3577 " vec4 fGreen;\n"
3578 " layout(row_major) mat4 worldToProj;\n"
3579 " layout(row_major) mat4 projToWorld;\n"
3580 " layout(row_major) mat4 worldToView;\n"
3581 " layout(row_major) mat4 viewToProj;\n"
3582 " layout(row_major) mat4 worldToShadow[4];\n"
3583 " float fZero;\n"
3584 " float fOne;\n"
3585 " float fTwo;\n"
3586 " float fThree;\n"
3587 " vec3 fZeroZeroZero;\n"
3588 " float fFour;\n"
3589 " vec3 fZeroZeroOne;\n"
3590 " float fFive;\n"
3591 " vec3 fZeroOneZero;\n"
3592 " float fSix;\n"
3593 " float fSeven;\n"
3594 " float fEight;\n"
3595 " float fNine;\n"
3596 " vec2 fZeroZero;\n"
3597 " vec2 fZeroOne;\n"
3598 " vec4 fBlue;\n"
3599 " vec2 fOneZero;\n"
3600 " vec2 fOneOne;\n"
3601 " vec3 fZeroOneOne;\n"
3602 " float fTen;\n"
3603 " float fEleven;\n"
3604 " float fTwelve;\n"
3605 " vec3 fOneZeroZero;\n"
3606 " vec4 uvOffsets[4];\n"
3607 "};\n"
3608
3609 "void main()\n"
3610 "{\n"
3611
3612 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3613 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3614
3615 // Each vertex will validate it can read VS output
3616 // then check a few values from the UBO
3617
3618 // first vertex
3619 " vec4 outColor = inColor[0];\n"
3620
3621 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3622 " outColor = wrong;\n"
3623 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3624 " outColor = wrong;\n"
3625 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3626 " outColor = wrong;\n"
3627 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3628 " outColor = wrong;\n"
3629
3630 " gl_Position = gl_in[0].gl_Position;\n"
3631 " color = outColor;\n"
3632 " EmitVertex();\n"
3633
3634 // second vertex
3635 " outColor = inColor[1];\n"
3636
3637 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3638 " outColor = wrong;\n"
3639 " if (fSix != 6.0)\n"
3640 " outColor = wrong;\n"
3641 " if (fOneOne != vec2(1.0, 1.0))\n"
3642 " outColor = wrong;\n"
3643
3644 " gl_Position = gl_in[1].gl_Position;\n"
3645 " color = outColor;\n"
3646 " EmitVertex();\n"
3647
3648 // third vertex
3649 " outColor = inColor[2];\n"
3650
3651 " if (fSeven != 7.0)\n"
3652 " outColor = wrong;\n"
3653 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3654 " outColor = wrong;\n"
3655
3656 " gl_Position = gl_in[2].gl_Position;\n"
3657 " color = outColor;\n"
3658 " EmitVertex();\n"
3659
3660 // done
3661 " EndPrimitive();\n"
3662 "}\n";
3663
3664 static const char *fragShaderText =
3665 "#version 140\n"
3666 "#extension GL_ARB_separate_shader_objects : enable\n"
3667 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06003668 "layout (std140, binding = 0) uniform mixedBuffer {\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003669 " vec4 fRed;\n"
3670 " vec4 fGreen;\n"
3671 " layout(row_major) mat4 worldToProj;\n"
3672 " layout(row_major) mat4 projToWorld;\n"
3673 " layout(row_major) mat4 worldToView;\n"
3674 " layout(row_major) mat4 viewToProj;\n"
3675 " layout(row_major) mat4 worldToShadow[4];\n"
3676 " float fZero;\n"
3677 " float fOne;\n"
3678 " float fTwo;\n"
3679 " float fThree;\n"
3680 " vec3 fZeroZeroZero;\n"
3681 " float fFour;\n"
3682 " vec3 fZeroZeroOne;\n"
3683 " float fFive;\n"
3684 " vec3 fZeroOneZero;\n"
3685 " float fSix;\n"
3686 " float fSeven;\n"
3687 " float fEight;\n"
3688 " float fNine;\n"
3689 " vec2 fZeroZero;\n"
3690 " vec2 fZeroOne;\n"
3691 " vec4 fBlue;\n"
3692 " vec2 fOneZero;\n"
3693 " vec2 fOneOne;\n"
3694 " vec3 fZeroOneOne;\n"
3695 " float fTen;\n"
3696 " float fEleven;\n"
3697 " float fTwelve;\n"
3698 " vec3 fOneZeroZero;\n"
3699 " vec4 uvOffsets[4];\n"
3700 "};\n"
3701 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06003702 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003703 "void main() {\n"
3704 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3705 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3706 " \n"
3707
3708 // start with GS value to ensure it passed
3709 " vec4 outColor = color;\n"
3710
3711 // do some exact comparisons, even though we should
3712 // really have an epsilon involved.
3713 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3714 " outColor = wrong;\n"
3715 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3716 " outColor = wrong;\n"
3717 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3718 " outColor = wrong;\n"
3719 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3720 " outColor = wrong;\n"
3721 " if (fTwo != 2.0)\n"
3722 " outColor = wrong;\n"
3723 " if (fOneOne != vec2(1.0, 1.0))\n"
3724 " outColor = wrong;\n"
3725 " if (fTen != 10.0)\n"
3726 " outColor = wrong;\n"
3727 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3728 " outColor = wrong;\n"
3729 " \n"
GregFaae75242015-06-03 18:40:50 -06003730 " uFragColor = outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003731 "}\n";
3732
3733
Cody Northropd2ad0342015-08-05 11:15:02 -06003734 const float mixedVals[196] = { 1.0f, 0.0f, 0.0f, 1.0f, // vec4 fRed; // align
3735 0.0f, 1.0f, 0.0f, 1.0f, // vec4 fGreen; // align
3736 1.0f, 0.0f, 0.0f, 1.0f, // layout(row_major) mat4 worldToProj;
3737 0.0f, 1.0f, 0.0f, 1.0f, // align
3738 0.0f, 0.0f, 1.0f, 1.0f, // align
3739 0.0f, 0.0f, 0.0f, 1.0f, // align
3740 2.0f, 0.0f, 0.0f, 2.0f, // layout(row_major) mat4 projToWorld;
3741 0.0f, 2.0f, 0.0f, 2.0f, // align
3742 0.0f, 0.0f, 2.0f, 2.0f, // align
3743 0.0f, 0.0f, 0.0f, 2.0f, // align
3744 3.0f, 0.0f, 0.0f, 3.0f, // layout(row_major) mat4 worldToView;
3745 0.0f, 3.0f, 0.0f, 3.0f, // align
3746 0.0f, 0.0f, 3.0f, 3.0f, // align
3747 0.0f, 0.0f, 0.0f, 3.0f, // align
3748 4.0f, 0.0f, 0.0f, 4.0f, // layout(row_major) mat4 viewToProj;
3749 0.0f, 4.0f, 0.0f, 4.0f, // align
3750 0.0f, 0.0f, 4.0f, 4.0f, // align
3751 0.0f, 0.0f, 0.0f, 4.0f, // align
3752 5.0f, 0.0f, 0.0f, 5.0f, // layout(row_major) mat4 worldToShadow[4];
3753 0.0f, 5.0f, 0.0f, 5.0f, // align
3754 0.0f, 0.0f, 5.0f, 5.0f, // align
3755 0.0f, 0.0f, 0.0f, 5.0f, // align
3756 6.0f, 0.0f, 0.0f, 6.0f, // align
3757 0.0f, 6.0f, 0.0f, 6.0f, // align
3758 0.0f, 0.0f, 6.0f, 6.0f, // align
3759 0.0f, 0.0f, 0.0f, 6.0f, // align
3760 7.0f, 0.0f, 0.0f, 7.0f, // align
3761 0.0f, 7.0f, 0.0f, 7.0f, // align
3762 0.0f, 0.0f, 7.0f, 7.0f, // align
3763 0.0f, 0.0f, 0.0f, 7.0f, // align
3764 8.0f, 0.0f, 0.0f, 8.0f, // align
3765 0.0f, 8.0f, 0.0f, 8.0f, // align
3766 0.0f, 0.0f, 8.0f, 8.0f, // align
3767 0.0f, 0.0f, 0.0f, 8.0f, // align
3768 0.0f, // float fZero; // align
3769 1.0f, // float fOne; // pack
3770 2.0f, // float fTwo; // pack
3771 3.0f, // float fThree; // pack
3772 0.0f, 0.0f, 0.0f, // vec3 fZeroZeroZero; // align
3773 4.0f, // float fFour; // pack
3774 0.0f, 0.0f, 1.0f, // vec3 fZeroZeroOne; // align
3775 5.0f, // float fFive; // pack
3776 0.0f, 1.0f, 0.0f, // vec3 fZeroOneZero; // align
3777 6.0f, // float fSix; // pack
3778 7.0f, // float fSeven; // align
3779 8.0f, // float fEight; // pack
3780 9.0f, // float fNine; // pack
3781 0.0f, // BUFFER
3782 0.0f, 0.0f, // vec2 fZeroZero; // align
3783 0.0f, 1.0f, // vec2 fZeroOne; // pack
3784 0.0f, 0.0f, 1.0f, 1.0f, // vec4 fBlue; // align
3785 1.0f, 0.0f, // vec2 fOneZero; // align
3786 1.0f, 1.0f, // vec2 fOneOne; // pack
3787 0.0f, 1.0f, 1.0f, // vec3 fZeroOneOne; // align
3788 10.0f, // float fTen; // pack
3789 11.0f, // float fEleven; // align
3790 12.0f, // float fTwelve; // pack
3791 0.0f, 0.0f, // BUFFER
3792 1.0f, 0.0f, 0.0f, // vec3 fOneZeroZero; // align
3793 0.0f, // BUFFER
3794 0.1f, 0.2f, 0.3f, 0.4f, // vec4 uvOffsets[4];
3795 0.5f, 0.6f, 0.7f, 0.8f, // align
3796 0.9f, 1.0f, 1.1f, 1.2f, // align
3797 1.3f, 1.4f, 1.5f, 1.6f, // align
Cody Northrop475663c2015-04-15 11:19:06 -06003798 };
3799
3800
3801
3802 ASSERT_NO_FATAL_FAILURE(InitState());
3803 ASSERT_NO_FATAL_FAILURE(InitViewport());
3804
3805 const int constCount = sizeof(mixedVals) / sizeof(float);
3806
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003807 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3808 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY_BIT, this);
3809 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northrop475663c2015-04-15 11:19:06 -06003810
3811 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
3812
3813 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003814 pipelineobj.AddColorAttachment();
Cody Northrop475663c2015-04-15 11:19:06 -06003815 pipelineobj.AddShader(&vs);
3816 pipelineobj.AddShader(&gs);
3817 pipelineobj.AddShader(&ps);
3818
3819 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003820 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop475663c2015-04-15 11:19:06 -06003821
3822 VkDescriptorSetObj descriptorSet(m_device);
3823 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
3824
Tony Barbourfe3351b2015-07-28 10:17:20 -06003825 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop475663c2015-04-15 11:19:06 -06003826
3827 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003828 Draw(3, 1, 0, 0);
Cody Northrop475663c2015-04-15 11:19:06 -06003829
3830 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003831 EndCommandBuffer();
3832 QueueCommandBuffer();
Cody Northrop475663c2015-04-15 11:19:06 -06003833
3834 RecordImages(m_renderTargets);
3835}
3836
3837TEST_F(VkRenderTest, GSPositions)
3838{
3839 // This test adds more inputs from the vertex shader and perturbs positions
3840 // Expected result is white triangle with weird positions
3841
3842 static const char *vertShaderText =
3843 "#version 140\n"
3844 "#extension GL_ARB_separate_shader_objects : enable\n"
3845 "#extension GL_ARB_shading_language_420pack : enable\n"
3846
3847 "layout(location = 0) out vec3 out_a;\n"
3848 "layout(location = 1) out vec3 out_b;\n"
3849 "layout(location = 2) out vec3 out_c;\n"
3850
3851 "void main() {\n"
3852
3853 // write a solid color to each
3854 " out_a = vec3(1.0, 0.0, 0.0);\n"
3855 " out_b = vec3(0.0, 1.0, 0.0);\n"
3856 " out_c = vec3(0.0, 0.0, 1.0);\n"
3857
3858 // generic position stuff
3859 " vec2 vertices;\n"
3860 " int vertexSelector = gl_VertexID;\n"
3861 " if (vertexSelector == 0)\n"
3862 " vertices = vec2(-0.5, -0.5);\n"
3863 " else if (vertexSelector == 1)\n"
3864 " vertices = vec2( 0.5, -0.5);\n"
3865 " else if (vertexSelector == 2)\n"
3866 " vertices = vec2( 0.5, 0.5);\n"
3867 " else\n"
3868 " vertices = vec2( 0.0, 0.0);\n"
3869 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3870
3871 "}\n";
3872
3873 static const char *geomShaderText =
3874 "#version 330\n"
3875 "#extension GL_ARB_separate_shader_objects : enable\n"
3876 "#extension GL_ARB_shading_language_420pack : enable\n"
3877 "layout( triangles ) in;\n"
3878 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3879
3880 "layout(location = 0) in vec3 in_a[3];\n"
3881 "layout(location = 1) in vec3 in_b[3];\n"
3882 "layout(location = 2) in vec3 in_c[3];\n"
3883
3884 "layout(location = 0) out vec3 out_a;\n"
3885 "layout(location = 1) out vec3 out_b;\n"
3886 "layout(location = 2) out vec3 out_c;\n"
3887
3888 "void main()\n"
3889 "{\n"
3890
3891 " gl_Position = gl_in[0].gl_Position;\n"
3892 " gl_Position.xy *= vec2(0.75);\n"
3893 " out_a = in_a[0];\n"
3894 " out_b = in_b[0];\n"
3895 " out_c = in_c[0];\n"
3896 " EmitVertex();\n"
3897
3898 " gl_Position = gl_in[1].gl_Position;\n"
3899 " gl_Position.xy *= vec2(1.5);\n"
3900 " out_a = in_a[1];\n"
3901 " out_b = in_b[1];\n"
3902 " out_c = in_c[1];\n"
3903 " EmitVertex();\n"
3904
3905 " gl_Position = gl_in[2].gl_Position;\n"
3906 " gl_Position.xy *= vec2(-0.1);\n"
3907 " out_a = in_a[2];\n"
3908 " out_b = in_b[2];\n"
3909 " out_c = in_c[2];\n"
3910 " EmitVertex();\n"
3911
3912 " EndPrimitive();\n"
3913 "}\n";
3914
3915
3916 static const char *fragShaderText =
3917 "#version 140\n"
3918 "#extension GL_ARB_separate_shader_objects : enable\n"
3919 "#extension GL_ARB_shading_language_420pack : enable\n"
3920
3921 "layout(location = 0) in vec3 in_a;\n"
3922 "layout(location = 1) in vec3 in_b;\n"
3923 "layout(location = 2) in vec3 in_c;\n"
GregFaae75242015-06-03 18:40:50 -06003924 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003925
3926 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06003927 " outColor = vec4(in_a.x, in_b.y, in_c.z, 1.0);\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003928 "}\n";
3929
3930
3931
3932 ASSERT_NO_FATAL_FAILURE(InitState());
3933 ASSERT_NO_FATAL_FAILURE(InitViewport());
3934
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003935 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3936 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY_BIT, this);
3937 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northrop475663c2015-04-15 11:19:06 -06003938
3939 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003940 pipelineobj.AddColorAttachment();
Cody Northrop475663c2015-04-15 11:19:06 -06003941 pipelineobj.AddShader(&vs);
3942 pipelineobj.AddShader(&gs);
3943 pipelineobj.AddShader(&ps);
3944
3945 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003946 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop475663c2015-04-15 11:19:06 -06003947
3948 VkDescriptorSetObj descriptorSet(m_device);
3949
Tony Barbourfe3351b2015-07-28 10:17:20 -06003950 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop475663c2015-04-15 11:19:06 -06003951
3952 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003953 Draw(3, 1, 0, 0);
Cody Northrop475663c2015-04-15 11:19:06 -06003954
3955 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003956 EndCommandBuffer();
3957 QueueCommandBuffer();
Cody Northrop475663c2015-04-15 11:19:06 -06003958
3959 RecordImages(m_renderTargets);
3960}
3961
3962TEST_F(VkRenderTest, GSTriStrip)
3963{
3964 // This test emits multiple multiple triangles using a GS
3965 // Correct result is an multicolor circle
3966
3967 static const char *vertShaderText =
3968 "#version 140\n"
3969 "#extension GL_ARB_separate_shader_objects : enable\n"
3970 "#extension GL_ARB_shading_language_420pack : enable\n"
3971
3972 "void main() {\n"
3973
3974 // generic position stuff
3975 " vec2 vertices;\n"
3976 " int vertexSelector = gl_VertexID;\n"
3977 " if (vertexSelector == 0)\n"
3978 " vertices = vec2(-0.5, -0.5);\n"
3979 " else if (vertexSelector == 1)\n"
3980 " vertices = vec2( 0.5, -0.5);\n"
3981 " else if (vertexSelector == 2)\n"
3982 " vertices = vec2( 0.5, 0.5);\n"
3983 " else\n"
3984 " vertices = vec2( 0.0, 0.0);\n"
3985 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3986
3987 "}\n";
3988
3989 static const char *geomShaderText =
3990 "#version 330\n"
3991 "#extension GL_ARB_separate_shader_objects : enable\n"
3992 "#extension GL_ARB_shading_language_420pack : enable\n"
3993 "layout( triangles ) in;\n"
3994 "layout( triangle_strip, max_vertices = 18 ) out;\n"
3995
3996 "layout(location = 0) out vec4 outColor;\n"
3997
3998 "void main()\n"
3999 "{\n"
4000 // init with first position to get zw
4001 " gl_Position = gl_in[0].gl_Position;\n"
4002
4003 " vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
4004 " vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
4005 " vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
4006 " vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
4007
4008 // different color per tri
4009 " vec4[6] colors = { red, white, \n"
4010 " yellow, white, \n"
4011 " blue, white }; \n"
4012
4013 // fan out the triangles
4014 " vec2[18] positions = { vec2(0.0, 0.0), vec2(-0.5, 0.0), vec2(-0.25, -0.5), \n"
4015 " vec2(0.0, 0.0), vec2(-0.25, -0.5), vec2( 0.25, -0.5), \n"
4016 " vec2(0.0, 0.0), vec2( 0.25, -0.5), vec2( 0.5, 0.0), \n"
4017 " vec2(0.0, 0.0), vec2( 0.5, 0.0), vec2( 0.25, 0.5), \n"
4018 " vec2(0.0, 0.0), vec2( 0.25, 0.5), vec2(-0.25, 0.5), \n"
4019 " vec2(0.0, 0.0), vec2(-0.25, 0.5), vec2(-0.5, 0.0) }; \n"
4020
4021 // make a triangle list of 6
4022 " for (int i = 0; i < 6; ++i) { \n"
4023 " outColor = colors[i]; \n"
4024 " for (int j = 0; j < 3; ++j) { \n"
4025 " gl_Position.xy = positions[i * 3 + j]; \n"
4026 " EmitVertex(); \n"
4027 " } \n"
4028 " EndPrimitive();\n"
4029 " } \n"
4030
4031 "}\n";
4032
4033
4034 static const char *fragShaderText =
4035 "#version 150\n"
4036 "#extension GL_ARB_separate_shader_objects : enable\n"
4037 "#extension GL_ARB_shading_language_420pack : enable\n"
4038
4039
4040 "layout(binding = 0) uniform windowDimensions {\n"
4041 " vec4 dimensions;\n"
4042 "};\n"
4043
4044 "layout(location = 0) in vec4 inColor;\n"
4045 "layout(origin_upper_left) in vec4 gl_FragCoord;\n"
GregFaae75242015-06-03 18:40:50 -06004046 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06004047
4048 "void main() {\n"
4049
4050 // discard to make a nice circle
4051 " vec2 pos = abs(gl_FragCoord.xy) - vec2(dimensions.x, dimensions.y) / 2;\n"
4052 " float dist = sqrt(dot(pos, pos));\n"
4053 " if (dist > 50.0)\n"
4054 " discard;\n"
4055
GregFaae75242015-06-03 18:40:50 -06004056 " outColor = inColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06004057
4058 "}\n";
4059
4060
4061
4062 ASSERT_NO_FATAL_FAILURE(InitState());
4063 ASSERT_NO_FATAL_FAILURE(InitViewport());
4064
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004065 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4066 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY_BIT, this);
4067 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northrop475663c2015-04-15 11:19:06 -06004068
4069 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004070 pipelineobj.AddColorAttachment();
Cody Northrop475663c2015-04-15 11:19:06 -06004071 pipelineobj.AddShader(&vs);
4072 pipelineobj.AddShader(&gs);
4073 pipelineobj.AddShader(&ps);
4074
4075 const float dimensions[4] = { VkRenderFramework::m_width, VkRenderFramework::m_height , 0.0, 0.0};
4076
4077 VkConstantBufferObj windowDimensions(m_device, sizeof(dimensions) / sizeof(dimensions[0]), sizeof(dimensions[0]), (const void*) dimensions);
4078
4079 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004080 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop475663c2015-04-15 11:19:06 -06004081
4082 VkDescriptorSetObj descriptorSet(m_device);
4083 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, windowDimensions);
4084
Tony Barbourfe3351b2015-07-28 10:17:20 -06004085 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop475663c2015-04-15 11:19:06 -06004086
4087 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06004088 Draw(3, 1, 0, 0);
Cody Northrop475663c2015-04-15 11:19:06 -06004089
4090 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06004091 EndCommandBuffer();
4092 QueueCommandBuffer();
Cody Northrop475663c2015-04-15 11:19:06 -06004093
4094 RecordImages(m_renderTargets);
4095}
4096
Chris Forbese182fe02015-06-15 09:32:35 +12004097TEST_F(VkRenderTest, RenderPassLoadOpClear)
4098{
4099 ASSERT_NO_FATAL_FAILURE(InitState());
4100 ASSERT_NO_FATAL_FAILURE(InitViewport());
4101
4102 /* clear via load op to full green */
4103 m_clear_via_load_op = true;
Cody Northrop85789d52015-08-25 15:26:38 -06004104 m_clear_color.float32[0] = 0;
4105 m_clear_color.float32[1] = 1;
4106 m_clear_color.float32[2] = 0;
4107 m_clear_color.float32[3] = 0;
Chris Forbese182fe02015-06-15 09:32:35 +12004108 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004109 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Chris Forbese182fe02015-06-15 09:32:35 +12004110 /* This command buffer contains ONLY the load op! */
Tony Barbourfe3351b2015-07-28 10:17:20 -06004111 EndCommandBuffer();
4112 QueueCommandBuffer();
Chris Forbese182fe02015-06-15 09:32:35 +12004113
4114 RecordImages(m_renderTargets);
4115}
4116
Chris Forbesfa27b952015-06-24 12:05:30 +12004117TEST_F(VkRenderTest, RenderPassAttachmentClear)
4118{
4119 ASSERT_NO_FATAL_FAILURE(InitState());
4120 ASSERT_NO_FATAL_FAILURE(InitViewport());
4121
4122 /* clear via load op to full red */
4123 m_clear_via_load_op = true;
Cody Northrop85789d52015-08-25 15:26:38 -06004124 m_clear_color.float32[0] = 1;
4125 m_clear_color.float32[1] = 0;
4126 m_clear_color.float32[2] = 0;
4127 m_clear_color.float32[3] = 0;
Chris Forbesfa27b952015-06-24 12:05:30 +12004128 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004129 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Chris Forbesfa27b952015-06-24 12:05:30 +12004130
4131 /* Load op has cleared to red */
4132
4133 /* Draw, draw, draw... */
4134
4135 /* Now, partway through this renderpass we want to clear the color
4136 * attachment again, this time to green.
4137 */
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004138 VkClearAttachment color_attachment;
4139 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4140 color_attachment.clearValue.color.float32[0] = 0;
4141 color_attachment.clearValue.color.float32[1] = 1;
4142 color_attachment.clearValue.color.float32[2] = 0;
4143 color_attachment.clearValue.color.float32[3] = 0;
4144 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004145 VkClearRect clear_rect = { { { 0, 0 }, { (int)m_width, (int)m_height } } };
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004146 vkCmdClearAttachments(m_commandBuffer->handle(), 1, &color_attachment,
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004147 1, &clear_rect);
Chris Forbesfa27b952015-06-24 12:05:30 +12004148
Tony Barbourfe3351b2015-07-28 10:17:20 -06004149 EndCommandBuffer();
4150 QueueCommandBuffer();
Chris Forbesfa27b952015-06-24 12:05:30 +12004151
4152 RecordImages(m_renderTargets);
4153}
4154
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06004155int main(int argc, char **argv) {
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004156 int result;
4157
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06004158 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -06004159 VkTestFramework::InitArgs(&argc, argv);
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004160
Chia-I Wu6f184292014-12-15 23:57:34 +08004161 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchtera0f74c52014-10-08 08:46:51 -06004162
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004163 result = RUN_ALL_TESTS();
4164
Tony Barbour6918cd52015-04-09 12:58:51 -06004165 VkTestFramework::Finish();
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004166 return result;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06004167}