blob: 0a5816517283a5558bd663a466bf77ac910f9449 [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);
277 VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600278 /* Convenience functions that use built-in command buffer */
279 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_cmdBuffer); }
280 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_cmdBuffer); }
281 void Draw(uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount)
282 { m_cmdBuffer->Draw(firstVertex, vertexCount, firstInstance, instanceCount); }
283 void DrawIndexed(uint32_t firstVertex, uint32_t vertexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount)
284 { m_cmdBuffer->DrawIndexed(firstVertex, vertexCount, vertexOffset,firstInstance, instanceCount); }
285 void QueueCommandBuffer() { m_cmdBuffer->QueueCommandBuffer(); }
286 void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
287 VkConstantBufferObj *constantBuffer)
288 {RotateTriangleVSUniform(Projection, View, Model, constantBuffer, m_cmdBuffer); }
289 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding)
290 { m_cmdBuffer->BindVertexBuffer(vertexBuffer, offset, binding); }
291 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset)
292 { m_cmdBuffer->BindIndexBuffer(indexBuffer, offset); }
293
294
Cody Northropee6586d2014-10-09 19:55:56 -0600295
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600296protected:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600297 VkImage m_texture;
298 VkImageView m_textureView;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800299 VkDescriptorInfo m_descriptorInfo;
Tony Barbourd1c35722015-04-16 15:59:00 -0600300 VkDeviceMemory m_textureMem;
Cody Northrop7d2035d2014-10-06 15:42:00 -0600301
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600302 VkSampler m_sampler;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600303
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600304
305 virtual void SetUp() {
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600306
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600307 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600308 this->app_info.pNext = NULL;
Chia-I Wuf1a5a742014-12-27 15:16:07 +0800309 this->app_info.pAppName = "render_tests";
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600310 this->app_info.appVersion = 1;
Chia-I Wuf1a5a742014-12-27 15:16:07 +0800311 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600312 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600313 this->app_info.apiVersion = VK_API_VERSION;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600314
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800315 memset(&m_descriptorInfo, 0, sizeof(m_descriptorInfo));
Cody Northrop7d2035d2014-10-06 15:42:00 -0600316
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600317 InitFramework();
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600318 }
319
320 virtual void TearDown() {
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600321 // Clean up resources before we reset
322 ShutdownFramework();
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -0600323 }
324};
325
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600326VkResult VkRenderTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600327{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600328 VkResult result;
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600329
330 result = cmdBuffer.BeginCommandBuffer();
331
332 /*
333 * For render test all drawing happens in a single render pass
334 * on a single command buffer.
335 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200336 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu08accc62015-07-07 11:50:03 +0800337 cmdBuffer.BeginRenderPass(renderPassBeginInfo());
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600338 }
339
340 return result;
341}
342
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600343VkResult VkRenderTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600344{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600345 VkResult result;
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600346
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200347 if (renderPass()) {
Chia-I Wu0b50a1c2015-06-26 15:34:39 +0800348 cmdBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200349 }
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600350
351 result = cmdBuffer.EndCommandBuffer();
352
353 return result;
354}
355
356
Tony Barbour6918cd52015-04-09 12:58:51 -0600357void VkRenderTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet)
Tony Barbour22e32a12015-01-08 17:08:28 -0700358{
Tony Barbour71bd4b32015-07-21 17:00:26 -0600359 if (!m_clear_via_load_op) {
360 if (m_depthStencil->Initialized()) {
361 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
362 } else {
363 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
364 }
Tony Barbour1c45ce02015-03-27 17:03:18 -0600365 }
366
Jeremy Hayesd65ae082015-01-14 16:17:08 -0700367 cmdBuffer->PrepareAttachments();
Tony Barbour67e99152015-07-10 14:10:27 -0600368 cmdBuffer->BindDynamicRasterState(m_stateRaster);
369 cmdBuffer->BindDynamicViewportState(m_stateViewport);
370 cmdBuffer->BindDynamicColorBlendState(m_colorBlend);
371 cmdBuffer->BindDynamicDepthStencilState(m_stateDepthStencil);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600372 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
Tony Barbour5781e8f2015-08-04 16:23:11 -0600373 pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600374 cmdBuffer->BindPipeline(pipelineobj);
Chia-I Wu53f07d72015-03-28 15:23:55 +0800375 cmdBuffer->BindDescriptorSet(descriptorSet);
Tony Barbour22e32a12015-01-08 17:08:28 -0700376}
Tony Barboure2c58df2014-11-25 13:18:32 -0700377
Tony Barbour6918cd52015-04-09 12:58:51 -0600378void VkRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
379 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer)
Tony Barbour664accc2015-01-09 12:55:14 -0700380{
381 int i;
382 glm::mat4 MVP;
383 int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600384 VkResult err;
Tony Barbour664accc2015-01-09 12:55:14 -0700385
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -0600386 /* Only do 3 positions to avoid back face cull */
387 for (i = 0; i < 3; i++) {
Chia-I Wu681d7a02015-07-03 13:44:34 +0800388 void *pData = constantBuffer->memory().map();
Tony Barbour664accc2015-01-09 12:55:14 -0700389
390 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
391 MVP = Projection * View * Model;
392 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
393
Chia-I Wu681d7a02015-07-03 13:44:34 +0800394 constantBuffer->memory().unmap();
Tony Barbour664accc2015-01-09 12:55:14 -0700395
396 // submit the command buffer to the universal queue
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600397 cmdBuffer->QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -0700398
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600399 err = vkQueueWaitIdle( m_device->m_queue );
400 ASSERT_VK_SUCCESS( err );
Tony Barbour664accc2015-01-09 12:55:14 -0700401
402 // Wait for work to finish before cleaning up.
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600403 vkDeviceWaitIdle(m_device->device());
Tony Barbour664accc2015-01-09 12:55:14 -0700404
Courtney Goeltzenleuchterb4337c12015-03-05 16:47:18 -0700405 assert(m_renderTargets.size() == 1);
Tony Barbour664accc2015-01-09 12:55:14 -0700406 RecordImage(m_renderTargets[0]);
407 }
408}
Courtney Goeltzenleuchterc55471f2014-10-13 13:03:31 -0600409
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600410void dumpMatrix(const char *note, glm::mat4 MVP)
411{
Chia-I Wu6f184292014-12-15 23:57:34 +0800412 int i;
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -0600413
414 printf("%s: \n", note);
415 for (i=0; i<4; i++) {
416 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
417 }
418 printf("\n");
419 fflush(stdout);
420}
421
422void dumpVec4(const char *note, glm::vec4 vector)
423{
424 printf("%s: \n", note);
425 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
426 printf("\n");
427 fflush(stdout);
428}
429
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600430struct vktriangle_vs_uniform {
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600431 // Must start with MVP
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600432 float mvp[4][4];
433 float position[3][4];
434 float color[3][4];
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600435};
436
Tony Barbour6918cd52015-04-09 12:58:51 -0600437void VkRenderTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600438{
Tobin Ehlis6663f492014-11-10 12:29:12 -0700439#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600440 vkDbgRegisterMsgCallback(inst, myDbgFunc, NULL);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700441#endif
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600442 // Create identity matrix
443 int i;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600444 struct vktriangle_vs_uniform data;
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600445
446 glm::mat4 Projection = glm::mat4(1.0f);
447 glm::mat4 View = glm::mat4(1.0f);
448 glm::mat4 Model = glm::mat4(1.0f);
449 glm::mat4 MVP = Projection * View * Model;
450 const int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600451 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600452 memcpy(&data.mvp, &MVP[0][0], matrixSize);
453
454 static const Vertex tri_data[] =
455 {
456 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
457 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
458 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
459 };
460
461 for (i=0; i<3; i++) {
462 data.position[i][0] = tri_data[i].posX;
463 data.position[i][1] = tri_data[i].posY;
464 data.position[i][2] = tri_data[i].posZ;
465 data.position[i][3] = tri_data[i].posW;
466 data.color[i][0] = tri_data[i].r;
467 data.color[i][1] = tri_data[i].g;
468 data.color[i][2] = tri_data[i].b;
469 data.color[i][3] = tri_data[i].a;
470 }
471
Tony Barboure2c58df2014-11-25 13:18:32 -0700472 ASSERT_NO_FATAL_FAILURE(InitState());
473 ASSERT_NO_FATAL_FAILURE(InitViewport());
474
Tony Barbour6918cd52015-04-09 12:58:51 -0600475 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barboure2c58df2014-11-25 13:18:32 -0700476
Tony Barbour6918cd52015-04-09 12:58:51 -0600477 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
478 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -0700479
Tony Barbour6918cd52015-04-09 12:58:51 -0600480 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800481 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -0700482 pipelineobj.AddShader(&vs);
483 pipelineobj.AddShader(&ps);
484
Tony Barbour6918cd52015-04-09 12:58:51 -0600485 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600486 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -0700487
Tony Barbourd726a172015-01-09 16:12:35 -0700488 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600489 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure2c58df2014-11-25 13:18:32 -0700490
Tony Barbourfe3351b2015-07-28 10:17:20 -0600491 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourd726a172015-01-09 16:12:35 -0700492#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600493 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourd726a172015-01-09 16:12:35 -0700494 pDSDumpDot((char*)"triTest2.dot");
495#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600496
Tony Barbourd726a172015-01-09 16:12:35 -0700497 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -0600498 Draw(0, 3, 0, 1);
Tony Barbourd726a172015-01-09 16:12:35 -0700499
500 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600501 ASSERT_VK_SUCCESS(EndCommandBuffer());
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600502
Tony Barbourfe3351b2015-07-28 10:17:20 -0600503 QueueCommandBuffer();
Tony Barbourd726a172015-01-09 16:12:35 -0700504
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600505 RecordImages(m_renderTargets);
Tony Barbourd726a172015-01-09 16:12:35 -0700506
507 if (rotate)
Tony Barbourfe3351b2015-07-28 10:17:20 -0600508 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer);
Tony Barbourd726a172015-01-09 16:12:35 -0700509
Tobin Ehlisca915872014-11-18 11:28:33 -0700510#ifdef PRINT_OBJECTS
Mark Lobodzinski7c75b852015-05-05 15:01:37 -0500511 OBJ_TRACK_GET_OBJECTS_COUNT pObjTrackGetObjectsCount = (OBJ_TRACK_GET_OBJECTS_COUNT)vkGetProcAddr(gpu(), (char*)"objTrackGetObjectsCount");
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600512 uint64_t numObjects = pObjTrackGetObjectsCount(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600513 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlisca915872014-11-18 11:28:33 -0700514 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600515 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlisca915872014-11-18 11:28:33 -0700516 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600517 pObjTrackGetObjs(m_device, numObjects, pObjNodeArray);
Tobin Ehlisca915872014-11-18 11:28:33 -0700518 for (i=0; i < numObjects; i++) {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600519 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 -0700520 }
521 free(pObjNodeArray);
522#endif
Tony Barboure2c58df2014-11-25 13:18:32 -0700523
Courtney Goeltzenleuchter5adb1812014-10-24 16:26:12 -0600524}
525
Tony Barbour6918cd52015-04-09 12:58:51 -0600526TEST_F(VkRenderTest, VKTriangle_FragColor)
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600527{
528 static const char *vertShaderText =
529 "#version 140\n"
530 "#extension GL_ARB_separate_shader_objects : enable\n"
531 "#extension GL_ARB_shading_language_420pack : enable\n"
532 "\n"
533 "layout(binding = 0) uniform buf {\n"
534 " mat4 MVP;\n"
535 " vec4 position[3];\n"
536 " vec4 color[3];\n"
537 "} ubuf;\n"
538 "\n"
539 "layout (location = 0) out vec4 outColor;\n"
540 "\n"
541 "void main() \n"
542 "{\n"
543 " outColor = ubuf.color[gl_VertexID];\n"
544 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
545 "}\n";
546
547 static const char *fragShaderText =
548 "#version 140\n"
549 "#extension GL_ARB_separate_shader_objects : enable\n"
550 "#extension GL_ARB_shading_language_420pack : enable\n"
551 "\n"
552 "layout (location = 0) in vec4 inColor;\n"
GregFaae75242015-06-03 18:40:50 -0600553 "layout (location = 0) out vec4 uFragColor;\n"
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600554 "\n"
555 "void main()\n"
556 "{\n"
GregFaae75242015-06-03 18:40:50 -0600557 " uFragColor = inColor;\n"
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600558 "}\n";
559
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600560 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
561 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600562}
563
Tony Barbour6918cd52015-04-09 12:58:51 -0600564TEST_F(VkRenderTest, VKTriangle_OutputLocation)
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600565{
566 static const char *vertShaderText =
567 "#version 140\n"
568 "#extension GL_ARB_separate_shader_objects : enable\n"
569 "#extension GL_ARB_shading_language_420pack : enable\n"
570 "\n"
571 "layout(binding = 0) uniform buf {\n"
572 " mat4 MVP;\n"
573 " vec4 position[3];\n"
574 " vec4 color[3];\n"
575 "} ubuf;\n"
576 "\n"
577 "layout (location = 0) out vec4 outColor;\n"
578 "\n"
579 "void main() \n"
580 "{\n"
581 " outColor = ubuf.color[gl_VertexID];\n"
582 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
583 "}\n";
584
585 static const char *fragShaderText =
586 "#version 140\n"
587 "#extension GL_ARB_separate_shader_objects : enable\n"
588 "#extension GL_ARB_shading_language_420pack : enable\n"
589 "\n"
590 "layout (location = 0) in vec4 inColor;\n"
591 "layout (location = 0) out vec4 outColor;\n"
592 "\n"
593 "void main()\n"
594 "{\n"
595 " outColor = inColor;\n"
596 "}\n";
597
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600598 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 -0600599
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600600 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter71d1f872014-10-27 13:08:55 -0600601}
Cody Northrop6922da12015-06-23 13:25:51 -0600602
Tony Barbour6918cd52015-04-09 12:58:51 -0600603TEST_F(VkRenderTest, SPV_VKTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -0700604{
Tony Barboure2c58df2014-11-25 13:18:32 -0700605 static const char *vertShaderText =
606 "#version 140\n"
607 "#extension GL_ARB_separate_shader_objects : enable\n"
608 "#extension GL_ARB_shading_language_420pack : enable\n"
609 "\n"
610 "layout(binding = 0) uniform buf {\n"
611 " mat4 MVP;\n"
612 " vec4 position[3];\n"
613 " vec4 color[3];\n"
614 "} ubuf;\n"
615 "\n"
616 "layout (location = 0) out vec4 outColor;\n"
617 "\n"
618 "void main() \n"
619 "{\n"
620 " outColor = ubuf.color[gl_VertexID];\n"
621 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
622 "}\n";
623
624 static const char *fragShaderText =
625 "#version 140\n"
626 "#extension GL_ARB_separate_shader_objects : enable\n"
627 "#extension GL_ARB_shading_language_420pack : enable\n"
628 "\n"
629 "layout (location = 0) in vec4 inColor;\n"
GregFaae75242015-06-03 18:40:50 -0600630 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700631 "\n"
632 "void main()\n"
633 "{\n"
GregFaae75242015-06-03 18:40:50 -0600634 " outColor = inColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700635 "}\n";
636
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600637 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 -0700638
Cody Northrop50a2a4b2015-06-03 16:49:20 -0600639 ScopedUseGlsl useGlsl(false);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600640 VKTriangleTest(vertShaderText, fragShaderText, true);
Tony Barboure2c58df2014-11-25 13:18:32 -0700641}
Courtney Goeltzenleuchter538062a2014-10-09 15:40:19 -0600642
Tony Barbour6918cd52015-04-09 12:58:51 -0600643TEST_F(VkRenderTest, SPV_GreenTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -0700644{
Tony Barboure2c58df2014-11-25 13:18:32 -0700645 static const char *vertShaderText =
646 "#version 130\n"
647 "vec2 vertices[3];\n"
648 "void main() {\n"
649 " vertices[0] = vec2(-1.0, -1.0);\n"
650 " vertices[1] = vec2( 1.0, -1.0);\n"
651 " vertices[2] = vec2( 0.0, 1.0);\n"
652 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
653 "}\n";
654
655 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -0600656 "#version 140\n"
657 "#extension GL_ARB_separate_shader_objects : enable\n"
658 "#extension GL_ARB_shading_language_420pack : enable\n"
659 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700660 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600661 " outColor = vec4(0,1,0,1);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700662 "}\n";
663
Cody Northrop3bfd27c2015-03-17 15:55:58 -0600664 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barboure2c58df2014-11-25 13:18:32 -0700665
Cody Northrop50a2a4b2015-06-03 16:49:20 -0600666 ScopedUseGlsl useGlsl(false);
667
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600668 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barboure2c58df2014-11-25 13:18:32 -0700669}
Cody Northrop6922da12015-06-23 13:25:51 -0600670
Tony Barbour6918cd52015-04-09 12:58:51 -0600671TEST_F(VkRenderTest, YellowTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -0700672{
673 static const char *vertShaderText =
674 "#version 130\n"
675 "void main() {\n"
676 " vec2 vertices[3];"
677 " vertices[0] = vec2(-0.5, -0.5);\n"
678 " vertices[1] = vec2( 0.5, -0.5);\n"
679 " vertices[2] = vec2( 0.5, 0.5);\n"
680 " vec4 colors[3];\n"
681 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
682 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
683 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
684 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
685 "}\n";
686
687 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -0600688 "#version 140\n"
689 "#extension GL_ARB_separate_shader_objects : enable\n"
690 "#extension GL_ARB_shading_language_420pack : enable\n"
691 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700692 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600693 " outColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700694 "}\n";
695
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600696 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barboure2c58df2014-11-25 13:18:32 -0700697}
698
Tony Barbour6918cd52015-04-09 12:58:51 -0600699TEST_F(VkRenderTest, QuadWithVertexFetch)
Cody Northropee6586d2014-10-09 19:55:56 -0600700{
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600701 static const char *vertShaderText =
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600702 "#version 140\n"
703 "#extension GL_ARB_separate_shader_objects : enable\n"
704 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700705 //XYZ1( -1, -1, -1 )
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600706 "layout (location = 0) in vec4 pos;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -0700707 //XYZ1( 0.f, 0.f, 0.f )
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600708 "layout (location = 1) in vec4 inColor;\n"
709 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600710 "void main() {\n"
Cody Northrop66594a72014-10-10 14:49:36 -0600711 " outColor = inColor;\n"
Cody Northrop7ad4aaf2014-10-09 21:25:22 -0600712 " gl_Position = pos;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600713 "}\n";
714
Cody Northropee6586d2014-10-09 19:55:56 -0600715
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600716 static const char *fragShaderText =
Cody Northropd43c52e2014-12-05 15:44:14 -0700717 "#version 140\n"
718 "#extension GL_ARB_separate_shader_objects : enable\n"
719 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600720 "layout (location = 0) in vec4 color;\n"
Cody Northropd43c52e2014-12-05 15:44:14 -0700721 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600722 "void main() {\n"
Cody Northropd43c52e2014-12-05 15:44:14 -0700723 " outColor = color;\n"
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600724 "}\n";
Courtney Goeltzenleuchterce25e252014-10-09 15:37:21 -0600725
Tony Barboure2c58df2014-11-25 13:18:32 -0700726
727
728 ASSERT_NO_FATAL_FAILURE(InitState());
729 ASSERT_NO_FATAL_FAILURE(InitViewport());
730
Tony Barbour6918cd52015-04-09 12:58:51 -0600731 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000732 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -0700733
Tony Barbour6918cd52015-04-09 12:58:51 -0600734 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
735 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -0700736
Tony Barbour6918cd52015-04-09 12:58:51 -0600737 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800738 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -0700739 pipelineobj.AddShader(&vs);
740 pipelineobj.AddShader(&ps);
741
Tony Barbour6918cd52015-04-09 12:58:51 -0600742 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600743 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -0600744
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600745#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600746 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600747 MESH_BIND_ID, // binding ID
Tony Barboure2c58df2014-11-25 13:18:32 -0700748 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600749 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barboure2c58df2014-11-25 13:18:32 -0700750 };
751
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600752 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600753 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
754 vi_attribs[0].location = 0; // location, position
Tony Barbourd1c35722015-04-16 15:59:00 -0600755 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600756 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
757 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
758 vi_attribs[1].location = 1; // location, color
Tony Barbourd1c35722015-04-16 15:59:00 -0600759 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600760 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 -0700761
762 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
763 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600764 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barboure2c58df2014-11-25 13:18:32 -0700765
Tony Barbour1fde6942015-01-09 10:06:53 -0700766 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600767 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure2c58df2014-11-25 13:18:32 -0700768
Tony Barbourfe3351b2015-07-28 10:17:20 -0600769 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600770
Tony Barbourfe3351b2015-07-28 10:17:20 -0600771 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour1fde6942015-01-09 10:06:53 -0700772
773 // render two triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -0600774 Draw(0, 6, 0, 1);
Tony Barbour1fde6942015-01-09 10:06:53 -0700775
776 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600777 ASSERT_VK_SUCCESS(EndCommandBuffer());
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600778
Tony Barbourfe3351b2015-07-28 10:17:20 -0600779 QueueCommandBuffer();
Tony Barbour1fde6942015-01-09 10:06:53 -0700780
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600781 RecordImages(m_renderTargets);
Tobin Ehlisd806c8e2014-10-07 14:41:29 -0600782}
783
Tony Barbour6918cd52015-04-09 12:58:51 -0600784TEST_F(VkRenderTest, TriangleMRT)
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800785{
786 static const char *vertShaderText =
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600787 "#version 140\n"
788 "#extension GL_ARB_separate_shader_objects : enable\n"
789 "#extension GL_ARB_shading_language_420pack : enable\n"
790 "layout (location = 0) in vec4 pos;\n"
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800791 "void main() {\n"
792 " gl_Position = pos;\n"
793 "}\n";
794
795 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -0600796 "#version 140\n"
797 "#extension GL_ARB_separate_shader_objects : enable\n"
798 "#extension GL_ARB_shading_language_420pack : enable\n"
799 "layout (location = 0) out vec4 uFragData0;\n"
800 "layout (location = 1) out vec4 uFragData1;\n"
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800801 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600802 " uFragData0 = vec4(1.0, 0.0, 0.0, 1.0);\n"
803 " uFragData1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800804 "}\n";
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600805 const float vb_data[][2] = {
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800806 { -1.0f, -1.0f },
807 { 1.0f, -1.0f },
808 { -1.0f, 1.0f }
809 };
810
811 ASSERT_NO_FATAL_FAILURE(InitState());
812 ASSERT_NO_FATAL_FAILURE(InitViewport());
813
Tony Barbour6918cd52015-04-09 12:58:51 -0600814 VkConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000815 meshBuffer.BufferMemoryBarrier();
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800816
Tony Barbour6918cd52015-04-09 12:58:51 -0600817 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
818 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800819
Tony Barbour6918cd52015-04-09 12:58:51 -0600820 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800821 pipelineobj.AddColorAttachment();
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800822 pipelineobj.AddShader(&vs);
823 pipelineobj.AddShader(&ps);
824
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600825#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600826 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600827 MESH_BUF_ID, // Binding ID
828 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600829 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800830 };
831
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600832 VkVertexInputAttributeDescription vi_attrib;
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600833 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
834 vi_attrib.location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -0600835 vi_attrib.format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600836 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800837
838 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
839 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600840 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800841
Tony Barbour6918cd52015-04-09 12:58:51 -0600842 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600843 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800844
Courtney Goeltzenleuchterb4337c12015-03-05 16:47:18 -0700845 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800846
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600847 VkPipelineColorBlendAttachmentState att = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600848 att.blendEnable = VK_FALSE;
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800849 att.channelWriteMask = 0xf;
Tony Barbourf52346d2015-01-16 14:27:35 -0700850 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800851
Tony Barbourfe3351b2015-07-28 10:17:20 -0600852 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour1fde6942015-01-09 10:06:53 -0700853
Tony Barbourfe3351b2015-07-28 10:17:20 -0600854 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour1fde6942015-01-09 10:06:53 -0700855
Tony Barbourfe3351b2015-07-28 10:17:20 -0600856 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour304ec8b2015-01-07 14:31:52 -0700857#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600858 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour304ec8b2015-01-07 14:31:52 -0700859 pDSDumpDot((char*)"triTest2.dot");
860#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600861
Tony Barbour304ec8b2015-01-07 14:31:52 -0700862 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -0600863 Draw(0, 3, 0, 1);
Tony Barbour304ec8b2015-01-07 14:31:52 -0700864
865 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600866 ASSERT_VK_SUCCESS(EndCommandBuffer());
867 QueueCommandBuffer();
Tony Barbour304ec8b2015-01-07 14:31:52 -0700868
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600869 RecordImages(m_renderTargets);
Chia-I Wufe7bb8f2014-12-05 10:32:23 +0800870}
871
Tony Barbour6918cd52015-04-09 12:58:51 -0600872TEST_F(VkRenderTest, QuadWithIndexedVertexFetch)
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700873{
874 static const char *vertShaderText =
875 "#version 140\n"
876 "#extension GL_ARB_separate_shader_objects : enable\n"
877 "#extension GL_ARB_shading_language_420pack : enable\n"
878 "layout(location = 0) in vec4 pos;\n"
879 "layout(location = 1) in vec4 inColor;\n"
880 "layout(location = 0) out vec4 outColor;\n"
881 "void main() {\n"
882 " outColor = inColor;\n"
883 " gl_Position = pos;\n"
884 "}\n";
885
886
887 static const char *fragShaderText =
888 "#version 140\n"
889 "#extension GL_ARB_separate_shader_objects : enable\n"
890 "#extension GL_ARB_shading_language_420pack : enable\n"
891 "layout(location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -0600892 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700893 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -0600894 " outColor = color;\n"
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700895 "}\n";
896
897 const Vertex g_vbData[] =
898 {
899 // first tri
900 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
901 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
902 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
903
904 // second tri
905 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
906 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
907 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
908 };
909
910 const uint16_t g_idxData[6] = {
911 0, 1, 2,
912 3, 4, 5,
913 };
914
915 ASSERT_NO_FATAL_FAILURE(InitState());
916 ASSERT_NO_FATAL_FAILURE(InitViewport());
917
Tony Barbour6918cd52015-04-09 12:58:51 -0600918 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +0000919 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700920
Tony Barbour6918cd52015-04-09 12:58:51 -0600921 VkIndexBufferObj indexBuffer(m_device);
Tony Barbourd1c35722015-04-16 15:59:00 -0600922 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), VK_INDEX_TYPE_UINT16, g_idxData);
Mark Lobodzinski49a6b4b2015-02-16 14:24:23 -0600923 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700924
Tony Barbour6918cd52015-04-09 12:58:51 -0600925 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
926 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700927
Tony Barbour6918cd52015-04-09 12:58:51 -0600928 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800929 pipelineobj.AddColorAttachment();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700930 pipelineobj.AddShader(&vs);
931 pipelineobj.AddShader(&ps);
932
Tony Barbour6918cd52015-04-09 12:58:51 -0600933 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600934 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
935 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, indexBuffer);
Tony Barbour831062d2015-04-02 15:43:15 -0600936
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700937
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600938#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600939 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600940 MESH_BIND_ID, // binding ID
941 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600942 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700943 };
944
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600945 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600946 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
947 vi_attribs[0].location = 0; // layout location of vertex attribute
Tony Barbourd1c35722015-04-16 15:59:00 -0600948 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600949 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
950 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
951 vi_attribs[1].location = 1; // layout location of vertex attribute
Tony Barbourd1c35722015-04-16 15:59:00 -0600952 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -0600953 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700954
955 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
956 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700957
958 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600959 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour1fde6942015-01-09 10:06:53 -0700960
Tony Barbourfe3351b2015-07-28 10:17:20 -0600961 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700962
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700963#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600964 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlisf27eba72014-12-16 17:34:50 -0700965 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700966#endif
Tony Barbour22e32a12015-01-08 17:08:28 -0700967
Tony Barbourfe3351b2015-07-28 10:17:20 -0600968 BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
969 BindIndexBuffer(&indexBuffer, 0);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700970
971 // render two triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -0600972 DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700973
974 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600975 ASSERT_VK_SUCCESS(EndCommandBuffer());
976 QueueCommandBuffer();
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700977
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -0600978 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter5e5c48f2014-12-04 15:45:16 -0700979}
980
Tony Barbour6918cd52015-04-09 12:58:51 -0600981TEST_F(VkRenderTest, GreyandRedCirclesonBlue)
GregF3156cb02014-12-02 15:41:44 -0700982{
983 // This tests gl_FragCoord
Tony Barboure2c58df2014-11-25 13:18:32 -0700984
GregF3156cb02014-12-02 15:41:44 -0700985 static const char *vertShaderText =
986 "#version 140\n"
987 "#extension GL_ARB_separate_shader_objects : enable\n"
988 "#extension GL_ARB_shading_language_420pack : enable\n"
989 "layout (location = 0) in vec4 pos;\n"
990 "layout (location = 0) out vec4 outColor;\n"
991 "layout (location = 1) out vec4 outColor2;\n"
992 "void main() {\n"
993 " gl_Position = pos;\n"
994 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
995 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
996 "}\n";
997
998 static const char *fragShaderText =
GregF3156cb02014-12-02 15:41:44 -0700999 "#version 330\n"
1000 "#extension GL_ARB_separate_shader_objects : enable\n"
1001 "#extension GL_ARB_shading_language_420pack : enable\n"
1002 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1003 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1004 "layout (location = 0) in vec4 color;\n"
1005 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001006 "layout (location = 0) out vec4 outColor;\n"
GregF3156cb02014-12-02 15:41:44 -07001007 "void main() {\n"
1008 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1009 " float dist_squared = dot(pos, pos);\n"
GregFaae75242015-06-03 18:40:50 -06001010 " outColor = (dist_squared < 400.0)\n"
GregF3156cb02014-12-02 15:41:44 -07001011 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1012 " : color2;\n"
1013 "}\n";
1014
1015 ASSERT_NO_FATAL_FAILURE(InitState());
1016 ASSERT_NO_FATAL_FAILURE(InitViewport());
1017
Tony Barbour6918cd52015-04-09 12:58:51 -06001018 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001019 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001020
Tony Barbour6918cd52015-04-09 12:58:51 -06001021 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1022 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF3156cb02014-12-02 15:41:44 -07001023
Tony Barbour6918cd52015-04-09 12:58:51 -06001024 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001025 pipelineobj.AddColorAttachment();
GregF3156cb02014-12-02 15:41:44 -07001026 pipelineobj.AddShader(&vs);
1027 pipelineobj.AddShader(&ps);
1028
Tony Barbour6918cd52015-04-09 12:58:51 -06001029 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001030 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001031
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001032#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001033 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001034 MESH_BIND_ID, // binding ID
1035 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001036 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF3156cb02014-12-02 15:41:44 -07001037 };
1038
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001039 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001040 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1041 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001042 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001043 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF3156cb02014-12-02 15:41:44 -07001044
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001045 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF3156cb02014-12-02 15:41:44 -07001046 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001047 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF3156cb02014-12-02 15:41:44 -07001048
Tony Barbour664accc2015-01-09 12:55:14 -07001049 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour664accc2015-01-09 12:55:14 -07001050
Tony Barbourfe3351b2015-07-28 10:17:20 -06001051 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001052
Tony Barbourfe3351b2015-07-28 10:17:20 -06001053 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001054
Tony Barbourfe3351b2015-07-28 10:17:20 -06001055 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001056#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001057 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001058 pDSDumpDot((char*)"triTest2.dot");
1059#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001060
Tony Barbour664accc2015-01-09 12:55:14 -07001061 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06001062 Draw(0, 6, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07001063
1064 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001065 EndCommandBuffer();
1066 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001067
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001068 RecordImages(m_renderTargets);
GregF3156cb02014-12-02 15:41:44 -07001069}
1070
Tony Barbour6918cd52015-04-09 12:58:51 -06001071TEST_F(VkRenderTest, RedCirclesonBlue)
GregF3156cb02014-12-02 15:41:44 -07001072{
1073 // This tests that we correctly handle unread fragment inputs
1074
1075 static const char *vertShaderText =
1076 "#version 140\n"
1077 "#extension GL_ARB_separate_shader_objects : enable\n"
1078 "#extension GL_ARB_shading_language_420pack : enable\n"
1079 "layout (location = 0) in vec4 pos;\n"
1080 "layout (location = 0) out vec4 outColor;\n"
1081 "layout (location = 1) out vec4 outColor2;\n"
1082 "void main() {\n"
1083 " gl_Position = pos;\n"
1084 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1085 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1086 "}\n";
1087
1088 static const char *fragShaderText =
GregF3156cb02014-12-02 15:41:44 -07001089 "#version 330\n"
1090 "#extension GL_ARB_separate_shader_objects : enable\n"
1091 "#extension GL_ARB_shading_language_420pack : enable\n"
1092 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1093 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1094 "layout (location = 0) in vec4 color;\n"
1095 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001096 "layout (location = 0) out vec4 outColor;\n"
GregF3156cb02014-12-02 15:41:44 -07001097 "void main() {\n"
1098 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1099 " float dist_squared = dot(pos, pos);\n"
GregFaae75242015-06-03 18:40:50 -06001100 " outColor = (dist_squared < 400.0)\n"
GregF3156cb02014-12-02 15:41:44 -07001101 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1102 " : color2;\n"
1103 "}\n";
1104
1105 ASSERT_NO_FATAL_FAILURE(InitState());
1106 ASSERT_NO_FATAL_FAILURE(InitViewport());
1107
Tony Barbour6918cd52015-04-09 12:58:51 -06001108 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001109 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001110
Tony Barbour6918cd52015-04-09 12:58:51 -06001111 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1112 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF3156cb02014-12-02 15:41:44 -07001113
Tony Barbour6918cd52015-04-09 12:58:51 -06001114 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001115 pipelineobj.AddColorAttachment();
GregF3156cb02014-12-02 15:41:44 -07001116 pipelineobj.AddShader(&vs);
1117 pipelineobj.AddShader(&ps);
1118
Tony Barbour6918cd52015-04-09 12:58:51 -06001119 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001120 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001121
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001122#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001123 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001124 MESH_BIND_ID, // binding ID
1125 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001126 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF3156cb02014-12-02 15:41:44 -07001127 };
1128
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001129 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001130 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1131 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001132 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001133 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF3156cb02014-12-02 15:41:44 -07001134
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001135 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF3156cb02014-12-02 15:41:44 -07001136 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001137 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF3156cb02014-12-02 15:41:44 -07001138
Tony Barbour664accc2015-01-09 12:55:14 -07001139 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001140 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001141
Tony Barbourfe3351b2015-07-28 10:17:20 -06001142 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001143
Tony Barbourfe3351b2015-07-28 10:17:20 -06001144 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001145#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001146 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001147 pDSDumpDot((char*)"triTest2.dot");
1148#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001149 // render two triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -06001150 Draw(0, 6, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07001151
1152 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001153 EndCommandBuffer();
1154 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001155
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001156 RecordImages(m_renderTargets);
GregF3156cb02014-12-02 15:41:44 -07001157}
1158
Tony Barbour6918cd52015-04-09 12:58:51 -06001159TEST_F(VkRenderTest, GreyCirclesonBlueFade)
GregF3156cb02014-12-02 15:41:44 -07001160{
1161 // This tests reading gl_ClipDistance from FS
1162
1163 static const char *vertShaderText =
GregFaae75242015-06-03 18:40:50 -06001164 //"#version 140\n"
GregF3156cb02014-12-02 15:41:44 -07001165 "#version 330\n"
1166 "#extension GL_ARB_separate_shader_objects : enable\n"
1167 "#extension GL_ARB_shading_language_420pack : enable\n"
1168 "out gl_PerVertex {\n"
1169 " vec4 gl_Position;\n"
1170 " float gl_ClipDistance[1];\n"
1171 "};\n"
1172 "layout (location = 0) in vec4 pos;\n"
1173 "layout (location = 0) out vec4 outColor;\n"
1174 "layout (location = 1) out vec4 outColor2;\n"
1175 "void main() {\n"
1176 " gl_Position = pos;\n"
1177 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1178 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1179 " float dists[3];\n"
1180 " dists[0] = 0.0;\n"
1181 " dists[1] = 1.0;\n"
1182 " dists[2] = 1.0;\n"
1183 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1184 "}\n";
1185
1186
1187 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -06001188 "#version 140\n"
1189 //"#version 330\n"
GregF3156cb02014-12-02 15:41:44 -07001190 "#extension GL_ARB_separate_shader_objects : enable\n"
1191 "#extension GL_ARB_shading_language_420pack : enable\n"
1192 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1193 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1194 "layout (location = 0) in vec4 color;\n"
1195 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001196 "layout (location = 0) out vec4 uFragColor;\n"
GregF3156cb02014-12-02 15:41:44 -07001197 "void main() {\n"
1198 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1199 " float dist_squared = dot(pos, pos);\n"
GregFaae75242015-06-03 18:40:50 -06001200 " uFragColor = (dist_squared < 400.0)\n"
GregF3156cb02014-12-02 15:41:44 -07001201 " ? color * gl_ClipDistance[0]\n"
1202 " : color2;\n"
1203 "}\n";
1204
1205 ASSERT_NO_FATAL_FAILURE(InitState());
1206 ASSERT_NO_FATAL_FAILURE(InitViewport());
1207
Tony Barbour6918cd52015-04-09 12:58:51 -06001208 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001209 meshBuffer.BufferMemoryBarrier();
GregF3156cb02014-12-02 15:41:44 -07001210
Tony Barbour6918cd52015-04-09 12:58:51 -06001211 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1212 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF3156cb02014-12-02 15:41:44 -07001213
Tony Barbour6918cd52015-04-09 12:58:51 -06001214 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001215 pipelineobj.AddColorAttachment();
GregF3156cb02014-12-02 15:41:44 -07001216 pipelineobj.AddShader(&vs);
1217 pipelineobj.AddShader(&ps);
1218
Tony Barbour6918cd52015-04-09 12:58:51 -06001219 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001220 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001221
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001222#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001223 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001224 MESH_BIND_ID, // binding ID
1225 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001226 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF3156cb02014-12-02 15:41:44 -07001227 };
1228
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001229 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001230 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1231 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001232 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001233 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF3156cb02014-12-02 15:41:44 -07001234
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001235 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF3156cb02014-12-02 15:41:44 -07001236 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001237 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF3156cb02014-12-02 15:41:44 -07001238
Tony Barbour664accc2015-01-09 12:55:14 -07001239 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
GregF3156cb02014-12-02 15:41:44 -07001240
Tony Barbourfe3351b2015-07-28 10:17:20 -06001241 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001242
Tony Barbourfe3351b2015-07-28 10:17:20 -06001243 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001244
Tony Barbourfe3351b2015-07-28 10:17:20 -06001245 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001246#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001247 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001248 pDSDumpDot((char*)"triTest2.dot");
1249#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001250
1251 // render two triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -06001252 Draw(0, 6, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07001253
1254 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001255 EndCommandBuffer();
1256 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001257
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001258 RecordImages(m_renderTargets);
GregF3156cb02014-12-02 15:41:44 -07001259}
Tony Barboure2c58df2014-11-25 13:18:32 -07001260
Tony Barbour6918cd52015-04-09 12:58:51 -06001261TEST_F(VkRenderTest, GreyCirclesonBlueDiscard)
GregF42226582014-12-02 17:19:34 -07001262{
1263 static const char *vertShaderText =
1264 "#version 140\n"
1265 "#extension GL_ARB_separate_shader_objects : enable\n"
1266 "#extension GL_ARB_shading_language_420pack : enable\n"
1267 "layout (location = 0) in vec4 pos;\n"
1268 "layout (location = 0) out vec4 outColor;\n"
1269 "layout (location = 1) out vec4 outColor2;\n"
1270 "void main() {\n"
1271 " gl_Position = pos;\n"
1272 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1273 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1274 "}\n";
1275
1276
1277 static const char *fragShaderText =
GregF42226582014-12-02 17:19:34 -07001278 "#version 330\n"
1279 "#extension GL_ARB_separate_shader_objects : enable\n"
1280 "#extension GL_ARB_shading_language_420pack : enable\n"
1281 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1282 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1283 "layout (location = 0) in vec4 color;\n"
1284 "layout (location = 1) in vec4 color2;\n"
GregFaae75242015-06-03 18:40:50 -06001285 "layout (location = 0) out vec4 outColor;\n"
GregF42226582014-12-02 17:19:34 -07001286 "void main() {\n"
1287 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1288 " float dist_squared = dot(pos, pos);\n"
1289 " if (dist_squared < 100.0)\n"
1290 " discard;\n"
GregFaae75242015-06-03 18:40:50 -06001291 " outColor = (dist_squared < 400.0)\n"
GregF42226582014-12-02 17:19:34 -07001292 " ? color\n"
1293 " : color2;\n"
1294 "}\n";
1295
1296 ASSERT_NO_FATAL_FAILURE(InitState());
1297 ASSERT_NO_FATAL_FAILURE(InitViewport());
1298
Tony Barbour6918cd52015-04-09 12:58:51 -06001299 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001300 meshBuffer.BufferMemoryBarrier();
GregF42226582014-12-02 17:19:34 -07001301
Tony Barbour6918cd52015-04-09 12:58:51 -06001302 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1303 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF42226582014-12-02 17:19:34 -07001304
Tony Barbour6918cd52015-04-09 12:58:51 -06001305 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001306 pipelineobj.AddColorAttachment();
GregF42226582014-12-02 17:19:34 -07001307 pipelineobj.AddShader(&vs);
1308 pipelineobj.AddShader(&ps);
1309
Tony Barbour6918cd52015-04-09 12:58:51 -06001310 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001311 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001312
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001313#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001314 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001315 MESH_BIND_ID, // binding ID
1316 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001317 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF42226582014-12-02 17:19:34 -07001318 };
1319
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001320 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001321 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1322 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001323 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001324 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF42226582014-12-02 17:19:34 -07001325
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001326 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF42226582014-12-02 17:19:34 -07001327 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001328 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF42226582014-12-02 17:19:34 -07001329
Tony Barbour664accc2015-01-09 12:55:14 -07001330 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour664accc2015-01-09 12:55:14 -07001331
Tony Barbourfe3351b2015-07-28 10:17:20 -06001332 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001333
Tony Barbourfe3351b2015-07-28 10:17:20 -06001334 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001335
Tony Barbourfe3351b2015-07-28 10:17:20 -06001336 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001337#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001338 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001339 pDSDumpDot((char*)"triTest2.dot");
1340#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001341
1342 // render two triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -06001343 Draw(0, 6, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07001344
1345 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001346 EndCommandBuffer();
1347 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001348
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001349 RecordImages(m_renderTargets);
GregF42226582014-12-02 17:19:34 -07001350}
1351
1352
Tony Barbour6918cd52015-04-09 12:58:51 -06001353TEST_F(VkRenderTest, TriangleVSUniform)
Cody Northrop66594a72014-10-10 14:49:36 -06001354{
1355 static const char *vertShaderText =
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001356 "#version 140\n"
1357 "#extension GL_ARB_separate_shader_objects : enable\n"
1358 "#extension GL_ARB_shading_language_420pack : enable\n"
1359 "\n"
1360 "layout(binding = 0) uniform buf {\n"
1361 " mat4 MVP;\n"
1362 "} ubuf;\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001363 "void main() {\n"
1364 " vec2 vertices[3];"
1365 " vertices[0] = vec2(-0.5, -0.5);\n"
1366 " vertices[1] = vec2( 0.5, -0.5);\n"
1367 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001368 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001369 "}\n";
1370
1371 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -06001372 "#version 140\n"
1373 "#extension GL_ARB_separate_shader_objects : enable\n"
1374 "#extension GL_ARB_shading_language_420pack : enable\n"
1375 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001376 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001377 " outColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop66594a72014-10-10 14:49:36 -06001378 "}\n";
1379
Tony Barboure2c58df2014-11-25 13:18:32 -07001380 ASSERT_NO_FATAL_FAILURE(InitState());
1381 ASSERT_NO_FATAL_FAILURE(InitViewport());
1382
Courtney Goeltzenleuchterfdcfb9f2014-10-10 18:04:39 -06001383 // Create identity matrix
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001384 glm::mat4 Projection = glm::mat4(1.0f);
1385 glm::mat4 View = glm::mat4(1.0f);
1386 glm::mat4 Model = glm::mat4(1.0f);
1387 glm::mat4 MVP = Projection * View * Model;
1388 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1389
Tony Barbour6918cd52015-04-09 12:58:51 -06001390 VkConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1391 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1392 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001393
Tony Barbour6918cd52015-04-09 12:58:51 -06001394 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001395 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001396 pipelineobj.AddShader(&vs);
1397 pipelineobj.AddShader(&ps);
1398
1399 // Create descriptor set and attach the constant buffer to it
Tony Barbour6918cd52015-04-09 12:58:51 -06001400 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001401 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07001402
Tony Barbour664accc2015-01-09 12:55:14 -07001403 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001404 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure2c58df2014-11-25 13:18:32 -07001405
Tony Barbourfe3351b2015-07-28 10:17:20 -06001406 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001407
Tony Barbour664accc2015-01-09 12:55:14 -07001408#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001409 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001410 pDSDumpDot((char*)"triTest2.dot");
1411#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001412
1413 // render two triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -06001414 Draw(0, 6, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07001415
1416 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001417 EndCommandBuffer();
1418 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001419
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001420 RecordImages(m_renderTargets);
Tony Barbour664accc2015-01-09 12:55:14 -07001421
Tony Barbourfe3351b2015-07-28 10:17:20 -06001422 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer);
Courtney Goeltzenleuchter82857042014-10-27 09:48:52 -06001423}
1424
Tony Barbour6918cd52015-04-09 12:58:51 -06001425TEST_F(VkRenderTest, MixTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07001426{
1427 // This tests location applied to varyings. Notice that we have switched foo
1428 // and bar in the FS. The triangle should be blended with red, green and blue
1429 // corners.
1430 static const char *vertShaderText =
1431 "#version 140\n"
1432 "#extension GL_ARB_separate_shader_objects : enable\n"
1433 "#extension GL_ARB_shading_language_420pack : enable\n"
1434 "layout (location=0) out vec4 bar;\n"
1435 "layout (location=1) out vec4 foo;\n"
1436 "layout (location=2) out float scale;\n"
1437 "vec2 vertices[3];\n"
1438 "void main() {\n"
1439 " vertices[0] = vec2(-1.0, -1.0);\n"
1440 " vertices[1] = vec2( 1.0, -1.0);\n"
1441 " vertices[2] = vec2( 0.0, 1.0);\n"
1442 "vec4 colors[3];\n"
1443 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1444 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1445 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1446 " foo = colors[gl_VertexID % 3];\n"
1447 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1448 " scale = 1.0;\n"
1449 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1450 "}\n";
1451
1452 static const char *fragShaderText =
1453 "#version 140\n"
1454 "#extension GL_ARB_separate_shader_objects : enable\n"
1455 "#extension GL_ARB_shading_language_420pack : enable\n"
1456 "layout (location = 1) in vec4 bar;\n"
1457 "layout (location = 0) in vec4 foo;\n"
1458 "layout (location = 2) in float scale;\n"
GregFaae75242015-06-03 18:40:50 -06001459 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001460 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001461 " outColor = bar * scale + foo * (1.0-scale);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001462 "}\n";
1463
1464 ASSERT_NO_FATAL_FAILURE(InitState());
1465 ASSERT_NO_FATAL_FAILURE(InitViewport());
1466
Tony Barbour6918cd52015-04-09 12:58:51 -06001467 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1468 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001469
Tony Barbour6918cd52015-04-09 12:58:51 -06001470 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001471 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001472 pipelineobj.AddShader(&vs);
1473 pipelineobj.AddShader(&ps);
1474
Tony Barbour6918cd52015-04-09 12:58:51 -06001475 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour831062d2015-04-02 15:43:15 -06001476 descriptorSet.AppendDummy();
Tony Barboure2c58df2014-11-25 13:18:32 -07001477
Tony Barbour664accc2015-01-09 12:55:14 -07001478 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour664accc2015-01-09 12:55:14 -07001479
Tony Barbourfe3351b2015-07-28 10:17:20 -06001480 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001481
Tony Barbourfe3351b2015-07-28 10:17:20 -06001482 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001483
1484#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001485 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001486 pDSDumpDot((char*)"triTest2.dot");
1487#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001488
Tony Barbour664accc2015-01-09 12:55:14 -07001489 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06001490 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07001491
1492 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001493 EndCommandBuffer();
1494 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001495
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001496 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001497}
1498
Tony Barbour6918cd52015-04-09 12:58:51 -06001499TEST_F(VkRenderTest, QuadVertFetchAndVertID)
Tony Barboure2c58df2014-11-25 13:18:32 -07001500{
1501 // This tests that attributes work in the presence of gl_VertexID
1502
1503 static const char *vertShaderText =
1504 "#version 140\n"
1505 "#extension GL_ARB_separate_shader_objects : enable\n"
1506 "#extension GL_ARB_shading_language_420pack : enable\n"
1507 //XYZ1( -1, -1, -1 )
1508 "layout (location = 0) in vec4 pos;\n"
1509 //XYZ1( 0.f, 0.f, 0.f )
1510 "layout (location = 1) in vec4 inColor;\n"
1511 "layout (location = 0) out vec4 outColor;\n"
1512 "void main() {\n"
1513 " outColor = inColor;\n"
1514 " vec4 vertices[3];"
1515 " vertices[gl_VertexID % 3] = pos;\n"
1516 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1517 "}\n";
1518
1519
1520 static const char *fragShaderText =
1521 "#version 140\n"
1522 "#extension GL_ARB_separate_shader_objects : enable\n"
1523 "#extension GL_ARB_shading_language_420pack : enable\n"
1524 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06001525 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001526 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001527 " outColor = color;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001528 "}\n";
1529
1530 ASSERT_NO_FATAL_FAILURE(InitState());
1531 ASSERT_NO_FATAL_FAILURE(InitViewport());
1532
Tony Barbour6918cd52015-04-09 12:58:51 -06001533 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001534 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07001535
Tony Barbour6918cd52015-04-09 12:58:51 -06001536 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1537 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001538
Tony Barbour6918cd52015-04-09 12:58:51 -06001539 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001540 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001541 pipelineobj.AddShader(&vs);
1542 pipelineobj.AddShader(&ps);
1543
Tony Barbour6918cd52015-04-09 12:58:51 -06001544 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001545 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001546
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001547#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001548 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001549 MESH_BUF_ID, // Binding ID
1550 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001551 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barboure2c58df2014-11-25 13:18:32 -07001552 };
1553
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001554 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001555 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1556 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001557 vi_attribs[0].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001558 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1559 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1560 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001561 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001562 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -07001563
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001564 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001565 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001566 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barboure2c58df2014-11-25 13:18:32 -07001567
Tony Barbour664accc2015-01-09 12:55:14 -07001568 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour664accc2015-01-09 12:55:14 -07001569
Tony Barbourfe3351b2015-07-28 10:17:20 -06001570 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001571
Tony Barbourfe3351b2015-07-28 10:17:20 -06001572 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001573
Tony Barbourfe3351b2015-07-28 10:17:20 -06001574 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001575#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001576 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001577 pDSDumpDot((char*)"triTest2.dot");
1578#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001579
1580 // render two triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -06001581 Draw(0, 6, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07001582
1583 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001584 EndCommandBuffer();
1585 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001586
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001587 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001588}
1589
Tony Barbour6918cd52015-04-09 12:58:51 -06001590TEST_F(VkRenderTest, QuadSparseVertFetch)
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001591{
1592 // This tests that attributes work in the presence of gl_VertexID
1593
1594 static const char *vertShaderText =
1595 "#version 140\n"
1596 "#extension GL_ARB_separate_shader_objects : enable\n"
1597 "#extension GL_ARB_shading_language_420pack : enable\n"
1598 //XYZ1( -1, -1, -1 )
1599 "layout (location = 1) in vec4 pos;\n"
1600 "layout (location = 4) in vec4 inColor;\n"
1601 //XYZ1( 0.f, 0.f, 0.f )
1602 "layout (location = 0) out vec4 outColor;\n"
1603 "void main() {\n"
1604 " outColor = inColor;\n"
1605 " gl_Position = pos;\n"
1606 "}\n";
1607
1608
1609 static const char *fragShaderText =
1610 "#version 140\n"
1611 "#extension GL_ARB_separate_shader_objects : enable\n"
1612 "#extension GL_ARB_shading_language_420pack : enable\n"
1613 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06001614 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001615 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001616 " outColor = color;\n"
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001617 "}\n";
1618
1619 ASSERT_NO_FATAL_FAILURE(InitState());
1620 ASSERT_NO_FATAL_FAILURE(InitViewport());
1621
1622 struct VDATA
1623 {
1624 float t1, t2, t3, t4; // filler data
1625 float posX, posY, posZ, posW; // Position data
1626 float r, g, b, a; // Color
1627 };
1628 const struct VDATA vData[] =
1629 {
1630 { XYZ1(0, 0, 0), XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
1631 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1632 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1633 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1634 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1635 { XYZ1(0, 0, 0), XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
1636 };
1637
Tony Barbour6918cd52015-04-09 12:58:51 -06001638 VkConstantBufferObj meshBuffer(m_device,sizeof(vData)/sizeof(vData[0]),sizeof(vData[0]), vData);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001639 meshBuffer.BufferMemoryBarrier();
1640
Tony Barbour6918cd52015-04-09 12:58:51 -06001641 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1642 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001643
Tony Barbour6918cd52015-04-09 12:58:51 -06001644 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001645 pipelineobj.AddColorAttachment();
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001646 pipelineobj.AddShader(&vs);
1647 pipelineobj.AddShader(&ps);
1648
Tony Barbour6918cd52015-04-09 12:58:51 -06001649 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001650 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001651
1652#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001653 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001654 MESH_BUF_ID, // Binding ID
1655 sizeof(vData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001656 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001657 };
1658
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001659 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001660 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1661 vi_attribs[0].location = 4;
Tony Barbourd1c35722015-04-16 15:59:00 -06001662 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001663 vi_attribs[0].offsetInBytes = sizeof(float) * 4 * 2; // Offset of first element in bytes from base of vertex
1664 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1665 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001666 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001667 vi_attribs[1].offsetInBytes = sizeof(float) * 4 * 1; // Offset of first element in bytes from base of vertex
1668
1669 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
1670 pipelineobj.AddVertexInputBindings(&vi_binding, 1);
1671 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
1672
1673 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001674
Tony Barbourfe3351b2015-07-28 10:17:20 -06001675 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001676
Tony Barbourfe3351b2015-07-28 10:17:20 -06001677 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001678
Tony Barbourfe3351b2015-07-28 10:17:20 -06001679 BindVertexBuffer(&meshBuffer, 0, MESH_BUF_ID);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001680#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001681 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001682 pDSDumpDot((char*)"triTest2.dot");
1683#endif
1684
1685 // render two triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -06001686 Draw(0, 6, 0, 1);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001687
1688 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001689 EndCommandBuffer();
1690 QueueCommandBuffer();
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001691
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001692 RecordImages(m_renderTargets);
Courtney Goeltzenleuchterf35a5142015-03-31 16:39:32 -06001693}
1694
Tony Barbour6918cd52015-04-09 12:58:51 -06001695TEST_F(VkRenderTest, TriVertFetchDeadAttr)
Tony Barboure2c58df2014-11-25 13:18:32 -07001696{
1697 // This tests that attributes work in the presence of gl_VertexID
1698 // and a dead attribute in position 0. Draws a triangle with yellow,
1699 // red and green corners, starting at top and going clockwise.
1700
1701 static const char *vertShaderText =
1702 "#version 140\n"
1703 "#extension GL_ARB_separate_shader_objects : enable\n"
1704 "#extension GL_ARB_shading_language_420pack : enable\n"
1705 //XYZ1( -1, -1, -1 )
1706 "layout (location = 0) in vec4 pos;\n"
1707 //XYZ1( 0.f, 0.f, 0.f )
1708 "layout (location = 1) in vec4 inColor;\n"
1709 "layout (location = 0) out vec4 outColor;\n"
1710 "void main() {\n"
1711 " outColor = inColor;\n"
1712 " vec2 vertices[3];"
1713 " vertices[0] = vec2(-1.0, -1.0);\n"
1714 " vertices[1] = vec2( 1.0, -1.0);\n"
1715 " vertices[2] = vec2( 0.0, 1.0);\n"
1716 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1717 "}\n";
1718
1719
1720 static const char *fragShaderText =
1721 "#version 140\n"
1722 "#extension GL_ARB_separate_shader_objects : enable\n"
1723 "#extension GL_ARB_shading_language_420pack : enable\n"
1724 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06001725 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001726 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001727 " outColor = color;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001728 "}\n";
1729
1730 ASSERT_NO_FATAL_FAILURE(InitState());
1731 ASSERT_NO_FATAL_FAILURE(InitViewport());
1732
Tony Barbour6918cd52015-04-09 12:58:51 -06001733 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001734 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07001735
Tony Barbour6918cd52015-04-09 12:58:51 -06001736 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1737 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001738
Tony Barbour6918cd52015-04-09 12:58:51 -06001739 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001740 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001741 pipelineobj.AddShader(&vs);
1742 pipelineobj.AddShader(&ps);
1743
Tony Barbour6918cd52015-04-09 12:58:51 -06001744 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001745 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001746
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001747#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001748 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001749 MESH_BUF_ID, // Binding ID
1750 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001751 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barboure2c58df2014-11-25 13:18:32 -07001752 };
1753
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001754 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001755 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1756 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001757 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001758 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1759 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1760 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001761 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001762 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -07001763
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001764 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001765 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001766 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barboure2c58df2014-11-25 13:18:32 -07001767
Tony Barbour664accc2015-01-09 12:55:14 -07001768 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboure2c58df2014-11-25 13:18:32 -07001769
Tony Barbourfe3351b2015-07-28 10:17:20 -06001770 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07001771
Tony Barbourfe3351b2015-07-28 10:17:20 -06001772 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001773
Tony Barbourfe3351b2015-07-28 10:17:20 -06001774 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07001775#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001776 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001777 pDSDumpDot((char*)"triTest2.dot");
1778#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001779
1780 // render two triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -06001781 Draw(0, 6, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07001782
1783 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001784 EndCommandBuffer();
1785 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001786
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001787 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001788}
1789
Tony Barbour6918cd52015-04-09 12:58:51 -06001790TEST_F(VkRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001791{
1792 static const char *vertShaderText =
1793 "#version 140\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001794 "#extension GL_ARB_separate_shader_objects : enable\n"
1795 "#extension GL_ARB_shading_language_420pack : enable\n"
GregFaae75242015-06-03 18:40:50 -06001796 "layout (std140, binding = 0) uniform bufferVals {\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001797 " mat4 mvp;\n"
1798 "} myBufferVals;\n"
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001799 "layout (location = 0) in vec4 pos;\n"
1800 "layout (location = 1) in vec4 inColor;\n"
Cody Northrop8a3bb132015-06-16 17:32:04 -06001801 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001802 "void main() {\n"
1803 " outColor = inColor;\n"
1804 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06001805 " gl_Position.y = -gl_Position.y;\n"
1806 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001807 "}\n";
1808
1809 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -06001810 "#version 140\n"
1811 "#extension GL_ARB_separate_shader_objects : enable\n"
1812 "#extension GL_ARB_shading_language_420pack : enable\n"
1813 "layout (location = 0) in vec4 color;\n"
1814 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001815 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001816 " outColor = color;\n"
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001817 "}\n";
Tony Barboure2c58df2014-11-25 13:18:32 -07001818 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001819
Tony Barboure2c58df2014-11-25 13:18:32 -07001820 glm::mat4 View = glm::lookAt(
1821 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1822 glm::vec3(0,0,0), // and looks at the origin
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06001823 glm::vec3(0,-1,0) // Head is up (set to 0,-1,0 to look upside-down)
Tony Barboure2c58df2014-11-25 13:18:32 -07001824 );
1825
1826 glm::mat4 Model = glm::mat4(1.0f);
1827
1828 glm::mat4 MVP = Projection * View * Model;
1829
1830 ASSERT_NO_FATAL_FAILURE(InitState());
1831 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wub4052042015-07-09 10:16:34 +08001832 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Chia-I Wu08accc62015-07-07 11:50:03 +08001833 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height, m_depth_stencil_fmt);
Tony Barboure2c58df2014-11-25 13:18:32 -07001834
Tony Barbour6918cd52015-04-09 12:58:51 -06001835 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 -07001836 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1837
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001838 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barboure2c58df2014-11-25 13:18:32 -07001839
Tony Barbour6918cd52015-04-09 12:58:51 -06001840 VkConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1841 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1842 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07001843
Tony Barbour6918cd52015-04-09 12:58:51 -06001844 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001845 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001846 pipelineobj.AddShader(&vs);
1847 pipelineobj.AddShader(&ps);
1848
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001849 VkPipelineDepthStencilStateCreateInfo ds_state;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001850 ds_state.depthTestEnable = VK_TRUE;
1851 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbourd1c35722015-04-16 15:59:00 -06001852 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001853 ds_state.depthBoundsEnable = VK_FALSE;
1854 ds_state.stencilTestEnable = VK_FALSE;
1855 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
1856 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
1857 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbourd1c35722015-04-16 15:59:00 -06001858 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
Tony Barbourf52346d2015-01-16 14:27:35 -07001859 ds_state.front = ds_state.back;
1860 pipelineobj.SetDepthStencil(&ds_state);
1861
Tony Barbour6918cd52015-04-09 12:58:51 -06001862 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001863 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07001864
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001865#define MESH_BUF_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001866 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001867 MESH_BUF_ID, // Binding ID
1868 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001869 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001870 };
Tony Barboure2c58df2014-11-25 13:18:32 -07001871
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001872 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001873 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1874 vi_attribs[0].location = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -06001875 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001876 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1877 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1878 vi_attribs[1].location = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001879 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001880 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barboure2c58df2014-11-25 13:18:32 -07001881
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001882 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barboure2c58df2014-11-25 13:18:32 -07001883 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06001884 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barboure2c58df2014-11-25 13:18:32 -07001885
Tony Barbour1c45ce02015-03-27 17:03:18 -06001886 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour1c45ce02015-03-27 17:03:18 -06001887
Tony Barbourfe3351b2015-07-28 10:17:20 -06001888 ASSERT_VK_SUCCESS(BeginCommandBuffer());
1889 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barboure2c58df2014-11-25 13:18:32 -07001890
Tony Barbourfe3351b2015-07-28 10:17:20 -06001891 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour1fde6942015-01-09 10:06:53 -07001892#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001893 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour1fde6942015-01-09 10:06:53 -07001894 pDSDumpDot((char*)"triTest2.dot");
1895#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001896
1897 // render triangles
Tony Barbourfe3351b2015-07-28 10:17:20 -06001898 Draw(0, 36, 0, 1);
Tony Barbour1fde6942015-01-09 10:06:53 -07001899
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001900
Tony Barbour1fde6942015-01-09 10:06:53 -07001901 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001902 EndCommandBuffer();
1903 QueueCommandBuffer();
Tony Barbour1fde6942015-01-09 10:06:53 -07001904
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001905 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter83884952014-10-20 16:33:15 -06001906}
1907
Tony Barbour6918cd52015-04-09 12:58:51 -06001908TEST_F(VkRenderTest, VSTexture)
Tony Barboure2c58df2014-11-25 13:18:32 -07001909{
1910 // The expected result from this test is a green and red triangle;
1911 // one red vertex on the left, two green vertices on the right.
1912 static const char *vertShaderText =
Cody Northrop8a3bb132015-06-16 17:32:04 -06001913 "#version 140\n"
1914 "#extension GL_ARB_separate_shader_objects : enable\n"
1915 "#extension GL_ARB_shading_language_420pack : enable\n"
1916 "layout (location = 0) out vec4 texColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001917 "uniform sampler2D surface;\n"
1918 "void main() {\n"
1919 " vec2 vertices[3];"
1920 " vertices[0] = vec2(-0.5, -0.5);\n"
1921 " vertices[1] = vec2( 0.5, -0.5);\n"
1922 " vertices[2] = vec2( 0.5, 0.5);\n"
1923 " vec2 positions[3];"
1924 " positions[0] = vec2( 0.0, 0.0);\n"
1925 " positions[1] = vec2( 0.25, 0.1);\n"
1926 " positions[2] = vec2( 0.1, 0.25);\n"
1927 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1928 " texColor = textureLod(surface, samplePos, 0.0);\n"
1929 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1930 "}\n";
1931
1932 static const char *fragShaderText =
GregFaae75242015-06-03 18:40:50 -06001933 "#version 140\n"
1934 "#extension GL_ARB_separate_shader_objects : enable\n"
1935 "#extension GL_ARB_shading_language_420pack : enable\n"
1936 "layout (location = 0) in vec4 texColor;\n"
1937 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001938 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06001939 " outColor = texColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07001940 "}\n";
1941
1942 ASSERT_NO_FATAL_FAILURE(InitState());
1943 ASSERT_NO_FATAL_FAILURE(InitViewport());
1944
Tony Barbour6918cd52015-04-09 12:58:51 -06001945 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1946 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
1947 VkSamplerObj sampler(m_device);
1948 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07001949
Tony Barbour6918cd52015-04-09 12:58:51 -06001950 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08001951 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07001952 pipelineobj.AddShader(&vs);
1953 pipelineobj.AddShader(&ps);
1954
Tony Barbour6918cd52015-04-09 12:58:51 -06001955 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08001956 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07001957
Tony Barbour664accc2015-01-09 12:55:14 -07001958 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06001959 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure2c58df2014-11-25 13:18:32 -07001960
Tony Barbourfe3351b2015-07-28 10:17:20 -06001961 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07001962
1963#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001964 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07001965 pDSDumpDot((char*)"triTest2.dot");
1966#endif
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001967
Tony Barbour664accc2015-01-09 12:55:14 -07001968 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06001969 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07001970
1971 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06001972 EndCommandBuffer();
1973 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07001974
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06001975 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07001976}
GregFaae75242015-06-03 18:40:50 -06001977
1978
1979
Tony Barbour6918cd52015-04-09 12:58:51 -06001980TEST_F(VkRenderTest, TexturedTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07001981{
1982 // The expected result from this test is a red and green checkered triangle
1983 static const char *vertShaderText =
1984 "#version 140\n"
1985 "#extension GL_ARB_separate_shader_objects : enable\n"
1986 "#extension GL_ARB_shading_language_420pack : enable\n"
1987 "layout (location = 0) out vec2 samplePos;\n"
1988 "void main() {\n"
1989 " vec2 vertices[3];"
1990 " vertices[0] = vec2(-0.5, -0.5);\n"
1991 " vertices[1] = vec2( 0.5, -0.5);\n"
1992 " vertices[2] = vec2( 0.5, 0.5);\n"
1993 " vec2 positions[3];"
1994 " positions[0] = vec2( 0.0, 0.0);\n"
1995 " positions[1] = vec2( 1.0, 0.0);\n"
1996 " positions[2] = vec2( 1.0, 1.0);\n"
1997 " samplePos = positions[gl_VertexID % 3];\n"
1998 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1999 "}\n";
2000
2001 static const char *fragShaderText =
2002 "#version 140\n"
2003 "#extension GL_ARB_separate_shader_objects : enable\n"
2004 "#extension GL_ARB_shading_language_420pack : enable\n"
2005 "layout (location = 0) in vec2 samplePos;\n"
2006 "layout (binding = 0) uniform sampler2D surface;\n"
2007 "layout (location=0) out vec4 outColor;\n"
2008 "void main() {\n"
2009 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2010 " outColor = texColor;\n"
2011 "}\n";
2012
2013 ASSERT_NO_FATAL_FAILURE(InitState());
2014 ASSERT_NO_FATAL_FAILURE(InitViewport());
2015
Tony Barbour6918cd52015-04-09 12:58:51 -06002016 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2017 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2018 VkSamplerObj sampler(m_device);
2019 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002020
Tony Barbour6918cd52015-04-09 12:58:51 -06002021 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002022 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002023 pipelineobj.AddShader(&vs);
2024 pipelineobj.AddShader(&ps);
2025
Tony Barbour6918cd52015-04-09 12:58:51 -06002026 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002027 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002028
Tony Barbour664accc2015-01-09 12:55:14 -07002029 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002030 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002031
Tony Barbourfe3351b2015-07-28 10:17:20 -06002032 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002033
2034#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002035 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002036 pDSDumpDot((char*)"triTest2.dot");
2037#endif
2038 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002039 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07002040
2041 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002042 EndCommandBuffer();
2043 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002044
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002045 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002046}
Tony Barbour6918cd52015-04-09 12:58:51 -06002047TEST_F(VkRenderTest, TexturedTriangleClip)
Tony Barboure2c58df2014-11-25 13:18:32 -07002048{
2049 // The expected result from this test is a red and green checkered triangle
2050 static const char *vertShaderText =
2051 "#version 330\n"
2052 "#extension GL_ARB_separate_shader_objects : enable\n"
2053 "#extension GL_ARB_shading_language_420pack : enable\n"
2054 "layout (location = 0) out vec2 samplePos;\n"
2055 "out gl_PerVertex {\n"
2056 " vec4 gl_Position;\n"
2057 " float gl_ClipDistance[1];\n"
2058 "};\n"
2059 "void main() {\n"
2060 " vec2 vertices[3];"
2061 " vertices[0] = vec2(-0.5, -0.5);\n"
2062 " vertices[1] = vec2( 0.5, -0.5);\n"
2063 " vertices[2] = vec2( 0.5, 0.5);\n"
2064 " vec2 positions[3];"
2065 " positions[0] = vec2( 0.0, 0.0);\n"
2066 " positions[1] = vec2( 1.0, 0.0);\n"
2067 " positions[2] = vec2( 1.0, 1.0);\n"
2068 " float dists[3];\n"
2069 " dists[0] = 1.0;\n"
2070 " dists[1] = 1.0;\n"
2071 " dists[2] = -1.0;\n"
2072 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2073 " samplePos = positions[gl_VertexID % 3];\n"
2074 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2075 "}\n";
2076
2077 static const char *fragShaderText =
2078 "#version 140\n"
2079 "#extension GL_ARB_separate_shader_objects : enable\n"
2080 "#extension GL_ARB_shading_language_420pack : enable\n"
2081 "layout (location = 0) in vec2 samplePos;\n"
2082 "layout (binding = 0) uniform sampler2D surface;\n"
2083 "layout (location=0) out vec4 outColor;\n"
2084 "void main() {\n"
2085 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2086 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2087 " outColor = texColor;\n"
2088 "}\n";
2089
2090
2091 ASSERT_NO_FATAL_FAILURE(InitState());
2092 ASSERT_NO_FATAL_FAILURE(InitViewport());
2093
Tony Barbour6918cd52015-04-09 12:58:51 -06002094 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2095 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2096 VkSamplerObj sampler(m_device);
2097 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002098
Tony Barbour6918cd52015-04-09 12:58:51 -06002099 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002100 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002101 pipelineobj.AddShader(&vs);
2102 pipelineobj.AddShader(&ps);
2103
Tony Barbour6918cd52015-04-09 12:58:51 -06002104 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002105 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002106
Tony Barbour664accc2015-01-09 12:55:14 -07002107 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002108 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002109
Tony Barbourfe3351b2015-07-28 10:17:20 -06002110 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002111
2112#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002113 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002114 pDSDumpDot((char*)"triTest2.dot");
2115#endif
2116 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002117 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07002118
2119 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002120 EndCommandBuffer();
2121 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002122
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002123 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002124}
GregFaae75242015-06-03 18:40:50 -06002125
Tony Barbour6918cd52015-04-09 12:58:51 -06002126TEST_F(VkRenderTest, FSTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07002127{
2128 // The expected result from this test is a red and green checkered triangle
2129 static const char *vertShaderText =
2130 "#version 140\n"
2131 "#extension GL_ARB_separate_shader_objects : enable\n"
2132 "#extension GL_ARB_shading_language_420pack : enable\n"
2133 "layout (location = 0) out vec2 samplePos;\n"
2134 "void main() {\n"
2135 " vec2 vertices[3];"
2136 " vertices[0] = vec2(-0.5, -0.5);\n"
2137 " vertices[1] = vec2( 0.5, -0.5);\n"
2138 " vertices[2] = vec2( 0.5, 0.5);\n"
2139 " vec2 positions[3];"
2140 " positions[0] = vec2( 0.0, 0.0);\n"
2141 " positions[1] = vec2( 1.0, 0.0);\n"
2142 " positions[2] = vec2( 1.0, 1.0);\n"
2143 " samplePos = positions[gl_VertexID % 3];\n"
2144 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2145 "}\n";
2146
2147 static const char *fragShaderText =
2148 "#version 140\n"
2149 "#extension GL_ARB_separate_shader_objects : enable\n"
2150 "#extension GL_ARB_shading_language_420pack : enable\n"
2151 "layout (location = 0) in vec2 samplePos;\n"
2152 "layout (binding = 0) uniform sampler2D surface;\n"
2153 "layout (location=0) out vec4 outColor;\n"
2154 "void main() {\n"
2155 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2156 " outColor = texColor;\n"
2157 "}\n";
2158
2159 ASSERT_NO_FATAL_FAILURE(InitState());
2160 ASSERT_NO_FATAL_FAILURE(InitViewport());
2161
Tony Barbour6918cd52015-04-09 12:58:51 -06002162 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2163 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2164 VkSamplerObj sampler(m_device);
2165 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002166
Tony Barbour6918cd52015-04-09 12:58:51 -06002167 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002168 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002169 pipelineobj.AddShader(&vs);
2170 pipelineobj.AddShader(&ps);
2171
Tony Barbour6918cd52015-04-09 12:58:51 -06002172 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002173 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002174
Tony Barbour664accc2015-01-09 12:55:14 -07002175 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002176 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002177
Tony Barbourfe3351b2015-07-28 10:17:20 -06002178 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002179
2180#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002181 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002182 pDSDumpDot((char*)"triTest2.dot");
2183#endif
2184 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002185 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07002186
2187 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002188 EndCommandBuffer();
2189 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002190
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002191 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002192}
Tony Barbour6918cd52015-04-09 12:58:51 -06002193TEST_F(VkRenderTest, SamplerBindingsTriangle)
Tony Barboure2c58df2014-11-25 13:18:32 -07002194{
2195 // This test sets bindings on the samplers
2196 // For now we are asserting that sampler and texture pairs
2197 // march in lock step, and are set via GLSL binding. This can
2198 // and will probably change.
2199 // The sampler bindings should match the sampler and texture slot
2200 // number set up by the application.
2201 // This test will result in a blue triangle
2202 static const char *vertShaderText =
2203 "#version 140\n"
2204 "#extension GL_ARB_separate_shader_objects : enable\n"
2205 "#extension GL_ARB_shading_language_420pack : enable\n"
2206 "layout (location = 0) out vec4 samplePos;\n"
2207 "void main() {\n"
2208 " vec2 vertices[3];"
2209 " vertices[0] = vec2(-0.5, -0.5);\n"
2210 " vertices[1] = vec2( 0.5, -0.5);\n"
2211 " vertices[2] = vec2( 0.5, 0.5);\n"
2212 " vec2 positions[3];"
2213 " positions[0] = vec2( 0.0, 0.0);\n"
2214 " positions[1] = vec2( 1.0, 0.0);\n"
2215 " positions[2] = vec2( 1.0, 1.0);\n"
2216 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2217 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2218 "}\n";
2219
2220 static const char *fragShaderText =
2221 "#version 140\n"
2222 "#extension GL_ARB_separate_shader_objects : enable\n"
2223 "#extension GL_ARB_shading_language_420pack : enable\n"
2224 "layout (location = 0) in vec4 samplePos;\n"
2225 "layout (binding = 0) uniform sampler2D surface0;\n"
2226 "layout (binding = 1) uniform sampler2D surface1;\n"
2227 "layout (binding = 12) uniform sampler2D surface2;\n"
GregFaae75242015-06-03 18:40:50 -06002228 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002229 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06002230 " outColor = textureLod(surface2, samplePos.xy, 0.0);\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002231 "}\n";
2232
2233 ASSERT_NO_FATAL_FAILURE(InitState());
2234 ASSERT_NO_FATAL_FAILURE(InitViewport());
2235
Tony Barbour6918cd52015-04-09 12:58:51 -06002236 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2237 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002238
Tony Barbour6918cd52015-04-09 12:58:51 -06002239 VkSamplerObj sampler1(m_device);
2240 VkSamplerObj sampler2(m_device);
2241 VkSamplerObj sampler3(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002242
Tony Barbourebc093f2015-04-01 16:38:10 -06002243 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
Tony Barbour6918cd52015-04-09 12:58:51 -06002244 VkTextureObj texture1(m_device, tex_colors); // Red
Tony Barbourebc093f2015-04-01 16:38:10 -06002245 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
Tony Barbour6918cd52015-04-09 12:58:51 -06002246 VkTextureObj texture2(m_device, tex_colors); // Green
Tony Barbourebc093f2015-04-01 16:38:10 -06002247 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
Tony Barbour6918cd52015-04-09 12:58:51 -06002248 VkTextureObj texture3(m_device, tex_colors); // Blue
Tony Barboure2c58df2014-11-25 13:18:32 -07002249
Tony Barbour6918cd52015-04-09 12:58:51 -06002250 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002251 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002252 pipelineobj.AddShader(&vs);
2253 pipelineobj.AddShader(&ps);
2254
Tony Barbour6918cd52015-04-09 12:58:51 -06002255 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002256 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2257 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2258 for (int i = 0; i < 10; i++)
2259 descriptorSet.AppendDummy();
2260 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barboure2c58df2014-11-25 13:18:32 -07002261
Tony Barbour664accc2015-01-09 12:55:14 -07002262 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002263 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002264
Tony Barbourfe3351b2015-07-28 10:17:20 -06002265 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002266
2267#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002268 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002269 pDSDumpDot((char*)"triTest2.dot");
2270#endif
2271 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002272 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07002273
2274 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002275 EndCommandBuffer();
2276 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002277
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002278 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002279}
2280
Tony Barbour6918cd52015-04-09 12:58:51 -06002281TEST_F(VkRenderTest, TriangleVSUniformBlock)
Tony Barboure2c58df2014-11-25 13:18:32 -07002282{
2283 // The expected result from this test is a blue triangle
2284
2285 static const char *vertShaderText =
2286 "#version 140\n"
2287 "#extension GL_ARB_separate_shader_objects : enable\n"
2288 "#extension GL_ARB_shading_language_420pack : enable\n"
2289 "layout (location = 0) out vec4 outColor;\n"
2290 "layout (std140, binding = 0) uniform bufferVals {\n"
2291 " vec4 red;\n"
2292 " vec4 green;\n"
2293 " vec4 blue;\n"
2294 " vec4 white;\n"
2295 "} myBufferVals;\n"
2296 "void main() {\n"
2297 " vec2 vertices[3];"
2298 " vertices[0] = vec2(-0.5, -0.5);\n"
2299 " vertices[1] = vec2( 0.5, -0.5);\n"
2300 " vertices[2] = vec2( 0.5, 0.5);\n"
2301 " outColor = myBufferVals.blue;\n"
2302 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2303 "}\n";
2304
2305 static const char *fragShaderText =
2306 "#version 140\n"
2307 "#extension GL_ARB_separate_shader_objects : enable\n"
2308 "#extension GL_ARB_shading_language_420pack : enable\n"
2309 "layout (location = 0) in vec4 inColor;\n"
GregFaae75242015-06-03 18:40:50 -06002310 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002311 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06002312 " outColor = inColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002313 "}\n";
2314
2315 ASSERT_NO_FATAL_FAILURE(InitState());
2316 ASSERT_NO_FATAL_FAILURE(InitViewport());
2317
Tony Barbour6918cd52015-04-09 12:58:51 -06002318 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2319 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002320
2321 // Let's populate our buffer with the following:
2322 // vec4 red;
2323 // vec4 green;
2324 // vec4 blue;
2325 // vec4 white;
2326 const int valCount = 4 * 4;
2327 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2328 0.0, 1.0, 0.0, 1.0,
2329 0.0, 0.0, 1.0, 1.0,
2330 1.0, 1.0, 1.0, 1.0 };
2331
Tony Barbour6918cd52015-04-09 12:58:51 -06002332 VkConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002333
Tony Barbour6918cd52015-04-09 12:58:51 -06002334 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002335 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002336 pipelineobj.AddShader(&vs);
2337 pipelineobj.AddShader(&ps);
2338
Tony Barbour6918cd52015-04-09 12:58:51 -06002339 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002340 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, colorBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002341
Tony Barbour664accc2015-01-09 12:55:14 -07002342 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002343 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002344
Tony Barbourfe3351b2015-07-28 10:17:20 -06002345 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002346
2347#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002348 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002349 pDSDumpDot((char*)"triTest2.dot");
2350#endif
2351 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002352 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07002353
2354 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002355 EndCommandBuffer();
2356 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002357
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002358 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002359}
2360
Tony Barbour6918cd52015-04-09 12:58:51 -06002361TEST_F(VkRenderTest, TriangleFSUniformBlockBinding)
Tony Barboure2c58df2014-11-25 13:18:32 -07002362{
2363 // This test allows the shader to select which buffer it is
2364 // pulling from using layout binding qualifier.
2365 // There are corresponding changes in the compiler stack that
2366 // will select the buffer using binding directly.
2367 // The binding number should match the slot number set up by
2368 // the application.
2369 // The expected result from this test is a purple triangle
2370
2371 static const char *vertShaderText =
2372 "#version 140\n"
2373 "#extension GL_ARB_separate_shader_objects : enable\n"
2374 "#extension GL_ARB_shading_language_420pack : enable\n"
2375 "void main() {\n"
2376 " vec2 vertices[3];"
2377 " vertices[0] = vec2(-0.5, -0.5);\n"
2378 " vertices[1] = vec2( 0.5, -0.5);\n"
2379 " vertices[2] = vec2( 0.5, 0.5);\n"
2380 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2381 "}\n";
2382
2383 static const char *fragShaderText =
2384 "#version 140\n"
2385 "#extension GL_ARB_separate_shader_objects : enable\n"
2386 "#extension GL_ARB_shading_language_420pack : enable\n"
2387 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2388 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2389 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wu11078b02015-01-04 16:27:24 +08002390 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
GregFaae75242015-06-03 18:40:50 -06002391 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002392 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06002393 " outColor = myBlueVal.color;\n"
2394 " outColor += myRedVal.color;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002395 "}\n";
2396
2397 ASSERT_NO_FATAL_FAILURE(InitState());
2398 ASSERT_NO_FATAL_FAILURE(InitViewport());
2399
Tony Barbour6918cd52015-04-09 12:58:51 -06002400 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2401 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002402
2403 // We're going to create a number of uniform buffers, and then allow
2404 // the shader to select which it wants to read from with a binding
2405
2406 // Let's populate the buffers with a single color each:
2407 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2408 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2409 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wu11078b02015-01-04 16:27:24 +08002410 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barboure2c58df2014-11-25 13:18:32 -07002411
2412 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2413 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2414 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2415 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2416
2417 const int redCount = sizeof(redVals) / sizeof(float);
2418 const int greenCount = sizeof(greenVals) / sizeof(float);
2419 const int blueCount = sizeof(blueVals) / sizeof(float);
2420 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2421
Tony Barbour6918cd52015-04-09 12:58:51 -06002422 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002423
Tony Barbour6918cd52015-04-09 12:58:51 -06002424 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002425
Tony Barbour6918cd52015-04-09 12:58:51 -06002426 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002427
Tony Barbour6918cd52015-04-09 12:58:51 -06002428 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002429
Tony Barbour6918cd52015-04-09 12:58:51 -06002430 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002431 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002432 pipelineobj.AddShader(&vs);
2433 pipelineobj.AddShader(&ps);
2434
Tony Barbour6918cd52015-04-09 12:58:51 -06002435 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002436 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2437 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2438 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2439 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002440
Tony Barbour664accc2015-01-09 12:55:14 -07002441 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002442 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure2c58df2014-11-25 13:18:32 -07002443
Tony Barbourfe3351b2015-07-28 10:17:20 -06002444 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002445
2446#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002447 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002448 pDSDumpDot((char*)"triTest2.dot");
2449#endif
2450 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002451 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07002452
2453 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002454 EndCommandBuffer();
2455 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002456
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002457 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002458}
2459
Tony Barbour6918cd52015-04-09 12:58:51 -06002460TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBinding)
Tony Barboure2c58df2014-11-25 13:18:32 -07002461{
2462 // This test is the same as TriangleFSUniformBlockBinding, but
2463 // it does not provide an instance name.
2464 // The expected result from this test is a purple triangle
2465
2466 static const char *vertShaderText =
2467 "#version 140\n"
2468 "#extension GL_ARB_separate_shader_objects : enable\n"
2469 "#extension GL_ARB_shading_language_420pack : enable\n"
2470 "void main() {\n"
2471 " vec2 vertices[3];"
2472 " vertices[0] = vec2(-0.5, -0.5);\n"
2473 " vertices[1] = vec2( 0.5, -0.5);\n"
2474 " vertices[2] = vec2( 0.5, 0.5);\n"
2475 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2476 "}\n";
2477
2478 static const char *fragShaderText =
2479 "#version 430\n"
2480 "#extension GL_ARB_separate_shader_objects : enable\n"
2481 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002482 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2483 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2484 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wu11078b02015-01-04 16:27:24 +08002485 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northropd43c52e2014-12-05 15:44:14 -07002486 "layout (location = 0) out vec4 outColor;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002487 "void main() {\n"
Cody Northropd43c52e2014-12-05 15:44:14 -07002488 " outColor = blue;\n"
2489 " outColor += red;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002490 "}\n";
2491 ASSERT_NO_FATAL_FAILURE(InitState());
2492 ASSERT_NO_FATAL_FAILURE(InitViewport());
2493
Tony Barbour6918cd52015-04-09 12:58:51 -06002494 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2495 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barboure2c58df2014-11-25 13:18:32 -07002496
2497 // We're going to create a number of uniform buffers, and then allow
2498 // the shader to select which it wants to read from with a binding
2499
2500 // Let's populate the buffers with a single color each:
2501 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2502 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2503 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2504 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2505
2506 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2507 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2508 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2509 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2510
2511 const int redCount = sizeof(redVals) / sizeof(float);
2512 const int greenCount = sizeof(greenVals) / sizeof(float);
2513 const int blueCount = sizeof(blueVals) / sizeof(float);
2514 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2515
Tony Barbour6918cd52015-04-09 12:58:51 -06002516 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002517
Tony Barbour6918cd52015-04-09 12:58:51 -06002518 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002519
Tony Barbour6918cd52015-04-09 12:58:51 -06002520 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002521
Tony Barbour6918cd52015-04-09 12:58:51 -06002522 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barboure2c58df2014-11-25 13:18:32 -07002523
Tony Barbour6918cd52015-04-09 12:58:51 -06002524 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002525 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002526 pipelineobj.AddShader(&vs);
2527 pipelineobj.AddShader(&ps);
2528
Tony Barbour6918cd52015-04-09 12:58:51 -06002529 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002530 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2531 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2532 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2533 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002534
Tony Barbour664accc2015-01-09 12:55:14 -07002535 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002536 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbour664accc2015-01-09 12:55:14 -07002537
Tony Barbourfe3351b2015-07-28 10:17:20 -06002538 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002539
2540#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002541 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002542 pDSDumpDot((char*)"triTest2.dot");
2543#endif
2544 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002545 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07002546
2547 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002548 EndCommandBuffer();
2549 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002550
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002551 RecordImages(m_renderTargets);
Tony Barboure2c58df2014-11-25 13:18:32 -07002552}
2553
GregF6084aec2015-07-01 16:11:09 -06002554TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBindingWithStruct)
2555{
2556 // This test is the same as TriangleFSUniformBlockBinding, but
2557 // it does not provide an instance name.
2558 // The expected result from this test is a purple triangle
2559
2560 static const char *vertShaderText =
2561 "#version 140\n"
2562 "#extension GL_ARB_separate_shader_objects : enable\n"
2563 "#extension GL_ARB_shading_language_420pack : enable\n"
2564 "void main() {\n"
2565 " vec2 vertices[3];"
2566 " vertices[0] = vec2(-0.5, -0.5);\n"
2567 " vertices[1] = vec2( 0.5, -0.5);\n"
2568 " vertices[2] = vec2( 0.5, 0.5);\n"
2569 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2570 "}\n";
2571
2572 static const char *fragShaderText =
2573 "#version 430\n"
2574 "#extension GL_ARB_separate_shader_objects : enable\n"
2575 "#extension GL_ARB_shading_language_420pack : enable\n"
2576 "\n"
2577 " struct PS_INPUT {\n"
2578 " vec2 member0;\n"
2579 " vec4 member1;\n"
2580 " vec4 member2;\n"
2581 " vec4 member3;\n"
2582 " vec4 member4;\n"
2583 " vec4 member5;\n"
2584 " vec4 member6;\n"
2585 " vec4 member7;\n"
2586 " vec4 member8;\n"
2587 " vec4 member9;\n"
2588 " };\n"
2589 "\n"
2590 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2591 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2592 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2593 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
2594 "layout (location = 0) out vec4 outColor;\n"
2595 "PS_INPUT MainFs()\n"
2596 "{\n"
2597 " PS_INPUT o;\n"
2598 " o.member9 = red;\n"
2599 " return o;\n"
2600 "}\n"
2601 "\n"
2602 "void main()\n"
2603 "{\n"
2604 " PS_INPUT o;\n"
2605 " o = MainFs();\n"
2606 " outColor = blue;"
2607 " outColor += o.member9;\n"
2608 "}\n";;
2609 ASSERT_NO_FATAL_FAILURE(InitState());
2610 ASSERT_NO_FATAL_FAILURE(InitViewport());
2611
2612 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2613 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2614
2615 // We're going to create a number of uniform buffers, and then allow
2616 // the shader to select which it wants to read from with a binding
2617
2618 // Let's populate the buffers with a single color each:
2619 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2620 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2621 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2622 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2623
2624 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2625 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2626 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2627 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2628
2629 const int redCount = sizeof(redVals) / sizeof(float);
2630 const int greenCount = sizeof(greenVals) / sizeof(float);
2631 const int blueCount = sizeof(blueVals) / sizeof(float);
2632 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2633
2634 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2635
2636 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2637
2638 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2639
2640 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
2641
2642 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002643 pipelineobj.AddColorAttachment();
GregF6084aec2015-07-01 16:11:09 -06002644 pipelineobj.AddShader(&vs);
2645 pipelineobj.AddShader(&ps);
2646
2647 VkDescriptorSetObj descriptorSet(m_device);
2648 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2649 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2650 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2651 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
2652
2653 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002654 ASSERT_VK_SUCCESS(BeginCommandBuffer());
GregF6084aec2015-07-01 16:11:09 -06002655
Tony Barbourfe3351b2015-07-28 10:17:20 -06002656 GenericDrawPreparation(pipelineobj, descriptorSet);
GregF6084aec2015-07-01 16:11:09 -06002657
2658#ifdef DUMP_STATE_DOT
2659 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
2660 pDSDumpDot((char*)"triTest2.dot");
2661#endif
2662 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002663 Draw(0, 3, 0, 1);
GregF6084aec2015-07-01 16:11:09 -06002664
2665 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002666 EndCommandBuffer();
2667 QueueCommandBuffer();
GregF6084aec2015-07-01 16:11:09 -06002668
2669 RecordImages(m_renderTargets);
2670}
2671
Tony Barbour6918cd52015-04-09 12:58:51 -06002672TEST_F(VkRenderTest, CubeWithVertexFetchAndMVPAndTexture)
Tony Barboure2c58df2014-11-25 13:18:32 -07002673{
2674 static const char *vertShaderText =
2675 "#version 140\n"
2676 "#extension GL_ARB_separate_shader_objects : enable\n"
2677 "#extension GL_ARB_shading_language_420pack : enable\n"
2678 "layout (std140, binding=0) uniform bufferVals {\n"
2679 " mat4 mvp;\n"
2680 "} myBufferVals;\n"
2681 "layout (location=0) in vec4 pos;\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002682 "layout (location=1) in vec2 input_uv;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002683 "layout (location=0) out vec2 UV;\n"
2684 "void main() {\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002685 " UV = input_uv;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002686 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002687 " gl_Position.y = -gl_Position.y;\n"
2688 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002689 "}\n";
2690
2691 static const char *fragShaderText =
2692 "#version 140\n"
2693 "#extension GL_ARB_separate_shader_objects : enable\n"
2694 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wu11078b02015-01-04 16:27:24 +08002695 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barboure2c58df2014-11-25 13:18:32 -07002696 "layout (location=0) out vec4 outColor;\n"
2697 "layout (location=0) in vec2 UV;\n"
2698 "void main() {\n"
2699 " outColor= textureLod(surface, UV, 0.0);\n"
2700 "}\n";
2701 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2702
2703 glm::mat4 View = glm::lookAt(
2704 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2705 glm::vec3(0,0,0), // and looks at the origin
2706 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2707 );
2708
2709 glm::mat4 Model = glm::mat4(1.0f);
2710
2711 glm::mat4 MVP = Projection * View * Model;
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002712 int num_verts = sizeof(g_vb_texture_Data) / sizeof(g_vb_texture_Data[0]);
Tony Barboure2c58df2014-11-25 13:18:32 -07002713
2714
2715 ASSERT_NO_FATAL_FAILURE(InitState());
2716 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wub4052042015-07-09 10:16:34 +08002717 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Chia-I Wu08accc62015-07-07 11:50:03 +08002718 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height, m_depth_stencil_fmt);
Tony Barboure2c58df2014-11-25 13:18:32 -07002719
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002720 VkConstantBufferObj meshBuffer(m_device, num_verts,
2721 sizeof(g_vb_texture_Data[0]), g_vb_texture_Data);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00002722 meshBuffer.BufferMemoryBarrier();
Tony Barboure2c58df2014-11-25 13:18:32 -07002723
Mark Lobodzinski17caf572015-01-29 08:55:56 -06002724 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barboure2c58df2014-11-25 13:18:32 -07002725
Tony Barbour6918cd52015-04-09 12:58:51 -06002726 VkConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2727 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2728 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2729 VkSamplerObj sampler(m_device);
2730 VkTextureObj texture(m_device);
Tony Barboure2c58df2014-11-25 13:18:32 -07002731
Tony Barbour6918cd52015-04-09 12:58:51 -06002732 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002733 pipelineobj.AddColorAttachment();
Tony Barboure2c58df2014-11-25 13:18:32 -07002734 pipelineobj.AddShader(&vs);
2735 pipelineobj.AddShader(&ps);
2736
Tony Barbour6918cd52015-04-09 12:58:51 -06002737 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002738 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mvpBuffer);
Chia-I Wu11078b02015-01-04 16:27:24 +08002739 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barboure2c58df2014-11-25 13:18:32 -07002740
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002741#define MESH_BIND_ID 0
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002742 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002743 MESH_BIND_ID, // binding ID
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002744 sizeof(g_vb_texture_Data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002745 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002746 };
Tony Barboure2c58df2014-11-25 13:18:32 -07002747
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002748 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002749 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2750 vi_attribs[0].location = 0; // location
Tony Barbourd1c35722015-04-16 15:59:00 -06002751 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06002752 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2753 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2754 vi_attribs[1].location = 1; // location
2755 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
2756 vi_attribs[1].offsetInBytes = 16; // Offset of uv components
Tony Barboure2c58df2014-11-25 13:18:32 -07002757
Tony Barboure2c58df2014-11-25 13:18:32 -07002758 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchter0d625272015-03-31 16:36:30 -06002759 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2760 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barboure2c58df2014-11-25 13:18:32 -07002761
Tony Barbourdd6e32e2015-07-10 15:29:03 -06002762 VkPipelineDepthStencilStateCreateInfo ds_state;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002763 ds_state.depthTestEnable = VK_TRUE;
2764 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbourd1c35722015-04-16 15:59:00 -06002765 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002766 ds_state.depthBoundsEnable = VK_FALSE;
2767 ds_state.stencilTestEnable = VK_FALSE;
2768 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
2769 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
2770 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbourd1c35722015-04-16 15:59:00 -06002771 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
Tony Barbourf52346d2015-01-16 14:27:35 -07002772 ds_state.front = ds_state.back;
2773 pipelineobj.SetDepthStencil(&ds_state);
2774
Tony Barbour1c45ce02015-03-27 17:03:18 -06002775 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbourfe3351b2015-07-28 10:17:20 -06002776 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure2c58df2014-11-25 13:18:32 -07002777
Tony Barbourfe3351b2015-07-28 10:17:20 -06002778 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002779
Tony Barbourfe3351b2015-07-28 10:17:20 -06002780 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour664accc2015-01-09 12:55:14 -07002781#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002782 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002783 pDSDumpDot((char*)"triTest2.dot");
2784#endif
2785 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002786 Draw(0, num_verts, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07002787
2788 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002789 EndCommandBuffer();
2790 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002791
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002792 RecordImages(m_renderTargets);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002793 RotateTriangleVSUniform(Projection, View, Model, &mvpBuffer);
Tony Barboure2c58df2014-11-25 13:18:32 -07002794}
Cody Northropf1990a92014-12-09 11:17:01 -07002795
Tony Barbour6918cd52015-04-09 12:58:51 -06002796TEST_F(VkRenderTest, TriangleMixedSamplerUniformBlockBinding)
Cody Northropf1990a92014-12-09 11:17:01 -07002797{
2798 // This test mixes binding slots of textures and buffers, ensuring
2799 // that sparse and overlapping assignments work.
Cody Northropb110b4f2014-12-09 13:59:39 -07002800 // The expected result from this test is a purple triangle, although
Cody Northropf1990a92014-12-09 11:17:01 -07002801 // you can modify it to move the desired result around.
2802
2803 static const char *vertShaderText =
2804 "#version 140\n"
2805 "#extension GL_ARB_separate_shader_objects : enable\n"
2806 "#extension GL_ARB_shading_language_420pack : enable\n"
2807 "void main() {\n"
2808 " vec2 vertices[3];"
2809 " vertices[0] = vec2(-0.5, -0.5);\n"
2810 " vertices[1] = vec2( 0.5, -0.5);\n"
2811 " vertices[2] = vec2( 0.5, 0.5);\n"
2812 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2813 "}\n";
2814
2815 static const char *fragShaderText =
2816 "#version 430\n"
2817 "#extension GL_ARB_separate_shader_objects : enable\n"
2818 "#extension GL_ARB_shading_language_420pack : enable\n"
2819 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wu11078b02015-01-04 16:27:24 +08002820 "layout (binding = 3) uniform sampler2D surface1;\n"
2821 "layout (binding = 1) uniform sampler2D surface2;\n"
2822 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002823
Cody Northropb110b4f2014-12-09 13:59:39 -07002824
Chia-I Wu11078b02015-01-04 16:27:24 +08002825 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2826 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2827 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2828 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropf1990a92014-12-09 11:17:01 -07002829 "layout (location = 0) out vec4 outColor;\n"
2830 "void main() {\n"
Cody Northropb110b4f2014-12-09 13:59:39 -07002831 " outColor = red * vec4(0.00001);\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002832 " outColor += white * vec4(0.00001);\n"
2833 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropb110b4f2014-12-09 13:59:39 -07002834 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropf1990a92014-12-09 11:17:01 -07002835 "}\n";
2836 ASSERT_NO_FATAL_FAILURE(InitState());
2837 ASSERT_NO_FATAL_FAILURE(InitViewport());
2838
Tony Barbour6918cd52015-04-09 12:58:51 -06002839 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2840 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northropf1990a92014-12-09 11:17:01 -07002841
Cody Northropf1990a92014-12-09 11:17:01 -07002842 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2843 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2844 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2845 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2846
2847 const int redCount = sizeof(redVals) / sizeof(float);
2848 const int greenCount = sizeof(greenVals) / sizeof(float);
2849 const int blueCount = sizeof(blueVals) / sizeof(float);
2850 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2851
Tony Barbour6918cd52015-04-09 12:58:51 -06002852 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2853 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2854 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2855 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropf1990a92014-12-09 11:17:01 -07002856
Tony Barbourebc093f2015-04-01 16:38:10 -06002857 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour6918cd52015-04-09 12:58:51 -06002858 VkSamplerObj sampler0(m_device);
2859 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbourebc093f2015-04-01 16:38:10 -06002860 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour6918cd52015-04-09 12:58:51 -06002861 VkSamplerObj sampler2(m_device);
2862 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbourebc093f2015-04-01 16:38:10 -06002863 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour6918cd52015-04-09 12:58:51 -06002864 VkSamplerObj sampler4(m_device);
2865 VkTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropb110b4f2014-12-09 13:59:39 -07002866
2867 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2868 // TODO: Get back here ASAP and understand why.
Tony Barbourebc093f2015-04-01 16:38:10 -06002869 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour6918cd52015-04-09 12:58:51 -06002870 VkSamplerObj sampler7(m_device);
2871 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropf1990a92014-12-09 11:17:01 -07002872
Tony Barbour6918cd52015-04-09 12:58:51 -06002873 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002874 pipelineobj.AddColorAttachment();
Cody Northropf1990a92014-12-09 11:17:01 -07002875 pipelineobj.AddShader(&vs);
2876 pipelineobj.AddShader(&ps);
2877
Tony Barbour6918cd52015-04-09 12:58:51 -06002878 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002879 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2880 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2881 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2882 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002883 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
Chia-I Wu11078b02015-01-04 16:27:24 +08002884 // swap blue and green
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002885 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2886 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2887 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropf1990a92014-12-09 11:17:01 -07002888
Tony Barbour664accc2015-01-09 12:55:14 -07002889 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002890 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropf1990a92014-12-09 11:17:01 -07002891
Tony Barbourfe3351b2015-07-28 10:17:20 -06002892 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002893
2894#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002895 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07002896 pDSDumpDot((char*)"triTest2.dot");
2897#endif
2898 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06002899 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07002900
2901 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06002902 EndCommandBuffer();
2903 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07002904
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06002905 RecordImages(m_renderTargets);
Cody Northropf1990a92014-12-09 11:17:01 -07002906}
2907
Tony Barbour6918cd52015-04-09 12:58:51 -06002908TEST_F(VkRenderTest, TriangleMatchingSamplerUniformBlockBinding)
Cody Northropbd531de2014-12-09 19:08:54 -07002909{
2910 // This test matches binding slots of textures and buffers, requiring
2911 // the driver to give them distinct number spaces.
2912 // The expected result from this test is a red triangle, although
2913 // you can modify it to move the desired result around.
2914
2915 static const char *vertShaderText =
2916 "#version 140\n"
2917 "#extension GL_ARB_separate_shader_objects : enable\n"
2918 "#extension GL_ARB_shading_language_420pack : enable\n"
2919 "void main() {\n"
2920 " vec2 vertices[3];"
2921 " vertices[0] = vec2(-0.5, -0.5);\n"
2922 " vertices[1] = vec2( 0.5, -0.5);\n"
2923 " vertices[2] = vec2( 0.5, 0.5);\n"
2924 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2925 "}\n";
2926
2927 static const char *fragShaderText =
2928 "#version 430\n"
2929 "#extension GL_ARB_separate_shader_objects : enable\n"
2930 "#extension GL_ARB_shading_language_420pack : enable\n"
2931 "layout (binding = 0) uniform sampler2D surface0;\n"
2932 "layout (binding = 1) uniform sampler2D surface1;\n"
2933 "layout (binding = 2) uniform sampler2D surface2;\n"
2934 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wu11078b02015-01-04 16:27:24 +08002935 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2936 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2937 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2938 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropbd531de2014-12-09 19:08:54 -07002939 "layout (location = 0) out vec4 outColor;\n"
2940 "void main() {\n"
2941 " outColor = red;// * vec4(0.00001);\n"
2942 " outColor += white * vec4(0.00001);\n"
2943 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2944 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2945 "}\n";
2946 ASSERT_NO_FATAL_FAILURE(InitState());
2947 ASSERT_NO_FATAL_FAILURE(InitViewport());
2948
Tony Barbour6918cd52015-04-09 12:58:51 -06002949 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2950 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northropbd531de2014-12-09 19:08:54 -07002951
2952 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2953 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2954 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2955 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2956
2957 const int redCount = sizeof(redVals) / sizeof(float);
2958 const int greenCount = sizeof(greenVals) / sizeof(float);
2959 const int blueCount = sizeof(blueVals) / sizeof(float);
2960 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2961
Tony Barbour6918cd52015-04-09 12:58:51 -06002962 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2963 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2964 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2965 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropbd531de2014-12-09 19:08:54 -07002966
Tony Barbourebc093f2015-04-01 16:38:10 -06002967 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour6918cd52015-04-09 12:58:51 -06002968 VkSamplerObj sampler0(m_device);
2969 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbourebc093f2015-04-01 16:38:10 -06002970 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour6918cd52015-04-09 12:58:51 -06002971 VkSamplerObj sampler2(m_device);
2972 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbourebc093f2015-04-01 16:38:10 -06002973 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour6918cd52015-04-09 12:58:51 -06002974 VkSamplerObj sampler4(m_device);
2975 VkTextureObj texture4(m_device, tex_colors); // Light Green
Tony Barbourebc093f2015-04-01 16:38:10 -06002976 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour6918cd52015-04-09 12:58:51 -06002977 VkSamplerObj sampler7(m_device);
2978 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropbd531de2014-12-09 19:08:54 -07002979
Tony Barbour6918cd52015-04-09 12:58:51 -06002980 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08002981 pipelineobj.AddColorAttachment();
Cody Northropbd531de2014-12-09 19:08:54 -07002982 pipelineobj.AddShader(&vs);
2983 pipelineobj.AddShader(&ps);
2984
Tony Barbour6918cd52015-04-09 12:58:51 -06002985 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu11078b02015-01-04 16:27:24 +08002986 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2987 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2988 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2989 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002990 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2991 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2992 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2993 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropbd531de2014-12-09 19:08:54 -07002994
Tony Barbour664accc2015-01-09 12:55:14 -07002995 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06002996 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropbd531de2014-12-09 19:08:54 -07002997
Tony Barbourfe3351b2015-07-28 10:17:20 -06002998 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour664accc2015-01-09 12:55:14 -07002999
3000#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003001 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour664accc2015-01-09 12:55:14 -07003002 pDSDumpDot((char*)"triTest2.dot");
3003#endif
3004 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06003005 Draw(0, 3, 0, 1);
Tony Barbour664accc2015-01-09 12:55:14 -07003006
3007 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003008 EndCommandBuffer();
3009 QueueCommandBuffer();
Tony Barbour664accc2015-01-09 12:55:14 -07003010
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06003011 RecordImages(m_renderTargets);
Cody Northropbd531de2014-12-09 19:08:54 -07003012}
3013
Tony Barbour6918cd52015-04-09 12:58:51 -06003014TEST_F(VkRenderTest, TriangleUniformBufferLayout)
Cody Northrop04ad1202014-12-17 15:26:33 -07003015{
3016 // This test populates a buffer with a variety of different data
3017 // types, then reads them out with a shader.
3018 // The expected result from this test is a green triangle
3019
3020 static const char *vertShaderText =
3021 "#version 140\n"
3022 "#extension GL_ARB_separate_shader_objects : enable\n"
3023 "#extension GL_ARB_shading_language_420pack : enable\n"
3024 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3025 " vec4 fRed;\n"
3026 " vec4 fGreen;\n"
3027 " layout(row_major) mat4 worldToProj;\n"
3028 " layout(row_major) mat4 projToWorld;\n"
3029 " layout(row_major) mat4 worldToView;\n"
3030 " layout(row_major) mat4 viewToProj;\n"
3031 " layout(row_major) mat4 worldToShadow[4];\n"
3032 " float fZero;\n"
3033 " float fOne;\n"
3034 " float fTwo;\n"
3035 " float fThree;\n"
3036 " vec3 fZeroZeroZero;\n"
3037 " float fFour;\n"
3038 " vec3 fZeroZeroOne;\n"
3039 " float fFive;\n"
3040 " vec3 fZeroOneZero;\n"
3041 " float fSix;\n"
3042 " float fSeven;\n"
3043 " float fEight;\n"
3044 " float fNine;\n"
3045 " vec2 fZeroZero;\n"
3046 " vec2 fZeroOne;\n"
3047 " vec4 fBlue;\n"
3048 " vec2 fOneZero;\n"
3049 " vec2 fOneOne;\n"
3050 " vec3 fZeroOneOne;\n"
3051 " float fTen;\n"
3052 " float fEleven;\n"
3053 " float fTwelve;\n"
3054 " vec3 fOneZeroZero;\n"
3055 " vec4 uvOffsets[4];\n"
3056 "};\n"
3057 "layout (location = 0) out vec4 color;"
3058 "void main() {\n"
3059
3060 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3061 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3062 " \n"
3063
3064 // do some exact comparisons, even though we should
3065 // really have an epsilon involved.
3066 " vec4 outColor = right;\n"
3067 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3068 " outColor = wrong;\n"
3069 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3070 " outColor = wrong;\n"
3071 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3072 " outColor = wrong;\n"
3073
3074 " color = outColor;\n"
3075
3076 // generic position stuff
3077 " vec2 vertices;\n"
3078 " int vertexSelector = gl_VertexID;\n"
3079 " if (vertexSelector == 0)\n"
3080 " vertices = vec2(-0.5, -0.5);\n"
3081 " else if (vertexSelector == 1)\n"
3082 " vertices = vec2( 0.5, -0.5);\n"
3083 " else if (vertexSelector == 2)\n"
3084 " vertices = vec2( 0.5, 0.5);\n"
3085 " else\n"
3086 " vertices = vec2( 0.0, 0.0);\n"
3087 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3088 "}\n";
3089
3090 static const char *fragShaderText =
3091 "#version 140\n"
3092 "#extension GL_ARB_separate_shader_objects : enable\n"
3093 "#extension GL_ARB_shading_language_420pack : enable\n"
3094 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3095 " vec4 fRed;\n"
3096 " vec4 fGreen;\n"
3097 " layout(row_major) mat4 worldToProj;\n"
3098 " layout(row_major) mat4 projToWorld;\n"
3099 " layout(row_major) mat4 worldToView;\n"
3100 " layout(row_major) mat4 viewToProj;\n"
3101 " layout(row_major) mat4 worldToShadow[4];\n"
3102 " float fZero;\n"
3103 " float fOne;\n"
3104 " float fTwo;\n"
3105 " float fThree;\n"
3106 " vec3 fZeroZeroZero;\n"
3107 " float fFour;\n"
3108 " vec3 fZeroZeroOne;\n"
3109 " float fFive;\n"
3110 " vec3 fZeroOneZero;\n"
3111 " float fSix;\n"
3112 " float fSeven;\n"
3113 " float fEight;\n"
3114 " float fNine;\n"
3115 " vec2 fZeroZero;\n"
3116 " vec2 fZeroOne;\n"
3117 " vec4 fBlue;\n"
3118 " vec2 fOneZero;\n"
3119 " vec2 fOneOne;\n"
3120 " vec3 fZeroOneOne;\n"
3121 " float fTen;\n"
3122 " float fEleven;\n"
3123 " float fTwelve;\n"
3124 " vec3 fOneZeroZero;\n"
3125 " vec4 uvOffsets[4];\n"
3126 "};\n"
3127 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06003128 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop04ad1202014-12-17 15:26:33 -07003129 "void main() {\n"
3130 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3131 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3132 " \n"
3133
3134 // start with VS value to ensure it passed
3135 " vec4 outColor = color;\n"
3136
3137 // do some exact comparisons, even though we should
3138 // really have an epsilon involved.
3139 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3140 " outColor = wrong;\n"
3141 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3142 " outColor = wrong;\n"
3143 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3144 " outColor = wrong;\n"
3145 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3146 " outColor = wrong;\n"
3147 " if (fTwo != 2.0)\n"
3148 " outColor = wrong;\n"
3149 " if (fOneOne != vec2(1.0, 1.0))\n"
3150 " outColor = wrong;\n"
3151 " if (fTen != 10.0)\n"
3152 " outColor = wrong;\n"
3153 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3154 " outColor = wrong;\n"
3155 " \n"
GregFaae75242015-06-03 18:40:50 -06003156 " uFragColor = outColor;\n"
Cody Northrop04ad1202014-12-17 15:26:33 -07003157 "}\n";
3158
3159
Cody Northropd2ad0342015-08-05 11:15:02 -06003160 const float mixedVals[196] = { 1.0f, 0.0f, 0.0f, 1.0f, // vec4 fRed; // align
3161 0.0f, 1.0f, 0.0f, 1.0f, // vec4 fGreen; // align
3162 1.0f, 0.0f, 0.0f, 1.0f, // layout(row_major) mat4 worldToProj;
3163 0.0f, 1.0f, 0.0f, 1.0f, // align
3164 0.0f, 0.0f, 1.0f, 1.0f, // align
3165 0.0f, 0.0f, 0.0f, 1.0f, // align
3166 2.0f, 0.0f, 0.0f, 2.0f, // layout(row_major) mat4 projToWorld;
3167 0.0f, 2.0f, 0.0f, 2.0f, // align
3168 0.0f, 0.0f, 2.0f, 2.0f, // align
3169 0.0f, 0.0f, 0.0f, 2.0f, // align
3170 3.0f, 0.0f, 0.0f, 3.0f, // layout(row_major) mat4 worldToView;
3171 0.0f, 3.0f, 0.0f, 3.0f, // align
3172 0.0f, 0.0f, 3.0f, 3.0f, // align
3173 0.0f, 0.0f, 0.0f, 3.0f, // align
3174 4.0f, 0.0f, 0.0f, 4.0f, // layout(row_major) mat4 viewToProj;
3175 0.0f, 4.0f, 0.0f, 4.0f, // align
3176 0.0f, 0.0f, 4.0f, 4.0f, // align
3177 0.0f, 0.0f, 0.0f, 4.0f, // align
3178 5.0f, 0.0f, 0.0f, 5.0f, // layout(row_major) mat4 worldToShadow[4];
3179 0.0f, 5.0f, 0.0f, 5.0f, // align
3180 0.0f, 0.0f, 5.0f, 5.0f, // align
3181 0.0f, 0.0f, 0.0f, 5.0f, // align
3182 6.0f, 0.0f, 0.0f, 6.0f, // align
3183 0.0f, 6.0f, 0.0f, 6.0f, // align
3184 0.0f, 0.0f, 6.0f, 6.0f, // align
3185 0.0f, 0.0f, 0.0f, 6.0f, // align
3186 7.0f, 0.0f, 0.0f, 7.0f, // align
3187 0.0f, 7.0f, 0.0f, 7.0f, // align
3188 0.0f, 0.0f, 7.0f, 7.0f, // align
3189 0.0f, 0.0f, 0.0f, 7.0f, // align
3190 8.0f, 0.0f, 0.0f, 8.0f, // align
3191 0.0f, 8.0f, 0.0f, 8.0f, // align
3192 0.0f, 0.0f, 8.0f, 8.0f, // align
3193 0.0f, 0.0f, 0.0f, 8.0f, // align
3194 0.0f, // float fZero; // align
3195 1.0f, // float fOne; // pack
3196 2.0f, // float fTwo; // pack
3197 3.0f, // float fThree; // pack
3198 0.0f, 0.0f, 0.0f, // vec3 fZeroZeroZero; // align
3199 4.0f, // float fFour; // pack
3200 0.0f, 0.0f, 1.0f, // vec3 fZeroZeroOne; // align
3201 5.0f, // float fFive; // pack
3202 0.0f, 1.0f, 0.0f, // vec3 fZeroOneZero; // align
3203 6.0f, // float fSix; // pack
3204 7.0f, // float fSeven; // align
3205 8.0f, // float fEight; // pack
3206 9.0f, // float fNine; // pack
3207 0.0f, // BUFFER
3208 0.0f, 0.0f, // vec2 fZeroZero; // align
3209 0.0f, 1.0f, // vec2 fZeroOne; // pack
3210 0.0f, 0.0f, 1.0f, 1.0f, // vec4 fBlue; // align
3211 1.0f, 0.0f, // vec2 fOneZero; // align
3212 1.0f, 1.0f, // vec2 fOneOne; // pack
3213 0.0f, 1.0f, 1.0f, // vec3 fZeroOneOne; // align
3214 10.0f, // float fTen; // pack
3215 11.0f, // float fEleven; // align
3216 12.0f, // float fTwelve; // pack
3217 0.0f, 0.0f, // BUFFER
3218 1.0f, 0.0f, 0.0f, // vec3 fOneZeroZero; // align
3219 0.0f, // BUFFER
3220 0.1f, 0.2f, 0.3f, 0.4f, // vec4 uvOffsets[4];
3221 0.5f, 0.6f, 0.7f, 0.8f, // align
3222 0.9f, 1.0f, 1.1f, 1.2f, // align
3223 1.3f, 1.4f, 1.5f, 1.6f, // align
Cody Northrop04ad1202014-12-17 15:26:33 -07003224 };
3225
3226 ASSERT_NO_FATAL_FAILURE(InitState());
3227 ASSERT_NO_FATAL_FAILURE(InitViewport());
3228
3229 const int constCount = sizeof(mixedVals) / sizeof(float);
3230
Tony Barbour6918cd52015-04-09 12:58:51 -06003231 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3232 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop04ad1202014-12-17 15:26:33 -07003233
Tony Barbour6918cd52015-04-09 12:58:51 -06003234 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop04ad1202014-12-17 15:26:33 -07003235
Tony Barbour6918cd52015-04-09 12:58:51 -06003236 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003237 pipelineobj.AddColorAttachment();
Cody Northrop04ad1202014-12-17 15:26:33 -07003238 pipelineobj.AddShader(&vs);
3239 pipelineobj.AddShader(&ps);
3240
Tony Barbour6918cd52015-04-09 12:58:51 -06003241 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003242 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
Cody Northrop04ad1202014-12-17 15:26:33 -07003243
3244 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003245 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop04ad1202014-12-17 15:26:33 -07003246
Tony Barbourfe3351b2015-07-28 10:17:20 -06003247 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop04ad1202014-12-17 15:26:33 -07003248
3249#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003250 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop04ad1202014-12-17 15:26:33 -07003251 pDSDumpDot((char*)"triTest2.dot");
3252#endif
3253 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06003254 Draw(0, 3, 0, 1);
Cody Northrop04ad1202014-12-17 15:26:33 -07003255
3256 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003257 EndCommandBuffer();
3258 QueueCommandBuffer();
Cody Northrop04ad1202014-12-17 15:26:33 -07003259
Courtney Goeltzenleuchtere5f0e6c2015-04-02 14:17:44 -06003260 RecordImages(m_renderTargets);
Cody Northrop04ad1202014-12-17 15:26:33 -07003261}
3262
Cody Northrop95638152015-05-07 14:39:12 -06003263TEST_F(VkRenderTest, TextureGather)
3264{
3265 // This test introduces textureGather and textureGatherOffset
3266 // Each call is compared against an expected inline color result
3267 // Green triangle means everything worked as expected
3268 // Red means something went wrong
3269
Cody Northropc55900f2015-08-06 13:18:13 -06003270 // disable SPV until texture gather is turned on in glsl->SPV
3271 if (!m_use_glsl) {
3272 printf("Skipping test that requires GLSL path (TextureGather)\n");
3273 return;
3274 }
3275
Cody Northrop50a2a4b2015-06-03 16:49:20 -06003276 ScopedUseGlsl useGlsl(true);
Cody Northrop95638152015-05-07 14:39:12 -06003277
3278 static const char *vertShaderText =
3279 "#version 140\n"
3280 "#extension GL_ARB_separate_shader_objects : enable\n"
3281 "#extension GL_ARB_shading_language_420pack : enable\n"
3282 "void main() {\n"
3283 " vec2 vertices[3];"
3284 " vertices[0] = vec2(-0.5, -0.5);\n"
3285 " vertices[1] = vec2( 0.5, -0.5);\n"
3286 " vertices[2] = vec2( 0.5, 0.5);\n"
3287 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
3288 "}\n";
3289
3290 static const char *fragShaderText =
3291 "#version 430\n"
3292 "#extension GL_ARB_separate_shader_objects : enable\n"
3293 "#extension GL_ARB_shading_language_420pack : enable\n"
3294 "layout (binding = 0) uniform sampler2D surface0;\n"
3295 "layout (binding = 1) uniform sampler2D surface1;\n"
3296 "layout (binding = 2) uniform sampler2D surface2;\n"
3297 "layout (binding = 3) uniform sampler2D surface3;\n"
3298 "layout (location = 0) out vec4 outColor;\n"
3299 "void main() {\n"
3300
3301 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3302 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3303
3304 " vec4 color = right;\n"
3305
3306 // Grab a normal texture sample to ensure it can work in conjuntion
3307 // with textureGather (there are some intracacies in the backend)
3308 " vec4 sampledColor = textureLod(surface2, vec2(0.5), 0.0);\n"
3309 " if (sampledColor != vec4(0.0, 0.0, 1.0, 1.0))\n"
3310 " color = wrong;\n"
3311
3312 " vec4 gatheredColor = textureGather(surface0, vec2(0.5), 0);\n"
3313 // This just grabbed four red components from a red surface
3314 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3315 " color = wrong;\n"
3316
3317 // Yes, this is using an offset of 0, we don't have enough fine grained
3318 // control of the texture contents here.
3319 " gatheredColor = textureGatherOffset(surface1, vec2(0.5), ivec2(0, 0), 1);\n"
3320 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3321 " color = wrong;\n"
3322
3323 " outColor = color;\n"
3324
3325 "}\n";
3326
3327 ASSERT_NO_FATAL_FAILURE(InitState());
3328 ASSERT_NO_FATAL_FAILURE(InitViewport());
3329
3330 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3331 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3332
3333 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
3334 VkSamplerObj sampler0(m_device);
3335 VkTextureObj texture0(m_device, tex_colors); // Red
3336 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
3337 VkSamplerObj sampler1(m_device);
3338 VkTextureObj texture1(m_device, tex_colors); // Green
3339 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
3340 VkSamplerObj sampler2(m_device);
3341 VkTextureObj texture2(m_device, tex_colors); // Blue
3342 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
3343 VkSamplerObj sampler3(m_device);
3344 VkTextureObj texture3(m_device, tex_colors); // Red and Blue
3345
3346 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003347 pipelineobj.AddColorAttachment();
Cody Northrop95638152015-05-07 14:39:12 -06003348 pipelineobj.AddShader(&vs);
3349 pipelineobj.AddShader(&ps);
3350
3351 VkDescriptorSetObj descriptorSet(m_device);
3352 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3353 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
3354 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3355 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
3356
3357 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003358 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop95638152015-05-07 14:39:12 -06003359
Tony Barbourfe3351b2015-07-28 10:17:20 -06003360 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop95638152015-05-07 14:39:12 -06003361
3362 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06003363 Draw(0, 3, 0, 1);
Cody Northrop95638152015-05-07 14:39:12 -06003364
3365 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003366 EndCommandBuffer();
3367 QueueCommandBuffer();
Cody Northrop95638152015-05-07 14:39:12 -06003368
3369 RecordImages(m_renderTargets);
Cody Northrop95638152015-05-07 14:39:12 -06003370}
3371
Cody Northrop475663c2015-04-15 11:19:06 -06003372TEST_F(VkRenderTest, GeometryShaderHelloWorld)
3373{
3374 // This test introduces a geometry shader that simply
3375 // changes the color of each vertex to red, green, blue
3376
3377 static const char *vertShaderText =
3378 "#version 140\n"
3379 "#extension GL_ARB_separate_shader_objects : enable\n"
3380 "#extension GL_ARB_shading_language_420pack : enable\n"
3381 "layout (location = 0) out vec4 color;"
3382 "void main() {\n"
3383
3384 // VS writes out red
3385 " color = vec4(1.0, 0.0, 0.0, 1.0);\n"
3386
3387 // generic position stuff
3388 " vec2 vertices;\n"
3389 " int vertexSelector = gl_VertexID;\n"
3390 " if (vertexSelector == 0)\n"
3391 " vertices = vec2(-0.5, -0.5);\n"
3392 " else if (vertexSelector == 1)\n"
3393 " vertices = vec2( 0.5, -0.5);\n"
3394 " else if (vertexSelector == 2)\n"
3395 " vertices = vec2( 0.5, 0.5);\n"
3396 " else\n"
3397 " vertices = vec2( 0.0, 0.0);\n"
3398 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3399
3400 "}\n";
3401
3402 static const char *geomShaderText =
3403 "#version 330\n"
3404 "#extension GL_ARB_separate_shader_objects : enable\n"
3405 "#extension GL_ARB_shading_language_420pack : enable\n"
3406 "layout( triangles ) in;\n"
3407 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3408 "layout( location = 0 ) in vec4 inColor[3];\n"
3409 "layout( location = 0 ) out vec4 outColor;\n"
3410 "void main()\n"
3411 "{\n"
3412
3413 // first vertex, pass through red
3414 " gl_Position = gl_in[0].gl_Position;\n"
3415 " outColor = inColor[0];\n"
3416 " EmitVertex();\n"
3417
3418 // second vertex, green
3419 " gl_Position = gl_in[1].gl_Position;\n"
3420 " outColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3421 " EmitVertex();\n"
3422
3423 // third vertex, blue
3424 " gl_Position = gl_in[2].gl_Position;\n"
3425 " outColor = vec4(0.0, 0.0, 1.0, 1.0);\n"
3426 " EmitVertex();\n"
3427
3428 // done
3429 " EndPrimitive();\n"
3430 "}\n";
3431
3432
3433 static const char *fragShaderText =
3434 "#version 140\n"
3435 "#extension GL_ARB_separate_shader_objects : enable\n"
3436 "#extension GL_ARB_shading_language_420pack : enable\n"
3437 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06003438 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003439 "void main() {\n"
3440 // pass through
GregFaae75242015-06-03 18:40:50 -06003441 " outColor = color;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003442 "}\n";
3443
3444
3445
3446 ASSERT_NO_FATAL_FAILURE(InitState());
3447 ASSERT_NO_FATAL_FAILURE(InitViewport());
3448
3449 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3450 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3451 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3452
3453 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003454 pipelineobj.AddColorAttachment();
Cody Northrop475663c2015-04-15 11:19:06 -06003455 pipelineobj.AddShader(&vs);
3456 pipelineobj.AddShader(&gs);
3457 pipelineobj.AddShader(&ps);
3458
3459 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003460 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop475663c2015-04-15 11:19:06 -06003461
3462 VkDescriptorSetObj descriptorSet(m_device);
3463
Tony Barbourfe3351b2015-07-28 10:17:20 -06003464 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop475663c2015-04-15 11:19:06 -06003465
3466 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06003467 Draw(0, 3, 0, 1);
Cody Northrop475663c2015-04-15 11:19:06 -06003468
3469 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003470 EndCommandBuffer();
3471 QueueCommandBuffer();
Cody Northrop475663c2015-04-15 11:19:06 -06003472
3473 RecordImages(m_renderTargets);
3474}
3475
3476TEST_F(VkRenderTest, GSUniformBufferLayout)
3477{
3478 // This test is just like TriangleUniformBufferLayout but adds
3479 // geometry as a stage that also does UBO lookups
3480 // The expected result from this test is a green triangle
3481
3482 static const char *vertShaderText =
3483 "#version 140\n"
3484 "#extension GL_ARB_separate_shader_objects : enable\n"
3485 "#extension GL_ARB_shading_language_420pack : enable\n"
3486 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3487 " vec4 fRed;\n"
3488 " vec4 fGreen;\n"
3489 " layout(row_major) mat4 worldToProj;\n"
3490 " layout(row_major) mat4 projToWorld;\n"
3491 " layout(row_major) mat4 worldToView;\n"
3492 " layout(row_major) mat4 viewToProj;\n"
3493 " layout(row_major) mat4 worldToShadow[4];\n"
3494 " float fZero;\n"
3495 " float fOne;\n"
3496 " float fTwo;\n"
3497 " float fThree;\n"
3498 " vec3 fZeroZeroZero;\n"
3499 " float fFour;\n"
3500 " vec3 fZeroZeroOne;\n"
3501 " float fFive;\n"
3502 " vec3 fZeroOneZero;\n"
3503 " float fSix;\n"
3504 " float fSeven;\n"
3505 " float fEight;\n"
3506 " float fNine;\n"
3507 " vec2 fZeroZero;\n"
3508 " vec2 fZeroOne;\n"
3509 " vec4 fBlue;\n"
3510 " vec2 fOneZero;\n"
3511 " vec2 fOneOne;\n"
3512 " vec3 fZeroOneOne;\n"
3513 " float fTen;\n"
3514 " float fEleven;\n"
3515 " float fTwelve;\n"
3516 " vec3 fOneZeroZero;\n"
3517 " vec4 uvOffsets[4];\n"
3518 "};\n"
3519 "layout (location = 0) out vec4 color;"
3520 "void main() {\n"
3521
3522 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3523 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3524 " \n"
3525
3526 // do some exact comparisons, even though we should
3527 // really have an epsilon involved.
3528 " vec4 outColor = right;\n"
3529 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3530 " outColor = wrong;\n"
3531 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3532 " outColor = wrong;\n"
3533 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3534 " outColor = wrong;\n"
3535
3536 " color = outColor;\n"
3537
3538 // generic position stuff
3539 " vec2 vertices;\n"
3540 " int vertexSelector = gl_VertexID;\n"
3541 " if (vertexSelector == 0)\n"
3542 " vertices = vec2(-0.5, -0.5);\n"
3543 " else if (vertexSelector == 1)\n"
3544 " vertices = vec2( 0.5, -0.5);\n"
3545 " else if (vertexSelector == 2)\n"
3546 " vertices = vec2( 0.5, 0.5);\n"
3547 " else\n"
3548 " vertices = vec2( 0.0, 0.0);\n"
3549 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3550 "}\n";
3551
3552 static const char *geomShaderText =
3553 "#version 330\n"
3554 "#extension GL_ARB_separate_shader_objects : enable\n"
3555 "#extension GL_ARB_shading_language_420pack : enable\n"
3556
3557 // GS layout stuff
3558 "layout( triangles ) in;\n"
3559 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3560
3561 // Between stage IO
3562 "layout( location = 0 ) in vec4 inColor[3];\n"
3563 "layout( location = 0 ) out vec4 color;\n"
3564
3565 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3566 " vec4 fRed;\n"
3567 " vec4 fGreen;\n"
3568 " layout(row_major) mat4 worldToProj;\n"
3569 " layout(row_major) mat4 projToWorld;\n"
3570 " layout(row_major) mat4 worldToView;\n"
3571 " layout(row_major) mat4 viewToProj;\n"
3572 " layout(row_major) mat4 worldToShadow[4];\n"
3573 " float fZero;\n"
3574 " float fOne;\n"
3575 " float fTwo;\n"
3576 " float fThree;\n"
3577 " vec3 fZeroZeroZero;\n"
3578 " float fFour;\n"
3579 " vec3 fZeroZeroOne;\n"
3580 " float fFive;\n"
3581 " vec3 fZeroOneZero;\n"
3582 " float fSix;\n"
3583 " float fSeven;\n"
3584 " float fEight;\n"
3585 " float fNine;\n"
3586 " vec2 fZeroZero;\n"
3587 " vec2 fZeroOne;\n"
3588 " vec4 fBlue;\n"
3589 " vec2 fOneZero;\n"
3590 " vec2 fOneOne;\n"
3591 " vec3 fZeroOneOne;\n"
3592 " float fTen;\n"
3593 " float fEleven;\n"
3594 " float fTwelve;\n"
3595 " vec3 fOneZeroZero;\n"
3596 " vec4 uvOffsets[4];\n"
3597 "};\n"
3598
3599 "void main()\n"
3600 "{\n"
3601
3602 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3603 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3604
3605 // Each vertex will validate it can read VS output
3606 // then check a few values from the UBO
3607
3608 // first vertex
3609 " vec4 outColor = inColor[0];\n"
3610
3611 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3612 " outColor = wrong;\n"
3613 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3614 " outColor = wrong;\n"
3615 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3616 " outColor = wrong;\n"
3617 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3618 " outColor = wrong;\n"
3619
3620 " gl_Position = gl_in[0].gl_Position;\n"
3621 " color = outColor;\n"
3622 " EmitVertex();\n"
3623
3624 // second vertex
3625 " outColor = inColor[1];\n"
3626
3627 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3628 " outColor = wrong;\n"
3629 " if (fSix != 6.0)\n"
3630 " outColor = wrong;\n"
3631 " if (fOneOne != vec2(1.0, 1.0))\n"
3632 " outColor = wrong;\n"
3633
3634 " gl_Position = gl_in[1].gl_Position;\n"
3635 " color = outColor;\n"
3636 " EmitVertex();\n"
3637
3638 // third vertex
3639 " outColor = inColor[2];\n"
3640
3641 " if (fSeven != 7.0)\n"
3642 " outColor = wrong;\n"
3643 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3644 " outColor = wrong;\n"
3645
3646 " gl_Position = gl_in[2].gl_Position;\n"
3647 " color = outColor;\n"
3648 " EmitVertex();\n"
3649
3650 // done
3651 " EndPrimitive();\n"
3652 "}\n";
3653
3654 static const char *fragShaderText =
3655 "#version 140\n"
3656 "#extension GL_ARB_separate_shader_objects : enable\n"
3657 "#extension GL_ARB_shading_language_420pack : enable\n"
3658 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3659 " vec4 fRed;\n"
3660 " vec4 fGreen;\n"
3661 " layout(row_major) mat4 worldToProj;\n"
3662 " layout(row_major) mat4 projToWorld;\n"
3663 " layout(row_major) mat4 worldToView;\n"
3664 " layout(row_major) mat4 viewToProj;\n"
3665 " layout(row_major) mat4 worldToShadow[4];\n"
3666 " float fZero;\n"
3667 " float fOne;\n"
3668 " float fTwo;\n"
3669 " float fThree;\n"
3670 " vec3 fZeroZeroZero;\n"
3671 " float fFour;\n"
3672 " vec3 fZeroZeroOne;\n"
3673 " float fFive;\n"
3674 " vec3 fZeroOneZero;\n"
3675 " float fSix;\n"
3676 " float fSeven;\n"
3677 " float fEight;\n"
3678 " float fNine;\n"
3679 " vec2 fZeroZero;\n"
3680 " vec2 fZeroOne;\n"
3681 " vec4 fBlue;\n"
3682 " vec2 fOneZero;\n"
3683 " vec2 fOneOne;\n"
3684 " vec3 fZeroOneOne;\n"
3685 " float fTen;\n"
3686 " float fEleven;\n"
3687 " float fTwelve;\n"
3688 " vec3 fOneZeroZero;\n"
3689 " vec4 uvOffsets[4];\n"
3690 "};\n"
3691 "layout (location = 0) in vec4 color;\n"
GregFaae75242015-06-03 18:40:50 -06003692 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003693 "void main() {\n"
3694 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3695 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3696 " \n"
3697
3698 // start with GS value to ensure it passed
3699 " vec4 outColor = color;\n"
3700
3701 // do some exact comparisons, even though we should
3702 // really have an epsilon involved.
3703 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3704 " outColor = wrong;\n"
3705 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3706 " outColor = wrong;\n"
3707 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3708 " outColor = wrong;\n"
3709 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3710 " outColor = wrong;\n"
3711 " if (fTwo != 2.0)\n"
3712 " outColor = wrong;\n"
3713 " if (fOneOne != vec2(1.0, 1.0))\n"
3714 " outColor = wrong;\n"
3715 " if (fTen != 10.0)\n"
3716 " outColor = wrong;\n"
3717 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3718 " outColor = wrong;\n"
3719 " \n"
GregFaae75242015-06-03 18:40:50 -06003720 " uFragColor = outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003721 "}\n";
3722
3723
Cody Northropd2ad0342015-08-05 11:15:02 -06003724 const float mixedVals[196] = { 1.0f, 0.0f, 0.0f, 1.0f, // vec4 fRed; // align
3725 0.0f, 1.0f, 0.0f, 1.0f, // vec4 fGreen; // align
3726 1.0f, 0.0f, 0.0f, 1.0f, // layout(row_major) mat4 worldToProj;
3727 0.0f, 1.0f, 0.0f, 1.0f, // align
3728 0.0f, 0.0f, 1.0f, 1.0f, // align
3729 0.0f, 0.0f, 0.0f, 1.0f, // align
3730 2.0f, 0.0f, 0.0f, 2.0f, // layout(row_major) mat4 projToWorld;
3731 0.0f, 2.0f, 0.0f, 2.0f, // align
3732 0.0f, 0.0f, 2.0f, 2.0f, // align
3733 0.0f, 0.0f, 0.0f, 2.0f, // align
3734 3.0f, 0.0f, 0.0f, 3.0f, // layout(row_major) mat4 worldToView;
3735 0.0f, 3.0f, 0.0f, 3.0f, // align
3736 0.0f, 0.0f, 3.0f, 3.0f, // align
3737 0.0f, 0.0f, 0.0f, 3.0f, // align
3738 4.0f, 0.0f, 0.0f, 4.0f, // layout(row_major) mat4 viewToProj;
3739 0.0f, 4.0f, 0.0f, 4.0f, // align
3740 0.0f, 0.0f, 4.0f, 4.0f, // align
3741 0.0f, 0.0f, 0.0f, 4.0f, // align
3742 5.0f, 0.0f, 0.0f, 5.0f, // layout(row_major) mat4 worldToShadow[4];
3743 0.0f, 5.0f, 0.0f, 5.0f, // align
3744 0.0f, 0.0f, 5.0f, 5.0f, // align
3745 0.0f, 0.0f, 0.0f, 5.0f, // align
3746 6.0f, 0.0f, 0.0f, 6.0f, // align
3747 0.0f, 6.0f, 0.0f, 6.0f, // align
3748 0.0f, 0.0f, 6.0f, 6.0f, // align
3749 0.0f, 0.0f, 0.0f, 6.0f, // align
3750 7.0f, 0.0f, 0.0f, 7.0f, // align
3751 0.0f, 7.0f, 0.0f, 7.0f, // align
3752 0.0f, 0.0f, 7.0f, 7.0f, // align
3753 0.0f, 0.0f, 0.0f, 7.0f, // align
3754 8.0f, 0.0f, 0.0f, 8.0f, // align
3755 0.0f, 8.0f, 0.0f, 8.0f, // align
3756 0.0f, 0.0f, 8.0f, 8.0f, // align
3757 0.0f, 0.0f, 0.0f, 8.0f, // align
3758 0.0f, // float fZero; // align
3759 1.0f, // float fOne; // pack
3760 2.0f, // float fTwo; // pack
3761 3.0f, // float fThree; // pack
3762 0.0f, 0.0f, 0.0f, // vec3 fZeroZeroZero; // align
3763 4.0f, // float fFour; // pack
3764 0.0f, 0.0f, 1.0f, // vec3 fZeroZeroOne; // align
3765 5.0f, // float fFive; // pack
3766 0.0f, 1.0f, 0.0f, // vec3 fZeroOneZero; // align
3767 6.0f, // float fSix; // pack
3768 7.0f, // float fSeven; // align
3769 8.0f, // float fEight; // pack
3770 9.0f, // float fNine; // pack
3771 0.0f, // BUFFER
3772 0.0f, 0.0f, // vec2 fZeroZero; // align
3773 0.0f, 1.0f, // vec2 fZeroOne; // pack
3774 0.0f, 0.0f, 1.0f, 1.0f, // vec4 fBlue; // align
3775 1.0f, 0.0f, // vec2 fOneZero; // align
3776 1.0f, 1.0f, // vec2 fOneOne; // pack
3777 0.0f, 1.0f, 1.0f, // vec3 fZeroOneOne; // align
3778 10.0f, // float fTen; // pack
3779 11.0f, // float fEleven; // align
3780 12.0f, // float fTwelve; // pack
3781 0.0f, 0.0f, // BUFFER
3782 1.0f, 0.0f, 0.0f, // vec3 fOneZeroZero; // align
3783 0.0f, // BUFFER
3784 0.1f, 0.2f, 0.3f, 0.4f, // vec4 uvOffsets[4];
3785 0.5f, 0.6f, 0.7f, 0.8f, // align
3786 0.9f, 1.0f, 1.1f, 1.2f, // align
3787 1.3f, 1.4f, 1.5f, 1.6f, // align
Cody Northrop475663c2015-04-15 11:19:06 -06003788 };
3789
3790
3791
3792 ASSERT_NO_FATAL_FAILURE(InitState());
3793 ASSERT_NO_FATAL_FAILURE(InitViewport());
3794
3795 const int constCount = sizeof(mixedVals) / sizeof(float);
3796
3797 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3798 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3799 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3800
3801 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
3802
3803 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003804 pipelineobj.AddColorAttachment();
Cody Northrop475663c2015-04-15 11:19:06 -06003805 pipelineobj.AddShader(&vs);
3806 pipelineobj.AddShader(&gs);
3807 pipelineobj.AddShader(&ps);
3808
3809 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003810 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop475663c2015-04-15 11:19:06 -06003811
3812 VkDescriptorSetObj descriptorSet(m_device);
3813 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
3814
Tony Barbourfe3351b2015-07-28 10:17:20 -06003815 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop475663c2015-04-15 11:19:06 -06003816
3817 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06003818 Draw(0, 3, 0, 1);
Cody Northrop475663c2015-04-15 11:19:06 -06003819
3820 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003821 EndCommandBuffer();
3822 QueueCommandBuffer();
Cody Northrop475663c2015-04-15 11:19:06 -06003823
3824 RecordImages(m_renderTargets);
3825}
3826
3827TEST_F(VkRenderTest, GSPositions)
3828{
3829 // This test adds more inputs from the vertex shader and perturbs positions
3830 // Expected result is white triangle with weird positions
3831
3832 static const char *vertShaderText =
3833 "#version 140\n"
3834 "#extension GL_ARB_separate_shader_objects : enable\n"
3835 "#extension GL_ARB_shading_language_420pack : enable\n"
3836
3837 "layout(location = 0) out vec3 out_a;\n"
3838 "layout(location = 1) out vec3 out_b;\n"
3839 "layout(location = 2) out vec3 out_c;\n"
3840
3841 "void main() {\n"
3842
3843 // write a solid color to each
3844 " out_a = vec3(1.0, 0.0, 0.0);\n"
3845 " out_b = vec3(0.0, 1.0, 0.0);\n"
3846 " out_c = vec3(0.0, 0.0, 1.0);\n"
3847
3848 // generic position stuff
3849 " vec2 vertices;\n"
3850 " int vertexSelector = gl_VertexID;\n"
3851 " if (vertexSelector == 0)\n"
3852 " vertices = vec2(-0.5, -0.5);\n"
3853 " else if (vertexSelector == 1)\n"
3854 " vertices = vec2( 0.5, -0.5);\n"
3855 " else if (vertexSelector == 2)\n"
3856 " vertices = vec2( 0.5, 0.5);\n"
3857 " else\n"
3858 " vertices = vec2( 0.0, 0.0);\n"
3859 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3860
3861 "}\n";
3862
3863 static const char *geomShaderText =
3864 "#version 330\n"
3865 "#extension GL_ARB_separate_shader_objects : enable\n"
3866 "#extension GL_ARB_shading_language_420pack : enable\n"
3867 "layout( triangles ) in;\n"
3868 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3869
3870 "layout(location = 0) in vec3 in_a[3];\n"
3871 "layout(location = 1) in vec3 in_b[3];\n"
3872 "layout(location = 2) in vec3 in_c[3];\n"
3873
3874 "layout(location = 0) out vec3 out_a;\n"
3875 "layout(location = 1) out vec3 out_b;\n"
3876 "layout(location = 2) out vec3 out_c;\n"
3877
3878 "void main()\n"
3879 "{\n"
3880
3881 " gl_Position = gl_in[0].gl_Position;\n"
3882 " gl_Position.xy *= vec2(0.75);\n"
3883 " out_a = in_a[0];\n"
3884 " out_b = in_b[0];\n"
3885 " out_c = in_c[0];\n"
3886 " EmitVertex();\n"
3887
3888 " gl_Position = gl_in[1].gl_Position;\n"
3889 " gl_Position.xy *= vec2(1.5);\n"
3890 " out_a = in_a[1];\n"
3891 " out_b = in_b[1];\n"
3892 " out_c = in_c[1];\n"
3893 " EmitVertex();\n"
3894
3895 " gl_Position = gl_in[2].gl_Position;\n"
3896 " gl_Position.xy *= vec2(-0.1);\n"
3897 " out_a = in_a[2];\n"
3898 " out_b = in_b[2];\n"
3899 " out_c = in_c[2];\n"
3900 " EmitVertex();\n"
3901
3902 " EndPrimitive();\n"
3903 "}\n";
3904
3905
3906 static const char *fragShaderText =
3907 "#version 140\n"
3908 "#extension GL_ARB_separate_shader_objects : enable\n"
3909 "#extension GL_ARB_shading_language_420pack : enable\n"
3910
3911 "layout(location = 0) in vec3 in_a;\n"
3912 "layout(location = 1) in vec3 in_b;\n"
3913 "layout(location = 2) in vec3 in_c;\n"
GregFaae75242015-06-03 18:40:50 -06003914 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003915
3916 "void main() {\n"
GregFaae75242015-06-03 18:40:50 -06003917 " outColor = vec4(in_a.x, in_b.y, in_c.z, 1.0);\n"
Cody Northrop475663c2015-04-15 11:19:06 -06003918 "}\n";
3919
3920
3921
3922 ASSERT_NO_FATAL_FAILURE(InitState());
3923 ASSERT_NO_FATAL_FAILURE(InitViewport());
3924
3925 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3926 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3927 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3928
3929 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08003930 pipelineobj.AddColorAttachment();
Cody Northrop475663c2015-04-15 11:19:06 -06003931 pipelineobj.AddShader(&vs);
3932 pipelineobj.AddShader(&gs);
3933 pipelineobj.AddShader(&ps);
3934
3935 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003936 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop475663c2015-04-15 11:19:06 -06003937
3938 VkDescriptorSetObj descriptorSet(m_device);
3939
Tony Barbourfe3351b2015-07-28 10:17:20 -06003940 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop475663c2015-04-15 11:19:06 -06003941
3942 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06003943 Draw(0, 3, 0, 1);
Cody Northrop475663c2015-04-15 11:19:06 -06003944
3945 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06003946 EndCommandBuffer();
3947 QueueCommandBuffer();
Cody Northrop475663c2015-04-15 11:19:06 -06003948
3949 RecordImages(m_renderTargets);
3950}
3951
3952TEST_F(VkRenderTest, GSTriStrip)
3953{
3954 // This test emits multiple multiple triangles using a GS
3955 // Correct result is an multicolor circle
3956
3957 static const char *vertShaderText =
3958 "#version 140\n"
3959 "#extension GL_ARB_separate_shader_objects : enable\n"
3960 "#extension GL_ARB_shading_language_420pack : enable\n"
3961
3962 "void main() {\n"
3963
3964 // generic position stuff
3965 " vec2 vertices;\n"
3966 " int vertexSelector = gl_VertexID;\n"
3967 " if (vertexSelector == 0)\n"
3968 " vertices = vec2(-0.5, -0.5);\n"
3969 " else if (vertexSelector == 1)\n"
3970 " vertices = vec2( 0.5, -0.5);\n"
3971 " else if (vertexSelector == 2)\n"
3972 " vertices = vec2( 0.5, 0.5);\n"
3973 " else\n"
3974 " vertices = vec2( 0.0, 0.0);\n"
3975 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3976
3977 "}\n";
3978
3979 static const char *geomShaderText =
3980 "#version 330\n"
3981 "#extension GL_ARB_separate_shader_objects : enable\n"
3982 "#extension GL_ARB_shading_language_420pack : enable\n"
3983 "layout( triangles ) in;\n"
3984 "layout( triangle_strip, max_vertices = 18 ) out;\n"
3985
3986 "layout(location = 0) out vec4 outColor;\n"
3987
3988 "void main()\n"
3989 "{\n"
3990 // init with first position to get zw
3991 " gl_Position = gl_in[0].gl_Position;\n"
3992
3993 " vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3994 " vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
3995 " vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
3996 " vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
3997
3998 // different color per tri
3999 " vec4[6] colors = { red, white, \n"
4000 " yellow, white, \n"
4001 " blue, white }; \n"
4002
4003 // fan out the triangles
4004 " vec2[18] positions = { vec2(0.0, 0.0), vec2(-0.5, 0.0), vec2(-0.25, -0.5), \n"
4005 " vec2(0.0, 0.0), vec2(-0.25, -0.5), vec2( 0.25, -0.5), \n"
4006 " vec2(0.0, 0.0), vec2( 0.25, -0.5), vec2( 0.5, 0.0), \n"
4007 " vec2(0.0, 0.0), vec2( 0.5, 0.0), vec2( 0.25, 0.5), \n"
4008 " vec2(0.0, 0.0), vec2( 0.25, 0.5), vec2(-0.25, 0.5), \n"
4009 " vec2(0.0, 0.0), vec2(-0.25, 0.5), vec2(-0.5, 0.0) }; \n"
4010
4011 // make a triangle list of 6
4012 " for (int i = 0; i < 6; ++i) { \n"
4013 " outColor = colors[i]; \n"
4014 " for (int j = 0; j < 3; ++j) { \n"
4015 " gl_Position.xy = positions[i * 3 + j]; \n"
4016 " EmitVertex(); \n"
4017 " } \n"
4018 " EndPrimitive();\n"
4019 " } \n"
4020
4021 "}\n";
4022
4023
4024 static const char *fragShaderText =
4025 "#version 150\n"
4026 "#extension GL_ARB_separate_shader_objects : enable\n"
4027 "#extension GL_ARB_shading_language_420pack : enable\n"
4028
4029
4030 "layout(binding = 0) uniform windowDimensions {\n"
4031 " vec4 dimensions;\n"
4032 "};\n"
4033
4034 "layout(location = 0) in vec4 inColor;\n"
4035 "layout(origin_upper_left) in vec4 gl_FragCoord;\n"
GregFaae75242015-06-03 18:40:50 -06004036 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06004037
4038 "void main() {\n"
4039
4040 // discard to make a nice circle
4041 " vec2 pos = abs(gl_FragCoord.xy) - vec2(dimensions.x, dimensions.y) / 2;\n"
4042 " float dist = sqrt(dot(pos, pos));\n"
4043 " if (dist > 50.0)\n"
4044 " discard;\n"
4045
GregFaae75242015-06-03 18:40:50 -06004046 " outColor = inColor;\n"
Cody Northrop475663c2015-04-15 11:19:06 -06004047
4048 "}\n";
4049
4050
4051
4052 ASSERT_NO_FATAL_FAILURE(InitState());
4053 ASSERT_NO_FATAL_FAILURE(InitViewport());
4054
4055 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
4056 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
4057 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
4058
4059 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08004060 pipelineobj.AddColorAttachment();
Cody Northrop475663c2015-04-15 11:19:06 -06004061 pipelineobj.AddShader(&vs);
4062 pipelineobj.AddShader(&gs);
4063 pipelineobj.AddShader(&ps);
4064
4065 const float dimensions[4] = { VkRenderFramework::m_width, VkRenderFramework::m_height , 0.0, 0.0};
4066
4067 VkConstantBufferObj windowDimensions(m_device, sizeof(dimensions) / sizeof(dimensions[0]), sizeof(dimensions[0]), (const void*) dimensions);
4068
4069 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004070 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop475663c2015-04-15 11:19:06 -06004071
4072 VkDescriptorSetObj descriptorSet(m_device);
4073 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, windowDimensions);
4074
Tony Barbourfe3351b2015-07-28 10:17:20 -06004075 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop475663c2015-04-15 11:19:06 -06004076
4077 // render triangle
Tony Barbourfe3351b2015-07-28 10:17:20 -06004078 Draw(0, 3, 0, 1);
Cody Northrop475663c2015-04-15 11:19:06 -06004079
4080 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -06004081 EndCommandBuffer();
4082 QueueCommandBuffer();
Cody Northrop475663c2015-04-15 11:19:06 -06004083
4084 RecordImages(m_renderTargets);
4085}
4086
Chris Forbese182fe02015-06-15 09:32:35 +12004087TEST_F(VkRenderTest, RenderPassLoadOpClear)
4088{
4089 ASSERT_NO_FATAL_FAILURE(InitState());
4090 ASSERT_NO_FATAL_FAILURE(InitViewport());
4091
4092 /* clear via load op to full green */
4093 m_clear_via_load_op = true;
Chris Forbesf0796e12015-06-24 14:34:53 +12004094 m_clear_color.f32[0] = 0;
4095 m_clear_color.f32[1] = 1;
4096 m_clear_color.f32[2] = 0;
4097 m_clear_color.f32[3] = 0;
Chris Forbese182fe02015-06-15 09:32:35 +12004098 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004099 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Chris Forbese182fe02015-06-15 09:32:35 +12004100 /* This command buffer contains ONLY the load op! */
Tony Barbourfe3351b2015-07-28 10:17:20 -06004101 EndCommandBuffer();
4102 QueueCommandBuffer();
Chris Forbese182fe02015-06-15 09:32:35 +12004103
4104 RecordImages(m_renderTargets);
4105}
4106
Chris Forbesfa27b952015-06-24 12:05:30 +12004107TEST_F(VkRenderTest, RenderPassAttachmentClear)
4108{
4109 ASSERT_NO_FATAL_FAILURE(InitState());
4110 ASSERT_NO_FATAL_FAILURE(InitViewport());
4111
4112 /* clear via load op to full red */
4113 m_clear_via_load_op = true;
Chris Forbesf0796e12015-06-24 14:34:53 +12004114 m_clear_color.f32[0] = 1;
4115 m_clear_color.f32[1] = 0;
4116 m_clear_color.f32[2] = 0;
4117 m_clear_color.f32[3] = 0;
Chris Forbesfa27b952015-06-24 12:05:30 +12004118 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004119 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Chris Forbesfa27b952015-06-24 12:05:30 +12004120
4121 /* Load op has cleared to red */
4122
4123 /* Draw, draw, draw... */
4124
4125 /* Now, partway through this renderpass we want to clear the color
4126 * attachment again, this time to green.
4127 */
Chris Forbesf0796e12015-06-24 14:34:53 +12004128 VkClearColorValue clear_color;
4129 clear_color.f32[0] = 0;
4130 clear_color.f32[1] = 1;
4131 clear_color.f32[2] = 0;
4132 clear_color.f32[3] = 0;
Chris Forbesfa27b952015-06-24 12:05:30 +12004133 VkRect3D clear_rect = { { 0, 0, 0 }, { (int)m_width, (int)m_height, 1 } };
Tony Barbourfe3351b2015-07-28 10:17:20 -06004134 vkCmdClearColorAttachment(m_cmdBuffer->handle(), 0,
Chris Forbesfa27b952015-06-24 12:05:30 +12004135 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4136 &clear_color, 1, &clear_rect);
4137
Tony Barbourfe3351b2015-07-28 10:17:20 -06004138 EndCommandBuffer();
4139 QueueCommandBuffer();
Chris Forbesfa27b952015-06-24 12:05:30 +12004140
4141 RecordImages(m_renderTargets);
4142}
4143
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06004144int main(int argc, char **argv) {
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004145 int result;
4146
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06004147 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -06004148 VkTestFramework::InitArgs(&argc, argv);
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004149
Chia-I Wu6f184292014-12-15 23:57:34 +08004150 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchtera0f74c52014-10-08 08:46:51 -06004151
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004152 result = RUN_ALL_TESTS();
4153
Tony Barbour6918cd52015-04-09 12:58:51 -06004154 VkTestFramework::Finish();
Courtney Goeltzenleuchter54119a32014-09-04 16:26:02 -06004155 return result;
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -06004156}