blob: 95f0358d890cdf98f20f046032d3bb9211f5b3b6 [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();
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600387 cmdBuffer->SetLineWidth(m_lineWidth);
388 cmdBuffer->SetDepthBias(m_depthBias, m_depthBiasClamp, m_slopeScaledDepthBias);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600389 cmdBuffer->SetViewport(m_viewports.size(), m_viewports.data());
390 cmdBuffer->SetScissor(m_scissors.size(), m_scissors.data());
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600391 cmdBuffer->SetBlendConstants(m_blendConst);
392 cmdBuffer->SetDepthBounds(m_minDepthBounds, m_maxDepthBounds);
393 cmdBuffer->SetStencilReadMask(VK_STENCIL_FACE_FRONT_BIT | VK_STENCIL_FACE_BACK_BIT, m_stencilCompareMask);
394 cmdBuffer->SetStencilWriteMask(VK_STENCIL_FACE_FRONT_BIT | VK_STENCIL_FACE_BACK_BIT, m_stencilWriteMask);
395 cmdBuffer->SetStencilReference(VK_STENCIL_FACE_FRONT_BIT | VK_STENCIL_FACE_BACK_BIT, m_stencilReference);
396
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600397 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
Cody Northrop29a08f22015-08-27 10:20:35 -0600398 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
399 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600400 cmdBuffer->BindPipeline(pipelineobj);
Chia-I Wu53f07d72015-03-28 15:23:55 +0800401 cmdBuffer->BindDescriptorSet(descriptorSet);
Tony Barbour22e32a12015-01-08 17:08:28 -0700402}
Tony Barboure2c58df2014-11-25 13:18:32 -0700403
Tony Barbour6918cd52015-04-09 12:58:51 -0600404void VkRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
405 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer)
Tony Barbour664accc2015-01-09 12:55:14 -0700406{
407 int i;
408 glm::mat4 MVP;
409 int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600410 VkResult err;
Tony Barbour664accc2015-01-09 12:55:14 -0700411
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600412 /* Only do 3 positions to avoid back face cull */
413 for (i = 0; i < 3; i++) {
Chia-I Wu681d7a02015-07-03 13:44:34 +0800414 void *pData = constantBuffer->memory().map();
Tony Barbour664accc2015-01-09 12:55:14 -0700415
416 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
417 MVP = Projection * View * Model;
418 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
419
Chia-I Wu681d7a02015-07-03 13:44:34 +0800420 constantBuffer->memory().unmap();
Tony Barbour664accc2015-01-09 12:55:14 -0700421
422 // submit the command buffer to the universal queue
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600423 cmdBuffer->QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -0700424
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600425 err = vkQueueWaitIdle( m_device->m_queue );
426 ASSERT_VK_SUCCESS( err );
Tony Barbour664accc2015-01-09 12:55:14 -0700427
428 // Wait for work to finish before cleaning up.
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600429 vkDeviceWaitIdle(m_device->device());
Tony Barbour664accc2015-01-09 12:55:14 -0700430
Courtney Goeltzenleuchterb4337c12015-03-05 16:47:18 -0700431 assert(m_renderTargets.size() == 1);
Tony Barbour664accc2015-01-09 12:55:14 -0700432 RecordImage(m_renderTargets[0]);
433 }
434}
Courtney Goeltzenleuchterc55471f2014-10-13 13:03:31 -0600435
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600436void dumpMatrix(const char *note, glm::mat4 MVP)
437{
Chia-I Wu6f184292014-12-15 23:57:34 +0800438 int i;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600439
440 printf("%s: \n", note);
441 for (i=0; i<4; i++) {
442 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
443 }
444 printf("\n");
445 fflush(stdout);
446}
447
448void dumpVec4(const char *note, glm::vec4 vector)
449{
450 printf("%s: \n", note);
451 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
452 printf("\n");
453 fflush(stdout);
454}
455
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600456struct vktriangle_vs_uniform {
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600457 // Must start with MVP
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600458 float mvp[4][4];
459 float position[3][4];
460 float color[3][4];
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600461};
462
Tony Barbour6918cd52015-04-09 12:58:51 -0600463void VkRenderTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600464{
Tobin Ehlis6663f492014-11-10 12:29:12 -0700465#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600466 vkDbgRegisterMsgCallback(inst, myDbgFunc, NULL);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700467#endif
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600468 // Create identity matrix
469 int i;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600470 struct vktriangle_vs_uniform data;
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600471
472 glm::mat4 Projection = glm::mat4(1.0f);
473 glm::mat4 View = glm::mat4(1.0f);
474 glm::mat4 Model = glm::mat4(1.0f);
475 glm::mat4 MVP = Projection * View * Model;
476 const int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600477 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600478 memcpy(&data.mvp, &MVP[0][0], matrixSize);
479
480 static const Vertex tri_data[] =
481 {
482 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
483 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
484 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
485 };
486
487 for (i=0; i<3; i++) {
488 data.position[i][0] = tri_data[i].posX;
489 data.position[i][1] = tri_data[i].posY;
490 data.position[i][2] = tri_data[i].posZ;
491 data.position[i][3] = tri_data[i].posW;
492 data.color[i][0] = tri_data[i].r;
493 data.color[i][1] = tri_data[i].g;
494 data.color[i][2] = tri_data[i].b;
495 data.color[i][3] = tri_data[i].a;
496 }
497
Tony Barboure2c58df2014-11-25 13:18:32 -0700498 ASSERT_NO_FATAL_FAILURE(InitState());
499 ASSERT_NO_FATAL_FAILURE(InitViewport());
500
Tony Barbour6918cd52015-04-09 12:58:51 -0600501 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barboure2c58df2014-11-25 13:18:32 -0700502
Tony Barbour6918cd52015-04-09 12:58:51 -0600503 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
504 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -0700505
Tony Barbour6918cd52015-04-09 12:58:51 -0600506 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800507 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -0700508 pipelineobj.AddShader(&vs);
509 pipelineobj.AddShader(&ps);
510
Tony Barbour6918cd52015-04-09 12:58:51 -0600511 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600512 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -0700513
Tony Barbourd726a172015-01-09 16:12:35 -0700514 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf1878c72015-08-18 14:24:32 -0600515
516 VkCmdBufferBeginInfo cbBeginInfo;
517 memset(&cbBeginInfo, 0, sizeof(VkCmdBufferBeginInfo));
518 cbBeginInfo.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
519 cbBeginInfo.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT;
520 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barboure2c58df2014-11-25 13:18:32 -0700521
Tony Barbourfe3351b2015-07-28 10:17:20 -0600522 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourd726a172015-01-09 16:12:35 -0700523#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600524 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourd726a172015-01-09 16:12:35 -0700525 pDSDumpDot((char*)"triTest2.dot");
526#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600527
Tony Barbourd726a172015-01-09 16:12:35 -0700528 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -0600529 Draw(0, 3, 0, 1);
Tony Barbourd726a172015-01-09 16:12:35 -0700530
531 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600532 ASSERT_VK_SUCCESS(EndCommandBuffer());
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600533
Tony Barbourfe3351b2015-07-28 10:17:20 -0600534 QueueCommandBuffer();
Tony Barbourd726a172015-01-09 16:12:35 -0700535
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600536 RecordImages(m_renderTargets);
Tony Barbourd726a172015-01-09 16:12:35 -0700537
538 if (rotate)
Tony Barbourfe3351b2015-07-28 10:17:20 -0600539 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer);
Tony Barbourd726a172015-01-09 16:12:35 -0700540
Tobin Ehlisca915872014-11-18 11:28:33 -0700541#ifdef PRINT_OBJECTS
Mark Lobodzinski7c75b852015-05-05 15:01:37 -0500542 OBJ_TRACK_GET_OBJECTS_COUNT pObjTrackGetObjectsCount = (OBJ_TRACK_GET_OBJECTS_COUNT)vkGetProcAddr(gpu(), (char*)"objTrackGetObjectsCount");
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600543 uint64_t numObjects = pObjTrackGetObjectsCount(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600544 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlisca915872014-11-18 11:28:33 -0700545 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600546 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlisca915872014-11-18 11:28:33 -0700547 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600548 pObjTrackGetObjs(m_device, numObjects, pObjNodeArray);
Tobin Ehlisca915872014-11-18 11:28:33 -0700549 for (i=0; i < numObjects; i++) {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600550 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 -0700551 }
552 free(pObjNodeArray);
553#endif
Tony Barboure2c58df2014-11-25 13:18:32 -0700554
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600555}
556
Tony Barbour6918cd52015-04-09 12:58:51 -0600557TEST_F(VkRenderTest, VKTriangle_FragColor)
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600558{
559 static const char *vertShaderText =
560 "#version 140\n"
561 "#extension GL_ARB_separate_shader_objects : enable\n"
562 "#extension GL_ARB_shading_language_420pack : enable\n"
563 "\n"
564 "layout(binding = 0) uniform buf {\n"
565 " mat4 MVP;\n"
566 " vec4 position[3];\n"
567 " vec4 color[3];\n"
568 "} ubuf;\n"
569 "\n"
570 "layout (location = 0) out vec4 outColor;\n"
571 "\n"
572 "void main() \n"
573 "{\n"
574 " outColor = ubuf.color[gl_VertexID];\n"
575 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
576 "}\n";
577
578 static const char *fragShaderText =
579 "#version 140\n"
580 "#extension GL_ARB_separate_shader_objects : enable\n"
581 "#extension GL_ARB_shading_language_420pack : enable\n"
582 "\n"
583 "layout (location = 0) in vec4 inColor;\n"
GregFaae75242015-06-03 18:40:50 -0600584 "layout (location = 0) out vec4 uFragColor;\n"
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600585 "\n"
586 "void main()\n"
587 "{\n"
GregFaae75242015-06-03 18:40:50 -0600588 " uFragColor = inColor;\n"
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600589 "}\n";
590
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600591 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
592 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600593}
594
Tony Barbour6918cd52015-04-09 12:58:51 -0600595TEST_F(VkRenderTest, VKTriangle_OutputLocation)
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600596{
597 static const char *vertShaderText =
598 "#version 140\n"
599 "#extension GL_ARB_separate_shader_objects : enable\n"
600 "#extension GL_ARB_shading_language_420pack : enable\n"
601 "\n"
602 "layout(binding = 0) uniform buf {\n"
603 " mat4 MVP;\n"
604 " vec4 position[3];\n"
605 " vec4 color[3];\n"
606 "} ubuf;\n"
607 "\n"
608 "layout (location = 0) out vec4 outColor;\n"
609 "\n"
610 "void main() \n"
611 "{\n"
612 " outColor = ubuf.color[gl_VertexID];\n"
613 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
614 "}\n";
615
616 static const char *fragShaderText =
617 "#version 140\n"
618 "#extension GL_ARB_separate_shader_objects : enable\n"
619 "#extension GL_ARB_shading_language_420pack : enable\n"
620 "\n"
621 "layout (location = 0) in vec4 inColor;\n"
622 "layout (location = 0) out vec4 outColor;\n"
623 "\n"
624 "void main()\n"
625 "{\n"
626 " outColor = inColor;\n"
627 "}\n";
628
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600629 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 -0600630
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600631 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600632}
Cody Northrop6922da12015-06-23 13:25:51 -0600633
Tony Barbour6918cd52015-04-09 12:58:51 -0600634TEST_F(VkRenderTest, SPV_VKTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -0700635{
Tony Barboure2c58df2014-11-25 13:18:32 -0700636 static const char *vertShaderText =
637 "#version 140\n"
638 "#extension GL_ARB_separate_shader_objects : enable\n"
639 "#extension GL_ARB_shading_language_420pack : enable\n"
640 "\n"
641 "layout(binding = 0) uniform buf {\n"
642 " mat4 MVP;\n"
643 " vec4 position[3];\n"
644 " vec4 color[3];\n"
645 "} ubuf;\n"
646 "\n"
647 "layout (location = 0) out vec4 outColor;\n"
648 "\n"
649 "void main() \n"
650 "{\n"
651 " outColor = ubuf.color[gl_VertexID];\n"
652 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
653 "}\n";
654
655 static const char *fragShaderText =
656 "#version 140\n"
657 "#extension GL_ARB_separate_shader_objects : enable\n"
658 "#extension GL_ARB_shading_language_420pack : enable\n"
659 "\n"
660 "layout (location = 0) in vec4 inColor;\n"
GregFaae75242015-06-03 18:40:50 -0600661 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700662 "\n"
663 "void main()\n"
664 "{\n"
GregFaae75242015-06-03 18:40:50 -0600665 " outColor = inColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700666 "}\n";
667
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600668 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 -0700669
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600670 VKTriangleTest(vertShaderText, fragShaderText, true);
Tony Barboure2c58df2014-11-25 13:18:32 -0700671}
Courtney Goeltzenleuchter538062a2014-10-09 15:40:19 -0600672
Tony Barbour6918cd52015-04-09 12:58:51 -0600673TEST_F(VkRenderTest, SPV_GreenTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -0700674{
Tony Barboure2c58df2014-11-25 13:18:32 -0700675 static const char *vertShaderText =
676 "#version 130\n"
677 "vec2 vertices[3];\n"
678 "void main() {\n"
679 " vertices[0] = vec2(-1.0, -1.0);\n"
680 " vertices[1] = vec2( 1.0, -1.0);\n"
681 " vertices[2] = vec2( 0.0, 1.0);\n"
682 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
683 "}\n";
684
685 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -0600686 "#version 140\n"
687 "#extension GL_ARB_separate_shader_objects : enable\n"
688 "#extension GL_ARB_shading_language_420pack : enable\n"
689 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700690 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600691 " outColor = vec4(0,1,0,1);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700692 "}\n";
693
Cody Northrop3bfd27c2015-03-17 15:55:58 -0600694 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barboure2c58df2014-11-25 13:18:32 -0700695
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600696 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barboure2c58df2014-11-25 13:18:32 -0700697}
Cody Northrop6922da12015-06-23 13:25:51 -0600698
Tony Barbour6918cd52015-04-09 12:58:51 -0600699TEST_F(VkRenderTest, YellowTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -0700700{
701 static const char *vertShaderText =
702 "#version 130\n"
703 "void main() {\n"
704 " vec2 vertices[3];"
705 " vertices[0] = vec2(-0.5, -0.5);\n"
706 " vertices[1] = vec2( 0.5, -0.5);\n"
707 " vertices[2] = vec2( 0.5, 0.5);\n"
708 " vec4 colors[3];\n"
709 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
710 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
711 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
712 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
713 "}\n";
714
715 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -0600716 "#version 140\n"
717 "#extension GL_ARB_separate_shader_objects : enable\n"
718 "#extension GL_ARB_shading_language_420pack : enable\n"
719 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700720 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600721 " outColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700722 "}\n";
723
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600724 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barboure2c58df2014-11-25 13:18:32 -0700725}
726
Tony Barbour6918cd52015-04-09 12:58:51 -0600727TEST_F(VkRenderTest, QuadWithVertexFetch)
Cody Northropee6586d2014-10-09 19:55:56 -0600728{
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600729 static const char *vertShaderText =
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600730 "#version 140\n"
731 "#extension GL_ARB_separate_shader_objects : enable\n"
732 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700733 //XYZ1( -1, -1, -1 )
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600734 "layout (location = 0) in vec4 pos;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700735 //XYZ1( 0.f, 0.f, 0.f )
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600736 "layout (location = 1) in vec4 inColor;\n"
737 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600738 "void main() {\n"
Cody Northrop66594a72014-10-10 14:49:36 -0600739 " outColor = inColor;\n"
Cody Northrop7ad4aaf2014-10-09 21:25:22 -0600740 " gl_Position = pos;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600741 "}\n";
742
Cody Northropee6586d2014-10-09 19:55:56 -0600743
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600744 static const char *fragShaderText =
Cody Northropd43c52e2014-12-05 15:44:14 -0700745 "#version 140\n"
746 "#extension GL_ARB_separate_shader_objects : enable\n"
747 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600748 "layout (location = 0) in vec4 color;\n"
Cody Northropd43c52e2014-12-05 15:44:14 -0700749 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600750 "void main() {\n"
Cody Northropd43c52e2014-12-05 15:44:14 -0700751 " outColor = color;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600752 "}\n";
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600753
Tony Barboure2c58df2014-11-25 13:18:32 -0700754
755
756 ASSERT_NO_FATAL_FAILURE(InitState());
757 ASSERT_NO_FATAL_FAILURE(InitViewport());
758
Tony Barbour6918cd52015-04-09 12:58:51 -0600759 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000760 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -0700761
Tony Barbour6918cd52015-04-09 12:58:51 -0600762 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
763 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -0700764
Tony Barbour6918cd52015-04-09 12:58:51 -0600765 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800766 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -0700767 pipelineobj.AddShader(&vs);
768 pipelineobj.AddShader(&ps);
769
Tony Barbour6918cd52015-04-09 12:58:51 -0600770 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -0600771
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600772#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600773 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600774 MESH_BIND_ID, // binding ID
Tony Barboure2c58df2014-11-25 13:18:32 -0700775 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600776 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barboure2c58df2014-11-25 13:18:32 -0700777 };
778
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600779 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600780 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
781 vi_attribs[0].location = 0; // location, position
Tony Barbourd1c35722015-04-16 15:59:00 -0600782 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600783 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
784 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
785 vi_attribs[1].location = 1; // location, color
Tony Barbourd1c35722015-04-16 15:59:00 -0600786 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600787 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 -0700788
789 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
790 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barboure2c58df2014-11-25 13:18:32 -0700791
Tony Barbour1fde6942015-01-09 10:06:53 -0700792 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600793 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure2c58df2014-11-25 13:18:32 -0700794
Tony Barbourfe3351b2015-07-28 10:17:20 -0600795 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600796
Tony Barbourfe3351b2015-07-28 10:17:20 -0600797 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour1fde6942015-01-09 10:06:53 -0700798
799 // render two triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -0600800 Draw(0, 6, 0, 1);
Tony Barbour1fde6942015-01-09 10:06:53 -0700801
802 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600803 ASSERT_VK_SUCCESS(EndCommandBuffer());
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600804
Tony Barbourfe3351b2015-07-28 10:17:20 -0600805 QueueCommandBuffer();
Tony Barbour1fde6942015-01-09 10:06:53 -0700806
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600807 RecordImages(m_renderTargets);
Tobin Ehlisd806c8e2014-10-07 14:41:29 -0600808}
809
Tony Barbour6918cd52015-04-09 12:58:51 -0600810TEST_F(VkRenderTest, TriangleMRT)
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800811{
812 static const char *vertShaderText =
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600813 "#version 140\n"
814 "#extension GL_ARB_separate_shader_objects : enable\n"
815 "#extension GL_ARB_shading_language_420pack : enable\n"
816 "layout (location = 0) in vec4 pos;\n"
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800817 "void main() {\n"
818 " gl_Position = pos;\n"
819 "}\n";
820
821 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -0600822 "#version 140\n"
823 "#extension GL_ARB_separate_shader_objects : enable\n"
824 "#extension GL_ARB_shading_language_420pack : enable\n"
825 "layout (location = 0) out vec4 uFragData0;\n"
826 "layout (location = 1) out vec4 uFragData1;\n"
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800827 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600828 " uFragData0 = vec4(1.0, 0.0, 0.0, 1.0);\n"
829 " uFragData1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800830 "}\n";
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600831 const float vb_data[][2] = {
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800832 { -1.0f, -1.0f },
833 { 1.0f, -1.0f },
834 { -1.0f, 1.0f }
835 };
836
837 ASSERT_NO_FATAL_FAILURE(InitState());
838 ASSERT_NO_FATAL_FAILURE(InitViewport());
839
Tony Barbour6918cd52015-04-09 12:58:51 -0600840 VkConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000841 meshBuffer.BufferMemoryBarrier();
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800842
Tony Barbour6918cd52015-04-09 12:58:51 -0600843 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
844 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800845
Tony Barbour6918cd52015-04-09 12:58:51 -0600846 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800847 pipelineobj.AddColorAttachment();
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800848 pipelineobj.AddShader(&vs);
849 pipelineobj.AddShader(&ps);
850
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600851#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600852 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600853 MESH_BUF_ID, // Binding ID
854 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600855 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800856 };
857
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600858 VkVertexInputAttributeDescription vi_attrib;
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600859 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
860 vi_attrib.location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -0600861 vi_attrib.format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600862 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800863
864 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
865 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800866
Tony Barbour6918cd52015-04-09 12:58:51 -0600867 VkDescriptorSetObj descriptorSet(m_device);
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);
Tony Barbour831062d2015-04-02 15:43:15 -0600958
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700959
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600960#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600961 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600962 MESH_BIND_ID, // binding ID
963 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600964 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700965 };
966
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600967 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600968 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
969 vi_attribs[0].location = 0; // layout location of vertex attribute
Tony Barbourd1c35722015-04-16 15:59:00 -0600970 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600971 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
972 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
973 vi_attribs[1].location = 1; // layout location of vertex attribute
Tony Barbourd1c35722015-04-16 15:59:00 -0600974 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600975 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700976
977 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
978 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700979
980 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600981 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour1fde6942015-01-09 10:06:53 -0700982
Tony Barbourfe3351b2015-07-28 10:17:20 -0600983 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700984
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700985#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600986 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlisf27eba72014-12-16 17:34:50 -0700987 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700988#endif
Tony Barbour22e32a12015-01-08 17:08:28 -0700989
Tony Barbourfe3351b2015-07-28 10:17:20 -0600990 BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
991 BindIndexBuffer(&indexBuffer, 0);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700992
993 // render two triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -0600994 DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700995
996 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600997 ASSERT_VK_SUCCESS(EndCommandBuffer());
998 QueueCommandBuffer();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700999
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001000 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -07001001}
1002
Tony Barbour6918cd52015-04-09 12:58:51 -06001003TEST_F(VkRenderTest, GreyandRedCirclesonBlue)
GregF3156cb02014-12-02 15:41:44 -07001004{
1005 // This tests gl_FragCoord
Tony Barboure2c58df2014-11-25 13:18:32 -07001006
GregF3156cb02014-12-02 15:41:44 -07001007 static const char *vertShaderText =
1008 "#version 140\n"
1009 "#extension GL_ARB_separate_shader_objects : enable\n"
1010 "#extension GL_ARB_shading_language_420pack : enable\n"
1011 "layout (location = 0) in vec4 pos;\n"
1012 "layout (location = 0) out vec4 outColor;\n"
1013 "layout (location = 1) out vec4 outColor2;\n"
1014 "void main() {\n"
1015 " gl_Position = pos;\n"
1016 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1017 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1018 "}\n";
1019
1020 static const char *fragShaderText =
GregF3156cb02014-12-02 15:41:44 -07001021 "#version 330\n"
1022 "#extension GL_ARB_separate_shader_objects : enable\n"
1023 "#extension GL_ARB_shading_language_420pack : enable\n"
1024 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1025 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1026 "layout (location = 0) in vec4 color;\n"
1027 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001028 "layout (location = 0) out vec4 outColor;\n"
GregF3156cb02014-12-02 15:41:44 -07001029 "void main() {\n"
1030 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1031 " float dist_squared = dot(pos, pos);\n"
GregFaae75242015-06-03 18:40:50 -06001032 " outColor = (dist_squared < 400.0)\n"
GregF3156cb02014-12-02 15:41:44 -07001033 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1034 " : color2;\n"
1035 "}\n";
1036
1037 ASSERT_NO_FATAL_FAILURE(InitState());
1038 ASSERT_NO_FATAL_FAILURE(InitViewport());
1039
Tony Barbour6918cd52015-04-09 12:58:51 -06001040 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001041 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001042
Tony Barbour6918cd52015-04-09 12:58:51 -06001043 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1044 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF3156cb02014-12-02 15:41:44 -07001045
Tony Barbour6918cd52015-04-09 12:58:51 -06001046 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001047 pipelineobj.AddColorAttachment();
GregF3156cb02014-12-02 15:41:44 -07001048 pipelineobj.AddShader(&vs);
1049 pipelineobj.AddShader(&ps);
1050
Tony Barbour6918cd52015-04-09 12:58:51 -06001051 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001052
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001053#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001054 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001055 MESH_BIND_ID, // binding ID
1056 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001057 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF3156cb02014-12-02 15:41:44 -07001058 };
1059
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001060 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001061 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1062 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001063 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001064 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF3156cb02014-12-02 15:41:44 -07001065
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001066 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF3156cb02014-12-02 15:41:44 -07001067 pipelineobj.AddVertexInputBindings(&vi_binding,1);
GregF3156cb02014-12-02 15:41:44 -07001068
Tony Barbour664accc2015-01-09 12:55:14 -07001069 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour664accc2015-01-09 12:55:14 -07001070
Tony Barbourfe3351b2015-07-28 10:17:20 -06001071 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001072
Tony Barbourfe3351b2015-07-28 10:17:20 -06001073 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001074
Tony Barbourfe3351b2015-07-28 10:17:20 -06001075 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001076#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001077 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001078 pDSDumpDot((char*)"triTest2.dot");
1079#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001080
Tony Barbour664accc2015-01-09 12:55:14 -07001081 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06001082 Draw(0, 6, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07001083
1084 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001085 EndCommandBuffer();
1086 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001087
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001088 RecordImages(m_renderTargets);
GregF3156cb02014-12-02 15:41:44 -07001089}
1090
Tony Barbour6918cd52015-04-09 12:58:51 -06001091TEST_F(VkRenderTest, RedCirclesonBlue)
GregF3156cb02014-12-02 15:41:44 -07001092{
1093 // This tests that we correctly handle unread fragment inputs
1094
1095 static const char *vertShaderText =
1096 "#version 140\n"
1097 "#extension GL_ARB_separate_shader_objects : enable\n"
1098 "#extension GL_ARB_shading_language_420pack : enable\n"
1099 "layout (location = 0) in vec4 pos;\n"
1100 "layout (location = 0) out vec4 outColor;\n"
1101 "layout (location = 1) out vec4 outColor2;\n"
1102 "void main() {\n"
1103 " gl_Position = pos;\n"
1104 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1105 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1106 "}\n";
1107
1108 static const char *fragShaderText =
GregF3156cb02014-12-02 15:41:44 -07001109 "#version 330\n"
1110 "#extension GL_ARB_separate_shader_objects : enable\n"
1111 "#extension GL_ARB_shading_language_420pack : enable\n"
1112 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1113 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1114 "layout (location = 0) in vec4 color;\n"
1115 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001116 "layout (location = 0) out vec4 outColor;\n"
GregF3156cb02014-12-02 15:41:44 -07001117 "void main() {\n"
1118 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1119 " float dist_squared = dot(pos, pos);\n"
GregFaae75242015-06-03 18:40:50 -06001120 " outColor = (dist_squared < 400.0)\n"
GregF3156cb02014-12-02 15:41:44 -07001121 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1122 " : color2;\n"
1123 "}\n";
1124
1125 ASSERT_NO_FATAL_FAILURE(InitState());
1126 ASSERT_NO_FATAL_FAILURE(InitViewport());
1127
Tony Barbour6918cd52015-04-09 12:58:51 -06001128 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001129 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001130
Tony Barbour6918cd52015-04-09 12:58:51 -06001131 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1132 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF3156cb02014-12-02 15:41:44 -07001133
Tony Barbour6918cd52015-04-09 12:58:51 -06001134 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001135 pipelineobj.AddColorAttachment();
GregF3156cb02014-12-02 15:41:44 -07001136 pipelineobj.AddShader(&vs);
1137 pipelineobj.AddShader(&ps);
1138
Tony Barbour6918cd52015-04-09 12:58:51 -06001139 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001140
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001141#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001142 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001143 MESH_BIND_ID, // binding ID
1144 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001145 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF3156cb02014-12-02 15:41:44 -07001146 };
1147
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001148 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001149 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1150 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001151 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001152 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF3156cb02014-12-02 15:41:44 -07001153
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001154 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF3156cb02014-12-02 15:41:44 -07001155 pipelineobj.AddVertexInputBindings(&vi_binding,1);
GregF3156cb02014-12-02 15:41:44 -07001156
Tony Barbour664accc2015-01-09 12:55:14 -07001157 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001158 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001159
Tony Barbourfe3351b2015-07-28 10:17:20 -06001160 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001161
Tony Barbourfe3351b2015-07-28 10:17:20 -06001162 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001163#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001164 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001165 pDSDumpDot((char*)"triTest2.dot");
1166#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001167 // render two triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -06001168 Draw(0, 6, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07001169
1170 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001171 EndCommandBuffer();
1172 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001173
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001174 RecordImages(m_renderTargets);
GregF3156cb02014-12-02 15:41:44 -07001175}
1176
Tony Barbour6918cd52015-04-09 12:58:51 -06001177TEST_F(VkRenderTest, GreyCirclesonBlueFade)
GregF3156cb02014-12-02 15:41:44 -07001178{
1179 // This tests reading gl_ClipDistance from FS
1180
1181 static const char *vertShaderText =
GregFaae75242015-06-03 18:40:50 -06001182 //"#version 140\n"
GregF3156cb02014-12-02 15:41:44 -07001183 "#version 330\n"
1184 "#extension GL_ARB_separate_shader_objects : enable\n"
1185 "#extension GL_ARB_shading_language_420pack : enable\n"
1186 "out gl_PerVertex {\n"
1187 " vec4 gl_Position;\n"
1188 " float gl_ClipDistance[1];\n"
1189 "};\n"
1190 "layout (location = 0) in vec4 pos;\n"
1191 "layout (location = 0) out vec4 outColor;\n"
1192 "layout (location = 1) out vec4 outColor2;\n"
1193 "void main() {\n"
1194 " gl_Position = pos;\n"
1195 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1196 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1197 " float dists[3];\n"
1198 " dists[0] = 0.0;\n"
1199 " dists[1] = 1.0;\n"
1200 " dists[2] = 1.0;\n"
1201 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1202 "}\n";
1203
1204
1205 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -06001206 "#version 140\n"
1207 //"#version 330\n"
GregF3156cb02014-12-02 15:41:44 -07001208 "#extension GL_ARB_separate_shader_objects : enable\n"
1209 "#extension GL_ARB_shading_language_420pack : enable\n"
1210 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1211 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1212 "layout (location = 0) in vec4 color;\n"
1213 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001214 "layout (location = 0) out vec4 uFragColor;\n"
GregF3156cb02014-12-02 15:41:44 -07001215 "void main() {\n"
1216 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1217 " float dist_squared = dot(pos, pos);\n"
GregFaae75242015-06-03 18:40:50 -06001218 " uFragColor = (dist_squared < 400.0)\n"
GregF3156cb02014-12-02 15:41:44 -07001219 " ? color * gl_ClipDistance[0]\n"
1220 " : color2;\n"
1221 "}\n";
1222
1223 ASSERT_NO_FATAL_FAILURE(InitState());
1224 ASSERT_NO_FATAL_FAILURE(InitViewport());
1225
Tony Barbour6918cd52015-04-09 12:58:51 -06001226 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001227 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001228
Tony Barbour6918cd52015-04-09 12:58:51 -06001229 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1230 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF3156cb02014-12-02 15:41:44 -07001231
Tony Barbour6918cd52015-04-09 12:58:51 -06001232 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001233 pipelineobj.AddColorAttachment();
GregF3156cb02014-12-02 15:41:44 -07001234 pipelineobj.AddShader(&vs);
1235 pipelineobj.AddShader(&ps);
1236
Tony Barbour6918cd52015-04-09 12:58:51 -06001237 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001238
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001239#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001240 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001241 MESH_BIND_ID, // binding ID
1242 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001243 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF3156cb02014-12-02 15:41:44 -07001244 };
1245
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001246 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001247 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1248 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001249 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001250 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF3156cb02014-12-02 15:41:44 -07001251
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001252 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF3156cb02014-12-02 15:41:44 -07001253 pipelineobj.AddVertexInputBindings(&vi_binding,1);
GregF3156cb02014-12-02 15:41:44 -07001254
Tony Barbour664accc2015-01-09 12:55:14 -07001255 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
GregF3156cb02014-12-02 15:41:44 -07001256
Tony Barbourfe3351b2015-07-28 10:17:20 -06001257 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001258
Tony Barbourfe3351b2015-07-28 10:17:20 -06001259 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001260
Tony Barbourfe3351b2015-07-28 10:17:20 -06001261 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001262#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001263 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001264 pDSDumpDot((char*)"triTest2.dot");
1265#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001266
1267 // render two triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -06001268 Draw(0, 6, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07001269
1270 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001271 EndCommandBuffer();
1272 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001273
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001274 RecordImages(m_renderTargets);
GregF3156cb02014-12-02 15:41:44 -07001275}
Tony Barboure2c58df2014-11-25 13:18:32 -07001276
Tony Barbour6918cd52015-04-09 12:58:51 -06001277TEST_F(VkRenderTest, GreyCirclesonBlueDiscard)
GregF42226582014-12-02 17:19:34 -07001278{
1279 static const char *vertShaderText =
1280 "#version 140\n"
1281 "#extension GL_ARB_separate_shader_objects : enable\n"
1282 "#extension GL_ARB_shading_language_420pack : enable\n"
1283 "layout (location = 0) in vec4 pos;\n"
1284 "layout (location = 0) out vec4 outColor;\n"
1285 "layout (location = 1) out vec4 outColor2;\n"
1286 "void main() {\n"
1287 " gl_Position = pos;\n"
1288 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1289 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1290 "}\n";
1291
1292
1293 static const char *fragShaderText =
GregF42226582014-12-02 17:19:34 -07001294 "#version 330\n"
1295 "#extension GL_ARB_separate_shader_objects : enable\n"
1296 "#extension GL_ARB_shading_language_420pack : enable\n"
1297 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1298 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1299 "layout (location = 0) in vec4 color;\n"
1300 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001301 "layout (location = 0) out vec4 outColor;\n"
GregF42226582014-12-02 17:19:34 -07001302 "void main() {\n"
1303 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1304 " float dist_squared = dot(pos, pos);\n"
1305 " if (dist_squared < 100.0)\n"
1306 " discard;\n"
GregFaae75242015-06-03 18:40:50 -06001307 " outColor = (dist_squared < 400.0)\n"
GregF42226582014-12-02 17:19:34 -07001308 " ? color\n"
1309 " : color2;\n"
1310 "}\n";
1311
1312 ASSERT_NO_FATAL_FAILURE(InitState());
1313 ASSERT_NO_FATAL_FAILURE(InitViewport());
1314
Tony Barbour6918cd52015-04-09 12:58:51 -06001315 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001316 meshBuffer.BufferMemoryBarrier();
GregF42226582014-12-02 17:19:34 -07001317
Tony Barbour6918cd52015-04-09 12:58:51 -06001318 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1319 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF42226582014-12-02 17:19:34 -07001320
Tony Barbour6918cd52015-04-09 12:58:51 -06001321 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001322 pipelineobj.AddColorAttachment();
GregF42226582014-12-02 17:19:34 -07001323 pipelineobj.AddShader(&vs);
1324 pipelineobj.AddShader(&ps);
1325
Tony Barbour6918cd52015-04-09 12:58:51 -06001326 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001327
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001328#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001329 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001330 MESH_BIND_ID, // binding ID
1331 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001332 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF42226582014-12-02 17:19:34 -07001333 };
1334
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001335 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001336 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1337 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001338 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001339 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF42226582014-12-02 17:19:34 -07001340
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001341 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF42226582014-12-02 17:19:34 -07001342 pipelineobj.AddVertexInputBindings(&vi_binding,1);
GregF42226582014-12-02 17:19:34 -07001343
Tony Barbour664accc2015-01-09 12:55:14 -07001344 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour664accc2015-01-09 12:55:14 -07001345
Tony Barbourfe3351b2015-07-28 10:17:20 -06001346 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001347
Tony Barbourfe3351b2015-07-28 10:17:20 -06001348 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001349
Tony Barbourfe3351b2015-07-28 10:17:20 -06001350 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001351#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001352 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001353 pDSDumpDot((char*)"triTest2.dot");
1354#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001355
1356 // render two triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -06001357 Draw(0, 6, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07001358
1359 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001360 EndCommandBuffer();
1361 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001362
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001363 RecordImages(m_renderTargets);
GregF42226582014-12-02 17:19:34 -07001364}
1365
1366
Tony Barbour6918cd52015-04-09 12:58:51 -06001367TEST_F(VkRenderTest, TriangleVSUniform)
Cody Northrop66594a72014-10-10 14:49:36 -06001368{
1369 static const char *vertShaderText =
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001370 "#version 140\n"
1371 "#extension GL_ARB_separate_shader_objects : enable\n"
1372 "#extension GL_ARB_shading_language_420pack : enable\n"
1373 "\n"
1374 "layout(binding = 0) uniform buf {\n"
1375 " mat4 MVP;\n"
1376 "} ubuf;\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001377 "void main() {\n"
1378 " vec2 vertices[3];"
1379 " vertices[0] = vec2(-0.5, -0.5);\n"
1380 " vertices[1] = vec2( 0.5, -0.5);\n"
1381 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001382 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001383 "}\n";
1384
1385 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -06001386 "#version 140\n"
1387 "#extension GL_ARB_separate_shader_objects : enable\n"
1388 "#extension GL_ARB_shading_language_420pack : enable\n"
1389 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001390 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001391 " outColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001392 "}\n";
1393
Tony Barboure2c58df2014-11-25 13:18:32 -07001394 ASSERT_NO_FATAL_FAILURE(InitState());
1395 ASSERT_NO_FATAL_FAILURE(InitViewport());
1396
Courtney Goeltzenleuchterfdcfb9f2014-10-10 18:04:39 -06001397 // Create identity matrix
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001398 glm::mat4 Projection = glm::mat4(1.0f);
1399 glm::mat4 View = glm::mat4(1.0f);
1400 glm::mat4 Model = glm::mat4(1.0f);
1401 glm::mat4 MVP = Projection * View * Model;
1402 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1403
Tony Barbour6918cd52015-04-09 12:58:51 -06001404 VkConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1405 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1406 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001407
Tony Barbour6918cd52015-04-09 12:58:51 -06001408 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001409 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001410 pipelineobj.AddShader(&vs);
1411 pipelineobj.AddShader(&ps);
1412
1413 // Create descriptor set and attach the constant buffer to it
Tony Barbour6918cd52015-04-09 12:58:51 -06001414 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001415 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07001416
Tony Barbour664accc2015-01-09 12:55:14 -07001417 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf1878c72015-08-18 14:24:32 -06001418
1419 VkCmdBufferBeginInfo cbBeginInfo;
1420 memset(&cbBeginInfo, 0, sizeof(VkCmdBufferBeginInfo));
1421 cbBeginInfo.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1422 cbBeginInfo.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT;
1423 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barboure2c58df2014-11-25 13:18:32 -07001424
Tony Barbourfe3351b2015-07-28 10:17:20 -06001425 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001426
Tony Barbour664accc2015-01-09 12:55:14 -07001427#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001428 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001429 pDSDumpDot((char*)"triTest2.dot");
1430#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001431
1432 // render two triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -06001433 Draw(0, 6, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07001434
1435 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001436 EndCommandBuffer();
1437 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001438
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001439 RecordImages(m_renderTargets);
Tony Barbour664accc2015-01-09 12:55:14 -07001440
Tony Barbourfe3351b2015-07-28 10:17:20 -06001441 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer);
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001442}
1443
Tony Barbour6918cd52015-04-09 12:58:51 -06001444TEST_F(VkRenderTest, MixTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07001445{
1446 // This tests location applied to varyings. Notice that we have switched foo
1447 // and bar in the FS. The triangle should be blended with red, green and blue
1448 // corners.
1449 static const char *vertShaderText =
1450 "#version 140\n"
1451 "#extension GL_ARB_separate_shader_objects : enable\n"
1452 "#extension GL_ARB_shading_language_420pack : enable\n"
1453 "layout (location=0) out vec4 bar;\n"
1454 "layout (location=1) out vec4 foo;\n"
1455 "layout (location=2) out float scale;\n"
1456 "vec2 vertices[3];\n"
1457 "void main() {\n"
1458 " vertices[0] = vec2(-1.0, -1.0);\n"
1459 " vertices[1] = vec2( 1.0, -1.0);\n"
1460 " vertices[2] = vec2( 0.0, 1.0);\n"
1461 "vec4 colors[3];\n"
1462 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1463 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1464 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1465 " foo = colors[gl_VertexID % 3];\n"
1466 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1467 " scale = 1.0;\n"
1468 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1469 "}\n";
1470
1471 static const char *fragShaderText =
1472 "#version 140\n"
1473 "#extension GL_ARB_separate_shader_objects : enable\n"
1474 "#extension GL_ARB_shading_language_420pack : enable\n"
1475 "layout (location = 1) in vec4 bar;\n"
1476 "layout (location = 0) in vec4 foo;\n"
1477 "layout (location = 2) in float scale;\n"
GregFaae75242015-06-03 18:40:50 -06001478 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001479 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001480 " outColor = bar * scale + foo * (1.0-scale);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001481 "}\n";
1482
1483 ASSERT_NO_FATAL_FAILURE(InitState());
1484 ASSERT_NO_FATAL_FAILURE(InitViewport());
1485
Tony Barbour6918cd52015-04-09 12:58:51 -06001486 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1487 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001488
Tony Barbour6918cd52015-04-09 12:58:51 -06001489 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001490 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001491 pipelineobj.AddShader(&vs);
1492 pipelineobj.AddShader(&ps);
1493
Tony Barbour6918cd52015-04-09 12:58:51 -06001494 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour831062d2015-04-02 15:43:15 -06001495 descriptorSet.AppendDummy();
Tony Barboure2c58df2014-11-25 13:18:32 -07001496
Tony Barbour664accc2015-01-09 12:55:14 -07001497 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour664accc2015-01-09 12:55:14 -07001498
Tony Barbourfe3351b2015-07-28 10:17:20 -06001499 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001500
Tony Barbourfe3351b2015-07-28 10:17:20 -06001501 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001502
1503#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001504 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001505 pDSDumpDot((char*)"triTest2.dot");
1506#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001507
Tony Barbour664accc2015-01-09 12:55:14 -07001508 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06001509 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07001510
1511 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001512 EndCommandBuffer();
1513 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001514
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001515 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001516}
1517
Tony Barbour6918cd52015-04-09 12:58:51 -06001518TEST_F(VkRenderTest, QuadVertFetchAndVertID)
Tony Barboure2c58df2014-11-25 13:18:32 -07001519{
1520 // This tests that attributes work in the presence of gl_VertexID
1521
1522 static const char *vertShaderText =
1523 "#version 140\n"
1524 "#extension GL_ARB_separate_shader_objects : enable\n"
1525 "#extension GL_ARB_shading_language_420pack : enable\n"
1526 //XYZ1( -1, -1, -1 )
1527 "layout (location = 0) in vec4 pos;\n"
1528 //XYZ1( 0.f, 0.f, 0.f )
1529 "layout (location = 1) in vec4 inColor;\n"
1530 "layout (location = 0) out vec4 outColor;\n"
1531 "void main() {\n"
1532 " outColor = inColor;\n"
1533 " vec4 vertices[3];"
1534 " vertices[gl_VertexID % 3] = pos;\n"
1535 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1536 "}\n";
1537
1538
1539 static const char *fragShaderText =
1540 "#version 140\n"
1541 "#extension GL_ARB_separate_shader_objects : enable\n"
1542 "#extension GL_ARB_shading_language_420pack : enable\n"
1543 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06001544 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001545 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001546 " outColor = color;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001547 "}\n";
1548
1549 ASSERT_NO_FATAL_FAILURE(InitState());
1550 ASSERT_NO_FATAL_FAILURE(InitViewport());
1551
Tony Barbour6918cd52015-04-09 12:58:51 -06001552 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001553 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07001554
Tony Barbour6918cd52015-04-09 12:58:51 -06001555 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1556 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001557
Tony Barbour6918cd52015-04-09 12:58:51 -06001558 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001559 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001560 pipelineobj.AddShader(&vs);
1561 pipelineobj.AddShader(&ps);
1562
Tony Barbour6918cd52015-04-09 12:58:51 -06001563 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001564
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001565#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001566 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001567 MESH_BUF_ID, // Binding ID
1568 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001569 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barboure2c58df2014-11-25 13:18:32 -07001570 };
1571
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001572 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001573 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1574 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001575 vi_attribs[0].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001576 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1577 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1578 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001579 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001580 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -07001581
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001582 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001583 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barboure2c58df2014-11-25 13:18:32 -07001584
Tony Barbour664accc2015-01-09 12:55:14 -07001585 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour664accc2015-01-09 12:55:14 -07001586
Tony Barbourfe3351b2015-07-28 10:17:20 -06001587 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001588
Tony Barbourfe3351b2015-07-28 10:17:20 -06001589 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001590
Tony Barbourfe3351b2015-07-28 10:17:20 -06001591 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001592#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001593 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001594 pDSDumpDot((char*)"triTest2.dot");
1595#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001596
1597 // render two triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -06001598 Draw(0, 6, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07001599
1600 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001601 EndCommandBuffer();
1602 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001603
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001604 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001605}
1606
Tony Barbour6918cd52015-04-09 12:58:51 -06001607TEST_F(VkRenderTest, QuadSparseVertFetch)
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001608{
1609 // This tests that attributes work in the presence of gl_VertexID
1610
1611 static const char *vertShaderText =
1612 "#version 140\n"
1613 "#extension GL_ARB_separate_shader_objects : enable\n"
1614 "#extension GL_ARB_shading_language_420pack : enable\n"
1615 //XYZ1( -1, -1, -1 )
1616 "layout (location = 1) in vec4 pos;\n"
1617 "layout (location = 4) in vec4 inColor;\n"
1618 //XYZ1( 0.f, 0.f, 0.f )
1619 "layout (location = 0) out vec4 outColor;\n"
1620 "void main() {\n"
1621 " outColor = inColor;\n"
1622 " gl_Position = pos;\n"
1623 "}\n";
1624
1625
1626 static const char *fragShaderText =
1627 "#version 140\n"
1628 "#extension GL_ARB_separate_shader_objects : enable\n"
1629 "#extension GL_ARB_shading_language_420pack : enable\n"
1630 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06001631 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001632 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001633 " outColor = color;\n"
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001634 "}\n";
1635
1636 ASSERT_NO_FATAL_FAILURE(InitState());
1637 ASSERT_NO_FATAL_FAILURE(InitViewport());
1638
1639 struct VDATA
1640 {
1641 float t1, t2, t3, t4; // filler data
1642 float posX, posY, posZ, posW; // Position data
1643 float r, g, b, a; // Color
1644 };
1645 const struct VDATA vData[] =
1646 {
1647 { XYZ1(0, 0, 0), XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
1648 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1649 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1650 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1651 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1652 { XYZ1(0, 0, 0), XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
1653 };
1654
Tony Barbour6918cd52015-04-09 12:58:51 -06001655 VkConstantBufferObj meshBuffer(m_device,sizeof(vData)/sizeof(vData[0]),sizeof(vData[0]), vData);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001656 meshBuffer.BufferMemoryBarrier();
1657
Tony Barbour6918cd52015-04-09 12:58:51 -06001658 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1659 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001660
Tony Barbour6918cd52015-04-09 12:58:51 -06001661 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001662 pipelineobj.AddColorAttachment();
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001663 pipelineobj.AddShader(&vs);
1664 pipelineobj.AddShader(&ps);
1665
Tony Barbour6918cd52015-04-09 12:58:51 -06001666 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001667
1668#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001669 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001670 MESH_BUF_ID, // Binding ID
1671 sizeof(vData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001672 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001673 };
1674
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001675 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001676 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1677 vi_attribs[0].location = 4;
Tony Barbourd1c35722015-04-16 15:59:00 -06001678 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001679 vi_attribs[0].offsetInBytes = sizeof(float) * 4 * 2; // Offset of first element in bytes from base of vertex
1680 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1681 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001682 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001683 vi_attribs[1].offsetInBytes = sizeof(float) * 4 * 1; // Offset of first element in bytes from base of vertex
1684
1685 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
1686 pipelineobj.AddVertexInputBindings(&vi_binding, 1);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001687
1688 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001689
Tony Barbourfe3351b2015-07-28 10:17:20 -06001690 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001691
Tony Barbourfe3351b2015-07-28 10:17:20 -06001692 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001693
Tony Barbourfe3351b2015-07-28 10:17:20 -06001694 BindVertexBuffer(&meshBuffer, 0, MESH_BUF_ID);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001695#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001696 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001697 pDSDumpDot((char*)"triTest2.dot");
1698#endif
1699
1700 // render two triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -06001701 Draw(0, 6, 0, 1);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001702
1703 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001704 EndCommandBuffer();
1705 QueueCommandBuffer();
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001706
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001707 RecordImages(m_renderTargets);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001708}
1709
Tony Barbour6918cd52015-04-09 12:58:51 -06001710TEST_F(VkRenderTest, TriVertFetchDeadAttr)
Tony Barboure2c58df2014-11-25 13:18:32 -07001711{
1712 // This tests that attributes work in the presence of gl_VertexID
1713 // and a dead attribute in position 0. Draws a triangle with yellow,
1714 // red and green corners, starting at top and going clockwise.
1715
1716 static const char *vertShaderText =
1717 "#version 140\n"
1718 "#extension GL_ARB_separate_shader_objects : enable\n"
1719 "#extension GL_ARB_shading_language_420pack : enable\n"
1720 //XYZ1( -1, -1, -1 )
1721 "layout (location = 0) in vec4 pos;\n"
1722 //XYZ1( 0.f, 0.f, 0.f )
1723 "layout (location = 1) in vec4 inColor;\n"
1724 "layout (location = 0) out vec4 outColor;\n"
1725 "void main() {\n"
1726 " outColor = inColor;\n"
1727 " vec2 vertices[3];"
1728 " vertices[0] = vec2(-1.0, -1.0);\n"
1729 " vertices[1] = vec2( 1.0, -1.0);\n"
1730 " vertices[2] = vec2( 0.0, 1.0);\n"
1731 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1732 "}\n";
1733
1734
1735 static const char *fragShaderText =
1736 "#version 140\n"
1737 "#extension GL_ARB_separate_shader_objects : enable\n"
1738 "#extension GL_ARB_shading_language_420pack : enable\n"
1739 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06001740 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001741 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001742 " outColor = color;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001743 "}\n";
1744
1745 ASSERT_NO_FATAL_FAILURE(InitState());
1746 ASSERT_NO_FATAL_FAILURE(InitViewport());
1747
Tony Barbour6918cd52015-04-09 12:58:51 -06001748 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001749 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07001750
Tony Barbour6918cd52015-04-09 12:58:51 -06001751 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1752 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001753
Tony Barbour6918cd52015-04-09 12:58:51 -06001754 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001755 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001756 pipelineobj.AddShader(&vs);
1757 pipelineobj.AddShader(&ps);
1758
Tony Barbour6918cd52015-04-09 12:58:51 -06001759 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001760
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001761#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001762 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001763 MESH_BUF_ID, // Binding ID
1764 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001765 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barboure2c58df2014-11-25 13:18:32 -07001766 };
1767
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001768 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001769 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1770 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001771 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001772 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1773 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1774 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001775 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001776 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -07001777
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001778 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001779 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barboure2c58df2014-11-25 13:18:32 -07001780
Tony Barbour664accc2015-01-09 12:55:14 -07001781 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboure2c58df2014-11-25 13:18:32 -07001782
Tony Barbourfe3351b2015-07-28 10:17:20 -06001783 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001784
Tony Barbourfe3351b2015-07-28 10:17:20 -06001785 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001786
Tony Barbourfe3351b2015-07-28 10:17:20 -06001787 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001788#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001789 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001790 pDSDumpDot((char*)"triTest2.dot");
1791#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001792
1793 // render two triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -06001794 Draw(0, 6, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07001795
1796 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001797 EndCommandBuffer();
1798 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001799
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001800 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001801}
1802
Tony Barbour6918cd52015-04-09 12:58:51 -06001803TEST_F(VkRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001804{
1805 static const char *vertShaderText =
1806 "#version 140\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001807 "#extension GL_ARB_separate_shader_objects : enable\n"
1808 "#extension GL_ARB_shading_language_420pack : enable\n"
GregFaae75242015-06-03 18:40:50 -06001809 "layout (std140, binding = 0) uniform bufferVals {\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001810 " mat4 mvp;\n"
1811 "} myBufferVals;\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001812 "layout (location = 0) in vec4 pos;\n"
1813 "layout (location = 1) in vec4 inColor;\n"
Cody Northrop8a3bb132015-06-16 17:32:04 -06001814 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001815 "void main() {\n"
1816 " outColor = inColor;\n"
1817 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06001818 " gl_Position.y = -gl_Position.y;\n"
1819 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001820 "}\n";
1821
1822 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -06001823 "#version 140\n"
1824 "#extension GL_ARB_separate_shader_objects : enable\n"
1825 "#extension GL_ARB_shading_language_420pack : enable\n"
1826 "layout (location = 0) in vec4 color;\n"
1827 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001828 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001829 " outColor = color;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001830 "}\n";
Tony Barboure2c58df2014-11-25 13:18:32 -07001831 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001832
Tony Barboure2c58df2014-11-25 13:18:32 -07001833 glm::mat4 View = glm::lookAt(
1834 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1835 glm::vec3(0,0,0), // and looks at the origin
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06001836 glm::vec3(0,-1,0) // Head is up (set to 0,-1,0 to look upside-down)
Tony Barboure2c58df2014-11-25 13:18:32 -07001837 );
1838
1839 glm::mat4 Model = glm::mat4(1.0f);
1840
1841 glm::mat4 MVP = Projection * View * Model;
1842
1843 ASSERT_NO_FATAL_FAILURE(InitState());
1844 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wub4052042015-07-09 10:16:34 +08001845 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Chia-I Wu08accc62015-07-07 11:50:03 +08001846 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height, m_depth_stencil_fmt);
Tony Barboure2c58df2014-11-25 13:18:32 -07001847
Tony Barbour6918cd52015-04-09 12:58:51 -06001848 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 -07001849 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1850
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001851 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barboure2c58df2014-11-25 13:18:32 -07001852
Tony Barbour6918cd52015-04-09 12:58:51 -06001853 VkConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1854 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1855 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001856
Tony Barbour6918cd52015-04-09 12:58:51 -06001857 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001858 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001859 pipelineobj.AddShader(&vs);
1860 pipelineobj.AddShader(&ps);
1861
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001862 VkPipelineDepthStencilStateCreateInfo ds_state;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001863 ds_state.depthTestEnable = VK_TRUE;
1864 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbourd1c35722015-04-16 15:59:00 -06001865 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Cody Northrop271ba752015-08-26 10:01:32 -06001866 ds_state.depthBoundsTestEnable = VK_FALSE;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001867 ds_state.stencilTestEnable = VK_FALSE;
1868 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
1869 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
1870 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbourd1c35722015-04-16 15:59:00 -06001871 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
Tony Barbourf52346d2015-01-16 14:27:35 -07001872 ds_state.front = ds_state.back;
1873 pipelineobj.SetDepthStencil(&ds_state);
1874
Tony Barbour6918cd52015-04-09 12:58:51 -06001875 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001876 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07001877
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001878#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001879 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001880 MESH_BUF_ID, // Binding ID
1881 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001882 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001883 };
Tony Barboure2c58df2014-11-25 13:18:32 -07001884
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001885 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001886 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1887 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001888 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001889 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1890 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1891 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001892 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001893 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -07001894
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001895 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001896 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barboure2c58df2014-11-25 13:18:32 -07001897
Tony Barbour1c45ce02015-03-27 17:03:18 -06001898 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour1c45ce02015-03-27 17:03:18 -06001899
Tony Barbourfe3351b2015-07-28 10:17:20 -06001900 ASSERT_VK_SUCCESS(BeginCommandBuffer());
1901 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barboure2c58df2014-11-25 13:18:32 -07001902
Tony Barbourfe3351b2015-07-28 10:17:20 -06001903 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour1fde6942015-01-09 10:06:53 -07001904#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001905 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour1fde6942015-01-09 10:06:53 -07001906 pDSDumpDot((char*)"triTest2.dot");
1907#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001908
1909 // render triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -06001910 Draw(0, 36, 0, 1);
Tony Barbour1fde6942015-01-09 10:06:53 -07001911
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001912
Tony Barbour1fde6942015-01-09 10:06:53 -07001913 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001914 EndCommandBuffer();
1915 QueueCommandBuffer();
Tony Barbour1fde6942015-01-09 10:06:53 -07001916
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001917 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001918}
1919
Tony Barbour6918cd52015-04-09 12:58:51 -06001920TEST_F(VkRenderTest, VSTexture)
Tony Barboure2c58df2014-11-25 13:18:32 -07001921{
1922 // The expected result from this test is a green and red triangle;
1923 // one red vertex on the left, two green vertices on the right.
1924 static const char *vertShaderText =
Cody Northrop8a3bb132015-06-16 17:32:04 -06001925 "#version 140\n"
1926 "#extension GL_ARB_separate_shader_objects : enable\n"
1927 "#extension GL_ARB_shading_language_420pack : enable\n"
1928 "layout (location = 0) out vec4 texColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001929 "uniform sampler2D surface;\n"
1930 "void main() {\n"
1931 " vec2 vertices[3];"
1932 " vertices[0] = vec2(-0.5, -0.5);\n"
1933 " vertices[1] = vec2( 0.5, -0.5);\n"
1934 " vertices[2] = vec2( 0.5, 0.5);\n"
1935 " vec2 positions[3];"
1936 " positions[0] = vec2( 0.0, 0.0);\n"
1937 " positions[1] = vec2( 0.25, 0.1);\n"
1938 " positions[2] = vec2( 0.1, 0.25);\n"
1939 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1940 " texColor = textureLod(surface, samplePos, 0.0);\n"
1941 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1942 "}\n";
1943
1944 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -06001945 "#version 140\n"
1946 "#extension GL_ARB_separate_shader_objects : enable\n"
1947 "#extension GL_ARB_shading_language_420pack : enable\n"
1948 "layout (location = 0) in vec4 texColor;\n"
1949 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001950 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001951 " outColor = texColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001952 "}\n";
1953
1954 ASSERT_NO_FATAL_FAILURE(InitState());
1955 ASSERT_NO_FATAL_FAILURE(InitViewport());
1956
Tony Barbour6918cd52015-04-09 12:58:51 -06001957 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1958 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
1959 VkSamplerObj sampler(m_device);
1960 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07001961
Tony Barbour6918cd52015-04-09 12:58:51 -06001962 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001963 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001964 pipelineobj.AddShader(&vs);
1965 pipelineobj.AddShader(&ps);
1966
Tony Barbour6918cd52015-04-09 12:58:51 -06001967 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08001968 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07001969
Tony Barbour664accc2015-01-09 12:55:14 -07001970 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001971 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure2c58df2014-11-25 13:18:32 -07001972
Tony Barbourfe3351b2015-07-28 10:17:20 -06001973 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001974
1975#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001976 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001977 pDSDumpDot((char*)"triTest2.dot");
1978#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001979
Tony Barbour664accc2015-01-09 12:55:14 -07001980 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06001981 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07001982
1983 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001984 EndCommandBuffer();
1985 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001986
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001987 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001988}
GregFaae75242015-06-03 18:40:50 -06001989
1990
1991
Tony Barbour6918cd52015-04-09 12:58:51 -06001992TEST_F(VkRenderTest, TexturedTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07001993{
1994 // The expected result from this test is a red and green checkered triangle
1995 static const char *vertShaderText =
1996 "#version 140\n"
1997 "#extension GL_ARB_separate_shader_objects : enable\n"
1998 "#extension GL_ARB_shading_language_420pack : enable\n"
1999 "layout (location = 0) out vec2 samplePos;\n"
2000 "void main() {\n"
2001 " vec2 vertices[3];"
2002 " vertices[0] = vec2(-0.5, -0.5);\n"
2003 " vertices[1] = vec2( 0.5, -0.5);\n"
2004 " vertices[2] = vec2( 0.5, 0.5);\n"
2005 " vec2 positions[3];"
2006 " positions[0] = vec2( 0.0, 0.0);\n"
2007 " positions[1] = vec2( 1.0, 0.0);\n"
2008 " positions[2] = vec2( 1.0, 1.0);\n"
2009 " samplePos = positions[gl_VertexID % 3];\n"
2010 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2011 "}\n";
2012
2013 static const char *fragShaderText =
2014 "#version 140\n"
2015 "#extension GL_ARB_separate_shader_objects : enable\n"
2016 "#extension GL_ARB_shading_language_420pack : enable\n"
2017 "layout (location = 0) in vec2 samplePos;\n"
2018 "layout (binding = 0) uniform sampler2D surface;\n"
2019 "layout (location=0) out vec4 outColor;\n"
2020 "void main() {\n"
2021 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2022 " outColor = texColor;\n"
2023 "}\n";
2024
2025 ASSERT_NO_FATAL_FAILURE(InitState());
2026 ASSERT_NO_FATAL_FAILURE(InitViewport());
2027
Tony Barbour6918cd52015-04-09 12:58:51 -06002028 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2029 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2030 VkSamplerObj sampler(m_device);
2031 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002032
Tony Barbour6918cd52015-04-09 12:58:51 -06002033 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002034 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002035 pipelineobj.AddShader(&vs);
2036 pipelineobj.AddShader(&ps);
2037
Tony Barbour6918cd52015-04-09 12:58:51 -06002038 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002039 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002040
Tony Barbour664accc2015-01-09 12:55:14 -07002041 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002042 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002043
Tony Barbourfe3351b2015-07-28 10:17:20 -06002044 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002045
2046#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002047 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002048 pDSDumpDot((char*)"triTest2.dot");
2049#endif
2050 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002051 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07002052
2053 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002054 EndCommandBuffer();
2055 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002056
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002057 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002058}
Tony Barbour6918cd52015-04-09 12:58:51 -06002059TEST_F(VkRenderTest, TexturedTriangleClip)
Tony Barboure2c58df2014-11-25 13:18:32 -07002060{
2061 // The expected result from this test is a red and green checkered triangle
2062 static const char *vertShaderText =
2063 "#version 330\n"
2064 "#extension GL_ARB_separate_shader_objects : enable\n"
2065 "#extension GL_ARB_shading_language_420pack : enable\n"
2066 "layout (location = 0) out vec2 samplePos;\n"
2067 "out gl_PerVertex {\n"
2068 " vec4 gl_Position;\n"
2069 " float gl_ClipDistance[1];\n"
2070 "};\n"
2071 "void main() {\n"
2072 " vec2 vertices[3];"
2073 " vertices[0] = vec2(-0.5, -0.5);\n"
2074 " vertices[1] = vec2( 0.5, -0.5);\n"
2075 " vertices[2] = vec2( 0.5, 0.5);\n"
2076 " vec2 positions[3];"
2077 " positions[0] = vec2( 0.0, 0.0);\n"
2078 " positions[1] = vec2( 1.0, 0.0);\n"
2079 " positions[2] = vec2( 1.0, 1.0);\n"
2080 " float dists[3];\n"
2081 " dists[0] = 1.0;\n"
2082 " dists[1] = 1.0;\n"
2083 " dists[2] = -1.0;\n"
2084 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2085 " samplePos = positions[gl_VertexID % 3];\n"
2086 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2087 "}\n";
2088
2089 static const char *fragShaderText =
2090 "#version 140\n"
2091 "#extension GL_ARB_separate_shader_objects : enable\n"
2092 "#extension GL_ARB_shading_language_420pack : enable\n"
2093 "layout (location = 0) in vec2 samplePos;\n"
2094 "layout (binding = 0) uniform sampler2D surface;\n"
2095 "layout (location=0) out vec4 outColor;\n"
2096 "void main() {\n"
2097 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2098 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2099 " outColor = texColor;\n"
2100 "}\n";
2101
2102
2103 ASSERT_NO_FATAL_FAILURE(InitState());
2104 ASSERT_NO_FATAL_FAILURE(InitViewport());
2105
Tony Barbour6918cd52015-04-09 12:58:51 -06002106 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2107 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2108 VkSamplerObj sampler(m_device);
2109 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002110
Tony Barbour6918cd52015-04-09 12:58:51 -06002111 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002112 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002113 pipelineobj.AddShader(&vs);
2114 pipelineobj.AddShader(&ps);
2115
Tony Barbour6918cd52015-04-09 12:58:51 -06002116 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002117 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002118
Tony Barbour664accc2015-01-09 12:55:14 -07002119 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002120 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002121
Tony Barbourfe3351b2015-07-28 10:17:20 -06002122 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002123
2124#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002125 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002126 pDSDumpDot((char*)"triTest2.dot");
2127#endif
2128 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002129 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07002130
2131 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002132 EndCommandBuffer();
2133 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002134
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002135 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002136}
GregFaae75242015-06-03 18:40:50 -06002137
Tony Barbour6918cd52015-04-09 12:58:51 -06002138TEST_F(VkRenderTest, FSTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07002139{
2140 // The expected result from this test is a red and green checkered triangle
2141 static const char *vertShaderText =
2142 "#version 140\n"
2143 "#extension GL_ARB_separate_shader_objects : enable\n"
2144 "#extension GL_ARB_shading_language_420pack : enable\n"
2145 "layout (location = 0) out vec2 samplePos;\n"
2146 "void main() {\n"
2147 " vec2 vertices[3];"
2148 " vertices[0] = vec2(-0.5, -0.5);\n"
2149 " vertices[1] = vec2( 0.5, -0.5);\n"
2150 " vertices[2] = vec2( 0.5, 0.5);\n"
2151 " vec2 positions[3];"
2152 " positions[0] = vec2( 0.0, 0.0);\n"
2153 " positions[1] = vec2( 1.0, 0.0);\n"
2154 " positions[2] = vec2( 1.0, 1.0);\n"
2155 " samplePos = positions[gl_VertexID % 3];\n"
2156 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2157 "}\n";
2158
2159 static const char *fragShaderText =
2160 "#version 140\n"
2161 "#extension GL_ARB_separate_shader_objects : enable\n"
2162 "#extension GL_ARB_shading_language_420pack : enable\n"
2163 "layout (location = 0) in vec2 samplePos;\n"
2164 "layout (binding = 0) uniform sampler2D surface;\n"
2165 "layout (location=0) out vec4 outColor;\n"
2166 "void main() {\n"
2167 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2168 " outColor = texColor;\n"
2169 "}\n";
2170
2171 ASSERT_NO_FATAL_FAILURE(InitState());
2172 ASSERT_NO_FATAL_FAILURE(InitViewport());
2173
Tony Barbour6918cd52015-04-09 12:58:51 -06002174 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2175 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2176 VkSamplerObj sampler(m_device);
2177 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002178
Tony Barbour6918cd52015-04-09 12:58:51 -06002179 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002180 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002181 pipelineobj.AddShader(&vs);
2182 pipelineobj.AddShader(&ps);
2183
Tony Barbour6918cd52015-04-09 12:58:51 -06002184 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002185 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002186
Tony Barbour664accc2015-01-09 12:55:14 -07002187 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002188 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002189
Tony Barbourfe3351b2015-07-28 10:17:20 -06002190 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002191
2192#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002193 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002194 pDSDumpDot((char*)"triTest2.dot");
2195#endif
2196 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002197 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07002198
2199 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002200 EndCommandBuffer();
2201 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002202
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002203 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002204}
Tony Barbour6918cd52015-04-09 12:58:51 -06002205TEST_F(VkRenderTest, SamplerBindingsTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07002206{
2207 // This test sets bindings on the samplers
2208 // For now we are asserting that sampler and texture pairs
2209 // march in lock step, and are set via GLSL binding. This can
2210 // and will probably change.
2211 // The sampler bindings should match the sampler and texture slot
2212 // number set up by the application.
2213 // This test will result in a blue triangle
2214 static const char *vertShaderText =
2215 "#version 140\n"
2216 "#extension GL_ARB_separate_shader_objects : enable\n"
2217 "#extension GL_ARB_shading_language_420pack : enable\n"
2218 "layout (location = 0) out vec4 samplePos;\n"
2219 "void main() {\n"
2220 " vec2 vertices[3];"
2221 " vertices[0] = vec2(-0.5, -0.5);\n"
2222 " vertices[1] = vec2( 0.5, -0.5);\n"
2223 " vertices[2] = vec2( 0.5, 0.5);\n"
2224 " vec2 positions[3];"
2225 " positions[0] = vec2( 0.0, 0.0);\n"
2226 " positions[1] = vec2( 1.0, 0.0);\n"
2227 " positions[2] = vec2( 1.0, 1.0);\n"
2228 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2229 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2230 "}\n";
2231
2232 static const char *fragShaderText =
2233 "#version 140\n"
2234 "#extension GL_ARB_separate_shader_objects : enable\n"
2235 "#extension GL_ARB_shading_language_420pack : enable\n"
2236 "layout (location = 0) in vec4 samplePos;\n"
2237 "layout (binding = 0) uniform sampler2D surface0;\n"
2238 "layout (binding = 1) uniform sampler2D surface1;\n"
2239 "layout (binding = 12) uniform sampler2D surface2;\n"
GregFaae75242015-06-03 18:40:50 -06002240 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002241 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06002242 " outColor = textureLod(surface2, samplePos.xy, 0.0);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002243 "}\n";
2244
2245 ASSERT_NO_FATAL_FAILURE(InitState());
2246 ASSERT_NO_FATAL_FAILURE(InitViewport());
2247
Tony Barbour6918cd52015-04-09 12:58:51 -06002248 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2249 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002250
Tony Barbour6918cd52015-04-09 12:58:51 -06002251 VkSamplerObj sampler1(m_device);
2252 VkSamplerObj sampler2(m_device);
2253 VkSamplerObj sampler3(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002254
Tony Barbourebc093f2015-04-01 16:38:10 -06002255 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
Tony Barbour6918cd52015-04-09 12:58:51 -06002256 VkTextureObj texture1(m_device, tex_colors); // Red
Tony Barbourebc093f2015-04-01 16:38:10 -06002257 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
Tony Barbour6918cd52015-04-09 12:58:51 -06002258 VkTextureObj texture2(m_device, tex_colors); // Green
Tony Barbourebc093f2015-04-01 16:38:10 -06002259 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
Tony Barbour6918cd52015-04-09 12:58:51 -06002260 VkTextureObj texture3(m_device, tex_colors); // Blue
Tony Barboure2c58df2014-11-25 13:18:32 -07002261
Tony Barbour6918cd52015-04-09 12:58:51 -06002262 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002263 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002264 pipelineobj.AddShader(&vs);
2265 pipelineobj.AddShader(&ps);
2266
Tony Barbour6918cd52015-04-09 12:58:51 -06002267 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002268 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2269 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2270 for (int i = 0; i < 10; i++)
2271 descriptorSet.AppendDummy();
2272 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barboure2c58df2014-11-25 13:18:32 -07002273
Tony Barbour664accc2015-01-09 12:55:14 -07002274 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002275 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002276
Tony Barbourfe3351b2015-07-28 10:17:20 -06002277 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002278
2279#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002280 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002281 pDSDumpDot((char*)"triTest2.dot");
2282#endif
2283 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002284 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07002285
2286 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002287 EndCommandBuffer();
2288 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002289
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002290 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002291}
2292
Tony Barbour6918cd52015-04-09 12:58:51 -06002293TEST_F(VkRenderTest, TriangleVSUniformBlock)
Tony Barboure2c58df2014-11-25 13:18:32 -07002294{
2295 // The expected result from this test is a blue triangle
2296
2297 static const char *vertShaderText =
2298 "#version 140\n"
2299 "#extension GL_ARB_separate_shader_objects : enable\n"
2300 "#extension GL_ARB_shading_language_420pack : enable\n"
2301 "layout (location = 0) out vec4 outColor;\n"
2302 "layout (std140, binding = 0) uniform bufferVals {\n"
2303 " vec4 red;\n"
2304 " vec4 green;\n"
2305 " vec4 blue;\n"
2306 " vec4 white;\n"
2307 "} myBufferVals;\n"
2308 "void main() {\n"
2309 " vec2 vertices[3];"
2310 " vertices[0] = vec2(-0.5, -0.5);\n"
2311 " vertices[1] = vec2( 0.5, -0.5);\n"
2312 " vertices[2] = vec2( 0.5, 0.5);\n"
2313 " outColor = myBufferVals.blue;\n"
2314 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2315 "}\n";
2316
2317 static const char *fragShaderText =
2318 "#version 140\n"
2319 "#extension GL_ARB_separate_shader_objects : enable\n"
2320 "#extension GL_ARB_shading_language_420pack : enable\n"
2321 "layout (location = 0) in vec4 inColor;\n"
GregFaae75242015-06-03 18:40:50 -06002322 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002323 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06002324 " outColor = inColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002325 "}\n";
2326
2327 ASSERT_NO_FATAL_FAILURE(InitState());
2328 ASSERT_NO_FATAL_FAILURE(InitViewport());
2329
Tony Barbour6918cd52015-04-09 12:58:51 -06002330 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2331 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002332
2333 // Let's populate our buffer with the following:
2334 // vec4 red;
2335 // vec4 green;
2336 // vec4 blue;
2337 // vec4 white;
2338 const int valCount = 4 * 4;
2339 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2340 0.0, 1.0, 0.0, 1.0,
2341 0.0, 0.0, 1.0, 1.0,
2342 1.0, 1.0, 1.0, 1.0 };
2343
Tony Barbour6918cd52015-04-09 12:58:51 -06002344 VkConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002345
Tony Barbour6918cd52015-04-09 12:58:51 -06002346 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002347 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002348 pipelineobj.AddShader(&vs);
2349 pipelineobj.AddShader(&ps);
2350
Tony Barbour6918cd52015-04-09 12:58:51 -06002351 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002352 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, colorBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002353
Tony Barbour664accc2015-01-09 12:55:14 -07002354 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002355 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002356
Tony Barbourfe3351b2015-07-28 10:17:20 -06002357 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002358
2359#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002360 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002361 pDSDumpDot((char*)"triTest2.dot");
2362#endif
2363 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002364 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07002365
2366 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002367 EndCommandBuffer();
2368 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002369
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002370 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002371}
2372
Tony Barbour6918cd52015-04-09 12:58:51 -06002373TEST_F(VkRenderTest, TriangleFSUniformBlockBinding)
Tony Barboure2c58df2014-11-25 13:18:32 -07002374{
2375 // This test allows the shader to select which buffer it is
2376 // pulling from using layout binding qualifier.
2377 // There are corresponding changes in the compiler stack that
2378 // will select the buffer using binding directly.
2379 // The binding number should match the slot number set up by
2380 // the application.
2381 // The expected result from this test is a purple triangle
2382
2383 static const char *vertShaderText =
2384 "#version 140\n"
2385 "#extension GL_ARB_separate_shader_objects : enable\n"
2386 "#extension GL_ARB_shading_language_420pack : enable\n"
2387 "void main() {\n"
2388 " vec2 vertices[3];"
2389 " vertices[0] = vec2(-0.5, -0.5);\n"
2390 " vertices[1] = vec2( 0.5, -0.5);\n"
2391 " vertices[2] = vec2( 0.5, 0.5);\n"
2392 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2393 "}\n";
2394
2395 static const char *fragShaderText =
2396 "#version 140\n"
2397 "#extension GL_ARB_separate_shader_objects : enable\n"
2398 "#extension GL_ARB_shading_language_420pack : enable\n"
2399 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2400 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2401 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wu11078b02015-01-04 16:27:24 +08002402 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
GregFaae75242015-06-03 18:40:50 -06002403 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002404 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06002405 " outColor = myBlueVal.color;\n"
2406 " outColor += myRedVal.color;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002407 "}\n";
2408
2409 ASSERT_NO_FATAL_FAILURE(InitState());
2410 ASSERT_NO_FATAL_FAILURE(InitViewport());
2411
Tony Barbour6918cd52015-04-09 12:58:51 -06002412 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2413 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002414
2415 // We're going to create a number of uniform buffers, and then allow
2416 // the shader to select which it wants to read from with a binding
2417
2418 // Let's populate the buffers with a single color each:
2419 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2420 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2421 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wu11078b02015-01-04 16:27:24 +08002422 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barboure2c58df2014-11-25 13:18:32 -07002423
2424 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2425 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2426 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2427 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2428
2429 const int redCount = sizeof(redVals) / sizeof(float);
2430 const int greenCount = sizeof(greenVals) / sizeof(float);
2431 const int blueCount = sizeof(blueVals) / sizeof(float);
2432 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2433
Tony Barbour6918cd52015-04-09 12:58:51 -06002434 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002435
Tony Barbour6918cd52015-04-09 12:58:51 -06002436 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002437
Tony Barbour6918cd52015-04-09 12:58:51 -06002438 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002439
Tony Barbour6918cd52015-04-09 12:58:51 -06002440 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002441
Tony Barbour6918cd52015-04-09 12:58:51 -06002442 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002443 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002444 pipelineobj.AddShader(&vs);
2445 pipelineobj.AddShader(&ps);
2446
Tony Barbour6918cd52015-04-09 12:58:51 -06002447 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002448 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2449 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2450 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2451 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002452
Tony Barbour664accc2015-01-09 12:55:14 -07002453 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002454 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure2c58df2014-11-25 13:18:32 -07002455
Tony Barbourfe3351b2015-07-28 10:17:20 -06002456 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002457
2458#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002459 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002460 pDSDumpDot((char*)"triTest2.dot");
2461#endif
2462 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002463 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07002464
2465 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002466 EndCommandBuffer();
2467 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002468
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002469 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002470}
2471
Tony Barbour6918cd52015-04-09 12:58:51 -06002472TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBinding)
Tony Barboure2c58df2014-11-25 13:18:32 -07002473{
2474 // This test is the same as TriangleFSUniformBlockBinding, but
2475 // it does not provide an instance name.
2476 // The expected result from this test is a purple triangle
2477
2478 static const char *vertShaderText =
2479 "#version 140\n"
2480 "#extension GL_ARB_separate_shader_objects : enable\n"
2481 "#extension GL_ARB_shading_language_420pack : enable\n"
2482 "void main() {\n"
2483 " vec2 vertices[3];"
2484 " vertices[0] = vec2(-0.5, -0.5);\n"
2485 " vertices[1] = vec2( 0.5, -0.5);\n"
2486 " vertices[2] = vec2( 0.5, 0.5);\n"
2487 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2488 "}\n";
2489
2490 static const char *fragShaderText =
2491 "#version 430\n"
2492 "#extension GL_ARB_separate_shader_objects : enable\n"
2493 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002494 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2495 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2496 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wu11078b02015-01-04 16:27:24 +08002497 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northropd43c52e2014-12-05 15:44:14 -07002498 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002499 "void main() {\n"
Cody Northropd43c52e2014-12-05 15:44:14 -07002500 " outColor = blue;\n"
2501 " outColor += red;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002502 "}\n";
2503 ASSERT_NO_FATAL_FAILURE(InitState());
2504 ASSERT_NO_FATAL_FAILURE(InitViewport());
2505
Tony Barbour6918cd52015-04-09 12:58:51 -06002506 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2507 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002508
2509 // We're going to create a number of uniform buffers, and then allow
2510 // the shader to select which it wants to read from with a binding
2511
2512 // Let's populate the buffers with a single color each:
2513 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2514 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2515 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2516 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2517
2518 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2519 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2520 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2521 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2522
2523 const int redCount = sizeof(redVals) / sizeof(float);
2524 const int greenCount = sizeof(greenVals) / sizeof(float);
2525 const int blueCount = sizeof(blueVals) / sizeof(float);
2526 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2527
Tony Barbour6918cd52015-04-09 12:58:51 -06002528 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002529
Tony Barbour6918cd52015-04-09 12:58:51 -06002530 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002531
Tony Barbour6918cd52015-04-09 12:58:51 -06002532 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002533
Tony Barbour6918cd52015-04-09 12:58:51 -06002534 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002535
Tony Barbour6918cd52015-04-09 12:58:51 -06002536 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002537 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002538 pipelineobj.AddShader(&vs);
2539 pipelineobj.AddShader(&ps);
2540
Tony Barbour6918cd52015-04-09 12:58:51 -06002541 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002542 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2543 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2544 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2545 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002546
Tony Barbour664accc2015-01-09 12:55:14 -07002547 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002548 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002549
Tony Barbourfe3351b2015-07-28 10:17:20 -06002550 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002551
2552#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002553 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002554 pDSDumpDot((char*)"triTest2.dot");
2555#endif
2556 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002557 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07002558
2559 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002560 EndCommandBuffer();
2561 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002562
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002563 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002564}
2565
GregF6084aec2015-07-01 16:11:09 -06002566TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBindingWithStruct)
2567{
2568 // This test is the same as TriangleFSUniformBlockBinding, but
2569 // it does not provide an instance name.
2570 // The expected result from this test is a purple triangle
2571
2572 static const char *vertShaderText =
2573 "#version 140\n"
2574 "#extension GL_ARB_separate_shader_objects : enable\n"
2575 "#extension GL_ARB_shading_language_420pack : enable\n"
2576 "void main() {\n"
2577 " vec2 vertices[3];"
2578 " vertices[0] = vec2(-0.5, -0.5);\n"
2579 " vertices[1] = vec2( 0.5, -0.5);\n"
2580 " vertices[2] = vec2( 0.5, 0.5);\n"
2581 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2582 "}\n";
2583
2584 static const char *fragShaderText =
2585 "#version 430\n"
2586 "#extension GL_ARB_separate_shader_objects : enable\n"
2587 "#extension GL_ARB_shading_language_420pack : enable\n"
2588 "\n"
2589 " struct PS_INPUT {\n"
2590 " vec2 member0;\n"
2591 " vec4 member1;\n"
2592 " vec4 member2;\n"
2593 " vec4 member3;\n"
2594 " vec4 member4;\n"
2595 " vec4 member5;\n"
2596 " vec4 member6;\n"
2597 " vec4 member7;\n"
2598 " vec4 member8;\n"
2599 " vec4 member9;\n"
2600 " };\n"
2601 "\n"
2602 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2603 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2604 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2605 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
2606 "layout (location = 0) out vec4 outColor;\n"
2607 "PS_INPUT MainFs()\n"
2608 "{\n"
2609 " PS_INPUT o;\n"
2610 " o.member9 = red;\n"
2611 " return o;\n"
2612 "}\n"
2613 "\n"
2614 "void main()\n"
2615 "{\n"
2616 " PS_INPUT o;\n"
2617 " o = MainFs();\n"
2618 " outColor = blue;"
2619 " outColor += o.member9;\n"
2620 "}\n";;
2621 ASSERT_NO_FATAL_FAILURE(InitState());
2622 ASSERT_NO_FATAL_FAILURE(InitViewport());
2623
2624 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2625 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2626
2627 // We're going to create a number of uniform buffers, and then allow
2628 // the shader to select which it wants to read from with a binding
2629
2630 // Let's populate the buffers with a single color each:
2631 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2632 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2633 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2634 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2635
2636 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2637 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2638 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2639 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2640
2641 const int redCount = sizeof(redVals) / sizeof(float);
2642 const int greenCount = sizeof(greenVals) / sizeof(float);
2643 const int blueCount = sizeof(blueVals) / sizeof(float);
2644 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2645
2646 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2647
2648 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2649
2650 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2651
2652 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
2653
2654 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002655 pipelineobj.AddColorAttachment();
GregF6084aec2015-07-01 16:11:09 -06002656 pipelineobj.AddShader(&vs);
2657 pipelineobj.AddShader(&ps);
2658
2659 VkDescriptorSetObj descriptorSet(m_device);
2660 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2661 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2662 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2663 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
2664
2665 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002666 ASSERT_VK_SUCCESS(BeginCommandBuffer());
GregF6084aec2015-07-01 16:11:09 -06002667
Tony Barbourfe3351b2015-07-28 10:17:20 -06002668 GenericDrawPreparation(pipelineobj, descriptorSet);
GregF6084aec2015-07-01 16:11:09 -06002669
2670#ifdef DUMP_STATE_DOT
2671 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
2672 pDSDumpDot((char*)"triTest2.dot");
2673#endif
2674 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002675 Draw(0, 3, 0, 1);
GregF6084aec2015-07-01 16:11:09 -06002676
2677 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002678 EndCommandBuffer();
2679 QueueCommandBuffer();
GregF6084aec2015-07-01 16:11:09 -06002680
2681 RecordImages(m_renderTargets);
2682}
2683
Tony Barbour6918cd52015-04-09 12:58:51 -06002684TEST_F(VkRenderTest, CubeWithVertexFetchAndMVPAndTexture)
Tony Barboure2c58df2014-11-25 13:18:32 -07002685{
2686 static const char *vertShaderText =
2687 "#version 140\n"
2688 "#extension GL_ARB_separate_shader_objects : enable\n"
2689 "#extension GL_ARB_shading_language_420pack : enable\n"
2690 "layout (std140, binding=0) uniform bufferVals {\n"
2691 " mat4 mvp;\n"
2692 "} myBufferVals;\n"
2693 "layout (location=0) in vec4 pos;\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002694 "layout (location=1) in vec2 input_uv;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002695 "layout (location=0) out vec2 UV;\n"
2696 "void main() {\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002697 " UV = input_uv;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002698 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002699 " gl_Position.y = -gl_Position.y;\n"
2700 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002701 "}\n";
2702
2703 static const char *fragShaderText =
2704 "#version 140\n"
2705 "#extension GL_ARB_separate_shader_objects : enable\n"
2706 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wu11078b02015-01-04 16:27:24 +08002707 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002708 "layout (location=0) out vec4 outColor;\n"
2709 "layout (location=0) in vec2 UV;\n"
2710 "void main() {\n"
2711 " outColor= textureLod(surface, UV, 0.0);\n"
2712 "}\n";
2713 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2714
2715 glm::mat4 View = glm::lookAt(
2716 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2717 glm::vec3(0,0,0), // and looks at the origin
2718 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2719 );
2720
2721 glm::mat4 Model = glm::mat4(1.0f);
2722
2723 glm::mat4 MVP = Projection * View * Model;
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002724 int num_verts = sizeof(g_vb_texture_Data) / sizeof(g_vb_texture_Data[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002725
2726
2727 ASSERT_NO_FATAL_FAILURE(InitState());
2728 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wub4052042015-07-09 10:16:34 +08002729 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Chia-I Wu08accc62015-07-07 11:50:03 +08002730 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height, m_depth_stencil_fmt);
Tony Barboure2c58df2014-11-25 13:18:32 -07002731
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002732 VkConstantBufferObj meshBuffer(m_device, num_verts,
2733 sizeof(g_vb_texture_Data[0]), g_vb_texture_Data);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00002734 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07002735
Mark Lobodzinski17caf572015-01-29 08:55:56 -06002736 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barboure2c58df2014-11-25 13:18:32 -07002737
Tony Barbour6918cd52015-04-09 12:58:51 -06002738 VkConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2739 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2740 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2741 VkSamplerObj sampler(m_device);
2742 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002743
Tony Barbour6918cd52015-04-09 12:58:51 -06002744 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002745 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002746 pipelineobj.AddShader(&vs);
2747 pipelineobj.AddShader(&ps);
2748
Tony Barbour6918cd52015-04-09 12:58:51 -06002749 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002750 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mvpBuffer);
Chia-I Wu11078b02015-01-04 16:27:24 +08002751 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002752
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002753#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002754 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002755 MESH_BIND_ID, // binding ID
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002756 sizeof(g_vb_texture_Data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002757 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002758 };
Tony Barboure2c58df2014-11-25 13:18:32 -07002759
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002760 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002761 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2762 vi_attribs[0].location = 0; // location
Tony Barbourd1c35722015-04-16 15:59:00 -06002763 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002764 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2765 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2766 vi_attribs[1].location = 1; // location
2767 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
2768 vi_attribs[1].offsetInBytes = 16; // Offset of uv components
Tony Barboure2c58df2014-11-25 13:18:32 -07002769
Tony Barboure2c58df2014-11-25 13:18:32 -07002770 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002771 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barboure2c58df2014-11-25 13:18:32 -07002772
Tony Barbourdd6e32e2015-07-10 15:29:03 -06002773 VkPipelineDepthStencilStateCreateInfo ds_state;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002774 ds_state.depthTestEnable = VK_TRUE;
2775 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbourd1c35722015-04-16 15:59:00 -06002776 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Cody Northrop271ba752015-08-26 10:01:32 -06002777 ds_state.depthBoundsTestEnable = VK_FALSE;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002778 ds_state.stencilTestEnable = VK_FALSE;
2779 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
2780 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
2781 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbourd1c35722015-04-16 15:59:00 -06002782 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
Tony Barbourf52346d2015-01-16 14:27:35 -07002783 ds_state.front = ds_state.back;
2784 pipelineobj.SetDepthStencil(&ds_state);
2785
Tony Barbour1c45ce02015-03-27 17:03:18 -06002786 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tobin Ehlisf1878c72015-08-18 14:24:32 -06002787
2788 VkCmdBufferBeginInfo cbBeginInfo;
2789 memset(&cbBeginInfo, 0, sizeof(VkCmdBufferBeginInfo));
2790 cbBeginInfo.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
2791 cbBeginInfo.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT;
2792 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barboure2c58df2014-11-25 13:18:32 -07002793
Tony Barbourfe3351b2015-07-28 10:17:20 -06002794 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002795
Tony Barbourfe3351b2015-07-28 10:17:20 -06002796 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002797#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002798 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002799 pDSDumpDot((char*)"triTest2.dot");
2800#endif
2801 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002802 Draw(0, num_verts, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07002803
2804 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002805 EndCommandBuffer();
2806 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002807
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002808 RecordImages(m_renderTargets);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002809 RotateTriangleVSUniform(Projection, View, Model, &mvpBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002810}
Cody Northropf1990a92014-12-09 11:17:01 -07002811
Tony Barbour6918cd52015-04-09 12:58:51 -06002812TEST_F(VkRenderTest, TriangleMixedSamplerUniformBlockBinding)
Cody Northropf1990a92014-12-09 11:17:01 -07002813{
2814 // This test mixes binding slots of textures and buffers, ensuring
2815 // that sparse and overlapping assignments work.
Cody Northropb110b4f2014-12-09 13:59:39 -07002816 // The expected result from this test is a purple triangle, although
Cody Northropf1990a92014-12-09 11:17:01 -07002817 // you can modify it to move the desired result around.
2818
2819 static const char *vertShaderText =
2820 "#version 140\n"
2821 "#extension GL_ARB_separate_shader_objects : enable\n"
2822 "#extension GL_ARB_shading_language_420pack : enable\n"
2823 "void main() {\n"
2824 " vec2 vertices[3];"
2825 " vertices[0] = vec2(-0.5, -0.5);\n"
2826 " vertices[1] = vec2( 0.5, -0.5);\n"
2827 " vertices[2] = vec2( 0.5, 0.5);\n"
2828 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2829 "}\n";
2830
2831 static const char *fragShaderText =
2832 "#version 430\n"
2833 "#extension GL_ARB_separate_shader_objects : enable\n"
2834 "#extension GL_ARB_shading_language_420pack : enable\n"
2835 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wu11078b02015-01-04 16:27:24 +08002836 "layout (binding = 3) uniform sampler2D surface1;\n"
2837 "layout (binding = 1) uniform sampler2D surface2;\n"
2838 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002839
Cody Northropb110b4f2014-12-09 13:59:39 -07002840
Chia-I Wu11078b02015-01-04 16:27:24 +08002841 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2842 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2843 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2844 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropf1990a92014-12-09 11:17:01 -07002845 "layout (location = 0) out vec4 outColor;\n"
2846 "void main() {\n"
Cody Northropb110b4f2014-12-09 13:59:39 -07002847 " outColor = red * vec4(0.00001);\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002848 " outColor += white * vec4(0.00001);\n"
2849 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropb110b4f2014-12-09 13:59:39 -07002850 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002851 "}\n";
2852 ASSERT_NO_FATAL_FAILURE(InitState());
2853 ASSERT_NO_FATAL_FAILURE(InitViewport());
2854
Tony Barbour6918cd52015-04-09 12:58:51 -06002855 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2856 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northropf1990a92014-12-09 11:17:01 -07002857
Cody Northropf1990a92014-12-09 11:17:01 -07002858 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2859 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2860 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2861 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2862
2863 const int redCount = sizeof(redVals) / sizeof(float);
2864 const int greenCount = sizeof(greenVals) / sizeof(float);
2865 const int blueCount = sizeof(blueVals) / sizeof(float);
2866 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2867
Tony Barbour6918cd52015-04-09 12:58:51 -06002868 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2869 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2870 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2871 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropf1990a92014-12-09 11:17:01 -07002872
Tony Barbourebc093f2015-04-01 16:38:10 -06002873 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour6918cd52015-04-09 12:58:51 -06002874 VkSamplerObj sampler0(m_device);
2875 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbourebc093f2015-04-01 16:38:10 -06002876 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour6918cd52015-04-09 12:58:51 -06002877 VkSamplerObj sampler2(m_device);
2878 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbourebc093f2015-04-01 16:38:10 -06002879 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour6918cd52015-04-09 12:58:51 -06002880 VkSamplerObj sampler4(m_device);
2881 VkTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropb110b4f2014-12-09 13:59:39 -07002882
2883 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2884 // TODO: Get back here ASAP and understand why.
Tony Barbourebc093f2015-04-01 16:38:10 -06002885 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour6918cd52015-04-09 12:58:51 -06002886 VkSamplerObj sampler7(m_device);
2887 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropf1990a92014-12-09 11:17:01 -07002888
Tony Barbour6918cd52015-04-09 12:58:51 -06002889 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002890 pipelineobj.AddColorAttachment();
Cody Northropf1990a92014-12-09 11:17:01 -07002891 pipelineobj.AddShader(&vs);
2892 pipelineobj.AddShader(&ps);
2893
Tony Barbour6918cd52015-04-09 12:58:51 -06002894 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002895 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2896 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2897 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2898 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002899 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
Chia-I Wu11078b02015-01-04 16:27:24 +08002900 // swap blue and green
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002901 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2902 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2903 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropf1990a92014-12-09 11:17:01 -07002904
Tony Barbour664accc2015-01-09 12:55:14 -07002905 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002906 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropf1990a92014-12-09 11:17:01 -07002907
Tony Barbourfe3351b2015-07-28 10:17:20 -06002908 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002909
2910#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002911 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002912 pDSDumpDot((char*)"triTest2.dot");
2913#endif
2914 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002915 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07002916
2917 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002918 EndCommandBuffer();
2919 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002920
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002921 RecordImages(m_renderTargets);
Cody Northropf1990a92014-12-09 11:17:01 -07002922}
2923
Tony Barbour6918cd52015-04-09 12:58:51 -06002924TEST_F(VkRenderTest, TriangleMatchingSamplerUniformBlockBinding)
Cody Northropbd531de2014-12-09 19:08:54 -07002925{
2926 // This test matches binding slots of textures and buffers, requiring
2927 // the driver to give them distinct number spaces.
2928 // The expected result from this test is a red triangle, although
2929 // you can modify it to move the desired result around.
2930
2931 static const char *vertShaderText =
2932 "#version 140\n"
2933 "#extension GL_ARB_separate_shader_objects : enable\n"
2934 "#extension GL_ARB_shading_language_420pack : enable\n"
2935 "void main() {\n"
2936 " vec2 vertices[3];"
2937 " vertices[0] = vec2(-0.5, -0.5);\n"
2938 " vertices[1] = vec2( 0.5, -0.5);\n"
2939 " vertices[2] = vec2( 0.5, 0.5);\n"
2940 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2941 "}\n";
2942
2943 static const char *fragShaderText =
2944 "#version 430\n"
2945 "#extension GL_ARB_separate_shader_objects : enable\n"
2946 "#extension GL_ARB_shading_language_420pack : enable\n"
2947 "layout (binding = 0) uniform sampler2D surface0;\n"
2948 "layout (binding = 1) uniform sampler2D surface1;\n"
2949 "layout (binding = 2) uniform sampler2D surface2;\n"
2950 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wu11078b02015-01-04 16:27:24 +08002951 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2952 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2953 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2954 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropbd531de2014-12-09 19:08:54 -07002955 "layout (location = 0) out vec4 outColor;\n"
2956 "void main() {\n"
2957 " outColor = red;// * vec4(0.00001);\n"
2958 " outColor += white * vec4(0.00001);\n"
2959 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2960 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2961 "}\n";
2962 ASSERT_NO_FATAL_FAILURE(InitState());
2963 ASSERT_NO_FATAL_FAILURE(InitViewport());
2964
Tony Barbour6918cd52015-04-09 12:58:51 -06002965 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2966 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northropbd531de2014-12-09 19:08:54 -07002967
2968 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2969 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2970 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2971 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2972
2973 const int redCount = sizeof(redVals) / sizeof(float);
2974 const int greenCount = sizeof(greenVals) / sizeof(float);
2975 const int blueCount = sizeof(blueVals) / sizeof(float);
2976 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2977
Tony Barbour6918cd52015-04-09 12:58:51 -06002978 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2979 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2980 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2981 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropbd531de2014-12-09 19:08:54 -07002982
Tony Barbourebc093f2015-04-01 16:38:10 -06002983 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour6918cd52015-04-09 12:58:51 -06002984 VkSamplerObj sampler0(m_device);
2985 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbourebc093f2015-04-01 16:38:10 -06002986 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour6918cd52015-04-09 12:58:51 -06002987 VkSamplerObj sampler2(m_device);
2988 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbourebc093f2015-04-01 16:38:10 -06002989 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour6918cd52015-04-09 12:58:51 -06002990 VkSamplerObj sampler4(m_device);
2991 VkTextureObj texture4(m_device, tex_colors); // Light Green
Tony Barbourebc093f2015-04-01 16:38:10 -06002992 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour6918cd52015-04-09 12:58:51 -06002993 VkSamplerObj sampler7(m_device);
2994 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropbd531de2014-12-09 19:08:54 -07002995
Tony Barbour6918cd52015-04-09 12:58:51 -06002996 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002997 pipelineobj.AddColorAttachment();
Cody Northropbd531de2014-12-09 19:08:54 -07002998 pipelineobj.AddShader(&vs);
2999 pipelineobj.AddShader(&ps);
3000
Tony Barbour6918cd52015-04-09 12:58:51 -06003001 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08003002 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3003 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3004 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
3005 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003006 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
3007 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
3008 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
3009 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropbd531de2014-12-09 19:08:54 -07003010
Tony Barbour664accc2015-01-09 12:55:14 -07003011 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003012 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropbd531de2014-12-09 19:08:54 -07003013
Tony Barbourfe3351b2015-07-28 10:17:20 -06003014 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07003015
3016#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003017 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07003018 pDSDumpDot((char*)"triTest2.dot");
3019#endif
3020 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06003021 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07003022
3023 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003024 EndCommandBuffer();
3025 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07003026
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06003027 RecordImages(m_renderTargets);
Cody Northropbd531de2014-12-09 19:08:54 -07003028}
3029
Tony Barbour6918cd52015-04-09 12:58:51 -06003030TEST_F(VkRenderTest, TriangleUniformBufferLayout)
Cody Northrop04ad1202014-12-17 15:26:33 -07003031{
3032 // This test populates a buffer with a variety of different data
3033 // types, then reads them out with a shader.
3034 // The expected result from this test is a green triangle
3035
3036 static const char *vertShaderText =
3037 "#version 140\n"
3038 "#extension GL_ARB_separate_shader_objects : enable\n"
3039 "#extension GL_ARB_shading_language_420pack : enable\n"
3040 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3041 " vec4 fRed;\n"
3042 " vec4 fGreen;\n"
3043 " layout(row_major) mat4 worldToProj;\n"
3044 " layout(row_major) mat4 projToWorld;\n"
3045 " layout(row_major) mat4 worldToView;\n"
3046 " layout(row_major) mat4 viewToProj;\n"
3047 " layout(row_major) mat4 worldToShadow[4];\n"
3048 " float fZero;\n"
3049 " float fOne;\n"
3050 " float fTwo;\n"
3051 " float fThree;\n"
3052 " vec3 fZeroZeroZero;\n"
3053 " float fFour;\n"
3054 " vec3 fZeroZeroOne;\n"
3055 " float fFive;\n"
3056 " vec3 fZeroOneZero;\n"
3057 " float fSix;\n"
3058 " float fSeven;\n"
3059 " float fEight;\n"
3060 " float fNine;\n"
3061 " vec2 fZeroZero;\n"
3062 " vec2 fZeroOne;\n"
3063 " vec4 fBlue;\n"
3064 " vec2 fOneZero;\n"
3065 " vec2 fOneOne;\n"
3066 " vec3 fZeroOneOne;\n"
3067 " float fTen;\n"
3068 " float fEleven;\n"
3069 " float fTwelve;\n"
3070 " vec3 fOneZeroZero;\n"
3071 " vec4 uvOffsets[4];\n"
3072 "};\n"
3073 "layout (location = 0) out vec4 color;"
3074 "void main() {\n"
3075
3076 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3077 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3078 " \n"
3079
3080 // do some exact comparisons, even though we should
3081 // really have an epsilon involved.
3082 " vec4 outColor = right;\n"
3083 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3084 " outColor = wrong;\n"
3085 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3086 " outColor = wrong;\n"
3087 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3088 " outColor = wrong;\n"
3089
3090 " color = outColor;\n"
3091
3092 // generic position stuff
3093 " vec2 vertices;\n"
3094 " int vertexSelector = gl_VertexID;\n"
3095 " if (vertexSelector == 0)\n"
3096 " vertices = vec2(-0.5, -0.5);\n"
3097 " else if (vertexSelector == 1)\n"
3098 " vertices = vec2( 0.5, -0.5);\n"
3099 " else if (vertexSelector == 2)\n"
3100 " vertices = vec2( 0.5, 0.5);\n"
3101 " else\n"
3102 " vertices = vec2( 0.0, 0.0);\n"
3103 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3104 "}\n";
3105
3106 static const char *fragShaderText =
3107 "#version 140\n"
3108 "#extension GL_ARB_separate_shader_objects : enable\n"
3109 "#extension GL_ARB_shading_language_420pack : enable\n"
3110 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3111 " vec4 fRed;\n"
3112 " vec4 fGreen;\n"
3113 " layout(row_major) mat4 worldToProj;\n"
3114 " layout(row_major) mat4 projToWorld;\n"
3115 " layout(row_major) mat4 worldToView;\n"
3116 " layout(row_major) mat4 viewToProj;\n"
3117 " layout(row_major) mat4 worldToShadow[4];\n"
3118 " float fZero;\n"
3119 " float fOne;\n"
3120 " float fTwo;\n"
3121 " float fThree;\n"
3122 " vec3 fZeroZeroZero;\n"
3123 " float fFour;\n"
3124 " vec3 fZeroZeroOne;\n"
3125 " float fFive;\n"
3126 " vec3 fZeroOneZero;\n"
3127 " float fSix;\n"
3128 " float fSeven;\n"
3129 " float fEight;\n"
3130 " float fNine;\n"
3131 " vec2 fZeroZero;\n"
3132 " vec2 fZeroOne;\n"
3133 " vec4 fBlue;\n"
3134 " vec2 fOneZero;\n"
3135 " vec2 fOneOne;\n"
3136 " vec3 fZeroOneOne;\n"
3137 " float fTen;\n"
3138 " float fEleven;\n"
3139 " float fTwelve;\n"
3140 " vec3 fOneZeroZero;\n"
3141 " vec4 uvOffsets[4];\n"
3142 "};\n"
3143 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06003144 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop04ad1202014-12-17 15:26:33 -07003145 "void main() {\n"
3146 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3147 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3148 " \n"
3149
3150 // start with VS value to ensure it passed
3151 " vec4 outColor = color;\n"
3152
3153 // do some exact comparisons, even though we should
3154 // really have an epsilon involved.
3155 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3156 " outColor = wrong;\n"
3157 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3158 " outColor = wrong;\n"
3159 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3160 " outColor = wrong;\n"
3161 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3162 " outColor = wrong;\n"
3163 " if (fTwo != 2.0)\n"
3164 " outColor = wrong;\n"
3165 " if (fOneOne != vec2(1.0, 1.0))\n"
3166 " outColor = wrong;\n"
3167 " if (fTen != 10.0)\n"
3168 " outColor = wrong;\n"
3169 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3170 " outColor = wrong;\n"
3171 " \n"
GregFaae75242015-06-03 18:40:50 -06003172 " uFragColor = outColor;\n"
Cody Northrop04ad1202014-12-17 15:26:33 -07003173 "}\n";
3174
3175
Cody Northropd2ad0342015-08-05 11:15:02 -06003176 const float mixedVals[196] = { 1.0f, 0.0f, 0.0f, 1.0f, // vec4 fRed; // align
3177 0.0f, 1.0f, 0.0f, 1.0f, // vec4 fGreen; // align
3178 1.0f, 0.0f, 0.0f, 1.0f, // layout(row_major) mat4 worldToProj;
3179 0.0f, 1.0f, 0.0f, 1.0f, // align
3180 0.0f, 0.0f, 1.0f, 1.0f, // align
3181 0.0f, 0.0f, 0.0f, 1.0f, // align
3182 2.0f, 0.0f, 0.0f, 2.0f, // layout(row_major) mat4 projToWorld;
3183 0.0f, 2.0f, 0.0f, 2.0f, // align
3184 0.0f, 0.0f, 2.0f, 2.0f, // align
3185 0.0f, 0.0f, 0.0f, 2.0f, // align
3186 3.0f, 0.0f, 0.0f, 3.0f, // layout(row_major) mat4 worldToView;
3187 0.0f, 3.0f, 0.0f, 3.0f, // align
3188 0.0f, 0.0f, 3.0f, 3.0f, // align
3189 0.0f, 0.0f, 0.0f, 3.0f, // align
3190 4.0f, 0.0f, 0.0f, 4.0f, // layout(row_major) mat4 viewToProj;
3191 0.0f, 4.0f, 0.0f, 4.0f, // align
3192 0.0f, 0.0f, 4.0f, 4.0f, // align
3193 0.0f, 0.0f, 0.0f, 4.0f, // align
3194 5.0f, 0.0f, 0.0f, 5.0f, // layout(row_major) mat4 worldToShadow[4];
3195 0.0f, 5.0f, 0.0f, 5.0f, // align
3196 0.0f, 0.0f, 5.0f, 5.0f, // align
3197 0.0f, 0.0f, 0.0f, 5.0f, // align
3198 6.0f, 0.0f, 0.0f, 6.0f, // align
3199 0.0f, 6.0f, 0.0f, 6.0f, // align
3200 0.0f, 0.0f, 6.0f, 6.0f, // align
3201 0.0f, 0.0f, 0.0f, 6.0f, // align
3202 7.0f, 0.0f, 0.0f, 7.0f, // align
3203 0.0f, 7.0f, 0.0f, 7.0f, // align
3204 0.0f, 0.0f, 7.0f, 7.0f, // align
3205 0.0f, 0.0f, 0.0f, 7.0f, // align
3206 8.0f, 0.0f, 0.0f, 8.0f, // align
3207 0.0f, 8.0f, 0.0f, 8.0f, // align
3208 0.0f, 0.0f, 8.0f, 8.0f, // align
3209 0.0f, 0.0f, 0.0f, 8.0f, // align
3210 0.0f, // float fZero; // align
3211 1.0f, // float fOne; // pack
3212 2.0f, // float fTwo; // pack
3213 3.0f, // float fThree; // pack
3214 0.0f, 0.0f, 0.0f, // vec3 fZeroZeroZero; // align
3215 4.0f, // float fFour; // pack
3216 0.0f, 0.0f, 1.0f, // vec3 fZeroZeroOne; // align
3217 5.0f, // float fFive; // pack
3218 0.0f, 1.0f, 0.0f, // vec3 fZeroOneZero; // align
3219 6.0f, // float fSix; // pack
3220 7.0f, // float fSeven; // align
3221 8.0f, // float fEight; // pack
3222 9.0f, // float fNine; // pack
3223 0.0f, // BUFFER
3224 0.0f, 0.0f, // vec2 fZeroZero; // align
3225 0.0f, 1.0f, // vec2 fZeroOne; // pack
3226 0.0f, 0.0f, 1.0f, 1.0f, // vec4 fBlue; // align
3227 1.0f, 0.0f, // vec2 fOneZero; // align
3228 1.0f, 1.0f, // vec2 fOneOne; // pack
3229 0.0f, 1.0f, 1.0f, // vec3 fZeroOneOne; // align
3230 10.0f, // float fTen; // pack
3231 11.0f, // float fEleven; // align
3232 12.0f, // float fTwelve; // pack
3233 0.0f, 0.0f, // BUFFER
3234 1.0f, 0.0f, 0.0f, // vec3 fOneZeroZero; // align
3235 0.0f, // BUFFER
3236 0.1f, 0.2f, 0.3f, 0.4f, // vec4 uvOffsets[4];
3237 0.5f, 0.6f, 0.7f, 0.8f, // align
3238 0.9f, 1.0f, 1.1f, 1.2f, // align
3239 1.3f, 1.4f, 1.5f, 1.6f, // align
Cody Northrop04ad1202014-12-17 15:26:33 -07003240 };
3241
3242 ASSERT_NO_FATAL_FAILURE(InitState());
3243 ASSERT_NO_FATAL_FAILURE(InitViewport());
3244
3245 const int constCount = sizeof(mixedVals) / sizeof(float);
3246
Tony Barbour6918cd52015-04-09 12:58:51 -06003247 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3248 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop04ad1202014-12-17 15:26:33 -07003249
Tony Barbour6918cd52015-04-09 12:58:51 -06003250 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop04ad1202014-12-17 15:26:33 -07003251
Tony Barbour6918cd52015-04-09 12:58:51 -06003252 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003253 pipelineobj.AddColorAttachment();
Cody Northrop04ad1202014-12-17 15:26:33 -07003254 pipelineobj.AddShader(&vs);
3255 pipelineobj.AddShader(&ps);
3256
Tony Barbour6918cd52015-04-09 12:58:51 -06003257 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003258 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
Cody Northrop04ad1202014-12-17 15:26:33 -07003259
3260 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003261 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop04ad1202014-12-17 15:26:33 -07003262
Tony Barbourfe3351b2015-07-28 10:17:20 -06003263 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop04ad1202014-12-17 15:26:33 -07003264
3265#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003266 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop04ad1202014-12-17 15:26:33 -07003267 pDSDumpDot((char*)"triTest2.dot");
3268#endif
3269 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06003270 Draw(0, 3, 0, 1);
Cody Northrop04ad1202014-12-17 15:26:33 -07003271
3272 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003273 EndCommandBuffer();
3274 QueueCommandBuffer();
Cody Northrop04ad1202014-12-17 15:26:33 -07003275
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06003276 RecordImages(m_renderTargets);
Cody Northrop04ad1202014-12-17 15:26:33 -07003277}
3278
Cody Northrop95638152015-05-07 14:39:12 -06003279TEST_F(VkRenderTest, TextureGather)
3280{
3281 // This test introduces textureGather and textureGatherOffset
3282 // Each call is compared against an expected inline color result
3283 // Green triangle means everything worked as expected
3284 // Red means something went wrong
3285
Cody Northropc55900f2015-08-06 13:18:13 -06003286 // disable SPV until texture gather is turned on in glsl->SPV
3287 if (!m_use_glsl) {
3288 printf("Skipping test that requires GLSL path (TextureGather)\n");
3289 return;
3290 }
3291
Cody Northrop95638152015-05-07 14:39:12 -06003292 static const char *vertShaderText =
3293 "#version 140\n"
3294 "#extension GL_ARB_separate_shader_objects : enable\n"
3295 "#extension GL_ARB_shading_language_420pack : enable\n"
3296 "void main() {\n"
3297 " vec2 vertices[3];"
3298 " vertices[0] = vec2(-0.5, -0.5);\n"
3299 " vertices[1] = vec2( 0.5, -0.5);\n"
3300 " vertices[2] = vec2( 0.5, 0.5);\n"
3301 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
3302 "}\n";
3303
3304 static const char *fragShaderText =
3305 "#version 430\n"
3306 "#extension GL_ARB_separate_shader_objects : enable\n"
3307 "#extension GL_ARB_shading_language_420pack : enable\n"
3308 "layout (binding = 0) uniform sampler2D surface0;\n"
3309 "layout (binding = 1) uniform sampler2D surface1;\n"
3310 "layout (binding = 2) uniform sampler2D surface2;\n"
3311 "layout (binding = 3) uniform sampler2D surface3;\n"
3312 "layout (location = 0) out vec4 outColor;\n"
3313 "void main() {\n"
3314
3315 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3316 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3317
3318 " vec4 color = right;\n"
3319
3320 // Grab a normal texture sample to ensure it can work in conjuntion
3321 // with textureGather (there are some intracacies in the backend)
3322 " vec4 sampledColor = textureLod(surface2, vec2(0.5), 0.0);\n"
3323 " if (sampledColor != vec4(0.0, 0.0, 1.0, 1.0))\n"
3324 " color = wrong;\n"
3325
3326 " vec4 gatheredColor = textureGather(surface0, vec2(0.5), 0);\n"
3327 // This just grabbed four red components from a red surface
3328 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3329 " color = wrong;\n"
3330
3331 // Yes, this is using an offset of 0, we don't have enough fine grained
3332 // control of the texture contents here.
3333 " gatheredColor = textureGatherOffset(surface1, vec2(0.5), ivec2(0, 0), 1);\n"
3334 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3335 " color = wrong;\n"
3336
3337 " outColor = color;\n"
3338
3339 "}\n";
3340
3341 ASSERT_NO_FATAL_FAILURE(InitState());
3342 ASSERT_NO_FATAL_FAILURE(InitViewport());
3343
3344 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3345 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3346
3347 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
3348 VkSamplerObj sampler0(m_device);
3349 VkTextureObj texture0(m_device, tex_colors); // Red
3350 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
3351 VkSamplerObj sampler1(m_device);
3352 VkTextureObj texture1(m_device, tex_colors); // Green
3353 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
3354 VkSamplerObj sampler2(m_device);
3355 VkTextureObj texture2(m_device, tex_colors); // Blue
3356 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
3357 VkSamplerObj sampler3(m_device);
3358 VkTextureObj texture3(m_device, tex_colors); // Red and Blue
3359
3360 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003361 pipelineobj.AddColorAttachment();
Cody Northrop95638152015-05-07 14:39:12 -06003362 pipelineobj.AddShader(&vs);
3363 pipelineobj.AddShader(&ps);
3364
3365 VkDescriptorSetObj descriptorSet(m_device);
3366 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3367 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
3368 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3369 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
3370
3371 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003372 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop95638152015-05-07 14:39:12 -06003373
Tony Barbourfe3351b2015-07-28 10:17:20 -06003374 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop95638152015-05-07 14:39:12 -06003375
3376 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06003377 Draw(0, 3, 0, 1);
Cody Northrop95638152015-05-07 14:39:12 -06003378
3379 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003380 EndCommandBuffer();
3381 QueueCommandBuffer();
Cody Northrop95638152015-05-07 14:39:12 -06003382
3383 RecordImages(m_renderTargets);
Cody Northrop95638152015-05-07 14:39:12 -06003384}
3385
Cody Northrop475663c2015-04-15 11:19:06 -06003386TEST_F(VkRenderTest, GeometryShaderHelloWorld)
3387{
3388 // This test introduces a geometry shader that simply
3389 // changes the color of each vertex to red, green, blue
3390
3391 static const char *vertShaderText =
3392 "#version 140\n"
3393 "#extension GL_ARB_separate_shader_objects : enable\n"
3394 "#extension GL_ARB_shading_language_420pack : enable\n"
3395 "layout (location = 0) out vec4 color;"
3396 "void main() {\n"
3397
3398 // VS writes out red
3399 " color = vec4(1.0, 0.0, 0.0, 1.0);\n"
3400
3401 // generic position stuff
3402 " vec2 vertices;\n"
3403 " int vertexSelector = gl_VertexID;\n"
3404 " if (vertexSelector == 0)\n"
3405 " vertices = vec2(-0.5, -0.5);\n"
3406 " else if (vertexSelector == 1)\n"
3407 " vertices = vec2( 0.5, -0.5);\n"
3408 " else if (vertexSelector == 2)\n"
3409 " vertices = vec2( 0.5, 0.5);\n"
3410 " else\n"
3411 " vertices = vec2( 0.0, 0.0);\n"
3412 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3413
3414 "}\n";
3415
3416 static const char *geomShaderText =
3417 "#version 330\n"
3418 "#extension GL_ARB_separate_shader_objects : enable\n"
3419 "#extension GL_ARB_shading_language_420pack : enable\n"
3420 "layout( triangles ) in;\n"
3421 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3422 "layout( location = 0 ) in vec4 inColor[3];\n"
3423 "layout( location = 0 ) out vec4 outColor;\n"
3424 "void main()\n"
3425 "{\n"
3426
3427 // first vertex, pass through red
3428 " gl_Position = gl_in[0].gl_Position;\n"
3429 " outColor = inColor[0];\n"
3430 " EmitVertex();\n"
3431
3432 // second vertex, green
3433 " gl_Position = gl_in[1].gl_Position;\n"
3434 " outColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3435 " EmitVertex();\n"
3436
3437 // third vertex, blue
3438 " gl_Position = gl_in[2].gl_Position;\n"
3439 " outColor = vec4(0.0, 0.0, 1.0, 1.0);\n"
3440 " EmitVertex();\n"
3441
3442 // done
3443 " EndPrimitive();\n"
3444 "}\n";
3445
3446
3447 static const char *fragShaderText =
3448 "#version 140\n"
3449 "#extension GL_ARB_separate_shader_objects : enable\n"
3450 "#extension GL_ARB_shading_language_420pack : enable\n"
3451 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06003452 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003453 "void main() {\n"
3454 // pass through
GregFaae75242015-06-03 18:40:50 -06003455 " outColor = color;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003456 "}\n";
3457
3458
3459
3460 ASSERT_NO_FATAL_FAILURE(InitState());
3461 ASSERT_NO_FATAL_FAILURE(InitViewport());
3462
3463 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3464 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3465 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3466
3467 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003468 pipelineobj.AddColorAttachment();
Cody Northrop475663c2015-04-15 11:19:06 -06003469 pipelineobj.AddShader(&vs);
3470 pipelineobj.AddShader(&gs);
3471 pipelineobj.AddShader(&ps);
3472
3473 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003474 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop475663c2015-04-15 11:19:06 -06003475
3476 VkDescriptorSetObj descriptorSet(m_device);
3477
Tony Barbourfe3351b2015-07-28 10:17:20 -06003478 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop475663c2015-04-15 11:19:06 -06003479
3480 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06003481 Draw(0, 3, 0, 1);
Cody Northrop475663c2015-04-15 11:19:06 -06003482
3483 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003484 EndCommandBuffer();
3485 QueueCommandBuffer();
Cody Northrop475663c2015-04-15 11:19:06 -06003486
3487 RecordImages(m_renderTargets);
3488}
3489
3490TEST_F(VkRenderTest, GSUniformBufferLayout)
3491{
3492 // This test is just like TriangleUniformBufferLayout but adds
3493 // geometry as a stage that also does UBO lookups
3494 // The expected result from this test is a green triangle
3495
3496 static const char *vertShaderText =
3497 "#version 140\n"
3498 "#extension GL_ARB_separate_shader_objects : enable\n"
3499 "#extension GL_ARB_shading_language_420pack : enable\n"
3500 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3501 " vec4 fRed;\n"
3502 " vec4 fGreen;\n"
3503 " layout(row_major) mat4 worldToProj;\n"
3504 " layout(row_major) mat4 projToWorld;\n"
3505 " layout(row_major) mat4 worldToView;\n"
3506 " layout(row_major) mat4 viewToProj;\n"
3507 " layout(row_major) mat4 worldToShadow[4];\n"
3508 " float fZero;\n"
3509 " float fOne;\n"
3510 " float fTwo;\n"
3511 " float fThree;\n"
3512 " vec3 fZeroZeroZero;\n"
3513 " float fFour;\n"
3514 " vec3 fZeroZeroOne;\n"
3515 " float fFive;\n"
3516 " vec3 fZeroOneZero;\n"
3517 " float fSix;\n"
3518 " float fSeven;\n"
3519 " float fEight;\n"
3520 " float fNine;\n"
3521 " vec2 fZeroZero;\n"
3522 " vec2 fZeroOne;\n"
3523 " vec4 fBlue;\n"
3524 " vec2 fOneZero;\n"
3525 " vec2 fOneOne;\n"
3526 " vec3 fZeroOneOne;\n"
3527 " float fTen;\n"
3528 " float fEleven;\n"
3529 " float fTwelve;\n"
3530 " vec3 fOneZeroZero;\n"
3531 " vec4 uvOffsets[4];\n"
3532 "};\n"
3533 "layout (location = 0) out vec4 color;"
3534 "void main() {\n"
3535
3536 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3537 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3538 " \n"
3539
3540 // do some exact comparisons, even though we should
3541 // really have an epsilon involved.
3542 " vec4 outColor = right;\n"
3543 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3544 " outColor = wrong;\n"
3545 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3546 " outColor = wrong;\n"
3547 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3548 " outColor = wrong;\n"
3549
3550 " color = outColor;\n"
3551
3552 // generic position stuff
3553 " vec2 vertices;\n"
3554 " int vertexSelector = gl_VertexID;\n"
3555 " if (vertexSelector == 0)\n"
3556 " vertices = vec2(-0.5, -0.5);\n"
3557 " else if (vertexSelector == 1)\n"
3558 " vertices = vec2( 0.5, -0.5);\n"
3559 " else if (vertexSelector == 2)\n"
3560 " vertices = vec2( 0.5, 0.5);\n"
3561 " else\n"
3562 " vertices = vec2( 0.0, 0.0);\n"
3563 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3564 "}\n";
3565
3566 static const char *geomShaderText =
3567 "#version 330\n"
3568 "#extension GL_ARB_separate_shader_objects : enable\n"
3569 "#extension GL_ARB_shading_language_420pack : enable\n"
3570
3571 // GS layout stuff
3572 "layout( triangles ) in;\n"
3573 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3574
3575 // Between stage IO
3576 "layout( location = 0 ) in vec4 inColor[3];\n"
3577 "layout( location = 0 ) out vec4 color;\n"
3578
3579 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3580 " vec4 fRed;\n"
3581 " vec4 fGreen;\n"
3582 " layout(row_major) mat4 worldToProj;\n"
3583 " layout(row_major) mat4 projToWorld;\n"
3584 " layout(row_major) mat4 worldToView;\n"
3585 " layout(row_major) mat4 viewToProj;\n"
3586 " layout(row_major) mat4 worldToShadow[4];\n"
3587 " float fZero;\n"
3588 " float fOne;\n"
3589 " float fTwo;\n"
3590 " float fThree;\n"
3591 " vec3 fZeroZeroZero;\n"
3592 " float fFour;\n"
3593 " vec3 fZeroZeroOne;\n"
3594 " float fFive;\n"
3595 " vec3 fZeroOneZero;\n"
3596 " float fSix;\n"
3597 " float fSeven;\n"
3598 " float fEight;\n"
3599 " float fNine;\n"
3600 " vec2 fZeroZero;\n"
3601 " vec2 fZeroOne;\n"
3602 " vec4 fBlue;\n"
3603 " vec2 fOneZero;\n"
3604 " vec2 fOneOne;\n"
3605 " vec3 fZeroOneOne;\n"
3606 " float fTen;\n"
3607 " float fEleven;\n"
3608 " float fTwelve;\n"
3609 " vec3 fOneZeroZero;\n"
3610 " vec4 uvOffsets[4];\n"
3611 "};\n"
3612
3613 "void main()\n"
3614 "{\n"
3615
3616 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3617 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3618
3619 // Each vertex will validate it can read VS output
3620 // then check a few values from the UBO
3621
3622 // first vertex
3623 " vec4 outColor = inColor[0];\n"
3624
3625 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3626 " outColor = wrong;\n"
3627 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3628 " outColor = wrong;\n"
3629 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3630 " outColor = wrong;\n"
3631 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3632 " outColor = wrong;\n"
3633
3634 " gl_Position = gl_in[0].gl_Position;\n"
3635 " color = outColor;\n"
3636 " EmitVertex();\n"
3637
3638 // second vertex
3639 " outColor = inColor[1];\n"
3640
3641 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3642 " outColor = wrong;\n"
3643 " if (fSix != 6.0)\n"
3644 " outColor = wrong;\n"
3645 " if (fOneOne != vec2(1.0, 1.0))\n"
3646 " outColor = wrong;\n"
3647
3648 " gl_Position = gl_in[1].gl_Position;\n"
3649 " color = outColor;\n"
3650 " EmitVertex();\n"
3651
3652 // third vertex
3653 " outColor = inColor[2];\n"
3654
3655 " if (fSeven != 7.0)\n"
3656 " outColor = wrong;\n"
3657 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3658 " outColor = wrong;\n"
3659
3660 " gl_Position = gl_in[2].gl_Position;\n"
3661 " color = outColor;\n"
3662 " EmitVertex();\n"
3663
3664 // done
3665 " EndPrimitive();\n"
3666 "}\n";
3667
3668 static const char *fragShaderText =
3669 "#version 140\n"
3670 "#extension GL_ARB_separate_shader_objects : enable\n"
3671 "#extension GL_ARB_shading_language_420pack : enable\n"
3672 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3673 " vec4 fRed;\n"
3674 " vec4 fGreen;\n"
3675 " layout(row_major) mat4 worldToProj;\n"
3676 " layout(row_major) mat4 projToWorld;\n"
3677 " layout(row_major) mat4 worldToView;\n"
3678 " layout(row_major) mat4 viewToProj;\n"
3679 " layout(row_major) mat4 worldToShadow[4];\n"
3680 " float fZero;\n"
3681 " float fOne;\n"
3682 " float fTwo;\n"
3683 " float fThree;\n"
3684 " vec3 fZeroZeroZero;\n"
3685 " float fFour;\n"
3686 " vec3 fZeroZeroOne;\n"
3687 " float fFive;\n"
3688 " vec3 fZeroOneZero;\n"
3689 " float fSix;\n"
3690 " float fSeven;\n"
3691 " float fEight;\n"
3692 " float fNine;\n"
3693 " vec2 fZeroZero;\n"
3694 " vec2 fZeroOne;\n"
3695 " vec4 fBlue;\n"
3696 " vec2 fOneZero;\n"
3697 " vec2 fOneOne;\n"
3698 " vec3 fZeroOneOne;\n"
3699 " float fTen;\n"
3700 " float fEleven;\n"
3701 " float fTwelve;\n"
3702 " vec3 fOneZeroZero;\n"
3703 " vec4 uvOffsets[4];\n"
3704 "};\n"
3705 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06003706 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003707 "void main() {\n"
3708 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3709 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3710 " \n"
3711
3712 // start with GS value to ensure it passed
3713 " vec4 outColor = color;\n"
3714
3715 // do some exact comparisons, even though we should
3716 // really have an epsilon involved.
3717 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3718 " outColor = wrong;\n"
3719 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3720 " outColor = wrong;\n"
3721 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3722 " outColor = wrong;\n"
3723 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3724 " outColor = wrong;\n"
3725 " if (fTwo != 2.0)\n"
3726 " outColor = wrong;\n"
3727 " if (fOneOne != vec2(1.0, 1.0))\n"
3728 " outColor = wrong;\n"
3729 " if (fTen != 10.0)\n"
3730 " outColor = wrong;\n"
3731 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3732 " outColor = wrong;\n"
3733 " \n"
GregFaae75242015-06-03 18:40:50 -06003734 " uFragColor = outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003735 "}\n";
3736
3737
Cody Northropd2ad0342015-08-05 11:15:02 -06003738 const float mixedVals[196] = { 1.0f, 0.0f, 0.0f, 1.0f, // vec4 fRed; // align
3739 0.0f, 1.0f, 0.0f, 1.0f, // vec4 fGreen; // align
3740 1.0f, 0.0f, 0.0f, 1.0f, // layout(row_major) mat4 worldToProj;
3741 0.0f, 1.0f, 0.0f, 1.0f, // align
3742 0.0f, 0.0f, 1.0f, 1.0f, // align
3743 0.0f, 0.0f, 0.0f, 1.0f, // align
3744 2.0f, 0.0f, 0.0f, 2.0f, // layout(row_major) mat4 projToWorld;
3745 0.0f, 2.0f, 0.0f, 2.0f, // align
3746 0.0f, 0.0f, 2.0f, 2.0f, // align
3747 0.0f, 0.0f, 0.0f, 2.0f, // align
3748 3.0f, 0.0f, 0.0f, 3.0f, // layout(row_major) mat4 worldToView;
3749 0.0f, 3.0f, 0.0f, 3.0f, // align
3750 0.0f, 0.0f, 3.0f, 3.0f, // align
3751 0.0f, 0.0f, 0.0f, 3.0f, // align
3752 4.0f, 0.0f, 0.0f, 4.0f, // layout(row_major) mat4 viewToProj;
3753 0.0f, 4.0f, 0.0f, 4.0f, // align
3754 0.0f, 0.0f, 4.0f, 4.0f, // align
3755 0.0f, 0.0f, 0.0f, 4.0f, // align
3756 5.0f, 0.0f, 0.0f, 5.0f, // layout(row_major) mat4 worldToShadow[4];
3757 0.0f, 5.0f, 0.0f, 5.0f, // align
3758 0.0f, 0.0f, 5.0f, 5.0f, // align
3759 0.0f, 0.0f, 0.0f, 5.0f, // align
3760 6.0f, 0.0f, 0.0f, 6.0f, // align
3761 0.0f, 6.0f, 0.0f, 6.0f, // align
3762 0.0f, 0.0f, 6.0f, 6.0f, // align
3763 0.0f, 0.0f, 0.0f, 6.0f, // align
3764 7.0f, 0.0f, 0.0f, 7.0f, // align
3765 0.0f, 7.0f, 0.0f, 7.0f, // align
3766 0.0f, 0.0f, 7.0f, 7.0f, // align
3767 0.0f, 0.0f, 0.0f, 7.0f, // align
3768 8.0f, 0.0f, 0.0f, 8.0f, // align
3769 0.0f, 8.0f, 0.0f, 8.0f, // align
3770 0.0f, 0.0f, 8.0f, 8.0f, // align
3771 0.0f, 0.0f, 0.0f, 8.0f, // align
3772 0.0f, // float fZero; // align
3773 1.0f, // float fOne; // pack
3774 2.0f, // float fTwo; // pack
3775 3.0f, // float fThree; // pack
3776 0.0f, 0.0f, 0.0f, // vec3 fZeroZeroZero; // align
3777 4.0f, // float fFour; // pack
3778 0.0f, 0.0f, 1.0f, // vec3 fZeroZeroOne; // align
3779 5.0f, // float fFive; // pack
3780 0.0f, 1.0f, 0.0f, // vec3 fZeroOneZero; // align
3781 6.0f, // float fSix; // pack
3782 7.0f, // float fSeven; // align
3783 8.0f, // float fEight; // pack
3784 9.0f, // float fNine; // pack
3785 0.0f, // BUFFER
3786 0.0f, 0.0f, // vec2 fZeroZero; // align
3787 0.0f, 1.0f, // vec2 fZeroOne; // pack
3788 0.0f, 0.0f, 1.0f, 1.0f, // vec4 fBlue; // align
3789 1.0f, 0.0f, // vec2 fOneZero; // align
3790 1.0f, 1.0f, // vec2 fOneOne; // pack
3791 0.0f, 1.0f, 1.0f, // vec3 fZeroOneOne; // align
3792 10.0f, // float fTen; // pack
3793 11.0f, // float fEleven; // align
3794 12.0f, // float fTwelve; // pack
3795 0.0f, 0.0f, // BUFFER
3796 1.0f, 0.0f, 0.0f, // vec3 fOneZeroZero; // align
3797 0.0f, // BUFFER
3798 0.1f, 0.2f, 0.3f, 0.4f, // vec4 uvOffsets[4];
3799 0.5f, 0.6f, 0.7f, 0.8f, // align
3800 0.9f, 1.0f, 1.1f, 1.2f, // align
3801 1.3f, 1.4f, 1.5f, 1.6f, // align
Cody Northrop475663c2015-04-15 11:19:06 -06003802 };
3803
3804
3805
3806 ASSERT_NO_FATAL_FAILURE(InitState());
3807 ASSERT_NO_FATAL_FAILURE(InitViewport());
3808
3809 const int constCount = sizeof(mixedVals) / sizeof(float);
3810
3811 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3812 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3813 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3814
3815 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
3816
3817 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003818 pipelineobj.AddColorAttachment();
Cody Northrop475663c2015-04-15 11:19:06 -06003819 pipelineobj.AddShader(&vs);
3820 pipelineobj.AddShader(&gs);
3821 pipelineobj.AddShader(&ps);
3822
3823 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003824 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop475663c2015-04-15 11:19:06 -06003825
3826 VkDescriptorSetObj descriptorSet(m_device);
3827 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
3828
Tony Barbourfe3351b2015-07-28 10:17:20 -06003829 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop475663c2015-04-15 11:19:06 -06003830
3831 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06003832 Draw(0, 3, 0, 1);
Cody Northrop475663c2015-04-15 11:19:06 -06003833
3834 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003835 EndCommandBuffer();
3836 QueueCommandBuffer();
Cody Northrop475663c2015-04-15 11:19:06 -06003837
3838 RecordImages(m_renderTargets);
3839}
3840
3841TEST_F(VkRenderTest, GSPositions)
3842{
3843 // This test adds more inputs from the vertex shader and perturbs positions
3844 // Expected result is white triangle with weird positions
3845
3846 static const char *vertShaderText =
3847 "#version 140\n"
3848 "#extension GL_ARB_separate_shader_objects : enable\n"
3849 "#extension GL_ARB_shading_language_420pack : enable\n"
3850
3851 "layout(location = 0) out vec3 out_a;\n"
3852 "layout(location = 1) out vec3 out_b;\n"
3853 "layout(location = 2) out vec3 out_c;\n"
3854
3855 "void main() {\n"
3856
3857 // write a solid color to each
3858 " out_a = vec3(1.0, 0.0, 0.0);\n"
3859 " out_b = vec3(0.0, 1.0, 0.0);\n"
3860 " out_c = vec3(0.0, 0.0, 1.0);\n"
3861
3862 // generic position stuff
3863 " vec2 vertices;\n"
3864 " int vertexSelector = gl_VertexID;\n"
3865 " if (vertexSelector == 0)\n"
3866 " vertices = vec2(-0.5, -0.5);\n"
3867 " else if (vertexSelector == 1)\n"
3868 " vertices = vec2( 0.5, -0.5);\n"
3869 " else if (vertexSelector == 2)\n"
3870 " vertices = vec2( 0.5, 0.5);\n"
3871 " else\n"
3872 " vertices = vec2( 0.0, 0.0);\n"
3873 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3874
3875 "}\n";
3876
3877 static const char *geomShaderText =
3878 "#version 330\n"
3879 "#extension GL_ARB_separate_shader_objects : enable\n"
3880 "#extension GL_ARB_shading_language_420pack : enable\n"
3881 "layout( triangles ) in;\n"
3882 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3883
3884 "layout(location = 0) in vec3 in_a[3];\n"
3885 "layout(location = 1) in vec3 in_b[3];\n"
3886 "layout(location = 2) in vec3 in_c[3];\n"
3887
3888 "layout(location = 0) out vec3 out_a;\n"
3889 "layout(location = 1) out vec3 out_b;\n"
3890 "layout(location = 2) out vec3 out_c;\n"
3891
3892 "void main()\n"
3893 "{\n"
3894
3895 " gl_Position = gl_in[0].gl_Position;\n"
3896 " gl_Position.xy *= vec2(0.75);\n"
3897 " out_a = in_a[0];\n"
3898 " out_b = in_b[0];\n"
3899 " out_c = in_c[0];\n"
3900 " EmitVertex();\n"
3901
3902 " gl_Position = gl_in[1].gl_Position;\n"
3903 " gl_Position.xy *= vec2(1.5);\n"
3904 " out_a = in_a[1];\n"
3905 " out_b = in_b[1];\n"
3906 " out_c = in_c[1];\n"
3907 " EmitVertex();\n"
3908
3909 " gl_Position = gl_in[2].gl_Position;\n"
3910 " gl_Position.xy *= vec2(-0.1);\n"
3911 " out_a = in_a[2];\n"
3912 " out_b = in_b[2];\n"
3913 " out_c = in_c[2];\n"
3914 " EmitVertex();\n"
3915
3916 " EndPrimitive();\n"
3917 "}\n";
3918
3919
3920 static const char *fragShaderText =
3921 "#version 140\n"
3922 "#extension GL_ARB_separate_shader_objects : enable\n"
3923 "#extension GL_ARB_shading_language_420pack : enable\n"
3924
3925 "layout(location = 0) in vec3 in_a;\n"
3926 "layout(location = 1) in vec3 in_b;\n"
3927 "layout(location = 2) in vec3 in_c;\n"
GregFaae75242015-06-03 18:40:50 -06003928 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003929
3930 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06003931 " outColor = vec4(in_a.x, in_b.y, in_c.z, 1.0);\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003932 "}\n";
3933
3934
3935
3936 ASSERT_NO_FATAL_FAILURE(InitState());
3937 ASSERT_NO_FATAL_FAILURE(InitViewport());
3938
3939 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3940 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3941 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3942
3943 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003944 pipelineobj.AddColorAttachment();
Cody Northrop475663c2015-04-15 11:19:06 -06003945 pipelineobj.AddShader(&vs);
3946 pipelineobj.AddShader(&gs);
3947 pipelineobj.AddShader(&ps);
3948
3949 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003950 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop475663c2015-04-15 11:19:06 -06003951
3952 VkDescriptorSetObj descriptorSet(m_device);
3953
Tony Barbourfe3351b2015-07-28 10:17:20 -06003954 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop475663c2015-04-15 11:19:06 -06003955
3956 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06003957 Draw(0, 3, 0, 1);
Cody Northrop475663c2015-04-15 11:19:06 -06003958
3959 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003960 EndCommandBuffer();
3961 QueueCommandBuffer();
Cody Northrop475663c2015-04-15 11:19:06 -06003962
3963 RecordImages(m_renderTargets);
3964}
3965
3966TEST_F(VkRenderTest, GSTriStrip)
3967{
3968 // This test emits multiple multiple triangles using a GS
3969 // Correct result is an multicolor circle
3970
3971 static const char *vertShaderText =
3972 "#version 140\n"
3973 "#extension GL_ARB_separate_shader_objects : enable\n"
3974 "#extension GL_ARB_shading_language_420pack : enable\n"
3975
3976 "void main() {\n"
3977
3978 // generic position stuff
3979 " vec2 vertices;\n"
3980 " int vertexSelector = gl_VertexID;\n"
3981 " if (vertexSelector == 0)\n"
3982 " vertices = vec2(-0.5, -0.5);\n"
3983 " else if (vertexSelector == 1)\n"
3984 " vertices = vec2( 0.5, -0.5);\n"
3985 " else if (vertexSelector == 2)\n"
3986 " vertices = vec2( 0.5, 0.5);\n"
3987 " else\n"
3988 " vertices = vec2( 0.0, 0.0);\n"
3989 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3990
3991 "}\n";
3992
3993 static const char *geomShaderText =
3994 "#version 330\n"
3995 "#extension GL_ARB_separate_shader_objects : enable\n"
3996 "#extension GL_ARB_shading_language_420pack : enable\n"
3997 "layout( triangles ) in;\n"
3998 "layout( triangle_strip, max_vertices = 18 ) out;\n"
3999
4000 "layout(location = 0) out vec4 outColor;\n"
4001
4002 "void main()\n"
4003 "{\n"
4004 // init with first position to get zw
4005 " gl_Position = gl_in[0].gl_Position;\n"
4006
4007 " vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
4008 " vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
4009 " vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
4010 " vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
4011
4012 // different color per tri
4013 " vec4[6] colors = { red, white, \n"
4014 " yellow, white, \n"
4015 " blue, white }; \n"
4016
4017 // fan out the triangles
4018 " vec2[18] positions = { vec2(0.0, 0.0), vec2(-0.5, 0.0), vec2(-0.25, -0.5), \n"
4019 " vec2(0.0, 0.0), vec2(-0.25, -0.5), vec2( 0.25, -0.5), \n"
4020 " vec2(0.0, 0.0), vec2( 0.25, -0.5), vec2( 0.5, 0.0), \n"
4021 " vec2(0.0, 0.0), vec2( 0.5, 0.0), vec2( 0.25, 0.5), \n"
4022 " vec2(0.0, 0.0), vec2( 0.25, 0.5), vec2(-0.25, 0.5), \n"
4023 " vec2(0.0, 0.0), vec2(-0.25, 0.5), vec2(-0.5, 0.0) }; \n"
4024
4025 // make a triangle list of 6
4026 " for (int i = 0; i < 6; ++i) { \n"
4027 " outColor = colors[i]; \n"
4028 " for (int j = 0; j < 3; ++j) { \n"
4029 " gl_Position.xy = positions[i * 3 + j]; \n"
4030 " EmitVertex(); \n"
4031 " } \n"
4032 " EndPrimitive();\n"
4033 " } \n"
4034
4035 "}\n";
4036
4037
4038 static const char *fragShaderText =
4039 "#version 150\n"
4040 "#extension GL_ARB_separate_shader_objects : enable\n"
4041 "#extension GL_ARB_shading_language_420pack : enable\n"
4042
4043
4044 "layout(binding = 0) uniform windowDimensions {\n"
4045 " vec4 dimensions;\n"
4046 "};\n"
4047
4048 "layout(location = 0) in vec4 inColor;\n"
4049 "layout(origin_upper_left) in vec4 gl_FragCoord;\n"
GregFaae75242015-06-03 18:40:50 -06004050 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06004051
4052 "void main() {\n"
4053
4054 // discard to make a nice circle
4055 " vec2 pos = abs(gl_FragCoord.xy) - vec2(dimensions.x, dimensions.y) / 2;\n"
4056 " float dist = sqrt(dot(pos, pos));\n"
4057 " if (dist > 50.0)\n"
4058 " discard;\n"
4059
GregFaae75242015-06-03 18:40:50 -06004060 " outColor = inColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06004061
4062 "}\n";
4063
4064
4065
4066 ASSERT_NO_FATAL_FAILURE(InitState());
4067 ASSERT_NO_FATAL_FAILURE(InitViewport());
4068
4069 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
4070 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
4071 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
4072
4073 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004074 pipelineobj.AddColorAttachment();
Cody Northrop475663c2015-04-15 11:19:06 -06004075 pipelineobj.AddShader(&vs);
4076 pipelineobj.AddShader(&gs);
4077 pipelineobj.AddShader(&ps);
4078
4079 const float dimensions[4] = { VkRenderFramework::m_width, VkRenderFramework::m_height , 0.0, 0.0};
4080
4081 VkConstantBufferObj windowDimensions(m_device, sizeof(dimensions) / sizeof(dimensions[0]), sizeof(dimensions[0]), (const void*) dimensions);
4082
4083 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004084 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop475663c2015-04-15 11:19:06 -06004085
4086 VkDescriptorSetObj descriptorSet(m_device);
4087 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, windowDimensions);
4088
Tony Barbourfe3351b2015-07-28 10:17:20 -06004089 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop475663c2015-04-15 11:19:06 -06004090
4091 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06004092 Draw(0, 3, 0, 1);
Cody Northrop475663c2015-04-15 11:19:06 -06004093
4094 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06004095 EndCommandBuffer();
4096 QueueCommandBuffer();
Cody Northrop475663c2015-04-15 11:19:06 -06004097
4098 RecordImages(m_renderTargets);
4099}
4100
Chris Forbese182fe02015-06-15 09:32:35 +12004101TEST_F(VkRenderTest, RenderPassLoadOpClear)
4102{
4103 ASSERT_NO_FATAL_FAILURE(InitState());
4104 ASSERT_NO_FATAL_FAILURE(InitViewport());
4105
4106 /* clear via load op to full green */
4107 m_clear_via_load_op = true;
Cody Northrop85789d52015-08-25 15:26:38 -06004108 m_clear_color.float32[0] = 0;
4109 m_clear_color.float32[1] = 1;
4110 m_clear_color.float32[2] = 0;
4111 m_clear_color.float32[3] = 0;
Chris Forbese182fe02015-06-15 09:32:35 +12004112 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004113 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Chris Forbese182fe02015-06-15 09:32:35 +12004114 /* This command buffer contains ONLY the load op! */
Tony Barbourfe3351b2015-07-28 10:17:20 -06004115 EndCommandBuffer();
4116 QueueCommandBuffer();
Chris Forbese182fe02015-06-15 09:32:35 +12004117
4118 RecordImages(m_renderTargets);
4119}
4120
Chris Forbesfa27b952015-06-24 12:05:30 +12004121TEST_F(VkRenderTest, RenderPassAttachmentClear)
4122{
4123 ASSERT_NO_FATAL_FAILURE(InitState());
4124 ASSERT_NO_FATAL_FAILURE(InitViewport());
4125
4126 /* clear via load op to full red */
4127 m_clear_via_load_op = true;
Cody Northrop85789d52015-08-25 15:26:38 -06004128 m_clear_color.float32[0] = 1;
4129 m_clear_color.float32[1] = 0;
4130 m_clear_color.float32[2] = 0;
4131 m_clear_color.float32[3] = 0;
Chris Forbesfa27b952015-06-24 12:05:30 +12004132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004133 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Chris Forbesfa27b952015-06-24 12:05:30 +12004134
4135 /* Load op has cleared to red */
4136
4137 /* Draw, draw, draw... */
4138
4139 /* Now, partway through this renderpass we want to clear the color
4140 * attachment again, this time to green.
4141 */
Chris Forbesf0796e12015-06-24 14:34:53 +12004142 VkClearColorValue clear_color;
Cody Northrop85789d52015-08-25 15:26:38 -06004143 clear_color.float32[0] = 0;
4144 clear_color.float32[1] = 1;
4145 clear_color.float32[2] = 0;
4146 clear_color.float32[3] = 0;
Chris Forbesfa27b952015-06-24 12:05:30 +12004147 VkRect3D clear_rect = { { 0, 0, 0 }, { (int)m_width, (int)m_height, 1 } };
Tony Barbourfe3351b2015-07-28 10:17:20 -06004148 vkCmdClearColorAttachment(m_cmdBuffer->handle(), 0,
Chris Forbesfa27b952015-06-24 12:05:30 +12004149 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4150 &clear_color, 1, &clear_rect);
4151
Tony Barbourfe3351b2015-07-28 10:17:20 -06004152 EndCommandBuffer();
4153 QueueCommandBuffer();
Chris Forbesfa27b952015-06-24 12:05:30 +12004154
4155 RecordImages(m_renderTargets);
4156}
4157
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06004158int main(int argc, char **argv) {
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004159 int result;
4160
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06004161 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -06004162 VkTestFramework::InitArgs(&argc, argv);
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004163
Chia-I Wu6f184292014-12-15 23:57:34 +08004164 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchtera0f74c52014-10-08 08:46:51 -06004165
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004166 result = RUN_ALL_TESTS();
4167
Tony Barbour6918cd52015-04-09 12:58:51 -06004168 VkTestFramework::Finish();
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004169 return result;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06004170}