blob: 86a6dd6ae8537ce8ef2e533bdf286d35bdbd3646 [file] [log] [blame]
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06001// Copyright 2005, Google Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14// * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060031// VK tests
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060032//
33// Copyright (C) 2014 LunarG, Inc.
34//
35// Permission is hereby granted, free of charge, to any person obtaining a
36// copy of this software and associated documentation files (the "Software"),
37// to deal in the Software without restriction, including without limitation
38// the rights to use, copy, modify, merge, publish, distribute, sublicense,
39// and/or sell copies of the Software, and to permit persons to whom the
40// Software is furnished to do so, subject to the following conditions:
41//
42// The above copyright notice and this permission notice shall be included
43// in all copies or substantial portions of the Software.
44//
45// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
48// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
49// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
50// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
51// DEALINGS IN THE SOFTWARE.
52
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060053// Basic rendering tests
54
55#include <stdlib.h>
56#include <stdio.h>
57#include <stdbool.h>
58#include <string.h>
Courtney Goeltzenleuchterda91b952014-08-21 17:34:22 -060059#include <iostream>
60#include <fstream>
61using namespace std;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060062
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060063#include <vulkan.h>
Tobin Ehlis11e52132014-11-28 11:17:19 -070064#ifdef DUMP_STATE_DOT
65#include "../layers/draw_state.h"
66#endif
Tobin Ehlisca915872014-11-18 11:28:33 -070067#ifdef PRINT_OBJECTS
68#include "../layers/object_track.h"
69#endif
Tobin Ehlis6663f492014-11-10 12:29:12 -070070#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060071#include <vk_debug_report_lunarg.h>
Tobin Ehlis6663f492014-11-10 12:29:12 -070072#endif
Courtney Goeltzenleuchter58f3eff2015-10-07 13:28:58 -060073#include "test_common.h"
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060074
Cody Northrop054a4702015-03-17 14:54:35 -060075#include "icd-spv.h"
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060076
Courtney Goeltzenleuchterfdcfb9f2014-10-10 18:04:39 -060077#define GLM_FORCE_RADIANS
78#include "glm/glm.hpp"
79#include <glm/gtc/matrix_transform.hpp>
80
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060081#include "vkrenderframework.h"
Tobin Ehlis6663f492014-11-10 12:29:12 -070082#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060083void VKAPI myDbgFunc(
84 VK_DBG_MSG_TYPE msgType,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060085 VkValidationLevel validationLevel,
Mike Stroyanb050c682015-04-17 12:36:38 -060086 VkObject srcObject,
Mark Lobodzinski17caf572015-01-29 08:55:56 -060087 size_t location,
88 int32_t msgCode,
89 const char* pMsg,
90 void* pUserData)
Tobin Ehlis6663f492014-11-10 12:29:12 -070091{
Tobin Ehlisca915872014-11-18 11:28:33 -070092 switch (msgType)
93 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060094 case VK_DBG_MSG_WARNING:
Tobin Ehlisca915872014-11-18 11:28:33 -070095 printf("CALLBACK WARNING : %s\n", pMsg);
96 break;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060097 case VK_DBG_REPORT_ERROR_BIT:
Tobin Ehlisca915872014-11-18 11:28:33 -070098 printf("CALLBACK ERROR : %s\n", pMsg);
99 break;
100 default:
101 printf("EATING Msg of type %u\n", msgType);
102 break;
103 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700104}
105#endif
Tony Barboure2c58df2014-11-25 13:18:32 -0700106
107
108#undef ASSERT_NO_FATAL_FAILURE
109#define ASSERT_NO_FATAL_FAILURE(x) x
110
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600111//--------------------------------------------------------------------------------------
112// Mesh and VertexFormat Data
113//--------------------------------------------------------------------------------------
114struct Vertex
115{
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600116 float posX, posY, posZ, posW; // Position data
117 float r, g, b, a; // Color
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600118};
119
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600120struct VertexUV
121{
122 float posX, posY, posZ, posW; // Position data
123 float u, v; // texture u,v
124};
125
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600126#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600127#define UV(_u_, _v_) (_u_), (_v_)
Courtney Goeltzenleuchter02461882014-08-22 16:27:58 -0600128
129static const Vertex g_vbData[] =
130{
131 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
132 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
133 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
134 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
135 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
136 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
137
138 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
139 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
140 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
141 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
142 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
143 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
144
145 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
146 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
147 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
148 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
149 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
150 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
151
152 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
153 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
154 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
155 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
156 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
157 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
158
159 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
160 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
161 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
162 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
163 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
164 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
165
166 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
167 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
168 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
169 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
170 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
171 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
172};
173
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600174static const Vertex g_vb_solid_face_colors_Data[] =
175{
176 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600177 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600178 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
179 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600180 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
181 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600182
183 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
184 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600185 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
186 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600187 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600188 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600189
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600190 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
191 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
192 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
193 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
194 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
195 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600196
197 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
198 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
199 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
200 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
201 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
202 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
203
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600204 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600205 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600206 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
207 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600208 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
209 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
210
211 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
212 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
213 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
214 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
215 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
216 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
217};
218
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600219static const VertexUV g_vb_texture_Data[] =
220{
221 { XYZ1( -1, -1, -1 ), UV( 0.f, 0.f ) },
222 { XYZ1( -1, 1, 1 ), UV( 1.f, 1.f ) },
223 { XYZ1( -1, -1, 1 ), UV( 1.f, 0.f ) },
224 { XYZ1( -1, 1, 1 ), UV( 1.f, 1.f ) },
225 { XYZ1( -1, -1, -1 ), UV( 0.f, 0.f ) },
226 { XYZ1( -1, 1, -1 ), UV( 0.f, 1.f ) },
227
228 { XYZ1( -1, -1, -1 ), UV( 1.f, 0.f ) },
229 { XYZ1( 1, -1, -1 ), UV( 0.f, 0.f ) },
230 { XYZ1( 1, 1, -1 ), UV( 0.f, 1.f ) },
231 { XYZ1( -1, -1, -1 ), UV( 1.f, 0.f ) },
232 { XYZ1( 1, 1, -1 ), UV( 0.f, 1.f ) },
233 { XYZ1( -1, 1, -1 ), UV( 1.f, 1.f ) },
234
235 { XYZ1( -1, -1, -1 ), UV( 1.f, 1.f ) },
236 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
237 { XYZ1( 1, -1, -1 ), UV( 1.f, 0.f ) },
238 { XYZ1( -1, -1, -1 ), UV( 1.f, 1.f ) },
239 { XYZ1( -1, -1, 1 ), UV( 0.f, 1.f ) },
240 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
241
242 { XYZ1( -1, 1, -1 ), UV( 1.f, 1.f ) },
243 { XYZ1( 1, 1, 1 ), UV( 0.f, 0.f ) },
244 { XYZ1( -1, 1, 1 ), UV( 0.f, 1.f ) },
245 { XYZ1( -1, 1, -1 ), UV( 1.f, 1.f ) },
246 { XYZ1( 1, 1, -1 ), UV( 1.f, 0.f ) },
247 { XYZ1( 1, 1, 1 ), UV( 0.f, 0.f ) },
248
249 { XYZ1( 1, 1, -1 ), UV( 1.f, 1.f ) },
250 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
251 { XYZ1( 1, 1, 1 ), UV( 0.f, 1.f ) },
252 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
253 { XYZ1( 1, 1, -1 ), UV( 1.f, 1.f ) },
254 { XYZ1( 1, -1, -1 ), UV( 1.f, 0.f ) },
255
256 { XYZ1( -1, 1, 1 ), UV( 0.f, 1.f ) },
257 { XYZ1( 1, 1, 1 ), UV( 1.f, 1.f ) },
258 { XYZ1( -1, -1, 1 ), UV( 0.f, 0.f ) },
259 { XYZ1( -1, -1, 1 ), UV( 0.f, 0.f ) },
260 { XYZ1( 1, 1, 1 ), UV( 1.f, 1.f ) },
261 { XYZ1( 1, -1, 1 ), UV( 1.f, 0.f ) },
262};
263
Tony Barbour6918cd52015-04-09 12:58:51 -0600264class VkRenderTest : public VkRenderFramework
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -0600265{
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600266public:
Cody Northrop7ad4aaf2014-10-09 21:25:22 -0600267
Tony Barboure2c58df2014-11-25 13:18:32 -0700268 void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbour6918cd52015-04-09 12:58:51 -0600269 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer);
270 void GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600271 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet)
272 { GenericDrawPreparation(m_cmdBuffer, pipelineobj, descriptorSet); }
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600273 void InitDepthStencil();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600274 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate);
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600275
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600276 VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer);
Tobin Ehlisf1878c72015-08-18 14:24:32 -0600277 VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer, VkCmdBufferBeginInfo *beginInfo);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600278 VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600279 /* Convenience functions that use built-in command buffer */
280 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_cmdBuffer); }
Tobin Ehlisf1878c72015-08-18 14:24:32 -0600281 VkResult BeginCommandBuffer(VkCmdBufferBeginInfo *beginInfo) { return BeginCommandBuffer(*m_cmdBuffer, beginInfo); }
Tony Barbourfe3351b2015-07-28 10:17:20 -0600282 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_cmdBuffer); }
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600283 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
284 { m_cmdBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance); }
285 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance)
286 { m_cmdBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); }
Tony Barbourfe3351b2015-07-28 10:17:20 -0600287 void QueueCommandBuffer() { m_cmdBuffer->QueueCommandBuffer(); }
288 void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
289 VkConstantBufferObj *constantBuffer)
290 {RotateTriangleVSUniform(Projection, View, Model, constantBuffer, m_cmdBuffer); }
291 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding)
292 { m_cmdBuffer->BindVertexBuffer(vertexBuffer, offset, binding); }
293 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset)
294 { m_cmdBuffer->BindIndexBuffer(indexBuffer, offset); }
295
296
Cody Northropee6586d2014-10-09 19:55:56 -0600297
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600298protected:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600299 VkImage m_texture;
300 VkImageView m_textureView;
Tony Barbourd1c35722015-04-16 15:59:00 -0600301 VkDeviceMemory m_textureMem;
Cody Northrop7d2035d2014-10-06 15:42:00 -0600302
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600303 VkSampler m_sampler;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600304
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600305
306 virtual void SetUp() {
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600307
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600308 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600309 this->app_info.pNext = NULL;
Chia-I Wuf1a5a742014-12-27 15:16:07 +0800310 this->app_info.pAppName = "render_tests";
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600311 this->app_info.appVersion = 1;
Chia-I Wuf1a5a742014-12-27 15:16:07 +0800312 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600313 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600314 this->app_info.apiVersion = VK_API_VERSION;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600315
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600316 InitFramework();
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600317 }
318
319 virtual void TearDown() {
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600320 // Clean up resources before we reset
321 ShutdownFramework();
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600322 }
323};
324
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600325VkResult VkRenderTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600326{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600327 VkResult result;
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600328
329 result = cmdBuffer.BeginCommandBuffer();
330
331 /*
332 * For render test all drawing happens in a single render pass
333 * on a single command buffer.
334 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200335 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu08accc62015-07-07 11:50:03 +0800336 cmdBuffer.BeginRenderPass(renderPassBeginInfo());
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600337 }
338
339 return result;
340}
341
Tobin Ehlisf1878c72015-08-18 14:24:32 -0600342VkResult VkRenderTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer, VkCmdBufferBeginInfo *beginInfo)
343{
344 VkResult result;
345
346 result = cmdBuffer.BeginCommandBuffer(beginInfo);
347
348 /*
349 * For render test all drawing happens in a single render pass
350 * on a single command buffer.
351 */
352 if (VK_SUCCESS == result && renderPass()) {
353 cmdBuffer.BeginRenderPass(renderPassBeginInfo());
354 }
355
356 return result;
357}
358
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600359VkResult VkRenderTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600360{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600361 VkResult result;
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600362
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200363 if (renderPass()) {
Chia-I Wu0b50a1c2015-06-26 15:34:39 +0800364 cmdBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200365 }
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600366
367 result = cmdBuffer.EndCommandBuffer();
368
369 return result;
370}
371
372
Tony Barbour6918cd52015-04-09 12:58:51 -0600373void VkRenderTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet)
Tony Barbour22e32a12015-01-08 17:08:28 -0700374{
Tony Barbour71bd4b32015-07-21 17:00:26 -0600375 if (!m_clear_via_load_op) {
376 if (m_depthStencil->Initialized()) {
377 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
378 } else {
379 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
380 }
Tony Barbour1c45ce02015-03-27 17:03:18 -0600381 }
382
Jeremy Hayesd65ae082015-01-14 16:17:08 -0700383 cmdBuffer->PrepareAttachments();
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600384 cmdBuffer->SetViewport(m_viewports.size(), m_viewports.data());
385 cmdBuffer->SetScissor(m_scissors.size(), m_scissors.data());
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600386
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600387 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
Cody Northrop29a08f22015-08-27 10:20:35 -0600388 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
389 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600390 cmdBuffer->BindPipeline(pipelineobj);
Chia-I Wu53f07d72015-03-28 15:23:55 +0800391 cmdBuffer->BindDescriptorSet(descriptorSet);
Tony Barbour22e32a12015-01-08 17:08:28 -0700392}
Tony Barboure2c58df2014-11-25 13:18:32 -0700393
Tony Barbour6918cd52015-04-09 12:58:51 -0600394void VkRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
395 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer)
Tony Barbour664accc2015-01-09 12:55:14 -0700396{
397 int i;
398 glm::mat4 MVP;
399 int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600400 VkResult err;
Tony Barbour664accc2015-01-09 12:55:14 -0700401
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600402 /* Only do 3 positions to avoid back face cull */
403 for (i = 0; i < 3; i++) {
Chia-I Wu681d7a02015-07-03 13:44:34 +0800404 void *pData = constantBuffer->memory().map();
Tony Barbour664accc2015-01-09 12:55:14 -0700405
406 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
407 MVP = Projection * View * Model;
408 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
409
Chia-I Wu681d7a02015-07-03 13:44:34 +0800410 constantBuffer->memory().unmap();
Tony Barbour664accc2015-01-09 12:55:14 -0700411
412 // submit the command buffer to the universal queue
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600413 cmdBuffer->QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -0700414
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600415 err = vkQueueWaitIdle( m_device->m_queue );
416 ASSERT_VK_SUCCESS( err );
Tony Barbour664accc2015-01-09 12:55:14 -0700417
418 // Wait for work to finish before cleaning up.
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600419 vkDeviceWaitIdle(m_device->device());
Tony Barbour664accc2015-01-09 12:55:14 -0700420
Courtney Goeltzenleuchterb4337c12015-03-05 16:47:18 -0700421 assert(m_renderTargets.size() == 1);
Tony Barbour664accc2015-01-09 12:55:14 -0700422 RecordImage(m_renderTargets[0]);
423 }
424}
Courtney Goeltzenleuchterc55471f2014-10-13 13:03:31 -0600425
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600426void dumpMatrix(const char *note, glm::mat4 MVP)
427{
Chia-I Wu6f184292014-12-15 23:57:34 +0800428 int i;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600429
430 printf("%s: \n", note);
431 for (i=0; i<4; i++) {
432 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
433 }
434 printf("\n");
435 fflush(stdout);
436}
437
438void dumpVec4(const char *note, glm::vec4 vector)
439{
440 printf("%s: \n", note);
441 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
442 printf("\n");
443 fflush(stdout);
444}
445
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600446struct vktriangle_vs_uniform {
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600447 // Must start with MVP
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600448 float mvp[4][4];
449 float position[3][4];
450 float color[3][4];
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600451};
452
Tony Barbour6918cd52015-04-09 12:58:51 -0600453void VkRenderTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600454{
Tobin Ehlis6663f492014-11-10 12:29:12 -0700455#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600456 vkDbgRegisterMsgCallback(inst, myDbgFunc, NULL);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700457#endif
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600458 // Create identity matrix
459 int i;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600460 struct vktriangle_vs_uniform data;
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600461
462 glm::mat4 Projection = glm::mat4(1.0f);
463 glm::mat4 View = glm::mat4(1.0f);
464 glm::mat4 Model = glm::mat4(1.0f);
465 glm::mat4 MVP = Projection * View * Model;
466 const int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600467 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600468 memcpy(&data.mvp, &MVP[0][0], matrixSize);
469
470 static const Vertex tri_data[] =
471 {
472 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
473 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
474 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
475 };
476
477 for (i=0; i<3; i++) {
478 data.position[i][0] = tri_data[i].posX;
479 data.position[i][1] = tri_data[i].posY;
480 data.position[i][2] = tri_data[i].posZ;
481 data.position[i][3] = tri_data[i].posW;
482 data.color[i][0] = tri_data[i].r;
483 data.color[i][1] = tri_data[i].g;
484 data.color[i][2] = tri_data[i].b;
485 data.color[i][3] = tri_data[i].a;
486 }
487
Tony Barboure2c58df2014-11-25 13:18:32 -0700488 ASSERT_NO_FATAL_FAILURE(InitState());
489 ASSERT_NO_FATAL_FAILURE(InitViewport());
490
Tony Barbour6918cd52015-04-09 12:58:51 -0600491 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barboure2c58df2014-11-25 13:18:32 -0700492
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -0600493 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
494 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -0700495
Tony Barbour6918cd52015-04-09 12:58:51 -0600496 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800497 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -0700498 pipelineobj.AddShader(&vs);
499 pipelineobj.AddShader(&ps);
500
Tony Barbour6918cd52015-04-09 12:58:51 -0600501 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600502 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -0700503
Tony Barbourd726a172015-01-09 16:12:35 -0700504 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf1878c72015-08-18 14:24:32 -0600505
506 VkCmdBufferBeginInfo cbBeginInfo;
507 memset(&cbBeginInfo, 0, sizeof(VkCmdBufferBeginInfo));
508 cbBeginInfo.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
Courtney Goeltzenleuchter04bb5f82015-10-21 18:11:04 -0600509 cbBeginInfo.flags = 0;
Tobin Ehlisf1878c72015-08-18 14:24:32 -0600510 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barboure2c58df2014-11-25 13:18:32 -0700511
Tony Barbourfe3351b2015-07-28 10:17:20 -0600512 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourd726a172015-01-09 16:12:35 -0700513#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600514 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourd726a172015-01-09 16:12:35 -0700515 pDSDumpDot((char*)"triTest2.dot");
516#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600517
Tony Barbourd726a172015-01-09 16:12:35 -0700518 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600519 Draw(3, 1, 0, 0);
Tony Barbourd726a172015-01-09 16:12:35 -0700520
521 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600522 ASSERT_VK_SUCCESS(EndCommandBuffer());
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600523
Tony Barbourfe3351b2015-07-28 10:17:20 -0600524 QueueCommandBuffer();
Tony Barbourd726a172015-01-09 16:12:35 -0700525
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600526 RecordImages(m_renderTargets);
Tony Barbourd726a172015-01-09 16:12:35 -0700527
528 if (rotate)
Tony Barbourfe3351b2015-07-28 10:17:20 -0600529 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer);
Tony Barbourd726a172015-01-09 16:12:35 -0700530
Tobin Ehlisca915872014-11-18 11:28:33 -0700531#ifdef PRINT_OBJECTS
Mark Lobodzinski7c75b852015-05-05 15:01:37 -0500532 OBJ_TRACK_GET_OBJECTS_COUNT pObjTrackGetObjectsCount = (OBJ_TRACK_GET_OBJECTS_COUNT)vkGetProcAddr(gpu(), (char*)"objTrackGetObjectsCount");
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600533 uint64_t numObjects = pObjTrackGetObjectsCount(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600534 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlisca915872014-11-18 11:28:33 -0700535 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600536 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlisca915872014-11-18 11:28:33 -0700537 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600538 pObjTrackGetObjs(m_device, numObjects, pObjNodeArray);
Tobin Ehlisca915872014-11-18 11:28:33 -0700539 for (i=0; i < numObjects; i++) {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600540 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 -0700541 }
542 free(pObjNodeArray);
543#endif
Tony Barboure2c58df2014-11-25 13:18:32 -0700544
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600545}
546
Tony Barbour6918cd52015-04-09 12:58:51 -0600547TEST_F(VkRenderTest, VKTriangle_FragColor)
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600548{
549 static const char *vertShaderText =
550 "#version 140\n"
551 "#extension GL_ARB_separate_shader_objects : enable\n"
552 "#extension GL_ARB_shading_language_420pack : enable\n"
553 "\n"
554 "layout(binding = 0) uniform buf {\n"
555 " mat4 MVP;\n"
556 " vec4 position[3];\n"
557 " vec4 color[3];\n"
558 "} ubuf;\n"
559 "\n"
560 "layout (location = 0) out vec4 outColor;\n"
561 "\n"
562 "void main() \n"
563 "{\n"
564 " outColor = ubuf.color[gl_VertexID];\n"
565 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
566 "}\n";
567
568 static const char *fragShaderText =
569 "#version 140\n"
570 "#extension GL_ARB_separate_shader_objects : enable\n"
571 "#extension GL_ARB_shading_language_420pack : enable\n"
572 "\n"
573 "layout (location = 0) in vec4 inColor;\n"
GregFaae75242015-06-03 18:40:50 -0600574 "layout (location = 0) out vec4 uFragColor;\n"
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600575 "\n"
576 "void main()\n"
577 "{\n"
GregFaae75242015-06-03 18:40:50 -0600578 " uFragColor = inColor;\n"
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600579 "}\n";
580
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600581 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
582 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600583}
584
Tony Barbour6918cd52015-04-09 12:58:51 -0600585TEST_F(VkRenderTest, VKTriangle_OutputLocation)
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600586{
587 static const char *vertShaderText =
588 "#version 140\n"
589 "#extension GL_ARB_separate_shader_objects : enable\n"
590 "#extension GL_ARB_shading_language_420pack : enable\n"
591 "\n"
592 "layout(binding = 0) uniform buf {\n"
593 " mat4 MVP;\n"
594 " vec4 position[3];\n"
595 " vec4 color[3];\n"
596 "} ubuf;\n"
597 "\n"
598 "layout (location = 0) out vec4 outColor;\n"
599 "\n"
600 "void main() \n"
601 "{\n"
602 " outColor = ubuf.color[gl_VertexID];\n"
603 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
604 "}\n";
605
606 static const char *fragShaderText =
607 "#version 140\n"
608 "#extension GL_ARB_separate_shader_objects : enable\n"
609 "#extension GL_ARB_shading_language_420pack : enable\n"
610 "\n"
611 "layout (location = 0) in vec4 inColor;\n"
612 "layout (location = 0) out vec4 outColor;\n"
613 "\n"
614 "void main()\n"
615 "{\n"
616 " outColor = inColor;\n"
617 "}\n";
618
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600619 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 -0600620
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600621 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600622}
Cody Northrop6922da12015-06-23 13:25:51 -0600623
Tony Barbour6918cd52015-04-09 12:58:51 -0600624TEST_F(VkRenderTest, SPV_VKTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -0700625{
Tony Barboure2c58df2014-11-25 13:18:32 -0700626 static const char *vertShaderText =
627 "#version 140\n"
628 "#extension GL_ARB_separate_shader_objects : enable\n"
629 "#extension GL_ARB_shading_language_420pack : enable\n"
630 "\n"
631 "layout(binding = 0) uniform buf {\n"
632 " mat4 MVP;\n"
633 " vec4 position[3];\n"
634 " vec4 color[3];\n"
635 "} ubuf;\n"
636 "\n"
637 "layout (location = 0) out vec4 outColor;\n"
638 "\n"
639 "void main() \n"
640 "{\n"
641 " outColor = ubuf.color[gl_VertexID];\n"
642 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
643 "}\n";
644
645 static const char *fragShaderText =
646 "#version 140\n"
647 "#extension GL_ARB_separate_shader_objects : enable\n"
648 "#extension GL_ARB_shading_language_420pack : enable\n"
649 "\n"
650 "layout (location = 0) in vec4 inColor;\n"
GregFaae75242015-06-03 18:40:50 -0600651 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700652 "\n"
653 "void main()\n"
654 "{\n"
GregFaae75242015-06-03 18:40:50 -0600655 " outColor = inColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700656 "}\n";
657
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600658 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 -0700659
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600660 VKTriangleTest(vertShaderText, fragShaderText, true);
Tony Barboure2c58df2014-11-25 13:18:32 -0700661}
Courtney Goeltzenleuchter538062a2014-10-09 15:40:19 -0600662
Tony Barbour6918cd52015-04-09 12:58:51 -0600663TEST_F(VkRenderTest, SPV_GreenTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -0700664{
Tony Barboure2c58df2014-11-25 13:18:32 -0700665 static const char *vertShaderText =
666 "#version 130\n"
667 "vec2 vertices[3];\n"
668 "void main() {\n"
669 " vertices[0] = vec2(-1.0, -1.0);\n"
670 " vertices[1] = vec2( 1.0, -1.0);\n"
671 " vertices[2] = vec2( 0.0, 1.0);\n"
672 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
673 "}\n";
674
675 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -0600676 "#version 140\n"
677 "#extension GL_ARB_separate_shader_objects : enable\n"
678 "#extension GL_ARB_shading_language_420pack : enable\n"
679 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700680 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600681 " outColor = vec4(0,1,0,1);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700682 "}\n";
683
Cody Northrop3bfd27c2015-03-17 15:55:58 -0600684 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barboure2c58df2014-11-25 13:18:32 -0700685
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600686 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barboure2c58df2014-11-25 13:18:32 -0700687}
Cody Northrop6922da12015-06-23 13:25:51 -0600688
Tony Barbour6918cd52015-04-09 12:58:51 -0600689TEST_F(VkRenderTest, YellowTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -0700690{
691 static const char *vertShaderText =
692 "#version 130\n"
693 "void main() {\n"
694 " vec2 vertices[3];"
695 " vertices[0] = vec2(-0.5, -0.5);\n"
696 " vertices[1] = vec2( 0.5, -0.5);\n"
697 " vertices[2] = vec2( 0.5, 0.5);\n"
698 " vec4 colors[3];\n"
699 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
700 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
701 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
702 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
703 "}\n";
704
705 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -0600706 "#version 140\n"
707 "#extension GL_ARB_separate_shader_objects : enable\n"
708 "#extension GL_ARB_shading_language_420pack : enable\n"
709 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700710 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600711 " outColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700712 "}\n";
713
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600714 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barboure2c58df2014-11-25 13:18:32 -0700715}
716
Tony Barbour6918cd52015-04-09 12:58:51 -0600717TEST_F(VkRenderTest, QuadWithVertexFetch)
Cody Northropee6586d2014-10-09 19:55:56 -0600718{
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600719 static const char *vertShaderText =
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600720 "#version 140\n"
721 "#extension GL_ARB_separate_shader_objects : enable\n"
722 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700723 //XYZ1( -1, -1, -1 )
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600724 "layout (location = 0) in vec4 pos;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700725 //XYZ1( 0.f, 0.f, 0.f )
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600726 "layout (location = 1) in vec4 inColor;\n"
727 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600728 "void main() {\n"
Cody Northrop66594a72014-10-10 14:49:36 -0600729 " outColor = inColor;\n"
Cody Northrop7ad4aaf2014-10-09 21:25:22 -0600730 " gl_Position = pos;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600731 "}\n";
732
Cody Northropee6586d2014-10-09 19:55:56 -0600733
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600734 static const char *fragShaderText =
Cody Northropd43c52e2014-12-05 15:44:14 -0700735 "#version 140\n"
736 "#extension GL_ARB_separate_shader_objects : enable\n"
737 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600738 "layout (location = 0) in vec4 color;\n"
Cody Northropd43c52e2014-12-05 15:44:14 -0700739 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600740 "void main() {\n"
Cody Northropd43c52e2014-12-05 15:44:14 -0700741 " outColor = color;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600742 "}\n";
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600743
Tony Barboure2c58df2014-11-25 13:18:32 -0700744
745
746 ASSERT_NO_FATAL_FAILURE(InitState());
747 ASSERT_NO_FATAL_FAILURE(InitViewport());
748
Tony Barbour6918cd52015-04-09 12:58:51 -0600749 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000750 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -0700751
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -0600752 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
753 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -0700754
Tony Barbour6918cd52015-04-09 12:58:51 -0600755 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800756 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -0700757 pipelineobj.AddShader(&vs);
758 pipelineobj.AddShader(&ps);
759
Tony Barbour6918cd52015-04-09 12:58:51 -0600760 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -0600761
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600762#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600763 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600764 MESH_BIND_ID, // binding ID
Tony Barboure2c58df2014-11-25 13:18:32 -0700765 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600766 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barboure2c58df2014-11-25 13:18:32 -0700767 };
768
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600769 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600770 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
771 vi_attribs[0].location = 0; // location, position
Tony Barbourd1c35722015-04-16 15:59:00 -0600772 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600773 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
774 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
775 vi_attribs[1].location = 1; // location, color
Tony Barbourd1c35722015-04-16 15:59:00 -0600776 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600777 vi_attribs[1].offsetInBytes = 1*sizeof(float)*4; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -0700778
779 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
780 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barboure2c58df2014-11-25 13:18:32 -0700781
Tony Barbour1fde6942015-01-09 10:06:53 -0700782 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600783 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure2c58df2014-11-25 13:18:32 -0700784
Tony Barbourfe3351b2015-07-28 10:17:20 -0600785 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600786
Tony Barbourfe3351b2015-07-28 10:17:20 -0600787 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour1fde6942015-01-09 10:06:53 -0700788
789 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600790 Draw(6, 1, 0, 0);
Tony Barbour1fde6942015-01-09 10:06:53 -0700791
792 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600793 ASSERT_VK_SUCCESS(EndCommandBuffer());
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600794
Tony Barbourfe3351b2015-07-28 10:17:20 -0600795 QueueCommandBuffer();
Tony Barbour1fde6942015-01-09 10:06:53 -0700796
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600797 RecordImages(m_renderTargets);
Tobin Ehlisd806c8e2014-10-07 14:41:29 -0600798}
799
Tony Barbour6918cd52015-04-09 12:58:51 -0600800TEST_F(VkRenderTest, TriangleMRT)
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800801{
802 static const char *vertShaderText =
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600803 "#version 140\n"
804 "#extension GL_ARB_separate_shader_objects : enable\n"
805 "#extension GL_ARB_shading_language_420pack : enable\n"
806 "layout (location = 0) in vec4 pos;\n"
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800807 "void main() {\n"
808 " gl_Position = pos;\n"
809 "}\n";
810
811 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -0600812 "#version 140\n"
813 "#extension GL_ARB_separate_shader_objects : enable\n"
814 "#extension GL_ARB_shading_language_420pack : enable\n"
815 "layout (location = 0) out vec4 uFragData0;\n"
816 "layout (location = 1) out vec4 uFragData1;\n"
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800817 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600818 " uFragData0 = vec4(1.0, 0.0, 0.0, 1.0);\n"
819 " uFragData1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800820 "}\n";
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600821 const float vb_data[][2] = {
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800822 { -1.0f, -1.0f },
823 { 1.0f, -1.0f },
824 { -1.0f, 1.0f }
825 };
826
827 ASSERT_NO_FATAL_FAILURE(InitState());
828 ASSERT_NO_FATAL_FAILURE(InitViewport());
829
Tony Barbour6918cd52015-04-09 12:58:51 -0600830 VkConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000831 meshBuffer.BufferMemoryBarrier();
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800832
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -0600833 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
834 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800835
Tony Barbour6918cd52015-04-09 12:58:51 -0600836 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800837 pipelineobj.AddColorAttachment();
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800838 pipelineobj.AddShader(&vs);
839 pipelineobj.AddShader(&ps);
840
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600841#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600842 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600843 MESH_BUF_ID, // Binding ID
844 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600845 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800846 };
847
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600848 VkVertexInputAttributeDescription vi_attrib;
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600849 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
850 vi_attrib.location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -0600851 vi_attrib.format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600852 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800853
854 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
855 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800856
Tony Barbour6918cd52015-04-09 12:58:51 -0600857 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800858
Courtney Goeltzenleuchterb4337c12015-03-05 16:47:18 -0700859 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800860
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600861 VkPipelineColorBlendAttachmentState att = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600862 att.blendEnable = VK_FALSE;
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800863 att.channelWriteMask = 0xf;
Tony Barbourf52346d2015-01-16 14:27:35 -0700864 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800865
Tony Barbourfe3351b2015-07-28 10:17:20 -0600866 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour1fde6942015-01-09 10:06:53 -0700867
Tony Barbourfe3351b2015-07-28 10:17:20 -0600868 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour1fde6942015-01-09 10:06:53 -0700869
Tony Barbourfe3351b2015-07-28 10:17:20 -0600870 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour304ec8b2015-01-07 14:31:52 -0700871#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600872 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour304ec8b2015-01-07 14:31:52 -0700873 pDSDumpDot((char*)"triTest2.dot");
874#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600875
Tony Barbour304ec8b2015-01-07 14:31:52 -0700876 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600877 Draw(3, 1, 0, 0);
Tony Barbour304ec8b2015-01-07 14:31:52 -0700878
879 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600880 ASSERT_VK_SUCCESS(EndCommandBuffer());
881 QueueCommandBuffer();
Tony Barbour304ec8b2015-01-07 14:31:52 -0700882
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600883 RecordImages(m_renderTargets);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800884}
885
Tony Barbour6918cd52015-04-09 12:58:51 -0600886TEST_F(VkRenderTest, QuadWithIndexedVertexFetch)
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700887{
888 static const char *vertShaderText =
889 "#version 140\n"
890 "#extension GL_ARB_separate_shader_objects : enable\n"
891 "#extension GL_ARB_shading_language_420pack : enable\n"
892 "layout(location = 0) in vec4 pos;\n"
893 "layout(location = 1) in vec4 inColor;\n"
894 "layout(location = 0) out vec4 outColor;\n"
895 "void main() {\n"
896 " outColor = inColor;\n"
897 " gl_Position = pos;\n"
898 "}\n";
899
900
901 static const char *fragShaderText =
902 "#version 140\n"
903 "#extension GL_ARB_separate_shader_objects : enable\n"
904 "#extension GL_ARB_shading_language_420pack : enable\n"
905 "layout(location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -0600906 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700907 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600908 " outColor = color;\n"
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700909 "}\n";
910
911 const Vertex g_vbData[] =
912 {
913 // first tri
914 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
915 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
916 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
917
918 // second tri
919 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
920 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
921 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
922 };
923
924 const uint16_t g_idxData[6] = {
925 0, 1, 2,
926 3, 4, 5,
927 };
928
929 ASSERT_NO_FATAL_FAILURE(InitState());
930 ASSERT_NO_FATAL_FAILURE(InitViewport());
931
Tony Barbour6918cd52015-04-09 12:58:51 -0600932 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000933 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700934
Tony Barbour6918cd52015-04-09 12:58:51 -0600935 VkIndexBufferObj indexBuffer(m_device);
Tony Barbourd1c35722015-04-16 15:59:00 -0600936 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), VK_INDEX_TYPE_UINT16, g_idxData);
Mark Lobodzinski49a6b4b2015-02-16 14:24:23 -0600937 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700938
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -0600939 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
940 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700941
Tony Barbour6918cd52015-04-09 12:58:51 -0600942 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800943 pipelineobj.AddColorAttachment();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700944 pipelineobj.AddShader(&vs);
945 pipelineobj.AddShader(&ps);
946
Tony Barbour6918cd52015-04-09 12:58:51 -0600947 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour831062d2015-04-02 15:43:15 -0600948
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700949
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600950#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600951 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600952 MESH_BIND_ID, // binding ID
953 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600954 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700955 };
956
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600957 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600958 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
959 vi_attribs[0].location = 0; // layout location of vertex attribute
Tony Barbourd1c35722015-04-16 15:59:00 -0600960 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600961 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
962 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
963 vi_attribs[1].location = 1; // layout location of vertex attribute
Tony Barbourd1c35722015-04-16 15:59:00 -0600964 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600965 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700966
967 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
968 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700969
970 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600971 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour1fde6942015-01-09 10:06:53 -0700972
Tony Barbourfe3351b2015-07-28 10:17:20 -0600973 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700974
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700975#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600976 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlisf27eba72014-12-16 17:34:50 -0700977 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700978#endif
Tony Barbour22e32a12015-01-08 17:08:28 -0700979
Tony Barbourfe3351b2015-07-28 10:17:20 -0600980 BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
981 BindIndexBuffer(&indexBuffer, 0);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700982
983 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600984 DrawIndexed(6, 1, 0, 0, 0);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700985
986 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600987 ASSERT_VK_SUCCESS(EndCommandBuffer());
988 QueueCommandBuffer();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700989
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600990 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700991}
992
Tony Barbour6918cd52015-04-09 12:58:51 -0600993TEST_F(VkRenderTest, GreyandRedCirclesonBlue)
GregF3156cb02014-12-02 15:41:44 -0700994{
995 // This tests gl_FragCoord
Tony Barboure2c58df2014-11-25 13:18:32 -0700996
GregF3156cb02014-12-02 15:41:44 -0700997 static const char *vertShaderText =
998 "#version 140\n"
999 "#extension GL_ARB_separate_shader_objects : enable\n"
1000 "#extension GL_ARB_shading_language_420pack : enable\n"
1001 "layout (location = 0) in vec4 pos;\n"
1002 "layout (location = 0) out vec4 outColor;\n"
1003 "layout (location = 1) out vec4 outColor2;\n"
1004 "void main() {\n"
1005 " gl_Position = pos;\n"
1006 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1007 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1008 "}\n";
1009
1010 static const char *fragShaderText =
GregF3156cb02014-12-02 15:41:44 -07001011 "#version 330\n"
1012 "#extension GL_ARB_separate_shader_objects : enable\n"
1013 "#extension GL_ARB_shading_language_420pack : enable\n"
1014 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1015 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1016 "layout (location = 0) in vec4 color;\n"
1017 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001018 "layout (location = 0) out vec4 outColor;\n"
GregF3156cb02014-12-02 15:41:44 -07001019 "void main() {\n"
1020 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1021 " float dist_squared = dot(pos, pos);\n"
GregFaae75242015-06-03 18:40:50 -06001022 " outColor = (dist_squared < 400.0)\n"
GregF3156cb02014-12-02 15:41:44 -07001023 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1024 " : color2;\n"
1025 "}\n";
1026
1027 ASSERT_NO_FATAL_FAILURE(InitState());
1028 ASSERT_NO_FATAL_FAILURE(InitViewport());
1029
Tony Barbour6918cd52015-04-09 12:58:51 -06001030 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001031 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001032
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001033 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1034 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
GregF3156cb02014-12-02 15:41:44 -07001035
Tony Barbour6918cd52015-04-09 12:58:51 -06001036 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001037 pipelineobj.AddColorAttachment();
GregF3156cb02014-12-02 15:41:44 -07001038 pipelineobj.AddShader(&vs);
1039 pipelineobj.AddShader(&ps);
1040
Tony Barbour6918cd52015-04-09 12:58:51 -06001041 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001042
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001043#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001044 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001045 MESH_BIND_ID, // binding ID
1046 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001047 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF3156cb02014-12-02 15:41:44 -07001048 };
1049
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001050 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001051 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1052 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001053 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001054 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF3156cb02014-12-02 15:41:44 -07001055
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001056 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF3156cb02014-12-02 15:41:44 -07001057 pipelineobj.AddVertexInputBindings(&vi_binding,1);
GregF3156cb02014-12-02 15:41:44 -07001058
Tony Barbour664accc2015-01-09 12:55:14 -07001059 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour664accc2015-01-09 12:55:14 -07001060
Tony Barbourfe3351b2015-07-28 10:17:20 -06001061 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001062
Tony Barbourfe3351b2015-07-28 10:17:20 -06001063 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001064
Tony Barbourfe3351b2015-07-28 10:17:20 -06001065 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001066#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001067 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001068 pDSDumpDot((char*)"triTest2.dot");
1069#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001070
Tony Barbour664accc2015-01-09 12:55:14 -07001071 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001072 Draw(6, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001073
1074 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001075 EndCommandBuffer();
1076 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001077
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001078 RecordImages(m_renderTargets);
GregF3156cb02014-12-02 15:41:44 -07001079}
1080
Tony Barbour6918cd52015-04-09 12:58:51 -06001081TEST_F(VkRenderTest, RedCirclesonBlue)
GregF3156cb02014-12-02 15:41:44 -07001082{
1083 // This tests that we correctly handle unread fragment inputs
1084
1085 static const char *vertShaderText =
1086 "#version 140\n"
1087 "#extension GL_ARB_separate_shader_objects : enable\n"
1088 "#extension GL_ARB_shading_language_420pack : enable\n"
1089 "layout (location = 0) in vec4 pos;\n"
1090 "layout (location = 0) out vec4 outColor;\n"
1091 "layout (location = 1) out vec4 outColor2;\n"
1092 "void main() {\n"
1093 " gl_Position = pos;\n"
1094 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1095 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1096 "}\n";
1097
1098 static const char *fragShaderText =
GregF3156cb02014-12-02 15:41:44 -07001099 "#version 330\n"
1100 "#extension GL_ARB_separate_shader_objects : enable\n"
1101 "#extension GL_ARB_shading_language_420pack : enable\n"
1102 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1103 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1104 "layout (location = 0) in vec4 color;\n"
1105 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001106 "layout (location = 0) out vec4 outColor;\n"
GregF3156cb02014-12-02 15:41:44 -07001107 "void main() {\n"
1108 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1109 " float dist_squared = dot(pos, pos);\n"
GregFaae75242015-06-03 18:40:50 -06001110 " outColor = (dist_squared < 400.0)\n"
GregF3156cb02014-12-02 15:41:44 -07001111 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1112 " : color2;\n"
1113 "}\n";
1114
1115 ASSERT_NO_FATAL_FAILURE(InitState());
1116 ASSERT_NO_FATAL_FAILURE(InitViewport());
1117
Tony Barbour6918cd52015-04-09 12:58:51 -06001118 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001119 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001120
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001121 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1122 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
GregF3156cb02014-12-02 15:41:44 -07001123
Tony Barbour6918cd52015-04-09 12:58:51 -06001124 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001125 pipelineobj.AddColorAttachment();
GregF3156cb02014-12-02 15:41:44 -07001126 pipelineobj.AddShader(&vs);
1127 pipelineobj.AddShader(&ps);
1128
Tony Barbour6918cd52015-04-09 12:58:51 -06001129 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001130
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001131#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001132 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001133 MESH_BIND_ID, // binding ID
1134 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001135 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF3156cb02014-12-02 15:41:44 -07001136 };
1137
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001138 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001139 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1140 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001141 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001142 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF3156cb02014-12-02 15:41:44 -07001143
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001144 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF3156cb02014-12-02 15:41:44 -07001145 pipelineobj.AddVertexInputBindings(&vi_binding,1);
GregF3156cb02014-12-02 15:41:44 -07001146
Tony Barbour664accc2015-01-09 12:55:14 -07001147 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001148 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001149
Tony Barbourfe3351b2015-07-28 10:17:20 -06001150 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001151
Tony Barbourfe3351b2015-07-28 10:17:20 -06001152 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001153#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001154 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001155 pDSDumpDot((char*)"triTest2.dot");
1156#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001157 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001158 Draw(6, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001159
1160 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001161 EndCommandBuffer();
1162 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001163
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001164 RecordImages(m_renderTargets);
GregF3156cb02014-12-02 15:41:44 -07001165}
1166
Tony Barbour6918cd52015-04-09 12:58:51 -06001167TEST_F(VkRenderTest, GreyCirclesonBlueFade)
GregF3156cb02014-12-02 15:41:44 -07001168{
1169 // This tests reading gl_ClipDistance from FS
1170
1171 static const char *vertShaderText =
GregFaae75242015-06-03 18:40:50 -06001172 //"#version 140\n"
GregF3156cb02014-12-02 15:41:44 -07001173 "#version 330\n"
1174 "#extension GL_ARB_separate_shader_objects : enable\n"
1175 "#extension GL_ARB_shading_language_420pack : enable\n"
1176 "out gl_PerVertex {\n"
1177 " vec4 gl_Position;\n"
1178 " float gl_ClipDistance[1];\n"
1179 "};\n"
1180 "layout (location = 0) in vec4 pos;\n"
1181 "layout (location = 0) out vec4 outColor;\n"
1182 "layout (location = 1) out vec4 outColor2;\n"
1183 "void main() {\n"
1184 " gl_Position = pos;\n"
1185 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1186 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1187 " float dists[3];\n"
1188 " dists[0] = 0.0;\n"
1189 " dists[1] = 1.0;\n"
1190 " dists[2] = 1.0;\n"
1191 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1192 "}\n";
1193
1194
1195 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -06001196 "#version 140\n"
1197 //"#version 330\n"
GregF3156cb02014-12-02 15:41:44 -07001198 "#extension GL_ARB_separate_shader_objects : enable\n"
1199 "#extension GL_ARB_shading_language_420pack : enable\n"
1200 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1201 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1202 "layout (location = 0) in vec4 color;\n"
1203 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001204 "layout (location = 0) out vec4 uFragColor;\n"
GregF3156cb02014-12-02 15:41:44 -07001205 "void main() {\n"
1206 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1207 " float dist_squared = dot(pos, pos);\n"
GregFaae75242015-06-03 18:40:50 -06001208 " uFragColor = (dist_squared < 400.0)\n"
GregF3156cb02014-12-02 15:41:44 -07001209 " ? color * gl_ClipDistance[0]\n"
1210 " : color2;\n"
1211 "}\n";
1212
1213 ASSERT_NO_FATAL_FAILURE(InitState());
1214 ASSERT_NO_FATAL_FAILURE(InitViewport());
1215
Tony Barbour6918cd52015-04-09 12:58:51 -06001216 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001217 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001218
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001219 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1220 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
GregF3156cb02014-12-02 15:41:44 -07001221
Tony Barbour6918cd52015-04-09 12:58:51 -06001222 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001223 pipelineobj.AddColorAttachment();
GregF3156cb02014-12-02 15:41:44 -07001224 pipelineobj.AddShader(&vs);
1225 pipelineobj.AddShader(&ps);
1226
Tony Barbour6918cd52015-04-09 12:58:51 -06001227 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001228
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001229#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001230 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001231 MESH_BIND_ID, // binding ID
1232 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001233 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF3156cb02014-12-02 15:41:44 -07001234 };
1235
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001236 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001237 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1238 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001239 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001240 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF3156cb02014-12-02 15:41:44 -07001241
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001242 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF3156cb02014-12-02 15:41:44 -07001243 pipelineobj.AddVertexInputBindings(&vi_binding,1);
GregF3156cb02014-12-02 15:41:44 -07001244
Tony Barbour664accc2015-01-09 12:55:14 -07001245 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
GregF3156cb02014-12-02 15:41:44 -07001246
Tony Barbourfe3351b2015-07-28 10:17:20 -06001247 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001248
Tony Barbourfe3351b2015-07-28 10:17:20 -06001249 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001250
Tony Barbourfe3351b2015-07-28 10:17:20 -06001251 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001252#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001253 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001254 pDSDumpDot((char*)"triTest2.dot");
1255#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001256
1257 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001258 Draw(6, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001259
1260 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001261 EndCommandBuffer();
1262 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001263
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001264 RecordImages(m_renderTargets);
GregF3156cb02014-12-02 15:41:44 -07001265}
Tony Barboure2c58df2014-11-25 13:18:32 -07001266
Tony Barbour6918cd52015-04-09 12:58:51 -06001267TEST_F(VkRenderTest, GreyCirclesonBlueDiscard)
GregF42226582014-12-02 17:19:34 -07001268{
1269 static const char *vertShaderText =
1270 "#version 140\n"
1271 "#extension GL_ARB_separate_shader_objects : enable\n"
1272 "#extension GL_ARB_shading_language_420pack : enable\n"
1273 "layout (location = 0) in vec4 pos;\n"
1274 "layout (location = 0) out vec4 outColor;\n"
1275 "layout (location = 1) out vec4 outColor2;\n"
1276 "void main() {\n"
1277 " gl_Position = pos;\n"
1278 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1279 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1280 "}\n";
1281
1282
1283 static const char *fragShaderText =
GregF42226582014-12-02 17:19:34 -07001284 "#version 330\n"
1285 "#extension GL_ARB_separate_shader_objects : enable\n"
1286 "#extension GL_ARB_shading_language_420pack : enable\n"
1287 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1288 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1289 "layout (location = 0) in vec4 color;\n"
1290 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001291 "layout (location = 0) out vec4 outColor;\n"
GregF42226582014-12-02 17:19:34 -07001292 "void main() {\n"
1293 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1294 " float dist_squared = dot(pos, pos);\n"
1295 " if (dist_squared < 100.0)\n"
1296 " discard;\n"
GregFaae75242015-06-03 18:40:50 -06001297 " outColor = (dist_squared < 400.0)\n"
GregF42226582014-12-02 17:19:34 -07001298 " ? color\n"
1299 " : color2;\n"
1300 "}\n";
1301
1302 ASSERT_NO_FATAL_FAILURE(InitState());
1303 ASSERT_NO_FATAL_FAILURE(InitViewport());
1304
Tony Barbour6918cd52015-04-09 12:58:51 -06001305 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001306 meshBuffer.BufferMemoryBarrier();
GregF42226582014-12-02 17:19:34 -07001307
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001308 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1309 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
GregF42226582014-12-02 17:19:34 -07001310
Tony Barbour6918cd52015-04-09 12:58:51 -06001311 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001312 pipelineobj.AddColorAttachment();
GregF42226582014-12-02 17:19:34 -07001313 pipelineobj.AddShader(&vs);
1314 pipelineobj.AddShader(&ps);
1315
Tony Barbour6918cd52015-04-09 12:58:51 -06001316 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001317
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001318#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001319 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001320 MESH_BIND_ID, // binding ID
1321 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001322 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF42226582014-12-02 17:19:34 -07001323 };
1324
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001325 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001326 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1327 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001328 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001329 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF42226582014-12-02 17:19:34 -07001330
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001331 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF42226582014-12-02 17:19:34 -07001332 pipelineobj.AddVertexInputBindings(&vi_binding,1);
GregF42226582014-12-02 17:19:34 -07001333
Tony Barbour664accc2015-01-09 12:55:14 -07001334 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour664accc2015-01-09 12:55:14 -07001335
Tony Barbourfe3351b2015-07-28 10:17:20 -06001336 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001337
Tony Barbourfe3351b2015-07-28 10:17:20 -06001338 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001339
Tony Barbourfe3351b2015-07-28 10:17:20 -06001340 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001341#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001342 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001343 pDSDumpDot((char*)"triTest2.dot");
1344#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001345
1346 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001347 Draw(6, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001348
1349 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001350 EndCommandBuffer();
1351 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001352
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001353 RecordImages(m_renderTargets);
GregF42226582014-12-02 17:19:34 -07001354}
1355
1356
Tony Barbour6918cd52015-04-09 12:58:51 -06001357TEST_F(VkRenderTest, TriangleVSUniform)
Cody Northrop66594a72014-10-10 14:49:36 -06001358{
1359 static const char *vertShaderText =
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001360 "#version 140\n"
1361 "#extension GL_ARB_separate_shader_objects : enable\n"
1362 "#extension GL_ARB_shading_language_420pack : enable\n"
1363 "\n"
1364 "layout(binding = 0) uniform buf {\n"
1365 " mat4 MVP;\n"
1366 "} ubuf;\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001367 "void main() {\n"
1368 " vec2 vertices[3];"
1369 " vertices[0] = vec2(-0.5, -0.5);\n"
1370 " vertices[1] = vec2( 0.5, -0.5);\n"
1371 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001372 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001373 "}\n";
1374
1375 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -06001376 "#version 140\n"
1377 "#extension GL_ARB_separate_shader_objects : enable\n"
1378 "#extension GL_ARB_shading_language_420pack : enable\n"
1379 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001380 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001381 " outColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001382 "}\n";
1383
Tony Barboure2c58df2014-11-25 13:18:32 -07001384 ASSERT_NO_FATAL_FAILURE(InitState());
1385 ASSERT_NO_FATAL_FAILURE(InitViewport());
1386
Courtney Goeltzenleuchterfdcfb9f2014-10-10 18:04:39 -06001387 // Create identity matrix
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001388 glm::mat4 Projection = glm::mat4(1.0f);
1389 glm::mat4 View = glm::mat4(1.0f);
1390 glm::mat4 Model = glm::mat4(1.0f);
1391 glm::mat4 MVP = Projection * View * Model;
1392 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1393
Tony Barbour6918cd52015-04-09 12:58:51 -06001394 VkConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001395 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1396 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001397
Tony Barbour6918cd52015-04-09 12:58:51 -06001398 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001399 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001400 pipelineobj.AddShader(&vs);
1401 pipelineobj.AddShader(&ps);
1402
1403 // Create descriptor set and attach the constant buffer to it
Tony Barbour6918cd52015-04-09 12:58:51 -06001404 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001405 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07001406
Tony Barbour664accc2015-01-09 12:55:14 -07001407 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf1878c72015-08-18 14:24:32 -06001408
1409 VkCmdBufferBeginInfo cbBeginInfo;
1410 memset(&cbBeginInfo, 0, sizeof(VkCmdBufferBeginInfo));
1411 cbBeginInfo.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
Courtney Goeltzenleuchter04bb5f82015-10-21 18:11:04 -06001412 cbBeginInfo.flags = 0;
Tobin Ehlisf1878c72015-08-18 14:24:32 -06001413 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barboure2c58df2014-11-25 13:18:32 -07001414
Tony Barbourfe3351b2015-07-28 10:17:20 -06001415 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001416
Tony Barbour664accc2015-01-09 12:55:14 -07001417#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001418 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001419 pDSDumpDot((char*)"triTest2.dot");
1420#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001421
1422 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001423 Draw(6, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001424
1425 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001426 EndCommandBuffer();
1427 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001428
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001429 RecordImages(m_renderTargets);
Tony Barbour664accc2015-01-09 12:55:14 -07001430
Tony Barbourfe3351b2015-07-28 10:17:20 -06001431 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer);
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001432}
1433
Tony Barbour6918cd52015-04-09 12:58:51 -06001434TEST_F(VkRenderTest, MixTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07001435{
1436 // This tests location applied to varyings. Notice that we have switched foo
1437 // and bar in the FS. The triangle should be blended with red, green and blue
1438 // corners.
1439 static const char *vertShaderText =
1440 "#version 140\n"
1441 "#extension GL_ARB_separate_shader_objects : enable\n"
1442 "#extension GL_ARB_shading_language_420pack : enable\n"
1443 "layout (location=0) out vec4 bar;\n"
1444 "layout (location=1) out vec4 foo;\n"
1445 "layout (location=2) out float scale;\n"
1446 "vec2 vertices[3];\n"
1447 "void main() {\n"
1448 " vertices[0] = vec2(-1.0, -1.0);\n"
1449 " vertices[1] = vec2( 1.0, -1.0);\n"
1450 " vertices[2] = vec2( 0.0, 1.0);\n"
1451 "vec4 colors[3];\n"
1452 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1453 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1454 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1455 " foo = colors[gl_VertexID % 3];\n"
1456 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1457 " scale = 1.0;\n"
1458 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1459 "}\n";
1460
1461 static const char *fragShaderText =
1462 "#version 140\n"
1463 "#extension GL_ARB_separate_shader_objects : enable\n"
1464 "#extension GL_ARB_shading_language_420pack : enable\n"
1465 "layout (location = 1) in vec4 bar;\n"
1466 "layout (location = 0) in vec4 foo;\n"
1467 "layout (location = 2) in float scale;\n"
GregFaae75242015-06-03 18:40:50 -06001468 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001469 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001470 " outColor = bar * scale + foo * (1.0-scale);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001471 "}\n";
1472
1473 ASSERT_NO_FATAL_FAILURE(InitState());
1474 ASSERT_NO_FATAL_FAILURE(InitViewport());
1475
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001476 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1477 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001478
Tony Barbour6918cd52015-04-09 12:58:51 -06001479 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001480 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001481 pipelineobj.AddShader(&vs);
1482 pipelineobj.AddShader(&ps);
1483
Tony Barbour6918cd52015-04-09 12:58:51 -06001484 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour831062d2015-04-02 15:43:15 -06001485 descriptorSet.AppendDummy();
Tony Barboure2c58df2014-11-25 13:18:32 -07001486
Tony Barbour664accc2015-01-09 12:55:14 -07001487 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour664accc2015-01-09 12:55:14 -07001488
Tony Barbourfe3351b2015-07-28 10:17:20 -06001489 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001490
Tony Barbourfe3351b2015-07-28 10:17:20 -06001491 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001492
1493#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001494 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001495 pDSDumpDot((char*)"triTest2.dot");
1496#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001497
Tony Barbour664accc2015-01-09 12:55:14 -07001498 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001499 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001500
1501 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001502 EndCommandBuffer();
1503 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001504
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001505 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001506}
1507
Tony Barbour6918cd52015-04-09 12:58:51 -06001508TEST_F(VkRenderTest, QuadVertFetchAndVertID)
Tony Barboure2c58df2014-11-25 13:18:32 -07001509{
1510 // This tests that attributes work in the presence of gl_VertexID
1511
1512 static const char *vertShaderText =
1513 "#version 140\n"
1514 "#extension GL_ARB_separate_shader_objects : enable\n"
1515 "#extension GL_ARB_shading_language_420pack : enable\n"
1516 //XYZ1( -1, -1, -1 )
1517 "layout (location = 0) in vec4 pos;\n"
1518 //XYZ1( 0.f, 0.f, 0.f )
1519 "layout (location = 1) in vec4 inColor;\n"
1520 "layout (location = 0) out vec4 outColor;\n"
1521 "void main() {\n"
1522 " outColor = inColor;\n"
1523 " vec4 vertices[3];"
1524 " vertices[gl_VertexID % 3] = pos;\n"
1525 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1526 "}\n";
1527
1528
1529 static const char *fragShaderText =
1530 "#version 140\n"
1531 "#extension GL_ARB_separate_shader_objects : enable\n"
1532 "#extension GL_ARB_shading_language_420pack : enable\n"
1533 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06001534 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001535 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001536 " outColor = color;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001537 "}\n";
1538
1539 ASSERT_NO_FATAL_FAILURE(InitState());
1540 ASSERT_NO_FATAL_FAILURE(InitViewport());
1541
Tony Barbour6918cd52015-04-09 12:58:51 -06001542 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001543 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07001544
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001545 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1546 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001547
Tony Barbour6918cd52015-04-09 12:58:51 -06001548 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001549 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001550 pipelineobj.AddShader(&vs);
1551 pipelineobj.AddShader(&ps);
1552
Tony Barbour6918cd52015-04-09 12:58:51 -06001553 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001554
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001555#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001556 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001557 MESH_BUF_ID, // Binding ID
1558 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001559 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barboure2c58df2014-11-25 13:18:32 -07001560 };
1561
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001562 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001563 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1564 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001565 vi_attribs[0].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001566 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1567 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1568 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001569 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001570 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -07001571
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001572 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001573 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barboure2c58df2014-11-25 13:18:32 -07001574
Tony Barbour664accc2015-01-09 12:55:14 -07001575 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour664accc2015-01-09 12:55:14 -07001576
Tony Barbourfe3351b2015-07-28 10:17:20 -06001577 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001578
Tony Barbourfe3351b2015-07-28 10:17:20 -06001579 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001580
Tony Barbourfe3351b2015-07-28 10:17:20 -06001581 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001582#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001583 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001584 pDSDumpDot((char*)"triTest2.dot");
1585#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001586
1587 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001588 Draw(6, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001589
1590 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001591 EndCommandBuffer();
1592 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001593
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001594 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001595}
1596
Tony Barbour6918cd52015-04-09 12:58:51 -06001597TEST_F(VkRenderTest, QuadSparseVertFetch)
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001598{
1599 // This tests that attributes work in the presence of gl_VertexID
1600
1601 static const char *vertShaderText =
1602 "#version 140\n"
1603 "#extension GL_ARB_separate_shader_objects : enable\n"
1604 "#extension GL_ARB_shading_language_420pack : enable\n"
1605 //XYZ1( -1, -1, -1 )
1606 "layout (location = 1) in vec4 pos;\n"
1607 "layout (location = 4) in vec4 inColor;\n"
1608 //XYZ1( 0.f, 0.f, 0.f )
1609 "layout (location = 0) out vec4 outColor;\n"
1610 "void main() {\n"
1611 " outColor = inColor;\n"
1612 " gl_Position = pos;\n"
1613 "}\n";
1614
1615
1616 static const char *fragShaderText =
1617 "#version 140\n"
1618 "#extension GL_ARB_separate_shader_objects : enable\n"
1619 "#extension GL_ARB_shading_language_420pack : enable\n"
1620 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06001621 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001622 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001623 " outColor = color;\n"
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001624 "}\n";
1625
1626 ASSERT_NO_FATAL_FAILURE(InitState());
1627 ASSERT_NO_FATAL_FAILURE(InitViewport());
1628
1629 struct VDATA
1630 {
1631 float t1, t2, t3, t4; // filler data
1632 float posX, posY, posZ, posW; // Position data
1633 float r, g, b, a; // Color
1634 };
1635 const struct VDATA vData[] =
1636 {
1637 { XYZ1(0, 0, 0), XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
1638 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.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( 0.f, 1.f, 0.f ) },
1641 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1642 { XYZ1(0, 0, 0), XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
1643 };
1644
Tony Barbour6918cd52015-04-09 12:58:51 -06001645 VkConstantBufferObj meshBuffer(m_device,sizeof(vData)/sizeof(vData[0]),sizeof(vData[0]), vData);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001646 meshBuffer.BufferMemoryBarrier();
1647
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001648 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1649 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001650
Tony Barbour6918cd52015-04-09 12:58:51 -06001651 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001652 pipelineobj.AddColorAttachment();
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001653 pipelineobj.AddShader(&vs);
1654 pipelineobj.AddShader(&ps);
1655
Tony Barbour6918cd52015-04-09 12:58:51 -06001656 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001657
1658#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001659 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001660 MESH_BUF_ID, // Binding ID
1661 sizeof(vData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001662 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001663 };
1664
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001665 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001666 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1667 vi_attribs[0].location = 4;
Tony Barbourd1c35722015-04-16 15:59:00 -06001668 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001669 vi_attribs[0].offsetInBytes = sizeof(float) * 4 * 2; // Offset of first element in bytes from base of vertex
1670 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1671 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001672 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001673 vi_attribs[1].offsetInBytes = sizeof(float) * 4 * 1; // Offset of first element in bytes from base of vertex
1674
1675 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
1676 pipelineobj.AddVertexInputBindings(&vi_binding, 1);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001677
1678 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001679
Tony Barbourfe3351b2015-07-28 10:17:20 -06001680 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001681
Tony Barbourfe3351b2015-07-28 10:17:20 -06001682 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001683
Tony Barbourfe3351b2015-07-28 10:17:20 -06001684 BindVertexBuffer(&meshBuffer, 0, MESH_BUF_ID);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001685#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001686 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001687 pDSDumpDot((char*)"triTest2.dot");
1688#endif
1689
1690 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001691 Draw(6, 1, 0, 0);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001692
1693 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001694 EndCommandBuffer();
1695 QueueCommandBuffer();
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001696
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001697 RecordImages(m_renderTargets);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001698}
1699
Tony Barbour6918cd52015-04-09 12:58:51 -06001700TEST_F(VkRenderTest, TriVertFetchDeadAttr)
Tony Barboure2c58df2014-11-25 13:18:32 -07001701{
1702 // This tests that attributes work in the presence of gl_VertexID
1703 // and a dead attribute in position 0. Draws a triangle with yellow,
1704 // red and green corners, starting at top and going clockwise.
1705
1706 static const char *vertShaderText =
1707 "#version 140\n"
1708 "#extension GL_ARB_separate_shader_objects : enable\n"
1709 "#extension GL_ARB_shading_language_420pack : enable\n"
1710 //XYZ1( -1, -1, -1 )
1711 "layout (location = 0) in vec4 pos;\n"
1712 //XYZ1( 0.f, 0.f, 0.f )
1713 "layout (location = 1) in vec4 inColor;\n"
1714 "layout (location = 0) out vec4 outColor;\n"
1715 "void main() {\n"
1716 " outColor = inColor;\n"
1717 " vec2 vertices[3];"
1718 " vertices[0] = vec2(-1.0, -1.0);\n"
1719 " vertices[1] = vec2( 1.0, -1.0);\n"
1720 " vertices[2] = vec2( 0.0, 1.0);\n"
1721 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1722 "}\n";
1723
1724
1725 static const char *fragShaderText =
1726 "#version 140\n"
1727 "#extension GL_ARB_separate_shader_objects : enable\n"
1728 "#extension GL_ARB_shading_language_420pack : enable\n"
1729 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06001730 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001731 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001732 " outColor = color;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001733 "}\n";
1734
1735 ASSERT_NO_FATAL_FAILURE(InitState());
1736 ASSERT_NO_FATAL_FAILURE(InitViewport());
1737
Tony Barbour6918cd52015-04-09 12:58:51 -06001738 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001739 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07001740
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001741 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1742 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001743
Tony Barbour6918cd52015-04-09 12:58:51 -06001744 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001745 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001746 pipelineobj.AddShader(&vs);
1747 pipelineobj.AddShader(&ps);
1748
Tony Barbour6918cd52015-04-09 12:58:51 -06001749 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001750
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001751#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001752 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001753 MESH_BUF_ID, // Binding ID
1754 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001755 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barboure2c58df2014-11-25 13:18:32 -07001756 };
1757
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001758 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001759 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1760 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001761 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001762 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1763 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1764 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001765 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001766 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -07001767
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001768 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001769 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barboure2c58df2014-11-25 13:18:32 -07001770
Tony Barbour664accc2015-01-09 12:55:14 -07001771 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboure2c58df2014-11-25 13:18:32 -07001772
Tony Barbourfe3351b2015-07-28 10:17:20 -06001773 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001774
Tony Barbourfe3351b2015-07-28 10:17:20 -06001775 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001776
Tony Barbourfe3351b2015-07-28 10:17:20 -06001777 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001778#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001779 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001780 pDSDumpDot((char*)"triTest2.dot");
1781#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001782
1783 // render two triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001784 Draw(6, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001785
1786 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001787 EndCommandBuffer();
1788 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001789
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001790 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001791}
1792
Tony Barbour6918cd52015-04-09 12:58:51 -06001793TEST_F(VkRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001794{
1795 static const char *vertShaderText =
1796 "#version 140\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001797 "#extension GL_ARB_separate_shader_objects : enable\n"
1798 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbouracb3c1c2015-09-29 14:56:09 -06001799 "layout (binding = 0) uniform bufferVals {\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001800 " mat4 mvp;\n"
1801 "} myBufferVals;\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001802 "layout (location = 0) in vec4 pos;\n"
1803 "layout (location = 1) in vec4 inColor;\n"
Cody Northrop8a3bb132015-06-16 17:32:04 -06001804 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001805 "void main() {\n"
1806 " outColor = inColor;\n"
1807 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06001808 " gl_Position.y = -gl_Position.y;\n"
1809 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001810 "}\n";
1811
1812 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -06001813 "#version 140\n"
1814 "#extension GL_ARB_separate_shader_objects : enable\n"
1815 "#extension GL_ARB_shading_language_420pack : enable\n"
1816 "layout (location = 0) in vec4 color;\n"
1817 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001818 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001819 " outColor = color;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001820 "}\n";
Tony Barboure2c58df2014-11-25 13:18:32 -07001821 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001822
Tony Barboure2c58df2014-11-25 13:18:32 -07001823 glm::mat4 View = glm::lookAt(
1824 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1825 glm::vec3(0,0,0), // and looks at the origin
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06001826 glm::vec3(0,-1,0) // Head is up (set to 0,-1,0 to look upside-down)
Tony Barboure2c58df2014-11-25 13:18:32 -07001827 );
1828
1829 glm::mat4 Model = glm::mat4(1.0f);
1830
1831 glm::mat4 MVP = Projection * View * Model;
1832
1833 ASSERT_NO_FATAL_FAILURE(InitState());
1834 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wub4052042015-07-09 10:16:34 +08001835 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Chia-I Wu08accc62015-07-07 11:50:03 +08001836 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height, m_depth_stencil_fmt);
Tony Barboure2c58df2014-11-25 13:18:32 -07001837
Tony Barbour6918cd52015-04-09 12:58:51 -06001838 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 -07001839 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1840
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001841 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barboure2c58df2014-11-25 13:18:32 -07001842
Tony Barbour6918cd52015-04-09 12:58:51 -06001843 VkConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001844 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1845 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001846
Tony Barbour6918cd52015-04-09 12:58:51 -06001847 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001848 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001849 pipelineobj.AddShader(&vs);
1850 pipelineobj.AddShader(&ps);
1851
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001852 VkPipelineDepthStencilStateCreateInfo ds_state;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001853 ds_state.depthTestEnable = VK_TRUE;
1854 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbourd1c35722015-04-16 15:59:00 -06001855 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Cody Northrop271ba752015-08-26 10:01:32 -06001856 ds_state.depthBoundsTestEnable = VK_FALSE;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001857 ds_state.stencilTestEnable = VK_FALSE;
1858 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
1859 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
1860 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbourd1c35722015-04-16 15:59:00 -06001861 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
Tony Barbourf52346d2015-01-16 14:27:35 -07001862 ds_state.front = ds_state.back;
1863 pipelineobj.SetDepthStencil(&ds_state);
1864
Tony Barbour6918cd52015-04-09 12:58:51 -06001865 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001866 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07001867
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001868#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001869 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001870 MESH_BUF_ID, // Binding ID
1871 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001872 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001873 };
Tony Barboure2c58df2014-11-25 13:18:32 -07001874
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001875 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001876 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1877 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001878 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001879 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1880 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1881 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001882 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001883 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -07001884
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001885 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001886 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barboure2c58df2014-11-25 13:18:32 -07001887
Tony Barbour1c45ce02015-03-27 17:03:18 -06001888 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour1c45ce02015-03-27 17:03:18 -06001889
Tony Barbourfe3351b2015-07-28 10:17:20 -06001890 ASSERT_VK_SUCCESS(BeginCommandBuffer());
1891 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barboure2c58df2014-11-25 13:18:32 -07001892
Tony Barbourfe3351b2015-07-28 10:17:20 -06001893 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour1fde6942015-01-09 10:06:53 -07001894#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001895 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour1fde6942015-01-09 10:06:53 -07001896 pDSDumpDot((char*)"triTest2.dot");
1897#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001898
1899 // render triangles
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001900 Draw(36, 1, 0, 0);
Tony Barbour1fde6942015-01-09 10:06:53 -07001901
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001902
Tony Barbour1fde6942015-01-09 10:06:53 -07001903 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001904 EndCommandBuffer();
1905 QueueCommandBuffer();
Tony Barbour1fde6942015-01-09 10:06:53 -07001906
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001907 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001908}
1909
Tony Barbour6918cd52015-04-09 12:58:51 -06001910TEST_F(VkRenderTest, VSTexture)
Tony Barboure2c58df2014-11-25 13:18:32 -07001911{
1912 // The expected result from this test is a green and red triangle;
1913 // one red vertex on the left, two green vertices on the right.
1914 static const char *vertShaderText =
Cody Northrop8a3bb132015-06-16 17:32:04 -06001915 "#version 140\n"
1916 "#extension GL_ARB_separate_shader_objects : enable\n"
1917 "#extension GL_ARB_shading_language_420pack : enable\n"
1918 "layout (location = 0) out vec4 texColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001919 "uniform sampler2D surface;\n"
1920 "void main() {\n"
1921 " vec2 vertices[3];"
1922 " vertices[0] = vec2(-0.5, -0.5);\n"
1923 " vertices[1] = vec2( 0.5, -0.5);\n"
1924 " vertices[2] = vec2( 0.5, 0.5);\n"
1925 " vec2 positions[3];"
1926 " positions[0] = vec2( 0.0, 0.0);\n"
1927 " positions[1] = vec2( 0.25, 0.1);\n"
1928 " positions[2] = vec2( 0.1, 0.25);\n"
1929 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1930 " texColor = textureLod(surface, samplePos, 0.0);\n"
1931 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1932 "}\n";
1933
1934 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -06001935 "#version 140\n"
1936 "#extension GL_ARB_separate_shader_objects : enable\n"
1937 "#extension GL_ARB_shading_language_420pack : enable\n"
1938 "layout (location = 0) in vec4 texColor;\n"
1939 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001940 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001941 " outColor = texColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001942 "}\n";
1943
1944 ASSERT_NO_FATAL_FAILURE(InitState());
1945 ASSERT_NO_FATAL_FAILURE(InitViewport());
1946
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001947 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1948 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbour6918cd52015-04-09 12:58:51 -06001949 VkSamplerObj sampler(m_device);
1950 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07001951
Tony Barbour6918cd52015-04-09 12:58:51 -06001952 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001953 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001954 pipelineobj.AddShader(&vs);
1955 pipelineobj.AddShader(&ps);
1956
Tony Barbour6918cd52015-04-09 12:58:51 -06001957 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08001958 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07001959
Tony Barbour664accc2015-01-09 12:55:14 -07001960 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001961 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure2c58df2014-11-25 13:18:32 -07001962
Tony Barbourfe3351b2015-07-28 10:17:20 -06001963 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001964
1965#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001966 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001967 pDSDumpDot((char*)"triTest2.dot");
1968#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001969
Tony Barbour664accc2015-01-09 12:55:14 -07001970 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06001971 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001972
1973 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001974 EndCommandBuffer();
1975 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001976
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001977 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001978}
GregFaae75242015-06-03 18:40:50 -06001979
1980
1981
Tony Barbour6918cd52015-04-09 12:58:51 -06001982TEST_F(VkRenderTest, TexturedTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07001983{
1984 // The expected result from this test is a red and green checkered triangle
1985 static const char *vertShaderText =
1986 "#version 140\n"
1987 "#extension GL_ARB_separate_shader_objects : enable\n"
1988 "#extension GL_ARB_shading_language_420pack : enable\n"
1989 "layout (location = 0) out vec2 samplePos;\n"
1990 "void main() {\n"
1991 " vec2 vertices[3];"
1992 " vertices[0] = vec2(-0.5, -0.5);\n"
1993 " vertices[1] = vec2( 0.5, -0.5);\n"
1994 " vertices[2] = vec2( 0.5, 0.5);\n"
1995 " vec2 positions[3];"
1996 " positions[0] = vec2( 0.0, 0.0);\n"
1997 " positions[1] = vec2( 1.0, 0.0);\n"
1998 " positions[2] = vec2( 1.0, 1.0);\n"
1999 " samplePos = positions[gl_VertexID % 3];\n"
2000 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2001 "}\n";
2002
2003 static const char *fragShaderText =
2004 "#version 140\n"
2005 "#extension GL_ARB_separate_shader_objects : enable\n"
2006 "#extension GL_ARB_shading_language_420pack : enable\n"
2007 "layout (location = 0) in vec2 samplePos;\n"
2008 "layout (binding = 0) uniform sampler2D surface;\n"
2009 "layout (location=0) out vec4 outColor;\n"
2010 "void main() {\n"
2011 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2012 " outColor = texColor;\n"
2013 "}\n";
2014
2015 ASSERT_NO_FATAL_FAILURE(InitState());
2016 ASSERT_NO_FATAL_FAILURE(InitViewport());
2017
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002018 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2019 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbour6918cd52015-04-09 12:58:51 -06002020 VkSamplerObj sampler(m_device);
2021 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002022
Tony Barbour6918cd52015-04-09 12:58:51 -06002023 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002024 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002025 pipelineobj.AddShader(&vs);
2026 pipelineobj.AddShader(&ps);
2027
Tony Barbour6918cd52015-04-09 12:58:51 -06002028 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002029 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002030
Tony Barbour664accc2015-01-09 12:55:14 -07002031 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002032 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002033
Tony Barbourfe3351b2015-07-28 10:17:20 -06002034 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002035
2036#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002037 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002038 pDSDumpDot((char*)"triTest2.dot");
2039#endif
2040 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002041 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002042
2043 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002044 EndCommandBuffer();
2045 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002046
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002047 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002048}
Tony Barbour6918cd52015-04-09 12:58:51 -06002049TEST_F(VkRenderTest, TexturedTriangleClip)
Tony Barboure2c58df2014-11-25 13:18:32 -07002050{
2051 // The expected result from this test is a red and green checkered triangle
2052 static const char *vertShaderText =
2053 "#version 330\n"
2054 "#extension GL_ARB_separate_shader_objects : enable\n"
2055 "#extension GL_ARB_shading_language_420pack : enable\n"
2056 "layout (location = 0) out vec2 samplePos;\n"
2057 "out gl_PerVertex {\n"
2058 " vec4 gl_Position;\n"
2059 " float gl_ClipDistance[1];\n"
2060 "};\n"
2061 "void main() {\n"
2062 " vec2 vertices[3];"
2063 " vertices[0] = vec2(-0.5, -0.5);\n"
2064 " vertices[1] = vec2( 0.5, -0.5);\n"
2065 " vertices[2] = vec2( 0.5, 0.5);\n"
2066 " vec2 positions[3];"
2067 " positions[0] = vec2( 0.0, 0.0);\n"
2068 " positions[1] = vec2( 1.0, 0.0);\n"
2069 " positions[2] = vec2( 1.0, 1.0);\n"
2070 " float dists[3];\n"
2071 " dists[0] = 1.0;\n"
2072 " dists[1] = 1.0;\n"
2073 " dists[2] = -1.0;\n"
2074 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2075 " samplePos = positions[gl_VertexID % 3];\n"
2076 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2077 "}\n";
2078
2079 static const char *fragShaderText =
2080 "#version 140\n"
2081 "#extension GL_ARB_separate_shader_objects : enable\n"
2082 "#extension GL_ARB_shading_language_420pack : enable\n"
2083 "layout (location = 0) in vec2 samplePos;\n"
2084 "layout (binding = 0) uniform sampler2D surface;\n"
2085 "layout (location=0) out vec4 outColor;\n"
2086 "void main() {\n"
2087 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2088 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2089 " outColor = texColor;\n"
2090 "}\n";
2091
2092
2093 ASSERT_NO_FATAL_FAILURE(InitState());
2094 ASSERT_NO_FATAL_FAILURE(InitViewport());
2095
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002096 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2097 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbour6918cd52015-04-09 12:58:51 -06002098 VkSamplerObj sampler(m_device);
2099 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002100
Tony Barbour6918cd52015-04-09 12:58:51 -06002101 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002102 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002103 pipelineobj.AddShader(&vs);
2104 pipelineobj.AddShader(&ps);
2105
Tony Barbour6918cd52015-04-09 12:58:51 -06002106 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002107 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002108
Tony Barbour664accc2015-01-09 12:55:14 -07002109 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002110 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002111
Tony Barbourfe3351b2015-07-28 10:17:20 -06002112 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002113
2114#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002115 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002116 pDSDumpDot((char*)"triTest2.dot");
2117#endif
2118 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002119 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002120
2121 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002122 EndCommandBuffer();
2123 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002124
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002125 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002126}
GregFaae75242015-06-03 18:40:50 -06002127
Tony Barbour6918cd52015-04-09 12:58:51 -06002128TEST_F(VkRenderTest, FSTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07002129{
2130 // The expected result from this test is a red and green checkered triangle
2131 static const char *vertShaderText =
2132 "#version 140\n"
2133 "#extension GL_ARB_separate_shader_objects : enable\n"
2134 "#extension GL_ARB_shading_language_420pack : enable\n"
2135 "layout (location = 0) out vec2 samplePos;\n"
2136 "void main() {\n"
2137 " vec2 vertices[3];"
2138 " vertices[0] = vec2(-0.5, -0.5);\n"
2139 " vertices[1] = vec2( 0.5, -0.5);\n"
2140 " vertices[2] = vec2( 0.5, 0.5);\n"
2141 " vec2 positions[3];"
2142 " positions[0] = vec2( 0.0, 0.0);\n"
2143 " positions[1] = vec2( 1.0, 0.0);\n"
2144 " positions[2] = vec2( 1.0, 1.0);\n"
2145 " samplePos = positions[gl_VertexID % 3];\n"
2146 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2147 "}\n";
2148
2149 static const char *fragShaderText =
2150 "#version 140\n"
2151 "#extension GL_ARB_separate_shader_objects : enable\n"
2152 "#extension GL_ARB_shading_language_420pack : enable\n"
2153 "layout (location = 0) in vec2 samplePos;\n"
2154 "layout (binding = 0) uniform sampler2D surface;\n"
2155 "layout (location=0) out vec4 outColor;\n"
2156 "void main() {\n"
2157 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2158 " outColor = texColor;\n"
2159 "}\n";
2160
2161 ASSERT_NO_FATAL_FAILURE(InitState());
2162 ASSERT_NO_FATAL_FAILURE(InitViewport());
2163
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002164 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2165 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbour6918cd52015-04-09 12:58:51 -06002166 VkSamplerObj sampler(m_device);
2167 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002168
Tony Barbour6918cd52015-04-09 12:58:51 -06002169 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002170 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002171 pipelineobj.AddShader(&vs);
2172 pipelineobj.AddShader(&ps);
2173
Tony Barbour6918cd52015-04-09 12:58:51 -06002174 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002175 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002176
Tony Barbour664accc2015-01-09 12:55:14 -07002177 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002178 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002179
Tony Barbourfe3351b2015-07-28 10:17:20 -06002180 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002181
2182#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002183 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002184 pDSDumpDot((char*)"triTest2.dot");
2185#endif
2186 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002187 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002188
2189 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002190 EndCommandBuffer();
2191 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002192
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002193 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002194}
Tony Barbour6918cd52015-04-09 12:58:51 -06002195TEST_F(VkRenderTest, SamplerBindingsTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07002196{
2197 // This test sets bindings on the samplers
2198 // For now we are asserting that sampler and texture pairs
2199 // march in lock step, and are set via GLSL binding. This can
2200 // and will probably change.
2201 // The sampler bindings should match the sampler and texture slot
2202 // number set up by the application.
2203 // This test will result in a blue triangle
2204 static const char *vertShaderText =
2205 "#version 140\n"
2206 "#extension GL_ARB_separate_shader_objects : enable\n"
2207 "#extension GL_ARB_shading_language_420pack : enable\n"
2208 "layout (location = 0) out vec4 samplePos;\n"
2209 "void main() {\n"
2210 " vec2 vertices[3];"
2211 " vertices[0] = vec2(-0.5, -0.5);\n"
2212 " vertices[1] = vec2( 0.5, -0.5);\n"
2213 " vertices[2] = vec2( 0.5, 0.5);\n"
2214 " vec2 positions[3];"
2215 " positions[0] = vec2( 0.0, 0.0);\n"
2216 " positions[1] = vec2( 1.0, 0.0);\n"
2217 " positions[2] = vec2( 1.0, 1.0);\n"
2218 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2219 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2220 "}\n";
2221
2222 static const char *fragShaderText =
2223 "#version 140\n"
2224 "#extension GL_ARB_separate_shader_objects : enable\n"
2225 "#extension GL_ARB_shading_language_420pack : enable\n"
2226 "layout (location = 0) in vec4 samplePos;\n"
2227 "layout (binding = 0) uniform sampler2D surface0;\n"
2228 "layout (binding = 1) uniform sampler2D surface1;\n"
2229 "layout (binding = 12) uniform sampler2D surface2;\n"
GregFaae75242015-06-03 18:40:50 -06002230 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002231 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06002232 " outColor = textureLod(surface2, samplePos.xy, 0.0);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002233 "}\n";
2234
2235 ASSERT_NO_FATAL_FAILURE(InitState());
2236 ASSERT_NO_FATAL_FAILURE(InitViewport());
2237
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002238 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2239 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002240
Tony Barbour6918cd52015-04-09 12:58:51 -06002241 VkSamplerObj sampler1(m_device);
2242 VkSamplerObj sampler2(m_device);
2243 VkSamplerObj sampler3(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002244
Tony Barbourebc093f2015-04-01 16:38:10 -06002245 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
Tony Barbour6918cd52015-04-09 12:58:51 -06002246 VkTextureObj texture1(m_device, tex_colors); // Red
Tony Barbourebc093f2015-04-01 16:38:10 -06002247 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
Tony Barbour6918cd52015-04-09 12:58:51 -06002248 VkTextureObj texture2(m_device, tex_colors); // Green
Tony Barbourebc093f2015-04-01 16:38:10 -06002249 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
Tony Barbour6918cd52015-04-09 12:58:51 -06002250 VkTextureObj texture3(m_device, tex_colors); // Blue
Tony Barboure2c58df2014-11-25 13:18:32 -07002251
Tony Barbour6918cd52015-04-09 12:58:51 -06002252 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002253 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002254 pipelineobj.AddShader(&vs);
2255 pipelineobj.AddShader(&ps);
2256
Tony Barbour6918cd52015-04-09 12:58:51 -06002257 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002258 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2259 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2260 for (int i = 0; i < 10; i++)
2261 descriptorSet.AppendDummy();
2262 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barboure2c58df2014-11-25 13:18:32 -07002263
Tony Barbour664accc2015-01-09 12:55:14 -07002264 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002265 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002266
Tony Barbourfe3351b2015-07-28 10:17:20 -06002267 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002268
2269#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002270 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002271 pDSDumpDot((char*)"triTest2.dot");
2272#endif
2273 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002274 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002275
2276 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002277 EndCommandBuffer();
2278 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002279
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002280 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002281}
2282
Tony Barbour6918cd52015-04-09 12:58:51 -06002283TEST_F(VkRenderTest, TriangleVSUniformBlock)
Tony Barboure2c58df2014-11-25 13:18:32 -07002284{
2285 // The expected result from this test is a blue triangle
2286
2287 static const char *vertShaderText =
2288 "#version 140\n"
2289 "#extension GL_ARB_separate_shader_objects : enable\n"
2290 "#extension GL_ARB_shading_language_420pack : enable\n"
2291 "layout (location = 0) out vec4 outColor;\n"
Tony Barbouracb3c1c2015-09-29 14:56:09 -06002292 "layout (binding = 0) uniform bufferVals {\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002293 " vec4 red;\n"
2294 " vec4 green;\n"
2295 " vec4 blue;\n"
2296 " vec4 white;\n"
2297 "} myBufferVals;\n"
2298 "void main() {\n"
2299 " vec2 vertices[3];"
2300 " vertices[0] = vec2(-0.5, -0.5);\n"
2301 " vertices[1] = vec2( 0.5, -0.5);\n"
2302 " vertices[2] = vec2( 0.5, 0.5);\n"
2303 " outColor = myBufferVals.blue;\n"
2304 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2305 "}\n";
2306
2307 static const char *fragShaderText =
2308 "#version 140\n"
2309 "#extension GL_ARB_separate_shader_objects : enable\n"
2310 "#extension GL_ARB_shading_language_420pack : enable\n"
2311 "layout (location = 0) in vec4 inColor;\n"
GregFaae75242015-06-03 18:40:50 -06002312 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002313 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06002314 " outColor = inColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002315 "}\n";
2316
2317 ASSERT_NO_FATAL_FAILURE(InitState());
2318 ASSERT_NO_FATAL_FAILURE(InitViewport());
2319
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002320 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2321 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002322
2323 // Let's populate our buffer with the following:
2324 // vec4 red;
2325 // vec4 green;
2326 // vec4 blue;
2327 // vec4 white;
2328 const int valCount = 4 * 4;
2329 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2330 0.0, 1.0, 0.0, 1.0,
2331 0.0, 0.0, 1.0, 1.0,
2332 1.0, 1.0, 1.0, 1.0 };
2333
Tony Barbour6918cd52015-04-09 12:58:51 -06002334 VkConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002335
Tony Barbour6918cd52015-04-09 12:58:51 -06002336 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002337 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002338 pipelineobj.AddShader(&vs);
2339 pipelineobj.AddShader(&ps);
2340
Tony Barbour6918cd52015-04-09 12:58:51 -06002341 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002342 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, colorBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002343
Tony Barbour664accc2015-01-09 12:55:14 -07002344 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002345 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002346
Tony Barbourfe3351b2015-07-28 10:17:20 -06002347 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002348
2349#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002350 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002351 pDSDumpDot((char*)"triTest2.dot");
2352#endif
2353 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002354 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002355
2356 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002357 EndCommandBuffer();
2358 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002359
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002360 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002361}
2362
Tony Barbour6918cd52015-04-09 12:58:51 -06002363TEST_F(VkRenderTest, TriangleFSUniformBlockBinding)
Tony Barboure2c58df2014-11-25 13:18:32 -07002364{
2365 // This test allows the shader to select which buffer it is
2366 // pulling from using layout binding qualifier.
2367 // There are corresponding changes in the compiler stack that
2368 // will select the buffer using binding directly.
2369 // The binding number should match the slot number set up by
2370 // the application.
2371 // The expected result from this test is a purple triangle
2372
2373 static const char *vertShaderText =
2374 "#version 140\n"
2375 "#extension GL_ARB_separate_shader_objects : enable\n"
2376 "#extension GL_ARB_shading_language_420pack : enable\n"
2377 "void main() {\n"
2378 " vec2 vertices[3];"
2379 " vertices[0] = vec2(-0.5, -0.5);\n"
2380 " vertices[1] = vec2( 0.5, -0.5);\n"
2381 " vertices[2] = vec2( 0.5, 0.5);\n"
2382 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2383 "}\n";
2384
2385 static const char *fragShaderText =
2386 "#version 140\n"
2387 "#extension GL_ARB_separate_shader_objects : enable\n"
2388 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbouracb3c1c2015-09-29 14:56:09 -06002389 "layout (binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2390 "layout (binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2391 "layout (binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
2392 "layout (binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
GregFaae75242015-06-03 18:40:50 -06002393 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002394 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06002395 " outColor = myBlueVal.color;\n"
2396 " outColor += myRedVal.color;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002397 "}\n";
2398
2399 ASSERT_NO_FATAL_FAILURE(InitState());
2400 ASSERT_NO_FATAL_FAILURE(InitViewport());
2401
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002402 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2403 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002404
2405 // We're going to create a number of uniform buffers, and then allow
2406 // the shader to select which it wants to read from with a binding
2407
2408 // Let's populate the buffers with a single color each:
Tony Barbouracb3c1c2015-09-29 14:56:09 -06002409 // layout (binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2410 // layout (binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2411 // layout (binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2412 // layout (binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barboure2c58df2014-11-25 13:18:32 -07002413
2414 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2415 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2416 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2417 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2418
2419 const int redCount = sizeof(redVals) / sizeof(float);
2420 const int greenCount = sizeof(greenVals) / sizeof(float);
2421 const int blueCount = sizeof(blueVals) / sizeof(float);
2422 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2423
Tony Barbour6918cd52015-04-09 12:58:51 -06002424 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002425
Tony Barbour6918cd52015-04-09 12:58:51 -06002426 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002427
Tony Barbour6918cd52015-04-09 12:58:51 -06002428 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002429
Tony Barbour6918cd52015-04-09 12:58:51 -06002430 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002431
Tony Barbour6918cd52015-04-09 12:58:51 -06002432 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002433 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002434 pipelineobj.AddShader(&vs);
2435 pipelineobj.AddShader(&ps);
2436
Tony Barbour6918cd52015-04-09 12:58:51 -06002437 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002438 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2439 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2440 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2441 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002442
Tony Barbour664accc2015-01-09 12:55:14 -07002443 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002444 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure2c58df2014-11-25 13:18:32 -07002445
Tony Barbourfe3351b2015-07-28 10:17:20 -06002446 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002447
2448#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002449 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002450 pDSDumpDot((char*)"triTest2.dot");
2451#endif
2452 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002453 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002454
2455 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002456 EndCommandBuffer();
2457 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002458
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002459 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002460}
2461
Tony Barbour6918cd52015-04-09 12:58:51 -06002462TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBinding)
Tony Barboure2c58df2014-11-25 13:18:32 -07002463{
2464 // This test is the same as TriangleFSUniformBlockBinding, but
2465 // it does not provide an instance name.
2466 // The expected result from this test is a purple triangle
2467
2468 static const char *vertShaderText =
2469 "#version 140\n"
2470 "#extension GL_ARB_separate_shader_objects : enable\n"
2471 "#extension GL_ARB_shading_language_420pack : enable\n"
2472 "void main() {\n"
2473 " vec2 vertices[3];"
2474 " vertices[0] = vec2(-0.5, -0.5);\n"
2475 " vertices[1] = vec2( 0.5, -0.5);\n"
2476 " vertices[2] = vec2( 0.5, 0.5);\n"
2477 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2478 "}\n";
2479
2480 static const char *fragShaderText =
2481 "#version 430\n"
2482 "#extension GL_ARB_separate_shader_objects : enable\n"
2483 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbouracb3c1c2015-09-29 14:56:09 -06002484 "layout (binding = 0) uniform redVal { vec4 red; };"
2485 "layout (binding = 1) uniform greenVal { vec4 green; };"
2486 "layout (binding = 2) uniform blueVal { vec4 blue; };"
2487 "layout (binding = 3) uniform whiteVal { vec4 white; };"
Cody Northropd43c52e2014-12-05 15:44:14 -07002488 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002489 "void main() {\n"
Cody Northropd43c52e2014-12-05 15:44:14 -07002490 " outColor = blue;\n"
2491 " outColor += red;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002492 "}\n";
2493 ASSERT_NO_FATAL_FAILURE(InitState());
2494 ASSERT_NO_FATAL_FAILURE(InitViewport());
2495
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002496 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2497 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002498
2499 // We're going to create a number of uniform buffers, and then allow
2500 // the shader to select which it wants to read from with a binding
2501
2502 // Let's populate the buffers with a single color each:
Tony Barbouracb3c1c2015-09-29 14:56:09 -06002503 // layout (binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2504 // layout (binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2505 // layout (binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2506 // layout (binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barboure2c58df2014-11-25 13:18:32 -07002507
2508 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2509 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2510 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2511 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2512
2513 const int redCount = sizeof(redVals) / sizeof(float);
2514 const int greenCount = sizeof(greenVals) / sizeof(float);
2515 const int blueCount = sizeof(blueVals) / sizeof(float);
2516 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2517
Tony Barbour6918cd52015-04-09 12:58:51 -06002518 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002519
Tony Barbour6918cd52015-04-09 12:58:51 -06002520 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002521
Tony Barbour6918cd52015-04-09 12:58:51 -06002522 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002523
Tony Barbour6918cd52015-04-09 12:58:51 -06002524 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002525
Tony Barbour6918cd52015-04-09 12:58:51 -06002526 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002527 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002528 pipelineobj.AddShader(&vs);
2529 pipelineobj.AddShader(&ps);
2530
Tony Barbour6918cd52015-04-09 12:58:51 -06002531 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002532 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2533 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2534 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2535 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002536
Tony Barbour664accc2015-01-09 12:55:14 -07002537 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002538 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002539
Tony Barbourfe3351b2015-07-28 10:17:20 -06002540 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002541
2542#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002543 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002544 pDSDumpDot((char*)"triTest2.dot");
2545#endif
2546 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002547 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002548
2549 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002550 EndCommandBuffer();
2551 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002552
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002553 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002554}
2555
GregF6084aec2015-07-01 16:11:09 -06002556TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBindingWithStruct)
2557{
2558 // This test is the same as TriangleFSUniformBlockBinding, but
2559 // it does not provide an instance name.
2560 // The expected result from this test is a purple triangle
2561
2562 static const char *vertShaderText =
2563 "#version 140\n"
2564 "#extension GL_ARB_separate_shader_objects : enable\n"
2565 "#extension GL_ARB_shading_language_420pack : enable\n"
2566 "void main() {\n"
2567 " vec2 vertices[3];"
2568 " vertices[0] = vec2(-0.5, -0.5);\n"
2569 " vertices[1] = vec2( 0.5, -0.5);\n"
2570 " vertices[2] = vec2( 0.5, 0.5);\n"
2571 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2572 "}\n";
2573
2574 static const char *fragShaderText =
2575 "#version 430\n"
2576 "#extension GL_ARB_separate_shader_objects : enable\n"
2577 "#extension GL_ARB_shading_language_420pack : enable\n"
2578 "\n"
2579 " struct PS_INPUT {\n"
2580 " vec2 member0;\n"
2581 " vec4 member1;\n"
2582 " vec4 member2;\n"
2583 " vec4 member3;\n"
2584 " vec4 member4;\n"
2585 " vec4 member5;\n"
2586 " vec4 member6;\n"
2587 " vec4 member7;\n"
2588 " vec4 member8;\n"
2589 " vec4 member9;\n"
2590 " };\n"
2591 "\n"
Tony Barbouracb3c1c2015-09-29 14:56:09 -06002592 "layout (binding = 0) uniform redVal { vec4 red; };"
2593 "layout (binding = 1) uniform greenVal { vec4 green; };"
2594 "layout (binding = 2) uniform blueVal { vec4 blue; };"
2595 "layout (binding = 3) uniform whiteVal { vec4 white; };"
GregF6084aec2015-07-01 16:11:09 -06002596 "layout (location = 0) out vec4 outColor;\n"
2597 "PS_INPUT MainFs()\n"
2598 "{\n"
2599 " PS_INPUT o;\n"
2600 " o.member9 = red;\n"
2601 " return o;\n"
2602 "}\n"
2603 "\n"
2604 "void main()\n"
2605 "{\n"
2606 " PS_INPUT o;\n"
2607 " o = MainFs();\n"
2608 " outColor = blue;"
2609 " outColor += o.member9;\n"
2610 "}\n";;
2611 ASSERT_NO_FATAL_FAILURE(InitState());
2612 ASSERT_NO_FATAL_FAILURE(InitViewport());
2613
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002614 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2615 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
GregF6084aec2015-07-01 16:11:09 -06002616
2617 // We're going to create a number of uniform buffers, and then allow
2618 // the shader to select which it wants to read from with a binding
2619
2620 // Let's populate the buffers with a single color each:
Tony Barbouracb3c1c2015-09-29 14:56:09 -06002621 // layout (binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2622 // layout (binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2623 // layout (binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2624 // layout (binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
GregF6084aec2015-07-01 16:11:09 -06002625
2626 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2627 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2628 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2629 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2630
2631 const int redCount = sizeof(redVals) / sizeof(float);
2632 const int greenCount = sizeof(greenVals) / sizeof(float);
2633 const int blueCount = sizeof(blueVals) / sizeof(float);
2634 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2635
2636 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2637
2638 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2639
2640 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2641
2642 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
2643
2644 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002645 pipelineobj.AddColorAttachment();
GregF6084aec2015-07-01 16:11:09 -06002646 pipelineobj.AddShader(&vs);
2647 pipelineobj.AddShader(&ps);
2648
2649 VkDescriptorSetObj descriptorSet(m_device);
2650 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2651 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2652 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2653 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
2654
2655 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002656 ASSERT_VK_SUCCESS(BeginCommandBuffer());
GregF6084aec2015-07-01 16:11:09 -06002657
Tony Barbourfe3351b2015-07-28 10:17:20 -06002658 GenericDrawPreparation(pipelineobj, descriptorSet);
GregF6084aec2015-07-01 16:11:09 -06002659
2660#ifdef DUMP_STATE_DOT
2661 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
2662 pDSDumpDot((char*)"triTest2.dot");
2663#endif
2664 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002665 Draw(3, 1, 0, 0);
GregF6084aec2015-07-01 16:11:09 -06002666
2667 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002668 EndCommandBuffer();
2669 QueueCommandBuffer();
GregF6084aec2015-07-01 16:11:09 -06002670
2671 RecordImages(m_renderTargets);
2672}
2673
Tony Barbour6918cd52015-04-09 12:58:51 -06002674TEST_F(VkRenderTest, CubeWithVertexFetchAndMVPAndTexture)
Tony Barboure2c58df2014-11-25 13:18:32 -07002675{
2676 static const char *vertShaderText =
2677 "#version 140\n"
2678 "#extension GL_ARB_separate_shader_objects : enable\n"
2679 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbouracb3c1c2015-09-29 14:56:09 -06002680 "layout (binding=0) uniform bufferVals {\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002681 " mat4 mvp;\n"
2682 "} myBufferVals;\n"
2683 "layout (location=0) in vec4 pos;\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002684 "layout (location=1) in vec2 input_uv;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002685 "layout (location=0) out vec2 UV;\n"
2686 "void main() {\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002687 " UV = input_uv;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002688 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002689 " gl_Position.y = -gl_Position.y;\n"
2690 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002691 "}\n";
2692
2693 static const char *fragShaderText =
2694 "#version 140\n"
2695 "#extension GL_ARB_separate_shader_objects : enable\n"
2696 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wu11078b02015-01-04 16:27:24 +08002697 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002698 "layout (location=0) out vec4 outColor;\n"
2699 "layout (location=0) in vec2 UV;\n"
2700 "void main() {\n"
2701 " outColor= textureLod(surface, UV, 0.0);\n"
2702 "}\n";
2703 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2704
2705 glm::mat4 View = glm::lookAt(
2706 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2707 glm::vec3(0,0,0), // and looks at the origin
2708 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2709 );
2710
2711 glm::mat4 Model = glm::mat4(1.0f);
2712
2713 glm::mat4 MVP = Projection * View * Model;
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002714 int num_verts = sizeof(g_vb_texture_Data) / sizeof(g_vb_texture_Data[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002715
2716
2717 ASSERT_NO_FATAL_FAILURE(InitState());
2718 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wub4052042015-07-09 10:16:34 +08002719 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Chia-I Wu08accc62015-07-07 11:50:03 +08002720 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height, m_depth_stencil_fmt);
Tony Barboure2c58df2014-11-25 13:18:32 -07002721
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002722 VkConstantBufferObj meshBuffer(m_device, num_verts,
2723 sizeof(g_vb_texture_Data[0]), g_vb_texture_Data);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00002724 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07002725
Mark Lobodzinski17caf572015-01-29 08:55:56 -06002726 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barboure2c58df2014-11-25 13:18:32 -07002727
Tony Barbour6918cd52015-04-09 12:58:51 -06002728 VkConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002729 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2730 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbour6918cd52015-04-09 12:58:51 -06002731 VkSamplerObj sampler(m_device);
2732 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002733
Tony Barbour6918cd52015-04-09 12:58:51 -06002734 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002735 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002736 pipelineobj.AddShader(&vs);
2737 pipelineobj.AddShader(&ps);
2738
Tony Barbour6918cd52015-04-09 12:58:51 -06002739 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002740 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mvpBuffer);
Chia-I Wu11078b02015-01-04 16:27:24 +08002741 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002742
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002743#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002744 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002745 MESH_BIND_ID, // binding ID
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002746 sizeof(g_vb_texture_Data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002747 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002748 };
Tony Barboure2c58df2014-11-25 13:18:32 -07002749
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002750 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002751 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2752 vi_attribs[0].location = 0; // location
Tony Barbourd1c35722015-04-16 15:59:00 -06002753 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002754 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2755 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2756 vi_attribs[1].location = 1; // location
2757 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
2758 vi_attribs[1].offsetInBytes = 16; // Offset of uv components
Tony Barboure2c58df2014-11-25 13:18:32 -07002759
Tony Barboure2c58df2014-11-25 13:18:32 -07002760 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002761 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barboure2c58df2014-11-25 13:18:32 -07002762
Tony Barbourdd6e32e2015-07-10 15:29:03 -06002763 VkPipelineDepthStencilStateCreateInfo ds_state;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002764 ds_state.depthTestEnable = VK_TRUE;
2765 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbourd1c35722015-04-16 15:59:00 -06002766 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Cody Northrop271ba752015-08-26 10:01:32 -06002767 ds_state.depthBoundsTestEnable = VK_FALSE;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002768 ds_state.stencilTestEnable = VK_FALSE;
2769 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
2770 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
2771 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbourd1c35722015-04-16 15:59:00 -06002772 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
Tony Barbourf52346d2015-01-16 14:27:35 -07002773 ds_state.front = ds_state.back;
2774 pipelineobj.SetDepthStencil(&ds_state);
2775
Tony Barbour1c45ce02015-03-27 17:03:18 -06002776 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tobin Ehlisf1878c72015-08-18 14:24:32 -06002777
2778 VkCmdBufferBeginInfo cbBeginInfo;
2779 memset(&cbBeginInfo, 0, sizeof(VkCmdBufferBeginInfo));
2780 cbBeginInfo.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
Courtney Goeltzenleuchter04bb5f82015-10-21 18:11:04 -06002781 cbBeginInfo.flags = 0;
Tobin Ehlisf1878c72015-08-18 14:24:32 -06002782 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barboure2c58df2014-11-25 13:18:32 -07002783
Tony Barbourfe3351b2015-07-28 10:17:20 -06002784 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002785
Tony Barbourfe3351b2015-07-28 10:17:20 -06002786 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002787#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002788 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002789 pDSDumpDot((char*)"triTest2.dot");
2790#endif
2791 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002792 Draw(num_verts, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002793
2794 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002795 EndCommandBuffer();
2796 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002797
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002798 RecordImages(m_renderTargets);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002799 RotateTriangleVSUniform(Projection, View, Model, &mvpBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002800}
Cody Northropf1990a92014-12-09 11:17:01 -07002801
Tony Barbour6918cd52015-04-09 12:58:51 -06002802TEST_F(VkRenderTest, TriangleMixedSamplerUniformBlockBinding)
Cody Northropf1990a92014-12-09 11:17:01 -07002803{
2804 // This test mixes binding slots of textures and buffers, ensuring
2805 // that sparse and overlapping assignments work.
Cody Northropb110b4f2014-12-09 13:59:39 -07002806 // The expected result from this test is a purple triangle, although
Cody Northropf1990a92014-12-09 11:17:01 -07002807 // you can modify it to move the desired result around.
2808
2809 static const char *vertShaderText =
2810 "#version 140\n"
2811 "#extension GL_ARB_separate_shader_objects : enable\n"
2812 "#extension GL_ARB_shading_language_420pack : enable\n"
2813 "void main() {\n"
2814 " vec2 vertices[3];"
2815 " vertices[0] = vec2(-0.5, -0.5);\n"
2816 " vertices[1] = vec2( 0.5, -0.5);\n"
2817 " vertices[2] = vec2( 0.5, 0.5);\n"
2818 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2819 "}\n";
2820
2821 static const char *fragShaderText =
2822 "#version 430\n"
2823 "#extension GL_ARB_separate_shader_objects : enable\n"
2824 "#extension GL_ARB_shading_language_420pack : enable\n"
2825 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wu11078b02015-01-04 16:27:24 +08002826 "layout (binding = 3) uniform sampler2D surface1;\n"
2827 "layout (binding = 1) uniform sampler2D surface2;\n"
2828 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002829
Cody Northropb110b4f2014-12-09 13:59:39 -07002830
Tony Barbouracb3c1c2015-09-29 14:56:09 -06002831 "layout (binding = 4) uniform redVal { vec4 red; };"
2832 "layout (binding = 6) uniform greenVal { vec4 green; };"
2833 "layout (binding = 5) uniform blueVal { vec4 blue; };"
2834 "layout (binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropf1990a92014-12-09 11:17:01 -07002835 "layout (location = 0) out vec4 outColor;\n"
2836 "void main() {\n"
Cody Northropb110b4f2014-12-09 13:59:39 -07002837 " outColor = red * vec4(0.00001);\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002838 " outColor += white * vec4(0.00001);\n"
2839 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropb110b4f2014-12-09 13:59:39 -07002840 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002841 "}\n";
2842 ASSERT_NO_FATAL_FAILURE(InitState());
2843 ASSERT_NO_FATAL_FAILURE(InitViewport());
2844
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002845 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2846 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northropf1990a92014-12-09 11:17:01 -07002847
Cody Northropf1990a92014-12-09 11:17:01 -07002848 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2849 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2850 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2851 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2852
2853 const int redCount = sizeof(redVals) / sizeof(float);
2854 const int greenCount = sizeof(greenVals) / sizeof(float);
2855 const int blueCount = sizeof(blueVals) / sizeof(float);
2856 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2857
Tony Barbour6918cd52015-04-09 12:58:51 -06002858 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2859 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2860 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2861 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropf1990a92014-12-09 11:17:01 -07002862
Tony Barbourebc093f2015-04-01 16:38:10 -06002863 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour6918cd52015-04-09 12:58:51 -06002864 VkSamplerObj sampler0(m_device);
2865 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbourebc093f2015-04-01 16:38:10 -06002866 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour6918cd52015-04-09 12:58:51 -06002867 VkSamplerObj sampler2(m_device);
2868 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbourebc093f2015-04-01 16:38:10 -06002869 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour6918cd52015-04-09 12:58:51 -06002870 VkSamplerObj sampler4(m_device);
2871 VkTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropb110b4f2014-12-09 13:59:39 -07002872
2873 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2874 // TODO: Get back here ASAP and understand why.
Tony Barbourebc093f2015-04-01 16:38:10 -06002875 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour6918cd52015-04-09 12:58:51 -06002876 VkSamplerObj sampler7(m_device);
2877 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropf1990a92014-12-09 11:17:01 -07002878
Tony Barbour6918cd52015-04-09 12:58:51 -06002879 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002880 pipelineobj.AddColorAttachment();
Cody Northropf1990a92014-12-09 11:17:01 -07002881 pipelineobj.AddShader(&vs);
2882 pipelineobj.AddShader(&ps);
2883
Tony Barbour6918cd52015-04-09 12:58:51 -06002884 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002885 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2886 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2887 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2888 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002889 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
Chia-I Wu11078b02015-01-04 16:27:24 +08002890 // swap blue and green
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002891 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2892 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2893 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropf1990a92014-12-09 11:17:01 -07002894
Tony Barbour664accc2015-01-09 12:55:14 -07002895 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002896 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropf1990a92014-12-09 11:17:01 -07002897
Tony Barbourfe3351b2015-07-28 10:17:20 -06002898 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002899
2900#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002901 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002902 pDSDumpDot((char*)"triTest2.dot");
2903#endif
2904 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06002905 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002906
2907 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002908 EndCommandBuffer();
2909 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002910
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002911 RecordImages(m_renderTargets);
Cody Northropf1990a92014-12-09 11:17:01 -07002912}
2913
Tony Barbour6918cd52015-04-09 12:58:51 -06002914TEST_F(VkRenderTest, TriangleMatchingSamplerUniformBlockBinding)
Cody Northropbd531de2014-12-09 19:08:54 -07002915{
2916 // This test matches binding slots of textures and buffers, requiring
2917 // the driver to give them distinct number spaces.
2918 // The expected result from this test is a red triangle, although
2919 // you can modify it to move the desired result around.
2920
2921 static const char *vertShaderText =
2922 "#version 140\n"
2923 "#extension GL_ARB_separate_shader_objects : enable\n"
2924 "#extension GL_ARB_shading_language_420pack : enable\n"
2925 "void main() {\n"
2926 " vec2 vertices[3];"
2927 " vertices[0] = vec2(-0.5, -0.5);\n"
2928 " vertices[1] = vec2( 0.5, -0.5);\n"
2929 " vertices[2] = vec2( 0.5, 0.5);\n"
2930 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2931 "}\n";
2932
2933 static const char *fragShaderText =
2934 "#version 430\n"
2935 "#extension GL_ARB_separate_shader_objects : enable\n"
2936 "#extension GL_ARB_shading_language_420pack : enable\n"
2937 "layout (binding = 0) uniform sampler2D surface0;\n"
2938 "layout (binding = 1) uniform sampler2D surface1;\n"
2939 "layout (binding = 2) uniform sampler2D surface2;\n"
2940 "layout (binding = 3) uniform sampler2D surface3;\n"
Tony Barbouracb3c1c2015-09-29 14:56:09 -06002941 "layout (binding = 4) uniform redVal { vec4 red; };"
2942 "layout (binding = 5) uniform greenVal { vec4 green; };"
2943 "layout (binding = 6) uniform blueVal { vec4 blue; };"
2944 "layout (binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropbd531de2014-12-09 19:08:54 -07002945 "layout (location = 0) out vec4 outColor;\n"
2946 "void main() {\n"
2947 " outColor = red;// * vec4(0.00001);\n"
2948 " outColor += white * vec4(0.00001);\n"
2949 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2950 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2951 "}\n";
2952 ASSERT_NO_FATAL_FAILURE(InitState());
2953 ASSERT_NO_FATAL_FAILURE(InitViewport());
2954
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06002955 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2956 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northropbd531de2014-12-09 19:08:54 -07002957
2958 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2959 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2960 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2961 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2962
2963 const int redCount = sizeof(redVals) / sizeof(float);
2964 const int greenCount = sizeof(greenVals) / sizeof(float);
2965 const int blueCount = sizeof(blueVals) / sizeof(float);
2966 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2967
Tony Barbour6918cd52015-04-09 12:58:51 -06002968 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2969 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2970 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2971 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropbd531de2014-12-09 19:08:54 -07002972
Tony Barbourebc093f2015-04-01 16:38:10 -06002973 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour6918cd52015-04-09 12:58:51 -06002974 VkSamplerObj sampler0(m_device);
2975 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbourebc093f2015-04-01 16:38:10 -06002976 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour6918cd52015-04-09 12:58:51 -06002977 VkSamplerObj sampler2(m_device);
2978 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbourebc093f2015-04-01 16:38:10 -06002979 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour6918cd52015-04-09 12:58:51 -06002980 VkSamplerObj sampler4(m_device);
2981 VkTextureObj texture4(m_device, tex_colors); // Light Green
Tony Barbourebc093f2015-04-01 16:38:10 -06002982 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour6918cd52015-04-09 12:58:51 -06002983 VkSamplerObj sampler7(m_device);
2984 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropbd531de2014-12-09 19:08:54 -07002985
Tony Barbour6918cd52015-04-09 12:58:51 -06002986 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002987 pipelineobj.AddColorAttachment();
Cody Northropbd531de2014-12-09 19:08:54 -07002988 pipelineobj.AddShader(&vs);
2989 pipelineobj.AddShader(&ps);
2990
Tony Barbour6918cd52015-04-09 12:58:51 -06002991 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002992 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2993 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2994 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2995 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002996 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2997 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2998 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2999 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropbd531de2014-12-09 19:08:54 -07003000
Tony Barbour664accc2015-01-09 12:55:14 -07003001 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003002 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropbd531de2014-12-09 19:08:54 -07003003
Tony Barbourfe3351b2015-07-28 10:17:20 -06003004 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07003005
3006#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003007 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07003008 pDSDumpDot((char*)"triTest2.dot");
3009#endif
3010 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003011 Draw(3, 1, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07003012
3013 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003014 EndCommandBuffer();
3015 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07003016
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06003017 RecordImages(m_renderTargets);
Cody Northropbd531de2014-12-09 19:08:54 -07003018}
3019
Tony Barbour6918cd52015-04-09 12:58:51 -06003020TEST_F(VkRenderTest, TriangleUniformBufferLayout)
Cody Northrop04ad1202014-12-17 15:26:33 -07003021{
3022 // This test populates a buffer with a variety of different data
3023 // types, then reads them out with a shader.
3024 // The expected result from this test is a green triangle
3025
3026 static const char *vertShaderText =
3027 "#version 140\n"
3028 "#extension GL_ARB_separate_shader_objects : enable\n"
3029 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbouracb3c1c2015-09-29 14:56:09 -06003030 "layout (binding = 0) uniform mixedBuffer {\n"
Cody Northrop04ad1202014-12-17 15:26:33 -07003031 " vec4 fRed;\n"
3032 " vec4 fGreen;\n"
3033 " layout(row_major) mat4 worldToProj;\n"
3034 " layout(row_major) mat4 projToWorld;\n"
3035 " layout(row_major) mat4 worldToView;\n"
3036 " layout(row_major) mat4 viewToProj;\n"
3037 " layout(row_major) mat4 worldToShadow[4];\n"
3038 " float fZero;\n"
3039 " float fOne;\n"
3040 " float fTwo;\n"
3041 " float fThree;\n"
3042 " vec3 fZeroZeroZero;\n"
3043 " float fFour;\n"
3044 " vec3 fZeroZeroOne;\n"
3045 " float fFive;\n"
3046 " vec3 fZeroOneZero;\n"
3047 " float fSix;\n"
3048 " float fSeven;\n"
3049 " float fEight;\n"
3050 " float fNine;\n"
3051 " vec2 fZeroZero;\n"
3052 " vec2 fZeroOne;\n"
3053 " vec4 fBlue;\n"
3054 " vec2 fOneZero;\n"
3055 " vec2 fOneOne;\n"
3056 " vec3 fZeroOneOne;\n"
3057 " float fTen;\n"
3058 " float fEleven;\n"
3059 " float fTwelve;\n"
3060 " vec3 fOneZeroZero;\n"
3061 " vec4 uvOffsets[4];\n"
3062 "};\n"
3063 "layout (location = 0) out vec4 color;"
3064 "void main() {\n"
3065
3066 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3067 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3068 " \n"
3069
3070 // do some exact comparisons, even though we should
3071 // really have an epsilon involved.
3072 " vec4 outColor = right;\n"
3073 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3074 " outColor = wrong;\n"
3075 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3076 " outColor = wrong;\n"
3077 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3078 " outColor = wrong;\n"
3079
3080 " color = outColor;\n"
3081
3082 // generic position stuff
3083 " vec2 vertices;\n"
3084 " int vertexSelector = gl_VertexID;\n"
3085 " if (vertexSelector == 0)\n"
3086 " vertices = vec2(-0.5, -0.5);\n"
3087 " else if (vertexSelector == 1)\n"
3088 " vertices = vec2( 0.5, -0.5);\n"
3089 " else if (vertexSelector == 2)\n"
3090 " vertices = vec2( 0.5, 0.5);\n"
3091 " else\n"
3092 " vertices = vec2( 0.0, 0.0);\n"
3093 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3094 "}\n";
3095
3096 static const char *fragShaderText =
3097 "#version 140\n"
3098 "#extension GL_ARB_separate_shader_objects : enable\n"
3099 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbouracb3c1c2015-09-29 14:56:09 -06003100 "layout (binding = 0) uniform mixedBuffer {\n"
Cody Northrop04ad1202014-12-17 15:26:33 -07003101 " vec4 fRed;\n"
3102 " vec4 fGreen;\n"
3103 " layout(row_major) mat4 worldToProj;\n"
3104 " layout(row_major) mat4 projToWorld;\n"
3105 " layout(row_major) mat4 worldToView;\n"
3106 " layout(row_major) mat4 viewToProj;\n"
3107 " layout(row_major) mat4 worldToShadow[4];\n"
3108 " float fZero;\n"
3109 " float fOne;\n"
3110 " float fTwo;\n"
3111 " float fThree;\n"
3112 " vec3 fZeroZeroZero;\n"
3113 " float fFour;\n"
3114 " vec3 fZeroZeroOne;\n"
3115 " float fFive;\n"
3116 " vec3 fZeroOneZero;\n"
3117 " float fSix;\n"
3118 " float fSeven;\n"
3119 " float fEight;\n"
3120 " float fNine;\n"
3121 " vec2 fZeroZero;\n"
3122 " vec2 fZeroOne;\n"
3123 " vec4 fBlue;\n"
3124 " vec2 fOneZero;\n"
3125 " vec2 fOneOne;\n"
3126 " vec3 fZeroOneOne;\n"
3127 " float fTen;\n"
3128 " float fEleven;\n"
3129 " float fTwelve;\n"
3130 " vec3 fOneZeroZero;\n"
3131 " vec4 uvOffsets[4];\n"
3132 "};\n"
3133 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06003134 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop04ad1202014-12-17 15:26:33 -07003135 "void main() {\n"
3136 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3137 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3138 " \n"
3139
3140 // start with VS value to ensure it passed
3141 " vec4 outColor = color;\n"
3142
3143 // do some exact comparisons, even though we should
3144 // really have an epsilon involved.
3145 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3146 " outColor = wrong;\n"
3147 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3148 " outColor = wrong;\n"
3149 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3150 " outColor = wrong;\n"
3151 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3152 " outColor = wrong;\n"
3153 " if (fTwo != 2.0)\n"
3154 " outColor = wrong;\n"
3155 " if (fOneOne != vec2(1.0, 1.0))\n"
3156 " outColor = wrong;\n"
3157 " if (fTen != 10.0)\n"
3158 " outColor = wrong;\n"
3159 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3160 " outColor = wrong;\n"
3161 " \n"
GregFaae75242015-06-03 18:40:50 -06003162 " uFragColor = outColor;\n"
Cody Northrop04ad1202014-12-17 15:26:33 -07003163 "}\n";
3164
3165
Cody Northropd2ad0342015-08-05 11:15:02 -06003166 const float mixedVals[196] = { 1.0f, 0.0f, 0.0f, 1.0f, // vec4 fRed; // align
3167 0.0f, 1.0f, 0.0f, 1.0f, // vec4 fGreen; // align
3168 1.0f, 0.0f, 0.0f, 1.0f, // layout(row_major) mat4 worldToProj;
3169 0.0f, 1.0f, 0.0f, 1.0f, // align
3170 0.0f, 0.0f, 1.0f, 1.0f, // align
3171 0.0f, 0.0f, 0.0f, 1.0f, // align
3172 2.0f, 0.0f, 0.0f, 2.0f, // layout(row_major) mat4 projToWorld;
3173 0.0f, 2.0f, 0.0f, 2.0f, // align
3174 0.0f, 0.0f, 2.0f, 2.0f, // align
3175 0.0f, 0.0f, 0.0f, 2.0f, // align
3176 3.0f, 0.0f, 0.0f, 3.0f, // layout(row_major) mat4 worldToView;
3177 0.0f, 3.0f, 0.0f, 3.0f, // align
3178 0.0f, 0.0f, 3.0f, 3.0f, // align
3179 0.0f, 0.0f, 0.0f, 3.0f, // align
3180 4.0f, 0.0f, 0.0f, 4.0f, // layout(row_major) mat4 viewToProj;
3181 0.0f, 4.0f, 0.0f, 4.0f, // align
3182 0.0f, 0.0f, 4.0f, 4.0f, // align
3183 0.0f, 0.0f, 0.0f, 4.0f, // align
3184 5.0f, 0.0f, 0.0f, 5.0f, // layout(row_major) mat4 worldToShadow[4];
3185 0.0f, 5.0f, 0.0f, 5.0f, // align
3186 0.0f, 0.0f, 5.0f, 5.0f, // align
3187 0.0f, 0.0f, 0.0f, 5.0f, // align
3188 6.0f, 0.0f, 0.0f, 6.0f, // align
3189 0.0f, 6.0f, 0.0f, 6.0f, // align
3190 0.0f, 0.0f, 6.0f, 6.0f, // align
3191 0.0f, 0.0f, 0.0f, 6.0f, // align
3192 7.0f, 0.0f, 0.0f, 7.0f, // align
3193 0.0f, 7.0f, 0.0f, 7.0f, // align
3194 0.0f, 0.0f, 7.0f, 7.0f, // align
3195 0.0f, 0.0f, 0.0f, 7.0f, // align
3196 8.0f, 0.0f, 0.0f, 8.0f, // align
3197 0.0f, 8.0f, 0.0f, 8.0f, // align
3198 0.0f, 0.0f, 8.0f, 8.0f, // align
3199 0.0f, 0.0f, 0.0f, 8.0f, // align
3200 0.0f, // float fZero; // align
3201 1.0f, // float fOne; // pack
3202 2.0f, // float fTwo; // pack
3203 3.0f, // float fThree; // pack
3204 0.0f, 0.0f, 0.0f, // vec3 fZeroZeroZero; // align
3205 4.0f, // float fFour; // pack
3206 0.0f, 0.0f, 1.0f, // vec3 fZeroZeroOne; // align
3207 5.0f, // float fFive; // pack
3208 0.0f, 1.0f, 0.0f, // vec3 fZeroOneZero; // align
3209 6.0f, // float fSix; // pack
3210 7.0f, // float fSeven; // align
3211 8.0f, // float fEight; // pack
3212 9.0f, // float fNine; // pack
3213 0.0f, // BUFFER
3214 0.0f, 0.0f, // vec2 fZeroZero; // align
3215 0.0f, 1.0f, // vec2 fZeroOne; // pack
3216 0.0f, 0.0f, 1.0f, 1.0f, // vec4 fBlue; // align
3217 1.0f, 0.0f, // vec2 fOneZero; // align
3218 1.0f, 1.0f, // vec2 fOneOne; // pack
3219 0.0f, 1.0f, 1.0f, // vec3 fZeroOneOne; // align
3220 10.0f, // float fTen; // pack
3221 11.0f, // float fEleven; // align
3222 12.0f, // float fTwelve; // pack
3223 0.0f, 0.0f, // BUFFER
3224 1.0f, 0.0f, 0.0f, // vec3 fOneZeroZero; // align
3225 0.0f, // BUFFER
3226 0.1f, 0.2f, 0.3f, 0.4f, // vec4 uvOffsets[4];
3227 0.5f, 0.6f, 0.7f, 0.8f, // align
3228 0.9f, 1.0f, 1.1f, 1.2f, // align
3229 1.3f, 1.4f, 1.5f, 1.6f, // align
Cody Northrop04ad1202014-12-17 15:26:33 -07003230 };
3231
3232 ASSERT_NO_FATAL_FAILURE(InitState());
3233 ASSERT_NO_FATAL_FAILURE(InitViewport());
3234
3235 const int constCount = sizeof(mixedVals) / sizeof(float);
3236
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003237 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
3238 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northrop04ad1202014-12-17 15:26:33 -07003239
Tony Barbour6918cd52015-04-09 12:58:51 -06003240 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop04ad1202014-12-17 15:26:33 -07003241
Tony Barbour6918cd52015-04-09 12:58:51 -06003242 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003243 pipelineobj.AddColorAttachment();
Cody Northrop04ad1202014-12-17 15:26:33 -07003244 pipelineobj.AddShader(&vs);
3245 pipelineobj.AddShader(&ps);
3246
Tony Barbour6918cd52015-04-09 12:58:51 -06003247 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003248 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
Cody Northrop04ad1202014-12-17 15:26:33 -07003249
3250 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003251 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop04ad1202014-12-17 15:26:33 -07003252
Tony Barbourfe3351b2015-07-28 10:17:20 -06003253 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop04ad1202014-12-17 15:26:33 -07003254
3255#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003256 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop04ad1202014-12-17 15:26:33 -07003257 pDSDumpDot((char*)"triTest2.dot");
3258#endif
3259 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003260 Draw(3, 1, 0, 0);
Cody Northrop04ad1202014-12-17 15:26:33 -07003261
3262 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003263 EndCommandBuffer();
3264 QueueCommandBuffer();
Cody Northrop04ad1202014-12-17 15:26:33 -07003265
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06003266 RecordImages(m_renderTargets);
Cody Northrop04ad1202014-12-17 15:26:33 -07003267}
3268
Cody Northrop95638152015-05-07 14:39:12 -06003269TEST_F(VkRenderTest, TextureGather)
3270{
3271 // This test introduces textureGather and textureGatherOffset
3272 // Each call is compared against an expected inline color result
3273 // Green triangle means everything worked as expected
3274 // Red means something went wrong
3275
Cody Northropc55900f2015-08-06 13:18:13 -06003276 // disable SPV until texture gather is turned on in glsl->SPV
3277 if (!m_use_glsl) {
3278 printf("Skipping test that requires GLSL path (TextureGather)\n");
3279 return;
3280 }
3281
Cody Northrop95638152015-05-07 14:39:12 -06003282 static const char *vertShaderText =
3283 "#version 140\n"
3284 "#extension GL_ARB_separate_shader_objects : enable\n"
3285 "#extension GL_ARB_shading_language_420pack : enable\n"
3286 "void main() {\n"
3287 " vec2 vertices[3];"
3288 " vertices[0] = vec2(-0.5, -0.5);\n"
3289 " vertices[1] = vec2( 0.5, -0.5);\n"
3290 " vertices[2] = vec2( 0.5, 0.5);\n"
3291 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
3292 "}\n";
3293
3294 static const char *fragShaderText =
3295 "#version 430\n"
3296 "#extension GL_ARB_separate_shader_objects : enable\n"
3297 "#extension GL_ARB_shading_language_420pack : enable\n"
3298 "layout (binding = 0) uniform sampler2D surface0;\n"
3299 "layout (binding = 1) uniform sampler2D surface1;\n"
3300 "layout (binding = 2) uniform sampler2D surface2;\n"
3301 "layout (binding = 3) uniform sampler2D surface3;\n"
3302 "layout (location = 0) out vec4 outColor;\n"
3303 "void main() {\n"
3304
3305 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3306 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3307
3308 " vec4 color = right;\n"
3309
3310 // Grab a normal texture sample to ensure it can work in conjuntion
3311 // with textureGather (there are some intracacies in the backend)
3312 " vec4 sampledColor = textureLod(surface2, vec2(0.5), 0.0);\n"
3313 " if (sampledColor != vec4(0.0, 0.0, 1.0, 1.0))\n"
3314 " color = wrong;\n"
3315
3316 " vec4 gatheredColor = textureGather(surface0, vec2(0.5), 0);\n"
3317 // This just grabbed four red components from a red surface
3318 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3319 " color = wrong;\n"
3320
3321 // Yes, this is using an offset of 0, we don't have enough fine grained
3322 // control of the texture contents here.
3323 " gatheredColor = textureGatherOffset(surface1, vec2(0.5), ivec2(0, 0), 1);\n"
3324 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3325 " color = wrong;\n"
3326
3327 " outColor = color;\n"
3328
3329 "}\n";
3330
3331 ASSERT_NO_FATAL_FAILURE(InitState());
3332 ASSERT_NO_FATAL_FAILURE(InitViewport());
3333
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003334 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
3335 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northrop95638152015-05-07 14:39:12 -06003336
3337 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
3338 VkSamplerObj sampler0(m_device);
3339 VkTextureObj texture0(m_device, tex_colors); // Red
3340 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
3341 VkSamplerObj sampler1(m_device);
3342 VkTextureObj texture1(m_device, tex_colors); // Green
3343 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
3344 VkSamplerObj sampler2(m_device);
3345 VkTextureObj texture2(m_device, tex_colors); // Blue
3346 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
3347 VkSamplerObj sampler3(m_device);
3348 VkTextureObj texture3(m_device, tex_colors); // Red and Blue
3349
3350 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003351 pipelineobj.AddColorAttachment();
Cody Northrop95638152015-05-07 14:39:12 -06003352 pipelineobj.AddShader(&vs);
3353 pipelineobj.AddShader(&ps);
3354
3355 VkDescriptorSetObj descriptorSet(m_device);
3356 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3357 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
3358 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3359 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
3360
3361 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003362 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop95638152015-05-07 14:39:12 -06003363
Tony Barbourfe3351b2015-07-28 10:17:20 -06003364 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop95638152015-05-07 14:39:12 -06003365
3366 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003367 Draw(3, 1, 0, 0);
Cody Northrop95638152015-05-07 14:39:12 -06003368
3369 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003370 EndCommandBuffer();
3371 QueueCommandBuffer();
Cody Northrop95638152015-05-07 14:39:12 -06003372
3373 RecordImages(m_renderTargets);
Cody Northrop95638152015-05-07 14:39:12 -06003374}
3375
Cody Northrop475663c2015-04-15 11:19:06 -06003376TEST_F(VkRenderTest, GeometryShaderHelloWorld)
3377{
3378 // This test introduces a geometry shader that simply
3379 // changes the color of each vertex to red, green, blue
3380
3381 static const char *vertShaderText =
3382 "#version 140\n"
3383 "#extension GL_ARB_separate_shader_objects : enable\n"
3384 "#extension GL_ARB_shading_language_420pack : enable\n"
3385 "layout (location = 0) out vec4 color;"
3386 "void main() {\n"
3387
3388 // VS writes out red
3389 " color = vec4(1.0, 0.0, 0.0, 1.0);\n"
3390
3391 // generic position stuff
3392 " vec2 vertices;\n"
3393 " int vertexSelector = gl_VertexID;\n"
3394 " if (vertexSelector == 0)\n"
3395 " vertices = vec2(-0.5, -0.5);\n"
3396 " else if (vertexSelector == 1)\n"
3397 " vertices = vec2( 0.5, -0.5);\n"
3398 " else if (vertexSelector == 2)\n"
3399 " vertices = vec2( 0.5, 0.5);\n"
3400 " else\n"
3401 " vertices = vec2( 0.0, 0.0);\n"
3402 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3403
3404 "}\n";
3405
3406 static const char *geomShaderText =
3407 "#version 330\n"
3408 "#extension GL_ARB_separate_shader_objects : enable\n"
3409 "#extension GL_ARB_shading_language_420pack : enable\n"
3410 "layout( triangles ) in;\n"
3411 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3412 "layout( location = 0 ) in vec4 inColor[3];\n"
3413 "layout( location = 0 ) out vec4 outColor;\n"
3414 "void main()\n"
3415 "{\n"
3416
3417 // first vertex, pass through red
3418 " gl_Position = gl_in[0].gl_Position;\n"
3419 " outColor = inColor[0];\n"
3420 " EmitVertex();\n"
3421
3422 // second vertex, green
3423 " gl_Position = gl_in[1].gl_Position;\n"
3424 " outColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3425 " EmitVertex();\n"
3426
3427 // third vertex, blue
3428 " gl_Position = gl_in[2].gl_Position;\n"
3429 " outColor = vec4(0.0, 0.0, 1.0, 1.0);\n"
3430 " EmitVertex();\n"
3431
3432 // done
3433 " EndPrimitive();\n"
3434 "}\n";
3435
3436
3437 static const char *fragShaderText =
3438 "#version 140\n"
3439 "#extension GL_ARB_separate_shader_objects : enable\n"
3440 "#extension GL_ARB_shading_language_420pack : enable\n"
3441 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06003442 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003443 "void main() {\n"
3444 // pass through
GregFaae75242015-06-03 18:40:50 -06003445 " outColor = color;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003446 "}\n";
3447
3448
3449
3450 ASSERT_NO_FATAL_FAILURE(InitState());
3451 ASSERT_NO_FATAL_FAILURE(InitViewport());
3452
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003453 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3454 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY_BIT, this);
3455 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northrop475663c2015-04-15 11:19:06 -06003456
3457 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003458 pipelineobj.AddColorAttachment();
Cody Northrop475663c2015-04-15 11:19:06 -06003459 pipelineobj.AddShader(&vs);
3460 pipelineobj.AddShader(&gs);
3461 pipelineobj.AddShader(&ps);
3462
3463 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003464 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop475663c2015-04-15 11:19:06 -06003465
3466 VkDescriptorSetObj descriptorSet(m_device);
3467
Tony Barbourfe3351b2015-07-28 10:17:20 -06003468 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop475663c2015-04-15 11:19:06 -06003469
3470 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003471 Draw(3, 1, 0, 0);
Cody Northrop475663c2015-04-15 11:19:06 -06003472
3473 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003474 EndCommandBuffer();
3475 QueueCommandBuffer();
Cody Northrop475663c2015-04-15 11:19:06 -06003476
3477 RecordImages(m_renderTargets);
3478}
3479
3480TEST_F(VkRenderTest, GSUniformBufferLayout)
3481{
3482 // This test is just like TriangleUniformBufferLayout but adds
3483 // geometry as a stage that also does UBO lookups
3484 // The expected result from this test is a green triangle
3485
3486 static const char *vertShaderText =
3487 "#version 140\n"
3488 "#extension GL_ARB_separate_shader_objects : enable\n"
3489 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbouracb3c1c2015-09-29 14:56:09 -06003490 "layout (binding = 0) uniform mixedBuffer {\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003491 " vec4 fRed;\n"
3492 " vec4 fGreen;\n"
3493 " layout(row_major) mat4 worldToProj;\n"
3494 " layout(row_major) mat4 projToWorld;\n"
3495 " layout(row_major) mat4 worldToView;\n"
3496 " layout(row_major) mat4 viewToProj;\n"
3497 " layout(row_major) mat4 worldToShadow[4];\n"
3498 " float fZero;\n"
3499 " float fOne;\n"
3500 " float fTwo;\n"
3501 " float fThree;\n"
3502 " vec3 fZeroZeroZero;\n"
3503 " float fFour;\n"
3504 " vec3 fZeroZeroOne;\n"
3505 " float fFive;\n"
3506 " vec3 fZeroOneZero;\n"
3507 " float fSix;\n"
3508 " float fSeven;\n"
3509 " float fEight;\n"
3510 " float fNine;\n"
3511 " vec2 fZeroZero;\n"
3512 " vec2 fZeroOne;\n"
3513 " vec4 fBlue;\n"
3514 " vec2 fOneZero;\n"
3515 " vec2 fOneOne;\n"
3516 " vec3 fZeroOneOne;\n"
3517 " float fTen;\n"
3518 " float fEleven;\n"
3519 " float fTwelve;\n"
3520 " vec3 fOneZeroZero;\n"
3521 " vec4 uvOffsets[4];\n"
3522 "};\n"
3523 "layout (location = 0) out vec4 color;"
3524 "void main() {\n"
3525
3526 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3527 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3528 " \n"
3529
3530 // do some exact comparisons, even though we should
3531 // really have an epsilon involved.
3532 " vec4 outColor = right;\n"
3533 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3534 " outColor = wrong;\n"
3535 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3536 " outColor = wrong;\n"
3537 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3538 " outColor = wrong;\n"
3539
3540 " color = outColor;\n"
3541
3542 // generic position stuff
3543 " vec2 vertices;\n"
3544 " int vertexSelector = gl_VertexID;\n"
3545 " if (vertexSelector == 0)\n"
3546 " vertices = vec2(-0.5, -0.5);\n"
3547 " else if (vertexSelector == 1)\n"
3548 " vertices = vec2( 0.5, -0.5);\n"
3549 " else if (vertexSelector == 2)\n"
3550 " vertices = vec2( 0.5, 0.5);\n"
3551 " else\n"
3552 " vertices = vec2( 0.0, 0.0);\n"
3553 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3554 "}\n";
3555
3556 static const char *geomShaderText =
3557 "#version 330\n"
3558 "#extension GL_ARB_separate_shader_objects : enable\n"
3559 "#extension GL_ARB_shading_language_420pack : enable\n"
3560
3561 // GS layout stuff
3562 "layout( triangles ) in;\n"
3563 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3564
3565 // Between stage IO
3566 "layout( location = 0 ) in vec4 inColor[3];\n"
3567 "layout( location = 0 ) out vec4 color;\n"
3568
Tony Barbouracb3c1c2015-09-29 14:56:09 -06003569 "layout (binding = 0) uniform mixedBuffer {\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003570 " vec4 fRed;\n"
3571 " vec4 fGreen;\n"
3572 " layout(row_major) mat4 worldToProj;\n"
3573 " layout(row_major) mat4 projToWorld;\n"
3574 " layout(row_major) mat4 worldToView;\n"
3575 " layout(row_major) mat4 viewToProj;\n"
3576 " layout(row_major) mat4 worldToShadow[4];\n"
3577 " float fZero;\n"
3578 " float fOne;\n"
3579 " float fTwo;\n"
3580 " float fThree;\n"
3581 " vec3 fZeroZeroZero;\n"
3582 " float fFour;\n"
3583 " vec3 fZeroZeroOne;\n"
3584 " float fFive;\n"
3585 " vec3 fZeroOneZero;\n"
3586 " float fSix;\n"
3587 " float fSeven;\n"
3588 " float fEight;\n"
3589 " float fNine;\n"
3590 " vec2 fZeroZero;\n"
3591 " vec2 fZeroOne;\n"
3592 " vec4 fBlue;\n"
3593 " vec2 fOneZero;\n"
3594 " vec2 fOneOne;\n"
3595 " vec3 fZeroOneOne;\n"
3596 " float fTen;\n"
3597 " float fEleven;\n"
3598 " float fTwelve;\n"
3599 " vec3 fOneZeroZero;\n"
3600 " vec4 uvOffsets[4];\n"
3601 "};\n"
3602
3603 "void main()\n"
3604 "{\n"
3605
3606 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3607 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3608
3609 // Each vertex will validate it can read VS output
3610 // then check a few values from the UBO
3611
3612 // first vertex
3613 " vec4 outColor = inColor[0];\n"
3614
3615 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3616 " outColor = wrong;\n"
3617 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3618 " outColor = wrong;\n"
3619 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3620 " outColor = wrong;\n"
3621 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3622 " outColor = wrong;\n"
3623
3624 " gl_Position = gl_in[0].gl_Position;\n"
3625 " color = outColor;\n"
3626 " EmitVertex();\n"
3627
3628 // second vertex
3629 " outColor = inColor[1];\n"
3630
3631 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3632 " outColor = wrong;\n"
3633 " if (fSix != 6.0)\n"
3634 " outColor = wrong;\n"
3635 " if (fOneOne != vec2(1.0, 1.0))\n"
3636 " outColor = wrong;\n"
3637
3638 " gl_Position = gl_in[1].gl_Position;\n"
3639 " color = outColor;\n"
3640 " EmitVertex();\n"
3641
3642 // third vertex
3643 " outColor = inColor[2];\n"
3644
3645 " if (fSeven != 7.0)\n"
3646 " outColor = wrong;\n"
3647 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3648 " outColor = wrong;\n"
3649
3650 " gl_Position = gl_in[2].gl_Position;\n"
3651 " color = outColor;\n"
3652 " EmitVertex();\n"
3653
3654 // done
3655 " EndPrimitive();\n"
3656 "}\n";
3657
3658 static const char *fragShaderText =
3659 "#version 140\n"
3660 "#extension GL_ARB_separate_shader_objects : enable\n"
3661 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbouracb3c1c2015-09-29 14:56:09 -06003662 "layout (binding = 0) uniform mixedBuffer {\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003663 " vec4 fRed;\n"
3664 " vec4 fGreen;\n"
3665 " layout(row_major) mat4 worldToProj;\n"
3666 " layout(row_major) mat4 projToWorld;\n"
3667 " layout(row_major) mat4 worldToView;\n"
3668 " layout(row_major) mat4 viewToProj;\n"
3669 " layout(row_major) mat4 worldToShadow[4];\n"
3670 " float fZero;\n"
3671 " float fOne;\n"
3672 " float fTwo;\n"
3673 " float fThree;\n"
3674 " vec3 fZeroZeroZero;\n"
3675 " float fFour;\n"
3676 " vec3 fZeroZeroOne;\n"
3677 " float fFive;\n"
3678 " vec3 fZeroOneZero;\n"
3679 " float fSix;\n"
3680 " float fSeven;\n"
3681 " float fEight;\n"
3682 " float fNine;\n"
3683 " vec2 fZeroZero;\n"
3684 " vec2 fZeroOne;\n"
3685 " vec4 fBlue;\n"
3686 " vec2 fOneZero;\n"
3687 " vec2 fOneOne;\n"
3688 " vec3 fZeroOneOne;\n"
3689 " float fTen;\n"
3690 " float fEleven;\n"
3691 " float fTwelve;\n"
3692 " vec3 fOneZeroZero;\n"
3693 " vec4 uvOffsets[4];\n"
3694 "};\n"
3695 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06003696 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003697 "void main() {\n"
3698 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3699 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3700 " \n"
3701
3702 // start with GS value to ensure it passed
3703 " vec4 outColor = color;\n"
3704
3705 // do some exact comparisons, even though we should
3706 // really have an epsilon involved.
3707 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3708 " outColor = wrong;\n"
3709 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3710 " outColor = wrong;\n"
3711 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3712 " outColor = wrong;\n"
3713 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3714 " outColor = wrong;\n"
3715 " if (fTwo != 2.0)\n"
3716 " outColor = wrong;\n"
3717 " if (fOneOne != vec2(1.0, 1.0))\n"
3718 " outColor = wrong;\n"
3719 " if (fTen != 10.0)\n"
3720 " outColor = wrong;\n"
3721 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3722 " outColor = wrong;\n"
3723 " \n"
GregFaae75242015-06-03 18:40:50 -06003724 " uFragColor = outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003725 "}\n";
3726
3727
Cody Northropd2ad0342015-08-05 11:15:02 -06003728 const float mixedVals[196] = { 1.0f, 0.0f, 0.0f, 1.0f, // vec4 fRed; // align
3729 0.0f, 1.0f, 0.0f, 1.0f, // vec4 fGreen; // align
3730 1.0f, 0.0f, 0.0f, 1.0f, // layout(row_major) mat4 worldToProj;
3731 0.0f, 1.0f, 0.0f, 1.0f, // align
3732 0.0f, 0.0f, 1.0f, 1.0f, // align
3733 0.0f, 0.0f, 0.0f, 1.0f, // align
3734 2.0f, 0.0f, 0.0f, 2.0f, // layout(row_major) mat4 projToWorld;
3735 0.0f, 2.0f, 0.0f, 2.0f, // align
3736 0.0f, 0.0f, 2.0f, 2.0f, // align
3737 0.0f, 0.0f, 0.0f, 2.0f, // align
3738 3.0f, 0.0f, 0.0f, 3.0f, // layout(row_major) mat4 worldToView;
3739 0.0f, 3.0f, 0.0f, 3.0f, // align
3740 0.0f, 0.0f, 3.0f, 3.0f, // align
3741 0.0f, 0.0f, 0.0f, 3.0f, // align
3742 4.0f, 0.0f, 0.0f, 4.0f, // layout(row_major) mat4 viewToProj;
3743 0.0f, 4.0f, 0.0f, 4.0f, // align
3744 0.0f, 0.0f, 4.0f, 4.0f, // align
3745 0.0f, 0.0f, 0.0f, 4.0f, // align
3746 5.0f, 0.0f, 0.0f, 5.0f, // layout(row_major) mat4 worldToShadow[4];
3747 0.0f, 5.0f, 0.0f, 5.0f, // align
3748 0.0f, 0.0f, 5.0f, 5.0f, // align
3749 0.0f, 0.0f, 0.0f, 5.0f, // align
3750 6.0f, 0.0f, 0.0f, 6.0f, // align
3751 0.0f, 6.0f, 0.0f, 6.0f, // align
3752 0.0f, 0.0f, 6.0f, 6.0f, // align
3753 0.0f, 0.0f, 0.0f, 6.0f, // align
3754 7.0f, 0.0f, 0.0f, 7.0f, // align
3755 0.0f, 7.0f, 0.0f, 7.0f, // align
3756 0.0f, 0.0f, 7.0f, 7.0f, // align
3757 0.0f, 0.0f, 0.0f, 7.0f, // align
3758 8.0f, 0.0f, 0.0f, 8.0f, // align
3759 0.0f, 8.0f, 0.0f, 8.0f, // align
3760 0.0f, 0.0f, 8.0f, 8.0f, // align
3761 0.0f, 0.0f, 0.0f, 8.0f, // align
3762 0.0f, // float fZero; // align
3763 1.0f, // float fOne; // pack
3764 2.0f, // float fTwo; // pack
3765 3.0f, // float fThree; // pack
3766 0.0f, 0.0f, 0.0f, // vec3 fZeroZeroZero; // align
3767 4.0f, // float fFour; // pack
3768 0.0f, 0.0f, 1.0f, // vec3 fZeroZeroOne; // align
3769 5.0f, // float fFive; // pack
3770 0.0f, 1.0f, 0.0f, // vec3 fZeroOneZero; // align
3771 6.0f, // float fSix; // pack
3772 7.0f, // float fSeven; // align
3773 8.0f, // float fEight; // pack
3774 9.0f, // float fNine; // pack
3775 0.0f, // BUFFER
3776 0.0f, 0.0f, // vec2 fZeroZero; // align
3777 0.0f, 1.0f, // vec2 fZeroOne; // pack
3778 0.0f, 0.0f, 1.0f, 1.0f, // vec4 fBlue; // align
3779 1.0f, 0.0f, // vec2 fOneZero; // align
3780 1.0f, 1.0f, // vec2 fOneOne; // pack
3781 0.0f, 1.0f, 1.0f, // vec3 fZeroOneOne; // align
3782 10.0f, // float fTen; // pack
3783 11.0f, // float fEleven; // align
3784 12.0f, // float fTwelve; // pack
3785 0.0f, 0.0f, // BUFFER
3786 1.0f, 0.0f, 0.0f, // vec3 fOneZeroZero; // align
3787 0.0f, // BUFFER
3788 0.1f, 0.2f, 0.3f, 0.4f, // vec4 uvOffsets[4];
3789 0.5f, 0.6f, 0.7f, 0.8f, // align
3790 0.9f, 1.0f, 1.1f, 1.2f, // align
3791 1.3f, 1.4f, 1.5f, 1.6f, // align
Cody Northrop475663c2015-04-15 11:19:06 -06003792 };
3793
3794
3795
3796 ASSERT_NO_FATAL_FAILURE(InitState());
3797 ASSERT_NO_FATAL_FAILURE(InitViewport());
3798
3799 const int constCount = sizeof(mixedVals) / sizeof(float);
3800
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003801 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3802 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY_BIT, this);
3803 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northrop475663c2015-04-15 11:19:06 -06003804
3805 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
3806
3807 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003808 pipelineobj.AddColorAttachment();
Cody Northrop475663c2015-04-15 11:19:06 -06003809 pipelineobj.AddShader(&vs);
3810 pipelineobj.AddShader(&gs);
3811 pipelineobj.AddShader(&ps);
3812
3813 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003814 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop475663c2015-04-15 11:19:06 -06003815
3816 VkDescriptorSetObj descriptorSet(m_device);
3817 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
3818
Tony Barbourfe3351b2015-07-28 10:17:20 -06003819 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop475663c2015-04-15 11:19:06 -06003820
3821 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003822 Draw(3, 1, 0, 0);
Cody Northrop475663c2015-04-15 11:19:06 -06003823
3824 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003825 EndCommandBuffer();
3826 QueueCommandBuffer();
Cody Northrop475663c2015-04-15 11:19:06 -06003827
3828 RecordImages(m_renderTargets);
3829}
3830
3831TEST_F(VkRenderTest, GSPositions)
3832{
3833 // This test adds more inputs from the vertex shader and perturbs positions
3834 // Expected result is white triangle with weird positions
3835
3836 static const char *vertShaderText =
3837 "#version 140\n"
3838 "#extension GL_ARB_separate_shader_objects : enable\n"
3839 "#extension GL_ARB_shading_language_420pack : enable\n"
3840
3841 "layout(location = 0) out vec3 out_a;\n"
3842 "layout(location = 1) out vec3 out_b;\n"
3843 "layout(location = 2) out vec3 out_c;\n"
3844
3845 "void main() {\n"
3846
3847 // write a solid color to each
3848 " out_a = vec3(1.0, 0.0, 0.0);\n"
3849 " out_b = vec3(0.0, 1.0, 0.0);\n"
3850 " out_c = vec3(0.0, 0.0, 1.0);\n"
3851
3852 // generic position stuff
3853 " vec2 vertices;\n"
3854 " int vertexSelector = gl_VertexID;\n"
3855 " if (vertexSelector == 0)\n"
3856 " vertices = vec2(-0.5, -0.5);\n"
3857 " else if (vertexSelector == 1)\n"
3858 " vertices = vec2( 0.5, -0.5);\n"
3859 " else if (vertexSelector == 2)\n"
3860 " vertices = vec2( 0.5, 0.5);\n"
3861 " else\n"
3862 " vertices = vec2( 0.0, 0.0);\n"
3863 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3864
3865 "}\n";
3866
3867 static const char *geomShaderText =
3868 "#version 330\n"
3869 "#extension GL_ARB_separate_shader_objects : enable\n"
3870 "#extension GL_ARB_shading_language_420pack : enable\n"
3871 "layout( triangles ) in;\n"
3872 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3873
3874 "layout(location = 0) in vec3 in_a[3];\n"
3875 "layout(location = 1) in vec3 in_b[3];\n"
3876 "layout(location = 2) in vec3 in_c[3];\n"
3877
3878 "layout(location = 0) out vec3 out_a;\n"
3879 "layout(location = 1) out vec3 out_b;\n"
3880 "layout(location = 2) out vec3 out_c;\n"
3881
3882 "void main()\n"
3883 "{\n"
3884
3885 " gl_Position = gl_in[0].gl_Position;\n"
3886 " gl_Position.xy *= vec2(0.75);\n"
3887 " out_a = in_a[0];\n"
3888 " out_b = in_b[0];\n"
3889 " out_c = in_c[0];\n"
3890 " EmitVertex();\n"
3891
3892 " gl_Position = gl_in[1].gl_Position;\n"
3893 " gl_Position.xy *= vec2(1.5);\n"
3894 " out_a = in_a[1];\n"
3895 " out_b = in_b[1];\n"
3896 " out_c = in_c[1];\n"
3897 " EmitVertex();\n"
3898
3899 " gl_Position = gl_in[2].gl_Position;\n"
3900 " gl_Position.xy *= vec2(-0.1);\n"
3901 " out_a = in_a[2];\n"
3902 " out_b = in_b[2];\n"
3903 " out_c = in_c[2];\n"
3904 " EmitVertex();\n"
3905
3906 " EndPrimitive();\n"
3907 "}\n";
3908
3909
3910 static const char *fragShaderText =
3911 "#version 140\n"
3912 "#extension GL_ARB_separate_shader_objects : enable\n"
3913 "#extension GL_ARB_shading_language_420pack : enable\n"
3914
3915 "layout(location = 0) in vec3 in_a;\n"
3916 "layout(location = 1) in vec3 in_b;\n"
3917 "layout(location = 2) in vec3 in_c;\n"
GregFaae75242015-06-03 18:40:50 -06003918 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003919
3920 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06003921 " outColor = vec4(in_a.x, in_b.y, in_c.z, 1.0);\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003922 "}\n";
3923
3924
3925
3926 ASSERT_NO_FATAL_FAILURE(InitState());
3927 ASSERT_NO_FATAL_FAILURE(InitViewport());
3928
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06003929 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3930 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY_BIT, this);
3931 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northrop475663c2015-04-15 11:19:06 -06003932
3933 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003934 pipelineobj.AddColorAttachment();
Cody Northrop475663c2015-04-15 11:19:06 -06003935 pipelineobj.AddShader(&vs);
3936 pipelineobj.AddShader(&gs);
3937 pipelineobj.AddShader(&ps);
3938
3939 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003940 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop475663c2015-04-15 11:19:06 -06003941
3942 VkDescriptorSetObj descriptorSet(m_device);
3943
Tony Barbourfe3351b2015-07-28 10:17:20 -06003944 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop475663c2015-04-15 11:19:06 -06003945
3946 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06003947 Draw(3, 1, 0, 0);
Cody Northrop475663c2015-04-15 11:19:06 -06003948
3949 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003950 EndCommandBuffer();
3951 QueueCommandBuffer();
Cody Northrop475663c2015-04-15 11:19:06 -06003952
3953 RecordImages(m_renderTargets);
3954}
3955
3956TEST_F(VkRenderTest, GSTriStrip)
3957{
3958 // This test emits multiple multiple triangles using a GS
3959 // Correct result is an multicolor circle
3960
3961 static const char *vertShaderText =
3962 "#version 140\n"
3963 "#extension GL_ARB_separate_shader_objects : enable\n"
3964 "#extension GL_ARB_shading_language_420pack : enable\n"
3965
3966 "void main() {\n"
3967
3968 // generic position stuff
3969 " vec2 vertices;\n"
3970 " int vertexSelector = gl_VertexID;\n"
3971 " if (vertexSelector == 0)\n"
3972 " vertices = vec2(-0.5, -0.5);\n"
3973 " else if (vertexSelector == 1)\n"
3974 " vertices = vec2( 0.5, -0.5);\n"
3975 " else if (vertexSelector == 2)\n"
3976 " vertices = vec2( 0.5, 0.5);\n"
3977 " else\n"
3978 " vertices = vec2( 0.0, 0.0);\n"
3979 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3980
3981 "}\n";
3982
3983 static const char *geomShaderText =
3984 "#version 330\n"
3985 "#extension GL_ARB_separate_shader_objects : enable\n"
3986 "#extension GL_ARB_shading_language_420pack : enable\n"
3987 "layout( triangles ) in;\n"
3988 "layout( triangle_strip, max_vertices = 18 ) out;\n"
3989
3990 "layout(location = 0) out vec4 outColor;\n"
3991
3992 "void main()\n"
3993 "{\n"
3994 // init with first position to get zw
3995 " gl_Position = gl_in[0].gl_Position;\n"
3996
3997 " vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3998 " vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
3999 " vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
4000 " vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
4001
4002 // different color per tri
4003 " vec4[6] colors = { red, white, \n"
4004 " yellow, white, \n"
4005 " blue, white }; \n"
4006
4007 // fan out the triangles
4008 " vec2[18] positions = { vec2(0.0, 0.0), vec2(-0.5, 0.0), vec2(-0.25, -0.5), \n"
4009 " vec2(0.0, 0.0), vec2(-0.25, -0.5), vec2( 0.25, -0.5), \n"
4010 " vec2(0.0, 0.0), vec2( 0.25, -0.5), vec2( 0.5, 0.0), \n"
4011 " vec2(0.0, 0.0), vec2( 0.5, 0.0), vec2( 0.25, 0.5), \n"
4012 " vec2(0.0, 0.0), vec2( 0.25, 0.5), vec2(-0.25, 0.5), \n"
4013 " vec2(0.0, 0.0), vec2(-0.25, 0.5), vec2(-0.5, 0.0) }; \n"
4014
4015 // make a triangle list of 6
4016 " for (int i = 0; i < 6; ++i) { \n"
4017 " outColor = colors[i]; \n"
4018 " for (int j = 0; j < 3; ++j) { \n"
4019 " gl_Position.xy = positions[i * 3 + j]; \n"
4020 " EmitVertex(); \n"
4021 " } \n"
4022 " EndPrimitive();\n"
4023 " } \n"
4024
4025 "}\n";
4026
4027
4028 static const char *fragShaderText =
4029 "#version 150\n"
4030 "#extension GL_ARB_separate_shader_objects : enable\n"
4031 "#extension GL_ARB_shading_language_420pack : enable\n"
4032
4033
4034 "layout(binding = 0) uniform windowDimensions {\n"
4035 " vec4 dimensions;\n"
4036 "};\n"
4037
4038 "layout(location = 0) in vec4 inColor;\n"
4039 "layout(origin_upper_left) in vec4 gl_FragCoord;\n"
GregFaae75242015-06-03 18:40:50 -06004040 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06004041
4042 "void main() {\n"
4043
4044 // discard to make a nice circle
4045 " vec2 pos = abs(gl_FragCoord.xy) - vec2(dimensions.x, dimensions.y) / 2;\n"
4046 " float dist = sqrt(dot(pos, pos));\n"
4047 " if (dist > 50.0)\n"
4048 " discard;\n"
4049
GregFaae75242015-06-03 18:40:50 -06004050 " outColor = inColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06004051
4052 "}\n";
4053
4054
4055
4056 ASSERT_NO_FATAL_FAILURE(InitState());
4057 ASSERT_NO_FATAL_FAILURE(InitViewport());
4058
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004059 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4060 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY_BIT, this);
4061 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northrop475663c2015-04-15 11:19:06 -06004062
4063 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004064 pipelineobj.AddColorAttachment();
Cody Northrop475663c2015-04-15 11:19:06 -06004065 pipelineobj.AddShader(&vs);
4066 pipelineobj.AddShader(&gs);
4067 pipelineobj.AddShader(&ps);
4068
4069 const float dimensions[4] = { VkRenderFramework::m_width, VkRenderFramework::m_height , 0.0, 0.0};
4070
4071 VkConstantBufferObj windowDimensions(m_device, sizeof(dimensions) / sizeof(dimensions[0]), sizeof(dimensions[0]), (const void*) dimensions);
4072
4073 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004074 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop475663c2015-04-15 11:19:06 -06004075
4076 VkDescriptorSetObj descriptorSet(m_device);
4077 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, windowDimensions);
4078
Tony Barbourfe3351b2015-07-28 10:17:20 -06004079 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop475663c2015-04-15 11:19:06 -06004080
4081 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06004082 Draw(3, 1, 0, 0);
Cody Northrop475663c2015-04-15 11:19:06 -06004083
4084 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06004085 EndCommandBuffer();
4086 QueueCommandBuffer();
Cody Northrop475663c2015-04-15 11:19:06 -06004087
4088 RecordImages(m_renderTargets);
4089}
4090
Chris Forbese182fe02015-06-15 09:32:35 +12004091TEST_F(VkRenderTest, RenderPassLoadOpClear)
4092{
4093 ASSERT_NO_FATAL_FAILURE(InitState());
4094 ASSERT_NO_FATAL_FAILURE(InitViewport());
4095
4096 /* clear via load op to full green */
4097 m_clear_via_load_op = true;
Cody Northrop85789d52015-08-25 15:26:38 -06004098 m_clear_color.float32[0] = 0;
4099 m_clear_color.float32[1] = 1;
4100 m_clear_color.float32[2] = 0;
4101 m_clear_color.float32[3] = 0;
Chris Forbese182fe02015-06-15 09:32:35 +12004102 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004103 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Chris Forbese182fe02015-06-15 09:32:35 +12004104 /* This command buffer contains ONLY the load op! */
Tony Barbourfe3351b2015-07-28 10:17:20 -06004105 EndCommandBuffer();
4106 QueueCommandBuffer();
Chris Forbese182fe02015-06-15 09:32:35 +12004107
4108 RecordImages(m_renderTargets);
4109}
4110
Chris Forbesfa27b952015-06-24 12:05:30 +12004111TEST_F(VkRenderTest, RenderPassAttachmentClear)
4112{
4113 ASSERT_NO_FATAL_FAILURE(InitState());
4114 ASSERT_NO_FATAL_FAILURE(InitViewport());
4115
4116 /* clear via load op to full red */
4117 m_clear_via_load_op = true;
Cody Northrop85789d52015-08-25 15:26:38 -06004118 m_clear_color.float32[0] = 1;
4119 m_clear_color.float32[1] = 0;
4120 m_clear_color.float32[2] = 0;
4121 m_clear_color.float32[3] = 0;
Chris Forbesfa27b952015-06-24 12:05:30 +12004122 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004123 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Chris Forbesfa27b952015-06-24 12:05:30 +12004124
4125 /* Load op has cleared to red */
4126
4127 /* Draw, draw, draw... */
4128
4129 /* Now, partway through this renderpass we want to clear the color
4130 * attachment again, this time to green.
4131 */
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004132 VkClearAttachment color_attachment;
4133 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4134 color_attachment.clearValue.color.float32[0] = 0;
4135 color_attachment.clearValue.color.float32[1] = 1;
4136 color_attachment.clearValue.color.float32[2] = 0;
4137 color_attachment.clearValue.color.float32[3] = 0;
4138 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -06004139 VkClearRect clear_rect = { { { 0, 0 }, { (int)m_width, (int)m_height } } };
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004140 vkCmdClearAttachments(m_cmdBuffer->handle(), 1, &color_attachment,
4141 1, &clear_rect);
Chris Forbesfa27b952015-06-24 12:05:30 +12004142
Tony Barbourfe3351b2015-07-28 10:17:20 -06004143 EndCommandBuffer();
4144 QueueCommandBuffer();
Chris Forbesfa27b952015-06-24 12:05:30 +12004145
4146 RecordImages(m_renderTargets);
4147}
4148
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06004149int main(int argc, char **argv) {
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004150 int result;
4151
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06004152 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -06004153 VkTestFramework::InitArgs(&argc, argv);
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004154
Chia-I Wu6f184292014-12-15 23:57:34 +08004155 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchtera0f74c52014-10-08 08:46:51 -06004156
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004157 result = RUN_ALL_TESTS();
4158
Tony Barbour6918cd52015-04-09 12:58:51 -06004159 VkTestFramework::Finish();
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004160 return result;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06004161}