blob: e2766d0136047e6558394de0a3046ca44f87a58c [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 Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060073#include "gtest-1.7.0/include/gtest/gtest.h"
74
Cody Northrop054a4702015-03-17 14:54:35 -060075#include "icd-spv.h"
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060076
Courtney Goeltzenleuchterfdcfb9f2014-10-10 18:04:39 -060077#define GLM_FORCE_RADIANS
78#include "glm/glm.hpp"
79#include <glm/gtc/matrix_transform.hpp>
80
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060081#include "vkrenderframework.h"
Tobin Ehlis6663f492014-11-10 12:29:12 -070082#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060083void VKAPI myDbgFunc(
84 VK_DBG_MSG_TYPE msgType,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060085 VkValidationLevel validationLevel,
Mike Stroyanb050c682015-04-17 12:36:38 -060086 VkObject srcObject,
Mark Lobodzinski17caf572015-01-29 08:55:56 -060087 size_t location,
88 int32_t msgCode,
89 const char* pMsg,
90 void* pUserData)
Tobin Ehlis6663f492014-11-10 12:29:12 -070091{
Tobin Ehlisca915872014-11-18 11:28:33 -070092 switch (msgType)
93 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060094 case VK_DBG_MSG_WARNING:
Tobin Ehlisca915872014-11-18 11:28:33 -070095 printf("CALLBACK WARNING : %s\n", pMsg);
96 break;
Courtney 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); }
283 void Draw(uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount)
284 { m_cmdBuffer->Draw(firstVertex, vertexCount, firstInstance, instanceCount); }
285 void DrawIndexed(uint32_t firstVertex, uint32_t vertexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount)
286 { m_cmdBuffer->DrawIndexed(firstVertex, vertexCount, vertexOffset,firstInstance, instanceCount); }
287 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;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800301 VkDescriptorInfo m_descriptorInfo;
Tony Barbourd1c35722015-04-16 15:59:00 -0600302 VkDeviceMemory m_textureMem;
Cody Northrop7d2035d2014-10-06 15:42:00 -0600303
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600304 VkSampler m_sampler;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600305
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600306
307 virtual void SetUp() {
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600308
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600309 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600310 this->app_info.pNext = NULL;
Chia-I Wuf1a5a742014-12-27 15:16:07 +0800311 this->app_info.pAppName = "render_tests";
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600312 this->app_info.appVersion = 1;
Chia-I Wuf1a5a742014-12-27 15:16:07 +0800313 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600314 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600315 this->app_info.apiVersion = VK_API_VERSION;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600316
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800317 memset(&m_descriptorInfo, 0, sizeof(m_descriptorInfo));
Cody Northrop7d2035d2014-10-06 15:42:00 -0600318
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600319 InitFramework();
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600320 }
321
322 virtual void TearDown() {
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600323 // Clean up resources before we reset
324 ShutdownFramework();
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600325 }
326};
327
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600328VkResult VkRenderTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600329{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600330 VkResult result;
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600331
332 result = cmdBuffer.BeginCommandBuffer();
333
334 /*
335 * For render test all drawing happens in a single render pass
336 * on a single command buffer.
337 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200338 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu08accc62015-07-07 11:50:03 +0800339 cmdBuffer.BeginRenderPass(renderPassBeginInfo());
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600340 }
341
342 return result;
343}
344
Tobin Ehlisf1878c72015-08-18 14:24:32 -0600345VkResult VkRenderTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer, VkCmdBufferBeginInfo *beginInfo)
346{
347 VkResult result;
348
349 result = cmdBuffer.BeginCommandBuffer(beginInfo);
350
351 /*
352 * For render test all drawing happens in a single render pass
353 * on a single command buffer.
354 */
355 if (VK_SUCCESS == result && renderPass()) {
356 cmdBuffer.BeginRenderPass(renderPassBeginInfo());
357 }
358
359 return result;
360}
361
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600362VkResult VkRenderTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600363{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600364 VkResult result;
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600365
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200366 if (renderPass()) {
Chia-I Wu0b50a1c2015-06-26 15:34:39 +0800367 cmdBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200368 }
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600369
370 result = cmdBuffer.EndCommandBuffer();
371
372 return result;
373}
374
375
Tony Barbour6918cd52015-04-09 12:58:51 -0600376void VkRenderTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet)
Tony Barbour22e32a12015-01-08 17:08:28 -0700377{
Tony Barbour71bd4b32015-07-21 17:00:26 -0600378 if (!m_clear_via_load_op) {
379 if (m_depthStencil->Initialized()) {
380 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
381 } else {
382 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
383 }
Tony Barbour1c45ce02015-03-27 17:03:18 -0600384 }
385
Jeremy Hayesd65ae082015-01-14 16:17:08 -0700386 cmdBuffer->PrepareAttachments();
Tony Barbour67e99152015-07-10 14:10:27 -0600387 cmdBuffer->BindDynamicRasterState(m_stateRaster);
388 cmdBuffer->BindDynamicViewportState(m_stateViewport);
389 cmdBuffer->BindDynamicColorBlendState(m_colorBlend);
390 cmdBuffer->BindDynamicDepthStencilState(m_stateDepthStencil);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600391 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
Tony Barbour5781e8f2015-08-04 16:23:11 -0600392 pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600393 cmdBuffer->BindPipeline(pipelineobj);
Chia-I Wu53f07d72015-03-28 15:23:55 +0800394 cmdBuffer->BindDescriptorSet(descriptorSet);
Tony Barbour22e32a12015-01-08 17:08:28 -0700395}
Tony Barboure2c58df2014-11-25 13:18:32 -0700396
Tony Barbour6918cd52015-04-09 12:58:51 -0600397void VkRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
398 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer)
Tony Barbour664accc2015-01-09 12:55:14 -0700399{
400 int i;
401 glm::mat4 MVP;
402 int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600403 VkResult err;
Tony Barbour664accc2015-01-09 12:55:14 -0700404
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600405 /* Only do 3 positions to avoid back face cull */
406 for (i = 0; i < 3; i++) {
Chia-I Wu681d7a02015-07-03 13:44:34 +0800407 void *pData = constantBuffer->memory().map();
Tony Barbour664accc2015-01-09 12:55:14 -0700408
409 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
410 MVP = Projection * View * Model;
411 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
412
Chia-I Wu681d7a02015-07-03 13:44:34 +0800413 constantBuffer->memory().unmap();
Tony Barbour664accc2015-01-09 12:55:14 -0700414
415 // submit the command buffer to the universal queue
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600416 cmdBuffer->QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -0700417
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600418 err = vkQueueWaitIdle( m_device->m_queue );
419 ASSERT_VK_SUCCESS( err );
Tony Barbour664accc2015-01-09 12:55:14 -0700420
421 // Wait for work to finish before cleaning up.
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600422 vkDeviceWaitIdle(m_device->device());
Tony Barbour664accc2015-01-09 12:55:14 -0700423
Courtney Goeltzenleuchterb4337c12015-03-05 16:47:18 -0700424 assert(m_renderTargets.size() == 1);
Tony Barbour664accc2015-01-09 12:55:14 -0700425 RecordImage(m_renderTargets[0]);
426 }
427}
Courtney Goeltzenleuchterc55471f2014-10-13 13:03:31 -0600428
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600429void dumpMatrix(const char *note, glm::mat4 MVP)
430{
Chia-I Wu6f184292014-12-15 23:57:34 +0800431 int i;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600432
433 printf("%s: \n", note);
434 for (i=0; i<4; i++) {
435 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
436 }
437 printf("\n");
438 fflush(stdout);
439}
440
441void dumpVec4(const char *note, glm::vec4 vector)
442{
443 printf("%s: \n", note);
444 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
445 printf("\n");
446 fflush(stdout);
447}
448
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600449struct vktriangle_vs_uniform {
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600450 // Must start with MVP
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600451 float mvp[4][4];
452 float position[3][4];
453 float color[3][4];
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600454};
455
Tony Barbour6918cd52015-04-09 12:58:51 -0600456void VkRenderTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600457{
Tobin Ehlis6663f492014-11-10 12:29:12 -0700458#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600459 vkDbgRegisterMsgCallback(inst, myDbgFunc, NULL);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700460#endif
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600461 // Create identity matrix
462 int i;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600463 struct vktriangle_vs_uniform data;
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600464
465 glm::mat4 Projection = glm::mat4(1.0f);
466 glm::mat4 View = glm::mat4(1.0f);
467 glm::mat4 Model = glm::mat4(1.0f);
468 glm::mat4 MVP = Projection * View * Model;
469 const int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600470 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600471 memcpy(&data.mvp, &MVP[0][0], matrixSize);
472
473 static const Vertex tri_data[] =
474 {
475 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
476 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
477 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
478 };
479
480 for (i=0; i<3; i++) {
481 data.position[i][0] = tri_data[i].posX;
482 data.position[i][1] = tri_data[i].posY;
483 data.position[i][2] = tri_data[i].posZ;
484 data.position[i][3] = tri_data[i].posW;
485 data.color[i][0] = tri_data[i].r;
486 data.color[i][1] = tri_data[i].g;
487 data.color[i][2] = tri_data[i].b;
488 data.color[i][3] = tri_data[i].a;
489 }
490
Tony Barboure2c58df2014-11-25 13:18:32 -0700491 ASSERT_NO_FATAL_FAILURE(InitState());
492 ASSERT_NO_FATAL_FAILURE(InitViewport());
493
Tony Barbour6918cd52015-04-09 12:58:51 -0600494 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barboure2c58df2014-11-25 13:18:32 -0700495
Tony Barbour6918cd52015-04-09 12:58:51 -0600496 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
497 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -0700498
Tony Barbour6918cd52015-04-09 12:58:51 -0600499 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800500 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -0700501 pipelineobj.AddShader(&vs);
502 pipelineobj.AddShader(&ps);
503
Tony Barbour6918cd52015-04-09 12:58:51 -0600504 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600505 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -0700506
Tony Barbourd726a172015-01-09 16:12:35 -0700507 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf1878c72015-08-18 14:24:32 -0600508
509 VkCmdBufferBeginInfo cbBeginInfo;
510 memset(&cbBeginInfo, 0, sizeof(VkCmdBufferBeginInfo));
511 cbBeginInfo.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
512 cbBeginInfo.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT;
513 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barboure2c58df2014-11-25 13:18:32 -0700514
Tony Barbourfe3351b2015-07-28 10:17:20 -0600515 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourd726a172015-01-09 16:12:35 -0700516#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600517 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourd726a172015-01-09 16:12:35 -0700518 pDSDumpDot((char*)"triTest2.dot");
519#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600520
Tony Barbourd726a172015-01-09 16:12:35 -0700521 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -0600522 Draw(0, 3, 0, 1);
Tony Barbourd726a172015-01-09 16:12:35 -0700523
524 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600525 ASSERT_VK_SUCCESS(EndCommandBuffer());
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600526
Tony Barbourfe3351b2015-07-28 10:17:20 -0600527 QueueCommandBuffer();
Tony Barbourd726a172015-01-09 16:12:35 -0700528
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600529 RecordImages(m_renderTargets);
Tony Barbourd726a172015-01-09 16:12:35 -0700530
531 if (rotate)
Tony Barbourfe3351b2015-07-28 10:17:20 -0600532 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer);
Tony Barbourd726a172015-01-09 16:12:35 -0700533
Tobin Ehlisca915872014-11-18 11:28:33 -0700534#ifdef PRINT_OBJECTS
Mark Lobodzinski7c75b852015-05-05 15:01:37 -0500535 OBJ_TRACK_GET_OBJECTS_COUNT pObjTrackGetObjectsCount = (OBJ_TRACK_GET_OBJECTS_COUNT)vkGetProcAddr(gpu(), (char*)"objTrackGetObjectsCount");
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600536 uint64_t numObjects = pObjTrackGetObjectsCount(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600537 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlisca915872014-11-18 11:28:33 -0700538 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600539 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlisca915872014-11-18 11:28:33 -0700540 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600541 pObjTrackGetObjs(m_device, numObjects, pObjNodeArray);
Tobin Ehlisca915872014-11-18 11:28:33 -0700542 for (i=0; i < numObjects; i++) {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600543 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 -0700544 }
545 free(pObjNodeArray);
546#endif
Tony Barboure2c58df2014-11-25 13:18:32 -0700547
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600548}
549
Tony Barbour6918cd52015-04-09 12:58:51 -0600550TEST_F(VkRenderTest, VKTriangle_FragColor)
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600551{
552 static const char *vertShaderText =
553 "#version 140\n"
554 "#extension GL_ARB_separate_shader_objects : enable\n"
555 "#extension GL_ARB_shading_language_420pack : enable\n"
556 "\n"
557 "layout(binding = 0) uniform buf {\n"
558 " mat4 MVP;\n"
559 " vec4 position[3];\n"
560 " vec4 color[3];\n"
561 "} ubuf;\n"
562 "\n"
563 "layout (location = 0) out vec4 outColor;\n"
564 "\n"
565 "void main() \n"
566 "{\n"
567 " outColor = ubuf.color[gl_VertexID];\n"
568 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
569 "}\n";
570
571 static const char *fragShaderText =
572 "#version 140\n"
573 "#extension GL_ARB_separate_shader_objects : enable\n"
574 "#extension GL_ARB_shading_language_420pack : enable\n"
575 "\n"
576 "layout (location = 0) in vec4 inColor;\n"
GregFaae75242015-06-03 18:40:50 -0600577 "layout (location = 0) out vec4 uFragColor;\n"
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600578 "\n"
579 "void main()\n"
580 "{\n"
GregFaae75242015-06-03 18:40:50 -0600581 " uFragColor = inColor;\n"
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600582 "}\n";
583
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600584 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
585 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600586}
587
Tony Barbour6918cd52015-04-09 12:58:51 -0600588TEST_F(VkRenderTest, VKTriangle_OutputLocation)
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600589{
590 static const char *vertShaderText =
591 "#version 140\n"
592 "#extension GL_ARB_separate_shader_objects : enable\n"
593 "#extension GL_ARB_shading_language_420pack : enable\n"
594 "\n"
595 "layout(binding = 0) uniform buf {\n"
596 " mat4 MVP;\n"
597 " vec4 position[3];\n"
598 " vec4 color[3];\n"
599 "} ubuf;\n"
600 "\n"
601 "layout (location = 0) out vec4 outColor;\n"
602 "\n"
603 "void main() \n"
604 "{\n"
605 " outColor = ubuf.color[gl_VertexID];\n"
606 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
607 "}\n";
608
609 static const char *fragShaderText =
610 "#version 140\n"
611 "#extension GL_ARB_separate_shader_objects : enable\n"
612 "#extension GL_ARB_shading_language_420pack : enable\n"
613 "\n"
614 "layout (location = 0) in vec4 inColor;\n"
615 "layout (location = 0) out vec4 outColor;\n"
616 "\n"
617 "void main()\n"
618 "{\n"
619 " outColor = inColor;\n"
620 "}\n";
621
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600622 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 -0600623
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600624 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600625}
Cody Northrop6922da12015-06-23 13:25:51 -0600626
Tony Barbour6918cd52015-04-09 12:58:51 -0600627TEST_F(VkRenderTest, SPV_VKTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -0700628{
Tony Barboure2c58df2014-11-25 13:18:32 -0700629 static const char *vertShaderText =
630 "#version 140\n"
631 "#extension GL_ARB_separate_shader_objects : enable\n"
632 "#extension GL_ARB_shading_language_420pack : enable\n"
633 "\n"
634 "layout(binding = 0) uniform buf {\n"
635 " mat4 MVP;\n"
636 " vec4 position[3];\n"
637 " vec4 color[3];\n"
638 "} ubuf;\n"
639 "\n"
640 "layout (location = 0) out vec4 outColor;\n"
641 "\n"
642 "void main() \n"
643 "{\n"
644 " outColor = ubuf.color[gl_VertexID];\n"
645 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
646 "}\n";
647
648 static const char *fragShaderText =
649 "#version 140\n"
650 "#extension GL_ARB_separate_shader_objects : enable\n"
651 "#extension GL_ARB_shading_language_420pack : enable\n"
652 "\n"
653 "layout (location = 0) in vec4 inColor;\n"
GregFaae75242015-06-03 18:40:50 -0600654 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700655 "\n"
656 "void main()\n"
657 "{\n"
GregFaae75242015-06-03 18:40:50 -0600658 " outColor = inColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700659 "}\n";
660
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600661 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 -0700662
Cody Northrop50a2a4b2015-06-03 16:49:20 -0600663 ScopedUseGlsl useGlsl(false);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600664 VKTriangleTest(vertShaderText, fragShaderText, true);
Tony Barboure2c58df2014-11-25 13:18:32 -0700665}
Courtney Goeltzenleuchter538062a2014-10-09 15:40:19 -0600666
Tony Barbour6918cd52015-04-09 12:58:51 -0600667TEST_F(VkRenderTest, SPV_GreenTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -0700668{
Tony Barboure2c58df2014-11-25 13:18:32 -0700669 static const char *vertShaderText =
670 "#version 130\n"
671 "vec2 vertices[3];\n"
672 "void main() {\n"
673 " vertices[0] = vec2(-1.0, -1.0);\n"
674 " vertices[1] = vec2( 1.0, -1.0);\n"
675 " vertices[2] = vec2( 0.0, 1.0);\n"
676 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
677 "}\n";
678
679 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -0600680 "#version 140\n"
681 "#extension GL_ARB_separate_shader_objects : enable\n"
682 "#extension GL_ARB_shading_language_420pack : enable\n"
683 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700684 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600685 " outColor = vec4(0,1,0,1);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700686 "}\n";
687
Cody Northrop3bfd27c2015-03-17 15:55:58 -0600688 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barboure2c58df2014-11-25 13:18:32 -0700689
Cody Northrop50a2a4b2015-06-03 16:49:20 -0600690 ScopedUseGlsl useGlsl(false);
691
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600692 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barboure2c58df2014-11-25 13:18:32 -0700693}
Cody Northrop6922da12015-06-23 13:25:51 -0600694
Tony Barbour6918cd52015-04-09 12:58:51 -0600695TEST_F(VkRenderTest, YellowTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -0700696{
697 static const char *vertShaderText =
698 "#version 130\n"
699 "void main() {\n"
700 " vec2 vertices[3];"
701 " vertices[0] = vec2(-0.5, -0.5);\n"
702 " vertices[1] = vec2( 0.5, -0.5);\n"
703 " vertices[2] = vec2( 0.5, 0.5);\n"
704 " vec4 colors[3];\n"
705 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
706 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
707 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
708 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
709 "}\n";
710
711 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -0600712 "#version 140\n"
713 "#extension GL_ARB_separate_shader_objects : enable\n"
714 "#extension GL_ARB_shading_language_420pack : enable\n"
715 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700716 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600717 " outColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700718 "}\n";
719
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600720 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barboure2c58df2014-11-25 13:18:32 -0700721}
722
Tony Barbour6918cd52015-04-09 12:58:51 -0600723TEST_F(VkRenderTest, QuadWithVertexFetch)
Cody Northropee6586d2014-10-09 19:55:56 -0600724{
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600725 static const char *vertShaderText =
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600726 "#version 140\n"
727 "#extension GL_ARB_separate_shader_objects : enable\n"
728 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700729 //XYZ1( -1, -1, -1 )
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600730 "layout (location = 0) in vec4 pos;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700731 //XYZ1( 0.f, 0.f, 0.f )
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600732 "layout (location = 1) in vec4 inColor;\n"
733 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600734 "void main() {\n"
Cody Northrop66594a72014-10-10 14:49:36 -0600735 " outColor = inColor;\n"
Cody Northrop7ad4aaf2014-10-09 21:25:22 -0600736 " gl_Position = pos;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600737 "}\n";
738
Cody Northropee6586d2014-10-09 19:55:56 -0600739
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600740 static const char *fragShaderText =
Cody Northropd43c52e2014-12-05 15:44:14 -0700741 "#version 140\n"
742 "#extension GL_ARB_separate_shader_objects : enable\n"
743 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600744 "layout (location = 0) in vec4 color;\n"
Cody Northropd43c52e2014-12-05 15:44:14 -0700745 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600746 "void main() {\n"
Cody Northropd43c52e2014-12-05 15:44:14 -0700747 " outColor = color;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600748 "}\n";
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600749
Tony Barboure2c58df2014-11-25 13:18:32 -0700750
751
752 ASSERT_NO_FATAL_FAILURE(InitState());
753 ASSERT_NO_FATAL_FAILURE(InitViewport());
754
Tony Barbour6918cd52015-04-09 12:58:51 -0600755 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000756 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -0700757
Tony Barbour6918cd52015-04-09 12:58:51 -0600758 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
759 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -0700760
Tony Barbour6918cd52015-04-09 12:58:51 -0600761 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800762 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -0700763 pipelineobj.AddShader(&vs);
764 pipelineobj.AddShader(&ps);
765
Tony Barbour6918cd52015-04-09 12:58:51 -0600766 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600767 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -0600768
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600769#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600770 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600771 MESH_BIND_ID, // binding ID
Tony Barboure2c58df2014-11-25 13:18:32 -0700772 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600773 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barboure2c58df2014-11-25 13:18:32 -0700774 };
775
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600776 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600777 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
778 vi_attribs[0].location = 0; // location, position
Tony Barbourd1c35722015-04-16 15:59:00 -0600779 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600780 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
781 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
782 vi_attribs[1].location = 1; // location, color
Tony Barbourd1c35722015-04-16 15:59:00 -0600783 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600784 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 -0700785
786 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
787 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600788 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barboure2c58df2014-11-25 13:18:32 -0700789
Tony Barbour1fde6942015-01-09 10:06:53 -0700790 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600791 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure2c58df2014-11-25 13:18:32 -0700792
Tony Barbourfe3351b2015-07-28 10:17:20 -0600793 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600794
Tony Barbourfe3351b2015-07-28 10:17:20 -0600795 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour1fde6942015-01-09 10:06:53 -0700796
797 // render two triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -0600798 Draw(0, 6, 0, 1);
Tony Barbour1fde6942015-01-09 10:06:53 -0700799
800 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600801 ASSERT_VK_SUCCESS(EndCommandBuffer());
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600802
Tony Barbourfe3351b2015-07-28 10:17:20 -0600803 QueueCommandBuffer();
Tony Barbour1fde6942015-01-09 10:06:53 -0700804
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600805 RecordImages(m_renderTargets);
Tobin Ehlisd806c8e2014-10-07 14:41:29 -0600806}
807
Tony Barbour6918cd52015-04-09 12:58:51 -0600808TEST_F(VkRenderTest, TriangleMRT)
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800809{
810 static const char *vertShaderText =
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600811 "#version 140\n"
812 "#extension GL_ARB_separate_shader_objects : enable\n"
813 "#extension GL_ARB_shading_language_420pack : enable\n"
814 "layout (location = 0) in vec4 pos;\n"
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800815 "void main() {\n"
816 " gl_Position = pos;\n"
817 "}\n";
818
819 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -0600820 "#version 140\n"
821 "#extension GL_ARB_separate_shader_objects : enable\n"
822 "#extension GL_ARB_shading_language_420pack : enable\n"
823 "layout (location = 0) out vec4 uFragData0;\n"
824 "layout (location = 1) out vec4 uFragData1;\n"
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800825 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600826 " uFragData0 = vec4(1.0, 0.0, 0.0, 1.0);\n"
827 " uFragData1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800828 "}\n";
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600829 const float vb_data[][2] = {
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800830 { -1.0f, -1.0f },
831 { 1.0f, -1.0f },
832 { -1.0f, 1.0f }
833 };
834
835 ASSERT_NO_FATAL_FAILURE(InitState());
836 ASSERT_NO_FATAL_FAILURE(InitViewport());
837
Tony Barbour6918cd52015-04-09 12:58:51 -0600838 VkConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000839 meshBuffer.BufferMemoryBarrier();
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800840
Tony Barbour6918cd52015-04-09 12:58:51 -0600841 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
842 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800843
Tony Barbour6918cd52015-04-09 12:58:51 -0600844 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800845 pipelineobj.AddColorAttachment();
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800846 pipelineobj.AddShader(&vs);
847 pipelineobj.AddShader(&ps);
848
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600849#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600850 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600851 MESH_BUF_ID, // Binding ID
852 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600853 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800854 };
855
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600856 VkVertexInputAttributeDescription vi_attrib;
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600857 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
858 vi_attrib.location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -0600859 vi_attrib.format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600860 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800861
862 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
863 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600864 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800865
Tony Barbour6918cd52015-04-09 12:58:51 -0600866 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600867 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800868
Courtney Goeltzenleuchterb4337c12015-03-05 16:47:18 -0700869 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800870
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600871 VkPipelineColorBlendAttachmentState att = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600872 att.blendEnable = VK_FALSE;
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800873 att.channelWriteMask = 0xf;
Tony Barbourf52346d2015-01-16 14:27:35 -0700874 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800875
Tony Barbourfe3351b2015-07-28 10:17:20 -0600876 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour1fde6942015-01-09 10:06:53 -0700877
Tony Barbourfe3351b2015-07-28 10:17:20 -0600878 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour1fde6942015-01-09 10:06:53 -0700879
Tony Barbourfe3351b2015-07-28 10:17:20 -0600880 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour304ec8b2015-01-07 14:31:52 -0700881#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600882 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour304ec8b2015-01-07 14:31:52 -0700883 pDSDumpDot((char*)"triTest2.dot");
884#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600885
Tony Barbour304ec8b2015-01-07 14:31:52 -0700886 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -0600887 Draw(0, 3, 0, 1);
Tony Barbour304ec8b2015-01-07 14:31:52 -0700888
889 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600890 ASSERT_VK_SUCCESS(EndCommandBuffer());
891 QueueCommandBuffer();
Tony Barbour304ec8b2015-01-07 14:31:52 -0700892
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600893 RecordImages(m_renderTargets);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800894}
895
Tony Barbour6918cd52015-04-09 12:58:51 -0600896TEST_F(VkRenderTest, QuadWithIndexedVertexFetch)
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700897{
898 static const char *vertShaderText =
899 "#version 140\n"
900 "#extension GL_ARB_separate_shader_objects : enable\n"
901 "#extension GL_ARB_shading_language_420pack : enable\n"
902 "layout(location = 0) in vec4 pos;\n"
903 "layout(location = 1) in vec4 inColor;\n"
904 "layout(location = 0) out vec4 outColor;\n"
905 "void main() {\n"
906 " outColor = inColor;\n"
907 " gl_Position = pos;\n"
908 "}\n";
909
910
911 static const char *fragShaderText =
912 "#version 140\n"
913 "#extension GL_ARB_separate_shader_objects : enable\n"
914 "#extension GL_ARB_shading_language_420pack : enable\n"
915 "layout(location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -0600916 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700917 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600918 " outColor = color;\n"
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700919 "}\n";
920
921 const Vertex g_vbData[] =
922 {
923 // first tri
924 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
925 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
926 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
927
928 // second tri
929 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
930 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
931 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
932 };
933
934 const uint16_t g_idxData[6] = {
935 0, 1, 2,
936 3, 4, 5,
937 };
938
939 ASSERT_NO_FATAL_FAILURE(InitState());
940 ASSERT_NO_FATAL_FAILURE(InitViewport());
941
Tony Barbour6918cd52015-04-09 12:58:51 -0600942 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000943 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700944
Tony Barbour6918cd52015-04-09 12:58:51 -0600945 VkIndexBufferObj indexBuffer(m_device);
Tony Barbourd1c35722015-04-16 15:59:00 -0600946 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), VK_INDEX_TYPE_UINT16, g_idxData);
Mark Lobodzinski49a6b4b2015-02-16 14:24:23 -0600947 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700948
Tony Barbour6918cd52015-04-09 12:58:51 -0600949 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
950 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700951
Tony Barbour6918cd52015-04-09 12:58:51 -0600952 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800953 pipelineobj.AddColorAttachment();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700954 pipelineobj.AddShader(&vs);
955 pipelineobj.AddShader(&ps);
956
Tony Barbour6918cd52015-04-09 12:58:51 -0600957 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600958 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
959 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, indexBuffer);
Tony Barbour831062d2015-04-02 15:43:15 -0600960
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700961
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600962#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600963 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600964 MESH_BIND_ID, // binding ID
965 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600966 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700967 };
968
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600969 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600970 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
971 vi_attribs[0].location = 0; // layout location of vertex attribute
Tony Barbourd1c35722015-04-16 15:59:00 -0600972 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600973 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
974 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
975 vi_attribs[1].location = 1; // layout location of vertex attribute
Tony Barbourd1c35722015-04-16 15:59:00 -0600976 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600977 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700978
979 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
980 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700981
982 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600983 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour1fde6942015-01-09 10:06:53 -0700984
Tony Barbourfe3351b2015-07-28 10:17:20 -0600985 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700986
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700987#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600988 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlisf27eba72014-12-16 17:34:50 -0700989 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700990#endif
Tony Barbour22e32a12015-01-08 17:08:28 -0700991
Tony Barbourfe3351b2015-07-28 10:17:20 -0600992 BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
993 BindIndexBuffer(&indexBuffer, 0);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700994
995 // render two triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -0600996 DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700997
998 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600999 ASSERT_VK_SUCCESS(EndCommandBuffer());
1000 QueueCommandBuffer();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001001
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001002 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001003}
1004
Tony Barbour6918cd52015-04-09 12:58:51 -06001005TEST_F(VkRenderTest, GreyandRedCirclesonBlue)
GregF3156cb02014-12-02 15:41:44 -07001006{
1007 // This tests gl_FragCoord
Tony Barboure2c58df2014-11-25 13:18:32 -07001008
GregF3156cb02014-12-02 15:41:44 -07001009 static const char *vertShaderText =
1010 "#version 140\n"
1011 "#extension GL_ARB_separate_shader_objects : enable\n"
1012 "#extension GL_ARB_shading_language_420pack : enable\n"
1013 "layout (location = 0) in vec4 pos;\n"
1014 "layout (location = 0) out vec4 outColor;\n"
1015 "layout (location = 1) out vec4 outColor2;\n"
1016 "void main() {\n"
1017 " gl_Position = pos;\n"
1018 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1019 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1020 "}\n";
1021
1022 static const char *fragShaderText =
GregF3156cb02014-12-02 15:41:44 -07001023 "#version 330\n"
1024 "#extension GL_ARB_separate_shader_objects : enable\n"
1025 "#extension GL_ARB_shading_language_420pack : enable\n"
1026 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1027 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1028 "layout (location = 0) in vec4 color;\n"
1029 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001030 "layout (location = 0) out vec4 outColor;\n"
GregF3156cb02014-12-02 15:41:44 -07001031 "void main() {\n"
1032 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1033 " float dist_squared = dot(pos, pos);\n"
GregFaae75242015-06-03 18:40:50 -06001034 " outColor = (dist_squared < 400.0)\n"
GregF3156cb02014-12-02 15:41:44 -07001035 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1036 " : color2;\n"
1037 "}\n";
1038
1039 ASSERT_NO_FATAL_FAILURE(InitState());
1040 ASSERT_NO_FATAL_FAILURE(InitViewport());
1041
Tony Barbour6918cd52015-04-09 12:58:51 -06001042 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001043 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001044
Tony Barbour6918cd52015-04-09 12:58:51 -06001045 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1046 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF3156cb02014-12-02 15:41:44 -07001047
Tony Barbour6918cd52015-04-09 12:58:51 -06001048 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001049 pipelineobj.AddColorAttachment();
GregF3156cb02014-12-02 15:41:44 -07001050 pipelineobj.AddShader(&vs);
1051 pipelineobj.AddShader(&ps);
1052
Tony Barbour6918cd52015-04-09 12:58:51 -06001053 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001054 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001055
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001056#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001057 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001058 MESH_BIND_ID, // binding ID
1059 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001060 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF3156cb02014-12-02 15:41:44 -07001061 };
1062
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001063 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001064 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1065 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001066 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001067 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF3156cb02014-12-02 15:41:44 -07001068
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001069 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF3156cb02014-12-02 15:41:44 -07001070 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001071 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF3156cb02014-12-02 15:41:44 -07001072
Tony Barbour664accc2015-01-09 12:55:14 -07001073 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour664accc2015-01-09 12:55:14 -07001074
Tony Barbourfe3351b2015-07-28 10:17:20 -06001075 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001076
Tony Barbourfe3351b2015-07-28 10:17:20 -06001077 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001078
Tony Barbourfe3351b2015-07-28 10:17:20 -06001079 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001080#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001081 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001082 pDSDumpDot((char*)"triTest2.dot");
1083#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001084
Tony Barbour664accc2015-01-09 12:55:14 -07001085 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06001086 Draw(0, 6, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07001087
1088 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001089 EndCommandBuffer();
1090 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001091
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001092 RecordImages(m_renderTargets);
GregF3156cb02014-12-02 15:41:44 -07001093}
1094
Tony Barbour6918cd52015-04-09 12:58:51 -06001095TEST_F(VkRenderTest, RedCirclesonBlue)
GregF3156cb02014-12-02 15:41:44 -07001096{
1097 // This tests that we correctly handle unread fragment inputs
1098
1099 static const char *vertShaderText =
1100 "#version 140\n"
1101 "#extension GL_ARB_separate_shader_objects : enable\n"
1102 "#extension GL_ARB_shading_language_420pack : enable\n"
1103 "layout (location = 0) in vec4 pos;\n"
1104 "layout (location = 0) out vec4 outColor;\n"
1105 "layout (location = 1) out vec4 outColor2;\n"
1106 "void main() {\n"
1107 " gl_Position = pos;\n"
1108 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1109 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1110 "}\n";
1111
1112 static const char *fragShaderText =
GregF3156cb02014-12-02 15:41:44 -07001113 "#version 330\n"
1114 "#extension GL_ARB_separate_shader_objects : enable\n"
1115 "#extension GL_ARB_shading_language_420pack : enable\n"
1116 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1117 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1118 "layout (location = 0) in vec4 color;\n"
1119 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001120 "layout (location = 0) out vec4 outColor;\n"
GregF3156cb02014-12-02 15:41:44 -07001121 "void main() {\n"
1122 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1123 " float dist_squared = dot(pos, pos);\n"
GregFaae75242015-06-03 18:40:50 -06001124 " outColor = (dist_squared < 400.0)\n"
GregF3156cb02014-12-02 15:41:44 -07001125 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1126 " : color2;\n"
1127 "}\n";
1128
1129 ASSERT_NO_FATAL_FAILURE(InitState());
1130 ASSERT_NO_FATAL_FAILURE(InitViewport());
1131
Tony Barbour6918cd52015-04-09 12:58:51 -06001132 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001133 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001134
Tony Barbour6918cd52015-04-09 12:58:51 -06001135 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1136 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF3156cb02014-12-02 15:41:44 -07001137
Tony Barbour6918cd52015-04-09 12:58:51 -06001138 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001139 pipelineobj.AddColorAttachment();
GregF3156cb02014-12-02 15:41:44 -07001140 pipelineobj.AddShader(&vs);
1141 pipelineobj.AddShader(&ps);
1142
Tony Barbour6918cd52015-04-09 12:58:51 -06001143 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001144 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001145
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001146#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001147 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001148 MESH_BIND_ID, // binding ID
1149 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001150 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF3156cb02014-12-02 15:41:44 -07001151 };
1152
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001153 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001154 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1155 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001156 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001157 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF3156cb02014-12-02 15:41:44 -07001158
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001159 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF3156cb02014-12-02 15:41:44 -07001160 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001161 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF3156cb02014-12-02 15:41:44 -07001162
Tony Barbour664accc2015-01-09 12:55:14 -07001163 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001164 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001165
Tony Barbourfe3351b2015-07-28 10:17:20 -06001166 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001167
Tony Barbourfe3351b2015-07-28 10:17:20 -06001168 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001169#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001170 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001171 pDSDumpDot((char*)"triTest2.dot");
1172#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001173 // render two triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -06001174 Draw(0, 6, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07001175
1176 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001177 EndCommandBuffer();
1178 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001179
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001180 RecordImages(m_renderTargets);
GregF3156cb02014-12-02 15:41:44 -07001181}
1182
Tony Barbour6918cd52015-04-09 12:58:51 -06001183TEST_F(VkRenderTest, GreyCirclesonBlueFade)
GregF3156cb02014-12-02 15:41:44 -07001184{
1185 // This tests reading gl_ClipDistance from FS
1186
1187 static const char *vertShaderText =
GregFaae75242015-06-03 18:40:50 -06001188 //"#version 140\n"
GregF3156cb02014-12-02 15:41:44 -07001189 "#version 330\n"
1190 "#extension GL_ARB_separate_shader_objects : enable\n"
1191 "#extension GL_ARB_shading_language_420pack : enable\n"
1192 "out gl_PerVertex {\n"
1193 " vec4 gl_Position;\n"
1194 " float gl_ClipDistance[1];\n"
1195 "};\n"
1196 "layout (location = 0) in vec4 pos;\n"
1197 "layout (location = 0) out vec4 outColor;\n"
1198 "layout (location = 1) out vec4 outColor2;\n"
1199 "void main() {\n"
1200 " gl_Position = pos;\n"
1201 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1202 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1203 " float dists[3];\n"
1204 " dists[0] = 0.0;\n"
1205 " dists[1] = 1.0;\n"
1206 " dists[2] = 1.0;\n"
1207 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1208 "}\n";
1209
1210
1211 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -06001212 "#version 140\n"
1213 //"#version 330\n"
GregF3156cb02014-12-02 15:41:44 -07001214 "#extension GL_ARB_separate_shader_objects : enable\n"
1215 "#extension GL_ARB_shading_language_420pack : enable\n"
1216 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1217 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1218 "layout (location = 0) in vec4 color;\n"
1219 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001220 "layout (location = 0) out vec4 uFragColor;\n"
GregF3156cb02014-12-02 15:41:44 -07001221 "void main() {\n"
1222 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1223 " float dist_squared = dot(pos, pos);\n"
GregFaae75242015-06-03 18:40:50 -06001224 " uFragColor = (dist_squared < 400.0)\n"
GregF3156cb02014-12-02 15:41:44 -07001225 " ? color * gl_ClipDistance[0]\n"
1226 " : color2;\n"
1227 "}\n";
1228
1229 ASSERT_NO_FATAL_FAILURE(InitState());
1230 ASSERT_NO_FATAL_FAILURE(InitViewport());
1231
Tony Barbour6918cd52015-04-09 12:58:51 -06001232 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001233 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001234
Tony Barbour6918cd52015-04-09 12:58:51 -06001235 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1236 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF3156cb02014-12-02 15:41:44 -07001237
Tony Barbour6918cd52015-04-09 12:58:51 -06001238 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001239 pipelineobj.AddColorAttachment();
GregF3156cb02014-12-02 15:41:44 -07001240 pipelineobj.AddShader(&vs);
1241 pipelineobj.AddShader(&ps);
1242
Tony Barbour6918cd52015-04-09 12:58:51 -06001243 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001244 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001245
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001246#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001247 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001248 MESH_BIND_ID, // binding ID
1249 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001250 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF3156cb02014-12-02 15:41:44 -07001251 };
1252
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001253 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001254 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1255 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001256 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001257 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF3156cb02014-12-02 15:41:44 -07001258
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001259 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF3156cb02014-12-02 15:41:44 -07001260 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001261 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF3156cb02014-12-02 15:41:44 -07001262
Tony Barbour664accc2015-01-09 12:55:14 -07001263 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
GregF3156cb02014-12-02 15:41:44 -07001264
Tony Barbourfe3351b2015-07-28 10:17:20 -06001265 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001266
Tony Barbourfe3351b2015-07-28 10:17:20 -06001267 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001268
Tony Barbourfe3351b2015-07-28 10:17:20 -06001269 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001270#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001271 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001272 pDSDumpDot((char*)"triTest2.dot");
1273#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001274
1275 // render two triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -06001276 Draw(0, 6, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07001277
1278 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001279 EndCommandBuffer();
1280 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001281
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001282 RecordImages(m_renderTargets);
GregF3156cb02014-12-02 15:41:44 -07001283}
Tony Barboure2c58df2014-11-25 13:18:32 -07001284
Tony Barbour6918cd52015-04-09 12:58:51 -06001285TEST_F(VkRenderTest, GreyCirclesonBlueDiscard)
GregF42226582014-12-02 17:19:34 -07001286{
1287 static const char *vertShaderText =
1288 "#version 140\n"
1289 "#extension GL_ARB_separate_shader_objects : enable\n"
1290 "#extension GL_ARB_shading_language_420pack : enable\n"
1291 "layout (location = 0) in vec4 pos;\n"
1292 "layout (location = 0) out vec4 outColor;\n"
1293 "layout (location = 1) out vec4 outColor2;\n"
1294 "void main() {\n"
1295 " gl_Position = pos;\n"
1296 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1297 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1298 "}\n";
1299
1300
1301 static const char *fragShaderText =
GregF42226582014-12-02 17:19:34 -07001302 "#version 330\n"
1303 "#extension GL_ARB_separate_shader_objects : enable\n"
1304 "#extension GL_ARB_shading_language_420pack : enable\n"
1305 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1306 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1307 "layout (location = 0) in vec4 color;\n"
1308 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001309 "layout (location = 0) out vec4 outColor;\n"
GregF42226582014-12-02 17:19:34 -07001310 "void main() {\n"
1311 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1312 " float dist_squared = dot(pos, pos);\n"
1313 " if (dist_squared < 100.0)\n"
1314 " discard;\n"
GregFaae75242015-06-03 18:40:50 -06001315 " outColor = (dist_squared < 400.0)\n"
GregF42226582014-12-02 17:19:34 -07001316 " ? color\n"
1317 " : color2;\n"
1318 "}\n";
1319
1320 ASSERT_NO_FATAL_FAILURE(InitState());
1321 ASSERT_NO_FATAL_FAILURE(InitViewport());
1322
Tony Barbour6918cd52015-04-09 12:58:51 -06001323 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001324 meshBuffer.BufferMemoryBarrier();
GregF42226582014-12-02 17:19:34 -07001325
Tony Barbour6918cd52015-04-09 12:58:51 -06001326 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1327 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF42226582014-12-02 17:19:34 -07001328
Tony Barbour6918cd52015-04-09 12:58:51 -06001329 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001330 pipelineobj.AddColorAttachment();
GregF42226582014-12-02 17:19:34 -07001331 pipelineobj.AddShader(&vs);
1332 pipelineobj.AddShader(&ps);
1333
Tony Barbour6918cd52015-04-09 12:58:51 -06001334 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001335 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001336
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001337#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001338 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001339 MESH_BIND_ID, // binding ID
1340 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001341 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF42226582014-12-02 17:19:34 -07001342 };
1343
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001344 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001345 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1346 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001347 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001348 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF42226582014-12-02 17:19:34 -07001349
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001350 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF42226582014-12-02 17:19:34 -07001351 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001352 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF42226582014-12-02 17:19:34 -07001353
Tony Barbour664accc2015-01-09 12:55:14 -07001354 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour664accc2015-01-09 12:55:14 -07001355
Tony Barbourfe3351b2015-07-28 10:17:20 -06001356 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001357
Tony Barbourfe3351b2015-07-28 10:17:20 -06001358 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001359
Tony Barbourfe3351b2015-07-28 10:17:20 -06001360 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001361#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001362 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001363 pDSDumpDot((char*)"triTest2.dot");
1364#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001365
1366 // render two triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -06001367 Draw(0, 6, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07001368
1369 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001370 EndCommandBuffer();
1371 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001372
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001373 RecordImages(m_renderTargets);
GregF42226582014-12-02 17:19:34 -07001374}
1375
1376
Tony Barbour6918cd52015-04-09 12:58:51 -06001377TEST_F(VkRenderTest, TriangleVSUniform)
Cody Northrop66594a72014-10-10 14:49:36 -06001378{
1379 static const char *vertShaderText =
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001380 "#version 140\n"
1381 "#extension GL_ARB_separate_shader_objects : enable\n"
1382 "#extension GL_ARB_shading_language_420pack : enable\n"
1383 "\n"
1384 "layout(binding = 0) uniform buf {\n"
1385 " mat4 MVP;\n"
1386 "} ubuf;\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001387 "void main() {\n"
1388 " vec2 vertices[3];"
1389 " vertices[0] = vec2(-0.5, -0.5);\n"
1390 " vertices[1] = vec2( 0.5, -0.5);\n"
1391 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001392 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001393 "}\n";
1394
1395 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -06001396 "#version 140\n"
1397 "#extension GL_ARB_separate_shader_objects : enable\n"
1398 "#extension GL_ARB_shading_language_420pack : enable\n"
1399 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001400 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001401 " outColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001402 "}\n";
1403
Tony Barboure2c58df2014-11-25 13:18:32 -07001404 ASSERT_NO_FATAL_FAILURE(InitState());
1405 ASSERT_NO_FATAL_FAILURE(InitViewport());
1406
Courtney Goeltzenleuchterfdcfb9f2014-10-10 18:04:39 -06001407 // Create identity matrix
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001408 glm::mat4 Projection = glm::mat4(1.0f);
1409 glm::mat4 View = glm::mat4(1.0f);
1410 glm::mat4 Model = glm::mat4(1.0f);
1411 glm::mat4 MVP = Projection * View * Model;
1412 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1413
Tony Barbour6918cd52015-04-09 12:58:51 -06001414 VkConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1415 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1416 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001417
Tony Barbour6918cd52015-04-09 12:58:51 -06001418 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001419 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001420 pipelineobj.AddShader(&vs);
1421 pipelineobj.AddShader(&ps);
1422
1423 // Create descriptor set and attach the constant buffer to it
Tony Barbour6918cd52015-04-09 12:58:51 -06001424 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001425 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07001426
Tony Barbour664accc2015-01-09 12:55:14 -07001427 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf1878c72015-08-18 14:24:32 -06001428
1429 VkCmdBufferBeginInfo cbBeginInfo;
1430 memset(&cbBeginInfo, 0, sizeof(VkCmdBufferBeginInfo));
1431 cbBeginInfo.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1432 cbBeginInfo.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT;
1433 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barboure2c58df2014-11-25 13:18:32 -07001434
Tony Barbourfe3351b2015-07-28 10:17:20 -06001435 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001436
Tony Barbour664accc2015-01-09 12:55:14 -07001437#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001438 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001439 pDSDumpDot((char*)"triTest2.dot");
1440#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001441
1442 // render two triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -06001443 Draw(0, 6, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07001444
1445 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001446 EndCommandBuffer();
1447 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001448
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001449 RecordImages(m_renderTargets);
Tony Barbour664accc2015-01-09 12:55:14 -07001450
Tony Barbourfe3351b2015-07-28 10:17:20 -06001451 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer);
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001452}
1453
Tony Barbour6918cd52015-04-09 12:58:51 -06001454TEST_F(VkRenderTest, MixTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07001455{
1456 // This tests location applied to varyings. Notice that we have switched foo
1457 // and bar in the FS. The triangle should be blended with red, green and blue
1458 // corners.
1459 static const char *vertShaderText =
1460 "#version 140\n"
1461 "#extension GL_ARB_separate_shader_objects : enable\n"
1462 "#extension GL_ARB_shading_language_420pack : enable\n"
1463 "layout (location=0) out vec4 bar;\n"
1464 "layout (location=1) out vec4 foo;\n"
1465 "layout (location=2) out float scale;\n"
1466 "vec2 vertices[3];\n"
1467 "void main() {\n"
1468 " vertices[0] = vec2(-1.0, -1.0);\n"
1469 " vertices[1] = vec2( 1.0, -1.0);\n"
1470 " vertices[2] = vec2( 0.0, 1.0);\n"
1471 "vec4 colors[3];\n"
1472 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1473 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1474 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1475 " foo = colors[gl_VertexID % 3];\n"
1476 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1477 " scale = 1.0;\n"
1478 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1479 "}\n";
1480
1481 static const char *fragShaderText =
1482 "#version 140\n"
1483 "#extension GL_ARB_separate_shader_objects : enable\n"
1484 "#extension GL_ARB_shading_language_420pack : enable\n"
1485 "layout (location = 1) in vec4 bar;\n"
1486 "layout (location = 0) in vec4 foo;\n"
1487 "layout (location = 2) in float scale;\n"
GregFaae75242015-06-03 18:40:50 -06001488 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001489 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001490 " outColor = bar * scale + foo * (1.0-scale);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001491 "}\n";
1492
1493 ASSERT_NO_FATAL_FAILURE(InitState());
1494 ASSERT_NO_FATAL_FAILURE(InitViewport());
1495
Tony Barbour6918cd52015-04-09 12:58:51 -06001496 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1497 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001498
Tony Barbour6918cd52015-04-09 12:58:51 -06001499 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001500 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001501 pipelineobj.AddShader(&vs);
1502 pipelineobj.AddShader(&ps);
1503
Tony Barbour6918cd52015-04-09 12:58:51 -06001504 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour831062d2015-04-02 15:43:15 -06001505 descriptorSet.AppendDummy();
Tony Barboure2c58df2014-11-25 13:18:32 -07001506
Tony Barbour664accc2015-01-09 12:55:14 -07001507 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour664accc2015-01-09 12:55:14 -07001508
Tony Barbourfe3351b2015-07-28 10:17:20 -06001509 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001510
Tony Barbourfe3351b2015-07-28 10:17:20 -06001511 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001512
1513#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001514 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001515 pDSDumpDot((char*)"triTest2.dot");
1516#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001517
Tony Barbour664accc2015-01-09 12:55:14 -07001518 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06001519 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07001520
1521 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001522 EndCommandBuffer();
1523 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001524
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001525 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001526}
1527
Tony Barbour6918cd52015-04-09 12:58:51 -06001528TEST_F(VkRenderTest, QuadVertFetchAndVertID)
Tony Barboure2c58df2014-11-25 13:18:32 -07001529{
1530 // This tests that attributes work in the presence of gl_VertexID
1531
1532 static const char *vertShaderText =
1533 "#version 140\n"
1534 "#extension GL_ARB_separate_shader_objects : enable\n"
1535 "#extension GL_ARB_shading_language_420pack : enable\n"
1536 //XYZ1( -1, -1, -1 )
1537 "layout (location = 0) in vec4 pos;\n"
1538 //XYZ1( 0.f, 0.f, 0.f )
1539 "layout (location = 1) in vec4 inColor;\n"
1540 "layout (location = 0) out vec4 outColor;\n"
1541 "void main() {\n"
1542 " outColor = inColor;\n"
1543 " vec4 vertices[3];"
1544 " vertices[gl_VertexID % 3] = pos;\n"
1545 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1546 "}\n";
1547
1548
1549 static const char *fragShaderText =
1550 "#version 140\n"
1551 "#extension GL_ARB_separate_shader_objects : enable\n"
1552 "#extension GL_ARB_shading_language_420pack : enable\n"
1553 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06001554 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001555 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001556 " outColor = color;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001557 "}\n";
1558
1559 ASSERT_NO_FATAL_FAILURE(InitState());
1560 ASSERT_NO_FATAL_FAILURE(InitViewport());
1561
Tony Barbour6918cd52015-04-09 12:58:51 -06001562 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001563 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07001564
Tony Barbour6918cd52015-04-09 12:58:51 -06001565 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1566 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001567
Tony Barbour6918cd52015-04-09 12:58:51 -06001568 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001569 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001570 pipelineobj.AddShader(&vs);
1571 pipelineobj.AddShader(&ps);
1572
Tony Barbour6918cd52015-04-09 12:58:51 -06001573 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001574 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001575
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001576#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001577 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001578 MESH_BUF_ID, // Binding ID
1579 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001580 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barboure2c58df2014-11-25 13:18:32 -07001581 };
1582
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001583 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001584 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1585 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001586 vi_attribs[0].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001587 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1588 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1589 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001590 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001591 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -07001592
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001593 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001594 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001595 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barboure2c58df2014-11-25 13:18:32 -07001596
Tony Barbour664accc2015-01-09 12:55:14 -07001597 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour664accc2015-01-09 12:55:14 -07001598
Tony Barbourfe3351b2015-07-28 10:17:20 -06001599 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001600
Tony Barbourfe3351b2015-07-28 10:17:20 -06001601 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001602
Tony Barbourfe3351b2015-07-28 10:17:20 -06001603 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001604#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001605 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001606 pDSDumpDot((char*)"triTest2.dot");
1607#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001608
1609 // render two triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -06001610 Draw(0, 6, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07001611
1612 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001613 EndCommandBuffer();
1614 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001615
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001616 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001617}
1618
Tony Barbour6918cd52015-04-09 12:58:51 -06001619TEST_F(VkRenderTest, QuadSparseVertFetch)
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001620{
1621 // This tests that attributes work in the presence of gl_VertexID
1622
1623 static const char *vertShaderText =
1624 "#version 140\n"
1625 "#extension GL_ARB_separate_shader_objects : enable\n"
1626 "#extension GL_ARB_shading_language_420pack : enable\n"
1627 //XYZ1( -1, -1, -1 )
1628 "layout (location = 1) in vec4 pos;\n"
1629 "layout (location = 4) in vec4 inColor;\n"
1630 //XYZ1( 0.f, 0.f, 0.f )
1631 "layout (location = 0) out vec4 outColor;\n"
1632 "void main() {\n"
1633 " outColor = inColor;\n"
1634 " gl_Position = pos;\n"
1635 "}\n";
1636
1637
1638 static const char *fragShaderText =
1639 "#version 140\n"
1640 "#extension GL_ARB_separate_shader_objects : enable\n"
1641 "#extension GL_ARB_shading_language_420pack : enable\n"
1642 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06001643 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001644 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001645 " outColor = color;\n"
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001646 "}\n";
1647
1648 ASSERT_NO_FATAL_FAILURE(InitState());
1649 ASSERT_NO_FATAL_FAILURE(InitViewport());
1650
1651 struct VDATA
1652 {
1653 float t1, t2, t3, t4; // filler data
1654 float posX, posY, posZ, posW; // Position data
1655 float r, g, b, a; // Color
1656 };
1657 const struct VDATA vData[] =
1658 {
1659 { XYZ1(0, 0, 0), XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
1660 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1661 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1662 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1663 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1664 { XYZ1(0, 0, 0), XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
1665 };
1666
Tony Barbour6918cd52015-04-09 12:58:51 -06001667 VkConstantBufferObj meshBuffer(m_device,sizeof(vData)/sizeof(vData[0]),sizeof(vData[0]), vData);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001668 meshBuffer.BufferMemoryBarrier();
1669
Tony Barbour6918cd52015-04-09 12:58:51 -06001670 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1671 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001672
Tony Barbour6918cd52015-04-09 12:58:51 -06001673 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001674 pipelineobj.AddColorAttachment();
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001675 pipelineobj.AddShader(&vs);
1676 pipelineobj.AddShader(&ps);
1677
Tony Barbour6918cd52015-04-09 12:58:51 -06001678 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001679 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001680
1681#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001682 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001683 MESH_BUF_ID, // Binding ID
1684 sizeof(vData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001685 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001686 };
1687
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001688 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001689 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1690 vi_attribs[0].location = 4;
Tony Barbourd1c35722015-04-16 15:59:00 -06001691 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001692 vi_attribs[0].offsetInBytes = sizeof(float) * 4 * 2; // Offset of first element in bytes from base of vertex
1693 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1694 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001695 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001696 vi_attribs[1].offsetInBytes = sizeof(float) * 4 * 1; // Offset of first element in bytes from base of vertex
1697
1698 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
1699 pipelineobj.AddVertexInputBindings(&vi_binding, 1);
1700 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
1701
1702 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001703
Tony Barbourfe3351b2015-07-28 10:17:20 -06001704 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001705
Tony Barbourfe3351b2015-07-28 10:17:20 -06001706 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001707
Tony Barbourfe3351b2015-07-28 10:17:20 -06001708 BindVertexBuffer(&meshBuffer, 0, MESH_BUF_ID);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001709#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001710 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001711 pDSDumpDot((char*)"triTest2.dot");
1712#endif
1713
1714 // render two triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -06001715 Draw(0, 6, 0, 1);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001716
1717 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001718 EndCommandBuffer();
1719 QueueCommandBuffer();
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001720
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001721 RecordImages(m_renderTargets);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001722}
1723
Tony Barbour6918cd52015-04-09 12:58:51 -06001724TEST_F(VkRenderTest, TriVertFetchDeadAttr)
Tony Barboure2c58df2014-11-25 13:18:32 -07001725{
1726 // This tests that attributes work in the presence of gl_VertexID
1727 // and a dead attribute in position 0. Draws a triangle with yellow,
1728 // red and green corners, starting at top and going clockwise.
1729
1730 static const char *vertShaderText =
1731 "#version 140\n"
1732 "#extension GL_ARB_separate_shader_objects : enable\n"
1733 "#extension GL_ARB_shading_language_420pack : enable\n"
1734 //XYZ1( -1, -1, -1 )
1735 "layout (location = 0) in vec4 pos;\n"
1736 //XYZ1( 0.f, 0.f, 0.f )
1737 "layout (location = 1) in vec4 inColor;\n"
1738 "layout (location = 0) out vec4 outColor;\n"
1739 "void main() {\n"
1740 " outColor = inColor;\n"
1741 " vec2 vertices[3];"
1742 " vertices[0] = vec2(-1.0, -1.0);\n"
1743 " vertices[1] = vec2( 1.0, -1.0);\n"
1744 " vertices[2] = vec2( 0.0, 1.0);\n"
1745 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1746 "}\n";
1747
1748
1749 static const char *fragShaderText =
1750 "#version 140\n"
1751 "#extension GL_ARB_separate_shader_objects : enable\n"
1752 "#extension GL_ARB_shading_language_420pack : enable\n"
1753 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06001754 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001755 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001756 " outColor = color;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001757 "}\n";
1758
1759 ASSERT_NO_FATAL_FAILURE(InitState());
1760 ASSERT_NO_FATAL_FAILURE(InitViewport());
1761
Tony Barbour6918cd52015-04-09 12:58:51 -06001762 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001763 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07001764
Tony Barbour6918cd52015-04-09 12:58:51 -06001765 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1766 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001767
Tony Barbour6918cd52015-04-09 12:58:51 -06001768 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001769 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001770 pipelineobj.AddShader(&vs);
1771 pipelineobj.AddShader(&ps);
1772
Tony Barbour6918cd52015-04-09 12:58:51 -06001773 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001774 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001775
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001776#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001777 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001778 MESH_BUF_ID, // Binding ID
1779 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001780 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barboure2c58df2014-11-25 13:18:32 -07001781 };
1782
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001783 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001784 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1785 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001786 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001787 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1788 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1789 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001790 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001791 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -07001792
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001793 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001794 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001795 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barboure2c58df2014-11-25 13:18:32 -07001796
Tony Barbour664accc2015-01-09 12:55:14 -07001797 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboure2c58df2014-11-25 13:18:32 -07001798
Tony Barbourfe3351b2015-07-28 10:17:20 -06001799 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001800
Tony Barbourfe3351b2015-07-28 10:17:20 -06001801 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001802
Tony Barbourfe3351b2015-07-28 10:17:20 -06001803 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001804#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001805 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001806 pDSDumpDot((char*)"triTest2.dot");
1807#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001808
1809 // render two triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -06001810 Draw(0, 6, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07001811
1812 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001813 EndCommandBuffer();
1814 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001815
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001816 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001817}
1818
Tony Barbour6918cd52015-04-09 12:58:51 -06001819TEST_F(VkRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001820{
1821 static const char *vertShaderText =
1822 "#version 140\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001823 "#extension GL_ARB_separate_shader_objects : enable\n"
1824 "#extension GL_ARB_shading_language_420pack : enable\n"
GregFaae75242015-06-03 18:40:50 -06001825 "layout (std140, binding = 0) uniform bufferVals {\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001826 " mat4 mvp;\n"
1827 "} myBufferVals;\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001828 "layout (location = 0) in vec4 pos;\n"
1829 "layout (location = 1) in vec4 inColor;\n"
Cody Northrop8a3bb132015-06-16 17:32:04 -06001830 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001831 "void main() {\n"
1832 " outColor = inColor;\n"
1833 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06001834 " gl_Position.y = -gl_Position.y;\n"
1835 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001836 "}\n";
1837
1838 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -06001839 "#version 140\n"
1840 "#extension GL_ARB_separate_shader_objects : enable\n"
1841 "#extension GL_ARB_shading_language_420pack : enable\n"
1842 "layout (location = 0) in vec4 color;\n"
1843 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001844 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001845 " outColor = color;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001846 "}\n";
Tony Barboure2c58df2014-11-25 13:18:32 -07001847 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001848
Tony Barboure2c58df2014-11-25 13:18:32 -07001849 glm::mat4 View = glm::lookAt(
1850 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1851 glm::vec3(0,0,0), // and looks at the origin
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06001852 glm::vec3(0,-1,0) // Head is up (set to 0,-1,0 to look upside-down)
Tony Barboure2c58df2014-11-25 13:18:32 -07001853 );
1854
1855 glm::mat4 Model = glm::mat4(1.0f);
1856
1857 glm::mat4 MVP = Projection * View * Model;
1858
1859 ASSERT_NO_FATAL_FAILURE(InitState());
1860 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wub4052042015-07-09 10:16:34 +08001861 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Chia-I Wu08accc62015-07-07 11:50:03 +08001862 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height, m_depth_stencil_fmt);
Tony Barboure2c58df2014-11-25 13:18:32 -07001863
Tony Barbour6918cd52015-04-09 12:58:51 -06001864 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 -07001865 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1866
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001867 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barboure2c58df2014-11-25 13:18:32 -07001868
Tony Barbour6918cd52015-04-09 12:58:51 -06001869 VkConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1870 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1871 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001872
Tony Barbour6918cd52015-04-09 12:58:51 -06001873 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001874 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001875 pipelineobj.AddShader(&vs);
1876 pipelineobj.AddShader(&ps);
1877
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001878 VkPipelineDepthStencilStateCreateInfo ds_state;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001879 ds_state.depthTestEnable = VK_TRUE;
1880 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbourd1c35722015-04-16 15:59:00 -06001881 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001882 ds_state.depthBoundsEnable = VK_FALSE;
1883 ds_state.stencilTestEnable = VK_FALSE;
1884 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
1885 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
1886 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbourd1c35722015-04-16 15:59:00 -06001887 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
Tony Barbourf52346d2015-01-16 14:27:35 -07001888 ds_state.front = ds_state.back;
1889 pipelineobj.SetDepthStencil(&ds_state);
1890
Tony Barbour6918cd52015-04-09 12:58:51 -06001891 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001892 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07001893
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001894#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001895 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001896 MESH_BUF_ID, // Binding ID
1897 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001898 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001899 };
Tony Barboure2c58df2014-11-25 13:18:32 -07001900
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001901 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001902 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1903 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001904 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001905 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1906 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1907 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001908 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001909 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -07001910
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001911 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001912 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001913 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barboure2c58df2014-11-25 13:18:32 -07001914
Tony Barbour1c45ce02015-03-27 17:03:18 -06001915 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour1c45ce02015-03-27 17:03:18 -06001916
Tony Barbourfe3351b2015-07-28 10:17:20 -06001917 ASSERT_VK_SUCCESS(BeginCommandBuffer());
1918 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barboure2c58df2014-11-25 13:18:32 -07001919
Tony Barbourfe3351b2015-07-28 10:17:20 -06001920 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour1fde6942015-01-09 10:06:53 -07001921#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001922 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour1fde6942015-01-09 10:06:53 -07001923 pDSDumpDot((char*)"triTest2.dot");
1924#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001925
1926 // render triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -06001927 Draw(0, 36, 0, 1);
Tony Barbour1fde6942015-01-09 10:06:53 -07001928
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001929
Tony Barbour1fde6942015-01-09 10:06:53 -07001930 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001931 EndCommandBuffer();
1932 QueueCommandBuffer();
Tony Barbour1fde6942015-01-09 10:06:53 -07001933
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001934 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001935}
1936
Tony Barbour6918cd52015-04-09 12:58:51 -06001937TEST_F(VkRenderTest, VSTexture)
Tony Barboure2c58df2014-11-25 13:18:32 -07001938{
1939 // The expected result from this test is a green and red triangle;
1940 // one red vertex on the left, two green vertices on the right.
1941 static const char *vertShaderText =
Cody Northrop8a3bb132015-06-16 17:32:04 -06001942 "#version 140\n"
1943 "#extension GL_ARB_separate_shader_objects : enable\n"
1944 "#extension GL_ARB_shading_language_420pack : enable\n"
1945 "layout (location = 0) out vec4 texColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001946 "uniform sampler2D surface;\n"
1947 "void main() {\n"
1948 " vec2 vertices[3];"
1949 " vertices[0] = vec2(-0.5, -0.5);\n"
1950 " vertices[1] = vec2( 0.5, -0.5);\n"
1951 " vertices[2] = vec2( 0.5, 0.5);\n"
1952 " vec2 positions[3];"
1953 " positions[0] = vec2( 0.0, 0.0);\n"
1954 " positions[1] = vec2( 0.25, 0.1);\n"
1955 " positions[2] = vec2( 0.1, 0.25);\n"
1956 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1957 " texColor = textureLod(surface, samplePos, 0.0);\n"
1958 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1959 "}\n";
1960
1961 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -06001962 "#version 140\n"
1963 "#extension GL_ARB_separate_shader_objects : enable\n"
1964 "#extension GL_ARB_shading_language_420pack : enable\n"
1965 "layout (location = 0) in vec4 texColor;\n"
1966 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001967 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001968 " outColor = texColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001969 "}\n";
1970
1971 ASSERT_NO_FATAL_FAILURE(InitState());
1972 ASSERT_NO_FATAL_FAILURE(InitViewport());
1973
Tony Barbour6918cd52015-04-09 12:58:51 -06001974 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1975 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
1976 VkSamplerObj sampler(m_device);
1977 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07001978
Tony Barbour6918cd52015-04-09 12:58:51 -06001979 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001980 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001981 pipelineobj.AddShader(&vs);
1982 pipelineobj.AddShader(&ps);
1983
Tony Barbour6918cd52015-04-09 12:58:51 -06001984 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08001985 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07001986
Tony Barbour664accc2015-01-09 12:55:14 -07001987 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001988 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure2c58df2014-11-25 13:18:32 -07001989
Tony Barbourfe3351b2015-07-28 10:17:20 -06001990 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001991
1992#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001993 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001994 pDSDumpDot((char*)"triTest2.dot");
1995#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001996
Tony Barbour664accc2015-01-09 12:55:14 -07001997 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06001998 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07001999
2000 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002001 EndCommandBuffer();
2002 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002003
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002004 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002005}
GregFaae75242015-06-03 18:40:50 -06002006
2007
2008
Tony Barbour6918cd52015-04-09 12:58:51 -06002009TEST_F(VkRenderTest, TexturedTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07002010{
2011 // The expected result from this test is a red and green checkered triangle
2012 static const char *vertShaderText =
2013 "#version 140\n"
2014 "#extension GL_ARB_separate_shader_objects : enable\n"
2015 "#extension GL_ARB_shading_language_420pack : enable\n"
2016 "layout (location = 0) out vec2 samplePos;\n"
2017 "void main() {\n"
2018 " vec2 vertices[3];"
2019 " vertices[0] = vec2(-0.5, -0.5);\n"
2020 " vertices[1] = vec2( 0.5, -0.5);\n"
2021 " vertices[2] = vec2( 0.5, 0.5);\n"
2022 " vec2 positions[3];"
2023 " positions[0] = vec2( 0.0, 0.0);\n"
2024 " positions[1] = vec2( 1.0, 0.0);\n"
2025 " positions[2] = vec2( 1.0, 1.0);\n"
2026 " samplePos = positions[gl_VertexID % 3];\n"
2027 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2028 "}\n";
2029
2030 static const char *fragShaderText =
2031 "#version 140\n"
2032 "#extension GL_ARB_separate_shader_objects : enable\n"
2033 "#extension GL_ARB_shading_language_420pack : enable\n"
2034 "layout (location = 0) in vec2 samplePos;\n"
2035 "layout (binding = 0) uniform sampler2D surface;\n"
2036 "layout (location=0) out vec4 outColor;\n"
2037 "void main() {\n"
2038 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2039 " outColor = texColor;\n"
2040 "}\n";
2041
2042 ASSERT_NO_FATAL_FAILURE(InitState());
2043 ASSERT_NO_FATAL_FAILURE(InitViewport());
2044
Tony Barbour6918cd52015-04-09 12:58:51 -06002045 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2046 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2047 VkSamplerObj sampler(m_device);
2048 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002049
Tony Barbour6918cd52015-04-09 12:58:51 -06002050 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002051 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002052 pipelineobj.AddShader(&vs);
2053 pipelineobj.AddShader(&ps);
2054
Tony Barbour6918cd52015-04-09 12:58:51 -06002055 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002056 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002057
Tony Barbour664accc2015-01-09 12:55:14 -07002058 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002059 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002060
Tony Barbourfe3351b2015-07-28 10:17:20 -06002061 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002062
2063#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002064 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002065 pDSDumpDot((char*)"triTest2.dot");
2066#endif
2067 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002068 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07002069
2070 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002071 EndCommandBuffer();
2072 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002073
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002074 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002075}
Tony Barbour6918cd52015-04-09 12:58:51 -06002076TEST_F(VkRenderTest, TexturedTriangleClip)
Tony Barboure2c58df2014-11-25 13:18:32 -07002077{
2078 // The expected result from this test is a red and green checkered triangle
2079 static const char *vertShaderText =
2080 "#version 330\n"
2081 "#extension GL_ARB_separate_shader_objects : enable\n"
2082 "#extension GL_ARB_shading_language_420pack : enable\n"
2083 "layout (location = 0) out vec2 samplePos;\n"
2084 "out gl_PerVertex {\n"
2085 " vec4 gl_Position;\n"
2086 " float gl_ClipDistance[1];\n"
2087 "};\n"
2088 "void main() {\n"
2089 " vec2 vertices[3];"
2090 " vertices[0] = vec2(-0.5, -0.5);\n"
2091 " vertices[1] = vec2( 0.5, -0.5);\n"
2092 " vertices[2] = vec2( 0.5, 0.5);\n"
2093 " vec2 positions[3];"
2094 " positions[0] = vec2( 0.0, 0.0);\n"
2095 " positions[1] = vec2( 1.0, 0.0);\n"
2096 " positions[2] = vec2( 1.0, 1.0);\n"
2097 " float dists[3];\n"
2098 " dists[0] = 1.0;\n"
2099 " dists[1] = 1.0;\n"
2100 " dists[2] = -1.0;\n"
2101 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2102 " samplePos = positions[gl_VertexID % 3];\n"
2103 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2104 "}\n";
2105
2106 static const char *fragShaderText =
2107 "#version 140\n"
2108 "#extension GL_ARB_separate_shader_objects : enable\n"
2109 "#extension GL_ARB_shading_language_420pack : enable\n"
2110 "layout (location = 0) in vec2 samplePos;\n"
2111 "layout (binding = 0) uniform sampler2D surface;\n"
2112 "layout (location=0) out vec4 outColor;\n"
2113 "void main() {\n"
2114 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2115 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2116 " outColor = texColor;\n"
2117 "}\n";
2118
2119
2120 ASSERT_NO_FATAL_FAILURE(InitState());
2121 ASSERT_NO_FATAL_FAILURE(InitViewport());
2122
Tony Barbour6918cd52015-04-09 12:58:51 -06002123 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2124 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2125 VkSamplerObj sampler(m_device);
2126 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002127
Tony Barbour6918cd52015-04-09 12:58:51 -06002128 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002129 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002130 pipelineobj.AddShader(&vs);
2131 pipelineobj.AddShader(&ps);
2132
Tony Barbour6918cd52015-04-09 12:58:51 -06002133 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002134 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002135
Tony Barbour664accc2015-01-09 12:55:14 -07002136 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002137 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002138
Tony Barbourfe3351b2015-07-28 10:17:20 -06002139 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002140
2141#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002142 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002143 pDSDumpDot((char*)"triTest2.dot");
2144#endif
2145 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002146 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07002147
2148 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002149 EndCommandBuffer();
2150 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002151
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002152 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002153}
GregFaae75242015-06-03 18:40:50 -06002154
Tony Barbour6918cd52015-04-09 12:58:51 -06002155TEST_F(VkRenderTest, FSTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07002156{
2157 // The expected result from this test is a red and green checkered triangle
2158 static const char *vertShaderText =
2159 "#version 140\n"
2160 "#extension GL_ARB_separate_shader_objects : enable\n"
2161 "#extension GL_ARB_shading_language_420pack : enable\n"
2162 "layout (location = 0) out vec2 samplePos;\n"
2163 "void main() {\n"
2164 " vec2 vertices[3];"
2165 " vertices[0] = vec2(-0.5, -0.5);\n"
2166 " vertices[1] = vec2( 0.5, -0.5);\n"
2167 " vertices[2] = vec2( 0.5, 0.5);\n"
2168 " vec2 positions[3];"
2169 " positions[0] = vec2( 0.0, 0.0);\n"
2170 " positions[1] = vec2( 1.0, 0.0);\n"
2171 " positions[2] = vec2( 1.0, 1.0);\n"
2172 " samplePos = positions[gl_VertexID % 3];\n"
2173 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2174 "}\n";
2175
2176 static const char *fragShaderText =
2177 "#version 140\n"
2178 "#extension GL_ARB_separate_shader_objects : enable\n"
2179 "#extension GL_ARB_shading_language_420pack : enable\n"
2180 "layout (location = 0) in vec2 samplePos;\n"
2181 "layout (binding = 0) uniform sampler2D surface;\n"
2182 "layout (location=0) out vec4 outColor;\n"
2183 "void main() {\n"
2184 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2185 " outColor = texColor;\n"
2186 "}\n";
2187
2188 ASSERT_NO_FATAL_FAILURE(InitState());
2189 ASSERT_NO_FATAL_FAILURE(InitViewport());
2190
Tony Barbour6918cd52015-04-09 12:58:51 -06002191 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2192 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2193 VkSamplerObj sampler(m_device);
2194 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002195
Tony Barbour6918cd52015-04-09 12:58:51 -06002196 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002197 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002198 pipelineobj.AddShader(&vs);
2199 pipelineobj.AddShader(&ps);
2200
Tony Barbour6918cd52015-04-09 12:58:51 -06002201 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002202 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002203
Tony Barbour664accc2015-01-09 12:55:14 -07002204 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002205 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002206
Tony Barbourfe3351b2015-07-28 10:17:20 -06002207 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002208
2209#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002210 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002211 pDSDumpDot((char*)"triTest2.dot");
2212#endif
2213 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002214 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07002215
2216 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002217 EndCommandBuffer();
2218 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002219
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002220 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002221}
Tony Barbour6918cd52015-04-09 12:58:51 -06002222TEST_F(VkRenderTest, SamplerBindingsTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07002223{
2224 // This test sets bindings on the samplers
2225 // For now we are asserting that sampler and texture pairs
2226 // march in lock step, and are set via GLSL binding. This can
2227 // and will probably change.
2228 // The sampler bindings should match the sampler and texture slot
2229 // number set up by the application.
2230 // This test will result in a blue triangle
2231 static const char *vertShaderText =
2232 "#version 140\n"
2233 "#extension GL_ARB_separate_shader_objects : enable\n"
2234 "#extension GL_ARB_shading_language_420pack : enable\n"
2235 "layout (location = 0) out vec4 samplePos;\n"
2236 "void main() {\n"
2237 " vec2 vertices[3];"
2238 " vertices[0] = vec2(-0.5, -0.5);\n"
2239 " vertices[1] = vec2( 0.5, -0.5);\n"
2240 " vertices[2] = vec2( 0.5, 0.5);\n"
2241 " vec2 positions[3];"
2242 " positions[0] = vec2( 0.0, 0.0);\n"
2243 " positions[1] = vec2( 1.0, 0.0);\n"
2244 " positions[2] = vec2( 1.0, 1.0);\n"
2245 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2246 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2247 "}\n";
2248
2249 static const char *fragShaderText =
2250 "#version 140\n"
2251 "#extension GL_ARB_separate_shader_objects : enable\n"
2252 "#extension GL_ARB_shading_language_420pack : enable\n"
2253 "layout (location = 0) in vec4 samplePos;\n"
2254 "layout (binding = 0) uniform sampler2D surface0;\n"
2255 "layout (binding = 1) uniform sampler2D surface1;\n"
2256 "layout (binding = 12) uniform sampler2D surface2;\n"
GregFaae75242015-06-03 18:40:50 -06002257 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002258 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06002259 " outColor = textureLod(surface2, samplePos.xy, 0.0);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002260 "}\n";
2261
2262 ASSERT_NO_FATAL_FAILURE(InitState());
2263 ASSERT_NO_FATAL_FAILURE(InitViewport());
2264
Tony Barbour6918cd52015-04-09 12:58:51 -06002265 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2266 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002267
Tony Barbour6918cd52015-04-09 12:58:51 -06002268 VkSamplerObj sampler1(m_device);
2269 VkSamplerObj sampler2(m_device);
2270 VkSamplerObj sampler3(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002271
Tony Barbourebc093f2015-04-01 16:38:10 -06002272 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
Tony Barbour6918cd52015-04-09 12:58:51 -06002273 VkTextureObj texture1(m_device, tex_colors); // Red
Tony Barbourebc093f2015-04-01 16:38:10 -06002274 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
Tony Barbour6918cd52015-04-09 12:58:51 -06002275 VkTextureObj texture2(m_device, tex_colors); // Green
Tony Barbourebc093f2015-04-01 16:38:10 -06002276 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
Tony Barbour6918cd52015-04-09 12:58:51 -06002277 VkTextureObj texture3(m_device, tex_colors); // Blue
Tony Barboure2c58df2014-11-25 13:18:32 -07002278
Tony Barbour6918cd52015-04-09 12:58:51 -06002279 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002280 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002281 pipelineobj.AddShader(&vs);
2282 pipelineobj.AddShader(&ps);
2283
Tony Barbour6918cd52015-04-09 12:58:51 -06002284 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002285 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2286 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2287 for (int i = 0; i < 10; i++)
2288 descriptorSet.AppendDummy();
2289 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barboure2c58df2014-11-25 13:18:32 -07002290
Tony Barbour664accc2015-01-09 12:55:14 -07002291 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002292 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002293
Tony Barbourfe3351b2015-07-28 10:17:20 -06002294 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002295
2296#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002297 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002298 pDSDumpDot((char*)"triTest2.dot");
2299#endif
2300 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002301 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07002302
2303 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002304 EndCommandBuffer();
2305 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002306
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002307 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002308}
2309
Tony Barbour6918cd52015-04-09 12:58:51 -06002310TEST_F(VkRenderTest, TriangleVSUniformBlock)
Tony Barboure2c58df2014-11-25 13:18:32 -07002311{
2312 // The expected result from this test is a blue triangle
2313
2314 static const char *vertShaderText =
2315 "#version 140\n"
2316 "#extension GL_ARB_separate_shader_objects : enable\n"
2317 "#extension GL_ARB_shading_language_420pack : enable\n"
2318 "layout (location = 0) out vec4 outColor;\n"
2319 "layout (std140, binding = 0) uniform bufferVals {\n"
2320 " vec4 red;\n"
2321 " vec4 green;\n"
2322 " vec4 blue;\n"
2323 " vec4 white;\n"
2324 "} myBufferVals;\n"
2325 "void main() {\n"
2326 " vec2 vertices[3];"
2327 " vertices[0] = vec2(-0.5, -0.5);\n"
2328 " vertices[1] = vec2( 0.5, -0.5);\n"
2329 " vertices[2] = vec2( 0.5, 0.5);\n"
2330 " outColor = myBufferVals.blue;\n"
2331 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2332 "}\n";
2333
2334 static const char *fragShaderText =
2335 "#version 140\n"
2336 "#extension GL_ARB_separate_shader_objects : enable\n"
2337 "#extension GL_ARB_shading_language_420pack : enable\n"
2338 "layout (location = 0) in vec4 inColor;\n"
GregFaae75242015-06-03 18:40:50 -06002339 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002340 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06002341 " outColor = inColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002342 "}\n";
2343
2344 ASSERT_NO_FATAL_FAILURE(InitState());
2345 ASSERT_NO_FATAL_FAILURE(InitViewport());
2346
Tony Barbour6918cd52015-04-09 12:58:51 -06002347 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2348 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002349
2350 // Let's populate our buffer with the following:
2351 // vec4 red;
2352 // vec4 green;
2353 // vec4 blue;
2354 // vec4 white;
2355 const int valCount = 4 * 4;
2356 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2357 0.0, 1.0, 0.0, 1.0,
2358 0.0, 0.0, 1.0, 1.0,
2359 1.0, 1.0, 1.0, 1.0 };
2360
Tony Barbour6918cd52015-04-09 12:58:51 -06002361 VkConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002362
Tony Barbour6918cd52015-04-09 12:58:51 -06002363 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002364 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002365 pipelineobj.AddShader(&vs);
2366 pipelineobj.AddShader(&ps);
2367
Tony Barbour6918cd52015-04-09 12:58:51 -06002368 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002369 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, colorBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002370
Tony Barbour664accc2015-01-09 12:55:14 -07002371 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002372 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002373
Tony Barbourfe3351b2015-07-28 10:17:20 -06002374 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002375
2376#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002377 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002378 pDSDumpDot((char*)"triTest2.dot");
2379#endif
2380 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002381 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07002382
2383 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002384 EndCommandBuffer();
2385 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002386
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002387 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002388}
2389
Tony Barbour6918cd52015-04-09 12:58:51 -06002390TEST_F(VkRenderTest, TriangleFSUniformBlockBinding)
Tony Barboure2c58df2014-11-25 13:18:32 -07002391{
2392 // This test allows the shader to select which buffer it is
2393 // pulling from using layout binding qualifier.
2394 // There are corresponding changes in the compiler stack that
2395 // will select the buffer using binding directly.
2396 // The binding number should match the slot number set up by
2397 // the application.
2398 // The expected result from this test is a purple triangle
2399
2400 static const char *vertShaderText =
2401 "#version 140\n"
2402 "#extension GL_ARB_separate_shader_objects : enable\n"
2403 "#extension GL_ARB_shading_language_420pack : enable\n"
2404 "void main() {\n"
2405 " vec2 vertices[3];"
2406 " vertices[0] = vec2(-0.5, -0.5);\n"
2407 " vertices[1] = vec2( 0.5, -0.5);\n"
2408 " vertices[2] = vec2( 0.5, 0.5);\n"
2409 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2410 "}\n";
2411
2412 static const char *fragShaderText =
2413 "#version 140\n"
2414 "#extension GL_ARB_separate_shader_objects : enable\n"
2415 "#extension GL_ARB_shading_language_420pack : enable\n"
2416 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2417 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2418 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wu11078b02015-01-04 16:27:24 +08002419 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
GregFaae75242015-06-03 18:40:50 -06002420 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002421 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06002422 " outColor = myBlueVal.color;\n"
2423 " outColor += myRedVal.color;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002424 "}\n";
2425
2426 ASSERT_NO_FATAL_FAILURE(InitState());
2427 ASSERT_NO_FATAL_FAILURE(InitViewport());
2428
Tony Barbour6918cd52015-04-09 12:58:51 -06002429 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2430 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002431
2432 // We're going to create a number of uniform buffers, and then allow
2433 // the shader to select which it wants to read from with a binding
2434
2435 // Let's populate the buffers with a single color each:
2436 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2437 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2438 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wu11078b02015-01-04 16:27:24 +08002439 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barboure2c58df2014-11-25 13:18:32 -07002440
2441 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2442 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2443 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2444 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2445
2446 const int redCount = sizeof(redVals) / sizeof(float);
2447 const int greenCount = sizeof(greenVals) / sizeof(float);
2448 const int blueCount = sizeof(blueVals) / sizeof(float);
2449 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2450
Tony Barbour6918cd52015-04-09 12:58:51 -06002451 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002452
Tony Barbour6918cd52015-04-09 12:58:51 -06002453 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002454
Tony Barbour6918cd52015-04-09 12:58:51 -06002455 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002456
Tony Barbour6918cd52015-04-09 12:58:51 -06002457 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002458
Tony Barbour6918cd52015-04-09 12:58:51 -06002459 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002460 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002461 pipelineobj.AddShader(&vs);
2462 pipelineobj.AddShader(&ps);
2463
Tony Barbour6918cd52015-04-09 12:58:51 -06002464 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002465 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2466 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2467 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2468 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002469
Tony Barbour664accc2015-01-09 12:55:14 -07002470 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002471 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure2c58df2014-11-25 13:18:32 -07002472
Tony Barbourfe3351b2015-07-28 10:17:20 -06002473 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002474
2475#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002476 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002477 pDSDumpDot((char*)"triTest2.dot");
2478#endif
2479 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002480 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07002481
2482 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002483 EndCommandBuffer();
2484 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002485
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002486 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002487}
2488
Tony Barbour6918cd52015-04-09 12:58:51 -06002489TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBinding)
Tony Barboure2c58df2014-11-25 13:18:32 -07002490{
2491 // This test is the same as TriangleFSUniformBlockBinding, but
2492 // it does not provide an instance name.
2493 // The expected result from this test is a purple triangle
2494
2495 static const char *vertShaderText =
2496 "#version 140\n"
2497 "#extension GL_ARB_separate_shader_objects : enable\n"
2498 "#extension GL_ARB_shading_language_420pack : enable\n"
2499 "void main() {\n"
2500 " vec2 vertices[3];"
2501 " vertices[0] = vec2(-0.5, -0.5);\n"
2502 " vertices[1] = vec2( 0.5, -0.5);\n"
2503 " vertices[2] = vec2( 0.5, 0.5);\n"
2504 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2505 "}\n";
2506
2507 static const char *fragShaderText =
2508 "#version 430\n"
2509 "#extension GL_ARB_separate_shader_objects : enable\n"
2510 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002511 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2512 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2513 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wu11078b02015-01-04 16:27:24 +08002514 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northropd43c52e2014-12-05 15:44:14 -07002515 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002516 "void main() {\n"
Cody Northropd43c52e2014-12-05 15:44:14 -07002517 " outColor = blue;\n"
2518 " outColor += red;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002519 "}\n";
2520 ASSERT_NO_FATAL_FAILURE(InitState());
2521 ASSERT_NO_FATAL_FAILURE(InitViewport());
2522
Tony Barbour6918cd52015-04-09 12:58:51 -06002523 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2524 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002525
2526 // We're going to create a number of uniform buffers, and then allow
2527 // the shader to select which it wants to read from with a binding
2528
2529 // Let's populate the buffers with a single color each:
2530 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2531 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2532 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2533 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2534
2535 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2536 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2537 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2538 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2539
2540 const int redCount = sizeof(redVals) / sizeof(float);
2541 const int greenCount = sizeof(greenVals) / sizeof(float);
2542 const int blueCount = sizeof(blueVals) / sizeof(float);
2543 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2544
Tony Barbour6918cd52015-04-09 12:58:51 -06002545 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002546
Tony Barbour6918cd52015-04-09 12:58:51 -06002547 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002548
Tony Barbour6918cd52015-04-09 12:58:51 -06002549 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002550
Tony Barbour6918cd52015-04-09 12:58:51 -06002551 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002552
Tony Barbour6918cd52015-04-09 12:58:51 -06002553 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002554 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002555 pipelineobj.AddShader(&vs);
2556 pipelineobj.AddShader(&ps);
2557
Tony Barbour6918cd52015-04-09 12:58:51 -06002558 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002559 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2560 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2561 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2562 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002563
Tony Barbour664accc2015-01-09 12:55:14 -07002564 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002565 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002566
Tony Barbourfe3351b2015-07-28 10:17:20 -06002567 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002568
2569#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002570 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002571 pDSDumpDot((char*)"triTest2.dot");
2572#endif
2573 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002574 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07002575
2576 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002577 EndCommandBuffer();
2578 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002579
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002580 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002581}
2582
GregF6084aec2015-07-01 16:11:09 -06002583TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBindingWithStruct)
2584{
2585 // This test is the same as TriangleFSUniformBlockBinding, but
2586 // it does not provide an instance name.
2587 // The expected result from this test is a purple triangle
2588
2589 static const char *vertShaderText =
2590 "#version 140\n"
2591 "#extension GL_ARB_separate_shader_objects : enable\n"
2592 "#extension GL_ARB_shading_language_420pack : enable\n"
2593 "void main() {\n"
2594 " vec2 vertices[3];"
2595 " vertices[0] = vec2(-0.5, -0.5);\n"
2596 " vertices[1] = vec2( 0.5, -0.5);\n"
2597 " vertices[2] = vec2( 0.5, 0.5);\n"
2598 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2599 "}\n";
2600
2601 static const char *fragShaderText =
2602 "#version 430\n"
2603 "#extension GL_ARB_separate_shader_objects : enable\n"
2604 "#extension GL_ARB_shading_language_420pack : enable\n"
2605 "\n"
2606 " struct PS_INPUT {\n"
2607 " vec2 member0;\n"
2608 " vec4 member1;\n"
2609 " vec4 member2;\n"
2610 " vec4 member3;\n"
2611 " vec4 member4;\n"
2612 " vec4 member5;\n"
2613 " vec4 member6;\n"
2614 " vec4 member7;\n"
2615 " vec4 member8;\n"
2616 " vec4 member9;\n"
2617 " };\n"
2618 "\n"
2619 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2620 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2621 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2622 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
2623 "layout (location = 0) out vec4 outColor;\n"
2624 "PS_INPUT MainFs()\n"
2625 "{\n"
2626 " PS_INPUT o;\n"
2627 " o.member9 = red;\n"
2628 " return o;\n"
2629 "}\n"
2630 "\n"
2631 "void main()\n"
2632 "{\n"
2633 " PS_INPUT o;\n"
2634 " o = MainFs();\n"
2635 " outColor = blue;"
2636 " outColor += o.member9;\n"
2637 "}\n";;
2638 ASSERT_NO_FATAL_FAILURE(InitState());
2639 ASSERT_NO_FATAL_FAILURE(InitViewport());
2640
2641 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2642 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2643
2644 // We're going to create a number of uniform buffers, and then allow
2645 // the shader to select which it wants to read from with a binding
2646
2647 // Let's populate the buffers with a single color each:
2648 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2649 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2650 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2651 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2652
2653 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2654 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2655 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2656 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2657
2658 const int redCount = sizeof(redVals) / sizeof(float);
2659 const int greenCount = sizeof(greenVals) / sizeof(float);
2660 const int blueCount = sizeof(blueVals) / sizeof(float);
2661 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2662
2663 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2664
2665 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2666
2667 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2668
2669 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
2670
2671 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002672 pipelineobj.AddColorAttachment();
GregF6084aec2015-07-01 16:11:09 -06002673 pipelineobj.AddShader(&vs);
2674 pipelineobj.AddShader(&ps);
2675
2676 VkDescriptorSetObj descriptorSet(m_device);
2677 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2678 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2679 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2680 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
2681
2682 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002683 ASSERT_VK_SUCCESS(BeginCommandBuffer());
GregF6084aec2015-07-01 16:11:09 -06002684
Tony Barbourfe3351b2015-07-28 10:17:20 -06002685 GenericDrawPreparation(pipelineobj, descriptorSet);
GregF6084aec2015-07-01 16:11:09 -06002686
2687#ifdef DUMP_STATE_DOT
2688 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
2689 pDSDumpDot((char*)"triTest2.dot");
2690#endif
2691 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002692 Draw(0, 3, 0, 1);
GregF6084aec2015-07-01 16:11:09 -06002693
2694 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002695 EndCommandBuffer();
2696 QueueCommandBuffer();
GregF6084aec2015-07-01 16:11:09 -06002697
2698 RecordImages(m_renderTargets);
2699}
2700
Tony Barbour6918cd52015-04-09 12:58:51 -06002701TEST_F(VkRenderTest, CubeWithVertexFetchAndMVPAndTexture)
Tony Barboure2c58df2014-11-25 13:18:32 -07002702{
2703 static const char *vertShaderText =
2704 "#version 140\n"
2705 "#extension GL_ARB_separate_shader_objects : enable\n"
2706 "#extension GL_ARB_shading_language_420pack : enable\n"
2707 "layout (std140, binding=0) uniform bufferVals {\n"
2708 " mat4 mvp;\n"
2709 "} myBufferVals;\n"
2710 "layout (location=0) in vec4 pos;\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002711 "layout (location=1) in vec2 input_uv;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002712 "layout (location=0) out vec2 UV;\n"
2713 "void main() {\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002714 " UV = input_uv;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002715 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002716 " gl_Position.y = -gl_Position.y;\n"
2717 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002718 "}\n";
2719
2720 static const char *fragShaderText =
2721 "#version 140\n"
2722 "#extension GL_ARB_separate_shader_objects : enable\n"
2723 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wu11078b02015-01-04 16:27:24 +08002724 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002725 "layout (location=0) out vec4 outColor;\n"
2726 "layout (location=0) in vec2 UV;\n"
2727 "void main() {\n"
2728 " outColor= textureLod(surface, UV, 0.0);\n"
2729 "}\n";
2730 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2731
2732 glm::mat4 View = glm::lookAt(
2733 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2734 glm::vec3(0,0,0), // and looks at the origin
2735 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2736 );
2737
2738 glm::mat4 Model = glm::mat4(1.0f);
2739
2740 glm::mat4 MVP = Projection * View * Model;
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002741 int num_verts = sizeof(g_vb_texture_Data) / sizeof(g_vb_texture_Data[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002742
2743
2744 ASSERT_NO_FATAL_FAILURE(InitState());
2745 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wub4052042015-07-09 10:16:34 +08002746 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Chia-I Wu08accc62015-07-07 11:50:03 +08002747 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height, m_depth_stencil_fmt);
Tony Barboure2c58df2014-11-25 13:18:32 -07002748
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002749 VkConstantBufferObj meshBuffer(m_device, num_verts,
2750 sizeof(g_vb_texture_Data[0]), g_vb_texture_Data);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00002751 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07002752
Mark Lobodzinski17caf572015-01-29 08:55:56 -06002753 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barboure2c58df2014-11-25 13:18:32 -07002754
Tony Barbour6918cd52015-04-09 12:58:51 -06002755 VkConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2756 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2757 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2758 VkSamplerObj sampler(m_device);
2759 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002760
Tony Barbour6918cd52015-04-09 12:58:51 -06002761 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002762 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002763 pipelineobj.AddShader(&vs);
2764 pipelineobj.AddShader(&ps);
2765
Tony Barbour6918cd52015-04-09 12:58:51 -06002766 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002767 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mvpBuffer);
Chia-I Wu11078b02015-01-04 16:27:24 +08002768 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002769
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002770#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002771 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002772 MESH_BIND_ID, // binding ID
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002773 sizeof(g_vb_texture_Data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002774 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002775 };
Tony Barboure2c58df2014-11-25 13:18:32 -07002776
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002777 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002778 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2779 vi_attribs[0].location = 0; // location
Tony Barbourd1c35722015-04-16 15:59:00 -06002780 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002781 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2782 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2783 vi_attribs[1].location = 1; // location
2784 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
2785 vi_attribs[1].offsetInBytes = 16; // Offset of uv components
Tony Barboure2c58df2014-11-25 13:18:32 -07002786
Tony Barboure2c58df2014-11-25 13:18:32 -07002787 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002788 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2789 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barboure2c58df2014-11-25 13:18:32 -07002790
Tony Barbourdd6e32e2015-07-10 15:29:03 -06002791 VkPipelineDepthStencilStateCreateInfo ds_state;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002792 ds_state.depthTestEnable = VK_TRUE;
2793 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbourd1c35722015-04-16 15:59:00 -06002794 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002795 ds_state.depthBoundsEnable = VK_FALSE;
2796 ds_state.stencilTestEnable = VK_FALSE;
2797 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
2798 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
2799 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbourd1c35722015-04-16 15:59:00 -06002800 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
Tony Barbourf52346d2015-01-16 14:27:35 -07002801 ds_state.front = ds_state.back;
2802 pipelineobj.SetDepthStencil(&ds_state);
2803
Tony Barbour1c45ce02015-03-27 17:03:18 -06002804 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tobin Ehlisf1878c72015-08-18 14:24:32 -06002805
2806 VkCmdBufferBeginInfo cbBeginInfo;
2807 memset(&cbBeginInfo, 0, sizeof(VkCmdBufferBeginInfo));
2808 cbBeginInfo.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
2809 cbBeginInfo.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT;
2810 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barboure2c58df2014-11-25 13:18:32 -07002811
Tony Barbourfe3351b2015-07-28 10:17:20 -06002812 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002813
Tony Barbourfe3351b2015-07-28 10:17:20 -06002814 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002815#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002816 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002817 pDSDumpDot((char*)"triTest2.dot");
2818#endif
2819 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002820 Draw(0, num_verts, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07002821
2822 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002823 EndCommandBuffer();
2824 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002825
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002826 RecordImages(m_renderTargets);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002827 RotateTriangleVSUniform(Projection, View, Model, &mvpBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002828}
Cody Northropf1990a92014-12-09 11:17:01 -07002829
Tony Barbour6918cd52015-04-09 12:58:51 -06002830TEST_F(VkRenderTest, TriangleMixedSamplerUniformBlockBinding)
Cody Northropf1990a92014-12-09 11:17:01 -07002831{
2832 // This test mixes binding slots of textures and buffers, ensuring
2833 // that sparse and overlapping assignments work.
Cody Northropb110b4f2014-12-09 13:59:39 -07002834 // The expected result from this test is a purple triangle, although
Cody Northropf1990a92014-12-09 11:17:01 -07002835 // you can modify it to move the desired result around.
2836
2837 static const char *vertShaderText =
2838 "#version 140\n"
2839 "#extension GL_ARB_separate_shader_objects : enable\n"
2840 "#extension GL_ARB_shading_language_420pack : enable\n"
2841 "void main() {\n"
2842 " vec2 vertices[3];"
2843 " vertices[0] = vec2(-0.5, -0.5);\n"
2844 " vertices[1] = vec2( 0.5, -0.5);\n"
2845 " vertices[2] = vec2( 0.5, 0.5);\n"
2846 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2847 "}\n";
2848
2849 static const char *fragShaderText =
2850 "#version 430\n"
2851 "#extension GL_ARB_separate_shader_objects : enable\n"
2852 "#extension GL_ARB_shading_language_420pack : enable\n"
2853 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wu11078b02015-01-04 16:27:24 +08002854 "layout (binding = 3) uniform sampler2D surface1;\n"
2855 "layout (binding = 1) uniform sampler2D surface2;\n"
2856 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002857
Cody Northropb110b4f2014-12-09 13:59:39 -07002858
Chia-I Wu11078b02015-01-04 16:27:24 +08002859 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2860 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2861 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2862 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropf1990a92014-12-09 11:17:01 -07002863 "layout (location = 0) out vec4 outColor;\n"
2864 "void main() {\n"
Cody Northropb110b4f2014-12-09 13:59:39 -07002865 " outColor = red * vec4(0.00001);\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002866 " outColor += white * vec4(0.00001);\n"
2867 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropb110b4f2014-12-09 13:59:39 -07002868 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002869 "}\n";
2870 ASSERT_NO_FATAL_FAILURE(InitState());
2871 ASSERT_NO_FATAL_FAILURE(InitViewport());
2872
Tony Barbour6918cd52015-04-09 12:58:51 -06002873 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2874 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northropf1990a92014-12-09 11:17:01 -07002875
Cody Northropf1990a92014-12-09 11:17:01 -07002876 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2877 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2878 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2879 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2880
2881 const int redCount = sizeof(redVals) / sizeof(float);
2882 const int greenCount = sizeof(greenVals) / sizeof(float);
2883 const int blueCount = sizeof(blueVals) / sizeof(float);
2884 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2885
Tony Barbour6918cd52015-04-09 12:58:51 -06002886 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2887 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2888 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2889 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropf1990a92014-12-09 11:17:01 -07002890
Tony Barbourebc093f2015-04-01 16:38:10 -06002891 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour6918cd52015-04-09 12:58:51 -06002892 VkSamplerObj sampler0(m_device);
2893 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbourebc093f2015-04-01 16:38:10 -06002894 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour6918cd52015-04-09 12:58:51 -06002895 VkSamplerObj sampler2(m_device);
2896 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbourebc093f2015-04-01 16:38:10 -06002897 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour6918cd52015-04-09 12:58:51 -06002898 VkSamplerObj sampler4(m_device);
2899 VkTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropb110b4f2014-12-09 13:59:39 -07002900
2901 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2902 // TODO: Get back here ASAP and understand why.
Tony Barbourebc093f2015-04-01 16:38:10 -06002903 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour6918cd52015-04-09 12:58:51 -06002904 VkSamplerObj sampler7(m_device);
2905 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropf1990a92014-12-09 11:17:01 -07002906
Tony Barbour6918cd52015-04-09 12:58:51 -06002907 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002908 pipelineobj.AddColorAttachment();
Cody Northropf1990a92014-12-09 11:17:01 -07002909 pipelineobj.AddShader(&vs);
2910 pipelineobj.AddShader(&ps);
2911
Tony Barbour6918cd52015-04-09 12:58:51 -06002912 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002913 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2914 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2915 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2916 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002917 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
Chia-I Wu11078b02015-01-04 16:27:24 +08002918 // swap blue and green
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002919 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2920 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2921 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropf1990a92014-12-09 11:17:01 -07002922
Tony Barbour664accc2015-01-09 12:55:14 -07002923 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002924 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropf1990a92014-12-09 11:17:01 -07002925
Tony Barbourfe3351b2015-07-28 10:17:20 -06002926 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002927
2928#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002929 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002930 pDSDumpDot((char*)"triTest2.dot");
2931#endif
2932 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002933 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07002934
2935 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002936 EndCommandBuffer();
2937 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002938
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002939 RecordImages(m_renderTargets);
Cody Northropf1990a92014-12-09 11:17:01 -07002940}
2941
Tony Barbour6918cd52015-04-09 12:58:51 -06002942TEST_F(VkRenderTest, TriangleMatchingSamplerUniformBlockBinding)
Cody Northropbd531de2014-12-09 19:08:54 -07002943{
2944 // This test matches binding slots of textures and buffers, requiring
2945 // the driver to give them distinct number spaces.
2946 // The expected result from this test is a red triangle, although
2947 // you can modify it to move the desired result around.
2948
2949 static const char *vertShaderText =
2950 "#version 140\n"
2951 "#extension GL_ARB_separate_shader_objects : enable\n"
2952 "#extension GL_ARB_shading_language_420pack : enable\n"
2953 "void main() {\n"
2954 " vec2 vertices[3];"
2955 " vertices[0] = vec2(-0.5, -0.5);\n"
2956 " vertices[1] = vec2( 0.5, -0.5);\n"
2957 " vertices[2] = vec2( 0.5, 0.5);\n"
2958 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2959 "}\n";
2960
2961 static const char *fragShaderText =
2962 "#version 430\n"
2963 "#extension GL_ARB_separate_shader_objects : enable\n"
2964 "#extension GL_ARB_shading_language_420pack : enable\n"
2965 "layout (binding = 0) uniform sampler2D surface0;\n"
2966 "layout (binding = 1) uniform sampler2D surface1;\n"
2967 "layout (binding = 2) uniform sampler2D surface2;\n"
2968 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wu11078b02015-01-04 16:27:24 +08002969 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2970 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2971 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2972 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropbd531de2014-12-09 19:08:54 -07002973 "layout (location = 0) out vec4 outColor;\n"
2974 "void main() {\n"
2975 " outColor = red;// * vec4(0.00001);\n"
2976 " outColor += white * vec4(0.00001);\n"
2977 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2978 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2979 "}\n";
2980 ASSERT_NO_FATAL_FAILURE(InitState());
2981 ASSERT_NO_FATAL_FAILURE(InitViewport());
2982
Tony Barbour6918cd52015-04-09 12:58:51 -06002983 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2984 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northropbd531de2014-12-09 19:08:54 -07002985
2986 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2987 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2988 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2989 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2990
2991 const int redCount = sizeof(redVals) / sizeof(float);
2992 const int greenCount = sizeof(greenVals) / sizeof(float);
2993 const int blueCount = sizeof(blueVals) / sizeof(float);
2994 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2995
Tony Barbour6918cd52015-04-09 12:58:51 -06002996 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2997 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2998 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2999 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropbd531de2014-12-09 19:08:54 -07003000
Tony Barbourebc093f2015-04-01 16:38:10 -06003001 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour6918cd52015-04-09 12:58:51 -06003002 VkSamplerObj sampler0(m_device);
3003 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbourebc093f2015-04-01 16:38:10 -06003004 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour6918cd52015-04-09 12:58:51 -06003005 VkSamplerObj sampler2(m_device);
3006 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbourebc093f2015-04-01 16:38:10 -06003007 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour6918cd52015-04-09 12:58:51 -06003008 VkSamplerObj sampler4(m_device);
3009 VkTextureObj texture4(m_device, tex_colors); // Light Green
Tony Barbourebc093f2015-04-01 16:38:10 -06003010 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour6918cd52015-04-09 12:58:51 -06003011 VkSamplerObj sampler7(m_device);
3012 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropbd531de2014-12-09 19:08:54 -07003013
Tony Barbour6918cd52015-04-09 12:58:51 -06003014 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003015 pipelineobj.AddColorAttachment();
Cody Northropbd531de2014-12-09 19:08:54 -07003016 pipelineobj.AddShader(&vs);
3017 pipelineobj.AddShader(&ps);
3018
Tony Barbour6918cd52015-04-09 12:58:51 -06003019 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08003020 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3021 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3022 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
3023 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003024 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
3025 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
3026 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
3027 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropbd531de2014-12-09 19:08:54 -07003028
Tony Barbour664accc2015-01-09 12:55:14 -07003029 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003030 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropbd531de2014-12-09 19:08:54 -07003031
Tony Barbourfe3351b2015-07-28 10:17:20 -06003032 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07003033
3034#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003035 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07003036 pDSDumpDot((char*)"triTest2.dot");
3037#endif
3038 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06003039 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07003040
3041 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003042 EndCommandBuffer();
3043 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07003044
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06003045 RecordImages(m_renderTargets);
Cody Northropbd531de2014-12-09 19:08:54 -07003046}
3047
Tony Barbour6918cd52015-04-09 12:58:51 -06003048TEST_F(VkRenderTest, TriangleUniformBufferLayout)
Cody Northrop04ad1202014-12-17 15:26:33 -07003049{
3050 // This test populates a buffer with a variety of different data
3051 // types, then reads them out with a shader.
3052 // The expected result from this test is a green triangle
3053
3054 static const char *vertShaderText =
3055 "#version 140\n"
3056 "#extension GL_ARB_separate_shader_objects : enable\n"
3057 "#extension GL_ARB_shading_language_420pack : enable\n"
3058 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3059 " vec4 fRed;\n"
3060 " vec4 fGreen;\n"
3061 " layout(row_major) mat4 worldToProj;\n"
3062 " layout(row_major) mat4 projToWorld;\n"
3063 " layout(row_major) mat4 worldToView;\n"
3064 " layout(row_major) mat4 viewToProj;\n"
3065 " layout(row_major) mat4 worldToShadow[4];\n"
3066 " float fZero;\n"
3067 " float fOne;\n"
3068 " float fTwo;\n"
3069 " float fThree;\n"
3070 " vec3 fZeroZeroZero;\n"
3071 " float fFour;\n"
3072 " vec3 fZeroZeroOne;\n"
3073 " float fFive;\n"
3074 " vec3 fZeroOneZero;\n"
3075 " float fSix;\n"
3076 " float fSeven;\n"
3077 " float fEight;\n"
3078 " float fNine;\n"
3079 " vec2 fZeroZero;\n"
3080 " vec2 fZeroOne;\n"
3081 " vec4 fBlue;\n"
3082 " vec2 fOneZero;\n"
3083 " vec2 fOneOne;\n"
3084 " vec3 fZeroOneOne;\n"
3085 " float fTen;\n"
3086 " float fEleven;\n"
3087 " float fTwelve;\n"
3088 " vec3 fOneZeroZero;\n"
3089 " vec4 uvOffsets[4];\n"
3090 "};\n"
3091 "layout (location = 0) out vec4 color;"
3092 "void main() {\n"
3093
3094 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3095 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3096 " \n"
3097
3098 // do some exact comparisons, even though we should
3099 // really have an epsilon involved.
3100 " vec4 outColor = right;\n"
3101 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3102 " outColor = wrong;\n"
3103 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3104 " outColor = wrong;\n"
3105 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3106 " outColor = wrong;\n"
3107
3108 " color = outColor;\n"
3109
3110 // generic position stuff
3111 " vec2 vertices;\n"
3112 " int vertexSelector = gl_VertexID;\n"
3113 " if (vertexSelector == 0)\n"
3114 " vertices = vec2(-0.5, -0.5);\n"
3115 " else if (vertexSelector == 1)\n"
3116 " vertices = vec2( 0.5, -0.5);\n"
3117 " else if (vertexSelector == 2)\n"
3118 " vertices = vec2( 0.5, 0.5);\n"
3119 " else\n"
3120 " vertices = vec2( 0.0, 0.0);\n"
3121 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3122 "}\n";
3123
3124 static const char *fragShaderText =
3125 "#version 140\n"
3126 "#extension GL_ARB_separate_shader_objects : enable\n"
3127 "#extension GL_ARB_shading_language_420pack : enable\n"
3128 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3129 " vec4 fRed;\n"
3130 " vec4 fGreen;\n"
3131 " layout(row_major) mat4 worldToProj;\n"
3132 " layout(row_major) mat4 projToWorld;\n"
3133 " layout(row_major) mat4 worldToView;\n"
3134 " layout(row_major) mat4 viewToProj;\n"
3135 " layout(row_major) mat4 worldToShadow[4];\n"
3136 " float fZero;\n"
3137 " float fOne;\n"
3138 " float fTwo;\n"
3139 " float fThree;\n"
3140 " vec3 fZeroZeroZero;\n"
3141 " float fFour;\n"
3142 " vec3 fZeroZeroOne;\n"
3143 " float fFive;\n"
3144 " vec3 fZeroOneZero;\n"
3145 " float fSix;\n"
3146 " float fSeven;\n"
3147 " float fEight;\n"
3148 " float fNine;\n"
3149 " vec2 fZeroZero;\n"
3150 " vec2 fZeroOne;\n"
3151 " vec4 fBlue;\n"
3152 " vec2 fOneZero;\n"
3153 " vec2 fOneOne;\n"
3154 " vec3 fZeroOneOne;\n"
3155 " float fTen;\n"
3156 " float fEleven;\n"
3157 " float fTwelve;\n"
3158 " vec3 fOneZeroZero;\n"
3159 " vec4 uvOffsets[4];\n"
3160 "};\n"
3161 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06003162 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop04ad1202014-12-17 15:26:33 -07003163 "void main() {\n"
3164 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3165 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3166 " \n"
3167
3168 // start with VS value to ensure it passed
3169 " vec4 outColor = color;\n"
3170
3171 // do some exact comparisons, even though we should
3172 // really have an epsilon involved.
3173 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3174 " outColor = wrong;\n"
3175 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3176 " outColor = wrong;\n"
3177 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3178 " outColor = wrong;\n"
3179 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3180 " outColor = wrong;\n"
3181 " if (fTwo != 2.0)\n"
3182 " outColor = wrong;\n"
3183 " if (fOneOne != vec2(1.0, 1.0))\n"
3184 " outColor = wrong;\n"
3185 " if (fTen != 10.0)\n"
3186 " outColor = wrong;\n"
3187 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3188 " outColor = wrong;\n"
3189 " \n"
GregFaae75242015-06-03 18:40:50 -06003190 " uFragColor = outColor;\n"
Cody Northrop04ad1202014-12-17 15:26:33 -07003191 "}\n";
3192
3193
Cody Northropd2ad0342015-08-05 11:15:02 -06003194 const float mixedVals[196] = { 1.0f, 0.0f, 0.0f, 1.0f, // vec4 fRed; // align
3195 0.0f, 1.0f, 0.0f, 1.0f, // vec4 fGreen; // align
3196 1.0f, 0.0f, 0.0f, 1.0f, // layout(row_major) mat4 worldToProj;
3197 0.0f, 1.0f, 0.0f, 1.0f, // align
3198 0.0f, 0.0f, 1.0f, 1.0f, // align
3199 0.0f, 0.0f, 0.0f, 1.0f, // align
3200 2.0f, 0.0f, 0.0f, 2.0f, // layout(row_major) mat4 projToWorld;
3201 0.0f, 2.0f, 0.0f, 2.0f, // align
3202 0.0f, 0.0f, 2.0f, 2.0f, // align
3203 0.0f, 0.0f, 0.0f, 2.0f, // align
3204 3.0f, 0.0f, 0.0f, 3.0f, // layout(row_major) mat4 worldToView;
3205 0.0f, 3.0f, 0.0f, 3.0f, // align
3206 0.0f, 0.0f, 3.0f, 3.0f, // align
3207 0.0f, 0.0f, 0.0f, 3.0f, // align
3208 4.0f, 0.0f, 0.0f, 4.0f, // layout(row_major) mat4 viewToProj;
3209 0.0f, 4.0f, 0.0f, 4.0f, // align
3210 0.0f, 0.0f, 4.0f, 4.0f, // align
3211 0.0f, 0.0f, 0.0f, 4.0f, // align
3212 5.0f, 0.0f, 0.0f, 5.0f, // layout(row_major) mat4 worldToShadow[4];
3213 0.0f, 5.0f, 0.0f, 5.0f, // align
3214 0.0f, 0.0f, 5.0f, 5.0f, // align
3215 0.0f, 0.0f, 0.0f, 5.0f, // align
3216 6.0f, 0.0f, 0.0f, 6.0f, // align
3217 0.0f, 6.0f, 0.0f, 6.0f, // align
3218 0.0f, 0.0f, 6.0f, 6.0f, // align
3219 0.0f, 0.0f, 0.0f, 6.0f, // align
3220 7.0f, 0.0f, 0.0f, 7.0f, // align
3221 0.0f, 7.0f, 0.0f, 7.0f, // align
3222 0.0f, 0.0f, 7.0f, 7.0f, // align
3223 0.0f, 0.0f, 0.0f, 7.0f, // align
3224 8.0f, 0.0f, 0.0f, 8.0f, // align
3225 0.0f, 8.0f, 0.0f, 8.0f, // align
3226 0.0f, 0.0f, 8.0f, 8.0f, // align
3227 0.0f, 0.0f, 0.0f, 8.0f, // align
3228 0.0f, // float fZero; // align
3229 1.0f, // float fOne; // pack
3230 2.0f, // float fTwo; // pack
3231 3.0f, // float fThree; // pack
3232 0.0f, 0.0f, 0.0f, // vec3 fZeroZeroZero; // align
3233 4.0f, // float fFour; // pack
3234 0.0f, 0.0f, 1.0f, // vec3 fZeroZeroOne; // align
3235 5.0f, // float fFive; // pack
3236 0.0f, 1.0f, 0.0f, // vec3 fZeroOneZero; // align
3237 6.0f, // float fSix; // pack
3238 7.0f, // float fSeven; // align
3239 8.0f, // float fEight; // pack
3240 9.0f, // float fNine; // pack
3241 0.0f, // BUFFER
3242 0.0f, 0.0f, // vec2 fZeroZero; // align
3243 0.0f, 1.0f, // vec2 fZeroOne; // pack
3244 0.0f, 0.0f, 1.0f, 1.0f, // vec4 fBlue; // align
3245 1.0f, 0.0f, // vec2 fOneZero; // align
3246 1.0f, 1.0f, // vec2 fOneOne; // pack
3247 0.0f, 1.0f, 1.0f, // vec3 fZeroOneOne; // align
3248 10.0f, // float fTen; // pack
3249 11.0f, // float fEleven; // align
3250 12.0f, // float fTwelve; // pack
3251 0.0f, 0.0f, // BUFFER
3252 1.0f, 0.0f, 0.0f, // vec3 fOneZeroZero; // align
3253 0.0f, // BUFFER
3254 0.1f, 0.2f, 0.3f, 0.4f, // vec4 uvOffsets[4];
3255 0.5f, 0.6f, 0.7f, 0.8f, // align
3256 0.9f, 1.0f, 1.1f, 1.2f, // align
3257 1.3f, 1.4f, 1.5f, 1.6f, // align
Cody Northrop04ad1202014-12-17 15:26:33 -07003258 };
3259
3260 ASSERT_NO_FATAL_FAILURE(InitState());
3261 ASSERT_NO_FATAL_FAILURE(InitViewport());
3262
3263 const int constCount = sizeof(mixedVals) / sizeof(float);
3264
Tony Barbour6918cd52015-04-09 12:58:51 -06003265 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3266 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop04ad1202014-12-17 15:26:33 -07003267
Tony Barbour6918cd52015-04-09 12:58:51 -06003268 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop04ad1202014-12-17 15:26:33 -07003269
Tony Barbour6918cd52015-04-09 12:58:51 -06003270 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003271 pipelineobj.AddColorAttachment();
Cody Northrop04ad1202014-12-17 15:26:33 -07003272 pipelineobj.AddShader(&vs);
3273 pipelineobj.AddShader(&ps);
3274
Tony Barbour6918cd52015-04-09 12:58:51 -06003275 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003276 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
Cody Northrop04ad1202014-12-17 15:26:33 -07003277
3278 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003279 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop04ad1202014-12-17 15:26:33 -07003280
Tony Barbourfe3351b2015-07-28 10:17:20 -06003281 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop04ad1202014-12-17 15:26:33 -07003282
3283#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003284 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop04ad1202014-12-17 15:26:33 -07003285 pDSDumpDot((char*)"triTest2.dot");
3286#endif
3287 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06003288 Draw(0, 3, 0, 1);
Cody Northrop04ad1202014-12-17 15:26:33 -07003289
3290 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003291 EndCommandBuffer();
3292 QueueCommandBuffer();
Cody Northrop04ad1202014-12-17 15:26:33 -07003293
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06003294 RecordImages(m_renderTargets);
Cody Northrop04ad1202014-12-17 15:26:33 -07003295}
3296
Cody Northrop95638152015-05-07 14:39:12 -06003297TEST_F(VkRenderTest, TextureGather)
3298{
3299 // This test introduces textureGather and textureGatherOffset
3300 // Each call is compared against an expected inline color result
3301 // Green triangle means everything worked as expected
3302 // Red means something went wrong
3303
Cody Northropc55900f2015-08-06 13:18:13 -06003304 // disable SPV until texture gather is turned on in glsl->SPV
3305 if (!m_use_glsl) {
3306 printf("Skipping test that requires GLSL path (TextureGather)\n");
3307 return;
3308 }
3309
Cody Northrop50a2a4b2015-06-03 16:49:20 -06003310 ScopedUseGlsl useGlsl(true);
Cody Northrop95638152015-05-07 14:39:12 -06003311
3312 static const char *vertShaderText =
3313 "#version 140\n"
3314 "#extension GL_ARB_separate_shader_objects : enable\n"
3315 "#extension GL_ARB_shading_language_420pack : enable\n"
3316 "void main() {\n"
3317 " vec2 vertices[3];"
3318 " vertices[0] = vec2(-0.5, -0.5);\n"
3319 " vertices[1] = vec2( 0.5, -0.5);\n"
3320 " vertices[2] = vec2( 0.5, 0.5);\n"
3321 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
3322 "}\n";
3323
3324 static const char *fragShaderText =
3325 "#version 430\n"
3326 "#extension GL_ARB_separate_shader_objects : enable\n"
3327 "#extension GL_ARB_shading_language_420pack : enable\n"
3328 "layout (binding = 0) uniform sampler2D surface0;\n"
3329 "layout (binding = 1) uniform sampler2D surface1;\n"
3330 "layout (binding = 2) uniform sampler2D surface2;\n"
3331 "layout (binding = 3) uniform sampler2D surface3;\n"
3332 "layout (location = 0) out vec4 outColor;\n"
3333 "void main() {\n"
3334
3335 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3336 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3337
3338 " vec4 color = right;\n"
3339
3340 // Grab a normal texture sample to ensure it can work in conjuntion
3341 // with textureGather (there are some intracacies in the backend)
3342 " vec4 sampledColor = textureLod(surface2, vec2(0.5), 0.0);\n"
3343 " if (sampledColor != vec4(0.0, 0.0, 1.0, 1.0))\n"
3344 " color = wrong;\n"
3345
3346 " vec4 gatheredColor = textureGather(surface0, vec2(0.5), 0);\n"
3347 // This just grabbed four red components from a red surface
3348 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3349 " color = wrong;\n"
3350
3351 // Yes, this is using an offset of 0, we don't have enough fine grained
3352 // control of the texture contents here.
3353 " gatheredColor = textureGatherOffset(surface1, vec2(0.5), ivec2(0, 0), 1);\n"
3354 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3355 " color = wrong;\n"
3356
3357 " outColor = color;\n"
3358
3359 "}\n";
3360
3361 ASSERT_NO_FATAL_FAILURE(InitState());
3362 ASSERT_NO_FATAL_FAILURE(InitViewport());
3363
3364 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3365 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3366
3367 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
3368 VkSamplerObj sampler0(m_device);
3369 VkTextureObj texture0(m_device, tex_colors); // Red
3370 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
3371 VkSamplerObj sampler1(m_device);
3372 VkTextureObj texture1(m_device, tex_colors); // Green
3373 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
3374 VkSamplerObj sampler2(m_device);
3375 VkTextureObj texture2(m_device, tex_colors); // Blue
3376 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
3377 VkSamplerObj sampler3(m_device);
3378 VkTextureObj texture3(m_device, tex_colors); // Red and Blue
3379
3380 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003381 pipelineobj.AddColorAttachment();
Cody Northrop95638152015-05-07 14:39:12 -06003382 pipelineobj.AddShader(&vs);
3383 pipelineobj.AddShader(&ps);
3384
3385 VkDescriptorSetObj descriptorSet(m_device);
3386 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3387 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
3388 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3389 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
3390
3391 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003392 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop95638152015-05-07 14:39:12 -06003393
Tony Barbourfe3351b2015-07-28 10:17:20 -06003394 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop95638152015-05-07 14:39:12 -06003395
3396 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06003397 Draw(0, 3, 0, 1);
Cody Northrop95638152015-05-07 14:39:12 -06003398
3399 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003400 EndCommandBuffer();
3401 QueueCommandBuffer();
Cody Northrop95638152015-05-07 14:39:12 -06003402
3403 RecordImages(m_renderTargets);
Cody Northrop95638152015-05-07 14:39:12 -06003404}
3405
Cody Northrop475663c2015-04-15 11:19:06 -06003406TEST_F(VkRenderTest, GeometryShaderHelloWorld)
3407{
3408 // This test introduces a geometry shader that simply
3409 // changes the color of each vertex to red, green, blue
3410
3411 static const char *vertShaderText =
3412 "#version 140\n"
3413 "#extension GL_ARB_separate_shader_objects : enable\n"
3414 "#extension GL_ARB_shading_language_420pack : enable\n"
3415 "layout (location = 0) out vec4 color;"
3416 "void main() {\n"
3417
3418 // VS writes out red
3419 " color = vec4(1.0, 0.0, 0.0, 1.0);\n"
3420
3421 // generic position stuff
3422 " vec2 vertices;\n"
3423 " int vertexSelector = gl_VertexID;\n"
3424 " if (vertexSelector == 0)\n"
3425 " vertices = vec2(-0.5, -0.5);\n"
3426 " else if (vertexSelector == 1)\n"
3427 " vertices = vec2( 0.5, -0.5);\n"
3428 " else if (vertexSelector == 2)\n"
3429 " vertices = vec2( 0.5, 0.5);\n"
3430 " else\n"
3431 " vertices = vec2( 0.0, 0.0);\n"
3432 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3433
3434 "}\n";
3435
3436 static const char *geomShaderText =
3437 "#version 330\n"
3438 "#extension GL_ARB_separate_shader_objects : enable\n"
3439 "#extension GL_ARB_shading_language_420pack : enable\n"
3440 "layout( triangles ) in;\n"
3441 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3442 "layout( location = 0 ) in vec4 inColor[3];\n"
3443 "layout( location = 0 ) out vec4 outColor;\n"
3444 "void main()\n"
3445 "{\n"
3446
3447 // first vertex, pass through red
3448 " gl_Position = gl_in[0].gl_Position;\n"
3449 " outColor = inColor[0];\n"
3450 " EmitVertex();\n"
3451
3452 // second vertex, green
3453 " gl_Position = gl_in[1].gl_Position;\n"
3454 " outColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3455 " EmitVertex();\n"
3456
3457 // third vertex, blue
3458 " gl_Position = gl_in[2].gl_Position;\n"
3459 " outColor = vec4(0.0, 0.0, 1.0, 1.0);\n"
3460 " EmitVertex();\n"
3461
3462 // done
3463 " EndPrimitive();\n"
3464 "}\n";
3465
3466
3467 static const char *fragShaderText =
3468 "#version 140\n"
3469 "#extension GL_ARB_separate_shader_objects : enable\n"
3470 "#extension GL_ARB_shading_language_420pack : enable\n"
3471 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06003472 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003473 "void main() {\n"
3474 // pass through
GregFaae75242015-06-03 18:40:50 -06003475 " outColor = color;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003476 "}\n";
3477
3478
3479
3480 ASSERT_NO_FATAL_FAILURE(InitState());
3481 ASSERT_NO_FATAL_FAILURE(InitViewport());
3482
3483 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3484 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3485 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3486
3487 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003488 pipelineobj.AddColorAttachment();
Cody Northrop475663c2015-04-15 11:19:06 -06003489 pipelineobj.AddShader(&vs);
3490 pipelineobj.AddShader(&gs);
3491 pipelineobj.AddShader(&ps);
3492
3493 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003494 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop475663c2015-04-15 11:19:06 -06003495
3496 VkDescriptorSetObj descriptorSet(m_device);
3497
Tony Barbourfe3351b2015-07-28 10:17:20 -06003498 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop475663c2015-04-15 11:19:06 -06003499
3500 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06003501 Draw(0, 3, 0, 1);
Cody Northrop475663c2015-04-15 11:19:06 -06003502
3503 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003504 EndCommandBuffer();
3505 QueueCommandBuffer();
Cody Northrop475663c2015-04-15 11:19:06 -06003506
3507 RecordImages(m_renderTargets);
3508}
3509
3510TEST_F(VkRenderTest, GSUniformBufferLayout)
3511{
3512 // This test is just like TriangleUniformBufferLayout but adds
3513 // geometry as a stage that also does UBO lookups
3514 // The expected result from this test is a green triangle
3515
3516 static const char *vertShaderText =
3517 "#version 140\n"
3518 "#extension GL_ARB_separate_shader_objects : enable\n"
3519 "#extension GL_ARB_shading_language_420pack : enable\n"
3520 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3521 " vec4 fRed;\n"
3522 " vec4 fGreen;\n"
3523 " layout(row_major) mat4 worldToProj;\n"
3524 " layout(row_major) mat4 projToWorld;\n"
3525 " layout(row_major) mat4 worldToView;\n"
3526 " layout(row_major) mat4 viewToProj;\n"
3527 " layout(row_major) mat4 worldToShadow[4];\n"
3528 " float fZero;\n"
3529 " float fOne;\n"
3530 " float fTwo;\n"
3531 " float fThree;\n"
3532 " vec3 fZeroZeroZero;\n"
3533 " float fFour;\n"
3534 " vec3 fZeroZeroOne;\n"
3535 " float fFive;\n"
3536 " vec3 fZeroOneZero;\n"
3537 " float fSix;\n"
3538 " float fSeven;\n"
3539 " float fEight;\n"
3540 " float fNine;\n"
3541 " vec2 fZeroZero;\n"
3542 " vec2 fZeroOne;\n"
3543 " vec4 fBlue;\n"
3544 " vec2 fOneZero;\n"
3545 " vec2 fOneOne;\n"
3546 " vec3 fZeroOneOne;\n"
3547 " float fTen;\n"
3548 " float fEleven;\n"
3549 " float fTwelve;\n"
3550 " vec3 fOneZeroZero;\n"
3551 " vec4 uvOffsets[4];\n"
3552 "};\n"
3553 "layout (location = 0) out vec4 color;"
3554 "void main() {\n"
3555
3556 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3557 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3558 " \n"
3559
3560 // do some exact comparisons, even though we should
3561 // really have an epsilon involved.
3562 " vec4 outColor = right;\n"
3563 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3564 " outColor = wrong;\n"
3565 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3566 " outColor = wrong;\n"
3567 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3568 " outColor = wrong;\n"
3569
3570 " color = outColor;\n"
3571
3572 // generic position stuff
3573 " vec2 vertices;\n"
3574 " int vertexSelector = gl_VertexID;\n"
3575 " if (vertexSelector == 0)\n"
3576 " vertices = vec2(-0.5, -0.5);\n"
3577 " else if (vertexSelector == 1)\n"
3578 " vertices = vec2( 0.5, -0.5);\n"
3579 " else if (vertexSelector == 2)\n"
3580 " vertices = vec2( 0.5, 0.5);\n"
3581 " else\n"
3582 " vertices = vec2( 0.0, 0.0);\n"
3583 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3584 "}\n";
3585
3586 static const char *geomShaderText =
3587 "#version 330\n"
3588 "#extension GL_ARB_separate_shader_objects : enable\n"
3589 "#extension GL_ARB_shading_language_420pack : enable\n"
3590
3591 // GS layout stuff
3592 "layout( triangles ) in;\n"
3593 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3594
3595 // Between stage IO
3596 "layout( location = 0 ) in vec4 inColor[3];\n"
3597 "layout( location = 0 ) out vec4 color;\n"
3598
3599 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3600 " vec4 fRed;\n"
3601 " vec4 fGreen;\n"
3602 " layout(row_major) mat4 worldToProj;\n"
3603 " layout(row_major) mat4 projToWorld;\n"
3604 " layout(row_major) mat4 worldToView;\n"
3605 " layout(row_major) mat4 viewToProj;\n"
3606 " layout(row_major) mat4 worldToShadow[4];\n"
3607 " float fZero;\n"
3608 " float fOne;\n"
3609 " float fTwo;\n"
3610 " float fThree;\n"
3611 " vec3 fZeroZeroZero;\n"
3612 " float fFour;\n"
3613 " vec3 fZeroZeroOne;\n"
3614 " float fFive;\n"
3615 " vec3 fZeroOneZero;\n"
3616 " float fSix;\n"
3617 " float fSeven;\n"
3618 " float fEight;\n"
3619 " float fNine;\n"
3620 " vec2 fZeroZero;\n"
3621 " vec2 fZeroOne;\n"
3622 " vec4 fBlue;\n"
3623 " vec2 fOneZero;\n"
3624 " vec2 fOneOne;\n"
3625 " vec3 fZeroOneOne;\n"
3626 " float fTen;\n"
3627 " float fEleven;\n"
3628 " float fTwelve;\n"
3629 " vec3 fOneZeroZero;\n"
3630 " vec4 uvOffsets[4];\n"
3631 "};\n"
3632
3633 "void main()\n"
3634 "{\n"
3635
3636 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3637 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3638
3639 // Each vertex will validate it can read VS output
3640 // then check a few values from the UBO
3641
3642 // first vertex
3643 " vec4 outColor = inColor[0];\n"
3644
3645 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3646 " outColor = wrong;\n"
3647 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3648 " outColor = wrong;\n"
3649 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3650 " outColor = wrong;\n"
3651 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3652 " outColor = wrong;\n"
3653
3654 " gl_Position = gl_in[0].gl_Position;\n"
3655 " color = outColor;\n"
3656 " EmitVertex();\n"
3657
3658 // second vertex
3659 " outColor = inColor[1];\n"
3660
3661 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3662 " outColor = wrong;\n"
3663 " if (fSix != 6.0)\n"
3664 " outColor = wrong;\n"
3665 " if (fOneOne != vec2(1.0, 1.0))\n"
3666 " outColor = wrong;\n"
3667
3668 " gl_Position = gl_in[1].gl_Position;\n"
3669 " color = outColor;\n"
3670 " EmitVertex();\n"
3671
3672 // third vertex
3673 " outColor = inColor[2];\n"
3674
3675 " if (fSeven != 7.0)\n"
3676 " outColor = wrong;\n"
3677 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3678 " outColor = wrong;\n"
3679
3680 " gl_Position = gl_in[2].gl_Position;\n"
3681 " color = outColor;\n"
3682 " EmitVertex();\n"
3683
3684 // done
3685 " EndPrimitive();\n"
3686 "}\n";
3687
3688 static const char *fragShaderText =
3689 "#version 140\n"
3690 "#extension GL_ARB_separate_shader_objects : enable\n"
3691 "#extension GL_ARB_shading_language_420pack : enable\n"
3692 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3693 " vec4 fRed;\n"
3694 " vec4 fGreen;\n"
3695 " layout(row_major) mat4 worldToProj;\n"
3696 " layout(row_major) mat4 projToWorld;\n"
3697 " layout(row_major) mat4 worldToView;\n"
3698 " layout(row_major) mat4 viewToProj;\n"
3699 " layout(row_major) mat4 worldToShadow[4];\n"
3700 " float fZero;\n"
3701 " float fOne;\n"
3702 " float fTwo;\n"
3703 " float fThree;\n"
3704 " vec3 fZeroZeroZero;\n"
3705 " float fFour;\n"
3706 " vec3 fZeroZeroOne;\n"
3707 " float fFive;\n"
3708 " vec3 fZeroOneZero;\n"
3709 " float fSix;\n"
3710 " float fSeven;\n"
3711 " float fEight;\n"
3712 " float fNine;\n"
3713 " vec2 fZeroZero;\n"
3714 " vec2 fZeroOne;\n"
3715 " vec4 fBlue;\n"
3716 " vec2 fOneZero;\n"
3717 " vec2 fOneOne;\n"
3718 " vec3 fZeroOneOne;\n"
3719 " float fTen;\n"
3720 " float fEleven;\n"
3721 " float fTwelve;\n"
3722 " vec3 fOneZeroZero;\n"
3723 " vec4 uvOffsets[4];\n"
3724 "};\n"
3725 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06003726 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003727 "void main() {\n"
3728 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3729 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3730 " \n"
3731
3732 // start with GS value to ensure it passed
3733 " vec4 outColor = color;\n"
3734
3735 // do some exact comparisons, even though we should
3736 // really have an epsilon involved.
3737 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3738 " outColor = wrong;\n"
3739 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3740 " outColor = wrong;\n"
3741 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3742 " outColor = wrong;\n"
3743 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3744 " outColor = wrong;\n"
3745 " if (fTwo != 2.0)\n"
3746 " outColor = wrong;\n"
3747 " if (fOneOne != vec2(1.0, 1.0))\n"
3748 " outColor = wrong;\n"
3749 " if (fTen != 10.0)\n"
3750 " outColor = wrong;\n"
3751 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3752 " outColor = wrong;\n"
3753 " \n"
GregFaae75242015-06-03 18:40:50 -06003754 " uFragColor = outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003755 "}\n";
3756
3757
Cody Northropd2ad0342015-08-05 11:15:02 -06003758 const float mixedVals[196] = { 1.0f, 0.0f, 0.0f, 1.0f, // vec4 fRed; // align
3759 0.0f, 1.0f, 0.0f, 1.0f, // vec4 fGreen; // align
3760 1.0f, 0.0f, 0.0f, 1.0f, // layout(row_major) mat4 worldToProj;
3761 0.0f, 1.0f, 0.0f, 1.0f, // align
3762 0.0f, 0.0f, 1.0f, 1.0f, // align
3763 0.0f, 0.0f, 0.0f, 1.0f, // align
3764 2.0f, 0.0f, 0.0f, 2.0f, // layout(row_major) mat4 projToWorld;
3765 0.0f, 2.0f, 0.0f, 2.0f, // align
3766 0.0f, 0.0f, 2.0f, 2.0f, // align
3767 0.0f, 0.0f, 0.0f, 2.0f, // align
3768 3.0f, 0.0f, 0.0f, 3.0f, // layout(row_major) mat4 worldToView;
3769 0.0f, 3.0f, 0.0f, 3.0f, // align
3770 0.0f, 0.0f, 3.0f, 3.0f, // align
3771 0.0f, 0.0f, 0.0f, 3.0f, // align
3772 4.0f, 0.0f, 0.0f, 4.0f, // layout(row_major) mat4 viewToProj;
3773 0.0f, 4.0f, 0.0f, 4.0f, // align
3774 0.0f, 0.0f, 4.0f, 4.0f, // align
3775 0.0f, 0.0f, 0.0f, 4.0f, // align
3776 5.0f, 0.0f, 0.0f, 5.0f, // layout(row_major) mat4 worldToShadow[4];
3777 0.0f, 5.0f, 0.0f, 5.0f, // align
3778 0.0f, 0.0f, 5.0f, 5.0f, // align
3779 0.0f, 0.0f, 0.0f, 5.0f, // align
3780 6.0f, 0.0f, 0.0f, 6.0f, // align
3781 0.0f, 6.0f, 0.0f, 6.0f, // align
3782 0.0f, 0.0f, 6.0f, 6.0f, // align
3783 0.0f, 0.0f, 0.0f, 6.0f, // align
3784 7.0f, 0.0f, 0.0f, 7.0f, // align
3785 0.0f, 7.0f, 0.0f, 7.0f, // align
3786 0.0f, 0.0f, 7.0f, 7.0f, // align
3787 0.0f, 0.0f, 0.0f, 7.0f, // align
3788 8.0f, 0.0f, 0.0f, 8.0f, // align
3789 0.0f, 8.0f, 0.0f, 8.0f, // align
3790 0.0f, 0.0f, 8.0f, 8.0f, // align
3791 0.0f, 0.0f, 0.0f, 8.0f, // align
3792 0.0f, // float fZero; // align
3793 1.0f, // float fOne; // pack
3794 2.0f, // float fTwo; // pack
3795 3.0f, // float fThree; // pack
3796 0.0f, 0.0f, 0.0f, // vec3 fZeroZeroZero; // align
3797 4.0f, // float fFour; // pack
3798 0.0f, 0.0f, 1.0f, // vec3 fZeroZeroOne; // align
3799 5.0f, // float fFive; // pack
3800 0.0f, 1.0f, 0.0f, // vec3 fZeroOneZero; // align
3801 6.0f, // float fSix; // pack
3802 7.0f, // float fSeven; // align
3803 8.0f, // float fEight; // pack
3804 9.0f, // float fNine; // pack
3805 0.0f, // BUFFER
3806 0.0f, 0.0f, // vec2 fZeroZero; // align
3807 0.0f, 1.0f, // vec2 fZeroOne; // pack
3808 0.0f, 0.0f, 1.0f, 1.0f, // vec4 fBlue; // align
3809 1.0f, 0.0f, // vec2 fOneZero; // align
3810 1.0f, 1.0f, // vec2 fOneOne; // pack
3811 0.0f, 1.0f, 1.0f, // vec3 fZeroOneOne; // align
3812 10.0f, // float fTen; // pack
3813 11.0f, // float fEleven; // align
3814 12.0f, // float fTwelve; // pack
3815 0.0f, 0.0f, // BUFFER
3816 1.0f, 0.0f, 0.0f, // vec3 fOneZeroZero; // align
3817 0.0f, // BUFFER
3818 0.1f, 0.2f, 0.3f, 0.4f, // vec4 uvOffsets[4];
3819 0.5f, 0.6f, 0.7f, 0.8f, // align
3820 0.9f, 1.0f, 1.1f, 1.2f, // align
3821 1.3f, 1.4f, 1.5f, 1.6f, // align
Cody Northrop475663c2015-04-15 11:19:06 -06003822 };
3823
3824
3825
3826 ASSERT_NO_FATAL_FAILURE(InitState());
3827 ASSERT_NO_FATAL_FAILURE(InitViewport());
3828
3829 const int constCount = sizeof(mixedVals) / sizeof(float);
3830
3831 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3832 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3833 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3834
3835 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
3836
3837 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003838 pipelineobj.AddColorAttachment();
Cody Northrop475663c2015-04-15 11:19:06 -06003839 pipelineobj.AddShader(&vs);
3840 pipelineobj.AddShader(&gs);
3841 pipelineobj.AddShader(&ps);
3842
3843 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003844 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop475663c2015-04-15 11:19:06 -06003845
3846 VkDescriptorSetObj descriptorSet(m_device);
3847 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
3848
Tony Barbourfe3351b2015-07-28 10:17:20 -06003849 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop475663c2015-04-15 11:19:06 -06003850
3851 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06003852 Draw(0, 3, 0, 1);
Cody Northrop475663c2015-04-15 11:19:06 -06003853
3854 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003855 EndCommandBuffer();
3856 QueueCommandBuffer();
Cody Northrop475663c2015-04-15 11:19:06 -06003857
3858 RecordImages(m_renderTargets);
3859}
3860
3861TEST_F(VkRenderTest, GSPositions)
3862{
3863 // This test adds more inputs from the vertex shader and perturbs positions
3864 // Expected result is white triangle with weird positions
3865
3866 static const char *vertShaderText =
3867 "#version 140\n"
3868 "#extension GL_ARB_separate_shader_objects : enable\n"
3869 "#extension GL_ARB_shading_language_420pack : enable\n"
3870
3871 "layout(location = 0) out vec3 out_a;\n"
3872 "layout(location = 1) out vec3 out_b;\n"
3873 "layout(location = 2) out vec3 out_c;\n"
3874
3875 "void main() {\n"
3876
3877 // write a solid color to each
3878 " out_a = vec3(1.0, 0.0, 0.0);\n"
3879 " out_b = vec3(0.0, 1.0, 0.0);\n"
3880 " out_c = vec3(0.0, 0.0, 1.0);\n"
3881
3882 // generic position stuff
3883 " vec2 vertices;\n"
3884 " int vertexSelector = gl_VertexID;\n"
3885 " if (vertexSelector == 0)\n"
3886 " vertices = vec2(-0.5, -0.5);\n"
3887 " else if (vertexSelector == 1)\n"
3888 " vertices = vec2( 0.5, -0.5);\n"
3889 " else if (vertexSelector == 2)\n"
3890 " vertices = vec2( 0.5, 0.5);\n"
3891 " else\n"
3892 " vertices = vec2( 0.0, 0.0);\n"
3893 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3894
3895 "}\n";
3896
3897 static const char *geomShaderText =
3898 "#version 330\n"
3899 "#extension GL_ARB_separate_shader_objects : enable\n"
3900 "#extension GL_ARB_shading_language_420pack : enable\n"
3901 "layout( triangles ) in;\n"
3902 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3903
3904 "layout(location = 0) in vec3 in_a[3];\n"
3905 "layout(location = 1) in vec3 in_b[3];\n"
3906 "layout(location = 2) in vec3 in_c[3];\n"
3907
3908 "layout(location = 0) out vec3 out_a;\n"
3909 "layout(location = 1) out vec3 out_b;\n"
3910 "layout(location = 2) out vec3 out_c;\n"
3911
3912 "void main()\n"
3913 "{\n"
3914
3915 " gl_Position = gl_in[0].gl_Position;\n"
3916 " gl_Position.xy *= vec2(0.75);\n"
3917 " out_a = in_a[0];\n"
3918 " out_b = in_b[0];\n"
3919 " out_c = in_c[0];\n"
3920 " EmitVertex();\n"
3921
3922 " gl_Position = gl_in[1].gl_Position;\n"
3923 " gl_Position.xy *= vec2(1.5);\n"
3924 " out_a = in_a[1];\n"
3925 " out_b = in_b[1];\n"
3926 " out_c = in_c[1];\n"
3927 " EmitVertex();\n"
3928
3929 " gl_Position = gl_in[2].gl_Position;\n"
3930 " gl_Position.xy *= vec2(-0.1);\n"
3931 " out_a = in_a[2];\n"
3932 " out_b = in_b[2];\n"
3933 " out_c = in_c[2];\n"
3934 " EmitVertex();\n"
3935
3936 " EndPrimitive();\n"
3937 "}\n";
3938
3939
3940 static const char *fragShaderText =
3941 "#version 140\n"
3942 "#extension GL_ARB_separate_shader_objects : enable\n"
3943 "#extension GL_ARB_shading_language_420pack : enable\n"
3944
3945 "layout(location = 0) in vec3 in_a;\n"
3946 "layout(location = 1) in vec3 in_b;\n"
3947 "layout(location = 2) in vec3 in_c;\n"
GregFaae75242015-06-03 18:40:50 -06003948 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003949
3950 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06003951 " outColor = vec4(in_a.x, in_b.y, in_c.z, 1.0);\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003952 "}\n";
3953
3954
3955
3956 ASSERT_NO_FATAL_FAILURE(InitState());
3957 ASSERT_NO_FATAL_FAILURE(InitViewport());
3958
3959 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3960 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3961 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3962
3963 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003964 pipelineobj.AddColorAttachment();
Cody Northrop475663c2015-04-15 11:19:06 -06003965 pipelineobj.AddShader(&vs);
3966 pipelineobj.AddShader(&gs);
3967 pipelineobj.AddShader(&ps);
3968
3969 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003970 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop475663c2015-04-15 11:19:06 -06003971
3972 VkDescriptorSetObj descriptorSet(m_device);
3973
Tony Barbourfe3351b2015-07-28 10:17:20 -06003974 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop475663c2015-04-15 11:19:06 -06003975
3976 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06003977 Draw(0, 3, 0, 1);
Cody Northrop475663c2015-04-15 11:19:06 -06003978
3979 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003980 EndCommandBuffer();
3981 QueueCommandBuffer();
Cody Northrop475663c2015-04-15 11:19:06 -06003982
3983 RecordImages(m_renderTargets);
3984}
3985
3986TEST_F(VkRenderTest, GSTriStrip)
3987{
3988 // This test emits multiple multiple triangles using a GS
3989 // Correct result is an multicolor circle
3990
3991 static const char *vertShaderText =
3992 "#version 140\n"
3993 "#extension GL_ARB_separate_shader_objects : enable\n"
3994 "#extension GL_ARB_shading_language_420pack : enable\n"
3995
3996 "void main() {\n"
3997
3998 // generic position stuff
3999 " vec2 vertices;\n"
4000 " int vertexSelector = gl_VertexID;\n"
4001 " if (vertexSelector == 0)\n"
4002 " vertices = vec2(-0.5, -0.5);\n"
4003 " else if (vertexSelector == 1)\n"
4004 " vertices = vec2( 0.5, -0.5);\n"
4005 " else if (vertexSelector == 2)\n"
4006 " vertices = vec2( 0.5, 0.5);\n"
4007 " else\n"
4008 " vertices = vec2( 0.0, 0.0);\n"
4009 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
4010
4011 "}\n";
4012
4013 static const char *geomShaderText =
4014 "#version 330\n"
4015 "#extension GL_ARB_separate_shader_objects : enable\n"
4016 "#extension GL_ARB_shading_language_420pack : enable\n"
4017 "layout( triangles ) in;\n"
4018 "layout( triangle_strip, max_vertices = 18 ) out;\n"
4019
4020 "layout(location = 0) out vec4 outColor;\n"
4021
4022 "void main()\n"
4023 "{\n"
4024 // init with first position to get zw
4025 " gl_Position = gl_in[0].gl_Position;\n"
4026
4027 " vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
4028 " vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
4029 " vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
4030 " vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
4031
4032 // different color per tri
4033 " vec4[6] colors = { red, white, \n"
4034 " yellow, white, \n"
4035 " blue, white }; \n"
4036
4037 // fan out the triangles
4038 " vec2[18] positions = { vec2(0.0, 0.0), vec2(-0.5, 0.0), vec2(-0.25, -0.5), \n"
4039 " vec2(0.0, 0.0), vec2(-0.25, -0.5), vec2( 0.25, -0.5), \n"
4040 " vec2(0.0, 0.0), vec2( 0.25, -0.5), vec2( 0.5, 0.0), \n"
4041 " vec2(0.0, 0.0), vec2( 0.5, 0.0), vec2( 0.25, 0.5), \n"
4042 " vec2(0.0, 0.0), vec2( 0.25, 0.5), vec2(-0.25, 0.5), \n"
4043 " vec2(0.0, 0.0), vec2(-0.25, 0.5), vec2(-0.5, 0.0) }; \n"
4044
4045 // make a triangle list of 6
4046 " for (int i = 0; i < 6; ++i) { \n"
4047 " outColor = colors[i]; \n"
4048 " for (int j = 0; j < 3; ++j) { \n"
4049 " gl_Position.xy = positions[i * 3 + j]; \n"
4050 " EmitVertex(); \n"
4051 " } \n"
4052 " EndPrimitive();\n"
4053 " } \n"
4054
4055 "}\n";
4056
4057
4058 static const char *fragShaderText =
4059 "#version 150\n"
4060 "#extension GL_ARB_separate_shader_objects : enable\n"
4061 "#extension GL_ARB_shading_language_420pack : enable\n"
4062
4063
4064 "layout(binding = 0) uniform windowDimensions {\n"
4065 " vec4 dimensions;\n"
4066 "};\n"
4067
4068 "layout(location = 0) in vec4 inColor;\n"
4069 "layout(origin_upper_left) in vec4 gl_FragCoord;\n"
GregFaae75242015-06-03 18:40:50 -06004070 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06004071
4072 "void main() {\n"
4073
4074 // discard to make a nice circle
4075 " vec2 pos = abs(gl_FragCoord.xy) - vec2(dimensions.x, dimensions.y) / 2;\n"
4076 " float dist = sqrt(dot(pos, pos));\n"
4077 " if (dist > 50.0)\n"
4078 " discard;\n"
4079
GregFaae75242015-06-03 18:40:50 -06004080 " outColor = inColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06004081
4082 "}\n";
4083
4084
4085
4086 ASSERT_NO_FATAL_FAILURE(InitState());
4087 ASSERT_NO_FATAL_FAILURE(InitViewport());
4088
4089 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
4090 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
4091 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
4092
4093 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004094 pipelineobj.AddColorAttachment();
Cody Northrop475663c2015-04-15 11:19:06 -06004095 pipelineobj.AddShader(&vs);
4096 pipelineobj.AddShader(&gs);
4097 pipelineobj.AddShader(&ps);
4098
4099 const float dimensions[4] = { VkRenderFramework::m_width, VkRenderFramework::m_height , 0.0, 0.0};
4100
4101 VkConstantBufferObj windowDimensions(m_device, sizeof(dimensions) / sizeof(dimensions[0]), sizeof(dimensions[0]), (const void*) dimensions);
4102
4103 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004104 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop475663c2015-04-15 11:19:06 -06004105
4106 VkDescriptorSetObj descriptorSet(m_device);
4107 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, windowDimensions);
4108
Tony Barbourfe3351b2015-07-28 10:17:20 -06004109 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop475663c2015-04-15 11:19:06 -06004110
4111 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06004112 Draw(0, 3, 0, 1);
Cody Northrop475663c2015-04-15 11:19:06 -06004113
4114 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06004115 EndCommandBuffer();
4116 QueueCommandBuffer();
Cody Northrop475663c2015-04-15 11:19:06 -06004117
4118 RecordImages(m_renderTargets);
4119}
4120
Chris Forbese182fe02015-06-15 09:32:35 +12004121TEST_F(VkRenderTest, RenderPassLoadOpClear)
4122{
4123 ASSERT_NO_FATAL_FAILURE(InitState());
4124 ASSERT_NO_FATAL_FAILURE(InitViewport());
4125
4126 /* clear via load op to full green */
4127 m_clear_via_load_op = true;
Chris Forbesf0796e12015-06-24 14:34:53 +12004128 m_clear_color.f32[0] = 0;
4129 m_clear_color.f32[1] = 1;
4130 m_clear_color.f32[2] = 0;
4131 m_clear_color.f32[3] = 0;
Chris Forbese182fe02015-06-15 09:32:35 +12004132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004133 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Chris Forbese182fe02015-06-15 09:32:35 +12004134 /* This command buffer contains ONLY the load op! */
Tony Barbourfe3351b2015-07-28 10:17:20 -06004135 EndCommandBuffer();
4136 QueueCommandBuffer();
Chris Forbese182fe02015-06-15 09:32:35 +12004137
4138 RecordImages(m_renderTargets);
4139}
4140
Chris Forbesfa27b952015-06-24 12:05:30 +12004141TEST_F(VkRenderTest, RenderPassAttachmentClear)
4142{
4143 ASSERT_NO_FATAL_FAILURE(InitState());
4144 ASSERT_NO_FATAL_FAILURE(InitViewport());
4145
4146 /* clear via load op to full red */
4147 m_clear_via_load_op = true;
Chris Forbesf0796e12015-06-24 14:34:53 +12004148 m_clear_color.f32[0] = 1;
4149 m_clear_color.f32[1] = 0;
4150 m_clear_color.f32[2] = 0;
4151 m_clear_color.f32[3] = 0;
Chris Forbesfa27b952015-06-24 12:05:30 +12004152 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004153 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Chris Forbesfa27b952015-06-24 12:05:30 +12004154
4155 /* Load op has cleared to red */
4156
4157 /* Draw, draw, draw... */
4158
4159 /* Now, partway through this renderpass we want to clear the color
4160 * attachment again, this time to green.
4161 */
Chris Forbesf0796e12015-06-24 14:34:53 +12004162 VkClearColorValue clear_color;
4163 clear_color.f32[0] = 0;
4164 clear_color.f32[1] = 1;
4165 clear_color.f32[2] = 0;
4166 clear_color.f32[3] = 0;
Chris Forbesfa27b952015-06-24 12:05:30 +12004167 VkRect3D clear_rect = { { 0, 0, 0 }, { (int)m_width, (int)m_height, 1 } };
Tony Barbourfe3351b2015-07-28 10:17:20 -06004168 vkCmdClearColorAttachment(m_cmdBuffer->handle(), 0,
Chris Forbesfa27b952015-06-24 12:05:30 +12004169 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4170 &clear_color, 1, &clear_rect);
4171
Tony Barbourfe3351b2015-07-28 10:17:20 -06004172 EndCommandBuffer();
4173 QueueCommandBuffer();
Chris Forbesfa27b952015-06-24 12:05:30 +12004174
4175 RecordImages(m_renderTargets);
4176}
4177
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06004178int main(int argc, char **argv) {
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004179 int result;
4180
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06004181 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -06004182 VkTestFramework::InitArgs(&argc, argv);
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004183
Chia-I Wu6f184292014-12-15 23:57:34 +08004184 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchtera0f74c52014-10-08 08:46:51 -06004185
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004186 result = RUN_ALL_TESTS();
4187
Tony Barbour6918cd52015-04-09 12:58:51 -06004188 VkTestFramework::Finish();
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004189 return result;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06004190}