blob: 24fe4cabbe1d39ea62cc089c293c919de7c7d81e [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.
51
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060052// Basic rendering tests
53
54#include <stdlib.h>
55#include <stdio.h>
56#include <stdbool.h>
57#include <string.h>
Courtney Goeltzenleuchterda91b952014-08-21 17:34:22 -060058#include <iostream>
59#include <fstream>
60using namespace std;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060061
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060062#include <vulkan.h>
Tobin Ehlis11e52132014-11-28 11:17:19 -070063#ifdef DUMP_STATE_DOT
64#include "../layers/draw_state.h"
65#endif
Tobin Ehlisca915872014-11-18 11:28:33 -070066#ifdef PRINT_OBJECTS
67#include "../layers/object_track.h"
68#endif
Tobin Ehlis6663f492014-11-10 12:29:12 -070069#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060070#include <vk_debug_report_lunarg.h>
Tobin Ehlis6663f492014-11-10 12:29:12 -070071#endif
Courtney Goeltzenleuchter58f3eff2015-10-07 13:28:58 -060072#include "test_common.h"
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060073
Cody Northrop054a4702015-03-17 14:54:35 -060074#include "icd-spv.h"
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060075
Courtney Goeltzenleuchterfdcfb9f2014-10-10 18:04:39 -060076#define GLM_FORCE_RADIANS
77#include "glm/glm.hpp"
78#include <glm/gtc/matrix_transform.hpp>
79
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060080#include "vkrenderframework.h"
Tobin Ehlis6663f492014-11-10 12:29:12 -070081#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060082void VKAPI myDbgFunc(
83 VK_DBG_MSG_TYPE msgType,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060084 VkValidationLevel validationLevel,
Mike Stroyanb050c682015-04-17 12:36:38 -060085 VkObject srcObject,
Mark Lobodzinski17caf572015-01-29 08:55:56 -060086 size_t location,
87 int32_t msgCode,
88 const char* pMsg,
89 void* pUserData)
Tobin Ehlis6663f492014-11-10 12:29:12 -070090{
Tobin Ehlisca915872014-11-18 11:28:33 -070091 switch (msgType)
92 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060093 case VK_DBG_MSG_WARNING:
Tobin Ehlisca915872014-11-18 11:28:33 -070094 printf("CALLBACK WARNING : %s\n", pMsg);
95 break;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060096 case VK_DBG_REPORT_ERROR_BIT:
Tobin Ehlisca915872014-11-18 11:28:33 -070097 printf("CALLBACK ERROR : %s\n", pMsg);
98 break;
99 default:
100 printf("EATING Msg of type %u\n", msgType);
101 break;
102 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700103}
104#endif
Tony Barboure2c58df2014-11-25 13:18:32 -0700105
106
107#undef ASSERT_NO_FATAL_FAILURE
108#define ASSERT_NO_FATAL_FAILURE(x) x
109
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600110//--------------------------------------------------------------------------------------
111// Mesh and VertexFormat Data
112//--------------------------------------------------------------------------------------
113struct Vertex
114{
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600115 float posX, posY, posZ, posW; // Position data
116 float r, g, b, a; // Color
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600117};
118
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600119struct VertexUV
120{
121 float posX, posY, posZ, posW; // Position data
122 float u, v; // texture u,v
123};
124
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600125#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600126#define UV(_u_, _v_) (_u_), (_v_)
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600127
128static const Vertex g_vbData[] =
129{
130 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
131 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
132 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
133 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
134 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
135 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
136
137 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
138 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
139 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
140 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
141 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
142 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
143
144 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
145 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.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( 1.f, 1.f, 0.f ) },
149 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
150
151 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
152 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
153 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
154 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
155 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
156 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
157
158 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
159 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
160 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
161 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
162 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
163 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
164
165 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
166 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
167 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
168 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
169 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
170 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
171};
172
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600173static const Vertex g_vb_solid_face_colors_Data[] =
174{
175 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600176 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600177 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
178 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600179 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
180 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600181
182 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
183 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600184 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
185 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600186 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600187 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600188
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600189 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
190 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
191 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
192 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
193 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
194 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600195
196 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
197 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
198 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
199 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
200 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
201 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
202
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600203 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600204 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600205 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
206 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600207 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
208 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
209
210 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
211 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
212 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
213 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
214 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
215 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
216};
217
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600218static const VertexUV g_vb_texture_Data[] =
219{
220 { XYZ1( -1, -1, -1 ), UV( 0.f, 0.f ) },
221 { XYZ1( -1, 1, 1 ), UV( 1.f, 1.f ) },
222 { XYZ1( -1, -1, 1 ), UV( 1.f, 0.f ) },
223 { XYZ1( -1, 1, 1 ), UV( 1.f, 1.f ) },
224 { XYZ1( -1, -1, -1 ), UV( 0.f, 0.f ) },
225 { XYZ1( -1, 1, -1 ), UV( 0.f, 1.f ) },
226
227 { XYZ1( -1, -1, -1 ), UV( 1.f, 0.f ) },
228 { XYZ1( 1, -1, -1 ), UV( 0.f, 0.f ) },
229 { XYZ1( 1, 1, -1 ), UV( 0.f, 1.f ) },
230 { XYZ1( -1, -1, -1 ), UV( 1.f, 0.f ) },
231 { XYZ1( 1, 1, -1 ), UV( 0.f, 1.f ) },
232 { XYZ1( -1, 1, -1 ), UV( 1.f, 1.f ) },
233
234 { XYZ1( -1, -1, -1 ), UV( 1.f, 1.f ) },
235 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
236 { XYZ1( 1, -1, -1 ), UV( 1.f, 0.f ) },
237 { XYZ1( -1, -1, -1 ), UV( 1.f, 1.f ) },
238 { XYZ1( -1, -1, 1 ), UV( 0.f, 1.f ) },
239 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.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( 0.f, 1.f ) },
244 { XYZ1( -1, 1, -1 ), UV( 1.f, 1.f ) },
245 { XYZ1( 1, 1, -1 ), UV( 1.f, 0.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( 0.f, 0.f ) },
252 { XYZ1( 1, 1, -1 ), UV( 1.f, 1.f ) },
253 { XYZ1( 1, -1, -1 ), UV( 1.f, 0.f ) },
254
255 { XYZ1( -1, 1, 1 ), UV( 0.f, 1.f ) },
256 { XYZ1( 1, 1, 1 ), UV( 1.f, 1.f ) },
257 { XYZ1( -1, -1, 1 ), UV( 0.f, 0.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
Tony Barbour6918cd52015-04-09 12:58:51 -0600263class VkRenderTest : public VkRenderFramework
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -0600264{
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600265public:
Cody Northrop7ad4aaf2014-10-09 21:25:22 -0600266
Tony Barboure2c58df2014-11-25 13:18:32 -0700267 void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800268 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *commandBuffer);
269 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600270 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet)
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800271 { GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet); }
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600272 void InitDepthStencil();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600273 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate);
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600274
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800275 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
276 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer, VkCommandBufferBeginInfo *beginInfo);
277 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600278 /* Convenience functions that use built-in command buffer */
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800279 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
280 VkResult BeginCommandBuffer(VkCommandBufferBeginInfo *beginInfo) { return BeginCommandBuffer(*m_commandBuffer, beginInfo); }
281 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600282 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800283 { m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance); }
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600284 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 +0800285 { m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); }
286 void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); }
Tony Barbourfe3351b2015-07-28 10:17:20 -0600287 void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
288 VkConstantBufferObj *constantBuffer)
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800289 {RotateTriangleVSUniform(Projection, View, Model, constantBuffer, m_commandBuffer); }
Tony Barbourfe3351b2015-07-28 10:17:20 -0600290 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding)
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800291 { m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding); }
Tony Barbourfe3351b2015-07-28 10:17:20 -0600292 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset)
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800293 { m_commandBuffer->BindIndexBuffer(indexBuffer, offset); }
Tony Barbourfe3351b2015-07-28 10:17:20 -0600294
295
Cody Northropee6586d2014-10-09 19:55:56 -0600296
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600297protected:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600298 VkImage m_texture;
299 VkImageView m_textureView;
Tony Barbourd1c35722015-04-16 15:59:00 -0600300 VkDeviceMemory m_textureMem;
Cody Northrop7d2035d2014-10-06 15:42:00 -0600301
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600302 VkSampler m_sampler;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600303
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600304
305 virtual void SetUp() {
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600306
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600307 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600308 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800309 this->app_info.pApplicationName = "render_tests";
310 this->app_info.applicationVersion = 1;
Chia-I Wuf1a5a742014-12-27 15:16:07 +0800311 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600312 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600313 this->app_info.apiVersion = VK_API_VERSION;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600314
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600315 InitFramework();
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600316 }
317
318 virtual void TearDown() {
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600319 // Clean up resources before we reset
320 ShutdownFramework();
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600321 }
322};
323
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800324VkResult VkRenderTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer)
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600325{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600326 VkResult result;
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600327
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800328 result = commandBuffer.BeginCommandBuffer();
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600329
330 /*
331 * For render test all drawing happens in a single render pass
332 * on a single command buffer.
333 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200334 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800335 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600336 }
337
338 return result;
339}
340
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800341VkResult VkRenderTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer, VkCommandBufferBeginInfo *beginInfo)
Tobin Ehlisf1878c72015-08-18 14:24:32 -0600342{
343 VkResult result;
344
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800345 result = commandBuffer.BeginCommandBuffer(beginInfo);
Tobin Ehlisf1878c72015-08-18 14:24:32 -0600346
347 /*
348 * For render test all drawing happens in a single render pass
349 * on a single command buffer.
350 */
351 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800352 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tobin Ehlisf1878c72015-08-18 14:24:32 -0600353 }
354
355 return result;
356}
357
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800358VkResult VkRenderTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer)
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600359{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600360 VkResult result;
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600361
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200362 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800363 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200364 }
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600365
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800366 result = commandBuffer.EndCommandBuffer();
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600367
368 return result;
369}
370
371
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800372void VkRenderTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet)
Tony Barbour22e32a12015-01-08 17:08:28 -0700373{
Tony Barbour71bd4b32015-07-21 17:00:26 -0600374 if (!m_clear_via_load_op) {
375 if (m_depthStencil->Initialized()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800376 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Tony Barbour71bd4b32015-07-21 17:00:26 -0600377 } else {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800378 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour71bd4b32015-07-21 17:00:26 -0600379 }
Tony Barbour1c45ce02015-03-27 17:03:18 -0600380 }
381
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800382 commandBuffer->PrepareAttachments();
383 commandBuffer->SetViewport(m_viewports.size(), m_viewports.data());
384 commandBuffer->SetScissor(m_scissors.size(), m_scissors.data());
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600385
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800386 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Cody Northrop29a08f22015-08-27 10:20:35 -0600387 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
388 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800389 commandBuffer->BindPipeline(pipelineobj);
390 commandBuffer->BindDescriptorSet(descriptorSet);
Tony Barbour22e32a12015-01-08 17:08:28 -0700391}
Tony Barboure2c58df2014-11-25 13:18:32 -0700392
Tony Barbour6918cd52015-04-09 12:58:51 -0600393void VkRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800394 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *commandBuffer)
Tony Barbour664accc2015-01-09 12:55:14 -0700395{
396 int i;
397 glm::mat4 MVP;
398 int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600399 VkResult err;
Tony Barbour664accc2015-01-09 12:55:14 -0700400
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600401 /* Only do 3 positions to avoid back face cull */
402 for (i = 0; i < 3; i++) {
Chia-I Wu681d7a02015-07-03 13:44:34 +0800403 void *pData = constantBuffer->memory().map();
Tony Barbour664accc2015-01-09 12:55:14 -0700404
405 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
406 MVP = Projection * View * Model;
407 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
408
Chia-I Wu681d7a02015-07-03 13:44:34 +0800409 constantBuffer->memory().unmap();
Tony Barbour664accc2015-01-09 12:55:14 -0700410
411 // submit the command buffer to the universal queue
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800412 commandBuffer->QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -0700413
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600414 err = vkQueueWaitIdle( m_device->m_queue );
415 ASSERT_VK_SUCCESS( err );
Tony Barbour664accc2015-01-09 12:55:14 -0700416
417 // Wait for work to finish before cleaning up.
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600418 vkDeviceWaitIdle(m_device->device());
Tony Barbour664accc2015-01-09 12:55:14 -0700419
Courtney Goeltzenleuchterb4337c12015-03-05 16:47:18 -0700420 assert(m_renderTargets.size() == 1);
Tony Barbour664accc2015-01-09 12:55:14 -0700421 RecordImage(m_renderTargets[0]);
422 }
423}
Courtney Goeltzenleuchterc55471f2014-10-13 13:03:31 -0600424
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600425void dumpMatrix(const char *note, glm::mat4 MVP)
426{
Chia-I Wu6f184292014-12-15 23:57:34 +0800427 int i;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600428
429 printf("%s: \n", note);
430 for (i=0; i<4; i++) {
431 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
432 }
433 printf("\n");
434 fflush(stdout);
435}
436
437void dumpVec4(const char *note, glm::vec4 vector)
438{
439 printf("%s: \n", note);
440 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
441 printf("\n");
442 fflush(stdout);
443}
444
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600445struct vktriangle_vs_uniform {
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600446 // Must start with MVP
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600447 float mvp[4][4];
448 float position[3][4];
449 float color[3][4];
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600450};
451
Tony Barbour6918cd52015-04-09 12:58:51 -0600452void VkRenderTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600453{
Tobin Ehlis6663f492014-11-10 12:29:12 -0700454#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600455 vkDbgRegisterMsgCallback(inst, myDbgFunc, NULL);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700456#endif
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600457 // Create identity matrix
458 int i;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600459 struct vktriangle_vs_uniform data;
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600460
461 glm::mat4 Projection = glm::mat4(1.0f);
462 glm::mat4 View = glm::mat4(1.0f);
463 glm::mat4 Model = glm::mat4(1.0f);
464 glm::mat4 MVP = Projection * View * Model;
465 const int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600466 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600467 memcpy(&data.mvp, &MVP[0][0], matrixSize);
468
469 static const Vertex tri_data[] =
470 {
471 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
472 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
473 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
474 };
475
476 for (i=0; i<3; i++) {
477 data.position[i][0] = tri_data[i].posX;
478 data.position[i][1] = tri_data[i].posY;
479 data.position[i][2] = tri_data[i].posZ;
480 data.position[i][3] = tri_data[i].posW;
481 data.color[i][0] = tri_data[i].r;
482 data.color[i][1] = tri_data[i].g;
483 data.color[i][2] = tri_data[i].b;
484 data.color[i][3] = tri_data[i].a;
485 }
486
Tony Barboure2c58df2014-11-25 13:18:32 -0700487 ASSERT_NO_FATAL_FAILURE(InitState());
488 ASSERT_NO_FATAL_FAILURE(InitViewport());
489
Tony Barbour6918cd52015-04-09 12:58:51 -0600490 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barboure2c58df2014-11-25 13:18:32 -0700491
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -0600492 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
493 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -0700494
Tony Barbour6918cd52015-04-09 12:58:51 -0600495 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800496 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -0700497 pipelineobj.AddShader(&vs);
498 pipelineobj.AddShader(&ps);
499
Tony Barbour6918cd52015-04-09 12:58:51 -0600500 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600501 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -0700502
Tony Barbourd726a172015-01-09 16:12:35 -0700503 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf1878c72015-08-18 14:24:32 -0600504
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800505 VkCommandBufferBeginInfo cbBeginInfo;
506 memset(&cbBeginInfo, 0, sizeof(VkCommandBufferBeginInfo));
507 cbBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Courtney Goeltzenleuchter04bb5f82015-10-21 18:11:04 -0600508 cbBeginInfo.flags = 0;
Tobin Ehlisf1878c72015-08-18 14:24:32 -0600509 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barboure2c58df2014-11-25 13:18:32 -0700510
Tony Barbourfe3351b2015-07-28 10:17:20 -0600511 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourd726a172015-01-09 16:12:35 -0700512#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600513 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourd726a172015-01-09 16:12:35 -0700514 pDSDumpDot((char*)"triTest2.dot");
515#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600516
Tony Barbourd726a172015-01-09 16:12:35 -0700517 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600518 Draw(3, 1, 0, 0);
Tony Barbourd726a172015-01-09 16:12:35 -0700519
520 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600521 ASSERT_VK_SUCCESS(EndCommandBuffer());
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600522
Tony Barbourfe3351b2015-07-28 10:17:20 -0600523 QueueCommandBuffer();
Tony Barbourd726a172015-01-09 16:12:35 -0700524
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600525 RecordImages(m_renderTargets);
Tony Barbourd726a172015-01-09 16:12:35 -0700526
527 if (rotate)
Tony Barbourfe3351b2015-07-28 10:17:20 -0600528 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer);
Tony Barbourd726a172015-01-09 16:12:35 -0700529
Tobin Ehlisca915872014-11-18 11:28:33 -0700530#ifdef PRINT_OBJECTS
Mark Lobodzinski7c75b852015-05-05 15:01:37 -0500531 OBJ_TRACK_GET_OBJECTS_COUNT pObjTrackGetObjectsCount = (OBJ_TRACK_GET_OBJECTS_COUNT)vkGetProcAddr(gpu(), (char*)"objTrackGetObjectsCount");
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600532 uint64_t numObjects = pObjTrackGetObjectsCount(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600533 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlisca915872014-11-18 11:28:33 -0700534 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600535 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlisca915872014-11-18 11:28:33 -0700536 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600537 pObjTrackGetObjs(m_device, numObjects, pObjNodeArray);
Tobin Ehlisca915872014-11-18 11:28:33 -0700538 for (i=0; i < numObjects; i++) {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600539 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 -0700540 }
541 free(pObjNodeArray);
542#endif
Tony Barboure2c58df2014-11-25 13:18:32 -0700543
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600544}
545
Tony Barbour6918cd52015-04-09 12:58:51 -0600546TEST_F(VkRenderTest, VKTriangle_FragColor)
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600547{
548 static const char *vertShaderText =
549 "#version 140\n"
550 "#extension GL_ARB_separate_shader_objects : enable\n"
551 "#extension GL_ARB_shading_language_420pack : enable\n"
552 "\n"
553 "layout(binding = 0) uniform buf {\n"
554 " mat4 MVP;\n"
555 " vec4 position[3];\n"
556 " vec4 color[3];\n"
557 "} ubuf;\n"
558 "\n"
559 "layout (location = 0) out vec4 outColor;\n"
560 "\n"
561 "void main() \n"
562 "{\n"
563 " outColor = ubuf.color[gl_VertexID];\n"
564 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
565 "}\n";
566
567 static const char *fragShaderText =
568 "#version 140\n"
569 "#extension GL_ARB_separate_shader_objects : enable\n"
570 "#extension GL_ARB_shading_language_420pack : enable\n"
571 "\n"
572 "layout (location = 0) in vec4 inColor;\n"
GregFaae75242015-06-03 18:40:50 -0600573 "layout (location = 0) out vec4 uFragColor;\n"
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600574 "\n"
575 "void main()\n"
576 "{\n"
GregFaae75242015-06-03 18:40:50 -0600577 " uFragColor = inColor;\n"
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600578 "}\n";
579
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600580 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
581 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600582}
583
Tony Barbour6918cd52015-04-09 12:58:51 -0600584TEST_F(VkRenderTest, VKTriangle_OutputLocation)
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600585{
586 static const char *vertShaderText =
587 "#version 140\n"
588 "#extension GL_ARB_separate_shader_objects : enable\n"
589 "#extension GL_ARB_shading_language_420pack : enable\n"
590 "\n"
591 "layout(binding = 0) uniform buf {\n"
592 " mat4 MVP;\n"
593 " vec4 position[3];\n"
594 " vec4 color[3];\n"
595 "} ubuf;\n"
596 "\n"
597 "layout (location = 0) out vec4 outColor;\n"
598 "\n"
599 "void main() \n"
600 "{\n"
601 " outColor = ubuf.color[gl_VertexID];\n"
602 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
603 "}\n";
604
605 static const char *fragShaderText =
606 "#version 140\n"
607 "#extension GL_ARB_separate_shader_objects : enable\n"
608 "#extension GL_ARB_shading_language_420pack : enable\n"
609 "\n"
610 "layout (location = 0) in vec4 inColor;\n"
611 "layout (location = 0) out vec4 outColor;\n"
612 "\n"
613 "void main()\n"
614 "{\n"
615 " outColor = inColor;\n"
616 "}\n";
617
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600618 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 -0600619
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600620 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600621}
Cody Northrop6922da12015-06-23 13:25:51 -0600622
Tony Barbour6918cd52015-04-09 12:58:51 -0600623TEST_F(VkRenderTest, SPV_VKTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -0700624{
Tony Barboure2c58df2014-11-25 13:18:32 -0700625 static const char *vertShaderText =
626 "#version 140\n"
627 "#extension GL_ARB_separate_shader_objects : enable\n"
628 "#extension GL_ARB_shading_language_420pack : enable\n"
629 "\n"
630 "layout(binding = 0) uniform buf {\n"
631 " mat4 MVP;\n"
632 " vec4 position[3];\n"
633 " vec4 color[3];\n"
634 "} ubuf;\n"
635 "\n"
636 "layout (location = 0) out vec4 outColor;\n"
637 "\n"
638 "void main() \n"
639 "{\n"
640 " outColor = ubuf.color[gl_VertexID];\n"
641 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
642 "}\n";
643
644 static const char *fragShaderText =
645 "#version 140\n"
646 "#extension GL_ARB_separate_shader_objects : enable\n"
647 "#extension GL_ARB_shading_language_420pack : enable\n"
648 "\n"
649 "layout (location = 0) in vec4 inColor;\n"
GregFaae75242015-06-03 18:40:50 -0600650 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700651 "\n"
652 "void main()\n"
653 "{\n"
GregFaae75242015-06-03 18:40:50 -0600654 " outColor = inColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700655 "}\n";
656
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600657 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 -0700658
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600659 VKTriangleTest(vertShaderText, fragShaderText, true);
Tony Barboure2c58df2014-11-25 13:18:32 -0700660}
Courtney Goeltzenleuchter538062a2014-10-09 15:40:19 -0600661
Tony Barbour6918cd52015-04-09 12:58:51 -0600662TEST_F(VkRenderTest, SPV_GreenTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -0700663{
Tony Barboure2c58df2014-11-25 13:18:32 -0700664 static const char *vertShaderText =
665 "#version 130\n"
666 "vec2 vertices[3];\n"
667 "void main() {\n"
668 " vertices[0] = vec2(-1.0, -1.0);\n"
669 " vertices[1] = vec2( 1.0, -1.0);\n"
670 " vertices[2] = vec2( 0.0, 1.0);\n"
671 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
672 "}\n";
673
674 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -0600675 "#version 140\n"
676 "#extension GL_ARB_separate_shader_objects : enable\n"
677 "#extension GL_ARB_shading_language_420pack : enable\n"
678 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700679 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600680 " outColor = vec4(0,1,0,1);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700681 "}\n";
682
Cody Northrop3bfd27c2015-03-17 15:55:58 -0600683 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barboure2c58df2014-11-25 13:18:32 -0700684
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600685 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barboure2c58df2014-11-25 13:18:32 -0700686}
Cody Northrop6922da12015-06-23 13:25:51 -0600687
Tony Barbour6918cd52015-04-09 12:58:51 -0600688TEST_F(VkRenderTest, YellowTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -0700689{
690 static const char *vertShaderText =
691 "#version 130\n"
692 "void main() {\n"
693 " vec2 vertices[3];"
694 " vertices[0] = vec2(-0.5, -0.5);\n"
695 " vertices[1] = vec2( 0.5, -0.5);\n"
696 " vertices[2] = vec2( 0.5, 0.5);\n"
697 " vec4 colors[3];\n"
698 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
699 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
700 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
701 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
702 "}\n";
703
704 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -0600705 "#version 140\n"
706 "#extension GL_ARB_separate_shader_objects : enable\n"
707 "#extension GL_ARB_shading_language_420pack : enable\n"
708 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700709 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600710 " outColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700711 "}\n";
712
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600713 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barboure2c58df2014-11-25 13:18:32 -0700714}
715
Tony Barbour6918cd52015-04-09 12:58:51 -0600716TEST_F(VkRenderTest, QuadWithVertexFetch)
Cody Northropee6586d2014-10-09 19:55:56 -0600717{
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600718 static const char *vertShaderText =
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600719 "#version 140\n"
720 "#extension GL_ARB_separate_shader_objects : enable\n"
721 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700722 //XYZ1( -1, -1, -1 )
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600723 "layout (location = 0) in vec4 pos;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700724 //XYZ1( 0.f, 0.f, 0.f )
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600725 "layout (location = 1) in vec4 inColor;\n"
726 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600727 "void main() {\n"
Cody Northrop66594a72014-10-10 14:49:36 -0600728 " outColor = inColor;\n"
Cody Northrop7ad4aaf2014-10-09 21:25:22 -0600729 " gl_Position = pos;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600730 "}\n";
731
Cody Northropee6586d2014-10-09 19:55:56 -0600732
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600733 static const char *fragShaderText =
Cody Northropd43c52e2014-12-05 15:44:14 -0700734 "#version 140\n"
735 "#extension GL_ARB_separate_shader_objects : enable\n"
736 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600737 "layout (location = 0) in vec4 color;\n"
Cody Northropd43c52e2014-12-05 15:44:14 -0700738 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600739 "void main() {\n"
Cody Northropd43c52e2014-12-05 15:44:14 -0700740 " outColor = color;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600741 "}\n";
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600742
Tony Barboure2c58df2014-11-25 13:18:32 -0700743
744
745 ASSERT_NO_FATAL_FAILURE(InitState());
746 ASSERT_NO_FATAL_FAILURE(InitViewport());
747
Tony Barbour6918cd52015-04-09 12:58:51 -0600748 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000749 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -0700750
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -0600751 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
752 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -0700753
Tony Barbour6918cd52015-04-09 12:58:51 -0600754 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800755 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -0700756 pipelineobj.AddShader(&vs);
757 pipelineobj.AddShader(&ps);
758
Tony Barbour6918cd52015-04-09 12:58:51 -0600759 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -0600760
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600761#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600762 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600763 MESH_BIND_ID, // binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800764 sizeof(g_vbData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800765 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
Tony Barboure2c58df2014-11-25 13:18:32 -0700766 };
767
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600768 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600769 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
770 vi_attribs[0].location = 0; // location, position
Tony Barbourd1c35722015-04-16 15:59:00 -0600771 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800772 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600773 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
774 vi_attribs[1].location = 1; // location, color
Tony Barbourd1c35722015-04-16 15:59:00 -0600775 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800776 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 -0700777
778 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
779 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barboure2c58df2014-11-25 13:18:32 -0700780
Tony Barbour1fde6942015-01-09 10:06:53 -0700781 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600782 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure2c58df2014-11-25 13:18:32 -0700783
Tony Barbourfe3351b2015-07-28 10:17:20 -0600784 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600785
Tony Barbourfe3351b2015-07-28 10:17:20 -0600786 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour1fde6942015-01-09 10:06:53 -0700787
788 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600789 Draw(6, 1, 0, 0);
Tony Barbour1fde6942015-01-09 10:06:53 -0700790
791 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600792 ASSERT_VK_SUCCESS(EndCommandBuffer());
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600793
Tony Barbourfe3351b2015-07-28 10:17:20 -0600794 QueueCommandBuffer();
Tony Barbour1fde6942015-01-09 10:06:53 -0700795
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600796 RecordImages(m_renderTargets);
Tobin Ehlisd806c8e2014-10-07 14:41:29 -0600797}
798
Tony Barbour6918cd52015-04-09 12:58:51 -0600799TEST_F(VkRenderTest, TriangleMRT)
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800800{
801 static const char *vertShaderText =
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600802 "#version 140\n"
803 "#extension GL_ARB_separate_shader_objects : enable\n"
804 "#extension GL_ARB_shading_language_420pack : enable\n"
805 "layout (location = 0) in vec4 pos;\n"
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800806 "void main() {\n"
807 " gl_Position = pos;\n"
808 "}\n";
809
810 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -0600811 "#version 140\n"
812 "#extension GL_ARB_separate_shader_objects : enable\n"
813 "#extension GL_ARB_shading_language_420pack : enable\n"
814 "layout (location = 0) out vec4 uFragData0;\n"
815 "layout (location = 1) out vec4 uFragData1;\n"
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800816 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600817 " uFragData0 = vec4(1.0, 0.0, 0.0, 1.0);\n"
818 " uFragData1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800819 "}\n";
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600820 const float vb_data[][2] = {
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800821 { -1.0f, -1.0f },
822 { 1.0f, -1.0f },
823 { -1.0f, 1.0f }
824 };
825
826 ASSERT_NO_FATAL_FAILURE(InitState());
827 ASSERT_NO_FATAL_FAILURE(InitViewport());
828
Tony Barbour6918cd52015-04-09 12:58:51 -0600829 VkConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000830 meshBuffer.BufferMemoryBarrier();
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800831
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -0600832 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
833 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800834
Tony Barbour6918cd52015-04-09 12:58:51 -0600835 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800836 pipelineobj.AddColorAttachment();
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800837 pipelineobj.AddShader(&vs);
838 pipelineobj.AddShader(&ps);
839
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600840#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600841 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600842 MESH_BUF_ID, // Binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800843 sizeof(vb_data[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800844 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800845 };
846
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600847 VkVertexInputAttributeDescription vi_attrib;
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600848 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
849 vi_attrib.location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -0600850 vi_attrib.format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800851 vi_attrib.offset = 0; // Offset of first element in bytes from base of vertex
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800852
853 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
854 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800855
Tony Barbour6918cd52015-04-09 12:58:51 -0600856 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800857
Courtney Goeltzenleuchterb4337c12015-03-05 16:47:18 -0700858 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800859
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600860 VkPipelineColorBlendAttachmentState att = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600861 att.blendEnable = VK_FALSE;
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800862 att.colorWriteMask = 0xf;
Tony Barbourf52346d2015-01-16 14:27:35 -0700863 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800864
Tony Barbourfe3351b2015-07-28 10:17:20 -0600865 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour1fde6942015-01-09 10:06:53 -0700866
Tony Barbourfe3351b2015-07-28 10:17:20 -0600867 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour1fde6942015-01-09 10:06:53 -0700868
Tony Barbourfe3351b2015-07-28 10:17:20 -0600869 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour304ec8b2015-01-07 14:31:52 -0700870#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600871 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour304ec8b2015-01-07 14:31:52 -0700872 pDSDumpDot((char*)"triTest2.dot");
873#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600874
Tony Barbour304ec8b2015-01-07 14:31:52 -0700875 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600876 Draw(3, 1, 0, 0);
Tony Barbour304ec8b2015-01-07 14:31:52 -0700877
878 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600879 ASSERT_VK_SUCCESS(EndCommandBuffer());
880 QueueCommandBuffer();
Tony Barbour304ec8b2015-01-07 14:31:52 -0700881
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600882 RecordImages(m_renderTargets);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800883}
884
Tony Barbour6918cd52015-04-09 12:58:51 -0600885TEST_F(VkRenderTest, QuadWithIndexedVertexFetch)
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700886{
887 static const char *vertShaderText =
888 "#version 140\n"
889 "#extension GL_ARB_separate_shader_objects : enable\n"
890 "#extension GL_ARB_shading_language_420pack : enable\n"
891 "layout(location = 0) in vec4 pos;\n"
892 "layout(location = 1) in vec4 inColor;\n"
893 "layout(location = 0) out vec4 outColor;\n"
894 "void main() {\n"
895 " outColor = inColor;\n"
896 " gl_Position = pos;\n"
897 "}\n";
898
899
900 static const char *fragShaderText =
901 "#version 140\n"
902 "#extension GL_ARB_separate_shader_objects : enable\n"
903 "#extension GL_ARB_shading_language_420pack : enable\n"
904 "layout(location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -0600905 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700906 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600907 " outColor = color;\n"
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700908 "}\n";
909
910 const Vertex g_vbData[] =
911 {
912 // first tri
913 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
914 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
915 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
916
917 // second tri
918 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
919 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
920 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
921 };
922
923 const uint16_t g_idxData[6] = {
924 0, 1, 2,
925 3, 4, 5,
926 };
927
928 ASSERT_NO_FATAL_FAILURE(InitState());
929 ASSERT_NO_FATAL_FAILURE(InitViewport());
930
Tony Barbour6918cd52015-04-09 12:58:51 -0600931 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000932 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700933
Tony Barbour6918cd52015-04-09 12:58:51 -0600934 VkIndexBufferObj indexBuffer(m_device);
Tony Barbourd1c35722015-04-16 15:59:00 -0600935 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), VK_INDEX_TYPE_UINT16, g_idxData);
Mark Lobodzinski49a6b4b2015-02-16 14:24:23 -0600936 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700937
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -0600938 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
939 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700940
Tony Barbour6918cd52015-04-09 12:58:51 -0600941 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800942 pipelineobj.AddColorAttachment();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700943 pipelineobj.AddShader(&vs);
944 pipelineobj.AddShader(&ps);
945
Tony Barbour6918cd52015-04-09 12:58:51 -0600946 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour831062d2015-04-02 15:43:15 -0600947
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700948
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600949#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600950 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600951 MESH_BIND_ID, // binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800952 sizeof(g_vbData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800953 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700954 };
955
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600956 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600957 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
958 vi_attribs[0].location = 0; // layout location of vertex attribute
Tony Barbourd1c35722015-04-16 15:59:00 -0600959 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800960 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600961 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
962 vi_attribs[1].location = 1; // layout location of vertex attribute
Tony Barbourd1c35722015-04-16 15:59:00 -0600963 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800964 vi_attribs[1].offset = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700965
966 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
967 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700968
969 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600970 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour1fde6942015-01-09 10:06:53 -0700971
Tony Barbourfe3351b2015-07-28 10:17:20 -0600972 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700973
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700974#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600975 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlisf27eba72014-12-16 17:34:50 -0700976 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700977#endif
Tony Barbour22e32a12015-01-08 17:08:28 -0700978
Tony Barbourfe3351b2015-07-28 10:17:20 -0600979 BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
980 BindIndexBuffer(&indexBuffer, 0);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700981
982 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600983 DrawIndexed(6, 1, 0, 0, 0);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700984
985 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600986 ASSERT_VK_SUCCESS(EndCommandBuffer());
987 QueueCommandBuffer();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700988
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600989 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700990}
991
Tony Barbour6918cd52015-04-09 12:58:51 -0600992TEST_F(VkRenderTest, GreyandRedCirclesonBlue)
GregF3156cb02014-12-02 15:41:44 -0700993{
994 // This tests gl_FragCoord
Tony Barboure2c58df2014-11-25 13:18:32 -0700995
GregF3156cb02014-12-02 15:41:44 -0700996 static const char *vertShaderText =
997 "#version 140\n"
998 "#extension GL_ARB_separate_shader_objects : enable\n"
999 "#extension GL_ARB_shading_language_420pack : enable\n"
1000 "layout (location = 0) in vec4 pos;\n"
1001 "layout (location = 0) out vec4 outColor;\n"
1002 "layout (location = 1) out vec4 outColor2;\n"
1003 "void main() {\n"
1004 " gl_Position = pos;\n"
1005 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1006 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1007 "}\n";
1008
1009 static const char *fragShaderText =
GregF3156cb02014-12-02 15:41:44 -07001010 "#version 330\n"
1011 "#extension GL_ARB_separate_shader_objects : enable\n"
1012 "#extension GL_ARB_shading_language_420pack : enable\n"
1013 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1014 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1015 "layout (location = 0) in vec4 color;\n"
1016 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001017 "layout (location = 0) out vec4 outColor;\n"
GregF3156cb02014-12-02 15:41:44 -07001018 "void main() {\n"
1019 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1020 " float dist_squared = dot(pos, pos);\n"
GregFaae75242015-06-03 18:40:50 -06001021 " outColor = (dist_squared < 400.0)\n"
GregF3156cb02014-12-02 15:41:44 -07001022 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1023 " : color2;\n"
1024 "}\n";
1025
1026 ASSERT_NO_FATAL_FAILURE(InitState());
1027 ASSERT_NO_FATAL_FAILURE(InitViewport());
1028
Tony Barbour6918cd52015-04-09 12:58:51 -06001029 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001030 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001031
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001032 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1033 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
GregF3156cb02014-12-02 15:41:44 -07001034
Tony Barbour6918cd52015-04-09 12:58:51 -06001035 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001036 pipelineobj.AddColorAttachment();
GregF3156cb02014-12-02 15:41:44 -07001037 pipelineobj.AddShader(&vs);
1038 pipelineobj.AddShader(&ps);
1039
Tony Barbour6918cd52015-04-09 12:58:51 -06001040 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001041
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001042#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001043 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001044 MESH_BIND_ID, // binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001045 sizeof(g_vbData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001046 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
GregF3156cb02014-12-02 15:41:44 -07001047 };
1048
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001049 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001050 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1051 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001052 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001053 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
GregF3156cb02014-12-02 15:41:44 -07001054
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001055 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF3156cb02014-12-02 15:41:44 -07001056 pipelineobj.AddVertexInputBindings(&vi_binding,1);
GregF3156cb02014-12-02 15:41:44 -07001057
Tony Barbour664accc2015-01-09 12:55:14 -07001058 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour664accc2015-01-09 12:55:14 -07001059
Tony Barbourfe3351b2015-07-28 10:17:20 -06001060 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001061
Tony Barbourfe3351b2015-07-28 10:17:20 -06001062 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001063
Tony Barbourfe3351b2015-07-28 10:17:20 -06001064 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001065#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001066 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001067 pDSDumpDot((char*)"triTest2.dot");
1068#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001069
Tony Barbour664accc2015-01-09 12:55:14 -07001070 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001071 Draw(6, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001072
1073 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001074 EndCommandBuffer();
1075 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001076
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001077 RecordImages(m_renderTargets);
GregF3156cb02014-12-02 15:41:44 -07001078}
1079
Tony Barbour6918cd52015-04-09 12:58:51 -06001080TEST_F(VkRenderTest, RedCirclesonBlue)
GregF3156cb02014-12-02 15:41:44 -07001081{
1082 // This tests that we correctly handle unread fragment inputs
1083
1084 static const char *vertShaderText =
1085 "#version 140\n"
1086 "#extension GL_ARB_separate_shader_objects : enable\n"
1087 "#extension GL_ARB_shading_language_420pack : enable\n"
1088 "layout (location = 0) in vec4 pos;\n"
1089 "layout (location = 0) out vec4 outColor;\n"
1090 "layout (location = 1) out vec4 outColor2;\n"
1091 "void main() {\n"
1092 " gl_Position = pos;\n"
1093 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1094 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1095 "}\n";
1096
1097 static const char *fragShaderText =
GregF3156cb02014-12-02 15:41:44 -07001098 "#version 330\n"
1099 "#extension GL_ARB_separate_shader_objects : enable\n"
1100 "#extension GL_ARB_shading_language_420pack : enable\n"
1101 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1102 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1103 "layout (location = 0) in vec4 color;\n"
1104 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001105 "layout (location = 0) out vec4 outColor;\n"
GregF3156cb02014-12-02 15:41:44 -07001106 "void main() {\n"
1107 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1108 " float dist_squared = dot(pos, pos);\n"
GregFaae75242015-06-03 18:40:50 -06001109 " outColor = (dist_squared < 400.0)\n"
GregF3156cb02014-12-02 15:41:44 -07001110 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1111 " : color2;\n"
1112 "}\n";
1113
1114 ASSERT_NO_FATAL_FAILURE(InitState());
1115 ASSERT_NO_FATAL_FAILURE(InitViewport());
1116
Tony Barbour6918cd52015-04-09 12:58:51 -06001117 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001118 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001119
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001120 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1121 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
GregF3156cb02014-12-02 15:41:44 -07001122
Tony Barbour6918cd52015-04-09 12:58:51 -06001123 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001124 pipelineobj.AddColorAttachment();
GregF3156cb02014-12-02 15:41:44 -07001125 pipelineobj.AddShader(&vs);
1126 pipelineobj.AddShader(&ps);
1127
Tony Barbour6918cd52015-04-09 12:58:51 -06001128 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001129
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001130#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001131 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001132 MESH_BIND_ID, // binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001133 sizeof(g_vbData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001134 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
GregF3156cb02014-12-02 15:41:44 -07001135 };
1136
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001137 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001138 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1139 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001140 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001141 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
GregF3156cb02014-12-02 15:41:44 -07001142
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001143 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF3156cb02014-12-02 15:41:44 -07001144 pipelineobj.AddVertexInputBindings(&vi_binding,1);
GregF3156cb02014-12-02 15:41:44 -07001145
Tony Barbour664accc2015-01-09 12:55:14 -07001146 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001147 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001148
Tony Barbourfe3351b2015-07-28 10:17:20 -06001149 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001150
Tony Barbourfe3351b2015-07-28 10:17:20 -06001151 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001152#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001153 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001154 pDSDumpDot((char*)"triTest2.dot");
1155#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001156 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001157 Draw(6, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001158
1159 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001160 EndCommandBuffer();
1161 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001162
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001163 RecordImages(m_renderTargets);
GregF3156cb02014-12-02 15:41:44 -07001164}
1165
Tony Barbour6918cd52015-04-09 12:58:51 -06001166TEST_F(VkRenderTest, GreyCirclesonBlueFade)
GregF3156cb02014-12-02 15:41:44 -07001167{
1168 // This tests reading gl_ClipDistance from FS
1169
1170 static const char *vertShaderText =
GregFaae75242015-06-03 18:40:50 -06001171 //"#version 140\n"
GregF3156cb02014-12-02 15:41:44 -07001172 "#version 330\n"
1173 "#extension GL_ARB_separate_shader_objects : enable\n"
1174 "#extension GL_ARB_shading_language_420pack : enable\n"
1175 "out gl_PerVertex {\n"
1176 " vec4 gl_Position;\n"
1177 " float gl_ClipDistance[1];\n"
1178 "};\n"
1179 "layout (location = 0) in vec4 pos;\n"
1180 "layout (location = 0) out vec4 outColor;\n"
1181 "layout (location = 1) out vec4 outColor2;\n"
1182 "void main() {\n"
1183 " gl_Position = pos;\n"
1184 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1185 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1186 " float dists[3];\n"
1187 " dists[0] = 0.0;\n"
1188 " dists[1] = 1.0;\n"
1189 " dists[2] = 1.0;\n"
1190 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1191 "}\n";
1192
1193
1194 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -06001195 "#version 140\n"
1196 //"#version 330\n"
GregF3156cb02014-12-02 15:41:44 -07001197 "#extension GL_ARB_separate_shader_objects : enable\n"
1198 "#extension GL_ARB_shading_language_420pack : enable\n"
1199 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1200 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1201 "layout (location = 0) in vec4 color;\n"
1202 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001203 "layout (location = 0) out vec4 uFragColor;\n"
GregF3156cb02014-12-02 15:41:44 -07001204 "void main() {\n"
1205 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1206 " float dist_squared = dot(pos, pos);\n"
GregFaae75242015-06-03 18:40:50 -06001207 " uFragColor = (dist_squared < 400.0)\n"
GregF3156cb02014-12-02 15:41:44 -07001208 " ? color * gl_ClipDistance[0]\n"
1209 " : color2;\n"
1210 "}\n";
1211
1212 ASSERT_NO_FATAL_FAILURE(InitState());
1213 ASSERT_NO_FATAL_FAILURE(InitViewport());
1214
Tony Barbour6918cd52015-04-09 12:58:51 -06001215 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001216 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001217
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001218 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1219 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
GregF3156cb02014-12-02 15:41:44 -07001220
Tony Barbour6918cd52015-04-09 12:58:51 -06001221 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001222 pipelineobj.AddColorAttachment();
GregF3156cb02014-12-02 15:41:44 -07001223 pipelineobj.AddShader(&vs);
1224 pipelineobj.AddShader(&ps);
1225
Tony Barbour6918cd52015-04-09 12:58:51 -06001226 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001227
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001228#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001229 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001230 MESH_BIND_ID, // binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001231 sizeof(g_vbData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001232 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
GregF3156cb02014-12-02 15:41:44 -07001233 };
1234
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001235 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001236 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1237 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001238 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001239 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
GregF3156cb02014-12-02 15:41:44 -07001240
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001241 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF3156cb02014-12-02 15:41:44 -07001242 pipelineobj.AddVertexInputBindings(&vi_binding,1);
GregF3156cb02014-12-02 15:41:44 -07001243
Tony Barbour664accc2015-01-09 12:55:14 -07001244 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
GregF3156cb02014-12-02 15:41:44 -07001245
Tony Barbourfe3351b2015-07-28 10:17:20 -06001246 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001247
Tony Barbourfe3351b2015-07-28 10:17:20 -06001248 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001249
Tony Barbourfe3351b2015-07-28 10:17:20 -06001250 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001251#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001252 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001253 pDSDumpDot((char*)"triTest2.dot");
1254#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001255
1256 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001257 Draw(6, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001258
1259 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001260 EndCommandBuffer();
1261 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001262
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001263 RecordImages(m_renderTargets);
GregF3156cb02014-12-02 15:41:44 -07001264}
Tony Barboure2c58df2014-11-25 13:18:32 -07001265
Tony Barbour6918cd52015-04-09 12:58:51 -06001266TEST_F(VkRenderTest, GreyCirclesonBlueDiscard)
GregF42226582014-12-02 17:19:34 -07001267{
1268 static const char *vertShaderText =
1269 "#version 140\n"
1270 "#extension GL_ARB_separate_shader_objects : enable\n"
1271 "#extension GL_ARB_shading_language_420pack : enable\n"
1272 "layout (location = 0) in vec4 pos;\n"
1273 "layout (location = 0) out vec4 outColor;\n"
1274 "layout (location = 1) out vec4 outColor2;\n"
1275 "void main() {\n"
1276 " gl_Position = pos;\n"
1277 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1278 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1279 "}\n";
1280
1281
1282 static const char *fragShaderText =
GregF42226582014-12-02 17:19:34 -07001283 "#version 330\n"
1284 "#extension GL_ARB_separate_shader_objects : enable\n"
1285 "#extension GL_ARB_shading_language_420pack : enable\n"
1286 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1287 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1288 "layout (location = 0) in vec4 color;\n"
1289 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001290 "layout (location = 0) out vec4 outColor;\n"
GregF42226582014-12-02 17:19:34 -07001291 "void main() {\n"
1292 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1293 " float dist_squared = dot(pos, pos);\n"
1294 " if (dist_squared < 100.0)\n"
1295 " discard;\n"
GregFaae75242015-06-03 18:40:50 -06001296 " outColor = (dist_squared < 400.0)\n"
GregF42226582014-12-02 17:19:34 -07001297 " ? color\n"
1298 " : color2;\n"
1299 "}\n";
1300
1301 ASSERT_NO_FATAL_FAILURE(InitState());
1302 ASSERT_NO_FATAL_FAILURE(InitViewport());
1303
Tony Barbour6918cd52015-04-09 12:58:51 -06001304 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001305 meshBuffer.BufferMemoryBarrier();
GregF42226582014-12-02 17:19:34 -07001306
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001307 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1308 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
GregF42226582014-12-02 17:19:34 -07001309
Tony Barbour6918cd52015-04-09 12:58:51 -06001310 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001311 pipelineobj.AddColorAttachment();
GregF42226582014-12-02 17:19:34 -07001312 pipelineobj.AddShader(&vs);
1313 pipelineobj.AddShader(&ps);
1314
Tony Barbour6918cd52015-04-09 12:58:51 -06001315 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001316
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001317#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001318 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001319 MESH_BIND_ID, // binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001320 sizeof(g_vbData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001321 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
GregF42226582014-12-02 17:19:34 -07001322 };
1323
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001324 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001325 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1326 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001327 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001328 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
GregF42226582014-12-02 17:19:34 -07001329
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001330 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF42226582014-12-02 17:19:34 -07001331 pipelineobj.AddVertexInputBindings(&vi_binding,1);
GregF42226582014-12-02 17:19:34 -07001332
Tony Barbour664accc2015-01-09 12:55:14 -07001333 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour664accc2015-01-09 12:55:14 -07001334
Tony Barbourfe3351b2015-07-28 10:17:20 -06001335 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001336
Tony Barbourfe3351b2015-07-28 10:17:20 -06001337 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001338
Tony Barbourfe3351b2015-07-28 10:17:20 -06001339 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001340#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001341 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001342 pDSDumpDot((char*)"triTest2.dot");
1343#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001344
1345 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001346 Draw(6, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001347
1348 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001349 EndCommandBuffer();
1350 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001351
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001352 RecordImages(m_renderTargets);
GregF42226582014-12-02 17:19:34 -07001353}
1354
1355
Tony Barbour6918cd52015-04-09 12:58:51 -06001356TEST_F(VkRenderTest, TriangleVSUniform)
Cody Northrop66594a72014-10-10 14:49:36 -06001357{
1358 static const char *vertShaderText =
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001359 "#version 140\n"
1360 "#extension GL_ARB_separate_shader_objects : enable\n"
1361 "#extension GL_ARB_shading_language_420pack : enable\n"
1362 "\n"
1363 "layout(binding = 0) uniform buf {\n"
1364 " mat4 MVP;\n"
1365 "} ubuf;\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001366 "void main() {\n"
1367 " vec2 vertices[3];"
1368 " vertices[0] = vec2(-0.5, -0.5);\n"
1369 " vertices[1] = vec2( 0.5, -0.5);\n"
1370 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001371 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001372 "}\n";
1373
1374 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -06001375 "#version 140\n"
1376 "#extension GL_ARB_separate_shader_objects : enable\n"
1377 "#extension GL_ARB_shading_language_420pack : enable\n"
1378 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001379 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001380 " outColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001381 "}\n";
1382
Tony Barboure2c58df2014-11-25 13:18:32 -07001383 ASSERT_NO_FATAL_FAILURE(InitState());
1384 ASSERT_NO_FATAL_FAILURE(InitViewport());
1385
Courtney Goeltzenleuchterfdcfb9f2014-10-10 18:04:39 -06001386 // Create identity matrix
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001387 glm::mat4 Projection = glm::mat4(1.0f);
1388 glm::mat4 View = glm::mat4(1.0f);
1389 glm::mat4 Model = glm::mat4(1.0f);
1390 glm::mat4 MVP = Projection * View * Model;
1391 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1392
Tony Barbour6918cd52015-04-09 12:58:51 -06001393 VkConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001394 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1395 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001396
Tony Barbour6918cd52015-04-09 12:58:51 -06001397 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001398 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001399 pipelineobj.AddShader(&vs);
1400 pipelineobj.AddShader(&ps);
1401
1402 // Create descriptor set and attach the constant buffer to it
Tony Barbour6918cd52015-04-09 12:58:51 -06001403 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001404 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07001405
Tony Barbour664accc2015-01-09 12:55:14 -07001406 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf1878c72015-08-18 14:24:32 -06001407
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001408 VkCommandBufferBeginInfo cbBeginInfo;
1409 memset(&cbBeginInfo, 0, sizeof(VkCommandBufferBeginInfo));
1410 cbBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Courtney Goeltzenleuchter04bb5f82015-10-21 18:11:04 -06001411 cbBeginInfo.flags = 0;
Tobin Ehlisf1878c72015-08-18 14:24:32 -06001412 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barboure2c58df2014-11-25 13:18:32 -07001413
Tony Barbourfe3351b2015-07-28 10:17:20 -06001414 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001415
Tony Barbour664accc2015-01-09 12:55:14 -07001416#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001417 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001418 pDSDumpDot((char*)"triTest2.dot");
1419#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001420
1421 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001422 Draw(6, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001423
1424 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001425 EndCommandBuffer();
1426 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001427
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001428 RecordImages(m_renderTargets);
Tony Barbour664accc2015-01-09 12:55:14 -07001429
Tony Barbourfe3351b2015-07-28 10:17:20 -06001430 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer);
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001431}
1432
Tony Barbour6918cd52015-04-09 12:58:51 -06001433TEST_F(VkRenderTest, MixTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07001434{
1435 // This tests location applied to varyings. Notice that we have switched foo
1436 // and bar in the FS. The triangle should be blended with red, green and blue
1437 // corners.
1438 static const char *vertShaderText =
1439 "#version 140\n"
1440 "#extension GL_ARB_separate_shader_objects : enable\n"
1441 "#extension GL_ARB_shading_language_420pack : enable\n"
1442 "layout (location=0) out vec4 bar;\n"
1443 "layout (location=1) out vec4 foo;\n"
1444 "layout (location=2) out float scale;\n"
1445 "vec2 vertices[3];\n"
1446 "void main() {\n"
1447 " vertices[0] = vec2(-1.0, -1.0);\n"
1448 " vertices[1] = vec2( 1.0, -1.0);\n"
1449 " vertices[2] = vec2( 0.0, 1.0);\n"
1450 "vec4 colors[3];\n"
1451 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1452 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1453 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1454 " foo = colors[gl_VertexID % 3];\n"
1455 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1456 " scale = 1.0;\n"
1457 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1458 "}\n";
1459
1460 static const char *fragShaderText =
1461 "#version 140\n"
1462 "#extension GL_ARB_separate_shader_objects : enable\n"
1463 "#extension GL_ARB_shading_language_420pack : enable\n"
1464 "layout (location = 1) in vec4 bar;\n"
1465 "layout (location = 0) in vec4 foo;\n"
1466 "layout (location = 2) in float scale;\n"
GregFaae75242015-06-03 18:40:50 -06001467 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001468 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001469 " outColor = bar * scale + foo * (1.0-scale);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001470 "}\n";
1471
1472 ASSERT_NO_FATAL_FAILURE(InitState());
1473 ASSERT_NO_FATAL_FAILURE(InitViewport());
1474
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001475 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1476 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001477
Tony Barbour6918cd52015-04-09 12:58:51 -06001478 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001479 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001480 pipelineobj.AddShader(&vs);
1481 pipelineobj.AddShader(&ps);
1482
Tony Barbour6918cd52015-04-09 12:58:51 -06001483 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour831062d2015-04-02 15:43:15 -06001484 descriptorSet.AppendDummy();
Tony Barboure2c58df2014-11-25 13:18:32 -07001485
Tony Barbour664accc2015-01-09 12:55:14 -07001486 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour664accc2015-01-09 12:55:14 -07001487
Tony Barbourfe3351b2015-07-28 10:17:20 -06001488 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001489
Tony Barbourfe3351b2015-07-28 10:17:20 -06001490 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001491
1492#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001493 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001494 pDSDumpDot((char*)"triTest2.dot");
1495#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001496
Tony Barbour664accc2015-01-09 12:55:14 -07001497 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001498 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001499
1500 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001501 EndCommandBuffer();
1502 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001503
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001504 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001505}
1506
Tony Barbour6918cd52015-04-09 12:58:51 -06001507TEST_F(VkRenderTest, QuadVertFetchAndVertID)
Tony Barboure2c58df2014-11-25 13:18:32 -07001508{
1509 // This tests that attributes work in the presence of gl_VertexID
1510
1511 static const char *vertShaderText =
1512 "#version 140\n"
1513 "#extension GL_ARB_separate_shader_objects : enable\n"
1514 "#extension GL_ARB_shading_language_420pack : enable\n"
1515 //XYZ1( -1, -1, -1 )
1516 "layout (location = 0) in vec4 pos;\n"
1517 //XYZ1( 0.f, 0.f, 0.f )
1518 "layout (location = 1) in vec4 inColor;\n"
1519 "layout (location = 0) out vec4 outColor;\n"
1520 "void main() {\n"
1521 " outColor = inColor;\n"
1522 " vec4 vertices[3];"
1523 " vertices[gl_VertexID % 3] = pos;\n"
1524 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1525 "}\n";
1526
1527
1528 static const char *fragShaderText =
1529 "#version 140\n"
1530 "#extension GL_ARB_separate_shader_objects : enable\n"
1531 "#extension GL_ARB_shading_language_420pack : enable\n"
1532 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06001533 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001534 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001535 " outColor = color;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001536 "}\n";
1537
1538 ASSERT_NO_FATAL_FAILURE(InitState());
1539 ASSERT_NO_FATAL_FAILURE(InitViewport());
1540
Tony Barbour6918cd52015-04-09 12:58:51 -06001541 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001542 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07001543
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001544 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1545 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001546
Tony Barbour6918cd52015-04-09 12:58:51 -06001547 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001548 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001549 pipelineobj.AddShader(&vs);
1550 pipelineobj.AddShader(&ps);
1551
Tony Barbour6918cd52015-04-09 12:58:51 -06001552 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001553
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001554#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001555 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001556 MESH_BUF_ID, // Binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001557 sizeof(g_vbData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001558 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
Tony Barboure2c58df2014-11-25 13:18:32 -07001559 };
1560
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001561 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001562 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1563 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001564 vi_attribs[0].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001565 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001566 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1567 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001568 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001569 vi_attribs[1].offset = 16; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -07001570
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001571 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001572 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barboure2c58df2014-11-25 13:18:32 -07001573
Tony Barbour664accc2015-01-09 12:55:14 -07001574 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour664accc2015-01-09 12:55:14 -07001575
Tony Barbourfe3351b2015-07-28 10:17:20 -06001576 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001577
Tony Barbourfe3351b2015-07-28 10:17:20 -06001578 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001579
Tony Barbourfe3351b2015-07-28 10:17:20 -06001580 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001581#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001582 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001583 pDSDumpDot((char*)"triTest2.dot");
1584#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001585
1586 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001587 Draw(6, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001588
1589 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001590 EndCommandBuffer();
1591 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001592
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001593 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001594}
1595
Tony Barbour6918cd52015-04-09 12:58:51 -06001596TEST_F(VkRenderTest, QuadSparseVertFetch)
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001597{
1598 // This tests that attributes work in the presence of gl_VertexID
1599
1600 static const char *vertShaderText =
1601 "#version 140\n"
1602 "#extension GL_ARB_separate_shader_objects : enable\n"
1603 "#extension GL_ARB_shading_language_420pack : enable\n"
1604 //XYZ1( -1, -1, -1 )
1605 "layout (location = 1) in vec4 pos;\n"
1606 "layout (location = 4) in vec4 inColor;\n"
1607 //XYZ1( 0.f, 0.f, 0.f )
1608 "layout (location = 0) out vec4 outColor;\n"
1609 "void main() {\n"
1610 " outColor = inColor;\n"
1611 " gl_Position = pos;\n"
1612 "}\n";
1613
1614
1615 static const char *fragShaderText =
1616 "#version 140\n"
1617 "#extension GL_ARB_separate_shader_objects : enable\n"
1618 "#extension GL_ARB_shading_language_420pack : enable\n"
1619 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06001620 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001621 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001622 " outColor = color;\n"
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001623 "}\n";
1624
1625 ASSERT_NO_FATAL_FAILURE(InitState());
1626 ASSERT_NO_FATAL_FAILURE(InitViewport());
1627
1628 struct VDATA
1629 {
1630 float t1, t2, t3, t4; // filler data
1631 float posX, posY, posZ, posW; // Position data
1632 float r, g, b, a; // Color
1633 };
1634 const struct VDATA vData[] =
1635 {
1636 { XYZ1(0, 0, 0), XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
1637 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1638 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1639 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1640 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1641 { XYZ1(0, 0, 0), XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
1642 };
1643
Tony Barbour6918cd52015-04-09 12:58:51 -06001644 VkConstantBufferObj meshBuffer(m_device,sizeof(vData)/sizeof(vData[0]),sizeof(vData[0]), vData);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001645 meshBuffer.BufferMemoryBarrier();
1646
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001647 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1648 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001649
Tony Barbour6918cd52015-04-09 12:58:51 -06001650 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001651 pipelineobj.AddColorAttachment();
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001652 pipelineobj.AddShader(&vs);
1653 pipelineobj.AddShader(&ps);
1654
Tony Barbour6918cd52015-04-09 12:58:51 -06001655 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001656
1657#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001658 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001659 MESH_BUF_ID, // Binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001660 sizeof(vData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001661 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001662 };
1663
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001664 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001665 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1666 vi_attribs[0].location = 4;
Tony Barbourd1c35722015-04-16 15:59:00 -06001667 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001668 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 -06001669 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1670 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001671 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001672 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 -06001673
1674 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
1675 pipelineobj.AddVertexInputBindings(&vi_binding, 1);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001676
1677 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001678
Tony Barbourfe3351b2015-07-28 10:17:20 -06001679 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001680
Tony Barbourfe3351b2015-07-28 10:17:20 -06001681 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001682
Tony Barbourfe3351b2015-07-28 10:17:20 -06001683 BindVertexBuffer(&meshBuffer, 0, MESH_BUF_ID);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001684#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001685 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001686 pDSDumpDot((char*)"triTest2.dot");
1687#endif
1688
1689 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001690 Draw(6, 1, 0, 0);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001691
1692 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001693 EndCommandBuffer();
1694 QueueCommandBuffer();
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001695
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001696 RecordImages(m_renderTargets);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001697}
1698
Tony Barbour6918cd52015-04-09 12:58:51 -06001699TEST_F(VkRenderTest, TriVertFetchDeadAttr)
Tony Barboure2c58df2014-11-25 13:18:32 -07001700{
1701 // This tests that attributes work in the presence of gl_VertexID
1702 // and a dead attribute in position 0. Draws a triangle with yellow,
1703 // red and green corners, starting at top and going clockwise.
1704
1705 static const char *vertShaderText =
1706 "#version 140\n"
1707 "#extension GL_ARB_separate_shader_objects : enable\n"
1708 "#extension GL_ARB_shading_language_420pack : enable\n"
1709 //XYZ1( -1, -1, -1 )
1710 "layout (location = 0) in vec4 pos;\n"
1711 //XYZ1( 0.f, 0.f, 0.f )
1712 "layout (location = 1) in vec4 inColor;\n"
1713 "layout (location = 0) out vec4 outColor;\n"
1714 "void main() {\n"
1715 " outColor = inColor;\n"
1716 " vec2 vertices[3];"
1717 " vertices[0] = vec2(-1.0, -1.0);\n"
1718 " vertices[1] = vec2( 1.0, -1.0);\n"
1719 " vertices[2] = vec2( 0.0, 1.0);\n"
1720 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1721 "}\n";
1722
1723
1724 static const char *fragShaderText =
1725 "#version 140\n"
1726 "#extension GL_ARB_separate_shader_objects : enable\n"
1727 "#extension GL_ARB_shading_language_420pack : enable\n"
1728 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06001729 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001730 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001731 " outColor = color;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001732 "}\n";
1733
1734 ASSERT_NO_FATAL_FAILURE(InitState());
1735 ASSERT_NO_FATAL_FAILURE(InitViewport());
1736
Tony Barbour6918cd52015-04-09 12:58:51 -06001737 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001738 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07001739
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001740 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1741 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001742
Tony Barbour6918cd52015-04-09 12:58:51 -06001743 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001744 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001745 pipelineobj.AddShader(&vs);
1746 pipelineobj.AddShader(&ps);
1747
Tony Barbour6918cd52015-04-09 12:58:51 -06001748 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001749
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001750#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001751 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001752 MESH_BUF_ID, // Binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001753 sizeof(g_vbData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001754 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
Tony Barboure2c58df2014-11-25 13:18:32 -07001755 };
1756
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001757 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001758 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1759 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001760 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001761 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001762 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1763 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001764 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001765 vi_attribs[1].offset = 16; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -07001766
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001767 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001768 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barboure2c58df2014-11-25 13:18:32 -07001769
Tony Barbour664accc2015-01-09 12:55:14 -07001770 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboure2c58df2014-11-25 13:18:32 -07001771
Tony Barbourfe3351b2015-07-28 10:17:20 -06001772 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001773
Tony Barbourfe3351b2015-07-28 10:17:20 -06001774 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001775
Tony Barbourfe3351b2015-07-28 10:17:20 -06001776 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001777#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001778 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001779 pDSDumpDot((char*)"triTest2.dot");
1780#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001781
1782 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001783 Draw(6, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001784
1785 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001786 EndCommandBuffer();
1787 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001788
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001789 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001790}
1791
Tony Barbour6918cd52015-04-09 12:58:51 -06001792TEST_F(VkRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001793{
1794 static const char *vertShaderText =
1795 "#version 140\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001796 "#extension GL_ARB_separate_shader_objects : enable\n"
1797 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06001798 "layout (std140, binding = 0) uniform bufferVals {\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001799 " mat4 mvp;\n"
1800 "} myBufferVals;\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001801 "layout (location = 0) in vec4 pos;\n"
1802 "layout (location = 1) in vec4 inColor;\n"
Cody Northrop8a3bb132015-06-16 17:32:04 -06001803 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001804 "void main() {\n"
1805 " outColor = inColor;\n"
1806 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06001807 " gl_Position.y = -gl_Position.y;\n"
1808 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001809 "}\n";
1810
1811 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -06001812 "#version 140\n"
1813 "#extension GL_ARB_separate_shader_objects : enable\n"
1814 "#extension GL_ARB_shading_language_420pack : enable\n"
1815 "layout (location = 0) in vec4 color;\n"
1816 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001817 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001818 " outColor = color;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001819 "}\n";
Tony Barboure2c58df2014-11-25 13:18:32 -07001820 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001821
Tony Barboure2c58df2014-11-25 13:18:32 -07001822 glm::mat4 View = glm::lookAt(
1823 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1824 glm::vec3(0,0,0), // and looks at the origin
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06001825 glm::vec3(0,-1,0) // Head is up (set to 0,-1,0 to look upside-down)
Tony Barboure2c58df2014-11-25 13:18:32 -07001826 );
1827
1828 glm::mat4 Model = glm::mat4(1.0f);
1829
1830 glm::mat4 MVP = Projection * View * Model;
1831
1832 ASSERT_NO_FATAL_FAILURE(InitState());
1833 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wub4052042015-07-09 10:16:34 +08001834 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Chia-I Wu08accc62015-07-07 11:50:03 +08001835 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height, m_depth_stencil_fmt);
Tony Barboure2c58df2014-11-25 13:18:32 -07001836
Tony Barbour6918cd52015-04-09 12:58:51 -06001837 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 -07001838 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1839
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001840 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barboure2c58df2014-11-25 13:18:32 -07001841
Tony Barbour6918cd52015-04-09 12:58:51 -06001842 VkConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001843 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1844 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001845
Tony Barbour6918cd52015-04-09 12:58:51 -06001846 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001847 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001848 pipelineobj.AddShader(&vs);
1849 pipelineobj.AddShader(&ps);
1850
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001851 VkPipelineDepthStencilStateCreateInfo ds_state;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001852 ds_state.depthTestEnable = VK_TRUE;
1853 ds_state.depthWriteEnable = VK_TRUE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001854 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL;
Cody Northrop271ba752015-08-26 10:01:32 -06001855 ds_state.depthBoundsTestEnable = VK_FALSE;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001856 ds_state.stencilTestEnable = VK_FALSE;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001857 ds_state.back.depthFailOp = VK_STENCIL_OP_KEEP;
1858 ds_state.back.failOp = VK_STENCIL_OP_KEEP;
1859 ds_state.back.passOp = VK_STENCIL_OP_KEEP;
1860 ds_state.back.compareOp = VK_COMPARE_OP_ALWAYS;
Tony Barbourf52346d2015-01-16 14:27:35 -07001861 ds_state.front = ds_state.back;
1862 pipelineobj.SetDepthStencil(&ds_state);
1863
Tony Barbour6918cd52015-04-09 12:58:51 -06001864 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001865 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07001866
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001867#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001868 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001869 MESH_BUF_ID, // Binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001870 sizeof(g_vbData[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001871 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001872 };
Tony Barboure2c58df2014-11-25 13:18:32 -07001873
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001874 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001875 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1876 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001877 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001878 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001879 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1880 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001881 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08001882 vi_attribs[1].offset = 16; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -07001883
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001884 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001885 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barboure2c58df2014-11-25 13:18:32 -07001886
Tony Barbour1c45ce02015-03-27 17:03:18 -06001887 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour1c45ce02015-03-27 17:03:18 -06001888
Tony Barbourfe3351b2015-07-28 10:17:20 -06001889 ASSERT_VK_SUCCESS(BeginCommandBuffer());
1890 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barboure2c58df2014-11-25 13:18:32 -07001891
Tony Barbourfe3351b2015-07-28 10:17:20 -06001892 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour1fde6942015-01-09 10:06:53 -07001893#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001894 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour1fde6942015-01-09 10:06:53 -07001895 pDSDumpDot((char*)"triTest2.dot");
1896#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001897
1898 // render triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001899 Draw(36, 1, 0, 0);
Tony Barbour1fde6942015-01-09 10:06:53 -07001900
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001901
Tony Barbour1fde6942015-01-09 10:06:53 -07001902 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001903 EndCommandBuffer();
1904 QueueCommandBuffer();
Tony Barbour1fde6942015-01-09 10:06:53 -07001905
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001906 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001907}
1908
Tony Barbour6918cd52015-04-09 12:58:51 -06001909TEST_F(VkRenderTest, VSTexture)
Tony Barboure2c58df2014-11-25 13:18:32 -07001910{
1911 // The expected result from this test is a green and red triangle;
1912 // one red vertex on the left, two green vertices on the right.
1913 static const char *vertShaderText =
Cody Northrop8a3bb132015-06-16 17:32:04 -06001914 "#version 140\n"
1915 "#extension GL_ARB_separate_shader_objects : enable\n"
1916 "#extension GL_ARB_shading_language_420pack : enable\n"
1917 "layout (location = 0) out vec4 texColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001918 "uniform sampler2D surface;\n"
1919 "void main() {\n"
1920 " vec2 vertices[3];"
1921 " vertices[0] = vec2(-0.5, -0.5);\n"
1922 " vertices[1] = vec2( 0.5, -0.5);\n"
1923 " vertices[2] = vec2( 0.5, 0.5);\n"
1924 " vec2 positions[3];"
1925 " positions[0] = vec2( 0.0, 0.0);\n"
1926 " positions[1] = vec2( 0.25, 0.1);\n"
1927 " positions[2] = vec2( 0.1, 0.25);\n"
1928 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1929 " texColor = textureLod(surface, samplePos, 0.0);\n"
1930 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1931 "}\n";
1932
1933 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -06001934 "#version 140\n"
1935 "#extension GL_ARB_separate_shader_objects : enable\n"
1936 "#extension GL_ARB_shading_language_420pack : enable\n"
1937 "layout (location = 0) in vec4 texColor;\n"
1938 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001939 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001940 " outColor = texColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001941 "}\n";
1942
1943 ASSERT_NO_FATAL_FAILURE(InitState());
1944 ASSERT_NO_FATAL_FAILURE(InitViewport());
1945
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001946 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1947 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbour6918cd52015-04-09 12:58:51 -06001948 VkSamplerObj sampler(m_device);
1949 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07001950
Tony Barbour6918cd52015-04-09 12:58:51 -06001951 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001952 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001953 pipelineobj.AddShader(&vs);
1954 pipelineobj.AddShader(&ps);
1955
Tony Barbour6918cd52015-04-09 12:58:51 -06001956 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08001957 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07001958
Tony Barbour664accc2015-01-09 12:55:14 -07001959 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001960 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure2c58df2014-11-25 13:18:32 -07001961
Tony Barbourfe3351b2015-07-28 10:17:20 -06001962 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001963
1964#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001965 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001966 pDSDumpDot((char*)"triTest2.dot");
1967#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001968
Tony Barbour664accc2015-01-09 12:55:14 -07001969 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001970 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001971
1972 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001973 EndCommandBuffer();
1974 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001975
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001976 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001977}
GregFaae75242015-06-03 18:40:50 -06001978
1979
1980
Tony Barbour6918cd52015-04-09 12:58:51 -06001981TEST_F(VkRenderTest, TexturedTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07001982{
1983 // The expected result from this test is a red and green checkered triangle
1984 static const char *vertShaderText =
1985 "#version 140\n"
1986 "#extension GL_ARB_separate_shader_objects : enable\n"
1987 "#extension GL_ARB_shading_language_420pack : enable\n"
1988 "layout (location = 0) out vec2 samplePos;\n"
1989 "void main() {\n"
1990 " vec2 vertices[3];"
1991 " vertices[0] = vec2(-0.5, -0.5);\n"
1992 " vertices[1] = vec2( 0.5, -0.5);\n"
1993 " vertices[2] = vec2( 0.5, 0.5);\n"
1994 " vec2 positions[3];"
1995 " positions[0] = vec2( 0.0, 0.0);\n"
1996 " positions[1] = vec2( 1.0, 0.0);\n"
1997 " positions[2] = vec2( 1.0, 1.0);\n"
1998 " samplePos = positions[gl_VertexID % 3];\n"
1999 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2000 "}\n";
2001
2002 static const char *fragShaderText =
2003 "#version 140\n"
2004 "#extension GL_ARB_separate_shader_objects : enable\n"
2005 "#extension GL_ARB_shading_language_420pack : enable\n"
2006 "layout (location = 0) in vec2 samplePos;\n"
2007 "layout (binding = 0) uniform sampler2D surface;\n"
2008 "layout (location=0) out vec4 outColor;\n"
2009 "void main() {\n"
2010 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2011 " outColor = texColor;\n"
2012 "}\n";
2013
2014 ASSERT_NO_FATAL_FAILURE(InitState());
2015 ASSERT_NO_FATAL_FAILURE(InitViewport());
2016
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002017 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2018 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbour6918cd52015-04-09 12:58:51 -06002019 VkSamplerObj sampler(m_device);
2020 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002021
Tony Barbour6918cd52015-04-09 12:58:51 -06002022 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002023 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002024 pipelineobj.AddShader(&vs);
2025 pipelineobj.AddShader(&ps);
2026
Tony Barbour6918cd52015-04-09 12:58:51 -06002027 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002028 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002029
Tony Barbour664accc2015-01-09 12:55:14 -07002030 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002031 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002032
Tony Barbourfe3351b2015-07-28 10:17:20 -06002033 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002034
2035#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002036 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002037 pDSDumpDot((char*)"triTest2.dot");
2038#endif
2039 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002040 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002041
2042 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002043 EndCommandBuffer();
2044 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002045
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002046 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002047}
Tony Barbour6918cd52015-04-09 12:58:51 -06002048TEST_F(VkRenderTest, TexturedTriangleClip)
Tony Barboure2c58df2014-11-25 13:18:32 -07002049{
2050 // The expected result from this test is a red and green checkered triangle
2051 static const char *vertShaderText =
2052 "#version 330\n"
2053 "#extension GL_ARB_separate_shader_objects : enable\n"
2054 "#extension GL_ARB_shading_language_420pack : enable\n"
2055 "layout (location = 0) out vec2 samplePos;\n"
2056 "out gl_PerVertex {\n"
2057 " vec4 gl_Position;\n"
2058 " float gl_ClipDistance[1];\n"
2059 "};\n"
2060 "void main() {\n"
2061 " vec2 vertices[3];"
2062 " vertices[0] = vec2(-0.5, -0.5);\n"
2063 " vertices[1] = vec2( 0.5, -0.5);\n"
2064 " vertices[2] = vec2( 0.5, 0.5);\n"
2065 " vec2 positions[3];"
2066 " positions[0] = vec2( 0.0, 0.0);\n"
2067 " positions[1] = vec2( 1.0, 0.0);\n"
2068 " positions[2] = vec2( 1.0, 1.0);\n"
2069 " float dists[3];\n"
2070 " dists[0] = 1.0;\n"
2071 " dists[1] = 1.0;\n"
2072 " dists[2] = -1.0;\n"
2073 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2074 " samplePos = positions[gl_VertexID % 3];\n"
2075 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2076 "}\n";
2077
2078 static const char *fragShaderText =
2079 "#version 140\n"
2080 "#extension GL_ARB_separate_shader_objects : enable\n"
2081 "#extension GL_ARB_shading_language_420pack : enable\n"
2082 "layout (location = 0) in vec2 samplePos;\n"
2083 "layout (binding = 0) uniform sampler2D surface;\n"
2084 "layout (location=0) out vec4 outColor;\n"
2085 "void main() {\n"
2086 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2087 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2088 " outColor = texColor;\n"
2089 "}\n";
2090
2091
2092 ASSERT_NO_FATAL_FAILURE(InitState());
2093 ASSERT_NO_FATAL_FAILURE(InitViewport());
2094
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002095 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2096 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbour6918cd52015-04-09 12:58:51 -06002097 VkSamplerObj sampler(m_device);
2098 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002099
Tony Barbour6918cd52015-04-09 12:58:51 -06002100 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002101 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002102 pipelineobj.AddShader(&vs);
2103 pipelineobj.AddShader(&ps);
2104
Tony Barbour6918cd52015-04-09 12:58:51 -06002105 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002106 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002107
Tony Barbour664accc2015-01-09 12:55:14 -07002108 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002109 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002110
Tony Barbourfe3351b2015-07-28 10:17:20 -06002111 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002112
2113#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002114 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002115 pDSDumpDot((char*)"triTest2.dot");
2116#endif
2117 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002118 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002119
2120 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002121 EndCommandBuffer();
2122 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002123
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002124 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002125}
GregFaae75242015-06-03 18:40:50 -06002126
Tony Barbour6918cd52015-04-09 12:58:51 -06002127TEST_F(VkRenderTest, FSTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07002128{
2129 // The expected result from this test is a red and green checkered triangle
2130 static const char *vertShaderText =
2131 "#version 140\n"
2132 "#extension GL_ARB_separate_shader_objects : enable\n"
2133 "#extension GL_ARB_shading_language_420pack : enable\n"
2134 "layout (location = 0) out vec2 samplePos;\n"
2135 "void main() {\n"
2136 " vec2 vertices[3];"
2137 " vertices[0] = vec2(-0.5, -0.5);\n"
2138 " vertices[1] = vec2( 0.5, -0.5);\n"
2139 " vertices[2] = vec2( 0.5, 0.5);\n"
2140 " vec2 positions[3];"
2141 " positions[0] = vec2( 0.0, 0.0);\n"
2142 " positions[1] = vec2( 1.0, 0.0);\n"
2143 " positions[2] = vec2( 1.0, 1.0);\n"
2144 " samplePos = positions[gl_VertexID % 3];\n"
2145 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2146 "}\n";
2147
2148 static const char *fragShaderText =
2149 "#version 140\n"
2150 "#extension GL_ARB_separate_shader_objects : enable\n"
2151 "#extension GL_ARB_shading_language_420pack : enable\n"
2152 "layout (location = 0) in vec2 samplePos;\n"
2153 "layout (binding = 0) uniform sampler2D surface;\n"
2154 "layout (location=0) out vec4 outColor;\n"
2155 "void main() {\n"
2156 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2157 " outColor = texColor;\n"
2158 "}\n";
2159
2160 ASSERT_NO_FATAL_FAILURE(InitState());
2161 ASSERT_NO_FATAL_FAILURE(InitViewport());
2162
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002163 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2164 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbour6918cd52015-04-09 12:58:51 -06002165 VkSamplerObj sampler(m_device);
2166 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002167
Tony Barbour6918cd52015-04-09 12:58:51 -06002168 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002169 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002170 pipelineobj.AddShader(&vs);
2171 pipelineobj.AddShader(&ps);
2172
Tony Barbour6918cd52015-04-09 12:58:51 -06002173 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002174 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002175
Tony Barbour664accc2015-01-09 12:55:14 -07002176 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002177 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002178
Tony Barbourfe3351b2015-07-28 10:17:20 -06002179 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002180
2181#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002182 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002183 pDSDumpDot((char*)"triTest2.dot");
2184#endif
2185 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002186 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002187
2188 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002189 EndCommandBuffer();
2190 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002191
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002192 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002193}
Tony Barbour6918cd52015-04-09 12:58:51 -06002194TEST_F(VkRenderTest, SamplerBindingsTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07002195{
2196 // This test sets bindings on the samplers
2197 // For now we are asserting that sampler and texture pairs
2198 // march in lock step, and are set via GLSL binding. This can
2199 // and will probably change.
2200 // The sampler bindings should match the sampler and texture slot
2201 // number set up by the application.
2202 // This test will result in a blue triangle
2203 static const char *vertShaderText =
2204 "#version 140\n"
2205 "#extension GL_ARB_separate_shader_objects : enable\n"
2206 "#extension GL_ARB_shading_language_420pack : enable\n"
2207 "layout (location = 0) out vec4 samplePos;\n"
2208 "void main() {\n"
2209 " vec2 vertices[3];"
2210 " vertices[0] = vec2(-0.5, -0.5);\n"
2211 " vertices[1] = vec2( 0.5, -0.5);\n"
2212 " vertices[2] = vec2( 0.5, 0.5);\n"
2213 " vec2 positions[3];"
2214 " positions[0] = vec2( 0.0, 0.0);\n"
2215 " positions[1] = vec2( 1.0, 0.0);\n"
2216 " positions[2] = vec2( 1.0, 1.0);\n"
2217 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2218 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2219 "}\n";
2220
2221 static const char *fragShaderText =
2222 "#version 140\n"
2223 "#extension GL_ARB_separate_shader_objects : enable\n"
2224 "#extension GL_ARB_shading_language_420pack : enable\n"
2225 "layout (location = 0) in vec4 samplePos;\n"
2226 "layout (binding = 0) uniform sampler2D surface0;\n"
2227 "layout (binding = 1) uniform sampler2D surface1;\n"
2228 "layout (binding = 12) uniform sampler2D surface2;\n"
GregFaae75242015-06-03 18:40:50 -06002229 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002230 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06002231 " outColor = textureLod(surface2, samplePos.xy, 0.0);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002232 "}\n";
2233
2234 ASSERT_NO_FATAL_FAILURE(InitState());
2235 ASSERT_NO_FATAL_FAILURE(InitViewport());
2236
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002237 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2238 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002239
Tony Barbour6918cd52015-04-09 12:58:51 -06002240 VkSamplerObj sampler1(m_device);
2241 VkSamplerObj sampler2(m_device);
2242 VkSamplerObj sampler3(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002243
Tony Barbourebc093f2015-04-01 16:38:10 -06002244 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
Tony Barbour6918cd52015-04-09 12:58:51 -06002245 VkTextureObj texture1(m_device, tex_colors); // Red
Tony Barbourebc093f2015-04-01 16:38:10 -06002246 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
Tony Barbour6918cd52015-04-09 12:58:51 -06002247 VkTextureObj texture2(m_device, tex_colors); // Green
Tony Barbourebc093f2015-04-01 16:38:10 -06002248 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
Tony Barbour6918cd52015-04-09 12:58:51 -06002249 VkTextureObj texture3(m_device, tex_colors); // Blue
Tony Barboure2c58df2014-11-25 13:18:32 -07002250
Tony Barbour6918cd52015-04-09 12:58:51 -06002251 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002252 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002253 pipelineobj.AddShader(&vs);
2254 pipelineobj.AddShader(&ps);
2255
Tony Barbour6918cd52015-04-09 12:58:51 -06002256 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002257 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2258 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2259 for (int i = 0; i < 10; i++)
2260 descriptorSet.AppendDummy();
2261 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barboure2c58df2014-11-25 13:18:32 -07002262
Tony Barbour664accc2015-01-09 12:55:14 -07002263 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002264 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002265
Tony Barbourfe3351b2015-07-28 10:17:20 -06002266 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002267
2268#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002269 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002270 pDSDumpDot((char*)"triTest2.dot");
2271#endif
2272 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002273 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002274
2275 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002276 EndCommandBuffer();
2277 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002278
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002279 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002280}
2281
Tony Barbour6918cd52015-04-09 12:58:51 -06002282TEST_F(VkRenderTest, TriangleVSUniformBlock)
Tony Barboure2c58df2014-11-25 13:18:32 -07002283{
2284 // The expected result from this test is a blue triangle
2285
2286 static const char *vertShaderText =
2287 "#version 140\n"
2288 "#extension GL_ARB_separate_shader_objects : enable\n"
2289 "#extension GL_ARB_shading_language_420pack : enable\n"
2290 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002291 "layout (std140, binding = 0) uniform bufferVals {\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002292 " vec4 red;\n"
2293 " vec4 green;\n"
2294 " vec4 blue;\n"
2295 " vec4 white;\n"
2296 "} myBufferVals;\n"
2297 "void main() {\n"
2298 " vec2 vertices[3];"
2299 " vertices[0] = vec2(-0.5, -0.5);\n"
2300 " vertices[1] = vec2( 0.5, -0.5);\n"
2301 " vertices[2] = vec2( 0.5, 0.5);\n"
2302 " outColor = myBufferVals.blue;\n"
2303 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2304 "}\n";
2305
2306 static const char *fragShaderText =
2307 "#version 140\n"
2308 "#extension GL_ARB_separate_shader_objects : enable\n"
2309 "#extension GL_ARB_shading_language_420pack : enable\n"
2310 "layout (location = 0) in vec4 inColor;\n"
GregFaae75242015-06-03 18:40:50 -06002311 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002312 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06002313 " outColor = inColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002314 "}\n";
2315
2316 ASSERT_NO_FATAL_FAILURE(InitState());
2317 ASSERT_NO_FATAL_FAILURE(InitViewport());
2318
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002319 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2320 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002321
2322 // Let's populate our buffer with the following:
2323 // vec4 red;
2324 // vec4 green;
2325 // vec4 blue;
2326 // vec4 white;
2327 const int valCount = 4 * 4;
2328 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2329 0.0, 1.0, 0.0, 1.0,
2330 0.0, 0.0, 1.0, 1.0,
2331 1.0, 1.0, 1.0, 1.0 };
2332
Tony Barbour6918cd52015-04-09 12:58:51 -06002333 VkConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002334
Tony Barbour6918cd52015-04-09 12:58:51 -06002335 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002336 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002337 pipelineobj.AddShader(&vs);
2338 pipelineobj.AddShader(&ps);
2339
Tony Barbour6918cd52015-04-09 12:58:51 -06002340 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002341 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, colorBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002342
Tony Barbour664accc2015-01-09 12:55:14 -07002343 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002344 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002345
Tony Barbourfe3351b2015-07-28 10:17:20 -06002346 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002347
2348#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002349 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002350 pDSDumpDot((char*)"triTest2.dot");
2351#endif
2352 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002353 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002354
2355 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002356 EndCommandBuffer();
2357 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002358
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002359 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002360}
2361
Tony Barbour6918cd52015-04-09 12:58:51 -06002362TEST_F(VkRenderTest, TriangleFSUniformBlockBinding)
Tony Barboure2c58df2014-11-25 13:18:32 -07002363{
2364 // This test allows the shader to select which buffer it is
2365 // pulling from using layout binding qualifier.
2366 // There are corresponding changes in the compiler stack that
2367 // will select the buffer using binding directly.
2368 // The binding number should match the slot number set up by
2369 // the application.
2370 // The expected result from this test is a purple triangle
2371
2372 static const char *vertShaderText =
2373 "#version 140\n"
2374 "#extension GL_ARB_separate_shader_objects : enable\n"
2375 "#extension GL_ARB_shading_language_420pack : enable\n"
2376 "void main() {\n"
2377 " vec2 vertices[3];"
2378 " vertices[0] = vec2(-0.5, -0.5);\n"
2379 " vertices[1] = vec2( 0.5, -0.5);\n"
2380 " vertices[2] = vec2( 0.5, 0.5);\n"
2381 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2382 "}\n";
2383
2384 static const char *fragShaderText =
2385 "#version 140\n"
2386 "#extension GL_ARB_separate_shader_objects : enable\n"
2387 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002388 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2389 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2390 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
2391 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
GregFaae75242015-06-03 18:40:50 -06002392 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002393 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06002394 " outColor = myBlueVal.color;\n"
2395 " outColor += myRedVal.color;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002396 "}\n";
2397
2398 ASSERT_NO_FATAL_FAILURE(InitState());
2399 ASSERT_NO_FATAL_FAILURE(InitViewport());
2400
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002401 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2402 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002403
2404 // We're going to create a number of uniform buffers, and then allow
2405 // the shader to select which it wants to read from with a binding
2406
2407 // Let's populate the buffers with a single color each:
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002408 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2409 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2410 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2411 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barboure2c58df2014-11-25 13:18:32 -07002412
2413 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2414 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2415 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2416 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2417
2418 const int redCount = sizeof(redVals) / sizeof(float);
2419 const int greenCount = sizeof(greenVals) / sizeof(float);
2420 const int blueCount = sizeof(blueVals) / sizeof(float);
2421 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2422
Tony Barbour6918cd52015-04-09 12:58:51 -06002423 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002424
Tony Barbour6918cd52015-04-09 12:58:51 -06002425 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002426
Tony Barbour6918cd52015-04-09 12:58:51 -06002427 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002428
Tony Barbour6918cd52015-04-09 12:58:51 -06002429 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002430
Tony Barbour6918cd52015-04-09 12:58:51 -06002431 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002432 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002433 pipelineobj.AddShader(&vs);
2434 pipelineobj.AddShader(&ps);
2435
Tony Barbour6918cd52015-04-09 12:58:51 -06002436 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002437 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2438 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2439 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2440 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002441
Tony Barbour664accc2015-01-09 12:55:14 -07002442 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002443 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure2c58df2014-11-25 13:18:32 -07002444
Tony Barbourfe3351b2015-07-28 10:17:20 -06002445 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002446
2447#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002448 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002449 pDSDumpDot((char*)"triTest2.dot");
2450#endif
2451 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002452 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002453
2454 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002455 EndCommandBuffer();
2456 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002457
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002458 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002459}
2460
Tony Barbour6918cd52015-04-09 12:58:51 -06002461TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBinding)
Tony Barboure2c58df2014-11-25 13:18:32 -07002462{
2463 // This test is the same as TriangleFSUniformBlockBinding, but
2464 // it does not provide an instance name.
2465 // The expected result from this test is a purple triangle
2466
2467 static const char *vertShaderText =
2468 "#version 140\n"
2469 "#extension GL_ARB_separate_shader_objects : enable\n"
2470 "#extension GL_ARB_shading_language_420pack : enable\n"
2471 "void main() {\n"
2472 " vec2 vertices[3];"
2473 " vertices[0] = vec2(-0.5, -0.5);\n"
2474 " vertices[1] = vec2( 0.5, -0.5);\n"
2475 " vertices[2] = vec2( 0.5, 0.5);\n"
2476 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2477 "}\n";
2478
2479 static const char *fragShaderText =
2480 "#version 430\n"
2481 "#extension GL_ARB_separate_shader_objects : enable\n"
2482 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002483 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2484 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2485 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2486 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northropd43c52e2014-12-05 15:44:14 -07002487 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002488 "void main() {\n"
Cody Northropd43c52e2014-12-05 15:44:14 -07002489 " outColor = blue;\n"
2490 " outColor += red;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002491 "}\n";
2492 ASSERT_NO_FATAL_FAILURE(InitState());
2493 ASSERT_NO_FATAL_FAILURE(InitViewport());
2494
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002495 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2496 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002497
2498 // We're going to create a number of uniform buffers, and then allow
2499 // the shader to select which it wants to read from with a binding
2500
2501 // Let's populate the buffers with a single color each:
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002502 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2503 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2504 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2505 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barboure2c58df2014-11-25 13:18:32 -07002506
2507 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2508 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2509 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2510 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2511
2512 const int redCount = sizeof(redVals) / sizeof(float);
2513 const int greenCount = sizeof(greenVals) / sizeof(float);
2514 const int blueCount = sizeof(blueVals) / sizeof(float);
2515 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2516
Tony Barbour6918cd52015-04-09 12:58:51 -06002517 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002518
Tony Barbour6918cd52015-04-09 12:58:51 -06002519 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002520
Tony Barbour6918cd52015-04-09 12:58:51 -06002521 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002522
Tony Barbour6918cd52015-04-09 12:58:51 -06002523 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002524
Tony Barbour6918cd52015-04-09 12:58:51 -06002525 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002526 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002527 pipelineobj.AddShader(&vs);
2528 pipelineobj.AddShader(&ps);
2529
Tony Barbour6918cd52015-04-09 12:58:51 -06002530 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002531 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2532 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2533 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2534 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002535
Tony Barbour664accc2015-01-09 12:55:14 -07002536 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002537 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002538
Tony Barbourfe3351b2015-07-28 10:17:20 -06002539 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002540
2541#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002542 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002543 pDSDumpDot((char*)"triTest2.dot");
2544#endif
2545 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002546 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002547
2548 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002549 EndCommandBuffer();
2550 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002551
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002552 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002553}
2554
GregF6084aec2015-07-01 16:11:09 -06002555TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBindingWithStruct)
2556{
2557 // This test is the same as TriangleFSUniformBlockBinding, but
2558 // it does not provide an instance name.
2559 // The expected result from this test is a purple triangle
2560
2561 static const char *vertShaderText =
2562 "#version 140\n"
2563 "#extension GL_ARB_separate_shader_objects : enable\n"
2564 "#extension GL_ARB_shading_language_420pack : enable\n"
2565 "void main() {\n"
2566 " vec2 vertices[3];"
2567 " vertices[0] = vec2(-0.5, -0.5);\n"
2568 " vertices[1] = vec2( 0.5, -0.5);\n"
2569 " vertices[2] = vec2( 0.5, 0.5);\n"
2570 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2571 "}\n";
2572
2573 static const char *fragShaderText =
2574 "#version 430\n"
2575 "#extension GL_ARB_separate_shader_objects : enable\n"
2576 "#extension GL_ARB_shading_language_420pack : enable\n"
2577 "\n"
2578 " struct PS_INPUT {\n"
2579 " vec2 member0;\n"
2580 " vec4 member1;\n"
2581 " vec4 member2;\n"
2582 " vec4 member3;\n"
2583 " vec4 member4;\n"
2584 " vec4 member5;\n"
2585 " vec4 member6;\n"
2586 " vec4 member7;\n"
2587 " vec4 member8;\n"
2588 " vec4 member9;\n"
2589 " };\n"
2590 "\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002591 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2592 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2593 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2594 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
GregF6084aec2015-07-01 16:11:09 -06002595 "layout (location = 0) out vec4 outColor;\n"
2596 "PS_INPUT MainFs()\n"
2597 "{\n"
2598 " PS_INPUT o;\n"
2599 " o.member9 = red;\n"
2600 " return o;\n"
2601 "}\n"
2602 "\n"
2603 "void main()\n"
2604 "{\n"
2605 " PS_INPUT o;\n"
2606 " o = MainFs();\n"
2607 " outColor = blue;"
2608 " outColor += o.member9;\n"
2609 "}\n";;
2610 ASSERT_NO_FATAL_FAILURE(InitState());
2611 ASSERT_NO_FATAL_FAILURE(InitViewport());
2612
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002613 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2614 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
GregF6084aec2015-07-01 16:11:09 -06002615
2616 // We're going to create a number of uniform buffers, and then allow
2617 // the shader to select which it wants to read from with a binding
2618
2619 // Let's populate the buffers with a single color each:
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002620 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2621 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2622 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2623 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
GregF6084aec2015-07-01 16:11:09 -06002624
2625 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2626 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2627 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2628 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2629
2630 const int redCount = sizeof(redVals) / sizeof(float);
2631 const int greenCount = sizeof(greenVals) / sizeof(float);
2632 const int blueCount = sizeof(blueVals) / sizeof(float);
2633 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2634
2635 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2636
2637 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2638
2639 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2640
2641 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
2642
2643 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002644 pipelineobj.AddColorAttachment();
GregF6084aec2015-07-01 16:11:09 -06002645 pipelineobj.AddShader(&vs);
2646 pipelineobj.AddShader(&ps);
2647
2648 VkDescriptorSetObj descriptorSet(m_device);
2649 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2650 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2651 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2652 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
2653
2654 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002655 ASSERT_VK_SUCCESS(BeginCommandBuffer());
GregF6084aec2015-07-01 16:11:09 -06002656
Tony Barbourfe3351b2015-07-28 10:17:20 -06002657 GenericDrawPreparation(pipelineobj, descriptorSet);
GregF6084aec2015-07-01 16:11:09 -06002658
2659#ifdef DUMP_STATE_DOT
2660 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
2661 pDSDumpDot((char*)"triTest2.dot");
2662#endif
2663 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002664 Draw(3, 1, 0, 0);
GregF6084aec2015-07-01 16:11:09 -06002665
2666 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002667 EndCommandBuffer();
2668 QueueCommandBuffer();
GregF6084aec2015-07-01 16:11:09 -06002669
2670 RecordImages(m_renderTargets);
2671}
2672
Tony Barbour6918cd52015-04-09 12:58:51 -06002673TEST_F(VkRenderTest, CubeWithVertexFetchAndMVPAndTexture)
Tony Barboure2c58df2014-11-25 13:18:32 -07002674{
2675 static const char *vertShaderText =
2676 "#version 140\n"
2677 "#extension GL_ARB_separate_shader_objects : enable\n"
2678 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002679 "layout (std140, binding=0) uniform bufferVals {\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002680 " mat4 mvp;\n"
2681 "} myBufferVals;\n"
2682 "layout (location=0) in vec4 pos;\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002683 "layout (location=1) in vec2 input_uv;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002684 "layout (location=0) out vec2 UV;\n"
2685 "void main() {\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002686 " UV = input_uv;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002687 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002688 " gl_Position.y = -gl_Position.y;\n"
2689 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002690 "}\n";
2691
2692 static const char *fragShaderText =
2693 "#version 140\n"
2694 "#extension GL_ARB_separate_shader_objects : enable\n"
2695 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wu11078b02015-01-04 16:27:24 +08002696 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002697 "layout (location=0) out vec4 outColor;\n"
2698 "layout (location=0) in vec2 UV;\n"
2699 "void main() {\n"
2700 " outColor= textureLod(surface, UV, 0.0);\n"
2701 "}\n";
2702 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2703
2704 glm::mat4 View = glm::lookAt(
2705 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2706 glm::vec3(0,0,0), // and looks at the origin
2707 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2708 );
2709
2710 glm::mat4 Model = glm::mat4(1.0f);
2711
2712 glm::mat4 MVP = Projection * View * Model;
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002713 int num_verts = sizeof(g_vb_texture_Data) / sizeof(g_vb_texture_Data[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002714
2715
2716 ASSERT_NO_FATAL_FAILURE(InitState());
2717 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wub4052042015-07-09 10:16:34 +08002718 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Chia-I Wu08accc62015-07-07 11:50:03 +08002719 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height, m_depth_stencil_fmt);
Tony Barboure2c58df2014-11-25 13:18:32 -07002720
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002721 VkConstantBufferObj meshBuffer(m_device, num_verts,
2722 sizeof(g_vb_texture_Data[0]), g_vb_texture_Data);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00002723 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07002724
Mark Lobodzinski17caf572015-01-29 08:55:56 -06002725 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barboure2c58df2014-11-25 13:18:32 -07002726
Tony Barbour6918cd52015-04-09 12:58:51 -06002727 VkConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002728 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2729 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbour6918cd52015-04-09 12:58:51 -06002730 VkSamplerObj sampler(m_device);
2731 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002732
Tony Barbour6918cd52015-04-09 12:58:51 -06002733 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002734 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002735 pipelineobj.AddShader(&vs);
2736 pipelineobj.AddShader(&ps);
2737
Tony Barbour6918cd52015-04-09 12:58:51 -06002738 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002739 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mvpBuffer);
Chia-I Wu11078b02015-01-04 16:27:24 +08002740 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002741
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002742#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002743 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002744 MESH_BIND_ID, // binding ID
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08002745 sizeof(g_vb_texture_Data[0]), // stride; Distance between vertices in bytes (0 = no advancement)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002746 VK_VERTEX_INPUT_RATE_VERTEX // inputRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002747 };
Tony Barboure2c58df2014-11-25 13:18:32 -07002748
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002749 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002750 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2751 vi_attribs[0].location = 0; // location
Tony Barbourd1c35722015-04-16 15:59:00 -06002752 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08002753 vi_attribs[0].offset = 0; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002754 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2755 vi_attribs[1].location = 1; // location
2756 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Chia-I Wu2bfb33c2015-10-26 17:24:52 +08002757 vi_attribs[1].offset = 16; // Offset of uv components
Tony Barboure2c58df2014-11-25 13:18:32 -07002758
Tony Barboure2c58df2014-11-25 13:18:32 -07002759 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002760 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barboure2c58df2014-11-25 13:18:32 -07002761
Tony Barbourdd6e32e2015-07-10 15:29:03 -06002762 VkPipelineDepthStencilStateCreateInfo ds_state;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002763 ds_state.depthTestEnable = VK_TRUE;
2764 ds_state.depthWriteEnable = VK_TRUE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002765 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL;
Cody Northrop271ba752015-08-26 10:01:32 -06002766 ds_state.depthBoundsTestEnable = VK_FALSE;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002767 ds_state.stencilTestEnable = VK_FALSE;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002768 ds_state.back.depthFailOp = VK_STENCIL_OP_KEEP;
2769 ds_state.back.failOp = VK_STENCIL_OP_KEEP;
2770 ds_state.back.passOp = VK_STENCIL_OP_KEEP;
2771 ds_state.back.compareOp = VK_COMPARE_OP_ALWAYS;
Tony Barbourf52346d2015-01-16 14:27:35 -07002772 ds_state.front = ds_state.back;
2773 pipelineobj.SetDepthStencil(&ds_state);
2774
Tony Barbour1c45ce02015-03-27 17:03:18 -06002775 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tobin Ehlisf1878c72015-08-18 14:24:32 -06002776
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002777 VkCommandBufferBeginInfo cbBeginInfo;
2778 memset(&cbBeginInfo, 0, sizeof(VkCommandBufferBeginInfo));
2779 cbBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Courtney Goeltzenleuchter04bb5f82015-10-21 18:11:04 -06002780 cbBeginInfo.flags = 0;
Tobin Ehlisf1878c72015-08-18 14:24:32 -06002781 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barboure2c58df2014-11-25 13:18:32 -07002782
Tony Barbourfe3351b2015-07-28 10:17:20 -06002783 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002784
Tony Barbourfe3351b2015-07-28 10:17:20 -06002785 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002786#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002787 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002788 pDSDumpDot((char*)"triTest2.dot");
2789#endif
2790 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002791 Draw(num_verts, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002792
2793 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002794 EndCommandBuffer();
2795 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002796
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002797 RecordImages(m_renderTargets);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002798 RotateTriangleVSUniform(Projection, View, Model, &mvpBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002799}
Cody Northropf1990a92014-12-09 11:17:01 -07002800
Tony Barbour6918cd52015-04-09 12:58:51 -06002801TEST_F(VkRenderTest, TriangleMixedSamplerUniformBlockBinding)
Cody Northropf1990a92014-12-09 11:17:01 -07002802{
2803 // This test mixes binding slots of textures and buffers, ensuring
2804 // that sparse and overlapping assignments work.
Cody Northropb110b4f2014-12-09 13:59:39 -07002805 // The expected result from this test is a purple triangle, although
Cody Northropf1990a92014-12-09 11:17:01 -07002806 // you can modify it to move the desired result around.
2807
2808 static const char *vertShaderText =
2809 "#version 140\n"
2810 "#extension GL_ARB_separate_shader_objects : enable\n"
2811 "#extension GL_ARB_shading_language_420pack : enable\n"
2812 "void main() {\n"
2813 " vec2 vertices[3];"
2814 " vertices[0] = vec2(-0.5, -0.5);\n"
2815 " vertices[1] = vec2( 0.5, -0.5);\n"
2816 " vertices[2] = vec2( 0.5, 0.5);\n"
2817 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2818 "}\n";
2819
2820 static const char *fragShaderText =
2821 "#version 430\n"
2822 "#extension GL_ARB_separate_shader_objects : enable\n"
2823 "#extension GL_ARB_shading_language_420pack : enable\n"
2824 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wu11078b02015-01-04 16:27:24 +08002825 "layout (binding = 3) uniform sampler2D surface1;\n"
2826 "layout (binding = 1) uniform sampler2D surface2;\n"
2827 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002828
Cody Northropb110b4f2014-12-09 13:59:39 -07002829
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002830 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2831 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2832 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2833 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropf1990a92014-12-09 11:17:01 -07002834 "layout (location = 0) out vec4 outColor;\n"
2835 "void main() {\n"
Cody Northropb110b4f2014-12-09 13:59:39 -07002836 " outColor = red * vec4(0.00001);\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002837 " outColor += white * vec4(0.00001);\n"
2838 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropb110b4f2014-12-09 13:59:39 -07002839 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002840 "}\n";
2841 ASSERT_NO_FATAL_FAILURE(InitState());
2842 ASSERT_NO_FATAL_FAILURE(InitViewport());
2843
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002844 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2845 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northropf1990a92014-12-09 11:17:01 -07002846
Cody Northropf1990a92014-12-09 11:17:01 -07002847 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2848 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2849 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2850 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2851
2852 const int redCount = sizeof(redVals) / sizeof(float);
2853 const int greenCount = sizeof(greenVals) / sizeof(float);
2854 const int blueCount = sizeof(blueVals) / sizeof(float);
2855 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2856
Tony Barbour6918cd52015-04-09 12:58:51 -06002857 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2858 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2859 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2860 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropf1990a92014-12-09 11:17:01 -07002861
Tony Barbourebc093f2015-04-01 16:38:10 -06002862 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour6918cd52015-04-09 12:58:51 -06002863 VkSamplerObj sampler0(m_device);
2864 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbourebc093f2015-04-01 16:38:10 -06002865 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour6918cd52015-04-09 12:58:51 -06002866 VkSamplerObj sampler2(m_device);
2867 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbourebc093f2015-04-01 16:38:10 -06002868 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour6918cd52015-04-09 12:58:51 -06002869 VkSamplerObj sampler4(m_device);
2870 VkTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropb110b4f2014-12-09 13:59:39 -07002871
2872 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2873 // TODO: Get back here ASAP and understand why.
Tony Barbourebc093f2015-04-01 16:38:10 -06002874 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour6918cd52015-04-09 12:58:51 -06002875 VkSamplerObj sampler7(m_device);
2876 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropf1990a92014-12-09 11:17:01 -07002877
Tony Barbour6918cd52015-04-09 12:58:51 -06002878 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002879 pipelineobj.AddColorAttachment();
Cody Northropf1990a92014-12-09 11:17:01 -07002880 pipelineobj.AddShader(&vs);
2881 pipelineobj.AddShader(&ps);
2882
Tony Barbour6918cd52015-04-09 12:58:51 -06002883 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002884 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2885 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2886 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2887 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002888 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
Chia-I Wu11078b02015-01-04 16:27:24 +08002889 // swap blue and green
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002890 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2891 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2892 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropf1990a92014-12-09 11:17:01 -07002893
Tony Barbour664accc2015-01-09 12:55:14 -07002894 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002895 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropf1990a92014-12-09 11:17:01 -07002896
Tony Barbourfe3351b2015-07-28 10:17:20 -06002897 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002898
2899#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002900 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002901 pDSDumpDot((char*)"triTest2.dot");
2902#endif
2903 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002904 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002905
2906 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002907 EndCommandBuffer();
2908 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002909
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002910 RecordImages(m_renderTargets);
Cody Northropf1990a92014-12-09 11:17:01 -07002911}
2912
Tony Barbour6918cd52015-04-09 12:58:51 -06002913TEST_F(VkRenderTest, TriangleMatchingSamplerUniformBlockBinding)
Cody Northropbd531de2014-12-09 19:08:54 -07002914{
2915 // This test matches binding slots of textures and buffers, requiring
2916 // the driver to give them distinct number spaces.
2917 // The expected result from this test is a red triangle, although
2918 // you can modify it to move the desired result around.
2919
2920 static const char *vertShaderText =
2921 "#version 140\n"
2922 "#extension GL_ARB_separate_shader_objects : enable\n"
2923 "#extension GL_ARB_shading_language_420pack : enable\n"
2924 "void main() {\n"
2925 " vec2 vertices[3];"
2926 " vertices[0] = vec2(-0.5, -0.5);\n"
2927 " vertices[1] = vec2( 0.5, -0.5);\n"
2928 " vertices[2] = vec2( 0.5, 0.5);\n"
2929 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2930 "}\n";
2931
2932 static const char *fragShaderText =
2933 "#version 430\n"
2934 "#extension GL_ARB_separate_shader_objects : enable\n"
2935 "#extension GL_ARB_shading_language_420pack : enable\n"
2936 "layout (binding = 0) uniform sampler2D surface0;\n"
2937 "layout (binding = 1) uniform sampler2D surface1;\n"
2938 "layout (binding = 2) uniform sampler2D surface2;\n"
2939 "layout (binding = 3) uniform sampler2D surface3;\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06002940 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2941 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2942 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2943 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropbd531de2014-12-09 19:08:54 -07002944 "layout (location = 0) out vec4 outColor;\n"
2945 "void main() {\n"
2946 " outColor = red;// * vec4(0.00001);\n"
2947 " outColor += white * vec4(0.00001);\n"
2948 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2949 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2950 "}\n";
2951 ASSERT_NO_FATAL_FAILURE(InitState());
2952 ASSERT_NO_FATAL_FAILURE(InitViewport());
2953
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002954 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2955 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northropbd531de2014-12-09 19:08:54 -07002956
2957 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2958 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2959 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2960 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2961
2962 const int redCount = sizeof(redVals) / sizeof(float);
2963 const int greenCount = sizeof(greenVals) / sizeof(float);
2964 const int blueCount = sizeof(blueVals) / sizeof(float);
2965 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2966
Tony Barbour6918cd52015-04-09 12:58:51 -06002967 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2968 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2969 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2970 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropbd531de2014-12-09 19:08:54 -07002971
Tony Barbourebc093f2015-04-01 16:38:10 -06002972 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour6918cd52015-04-09 12:58:51 -06002973 VkSamplerObj sampler0(m_device);
2974 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbourebc093f2015-04-01 16:38:10 -06002975 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour6918cd52015-04-09 12:58:51 -06002976 VkSamplerObj sampler2(m_device);
2977 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbourebc093f2015-04-01 16:38:10 -06002978 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour6918cd52015-04-09 12:58:51 -06002979 VkSamplerObj sampler4(m_device);
2980 VkTextureObj texture4(m_device, tex_colors); // Light Green
Tony Barbourebc093f2015-04-01 16:38:10 -06002981 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour6918cd52015-04-09 12:58:51 -06002982 VkSamplerObj sampler7(m_device);
2983 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropbd531de2014-12-09 19:08:54 -07002984
Tony Barbour6918cd52015-04-09 12:58:51 -06002985 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002986 pipelineobj.AddColorAttachment();
Cody Northropbd531de2014-12-09 19:08:54 -07002987 pipelineobj.AddShader(&vs);
2988 pipelineobj.AddShader(&ps);
2989
Tony Barbour6918cd52015-04-09 12:58:51 -06002990 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002991 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2992 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2993 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2994 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002995 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2996 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2997 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2998 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropbd531de2014-12-09 19:08:54 -07002999
Tony Barbour664accc2015-01-09 12:55:14 -07003000 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003001 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropbd531de2014-12-09 19:08:54 -07003002
Tony Barbourfe3351b2015-07-28 10:17:20 -06003003 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07003004
3005#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003006 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07003007 pDSDumpDot((char*)"triTest2.dot");
3008#endif
3009 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003010 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07003011
3012 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003013 EndCommandBuffer();
3014 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07003015
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06003016 RecordImages(m_renderTargets);
Cody Northropbd531de2014-12-09 19:08:54 -07003017}
3018
Tony Barbour6918cd52015-04-09 12:58:51 -06003019TEST_F(VkRenderTest, TriangleUniformBufferLayout)
Cody Northrop04ad1202014-12-17 15:26:33 -07003020{
3021 // This test populates a buffer with a variety of different data
3022 // types, then reads them out with a shader.
3023 // The expected result from this test is a green triangle
3024
3025 static const char *vertShaderText =
3026 "#version 140\n"
3027 "#extension GL_ARB_separate_shader_objects : enable\n"
3028 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06003029 "layout (std140, binding = 0) uniform mixedBuffer {\n"
Cody Northrop04ad1202014-12-17 15:26:33 -07003030 " vec4 fRed;\n"
3031 " vec4 fGreen;\n"
3032 " layout(row_major) mat4 worldToProj;\n"
3033 " layout(row_major) mat4 projToWorld;\n"
3034 " layout(row_major) mat4 worldToView;\n"
3035 " layout(row_major) mat4 viewToProj;\n"
3036 " layout(row_major) mat4 worldToShadow[4];\n"
3037 " float fZero;\n"
3038 " float fOne;\n"
3039 " float fTwo;\n"
3040 " float fThree;\n"
3041 " vec3 fZeroZeroZero;\n"
3042 " float fFour;\n"
3043 " vec3 fZeroZeroOne;\n"
3044 " float fFive;\n"
3045 " vec3 fZeroOneZero;\n"
3046 " float fSix;\n"
3047 " float fSeven;\n"
3048 " float fEight;\n"
3049 " float fNine;\n"
3050 " vec2 fZeroZero;\n"
3051 " vec2 fZeroOne;\n"
3052 " vec4 fBlue;\n"
3053 " vec2 fOneZero;\n"
3054 " vec2 fOneOne;\n"
3055 " vec3 fZeroOneOne;\n"
3056 " float fTen;\n"
3057 " float fEleven;\n"
3058 " float fTwelve;\n"
3059 " vec3 fOneZeroZero;\n"
3060 " vec4 uvOffsets[4];\n"
3061 "};\n"
3062 "layout (location = 0) out vec4 color;"
3063 "void main() {\n"
3064
3065 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3066 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3067 " \n"
3068
3069 // do some exact comparisons, even though we should
3070 // really have an epsilon involved.
3071 " vec4 outColor = right;\n"
3072 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3073 " outColor = wrong;\n"
3074 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3075 " outColor = wrong;\n"
3076 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3077 " outColor = wrong;\n"
3078
3079 " color = outColor;\n"
3080
3081 // generic position stuff
3082 " vec2 vertices;\n"
3083 " int vertexSelector = gl_VertexID;\n"
3084 " if (vertexSelector == 0)\n"
3085 " vertices = vec2(-0.5, -0.5);\n"
3086 " else if (vertexSelector == 1)\n"
3087 " vertices = vec2( 0.5, -0.5);\n"
3088 " else if (vertexSelector == 2)\n"
3089 " vertices = vec2( 0.5, 0.5);\n"
3090 " else\n"
3091 " vertices = vec2( 0.0, 0.0);\n"
3092 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3093 "}\n";
3094
3095 static const char *fragShaderText =
3096 "#version 140\n"
3097 "#extension GL_ARB_separate_shader_objects : enable\n"
3098 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06003099 "layout (std140, binding = 0) uniform mixedBuffer {\n"
Cody Northrop04ad1202014-12-17 15:26:33 -07003100 " vec4 fRed;\n"
3101 " vec4 fGreen;\n"
3102 " layout(row_major) mat4 worldToProj;\n"
3103 " layout(row_major) mat4 projToWorld;\n"
3104 " layout(row_major) mat4 worldToView;\n"
3105 " layout(row_major) mat4 viewToProj;\n"
3106 " layout(row_major) mat4 worldToShadow[4];\n"
3107 " float fZero;\n"
3108 " float fOne;\n"
3109 " float fTwo;\n"
3110 " float fThree;\n"
3111 " vec3 fZeroZeroZero;\n"
3112 " float fFour;\n"
3113 " vec3 fZeroZeroOne;\n"
3114 " float fFive;\n"
3115 " vec3 fZeroOneZero;\n"
3116 " float fSix;\n"
3117 " float fSeven;\n"
3118 " float fEight;\n"
3119 " float fNine;\n"
3120 " vec2 fZeroZero;\n"
3121 " vec2 fZeroOne;\n"
3122 " vec4 fBlue;\n"
3123 " vec2 fOneZero;\n"
3124 " vec2 fOneOne;\n"
3125 " vec3 fZeroOneOne;\n"
3126 " float fTen;\n"
3127 " float fEleven;\n"
3128 " float fTwelve;\n"
3129 " vec3 fOneZeroZero;\n"
3130 " vec4 uvOffsets[4];\n"
3131 "};\n"
3132 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06003133 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop04ad1202014-12-17 15:26:33 -07003134 "void main() {\n"
3135 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3136 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3137 " \n"
3138
3139 // start with VS value to ensure it passed
3140 " vec4 outColor = color;\n"
3141
3142 // do some exact comparisons, even though we should
3143 // really have an epsilon involved.
3144 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3145 " outColor = wrong;\n"
3146 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3147 " outColor = wrong;\n"
3148 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3149 " outColor = wrong;\n"
3150 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3151 " outColor = wrong;\n"
3152 " if (fTwo != 2.0)\n"
3153 " outColor = wrong;\n"
3154 " if (fOneOne != vec2(1.0, 1.0))\n"
3155 " outColor = wrong;\n"
3156 " if (fTen != 10.0)\n"
3157 " outColor = wrong;\n"
3158 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3159 " outColor = wrong;\n"
3160 " \n"
GregFaae75242015-06-03 18:40:50 -06003161 " uFragColor = outColor;\n"
Cody Northrop04ad1202014-12-17 15:26:33 -07003162 "}\n";
3163
3164
Cody Northropd2ad0342015-08-05 11:15:02 -06003165 const float mixedVals[196] = { 1.0f, 0.0f, 0.0f, 1.0f, // vec4 fRed; // align
3166 0.0f, 1.0f, 0.0f, 1.0f, // vec4 fGreen; // align
3167 1.0f, 0.0f, 0.0f, 1.0f, // layout(row_major) mat4 worldToProj;
3168 0.0f, 1.0f, 0.0f, 1.0f, // align
3169 0.0f, 0.0f, 1.0f, 1.0f, // align
3170 0.0f, 0.0f, 0.0f, 1.0f, // align
3171 2.0f, 0.0f, 0.0f, 2.0f, // layout(row_major) mat4 projToWorld;
3172 0.0f, 2.0f, 0.0f, 2.0f, // align
3173 0.0f, 0.0f, 2.0f, 2.0f, // align
3174 0.0f, 0.0f, 0.0f, 2.0f, // align
3175 3.0f, 0.0f, 0.0f, 3.0f, // layout(row_major) mat4 worldToView;
3176 0.0f, 3.0f, 0.0f, 3.0f, // align
3177 0.0f, 0.0f, 3.0f, 3.0f, // align
3178 0.0f, 0.0f, 0.0f, 3.0f, // align
3179 4.0f, 0.0f, 0.0f, 4.0f, // layout(row_major) mat4 viewToProj;
3180 0.0f, 4.0f, 0.0f, 4.0f, // align
3181 0.0f, 0.0f, 4.0f, 4.0f, // align
3182 0.0f, 0.0f, 0.0f, 4.0f, // align
3183 5.0f, 0.0f, 0.0f, 5.0f, // layout(row_major) mat4 worldToShadow[4];
3184 0.0f, 5.0f, 0.0f, 5.0f, // align
3185 0.0f, 0.0f, 5.0f, 5.0f, // align
3186 0.0f, 0.0f, 0.0f, 5.0f, // align
3187 6.0f, 0.0f, 0.0f, 6.0f, // align
3188 0.0f, 6.0f, 0.0f, 6.0f, // align
3189 0.0f, 0.0f, 6.0f, 6.0f, // align
3190 0.0f, 0.0f, 0.0f, 6.0f, // align
3191 7.0f, 0.0f, 0.0f, 7.0f, // align
3192 0.0f, 7.0f, 0.0f, 7.0f, // align
3193 0.0f, 0.0f, 7.0f, 7.0f, // align
3194 0.0f, 0.0f, 0.0f, 7.0f, // align
3195 8.0f, 0.0f, 0.0f, 8.0f, // align
3196 0.0f, 8.0f, 0.0f, 8.0f, // align
3197 0.0f, 0.0f, 8.0f, 8.0f, // align
3198 0.0f, 0.0f, 0.0f, 8.0f, // align
3199 0.0f, // float fZero; // align
3200 1.0f, // float fOne; // pack
3201 2.0f, // float fTwo; // pack
3202 3.0f, // float fThree; // pack
3203 0.0f, 0.0f, 0.0f, // vec3 fZeroZeroZero; // align
3204 4.0f, // float fFour; // pack
3205 0.0f, 0.0f, 1.0f, // vec3 fZeroZeroOne; // align
3206 5.0f, // float fFive; // pack
3207 0.0f, 1.0f, 0.0f, // vec3 fZeroOneZero; // align
3208 6.0f, // float fSix; // pack
3209 7.0f, // float fSeven; // align
3210 8.0f, // float fEight; // pack
3211 9.0f, // float fNine; // pack
3212 0.0f, // BUFFER
3213 0.0f, 0.0f, // vec2 fZeroZero; // align
3214 0.0f, 1.0f, // vec2 fZeroOne; // pack
3215 0.0f, 0.0f, 1.0f, 1.0f, // vec4 fBlue; // align
3216 1.0f, 0.0f, // vec2 fOneZero; // align
3217 1.0f, 1.0f, // vec2 fOneOne; // pack
3218 0.0f, 1.0f, 1.0f, // vec3 fZeroOneOne; // align
3219 10.0f, // float fTen; // pack
3220 11.0f, // float fEleven; // align
3221 12.0f, // float fTwelve; // pack
3222 0.0f, 0.0f, // BUFFER
3223 1.0f, 0.0f, 0.0f, // vec3 fOneZeroZero; // align
3224 0.0f, // BUFFER
3225 0.1f, 0.2f, 0.3f, 0.4f, // vec4 uvOffsets[4];
3226 0.5f, 0.6f, 0.7f, 0.8f, // align
3227 0.9f, 1.0f, 1.1f, 1.2f, // align
3228 1.3f, 1.4f, 1.5f, 1.6f, // align
Cody Northrop04ad1202014-12-17 15:26:33 -07003229 };
3230
3231 ASSERT_NO_FATAL_FAILURE(InitState());
3232 ASSERT_NO_FATAL_FAILURE(InitViewport());
3233
3234 const int constCount = sizeof(mixedVals) / sizeof(float);
3235
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003236 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
3237 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northrop04ad1202014-12-17 15:26:33 -07003238
Tony Barbour6918cd52015-04-09 12:58:51 -06003239 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop04ad1202014-12-17 15:26:33 -07003240
Tony Barbour6918cd52015-04-09 12:58:51 -06003241 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003242 pipelineobj.AddColorAttachment();
Cody Northrop04ad1202014-12-17 15:26:33 -07003243 pipelineobj.AddShader(&vs);
3244 pipelineobj.AddShader(&ps);
3245
Tony Barbour6918cd52015-04-09 12:58:51 -06003246 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003247 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
Cody Northrop04ad1202014-12-17 15:26:33 -07003248
3249 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003250 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop04ad1202014-12-17 15:26:33 -07003251
Tony Barbourfe3351b2015-07-28 10:17:20 -06003252 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop04ad1202014-12-17 15:26:33 -07003253
3254#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003255 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop04ad1202014-12-17 15:26:33 -07003256 pDSDumpDot((char*)"triTest2.dot");
3257#endif
3258 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003259 Draw(3, 1, 0, 0);
Cody Northrop04ad1202014-12-17 15:26:33 -07003260
3261 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003262 EndCommandBuffer();
3263 QueueCommandBuffer();
Cody Northrop04ad1202014-12-17 15:26:33 -07003264
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06003265 RecordImages(m_renderTargets);
Cody Northrop04ad1202014-12-17 15:26:33 -07003266}
3267
Cody Northrop95638152015-05-07 14:39:12 -06003268TEST_F(VkRenderTest, TextureGather)
3269{
3270 // This test introduces textureGather and textureGatherOffset
3271 // Each call is compared against an expected inline color result
3272 // Green triangle means everything worked as expected
3273 // Red means something went wrong
3274
Cody Northropc55900f2015-08-06 13:18:13 -06003275 // disable SPV until texture gather is turned on in glsl->SPV
3276 if (!m_use_glsl) {
3277 printf("Skipping test that requires GLSL path (TextureGather)\n");
3278 return;
3279 }
3280
Cody Northrop95638152015-05-07 14:39:12 -06003281 static const char *vertShaderText =
3282 "#version 140\n"
3283 "#extension GL_ARB_separate_shader_objects : enable\n"
3284 "#extension GL_ARB_shading_language_420pack : enable\n"
3285 "void main() {\n"
3286 " vec2 vertices[3];"
3287 " vertices[0] = vec2(-0.5, -0.5);\n"
3288 " vertices[1] = vec2( 0.5, -0.5);\n"
3289 " vertices[2] = vec2( 0.5, 0.5);\n"
3290 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
3291 "}\n";
3292
3293 static const char *fragShaderText =
3294 "#version 430\n"
3295 "#extension GL_ARB_separate_shader_objects : enable\n"
3296 "#extension GL_ARB_shading_language_420pack : enable\n"
3297 "layout (binding = 0) uniform sampler2D surface0;\n"
3298 "layout (binding = 1) uniform sampler2D surface1;\n"
3299 "layout (binding = 2) uniform sampler2D surface2;\n"
3300 "layout (binding = 3) uniform sampler2D surface3;\n"
3301 "layout (location = 0) out vec4 outColor;\n"
3302 "void main() {\n"
3303
3304 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3305 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3306
3307 " vec4 color = right;\n"
3308
3309 // Grab a normal texture sample to ensure it can work in conjuntion
3310 // with textureGather (there are some intracacies in the backend)
3311 " vec4 sampledColor = textureLod(surface2, vec2(0.5), 0.0);\n"
3312 " if (sampledColor != vec4(0.0, 0.0, 1.0, 1.0))\n"
3313 " color = wrong;\n"
3314
3315 " vec4 gatheredColor = textureGather(surface0, vec2(0.5), 0);\n"
3316 // This just grabbed four red components from a red surface
3317 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3318 " color = wrong;\n"
3319
3320 // Yes, this is using an offset of 0, we don't have enough fine grained
3321 // control of the texture contents here.
3322 " gatheredColor = textureGatherOffset(surface1, vec2(0.5), ivec2(0, 0), 1);\n"
3323 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3324 " color = wrong;\n"
3325
3326 " outColor = color;\n"
3327
3328 "}\n";
3329
3330 ASSERT_NO_FATAL_FAILURE(InitState());
3331 ASSERT_NO_FATAL_FAILURE(InitViewport());
3332
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003333 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
3334 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northrop95638152015-05-07 14:39:12 -06003335
3336 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
3337 VkSamplerObj sampler0(m_device);
3338 VkTextureObj texture0(m_device, tex_colors); // Red
3339 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
3340 VkSamplerObj sampler1(m_device);
3341 VkTextureObj texture1(m_device, tex_colors); // Green
3342 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
3343 VkSamplerObj sampler2(m_device);
3344 VkTextureObj texture2(m_device, tex_colors); // Blue
3345 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
3346 VkSamplerObj sampler3(m_device);
3347 VkTextureObj texture3(m_device, tex_colors); // Red and Blue
3348
3349 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003350 pipelineobj.AddColorAttachment();
Cody Northrop95638152015-05-07 14:39:12 -06003351 pipelineobj.AddShader(&vs);
3352 pipelineobj.AddShader(&ps);
3353
3354 VkDescriptorSetObj descriptorSet(m_device);
3355 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3356 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
3357 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3358 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
3359
3360 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003361 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop95638152015-05-07 14:39:12 -06003362
Tony Barbourfe3351b2015-07-28 10:17:20 -06003363 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop95638152015-05-07 14:39:12 -06003364
3365 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003366 Draw(3, 1, 0, 0);
Cody Northrop95638152015-05-07 14:39:12 -06003367
3368 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003369 EndCommandBuffer();
3370 QueueCommandBuffer();
Cody Northrop95638152015-05-07 14:39:12 -06003371
3372 RecordImages(m_renderTargets);
Cody Northrop95638152015-05-07 14:39:12 -06003373}
3374
Cody Northrop475663c2015-04-15 11:19:06 -06003375TEST_F(VkRenderTest, GeometryShaderHelloWorld)
3376{
3377 // This test introduces a geometry shader that simply
3378 // changes the color of each vertex to red, green, blue
3379
3380 static const char *vertShaderText =
3381 "#version 140\n"
3382 "#extension GL_ARB_separate_shader_objects : enable\n"
3383 "#extension GL_ARB_shading_language_420pack : enable\n"
3384 "layout (location = 0) out vec4 color;"
3385 "void main() {\n"
3386
3387 // VS writes out red
3388 " color = vec4(1.0, 0.0, 0.0, 1.0);\n"
3389
3390 // generic position stuff
3391 " vec2 vertices;\n"
3392 " int vertexSelector = gl_VertexID;\n"
3393 " if (vertexSelector == 0)\n"
3394 " vertices = vec2(-0.5, -0.5);\n"
3395 " else if (vertexSelector == 1)\n"
3396 " vertices = vec2( 0.5, -0.5);\n"
3397 " else if (vertexSelector == 2)\n"
3398 " vertices = vec2( 0.5, 0.5);\n"
3399 " else\n"
3400 " vertices = vec2( 0.0, 0.0);\n"
3401 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3402
3403 "}\n";
3404
3405 static const char *geomShaderText =
3406 "#version 330\n"
3407 "#extension GL_ARB_separate_shader_objects : enable\n"
3408 "#extension GL_ARB_shading_language_420pack : enable\n"
3409 "layout( triangles ) in;\n"
3410 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3411 "layout( location = 0 ) in vec4 inColor[3];\n"
3412 "layout( location = 0 ) out vec4 outColor;\n"
3413 "void main()\n"
3414 "{\n"
3415
3416 // first vertex, pass through red
3417 " gl_Position = gl_in[0].gl_Position;\n"
3418 " outColor = inColor[0];\n"
3419 " EmitVertex();\n"
3420
3421 // second vertex, green
3422 " gl_Position = gl_in[1].gl_Position;\n"
3423 " outColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3424 " EmitVertex();\n"
3425
3426 // third vertex, blue
3427 " gl_Position = gl_in[2].gl_Position;\n"
3428 " outColor = vec4(0.0, 0.0, 1.0, 1.0);\n"
3429 " EmitVertex();\n"
3430
3431 // done
3432 " EndPrimitive();\n"
3433 "}\n";
3434
3435
3436 static const char *fragShaderText =
3437 "#version 140\n"
3438 "#extension GL_ARB_separate_shader_objects : enable\n"
3439 "#extension GL_ARB_shading_language_420pack : enable\n"
3440 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06003441 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003442 "void main() {\n"
3443 // pass through
GregFaae75242015-06-03 18:40:50 -06003444 " outColor = color;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003445 "}\n";
3446
3447
3448
3449 ASSERT_NO_FATAL_FAILURE(InitState());
3450 ASSERT_NO_FATAL_FAILURE(InitViewport());
3451
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003452 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3453 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY_BIT, this);
3454 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northrop475663c2015-04-15 11:19:06 -06003455
3456 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003457 pipelineobj.AddColorAttachment();
Cody Northrop475663c2015-04-15 11:19:06 -06003458 pipelineobj.AddShader(&vs);
3459 pipelineobj.AddShader(&gs);
3460 pipelineobj.AddShader(&ps);
3461
3462 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003463 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop475663c2015-04-15 11:19:06 -06003464
3465 VkDescriptorSetObj descriptorSet(m_device);
3466
Tony Barbourfe3351b2015-07-28 10:17:20 -06003467 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop475663c2015-04-15 11:19:06 -06003468
3469 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003470 Draw(3, 1, 0, 0);
Cody Northrop475663c2015-04-15 11:19:06 -06003471
3472 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003473 EndCommandBuffer();
3474 QueueCommandBuffer();
Cody Northrop475663c2015-04-15 11:19:06 -06003475
3476 RecordImages(m_renderTargets);
3477}
3478
3479TEST_F(VkRenderTest, GSUniformBufferLayout)
3480{
3481 // This test is just like TriangleUniformBufferLayout but adds
3482 // geometry as a stage that also does UBO lookups
3483 // The expected result from this test is a green triangle
3484
3485 static const char *vertShaderText =
3486 "#version 140\n"
3487 "#extension GL_ARB_separate_shader_objects : enable\n"
3488 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06003489 "layout (std140, binding = 0) uniform mixedBuffer {\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003490 " vec4 fRed;\n"
3491 " vec4 fGreen;\n"
3492 " layout(row_major) mat4 worldToProj;\n"
3493 " layout(row_major) mat4 projToWorld;\n"
3494 " layout(row_major) mat4 worldToView;\n"
3495 " layout(row_major) mat4 viewToProj;\n"
3496 " layout(row_major) mat4 worldToShadow[4];\n"
3497 " float fZero;\n"
3498 " float fOne;\n"
3499 " float fTwo;\n"
3500 " float fThree;\n"
3501 " vec3 fZeroZeroZero;\n"
3502 " float fFour;\n"
3503 " vec3 fZeroZeroOne;\n"
3504 " float fFive;\n"
3505 " vec3 fZeroOneZero;\n"
3506 " float fSix;\n"
3507 " float fSeven;\n"
3508 " float fEight;\n"
3509 " float fNine;\n"
3510 " vec2 fZeroZero;\n"
3511 " vec2 fZeroOne;\n"
3512 " vec4 fBlue;\n"
3513 " vec2 fOneZero;\n"
3514 " vec2 fOneOne;\n"
3515 " vec3 fZeroOneOne;\n"
3516 " float fTen;\n"
3517 " float fEleven;\n"
3518 " float fTwelve;\n"
3519 " vec3 fOneZeroZero;\n"
3520 " vec4 uvOffsets[4];\n"
3521 "};\n"
3522 "layout (location = 0) out vec4 color;"
3523 "void main() {\n"
3524
3525 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3526 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3527 " \n"
3528
3529 // do some exact comparisons, even though we should
3530 // really have an epsilon involved.
3531 " vec4 outColor = right;\n"
3532 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3533 " outColor = wrong;\n"
3534 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3535 " outColor = wrong;\n"
3536 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3537 " outColor = wrong;\n"
3538
3539 " color = outColor;\n"
3540
3541 // generic position stuff
3542 " vec2 vertices;\n"
3543 " int vertexSelector = gl_VertexID;\n"
3544 " if (vertexSelector == 0)\n"
3545 " vertices = vec2(-0.5, -0.5);\n"
3546 " else if (vertexSelector == 1)\n"
3547 " vertices = vec2( 0.5, -0.5);\n"
3548 " else if (vertexSelector == 2)\n"
3549 " vertices = vec2( 0.5, 0.5);\n"
3550 " else\n"
3551 " vertices = vec2( 0.0, 0.0);\n"
3552 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3553 "}\n";
3554
3555 static const char *geomShaderText =
3556 "#version 330\n"
3557 "#extension GL_ARB_separate_shader_objects : enable\n"
3558 "#extension GL_ARB_shading_language_420pack : enable\n"
3559
3560 // GS layout stuff
3561 "layout( triangles ) in;\n"
3562 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3563
3564 // Between stage IO
3565 "layout( location = 0 ) in vec4 inColor[3];\n"
3566 "layout( location = 0 ) out vec4 color;\n"
3567
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06003568 "layout (std140, binding = 0) uniform mixedBuffer {\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003569 " vec4 fRed;\n"
3570 " vec4 fGreen;\n"
3571 " layout(row_major) mat4 worldToProj;\n"
3572 " layout(row_major) mat4 projToWorld;\n"
3573 " layout(row_major) mat4 worldToView;\n"
3574 " layout(row_major) mat4 viewToProj;\n"
3575 " layout(row_major) mat4 worldToShadow[4];\n"
3576 " float fZero;\n"
3577 " float fOne;\n"
3578 " float fTwo;\n"
3579 " float fThree;\n"
3580 " vec3 fZeroZeroZero;\n"
3581 " float fFour;\n"
3582 " vec3 fZeroZeroOne;\n"
3583 " float fFive;\n"
3584 " vec3 fZeroOneZero;\n"
3585 " float fSix;\n"
3586 " float fSeven;\n"
3587 " float fEight;\n"
3588 " float fNine;\n"
3589 " vec2 fZeroZero;\n"
3590 " vec2 fZeroOne;\n"
3591 " vec4 fBlue;\n"
3592 " vec2 fOneZero;\n"
3593 " vec2 fOneOne;\n"
3594 " vec3 fZeroOneOne;\n"
3595 " float fTen;\n"
3596 " float fEleven;\n"
3597 " float fTwelve;\n"
3598 " vec3 fOneZeroZero;\n"
3599 " vec4 uvOffsets[4];\n"
3600 "};\n"
3601
3602 "void main()\n"
3603 "{\n"
3604
3605 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3606 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3607
3608 // Each vertex will validate it can read VS output
3609 // then check a few values from the UBO
3610
3611 // first vertex
3612 " vec4 outColor = inColor[0];\n"
3613
3614 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3615 " outColor = wrong;\n"
3616 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3617 " outColor = wrong;\n"
3618 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3619 " outColor = wrong;\n"
3620 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3621 " outColor = wrong;\n"
3622
3623 " gl_Position = gl_in[0].gl_Position;\n"
3624 " color = outColor;\n"
3625 " EmitVertex();\n"
3626
3627 // second vertex
3628 " outColor = inColor[1];\n"
3629
3630 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3631 " outColor = wrong;\n"
3632 " if (fSix != 6.0)\n"
3633 " outColor = wrong;\n"
3634 " if (fOneOne != vec2(1.0, 1.0))\n"
3635 " outColor = wrong;\n"
3636
3637 " gl_Position = gl_in[1].gl_Position;\n"
3638 " color = outColor;\n"
3639 " EmitVertex();\n"
3640
3641 // third vertex
3642 " outColor = inColor[2];\n"
3643
3644 " if (fSeven != 7.0)\n"
3645 " outColor = wrong;\n"
3646 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3647 " outColor = wrong;\n"
3648
3649 " gl_Position = gl_in[2].gl_Position;\n"
3650 " color = outColor;\n"
3651 " EmitVertex();\n"
3652
3653 // done
3654 " EndPrimitive();\n"
3655 "}\n";
3656
3657 static const char *fragShaderText =
3658 "#version 140\n"
3659 "#extension GL_ARB_separate_shader_objects : enable\n"
3660 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter6de5f732015-10-28 15:35:37 -06003661 "layout (std140, binding = 0) uniform mixedBuffer {\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003662 " vec4 fRed;\n"
3663 " vec4 fGreen;\n"
3664 " layout(row_major) mat4 worldToProj;\n"
3665 " layout(row_major) mat4 projToWorld;\n"
3666 " layout(row_major) mat4 worldToView;\n"
3667 " layout(row_major) mat4 viewToProj;\n"
3668 " layout(row_major) mat4 worldToShadow[4];\n"
3669 " float fZero;\n"
3670 " float fOne;\n"
3671 " float fTwo;\n"
3672 " float fThree;\n"
3673 " vec3 fZeroZeroZero;\n"
3674 " float fFour;\n"
3675 " vec3 fZeroZeroOne;\n"
3676 " float fFive;\n"
3677 " vec3 fZeroOneZero;\n"
3678 " float fSix;\n"
3679 " float fSeven;\n"
3680 " float fEight;\n"
3681 " float fNine;\n"
3682 " vec2 fZeroZero;\n"
3683 " vec2 fZeroOne;\n"
3684 " vec4 fBlue;\n"
3685 " vec2 fOneZero;\n"
3686 " vec2 fOneOne;\n"
3687 " vec3 fZeroOneOne;\n"
3688 " float fTen;\n"
3689 " float fEleven;\n"
3690 " float fTwelve;\n"
3691 " vec3 fOneZeroZero;\n"
3692 " vec4 uvOffsets[4];\n"
3693 "};\n"
3694 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06003695 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003696 "void main() {\n"
3697 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3698 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3699 " \n"
3700
3701 // start with GS value to ensure it passed
3702 " vec4 outColor = color;\n"
3703
3704 // do some exact comparisons, even though we should
3705 // really have an epsilon involved.
3706 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3707 " outColor = wrong;\n"
3708 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3709 " outColor = wrong;\n"
3710 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3711 " outColor = wrong;\n"
3712 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3713 " outColor = wrong;\n"
3714 " if (fTwo != 2.0)\n"
3715 " outColor = wrong;\n"
3716 " if (fOneOne != vec2(1.0, 1.0))\n"
3717 " outColor = wrong;\n"
3718 " if (fTen != 10.0)\n"
3719 " outColor = wrong;\n"
3720 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3721 " outColor = wrong;\n"
3722 " \n"
GregFaae75242015-06-03 18:40:50 -06003723 " uFragColor = outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003724 "}\n";
3725
3726
Cody Northropd2ad0342015-08-05 11:15:02 -06003727 const float mixedVals[196] = { 1.0f, 0.0f, 0.0f, 1.0f, // vec4 fRed; // align
3728 0.0f, 1.0f, 0.0f, 1.0f, // vec4 fGreen; // align
3729 1.0f, 0.0f, 0.0f, 1.0f, // layout(row_major) mat4 worldToProj;
3730 0.0f, 1.0f, 0.0f, 1.0f, // align
3731 0.0f, 0.0f, 1.0f, 1.0f, // align
3732 0.0f, 0.0f, 0.0f, 1.0f, // align
3733 2.0f, 0.0f, 0.0f, 2.0f, // layout(row_major) mat4 projToWorld;
3734 0.0f, 2.0f, 0.0f, 2.0f, // align
3735 0.0f, 0.0f, 2.0f, 2.0f, // align
3736 0.0f, 0.0f, 0.0f, 2.0f, // align
3737 3.0f, 0.0f, 0.0f, 3.0f, // layout(row_major) mat4 worldToView;
3738 0.0f, 3.0f, 0.0f, 3.0f, // align
3739 0.0f, 0.0f, 3.0f, 3.0f, // align
3740 0.0f, 0.0f, 0.0f, 3.0f, // align
3741 4.0f, 0.0f, 0.0f, 4.0f, // layout(row_major) mat4 viewToProj;
3742 0.0f, 4.0f, 0.0f, 4.0f, // align
3743 0.0f, 0.0f, 4.0f, 4.0f, // align
3744 0.0f, 0.0f, 0.0f, 4.0f, // align
3745 5.0f, 0.0f, 0.0f, 5.0f, // layout(row_major) mat4 worldToShadow[4];
3746 0.0f, 5.0f, 0.0f, 5.0f, // align
3747 0.0f, 0.0f, 5.0f, 5.0f, // align
3748 0.0f, 0.0f, 0.0f, 5.0f, // align
3749 6.0f, 0.0f, 0.0f, 6.0f, // align
3750 0.0f, 6.0f, 0.0f, 6.0f, // align
3751 0.0f, 0.0f, 6.0f, 6.0f, // align
3752 0.0f, 0.0f, 0.0f, 6.0f, // align
3753 7.0f, 0.0f, 0.0f, 7.0f, // align
3754 0.0f, 7.0f, 0.0f, 7.0f, // align
3755 0.0f, 0.0f, 7.0f, 7.0f, // align
3756 0.0f, 0.0f, 0.0f, 7.0f, // align
3757 8.0f, 0.0f, 0.0f, 8.0f, // align
3758 0.0f, 8.0f, 0.0f, 8.0f, // align
3759 0.0f, 0.0f, 8.0f, 8.0f, // align
3760 0.0f, 0.0f, 0.0f, 8.0f, // align
3761 0.0f, // float fZero; // align
3762 1.0f, // float fOne; // pack
3763 2.0f, // float fTwo; // pack
3764 3.0f, // float fThree; // pack
3765 0.0f, 0.0f, 0.0f, // vec3 fZeroZeroZero; // align
3766 4.0f, // float fFour; // pack
3767 0.0f, 0.0f, 1.0f, // vec3 fZeroZeroOne; // align
3768 5.0f, // float fFive; // pack
3769 0.0f, 1.0f, 0.0f, // vec3 fZeroOneZero; // align
3770 6.0f, // float fSix; // pack
3771 7.0f, // float fSeven; // align
3772 8.0f, // float fEight; // pack
3773 9.0f, // float fNine; // pack
3774 0.0f, // BUFFER
3775 0.0f, 0.0f, // vec2 fZeroZero; // align
3776 0.0f, 1.0f, // vec2 fZeroOne; // pack
3777 0.0f, 0.0f, 1.0f, 1.0f, // vec4 fBlue; // align
3778 1.0f, 0.0f, // vec2 fOneZero; // align
3779 1.0f, 1.0f, // vec2 fOneOne; // pack
3780 0.0f, 1.0f, 1.0f, // vec3 fZeroOneOne; // align
3781 10.0f, // float fTen; // pack
3782 11.0f, // float fEleven; // align
3783 12.0f, // float fTwelve; // pack
3784 0.0f, 0.0f, // BUFFER
3785 1.0f, 0.0f, 0.0f, // vec3 fOneZeroZero; // align
3786 0.0f, // BUFFER
3787 0.1f, 0.2f, 0.3f, 0.4f, // vec4 uvOffsets[4];
3788 0.5f, 0.6f, 0.7f, 0.8f, // align
3789 0.9f, 1.0f, 1.1f, 1.2f, // align
3790 1.3f, 1.4f, 1.5f, 1.6f, // align
Cody Northrop475663c2015-04-15 11:19:06 -06003791 };
3792
3793
3794
3795 ASSERT_NO_FATAL_FAILURE(InitState());
3796 ASSERT_NO_FATAL_FAILURE(InitViewport());
3797
3798 const int constCount = sizeof(mixedVals) / sizeof(float);
3799
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003800 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3801 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY_BIT, this);
3802 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northrop475663c2015-04-15 11:19:06 -06003803
3804 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
3805
3806 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003807 pipelineobj.AddColorAttachment();
Cody Northrop475663c2015-04-15 11:19:06 -06003808 pipelineobj.AddShader(&vs);
3809 pipelineobj.AddShader(&gs);
3810 pipelineobj.AddShader(&ps);
3811
3812 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003813 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop475663c2015-04-15 11:19:06 -06003814
3815 VkDescriptorSetObj descriptorSet(m_device);
3816 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
3817
Tony Barbourfe3351b2015-07-28 10:17:20 -06003818 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop475663c2015-04-15 11:19:06 -06003819
3820 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003821 Draw(3, 1, 0, 0);
Cody Northrop475663c2015-04-15 11:19:06 -06003822
3823 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003824 EndCommandBuffer();
3825 QueueCommandBuffer();
Cody Northrop475663c2015-04-15 11:19:06 -06003826
3827 RecordImages(m_renderTargets);
3828}
3829
3830TEST_F(VkRenderTest, GSPositions)
3831{
3832 // This test adds more inputs from the vertex shader and perturbs positions
3833 // Expected result is white triangle with weird positions
3834
3835 static const char *vertShaderText =
3836 "#version 140\n"
3837 "#extension GL_ARB_separate_shader_objects : enable\n"
3838 "#extension GL_ARB_shading_language_420pack : enable\n"
3839
3840 "layout(location = 0) out vec3 out_a;\n"
3841 "layout(location = 1) out vec3 out_b;\n"
3842 "layout(location = 2) out vec3 out_c;\n"
3843
3844 "void main() {\n"
3845
3846 // write a solid color to each
3847 " out_a = vec3(1.0, 0.0, 0.0);\n"
3848 " out_b = vec3(0.0, 1.0, 0.0);\n"
3849 " out_c = vec3(0.0, 0.0, 1.0);\n"
3850
3851 // generic position stuff
3852 " vec2 vertices;\n"
3853 " int vertexSelector = gl_VertexID;\n"
3854 " if (vertexSelector == 0)\n"
3855 " vertices = vec2(-0.5, -0.5);\n"
3856 " else if (vertexSelector == 1)\n"
3857 " vertices = vec2( 0.5, -0.5);\n"
3858 " else if (vertexSelector == 2)\n"
3859 " vertices = vec2( 0.5, 0.5);\n"
3860 " else\n"
3861 " vertices = vec2( 0.0, 0.0);\n"
3862 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3863
3864 "}\n";
3865
3866 static const char *geomShaderText =
3867 "#version 330\n"
3868 "#extension GL_ARB_separate_shader_objects : enable\n"
3869 "#extension GL_ARB_shading_language_420pack : enable\n"
3870 "layout( triangles ) in;\n"
3871 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3872
3873 "layout(location = 0) in vec3 in_a[3];\n"
3874 "layout(location = 1) in vec3 in_b[3];\n"
3875 "layout(location = 2) in vec3 in_c[3];\n"
3876
3877 "layout(location = 0) out vec3 out_a;\n"
3878 "layout(location = 1) out vec3 out_b;\n"
3879 "layout(location = 2) out vec3 out_c;\n"
3880
3881 "void main()\n"
3882 "{\n"
3883
3884 " gl_Position = gl_in[0].gl_Position;\n"
3885 " gl_Position.xy *= vec2(0.75);\n"
3886 " out_a = in_a[0];\n"
3887 " out_b = in_b[0];\n"
3888 " out_c = in_c[0];\n"
3889 " EmitVertex();\n"
3890
3891 " gl_Position = gl_in[1].gl_Position;\n"
3892 " gl_Position.xy *= vec2(1.5);\n"
3893 " out_a = in_a[1];\n"
3894 " out_b = in_b[1];\n"
3895 " out_c = in_c[1];\n"
3896 " EmitVertex();\n"
3897
3898 " gl_Position = gl_in[2].gl_Position;\n"
3899 " gl_Position.xy *= vec2(-0.1);\n"
3900 " out_a = in_a[2];\n"
3901 " out_b = in_b[2];\n"
3902 " out_c = in_c[2];\n"
3903 " EmitVertex();\n"
3904
3905 " EndPrimitive();\n"
3906 "}\n";
3907
3908
3909 static const char *fragShaderText =
3910 "#version 140\n"
3911 "#extension GL_ARB_separate_shader_objects : enable\n"
3912 "#extension GL_ARB_shading_language_420pack : enable\n"
3913
3914 "layout(location = 0) in vec3 in_a;\n"
3915 "layout(location = 1) in vec3 in_b;\n"
3916 "layout(location = 2) in vec3 in_c;\n"
GregFaae75242015-06-03 18:40:50 -06003917 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003918
3919 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06003920 " outColor = vec4(in_a.x, in_b.y, in_c.z, 1.0);\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003921 "}\n";
3922
3923
3924
3925 ASSERT_NO_FATAL_FAILURE(InitState());
3926 ASSERT_NO_FATAL_FAILURE(InitViewport());
3927
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003928 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3929 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY_BIT, this);
3930 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northrop475663c2015-04-15 11:19:06 -06003931
3932 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003933 pipelineobj.AddColorAttachment();
Cody Northrop475663c2015-04-15 11:19:06 -06003934 pipelineobj.AddShader(&vs);
3935 pipelineobj.AddShader(&gs);
3936 pipelineobj.AddShader(&ps);
3937
3938 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003939 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop475663c2015-04-15 11:19:06 -06003940
3941 VkDescriptorSetObj descriptorSet(m_device);
3942
Tony Barbourfe3351b2015-07-28 10:17:20 -06003943 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop475663c2015-04-15 11:19:06 -06003944
3945 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003946 Draw(3, 1, 0, 0);
Cody Northrop475663c2015-04-15 11:19:06 -06003947
3948 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003949 EndCommandBuffer();
3950 QueueCommandBuffer();
Cody Northrop475663c2015-04-15 11:19:06 -06003951
3952 RecordImages(m_renderTargets);
3953}
3954
3955TEST_F(VkRenderTest, GSTriStrip)
3956{
3957 // This test emits multiple multiple triangles using a GS
3958 // Correct result is an multicolor circle
3959
3960 static const char *vertShaderText =
3961 "#version 140\n"
3962 "#extension GL_ARB_separate_shader_objects : enable\n"
3963 "#extension GL_ARB_shading_language_420pack : enable\n"
3964
3965 "void main() {\n"
3966
3967 // generic position stuff
3968 " vec2 vertices;\n"
3969 " int vertexSelector = gl_VertexID;\n"
3970 " if (vertexSelector == 0)\n"
3971 " vertices = vec2(-0.5, -0.5);\n"
3972 " else if (vertexSelector == 1)\n"
3973 " vertices = vec2( 0.5, -0.5);\n"
3974 " else if (vertexSelector == 2)\n"
3975 " vertices = vec2( 0.5, 0.5);\n"
3976 " else\n"
3977 " vertices = vec2( 0.0, 0.0);\n"
3978 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3979
3980 "}\n";
3981
3982 static const char *geomShaderText =
3983 "#version 330\n"
3984 "#extension GL_ARB_separate_shader_objects : enable\n"
3985 "#extension GL_ARB_shading_language_420pack : enable\n"
3986 "layout( triangles ) in;\n"
3987 "layout( triangle_strip, max_vertices = 18 ) out;\n"
3988
3989 "layout(location = 0) out vec4 outColor;\n"
3990
3991 "void main()\n"
3992 "{\n"
3993 // init with first position to get zw
3994 " gl_Position = gl_in[0].gl_Position;\n"
3995
3996 " vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3997 " vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
3998 " vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
3999 " vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
4000
4001 // different color per tri
4002 " vec4[6] colors = { red, white, \n"
4003 " yellow, white, \n"
4004 " blue, white }; \n"
4005
4006 // fan out the triangles
4007 " vec2[18] positions = { vec2(0.0, 0.0), vec2(-0.5, 0.0), vec2(-0.25, -0.5), \n"
4008 " vec2(0.0, 0.0), vec2(-0.25, -0.5), vec2( 0.25, -0.5), \n"
4009 " vec2(0.0, 0.0), vec2( 0.25, -0.5), vec2( 0.5, 0.0), \n"
4010 " vec2(0.0, 0.0), vec2( 0.5, 0.0), vec2( 0.25, 0.5), \n"
4011 " vec2(0.0, 0.0), vec2( 0.25, 0.5), vec2(-0.25, 0.5), \n"
4012 " vec2(0.0, 0.0), vec2(-0.25, 0.5), vec2(-0.5, 0.0) }; \n"
4013
4014 // make a triangle list of 6
4015 " for (int i = 0; i < 6; ++i) { \n"
4016 " outColor = colors[i]; \n"
4017 " for (int j = 0; j < 3; ++j) { \n"
4018 " gl_Position.xy = positions[i * 3 + j]; \n"
4019 " EmitVertex(); \n"
4020 " } \n"
4021 " EndPrimitive();\n"
4022 " } \n"
4023
4024 "}\n";
4025
4026
4027 static const char *fragShaderText =
4028 "#version 150\n"
4029 "#extension GL_ARB_separate_shader_objects : enable\n"
4030 "#extension GL_ARB_shading_language_420pack : enable\n"
4031
4032
4033 "layout(binding = 0) uniform windowDimensions {\n"
4034 " vec4 dimensions;\n"
4035 "};\n"
4036
4037 "layout(location = 0) in vec4 inColor;\n"
4038 "layout(origin_upper_left) in vec4 gl_FragCoord;\n"
GregFaae75242015-06-03 18:40:50 -06004039 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06004040
4041 "void main() {\n"
4042
4043 // discard to make a nice circle
4044 " vec2 pos = abs(gl_FragCoord.xy) - vec2(dimensions.x, dimensions.y) / 2;\n"
4045 " float dist = sqrt(dot(pos, pos));\n"
4046 " if (dist > 50.0)\n"
4047 " discard;\n"
4048
GregFaae75242015-06-03 18:40:50 -06004049 " outColor = inColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06004050
4051 "}\n";
4052
4053
4054
4055 ASSERT_NO_FATAL_FAILURE(InitState());
4056 ASSERT_NO_FATAL_FAILURE(InitViewport());
4057
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004058 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4059 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY_BIT, this);
4060 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northrop475663c2015-04-15 11:19:06 -06004061
4062 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004063 pipelineobj.AddColorAttachment();
Cody Northrop475663c2015-04-15 11:19:06 -06004064 pipelineobj.AddShader(&vs);
4065 pipelineobj.AddShader(&gs);
4066 pipelineobj.AddShader(&ps);
4067
4068 const float dimensions[4] = { VkRenderFramework::m_width, VkRenderFramework::m_height , 0.0, 0.0};
4069
4070 VkConstantBufferObj windowDimensions(m_device, sizeof(dimensions) / sizeof(dimensions[0]), sizeof(dimensions[0]), (const void*) dimensions);
4071
4072 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004073 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop475663c2015-04-15 11:19:06 -06004074
4075 VkDescriptorSetObj descriptorSet(m_device);
4076 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, windowDimensions);
4077
Tony Barbourfe3351b2015-07-28 10:17:20 -06004078 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop475663c2015-04-15 11:19:06 -06004079
4080 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06004081 Draw(3, 1, 0, 0);
Cody Northrop475663c2015-04-15 11:19:06 -06004082
4083 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06004084 EndCommandBuffer();
4085 QueueCommandBuffer();
Cody Northrop475663c2015-04-15 11:19:06 -06004086
4087 RecordImages(m_renderTargets);
4088}
4089
Chris Forbese182fe02015-06-15 09:32:35 +12004090TEST_F(VkRenderTest, RenderPassLoadOpClear)
4091{
4092 ASSERT_NO_FATAL_FAILURE(InitState());
4093 ASSERT_NO_FATAL_FAILURE(InitViewport());
4094
4095 /* clear via load op to full green */
4096 m_clear_via_load_op = true;
Cody Northrop85789d52015-08-25 15:26:38 -06004097 m_clear_color.float32[0] = 0;
4098 m_clear_color.float32[1] = 1;
4099 m_clear_color.float32[2] = 0;
4100 m_clear_color.float32[3] = 0;
Chris Forbese182fe02015-06-15 09:32:35 +12004101 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004102 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Chris Forbese182fe02015-06-15 09:32:35 +12004103 /* This command buffer contains ONLY the load op! */
Tony Barbourfe3351b2015-07-28 10:17:20 -06004104 EndCommandBuffer();
4105 QueueCommandBuffer();
Chris Forbese182fe02015-06-15 09:32:35 +12004106
4107 RecordImages(m_renderTargets);
4108}
4109
Chris Forbesfa27b952015-06-24 12:05:30 +12004110TEST_F(VkRenderTest, RenderPassAttachmentClear)
4111{
4112 ASSERT_NO_FATAL_FAILURE(InitState());
4113 ASSERT_NO_FATAL_FAILURE(InitViewport());
4114
4115 /* clear via load op to full red */
4116 m_clear_via_load_op = true;
Cody Northrop85789d52015-08-25 15:26:38 -06004117 m_clear_color.float32[0] = 1;
4118 m_clear_color.float32[1] = 0;
4119 m_clear_color.float32[2] = 0;
4120 m_clear_color.float32[3] = 0;
Chris Forbesfa27b952015-06-24 12:05:30 +12004121 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004122 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Chris Forbesfa27b952015-06-24 12:05:30 +12004123
4124 /* Load op has cleared to red */
4125
4126 /* Draw, draw, draw... */
4127
4128 /* Now, partway through this renderpass we want to clear the color
4129 * attachment again, this time to green.
4130 */
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004131 VkClearAttachment color_attachment;
4132 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4133 color_attachment.clearValue.color.float32[0] = 0;
4134 color_attachment.clearValue.color.float32[1] = 1;
4135 color_attachment.clearValue.color.float32[2] = 0;
4136 color_attachment.clearValue.color.float32[3] = 0;
4137 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004138 VkClearRect clear_rect = { { { 0, 0 }, { (int)m_width, (int)m_height } } };
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004139 vkCmdClearAttachments(m_commandBuffer->handle(), 1, &color_attachment,
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004140 1, &clear_rect);
Chris Forbesfa27b952015-06-24 12:05:30 +12004141
Tony Barbourfe3351b2015-07-28 10:17:20 -06004142 EndCommandBuffer();
4143 QueueCommandBuffer();
Chris Forbesfa27b952015-06-24 12:05:30 +12004144
4145 RecordImages(m_renderTargets);
4146}
4147
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06004148int main(int argc, char **argv) {
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004149 int result;
4150
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06004151 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -06004152 VkTestFramework::InitArgs(&argc, argv);
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004153
Chia-I Wu6f184292014-12-15 23:57:34 +08004154 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchtera0f74c52014-10-08 08:46:51 -06004155
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004156 result = RUN_ALL_TESTS();
4157
Tony Barbour6918cd52015-04-09 12:58:51 -06004158 VkTestFramework::Finish();
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004159 return result;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06004160}