blob: a4aad3f4bd764447993f6d9d167e38e3bcaf3e7c [file] [log] [blame]
Courtney Goeltzenleuchterb85c5812014-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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060031// VK tests
Courtney Goeltzenleuchterb85c5812014-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 Goeltzenleuchterb85c5812014-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 Goeltzenleuchter76a643b2014-08-21 17:34:22 -060059#include <iostream>
60#include <fstream>
61using namespace std;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060062
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060063#include <vulkan.h>
Tobin Ehlis31446e52014-11-28 11:17:19 -070064#ifdef DUMP_STATE_DOT
65#include "../layers/draw_state.h"
66#endif
Tobin Ehlis3c26a542014-11-18 11:28:33 -070067#ifdef PRINT_OBJECTS
68#include "../layers/object_track.h"
69#endif
Tobin Ehlis791a49c2014-11-10 12:29:12 -070070#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060071#include <vk_debug_report_lunarg.h>
Tobin Ehlis791a49c2014-11-10 12:29:12 -070072#endif
Courtney Goeltzenleuchter0abdb662015-10-07 13:28:58 -060073#include "test_common.h"
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060074
Cody Northropd4e020a2015-03-17 14:54:35 -060075#include "icd-spv.h"
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060076
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -060077#define GLM_FORCE_RADIANS
78#include "glm/glm.hpp"
79#include <glm/gtc/matrix_transform.hpp>
80
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060081#include "vkrenderframework.h"
Tobin Ehlis791a49c2014-11-10 12:29:12 -070082#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060083void VKAPI myDbgFunc(
84 VK_DBG_MSG_TYPE msgType,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060085 VkValidationLevel validationLevel,
Mike Stroyan230e6252015-04-17 12:36:38 -060086 VkObject srcObject,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060087 size_t location,
88 int32_t msgCode,
89 const char* pMsg,
90 void* pUserData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -070091{
Tobin Ehlis3c26a542014-11-18 11:28:33 -070092 switch (msgType)
93 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060094 case VK_DBG_MSG_WARNING:
Tobin Ehlis3c26a542014-11-18 11:28:33 -070095 printf("CALLBACK WARNING : %s\n", pMsg);
96 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060097 case VK_DBG_REPORT_ERROR_BIT:
Tobin Ehlis3c26a542014-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 Ehlis791a49c2014-11-10 12:29:12 -0700104}
105#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700106
107
108#undef ASSERT_NO_FATAL_FAILURE
109#define ASSERT_NO_FATAL_FAILURE(x) x
110
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600111//--------------------------------------------------------------------------------------
112// Mesh and VertexFormat Data
113//--------------------------------------------------------------------------------------
114struct Vertex
115{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600116 float posX, posY, posZ, posW; // Position data
117 float r, g, b, a; // Color
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600118};
119
Courtney Goeltzenleuchter28846ae2015-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 Goeltzenleuchtera948d842014-08-22 16:27:58 -0600126#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600127#define UV(_u_, _v_) (_u_), (_v_)
Courtney Goeltzenleuchtera948d842014-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 Goeltzenleuchterd0556292014-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 Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600177 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchterd0556292014-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 Goeltzenleuchter28846ae2015-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 Goeltzenleuchterd0556292014-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 Goeltzenleuchter28846ae2015-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 Goeltzenleuchterd0556292014-10-20 16:33:15 -0600187 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600188 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600189
Courtney Goeltzenleuchter28846ae2015-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 Goeltzenleuchterd0556292014-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 Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600204 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600205 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchter28846ae2015-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 Goeltzenleuchterd0556292014-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 Goeltzenleuchter28846ae2015-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 Barbour01999182015-04-09 12:58:51 -0600264class VkRenderTest : public VkRenderFramework
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -0600265{
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600266public:
Cody Northrop4e6b4762014-10-09 21:25:22 -0600267
Tony Barbourf43b6982014-11-25 13:18:32 -0700268 void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbour01999182015-04-09 12:58:51 -0600269 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer);
270 void GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet);
Tony Barbour1490c912015-07-28 10:17:20 -0600271 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet)
272 { GenericDrawPreparation(m_cmdBuffer, pipelineobj, descriptorSet); }
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600273 void InitDepthStencil();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600274 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate);
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600275
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600276 VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer);
Tobin Ehlis7f7b4422015-08-18 14:24:32 -0600277 VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer, VkCmdBufferBeginInfo *beginInfo);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600278 VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer);
Tony Barbour1490c912015-07-28 10:17:20 -0600279 /* Convenience functions that use built-in command buffer */
280 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_cmdBuffer); }
Tobin Ehlis7f7b4422015-08-18 14:24:32 -0600281 VkResult BeginCommandBuffer(VkCmdBufferBeginInfo *beginInfo) { return BeginCommandBuffer(*m_cmdBuffer, beginInfo); }
Tony Barbour1490c912015-07-28 10:17:20 -0600282 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_cmdBuffer); }
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -0600283 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
284 { m_cmdBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance); }
285 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance)
286 { m_cmdBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); }
Tony Barbour1490c912015-07-28 10:17:20 -0600287 void QueueCommandBuffer() { m_cmdBuffer->QueueCommandBuffer(); }
288 void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
289 VkConstantBufferObj *constantBuffer)
290 {RotateTriangleVSUniform(Projection, View, Model, constantBuffer, m_cmdBuffer); }
291 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding)
292 { m_cmdBuffer->BindVertexBuffer(vertexBuffer, offset, binding); }
293 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset)
294 { m_cmdBuffer->BindIndexBuffer(indexBuffer, offset); }
295
296
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600297
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600298protected:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600299 VkImage m_texture;
300 VkImageView m_textureView;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800301 VkDescriptorInfo m_descriptorInfo;
Tony Barbour8205d902015-04-16 15:59:00 -0600302 VkDeviceMemory m_textureMem;
Cody Northrop350727b2014-10-06 15:42:00 -0600303
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600304 VkSampler m_sampler;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600305
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600306
307 virtual void SetUp() {
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600308
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600309 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600310 this->app_info.pNext = NULL;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800311 this->app_info.pAppName = "render_tests";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600312 this->app_info.appVersion = 1;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800313 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600314 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600315 this->app_info.apiVersion = VK_API_VERSION;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600316
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800317 memset(&m_descriptorInfo, 0, sizeof(m_descriptorInfo));
Cody Northrop350727b2014-10-06 15:42:00 -0600318
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600319 InitFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600320 }
321
322 virtual void TearDown() {
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600323 // Clean up resources before we reset
324 ShutdownFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600325 }
326};
327
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600328VkResult VkRenderTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600329{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600330 VkResult result;
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600331
332 result = cmdBuffer.BeginCommandBuffer();
333
334 /*
335 * For render test all drawing happens in a single render pass
336 * on a single command buffer.
337 */
Chris Forbesfe133ef2015-06-16 14:05:59 +1200338 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wuc278df82015-07-07 11:50:03 +0800339 cmdBuffer.BeginRenderPass(renderPassBeginInfo());
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600340 }
341
342 return result;
343}
344
Tobin Ehlis7f7b4422015-08-18 14:24:32 -0600345VkResult VkRenderTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer, VkCmdBufferBeginInfo *beginInfo)
346{
347 VkResult result;
348
349 result = cmdBuffer.BeginCommandBuffer(beginInfo);
350
351 /*
352 * For render test all drawing happens in a single render pass
353 * on a single command buffer.
354 */
355 if (VK_SUCCESS == result && renderPass()) {
356 cmdBuffer.BeginRenderPass(renderPassBeginInfo());
357 }
358
359 return result;
360}
361
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600362VkResult VkRenderTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600363{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600364 VkResult result;
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600365
Chris Forbesfe133ef2015-06-16 14:05:59 +1200366 if (renderPass()) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +0800367 cmdBuffer.EndRenderPass();
Chris Forbesfe133ef2015-06-16 14:05:59 +1200368 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600369
370 result = cmdBuffer.EndCommandBuffer();
371
372 return result;
373}
374
375
Tony Barbour01999182015-04-09 12:58:51 -0600376void VkRenderTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet)
Tony Barbour02472db2015-01-08 17:08:28 -0700377{
Tony Barbour6d841032015-07-21 17:00:26 -0600378 if (!m_clear_via_load_op) {
379 if (m_depthStencil->Initialized()) {
380 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
381 } else {
382 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
383 }
Tony Barbour17c6ab12015-03-27 17:03:18 -0600384 }
385
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700386 cmdBuffer->PrepareAttachments();
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600387 cmdBuffer->SetViewport(m_viewports.size(), m_viewports.data());
388 cmdBuffer->SetScissor(m_scissors.size(), m_scissors.data());
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600389
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600390 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
Cody Northropccfa96d2015-08-27 10:20:35 -0600391 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
392 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600393 cmdBuffer->BindPipeline(pipelineobj);
Chia-I Wu862c5572015-03-28 15:23:55 +0800394 cmdBuffer->BindDescriptorSet(descriptorSet);
Tony Barbour02472db2015-01-08 17:08:28 -0700395}
Tony Barbourf43b6982014-11-25 13:18:32 -0700396
Tony Barbour01999182015-04-09 12:58:51 -0600397void VkRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
398 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer)
Tony Barbourdd4c9642015-01-09 12:55:14 -0700399{
400 int i;
401 glm::mat4 MVP;
402 int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600403 VkResult err;
Tony Barbourdd4c9642015-01-09 12:55:14 -0700404
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600405 /* Only do 3 positions to avoid back face cull */
406 for (i = 0; i < 3; i++) {
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800407 void *pData = constantBuffer->memory().map();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700408
409 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
410 MVP = Projection * View * Model;
411 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
412
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800413 constantBuffer->memory().unmap();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700414
415 // submit the command buffer to the universal queue
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600416 cmdBuffer->QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700417
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600418 err = vkQueueWaitIdle( m_device->m_queue );
419 ASSERT_VK_SUCCESS( err );
Tony Barbourdd4c9642015-01-09 12:55:14 -0700420
421 // Wait for work to finish before cleaning up.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600422 vkDeviceWaitIdle(m_device->device());
Tony Barbourdd4c9642015-01-09 12:55:14 -0700423
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700424 assert(m_renderTargets.size() == 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -0700425 RecordImage(m_renderTargets[0]);
426 }
427}
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600428
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600429void dumpMatrix(const char *note, glm::mat4 MVP)
430{
Chia-I Wu7133fdc2014-12-15 23:57:34 +0800431 int i;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600432
433 printf("%s: \n", note);
434 for (i=0; i<4; i++) {
435 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
436 }
437 printf("\n");
438 fflush(stdout);
439}
440
441void dumpVec4(const char *note, glm::vec4 vector)
442{
443 printf("%s: \n", note);
444 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
445 printf("\n");
446 fflush(stdout);
447}
448
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600449struct vktriangle_vs_uniform {
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600450 // Must start with MVP
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600451 float mvp[4][4];
452 float position[3][4];
453 float color[3][4];
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600454};
455
Tony Barbour01999182015-04-09 12:58:51 -0600456void VkRenderTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600457{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700458#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600459 vkDbgRegisterMsgCallback(inst, myDbgFunc, NULL);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700460#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600461 // Create identity matrix
462 int i;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600463 struct vktriangle_vs_uniform data;
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600464
465 glm::mat4 Projection = glm::mat4(1.0f);
466 glm::mat4 View = glm::mat4(1.0f);
467 glm::mat4 Model = glm::mat4(1.0f);
468 glm::mat4 MVP = Projection * View * Model;
469 const int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600470 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600471 memcpy(&data.mvp, &MVP[0][0], matrixSize);
472
473 static const Vertex tri_data[] =
474 {
475 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
476 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
477 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
478 };
479
480 for (i=0; i<3; i++) {
481 data.position[i][0] = tri_data[i].posX;
482 data.position[i][1] = tri_data[i].posY;
483 data.position[i][2] = tri_data[i].posZ;
484 data.position[i][3] = tri_data[i].posW;
485 data.color[i][0] = tri_data[i].r;
486 data.color[i][1] = tri_data[i].g;
487 data.color[i][2] = tri_data[i].b;
488 data.color[i][3] = tri_data[i].a;
489 }
490
Tony Barbourf43b6982014-11-25 13:18:32 -0700491 ASSERT_NO_FATAL_FAILURE(InitState());
492 ASSERT_NO_FATAL_FAILURE(InitViewport());
493
Tony Barbour01999182015-04-09 12:58:51 -0600494 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barbourf43b6982014-11-25 13:18:32 -0700495
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600496 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
497 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700498
Tony Barbour01999182015-04-09 12:58:51 -0600499 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800500 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -0700501 pipelineobj.AddShader(&vs);
502 pipelineobj.AddShader(&ps);
503
Tony Barbour01999182015-04-09 12:58:51 -0600504 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600505 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700506
Tony Barbour71ba3612015-01-09 16:12:35 -0700507 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis7f7b4422015-08-18 14:24:32 -0600508
509 VkCmdBufferBeginInfo cbBeginInfo;
510 memset(&cbBeginInfo, 0, sizeof(VkCmdBufferBeginInfo));
511 cbBeginInfo.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
512 cbBeginInfo.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT;
513 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barbourf43b6982014-11-25 13:18:32 -0700514
Tony Barbour1490c912015-07-28 10:17:20 -0600515 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour71ba3612015-01-09 16:12:35 -0700516#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600517 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour71ba3612015-01-09 16:12:35 -0700518 pDSDumpDot((char*)"triTest2.dot");
519#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600520
Tony Barbour71ba3612015-01-09 16:12:35 -0700521 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -0600522 Draw(3, 1, 0, 0);
Tony Barbour71ba3612015-01-09 16:12:35 -0700523
524 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600525 ASSERT_VK_SUCCESS(EndCommandBuffer());
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600526
Tony Barbour1490c912015-07-28 10:17:20 -0600527 QueueCommandBuffer();
Tony Barbour71ba3612015-01-09 16:12:35 -0700528
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600529 RecordImages(m_renderTargets);
Tony Barbour71ba3612015-01-09 16:12:35 -0700530
531 if (rotate)
Tony Barbour1490c912015-07-28 10:17:20 -0600532 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer);
Tony Barbour71ba3612015-01-09 16:12:35 -0700533
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700534#ifdef PRINT_OBJECTS
Mark Lobodzinski4e5016f2015-05-05 15:01:37 -0500535 OBJ_TRACK_GET_OBJECTS_COUNT pObjTrackGetObjectsCount = (OBJ_TRACK_GET_OBJECTS_COUNT)vkGetProcAddr(gpu(), (char*)"objTrackGetObjectsCount");
Mark Lobodzinski14305ad2015-06-23 11:35:12 -0600536 uint64_t numObjects = pObjTrackGetObjectsCount(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600537 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700538 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600539 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700540 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
Mark Lobodzinski14305ad2015-06-23 11:35:12 -0600541 pObjTrackGetObjs(m_device, numObjects, pObjNodeArray);
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700542 for (i=0; i < numObjects; i++) {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600543 printf("Object %i of type %s has objID (%p) and %lu uses\n", i, string_VkObjectType(pObjNodeArray[i].objType), pObjNodeArray[i].pObj, pObjNodeArray[i].numUses);
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700544 }
545 free(pObjNodeArray);
546#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700547
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600548}
549
Tony Barbour01999182015-04-09 12:58:51 -0600550TEST_F(VkRenderTest, VKTriangle_FragColor)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600551{
552 static const char *vertShaderText =
553 "#version 140\n"
554 "#extension GL_ARB_separate_shader_objects : enable\n"
555 "#extension GL_ARB_shading_language_420pack : enable\n"
556 "\n"
557 "layout(binding = 0) uniform buf {\n"
558 " mat4 MVP;\n"
559 " vec4 position[3];\n"
560 " vec4 color[3];\n"
561 "} ubuf;\n"
562 "\n"
563 "layout (location = 0) out vec4 outColor;\n"
564 "\n"
565 "void main() \n"
566 "{\n"
567 " outColor = ubuf.color[gl_VertexID];\n"
568 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
569 "}\n";
570
571 static const char *fragShaderText =
572 "#version 140\n"
573 "#extension GL_ARB_separate_shader_objects : enable\n"
574 "#extension GL_ARB_shading_language_420pack : enable\n"
575 "\n"
576 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600577 "layout (location = 0) out vec4 uFragColor;\n"
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600578 "\n"
579 "void main()\n"
580 "{\n"
GregFd6ebdb32015-06-03 18:40:50 -0600581 " uFragColor = inColor;\n"
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600582 "}\n";
583
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600584 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
585 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600586}
587
Tony Barbour01999182015-04-09 12:58:51 -0600588TEST_F(VkRenderTest, VKTriangle_OutputLocation)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600589{
590 static const char *vertShaderText =
591 "#version 140\n"
592 "#extension GL_ARB_separate_shader_objects : enable\n"
593 "#extension GL_ARB_shading_language_420pack : enable\n"
594 "\n"
595 "layout(binding = 0) uniform buf {\n"
596 " mat4 MVP;\n"
597 " vec4 position[3];\n"
598 " vec4 color[3];\n"
599 "} ubuf;\n"
600 "\n"
601 "layout (location = 0) out vec4 outColor;\n"
602 "\n"
603 "void main() \n"
604 "{\n"
605 " outColor = ubuf.color[gl_VertexID];\n"
606 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
607 "}\n";
608
609 static const char *fragShaderText =
610 "#version 140\n"
611 "#extension GL_ARB_separate_shader_objects : enable\n"
612 "#extension GL_ARB_shading_language_420pack : enable\n"
613 "\n"
614 "layout (location = 0) in vec4 inColor;\n"
615 "layout (location = 0) out vec4 outColor;\n"
616 "\n"
617 "void main()\n"
618 "{\n"
619 " outColor = inColor;\n"
620 "}\n";
621
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600622 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to output location 0, which should be the same as gl_FragColor");
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600623
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600624 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600625}
Cody Northrop71727d22015-06-23 13:25:51 -0600626
Tony Barbour01999182015-04-09 12:58:51 -0600627TEST_F(VkRenderTest, SPV_VKTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700628{
Tony Barbourf43b6982014-11-25 13:18:32 -0700629 static const char *vertShaderText =
630 "#version 140\n"
631 "#extension GL_ARB_separate_shader_objects : enable\n"
632 "#extension GL_ARB_shading_language_420pack : enable\n"
633 "\n"
634 "layout(binding = 0) uniform buf {\n"
635 " mat4 MVP;\n"
636 " vec4 position[3];\n"
637 " vec4 color[3];\n"
638 "} ubuf;\n"
639 "\n"
640 "layout (location = 0) out vec4 outColor;\n"
641 "\n"
642 "void main() \n"
643 "{\n"
644 " outColor = ubuf.color[gl_VertexID];\n"
645 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
646 "}\n";
647
648 static const char *fragShaderText =
649 "#version 140\n"
650 "#extension GL_ARB_separate_shader_objects : enable\n"
651 "#extension GL_ARB_shading_language_420pack : enable\n"
652 "\n"
653 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600654 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700655 "\n"
656 "void main()\n"
657 "{\n"
GregFd6ebdb32015-06-03 18:40:50 -0600658 " outColor = inColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700659 "}\n";
660
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600661 TEST_DESCRIPTION("VK-style shaders, but force test framework to compile shader to SPV and pass SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700662
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600663 VKTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700664}
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600665
Tony Barbour01999182015-04-09 12:58:51 -0600666TEST_F(VkRenderTest, SPV_GreenTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700667{
Tony Barbourf43b6982014-11-25 13:18:32 -0700668 static const char *vertShaderText =
669 "#version 130\n"
670 "vec2 vertices[3];\n"
671 "void main() {\n"
672 " vertices[0] = vec2(-1.0, -1.0);\n"
673 " vertices[1] = vec2( 1.0, -1.0);\n"
674 " vertices[2] = vec2( 0.0, 1.0);\n"
675 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
676 "}\n";
677
678 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600679 "#version 140\n"
680 "#extension GL_ARB_separate_shader_objects : enable\n"
681 "#extension GL_ARB_shading_language_420pack : enable\n"
682 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700683 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600684 " outColor = vec4(0,1,0,1);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700685 "}\n";
686
Cody Northropacfb0492015-03-17 15:55:58 -0600687 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700688
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600689 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700690}
Cody Northrop71727d22015-06-23 13:25:51 -0600691
Tony Barbour01999182015-04-09 12:58:51 -0600692TEST_F(VkRenderTest, YellowTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700693{
694 static const char *vertShaderText =
695 "#version 130\n"
696 "void main() {\n"
697 " vec2 vertices[3];"
698 " vertices[0] = vec2(-0.5, -0.5);\n"
699 " vertices[1] = vec2( 0.5, -0.5);\n"
700 " vertices[2] = vec2( 0.5, 0.5);\n"
701 " vec4 colors[3];\n"
702 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
703 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
704 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
705 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
706 "}\n";
707
708 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600709 "#version 140\n"
710 "#extension GL_ARB_separate_shader_objects : enable\n"
711 "#extension GL_ARB_shading_language_420pack : enable\n"
712 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700713 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600714 " outColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700715 "}\n";
716
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600717 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700718}
719
Tony Barbour01999182015-04-09 12:58:51 -0600720TEST_F(VkRenderTest, QuadWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600721{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600722 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600723 "#version 140\n"
724 "#extension GL_ARB_separate_shader_objects : enable\n"
725 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700726 //XYZ1( -1, -1, -1 )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600727 "layout (location = 0) in vec4 pos;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700728 //XYZ1( 0.f, 0.f, 0.f )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600729 "layout (location = 1) in vec4 inColor;\n"
730 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600731 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600732 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600733 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600734 "}\n";
735
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600736
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600737 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700738 "#version 140\n"
739 "#extension GL_ARB_separate_shader_objects : enable\n"
740 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600741 "layout (location = 0) in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700742 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600743 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700744 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600745 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600746
Tony Barbourf43b6982014-11-25 13:18:32 -0700747
748
749 ASSERT_NO_FATAL_FAILURE(InitState());
750 ASSERT_NO_FATAL_FAILURE(InitViewport());
751
Tony Barbour01999182015-04-09 12:58:51 -0600752 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000753 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700754
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600755 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
756 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700757
Tony Barbour01999182015-04-09 12:58:51 -0600758 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800759 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -0700760 pipelineobj.AddShader(&vs);
761 pipelineobj.AddShader(&ps);
762
Tony Barbour01999182015-04-09 12:58:51 -0600763 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinski15427102015-02-18 16:38:17 -0600764
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600765#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600766 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600767 MESH_BIND_ID, // binding ID
Tony Barbourf43b6982014-11-25 13:18:32 -0700768 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600769 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -0700770 };
771
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600772 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600773 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
774 vi_attribs[0].location = 0; // location, position
Tony Barbour8205d902015-04-16 15:59:00 -0600775 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600776 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
777 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
778 vi_attribs[1].location = 1; // location, color
Tony Barbour8205d902015-04-16 15:59:00 -0600779 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600780 vi_attribs[1].offsetInBytes = 1*sizeof(float)*4; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -0700781
782 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
783 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barbourf43b6982014-11-25 13:18:32 -0700784
Tony Barboure4ed9942015-01-09 10:06:53 -0700785 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -0600786 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourf43b6982014-11-25 13:18:32 -0700787
Tony Barbour1490c912015-07-28 10:17:20 -0600788 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600789
Tony Barbour1490c912015-07-28 10:17:20 -0600790 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barboure4ed9942015-01-09 10:06:53 -0700791
792 // render two triangles
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -0600793 Draw(6, 1, 0, 0);
Tony Barboure4ed9942015-01-09 10:06:53 -0700794
795 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600796 ASSERT_VK_SUCCESS(EndCommandBuffer());
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600797
Tony Barbour1490c912015-07-28 10:17:20 -0600798 QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -0700799
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600800 RecordImages(m_renderTargets);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600801}
802
Tony Barbour01999182015-04-09 12:58:51 -0600803TEST_F(VkRenderTest, TriangleMRT)
Chia-I Wue09d1a72014-12-05 10:32:23 +0800804{
805 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600806 "#version 140\n"
807 "#extension GL_ARB_separate_shader_objects : enable\n"
808 "#extension GL_ARB_shading_language_420pack : enable\n"
809 "layout (location = 0) in vec4 pos;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800810 "void main() {\n"
811 " gl_Position = pos;\n"
812 "}\n";
813
814 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600815 "#version 140\n"
816 "#extension GL_ARB_separate_shader_objects : enable\n"
817 "#extension GL_ARB_shading_language_420pack : enable\n"
818 "layout (location = 0) out vec4 uFragData0;\n"
819 "layout (location = 1) out vec4 uFragData1;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800820 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600821 " uFragData0 = vec4(1.0, 0.0, 0.0, 1.0);\n"
822 " uFragData1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800823 "}\n";
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600824 const float vb_data[][2] = {
Chia-I Wue09d1a72014-12-05 10:32:23 +0800825 { -1.0f, -1.0f },
826 { 1.0f, -1.0f },
827 { -1.0f, 1.0f }
828 };
829
830 ASSERT_NO_FATAL_FAILURE(InitState());
831 ASSERT_NO_FATAL_FAILURE(InitViewport());
832
Tony Barbour01999182015-04-09 12:58:51 -0600833 VkConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000834 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800835
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600836 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
837 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800838
Tony Barbour01999182015-04-09 12:58:51 -0600839 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800840 pipelineobj.AddColorAttachment();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800841 pipelineobj.AddShader(&vs);
842 pipelineobj.AddShader(&ps);
843
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600844#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600845 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600846 MESH_BUF_ID, // Binding ID
847 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600848 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Chia-I Wue09d1a72014-12-05 10:32:23 +0800849 };
850
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600851 VkVertexInputAttributeDescription vi_attrib;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600852 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
853 vi_attrib.location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -0600854 vi_attrib.format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600855 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
Chia-I Wue09d1a72014-12-05 10:32:23 +0800856
857 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
858 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800859
Tony Barbour01999182015-04-09 12:58:51 -0600860 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800861
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700862 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
Chia-I Wue09d1a72014-12-05 10:32:23 +0800863
Tony Barboure307f582015-07-10 15:29:03 -0600864 VkPipelineColorBlendAttachmentState att = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600865 att.blendEnable = VK_FALSE;
Chia-I Wue09d1a72014-12-05 10:32:23 +0800866 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700867 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800868
Tony Barbour1490c912015-07-28 10:17:20 -0600869 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure4ed9942015-01-09 10:06:53 -0700870
Tony Barbour1490c912015-07-28 10:17:20 -0600871 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700872
Tony Barbour1490c912015-07-28 10:17:20 -0600873 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700874#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600875 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour5ed79702015-01-07 14:31:52 -0700876 pDSDumpDot((char*)"triTest2.dot");
877#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600878
Tony Barbour5ed79702015-01-07 14:31:52 -0700879 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -0600880 Draw(3, 1, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700881
882 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600883 ASSERT_VK_SUCCESS(EndCommandBuffer());
884 QueueCommandBuffer();
Tony Barbour5ed79702015-01-07 14:31:52 -0700885
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600886 RecordImages(m_renderTargets);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800887}
888
Tony Barbour01999182015-04-09 12:58:51 -0600889TEST_F(VkRenderTest, QuadWithIndexedVertexFetch)
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700890{
891 static const char *vertShaderText =
892 "#version 140\n"
893 "#extension GL_ARB_separate_shader_objects : enable\n"
894 "#extension GL_ARB_shading_language_420pack : enable\n"
895 "layout(location = 0) in vec4 pos;\n"
896 "layout(location = 1) in vec4 inColor;\n"
897 "layout(location = 0) out vec4 outColor;\n"
898 "void main() {\n"
899 " outColor = inColor;\n"
900 " gl_Position = pos;\n"
901 "}\n";
902
903
904 static const char *fragShaderText =
905 "#version 140\n"
906 "#extension GL_ARB_separate_shader_objects : enable\n"
907 "#extension GL_ARB_shading_language_420pack : enable\n"
908 "layout(location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600909 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700910 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600911 " outColor = color;\n"
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700912 "}\n";
913
914 const Vertex g_vbData[] =
915 {
916 // first tri
917 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
918 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
919 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
920
921 // second tri
922 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
923 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
924 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
925 };
926
927 const uint16_t g_idxData[6] = {
928 0, 1, 2,
929 3, 4, 5,
930 };
931
932 ASSERT_NO_FATAL_FAILURE(InitState());
933 ASSERT_NO_FATAL_FAILURE(InitViewport());
934
Tony Barbour01999182015-04-09 12:58:51 -0600935 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000936 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700937
Tony Barbour01999182015-04-09 12:58:51 -0600938 VkIndexBufferObj indexBuffer(m_device);
Tony Barbour8205d902015-04-16 15:59:00 -0600939 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), VK_INDEX_TYPE_UINT16, g_idxData);
Mark Lobodzinskid30f82a2015-02-16 14:24:23 -0600940 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700941
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -0600942 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
943 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700944
Tony Barbour01999182015-04-09 12:58:51 -0600945 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800946 pipelineobj.AddColorAttachment();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700947 pipelineobj.AddShader(&vs);
948 pipelineobj.AddShader(&ps);
949
Tony Barbour01999182015-04-09 12:58:51 -0600950 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -0600951
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700952
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600953#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600954 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600955 MESH_BIND_ID, // binding ID
956 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600957 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700958 };
959
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600960 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600961 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
962 vi_attribs[0].location = 0; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600963 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600964 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
965 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
966 vi_attribs[1].location = 1; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600967 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600968 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700969
970 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
971 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700972
973 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -0600974 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure4ed9942015-01-09 10:06:53 -0700975
Tony Barbour1490c912015-07-28 10:17:20 -0600976 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700977
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700978#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600979 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700980 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700981#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700982
Tony Barbour1490c912015-07-28 10:17:20 -0600983 BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
984 BindIndexBuffer(&indexBuffer, 0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700985
986 // render two triangles
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -0600987 DrawIndexed(6, 1, 0, 0, 0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700988
989 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600990 ASSERT_VK_SUCCESS(EndCommandBuffer());
991 QueueCommandBuffer();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700992
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600993 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700994}
995
Tony Barbour01999182015-04-09 12:58:51 -0600996TEST_F(VkRenderTest, GreyandRedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -0700997{
998 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -0700999
GregF6bef1212014-12-02 15:41:44 -07001000 static const char *vertShaderText =
1001 "#version 140\n"
1002 "#extension GL_ARB_separate_shader_objects : enable\n"
1003 "#extension GL_ARB_shading_language_420pack : enable\n"
1004 "layout (location = 0) in vec4 pos;\n"
1005 "layout (location = 0) out vec4 outColor;\n"
1006 "layout (location = 1) out vec4 outColor2;\n"
1007 "void main() {\n"
1008 " gl_Position = pos;\n"
1009 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1010 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1011 "}\n";
1012
1013 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001014 "#version 330\n"
1015 "#extension GL_ARB_separate_shader_objects : enable\n"
1016 "#extension GL_ARB_shading_language_420pack : enable\n"
1017 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1018 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1019 "layout (location = 0) in vec4 color;\n"
1020 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001021 "layout (location = 0) out vec4 outColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001022 "void main() {\n"
1023 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1024 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001025 " outColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001026 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1027 " : color2;\n"
1028 "}\n";
1029
1030 ASSERT_NO_FATAL_FAILURE(InitState());
1031 ASSERT_NO_FATAL_FAILURE(InitViewport());
1032
Tony Barbour01999182015-04-09 12:58:51 -06001033 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001034 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001035
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001036 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1037 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
GregF6bef1212014-12-02 15:41:44 -07001038
Tony Barbour01999182015-04-09 12:58:51 -06001039 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001040 pipelineobj.AddColorAttachment();
GregF6bef1212014-12-02 15:41:44 -07001041 pipelineobj.AddShader(&vs);
1042 pipelineobj.AddShader(&ps);
1043
Tony Barbour01999182015-04-09 12:58:51 -06001044 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001045
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001046#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001047 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001048 MESH_BIND_ID, // binding ID
1049 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001050 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001051 };
1052
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001053 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001054 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1055 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001056 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001057 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001058
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001059 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001060 pipelineobj.AddVertexInputBindings(&vi_binding,1);
GregF6bef1212014-12-02 15:41:44 -07001061
Tony Barbourdd4c9642015-01-09 12:55:14 -07001062 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001063
Tony Barbour1490c912015-07-28 10:17:20 -06001064 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001065
Tony Barbour1490c912015-07-28 10:17:20 -06001066 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001067
Tony Barbour1490c912015-07-28 10:17:20 -06001068 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001069#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001070 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001071 pDSDumpDot((char*)"triTest2.dot");
1072#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001073
Tony Barbourdd4c9642015-01-09 12:55:14 -07001074 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06001075 Draw(6, 1, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001076
1077 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001078 EndCommandBuffer();
1079 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001080
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001081 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001082}
1083
Tony Barbour01999182015-04-09 12:58:51 -06001084TEST_F(VkRenderTest, RedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -07001085{
1086 // This tests that we correctly handle unread fragment inputs
1087
1088 static const char *vertShaderText =
1089 "#version 140\n"
1090 "#extension GL_ARB_separate_shader_objects : enable\n"
1091 "#extension GL_ARB_shading_language_420pack : enable\n"
1092 "layout (location = 0) in vec4 pos;\n"
1093 "layout (location = 0) out vec4 outColor;\n"
1094 "layout (location = 1) out vec4 outColor2;\n"
1095 "void main() {\n"
1096 " gl_Position = pos;\n"
1097 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1098 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1099 "}\n";
1100
1101 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001102 "#version 330\n"
1103 "#extension GL_ARB_separate_shader_objects : enable\n"
1104 "#extension GL_ARB_shading_language_420pack : enable\n"
1105 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1106 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1107 "layout (location = 0) in vec4 color;\n"
1108 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001109 "layout (location = 0) out vec4 outColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001110 "void main() {\n"
1111 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1112 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001113 " outColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001114 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1115 " : color2;\n"
1116 "}\n";
1117
1118 ASSERT_NO_FATAL_FAILURE(InitState());
1119 ASSERT_NO_FATAL_FAILURE(InitViewport());
1120
Tony Barbour01999182015-04-09 12:58:51 -06001121 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001122 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001123
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001124 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1125 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
GregF6bef1212014-12-02 15:41:44 -07001126
Tony Barbour01999182015-04-09 12:58:51 -06001127 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001128 pipelineobj.AddColorAttachment();
GregF6bef1212014-12-02 15:41:44 -07001129 pipelineobj.AddShader(&vs);
1130 pipelineobj.AddShader(&ps);
1131
Tony Barbour01999182015-04-09 12:58:51 -06001132 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001133
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001134#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001135 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001136 MESH_BIND_ID, // binding ID
1137 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001138 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001139 };
1140
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001141 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001142 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1143 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001144 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001145 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001146
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001147 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001148 pipelineobj.AddVertexInputBindings(&vi_binding,1);
GregF6bef1212014-12-02 15:41:44 -07001149
Tony Barbourdd4c9642015-01-09 12:55:14 -07001150 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06001151 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001152
Tony Barbour1490c912015-07-28 10:17:20 -06001153 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001154
Tony Barbour1490c912015-07-28 10:17:20 -06001155 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001156#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001157 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001158 pDSDumpDot((char*)"triTest2.dot");
1159#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001160 // render two triangles
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06001161 Draw(6, 1, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001162
1163 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001164 EndCommandBuffer();
1165 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001166
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001167 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001168}
1169
Tony Barbour01999182015-04-09 12:58:51 -06001170TEST_F(VkRenderTest, GreyCirclesonBlueFade)
GregF6bef1212014-12-02 15:41:44 -07001171{
1172 // This tests reading gl_ClipDistance from FS
1173
1174 static const char *vertShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001175 //"#version 140\n"
GregF6bef1212014-12-02 15:41:44 -07001176 "#version 330\n"
1177 "#extension GL_ARB_separate_shader_objects : enable\n"
1178 "#extension GL_ARB_shading_language_420pack : enable\n"
1179 "out gl_PerVertex {\n"
1180 " vec4 gl_Position;\n"
1181 " float gl_ClipDistance[1];\n"
1182 "};\n"
1183 "layout (location = 0) in vec4 pos;\n"
1184 "layout (location = 0) out vec4 outColor;\n"
1185 "layout (location = 1) out vec4 outColor2;\n"
1186 "void main() {\n"
1187 " gl_Position = pos;\n"
1188 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1189 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1190 " float dists[3];\n"
1191 " dists[0] = 0.0;\n"
1192 " dists[1] = 1.0;\n"
1193 " dists[2] = 1.0;\n"
1194 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1195 "}\n";
1196
1197
1198 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001199 "#version 140\n"
1200 //"#version 330\n"
GregF6bef1212014-12-02 15:41:44 -07001201 "#extension GL_ARB_separate_shader_objects : enable\n"
1202 "#extension GL_ARB_shading_language_420pack : enable\n"
1203 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1204 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1205 "layout (location = 0) in vec4 color;\n"
1206 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001207 "layout (location = 0) out vec4 uFragColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001208 "void main() {\n"
1209 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1210 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001211 " uFragColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001212 " ? color * gl_ClipDistance[0]\n"
1213 " : color2;\n"
1214 "}\n";
1215
1216 ASSERT_NO_FATAL_FAILURE(InitState());
1217 ASSERT_NO_FATAL_FAILURE(InitViewport());
1218
Tony Barbour01999182015-04-09 12:58:51 -06001219 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001220 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001221
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001222 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1223 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
GregF6bef1212014-12-02 15:41:44 -07001224
Tony Barbour01999182015-04-09 12:58:51 -06001225 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001226 pipelineobj.AddColorAttachment();
GregF6bef1212014-12-02 15:41:44 -07001227 pipelineobj.AddShader(&vs);
1228 pipelineobj.AddShader(&ps);
1229
Tony Barbour01999182015-04-09 12:58:51 -06001230 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001231
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001232#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001233 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001234 MESH_BIND_ID, // binding ID
1235 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001236 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001237 };
1238
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001239 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001240 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1241 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001242 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001243 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001244
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001245 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001246 pipelineobj.AddVertexInputBindings(&vi_binding,1);
GregF6bef1212014-12-02 15:41:44 -07001247
Tony Barbourdd4c9642015-01-09 12:55:14 -07001248 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
GregF6bef1212014-12-02 15:41:44 -07001249
Tony Barbour1490c912015-07-28 10:17:20 -06001250 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001251
Tony Barbour1490c912015-07-28 10:17:20 -06001252 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001253
Tony Barbour1490c912015-07-28 10:17:20 -06001254 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001255#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001256 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001257 pDSDumpDot((char*)"triTest2.dot");
1258#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001259
1260 // render two triangles
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06001261 Draw(6, 1, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001262
1263 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001264 EndCommandBuffer();
1265 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001266
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001267 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001268}
Tony Barbourf43b6982014-11-25 13:18:32 -07001269
Tony Barbour01999182015-04-09 12:58:51 -06001270TEST_F(VkRenderTest, GreyCirclesonBlueDiscard)
GregF7a23c792014-12-02 17:19:34 -07001271{
1272 static const char *vertShaderText =
1273 "#version 140\n"
1274 "#extension GL_ARB_separate_shader_objects : enable\n"
1275 "#extension GL_ARB_shading_language_420pack : enable\n"
1276 "layout (location = 0) in vec4 pos;\n"
1277 "layout (location = 0) out vec4 outColor;\n"
1278 "layout (location = 1) out vec4 outColor2;\n"
1279 "void main() {\n"
1280 " gl_Position = pos;\n"
1281 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1282 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1283 "}\n";
1284
1285
1286 static const char *fragShaderText =
GregF7a23c792014-12-02 17:19:34 -07001287 "#version 330\n"
1288 "#extension GL_ARB_separate_shader_objects : enable\n"
1289 "#extension GL_ARB_shading_language_420pack : enable\n"
1290 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1291 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1292 "layout (location = 0) in vec4 color;\n"
1293 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001294 "layout (location = 0) out vec4 outColor;\n"
GregF7a23c792014-12-02 17:19:34 -07001295 "void main() {\n"
1296 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1297 " float dist_squared = dot(pos, pos);\n"
1298 " if (dist_squared < 100.0)\n"
1299 " discard;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001300 " outColor = (dist_squared < 400.0)\n"
GregF7a23c792014-12-02 17:19:34 -07001301 " ? color\n"
1302 " : color2;\n"
1303 "}\n";
1304
1305 ASSERT_NO_FATAL_FAILURE(InitState());
1306 ASSERT_NO_FATAL_FAILURE(InitViewport());
1307
Tony Barbour01999182015-04-09 12:58:51 -06001308 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001309 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001310
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001311 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1312 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
GregF7a23c792014-12-02 17:19:34 -07001313
Tony Barbour01999182015-04-09 12:58:51 -06001314 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001315 pipelineobj.AddColorAttachment();
GregF7a23c792014-12-02 17:19:34 -07001316 pipelineobj.AddShader(&vs);
1317 pipelineobj.AddShader(&ps);
1318
Tony Barbour01999182015-04-09 12:58:51 -06001319 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001320
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001321#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001322 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001323 MESH_BIND_ID, // binding ID
1324 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001325 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF7a23c792014-12-02 17:19:34 -07001326 };
1327
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001328 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001329 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1330 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001331 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001332 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF7a23c792014-12-02 17:19:34 -07001333
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001334 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF7a23c792014-12-02 17:19:34 -07001335 pipelineobj.AddVertexInputBindings(&vi_binding,1);
GregF7a23c792014-12-02 17:19:34 -07001336
Tony Barbourdd4c9642015-01-09 12:55:14 -07001337 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001338
Tony Barbour1490c912015-07-28 10:17:20 -06001339 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001340
Tony Barbour1490c912015-07-28 10:17:20 -06001341 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001342
Tony Barbour1490c912015-07-28 10:17:20 -06001343 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001344#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001345 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001346 pDSDumpDot((char*)"triTest2.dot");
1347#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001348
1349 // render two triangles
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06001350 Draw(6, 1, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001351
1352 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001353 EndCommandBuffer();
1354 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001355
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001356 RecordImages(m_renderTargets);
GregF7a23c792014-12-02 17:19:34 -07001357}
1358
1359
Tony Barbour01999182015-04-09 12:58:51 -06001360TEST_F(VkRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001361{
1362 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001363 "#version 140\n"
1364 "#extension GL_ARB_separate_shader_objects : enable\n"
1365 "#extension GL_ARB_shading_language_420pack : enable\n"
1366 "\n"
1367 "layout(binding = 0) uniform buf {\n"
1368 " mat4 MVP;\n"
1369 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001370 "void main() {\n"
1371 " vec2 vertices[3];"
1372 " vertices[0] = vec2(-0.5, -0.5);\n"
1373 " vertices[1] = vec2( 0.5, -0.5);\n"
1374 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001375 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001376 "}\n";
1377
1378 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001379 "#version 140\n"
1380 "#extension GL_ARB_separate_shader_objects : enable\n"
1381 "#extension GL_ARB_shading_language_420pack : enable\n"
1382 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001383 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001384 " outColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001385 "}\n";
1386
Tony Barbourf43b6982014-11-25 13:18:32 -07001387 ASSERT_NO_FATAL_FAILURE(InitState());
1388 ASSERT_NO_FATAL_FAILURE(InitViewport());
1389
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001390 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001391 glm::mat4 Projection = glm::mat4(1.0f);
1392 glm::mat4 View = glm::mat4(1.0f);
1393 glm::mat4 Model = glm::mat4(1.0f);
1394 glm::mat4 MVP = Projection * View * Model;
1395 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1396
Tony Barbour01999182015-04-09 12:58:51 -06001397 VkConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001398 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1399 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001400
Tony Barbour01999182015-04-09 12:58:51 -06001401 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001402 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001403 pipelineobj.AddShader(&vs);
1404 pipelineobj.AddShader(&ps);
1405
1406 // Create descriptor set and attach the constant buffer to it
Tony Barbour01999182015-04-09 12:58:51 -06001407 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001408 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001409
Tony Barbourdd4c9642015-01-09 12:55:14 -07001410 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis7f7b4422015-08-18 14:24:32 -06001411
1412 VkCmdBufferBeginInfo cbBeginInfo;
1413 memset(&cbBeginInfo, 0, sizeof(VkCmdBufferBeginInfo));
1414 cbBeginInfo.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1415 cbBeginInfo.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT;
1416 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barbourf43b6982014-11-25 13:18:32 -07001417
Tony Barbour1490c912015-07-28 10:17:20 -06001418 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001419
Tony Barbourdd4c9642015-01-09 12:55:14 -07001420#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001421 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001422 pDSDumpDot((char*)"triTest2.dot");
1423#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001424
1425 // render two triangles
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06001426 Draw(6, 1, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001427
1428 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001429 EndCommandBuffer();
1430 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001431
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001432 RecordImages(m_renderTargets);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001433
Tony Barbour1490c912015-07-28 10:17:20 -06001434 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001435}
1436
Tony Barbour01999182015-04-09 12:58:51 -06001437TEST_F(VkRenderTest, MixTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07001438{
1439 // This tests location applied to varyings. Notice that we have switched foo
1440 // and bar in the FS. The triangle should be blended with red, green and blue
1441 // corners.
1442 static const char *vertShaderText =
1443 "#version 140\n"
1444 "#extension GL_ARB_separate_shader_objects : enable\n"
1445 "#extension GL_ARB_shading_language_420pack : enable\n"
1446 "layout (location=0) out vec4 bar;\n"
1447 "layout (location=1) out vec4 foo;\n"
1448 "layout (location=2) out float scale;\n"
1449 "vec2 vertices[3];\n"
1450 "void main() {\n"
1451 " vertices[0] = vec2(-1.0, -1.0);\n"
1452 " vertices[1] = vec2( 1.0, -1.0);\n"
1453 " vertices[2] = vec2( 0.0, 1.0);\n"
1454 "vec4 colors[3];\n"
1455 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1456 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1457 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1458 " foo = colors[gl_VertexID % 3];\n"
1459 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1460 " scale = 1.0;\n"
1461 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1462 "}\n";
1463
1464 static const char *fragShaderText =
1465 "#version 140\n"
1466 "#extension GL_ARB_separate_shader_objects : enable\n"
1467 "#extension GL_ARB_shading_language_420pack : enable\n"
1468 "layout (location = 1) in vec4 bar;\n"
1469 "layout (location = 0) in vec4 foo;\n"
1470 "layout (location = 2) in float scale;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001471 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001472 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001473 " outColor = bar * scale + foo * (1.0-scale);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001474 "}\n";
1475
1476 ASSERT_NO_FATAL_FAILURE(InitState());
1477 ASSERT_NO_FATAL_FAILURE(InitViewport());
1478
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001479 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1480 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001481
Tony Barbour01999182015-04-09 12:58:51 -06001482 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001483 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001484 pipelineobj.AddShader(&vs);
1485 pipelineobj.AddShader(&ps);
1486
Tony Barbour01999182015-04-09 12:58:51 -06001487 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06001488 descriptorSet.AppendDummy();
Tony Barbourf43b6982014-11-25 13:18:32 -07001489
Tony Barbourdd4c9642015-01-09 12:55:14 -07001490 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001491
Tony Barbour1490c912015-07-28 10:17:20 -06001492 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001493
Tony Barbour1490c912015-07-28 10:17:20 -06001494 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001495
1496#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001497 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001498 pDSDumpDot((char*)"triTest2.dot");
1499#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001500
Tony Barbourdd4c9642015-01-09 12:55:14 -07001501 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06001502 Draw(3, 1, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001503
1504 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001505 EndCommandBuffer();
1506 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001507
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001508 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001509}
1510
Tony Barbour01999182015-04-09 12:58:51 -06001511TEST_F(VkRenderTest, QuadVertFetchAndVertID)
Tony Barbourf43b6982014-11-25 13:18:32 -07001512{
1513 // This tests that attributes work in the presence of gl_VertexID
1514
1515 static const char *vertShaderText =
1516 "#version 140\n"
1517 "#extension GL_ARB_separate_shader_objects : enable\n"
1518 "#extension GL_ARB_shading_language_420pack : enable\n"
1519 //XYZ1( -1, -1, -1 )
1520 "layout (location = 0) in vec4 pos;\n"
1521 //XYZ1( 0.f, 0.f, 0.f )
1522 "layout (location = 1) in vec4 inColor;\n"
1523 "layout (location = 0) out vec4 outColor;\n"
1524 "void main() {\n"
1525 " outColor = inColor;\n"
1526 " vec4 vertices[3];"
1527 " vertices[gl_VertexID % 3] = pos;\n"
1528 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1529 "}\n";
1530
1531
1532 static const char *fragShaderText =
1533 "#version 140\n"
1534 "#extension GL_ARB_separate_shader_objects : enable\n"
1535 "#extension GL_ARB_shading_language_420pack : enable\n"
1536 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001537 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001538 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001539 " outColor = color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001540 "}\n";
1541
1542 ASSERT_NO_FATAL_FAILURE(InitState());
1543 ASSERT_NO_FATAL_FAILURE(InitViewport());
1544
Tony Barbour01999182015-04-09 12:58:51 -06001545 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001546 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001547
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001548 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1549 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001550
Tony Barbour01999182015-04-09 12:58:51 -06001551 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001552 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001553 pipelineobj.AddShader(&vs);
1554 pipelineobj.AddShader(&ps);
1555
Tony Barbour01999182015-04-09 12:58:51 -06001556 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001557
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001558#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001559 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001560 MESH_BUF_ID, // Binding ID
1561 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001562 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001563 };
1564
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001565 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001566 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1567 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001568 vi_attribs[0].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001569 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1570 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1571 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001572 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001573 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001574
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001575 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001576 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barbourf43b6982014-11-25 13:18:32 -07001577
Tony Barbourdd4c9642015-01-09 12:55:14 -07001578 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001579
Tony Barbour1490c912015-07-28 10:17:20 -06001580 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001581
Tony Barbour1490c912015-07-28 10:17:20 -06001582 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001583
Tony Barbour1490c912015-07-28 10:17:20 -06001584 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001585#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001586 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001587 pDSDumpDot((char*)"triTest2.dot");
1588#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001589
1590 // render two triangles
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06001591 Draw(6, 1, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001592
1593 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001594 EndCommandBuffer();
1595 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001596
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001597 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001598}
1599
Tony Barbour01999182015-04-09 12:58:51 -06001600TEST_F(VkRenderTest, QuadSparseVertFetch)
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001601{
1602 // This tests that attributes work in the presence of gl_VertexID
1603
1604 static const char *vertShaderText =
1605 "#version 140\n"
1606 "#extension GL_ARB_separate_shader_objects : enable\n"
1607 "#extension GL_ARB_shading_language_420pack : enable\n"
1608 //XYZ1( -1, -1, -1 )
1609 "layout (location = 1) in vec4 pos;\n"
1610 "layout (location = 4) in vec4 inColor;\n"
1611 //XYZ1( 0.f, 0.f, 0.f )
1612 "layout (location = 0) out vec4 outColor;\n"
1613 "void main() {\n"
1614 " outColor = inColor;\n"
1615 " gl_Position = pos;\n"
1616 "}\n";
1617
1618
1619 static const char *fragShaderText =
1620 "#version 140\n"
1621 "#extension GL_ARB_separate_shader_objects : enable\n"
1622 "#extension GL_ARB_shading_language_420pack : enable\n"
1623 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001624 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001625 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001626 " outColor = color;\n"
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001627 "}\n";
1628
1629 ASSERT_NO_FATAL_FAILURE(InitState());
1630 ASSERT_NO_FATAL_FAILURE(InitViewport());
1631
1632 struct VDATA
1633 {
1634 float t1, t2, t3, t4; // filler data
1635 float posX, posY, posZ, posW; // Position data
1636 float r, g, b, a; // Color
1637 };
1638 const struct VDATA vData[] =
1639 {
1640 { XYZ1(0, 0, 0), XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
1641 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1642 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1643 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1644 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1645 { XYZ1(0, 0, 0), XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
1646 };
1647
Tony Barbour01999182015-04-09 12:58:51 -06001648 VkConstantBufferObj meshBuffer(m_device,sizeof(vData)/sizeof(vData[0]),sizeof(vData[0]), vData);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001649 meshBuffer.BufferMemoryBarrier();
1650
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001651 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1652 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001653
Tony Barbour01999182015-04-09 12:58:51 -06001654 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001655 pipelineobj.AddColorAttachment();
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001656 pipelineobj.AddShader(&vs);
1657 pipelineobj.AddShader(&ps);
1658
Tony Barbour01999182015-04-09 12:58:51 -06001659 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001660
1661#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001662 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001663 MESH_BUF_ID, // Binding ID
1664 sizeof(vData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001665 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001666 };
1667
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001668 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001669 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1670 vi_attribs[0].location = 4;
Tony Barbour8205d902015-04-16 15:59:00 -06001671 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001672 vi_attribs[0].offsetInBytes = sizeof(float) * 4 * 2; // Offset of first element in bytes from base of vertex
1673 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1674 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001675 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001676 vi_attribs[1].offsetInBytes = sizeof(float) * 4 * 1; // Offset of first element in bytes from base of vertex
1677
1678 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
1679 pipelineobj.AddVertexInputBindings(&vi_binding, 1);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001680
1681 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001682
Tony Barbour1490c912015-07-28 10:17:20 -06001683 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001684
Tony Barbour1490c912015-07-28 10:17:20 -06001685 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001686
Tony Barbour1490c912015-07-28 10:17:20 -06001687 BindVertexBuffer(&meshBuffer, 0, MESH_BUF_ID);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001688#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001689 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001690 pDSDumpDot((char*)"triTest2.dot");
1691#endif
1692
1693 // render two triangles
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06001694 Draw(6, 1, 0, 0);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001695
1696 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001697 EndCommandBuffer();
1698 QueueCommandBuffer();
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001699
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001700 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001701}
1702
Tony Barbour01999182015-04-09 12:58:51 -06001703TEST_F(VkRenderTest, TriVertFetchDeadAttr)
Tony Barbourf43b6982014-11-25 13:18:32 -07001704{
1705 // This tests that attributes work in the presence of gl_VertexID
1706 // and a dead attribute in position 0. Draws a triangle with yellow,
1707 // red and green corners, starting at top and going clockwise.
1708
1709 static const char *vertShaderText =
1710 "#version 140\n"
1711 "#extension GL_ARB_separate_shader_objects : enable\n"
1712 "#extension GL_ARB_shading_language_420pack : enable\n"
1713 //XYZ1( -1, -1, -1 )
1714 "layout (location = 0) in vec4 pos;\n"
1715 //XYZ1( 0.f, 0.f, 0.f )
1716 "layout (location = 1) in vec4 inColor;\n"
1717 "layout (location = 0) out vec4 outColor;\n"
1718 "void main() {\n"
1719 " outColor = inColor;\n"
1720 " vec2 vertices[3];"
1721 " vertices[0] = vec2(-1.0, -1.0);\n"
1722 " vertices[1] = vec2( 1.0, -1.0);\n"
1723 " vertices[2] = vec2( 0.0, 1.0);\n"
1724 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1725 "}\n";
1726
1727
1728 static const char *fragShaderText =
1729 "#version 140\n"
1730 "#extension GL_ARB_separate_shader_objects : enable\n"
1731 "#extension GL_ARB_shading_language_420pack : enable\n"
1732 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001733 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001734 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001735 " outColor = color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001736 "}\n";
1737
1738 ASSERT_NO_FATAL_FAILURE(InitState());
1739 ASSERT_NO_FATAL_FAILURE(InitViewport());
1740
Tony Barbour01999182015-04-09 12:58:51 -06001741 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001742 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001743
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001744 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1745 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001746
Tony Barbour01999182015-04-09 12:58:51 -06001747 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001748 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001749 pipelineobj.AddShader(&vs);
1750 pipelineobj.AddShader(&ps);
1751
Tony Barbour01999182015-04-09 12:58:51 -06001752 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001753
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001754#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001755 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001756 MESH_BUF_ID, // Binding ID
1757 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001758 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001759 };
1760
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001761 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001762 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1763 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001764 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001765 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1766 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1767 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001768 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001769 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001770
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001771 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001772 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barbourf43b6982014-11-25 13:18:32 -07001773
Tony Barbourdd4c9642015-01-09 12:55:14 -07001774 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourf43b6982014-11-25 13:18:32 -07001775
Tony Barbour1490c912015-07-28 10:17:20 -06001776 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001777
Tony Barbour1490c912015-07-28 10:17:20 -06001778 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001779
Tony Barbour1490c912015-07-28 10:17:20 -06001780 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001781#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001782 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001783 pDSDumpDot((char*)"triTest2.dot");
1784#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001785
1786 // render two triangles
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06001787 Draw(6, 1, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001788
1789 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001790 EndCommandBuffer();
1791 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001792
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001793 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001794}
1795
Tony Barbour01999182015-04-09 12:58:51 -06001796TEST_F(VkRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001797{
1798 static const char *vertShaderText =
1799 "#version 140\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001800 "#extension GL_ARB_separate_shader_objects : enable\n"
1801 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbour6baf4402015-09-29 14:56:09 -06001802 "layout (binding = 0) uniform bufferVals {\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001803 " mat4 mvp;\n"
1804 "} myBufferVals;\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001805 "layout (location = 0) in vec4 pos;\n"
1806 "layout (location = 1) in vec4 inColor;\n"
Cody Northrop74a2d2c2015-06-16 17:32:04 -06001807 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001808 "void main() {\n"
1809 " outColor = inColor;\n"
1810 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001811 " gl_Position.y = -gl_Position.y;\n"
1812 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001813 "}\n";
1814
1815 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001816 "#version 140\n"
1817 "#extension GL_ARB_separate_shader_objects : enable\n"
1818 "#extension GL_ARB_shading_language_420pack : enable\n"
1819 "layout (location = 0) in vec4 color;\n"
1820 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001821 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001822 " outColor = color;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001823 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001824 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001825
Tony Barbourf43b6982014-11-25 13:18:32 -07001826 glm::mat4 View = glm::lookAt(
1827 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1828 glm::vec3(0,0,0), // and looks at the origin
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001829 glm::vec3(0,-1,0) // Head is up (set to 0,-1,0 to look upside-down)
Tony Barbourf43b6982014-11-25 13:18:32 -07001830 );
1831
1832 glm::mat4 Model = glm::mat4(1.0f);
1833
1834 glm::mat4 MVP = Projection * View * Model;
1835
1836 ASSERT_NO_FATAL_FAILURE(InitState());
1837 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wu9e81ebb2015-07-09 10:16:34 +08001838 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Chia-I Wuc278df82015-07-07 11:50:03 +08001839 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height, m_depth_stencil_fmt);
Tony Barbourf43b6982014-11-25 13:18:32 -07001840
Tony Barbour01999182015-04-09 12:58:51 -06001841 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
Tony Barbourf43b6982014-11-25 13:18:32 -07001842 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1843
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001844 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07001845
Tony Barbour01999182015-04-09 12:58:51 -06001846 VkConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001847 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1848 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001849
Tony Barbour01999182015-04-09 12:58:51 -06001850 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001851 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001852 pipelineobj.AddShader(&vs);
1853 pipelineobj.AddShader(&ps);
1854
Tony Barboure307f582015-07-10 15:29:03 -06001855 VkPipelineDepthStencilStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001856 ds_state.depthTestEnable = VK_TRUE;
1857 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06001858 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Cody Northrope4bc6942015-08-26 10:01:32 -06001859 ds_state.depthBoundsTestEnable = VK_FALSE;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001860 ds_state.stencilTestEnable = VK_FALSE;
1861 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
1862 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
1863 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06001864 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001865 ds_state.front = ds_state.back;
1866 pipelineobj.SetDepthStencil(&ds_state);
1867
Tony Barbour01999182015-04-09 12:58:51 -06001868 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001869 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001870
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001871#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001872 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001873 MESH_BUF_ID, // Binding ID
1874 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001875 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001876 };
Tony Barbourf43b6982014-11-25 13:18:32 -07001877
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001878 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001879 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1880 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001881 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001882 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1883 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1884 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001885 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001886 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001887
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001888 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001889 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barbourf43b6982014-11-25 13:18:32 -07001890
Tony Barbour17c6ab12015-03-27 17:03:18 -06001891 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour17c6ab12015-03-27 17:03:18 -06001892
Tony Barbour1490c912015-07-28 10:17:20 -06001893 ASSERT_VK_SUCCESS(BeginCommandBuffer());
1894 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001895
Tony Barbour1490c912015-07-28 10:17:20 -06001896 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barboure4ed9942015-01-09 10:06:53 -07001897#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001898 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barboure4ed9942015-01-09 10:06:53 -07001899 pDSDumpDot((char*)"triTest2.dot");
1900#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001901
1902 // render triangles
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06001903 Draw(36, 1, 0, 0);
Tony Barboure4ed9942015-01-09 10:06:53 -07001904
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001905
Tony Barboure4ed9942015-01-09 10:06:53 -07001906 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001907 EndCommandBuffer();
1908 QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -07001909
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001910 RecordImages(m_renderTargets);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001911}
1912
Tony Barbour01999182015-04-09 12:58:51 -06001913TEST_F(VkRenderTest, VSTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07001914{
1915 // The expected result from this test is a green and red triangle;
1916 // one red vertex on the left, two green vertices on the right.
1917 static const char *vertShaderText =
Cody Northrop74a2d2c2015-06-16 17:32:04 -06001918 "#version 140\n"
1919 "#extension GL_ARB_separate_shader_objects : enable\n"
1920 "#extension GL_ARB_shading_language_420pack : enable\n"
1921 "layout (location = 0) out vec4 texColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001922 "uniform sampler2D surface;\n"
1923 "void main() {\n"
1924 " vec2 vertices[3];"
1925 " vertices[0] = vec2(-0.5, -0.5);\n"
1926 " vertices[1] = vec2( 0.5, -0.5);\n"
1927 " vertices[2] = vec2( 0.5, 0.5);\n"
1928 " vec2 positions[3];"
1929 " positions[0] = vec2( 0.0, 0.0);\n"
1930 " positions[1] = vec2( 0.25, 0.1);\n"
1931 " positions[2] = vec2( 0.1, 0.25);\n"
1932 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1933 " texColor = textureLod(surface, samplePos, 0.0);\n"
1934 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1935 "}\n";
1936
1937 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001938 "#version 140\n"
1939 "#extension GL_ARB_separate_shader_objects : enable\n"
1940 "#extension GL_ARB_shading_language_420pack : enable\n"
1941 "layout (location = 0) in vec4 texColor;\n"
1942 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001943 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001944 " outColor = texColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001945 "}\n";
1946
1947 ASSERT_NO_FATAL_FAILURE(InitState());
1948 ASSERT_NO_FATAL_FAILURE(InitViewport());
1949
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001950 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
1951 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbour01999182015-04-09 12:58:51 -06001952 VkSamplerObj sampler(m_device);
1953 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001954
Tony Barbour01999182015-04-09 12:58:51 -06001955 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001956 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001957 pipelineobj.AddShader(&vs);
1958 pipelineobj.AddShader(&ps);
1959
Tony Barbour01999182015-04-09 12:58:51 -06001960 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001961 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001962
Tony Barbourdd4c9642015-01-09 12:55:14 -07001963 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06001964 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourf43b6982014-11-25 13:18:32 -07001965
Tony Barbour1490c912015-07-28 10:17:20 -06001966 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001967
1968#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001969 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001970 pDSDumpDot((char*)"triTest2.dot");
1971#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001972
Tony Barbourdd4c9642015-01-09 12:55:14 -07001973 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06001974 Draw(3, 1, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001975
1976 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001977 EndCommandBuffer();
1978 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001979
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001980 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001981}
GregFd6ebdb32015-06-03 18:40:50 -06001982
1983
1984
Tony Barbour01999182015-04-09 12:58:51 -06001985TEST_F(VkRenderTest, TexturedTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07001986{
1987 // The expected result from this test is a red and green checkered triangle
1988 static const char *vertShaderText =
1989 "#version 140\n"
1990 "#extension GL_ARB_separate_shader_objects : enable\n"
1991 "#extension GL_ARB_shading_language_420pack : enable\n"
1992 "layout (location = 0) out vec2 samplePos;\n"
1993 "void main() {\n"
1994 " vec2 vertices[3];"
1995 " vertices[0] = vec2(-0.5, -0.5);\n"
1996 " vertices[1] = vec2( 0.5, -0.5);\n"
1997 " vertices[2] = vec2( 0.5, 0.5);\n"
1998 " vec2 positions[3];"
1999 " positions[0] = vec2( 0.0, 0.0);\n"
2000 " positions[1] = vec2( 1.0, 0.0);\n"
2001 " positions[2] = vec2( 1.0, 1.0);\n"
2002 " samplePos = positions[gl_VertexID % 3];\n"
2003 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2004 "}\n";
2005
2006 static const char *fragShaderText =
2007 "#version 140\n"
2008 "#extension GL_ARB_separate_shader_objects : enable\n"
2009 "#extension GL_ARB_shading_language_420pack : enable\n"
2010 "layout (location = 0) in vec2 samplePos;\n"
2011 "layout (binding = 0) uniform sampler2D surface;\n"
2012 "layout (location=0) out vec4 outColor;\n"
2013 "void main() {\n"
2014 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2015 " outColor = texColor;\n"
2016 "}\n";
2017
2018 ASSERT_NO_FATAL_FAILURE(InitState());
2019 ASSERT_NO_FATAL_FAILURE(InitViewport());
2020
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002021 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2022 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbour01999182015-04-09 12:58:51 -06002023 VkSamplerObj sampler(m_device);
2024 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002025
Tony Barbour01999182015-04-09 12:58:51 -06002026 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002027 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002028 pipelineobj.AddShader(&vs);
2029 pipelineobj.AddShader(&ps);
2030
Tony Barbour01999182015-04-09 12:58:51 -06002031 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002032 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002033
Tony Barbourdd4c9642015-01-09 12:55:14 -07002034 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002035 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002036
Tony Barbour1490c912015-07-28 10:17:20 -06002037 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002038
2039#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002040 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002041 pDSDumpDot((char*)"triTest2.dot");
2042#endif
2043 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06002044 Draw(3, 1, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002045
2046 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002047 EndCommandBuffer();
2048 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002049
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002050 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002051}
Tony Barbour01999182015-04-09 12:58:51 -06002052TEST_F(VkRenderTest, TexturedTriangleClip)
Tony Barbourf43b6982014-11-25 13:18:32 -07002053{
2054 // The expected result from this test is a red and green checkered triangle
2055 static const char *vertShaderText =
2056 "#version 330\n"
2057 "#extension GL_ARB_separate_shader_objects : enable\n"
2058 "#extension GL_ARB_shading_language_420pack : enable\n"
2059 "layout (location = 0) out vec2 samplePos;\n"
2060 "out gl_PerVertex {\n"
2061 " vec4 gl_Position;\n"
2062 " float gl_ClipDistance[1];\n"
2063 "};\n"
2064 "void main() {\n"
2065 " vec2 vertices[3];"
2066 " vertices[0] = vec2(-0.5, -0.5);\n"
2067 " vertices[1] = vec2( 0.5, -0.5);\n"
2068 " vertices[2] = vec2( 0.5, 0.5);\n"
2069 " vec2 positions[3];"
2070 " positions[0] = vec2( 0.0, 0.0);\n"
2071 " positions[1] = vec2( 1.0, 0.0);\n"
2072 " positions[2] = vec2( 1.0, 1.0);\n"
2073 " float dists[3];\n"
2074 " dists[0] = 1.0;\n"
2075 " dists[1] = 1.0;\n"
2076 " dists[2] = -1.0;\n"
2077 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2078 " samplePos = positions[gl_VertexID % 3];\n"
2079 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2080 "}\n";
2081
2082 static const char *fragShaderText =
2083 "#version 140\n"
2084 "#extension GL_ARB_separate_shader_objects : enable\n"
2085 "#extension GL_ARB_shading_language_420pack : enable\n"
2086 "layout (location = 0) in vec2 samplePos;\n"
2087 "layout (binding = 0) uniform sampler2D surface;\n"
2088 "layout (location=0) out vec4 outColor;\n"
2089 "void main() {\n"
2090 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2091 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2092 " outColor = texColor;\n"
2093 "}\n";
2094
2095
2096 ASSERT_NO_FATAL_FAILURE(InitState());
2097 ASSERT_NO_FATAL_FAILURE(InitViewport());
2098
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002099 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2100 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbour01999182015-04-09 12:58:51 -06002101 VkSamplerObj sampler(m_device);
2102 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002103
Tony Barbour01999182015-04-09 12:58:51 -06002104 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002105 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002106 pipelineobj.AddShader(&vs);
2107 pipelineobj.AddShader(&ps);
2108
Tony Barbour01999182015-04-09 12:58:51 -06002109 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002110 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002111
Tony Barbourdd4c9642015-01-09 12:55:14 -07002112 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002113 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002114
Tony Barbour1490c912015-07-28 10:17:20 -06002115 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002116
2117#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002118 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002119 pDSDumpDot((char*)"triTest2.dot");
2120#endif
2121 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06002122 Draw(3, 1, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002123
2124 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002125 EndCommandBuffer();
2126 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002127
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002128 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002129}
GregFd6ebdb32015-06-03 18:40:50 -06002130
Tony Barbour01999182015-04-09 12:58:51 -06002131TEST_F(VkRenderTest, FSTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002132{
2133 // The expected result from this test is a red and green checkered triangle
2134 static const char *vertShaderText =
2135 "#version 140\n"
2136 "#extension GL_ARB_separate_shader_objects : enable\n"
2137 "#extension GL_ARB_shading_language_420pack : enable\n"
2138 "layout (location = 0) out vec2 samplePos;\n"
2139 "void main() {\n"
2140 " vec2 vertices[3];"
2141 " vertices[0] = vec2(-0.5, -0.5);\n"
2142 " vertices[1] = vec2( 0.5, -0.5);\n"
2143 " vertices[2] = vec2( 0.5, 0.5);\n"
2144 " vec2 positions[3];"
2145 " positions[0] = vec2( 0.0, 0.0);\n"
2146 " positions[1] = vec2( 1.0, 0.0);\n"
2147 " positions[2] = vec2( 1.0, 1.0);\n"
2148 " samplePos = positions[gl_VertexID % 3];\n"
2149 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2150 "}\n";
2151
2152 static const char *fragShaderText =
2153 "#version 140\n"
2154 "#extension GL_ARB_separate_shader_objects : enable\n"
2155 "#extension GL_ARB_shading_language_420pack : enable\n"
2156 "layout (location = 0) in vec2 samplePos;\n"
2157 "layout (binding = 0) uniform sampler2D surface;\n"
2158 "layout (location=0) out vec4 outColor;\n"
2159 "void main() {\n"
2160 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2161 " outColor = texColor;\n"
2162 "}\n";
2163
2164 ASSERT_NO_FATAL_FAILURE(InitState());
2165 ASSERT_NO_FATAL_FAILURE(InitViewport());
2166
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002167 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2168 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbour01999182015-04-09 12:58:51 -06002169 VkSamplerObj sampler(m_device);
2170 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002171
Tony Barbour01999182015-04-09 12:58:51 -06002172 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002173 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002174 pipelineobj.AddShader(&vs);
2175 pipelineobj.AddShader(&ps);
2176
Tony Barbour01999182015-04-09 12:58:51 -06002177 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002178 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002179
Tony Barbourdd4c9642015-01-09 12:55:14 -07002180 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002181 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002182
Tony Barbour1490c912015-07-28 10:17:20 -06002183 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002184
2185#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002186 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002187 pDSDumpDot((char*)"triTest2.dot");
2188#endif
2189 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06002190 Draw(3, 1, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002191
2192 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002193 EndCommandBuffer();
2194 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002195
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002196 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002197}
Tony Barbour01999182015-04-09 12:58:51 -06002198TEST_F(VkRenderTest, SamplerBindingsTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002199{
2200 // This test sets bindings on the samplers
2201 // For now we are asserting that sampler and texture pairs
2202 // march in lock step, and are set via GLSL binding. This can
2203 // and will probably change.
2204 // The sampler bindings should match the sampler and texture slot
2205 // number set up by the application.
2206 // This test will result in a blue triangle
2207 static const char *vertShaderText =
2208 "#version 140\n"
2209 "#extension GL_ARB_separate_shader_objects : enable\n"
2210 "#extension GL_ARB_shading_language_420pack : enable\n"
2211 "layout (location = 0) out vec4 samplePos;\n"
2212 "void main() {\n"
2213 " vec2 vertices[3];"
2214 " vertices[0] = vec2(-0.5, -0.5);\n"
2215 " vertices[1] = vec2( 0.5, -0.5);\n"
2216 " vertices[2] = vec2( 0.5, 0.5);\n"
2217 " vec2 positions[3];"
2218 " positions[0] = vec2( 0.0, 0.0);\n"
2219 " positions[1] = vec2( 1.0, 0.0);\n"
2220 " positions[2] = vec2( 1.0, 1.0);\n"
2221 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2222 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2223 "}\n";
2224
2225 static const char *fragShaderText =
2226 "#version 140\n"
2227 "#extension GL_ARB_separate_shader_objects : enable\n"
2228 "#extension GL_ARB_shading_language_420pack : enable\n"
2229 "layout (location = 0) in vec4 samplePos;\n"
2230 "layout (binding = 0) uniform sampler2D surface0;\n"
2231 "layout (binding = 1) uniform sampler2D surface1;\n"
2232 "layout (binding = 12) uniform sampler2D surface2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06002233 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002234 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002235 " outColor = textureLod(surface2, samplePos.xy, 0.0);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002236 "}\n";
2237
2238 ASSERT_NO_FATAL_FAILURE(InitState());
2239 ASSERT_NO_FATAL_FAILURE(InitViewport());
2240
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002241 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2242 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002243
Tony Barbour01999182015-04-09 12:58:51 -06002244 VkSamplerObj sampler1(m_device);
2245 VkSamplerObj sampler2(m_device);
2246 VkSamplerObj sampler3(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002247
Tony Barbour2f421a02015-04-01 16:38:10 -06002248 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
Tony Barbour01999182015-04-09 12:58:51 -06002249 VkTextureObj texture1(m_device, tex_colors); // Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002250 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
Tony Barbour01999182015-04-09 12:58:51 -06002251 VkTextureObj texture2(m_device, tex_colors); // Green
Tony Barbour2f421a02015-04-01 16:38:10 -06002252 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
Tony Barbour01999182015-04-09 12:58:51 -06002253 VkTextureObj texture3(m_device, tex_colors); // Blue
Tony Barbourf43b6982014-11-25 13:18:32 -07002254
Tony Barbour01999182015-04-09 12:58:51 -06002255 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002256 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002257 pipelineobj.AddShader(&vs);
2258 pipelineobj.AddShader(&ps);
2259
Tony Barbour01999182015-04-09 12:58:51 -06002260 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002261 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2262 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2263 for (int i = 0; i < 10; i++)
2264 descriptorSet.AppendDummy();
2265 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002266
Tony Barbourdd4c9642015-01-09 12:55:14 -07002267 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002268 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002269
Tony Barbour1490c912015-07-28 10:17:20 -06002270 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002271
2272#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002273 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002274 pDSDumpDot((char*)"triTest2.dot");
2275#endif
2276 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06002277 Draw(3, 1, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002278
2279 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002280 EndCommandBuffer();
2281 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002282
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002283 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002284}
2285
Tony Barbour01999182015-04-09 12:58:51 -06002286TEST_F(VkRenderTest, TriangleVSUniformBlock)
Tony Barbourf43b6982014-11-25 13:18:32 -07002287{
2288 // The expected result from this test is a blue triangle
2289
2290 static const char *vertShaderText =
2291 "#version 140\n"
2292 "#extension GL_ARB_separate_shader_objects : enable\n"
2293 "#extension GL_ARB_shading_language_420pack : enable\n"
2294 "layout (location = 0) out vec4 outColor;\n"
Tony Barbour6baf4402015-09-29 14:56:09 -06002295 "layout (binding = 0) uniform bufferVals {\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002296 " vec4 red;\n"
2297 " vec4 green;\n"
2298 " vec4 blue;\n"
2299 " vec4 white;\n"
2300 "} myBufferVals;\n"
2301 "void main() {\n"
2302 " vec2 vertices[3];"
2303 " vertices[0] = vec2(-0.5, -0.5);\n"
2304 " vertices[1] = vec2( 0.5, -0.5);\n"
2305 " vertices[2] = vec2( 0.5, 0.5);\n"
2306 " outColor = myBufferVals.blue;\n"
2307 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2308 "}\n";
2309
2310 static const char *fragShaderText =
2311 "#version 140\n"
2312 "#extension GL_ARB_separate_shader_objects : enable\n"
2313 "#extension GL_ARB_shading_language_420pack : enable\n"
2314 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -06002315 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002316 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002317 " outColor = inColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002318 "}\n";
2319
2320 ASSERT_NO_FATAL_FAILURE(InitState());
2321 ASSERT_NO_FATAL_FAILURE(InitViewport());
2322
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002323 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2324 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002325
2326 // Let's populate our buffer with the following:
2327 // vec4 red;
2328 // vec4 green;
2329 // vec4 blue;
2330 // vec4 white;
2331 const int valCount = 4 * 4;
2332 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2333 0.0, 1.0, 0.0, 1.0,
2334 0.0, 0.0, 1.0, 1.0,
2335 1.0, 1.0, 1.0, 1.0 };
2336
Tony Barbour01999182015-04-09 12:58:51 -06002337 VkConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002338
Tony Barbour01999182015-04-09 12:58:51 -06002339 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002340 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002341 pipelineobj.AddShader(&vs);
2342 pipelineobj.AddShader(&ps);
2343
Tony Barbour01999182015-04-09 12:58:51 -06002344 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002345 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002346
Tony Barbourdd4c9642015-01-09 12:55:14 -07002347 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002348 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002349
Tony Barbour1490c912015-07-28 10:17:20 -06002350 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002351
2352#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002353 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002354 pDSDumpDot((char*)"triTest2.dot");
2355#endif
2356 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06002357 Draw(3, 1, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002358
2359 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002360 EndCommandBuffer();
2361 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002362
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002363 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002364}
2365
Tony Barbour01999182015-04-09 12:58:51 -06002366TEST_F(VkRenderTest, TriangleFSUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002367{
2368 // This test allows the shader to select which buffer it is
2369 // pulling from using layout binding qualifier.
2370 // There are corresponding changes in the compiler stack that
2371 // will select the buffer using binding directly.
2372 // The binding number should match the slot number set up by
2373 // the application.
2374 // The expected result from this test is a purple triangle
2375
2376 static const char *vertShaderText =
2377 "#version 140\n"
2378 "#extension GL_ARB_separate_shader_objects : enable\n"
2379 "#extension GL_ARB_shading_language_420pack : enable\n"
2380 "void main() {\n"
2381 " vec2 vertices[3];"
2382 " vertices[0] = vec2(-0.5, -0.5);\n"
2383 " vertices[1] = vec2( 0.5, -0.5);\n"
2384 " vertices[2] = vec2( 0.5, 0.5);\n"
2385 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2386 "}\n";
2387
2388 static const char *fragShaderText =
2389 "#version 140\n"
2390 "#extension GL_ARB_separate_shader_objects : enable\n"
2391 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbour6baf4402015-09-29 14:56:09 -06002392 "layout (binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2393 "layout (binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2394 "layout (binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
2395 "layout (binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
GregFd6ebdb32015-06-03 18:40:50 -06002396 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002397 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002398 " outColor = myBlueVal.color;\n"
2399 " outColor += myRedVal.color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002400 "}\n";
2401
2402 ASSERT_NO_FATAL_FAILURE(InitState());
2403 ASSERT_NO_FATAL_FAILURE(InitViewport());
2404
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002405 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2406 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002407
2408 // We're going to create a number of uniform buffers, and then allow
2409 // the shader to select which it wants to read from with a binding
2410
2411 // Let's populate the buffers with a single color each:
Tony Barbour6baf4402015-09-29 14:56:09 -06002412 // layout (binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2413 // layout (binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2414 // layout (binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2415 // layout (binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002416
2417 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2418 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2419 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2420 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2421
2422 const int redCount = sizeof(redVals) / sizeof(float);
2423 const int greenCount = sizeof(greenVals) / sizeof(float);
2424 const int blueCount = sizeof(blueVals) / sizeof(float);
2425 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2426
Tony Barbour01999182015-04-09 12:58:51 -06002427 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002428
Tony Barbour01999182015-04-09 12:58:51 -06002429 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002430
Tony Barbour01999182015-04-09 12:58:51 -06002431 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002432
Tony Barbour01999182015-04-09 12:58:51 -06002433 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002434
Tony Barbour01999182015-04-09 12:58:51 -06002435 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002436 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002437 pipelineobj.AddShader(&vs);
2438 pipelineobj.AddShader(&ps);
2439
Tony Barbour01999182015-04-09 12:58:51 -06002440 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002441 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2442 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2443 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2444 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002445
Tony Barbourdd4c9642015-01-09 12:55:14 -07002446 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002447 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourf43b6982014-11-25 13:18:32 -07002448
Tony Barbour1490c912015-07-28 10:17:20 -06002449 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002450
2451#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002452 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002453 pDSDumpDot((char*)"triTest2.dot");
2454#endif
2455 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06002456 Draw(3, 1, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002457
2458 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002459 EndCommandBuffer();
2460 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002461
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002462 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002463}
2464
Tony Barbour01999182015-04-09 12:58:51 -06002465TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002466{
2467 // This test is the same as TriangleFSUniformBlockBinding, but
2468 // it does not provide an instance name.
2469 // The expected result from this test is a purple triangle
2470
2471 static const char *vertShaderText =
2472 "#version 140\n"
2473 "#extension GL_ARB_separate_shader_objects : enable\n"
2474 "#extension GL_ARB_shading_language_420pack : enable\n"
2475 "void main() {\n"
2476 " vec2 vertices[3];"
2477 " vertices[0] = vec2(-0.5, -0.5);\n"
2478 " vertices[1] = vec2( 0.5, -0.5);\n"
2479 " vertices[2] = vec2( 0.5, 0.5);\n"
2480 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2481 "}\n";
2482
2483 static const char *fragShaderText =
2484 "#version 430\n"
2485 "#extension GL_ARB_separate_shader_objects : enable\n"
2486 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbour6baf4402015-09-29 14:56:09 -06002487 "layout (binding = 0) uniform redVal { vec4 red; };"
2488 "layout (binding = 1) uniform greenVal { vec4 green; };"
2489 "layout (binding = 2) uniform blueVal { vec4 blue; };"
2490 "layout (binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002491 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002492 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002493 " outColor = blue;\n"
2494 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002495 "}\n";
2496 ASSERT_NO_FATAL_FAILURE(InitState());
2497 ASSERT_NO_FATAL_FAILURE(InitViewport());
2498
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002499 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2500 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002501
2502 // We're going to create a number of uniform buffers, and then allow
2503 // the shader to select which it wants to read from with a binding
2504
2505 // Let's populate the buffers with a single color each:
Tony Barbour6baf4402015-09-29 14:56:09 -06002506 // layout (binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2507 // layout (binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2508 // layout (binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2509 // layout (binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002510
2511 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2512 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2513 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2514 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2515
2516 const int redCount = sizeof(redVals) / sizeof(float);
2517 const int greenCount = sizeof(greenVals) / sizeof(float);
2518 const int blueCount = sizeof(blueVals) / sizeof(float);
2519 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2520
Tony Barbour01999182015-04-09 12:58:51 -06002521 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002522
Tony Barbour01999182015-04-09 12:58:51 -06002523 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002524
Tony Barbour01999182015-04-09 12:58:51 -06002525 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002526
Tony Barbour01999182015-04-09 12:58:51 -06002527 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002528
Tony Barbour01999182015-04-09 12:58:51 -06002529 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002530 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002531 pipelineobj.AddShader(&vs);
2532 pipelineobj.AddShader(&ps);
2533
Tony Barbour01999182015-04-09 12:58:51 -06002534 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002535 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2536 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2537 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2538 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002539
Tony Barbourdd4c9642015-01-09 12:55:14 -07002540 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002541 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002542
Tony Barbour1490c912015-07-28 10:17:20 -06002543 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002544
2545#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002546 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002547 pDSDumpDot((char*)"triTest2.dot");
2548#endif
2549 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06002550 Draw(3, 1, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002551
2552 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002553 EndCommandBuffer();
2554 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002555
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002556 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002557}
2558
GregF54a32172015-07-01 16:11:09 -06002559TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBindingWithStruct)
2560{
2561 // This test is the same as TriangleFSUniformBlockBinding, but
2562 // it does not provide an instance name.
2563 // The expected result from this test is a purple triangle
2564
2565 static const char *vertShaderText =
2566 "#version 140\n"
2567 "#extension GL_ARB_separate_shader_objects : enable\n"
2568 "#extension GL_ARB_shading_language_420pack : enable\n"
2569 "void main() {\n"
2570 " vec2 vertices[3];"
2571 " vertices[0] = vec2(-0.5, -0.5);\n"
2572 " vertices[1] = vec2( 0.5, -0.5);\n"
2573 " vertices[2] = vec2( 0.5, 0.5);\n"
2574 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2575 "}\n";
2576
2577 static const char *fragShaderText =
2578 "#version 430\n"
2579 "#extension GL_ARB_separate_shader_objects : enable\n"
2580 "#extension GL_ARB_shading_language_420pack : enable\n"
2581 "\n"
2582 " struct PS_INPUT {\n"
2583 " vec2 member0;\n"
2584 " vec4 member1;\n"
2585 " vec4 member2;\n"
2586 " vec4 member3;\n"
2587 " vec4 member4;\n"
2588 " vec4 member5;\n"
2589 " vec4 member6;\n"
2590 " vec4 member7;\n"
2591 " vec4 member8;\n"
2592 " vec4 member9;\n"
2593 " };\n"
2594 "\n"
Tony Barbour6baf4402015-09-29 14:56:09 -06002595 "layout (binding = 0) uniform redVal { vec4 red; };"
2596 "layout (binding = 1) uniform greenVal { vec4 green; };"
2597 "layout (binding = 2) uniform blueVal { vec4 blue; };"
2598 "layout (binding = 3) uniform whiteVal { vec4 white; };"
GregF54a32172015-07-01 16:11:09 -06002599 "layout (location = 0) out vec4 outColor;\n"
2600 "PS_INPUT MainFs()\n"
2601 "{\n"
2602 " PS_INPUT o;\n"
2603 " o.member9 = red;\n"
2604 " return o;\n"
2605 "}\n"
2606 "\n"
2607 "void main()\n"
2608 "{\n"
2609 " PS_INPUT o;\n"
2610 " o = MainFs();\n"
2611 " outColor = blue;"
2612 " outColor += o.member9;\n"
2613 "}\n";;
2614 ASSERT_NO_FATAL_FAILURE(InitState());
2615 ASSERT_NO_FATAL_FAILURE(InitViewport());
2616
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002617 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2618 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
GregF54a32172015-07-01 16:11:09 -06002619
2620 // We're going to create a number of uniform buffers, and then allow
2621 // the shader to select which it wants to read from with a binding
2622
2623 // Let's populate the buffers with a single color each:
Tony Barbour6baf4402015-09-29 14:56:09 -06002624 // layout (binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2625 // layout (binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2626 // layout (binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2627 // layout (binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
GregF54a32172015-07-01 16:11:09 -06002628
2629 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2630 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2631 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2632 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2633
2634 const int redCount = sizeof(redVals) / sizeof(float);
2635 const int greenCount = sizeof(greenVals) / sizeof(float);
2636 const int blueCount = sizeof(blueVals) / sizeof(float);
2637 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2638
2639 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2640
2641 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2642
2643 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2644
2645 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
2646
2647 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002648 pipelineobj.AddColorAttachment();
GregF54a32172015-07-01 16:11:09 -06002649 pipelineobj.AddShader(&vs);
2650 pipelineobj.AddShader(&ps);
2651
2652 VkDescriptorSetObj descriptorSet(m_device);
2653 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2654 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2655 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2656 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
2657
2658 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002659 ASSERT_VK_SUCCESS(BeginCommandBuffer());
GregF54a32172015-07-01 16:11:09 -06002660
Tony Barbour1490c912015-07-28 10:17:20 -06002661 GenericDrawPreparation(pipelineobj, descriptorSet);
GregF54a32172015-07-01 16:11:09 -06002662
2663#ifdef DUMP_STATE_DOT
2664 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
2665 pDSDumpDot((char*)"triTest2.dot");
2666#endif
2667 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06002668 Draw(3, 1, 0, 0);
GregF54a32172015-07-01 16:11:09 -06002669
2670 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002671 EndCommandBuffer();
2672 QueueCommandBuffer();
GregF54a32172015-07-01 16:11:09 -06002673
2674 RecordImages(m_renderTargets);
2675}
2676
Tony Barbour01999182015-04-09 12:58:51 -06002677TEST_F(VkRenderTest, CubeWithVertexFetchAndMVPAndTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07002678{
2679 static const char *vertShaderText =
2680 "#version 140\n"
2681 "#extension GL_ARB_separate_shader_objects : enable\n"
2682 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbour6baf4402015-09-29 14:56:09 -06002683 "layout (binding=0) uniform bufferVals {\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002684 " mat4 mvp;\n"
2685 "} myBufferVals;\n"
2686 "layout (location=0) in vec4 pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002687 "layout (location=1) in vec2 input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002688 "layout (location=0) out vec2 UV;\n"
2689 "void main() {\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002690 " UV = input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002691 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002692 " gl_Position.y = -gl_Position.y;\n"
2693 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002694 "}\n";
2695
2696 static const char *fragShaderText =
2697 "#version 140\n"
2698 "#extension GL_ARB_separate_shader_objects : enable\n"
2699 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002700 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002701 "layout (location=0) out vec4 outColor;\n"
2702 "layout (location=0) in vec2 UV;\n"
2703 "void main() {\n"
2704 " outColor= textureLod(surface, UV, 0.0);\n"
2705 "}\n";
2706 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2707
2708 glm::mat4 View = glm::lookAt(
2709 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2710 glm::vec3(0,0,0), // and looks at the origin
2711 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2712 );
2713
2714 glm::mat4 Model = glm::mat4(1.0f);
2715
2716 glm::mat4 MVP = Projection * View * Model;
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002717 int num_verts = sizeof(g_vb_texture_Data) / sizeof(g_vb_texture_Data[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002718
2719
2720 ASSERT_NO_FATAL_FAILURE(InitState());
2721 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wu9e81ebb2015-07-09 10:16:34 +08002722 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Chia-I Wuc278df82015-07-07 11:50:03 +08002723 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height, m_depth_stencil_fmt);
Tony Barbourf43b6982014-11-25 13:18:32 -07002724
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002725 VkConstantBufferObj meshBuffer(m_device, num_verts,
2726 sizeof(g_vb_texture_Data[0]), g_vb_texture_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002727 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002728
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002729 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07002730
Tony Barbour01999182015-04-09 12:58:51 -06002731 VkConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002732 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2733 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tony Barbour01999182015-04-09 12:58:51 -06002734 VkSamplerObj sampler(m_device);
2735 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002736
Tony Barbour01999182015-04-09 12:58:51 -06002737 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002738 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002739 pipelineobj.AddShader(&vs);
2740 pipelineobj.AddShader(&ps);
2741
Tony Barbour01999182015-04-09 12:58:51 -06002742 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002743 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mvpBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002744 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002745
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002746#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002747 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002748 MESH_BIND_ID, // binding ID
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002749 sizeof(g_vb_texture_Data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002750 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002751 };
Tony Barbourf43b6982014-11-25 13:18:32 -07002752
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002753 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002754 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2755 vi_attribs[0].location = 0; // location
Tony Barbour8205d902015-04-16 15:59:00 -06002756 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002757 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2758 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2759 vi_attribs[1].location = 1; // location
2760 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
2761 vi_attribs[1].offsetInBytes = 16; // Offset of uv components
Tony Barbourf43b6982014-11-25 13:18:32 -07002762
Tony Barbourf43b6982014-11-25 13:18:32 -07002763 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002764 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barbourf43b6982014-11-25 13:18:32 -07002765
Tony Barboure307f582015-07-10 15:29:03 -06002766 VkPipelineDepthStencilStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002767 ds_state.depthTestEnable = VK_TRUE;
2768 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06002769 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Cody Northrope4bc6942015-08-26 10:01:32 -06002770 ds_state.depthBoundsTestEnable = VK_FALSE;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002771 ds_state.stencilTestEnable = VK_FALSE;
2772 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
2773 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
2774 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06002775 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002776 ds_state.front = ds_state.back;
2777 pipelineobj.SetDepthStencil(&ds_state);
2778
Tony Barbour17c6ab12015-03-27 17:03:18 -06002779 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tobin Ehlis7f7b4422015-08-18 14:24:32 -06002780
2781 VkCmdBufferBeginInfo cbBeginInfo;
2782 memset(&cbBeginInfo, 0, sizeof(VkCmdBufferBeginInfo));
2783 cbBeginInfo.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
2784 cbBeginInfo.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT;
2785 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barbourf43b6982014-11-25 13:18:32 -07002786
Tony Barbour1490c912015-07-28 10:17:20 -06002787 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002788
Tony Barbour1490c912015-07-28 10:17:20 -06002789 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002790#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002791 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002792 pDSDumpDot((char*)"triTest2.dot");
2793#endif
2794 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06002795 Draw(num_verts, 1, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002796
2797 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002798 EndCommandBuffer();
2799 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002800
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002801 RecordImages(m_renderTargets);
Tony Barbour1490c912015-07-28 10:17:20 -06002802 RotateTriangleVSUniform(Projection, View, Model, &mvpBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002803}
Cody Northropd1ce7842014-12-09 11:17:01 -07002804
Tony Barbour01999182015-04-09 12:58:51 -06002805TEST_F(VkRenderTest, TriangleMixedSamplerUniformBlockBinding)
Cody Northropd1ce7842014-12-09 11:17:01 -07002806{
2807 // This test mixes binding slots of textures and buffers, ensuring
2808 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002809 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002810 // you can modify it to move the desired result around.
2811
2812 static const char *vertShaderText =
2813 "#version 140\n"
2814 "#extension GL_ARB_separate_shader_objects : enable\n"
2815 "#extension GL_ARB_shading_language_420pack : enable\n"
2816 "void main() {\n"
2817 " vec2 vertices[3];"
2818 " vertices[0] = vec2(-0.5, -0.5);\n"
2819 " vertices[1] = vec2( 0.5, -0.5);\n"
2820 " vertices[2] = vec2( 0.5, 0.5);\n"
2821 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2822 "}\n";
2823
2824 static const char *fragShaderText =
2825 "#version 430\n"
2826 "#extension GL_ARB_separate_shader_objects : enable\n"
2827 "#extension GL_ARB_shading_language_420pack : enable\n"
2828 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002829 "layout (binding = 3) uniform sampler2D surface1;\n"
2830 "layout (binding = 1) uniform sampler2D surface2;\n"
2831 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002832
Cody Northropa0410942014-12-09 13:59:39 -07002833
Tony Barbour6baf4402015-09-29 14:56:09 -06002834 "layout (binding = 4) uniform redVal { vec4 red; };"
2835 "layout (binding = 6) uniform greenVal { vec4 green; };"
2836 "layout (binding = 5) uniform blueVal { vec4 blue; };"
2837 "layout (binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002838 "layout (location = 0) out vec4 outColor;\n"
2839 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002840 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002841 " outColor += white * vec4(0.00001);\n"
2842 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002843 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002844 "}\n";
2845 ASSERT_NO_FATAL_FAILURE(InitState());
2846 ASSERT_NO_FATAL_FAILURE(InitViewport());
2847
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002848 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2849 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northropd1ce7842014-12-09 11:17:01 -07002850
Cody Northropd1ce7842014-12-09 11:17:01 -07002851 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2852 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2853 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2854 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2855
2856 const int redCount = sizeof(redVals) / sizeof(float);
2857 const int greenCount = sizeof(greenVals) / sizeof(float);
2858 const int blueCount = sizeof(blueVals) / sizeof(float);
2859 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2860
Tony Barbour01999182015-04-09 12:58:51 -06002861 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2862 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2863 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2864 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002865
Tony Barbour2f421a02015-04-01 16:38:10 -06002866 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002867 VkSamplerObj sampler0(m_device);
2868 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002869 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002870 VkSamplerObj sampler2(m_device);
2871 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002872 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002873 VkSamplerObj sampler4(m_device);
2874 VkTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropa0410942014-12-09 13:59:39 -07002875
2876 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2877 // TODO: Get back here ASAP and understand why.
Tony Barbour2f421a02015-04-01 16:38:10 -06002878 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06002879 VkSamplerObj sampler7(m_device);
2880 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropd1ce7842014-12-09 11:17:01 -07002881
Tony Barbour01999182015-04-09 12:58:51 -06002882 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002883 pipelineobj.AddColorAttachment();
Cody Northropd1ce7842014-12-09 11:17:01 -07002884 pipelineobj.AddShader(&vs);
2885 pipelineobj.AddShader(&ps);
2886
Tony Barbour01999182015-04-09 12:58:51 -06002887 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002888 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2889 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2890 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2891 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002892 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002893 // swap blue and green
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002894 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2895 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2896 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002897
Tony Barbourdd4c9642015-01-09 12:55:14 -07002898 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002899 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropd1ce7842014-12-09 11:17:01 -07002900
Tony Barbour1490c912015-07-28 10:17:20 -06002901 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002902
2903#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002904 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002905 pDSDumpDot((char*)"triTest2.dot");
2906#endif
2907 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06002908 Draw(3, 1, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002909
2910 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002911 EndCommandBuffer();
2912 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002913
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002914 RecordImages(m_renderTargets);
Cody Northropd1ce7842014-12-09 11:17:01 -07002915}
2916
Tony Barbour01999182015-04-09 12:58:51 -06002917TEST_F(VkRenderTest, TriangleMatchingSamplerUniformBlockBinding)
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002918{
2919 // This test matches binding slots of textures and buffers, requiring
2920 // the driver to give them distinct number spaces.
2921 // The expected result from this test is a red triangle, although
2922 // you can modify it to move the desired result around.
2923
2924 static const char *vertShaderText =
2925 "#version 140\n"
2926 "#extension GL_ARB_separate_shader_objects : enable\n"
2927 "#extension GL_ARB_shading_language_420pack : enable\n"
2928 "void main() {\n"
2929 " vec2 vertices[3];"
2930 " vertices[0] = vec2(-0.5, -0.5);\n"
2931 " vertices[1] = vec2( 0.5, -0.5);\n"
2932 " vertices[2] = vec2( 0.5, 0.5);\n"
2933 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2934 "}\n";
2935
2936 static const char *fragShaderText =
2937 "#version 430\n"
2938 "#extension GL_ARB_separate_shader_objects : enable\n"
2939 "#extension GL_ARB_shading_language_420pack : enable\n"
2940 "layout (binding = 0) uniform sampler2D surface0;\n"
2941 "layout (binding = 1) uniform sampler2D surface1;\n"
2942 "layout (binding = 2) uniform sampler2D surface2;\n"
2943 "layout (binding = 3) uniform sampler2D surface3;\n"
Tony Barbour6baf4402015-09-29 14:56:09 -06002944 "layout (binding = 4) uniform redVal { vec4 red; };"
2945 "layout (binding = 5) uniform greenVal { vec4 green; };"
2946 "layout (binding = 6) uniform blueVal { vec4 blue; };"
2947 "layout (binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002948 "layout (location = 0) out vec4 outColor;\n"
2949 "void main() {\n"
2950 " outColor = red;// * vec4(0.00001);\n"
2951 " outColor += white * vec4(0.00001);\n"
2952 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2953 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2954 "}\n";
2955 ASSERT_NO_FATAL_FAILURE(InitState());
2956 ASSERT_NO_FATAL_FAILURE(InitViewport());
2957
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06002958 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
2959 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002960
2961 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2962 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2963 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2964 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2965
2966 const int redCount = sizeof(redVals) / sizeof(float);
2967 const int greenCount = sizeof(greenVals) / sizeof(float);
2968 const int blueCount = sizeof(blueVals) / sizeof(float);
2969 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2970
Tony Barbour01999182015-04-09 12:58:51 -06002971 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2972 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2973 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2974 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002975
Tony Barbour2f421a02015-04-01 16:38:10 -06002976 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002977 VkSamplerObj sampler0(m_device);
2978 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002979 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002980 VkSamplerObj sampler2(m_device);
2981 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002982 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002983 VkSamplerObj sampler4(m_device);
2984 VkTextureObj texture4(m_device, tex_colors); // Light Green
Tony Barbour2f421a02015-04-01 16:38:10 -06002985 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06002986 VkSamplerObj sampler7(m_device);
2987 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002988
Tony Barbour01999182015-04-09 12:58:51 -06002989 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002990 pipelineobj.AddColorAttachment();
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002991 pipelineobj.AddShader(&vs);
2992 pipelineobj.AddShader(&ps);
2993
Tony Barbour01999182015-04-09 12:58:51 -06002994 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002995 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2996 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2997 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2998 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002999 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
3000 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
3001 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
3002 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003003
Tony Barbourdd4c9642015-01-09 12:55:14 -07003004 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003005 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003006
Tony Barbour1490c912015-07-28 10:17:20 -06003007 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07003008
3009#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003010 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07003011 pDSDumpDot((char*)"triTest2.dot");
3012#endif
3013 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06003014 Draw(3, 1, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07003015
3016 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003017 EndCommandBuffer();
3018 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07003019
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003020 RecordImages(m_renderTargets);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003021}
3022
Tony Barbour01999182015-04-09 12:58:51 -06003023TEST_F(VkRenderTest, TriangleUniformBufferLayout)
Cody Northrop02690bd2014-12-17 15:26:33 -07003024{
3025 // This test populates a buffer with a variety of different data
3026 // types, then reads them out with a shader.
3027 // The expected result from this test is a green triangle
3028
3029 static const char *vertShaderText =
3030 "#version 140\n"
3031 "#extension GL_ARB_separate_shader_objects : enable\n"
3032 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbour6baf4402015-09-29 14:56:09 -06003033 "layout (binding = 0) uniform mixedBuffer {\n"
Cody Northrop02690bd2014-12-17 15:26:33 -07003034 " vec4 fRed;\n"
3035 " vec4 fGreen;\n"
3036 " layout(row_major) mat4 worldToProj;\n"
3037 " layout(row_major) mat4 projToWorld;\n"
3038 " layout(row_major) mat4 worldToView;\n"
3039 " layout(row_major) mat4 viewToProj;\n"
3040 " layout(row_major) mat4 worldToShadow[4];\n"
3041 " float fZero;\n"
3042 " float fOne;\n"
3043 " float fTwo;\n"
3044 " float fThree;\n"
3045 " vec3 fZeroZeroZero;\n"
3046 " float fFour;\n"
3047 " vec3 fZeroZeroOne;\n"
3048 " float fFive;\n"
3049 " vec3 fZeroOneZero;\n"
3050 " float fSix;\n"
3051 " float fSeven;\n"
3052 " float fEight;\n"
3053 " float fNine;\n"
3054 " vec2 fZeroZero;\n"
3055 " vec2 fZeroOne;\n"
3056 " vec4 fBlue;\n"
3057 " vec2 fOneZero;\n"
3058 " vec2 fOneOne;\n"
3059 " vec3 fZeroOneOne;\n"
3060 " float fTen;\n"
3061 " float fEleven;\n"
3062 " float fTwelve;\n"
3063 " vec3 fOneZeroZero;\n"
3064 " vec4 uvOffsets[4];\n"
3065 "};\n"
3066 "layout (location = 0) out vec4 color;"
3067 "void main() {\n"
3068
3069 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3070 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3071 " \n"
3072
3073 // do some exact comparisons, even though we should
3074 // really have an epsilon involved.
3075 " vec4 outColor = right;\n"
3076 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3077 " outColor = wrong;\n"
3078 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3079 " outColor = wrong;\n"
3080 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3081 " outColor = wrong;\n"
3082
3083 " color = outColor;\n"
3084
3085 // generic position stuff
3086 " vec2 vertices;\n"
3087 " int vertexSelector = gl_VertexID;\n"
3088 " if (vertexSelector == 0)\n"
3089 " vertices = vec2(-0.5, -0.5);\n"
3090 " else if (vertexSelector == 1)\n"
3091 " vertices = vec2( 0.5, -0.5);\n"
3092 " else if (vertexSelector == 2)\n"
3093 " vertices = vec2( 0.5, 0.5);\n"
3094 " else\n"
3095 " vertices = vec2( 0.0, 0.0);\n"
3096 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3097 "}\n";
3098
3099 static const char *fragShaderText =
3100 "#version 140\n"
3101 "#extension GL_ARB_separate_shader_objects : enable\n"
3102 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbour6baf4402015-09-29 14:56:09 -06003103 "layout (binding = 0) uniform mixedBuffer {\n"
Cody Northrop02690bd2014-12-17 15:26:33 -07003104 " vec4 fRed;\n"
3105 " vec4 fGreen;\n"
3106 " layout(row_major) mat4 worldToProj;\n"
3107 " layout(row_major) mat4 projToWorld;\n"
3108 " layout(row_major) mat4 worldToView;\n"
3109 " layout(row_major) mat4 viewToProj;\n"
3110 " layout(row_major) mat4 worldToShadow[4];\n"
3111 " float fZero;\n"
3112 " float fOne;\n"
3113 " float fTwo;\n"
3114 " float fThree;\n"
3115 " vec3 fZeroZeroZero;\n"
3116 " float fFour;\n"
3117 " vec3 fZeroZeroOne;\n"
3118 " float fFive;\n"
3119 " vec3 fZeroOneZero;\n"
3120 " float fSix;\n"
3121 " float fSeven;\n"
3122 " float fEight;\n"
3123 " float fNine;\n"
3124 " vec2 fZeroZero;\n"
3125 " vec2 fZeroOne;\n"
3126 " vec4 fBlue;\n"
3127 " vec2 fOneZero;\n"
3128 " vec2 fOneOne;\n"
3129 " vec3 fZeroOneOne;\n"
3130 " float fTen;\n"
3131 " float fEleven;\n"
3132 " float fTwelve;\n"
3133 " vec3 fOneZeroZero;\n"
3134 " vec4 uvOffsets[4];\n"
3135 "};\n"
3136 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003137 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop02690bd2014-12-17 15:26:33 -07003138 "void main() {\n"
3139 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3140 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3141 " \n"
3142
3143 // start with VS value to ensure it passed
3144 " vec4 outColor = color;\n"
3145
3146 // do some exact comparisons, even though we should
3147 // really have an epsilon involved.
3148 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3149 " outColor = wrong;\n"
3150 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3151 " outColor = wrong;\n"
3152 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3153 " outColor = wrong;\n"
3154 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3155 " outColor = wrong;\n"
3156 " if (fTwo != 2.0)\n"
3157 " outColor = wrong;\n"
3158 " if (fOneOne != vec2(1.0, 1.0))\n"
3159 " outColor = wrong;\n"
3160 " if (fTen != 10.0)\n"
3161 " outColor = wrong;\n"
3162 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3163 " outColor = wrong;\n"
3164 " \n"
GregFd6ebdb32015-06-03 18:40:50 -06003165 " uFragColor = outColor;\n"
Cody Northrop02690bd2014-12-17 15:26:33 -07003166 "}\n";
3167
3168
Cody Northrop1684adb2015-08-05 11:15:02 -06003169 const float mixedVals[196] = { 1.0f, 0.0f, 0.0f, 1.0f, // vec4 fRed; // align
3170 0.0f, 1.0f, 0.0f, 1.0f, // vec4 fGreen; // align
3171 1.0f, 0.0f, 0.0f, 1.0f, // layout(row_major) mat4 worldToProj;
3172 0.0f, 1.0f, 0.0f, 1.0f, // align
3173 0.0f, 0.0f, 1.0f, 1.0f, // align
3174 0.0f, 0.0f, 0.0f, 1.0f, // align
3175 2.0f, 0.0f, 0.0f, 2.0f, // layout(row_major) mat4 projToWorld;
3176 0.0f, 2.0f, 0.0f, 2.0f, // align
3177 0.0f, 0.0f, 2.0f, 2.0f, // align
3178 0.0f, 0.0f, 0.0f, 2.0f, // align
3179 3.0f, 0.0f, 0.0f, 3.0f, // layout(row_major) mat4 worldToView;
3180 0.0f, 3.0f, 0.0f, 3.0f, // align
3181 0.0f, 0.0f, 3.0f, 3.0f, // align
3182 0.0f, 0.0f, 0.0f, 3.0f, // align
3183 4.0f, 0.0f, 0.0f, 4.0f, // layout(row_major) mat4 viewToProj;
3184 0.0f, 4.0f, 0.0f, 4.0f, // align
3185 0.0f, 0.0f, 4.0f, 4.0f, // align
3186 0.0f, 0.0f, 0.0f, 4.0f, // align
3187 5.0f, 0.0f, 0.0f, 5.0f, // layout(row_major) mat4 worldToShadow[4];
3188 0.0f, 5.0f, 0.0f, 5.0f, // align
3189 0.0f, 0.0f, 5.0f, 5.0f, // align
3190 0.0f, 0.0f, 0.0f, 5.0f, // align
3191 6.0f, 0.0f, 0.0f, 6.0f, // align
3192 0.0f, 6.0f, 0.0f, 6.0f, // align
3193 0.0f, 0.0f, 6.0f, 6.0f, // align
3194 0.0f, 0.0f, 0.0f, 6.0f, // align
3195 7.0f, 0.0f, 0.0f, 7.0f, // align
3196 0.0f, 7.0f, 0.0f, 7.0f, // align
3197 0.0f, 0.0f, 7.0f, 7.0f, // align
3198 0.0f, 0.0f, 0.0f, 7.0f, // align
3199 8.0f, 0.0f, 0.0f, 8.0f, // align
3200 0.0f, 8.0f, 0.0f, 8.0f, // align
3201 0.0f, 0.0f, 8.0f, 8.0f, // align
3202 0.0f, 0.0f, 0.0f, 8.0f, // align
3203 0.0f, // float fZero; // align
3204 1.0f, // float fOne; // pack
3205 2.0f, // float fTwo; // pack
3206 3.0f, // float fThree; // pack
3207 0.0f, 0.0f, 0.0f, // vec3 fZeroZeroZero; // align
3208 4.0f, // float fFour; // pack
3209 0.0f, 0.0f, 1.0f, // vec3 fZeroZeroOne; // align
3210 5.0f, // float fFive; // pack
3211 0.0f, 1.0f, 0.0f, // vec3 fZeroOneZero; // align
3212 6.0f, // float fSix; // pack
3213 7.0f, // float fSeven; // align
3214 8.0f, // float fEight; // pack
3215 9.0f, // float fNine; // pack
3216 0.0f, // BUFFER
3217 0.0f, 0.0f, // vec2 fZeroZero; // align
3218 0.0f, 1.0f, // vec2 fZeroOne; // pack
3219 0.0f, 0.0f, 1.0f, 1.0f, // vec4 fBlue; // align
3220 1.0f, 0.0f, // vec2 fOneZero; // align
3221 1.0f, 1.0f, // vec2 fOneOne; // pack
3222 0.0f, 1.0f, 1.0f, // vec3 fZeroOneOne; // align
3223 10.0f, // float fTen; // pack
3224 11.0f, // float fEleven; // align
3225 12.0f, // float fTwelve; // pack
3226 0.0f, 0.0f, // BUFFER
3227 1.0f, 0.0f, 0.0f, // vec3 fOneZeroZero; // align
3228 0.0f, // BUFFER
3229 0.1f, 0.2f, 0.3f, 0.4f, // vec4 uvOffsets[4];
3230 0.5f, 0.6f, 0.7f, 0.8f, // align
3231 0.9f, 1.0f, 1.1f, 1.2f, // align
3232 1.3f, 1.4f, 1.5f, 1.6f, // align
Cody Northrop02690bd2014-12-17 15:26:33 -07003233 };
3234
3235 ASSERT_NO_FATAL_FAILURE(InitState());
3236 ASSERT_NO_FATAL_FAILURE(InitViewport());
3237
3238 const int constCount = sizeof(mixedVals) / sizeof(float);
3239
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003240 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
3241 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northrop02690bd2014-12-17 15:26:33 -07003242
Tony Barbour01999182015-04-09 12:58:51 -06003243 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003244
Tony Barbour01999182015-04-09 12:58:51 -06003245 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003246 pipelineobj.AddColorAttachment();
Cody Northrop02690bd2014-12-17 15:26:33 -07003247 pipelineobj.AddShader(&vs);
3248 pipelineobj.AddShader(&ps);
3249
Tony Barbour01999182015-04-09 12:58:51 -06003250 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003251 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003252
3253 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003254 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop02690bd2014-12-17 15:26:33 -07003255
Tony Barbour1490c912015-07-28 10:17:20 -06003256 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop02690bd2014-12-17 15:26:33 -07003257
3258#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003259 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop02690bd2014-12-17 15:26:33 -07003260 pDSDumpDot((char*)"triTest2.dot");
3261#endif
3262 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06003263 Draw(3, 1, 0, 0);
Cody Northrop02690bd2014-12-17 15:26:33 -07003264
3265 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003266 EndCommandBuffer();
3267 QueueCommandBuffer();
Cody Northrop02690bd2014-12-17 15:26:33 -07003268
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003269 RecordImages(m_renderTargets);
Cody Northrop02690bd2014-12-17 15:26:33 -07003270}
3271
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003272TEST_F(VkRenderTest, TextureGather)
3273{
3274 // This test introduces textureGather and textureGatherOffset
3275 // Each call is compared against an expected inline color result
3276 // Green triangle means everything worked as expected
3277 // Red means something went wrong
3278
Cody Northropbe701ac2015-08-06 13:18:13 -06003279 // disable SPV until texture gather is turned on in glsl->SPV
3280 if (!m_use_glsl) {
3281 printf("Skipping test that requires GLSL path (TextureGather)\n");
3282 return;
3283 }
3284
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003285 static const char *vertShaderText =
3286 "#version 140\n"
3287 "#extension GL_ARB_separate_shader_objects : enable\n"
3288 "#extension GL_ARB_shading_language_420pack : enable\n"
3289 "void main() {\n"
3290 " vec2 vertices[3];"
3291 " vertices[0] = vec2(-0.5, -0.5);\n"
3292 " vertices[1] = vec2( 0.5, -0.5);\n"
3293 " vertices[2] = vec2( 0.5, 0.5);\n"
3294 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
3295 "}\n";
3296
3297 static const char *fragShaderText =
3298 "#version 430\n"
3299 "#extension GL_ARB_separate_shader_objects : enable\n"
3300 "#extension GL_ARB_shading_language_420pack : enable\n"
3301 "layout (binding = 0) uniform sampler2D surface0;\n"
3302 "layout (binding = 1) uniform sampler2D surface1;\n"
3303 "layout (binding = 2) uniform sampler2D surface2;\n"
3304 "layout (binding = 3) uniform sampler2D surface3;\n"
3305 "layout (location = 0) out vec4 outColor;\n"
3306 "void main() {\n"
3307
3308 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3309 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3310
3311 " vec4 color = right;\n"
3312
3313 // Grab a normal texture sample to ensure it can work in conjuntion
3314 // with textureGather (there are some intracacies in the backend)
3315 " vec4 sampledColor = textureLod(surface2, vec2(0.5), 0.0);\n"
3316 " if (sampledColor != vec4(0.0, 0.0, 1.0, 1.0))\n"
3317 " color = wrong;\n"
3318
3319 " vec4 gatheredColor = textureGather(surface0, vec2(0.5), 0);\n"
3320 // This just grabbed four red components from a red surface
3321 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3322 " color = wrong;\n"
3323
3324 // Yes, this is using an offset of 0, we don't have enough fine grained
3325 // control of the texture contents here.
3326 " gatheredColor = textureGatherOffset(surface1, vec2(0.5), ivec2(0, 0), 1);\n"
3327 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3328 " color = wrong;\n"
3329
3330 " outColor = color;\n"
3331
3332 "}\n";
3333
3334 ASSERT_NO_FATAL_FAILURE(InitState());
3335 ASSERT_NO_FATAL_FAILURE(InitViewport());
3336
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003337 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX_BIT, this);
3338 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003339
3340 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
3341 VkSamplerObj sampler0(m_device);
3342 VkTextureObj texture0(m_device, tex_colors); // Red
3343 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
3344 VkSamplerObj sampler1(m_device);
3345 VkTextureObj texture1(m_device, tex_colors); // Green
3346 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
3347 VkSamplerObj sampler2(m_device);
3348 VkTextureObj texture2(m_device, tex_colors); // Blue
3349 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
3350 VkSamplerObj sampler3(m_device);
3351 VkTextureObj texture3(m_device, tex_colors); // Red and Blue
3352
3353 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003354 pipelineobj.AddColorAttachment();
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003355 pipelineobj.AddShader(&vs);
3356 pipelineobj.AddShader(&ps);
3357
3358 VkDescriptorSetObj descriptorSet(m_device);
3359 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3360 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
3361 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3362 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
3363
3364 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003365 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003366
Tony Barbour1490c912015-07-28 10:17:20 -06003367 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003368
3369 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06003370 Draw(3, 1, 0, 0);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003371
3372 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003373 EndCommandBuffer();
3374 QueueCommandBuffer();
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003375
3376 RecordImages(m_renderTargets);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003377}
3378
Cody Northropa44c2ff2015-04-15 11:19:06 -06003379TEST_F(VkRenderTest, GeometryShaderHelloWorld)
3380{
3381 // This test introduces a geometry shader that simply
3382 // changes the color of each vertex to red, green, blue
3383
3384 static const char *vertShaderText =
3385 "#version 140\n"
3386 "#extension GL_ARB_separate_shader_objects : enable\n"
3387 "#extension GL_ARB_shading_language_420pack : enable\n"
3388 "layout (location = 0) out vec4 color;"
3389 "void main() {\n"
3390
3391 // VS writes out red
3392 " color = vec4(1.0, 0.0, 0.0, 1.0);\n"
3393
3394 // generic position stuff
3395 " vec2 vertices;\n"
3396 " int vertexSelector = gl_VertexID;\n"
3397 " if (vertexSelector == 0)\n"
3398 " vertices = vec2(-0.5, -0.5);\n"
3399 " else if (vertexSelector == 1)\n"
3400 " vertices = vec2( 0.5, -0.5);\n"
3401 " else if (vertexSelector == 2)\n"
3402 " vertices = vec2( 0.5, 0.5);\n"
3403 " else\n"
3404 " vertices = vec2( 0.0, 0.0);\n"
3405 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3406
3407 "}\n";
3408
3409 static const char *geomShaderText =
3410 "#version 330\n"
3411 "#extension GL_ARB_separate_shader_objects : enable\n"
3412 "#extension GL_ARB_shading_language_420pack : enable\n"
3413 "layout( triangles ) in;\n"
3414 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3415 "layout( location = 0 ) in vec4 inColor[3];\n"
3416 "layout( location = 0 ) out vec4 outColor;\n"
3417 "void main()\n"
3418 "{\n"
3419
3420 // first vertex, pass through red
3421 " gl_Position = gl_in[0].gl_Position;\n"
3422 " outColor = inColor[0];\n"
3423 " EmitVertex();\n"
3424
3425 // second vertex, green
3426 " gl_Position = gl_in[1].gl_Position;\n"
3427 " outColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3428 " EmitVertex();\n"
3429
3430 // third vertex, blue
3431 " gl_Position = gl_in[2].gl_Position;\n"
3432 " outColor = vec4(0.0, 0.0, 1.0, 1.0);\n"
3433 " EmitVertex();\n"
3434
3435 // done
3436 " EndPrimitive();\n"
3437 "}\n";
3438
3439
3440 static const char *fragShaderText =
3441 "#version 140\n"
3442 "#extension GL_ARB_separate_shader_objects : enable\n"
3443 "#extension GL_ARB_shading_language_420pack : enable\n"
3444 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003445 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003446 "void main() {\n"
3447 // pass through
GregFd6ebdb32015-06-03 18:40:50 -06003448 " outColor = color;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003449 "}\n";
3450
3451
3452
3453 ASSERT_NO_FATAL_FAILURE(InitState());
3454 ASSERT_NO_FATAL_FAILURE(InitViewport());
3455
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003456 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3457 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY_BIT, this);
3458 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003459
3460 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003461 pipelineobj.AddColorAttachment();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003462 pipelineobj.AddShader(&vs);
3463 pipelineobj.AddShader(&gs);
3464 pipelineobj.AddShader(&ps);
3465
3466 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003467 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropa44c2ff2015-04-15 11:19:06 -06003468
3469 VkDescriptorSetObj descriptorSet(m_device);
3470
Tony Barbour1490c912015-07-28 10:17:20 -06003471 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003472
3473 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06003474 Draw(3, 1, 0, 0);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003475
3476 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003477 EndCommandBuffer();
3478 QueueCommandBuffer();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003479
3480 RecordImages(m_renderTargets);
3481}
3482
3483TEST_F(VkRenderTest, GSUniformBufferLayout)
3484{
3485 // This test is just like TriangleUniformBufferLayout but adds
3486 // geometry as a stage that also does UBO lookups
3487 // The expected result from this test is a green triangle
3488
3489 static const char *vertShaderText =
3490 "#version 140\n"
3491 "#extension GL_ARB_separate_shader_objects : enable\n"
3492 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbour6baf4402015-09-29 14:56:09 -06003493 "layout (binding = 0) uniform mixedBuffer {\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003494 " vec4 fRed;\n"
3495 " vec4 fGreen;\n"
3496 " layout(row_major) mat4 worldToProj;\n"
3497 " layout(row_major) mat4 projToWorld;\n"
3498 " layout(row_major) mat4 worldToView;\n"
3499 " layout(row_major) mat4 viewToProj;\n"
3500 " layout(row_major) mat4 worldToShadow[4];\n"
3501 " float fZero;\n"
3502 " float fOne;\n"
3503 " float fTwo;\n"
3504 " float fThree;\n"
3505 " vec3 fZeroZeroZero;\n"
3506 " float fFour;\n"
3507 " vec3 fZeroZeroOne;\n"
3508 " float fFive;\n"
3509 " vec3 fZeroOneZero;\n"
3510 " float fSix;\n"
3511 " float fSeven;\n"
3512 " float fEight;\n"
3513 " float fNine;\n"
3514 " vec2 fZeroZero;\n"
3515 " vec2 fZeroOne;\n"
3516 " vec4 fBlue;\n"
3517 " vec2 fOneZero;\n"
3518 " vec2 fOneOne;\n"
3519 " vec3 fZeroOneOne;\n"
3520 " float fTen;\n"
3521 " float fEleven;\n"
3522 " float fTwelve;\n"
3523 " vec3 fOneZeroZero;\n"
3524 " vec4 uvOffsets[4];\n"
3525 "};\n"
3526 "layout (location = 0) out vec4 color;"
3527 "void main() {\n"
3528
3529 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3530 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3531 " \n"
3532
3533 // do some exact comparisons, even though we should
3534 // really have an epsilon involved.
3535 " vec4 outColor = right;\n"
3536 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3537 " outColor = wrong;\n"
3538 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3539 " outColor = wrong;\n"
3540 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3541 " outColor = wrong;\n"
3542
3543 " color = outColor;\n"
3544
3545 // generic position stuff
3546 " vec2 vertices;\n"
3547 " int vertexSelector = gl_VertexID;\n"
3548 " if (vertexSelector == 0)\n"
3549 " vertices = vec2(-0.5, -0.5);\n"
3550 " else if (vertexSelector == 1)\n"
3551 " vertices = vec2( 0.5, -0.5);\n"
3552 " else if (vertexSelector == 2)\n"
3553 " vertices = vec2( 0.5, 0.5);\n"
3554 " else\n"
3555 " vertices = vec2( 0.0, 0.0);\n"
3556 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3557 "}\n";
3558
3559 static const char *geomShaderText =
3560 "#version 330\n"
3561 "#extension GL_ARB_separate_shader_objects : enable\n"
3562 "#extension GL_ARB_shading_language_420pack : enable\n"
3563
3564 // GS layout stuff
3565 "layout( triangles ) in;\n"
3566 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3567
3568 // Between stage IO
3569 "layout( location = 0 ) in vec4 inColor[3];\n"
3570 "layout( location = 0 ) out vec4 color;\n"
3571
Tony Barbour6baf4402015-09-29 14:56:09 -06003572 "layout (binding = 0) uniform mixedBuffer {\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003573 " vec4 fRed;\n"
3574 " vec4 fGreen;\n"
3575 " layout(row_major) mat4 worldToProj;\n"
3576 " layout(row_major) mat4 projToWorld;\n"
3577 " layout(row_major) mat4 worldToView;\n"
3578 " layout(row_major) mat4 viewToProj;\n"
3579 " layout(row_major) mat4 worldToShadow[4];\n"
3580 " float fZero;\n"
3581 " float fOne;\n"
3582 " float fTwo;\n"
3583 " float fThree;\n"
3584 " vec3 fZeroZeroZero;\n"
3585 " float fFour;\n"
3586 " vec3 fZeroZeroOne;\n"
3587 " float fFive;\n"
3588 " vec3 fZeroOneZero;\n"
3589 " float fSix;\n"
3590 " float fSeven;\n"
3591 " float fEight;\n"
3592 " float fNine;\n"
3593 " vec2 fZeroZero;\n"
3594 " vec2 fZeroOne;\n"
3595 " vec4 fBlue;\n"
3596 " vec2 fOneZero;\n"
3597 " vec2 fOneOne;\n"
3598 " vec3 fZeroOneOne;\n"
3599 " float fTen;\n"
3600 " float fEleven;\n"
3601 " float fTwelve;\n"
3602 " vec3 fOneZeroZero;\n"
3603 " vec4 uvOffsets[4];\n"
3604 "};\n"
3605
3606 "void main()\n"
3607 "{\n"
3608
3609 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3610 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3611
3612 // Each vertex will validate it can read VS output
3613 // then check a few values from the UBO
3614
3615 // first vertex
3616 " vec4 outColor = inColor[0];\n"
3617
3618 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3619 " outColor = wrong;\n"
3620 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3621 " outColor = wrong;\n"
3622 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3623 " outColor = wrong;\n"
3624 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3625 " outColor = wrong;\n"
3626
3627 " gl_Position = gl_in[0].gl_Position;\n"
3628 " color = outColor;\n"
3629 " EmitVertex();\n"
3630
3631 // second vertex
3632 " outColor = inColor[1];\n"
3633
3634 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3635 " outColor = wrong;\n"
3636 " if (fSix != 6.0)\n"
3637 " outColor = wrong;\n"
3638 " if (fOneOne != vec2(1.0, 1.0))\n"
3639 " outColor = wrong;\n"
3640
3641 " gl_Position = gl_in[1].gl_Position;\n"
3642 " color = outColor;\n"
3643 " EmitVertex();\n"
3644
3645 // third vertex
3646 " outColor = inColor[2];\n"
3647
3648 " if (fSeven != 7.0)\n"
3649 " outColor = wrong;\n"
3650 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3651 " outColor = wrong;\n"
3652
3653 " gl_Position = gl_in[2].gl_Position;\n"
3654 " color = outColor;\n"
3655 " EmitVertex();\n"
3656
3657 // done
3658 " EndPrimitive();\n"
3659 "}\n";
3660
3661 static const char *fragShaderText =
3662 "#version 140\n"
3663 "#extension GL_ARB_separate_shader_objects : enable\n"
3664 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbour6baf4402015-09-29 14:56:09 -06003665 "layout (binding = 0) uniform mixedBuffer {\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003666 " vec4 fRed;\n"
3667 " vec4 fGreen;\n"
3668 " layout(row_major) mat4 worldToProj;\n"
3669 " layout(row_major) mat4 projToWorld;\n"
3670 " layout(row_major) mat4 worldToView;\n"
3671 " layout(row_major) mat4 viewToProj;\n"
3672 " layout(row_major) mat4 worldToShadow[4];\n"
3673 " float fZero;\n"
3674 " float fOne;\n"
3675 " float fTwo;\n"
3676 " float fThree;\n"
3677 " vec3 fZeroZeroZero;\n"
3678 " float fFour;\n"
3679 " vec3 fZeroZeroOne;\n"
3680 " float fFive;\n"
3681 " vec3 fZeroOneZero;\n"
3682 " float fSix;\n"
3683 " float fSeven;\n"
3684 " float fEight;\n"
3685 " float fNine;\n"
3686 " vec2 fZeroZero;\n"
3687 " vec2 fZeroOne;\n"
3688 " vec4 fBlue;\n"
3689 " vec2 fOneZero;\n"
3690 " vec2 fOneOne;\n"
3691 " vec3 fZeroOneOne;\n"
3692 " float fTen;\n"
3693 " float fEleven;\n"
3694 " float fTwelve;\n"
3695 " vec3 fOneZeroZero;\n"
3696 " vec4 uvOffsets[4];\n"
3697 "};\n"
3698 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003699 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003700 "void main() {\n"
3701 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3702 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3703 " \n"
3704
3705 // start with GS value to ensure it passed
3706 " vec4 outColor = color;\n"
3707
3708 // do some exact comparisons, even though we should
3709 // really have an epsilon involved.
3710 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3711 " outColor = wrong;\n"
3712 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3713 " outColor = wrong;\n"
3714 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3715 " outColor = wrong;\n"
3716 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3717 " outColor = wrong;\n"
3718 " if (fTwo != 2.0)\n"
3719 " outColor = wrong;\n"
3720 " if (fOneOne != vec2(1.0, 1.0))\n"
3721 " outColor = wrong;\n"
3722 " if (fTen != 10.0)\n"
3723 " outColor = wrong;\n"
3724 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3725 " outColor = wrong;\n"
3726 " \n"
GregFd6ebdb32015-06-03 18:40:50 -06003727 " uFragColor = outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003728 "}\n";
3729
3730
Cody Northrop1684adb2015-08-05 11:15:02 -06003731 const float mixedVals[196] = { 1.0f, 0.0f, 0.0f, 1.0f, // vec4 fRed; // align
3732 0.0f, 1.0f, 0.0f, 1.0f, // vec4 fGreen; // align
3733 1.0f, 0.0f, 0.0f, 1.0f, // layout(row_major) mat4 worldToProj;
3734 0.0f, 1.0f, 0.0f, 1.0f, // align
3735 0.0f, 0.0f, 1.0f, 1.0f, // align
3736 0.0f, 0.0f, 0.0f, 1.0f, // align
3737 2.0f, 0.0f, 0.0f, 2.0f, // layout(row_major) mat4 projToWorld;
3738 0.0f, 2.0f, 0.0f, 2.0f, // align
3739 0.0f, 0.0f, 2.0f, 2.0f, // align
3740 0.0f, 0.0f, 0.0f, 2.0f, // align
3741 3.0f, 0.0f, 0.0f, 3.0f, // layout(row_major) mat4 worldToView;
3742 0.0f, 3.0f, 0.0f, 3.0f, // align
3743 0.0f, 0.0f, 3.0f, 3.0f, // align
3744 0.0f, 0.0f, 0.0f, 3.0f, // align
3745 4.0f, 0.0f, 0.0f, 4.0f, // layout(row_major) mat4 viewToProj;
3746 0.0f, 4.0f, 0.0f, 4.0f, // align
3747 0.0f, 0.0f, 4.0f, 4.0f, // align
3748 0.0f, 0.0f, 0.0f, 4.0f, // align
3749 5.0f, 0.0f, 0.0f, 5.0f, // layout(row_major) mat4 worldToShadow[4];
3750 0.0f, 5.0f, 0.0f, 5.0f, // align
3751 0.0f, 0.0f, 5.0f, 5.0f, // align
3752 0.0f, 0.0f, 0.0f, 5.0f, // align
3753 6.0f, 0.0f, 0.0f, 6.0f, // align
3754 0.0f, 6.0f, 0.0f, 6.0f, // align
3755 0.0f, 0.0f, 6.0f, 6.0f, // align
3756 0.0f, 0.0f, 0.0f, 6.0f, // align
3757 7.0f, 0.0f, 0.0f, 7.0f, // align
3758 0.0f, 7.0f, 0.0f, 7.0f, // align
3759 0.0f, 0.0f, 7.0f, 7.0f, // align
3760 0.0f, 0.0f, 0.0f, 7.0f, // align
3761 8.0f, 0.0f, 0.0f, 8.0f, // align
3762 0.0f, 8.0f, 0.0f, 8.0f, // align
3763 0.0f, 0.0f, 8.0f, 8.0f, // align
3764 0.0f, 0.0f, 0.0f, 8.0f, // align
3765 0.0f, // float fZero; // align
3766 1.0f, // float fOne; // pack
3767 2.0f, // float fTwo; // pack
3768 3.0f, // float fThree; // pack
3769 0.0f, 0.0f, 0.0f, // vec3 fZeroZeroZero; // align
3770 4.0f, // float fFour; // pack
3771 0.0f, 0.0f, 1.0f, // vec3 fZeroZeroOne; // align
3772 5.0f, // float fFive; // pack
3773 0.0f, 1.0f, 0.0f, // vec3 fZeroOneZero; // align
3774 6.0f, // float fSix; // pack
3775 7.0f, // float fSeven; // align
3776 8.0f, // float fEight; // pack
3777 9.0f, // float fNine; // pack
3778 0.0f, // BUFFER
3779 0.0f, 0.0f, // vec2 fZeroZero; // align
3780 0.0f, 1.0f, // vec2 fZeroOne; // pack
3781 0.0f, 0.0f, 1.0f, 1.0f, // vec4 fBlue; // align
3782 1.0f, 0.0f, // vec2 fOneZero; // align
3783 1.0f, 1.0f, // vec2 fOneOne; // pack
3784 0.0f, 1.0f, 1.0f, // vec3 fZeroOneOne; // align
3785 10.0f, // float fTen; // pack
3786 11.0f, // float fEleven; // align
3787 12.0f, // float fTwelve; // pack
3788 0.0f, 0.0f, // BUFFER
3789 1.0f, 0.0f, 0.0f, // vec3 fOneZeroZero; // align
3790 0.0f, // BUFFER
3791 0.1f, 0.2f, 0.3f, 0.4f, // vec4 uvOffsets[4];
3792 0.5f, 0.6f, 0.7f, 0.8f, // align
3793 0.9f, 1.0f, 1.1f, 1.2f, // align
3794 1.3f, 1.4f, 1.5f, 1.6f, // align
Cody Northropa44c2ff2015-04-15 11:19:06 -06003795 };
3796
3797
3798
3799 ASSERT_NO_FATAL_FAILURE(InitState());
3800 ASSERT_NO_FATAL_FAILURE(InitViewport());
3801
3802 const int constCount = sizeof(mixedVals) / sizeof(float);
3803
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003804 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3805 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY_BIT, this);
3806 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003807
3808 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
3809
3810 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003811 pipelineobj.AddColorAttachment();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003812 pipelineobj.AddShader(&vs);
3813 pipelineobj.AddShader(&gs);
3814 pipelineobj.AddShader(&ps);
3815
3816 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003817 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropa44c2ff2015-04-15 11:19:06 -06003818
3819 VkDescriptorSetObj descriptorSet(m_device);
3820 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
3821
Tony Barbour1490c912015-07-28 10:17:20 -06003822 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003823
3824 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06003825 Draw(3, 1, 0, 0);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003826
3827 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003828 EndCommandBuffer();
3829 QueueCommandBuffer();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003830
3831 RecordImages(m_renderTargets);
3832}
3833
3834TEST_F(VkRenderTest, GSPositions)
3835{
3836 // This test adds more inputs from the vertex shader and perturbs positions
3837 // Expected result is white triangle with weird positions
3838
3839 static const char *vertShaderText =
3840 "#version 140\n"
3841 "#extension GL_ARB_separate_shader_objects : enable\n"
3842 "#extension GL_ARB_shading_language_420pack : enable\n"
3843
3844 "layout(location = 0) out vec3 out_a;\n"
3845 "layout(location = 1) out vec3 out_b;\n"
3846 "layout(location = 2) out vec3 out_c;\n"
3847
3848 "void main() {\n"
3849
3850 // write a solid color to each
3851 " out_a = vec3(1.0, 0.0, 0.0);\n"
3852 " out_b = vec3(0.0, 1.0, 0.0);\n"
3853 " out_c = vec3(0.0, 0.0, 1.0);\n"
3854
3855 // generic position stuff
3856 " vec2 vertices;\n"
3857 " int vertexSelector = gl_VertexID;\n"
3858 " if (vertexSelector == 0)\n"
3859 " vertices = vec2(-0.5, -0.5);\n"
3860 " else if (vertexSelector == 1)\n"
3861 " vertices = vec2( 0.5, -0.5);\n"
3862 " else if (vertexSelector == 2)\n"
3863 " vertices = vec2( 0.5, 0.5);\n"
3864 " else\n"
3865 " vertices = vec2( 0.0, 0.0);\n"
3866 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3867
3868 "}\n";
3869
3870 static const char *geomShaderText =
3871 "#version 330\n"
3872 "#extension GL_ARB_separate_shader_objects : enable\n"
3873 "#extension GL_ARB_shading_language_420pack : enable\n"
3874 "layout( triangles ) in;\n"
3875 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3876
3877 "layout(location = 0) in vec3 in_a[3];\n"
3878 "layout(location = 1) in vec3 in_b[3];\n"
3879 "layout(location = 2) in vec3 in_c[3];\n"
3880
3881 "layout(location = 0) out vec3 out_a;\n"
3882 "layout(location = 1) out vec3 out_b;\n"
3883 "layout(location = 2) out vec3 out_c;\n"
3884
3885 "void main()\n"
3886 "{\n"
3887
3888 " gl_Position = gl_in[0].gl_Position;\n"
3889 " gl_Position.xy *= vec2(0.75);\n"
3890 " out_a = in_a[0];\n"
3891 " out_b = in_b[0];\n"
3892 " out_c = in_c[0];\n"
3893 " EmitVertex();\n"
3894
3895 " gl_Position = gl_in[1].gl_Position;\n"
3896 " gl_Position.xy *= vec2(1.5);\n"
3897 " out_a = in_a[1];\n"
3898 " out_b = in_b[1];\n"
3899 " out_c = in_c[1];\n"
3900 " EmitVertex();\n"
3901
3902 " gl_Position = gl_in[2].gl_Position;\n"
3903 " gl_Position.xy *= vec2(-0.1);\n"
3904 " out_a = in_a[2];\n"
3905 " out_b = in_b[2];\n"
3906 " out_c = in_c[2];\n"
3907 " EmitVertex();\n"
3908
3909 " EndPrimitive();\n"
3910 "}\n";
3911
3912
3913 static const char *fragShaderText =
3914 "#version 140\n"
3915 "#extension GL_ARB_separate_shader_objects : enable\n"
3916 "#extension GL_ARB_shading_language_420pack : enable\n"
3917
3918 "layout(location = 0) in vec3 in_a;\n"
3919 "layout(location = 1) in vec3 in_b;\n"
3920 "layout(location = 2) in vec3 in_c;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003921 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003922
3923 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06003924 " outColor = vec4(in_a.x, in_b.y, in_c.z, 1.0);\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003925 "}\n";
3926
3927
3928
3929 ASSERT_NO_FATAL_FAILURE(InitState());
3930 ASSERT_NO_FATAL_FAILURE(InitViewport());
3931
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06003932 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3933 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY_BIT, this);
3934 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003935
3936 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003937 pipelineobj.AddColorAttachment();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003938 pipelineobj.AddShader(&vs);
3939 pipelineobj.AddShader(&gs);
3940 pipelineobj.AddShader(&ps);
3941
3942 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003943 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropa44c2ff2015-04-15 11:19:06 -06003944
3945 VkDescriptorSetObj descriptorSet(m_device);
3946
Tony Barbour1490c912015-07-28 10:17:20 -06003947 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003948
3949 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06003950 Draw(3, 1, 0, 0);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003951
3952 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003953 EndCommandBuffer();
3954 QueueCommandBuffer();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003955
3956 RecordImages(m_renderTargets);
3957}
3958
3959TEST_F(VkRenderTest, GSTriStrip)
3960{
3961 // This test emits multiple multiple triangles using a GS
3962 // Correct result is an multicolor circle
3963
3964 static const char *vertShaderText =
3965 "#version 140\n"
3966 "#extension GL_ARB_separate_shader_objects : enable\n"
3967 "#extension GL_ARB_shading_language_420pack : enable\n"
3968
3969 "void main() {\n"
3970
3971 // generic position stuff
3972 " vec2 vertices;\n"
3973 " int vertexSelector = gl_VertexID;\n"
3974 " if (vertexSelector == 0)\n"
3975 " vertices = vec2(-0.5, -0.5);\n"
3976 " else if (vertexSelector == 1)\n"
3977 " vertices = vec2( 0.5, -0.5);\n"
3978 " else if (vertexSelector == 2)\n"
3979 " vertices = vec2( 0.5, 0.5);\n"
3980 " else\n"
3981 " vertices = vec2( 0.0, 0.0);\n"
3982 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3983
3984 "}\n";
3985
3986 static const char *geomShaderText =
3987 "#version 330\n"
3988 "#extension GL_ARB_separate_shader_objects : enable\n"
3989 "#extension GL_ARB_shading_language_420pack : enable\n"
3990 "layout( triangles ) in;\n"
3991 "layout( triangle_strip, max_vertices = 18 ) out;\n"
3992
3993 "layout(location = 0) out vec4 outColor;\n"
3994
3995 "void main()\n"
3996 "{\n"
3997 // init with first position to get zw
3998 " gl_Position = gl_in[0].gl_Position;\n"
3999
4000 " vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
4001 " vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
4002 " vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
4003 " vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
4004
4005 // different color per tri
4006 " vec4[6] colors = { red, white, \n"
4007 " yellow, white, \n"
4008 " blue, white }; \n"
4009
4010 // fan out the triangles
4011 " vec2[18] positions = { vec2(0.0, 0.0), vec2(-0.5, 0.0), vec2(-0.25, -0.5), \n"
4012 " vec2(0.0, 0.0), vec2(-0.25, -0.5), vec2( 0.25, -0.5), \n"
4013 " vec2(0.0, 0.0), vec2( 0.25, -0.5), vec2( 0.5, 0.0), \n"
4014 " vec2(0.0, 0.0), vec2( 0.5, 0.0), vec2( 0.25, 0.5), \n"
4015 " vec2(0.0, 0.0), vec2( 0.25, 0.5), vec2(-0.25, 0.5), \n"
4016 " vec2(0.0, 0.0), vec2(-0.25, 0.5), vec2(-0.5, 0.0) }; \n"
4017
4018 // make a triangle list of 6
4019 " for (int i = 0; i < 6; ++i) { \n"
4020 " outColor = colors[i]; \n"
4021 " for (int j = 0; j < 3; ++j) { \n"
4022 " gl_Position.xy = positions[i * 3 + j]; \n"
4023 " EmitVertex(); \n"
4024 " } \n"
4025 " EndPrimitive();\n"
4026 " } \n"
4027
4028 "}\n";
4029
4030
4031 static const char *fragShaderText =
4032 "#version 150\n"
4033 "#extension GL_ARB_separate_shader_objects : enable\n"
4034 "#extension GL_ARB_shading_language_420pack : enable\n"
4035
4036
4037 "layout(binding = 0) uniform windowDimensions {\n"
4038 " vec4 dimensions;\n"
4039 "};\n"
4040
4041 "layout(location = 0) in vec4 inColor;\n"
4042 "layout(origin_upper_left) in vec4 gl_FragCoord;\n"
GregFd6ebdb32015-06-03 18:40:50 -06004043 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06004044
4045 "void main() {\n"
4046
4047 // discard to make a nice circle
4048 " vec2 pos = abs(gl_FragCoord.xy) - vec2(dimensions.x, dimensions.y) / 2;\n"
4049 " float dist = sqrt(dot(pos, pos));\n"
4050 " if (dist > 50.0)\n"
4051 " discard;\n"
4052
GregFd6ebdb32015-06-03 18:40:50 -06004053 " outColor = inColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06004054
4055 "}\n";
4056
4057
4058
4059 ASSERT_NO_FATAL_FAILURE(InitState());
4060 ASSERT_NO_FATAL_FAILURE(InitViewport());
4061
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06004062 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4063 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY_BIT, this);
4064 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cody Northropa44c2ff2015-04-15 11:19:06 -06004065
4066 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004067 pipelineobj.AddColorAttachment();
Cody Northropa44c2ff2015-04-15 11:19:06 -06004068 pipelineobj.AddShader(&vs);
4069 pipelineobj.AddShader(&gs);
4070 pipelineobj.AddShader(&ps);
4071
4072 const float dimensions[4] = { VkRenderFramework::m_width, VkRenderFramework::m_height , 0.0, 0.0};
4073
4074 VkConstantBufferObj windowDimensions(m_device, sizeof(dimensions) / sizeof(dimensions[0]), sizeof(dimensions[0]), (const void*) dimensions);
4075
4076 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06004077 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropa44c2ff2015-04-15 11:19:06 -06004078
4079 VkDescriptorSetObj descriptorSet(m_device);
4080 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, windowDimensions);
4081
Tony Barbour1490c912015-07-28 10:17:20 -06004082 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northropa44c2ff2015-04-15 11:19:06 -06004083
4084 // render triangle
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06004085 Draw(3, 1, 0, 0);
Cody Northropa44c2ff2015-04-15 11:19:06 -06004086
4087 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06004088 EndCommandBuffer();
4089 QueueCommandBuffer();
Cody Northropa44c2ff2015-04-15 11:19:06 -06004090
4091 RecordImages(m_renderTargets);
4092}
4093
Chris Forbes23e6db62015-06-15 09:32:35 +12004094TEST_F(VkRenderTest, RenderPassLoadOpClear)
4095{
4096 ASSERT_NO_FATAL_FAILURE(InitState());
4097 ASSERT_NO_FATAL_FAILURE(InitViewport());
4098
4099 /* clear via load op to full green */
4100 m_clear_via_load_op = true;
Cody Northrop2563a032015-08-25 15:26:38 -06004101 m_clear_color.float32[0] = 0;
4102 m_clear_color.float32[1] = 1;
4103 m_clear_color.float32[2] = 0;
4104 m_clear_color.float32[3] = 0;
Chris Forbes23e6db62015-06-15 09:32:35 +12004105 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06004106 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Chris Forbes23e6db62015-06-15 09:32:35 +12004107 /* This command buffer contains ONLY the load op! */
Tony Barbour1490c912015-07-28 10:17:20 -06004108 EndCommandBuffer();
4109 QueueCommandBuffer();
Chris Forbes23e6db62015-06-15 09:32:35 +12004110
4111 RecordImages(m_renderTargets);
4112}
4113
Chris Forbes1e16cb82015-06-24 12:05:30 +12004114TEST_F(VkRenderTest, RenderPassAttachmentClear)
4115{
4116 ASSERT_NO_FATAL_FAILURE(InitState());
4117 ASSERT_NO_FATAL_FAILURE(InitViewport());
4118
4119 /* clear via load op to full red */
4120 m_clear_via_load_op = true;
Cody Northrop2563a032015-08-25 15:26:38 -06004121 m_clear_color.float32[0] = 1;
4122 m_clear_color.float32[1] = 0;
4123 m_clear_color.float32[2] = 0;
4124 m_clear_color.float32[3] = 0;
Chris Forbes1e16cb82015-06-24 12:05:30 +12004125 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06004126 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Chris Forbes1e16cb82015-06-24 12:05:30 +12004127
4128 /* Load op has cleared to red */
4129
4130 /* Draw, draw, draw... */
4131
4132 /* Now, partway through this renderpass we want to clear the color
4133 * attachment again, this time to green.
4134 */
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004135 VkClearAttachment color_attachment;
4136 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4137 color_attachment.clearValue.color.float32[0] = 0;
4138 color_attachment.clearValue.color.float32[1] = 1;
4139 color_attachment.clearValue.color.float32[2] = 0;
4140 color_attachment.clearValue.color.float32[3] = 0;
4141 color_attachment.colorAttachment = 0;
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -06004142 VkClearRect clear_rect = { { { 0, 0 }, { (int)m_width, (int)m_height } } };
Courtney Goeltzenleuchter9feb0732015-10-15 16:51:05 -06004143 vkCmdClearAttachments(m_cmdBuffer->handle(), 1, &color_attachment,
4144 1, &clear_rect);
Chris Forbes1e16cb82015-06-24 12:05:30 +12004145
Tony Barbour1490c912015-07-28 10:17:20 -06004146 EndCommandBuffer();
4147 QueueCommandBuffer();
Chris Forbes1e16cb82015-06-24 12:05:30 +12004148
4149 RecordImages(m_renderTargets);
4150}
4151
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004152int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004153 int result;
4154
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004155 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06004156 VkTestFramework::InitArgs(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004157
Chia-I Wu7133fdc2014-12-15 23:57:34 +08004158 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06004159
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004160 result = RUN_ALL_TESTS();
4161
Tony Barbour01999182015-04-09 12:58:51 -06004162 VkTestFramework::Finish();
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004163 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004164}