blob: 2d789950cd74055fa59eb52f65253ef37fbb5d4e [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 Goeltzenleuchterb85c5812014-08-19 18:35:50 -060073#include "gtest-1.7.0/include/gtest/gtest.h"
74
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); }
283 void Draw(uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount)
284 { m_cmdBuffer->Draw(firstVertex, vertexCount, firstInstance, instanceCount); }
285 void DrawIndexed(uint32_t firstVertex, uint32_t vertexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount)
286 { m_cmdBuffer->DrawIndexed(firstVertex, vertexCount, vertexOffset,firstInstance, instanceCount); }
287 void QueueCommandBuffer() { m_cmdBuffer->QueueCommandBuffer(); }
288 void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
289 VkConstantBufferObj *constantBuffer)
290 {RotateTriangleVSUniform(Projection, View, Model, constantBuffer, m_cmdBuffer); }
291 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding)
292 { m_cmdBuffer->BindVertexBuffer(vertexBuffer, offset, binding); }
293 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset)
294 { m_cmdBuffer->BindIndexBuffer(indexBuffer, offset); }
295
296
Cody 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();
Cody Northropf5bd2252015-08-17 11:10:49 -0600387 cmdBuffer->BindDynamicRasterLineState(m_stateRasterLine);
388 cmdBuffer->BindDynamicRasterDepthBiasState(m_stateRasterDepthBias);
Tony Barboure84a8d62015-07-10 14:10:27 -0600389 cmdBuffer->BindDynamicViewportState(m_stateViewport);
390 cmdBuffer->BindDynamicColorBlendState(m_colorBlend);
391 cmdBuffer->BindDynamicDepthStencilState(m_stateDepthStencil);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600392 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
Tony Barboured132432015-08-04 16:23:11 -0600393 pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600394 cmdBuffer->BindPipeline(pipelineobj);
Chia-I Wu862c5572015-03-28 15:23:55 +0800395 cmdBuffer->BindDescriptorSet(descriptorSet);
Tony Barbour02472db2015-01-08 17:08:28 -0700396}
Tony Barbourf43b6982014-11-25 13:18:32 -0700397
Tony Barbour01999182015-04-09 12:58:51 -0600398void VkRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
399 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer)
Tony Barbourdd4c9642015-01-09 12:55:14 -0700400{
401 int i;
402 glm::mat4 MVP;
403 int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600404 VkResult err;
Tony Barbourdd4c9642015-01-09 12:55:14 -0700405
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600406 /* Only do 3 positions to avoid back face cull */
407 for (i = 0; i < 3; i++) {
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800408 void *pData = constantBuffer->memory().map();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700409
410 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
411 MVP = Projection * View * Model;
412 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
413
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800414 constantBuffer->memory().unmap();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700415
416 // submit the command buffer to the universal queue
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600417 cmdBuffer->QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700418
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600419 err = vkQueueWaitIdle( m_device->m_queue );
420 ASSERT_VK_SUCCESS( err );
Tony Barbourdd4c9642015-01-09 12:55:14 -0700421
422 // Wait for work to finish before cleaning up.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600423 vkDeviceWaitIdle(m_device->device());
Tony Barbourdd4c9642015-01-09 12:55:14 -0700424
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700425 assert(m_renderTargets.size() == 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -0700426 RecordImage(m_renderTargets[0]);
427 }
428}
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600429
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600430void dumpMatrix(const char *note, glm::mat4 MVP)
431{
Chia-I Wu7133fdc2014-12-15 23:57:34 +0800432 int i;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600433
434 printf("%s: \n", note);
435 for (i=0; i<4; i++) {
436 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
437 }
438 printf("\n");
439 fflush(stdout);
440}
441
442void dumpVec4(const char *note, glm::vec4 vector)
443{
444 printf("%s: \n", note);
445 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
446 printf("\n");
447 fflush(stdout);
448}
449
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600450struct vktriangle_vs_uniform {
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600451 // Must start with MVP
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600452 float mvp[4][4];
453 float position[3][4];
454 float color[3][4];
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600455};
456
Tony Barbour01999182015-04-09 12:58:51 -0600457void VkRenderTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600458{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700459#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600460 vkDbgRegisterMsgCallback(inst, myDbgFunc, NULL);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700461#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600462 // Create identity matrix
463 int i;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600464 struct vktriangle_vs_uniform data;
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600465
466 glm::mat4 Projection = glm::mat4(1.0f);
467 glm::mat4 View = glm::mat4(1.0f);
468 glm::mat4 Model = glm::mat4(1.0f);
469 glm::mat4 MVP = Projection * View * Model;
470 const int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600471 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600472 memcpy(&data.mvp, &MVP[0][0], matrixSize);
473
474 static const Vertex tri_data[] =
475 {
476 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
477 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
478 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
479 };
480
481 for (i=0; i<3; i++) {
482 data.position[i][0] = tri_data[i].posX;
483 data.position[i][1] = tri_data[i].posY;
484 data.position[i][2] = tri_data[i].posZ;
485 data.position[i][3] = tri_data[i].posW;
486 data.color[i][0] = tri_data[i].r;
487 data.color[i][1] = tri_data[i].g;
488 data.color[i][2] = tri_data[i].b;
489 data.color[i][3] = tri_data[i].a;
490 }
491
Tony Barbourf43b6982014-11-25 13:18:32 -0700492 ASSERT_NO_FATAL_FAILURE(InitState());
493 ASSERT_NO_FATAL_FAILURE(InitViewport());
494
Tony Barbour01999182015-04-09 12:58:51 -0600495 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barbourf43b6982014-11-25 13:18:32 -0700496
Tony Barbour01999182015-04-09 12:58:51 -0600497 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
498 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700499
Tony Barbour01999182015-04-09 12:58:51 -0600500 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800501 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -0700502 pipelineobj.AddShader(&vs);
503 pipelineobj.AddShader(&ps);
504
Tony Barbour01999182015-04-09 12:58:51 -0600505 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600506 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700507
Tony Barbour71ba3612015-01-09 16:12:35 -0700508 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis7f7b4422015-08-18 14:24:32 -0600509
510 VkCmdBufferBeginInfo cbBeginInfo;
511 memset(&cbBeginInfo, 0, sizeof(VkCmdBufferBeginInfo));
512 cbBeginInfo.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
513 cbBeginInfo.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT;
514 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barbourf43b6982014-11-25 13:18:32 -0700515
Tony Barbour1490c912015-07-28 10:17:20 -0600516 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour71ba3612015-01-09 16:12:35 -0700517#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600518 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour71ba3612015-01-09 16:12:35 -0700519 pDSDumpDot((char*)"triTest2.dot");
520#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600521
Tony Barbour71ba3612015-01-09 16:12:35 -0700522 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -0600523 Draw(0, 3, 0, 1);
Tony Barbour71ba3612015-01-09 16:12:35 -0700524
525 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600526 ASSERT_VK_SUCCESS(EndCommandBuffer());
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600527
Tony Barbour1490c912015-07-28 10:17:20 -0600528 QueueCommandBuffer();
Tony Barbour71ba3612015-01-09 16:12:35 -0700529
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600530 RecordImages(m_renderTargets);
Tony Barbour71ba3612015-01-09 16:12:35 -0700531
532 if (rotate)
Tony Barbour1490c912015-07-28 10:17:20 -0600533 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer);
Tony Barbour71ba3612015-01-09 16:12:35 -0700534
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700535#ifdef PRINT_OBJECTS
Mark Lobodzinski4e5016f2015-05-05 15:01:37 -0500536 OBJ_TRACK_GET_OBJECTS_COUNT pObjTrackGetObjectsCount = (OBJ_TRACK_GET_OBJECTS_COUNT)vkGetProcAddr(gpu(), (char*)"objTrackGetObjectsCount");
Mark Lobodzinski14305ad2015-06-23 11:35:12 -0600537 uint64_t numObjects = pObjTrackGetObjectsCount(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600538 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700539 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600540 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700541 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
Mark Lobodzinski14305ad2015-06-23 11:35:12 -0600542 pObjTrackGetObjs(m_device, numObjects, pObjNodeArray);
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700543 for (i=0; i < numObjects; i++) {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600544 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 -0700545 }
546 free(pObjNodeArray);
547#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700548
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600549}
550
Tony Barbour01999182015-04-09 12:58:51 -0600551TEST_F(VkRenderTest, VKTriangle_FragColor)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600552{
553 static const char *vertShaderText =
554 "#version 140\n"
555 "#extension GL_ARB_separate_shader_objects : enable\n"
556 "#extension GL_ARB_shading_language_420pack : enable\n"
557 "\n"
558 "layout(binding = 0) uniform buf {\n"
559 " mat4 MVP;\n"
560 " vec4 position[3];\n"
561 " vec4 color[3];\n"
562 "} ubuf;\n"
563 "\n"
564 "layout (location = 0) out vec4 outColor;\n"
565 "\n"
566 "void main() \n"
567 "{\n"
568 " outColor = ubuf.color[gl_VertexID];\n"
569 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
570 "}\n";
571
572 static const char *fragShaderText =
573 "#version 140\n"
574 "#extension GL_ARB_separate_shader_objects : enable\n"
575 "#extension GL_ARB_shading_language_420pack : enable\n"
576 "\n"
577 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600578 "layout (location = 0) out vec4 uFragColor;\n"
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600579 "\n"
580 "void main()\n"
581 "{\n"
GregFd6ebdb32015-06-03 18:40:50 -0600582 " uFragColor = inColor;\n"
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600583 "}\n";
584
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600585 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
586 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600587}
588
Tony Barbour01999182015-04-09 12:58:51 -0600589TEST_F(VkRenderTest, VKTriangle_OutputLocation)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600590{
591 static const char *vertShaderText =
592 "#version 140\n"
593 "#extension GL_ARB_separate_shader_objects : enable\n"
594 "#extension GL_ARB_shading_language_420pack : enable\n"
595 "\n"
596 "layout(binding = 0) uniform buf {\n"
597 " mat4 MVP;\n"
598 " vec4 position[3];\n"
599 " vec4 color[3];\n"
600 "} ubuf;\n"
601 "\n"
602 "layout (location = 0) out vec4 outColor;\n"
603 "\n"
604 "void main() \n"
605 "{\n"
606 " outColor = ubuf.color[gl_VertexID];\n"
607 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
608 "}\n";
609
610 static const char *fragShaderText =
611 "#version 140\n"
612 "#extension GL_ARB_separate_shader_objects : enable\n"
613 "#extension GL_ARB_shading_language_420pack : enable\n"
614 "\n"
615 "layout (location = 0) in vec4 inColor;\n"
616 "layout (location = 0) out vec4 outColor;\n"
617 "\n"
618 "void main()\n"
619 "{\n"
620 " outColor = inColor;\n"
621 "}\n";
622
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600623 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 -0600624
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600625 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600626}
Cody Northrop71727d22015-06-23 13:25:51 -0600627
Tony Barbour01999182015-04-09 12:58:51 -0600628TEST_F(VkRenderTest, SPV_VKTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700629{
Tony Barbourf43b6982014-11-25 13:18:32 -0700630 static const char *vertShaderText =
631 "#version 140\n"
632 "#extension GL_ARB_separate_shader_objects : enable\n"
633 "#extension GL_ARB_shading_language_420pack : enable\n"
634 "\n"
635 "layout(binding = 0) uniform buf {\n"
636 " mat4 MVP;\n"
637 " vec4 position[3];\n"
638 " vec4 color[3];\n"
639 "} ubuf;\n"
640 "\n"
641 "layout (location = 0) out vec4 outColor;\n"
642 "\n"
643 "void main() \n"
644 "{\n"
645 " outColor = ubuf.color[gl_VertexID];\n"
646 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
647 "}\n";
648
649 static const char *fragShaderText =
650 "#version 140\n"
651 "#extension GL_ARB_separate_shader_objects : enable\n"
652 "#extension GL_ARB_shading_language_420pack : enable\n"
653 "\n"
654 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600655 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700656 "\n"
657 "void main()\n"
658 "{\n"
GregFd6ebdb32015-06-03 18:40:50 -0600659 " outColor = inColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700660 "}\n";
661
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600662 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 -0700663
Cody Northrop1cfbd172015-06-03 16:49:20 -0600664 ScopedUseGlsl useGlsl(false);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600665 VKTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700666}
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600667
Tony Barbour01999182015-04-09 12:58:51 -0600668TEST_F(VkRenderTest, SPV_GreenTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700669{
Tony Barbourf43b6982014-11-25 13:18:32 -0700670 static const char *vertShaderText =
671 "#version 130\n"
672 "vec2 vertices[3];\n"
673 "void main() {\n"
674 " vertices[0] = vec2(-1.0, -1.0);\n"
675 " vertices[1] = vec2( 1.0, -1.0);\n"
676 " vertices[2] = vec2( 0.0, 1.0);\n"
677 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
678 "}\n";
679
680 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600681 "#version 140\n"
682 "#extension GL_ARB_separate_shader_objects : enable\n"
683 "#extension GL_ARB_shading_language_420pack : enable\n"
684 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700685 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600686 " outColor = vec4(0,1,0,1);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700687 "}\n";
688
Cody Northropacfb0492015-03-17 15:55:58 -0600689 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700690
Cody Northrop1cfbd172015-06-03 16:49:20 -0600691 ScopedUseGlsl useGlsl(false);
692
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600693 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700694}
Cody Northrop71727d22015-06-23 13:25:51 -0600695
Tony Barbour01999182015-04-09 12:58:51 -0600696TEST_F(VkRenderTest, YellowTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700697{
698 static const char *vertShaderText =
699 "#version 130\n"
700 "void main() {\n"
701 " vec2 vertices[3];"
702 " vertices[0] = vec2(-0.5, -0.5);\n"
703 " vertices[1] = vec2( 0.5, -0.5);\n"
704 " vertices[2] = vec2( 0.5, 0.5);\n"
705 " vec4 colors[3];\n"
706 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
707 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
708 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
709 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
710 "}\n";
711
712 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600713 "#version 140\n"
714 "#extension GL_ARB_separate_shader_objects : enable\n"
715 "#extension GL_ARB_shading_language_420pack : enable\n"
716 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700717 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600718 " outColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700719 "}\n";
720
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600721 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700722}
723
Tony Barbour01999182015-04-09 12:58:51 -0600724TEST_F(VkRenderTest, QuadWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600725{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600726 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600727 "#version 140\n"
728 "#extension GL_ARB_separate_shader_objects : enable\n"
729 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700730 //XYZ1( -1, -1, -1 )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600731 "layout (location = 0) in vec4 pos;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700732 //XYZ1( 0.f, 0.f, 0.f )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600733 "layout (location = 1) in vec4 inColor;\n"
734 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600735 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600736 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600737 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600738 "}\n";
739
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600740
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600741 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700742 "#version 140\n"
743 "#extension GL_ARB_separate_shader_objects : enable\n"
744 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600745 "layout (location = 0) in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700746 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600747 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700748 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600749 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600750
Tony Barbourf43b6982014-11-25 13:18:32 -0700751
752
753 ASSERT_NO_FATAL_FAILURE(InitState());
754 ASSERT_NO_FATAL_FAILURE(InitViewport());
755
Tony Barbour01999182015-04-09 12:58:51 -0600756 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000757 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700758
Tony Barbour01999182015-04-09 12:58:51 -0600759 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
760 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700761
Tony Barbour01999182015-04-09 12:58:51 -0600762 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800763 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -0700764 pipelineobj.AddShader(&vs);
765 pipelineobj.AddShader(&ps);
766
Tony Barbour01999182015-04-09 12:58:51 -0600767 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600768 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -0600769
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600770#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600771 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600772 MESH_BIND_ID, // binding ID
Tony Barbourf43b6982014-11-25 13:18:32 -0700773 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600774 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -0700775 };
776
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600777 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600778 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
779 vi_attribs[0].location = 0; // location, position
Tony Barbour8205d902015-04-16 15:59:00 -0600780 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600781 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
782 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
783 vi_attribs[1].location = 1; // location, color
Tony Barbour8205d902015-04-16 15:59:00 -0600784 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600785 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 -0700786
787 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
788 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600789 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -0700790
Tony Barboure4ed9942015-01-09 10:06:53 -0700791 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -0600792 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourf43b6982014-11-25 13:18:32 -0700793
Tony Barbour1490c912015-07-28 10:17:20 -0600794 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600795
Tony Barbour1490c912015-07-28 10:17:20 -0600796 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barboure4ed9942015-01-09 10:06:53 -0700797
798 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -0600799 Draw(0, 6, 0, 1);
Tony Barboure4ed9942015-01-09 10:06:53 -0700800
801 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600802 ASSERT_VK_SUCCESS(EndCommandBuffer());
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600803
Tony Barbour1490c912015-07-28 10:17:20 -0600804 QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -0700805
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600806 RecordImages(m_renderTargets);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600807}
808
Tony Barbour01999182015-04-09 12:58:51 -0600809TEST_F(VkRenderTest, TriangleMRT)
Chia-I Wue09d1a72014-12-05 10:32:23 +0800810{
811 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600812 "#version 140\n"
813 "#extension GL_ARB_separate_shader_objects : enable\n"
814 "#extension GL_ARB_shading_language_420pack : enable\n"
815 "layout (location = 0) in vec4 pos;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800816 "void main() {\n"
817 " gl_Position = pos;\n"
818 "}\n";
819
820 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600821 "#version 140\n"
822 "#extension GL_ARB_separate_shader_objects : enable\n"
823 "#extension GL_ARB_shading_language_420pack : enable\n"
824 "layout (location = 0) out vec4 uFragData0;\n"
825 "layout (location = 1) out vec4 uFragData1;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800826 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600827 " uFragData0 = vec4(1.0, 0.0, 0.0, 1.0);\n"
828 " uFragData1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800829 "}\n";
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600830 const float vb_data[][2] = {
Chia-I Wue09d1a72014-12-05 10:32:23 +0800831 { -1.0f, -1.0f },
832 { 1.0f, -1.0f },
833 { -1.0f, 1.0f }
834 };
835
836 ASSERT_NO_FATAL_FAILURE(InitState());
837 ASSERT_NO_FATAL_FAILURE(InitViewport());
838
Tony Barbour01999182015-04-09 12:58:51 -0600839 VkConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000840 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800841
Tony Barbour01999182015-04-09 12:58:51 -0600842 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
843 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800844
Tony Barbour01999182015-04-09 12:58:51 -0600845 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800846 pipelineobj.AddColorAttachment();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800847 pipelineobj.AddShader(&vs);
848 pipelineobj.AddShader(&ps);
849
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600850#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600851 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600852 MESH_BUF_ID, // Binding ID
853 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600854 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Chia-I Wue09d1a72014-12-05 10:32:23 +0800855 };
856
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600857 VkVertexInputAttributeDescription vi_attrib;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600858 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
859 vi_attrib.location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -0600860 vi_attrib.format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600861 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
Chia-I Wue09d1a72014-12-05 10:32:23 +0800862
863 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
864 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600865 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800866
Tony Barbour01999182015-04-09 12:58:51 -0600867 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600868 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800869
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700870 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
Chia-I Wue09d1a72014-12-05 10:32:23 +0800871
Tony Barboure307f582015-07-10 15:29:03 -0600872 VkPipelineColorBlendAttachmentState att = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600873 att.blendEnable = VK_FALSE;
Chia-I Wue09d1a72014-12-05 10:32:23 +0800874 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700875 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800876
Tony Barbour1490c912015-07-28 10:17:20 -0600877 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure4ed9942015-01-09 10:06:53 -0700878
Tony Barbour1490c912015-07-28 10:17:20 -0600879 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700880
Tony Barbour1490c912015-07-28 10:17:20 -0600881 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700882#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600883 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour5ed79702015-01-07 14:31:52 -0700884 pDSDumpDot((char*)"triTest2.dot");
885#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600886
Tony Barbour5ed79702015-01-07 14:31:52 -0700887 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -0600888 Draw(0, 3, 0, 1);
Tony Barbour5ed79702015-01-07 14:31:52 -0700889
890 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600891 ASSERT_VK_SUCCESS(EndCommandBuffer());
892 QueueCommandBuffer();
Tony Barbour5ed79702015-01-07 14:31:52 -0700893
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600894 RecordImages(m_renderTargets);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800895}
896
Tony Barbour01999182015-04-09 12:58:51 -0600897TEST_F(VkRenderTest, QuadWithIndexedVertexFetch)
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700898{
899 static const char *vertShaderText =
900 "#version 140\n"
901 "#extension GL_ARB_separate_shader_objects : enable\n"
902 "#extension GL_ARB_shading_language_420pack : enable\n"
903 "layout(location = 0) in vec4 pos;\n"
904 "layout(location = 1) in vec4 inColor;\n"
905 "layout(location = 0) out vec4 outColor;\n"
906 "void main() {\n"
907 " outColor = inColor;\n"
908 " gl_Position = pos;\n"
909 "}\n";
910
911
912 static const char *fragShaderText =
913 "#version 140\n"
914 "#extension GL_ARB_separate_shader_objects : enable\n"
915 "#extension GL_ARB_shading_language_420pack : enable\n"
916 "layout(location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600917 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700918 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600919 " outColor = color;\n"
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700920 "}\n";
921
922 const Vertex g_vbData[] =
923 {
924 // first tri
925 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
926 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
927 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
928
929 // second tri
930 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
931 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
932 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
933 };
934
935 const uint16_t g_idxData[6] = {
936 0, 1, 2,
937 3, 4, 5,
938 };
939
940 ASSERT_NO_FATAL_FAILURE(InitState());
941 ASSERT_NO_FATAL_FAILURE(InitViewport());
942
Tony Barbour01999182015-04-09 12:58:51 -0600943 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000944 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700945
Tony Barbour01999182015-04-09 12:58:51 -0600946 VkIndexBufferObj indexBuffer(m_device);
Tony Barbour8205d902015-04-16 15:59:00 -0600947 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), VK_INDEX_TYPE_UINT16, g_idxData);
Mark Lobodzinskid30f82a2015-02-16 14:24:23 -0600948 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700949
Tony Barbour01999182015-04-09 12:58:51 -0600950 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
951 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700952
Tony Barbour01999182015-04-09 12:58:51 -0600953 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800954 pipelineobj.AddColorAttachment();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700955 pipelineobj.AddShader(&vs);
956 pipelineobj.AddShader(&ps);
957
Tony Barbour01999182015-04-09 12:58:51 -0600958 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600959 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
960 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, indexBuffer);
Tony Barbour83a83802015-04-02 15:43:15 -0600961
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700962
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600963#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600964 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600965 MESH_BIND_ID, // binding ID
966 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600967 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700968 };
969
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600970 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600971 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
972 vi_attribs[0].location = 0; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600973 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600974 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
975 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
976 vi_attribs[1].location = 1; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600977 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600978 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700979
980 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
981 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700982
983 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -0600984 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure4ed9942015-01-09 10:06:53 -0700985
Tony Barbour1490c912015-07-28 10:17:20 -0600986 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700987
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700988#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600989 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700990 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700991#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700992
Tony Barbour1490c912015-07-28 10:17:20 -0600993 BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
994 BindIndexBuffer(&indexBuffer, 0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700995
996 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -0600997 DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700998
999 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001000 ASSERT_VK_SUCCESS(EndCommandBuffer());
1001 QueueCommandBuffer();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001002
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001003 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001004}
1005
Tony Barbour01999182015-04-09 12:58:51 -06001006TEST_F(VkRenderTest, GreyandRedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -07001007{
1008 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -07001009
GregF6bef1212014-12-02 15:41:44 -07001010 static const char *vertShaderText =
1011 "#version 140\n"
1012 "#extension GL_ARB_separate_shader_objects : enable\n"
1013 "#extension GL_ARB_shading_language_420pack : enable\n"
1014 "layout (location = 0) in vec4 pos;\n"
1015 "layout (location = 0) out vec4 outColor;\n"
1016 "layout (location = 1) out vec4 outColor2;\n"
1017 "void main() {\n"
1018 " gl_Position = pos;\n"
1019 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1020 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1021 "}\n";
1022
1023 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001024 "#version 330\n"
1025 "#extension GL_ARB_separate_shader_objects : enable\n"
1026 "#extension GL_ARB_shading_language_420pack : enable\n"
1027 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1028 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1029 "layout (location = 0) in vec4 color;\n"
1030 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001031 "layout (location = 0) out vec4 outColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001032 "void main() {\n"
1033 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1034 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001035 " outColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001036 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1037 " : color2;\n"
1038 "}\n";
1039
1040 ASSERT_NO_FATAL_FAILURE(InitState());
1041 ASSERT_NO_FATAL_FAILURE(InitViewport());
1042
Tony Barbour01999182015-04-09 12:58:51 -06001043 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001044 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001045
Tony Barbour01999182015-04-09 12:58:51 -06001046 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1047 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001048
Tony Barbour01999182015-04-09 12:58:51 -06001049 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001050 pipelineobj.AddColorAttachment();
GregF6bef1212014-12-02 15:41:44 -07001051 pipelineobj.AddShader(&vs);
1052 pipelineobj.AddShader(&ps);
1053
Tony Barbour01999182015-04-09 12:58:51 -06001054 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001055 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001056
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001057#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001058 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001059 MESH_BIND_ID, // binding ID
1060 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001061 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001062 };
1063
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001064 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001065 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1066 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001067 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001068 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001069
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001070 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001071 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001072 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001073
Tony Barbourdd4c9642015-01-09 12:55:14 -07001074 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001075
Tony Barbour1490c912015-07-28 10:17:20 -06001076 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001077
Tony Barbour1490c912015-07-28 10:17:20 -06001078 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001079
Tony Barbour1490c912015-07-28 10:17:20 -06001080 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001081#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001082 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001083 pDSDumpDot((char*)"triTest2.dot");
1084#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001085
Tony Barbourdd4c9642015-01-09 12:55:14 -07001086 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06001087 Draw(0, 6, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001088
1089 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001090 EndCommandBuffer();
1091 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001092
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001093 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001094}
1095
Tony Barbour01999182015-04-09 12:58:51 -06001096TEST_F(VkRenderTest, RedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -07001097{
1098 // This tests that we correctly handle unread fragment inputs
1099
1100 static const char *vertShaderText =
1101 "#version 140\n"
1102 "#extension GL_ARB_separate_shader_objects : enable\n"
1103 "#extension GL_ARB_shading_language_420pack : enable\n"
1104 "layout (location = 0) in vec4 pos;\n"
1105 "layout (location = 0) out vec4 outColor;\n"
1106 "layout (location = 1) out vec4 outColor2;\n"
1107 "void main() {\n"
1108 " gl_Position = pos;\n"
1109 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1110 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1111 "}\n";
1112
1113 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001114 "#version 330\n"
1115 "#extension GL_ARB_separate_shader_objects : enable\n"
1116 "#extension GL_ARB_shading_language_420pack : enable\n"
1117 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1118 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1119 "layout (location = 0) in vec4 color;\n"
1120 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001121 "layout (location = 0) out vec4 outColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001122 "void main() {\n"
1123 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1124 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001125 " outColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001126 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1127 " : color2;\n"
1128 "}\n";
1129
1130 ASSERT_NO_FATAL_FAILURE(InitState());
1131 ASSERT_NO_FATAL_FAILURE(InitViewport());
1132
Tony Barbour01999182015-04-09 12:58:51 -06001133 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001134 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001135
Tony Barbour01999182015-04-09 12:58:51 -06001136 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1137 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001138
Tony Barbour01999182015-04-09 12:58:51 -06001139 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001140 pipelineobj.AddColorAttachment();
GregF6bef1212014-12-02 15:41:44 -07001141 pipelineobj.AddShader(&vs);
1142 pipelineobj.AddShader(&ps);
1143
Tony Barbour01999182015-04-09 12:58:51 -06001144 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001145 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001146
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001147#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001148 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001149 MESH_BIND_ID, // binding ID
1150 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001151 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001152 };
1153
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001154 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001155 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1156 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001157 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001158 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001159
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001160 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001161 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001162 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001163
Tony Barbourdd4c9642015-01-09 12:55:14 -07001164 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06001165 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001166
Tony Barbour1490c912015-07-28 10:17:20 -06001167 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001168
Tony Barbour1490c912015-07-28 10:17:20 -06001169 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001170#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001171 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001172 pDSDumpDot((char*)"triTest2.dot");
1173#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001174 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001175 Draw(0, 6, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001176
1177 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001178 EndCommandBuffer();
1179 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001180
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001181 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001182}
1183
Tony Barbour01999182015-04-09 12:58:51 -06001184TEST_F(VkRenderTest, GreyCirclesonBlueFade)
GregF6bef1212014-12-02 15:41:44 -07001185{
1186 // This tests reading gl_ClipDistance from FS
1187
1188 static const char *vertShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001189 //"#version 140\n"
GregF6bef1212014-12-02 15:41:44 -07001190 "#version 330\n"
1191 "#extension GL_ARB_separate_shader_objects : enable\n"
1192 "#extension GL_ARB_shading_language_420pack : enable\n"
1193 "out gl_PerVertex {\n"
1194 " vec4 gl_Position;\n"
1195 " float gl_ClipDistance[1];\n"
1196 "};\n"
1197 "layout (location = 0) in vec4 pos;\n"
1198 "layout (location = 0) out vec4 outColor;\n"
1199 "layout (location = 1) out vec4 outColor2;\n"
1200 "void main() {\n"
1201 " gl_Position = pos;\n"
1202 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1203 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1204 " float dists[3];\n"
1205 " dists[0] = 0.0;\n"
1206 " dists[1] = 1.0;\n"
1207 " dists[2] = 1.0;\n"
1208 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1209 "}\n";
1210
1211
1212 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001213 "#version 140\n"
1214 //"#version 330\n"
GregF6bef1212014-12-02 15:41:44 -07001215 "#extension GL_ARB_separate_shader_objects : enable\n"
1216 "#extension GL_ARB_shading_language_420pack : enable\n"
1217 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1218 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1219 "layout (location = 0) in vec4 color;\n"
1220 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001221 "layout (location = 0) out vec4 uFragColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001222 "void main() {\n"
1223 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1224 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001225 " uFragColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001226 " ? color * gl_ClipDistance[0]\n"
1227 " : color2;\n"
1228 "}\n";
1229
1230 ASSERT_NO_FATAL_FAILURE(InitState());
1231 ASSERT_NO_FATAL_FAILURE(InitViewport());
1232
Tony Barbour01999182015-04-09 12:58:51 -06001233 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001234 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001235
Tony Barbour01999182015-04-09 12:58:51 -06001236 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1237 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001238
Tony Barbour01999182015-04-09 12:58:51 -06001239 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001240 pipelineobj.AddColorAttachment();
GregF6bef1212014-12-02 15:41:44 -07001241 pipelineobj.AddShader(&vs);
1242 pipelineobj.AddShader(&ps);
1243
Tony Barbour01999182015-04-09 12:58:51 -06001244 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001245 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001246
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001247#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001248 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001249 MESH_BIND_ID, // binding ID
1250 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001251 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001252 };
1253
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001254 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001255 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1256 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001257 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001258 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001259
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001260 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001261 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001262 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001263
Tony Barbourdd4c9642015-01-09 12:55:14 -07001264 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
GregF6bef1212014-12-02 15:41:44 -07001265
Tony Barbour1490c912015-07-28 10:17:20 -06001266 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001267
Tony Barbour1490c912015-07-28 10:17:20 -06001268 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001269
Tony Barbour1490c912015-07-28 10:17:20 -06001270 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001271#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001272 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001273 pDSDumpDot((char*)"triTest2.dot");
1274#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001275
1276 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001277 Draw(0, 6, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001278
1279 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001280 EndCommandBuffer();
1281 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001282
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001283 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001284}
Tony Barbourf43b6982014-11-25 13:18:32 -07001285
Tony Barbour01999182015-04-09 12:58:51 -06001286TEST_F(VkRenderTest, GreyCirclesonBlueDiscard)
GregF7a23c792014-12-02 17:19:34 -07001287{
1288 static const char *vertShaderText =
1289 "#version 140\n"
1290 "#extension GL_ARB_separate_shader_objects : enable\n"
1291 "#extension GL_ARB_shading_language_420pack : enable\n"
1292 "layout (location = 0) in vec4 pos;\n"
1293 "layout (location = 0) out vec4 outColor;\n"
1294 "layout (location = 1) out vec4 outColor2;\n"
1295 "void main() {\n"
1296 " gl_Position = pos;\n"
1297 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1298 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1299 "}\n";
1300
1301
1302 static const char *fragShaderText =
GregF7a23c792014-12-02 17:19:34 -07001303 "#version 330\n"
1304 "#extension GL_ARB_separate_shader_objects : enable\n"
1305 "#extension GL_ARB_shading_language_420pack : enable\n"
1306 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1307 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1308 "layout (location = 0) in vec4 color;\n"
1309 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001310 "layout (location = 0) out vec4 outColor;\n"
GregF7a23c792014-12-02 17:19:34 -07001311 "void main() {\n"
1312 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1313 " float dist_squared = dot(pos, pos);\n"
1314 " if (dist_squared < 100.0)\n"
1315 " discard;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001316 " outColor = (dist_squared < 400.0)\n"
GregF7a23c792014-12-02 17:19:34 -07001317 " ? color\n"
1318 " : color2;\n"
1319 "}\n";
1320
1321 ASSERT_NO_FATAL_FAILURE(InitState());
1322 ASSERT_NO_FATAL_FAILURE(InitViewport());
1323
Tony Barbour01999182015-04-09 12:58:51 -06001324 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001325 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001326
Tony Barbour01999182015-04-09 12:58:51 -06001327 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1328 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF7a23c792014-12-02 17:19:34 -07001329
Tony Barbour01999182015-04-09 12:58:51 -06001330 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001331 pipelineobj.AddColorAttachment();
GregF7a23c792014-12-02 17:19:34 -07001332 pipelineobj.AddShader(&vs);
1333 pipelineobj.AddShader(&ps);
1334
Tony Barbour01999182015-04-09 12:58:51 -06001335 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001336 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001337
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001338#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001339 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001340 MESH_BIND_ID, // binding ID
1341 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001342 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF7a23c792014-12-02 17:19:34 -07001343 };
1344
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001345 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001346 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1347 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001348 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001349 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF7a23c792014-12-02 17:19:34 -07001350
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001351 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF7a23c792014-12-02 17:19:34 -07001352 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001353 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF7a23c792014-12-02 17:19:34 -07001354
Tony Barbourdd4c9642015-01-09 12:55:14 -07001355 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001356
Tony Barbour1490c912015-07-28 10:17:20 -06001357 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001358
Tony Barbour1490c912015-07-28 10:17:20 -06001359 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001360
Tony Barbour1490c912015-07-28 10:17:20 -06001361 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001362#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001363 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001364 pDSDumpDot((char*)"triTest2.dot");
1365#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001366
1367 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001368 Draw(0, 6, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001369
1370 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001371 EndCommandBuffer();
1372 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001373
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001374 RecordImages(m_renderTargets);
GregF7a23c792014-12-02 17:19:34 -07001375}
1376
1377
Tony Barbour01999182015-04-09 12:58:51 -06001378TEST_F(VkRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001379{
1380 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001381 "#version 140\n"
1382 "#extension GL_ARB_separate_shader_objects : enable\n"
1383 "#extension GL_ARB_shading_language_420pack : enable\n"
1384 "\n"
1385 "layout(binding = 0) uniform buf {\n"
1386 " mat4 MVP;\n"
1387 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001388 "void main() {\n"
1389 " vec2 vertices[3];"
1390 " vertices[0] = vec2(-0.5, -0.5);\n"
1391 " vertices[1] = vec2( 0.5, -0.5);\n"
1392 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001393 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001394 "}\n";
1395
1396 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001397 "#version 140\n"
1398 "#extension GL_ARB_separate_shader_objects : enable\n"
1399 "#extension GL_ARB_shading_language_420pack : enable\n"
1400 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001401 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001402 " outColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001403 "}\n";
1404
Tony Barbourf43b6982014-11-25 13:18:32 -07001405 ASSERT_NO_FATAL_FAILURE(InitState());
1406 ASSERT_NO_FATAL_FAILURE(InitViewport());
1407
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001408 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001409 glm::mat4 Projection = glm::mat4(1.0f);
1410 glm::mat4 View = glm::mat4(1.0f);
1411 glm::mat4 Model = glm::mat4(1.0f);
1412 glm::mat4 MVP = Projection * View * Model;
1413 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1414
Tony Barbour01999182015-04-09 12:58:51 -06001415 VkConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1416 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1417 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001418
Tony Barbour01999182015-04-09 12:58:51 -06001419 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001420 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001421 pipelineobj.AddShader(&vs);
1422 pipelineobj.AddShader(&ps);
1423
1424 // Create descriptor set and attach the constant buffer to it
Tony Barbour01999182015-04-09 12:58:51 -06001425 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001426 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001427
Tony Barbourdd4c9642015-01-09 12:55:14 -07001428 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis7f7b4422015-08-18 14:24:32 -06001429
1430 VkCmdBufferBeginInfo cbBeginInfo;
1431 memset(&cbBeginInfo, 0, sizeof(VkCmdBufferBeginInfo));
1432 cbBeginInfo.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1433 cbBeginInfo.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT;
1434 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barbourf43b6982014-11-25 13:18:32 -07001435
Tony Barbour1490c912015-07-28 10:17:20 -06001436 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001437
Tony Barbourdd4c9642015-01-09 12:55:14 -07001438#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001439 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001440 pDSDumpDot((char*)"triTest2.dot");
1441#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001442
1443 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001444 Draw(0, 6, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001445
1446 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001447 EndCommandBuffer();
1448 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001449
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001450 RecordImages(m_renderTargets);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001451
Tony Barbour1490c912015-07-28 10:17:20 -06001452 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001453}
1454
Tony Barbour01999182015-04-09 12:58:51 -06001455TEST_F(VkRenderTest, MixTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07001456{
1457 // This tests location applied to varyings. Notice that we have switched foo
1458 // and bar in the FS. The triangle should be blended with red, green and blue
1459 // corners.
1460 static const char *vertShaderText =
1461 "#version 140\n"
1462 "#extension GL_ARB_separate_shader_objects : enable\n"
1463 "#extension GL_ARB_shading_language_420pack : enable\n"
1464 "layout (location=0) out vec4 bar;\n"
1465 "layout (location=1) out vec4 foo;\n"
1466 "layout (location=2) out float scale;\n"
1467 "vec2 vertices[3];\n"
1468 "void main() {\n"
1469 " vertices[0] = vec2(-1.0, -1.0);\n"
1470 " vertices[1] = vec2( 1.0, -1.0);\n"
1471 " vertices[2] = vec2( 0.0, 1.0);\n"
1472 "vec4 colors[3];\n"
1473 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1474 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1475 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1476 " foo = colors[gl_VertexID % 3];\n"
1477 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1478 " scale = 1.0;\n"
1479 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1480 "}\n";
1481
1482 static const char *fragShaderText =
1483 "#version 140\n"
1484 "#extension GL_ARB_separate_shader_objects : enable\n"
1485 "#extension GL_ARB_shading_language_420pack : enable\n"
1486 "layout (location = 1) in vec4 bar;\n"
1487 "layout (location = 0) in vec4 foo;\n"
1488 "layout (location = 2) in float scale;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001489 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001490 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001491 " outColor = bar * scale + foo * (1.0-scale);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001492 "}\n";
1493
1494 ASSERT_NO_FATAL_FAILURE(InitState());
1495 ASSERT_NO_FATAL_FAILURE(InitViewport());
1496
Tony Barbour01999182015-04-09 12:58:51 -06001497 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1498 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001499
Tony Barbour01999182015-04-09 12:58:51 -06001500 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001501 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001502 pipelineobj.AddShader(&vs);
1503 pipelineobj.AddShader(&ps);
1504
Tony Barbour01999182015-04-09 12:58:51 -06001505 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06001506 descriptorSet.AppendDummy();
Tony Barbourf43b6982014-11-25 13:18:32 -07001507
Tony Barbourdd4c9642015-01-09 12:55:14 -07001508 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001509
Tony Barbour1490c912015-07-28 10:17:20 -06001510 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001511
Tony Barbour1490c912015-07-28 10:17:20 -06001512 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001513
1514#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001515 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001516 pDSDumpDot((char*)"triTest2.dot");
1517#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001518
Tony Barbourdd4c9642015-01-09 12:55:14 -07001519 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06001520 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001521
1522 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001523 EndCommandBuffer();
1524 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001525
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001526 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001527}
1528
Tony Barbour01999182015-04-09 12:58:51 -06001529TEST_F(VkRenderTest, QuadVertFetchAndVertID)
Tony Barbourf43b6982014-11-25 13:18:32 -07001530{
1531 // This tests that attributes work in the presence of gl_VertexID
1532
1533 static const char *vertShaderText =
1534 "#version 140\n"
1535 "#extension GL_ARB_separate_shader_objects : enable\n"
1536 "#extension GL_ARB_shading_language_420pack : enable\n"
1537 //XYZ1( -1, -1, -1 )
1538 "layout (location = 0) in vec4 pos;\n"
1539 //XYZ1( 0.f, 0.f, 0.f )
1540 "layout (location = 1) in vec4 inColor;\n"
1541 "layout (location = 0) out vec4 outColor;\n"
1542 "void main() {\n"
1543 " outColor = inColor;\n"
1544 " vec4 vertices[3];"
1545 " vertices[gl_VertexID % 3] = pos;\n"
1546 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1547 "}\n";
1548
1549
1550 static const char *fragShaderText =
1551 "#version 140\n"
1552 "#extension GL_ARB_separate_shader_objects : enable\n"
1553 "#extension GL_ARB_shading_language_420pack : enable\n"
1554 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001555 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001556 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001557 " outColor = color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001558 "}\n";
1559
1560 ASSERT_NO_FATAL_FAILURE(InitState());
1561 ASSERT_NO_FATAL_FAILURE(InitViewport());
1562
Tony Barbour01999182015-04-09 12:58:51 -06001563 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001564 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001565
Tony Barbour01999182015-04-09 12:58:51 -06001566 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1567 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001568
Tony Barbour01999182015-04-09 12:58:51 -06001569 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001570 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001571 pipelineobj.AddShader(&vs);
1572 pipelineobj.AddShader(&ps);
1573
Tony Barbour01999182015-04-09 12:58:51 -06001574 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001575 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001576
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001577#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001578 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001579 MESH_BUF_ID, // Binding ID
1580 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001581 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001582 };
1583
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001584 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001585 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1586 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001587 vi_attribs[0].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001588 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1589 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1590 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001591 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001592 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001593
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001594 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001595 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001596 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001597
Tony Barbourdd4c9642015-01-09 12:55:14 -07001598 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001599
Tony Barbour1490c912015-07-28 10:17:20 -06001600 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001601
Tony Barbour1490c912015-07-28 10:17:20 -06001602 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001603
Tony Barbour1490c912015-07-28 10:17:20 -06001604 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001605#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001606 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001607 pDSDumpDot((char*)"triTest2.dot");
1608#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001609
1610 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001611 Draw(0, 6, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001612
1613 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001614 EndCommandBuffer();
1615 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001616
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001617 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001618}
1619
Tony Barbour01999182015-04-09 12:58:51 -06001620TEST_F(VkRenderTest, QuadSparseVertFetch)
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001621{
1622 // This tests that attributes work in the presence of gl_VertexID
1623
1624 static const char *vertShaderText =
1625 "#version 140\n"
1626 "#extension GL_ARB_separate_shader_objects : enable\n"
1627 "#extension GL_ARB_shading_language_420pack : enable\n"
1628 //XYZ1( -1, -1, -1 )
1629 "layout (location = 1) in vec4 pos;\n"
1630 "layout (location = 4) in vec4 inColor;\n"
1631 //XYZ1( 0.f, 0.f, 0.f )
1632 "layout (location = 0) out vec4 outColor;\n"
1633 "void main() {\n"
1634 " outColor = inColor;\n"
1635 " gl_Position = pos;\n"
1636 "}\n";
1637
1638
1639 static const char *fragShaderText =
1640 "#version 140\n"
1641 "#extension GL_ARB_separate_shader_objects : enable\n"
1642 "#extension GL_ARB_shading_language_420pack : enable\n"
1643 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001644 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001645 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001646 " outColor = color;\n"
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001647 "}\n";
1648
1649 ASSERT_NO_FATAL_FAILURE(InitState());
1650 ASSERT_NO_FATAL_FAILURE(InitViewport());
1651
1652 struct VDATA
1653 {
1654 float t1, t2, t3, t4; // filler data
1655 float posX, posY, posZ, posW; // Position data
1656 float r, g, b, a; // Color
1657 };
1658 const struct VDATA vData[] =
1659 {
1660 { XYZ1(0, 0, 0), XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
1661 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1662 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1663 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1664 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1665 { XYZ1(0, 0, 0), XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
1666 };
1667
Tony Barbour01999182015-04-09 12:58:51 -06001668 VkConstantBufferObj meshBuffer(m_device,sizeof(vData)/sizeof(vData[0]),sizeof(vData[0]), vData);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001669 meshBuffer.BufferMemoryBarrier();
1670
Tony Barbour01999182015-04-09 12:58:51 -06001671 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1672 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001673
Tony Barbour01999182015-04-09 12:58:51 -06001674 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001675 pipelineobj.AddColorAttachment();
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001676 pipelineobj.AddShader(&vs);
1677 pipelineobj.AddShader(&ps);
1678
Tony Barbour01999182015-04-09 12:58:51 -06001679 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001680 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001681
1682#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001683 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001684 MESH_BUF_ID, // Binding ID
1685 sizeof(vData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001686 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001687 };
1688
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001689 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001690 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1691 vi_attribs[0].location = 4;
Tony Barbour8205d902015-04-16 15:59:00 -06001692 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001693 vi_attribs[0].offsetInBytes = sizeof(float) * 4 * 2; // Offset of first element in bytes from base of vertex
1694 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1695 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001696 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001697 vi_attribs[1].offsetInBytes = sizeof(float) * 4 * 1; // Offset of first element in bytes from base of vertex
1698
1699 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
1700 pipelineobj.AddVertexInputBindings(&vi_binding, 1);
1701 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
1702
1703 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001704
Tony Barbour1490c912015-07-28 10:17:20 -06001705 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001706
Tony Barbour1490c912015-07-28 10:17:20 -06001707 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001708
Tony Barbour1490c912015-07-28 10:17:20 -06001709 BindVertexBuffer(&meshBuffer, 0, MESH_BUF_ID);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001710#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001711 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001712 pDSDumpDot((char*)"triTest2.dot");
1713#endif
1714
1715 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001716 Draw(0, 6, 0, 1);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001717
1718 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001719 EndCommandBuffer();
1720 QueueCommandBuffer();
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001721
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001722 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001723}
1724
Tony Barbour01999182015-04-09 12:58:51 -06001725TEST_F(VkRenderTest, TriVertFetchDeadAttr)
Tony Barbourf43b6982014-11-25 13:18:32 -07001726{
1727 // This tests that attributes work in the presence of gl_VertexID
1728 // and a dead attribute in position 0. Draws a triangle with yellow,
1729 // red and green corners, starting at top and going clockwise.
1730
1731 static const char *vertShaderText =
1732 "#version 140\n"
1733 "#extension GL_ARB_separate_shader_objects : enable\n"
1734 "#extension GL_ARB_shading_language_420pack : enable\n"
1735 //XYZ1( -1, -1, -1 )
1736 "layout (location = 0) in vec4 pos;\n"
1737 //XYZ1( 0.f, 0.f, 0.f )
1738 "layout (location = 1) in vec4 inColor;\n"
1739 "layout (location = 0) out vec4 outColor;\n"
1740 "void main() {\n"
1741 " outColor = inColor;\n"
1742 " vec2 vertices[3];"
1743 " vertices[0] = vec2(-1.0, -1.0);\n"
1744 " vertices[1] = vec2( 1.0, -1.0);\n"
1745 " vertices[2] = vec2( 0.0, 1.0);\n"
1746 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1747 "}\n";
1748
1749
1750 static const char *fragShaderText =
1751 "#version 140\n"
1752 "#extension GL_ARB_separate_shader_objects : enable\n"
1753 "#extension GL_ARB_shading_language_420pack : enable\n"
1754 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001755 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001756 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001757 " outColor = color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001758 "}\n";
1759
1760 ASSERT_NO_FATAL_FAILURE(InitState());
1761 ASSERT_NO_FATAL_FAILURE(InitViewport());
1762
Tony Barbour01999182015-04-09 12:58:51 -06001763 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001764 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001765
Tony Barbour01999182015-04-09 12:58:51 -06001766 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1767 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001768
Tony Barbour01999182015-04-09 12:58:51 -06001769 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001770 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001771 pipelineobj.AddShader(&vs);
1772 pipelineobj.AddShader(&ps);
1773
Tony Barbour01999182015-04-09 12:58:51 -06001774 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001775 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001776
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001777#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001778 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001779 MESH_BUF_ID, // Binding ID
1780 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001781 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001782 };
1783
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001784 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001785 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1786 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001787 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001788 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1789 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1790 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001791 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001792 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001793
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001794 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001795 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001796 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001797
Tony Barbourdd4c9642015-01-09 12:55:14 -07001798 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourf43b6982014-11-25 13:18:32 -07001799
Tony Barbour1490c912015-07-28 10:17:20 -06001800 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001801
Tony Barbour1490c912015-07-28 10:17:20 -06001802 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001803
Tony Barbour1490c912015-07-28 10:17:20 -06001804 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001805#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001806 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001807 pDSDumpDot((char*)"triTest2.dot");
1808#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001809
1810 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001811 Draw(0, 6, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001812
1813 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001814 EndCommandBuffer();
1815 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001816
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001817 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001818}
1819
Tony Barbour01999182015-04-09 12:58:51 -06001820TEST_F(VkRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001821{
1822 static const char *vertShaderText =
1823 "#version 140\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001824 "#extension GL_ARB_separate_shader_objects : enable\n"
1825 "#extension GL_ARB_shading_language_420pack : enable\n"
GregFd6ebdb32015-06-03 18:40:50 -06001826 "layout (std140, binding = 0) uniform bufferVals {\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001827 " mat4 mvp;\n"
1828 "} myBufferVals;\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001829 "layout (location = 0) in vec4 pos;\n"
1830 "layout (location = 1) in vec4 inColor;\n"
Cody Northrop74a2d2c2015-06-16 17:32:04 -06001831 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001832 "void main() {\n"
1833 " outColor = inColor;\n"
1834 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001835 " gl_Position.y = -gl_Position.y;\n"
1836 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001837 "}\n";
1838
1839 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001840 "#version 140\n"
1841 "#extension GL_ARB_separate_shader_objects : enable\n"
1842 "#extension GL_ARB_shading_language_420pack : enable\n"
1843 "layout (location = 0) in vec4 color;\n"
1844 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001845 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001846 " outColor = color;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001847 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001848 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001849
Tony Barbourf43b6982014-11-25 13:18:32 -07001850 glm::mat4 View = glm::lookAt(
1851 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1852 glm::vec3(0,0,0), // and looks at the origin
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001853 glm::vec3(0,-1,0) // Head is up (set to 0,-1,0 to look upside-down)
Tony Barbourf43b6982014-11-25 13:18:32 -07001854 );
1855
1856 glm::mat4 Model = glm::mat4(1.0f);
1857
1858 glm::mat4 MVP = Projection * View * Model;
1859
1860 ASSERT_NO_FATAL_FAILURE(InitState());
1861 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wu9e81ebb2015-07-09 10:16:34 +08001862 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Chia-I Wuc278df82015-07-07 11:50:03 +08001863 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height, m_depth_stencil_fmt);
Tony Barbourf43b6982014-11-25 13:18:32 -07001864
Tony Barbour01999182015-04-09 12:58:51 -06001865 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 -07001866 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1867
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001868 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07001869
Tony Barbour01999182015-04-09 12:58:51 -06001870 VkConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1871 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1872 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001873
Tony Barbour01999182015-04-09 12:58:51 -06001874 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001875 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001876 pipelineobj.AddShader(&vs);
1877 pipelineobj.AddShader(&ps);
1878
Tony Barboure307f582015-07-10 15:29:03 -06001879 VkPipelineDepthStencilStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001880 ds_state.depthTestEnable = VK_TRUE;
1881 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06001882 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001883 ds_state.depthBoundsEnable = VK_FALSE;
1884 ds_state.stencilTestEnable = VK_FALSE;
1885 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
1886 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
1887 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06001888 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001889 ds_state.front = ds_state.back;
1890 pipelineobj.SetDepthStencil(&ds_state);
1891
Tony Barbour01999182015-04-09 12:58:51 -06001892 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001893 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001894
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001895#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001896 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001897 MESH_BUF_ID, // Binding ID
1898 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001899 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001900 };
Tony Barbourf43b6982014-11-25 13:18:32 -07001901
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001902 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001903 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1904 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001905 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001906 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1907 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1908 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001909 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001910 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001911
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001912 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001913 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001914 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001915
Tony Barbour17c6ab12015-03-27 17:03:18 -06001916 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour17c6ab12015-03-27 17:03:18 -06001917
Tony Barbour1490c912015-07-28 10:17:20 -06001918 ASSERT_VK_SUCCESS(BeginCommandBuffer());
1919 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001920
Tony Barbour1490c912015-07-28 10:17:20 -06001921 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barboure4ed9942015-01-09 10:06:53 -07001922#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001923 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barboure4ed9942015-01-09 10:06:53 -07001924 pDSDumpDot((char*)"triTest2.dot");
1925#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001926
1927 // render triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001928 Draw(0, 36, 0, 1);
Tony Barboure4ed9942015-01-09 10:06:53 -07001929
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001930
Tony Barboure4ed9942015-01-09 10:06:53 -07001931 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001932 EndCommandBuffer();
1933 QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -07001934
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001935 RecordImages(m_renderTargets);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001936}
1937
Tony Barbour01999182015-04-09 12:58:51 -06001938TEST_F(VkRenderTest, VSTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07001939{
1940 // The expected result from this test is a green and red triangle;
1941 // one red vertex on the left, two green vertices on the right.
1942 static const char *vertShaderText =
Cody Northrop74a2d2c2015-06-16 17:32:04 -06001943 "#version 140\n"
1944 "#extension GL_ARB_separate_shader_objects : enable\n"
1945 "#extension GL_ARB_shading_language_420pack : enable\n"
1946 "layout (location = 0) out vec4 texColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001947 "uniform sampler2D surface;\n"
1948 "void main() {\n"
1949 " vec2 vertices[3];"
1950 " vertices[0] = vec2(-0.5, -0.5);\n"
1951 " vertices[1] = vec2( 0.5, -0.5);\n"
1952 " vertices[2] = vec2( 0.5, 0.5);\n"
1953 " vec2 positions[3];"
1954 " positions[0] = vec2( 0.0, 0.0);\n"
1955 " positions[1] = vec2( 0.25, 0.1);\n"
1956 " positions[2] = vec2( 0.1, 0.25);\n"
1957 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1958 " texColor = textureLod(surface, samplePos, 0.0);\n"
1959 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1960 "}\n";
1961
1962 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001963 "#version 140\n"
1964 "#extension GL_ARB_separate_shader_objects : enable\n"
1965 "#extension GL_ARB_shading_language_420pack : enable\n"
1966 "layout (location = 0) in vec4 texColor;\n"
1967 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001968 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001969 " outColor = texColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001970 "}\n";
1971
1972 ASSERT_NO_FATAL_FAILURE(InitState());
1973 ASSERT_NO_FATAL_FAILURE(InitViewport());
1974
Tony Barbour01999182015-04-09 12:58:51 -06001975 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1976 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
1977 VkSamplerObj sampler(m_device);
1978 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001979
Tony Barbour01999182015-04-09 12:58:51 -06001980 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001981 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001982 pipelineobj.AddShader(&vs);
1983 pipelineobj.AddShader(&ps);
1984
Tony Barbour01999182015-04-09 12:58:51 -06001985 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001986 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001987
Tony Barbourdd4c9642015-01-09 12:55:14 -07001988 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06001989 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourf43b6982014-11-25 13:18:32 -07001990
Tony Barbour1490c912015-07-28 10:17:20 -06001991 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001992
1993#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001994 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001995 pDSDumpDot((char*)"triTest2.dot");
1996#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001997
Tony Barbourdd4c9642015-01-09 12:55:14 -07001998 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06001999 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002000
2001 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002002 EndCommandBuffer();
2003 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002004
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002005 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002006}
GregFd6ebdb32015-06-03 18:40:50 -06002007
2008
2009
Tony Barbour01999182015-04-09 12:58:51 -06002010TEST_F(VkRenderTest, TexturedTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002011{
2012 // The expected result from this test is a red and green checkered triangle
2013 static const char *vertShaderText =
2014 "#version 140\n"
2015 "#extension GL_ARB_separate_shader_objects : enable\n"
2016 "#extension GL_ARB_shading_language_420pack : enable\n"
2017 "layout (location = 0) out vec2 samplePos;\n"
2018 "void main() {\n"
2019 " vec2 vertices[3];"
2020 " vertices[0] = vec2(-0.5, -0.5);\n"
2021 " vertices[1] = vec2( 0.5, -0.5);\n"
2022 " vertices[2] = vec2( 0.5, 0.5);\n"
2023 " vec2 positions[3];"
2024 " positions[0] = vec2( 0.0, 0.0);\n"
2025 " positions[1] = vec2( 1.0, 0.0);\n"
2026 " positions[2] = vec2( 1.0, 1.0);\n"
2027 " samplePos = positions[gl_VertexID % 3];\n"
2028 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2029 "}\n";
2030
2031 static const char *fragShaderText =
2032 "#version 140\n"
2033 "#extension GL_ARB_separate_shader_objects : enable\n"
2034 "#extension GL_ARB_shading_language_420pack : enable\n"
2035 "layout (location = 0) in vec2 samplePos;\n"
2036 "layout (binding = 0) uniform sampler2D surface;\n"
2037 "layout (location=0) out vec4 outColor;\n"
2038 "void main() {\n"
2039 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2040 " outColor = texColor;\n"
2041 "}\n";
2042
2043 ASSERT_NO_FATAL_FAILURE(InitState());
2044 ASSERT_NO_FATAL_FAILURE(InitViewport());
2045
Tony Barbour01999182015-04-09 12:58:51 -06002046 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2047 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2048 VkSamplerObj sampler(m_device);
2049 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002050
Tony Barbour01999182015-04-09 12:58:51 -06002051 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002052 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002053 pipelineobj.AddShader(&vs);
2054 pipelineobj.AddShader(&ps);
2055
Tony Barbour01999182015-04-09 12:58:51 -06002056 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002057 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002058
Tony Barbourdd4c9642015-01-09 12:55:14 -07002059 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002060 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002061
Tony Barbour1490c912015-07-28 10:17:20 -06002062 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002063
2064#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002065 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002066 pDSDumpDot((char*)"triTest2.dot");
2067#endif
2068 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002069 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002070
2071 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002072 EndCommandBuffer();
2073 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002074
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002075 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002076}
Tony Barbour01999182015-04-09 12:58:51 -06002077TEST_F(VkRenderTest, TexturedTriangleClip)
Tony Barbourf43b6982014-11-25 13:18:32 -07002078{
2079 // The expected result from this test is a red and green checkered triangle
2080 static const char *vertShaderText =
2081 "#version 330\n"
2082 "#extension GL_ARB_separate_shader_objects : enable\n"
2083 "#extension GL_ARB_shading_language_420pack : enable\n"
2084 "layout (location = 0) out vec2 samplePos;\n"
2085 "out gl_PerVertex {\n"
2086 " vec4 gl_Position;\n"
2087 " float gl_ClipDistance[1];\n"
2088 "};\n"
2089 "void main() {\n"
2090 " vec2 vertices[3];"
2091 " vertices[0] = vec2(-0.5, -0.5);\n"
2092 " vertices[1] = vec2( 0.5, -0.5);\n"
2093 " vertices[2] = vec2( 0.5, 0.5);\n"
2094 " vec2 positions[3];"
2095 " positions[0] = vec2( 0.0, 0.0);\n"
2096 " positions[1] = vec2( 1.0, 0.0);\n"
2097 " positions[2] = vec2( 1.0, 1.0);\n"
2098 " float dists[3];\n"
2099 " dists[0] = 1.0;\n"
2100 " dists[1] = 1.0;\n"
2101 " dists[2] = -1.0;\n"
2102 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2103 " samplePos = positions[gl_VertexID % 3];\n"
2104 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2105 "}\n";
2106
2107 static const char *fragShaderText =
2108 "#version 140\n"
2109 "#extension GL_ARB_separate_shader_objects : enable\n"
2110 "#extension GL_ARB_shading_language_420pack : enable\n"
2111 "layout (location = 0) in vec2 samplePos;\n"
2112 "layout (binding = 0) uniform sampler2D surface;\n"
2113 "layout (location=0) out vec4 outColor;\n"
2114 "void main() {\n"
2115 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2116 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2117 " outColor = texColor;\n"
2118 "}\n";
2119
2120
2121 ASSERT_NO_FATAL_FAILURE(InitState());
2122 ASSERT_NO_FATAL_FAILURE(InitViewport());
2123
Tony Barbour01999182015-04-09 12:58:51 -06002124 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2125 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2126 VkSamplerObj sampler(m_device);
2127 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002128
Tony Barbour01999182015-04-09 12:58:51 -06002129 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002130 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002131 pipelineobj.AddShader(&vs);
2132 pipelineobj.AddShader(&ps);
2133
Tony Barbour01999182015-04-09 12:58:51 -06002134 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002135 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002136
Tony Barbourdd4c9642015-01-09 12:55:14 -07002137 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002138 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002139
Tony Barbour1490c912015-07-28 10:17:20 -06002140 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002141
2142#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002143 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002144 pDSDumpDot((char*)"triTest2.dot");
2145#endif
2146 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002147 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002148
2149 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002150 EndCommandBuffer();
2151 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002152
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002153 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002154}
GregFd6ebdb32015-06-03 18:40:50 -06002155
Tony Barbour01999182015-04-09 12:58:51 -06002156TEST_F(VkRenderTest, FSTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002157{
2158 // The expected result from this test is a red and green checkered triangle
2159 static const char *vertShaderText =
2160 "#version 140\n"
2161 "#extension GL_ARB_separate_shader_objects : enable\n"
2162 "#extension GL_ARB_shading_language_420pack : enable\n"
2163 "layout (location = 0) out vec2 samplePos;\n"
2164 "void main() {\n"
2165 " vec2 vertices[3];"
2166 " vertices[0] = vec2(-0.5, -0.5);\n"
2167 " vertices[1] = vec2( 0.5, -0.5);\n"
2168 " vertices[2] = vec2( 0.5, 0.5);\n"
2169 " vec2 positions[3];"
2170 " positions[0] = vec2( 0.0, 0.0);\n"
2171 " positions[1] = vec2( 1.0, 0.0);\n"
2172 " positions[2] = vec2( 1.0, 1.0);\n"
2173 " samplePos = positions[gl_VertexID % 3];\n"
2174 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2175 "}\n";
2176
2177 static const char *fragShaderText =
2178 "#version 140\n"
2179 "#extension GL_ARB_separate_shader_objects : enable\n"
2180 "#extension GL_ARB_shading_language_420pack : enable\n"
2181 "layout (location = 0) in vec2 samplePos;\n"
2182 "layout (binding = 0) uniform sampler2D surface;\n"
2183 "layout (location=0) out vec4 outColor;\n"
2184 "void main() {\n"
2185 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2186 " outColor = texColor;\n"
2187 "}\n";
2188
2189 ASSERT_NO_FATAL_FAILURE(InitState());
2190 ASSERT_NO_FATAL_FAILURE(InitViewport());
2191
Tony Barbour01999182015-04-09 12:58:51 -06002192 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2193 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2194 VkSamplerObj sampler(m_device);
2195 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002196
Tony Barbour01999182015-04-09 12:58:51 -06002197 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002198 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002199 pipelineobj.AddShader(&vs);
2200 pipelineobj.AddShader(&ps);
2201
Tony Barbour01999182015-04-09 12:58:51 -06002202 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002203 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002204
Tony Barbourdd4c9642015-01-09 12:55:14 -07002205 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002206 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002207
Tony Barbour1490c912015-07-28 10:17:20 -06002208 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002209
2210#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002211 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002212 pDSDumpDot((char*)"triTest2.dot");
2213#endif
2214 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002215 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002216
2217 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002218 EndCommandBuffer();
2219 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002220
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002221 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002222}
Tony Barbour01999182015-04-09 12:58:51 -06002223TEST_F(VkRenderTest, SamplerBindingsTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002224{
2225 // This test sets bindings on the samplers
2226 // For now we are asserting that sampler and texture pairs
2227 // march in lock step, and are set via GLSL binding. This can
2228 // and will probably change.
2229 // The sampler bindings should match the sampler and texture slot
2230 // number set up by the application.
2231 // This test will result in a blue triangle
2232 static const char *vertShaderText =
2233 "#version 140\n"
2234 "#extension GL_ARB_separate_shader_objects : enable\n"
2235 "#extension GL_ARB_shading_language_420pack : enable\n"
2236 "layout (location = 0) out vec4 samplePos;\n"
2237 "void main() {\n"
2238 " vec2 vertices[3];"
2239 " vertices[0] = vec2(-0.5, -0.5);\n"
2240 " vertices[1] = vec2( 0.5, -0.5);\n"
2241 " vertices[2] = vec2( 0.5, 0.5);\n"
2242 " vec2 positions[3];"
2243 " positions[0] = vec2( 0.0, 0.0);\n"
2244 " positions[1] = vec2( 1.0, 0.0);\n"
2245 " positions[2] = vec2( 1.0, 1.0);\n"
2246 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2247 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2248 "}\n";
2249
2250 static const char *fragShaderText =
2251 "#version 140\n"
2252 "#extension GL_ARB_separate_shader_objects : enable\n"
2253 "#extension GL_ARB_shading_language_420pack : enable\n"
2254 "layout (location = 0) in vec4 samplePos;\n"
2255 "layout (binding = 0) uniform sampler2D surface0;\n"
2256 "layout (binding = 1) uniform sampler2D surface1;\n"
2257 "layout (binding = 12) uniform sampler2D surface2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06002258 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002259 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002260 " outColor = textureLod(surface2, samplePos.xy, 0.0);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002261 "}\n";
2262
2263 ASSERT_NO_FATAL_FAILURE(InitState());
2264 ASSERT_NO_FATAL_FAILURE(InitViewport());
2265
Tony Barbour01999182015-04-09 12:58:51 -06002266 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2267 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002268
Tony Barbour01999182015-04-09 12:58:51 -06002269 VkSamplerObj sampler1(m_device);
2270 VkSamplerObj sampler2(m_device);
2271 VkSamplerObj sampler3(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002272
Tony Barbour2f421a02015-04-01 16:38:10 -06002273 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
Tony Barbour01999182015-04-09 12:58:51 -06002274 VkTextureObj texture1(m_device, tex_colors); // Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002275 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
Tony Barbour01999182015-04-09 12:58:51 -06002276 VkTextureObj texture2(m_device, tex_colors); // Green
Tony Barbour2f421a02015-04-01 16:38:10 -06002277 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
Tony Barbour01999182015-04-09 12:58:51 -06002278 VkTextureObj texture3(m_device, tex_colors); // Blue
Tony Barbourf43b6982014-11-25 13:18:32 -07002279
Tony Barbour01999182015-04-09 12:58:51 -06002280 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002281 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002282 pipelineobj.AddShader(&vs);
2283 pipelineobj.AddShader(&ps);
2284
Tony Barbour01999182015-04-09 12:58:51 -06002285 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002286 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2287 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2288 for (int i = 0; i < 10; i++)
2289 descriptorSet.AppendDummy();
2290 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002291
Tony Barbourdd4c9642015-01-09 12:55:14 -07002292 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002293 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002294
Tony Barbour1490c912015-07-28 10:17:20 -06002295 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002296
2297#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002298 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002299 pDSDumpDot((char*)"triTest2.dot");
2300#endif
2301 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002302 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002303
2304 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002305 EndCommandBuffer();
2306 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002307
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002308 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002309}
2310
Tony Barbour01999182015-04-09 12:58:51 -06002311TEST_F(VkRenderTest, TriangleVSUniformBlock)
Tony Barbourf43b6982014-11-25 13:18:32 -07002312{
2313 // The expected result from this test is a blue triangle
2314
2315 static const char *vertShaderText =
2316 "#version 140\n"
2317 "#extension GL_ARB_separate_shader_objects : enable\n"
2318 "#extension GL_ARB_shading_language_420pack : enable\n"
2319 "layout (location = 0) out vec4 outColor;\n"
2320 "layout (std140, binding = 0) uniform bufferVals {\n"
2321 " vec4 red;\n"
2322 " vec4 green;\n"
2323 " vec4 blue;\n"
2324 " vec4 white;\n"
2325 "} myBufferVals;\n"
2326 "void main() {\n"
2327 " vec2 vertices[3];"
2328 " vertices[0] = vec2(-0.5, -0.5);\n"
2329 " vertices[1] = vec2( 0.5, -0.5);\n"
2330 " vertices[2] = vec2( 0.5, 0.5);\n"
2331 " outColor = myBufferVals.blue;\n"
2332 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2333 "}\n";
2334
2335 static const char *fragShaderText =
2336 "#version 140\n"
2337 "#extension GL_ARB_separate_shader_objects : enable\n"
2338 "#extension GL_ARB_shading_language_420pack : enable\n"
2339 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -06002340 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002341 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002342 " outColor = inColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002343 "}\n";
2344
2345 ASSERT_NO_FATAL_FAILURE(InitState());
2346 ASSERT_NO_FATAL_FAILURE(InitViewport());
2347
Tony Barbour01999182015-04-09 12:58:51 -06002348 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2349 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002350
2351 // Let's populate our buffer with the following:
2352 // vec4 red;
2353 // vec4 green;
2354 // vec4 blue;
2355 // vec4 white;
2356 const int valCount = 4 * 4;
2357 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2358 0.0, 1.0, 0.0, 1.0,
2359 0.0, 0.0, 1.0, 1.0,
2360 1.0, 1.0, 1.0, 1.0 };
2361
Tony Barbour01999182015-04-09 12:58:51 -06002362 VkConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002363
Tony Barbour01999182015-04-09 12:58:51 -06002364 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002365 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002366 pipelineobj.AddShader(&vs);
2367 pipelineobj.AddShader(&ps);
2368
Tony Barbour01999182015-04-09 12:58:51 -06002369 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002370 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002371
Tony Barbourdd4c9642015-01-09 12:55:14 -07002372 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002373 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002374
Tony Barbour1490c912015-07-28 10:17:20 -06002375 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002376
2377#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002378 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002379 pDSDumpDot((char*)"triTest2.dot");
2380#endif
2381 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002382 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002383
2384 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002385 EndCommandBuffer();
2386 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002387
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002388 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002389}
2390
Tony Barbour01999182015-04-09 12:58:51 -06002391TEST_F(VkRenderTest, TriangleFSUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002392{
2393 // This test allows the shader to select which buffer it is
2394 // pulling from using layout binding qualifier.
2395 // There are corresponding changes in the compiler stack that
2396 // will select the buffer using binding directly.
2397 // The binding number should match the slot number set up by
2398 // the application.
2399 // The expected result from this test is a purple triangle
2400
2401 static const char *vertShaderText =
2402 "#version 140\n"
2403 "#extension GL_ARB_separate_shader_objects : enable\n"
2404 "#extension GL_ARB_shading_language_420pack : enable\n"
2405 "void main() {\n"
2406 " vec2 vertices[3];"
2407 " vertices[0] = vec2(-0.5, -0.5);\n"
2408 " vertices[1] = vec2( 0.5, -0.5);\n"
2409 " vertices[2] = vec2( 0.5, 0.5);\n"
2410 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2411 "}\n";
2412
2413 static const char *fragShaderText =
2414 "#version 140\n"
2415 "#extension GL_ARB_separate_shader_objects : enable\n"
2416 "#extension GL_ARB_shading_language_420pack : enable\n"
2417 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2418 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2419 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002420 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
GregFd6ebdb32015-06-03 18:40:50 -06002421 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002422 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002423 " outColor = myBlueVal.color;\n"
2424 " outColor += myRedVal.color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002425 "}\n";
2426
2427 ASSERT_NO_FATAL_FAILURE(InitState());
2428 ASSERT_NO_FATAL_FAILURE(InitViewport());
2429
Tony Barbour01999182015-04-09 12:58:51 -06002430 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2431 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002432
2433 // We're going to create a number of uniform buffers, and then allow
2434 // the shader to select which it wants to read from with a binding
2435
2436 // Let's populate the buffers with a single color each:
2437 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2438 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2439 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002440 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002441
2442 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2443 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2444 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2445 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2446
2447 const int redCount = sizeof(redVals) / sizeof(float);
2448 const int greenCount = sizeof(greenVals) / sizeof(float);
2449 const int blueCount = sizeof(blueVals) / sizeof(float);
2450 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2451
Tony Barbour01999182015-04-09 12:58:51 -06002452 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002453
Tony Barbour01999182015-04-09 12:58:51 -06002454 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002455
Tony Barbour01999182015-04-09 12:58:51 -06002456 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002457
Tony Barbour01999182015-04-09 12:58:51 -06002458 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002459
Tony Barbour01999182015-04-09 12:58:51 -06002460 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002461 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002462 pipelineobj.AddShader(&vs);
2463 pipelineobj.AddShader(&ps);
2464
Tony Barbour01999182015-04-09 12:58:51 -06002465 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002466 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2467 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2468 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2469 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002470
Tony Barbourdd4c9642015-01-09 12:55:14 -07002471 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002472 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourf43b6982014-11-25 13:18:32 -07002473
Tony Barbour1490c912015-07-28 10:17:20 -06002474 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002475
2476#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002477 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002478 pDSDumpDot((char*)"triTest2.dot");
2479#endif
2480 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002481 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002482
2483 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002484 EndCommandBuffer();
2485 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002486
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002487 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002488}
2489
Tony Barbour01999182015-04-09 12:58:51 -06002490TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002491{
2492 // This test is the same as TriangleFSUniformBlockBinding, but
2493 // it does not provide an instance name.
2494 // The expected result from this test is a purple triangle
2495
2496 static const char *vertShaderText =
2497 "#version 140\n"
2498 "#extension GL_ARB_separate_shader_objects : enable\n"
2499 "#extension GL_ARB_shading_language_420pack : enable\n"
2500 "void main() {\n"
2501 " vec2 vertices[3];"
2502 " vertices[0] = vec2(-0.5, -0.5);\n"
2503 " vertices[1] = vec2( 0.5, -0.5);\n"
2504 " vertices[2] = vec2( 0.5, 0.5);\n"
2505 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2506 "}\n";
2507
2508 static const char *fragShaderText =
2509 "#version 430\n"
2510 "#extension GL_ARB_separate_shader_objects : enable\n"
2511 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002512 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2513 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2514 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002515 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002516 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002517 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002518 " outColor = blue;\n"
2519 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002520 "}\n";
2521 ASSERT_NO_FATAL_FAILURE(InitState());
2522 ASSERT_NO_FATAL_FAILURE(InitViewport());
2523
Tony Barbour01999182015-04-09 12:58:51 -06002524 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2525 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002526
2527 // We're going to create a number of uniform buffers, and then allow
2528 // the shader to select which it wants to read from with a binding
2529
2530 // Let's populate the buffers with a single color each:
2531 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2532 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2533 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2534 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2535
2536 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2537 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2538 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2539 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2540
2541 const int redCount = sizeof(redVals) / sizeof(float);
2542 const int greenCount = sizeof(greenVals) / sizeof(float);
2543 const int blueCount = sizeof(blueVals) / sizeof(float);
2544 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2545
Tony Barbour01999182015-04-09 12:58:51 -06002546 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002547
Tony Barbour01999182015-04-09 12:58:51 -06002548 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002549
Tony Barbour01999182015-04-09 12:58:51 -06002550 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002551
Tony Barbour01999182015-04-09 12:58:51 -06002552 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002553
Tony Barbour01999182015-04-09 12:58:51 -06002554 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002555 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002556 pipelineobj.AddShader(&vs);
2557 pipelineobj.AddShader(&ps);
2558
Tony Barbour01999182015-04-09 12:58:51 -06002559 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002560 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2561 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2562 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2563 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002564
Tony Barbourdd4c9642015-01-09 12:55:14 -07002565 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002566 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002567
Tony Barbour1490c912015-07-28 10:17:20 -06002568 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002569
2570#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002571 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002572 pDSDumpDot((char*)"triTest2.dot");
2573#endif
2574 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002575 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002576
2577 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002578 EndCommandBuffer();
2579 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002580
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002581 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002582}
2583
GregF54a32172015-07-01 16:11:09 -06002584TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBindingWithStruct)
2585{
2586 // This test is the same as TriangleFSUniformBlockBinding, but
2587 // it does not provide an instance name.
2588 // The expected result from this test is a purple triangle
2589
2590 static const char *vertShaderText =
2591 "#version 140\n"
2592 "#extension GL_ARB_separate_shader_objects : enable\n"
2593 "#extension GL_ARB_shading_language_420pack : enable\n"
2594 "void main() {\n"
2595 " vec2 vertices[3];"
2596 " vertices[0] = vec2(-0.5, -0.5);\n"
2597 " vertices[1] = vec2( 0.5, -0.5);\n"
2598 " vertices[2] = vec2( 0.5, 0.5);\n"
2599 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2600 "}\n";
2601
2602 static const char *fragShaderText =
2603 "#version 430\n"
2604 "#extension GL_ARB_separate_shader_objects : enable\n"
2605 "#extension GL_ARB_shading_language_420pack : enable\n"
2606 "\n"
2607 " struct PS_INPUT {\n"
2608 " vec2 member0;\n"
2609 " vec4 member1;\n"
2610 " vec4 member2;\n"
2611 " vec4 member3;\n"
2612 " vec4 member4;\n"
2613 " vec4 member5;\n"
2614 " vec4 member6;\n"
2615 " vec4 member7;\n"
2616 " vec4 member8;\n"
2617 " vec4 member9;\n"
2618 " };\n"
2619 "\n"
2620 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2621 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2622 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2623 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
2624 "layout (location = 0) out vec4 outColor;\n"
2625 "PS_INPUT MainFs()\n"
2626 "{\n"
2627 " PS_INPUT o;\n"
2628 " o.member9 = red;\n"
2629 " return o;\n"
2630 "}\n"
2631 "\n"
2632 "void main()\n"
2633 "{\n"
2634 " PS_INPUT o;\n"
2635 " o = MainFs();\n"
2636 " outColor = blue;"
2637 " outColor += o.member9;\n"
2638 "}\n";;
2639 ASSERT_NO_FATAL_FAILURE(InitState());
2640 ASSERT_NO_FATAL_FAILURE(InitViewport());
2641
2642 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2643 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2644
2645 // We're going to create a number of uniform buffers, and then allow
2646 // the shader to select which it wants to read from with a binding
2647
2648 // Let's populate the buffers with a single color each:
2649 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2650 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2651 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2652 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2653
2654 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2655 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2656 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2657 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2658
2659 const int redCount = sizeof(redVals) / sizeof(float);
2660 const int greenCount = sizeof(greenVals) / sizeof(float);
2661 const int blueCount = sizeof(blueVals) / sizeof(float);
2662 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2663
2664 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2665
2666 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2667
2668 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2669
2670 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
2671
2672 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002673 pipelineobj.AddColorAttachment();
GregF54a32172015-07-01 16:11:09 -06002674 pipelineobj.AddShader(&vs);
2675 pipelineobj.AddShader(&ps);
2676
2677 VkDescriptorSetObj descriptorSet(m_device);
2678 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2679 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2680 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2681 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
2682
2683 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002684 ASSERT_VK_SUCCESS(BeginCommandBuffer());
GregF54a32172015-07-01 16:11:09 -06002685
Tony Barbour1490c912015-07-28 10:17:20 -06002686 GenericDrawPreparation(pipelineobj, descriptorSet);
GregF54a32172015-07-01 16:11:09 -06002687
2688#ifdef DUMP_STATE_DOT
2689 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
2690 pDSDumpDot((char*)"triTest2.dot");
2691#endif
2692 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002693 Draw(0, 3, 0, 1);
GregF54a32172015-07-01 16:11:09 -06002694
2695 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002696 EndCommandBuffer();
2697 QueueCommandBuffer();
GregF54a32172015-07-01 16:11:09 -06002698
2699 RecordImages(m_renderTargets);
2700}
2701
Tony Barbour01999182015-04-09 12:58:51 -06002702TEST_F(VkRenderTest, CubeWithVertexFetchAndMVPAndTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07002703{
2704 static const char *vertShaderText =
2705 "#version 140\n"
2706 "#extension GL_ARB_separate_shader_objects : enable\n"
2707 "#extension GL_ARB_shading_language_420pack : enable\n"
2708 "layout (std140, binding=0) uniform bufferVals {\n"
2709 " mat4 mvp;\n"
2710 "} myBufferVals;\n"
2711 "layout (location=0) in vec4 pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002712 "layout (location=1) in vec2 input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002713 "layout (location=0) out vec2 UV;\n"
2714 "void main() {\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002715 " UV = input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002716 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002717 " gl_Position.y = -gl_Position.y;\n"
2718 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002719 "}\n";
2720
2721 static const char *fragShaderText =
2722 "#version 140\n"
2723 "#extension GL_ARB_separate_shader_objects : enable\n"
2724 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002725 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002726 "layout (location=0) out vec4 outColor;\n"
2727 "layout (location=0) in vec2 UV;\n"
2728 "void main() {\n"
2729 " outColor= textureLod(surface, UV, 0.0);\n"
2730 "}\n";
2731 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2732
2733 glm::mat4 View = glm::lookAt(
2734 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2735 glm::vec3(0,0,0), // and looks at the origin
2736 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2737 );
2738
2739 glm::mat4 Model = glm::mat4(1.0f);
2740
2741 glm::mat4 MVP = Projection * View * Model;
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002742 int num_verts = sizeof(g_vb_texture_Data) / sizeof(g_vb_texture_Data[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002743
2744
2745 ASSERT_NO_FATAL_FAILURE(InitState());
2746 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wu9e81ebb2015-07-09 10:16:34 +08002747 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Chia-I Wuc278df82015-07-07 11:50:03 +08002748 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height, m_depth_stencil_fmt);
Tony Barbourf43b6982014-11-25 13:18:32 -07002749
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002750 VkConstantBufferObj meshBuffer(m_device, num_verts,
2751 sizeof(g_vb_texture_Data[0]), g_vb_texture_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002752 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002753
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002754 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07002755
Tony Barbour01999182015-04-09 12:58:51 -06002756 VkConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2757 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2758 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2759 VkSamplerObj sampler(m_device);
2760 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002761
Tony Barbour01999182015-04-09 12:58:51 -06002762 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002763 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002764 pipelineobj.AddShader(&vs);
2765 pipelineobj.AddShader(&ps);
2766
Tony Barbour01999182015-04-09 12:58:51 -06002767 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002768 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mvpBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002769 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002770
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002771#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002772 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002773 MESH_BIND_ID, // binding ID
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002774 sizeof(g_vb_texture_Data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002775 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002776 };
Tony Barbourf43b6982014-11-25 13:18:32 -07002777
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002778 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002779 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2780 vi_attribs[0].location = 0; // location
Tony Barbour8205d902015-04-16 15:59:00 -06002781 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002782 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2783 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2784 vi_attribs[1].location = 1; // location
2785 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
2786 vi_attribs[1].offsetInBytes = 16; // Offset of uv components
Tony Barbourf43b6982014-11-25 13:18:32 -07002787
Tony Barbourf43b6982014-11-25 13:18:32 -07002788 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002789 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2790 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07002791
Tony Barboure307f582015-07-10 15:29:03 -06002792 VkPipelineDepthStencilStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002793 ds_state.depthTestEnable = VK_TRUE;
2794 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06002795 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002796 ds_state.depthBoundsEnable = VK_FALSE;
2797 ds_state.stencilTestEnable = VK_FALSE;
2798 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
2799 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
2800 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06002801 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002802 ds_state.front = ds_state.back;
2803 pipelineobj.SetDepthStencil(&ds_state);
2804
Tony Barbour17c6ab12015-03-27 17:03:18 -06002805 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tobin Ehlis7f7b4422015-08-18 14:24:32 -06002806
2807 VkCmdBufferBeginInfo cbBeginInfo;
2808 memset(&cbBeginInfo, 0, sizeof(VkCmdBufferBeginInfo));
2809 cbBeginInfo.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
2810 cbBeginInfo.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT;
2811 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barbourf43b6982014-11-25 13:18:32 -07002812
Tony Barbour1490c912015-07-28 10:17:20 -06002813 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002814
Tony Barbour1490c912015-07-28 10:17:20 -06002815 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002816#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002817 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002818 pDSDumpDot((char*)"triTest2.dot");
2819#endif
2820 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002821 Draw(0, num_verts, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002822
2823 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002824 EndCommandBuffer();
2825 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002826
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002827 RecordImages(m_renderTargets);
Tony Barbour1490c912015-07-28 10:17:20 -06002828 RotateTriangleVSUniform(Projection, View, Model, &mvpBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002829}
Cody Northropd1ce7842014-12-09 11:17:01 -07002830
Tony Barbour01999182015-04-09 12:58:51 -06002831TEST_F(VkRenderTest, TriangleMixedSamplerUniformBlockBinding)
Cody Northropd1ce7842014-12-09 11:17:01 -07002832{
2833 // This test mixes binding slots of textures and buffers, ensuring
2834 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002835 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002836 // you can modify it to move the desired result around.
2837
2838 static const char *vertShaderText =
2839 "#version 140\n"
2840 "#extension GL_ARB_separate_shader_objects : enable\n"
2841 "#extension GL_ARB_shading_language_420pack : enable\n"
2842 "void main() {\n"
2843 " vec2 vertices[3];"
2844 " vertices[0] = vec2(-0.5, -0.5);\n"
2845 " vertices[1] = vec2( 0.5, -0.5);\n"
2846 " vertices[2] = vec2( 0.5, 0.5);\n"
2847 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2848 "}\n";
2849
2850 static const char *fragShaderText =
2851 "#version 430\n"
2852 "#extension GL_ARB_separate_shader_objects : enable\n"
2853 "#extension GL_ARB_shading_language_420pack : enable\n"
2854 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002855 "layout (binding = 3) uniform sampler2D surface1;\n"
2856 "layout (binding = 1) uniform sampler2D surface2;\n"
2857 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002858
Cody Northropa0410942014-12-09 13:59:39 -07002859
Chia-I Wuf8385062015-01-04 16:27:24 +08002860 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2861 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2862 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2863 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002864 "layout (location = 0) out vec4 outColor;\n"
2865 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002866 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002867 " outColor += white * vec4(0.00001);\n"
2868 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002869 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002870 "}\n";
2871 ASSERT_NO_FATAL_FAILURE(InitState());
2872 ASSERT_NO_FATAL_FAILURE(InitViewport());
2873
Tony Barbour01999182015-04-09 12:58:51 -06002874 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2875 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northropd1ce7842014-12-09 11:17:01 -07002876
Cody Northropd1ce7842014-12-09 11:17:01 -07002877 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2878 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2879 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2880 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2881
2882 const int redCount = sizeof(redVals) / sizeof(float);
2883 const int greenCount = sizeof(greenVals) / sizeof(float);
2884 const int blueCount = sizeof(blueVals) / sizeof(float);
2885 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2886
Tony Barbour01999182015-04-09 12:58:51 -06002887 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2888 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2889 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2890 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002891
Tony Barbour2f421a02015-04-01 16:38:10 -06002892 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002893 VkSamplerObj sampler0(m_device);
2894 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002895 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002896 VkSamplerObj sampler2(m_device);
2897 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002898 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002899 VkSamplerObj sampler4(m_device);
2900 VkTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropa0410942014-12-09 13:59:39 -07002901
2902 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2903 // TODO: Get back here ASAP and understand why.
Tony Barbour2f421a02015-04-01 16:38:10 -06002904 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06002905 VkSamplerObj sampler7(m_device);
2906 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropd1ce7842014-12-09 11:17:01 -07002907
Tony Barbour01999182015-04-09 12:58:51 -06002908 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002909 pipelineobj.AddColorAttachment();
Cody Northropd1ce7842014-12-09 11:17:01 -07002910 pipelineobj.AddShader(&vs);
2911 pipelineobj.AddShader(&ps);
2912
Tony Barbour01999182015-04-09 12:58:51 -06002913 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002914 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2915 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2916 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2917 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002918 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002919 // swap blue and green
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002920 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2921 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2922 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002923
Tony Barbourdd4c9642015-01-09 12:55:14 -07002924 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002925 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropd1ce7842014-12-09 11:17:01 -07002926
Tony Barbour1490c912015-07-28 10:17:20 -06002927 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002928
2929#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002930 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002931 pDSDumpDot((char*)"triTest2.dot");
2932#endif
2933 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002934 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002935
2936 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002937 EndCommandBuffer();
2938 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002939
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002940 RecordImages(m_renderTargets);
Cody Northropd1ce7842014-12-09 11:17:01 -07002941}
2942
Tony Barbour01999182015-04-09 12:58:51 -06002943TEST_F(VkRenderTest, TriangleMatchingSamplerUniformBlockBinding)
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002944{
2945 // This test matches binding slots of textures and buffers, requiring
2946 // the driver to give them distinct number spaces.
2947 // The expected result from this test is a red triangle, although
2948 // you can modify it to move the desired result around.
2949
2950 static const char *vertShaderText =
2951 "#version 140\n"
2952 "#extension GL_ARB_separate_shader_objects : enable\n"
2953 "#extension GL_ARB_shading_language_420pack : enable\n"
2954 "void main() {\n"
2955 " vec2 vertices[3];"
2956 " vertices[0] = vec2(-0.5, -0.5);\n"
2957 " vertices[1] = vec2( 0.5, -0.5);\n"
2958 " vertices[2] = vec2( 0.5, 0.5);\n"
2959 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2960 "}\n";
2961
2962 static const char *fragShaderText =
2963 "#version 430\n"
2964 "#extension GL_ARB_separate_shader_objects : enable\n"
2965 "#extension GL_ARB_shading_language_420pack : enable\n"
2966 "layout (binding = 0) uniform sampler2D surface0;\n"
2967 "layout (binding = 1) uniform sampler2D surface1;\n"
2968 "layout (binding = 2) uniform sampler2D surface2;\n"
2969 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002970 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2971 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2972 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2973 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002974 "layout (location = 0) out vec4 outColor;\n"
2975 "void main() {\n"
2976 " outColor = red;// * vec4(0.00001);\n"
2977 " outColor += white * vec4(0.00001);\n"
2978 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2979 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2980 "}\n";
2981 ASSERT_NO_FATAL_FAILURE(InitState());
2982 ASSERT_NO_FATAL_FAILURE(InitViewport());
2983
Tony Barbour01999182015-04-09 12:58:51 -06002984 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2985 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002986
2987 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2988 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2989 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2990 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2991
2992 const int redCount = sizeof(redVals) / sizeof(float);
2993 const int greenCount = sizeof(greenVals) / sizeof(float);
2994 const int blueCount = sizeof(blueVals) / sizeof(float);
2995 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2996
Tony Barbour01999182015-04-09 12:58:51 -06002997 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2998 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2999 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
3000 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003001
Tony Barbour2f421a02015-04-01 16:38:10 -06003002 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06003003 VkSamplerObj sampler0(m_device);
3004 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06003005 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06003006 VkSamplerObj sampler2(m_device);
3007 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06003008 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06003009 VkSamplerObj sampler4(m_device);
3010 VkTextureObj texture4(m_device, tex_colors); // Light Green
Tony Barbour2f421a02015-04-01 16:38:10 -06003011 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06003012 VkSamplerObj sampler7(m_device);
3013 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003014
Tony Barbour01999182015-04-09 12:58:51 -06003015 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003016 pipelineobj.AddColorAttachment();
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003017 pipelineobj.AddShader(&vs);
3018 pipelineobj.AddShader(&ps);
3019
Tony Barbour01999182015-04-09 12:58:51 -06003020 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08003021 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3022 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3023 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
3024 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003025 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
3026 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
3027 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
3028 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003029
Tony Barbourdd4c9642015-01-09 12:55:14 -07003030 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003031 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003032
Tony Barbour1490c912015-07-28 10:17:20 -06003033 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07003034
3035#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003036 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07003037 pDSDumpDot((char*)"triTest2.dot");
3038#endif
3039 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06003040 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07003041
3042 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003043 EndCommandBuffer();
3044 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07003045
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003046 RecordImages(m_renderTargets);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003047}
3048
Tony Barbour01999182015-04-09 12:58:51 -06003049TEST_F(VkRenderTest, TriangleUniformBufferLayout)
Cody Northrop02690bd2014-12-17 15:26:33 -07003050{
3051 // This test populates a buffer with a variety of different data
3052 // types, then reads them out with a shader.
3053 // The expected result from this test is a green triangle
3054
3055 static const char *vertShaderText =
3056 "#version 140\n"
3057 "#extension GL_ARB_separate_shader_objects : enable\n"
3058 "#extension GL_ARB_shading_language_420pack : enable\n"
3059 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3060 " vec4 fRed;\n"
3061 " vec4 fGreen;\n"
3062 " layout(row_major) mat4 worldToProj;\n"
3063 " layout(row_major) mat4 projToWorld;\n"
3064 " layout(row_major) mat4 worldToView;\n"
3065 " layout(row_major) mat4 viewToProj;\n"
3066 " layout(row_major) mat4 worldToShadow[4];\n"
3067 " float fZero;\n"
3068 " float fOne;\n"
3069 " float fTwo;\n"
3070 " float fThree;\n"
3071 " vec3 fZeroZeroZero;\n"
3072 " float fFour;\n"
3073 " vec3 fZeroZeroOne;\n"
3074 " float fFive;\n"
3075 " vec3 fZeroOneZero;\n"
3076 " float fSix;\n"
3077 " float fSeven;\n"
3078 " float fEight;\n"
3079 " float fNine;\n"
3080 " vec2 fZeroZero;\n"
3081 " vec2 fZeroOne;\n"
3082 " vec4 fBlue;\n"
3083 " vec2 fOneZero;\n"
3084 " vec2 fOneOne;\n"
3085 " vec3 fZeroOneOne;\n"
3086 " float fTen;\n"
3087 " float fEleven;\n"
3088 " float fTwelve;\n"
3089 " vec3 fOneZeroZero;\n"
3090 " vec4 uvOffsets[4];\n"
3091 "};\n"
3092 "layout (location = 0) out vec4 color;"
3093 "void main() {\n"
3094
3095 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3096 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3097 " \n"
3098
3099 // do some exact comparisons, even though we should
3100 // really have an epsilon involved.
3101 " vec4 outColor = right;\n"
3102 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3103 " outColor = wrong;\n"
3104 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3105 " outColor = wrong;\n"
3106 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3107 " outColor = wrong;\n"
3108
3109 " color = outColor;\n"
3110
3111 // generic position stuff
3112 " vec2 vertices;\n"
3113 " int vertexSelector = gl_VertexID;\n"
3114 " if (vertexSelector == 0)\n"
3115 " vertices = vec2(-0.5, -0.5);\n"
3116 " else if (vertexSelector == 1)\n"
3117 " vertices = vec2( 0.5, -0.5);\n"
3118 " else if (vertexSelector == 2)\n"
3119 " vertices = vec2( 0.5, 0.5);\n"
3120 " else\n"
3121 " vertices = vec2( 0.0, 0.0);\n"
3122 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3123 "}\n";
3124
3125 static const char *fragShaderText =
3126 "#version 140\n"
3127 "#extension GL_ARB_separate_shader_objects : enable\n"
3128 "#extension GL_ARB_shading_language_420pack : enable\n"
3129 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3130 " vec4 fRed;\n"
3131 " vec4 fGreen;\n"
3132 " layout(row_major) mat4 worldToProj;\n"
3133 " layout(row_major) mat4 projToWorld;\n"
3134 " layout(row_major) mat4 worldToView;\n"
3135 " layout(row_major) mat4 viewToProj;\n"
3136 " layout(row_major) mat4 worldToShadow[4];\n"
3137 " float fZero;\n"
3138 " float fOne;\n"
3139 " float fTwo;\n"
3140 " float fThree;\n"
3141 " vec3 fZeroZeroZero;\n"
3142 " float fFour;\n"
3143 " vec3 fZeroZeroOne;\n"
3144 " float fFive;\n"
3145 " vec3 fZeroOneZero;\n"
3146 " float fSix;\n"
3147 " float fSeven;\n"
3148 " float fEight;\n"
3149 " float fNine;\n"
3150 " vec2 fZeroZero;\n"
3151 " vec2 fZeroOne;\n"
3152 " vec4 fBlue;\n"
3153 " vec2 fOneZero;\n"
3154 " vec2 fOneOne;\n"
3155 " vec3 fZeroOneOne;\n"
3156 " float fTen;\n"
3157 " float fEleven;\n"
3158 " float fTwelve;\n"
3159 " vec3 fOneZeroZero;\n"
3160 " vec4 uvOffsets[4];\n"
3161 "};\n"
3162 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003163 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop02690bd2014-12-17 15:26:33 -07003164 "void main() {\n"
3165 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3166 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3167 " \n"
3168
3169 // start with VS value to ensure it passed
3170 " vec4 outColor = color;\n"
3171
3172 // do some exact comparisons, even though we should
3173 // really have an epsilon involved.
3174 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3175 " outColor = wrong;\n"
3176 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3177 " outColor = wrong;\n"
3178 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3179 " outColor = wrong;\n"
3180 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3181 " outColor = wrong;\n"
3182 " if (fTwo != 2.0)\n"
3183 " outColor = wrong;\n"
3184 " if (fOneOne != vec2(1.0, 1.0))\n"
3185 " outColor = wrong;\n"
3186 " if (fTen != 10.0)\n"
3187 " outColor = wrong;\n"
3188 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3189 " outColor = wrong;\n"
3190 " \n"
GregFd6ebdb32015-06-03 18:40:50 -06003191 " uFragColor = outColor;\n"
Cody Northrop02690bd2014-12-17 15:26:33 -07003192 "}\n";
3193
3194
Cody Northrop1684adb2015-08-05 11:15:02 -06003195 const float mixedVals[196] = { 1.0f, 0.0f, 0.0f, 1.0f, // vec4 fRed; // align
3196 0.0f, 1.0f, 0.0f, 1.0f, // vec4 fGreen; // align
3197 1.0f, 0.0f, 0.0f, 1.0f, // layout(row_major) mat4 worldToProj;
3198 0.0f, 1.0f, 0.0f, 1.0f, // align
3199 0.0f, 0.0f, 1.0f, 1.0f, // align
3200 0.0f, 0.0f, 0.0f, 1.0f, // align
3201 2.0f, 0.0f, 0.0f, 2.0f, // layout(row_major) mat4 projToWorld;
3202 0.0f, 2.0f, 0.0f, 2.0f, // align
3203 0.0f, 0.0f, 2.0f, 2.0f, // align
3204 0.0f, 0.0f, 0.0f, 2.0f, // align
3205 3.0f, 0.0f, 0.0f, 3.0f, // layout(row_major) mat4 worldToView;
3206 0.0f, 3.0f, 0.0f, 3.0f, // align
3207 0.0f, 0.0f, 3.0f, 3.0f, // align
3208 0.0f, 0.0f, 0.0f, 3.0f, // align
3209 4.0f, 0.0f, 0.0f, 4.0f, // layout(row_major) mat4 viewToProj;
3210 0.0f, 4.0f, 0.0f, 4.0f, // align
3211 0.0f, 0.0f, 4.0f, 4.0f, // align
3212 0.0f, 0.0f, 0.0f, 4.0f, // align
3213 5.0f, 0.0f, 0.0f, 5.0f, // layout(row_major) mat4 worldToShadow[4];
3214 0.0f, 5.0f, 0.0f, 5.0f, // align
3215 0.0f, 0.0f, 5.0f, 5.0f, // align
3216 0.0f, 0.0f, 0.0f, 5.0f, // align
3217 6.0f, 0.0f, 0.0f, 6.0f, // align
3218 0.0f, 6.0f, 0.0f, 6.0f, // align
3219 0.0f, 0.0f, 6.0f, 6.0f, // align
3220 0.0f, 0.0f, 0.0f, 6.0f, // align
3221 7.0f, 0.0f, 0.0f, 7.0f, // align
3222 0.0f, 7.0f, 0.0f, 7.0f, // align
3223 0.0f, 0.0f, 7.0f, 7.0f, // align
3224 0.0f, 0.0f, 0.0f, 7.0f, // align
3225 8.0f, 0.0f, 0.0f, 8.0f, // align
3226 0.0f, 8.0f, 0.0f, 8.0f, // align
3227 0.0f, 0.0f, 8.0f, 8.0f, // align
3228 0.0f, 0.0f, 0.0f, 8.0f, // align
3229 0.0f, // float fZero; // align
3230 1.0f, // float fOne; // pack
3231 2.0f, // float fTwo; // pack
3232 3.0f, // float fThree; // pack
3233 0.0f, 0.0f, 0.0f, // vec3 fZeroZeroZero; // align
3234 4.0f, // float fFour; // pack
3235 0.0f, 0.0f, 1.0f, // vec3 fZeroZeroOne; // align
3236 5.0f, // float fFive; // pack
3237 0.0f, 1.0f, 0.0f, // vec3 fZeroOneZero; // align
3238 6.0f, // float fSix; // pack
3239 7.0f, // float fSeven; // align
3240 8.0f, // float fEight; // pack
3241 9.0f, // float fNine; // pack
3242 0.0f, // BUFFER
3243 0.0f, 0.0f, // vec2 fZeroZero; // align
3244 0.0f, 1.0f, // vec2 fZeroOne; // pack
3245 0.0f, 0.0f, 1.0f, 1.0f, // vec4 fBlue; // align
3246 1.0f, 0.0f, // vec2 fOneZero; // align
3247 1.0f, 1.0f, // vec2 fOneOne; // pack
3248 0.0f, 1.0f, 1.0f, // vec3 fZeroOneOne; // align
3249 10.0f, // float fTen; // pack
3250 11.0f, // float fEleven; // align
3251 12.0f, // float fTwelve; // pack
3252 0.0f, 0.0f, // BUFFER
3253 1.0f, 0.0f, 0.0f, // vec3 fOneZeroZero; // align
3254 0.0f, // BUFFER
3255 0.1f, 0.2f, 0.3f, 0.4f, // vec4 uvOffsets[4];
3256 0.5f, 0.6f, 0.7f, 0.8f, // align
3257 0.9f, 1.0f, 1.1f, 1.2f, // align
3258 1.3f, 1.4f, 1.5f, 1.6f, // align
Cody Northrop02690bd2014-12-17 15:26:33 -07003259 };
3260
3261 ASSERT_NO_FATAL_FAILURE(InitState());
3262 ASSERT_NO_FATAL_FAILURE(InitViewport());
3263
3264 const int constCount = sizeof(mixedVals) / sizeof(float);
3265
Tony Barbour01999182015-04-09 12:58:51 -06003266 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3267 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop02690bd2014-12-17 15:26:33 -07003268
Tony Barbour01999182015-04-09 12:58:51 -06003269 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003270
Tony Barbour01999182015-04-09 12:58:51 -06003271 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003272 pipelineobj.AddColorAttachment();
Cody Northrop02690bd2014-12-17 15:26:33 -07003273 pipelineobj.AddShader(&vs);
3274 pipelineobj.AddShader(&ps);
3275
Tony Barbour01999182015-04-09 12:58:51 -06003276 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003277 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003278
3279 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003280 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop02690bd2014-12-17 15:26:33 -07003281
Tony Barbour1490c912015-07-28 10:17:20 -06003282 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop02690bd2014-12-17 15:26:33 -07003283
3284#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003285 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop02690bd2014-12-17 15:26:33 -07003286 pDSDumpDot((char*)"triTest2.dot");
3287#endif
3288 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06003289 Draw(0, 3, 0, 1);
Cody Northrop02690bd2014-12-17 15:26:33 -07003290
3291 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003292 EndCommandBuffer();
3293 QueueCommandBuffer();
Cody Northrop02690bd2014-12-17 15:26:33 -07003294
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003295 RecordImages(m_renderTargets);
Cody Northrop02690bd2014-12-17 15:26:33 -07003296}
3297
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003298TEST_F(VkRenderTest, TextureGather)
3299{
3300 // This test introduces textureGather and textureGatherOffset
3301 // Each call is compared against an expected inline color result
3302 // Green triangle means everything worked as expected
3303 // Red means something went wrong
3304
Cody Northropbe701ac2015-08-06 13:18:13 -06003305 // disable SPV until texture gather is turned on in glsl->SPV
3306 if (!m_use_glsl) {
3307 printf("Skipping test that requires GLSL path (TextureGather)\n");
3308 return;
3309 }
3310
Cody Northrop1cfbd172015-06-03 16:49:20 -06003311 ScopedUseGlsl useGlsl(true);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003312
3313 static const char *vertShaderText =
3314 "#version 140\n"
3315 "#extension GL_ARB_separate_shader_objects : enable\n"
3316 "#extension GL_ARB_shading_language_420pack : enable\n"
3317 "void main() {\n"
3318 " vec2 vertices[3];"
3319 " vertices[0] = vec2(-0.5, -0.5);\n"
3320 " vertices[1] = vec2( 0.5, -0.5);\n"
3321 " vertices[2] = vec2( 0.5, 0.5);\n"
3322 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
3323 "}\n";
3324
3325 static const char *fragShaderText =
3326 "#version 430\n"
3327 "#extension GL_ARB_separate_shader_objects : enable\n"
3328 "#extension GL_ARB_shading_language_420pack : enable\n"
3329 "layout (binding = 0) uniform sampler2D surface0;\n"
3330 "layout (binding = 1) uniform sampler2D surface1;\n"
3331 "layout (binding = 2) uniform sampler2D surface2;\n"
3332 "layout (binding = 3) uniform sampler2D surface3;\n"
3333 "layout (location = 0) out vec4 outColor;\n"
3334 "void main() {\n"
3335
3336 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3337 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3338
3339 " vec4 color = right;\n"
3340
3341 // Grab a normal texture sample to ensure it can work in conjuntion
3342 // with textureGather (there are some intracacies in the backend)
3343 " vec4 sampledColor = textureLod(surface2, vec2(0.5), 0.0);\n"
3344 " if (sampledColor != vec4(0.0, 0.0, 1.0, 1.0))\n"
3345 " color = wrong;\n"
3346
3347 " vec4 gatheredColor = textureGather(surface0, vec2(0.5), 0);\n"
3348 // This just grabbed four red components from a red surface
3349 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3350 " color = wrong;\n"
3351
3352 // Yes, this is using an offset of 0, we don't have enough fine grained
3353 // control of the texture contents here.
3354 " gatheredColor = textureGatherOffset(surface1, vec2(0.5), ivec2(0, 0), 1);\n"
3355 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3356 " color = wrong;\n"
3357
3358 " outColor = color;\n"
3359
3360 "}\n";
3361
3362 ASSERT_NO_FATAL_FAILURE(InitState());
3363 ASSERT_NO_FATAL_FAILURE(InitViewport());
3364
3365 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3366 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3367
3368 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
3369 VkSamplerObj sampler0(m_device);
3370 VkTextureObj texture0(m_device, tex_colors); // Red
3371 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
3372 VkSamplerObj sampler1(m_device);
3373 VkTextureObj texture1(m_device, tex_colors); // Green
3374 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
3375 VkSamplerObj sampler2(m_device);
3376 VkTextureObj texture2(m_device, tex_colors); // Blue
3377 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
3378 VkSamplerObj sampler3(m_device);
3379 VkTextureObj texture3(m_device, tex_colors); // Red and Blue
3380
3381 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003382 pipelineobj.AddColorAttachment();
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003383 pipelineobj.AddShader(&vs);
3384 pipelineobj.AddShader(&ps);
3385
3386 VkDescriptorSetObj descriptorSet(m_device);
3387 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3388 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
3389 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3390 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
3391
3392 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003393 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003394
Tony Barbour1490c912015-07-28 10:17:20 -06003395 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003396
3397 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06003398 Draw(0, 3, 0, 1);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003399
3400 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003401 EndCommandBuffer();
3402 QueueCommandBuffer();
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003403
3404 RecordImages(m_renderTargets);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003405}
3406
Cody Northropa44c2ff2015-04-15 11:19:06 -06003407TEST_F(VkRenderTest, GeometryShaderHelloWorld)
3408{
3409 // This test introduces a geometry shader that simply
3410 // changes the color of each vertex to red, green, blue
3411
3412 static const char *vertShaderText =
3413 "#version 140\n"
3414 "#extension GL_ARB_separate_shader_objects : enable\n"
3415 "#extension GL_ARB_shading_language_420pack : enable\n"
3416 "layout (location = 0) out vec4 color;"
3417 "void main() {\n"
3418
3419 // VS writes out red
3420 " color = vec4(1.0, 0.0, 0.0, 1.0);\n"
3421
3422 // generic position stuff
3423 " vec2 vertices;\n"
3424 " int vertexSelector = gl_VertexID;\n"
3425 " if (vertexSelector == 0)\n"
3426 " vertices = vec2(-0.5, -0.5);\n"
3427 " else if (vertexSelector == 1)\n"
3428 " vertices = vec2( 0.5, -0.5);\n"
3429 " else if (vertexSelector == 2)\n"
3430 " vertices = vec2( 0.5, 0.5);\n"
3431 " else\n"
3432 " vertices = vec2( 0.0, 0.0);\n"
3433 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3434
3435 "}\n";
3436
3437 static const char *geomShaderText =
3438 "#version 330\n"
3439 "#extension GL_ARB_separate_shader_objects : enable\n"
3440 "#extension GL_ARB_shading_language_420pack : enable\n"
3441 "layout( triangles ) in;\n"
3442 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3443 "layout( location = 0 ) in vec4 inColor[3];\n"
3444 "layout( location = 0 ) out vec4 outColor;\n"
3445 "void main()\n"
3446 "{\n"
3447
3448 // first vertex, pass through red
3449 " gl_Position = gl_in[0].gl_Position;\n"
3450 " outColor = inColor[0];\n"
3451 " EmitVertex();\n"
3452
3453 // second vertex, green
3454 " gl_Position = gl_in[1].gl_Position;\n"
3455 " outColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3456 " EmitVertex();\n"
3457
3458 // third vertex, blue
3459 " gl_Position = gl_in[2].gl_Position;\n"
3460 " outColor = vec4(0.0, 0.0, 1.0, 1.0);\n"
3461 " EmitVertex();\n"
3462
3463 // done
3464 " EndPrimitive();\n"
3465 "}\n";
3466
3467
3468 static const char *fragShaderText =
3469 "#version 140\n"
3470 "#extension GL_ARB_separate_shader_objects : enable\n"
3471 "#extension GL_ARB_shading_language_420pack : enable\n"
3472 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003473 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003474 "void main() {\n"
3475 // pass through
GregFd6ebdb32015-06-03 18:40:50 -06003476 " outColor = color;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003477 "}\n";
3478
3479
3480
3481 ASSERT_NO_FATAL_FAILURE(InitState());
3482 ASSERT_NO_FATAL_FAILURE(InitViewport());
3483
3484 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3485 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3486 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3487
3488 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003489 pipelineobj.AddColorAttachment();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003490 pipelineobj.AddShader(&vs);
3491 pipelineobj.AddShader(&gs);
3492 pipelineobj.AddShader(&ps);
3493
3494 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003495 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropa44c2ff2015-04-15 11:19:06 -06003496
3497 VkDescriptorSetObj descriptorSet(m_device);
3498
Tony Barbour1490c912015-07-28 10:17:20 -06003499 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003500
3501 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06003502 Draw(0, 3, 0, 1);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003503
3504 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003505 EndCommandBuffer();
3506 QueueCommandBuffer();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003507
3508 RecordImages(m_renderTargets);
3509}
3510
3511TEST_F(VkRenderTest, GSUniformBufferLayout)
3512{
3513 // This test is just like TriangleUniformBufferLayout but adds
3514 // geometry as a stage that also does UBO lookups
3515 // The expected result from this test is a green triangle
3516
3517 static const char *vertShaderText =
3518 "#version 140\n"
3519 "#extension GL_ARB_separate_shader_objects : enable\n"
3520 "#extension GL_ARB_shading_language_420pack : enable\n"
3521 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3522 " vec4 fRed;\n"
3523 " vec4 fGreen;\n"
3524 " layout(row_major) mat4 worldToProj;\n"
3525 " layout(row_major) mat4 projToWorld;\n"
3526 " layout(row_major) mat4 worldToView;\n"
3527 " layout(row_major) mat4 viewToProj;\n"
3528 " layout(row_major) mat4 worldToShadow[4];\n"
3529 " float fZero;\n"
3530 " float fOne;\n"
3531 " float fTwo;\n"
3532 " float fThree;\n"
3533 " vec3 fZeroZeroZero;\n"
3534 " float fFour;\n"
3535 " vec3 fZeroZeroOne;\n"
3536 " float fFive;\n"
3537 " vec3 fZeroOneZero;\n"
3538 " float fSix;\n"
3539 " float fSeven;\n"
3540 " float fEight;\n"
3541 " float fNine;\n"
3542 " vec2 fZeroZero;\n"
3543 " vec2 fZeroOne;\n"
3544 " vec4 fBlue;\n"
3545 " vec2 fOneZero;\n"
3546 " vec2 fOneOne;\n"
3547 " vec3 fZeroOneOne;\n"
3548 " float fTen;\n"
3549 " float fEleven;\n"
3550 " float fTwelve;\n"
3551 " vec3 fOneZeroZero;\n"
3552 " vec4 uvOffsets[4];\n"
3553 "};\n"
3554 "layout (location = 0) out vec4 color;"
3555 "void main() {\n"
3556
3557 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3558 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3559 " \n"
3560
3561 // do some exact comparisons, even though we should
3562 // really have an epsilon involved.
3563 " vec4 outColor = right;\n"
3564 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3565 " outColor = wrong;\n"
3566 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3567 " outColor = wrong;\n"
3568 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3569 " outColor = wrong;\n"
3570
3571 " color = outColor;\n"
3572
3573 // generic position stuff
3574 " vec2 vertices;\n"
3575 " int vertexSelector = gl_VertexID;\n"
3576 " if (vertexSelector == 0)\n"
3577 " vertices = vec2(-0.5, -0.5);\n"
3578 " else if (vertexSelector == 1)\n"
3579 " vertices = vec2( 0.5, -0.5);\n"
3580 " else if (vertexSelector == 2)\n"
3581 " vertices = vec2( 0.5, 0.5);\n"
3582 " else\n"
3583 " vertices = vec2( 0.0, 0.0);\n"
3584 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3585 "}\n";
3586
3587 static const char *geomShaderText =
3588 "#version 330\n"
3589 "#extension GL_ARB_separate_shader_objects : enable\n"
3590 "#extension GL_ARB_shading_language_420pack : enable\n"
3591
3592 // GS layout stuff
3593 "layout( triangles ) in;\n"
3594 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3595
3596 // Between stage IO
3597 "layout( location = 0 ) in vec4 inColor[3];\n"
3598 "layout( location = 0 ) out vec4 color;\n"
3599
3600 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3601 " vec4 fRed;\n"
3602 " vec4 fGreen;\n"
3603 " layout(row_major) mat4 worldToProj;\n"
3604 " layout(row_major) mat4 projToWorld;\n"
3605 " layout(row_major) mat4 worldToView;\n"
3606 " layout(row_major) mat4 viewToProj;\n"
3607 " layout(row_major) mat4 worldToShadow[4];\n"
3608 " float fZero;\n"
3609 " float fOne;\n"
3610 " float fTwo;\n"
3611 " float fThree;\n"
3612 " vec3 fZeroZeroZero;\n"
3613 " float fFour;\n"
3614 " vec3 fZeroZeroOne;\n"
3615 " float fFive;\n"
3616 " vec3 fZeroOneZero;\n"
3617 " float fSix;\n"
3618 " float fSeven;\n"
3619 " float fEight;\n"
3620 " float fNine;\n"
3621 " vec2 fZeroZero;\n"
3622 " vec2 fZeroOne;\n"
3623 " vec4 fBlue;\n"
3624 " vec2 fOneZero;\n"
3625 " vec2 fOneOne;\n"
3626 " vec3 fZeroOneOne;\n"
3627 " float fTen;\n"
3628 " float fEleven;\n"
3629 " float fTwelve;\n"
3630 " vec3 fOneZeroZero;\n"
3631 " vec4 uvOffsets[4];\n"
3632 "};\n"
3633
3634 "void main()\n"
3635 "{\n"
3636
3637 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3638 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3639
3640 // Each vertex will validate it can read VS output
3641 // then check a few values from the UBO
3642
3643 // first vertex
3644 " vec4 outColor = inColor[0];\n"
3645
3646 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3647 " outColor = wrong;\n"
3648 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3649 " outColor = wrong;\n"
3650 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3651 " outColor = wrong;\n"
3652 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3653 " outColor = wrong;\n"
3654
3655 " gl_Position = gl_in[0].gl_Position;\n"
3656 " color = outColor;\n"
3657 " EmitVertex();\n"
3658
3659 // second vertex
3660 " outColor = inColor[1];\n"
3661
3662 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3663 " outColor = wrong;\n"
3664 " if (fSix != 6.0)\n"
3665 " outColor = wrong;\n"
3666 " if (fOneOne != vec2(1.0, 1.0))\n"
3667 " outColor = wrong;\n"
3668
3669 " gl_Position = gl_in[1].gl_Position;\n"
3670 " color = outColor;\n"
3671 " EmitVertex();\n"
3672
3673 // third vertex
3674 " outColor = inColor[2];\n"
3675
3676 " if (fSeven != 7.0)\n"
3677 " outColor = wrong;\n"
3678 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3679 " outColor = wrong;\n"
3680
3681 " gl_Position = gl_in[2].gl_Position;\n"
3682 " color = outColor;\n"
3683 " EmitVertex();\n"
3684
3685 // done
3686 " EndPrimitive();\n"
3687 "}\n";
3688
3689 static const char *fragShaderText =
3690 "#version 140\n"
3691 "#extension GL_ARB_separate_shader_objects : enable\n"
3692 "#extension GL_ARB_shading_language_420pack : enable\n"
3693 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3694 " vec4 fRed;\n"
3695 " vec4 fGreen;\n"
3696 " layout(row_major) mat4 worldToProj;\n"
3697 " layout(row_major) mat4 projToWorld;\n"
3698 " layout(row_major) mat4 worldToView;\n"
3699 " layout(row_major) mat4 viewToProj;\n"
3700 " layout(row_major) mat4 worldToShadow[4];\n"
3701 " float fZero;\n"
3702 " float fOne;\n"
3703 " float fTwo;\n"
3704 " float fThree;\n"
3705 " vec3 fZeroZeroZero;\n"
3706 " float fFour;\n"
3707 " vec3 fZeroZeroOne;\n"
3708 " float fFive;\n"
3709 " vec3 fZeroOneZero;\n"
3710 " float fSix;\n"
3711 " float fSeven;\n"
3712 " float fEight;\n"
3713 " float fNine;\n"
3714 " vec2 fZeroZero;\n"
3715 " vec2 fZeroOne;\n"
3716 " vec4 fBlue;\n"
3717 " vec2 fOneZero;\n"
3718 " vec2 fOneOne;\n"
3719 " vec3 fZeroOneOne;\n"
3720 " float fTen;\n"
3721 " float fEleven;\n"
3722 " float fTwelve;\n"
3723 " vec3 fOneZeroZero;\n"
3724 " vec4 uvOffsets[4];\n"
3725 "};\n"
3726 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003727 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003728 "void main() {\n"
3729 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3730 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3731 " \n"
3732
3733 // start with GS value to ensure it passed
3734 " vec4 outColor = color;\n"
3735
3736 // do some exact comparisons, even though we should
3737 // really have an epsilon involved.
3738 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3739 " outColor = wrong;\n"
3740 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3741 " outColor = wrong;\n"
3742 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3743 " outColor = wrong;\n"
3744 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3745 " outColor = wrong;\n"
3746 " if (fTwo != 2.0)\n"
3747 " outColor = wrong;\n"
3748 " if (fOneOne != vec2(1.0, 1.0))\n"
3749 " outColor = wrong;\n"
3750 " if (fTen != 10.0)\n"
3751 " outColor = wrong;\n"
3752 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3753 " outColor = wrong;\n"
3754 " \n"
GregFd6ebdb32015-06-03 18:40:50 -06003755 " uFragColor = outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003756 "}\n";
3757
3758
Cody Northrop1684adb2015-08-05 11:15:02 -06003759 const float mixedVals[196] = { 1.0f, 0.0f, 0.0f, 1.0f, // vec4 fRed; // align
3760 0.0f, 1.0f, 0.0f, 1.0f, // vec4 fGreen; // align
3761 1.0f, 0.0f, 0.0f, 1.0f, // layout(row_major) mat4 worldToProj;
3762 0.0f, 1.0f, 0.0f, 1.0f, // align
3763 0.0f, 0.0f, 1.0f, 1.0f, // align
3764 0.0f, 0.0f, 0.0f, 1.0f, // align
3765 2.0f, 0.0f, 0.0f, 2.0f, // layout(row_major) mat4 projToWorld;
3766 0.0f, 2.0f, 0.0f, 2.0f, // align
3767 0.0f, 0.0f, 2.0f, 2.0f, // align
3768 0.0f, 0.0f, 0.0f, 2.0f, // align
3769 3.0f, 0.0f, 0.0f, 3.0f, // layout(row_major) mat4 worldToView;
3770 0.0f, 3.0f, 0.0f, 3.0f, // align
3771 0.0f, 0.0f, 3.0f, 3.0f, // align
3772 0.0f, 0.0f, 0.0f, 3.0f, // align
3773 4.0f, 0.0f, 0.0f, 4.0f, // layout(row_major) mat4 viewToProj;
3774 0.0f, 4.0f, 0.0f, 4.0f, // align
3775 0.0f, 0.0f, 4.0f, 4.0f, // align
3776 0.0f, 0.0f, 0.0f, 4.0f, // align
3777 5.0f, 0.0f, 0.0f, 5.0f, // layout(row_major) mat4 worldToShadow[4];
3778 0.0f, 5.0f, 0.0f, 5.0f, // align
3779 0.0f, 0.0f, 5.0f, 5.0f, // align
3780 0.0f, 0.0f, 0.0f, 5.0f, // align
3781 6.0f, 0.0f, 0.0f, 6.0f, // align
3782 0.0f, 6.0f, 0.0f, 6.0f, // align
3783 0.0f, 0.0f, 6.0f, 6.0f, // align
3784 0.0f, 0.0f, 0.0f, 6.0f, // align
3785 7.0f, 0.0f, 0.0f, 7.0f, // align
3786 0.0f, 7.0f, 0.0f, 7.0f, // align
3787 0.0f, 0.0f, 7.0f, 7.0f, // align
3788 0.0f, 0.0f, 0.0f, 7.0f, // align
3789 8.0f, 0.0f, 0.0f, 8.0f, // align
3790 0.0f, 8.0f, 0.0f, 8.0f, // align
3791 0.0f, 0.0f, 8.0f, 8.0f, // align
3792 0.0f, 0.0f, 0.0f, 8.0f, // align
3793 0.0f, // float fZero; // align
3794 1.0f, // float fOne; // pack
3795 2.0f, // float fTwo; // pack
3796 3.0f, // float fThree; // pack
3797 0.0f, 0.0f, 0.0f, // vec3 fZeroZeroZero; // align
3798 4.0f, // float fFour; // pack
3799 0.0f, 0.0f, 1.0f, // vec3 fZeroZeroOne; // align
3800 5.0f, // float fFive; // pack
3801 0.0f, 1.0f, 0.0f, // vec3 fZeroOneZero; // align
3802 6.0f, // float fSix; // pack
3803 7.0f, // float fSeven; // align
3804 8.0f, // float fEight; // pack
3805 9.0f, // float fNine; // pack
3806 0.0f, // BUFFER
3807 0.0f, 0.0f, // vec2 fZeroZero; // align
3808 0.0f, 1.0f, // vec2 fZeroOne; // pack
3809 0.0f, 0.0f, 1.0f, 1.0f, // vec4 fBlue; // align
3810 1.0f, 0.0f, // vec2 fOneZero; // align
3811 1.0f, 1.0f, // vec2 fOneOne; // pack
3812 0.0f, 1.0f, 1.0f, // vec3 fZeroOneOne; // align
3813 10.0f, // float fTen; // pack
3814 11.0f, // float fEleven; // align
3815 12.0f, // float fTwelve; // pack
3816 0.0f, 0.0f, // BUFFER
3817 1.0f, 0.0f, 0.0f, // vec3 fOneZeroZero; // align
3818 0.0f, // BUFFER
3819 0.1f, 0.2f, 0.3f, 0.4f, // vec4 uvOffsets[4];
3820 0.5f, 0.6f, 0.7f, 0.8f, // align
3821 0.9f, 1.0f, 1.1f, 1.2f, // align
3822 1.3f, 1.4f, 1.5f, 1.6f, // align
Cody Northropa44c2ff2015-04-15 11:19:06 -06003823 };
3824
3825
3826
3827 ASSERT_NO_FATAL_FAILURE(InitState());
3828 ASSERT_NO_FATAL_FAILURE(InitViewport());
3829
3830 const int constCount = sizeof(mixedVals) / sizeof(float);
3831
3832 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3833 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3834 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3835
3836 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
3837
3838 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003839 pipelineobj.AddColorAttachment();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003840 pipelineobj.AddShader(&vs);
3841 pipelineobj.AddShader(&gs);
3842 pipelineobj.AddShader(&ps);
3843
3844 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003845 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropa44c2ff2015-04-15 11:19:06 -06003846
3847 VkDescriptorSetObj descriptorSet(m_device);
3848 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
3849
Tony Barbour1490c912015-07-28 10:17:20 -06003850 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003851
3852 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06003853 Draw(0, 3, 0, 1);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003854
3855 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003856 EndCommandBuffer();
3857 QueueCommandBuffer();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003858
3859 RecordImages(m_renderTargets);
3860}
3861
3862TEST_F(VkRenderTest, GSPositions)
3863{
3864 // This test adds more inputs from the vertex shader and perturbs positions
3865 // Expected result is white triangle with weird positions
3866
3867 static const char *vertShaderText =
3868 "#version 140\n"
3869 "#extension GL_ARB_separate_shader_objects : enable\n"
3870 "#extension GL_ARB_shading_language_420pack : enable\n"
3871
3872 "layout(location = 0) out vec3 out_a;\n"
3873 "layout(location = 1) out vec3 out_b;\n"
3874 "layout(location = 2) out vec3 out_c;\n"
3875
3876 "void main() {\n"
3877
3878 // write a solid color to each
3879 " out_a = vec3(1.0, 0.0, 0.0);\n"
3880 " out_b = vec3(0.0, 1.0, 0.0);\n"
3881 " out_c = vec3(0.0, 0.0, 1.0);\n"
3882
3883 // generic position stuff
3884 " vec2 vertices;\n"
3885 " int vertexSelector = gl_VertexID;\n"
3886 " if (vertexSelector == 0)\n"
3887 " vertices = vec2(-0.5, -0.5);\n"
3888 " else if (vertexSelector == 1)\n"
3889 " vertices = vec2( 0.5, -0.5);\n"
3890 " else if (vertexSelector == 2)\n"
3891 " vertices = vec2( 0.5, 0.5);\n"
3892 " else\n"
3893 " vertices = vec2( 0.0, 0.0);\n"
3894 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3895
3896 "}\n";
3897
3898 static const char *geomShaderText =
3899 "#version 330\n"
3900 "#extension GL_ARB_separate_shader_objects : enable\n"
3901 "#extension GL_ARB_shading_language_420pack : enable\n"
3902 "layout( triangles ) in;\n"
3903 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3904
3905 "layout(location = 0) in vec3 in_a[3];\n"
3906 "layout(location = 1) in vec3 in_b[3];\n"
3907 "layout(location = 2) in vec3 in_c[3];\n"
3908
3909 "layout(location = 0) out vec3 out_a;\n"
3910 "layout(location = 1) out vec3 out_b;\n"
3911 "layout(location = 2) out vec3 out_c;\n"
3912
3913 "void main()\n"
3914 "{\n"
3915
3916 " gl_Position = gl_in[0].gl_Position;\n"
3917 " gl_Position.xy *= vec2(0.75);\n"
3918 " out_a = in_a[0];\n"
3919 " out_b = in_b[0];\n"
3920 " out_c = in_c[0];\n"
3921 " EmitVertex();\n"
3922
3923 " gl_Position = gl_in[1].gl_Position;\n"
3924 " gl_Position.xy *= vec2(1.5);\n"
3925 " out_a = in_a[1];\n"
3926 " out_b = in_b[1];\n"
3927 " out_c = in_c[1];\n"
3928 " EmitVertex();\n"
3929
3930 " gl_Position = gl_in[2].gl_Position;\n"
3931 " gl_Position.xy *= vec2(-0.1);\n"
3932 " out_a = in_a[2];\n"
3933 " out_b = in_b[2];\n"
3934 " out_c = in_c[2];\n"
3935 " EmitVertex();\n"
3936
3937 " EndPrimitive();\n"
3938 "}\n";
3939
3940
3941 static const char *fragShaderText =
3942 "#version 140\n"
3943 "#extension GL_ARB_separate_shader_objects : enable\n"
3944 "#extension GL_ARB_shading_language_420pack : enable\n"
3945
3946 "layout(location = 0) in vec3 in_a;\n"
3947 "layout(location = 1) in vec3 in_b;\n"
3948 "layout(location = 2) in vec3 in_c;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003949 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003950
3951 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06003952 " outColor = vec4(in_a.x, in_b.y, in_c.z, 1.0);\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003953 "}\n";
3954
3955
3956
3957 ASSERT_NO_FATAL_FAILURE(InitState());
3958 ASSERT_NO_FATAL_FAILURE(InitViewport());
3959
3960 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3961 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3962 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3963
3964 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003965 pipelineobj.AddColorAttachment();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003966 pipelineobj.AddShader(&vs);
3967 pipelineobj.AddShader(&gs);
3968 pipelineobj.AddShader(&ps);
3969
3970 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003971 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropa44c2ff2015-04-15 11:19:06 -06003972
3973 VkDescriptorSetObj descriptorSet(m_device);
3974
Tony Barbour1490c912015-07-28 10:17:20 -06003975 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003976
3977 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06003978 Draw(0, 3, 0, 1);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003979
3980 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003981 EndCommandBuffer();
3982 QueueCommandBuffer();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003983
3984 RecordImages(m_renderTargets);
3985}
3986
3987TEST_F(VkRenderTest, GSTriStrip)
3988{
3989 // This test emits multiple multiple triangles using a GS
3990 // Correct result is an multicolor circle
3991
3992 static const char *vertShaderText =
3993 "#version 140\n"
3994 "#extension GL_ARB_separate_shader_objects : enable\n"
3995 "#extension GL_ARB_shading_language_420pack : enable\n"
3996
3997 "void main() {\n"
3998
3999 // generic position stuff
4000 " vec2 vertices;\n"
4001 " int vertexSelector = gl_VertexID;\n"
4002 " if (vertexSelector == 0)\n"
4003 " vertices = vec2(-0.5, -0.5);\n"
4004 " else if (vertexSelector == 1)\n"
4005 " vertices = vec2( 0.5, -0.5);\n"
4006 " else if (vertexSelector == 2)\n"
4007 " vertices = vec2( 0.5, 0.5);\n"
4008 " else\n"
4009 " vertices = vec2( 0.0, 0.0);\n"
4010 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
4011
4012 "}\n";
4013
4014 static const char *geomShaderText =
4015 "#version 330\n"
4016 "#extension GL_ARB_separate_shader_objects : enable\n"
4017 "#extension GL_ARB_shading_language_420pack : enable\n"
4018 "layout( triangles ) in;\n"
4019 "layout( triangle_strip, max_vertices = 18 ) out;\n"
4020
4021 "layout(location = 0) out vec4 outColor;\n"
4022
4023 "void main()\n"
4024 "{\n"
4025 // init with first position to get zw
4026 " gl_Position = gl_in[0].gl_Position;\n"
4027
4028 " vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
4029 " vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
4030 " vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
4031 " vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
4032
4033 // different color per tri
4034 " vec4[6] colors = { red, white, \n"
4035 " yellow, white, \n"
4036 " blue, white }; \n"
4037
4038 // fan out the triangles
4039 " vec2[18] positions = { vec2(0.0, 0.0), vec2(-0.5, 0.0), vec2(-0.25, -0.5), \n"
4040 " vec2(0.0, 0.0), vec2(-0.25, -0.5), vec2( 0.25, -0.5), \n"
4041 " vec2(0.0, 0.0), vec2( 0.25, -0.5), vec2( 0.5, 0.0), \n"
4042 " vec2(0.0, 0.0), vec2( 0.5, 0.0), vec2( 0.25, 0.5), \n"
4043 " vec2(0.0, 0.0), vec2( 0.25, 0.5), vec2(-0.25, 0.5), \n"
4044 " vec2(0.0, 0.0), vec2(-0.25, 0.5), vec2(-0.5, 0.0) }; \n"
4045
4046 // make a triangle list of 6
4047 " for (int i = 0; i < 6; ++i) { \n"
4048 " outColor = colors[i]; \n"
4049 " for (int j = 0; j < 3; ++j) { \n"
4050 " gl_Position.xy = positions[i * 3 + j]; \n"
4051 " EmitVertex(); \n"
4052 " } \n"
4053 " EndPrimitive();\n"
4054 " } \n"
4055
4056 "}\n";
4057
4058
4059 static const char *fragShaderText =
4060 "#version 150\n"
4061 "#extension GL_ARB_separate_shader_objects : enable\n"
4062 "#extension GL_ARB_shading_language_420pack : enable\n"
4063
4064
4065 "layout(binding = 0) uniform windowDimensions {\n"
4066 " vec4 dimensions;\n"
4067 "};\n"
4068
4069 "layout(location = 0) in vec4 inColor;\n"
4070 "layout(origin_upper_left) in vec4 gl_FragCoord;\n"
GregFd6ebdb32015-06-03 18:40:50 -06004071 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06004072
4073 "void main() {\n"
4074
4075 // discard to make a nice circle
4076 " vec2 pos = abs(gl_FragCoord.xy) - vec2(dimensions.x, dimensions.y) / 2;\n"
4077 " float dist = sqrt(dot(pos, pos));\n"
4078 " if (dist > 50.0)\n"
4079 " discard;\n"
4080
GregFd6ebdb32015-06-03 18:40:50 -06004081 " outColor = inColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06004082
4083 "}\n";
4084
4085
4086
4087 ASSERT_NO_FATAL_FAILURE(InitState());
4088 ASSERT_NO_FATAL_FAILURE(InitViewport());
4089
4090 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
4091 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
4092 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
4093
4094 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004095 pipelineobj.AddColorAttachment();
Cody Northropa44c2ff2015-04-15 11:19:06 -06004096 pipelineobj.AddShader(&vs);
4097 pipelineobj.AddShader(&gs);
4098 pipelineobj.AddShader(&ps);
4099
4100 const float dimensions[4] = { VkRenderFramework::m_width, VkRenderFramework::m_height , 0.0, 0.0};
4101
4102 VkConstantBufferObj windowDimensions(m_device, sizeof(dimensions) / sizeof(dimensions[0]), sizeof(dimensions[0]), (const void*) dimensions);
4103
4104 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06004105 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropa44c2ff2015-04-15 11:19:06 -06004106
4107 VkDescriptorSetObj descriptorSet(m_device);
4108 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, windowDimensions);
4109
Tony Barbour1490c912015-07-28 10:17:20 -06004110 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northropa44c2ff2015-04-15 11:19:06 -06004111
4112 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06004113 Draw(0, 3, 0, 1);
Cody Northropa44c2ff2015-04-15 11:19:06 -06004114
4115 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06004116 EndCommandBuffer();
4117 QueueCommandBuffer();
Cody Northropa44c2ff2015-04-15 11:19:06 -06004118
4119 RecordImages(m_renderTargets);
4120}
4121
Chris Forbes23e6db62015-06-15 09:32:35 +12004122TEST_F(VkRenderTest, RenderPassLoadOpClear)
4123{
4124 ASSERT_NO_FATAL_FAILURE(InitState());
4125 ASSERT_NO_FATAL_FAILURE(InitViewport());
4126
4127 /* clear via load op to full green */
4128 m_clear_via_load_op = true;
Chris Forbese3105972015-06-24 14:34:53 +12004129 m_clear_color.f32[0] = 0;
4130 m_clear_color.f32[1] = 1;
4131 m_clear_color.f32[2] = 0;
4132 m_clear_color.f32[3] = 0;
Chris Forbes23e6db62015-06-15 09:32:35 +12004133 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06004134 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Chris Forbes23e6db62015-06-15 09:32:35 +12004135 /* This command buffer contains ONLY the load op! */
Tony Barbour1490c912015-07-28 10:17:20 -06004136 EndCommandBuffer();
4137 QueueCommandBuffer();
Chris Forbes23e6db62015-06-15 09:32:35 +12004138
4139 RecordImages(m_renderTargets);
4140}
4141
Chris Forbes1e16cb82015-06-24 12:05:30 +12004142TEST_F(VkRenderTest, RenderPassAttachmentClear)
4143{
4144 ASSERT_NO_FATAL_FAILURE(InitState());
4145 ASSERT_NO_FATAL_FAILURE(InitViewport());
4146
4147 /* clear via load op to full red */
4148 m_clear_via_load_op = true;
Chris Forbese3105972015-06-24 14:34:53 +12004149 m_clear_color.f32[0] = 1;
4150 m_clear_color.f32[1] = 0;
4151 m_clear_color.f32[2] = 0;
4152 m_clear_color.f32[3] = 0;
Chris Forbes1e16cb82015-06-24 12:05:30 +12004153 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06004154 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Chris Forbes1e16cb82015-06-24 12:05:30 +12004155
4156 /* Load op has cleared to red */
4157
4158 /* Draw, draw, draw... */
4159
4160 /* Now, partway through this renderpass we want to clear the color
4161 * attachment again, this time to green.
4162 */
Chris Forbese3105972015-06-24 14:34:53 +12004163 VkClearColorValue clear_color;
4164 clear_color.f32[0] = 0;
4165 clear_color.f32[1] = 1;
4166 clear_color.f32[2] = 0;
4167 clear_color.f32[3] = 0;
Chris Forbes1e16cb82015-06-24 12:05:30 +12004168 VkRect3D clear_rect = { { 0, 0, 0 }, { (int)m_width, (int)m_height, 1 } };
Tony Barbour1490c912015-07-28 10:17:20 -06004169 vkCmdClearColorAttachment(m_cmdBuffer->handle(), 0,
Chris Forbes1e16cb82015-06-24 12:05:30 +12004170 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4171 &clear_color, 1, &clear_rect);
4172
Tony Barbour1490c912015-07-28 10:17:20 -06004173 EndCommandBuffer();
4174 QueueCommandBuffer();
Chris Forbes1e16cb82015-06-24 12:05:30 +12004175
4176 RecordImages(m_renderTargets);
4177}
4178
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004179int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004180 int result;
4181
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004182 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06004183 VkTestFramework::InitArgs(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004184
Chia-I Wu7133fdc2014-12-15 23:57:34 +08004185 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06004186
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004187 result = RUN_ALL_TESTS();
4188
Tony Barbour01999182015-04-09 12:58:51 -06004189 VkTestFramework::Finish();
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004190 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004191}