blob: 4e1c1d70367765e1d92b0e819215761fe29430a2 [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);
Cody Northrop2605cb02015-08-18 15:21:16 -0600391 cmdBuffer->BindDynamicDepthState(m_stateDepth);
392 cmdBuffer->BindDynamicStencilState(m_stateStencil);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600393 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
Tony Barboured132432015-08-04 16:23:11 -0600394 pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600395 cmdBuffer->BindPipeline(pipelineobj);
Chia-I Wu862c5572015-03-28 15:23:55 +0800396 cmdBuffer->BindDescriptorSet(descriptorSet);
Tony Barbour02472db2015-01-08 17:08:28 -0700397}
Tony Barbourf43b6982014-11-25 13:18:32 -0700398
Tony Barbour01999182015-04-09 12:58:51 -0600399void VkRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
400 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer)
Tony Barbourdd4c9642015-01-09 12:55:14 -0700401{
402 int i;
403 glm::mat4 MVP;
404 int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600405 VkResult err;
Tony Barbourdd4c9642015-01-09 12:55:14 -0700406
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600407 /* Only do 3 positions to avoid back face cull */
408 for (i = 0; i < 3; i++) {
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800409 void *pData = constantBuffer->memory().map();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700410
411 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
412 MVP = Projection * View * Model;
413 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
414
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800415 constantBuffer->memory().unmap();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700416
417 // submit the command buffer to the universal queue
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600418 cmdBuffer->QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700419
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600420 err = vkQueueWaitIdle( m_device->m_queue );
421 ASSERT_VK_SUCCESS( err );
Tony Barbourdd4c9642015-01-09 12:55:14 -0700422
423 // Wait for work to finish before cleaning up.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600424 vkDeviceWaitIdle(m_device->device());
Tony Barbourdd4c9642015-01-09 12:55:14 -0700425
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700426 assert(m_renderTargets.size() == 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -0700427 RecordImage(m_renderTargets[0]);
428 }
429}
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600430
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600431void dumpMatrix(const char *note, glm::mat4 MVP)
432{
Chia-I Wu7133fdc2014-12-15 23:57:34 +0800433 int i;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600434
435 printf("%s: \n", note);
436 for (i=0; i<4; i++) {
437 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
438 }
439 printf("\n");
440 fflush(stdout);
441}
442
443void dumpVec4(const char *note, glm::vec4 vector)
444{
445 printf("%s: \n", note);
446 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
447 printf("\n");
448 fflush(stdout);
449}
450
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600451struct vktriangle_vs_uniform {
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600452 // Must start with MVP
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600453 float mvp[4][4];
454 float position[3][4];
455 float color[3][4];
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600456};
457
Tony Barbour01999182015-04-09 12:58:51 -0600458void VkRenderTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600459{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700460#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600461 vkDbgRegisterMsgCallback(inst, myDbgFunc, NULL);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700462#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600463 // Create identity matrix
464 int i;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600465 struct vktriangle_vs_uniform data;
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600466
467 glm::mat4 Projection = glm::mat4(1.0f);
468 glm::mat4 View = glm::mat4(1.0f);
469 glm::mat4 Model = glm::mat4(1.0f);
470 glm::mat4 MVP = Projection * View * Model;
471 const int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600472 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600473 memcpy(&data.mvp, &MVP[0][0], matrixSize);
474
475 static const Vertex tri_data[] =
476 {
477 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
478 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
479 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
480 };
481
482 for (i=0; i<3; i++) {
483 data.position[i][0] = tri_data[i].posX;
484 data.position[i][1] = tri_data[i].posY;
485 data.position[i][2] = tri_data[i].posZ;
486 data.position[i][3] = tri_data[i].posW;
487 data.color[i][0] = tri_data[i].r;
488 data.color[i][1] = tri_data[i].g;
489 data.color[i][2] = tri_data[i].b;
490 data.color[i][3] = tri_data[i].a;
491 }
492
Tony Barbourf43b6982014-11-25 13:18:32 -0700493 ASSERT_NO_FATAL_FAILURE(InitState());
494 ASSERT_NO_FATAL_FAILURE(InitViewport());
495
Tony Barbour01999182015-04-09 12:58:51 -0600496 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barbourf43b6982014-11-25 13:18:32 -0700497
Tony Barbour01999182015-04-09 12:58:51 -0600498 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
499 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700500
Tony Barbour01999182015-04-09 12:58:51 -0600501 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800502 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -0700503 pipelineobj.AddShader(&vs);
504 pipelineobj.AddShader(&ps);
505
Tony Barbour01999182015-04-09 12:58:51 -0600506 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600507 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700508
Tony Barbour71ba3612015-01-09 16:12:35 -0700509 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis7f7b4422015-08-18 14:24:32 -0600510
511 VkCmdBufferBeginInfo cbBeginInfo;
512 memset(&cbBeginInfo, 0, sizeof(VkCmdBufferBeginInfo));
513 cbBeginInfo.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
514 cbBeginInfo.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT;
515 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barbourf43b6982014-11-25 13:18:32 -0700516
Tony Barbour1490c912015-07-28 10:17:20 -0600517 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour71ba3612015-01-09 16:12:35 -0700518#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600519 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour71ba3612015-01-09 16:12:35 -0700520 pDSDumpDot((char*)"triTest2.dot");
521#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600522
Tony Barbour71ba3612015-01-09 16:12:35 -0700523 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -0600524 Draw(0, 3, 0, 1);
Tony Barbour71ba3612015-01-09 16:12:35 -0700525
526 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600527 ASSERT_VK_SUCCESS(EndCommandBuffer());
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600528
Tony Barbour1490c912015-07-28 10:17:20 -0600529 QueueCommandBuffer();
Tony Barbour71ba3612015-01-09 16:12:35 -0700530
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600531 RecordImages(m_renderTargets);
Tony Barbour71ba3612015-01-09 16:12:35 -0700532
533 if (rotate)
Tony Barbour1490c912015-07-28 10:17:20 -0600534 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer);
Tony Barbour71ba3612015-01-09 16:12:35 -0700535
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700536#ifdef PRINT_OBJECTS
Mark Lobodzinski4e5016f2015-05-05 15:01:37 -0500537 OBJ_TRACK_GET_OBJECTS_COUNT pObjTrackGetObjectsCount = (OBJ_TRACK_GET_OBJECTS_COUNT)vkGetProcAddr(gpu(), (char*)"objTrackGetObjectsCount");
Mark Lobodzinski14305ad2015-06-23 11:35:12 -0600538 uint64_t numObjects = pObjTrackGetObjectsCount(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600539 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700540 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600541 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700542 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
Mark Lobodzinski14305ad2015-06-23 11:35:12 -0600543 pObjTrackGetObjs(m_device, numObjects, pObjNodeArray);
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700544 for (i=0; i < numObjects; i++) {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600545 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 -0700546 }
547 free(pObjNodeArray);
548#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700549
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600550}
551
Tony Barbour01999182015-04-09 12:58:51 -0600552TEST_F(VkRenderTest, VKTriangle_FragColor)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600553{
554 static const char *vertShaderText =
555 "#version 140\n"
556 "#extension GL_ARB_separate_shader_objects : enable\n"
557 "#extension GL_ARB_shading_language_420pack : enable\n"
558 "\n"
559 "layout(binding = 0) uniform buf {\n"
560 " mat4 MVP;\n"
561 " vec4 position[3];\n"
562 " vec4 color[3];\n"
563 "} ubuf;\n"
564 "\n"
565 "layout (location = 0) out vec4 outColor;\n"
566 "\n"
567 "void main() \n"
568 "{\n"
569 " outColor = ubuf.color[gl_VertexID];\n"
570 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
571 "}\n";
572
573 static const char *fragShaderText =
574 "#version 140\n"
575 "#extension GL_ARB_separate_shader_objects : enable\n"
576 "#extension GL_ARB_shading_language_420pack : enable\n"
577 "\n"
578 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600579 "layout (location = 0) out vec4 uFragColor;\n"
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600580 "\n"
581 "void main()\n"
582 "{\n"
GregFd6ebdb32015-06-03 18:40:50 -0600583 " uFragColor = inColor;\n"
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600584 "}\n";
585
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600586 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
587 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600588}
589
Tony Barbour01999182015-04-09 12:58:51 -0600590TEST_F(VkRenderTest, VKTriangle_OutputLocation)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600591{
592 static const char *vertShaderText =
593 "#version 140\n"
594 "#extension GL_ARB_separate_shader_objects : enable\n"
595 "#extension GL_ARB_shading_language_420pack : enable\n"
596 "\n"
597 "layout(binding = 0) uniform buf {\n"
598 " mat4 MVP;\n"
599 " vec4 position[3];\n"
600 " vec4 color[3];\n"
601 "} ubuf;\n"
602 "\n"
603 "layout (location = 0) out vec4 outColor;\n"
604 "\n"
605 "void main() \n"
606 "{\n"
607 " outColor = ubuf.color[gl_VertexID];\n"
608 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
609 "}\n";
610
611 static const char *fragShaderText =
612 "#version 140\n"
613 "#extension GL_ARB_separate_shader_objects : enable\n"
614 "#extension GL_ARB_shading_language_420pack : enable\n"
615 "\n"
616 "layout (location = 0) in vec4 inColor;\n"
617 "layout (location = 0) out vec4 outColor;\n"
618 "\n"
619 "void main()\n"
620 "{\n"
621 " outColor = inColor;\n"
622 "}\n";
623
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600624 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 -0600625
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600626 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600627}
Cody Northrop71727d22015-06-23 13:25:51 -0600628
Tony Barbour01999182015-04-09 12:58:51 -0600629TEST_F(VkRenderTest, SPV_VKTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700630{
Tony Barbourf43b6982014-11-25 13:18:32 -0700631 static const char *vertShaderText =
632 "#version 140\n"
633 "#extension GL_ARB_separate_shader_objects : enable\n"
634 "#extension GL_ARB_shading_language_420pack : enable\n"
635 "\n"
636 "layout(binding = 0) uniform buf {\n"
637 " mat4 MVP;\n"
638 " vec4 position[3];\n"
639 " vec4 color[3];\n"
640 "} ubuf;\n"
641 "\n"
642 "layout (location = 0) out vec4 outColor;\n"
643 "\n"
644 "void main() \n"
645 "{\n"
646 " outColor = ubuf.color[gl_VertexID];\n"
647 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
648 "}\n";
649
650 static const char *fragShaderText =
651 "#version 140\n"
652 "#extension GL_ARB_separate_shader_objects : enable\n"
653 "#extension GL_ARB_shading_language_420pack : enable\n"
654 "\n"
655 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600656 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700657 "\n"
658 "void main()\n"
659 "{\n"
GregFd6ebdb32015-06-03 18:40:50 -0600660 " outColor = inColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700661 "}\n";
662
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600663 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 -0700664
Cody Northrop1cfbd172015-06-03 16:49:20 -0600665 ScopedUseGlsl useGlsl(false);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600666 VKTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700667}
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600668
Tony Barbour01999182015-04-09 12:58:51 -0600669TEST_F(VkRenderTest, SPV_GreenTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700670{
Tony Barbourf43b6982014-11-25 13:18:32 -0700671 static const char *vertShaderText =
672 "#version 130\n"
673 "vec2 vertices[3];\n"
674 "void main() {\n"
675 " vertices[0] = vec2(-1.0, -1.0);\n"
676 " vertices[1] = vec2( 1.0, -1.0);\n"
677 " vertices[2] = vec2( 0.0, 1.0);\n"
678 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
679 "}\n";
680
681 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600682 "#version 140\n"
683 "#extension GL_ARB_separate_shader_objects : enable\n"
684 "#extension GL_ARB_shading_language_420pack : enable\n"
685 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700686 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600687 " outColor = vec4(0,1,0,1);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700688 "}\n";
689
Cody Northropacfb0492015-03-17 15:55:58 -0600690 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700691
Cody Northrop1cfbd172015-06-03 16:49:20 -0600692 ScopedUseGlsl useGlsl(false);
693
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600694 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700695}
Cody Northrop71727d22015-06-23 13:25:51 -0600696
Tony Barbour01999182015-04-09 12:58:51 -0600697TEST_F(VkRenderTest, YellowTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700698{
699 static const char *vertShaderText =
700 "#version 130\n"
701 "void main() {\n"
702 " vec2 vertices[3];"
703 " vertices[0] = vec2(-0.5, -0.5);\n"
704 " vertices[1] = vec2( 0.5, -0.5);\n"
705 " vertices[2] = vec2( 0.5, 0.5);\n"
706 " vec4 colors[3];\n"
707 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
708 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
709 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
710 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
711 "}\n";
712
713 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600714 "#version 140\n"
715 "#extension GL_ARB_separate_shader_objects : enable\n"
716 "#extension GL_ARB_shading_language_420pack : enable\n"
717 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700718 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600719 " outColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700720 "}\n";
721
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600722 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700723}
724
Tony Barbour01999182015-04-09 12:58:51 -0600725TEST_F(VkRenderTest, QuadWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600726{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600727 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600728 "#version 140\n"
729 "#extension GL_ARB_separate_shader_objects : enable\n"
730 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700731 //XYZ1( -1, -1, -1 )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600732 "layout (location = 0) in vec4 pos;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700733 //XYZ1( 0.f, 0.f, 0.f )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600734 "layout (location = 1) in vec4 inColor;\n"
735 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600736 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600737 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600738 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600739 "}\n";
740
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600741
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600742 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700743 "#version 140\n"
744 "#extension GL_ARB_separate_shader_objects : enable\n"
745 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600746 "layout (location = 0) in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700747 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600748 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700749 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600750 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600751
Tony Barbourf43b6982014-11-25 13:18:32 -0700752
753
754 ASSERT_NO_FATAL_FAILURE(InitState());
755 ASSERT_NO_FATAL_FAILURE(InitViewport());
756
Tony Barbour01999182015-04-09 12:58:51 -0600757 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000758 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700759
Tony Barbour01999182015-04-09 12:58:51 -0600760 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
761 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700762
Tony Barbour01999182015-04-09 12:58:51 -0600763 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800764 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -0700765 pipelineobj.AddShader(&vs);
766 pipelineobj.AddShader(&ps);
767
Tony Barbour01999182015-04-09 12:58:51 -0600768 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600769 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -0600770
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600771#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600772 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600773 MESH_BIND_ID, // binding ID
Tony Barbourf43b6982014-11-25 13:18:32 -0700774 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600775 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -0700776 };
777
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600778 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600779 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
780 vi_attribs[0].location = 0; // location, position
Tony Barbour8205d902015-04-16 15:59:00 -0600781 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600782 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
783 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
784 vi_attribs[1].location = 1; // location, color
Tony Barbour8205d902015-04-16 15:59:00 -0600785 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600786 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 -0700787
788 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
789 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600790 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -0700791
Tony Barboure4ed9942015-01-09 10:06:53 -0700792 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -0600793 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourf43b6982014-11-25 13:18:32 -0700794
Tony Barbour1490c912015-07-28 10:17:20 -0600795 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600796
Tony Barbour1490c912015-07-28 10:17:20 -0600797 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barboure4ed9942015-01-09 10:06:53 -0700798
799 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -0600800 Draw(0, 6, 0, 1);
Tony Barboure4ed9942015-01-09 10:06:53 -0700801
802 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600803 ASSERT_VK_SUCCESS(EndCommandBuffer());
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600804
Tony Barbour1490c912015-07-28 10:17:20 -0600805 QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -0700806
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600807 RecordImages(m_renderTargets);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600808}
809
Tony Barbour01999182015-04-09 12:58:51 -0600810TEST_F(VkRenderTest, TriangleMRT)
Chia-I Wue09d1a72014-12-05 10:32:23 +0800811{
812 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600813 "#version 140\n"
814 "#extension GL_ARB_separate_shader_objects : enable\n"
815 "#extension GL_ARB_shading_language_420pack : enable\n"
816 "layout (location = 0) in vec4 pos;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800817 "void main() {\n"
818 " gl_Position = pos;\n"
819 "}\n";
820
821 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600822 "#version 140\n"
823 "#extension GL_ARB_separate_shader_objects : enable\n"
824 "#extension GL_ARB_shading_language_420pack : enable\n"
825 "layout (location = 0) out vec4 uFragData0;\n"
826 "layout (location = 1) out vec4 uFragData1;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800827 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600828 " uFragData0 = vec4(1.0, 0.0, 0.0, 1.0);\n"
829 " uFragData1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800830 "}\n";
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600831 const float vb_data[][2] = {
Chia-I Wue09d1a72014-12-05 10:32:23 +0800832 { -1.0f, -1.0f },
833 { 1.0f, -1.0f },
834 { -1.0f, 1.0f }
835 };
836
837 ASSERT_NO_FATAL_FAILURE(InitState());
838 ASSERT_NO_FATAL_FAILURE(InitViewport());
839
Tony Barbour01999182015-04-09 12:58:51 -0600840 VkConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000841 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800842
Tony Barbour01999182015-04-09 12:58:51 -0600843 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
844 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800845
Tony Barbour01999182015-04-09 12:58:51 -0600846 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800847 pipelineobj.AddColorAttachment();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800848 pipelineobj.AddShader(&vs);
849 pipelineobj.AddShader(&ps);
850
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600851#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600852 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600853 MESH_BUF_ID, // Binding ID
854 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600855 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Chia-I Wue09d1a72014-12-05 10:32:23 +0800856 };
857
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600858 VkVertexInputAttributeDescription vi_attrib;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600859 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
860 vi_attrib.location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -0600861 vi_attrib.format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600862 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
Chia-I Wue09d1a72014-12-05 10:32:23 +0800863
864 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
865 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600866 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800867
Tony Barbour01999182015-04-09 12:58:51 -0600868 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600869 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800870
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700871 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
Chia-I Wue09d1a72014-12-05 10:32:23 +0800872
Tony Barboure307f582015-07-10 15:29:03 -0600873 VkPipelineColorBlendAttachmentState att = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600874 att.blendEnable = VK_FALSE;
Chia-I Wue09d1a72014-12-05 10:32:23 +0800875 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700876 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800877
Tony Barbour1490c912015-07-28 10:17:20 -0600878 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure4ed9942015-01-09 10:06:53 -0700879
Tony Barbour1490c912015-07-28 10:17:20 -0600880 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700881
Tony Barbour1490c912015-07-28 10:17:20 -0600882 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700883#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600884 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour5ed79702015-01-07 14:31:52 -0700885 pDSDumpDot((char*)"triTest2.dot");
886#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600887
Tony Barbour5ed79702015-01-07 14:31:52 -0700888 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -0600889 Draw(0, 3, 0, 1);
Tony Barbour5ed79702015-01-07 14:31:52 -0700890
891 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600892 ASSERT_VK_SUCCESS(EndCommandBuffer());
893 QueueCommandBuffer();
Tony Barbour5ed79702015-01-07 14:31:52 -0700894
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600895 RecordImages(m_renderTargets);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800896}
897
Tony Barbour01999182015-04-09 12:58:51 -0600898TEST_F(VkRenderTest, QuadWithIndexedVertexFetch)
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700899{
900 static const char *vertShaderText =
901 "#version 140\n"
902 "#extension GL_ARB_separate_shader_objects : enable\n"
903 "#extension GL_ARB_shading_language_420pack : enable\n"
904 "layout(location = 0) in vec4 pos;\n"
905 "layout(location = 1) in vec4 inColor;\n"
906 "layout(location = 0) out vec4 outColor;\n"
907 "void main() {\n"
908 " outColor = inColor;\n"
909 " gl_Position = pos;\n"
910 "}\n";
911
912
913 static const char *fragShaderText =
914 "#version 140\n"
915 "#extension GL_ARB_separate_shader_objects : enable\n"
916 "#extension GL_ARB_shading_language_420pack : enable\n"
917 "layout(location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600918 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700919 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600920 " outColor = color;\n"
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700921 "}\n";
922
923 const Vertex g_vbData[] =
924 {
925 // first tri
926 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
927 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
928 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
929
930 // second tri
931 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
932 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
933 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
934 };
935
936 const uint16_t g_idxData[6] = {
937 0, 1, 2,
938 3, 4, 5,
939 };
940
941 ASSERT_NO_FATAL_FAILURE(InitState());
942 ASSERT_NO_FATAL_FAILURE(InitViewport());
943
Tony Barbour01999182015-04-09 12:58:51 -0600944 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000945 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700946
Tony Barbour01999182015-04-09 12:58:51 -0600947 VkIndexBufferObj indexBuffer(m_device);
Tony Barbour8205d902015-04-16 15:59:00 -0600948 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), VK_INDEX_TYPE_UINT16, g_idxData);
Mark Lobodzinskid30f82a2015-02-16 14:24:23 -0600949 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700950
Tony Barbour01999182015-04-09 12:58:51 -0600951 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
952 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700953
Tony Barbour01999182015-04-09 12:58:51 -0600954 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800955 pipelineobj.AddColorAttachment();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700956 pipelineobj.AddShader(&vs);
957 pipelineobj.AddShader(&ps);
958
Tony Barbour01999182015-04-09 12:58:51 -0600959 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600960 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
961 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, indexBuffer);
Tony Barbour83a83802015-04-02 15:43:15 -0600962
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700963
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600964#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600965 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600966 MESH_BIND_ID, // binding ID
967 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600968 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700969 };
970
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600971 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600972 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
973 vi_attribs[0].location = 0; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600974 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600975 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
976 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
977 vi_attribs[1].location = 1; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600978 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600979 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700980
981 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
982 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700983
984 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -0600985 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure4ed9942015-01-09 10:06:53 -0700986
Tony Barbour1490c912015-07-28 10:17:20 -0600987 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700988
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700989#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600990 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700991 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700992#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700993
Tony Barbour1490c912015-07-28 10:17:20 -0600994 BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
995 BindIndexBuffer(&indexBuffer, 0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700996
997 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -0600998 DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700999
1000 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001001 ASSERT_VK_SUCCESS(EndCommandBuffer());
1002 QueueCommandBuffer();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001003
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001004 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001005}
1006
Tony Barbour01999182015-04-09 12:58:51 -06001007TEST_F(VkRenderTest, GreyandRedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -07001008{
1009 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -07001010
GregF6bef1212014-12-02 15:41:44 -07001011 static const char *vertShaderText =
1012 "#version 140\n"
1013 "#extension GL_ARB_separate_shader_objects : enable\n"
1014 "#extension GL_ARB_shading_language_420pack : enable\n"
1015 "layout (location = 0) in vec4 pos;\n"
1016 "layout (location = 0) out vec4 outColor;\n"
1017 "layout (location = 1) out vec4 outColor2;\n"
1018 "void main() {\n"
1019 " gl_Position = pos;\n"
1020 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1021 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1022 "}\n";
1023
1024 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001025 "#version 330\n"
1026 "#extension GL_ARB_separate_shader_objects : enable\n"
1027 "#extension GL_ARB_shading_language_420pack : enable\n"
1028 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1029 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1030 "layout (location = 0) in vec4 color;\n"
1031 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001032 "layout (location = 0) out vec4 outColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001033 "void main() {\n"
1034 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1035 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001036 " outColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001037 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1038 " : color2;\n"
1039 "}\n";
1040
1041 ASSERT_NO_FATAL_FAILURE(InitState());
1042 ASSERT_NO_FATAL_FAILURE(InitViewport());
1043
Tony Barbour01999182015-04-09 12:58:51 -06001044 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001045 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001046
Tony Barbour01999182015-04-09 12:58:51 -06001047 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1048 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001049
Tony Barbour01999182015-04-09 12:58:51 -06001050 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001051 pipelineobj.AddColorAttachment();
GregF6bef1212014-12-02 15:41:44 -07001052 pipelineobj.AddShader(&vs);
1053 pipelineobj.AddShader(&ps);
1054
Tony Barbour01999182015-04-09 12:58:51 -06001055 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001056 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001057
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001058#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001059 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001060 MESH_BIND_ID, // binding ID
1061 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001062 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001063 };
1064
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001065 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001066 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1067 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001068 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001069 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001070
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001071 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001072 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001073 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001074
Tony Barbourdd4c9642015-01-09 12:55:14 -07001075 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001076
Tony Barbour1490c912015-07-28 10:17:20 -06001077 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001078
Tony Barbour1490c912015-07-28 10:17:20 -06001079 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001080
Tony Barbour1490c912015-07-28 10:17:20 -06001081 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001082#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001083 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001084 pDSDumpDot((char*)"triTest2.dot");
1085#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001086
Tony Barbourdd4c9642015-01-09 12:55:14 -07001087 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06001088 Draw(0, 6, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001089
1090 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001091 EndCommandBuffer();
1092 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001093
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001094 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001095}
1096
Tony Barbour01999182015-04-09 12:58:51 -06001097TEST_F(VkRenderTest, RedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -07001098{
1099 // This tests that we correctly handle unread fragment inputs
1100
1101 static const char *vertShaderText =
1102 "#version 140\n"
1103 "#extension GL_ARB_separate_shader_objects : enable\n"
1104 "#extension GL_ARB_shading_language_420pack : enable\n"
1105 "layout (location = 0) in vec4 pos;\n"
1106 "layout (location = 0) out vec4 outColor;\n"
1107 "layout (location = 1) out vec4 outColor2;\n"
1108 "void main() {\n"
1109 " gl_Position = pos;\n"
1110 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1111 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1112 "}\n";
1113
1114 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001115 "#version 330\n"
1116 "#extension GL_ARB_separate_shader_objects : enable\n"
1117 "#extension GL_ARB_shading_language_420pack : enable\n"
1118 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1119 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1120 "layout (location = 0) in vec4 color;\n"
1121 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001122 "layout (location = 0) out vec4 outColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001123 "void main() {\n"
1124 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1125 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001126 " outColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001127 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1128 " : color2;\n"
1129 "}\n";
1130
1131 ASSERT_NO_FATAL_FAILURE(InitState());
1132 ASSERT_NO_FATAL_FAILURE(InitViewport());
1133
Tony Barbour01999182015-04-09 12:58:51 -06001134 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001135 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001136
Tony Barbour01999182015-04-09 12:58:51 -06001137 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1138 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001139
Tony Barbour01999182015-04-09 12:58:51 -06001140 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001141 pipelineobj.AddColorAttachment();
GregF6bef1212014-12-02 15:41:44 -07001142 pipelineobj.AddShader(&vs);
1143 pipelineobj.AddShader(&ps);
1144
Tony Barbour01999182015-04-09 12:58:51 -06001145 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001146 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001147
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001148#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001149 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001150 MESH_BIND_ID, // binding ID
1151 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001152 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001153 };
1154
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001155 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001156 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1157 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001158 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001159 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001160
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001161 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001162 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001163 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001164
Tony Barbourdd4c9642015-01-09 12:55:14 -07001165 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06001166 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001167
Tony Barbour1490c912015-07-28 10:17:20 -06001168 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001169
Tony Barbour1490c912015-07-28 10:17:20 -06001170 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001171#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001172 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001173 pDSDumpDot((char*)"triTest2.dot");
1174#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001175 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001176 Draw(0, 6, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001177
1178 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001179 EndCommandBuffer();
1180 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001181
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001182 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001183}
1184
Tony Barbour01999182015-04-09 12:58:51 -06001185TEST_F(VkRenderTest, GreyCirclesonBlueFade)
GregF6bef1212014-12-02 15:41:44 -07001186{
1187 // This tests reading gl_ClipDistance from FS
1188
1189 static const char *vertShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001190 //"#version 140\n"
GregF6bef1212014-12-02 15:41:44 -07001191 "#version 330\n"
1192 "#extension GL_ARB_separate_shader_objects : enable\n"
1193 "#extension GL_ARB_shading_language_420pack : enable\n"
1194 "out gl_PerVertex {\n"
1195 " vec4 gl_Position;\n"
1196 " float gl_ClipDistance[1];\n"
1197 "};\n"
1198 "layout (location = 0) in vec4 pos;\n"
1199 "layout (location = 0) out vec4 outColor;\n"
1200 "layout (location = 1) out vec4 outColor2;\n"
1201 "void main() {\n"
1202 " gl_Position = pos;\n"
1203 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1204 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1205 " float dists[3];\n"
1206 " dists[0] = 0.0;\n"
1207 " dists[1] = 1.0;\n"
1208 " dists[2] = 1.0;\n"
1209 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1210 "}\n";
1211
1212
1213 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001214 "#version 140\n"
1215 //"#version 330\n"
GregF6bef1212014-12-02 15:41:44 -07001216 "#extension GL_ARB_separate_shader_objects : enable\n"
1217 "#extension GL_ARB_shading_language_420pack : enable\n"
1218 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1219 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1220 "layout (location = 0) in vec4 color;\n"
1221 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001222 "layout (location = 0) out vec4 uFragColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001223 "void main() {\n"
1224 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1225 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001226 " uFragColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001227 " ? color * gl_ClipDistance[0]\n"
1228 " : color2;\n"
1229 "}\n";
1230
1231 ASSERT_NO_FATAL_FAILURE(InitState());
1232 ASSERT_NO_FATAL_FAILURE(InitViewport());
1233
Tony Barbour01999182015-04-09 12:58:51 -06001234 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001235 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001236
Tony Barbour01999182015-04-09 12:58:51 -06001237 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1238 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001239
Tony Barbour01999182015-04-09 12:58:51 -06001240 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001241 pipelineobj.AddColorAttachment();
GregF6bef1212014-12-02 15:41:44 -07001242 pipelineobj.AddShader(&vs);
1243 pipelineobj.AddShader(&ps);
1244
Tony Barbour01999182015-04-09 12:58:51 -06001245 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001246 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001247
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001248#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001249 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001250 MESH_BIND_ID, // binding ID
1251 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001252 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001253 };
1254
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001255 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001256 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1257 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001258 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001259 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001260
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001261 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001262 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001263 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001264
Tony Barbourdd4c9642015-01-09 12:55:14 -07001265 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
GregF6bef1212014-12-02 15:41:44 -07001266
Tony Barbour1490c912015-07-28 10:17:20 -06001267 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001268
Tony Barbour1490c912015-07-28 10:17:20 -06001269 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001270
Tony Barbour1490c912015-07-28 10:17:20 -06001271 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001272#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001273 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001274 pDSDumpDot((char*)"triTest2.dot");
1275#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001276
1277 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001278 Draw(0, 6, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001279
1280 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001281 EndCommandBuffer();
1282 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001283
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001284 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001285}
Tony Barbourf43b6982014-11-25 13:18:32 -07001286
Tony Barbour01999182015-04-09 12:58:51 -06001287TEST_F(VkRenderTest, GreyCirclesonBlueDiscard)
GregF7a23c792014-12-02 17:19:34 -07001288{
1289 static const char *vertShaderText =
1290 "#version 140\n"
1291 "#extension GL_ARB_separate_shader_objects : enable\n"
1292 "#extension GL_ARB_shading_language_420pack : enable\n"
1293 "layout (location = 0) in vec4 pos;\n"
1294 "layout (location = 0) out vec4 outColor;\n"
1295 "layout (location = 1) out vec4 outColor2;\n"
1296 "void main() {\n"
1297 " gl_Position = pos;\n"
1298 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1299 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1300 "}\n";
1301
1302
1303 static const char *fragShaderText =
GregF7a23c792014-12-02 17:19:34 -07001304 "#version 330\n"
1305 "#extension GL_ARB_separate_shader_objects : enable\n"
1306 "#extension GL_ARB_shading_language_420pack : enable\n"
1307 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1308 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1309 "layout (location = 0) in vec4 color;\n"
1310 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001311 "layout (location = 0) out vec4 outColor;\n"
GregF7a23c792014-12-02 17:19:34 -07001312 "void main() {\n"
1313 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1314 " float dist_squared = dot(pos, pos);\n"
1315 " if (dist_squared < 100.0)\n"
1316 " discard;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001317 " outColor = (dist_squared < 400.0)\n"
GregF7a23c792014-12-02 17:19:34 -07001318 " ? color\n"
1319 " : color2;\n"
1320 "}\n";
1321
1322 ASSERT_NO_FATAL_FAILURE(InitState());
1323 ASSERT_NO_FATAL_FAILURE(InitViewport());
1324
Tony Barbour01999182015-04-09 12:58:51 -06001325 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001326 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001327
Tony Barbour01999182015-04-09 12:58:51 -06001328 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1329 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF7a23c792014-12-02 17:19:34 -07001330
Tony Barbour01999182015-04-09 12:58:51 -06001331 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001332 pipelineobj.AddColorAttachment();
GregF7a23c792014-12-02 17:19:34 -07001333 pipelineobj.AddShader(&vs);
1334 pipelineobj.AddShader(&ps);
1335
Tony Barbour01999182015-04-09 12:58:51 -06001336 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001337 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001338
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001339#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001340 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001341 MESH_BIND_ID, // binding ID
1342 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001343 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF7a23c792014-12-02 17:19:34 -07001344 };
1345
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001346 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001347 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1348 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001349 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001350 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF7a23c792014-12-02 17:19:34 -07001351
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001352 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF7a23c792014-12-02 17:19:34 -07001353 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001354 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF7a23c792014-12-02 17:19:34 -07001355
Tony Barbourdd4c9642015-01-09 12:55:14 -07001356 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001357
Tony Barbour1490c912015-07-28 10:17:20 -06001358 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001359
Tony Barbour1490c912015-07-28 10:17:20 -06001360 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001361
Tony Barbour1490c912015-07-28 10:17:20 -06001362 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001363#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001364 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001365 pDSDumpDot((char*)"triTest2.dot");
1366#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001367
1368 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001369 Draw(0, 6, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001370
1371 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001372 EndCommandBuffer();
1373 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001374
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001375 RecordImages(m_renderTargets);
GregF7a23c792014-12-02 17:19:34 -07001376}
1377
1378
Tony Barbour01999182015-04-09 12:58:51 -06001379TEST_F(VkRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001380{
1381 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001382 "#version 140\n"
1383 "#extension GL_ARB_separate_shader_objects : enable\n"
1384 "#extension GL_ARB_shading_language_420pack : enable\n"
1385 "\n"
1386 "layout(binding = 0) uniform buf {\n"
1387 " mat4 MVP;\n"
1388 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001389 "void main() {\n"
1390 " vec2 vertices[3];"
1391 " vertices[0] = vec2(-0.5, -0.5);\n"
1392 " vertices[1] = vec2( 0.5, -0.5);\n"
1393 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001394 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001395 "}\n";
1396
1397 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001398 "#version 140\n"
1399 "#extension GL_ARB_separate_shader_objects : enable\n"
1400 "#extension GL_ARB_shading_language_420pack : enable\n"
1401 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001402 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001403 " outColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001404 "}\n";
1405
Tony Barbourf43b6982014-11-25 13:18:32 -07001406 ASSERT_NO_FATAL_FAILURE(InitState());
1407 ASSERT_NO_FATAL_FAILURE(InitViewport());
1408
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001409 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001410 glm::mat4 Projection = glm::mat4(1.0f);
1411 glm::mat4 View = glm::mat4(1.0f);
1412 glm::mat4 Model = glm::mat4(1.0f);
1413 glm::mat4 MVP = Projection * View * Model;
1414 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1415
Tony Barbour01999182015-04-09 12:58:51 -06001416 VkConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1417 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1418 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001419
Tony Barbour01999182015-04-09 12:58:51 -06001420 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001421 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001422 pipelineobj.AddShader(&vs);
1423 pipelineobj.AddShader(&ps);
1424
1425 // Create descriptor set and attach the constant buffer to it
Tony Barbour01999182015-04-09 12:58:51 -06001426 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001427 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001428
Tony Barbourdd4c9642015-01-09 12:55:14 -07001429 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis7f7b4422015-08-18 14:24:32 -06001430
1431 VkCmdBufferBeginInfo cbBeginInfo;
1432 memset(&cbBeginInfo, 0, sizeof(VkCmdBufferBeginInfo));
1433 cbBeginInfo.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1434 cbBeginInfo.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT;
1435 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barbourf43b6982014-11-25 13:18:32 -07001436
Tony Barbour1490c912015-07-28 10:17:20 -06001437 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001438
Tony Barbourdd4c9642015-01-09 12:55:14 -07001439#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001440 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001441 pDSDumpDot((char*)"triTest2.dot");
1442#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001443
1444 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001445 Draw(0, 6, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001446
1447 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001448 EndCommandBuffer();
1449 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001450
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001451 RecordImages(m_renderTargets);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001452
Tony Barbour1490c912015-07-28 10:17:20 -06001453 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001454}
1455
Tony Barbour01999182015-04-09 12:58:51 -06001456TEST_F(VkRenderTest, MixTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07001457{
1458 // This tests location applied to varyings. Notice that we have switched foo
1459 // and bar in the FS. The triangle should be blended with red, green and blue
1460 // corners.
1461 static const char *vertShaderText =
1462 "#version 140\n"
1463 "#extension GL_ARB_separate_shader_objects : enable\n"
1464 "#extension GL_ARB_shading_language_420pack : enable\n"
1465 "layout (location=0) out vec4 bar;\n"
1466 "layout (location=1) out vec4 foo;\n"
1467 "layout (location=2) out float scale;\n"
1468 "vec2 vertices[3];\n"
1469 "void main() {\n"
1470 " vertices[0] = vec2(-1.0, -1.0);\n"
1471 " vertices[1] = vec2( 1.0, -1.0);\n"
1472 " vertices[2] = vec2( 0.0, 1.0);\n"
1473 "vec4 colors[3];\n"
1474 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1475 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1476 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1477 " foo = colors[gl_VertexID % 3];\n"
1478 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1479 " scale = 1.0;\n"
1480 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1481 "}\n";
1482
1483 static const char *fragShaderText =
1484 "#version 140\n"
1485 "#extension GL_ARB_separate_shader_objects : enable\n"
1486 "#extension GL_ARB_shading_language_420pack : enable\n"
1487 "layout (location = 1) in vec4 bar;\n"
1488 "layout (location = 0) in vec4 foo;\n"
1489 "layout (location = 2) in float scale;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001490 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001491 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001492 " outColor = bar * scale + foo * (1.0-scale);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001493 "}\n";
1494
1495 ASSERT_NO_FATAL_FAILURE(InitState());
1496 ASSERT_NO_FATAL_FAILURE(InitViewport());
1497
Tony Barbour01999182015-04-09 12:58:51 -06001498 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1499 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001500
Tony Barbour01999182015-04-09 12:58:51 -06001501 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001502 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001503 pipelineobj.AddShader(&vs);
1504 pipelineobj.AddShader(&ps);
1505
Tony Barbour01999182015-04-09 12:58:51 -06001506 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06001507 descriptorSet.AppendDummy();
Tony Barbourf43b6982014-11-25 13:18:32 -07001508
Tony Barbourdd4c9642015-01-09 12:55:14 -07001509 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001510
Tony Barbour1490c912015-07-28 10:17:20 -06001511 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001512
Tony Barbour1490c912015-07-28 10:17:20 -06001513 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001514
1515#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001516 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001517 pDSDumpDot((char*)"triTest2.dot");
1518#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001519
Tony Barbourdd4c9642015-01-09 12:55:14 -07001520 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06001521 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001522
1523 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001524 EndCommandBuffer();
1525 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001526
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001527 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001528}
1529
Tony Barbour01999182015-04-09 12:58:51 -06001530TEST_F(VkRenderTest, QuadVertFetchAndVertID)
Tony Barbourf43b6982014-11-25 13:18:32 -07001531{
1532 // This tests that attributes work in the presence of gl_VertexID
1533
1534 static const char *vertShaderText =
1535 "#version 140\n"
1536 "#extension GL_ARB_separate_shader_objects : enable\n"
1537 "#extension GL_ARB_shading_language_420pack : enable\n"
1538 //XYZ1( -1, -1, -1 )
1539 "layout (location = 0) in vec4 pos;\n"
1540 //XYZ1( 0.f, 0.f, 0.f )
1541 "layout (location = 1) in vec4 inColor;\n"
1542 "layout (location = 0) out vec4 outColor;\n"
1543 "void main() {\n"
1544 " outColor = inColor;\n"
1545 " vec4 vertices[3];"
1546 " vertices[gl_VertexID % 3] = pos;\n"
1547 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1548 "}\n";
1549
1550
1551 static const char *fragShaderText =
1552 "#version 140\n"
1553 "#extension GL_ARB_separate_shader_objects : enable\n"
1554 "#extension GL_ARB_shading_language_420pack : enable\n"
1555 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001556 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001557 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001558 " outColor = color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001559 "}\n";
1560
1561 ASSERT_NO_FATAL_FAILURE(InitState());
1562 ASSERT_NO_FATAL_FAILURE(InitViewport());
1563
Tony Barbour01999182015-04-09 12:58:51 -06001564 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001565 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001566
Tony Barbour01999182015-04-09 12:58:51 -06001567 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1568 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001569
Tony Barbour01999182015-04-09 12:58:51 -06001570 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001571 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001572 pipelineobj.AddShader(&vs);
1573 pipelineobj.AddShader(&ps);
1574
Tony Barbour01999182015-04-09 12:58:51 -06001575 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001576 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001577
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001578#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001579 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001580 MESH_BUF_ID, // Binding ID
1581 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001582 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001583 };
1584
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001585 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001586 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1587 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001588 vi_attribs[0].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001589 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1590 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1591 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001592 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001593 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001594
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001595 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001596 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001597 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001598
Tony Barbourdd4c9642015-01-09 12:55:14 -07001599 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001600
Tony Barbour1490c912015-07-28 10:17:20 -06001601 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001602
Tony Barbour1490c912015-07-28 10:17:20 -06001603 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001604
Tony Barbour1490c912015-07-28 10:17:20 -06001605 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001606#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001607 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001608 pDSDumpDot((char*)"triTest2.dot");
1609#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001610
1611 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001612 Draw(0, 6, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001613
1614 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001615 EndCommandBuffer();
1616 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001617
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001618 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001619}
1620
Tony Barbour01999182015-04-09 12:58:51 -06001621TEST_F(VkRenderTest, QuadSparseVertFetch)
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001622{
1623 // This tests that attributes work in the presence of gl_VertexID
1624
1625 static const char *vertShaderText =
1626 "#version 140\n"
1627 "#extension GL_ARB_separate_shader_objects : enable\n"
1628 "#extension GL_ARB_shading_language_420pack : enable\n"
1629 //XYZ1( -1, -1, -1 )
1630 "layout (location = 1) in vec4 pos;\n"
1631 "layout (location = 4) in vec4 inColor;\n"
1632 //XYZ1( 0.f, 0.f, 0.f )
1633 "layout (location = 0) out vec4 outColor;\n"
1634 "void main() {\n"
1635 " outColor = inColor;\n"
1636 " gl_Position = pos;\n"
1637 "}\n";
1638
1639
1640 static const char *fragShaderText =
1641 "#version 140\n"
1642 "#extension GL_ARB_separate_shader_objects : enable\n"
1643 "#extension GL_ARB_shading_language_420pack : enable\n"
1644 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001645 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001646 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001647 " outColor = color;\n"
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001648 "}\n";
1649
1650 ASSERT_NO_FATAL_FAILURE(InitState());
1651 ASSERT_NO_FATAL_FAILURE(InitViewport());
1652
1653 struct VDATA
1654 {
1655 float t1, t2, t3, t4; // filler data
1656 float posX, posY, posZ, posW; // Position data
1657 float r, g, b, a; // Color
1658 };
1659 const struct VDATA vData[] =
1660 {
1661 { XYZ1(0, 0, 0), XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
1662 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.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( 0.f, 1.f, 0.f ) },
1665 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1666 { XYZ1(0, 0, 0), XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
1667 };
1668
Tony Barbour01999182015-04-09 12:58:51 -06001669 VkConstantBufferObj meshBuffer(m_device,sizeof(vData)/sizeof(vData[0]),sizeof(vData[0]), vData);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001670 meshBuffer.BufferMemoryBarrier();
1671
Tony Barbour01999182015-04-09 12:58:51 -06001672 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1673 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001674
Tony Barbour01999182015-04-09 12:58:51 -06001675 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001676 pipelineobj.AddColorAttachment();
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001677 pipelineobj.AddShader(&vs);
1678 pipelineobj.AddShader(&ps);
1679
Tony Barbour01999182015-04-09 12:58:51 -06001680 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001681 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001682
1683#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001684 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001685 MESH_BUF_ID, // Binding ID
1686 sizeof(vData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001687 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001688 };
1689
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001690 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001691 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1692 vi_attribs[0].location = 4;
Tony Barbour8205d902015-04-16 15:59:00 -06001693 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001694 vi_attribs[0].offsetInBytes = sizeof(float) * 4 * 2; // Offset of first element in bytes from base of vertex
1695 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1696 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001697 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001698 vi_attribs[1].offsetInBytes = sizeof(float) * 4 * 1; // Offset of first element in bytes from base of vertex
1699
1700 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
1701 pipelineobj.AddVertexInputBindings(&vi_binding, 1);
1702 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
1703
1704 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001705
Tony Barbour1490c912015-07-28 10:17:20 -06001706 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001707
Tony Barbour1490c912015-07-28 10:17:20 -06001708 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001709
Tony Barbour1490c912015-07-28 10:17:20 -06001710 BindVertexBuffer(&meshBuffer, 0, MESH_BUF_ID);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001711#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001712 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001713 pDSDumpDot((char*)"triTest2.dot");
1714#endif
1715
1716 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001717 Draw(0, 6, 0, 1);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001718
1719 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001720 EndCommandBuffer();
1721 QueueCommandBuffer();
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001722
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001723 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001724}
1725
Tony Barbour01999182015-04-09 12:58:51 -06001726TEST_F(VkRenderTest, TriVertFetchDeadAttr)
Tony Barbourf43b6982014-11-25 13:18:32 -07001727{
1728 // This tests that attributes work in the presence of gl_VertexID
1729 // and a dead attribute in position 0. Draws a triangle with yellow,
1730 // red and green corners, starting at top and going clockwise.
1731
1732 static const char *vertShaderText =
1733 "#version 140\n"
1734 "#extension GL_ARB_separate_shader_objects : enable\n"
1735 "#extension GL_ARB_shading_language_420pack : enable\n"
1736 //XYZ1( -1, -1, -1 )
1737 "layout (location = 0) in vec4 pos;\n"
1738 //XYZ1( 0.f, 0.f, 0.f )
1739 "layout (location = 1) in vec4 inColor;\n"
1740 "layout (location = 0) out vec4 outColor;\n"
1741 "void main() {\n"
1742 " outColor = inColor;\n"
1743 " vec2 vertices[3];"
1744 " vertices[0] = vec2(-1.0, -1.0);\n"
1745 " vertices[1] = vec2( 1.0, -1.0);\n"
1746 " vertices[2] = vec2( 0.0, 1.0);\n"
1747 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1748 "}\n";
1749
1750
1751 static const char *fragShaderText =
1752 "#version 140\n"
1753 "#extension GL_ARB_separate_shader_objects : enable\n"
1754 "#extension GL_ARB_shading_language_420pack : enable\n"
1755 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001756 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001757 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001758 " outColor = color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001759 "}\n";
1760
1761 ASSERT_NO_FATAL_FAILURE(InitState());
1762 ASSERT_NO_FATAL_FAILURE(InitViewport());
1763
Tony Barbour01999182015-04-09 12:58:51 -06001764 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001765 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001766
Tony Barbour01999182015-04-09 12:58:51 -06001767 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1768 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001769
Tony Barbour01999182015-04-09 12:58:51 -06001770 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001771 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001772 pipelineobj.AddShader(&vs);
1773 pipelineobj.AddShader(&ps);
1774
Tony Barbour01999182015-04-09 12:58:51 -06001775 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001776 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001777
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001778#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001779 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001780 MESH_BUF_ID, // Binding ID
1781 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001782 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001783 };
1784
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001785 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001786 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1787 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001788 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001789 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1790 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1791 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001792 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001793 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001794
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001795 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001796 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001797 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001798
Tony Barbourdd4c9642015-01-09 12:55:14 -07001799 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourf43b6982014-11-25 13:18:32 -07001800
Tony Barbour1490c912015-07-28 10:17:20 -06001801 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001802
Tony Barbour1490c912015-07-28 10:17:20 -06001803 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001804
Tony Barbour1490c912015-07-28 10:17:20 -06001805 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001806#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001807 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001808 pDSDumpDot((char*)"triTest2.dot");
1809#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001810
1811 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001812 Draw(0, 6, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001813
1814 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001815 EndCommandBuffer();
1816 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001817
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001818 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001819}
1820
Tony Barbour01999182015-04-09 12:58:51 -06001821TEST_F(VkRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001822{
1823 static const char *vertShaderText =
1824 "#version 140\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001825 "#extension GL_ARB_separate_shader_objects : enable\n"
1826 "#extension GL_ARB_shading_language_420pack : enable\n"
GregFd6ebdb32015-06-03 18:40:50 -06001827 "layout (std140, binding = 0) uniform bufferVals {\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001828 " mat4 mvp;\n"
1829 "} myBufferVals;\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001830 "layout (location = 0) in vec4 pos;\n"
1831 "layout (location = 1) in vec4 inColor;\n"
Cody Northrop74a2d2c2015-06-16 17:32:04 -06001832 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001833 "void main() {\n"
1834 " outColor = inColor;\n"
1835 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001836 " gl_Position.y = -gl_Position.y;\n"
1837 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001838 "}\n";
1839
1840 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001841 "#version 140\n"
1842 "#extension GL_ARB_separate_shader_objects : enable\n"
1843 "#extension GL_ARB_shading_language_420pack : enable\n"
1844 "layout (location = 0) in vec4 color;\n"
1845 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001846 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001847 " outColor = color;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001848 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001849 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001850
Tony Barbourf43b6982014-11-25 13:18:32 -07001851 glm::mat4 View = glm::lookAt(
1852 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1853 glm::vec3(0,0,0), // and looks at the origin
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001854 glm::vec3(0,-1,0) // Head is up (set to 0,-1,0 to look upside-down)
Tony Barbourf43b6982014-11-25 13:18:32 -07001855 );
1856
1857 glm::mat4 Model = glm::mat4(1.0f);
1858
1859 glm::mat4 MVP = Projection * View * Model;
1860
1861 ASSERT_NO_FATAL_FAILURE(InitState());
1862 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wu9e81ebb2015-07-09 10:16:34 +08001863 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Chia-I Wuc278df82015-07-07 11:50:03 +08001864 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height, m_depth_stencil_fmt);
Tony Barbourf43b6982014-11-25 13:18:32 -07001865
Tony Barbour01999182015-04-09 12:58:51 -06001866 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 -07001867 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1868
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001869 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07001870
Tony Barbour01999182015-04-09 12:58:51 -06001871 VkConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1872 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1873 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001874
Tony Barbour01999182015-04-09 12:58:51 -06001875 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001876 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001877 pipelineobj.AddShader(&vs);
1878 pipelineobj.AddShader(&ps);
1879
Tony Barboure307f582015-07-10 15:29:03 -06001880 VkPipelineDepthStencilStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001881 ds_state.depthTestEnable = VK_TRUE;
1882 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06001883 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001884 ds_state.depthBoundsEnable = VK_FALSE;
1885 ds_state.stencilTestEnable = VK_FALSE;
1886 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
1887 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
1888 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06001889 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001890 ds_state.front = ds_state.back;
1891 pipelineobj.SetDepthStencil(&ds_state);
1892
Tony Barbour01999182015-04-09 12:58:51 -06001893 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001894 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001895
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001896#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001897 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001898 MESH_BUF_ID, // Binding ID
1899 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001900 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001901 };
Tony Barbourf43b6982014-11-25 13:18:32 -07001902
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001903 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001904 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1905 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001906 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001907 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1908 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1909 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001910 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001911 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001912
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001913 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001914 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001915 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001916
Tony Barbour17c6ab12015-03-27 17:03:18 -06001917 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour17c6ab12015-03-27 17:03:18 -06001918
Tony Barbour1490c912015-07-28 10:17:20 -06001919 ASSERT_VK_SUCCESS(BeginCommandBuffer());
1920 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001921
Tony Barbour1490c912015-07-28 10:17:20 -06001922 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barboure4ed9942015-01-09 10:06:53 -07001923#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001924 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barboure4ed9942015-01-09 10:06:53 -07001925 pDSDumpDot((char*)"triTest2.dot");
1926#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001927
1928 // render triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001929 Draw(0, 36, 0, 1);
Tony Barboure4ed9942015-01-09 10:06:53 -07001930
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001931
Tony Barboure4ed9942015-01-09 10:06:53 -07001932 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001933 EndCommandBuffer();
1934 QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -07001935
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001936 RecordImages(m_renderTargets);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001937}
1938
Tony Barbour01999182015-04-09 12:58:51 -06001939TEST_F(VkRenderTest, VSTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07001940{
1941 // The expected result from this test is a green and red triangle;
1942 // one red vertex on the left, two green vertices on the right.
1943 static const char *vertShaderText =
Cody Northrop74a2d2c2015-06-16 17:32:04 -06001944 "#version 140\n"
1945 "#extension GL_ARB_separate_shader_objects : enable\n"
1946 "#extension GL_ARB_shading_language_420pack : enable\n"
1947 "layout (location = 0) out vec4 texColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001948 "uniform sampler2D surface;\n"
1949 "void main() {\n"
1950 " vec2 vertices[3];"
1951 " vertices[0] = vec2(-0.5, -0.5);\n"
1952 " vertices[1] = vec2( 0.5, -0.5);\n"
1953 " vertices[2] = vec2( 0.5, 0.5);\n"
1954 " vec2 positions[3];"
1955 " positions[0] = vec2( 0.0, 0.0);\n"
1956 " positions[1] = vec2( 0.25, 0.1);\n"
1957 " positions[2] = vec2( 0.1, 0.25);\n"
1958 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1959 " texColor = textureLod(surface, samplePos, 0.0);\n"
1960 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1961 "}\n";
1962
1963 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001964 "#version 140\n"
1965 "#extension GL_ARB_separate_shader_objects : enable\n"
1966 "#extension GL_ARB_shading_language_420pack : enable\n"
1967 "layout (location = 0) in vec4 texColor;\n"
1968 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001969 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001970 " outColor = texColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001971 "}\n";
1972
1973 ASSERT_NO_FATAL_FAILURE(InitState());
1974 ASSERT_NO_FATAL_FAILURE(InitViewport());
1975
Tony Barbour01999182015-04-09 12:58:51 -06001976 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1977 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
1978 VkSamplerObj sampler(m_device);
1979 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001980
Tony Barbour01999182015-04-09 12:58:51 -06001981 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001982 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001983 pipelineobj.AddShader(&vs);
1984 pipelineobj.AddShader(&ps);
1985
Tony Barbour01999182015-04-09 12:58:51 -06001986 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001987 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001988
Tony Barbourdd4c9642015-01-09 12:55:14 -07001989 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06001990 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourf43b6982014-11-25 13:18:32 -07001991
Tony Barbour1490c912015-07-28 10:17:20 -06001992 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001993
1994#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001995 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001996 pDSDumpDot((char*)"triTest2.dot");
1997#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001998
Tony Barbourdd4c9642015-01-09 12:55:14 -07001999 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002000 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002001
2002 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002003 EndCommandBuffer();
2004 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002005
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002006 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002007}
GregFd6ebdb32015-06-03 18:40:50 -06002008
2009
2010
Tony Barbour01999182015-04-09 12:58:51 -06002011TEST_F(VkRenderTest, TexturedTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002012{
2013 // The expected result from this test is a red and green checkered triangle
2014 static const char *vertShaderText =
2015 "#version 140\n"
2016 "#extension GL_ARB_separate_shader_objects : enable\n"
2017 "#extension GL_ARB_shading_language_420pack : enable\n"
2018 "layout (location = 0) out vec2 samplePos;\n"
2019 "void main() {\n"
2020 " vec2 vertices[3];"
2021 " vertices[0] = vec2(-0.5, -0.5);\n"
2022 " vertices[1] = vec2( 0.5, -0.5);\n"
2023 " vertices[2] = vec2( 0.5, 0.5);\n"
2024 " vec2 positions[3];"
2025 " positions[0] = vec2( 0.0, 0.0);\n"
2026 " positions[1] = vec2( 1.0, 0.0);\n"
2027 " positions[2] = vec2( 1.0, 1.0);\n"
2028 " samplePos = positions[gl_VertexID % 3];\n"
2029 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2030 "}\n";
2031
2032 static const char *fragShaderText =
2033 "#version 140\n"
2034 "#extension GL_ARB_separate_shader_objects : enable\n"
2035 "#extension GL_ARB_shading_language_420pack : enable\n"
2036 "layout (location = 0) in vec2 samplePos;\n"
2037 "layout (binding = 0) uniform sampler2D surface;\n"
2038 "layout (location=0) out vec4 outColor;\n"
2039 "void main() {\n"
2040 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2041 " outColor = texColor;\n"
2042 "}\n";
2043
2044 ASSERT_NO_FATAL_FAILURE(InitState());
2045 ASSERT_NO_FATAL_FAILURE(InitViewport());
2046
Tony Barbour01999182015-04-09 12:58:51 -06002047 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2048 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2049 VkSamplerObj sampler(m_device);
2050 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002051
Tony Barbour01999182015-04-09 12:58:51 -06002052 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002053 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002054 pipelineobj.AddShader(&vs);
2055 pipelineobj.AddShader(&ps);
2056
Tony Barbour01999182015-04-09 12:58:51 -06002057 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002058 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002059
Tony Barbourdd4c9642015-01-09 12:55:14 -07002060 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002061 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002062
Tony Barbour1490c912015-07-28 10:17:20 -06002063 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002064
2065#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002066 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002067 pDSDumpDot((char*)"triTest2.dot");
2068#endif
2069 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002070 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002071
2072 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002073 EndCommandBuffer();
2074 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002075
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002076 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002077}
Tony Barbour01999182015-04-09 12:58:51 -06002078TEST_F(VkRenderTest, TexturedTriangleClip)
Tony Barbourf43b6982014-11-25 13:18:32 -07002079{
2080 // The expected result from this test is a red and green checkered triangle
2081 static const char *vertShaderText =
2082 "#version 330\n"
2083 "#extension GL_ARB_separate_shader_objects : enable\n"
2084 "#extension GL_ARB_shading_language_420pack : enable\n"
2085 "layout (location = 0) out vec2 samplePos;\n"
2086 "out gl_PerVertex {\n"
2087 " vec4 gl_Position;\n"
2088 " float gl_ClipDistance[1];\n"
2089 "};\n"
2090 "void main() {\n"
2091 " vec2 vertices[3];"
2092 " vertices[0] = vec2(-0.5, -0.5);\n"
2093 " vertices[1] = vec2( 0.5, -0.5);\n"
2094 " vertices[2] = vec2( 0.5, 0.5);\n"
2095 " vec2 positions[3];"
2096 " positions[0] = vec2( 0.0, 0.0);\n"
2097 " positions[1] = vec2( 1.0, 0.0);\n"
2098 " positions[2] = vec2( 1.0, 1.0);\n"
2099 " float dists[3];\n"
2100 " dists[0] = 1.0;\n"
2101 " dists[1] = 1.0;\n"
2102 " dists[2] = -1.0;\n"
2103 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2104 " samplePos = positions[gl_VertexID % 3];\n"
2105 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2106 "}\n";
2107
2108 static const char *fragShaderText =
2109 "#version 140\n"
2110 "#extension GL_ARB_separate_shader_objects : enable\n"
2111 "#extension GL_ARB_shading_language_420pack : enable\n"
2112 "layout (location = 0) in vec2 samplePos;\n"
2113 "layout (binding = 0) uniform sampler2D surface;\n"
2114 "layout (location=0) out vec4 outColor;\n"
2115 "void main() {\n"
2116 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2117 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2118 " outColor = texColor;\n"
2119 "}\n";
2120
2121
2122 ASSERT_NO_FATAL_FAILURE(InitState());
2123 ASSERT_NO_FATAL_FAILURE(InitViewport());
2124
Tony Barbour01999182015-04-09 12:58:51 -06002125 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2126 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2127 VkSamplerObj sampler(m_device);
2128 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002129
Tony Barbour01999182015-04-09 12:58:51 -06002130 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002131 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002132 pipelineobj.AddShader(&vs);
2133 pipelineobj.AddShader(&ps);
2134
Tony Barbour01999182015-04-09 12:58:51 -06002135 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002136 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002137
Tony Barbourdd4c9642015-01-09 12:55:14 -07002138 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002139 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002140
Tony Barbour1490c912015-07-28 10:17:20 -06002141 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002142
2143#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002144 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002145 pDSDumpDot((char*)"triTest2.dot");
2146#endif
2147 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002148 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002149
2150 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002151 EndCommandBuffer();
2152 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002153
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002154 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002155}
GregFd6ebdb32015-06-03 18:40:50 -06002156
Tony Barbour01999182015-04-09 12:58:51 -06002157TEST_F(VkRenderTest, FSTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002158{
2159 // The expected result from this test is a red and green checkered triangle
2160 static const char *vertShaderText =
2161 "#version 140\n"
2162 "#extension GL_ARB_separate_shader_objects : enable\n"
2163 "#extension GL_ARB_shading_language_420pack : enable\n"
2164 "layout (location = 0) out vec2 samplePos;\n"
2165 "void main() {\n"
2166 " vec2 vertices[3];"
2167 " vertices[0] = vec2(-0.5, -0.5);\n"
2168 " vertices[1] = vec2( 0.5, -0.5);\n"
2169 " vertices[2] = vec2( 0.5, 0.5);\n"
2170 " vec2 positions[3];"
2171 " positions[0] = vec2( 0.0, 0.0);\n"
2172 " positions[1] = vec2( 1.0, 0.0);\n"
2173 " positions[2] = vec2( 1.0, 1.0);\n"
2174 " samplePos = positions[gl_VertexID % 3];\n"
2175 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2176 "}\n";
2177
2178 static const char *fragShaderText =
2179 "#version 140\n"
2180 "#extension GL_ARB_separate_shader_objects : enable\n"
2181 "#extension GL_ARB_shading_language_420pack : enable\n"
2182 "layout (location = 0) in vec2 samplePos;\n"
2183 "layout (binding = 0) uniform sampler2D surface;\n"
2184 "layout (location=0) out vec4 outColor;\n"
2185 "void main() {\n"
2186 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2187 " outColor = texColor;\n"
2188 "}\n";
2189
2190 ASSERT_NO_FATAL_FAILURE(InitState());
2191 ASSERT_NO_FATAL_FAILURE(InitViewport());
2192
Tony Barbour01999182015-04-09 12:58:51 -06002193 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2194 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2195 VkSamplerObj sampler(m_device);
2196 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002197
Tony Barbour01999182015-04-09 12:58:51 -06002198 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002199 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002200 pipelineobj.AddShader(&vs);
2201 pipelineobj.AddShader(&ps);
2202
Tony Barbour01999182015-04-09 12:58:51 -06002203 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002204 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002205
Tony Barbourdd4c9642015-01-09 12:55:14 -07002206 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002207 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002208
Tony Barbour1490c912015-07-28 10:17:20 -06002209 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002210
2211#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002212 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002213 pDSDumpDot((char*)"triTest2.dot");
2214#endif
2215 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002216 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002217
2218 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002219 EndCommandBuffer();
2220 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002221
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002222 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002223}
Tony Barbour01999182015-04-09 12:58:51 -06002224TEST_F(VkRenderTest, SamplerBindingsTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002225{
2226 // This test sets bindings on the samplers
2227 // For now we are asserting that sampler and texture pairs
2228 // march in lock step, and are set via GLSL binding. This can
2229 // and will probably change.
2230 // The sampler bindings should match the sampler and texture slot
2231 // number set up by the application.
2232 // This test will result in a blue triangle
2233 static const char *vertShaderText =
2234 "#version 140\n"
2235 "#extension GL_ARB_separate_shader_objects : enable\n"
2236 "#extension GL_ARB_shading_language_420pack : enable\n"
2237 "layout (location = 0) out vec4 samplePos;\n"
2238 "void main() {\n"
2239 " vec2 vertices[3];"
2240 " vertices[0] = vec2(-0.5, -0.5);\n"
2241 " vertices[1] = vec2( 0.5, -0.5);\n"
2242 " vertices[2] = vec2( 0.5, 0.5);\n"
2243 " vec2 positions[3];"
2244 " positions[0] = vec2( 0.0, 0.0);\n"
2245 " positions[1] = vec2( 1.0, 0.0);\n"
2246 " positions[2] = vec2( 1.0, 1.0);\n"
2247 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2248 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2249 "}\n";
2250
2251 static const char *fragShaderText =
2252 "#version 140\n"
2253 "#extension GL_ARB_separate_shader_objects : enable\n"
2254 "#extension GL_ARB_shading_language_420pack : enable\n"
2255 "layout (location = 0) in vec4 samplePos;\n"
2256 "layout (binding = 0) uniform sampler2D surface0;\n"
2257 "layout (binding = 1) uniform sampler2D surface1;\n"
2258 "layout (binding = 12) uniform sampler2D surface2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06002259 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002260 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002261 " outColor = textureLod(surface2, samplePos.xy, 0.0);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002262 "}\n";
2263
2264 ASSERT_NO_FATAL_FAILURE(InitState());
2265 ASSERT_NO_FATAL_FAILURE(InitViewport());
2266
Tony Barbour01999182015-04-09 12:58:51 -06002267 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2268 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002269
Tony Barbour01999182015-04-09 12:58:51 -06002270 VkSamplerObj sampler1(m_device);
2271 VkSamplerObj sampler2(m_device);
2272 VkSamplerObj sampler3(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002273
Tony Barbour2f421a02015-04-01 16:38:10 -06002274 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
Tony Barbour01999182015-04-09 12:58:51 -06002275 VkTextureObj texture1(m_device, tex_colors); // Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002276 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
Tony Barbour01999182015-04-09 12:58:51 -06002277 VkTextureObj texture2(m_device, tex_colors); // Green
Tony Barbour2f421a02015-04-01 16:38:10 -06002278 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
Tony Barbour01999182015-04-09 12:58:51 -06002279 VkTextureObj texture3(m_device, tex_colors); // Blue
Tony Barbourf43b6982014-11-25 13:18:32 -07002280
Tony Barbour01999182015-04-09 12:58:51 -06002281 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002282 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002283 pipelineobj.AddShader(&vs);
2284 pipelineobj.AddShader(&ps);
2285
Tony Barbour01999182015-04-09 12:58:51 -06002286 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002287 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2288 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2289 for (int i = 0; i < 10; i++)
2290 descriptorSet.AppendDummy();
2291 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002292
Tony Barbourdd4c9642015-01-09 12:55:14 -07002293 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002294 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002295
Tony Barbour1490c912015-07-28 10:17:20 -06002296 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002297
2298#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002299 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002300 pDSDumpDot((char*)"triTest2.dot");
2301#endif
2302 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002303 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002304
2305 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002306 EndCommandBuffer();
2307 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002308
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002309 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002310}
2311
Tony Barbour01999182015-04-09 12:58:51 -06002312TEST_F(VkRenderTest, TriangleVSUniformBlock)
Tony Barbourf43b6982014-11-25 13:18:32 -07002313{
2314 // The expected result from this test is a blue triangle
2315
2316 static const char *vertShaderText =
2317 "#version 140\n"
2318 "#extension GL_ARB_separate_shader_objects : enable\n"
2319 "#extension GL_ARB_shading_language_420pack : enable\n"
2320 "layout (location = 0) out vec4 outColor;\n"
2321 "layout (std140, binding = 0) uniform bufferVals {\n"
2322 " vec4 red;\n"
2323 " vec4 green;\n"
2324 " vec4 blue;\n"
2325 " vec4 white;\n"
2326 "} myBufferVals;\n"
2327 "void main() {\n"
2328 " vec2 vertices[3];"
2329 " vertices[0] = vec2(-0.5, -0.5);\n"
2330 " vertices[1] = vec2( 0.5, -0.5);\n"
2331 " vertices[2] = vec2( 0.5, 0.5);\n"
2332 " outColor = myBufferVals.blue;\n"
2333 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2334 "}\n";
2335
2336 static const char *fragShaderText =
2337 "#version 140\n"
2338 "#extension GL_ARB_separate_shader_objects : enable\n"
2339 "#extension GL_ARB_shading_language_420pack : enable\n"
2340 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -06002341 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002342 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002343 " outColor = inColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002344 "}\n";
2345
2346 ASSERT_NO_FATAL_FAILURE(InitState());
2347 ASSERT_NO_FATAL_FAILURE(InitViewport());
2348
Tony Barbour01999182015-04-09 12:58:51 -06002349 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2350 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002351
2352 // Let's populate our buffer with the following:
2353 // vec4 red;
2354 // vec4 green;
2355 // vec4 blue;
2356 // vec4 white;
2357 const int valCount = 4 * 4;
2358 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2359 0.0, 1.0, 0.0, 1.0,
2360 0.0, 0.0, 1.0, 1.0,
2361 1.0, 1.0, 1.0, 1.0 };
2362
Tony Barbour01999182015-04-09 12:58:51 -06002363 VkConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002364
Tony Barbour01999182015-04-09 12:58:51 -06002365 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002366 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002367 pipelineobj.AddShader(&vs);
2368 pipelineobj.AddShader(&ps);
2369
Tony Barbour01999182015-04-09 12:58:51 -06002370 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002371 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002372
Tony Barbourdd4c9642015-01-09 12:55:14 -07002373 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002374 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002375
Tony Barbour1490c912015-07-28 10:17:20 -06002376 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002377
2378#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002379 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002380 pDSDumpDot((char*)"triTest2.dot");
2381#endif
2382 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002383 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002384
2385 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002386 EndCommandBuffer();
2387 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002388
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002389 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002390}
2391
Tony Barbour01999182015-04-09 12:58:51 -06002392TEST_F(VkRenderTest, TriangleFSUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002393{
2394 // This test allows the shader to select which buffer it is
2395 // pulling from using layout binding qualifier.
2396 // There are corresponding changes in the compiler stack that
2397 // will select the buffer using binding directly.
2398 // The binding number should match the slot number set up by
2399 // the application.
2400 // The expected result from this test is a purple triangle
2401
2402 static const char *vertShaderText =
2403 "#version 140\n"
2404 "#extension GL_ARB_separate_shader_objects : enable\n"
2405 "#extension GL_ARB_shading_language_420pack : enable\n"
2406 "void main() {\n"
2407 " vec2 vertices[3];"
2408 " vertices[0] = vec2(-0.5, -0.5);\n"
2409 " vertices[1] = vec2( 0.5, -0.5);\n"
2410 " vertices[2] = vec2( 0.5, 0.5);\n"
2411 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2412 "}\n";
2413
2414 static const char *fragShaderText =
2415 "#version 140\n"
2416 "#extension GL_ARB_separate_shader_objects : enable\n"
2417 "#extension GL_ARB_shading_language_420pack : enable\n"
2418 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2419 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2420 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002421 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
GregFd6ebdb32015-06-03 18:40:50 -06002422 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002423 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002424 " outColor = myBlueVal.color;\n"
2425 " outColor += myRedVal.color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002426 "}\n";
2427
2428 ASSERT_NO_FATAL_FAILURE(InitState());
2429 ASSERT_NO_FATAL_FAILURE(InitViewport());
2430
Tony Barbour01999182015-04-09 12:58:51 -06002431 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2432 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002433
2434 // We're going to create a number of uniform buffers, and then allow
2435 // the shader to select which it wants to read from with a binding
2436
2437 // Let's populate the buffers with a single color each:
2438 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2439 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2440 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002441 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002442
2443 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2444 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2445 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2446 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2447
2448 const int redCount = sizeof(redVals) / sizeof(float);
2449 const int greenCount = sizeof(greenVals) / sizeof(float);
2450 const int blueCount = sizeof(blueVals) / sizeof(float);
2451 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2452
Tony Barbour01999182015-04-09 12:58:51 -06002453 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002454
Tony Barbour01999182015-04-09 12:58:51 -06002455 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002456
Tony Barbour01999182015-04-09 12:58:51 -06002457 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002458
Tony Barbour01999182015-04-09 12:58:51 -06002459 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002460
Tony Barbour01999182015-04-09 12:58:51 -06002461 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002462 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002463 pipelineobj.AddShader(&vs);
2464 pipelineobj.AddShader(&ps);
2465
Tony Barbour01999182015-04-09 12:58:51 -06002466 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002467 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2468 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2469 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2470 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002471
Tony Barbourdd4c9642015-01-09 12:55:14 -07002472 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002473 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourf43b6982014-11-25 13:18:32 -07002474
Tony Barbour1490c912015-07-28 10:17:20 -06002475 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002476
2477#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002478 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002479 pDSDumpDot((char*)"triTest2.dot");
2480#endif
2481 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002482 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002483
2484 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002485 EndCommandBuffer();
2486 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002487
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002488 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002489}
2490
Tony Barbour01999182015-04-09 12:58:51 -06002491TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002492{
2493 // This test is the same as TriangleFSUniformBlockBinding, but
2494 // it does not provide an instance name.
2495 // The expected result from this test is a purple triangle
2496
2497 static const char *vertShaderText =
2498 "#version 140\n"
2499 "#extension GL_ARB_separate_shader_objects : enable\n"
2500 "#extension GL_ARB_shading_language_420pack : enable\n"
2501 "void main() {\n"
2502 " vec2 vertices[3];"
2503 " vertices[0] = vec2(-0.5, -0.5);\n"
2504 " vertices[1] = vec2( 0.5, -0.5);\n"
2505 " vertices[2] = vec2( 0.5, 0.5);\n"
2506 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2507 "}\n";
2508
2509 static const char *fragShaderText =
2510 "#version 430\n"
2511 "#extension GL_ARB_separate_shader_objects : enable\n"
2512 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002513 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2514 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2515 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002516 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002517 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002518 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002519 " outColor = blue;\n"
2520 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002521 "}\n";
2522 ASSERT_NO_FATAL_FAILURE(InitState());
2523 ASSERT_NO_FATAL_FAILURE(InitViewport());
2524
Tony Barbour01999182015-04-09 12:58:51 -06002525 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2526 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002527
2528 // We're going to create a number of uniform buffers, and then allow
2529 // the shader to select which it wants to read from with a binding
2530
2531 // Let's populate the buffers with a single color each:
2532 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2533 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2534 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2535 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2536
2537 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2538 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2539 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2540 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2541
2542 const int redCount = sizeof(redVals) / sizeof(float);
2543 const int greenCount = sizeof(greenVals) / sizeof(float);
2544 const int blueCount = sizeof(blueVals) / sizeof(float);
2545 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2546
Tony Barbour01999182015-04-09 12:58:51 -06002547 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002548
Tony Barbour01999182015-04-09 12:58:51 -06002549 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002550
Tony Barbour01999182015-04-09 12:58:51 -06002551 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002552
Tony Barbour01999182015-04-09 12:58:51 -06002553 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002554
Tony Barbour01999182015-04-09 12:58:51 -06002555 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002556 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002557 pipelineobj.AddShader(&vs);
2558 pipelineobj.AddShader(&ps);
2559
Tony Barbour01999182015-04-09 12:58:51 -06002560 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002561 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2562 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2563 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2564 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002565
Tony Barbourdd4c9642015-01-09 12:55:14 -07002566 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002567 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002568
Tony Barbour1490c912015-07-28 10:17:20 -06002569 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002570
2571#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002572 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002573 pDSDumpDot((char*)"triTest2.dot");
2574#endif
2575 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002576 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002577
2578 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002579 EndCommandBuffer();
2580 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002581
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002582 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002583}
2584
GregF54a32172015-07-01 16:11:09 -06002585TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBindingWithStruct)
2586{
2587 // This test is the same as TriangleFSUniformBlockBinding, but
2588 // it does not provide an instance name.
2589 // The expected result from this test is a purple triangle
2590
2591 static const char *vertShaderText =
2592 "#version 140\n"
2593 "#extension GL_ARB_separate_shader_objects : enable\n"
2594 "#extension GL_ARB_shading_language_420pack : enable\n"
2595 "void main() {\n"
2596 " vec2 vertices[3];"
2597 " vertices[0] = vec2(-0.5, -0.5);\n"
2598 " vertices[1] = vec2( 0.5, -0.5);\n"
2599 " vertices[2] = vec2( 0.5, 0.5);\n"
2600 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2601 "}\n";
2602
2603 static const char *fragShaderText =
2604 "#version 430\n"
2605 "#extension GL_ARB_separate_shader_objects : enable\n"
2606 "#extension GL_ARB_shading_language_420pack : enable\n"
2607 "\n"
2608 " struct PS_INPUT {\n"
2609 " vec2 member0;\n"
2610 " vec4 member1;\n"
2611 " vec4 member2;\n"
2612 " vec4 member3;\n"
2613 " vec4 member4;\n"
2614 " vec4 member5;\n"
2615 " vec4 member6;\n"
2616 " vec4 member7;\n"
2617 " vec4 member8;\n"
2618 " vec4 member9;\n"
2619 " };\n"
2620 "\n"
2621 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2622 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2623 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2624 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
2625 "layout (location = 0) out vec4 outColor;\n"
2626 "PS_INPUT MainFs()\n"
2627 "{\n"
2628 " PS_INPUT o;\n"
2629 " o.member9 = red;\n"
2630 " return o;\n"
2631 "}\n"
2632 "\n"
2633 "void main()\n"
2634 "{\n"
2635 " PS_INPUT o;\n"
2636 " o = MainFs();\n"
2637 " outColor = blue;"
2638 " outColor += o.member9;\n"
2639 "}\n";;
2640 ASSERT_NO_FATAL_FAILURE(InitState());
2641 ASSERT_NO_FATAL_FAILURE(InitViewport());
2642
2643 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2644 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2645
2646 // We're going to create a number of uniform buffers, and then allow
2647 // the shader to select which it wants to read from with a binding
2648
2649 // Let's populate the buffers with a single color each:
2650 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2651 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2652 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2653 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2654
2655 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2656 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2657 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2658 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2659
2660 const int redCount = sizeof(redVals) / sizeof(float);
2661 const int greenCount = sizeof(greenVals) / sizeof(float);
2662 const int blueCount = sizeof(blueVals) / sizeof(float);
2663 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2664
2665 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2666
2667 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2668
2669 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2670
2671 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
2672
2673 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002674 pipelineobj.AddColorAttachment();
GregF54a32172015-07-01 16:11:09 -06002675 pipelineobj.AddShader(&vs);
2676 pipelineobj.AddShader(&ps);
2677
2678 VkDescriptorSetObj descriptorSet(m_device);
2679 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2680 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2681 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2682 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
2683
2684 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002685 ASSERT_VK_SUCCESS(BeginCommandBuffer());
GregF54a32172015-07-01 16:11:09 -06002686
Tony Barbour1490c912015-07-28 10:17:20 -06002687 GenericDrawPreparation(pipelineobj, descriptorSet);
GregF54a32172015-07-01 16:11:09 -06002688
2689#ifdef DUMP_STATE_DOT
2690 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
2691 pDSDumpDot((char*)"triTest2.dot");
2692#endif
2693 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002694 Draw(0, 3, 0, 1);
GregF54a32172015-07-01 16:11:09 -06002695
2696 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002697 EndCommandBuffer();
2698 QueueCommandBuffer();
GregF54a32172015-07-01 16:11:09 -06002699
2700 RecordImages(m_renderTargets);
2701}
2702
Tony Barbour01999182015-04-09 12:58:51 -06002703TEST_F(VkRenderTest, CubeWithVertexFetchAndMVPAndTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07002704{
2705 static const char *vertShaderText =
2706 "#version 140\n"
2707 "#extension GL_ARB_separate_shader_objects : enable\n"
2708 "#extension GL_ARB_shading_language_420pack : enable\n"
2709 "layout (std140, binding=0) uniform bufferVals {\n"
2710 " mat4 mvp;\n"
2711 "} myBufferVals;\n"
2712 "layout (location=0) in vec4 pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002713 "layout (location=1) in vec2 input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002714 "layout (location=0) out vec2 UV;\n"
2715 "void main() {\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002716 " UV = input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002717 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002718 " gl_Position.y = -gl_Position.y;\n"
2719 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002720 "}\n";
2721
2722 static const char *fragShaderText =
2723 "#version 140\n"
2724 "#extension GL_ARB_separate_shader_objects : enable\n"
2725 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002726 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002727 "layout (location=0) out vec4 outColor;\n"
2728 "layout (location=0) in vec2 UV;\n"
2729 "void main() {\n"
2730 " outColor= textureLod(surface, UV, 0.0);\n"
2731 "}\n";
2732 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2733
2734 glm::mat4 View = glm::lookAt(
2735 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2736 glm::vec3(0,0,0), // and looks at the origin
2737 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2738 );
2739
2740 glm::mat4 Model = glm::mat4(1.0f);
2741
2742 glm::mat4 MVP = Projection * View * Model;
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002743 int num_verts = sizeof(g_vb_texture_Data) / sizeof(g_vb_texture_Data[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002744
2745
2746 ASSERT_NO_FATAL_FAILURE(InitState());
2747 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wu9e81ebb2015-07-09 10:16:34 +08002748 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Chia-I Wuc278df82015-07-07 11:50:03 +08002749 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height, m_depth_stencil_fmt);
Tony Barbourf43b6982014-11-25 13:18:32 -07002750
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002751 VkConstantBufferObj meshBuffer(m_device, num_verts,
2752 sizeof(g_vb_texture_Data[0]), g_vb_texture_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002753 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002754
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002755 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07002756
Tony Barbour01999182015-04-09 12:58:51 -06002757 VkConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2758 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2759 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2760 VkSamplerObj sampler(m_device);
2761 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002762
Tony Barbour01999182015-04-09 12:58:51 -06002763 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002764 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002765 pipelineobj.AddShader(&vs);
2766 pipelineobj.AddShader(&ps);
2767
Tony Barbour01999182015-04-09 12:58:51 -06002768 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002769 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mvpBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002770 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002771
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002772#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002773 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002774 MESH_BIND_ID, // binding ID
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002775 sizeof(g_vb_texture_Data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002776 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002777 };
Tony Barbourf43b6982014-11-25 13:18:32 -07002778
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002779 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002780 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2781 vi_attribs[0].location = 0; // location
Tony Barbour8205d902015-04-16 15:59:00 -06002782 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002783 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2784 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2785 vi_attribs[1].location = 1; // location
2786 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
2787 vi_attribs[1].offsetInBytes = 16; // Offset of uv components
Tony Barbourf43b6982014-11-25 13:18:32 -07002788
Tony Barbourf43b6982014-11-25 13:18:32 -07002789 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002790 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2791 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07002792
Tony Barboure307f582015-07-10 15:29:03 -06002793 VkPipelineDepthStencilStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002794 ds_state.depthTestEnable = VK_TRUE;
2795 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06002796 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002797 ds_state.depthBoundsEnable = VK_FALSE;
2798 ds_state.stencilTestEnable = VK_FALSE;
2799 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
2800 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
2801 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06002802 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002803 ds_state.front = ds_state.back;
2804 pipelineobj.SetDepthStencil(&ds_state);
2805
Tony Barbour17c6ab12015-03-27 17:03:18 -06002806 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tobin Ehlis7f7b4422015-08-18 14:24:32 -06002807
2808 VkCmdBufferBeginInfo cbBeginInfo;
2809 memset(&cbBeginInfo, 0, sizeof(VkCmdBufferBeginInfo));
2810 cbBeginInfo.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
2811 cbBeginInfo.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT;
2812 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barbourf43b6982014-11-25 13:18:32 -07002813
Tony Barbour1490c912015-07-28 10:17:20 -06002814 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002815
Tony Barbour1490c912015-07-28 10:17:20 -06002816 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002817#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002818 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002819 pDSDumpDot((char*)"triTest2.dot");
2820#endif
2821 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002822 Draw(0, num_verts, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002823
2824 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002825 EndCommandBuffer();
2826 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002827
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002828 RecordImages(m_renderTargets);
Tony Barbour1490c912015-07-28 10:17:20 -06002829 RotateTriangleVSUniform(Projection, View, Model, &mvpBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002830}
Cody Northropd1ce7842014-12-09 11:17:01 -07002831
Tony Barbour01999182015-04-09 12:58:51 -06002832TEST_F(VkRenderTest, TriangleMixedSamplerUniformBlockBinding)
Cody Northropd1ce7842014-12-09 11:17:01 -07002833{
2834 // This test mixes binding slots of textures and buffers, ensuring
2835 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002836 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002837 // you can modify it to move the desired result around.
2838
2839 static const char *vertShaderText =
2840 "#version 140\n"
2841 "#extension GL_ARB_separate_shader_objects : enable\n"
2842 "#extension GL_ARB_shading_language_420pack : enable\n"
2843 "void main() {\n"
2844 " vec2 vertices[3];"
2845 " vertices[0] = vec2(-0.5, -0.5);\n"
2846 " vertices[1] = vec2( 0.5, -0.5);\n"
2847 " vertices[2] = vec2( 0.5, 0.5);\n"
2848 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2849 "}\n";
2850
2851 static const char *fragShaderText =
2852 "#version 430\n"
2853 "#extension GL_ARB_separate_shader_objects : enable\n"
2854 "#extension GL_ARB_shading_language_420pack : enable\n"
2855 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002856 "layout (binding = 3) uniform sampler2D surface1;\n"
2857 "layout (binding = 1) uniform sampler2D surface2;\n"
2858 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002859
Cody Northropa0410942014-12-09 13:59:39 -07002860
Chia-I Wuf8385062015-01-04 16:27:24 +08002861 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2862 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2863 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2864 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002865 "layout (location = 0) out vec4 outColor;\n"
2866 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002867 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002868 " outColor += white * vec4(0.00001);\n"
2869 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002870 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002871 "}\n";
2872 ASSERT_NO_FATAL_FAILURE(InitState());
2873 ASSERT_NO_FATAL_FAILURE(InitViewport());
2874
Tony Barbour01999182015-04-09 12:58:51 -06002875 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2876 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northropd1ce7842014-12-09 11:17:01 -07002877
Cody Northropd1ce7842014-12-09 11:17:01 -07002878 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2879 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2880 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2881 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2882
2883 const int redCount = sizeof(redVals) / sizeof(float);
2884 const int greenCount = sizeof(greenVals) / sizeof(float);
2885 const int blueCount = sizeof(blueVals) / sizeof(float);
2886 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2887
Tony Barbour01999182015-04-09 12:58:51 -06002888 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2889 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2890 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2891 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002892
Tony Barbour2f421a02015-04-01 16:38:10 -06002893 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002894 VkSamplerObj sampler0(m_device);
2895 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002896 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002897 VkSamplerObj sampler2(m_device);
2898 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002899 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002900 VkSamplerObj sampler4(m_device);
2901 VkTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropa0410942014-12-09 13:59:39 -07002902
2903 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2904 // TODO: Get back here ASAP and understand why.
Tony Barbour2f421a02015-04-01 16:38:10 -06002905 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06002906 VkSamplerObj sampler7(m_device);
2907 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropd1ce7842014-12-09 11:17:01 -07002908
Tony Barbour01999182015-04-09 12:58:51 -06002909 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002910 pipelineobj.AddColorAttachment();
Cody Northropd1ce7842014-12-09 11:17:01 -07002911 pipelineobj.AddShader(&vs);
2912 pipelineobj.AddShader(&ps);
2913
Tony Barbour01999182015-04-09 12:58:51 -06002914 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002915 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2916 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2917 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2918 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002919 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002920 // swap blue and green
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002921 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2922 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2923 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002924
Tony Barbourdd4c9642015-01-09 12:55:14 -07002925 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002926 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropd1ce7842014-12-09 11:17:01 -07002927
Tony Barbour1490c912015-07-28 10:17:20 -06002928 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002929
2930#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002931 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002932 pDSDumpDot((char*)"triTest2.dot");
2933#endif
2934 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002935 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002936
2937 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002938 EndCommandBuffer();
2939 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002940
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002941 RecordImages(m_renderTargets);
Cody Northropd1ce7842014-12-09 11:17:01 -07002942}
2943
Tony Barbour01999182015-04-09 12:58:51 -06002944TEST_F(VkRenderTest, TriangleMatchingSamplerUniformBlockBinding)
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002945{
2946 // This test matches binding slots of textures and buffers, requiring
2947 // the driver to give them distinct number spaces.
2948 // The expected result from this test is a red triangle, although
2949 // you can modify it to move the desired result around.
2950
2951 static const char *vertShaderText =
2952 "#version 140\n"
2953 "#extension GL_ARB_separate_shader_objects : enable\n"
2954 "#extension GL_ARB_shading_language_420pack : enable\n"
2955 "void main() {\n"
2956 " vec2 vertices[3];"
2957 " vertices[0] = vec2(-0.5, -0.5);\n"
2958 " vertices[1] = vec2( 0.5, -0.5);\n"
2959 " vertices[2] = vec2( 0.5, 0.5);\n"
2960 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2961 "}\n";
2962
2963 static const char *fragShaderText =
2964 "#version 430\n"
2965 "#extension GL_ARB_separate_shader_objects : enable\n"
2966 "#extension GL_ARB_shading_language_420pack : enable\n"
2967 "layout (binding = 0) uniform sampler2D surface0;\n"
2968 "layout (binding = 1) uniform sampler2D surface1;\n"
2969 "layout (binding = 2) uniform sampler2D surface2;\n"
2970 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002971 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2972 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2973 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2974 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002975 "layout (location = 0) out vec4 outColor;\n"
2976 "void main() {\n"
2977 " outColor = red;// * vec4(0.00001);\n"
2978 " outColor += white * vec4(0.00001);\n"
2979 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2980 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2981 "}\n";
2982 ASSERT_NO_FATAL_FAILURE(InitState());
2983 ASSERT_NO_FATAL_FAILURE(InitViewport());
2984
Tony Barbour01999182015-04-09 12:58:51 -06002985 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2986 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002987
2988 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2989 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2990 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2991 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2992
2993 const int redCount = sizeof(redVals) / sizeof(float);
2994 const int greenCount = sizeof(greenVals) / sizeof(float);
2995 const int blueCount = sizeof(blueVals) / sizeof(float);
2996 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2997
Tony Barbour01999182015-04-09 12:58:51 -06002998 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2999 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
3000 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
3001 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003002
Tony Barbour2f421a02015-04-01 16:38:10 -06003003 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06003004 VkSamplerObj sampler0(m_device);
3005 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06003006 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06003007 VkSamplerObj sampler2(m_device);
3008 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06003009 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06003010 VkSamplerObj sampler4(m_device);
3011 VkTextureObj texture4(m_device, tex_colors); // Light Green
Tony Barbour2f421a02015-04-01 16:38:10 -06003012 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06003013 VkSamplerObj sampler7(m_device);
3014 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003015
Tony Barbour01999182015-04-09 12:58:51 -06003016 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003017 pipelineobj.AddColorAttachment();
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003018 pipelineobj.AddShader(&vs);
3019 pipelineobj.AddShader(&ps);
3020
Tony Barbour01999182015-04-09 12:58:51 -06003021 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08003022 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3023 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3024 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
3025 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003026 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
3027 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
3028 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
3029 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003030
Tony Barbourdd4c9642015-01-09 12:55:14 -07003031 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003032 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003033
Tony Barbour1490c912015-07-28 10:17:20 -06003034 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07003035
3036#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003037 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07003038 pDSDumpDot((char*)"triTest2.dot");
3039#endif
3040 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06003041 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07003042
3043 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003044 EndCommandBuffer();
3045 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07003046
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003047 RecordImages(m_renderTargets);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003048}
3049
Tony Barbour01999182015-04-09 12:58:51 -06003050TEST_F(VkRenderTest, TriangleUniformBufferLayout)
Cody Northrop02690bd2014-12-17 15:26:33 -07003051{
3052 // This test populates a buffer with a variety of different data
3053 // types, then reads them out with a shader.
3054 // The expected result from this test is a green triangle
3055
3056 static const char *vertShaderText =
3057 "#version 140\n"
3058 "#extension GL_ARB_separate_shader_objects : enable\n"
3059 "#extension GL_ARB_shading_language_420pack : enable\n"
3060 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3061 " vec4 fRed;\n"
3062 " vec4 fGreen;\n"
3063 " layout(row_major) mat4 worldToProj;\n"
3064 " layout(row_major) mat4 projToWorld;\n"
3065 " layout(row_major) mat4 worldToView;\n"
3066 " layout(row_major) mat4 viewToProj;\n"
3067 " layout(row_major) mat4 worldToShadow[4];\n"
3068 " float fZero;\n"
3069 " float fOne;\n"
3070 " float fTwo;\n"
3071 " float fThree;\n"
3072 " vec3 fZeroZeroZero;\n"
3073 " float fFour;\n"
3074 " vec3 fZeroZeroOne;\n"
3075 " float fFive;\n"
3076 " vec3 fZeroOneZero;\n"
3077 " float fSix;\n"
3078 " float fSeven;\n"
3079 " float fEight;\n"
3080 " float fNine;\n"
3081 " vec2 fZeroZero;\n"
3082 " vec2 fZeroOne;\n"
3083 " vec4 fBlue;\n"
3084 " vec2 fOneZero;\n"
3085 " vec2 fOneOne;\n"
3086 " vec3 fZeroOneOne;\n"
3087 " float fTen;\n"
3088 " float fEleven;\n"
3089 " float fTwelve;\n"
3090 " vec3 fOneZeroZero;\n"
3091 " vec4 uvOffsets[4];\n"
3092 "};\n"
3093 "layout (location = 0) out vec4 color;"
3094 "void main() {\n"
3095
3096 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3097 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3098 " \n"
3099
3100 // do some exact comparisons, even though we should
3101 // really have an epsilon involved.
3102 " vec4 outColor = right;\n"
3103 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3104 " outColor = wrong;\n"
3105 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3106 " outColor = wrong;\n"
3107 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3108 " outColor = wrong;\n"
3109
3110 " color = outColor;\n"
3111
3112 // generic position stuff
3113 " vec2 vertices;\n"
3114 " int vertexSelector = gl_VertexID;\n"
3115 " if (vertexSelector == 0)\n"
3116 " vertices = vec2(-0.5, -0.5);\n"
3117 " else if (vertexSelector == 1)\n"
3118 " vertices = vec2( 0.5, -0.5);\n"
3119 " else if (vertexSelector == 2)\n"
3120 " vertices = vec2( 0.5, 0.5);\n"
3121 " else\n"
3122 " vertices = vec2( 0.0, 0.0);\n"
3123 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3124 "}\n";
3125
3126 static const char *fragShaderText =
3127 "#version 140\n"
3128 "#extension GL_ARB_separate_shader_objects : enable\n"
3129 "#extension GL_ARB_shading_language_420pack : enable\n"
3130 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3131 " vec4 fRed;\n"
3132 " vec4 fGreen;\n"
3133 " layout(row_major) mat4 worldToProj;\n"
3134 " layout(row_major) mat4 projToWorld;\n"
3135 " layout(row_major) mat4 worldToView;\n"
3136 " layout(row_major) mat4 viewToProj;\n"
3137 " layout(row_major) mat4 worldToShadow[4];\n"
3138 " float fZero;\n"
3139 " float fOne;\n"
3140 " float fTwo;\n"
3141 " float fThree;\n"
3142 " vec3 fZeroZeroZero;\n"
3143 " float fFour;\n"
3144 " vec3 fZeroZeroOne;\n"
3145 " float fFive;\n"
3146 " vec3 fZeroOneZero;\n"
3147 " float fSix;\n"
3148 " float fSeven;\n"
3149 " float fEight;\n"
3150 " float fNine;\n"
3151 " vec2 fZeroZero;\n"
3152 " vec2 fZeroOne;\n"
3153 " vec4 fBlue;\n"
3154 " vec2 fOneZero;\n"
3155 " vec2 fOneOne;\n"
3156 " vec3 fZeroOneOne;\n"
3157 " float fTen;\n"
3158 " float fEleven;\n"
3159 " float fTwelve;\n"
3160 " vec3 fOneZeroZero;\n"
3161 " vec4 uvOffsets[4];\n"
3162 "};\n"
3163 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003164 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop02690bd2014-12-17 15:26:33 -07003165 "void main() {\n"
3166 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3167 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3168 " \n"
3169
3170 // start with VS value to ensure it passed
3171 " vec4 outColor = color;\n"
3172
3173 // do some exact comparisons, even though we should
3174 // really have an epsilon involved.
3175 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3176 " outColor = wrong;\n"
3177 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3178 " outColor = wrong;\n"
3179 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3180 " outColor = wrong;\n"
3181 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3182 " outColor = wrong;\n"
3183 " if (fTwo != 2.0)\n"
3184 " outColor = wrong;\n"
3185 " if (fOneOne != vec2(1.0, 1.0))\n"
3186 " outColor = wrong;\n"
3187 " if (fTen != 10.0)\n"
3188 " outColor = wrong;\n"
3189 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3190 " outColor = wrong;\n"
3191 " \n"
GregFd6ebdb32015-06-03 18:40:50 -06003192 " uFragColor = outColor;\n"
Cody Northrop02690bd2014-12-17 15:26:33 -07003193 "}\n";
3194
3195
Cody Northrop1684adb2015-08-05 11:15:02 -06003196 const float mixedVals[196] = { 1.0f, 0.0f, 0.0f, 1.0f, // vec4 fRed; // align
3197 0.0f, 1.0f, 0.0f, 1.0f, // vec4 fGreen; // align
3198 1.0f, 0.0f, 0.0f, 1.0f, // layout(row_major) mat4 worldToProj;
3199 0.0f, 1.0f, 0.0f, 1.0f, // align
3200 0.0f, 0.0f, 1.0f, 1.0f, // align
3201 0.0f, 0.0f, 0.0f, 1.0f, // align
3202 2.0f, 0.0f, 0.0f, 2.0f, // layout(row_major) mat4 projToWorld;
3203 0.0f, 2.0f, 0.0f, 2.0f, // align
3204 0.0f, 0.0f, 2.0f, 2.0f, // align
3205 0.0f, 0.0f, 0.0f, 2.0f, // align
3206 3.0f, 0.0f, 0.0f, 3.0f, // layout(row_major) mat4 worldToView;
3207 0.0f, 3.0f, 0.0f, 3.0f, // align
3208 0.0f, 0.0f, 3.0f, 3.0f, // align
3209 0.0f, 0.0f, 0.0f, 3.0f, // align
3210 4.0f, 0.0f, 0.0f, 4.0f, // layout(row_major) mat4 viewToProj;
3211 0.0f, 4.0f, 0.0f, 4.0f, // align
3212 0.0f, 0.0f, 4.0f, 4.0f, // align
3213 0.0f, 0.0f, 0.0f, 4.0f, // align
3214 5.0f, 0.0f, 0.0f, 5.0f, // layout(row_major) mat4 worldToShadow[4];
3215 0.0f, 5.0f, 0.0f, 5.0f, // align
3216 0.0f, 0.0f, 5.0f, 5.0f, // align
3217 0.0f, 0.0f, 0.0f, 5.0f, // align
3218 6.0f, 0.0f, 0.0f, 6.0f, // align
3219 0.0f, 6.0f, 0.0f, 6.0f, // align
3220 0.0f, 0.0f, 6.0f, 6.0f, // align
3221 0.0f, 0.0f, 0.0f, 6.0f, // align
3222 7.0f, 0.0f, 0.0f, 7.0f, // align
3223 0.0f, 7.0f, 0.0f, 7.0f, // align
3224 0.0f, 0.0f, 7.0f, 7.0f, // align
3225 0.0f, 0.0f, 0.0f, 7.0f, // align
3226 8.0f, 0.0f, 0.0f, 8.0f, // align
3227 0.0f, 8.0f, 0.0f, 8.0f, // align
3228 0.0f, 0.0f, 8.0f, 8.0f, // align
3229 0.0f, 0.0f, 0.0f, 8.0f, // align
3230 0.0f, // float fZero; // align
3231 1.0f, // float fOne; // pack
3232 2.0f, // float fTwo; // pack
3233 3.0f, // float fThree; // pack
3234 0.0f, 0.0f, 0.0f, // vec3 fZeroZeroZero; // align
3235 4.0f, // float fFour; // pack
3236 0.0f, 0.0f, 1.0f, // vec3 fZeroZeroOne; // align
3237 5.0f, // float fFive; // pack
3238 0.0f, 1.0f, 0.0f, // vec3 fZeroOneZero; // align
3239 6.0f, // float fSix; // pack
3240 7.0f, // float fSeven; // align
3241 8.0f, // float fEight; // pack
3242 9.0f, // float fNine; // pack
3243 0.0f, // BUFFER
3244 0.0f, 0.0f, // vec2 fZeroZero; // align
3245 0.0f, 1.0f, // vec2 fZeroOne; // pack
3246 0.0f, 0.0f, 1.0f, 1.0f, // vec4 fBlue; // align
3247 1.0f, 0.0f, // vec2 fOneZero; // align
3248 1.0f, 1.0f, // vec2 fOneOne; // pack
3249 0.0f, 1.0f, 1.0f, // vec3 fZeroOneOne; // align
3250 10.0f, // float fTen; // pack
3251 11.0f, // float fEleven; // align
3252 12.0f, // float fTwelve; // pack
3253 0.0f, 0.0f, // BUFFER
3254 1.0f, 0.0f, 0.0f, // vec3 fOneZeroZero; // align
3255 0.0f, // BUFFER
3256 0.1f, 0.2f, 0.3f, 0.4f, // vec4 uvOffsets[4];
3257 0.5f, 0.6f, 0.7f, 0.8f, // align
3258 0.9f, 1.0f, 1.1f, 1.2f, // align
3259 1.3f, 1.4f, 1.5f, 1.6f, // align
Cody Northrop02690bd2014-12-17 15:26:33 -07003260 };
3261
3262 ASSERT_NO_FATAL_FAILURE(InitState());
3263 ASSERT_NO_FATAL_FAILURE(InitViewport());
3264
3265 const int constCount = sizeof(mixedVals) / sizeof(float);
3266
Tony Barbour01999182015-04-09 12:58:51 -06003267 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3268 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop02690bd2014-12-17 15:26:33 -07003269
Tony Barbour01999182015-04-09 12:58:51 -06003270 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003271
Tony Barbour01999182015-04-09 12:58:51 -06003272 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003273 pipelineobj.AddColorAttachment();
Cody Northrop02690bd2014-12-17 15:26:33 -07003274 pipelineobj.AddShader(&vs);
3275 pipelineobj.AddShader(&ps);
3276
Tony Barbour01999182015-04-09 12:58:51 -06003277 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003278 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003279
3280 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003281 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop02690bd2014-12-17 15:26:33 -07003282
Tony Barbour1490c912015-07-28 10:17:20 -06003283 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop02690bd2014-12-17 15:26:33 -07003284
3285#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003286 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop02690bd2014-12-17 15:26:33 -07003287 pDSDumpDot((char*)"triTest2.dot");
3288#endif
3289 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06003290 Draw(0, 3, 0, 1);
Cody Northrop02690bd2014-12-17 15:26:33 -07003291
3292 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003293 EndCommandBuffer();
3294 QueueCommandBuffer();
Cody Northrop02690bd2014-12-17 15:26:33 -07003295
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003296 RecordImages(m_renderTargets);
Cody Northrop02690bd2014-12-17 15:26:33 -07003297}
3298
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003299TEST_F(VkRenderTest, TextureGather)
3300{
3301 // This test introduces textureGather and textureGatherOffset
3302 // Each call is compared against an expected inline color result
3303 // Green triangle means everything worked as expected
3304 // Red means something went wrong
3305
Cody Northropbe701ac2015-08-06 13:18:13 -06003306 // disable SPV until texture gather is turned on in glsl->SPV
3307 if (!m_use_glsl) {
3308 printf("Skipping test that requires GLSL path (TextureGather)\n");
3309 return;
3310 }
3311
Cody Northrop1cfbd172015-06-03 16:49:20 -06003312 ScopedUseGlsl useGlsl(true);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003313
3314 static const char *vertShaderText =
3315 "#version 140\n"
3316 "#extension GL_ARB_separate_shader_objects : enable\n"
3317 "#extension GL_ARB_shading_language_420pack : enable\n"
3318 "void main() {\n"
3319 " vec2 vertices[3];"
3320 " vertices[0] = vec2(-0.5, -0.5);\n"
3321 " vertices[1] = vec2( 0.5, -0.5);\n"
3322 " vertices[2] = vec2( 0.5, 0.5);\n"
3323 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
3324 "}\n";
3325
3326 static const char *fragShaderText =
3327 "#version 430\n"
3328 "#extension GL_ARB_separate_shader_objects : enable\n"
3329 "#extension GL_ARB_shading_language_420pack : enable\n"
3330 "layout (binding = 0) uniform sampler2D surface0;\n"
3331 "layout (binding = 1) uniform sampler2D surface1;\n"
3332 "layout (binding = 2) uniform sampler2D surface2;\n"
3333 "layout (binding = 3) uniform sampler2D surface3;\n"
3334 "layout (location = 0) out vec4 outColor;\n"
3335 "void main() {\n"
3336
3337 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3338 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3339
3340 " vec4 color = right;\n"
3341
3342 // Grab a normal texture sample to ensure it can work in conjuntion
3343 // with textureGather (there are some intracacies in the backend)
3344 " vec4 sampledColor = textureLod(surface2, vec2(0.5), 0.0);\n"
3345 " if (sampledColor != vec4(0.0, 0.0, 1.0, 1.0))\n"
3346 " color = wrong;\n"
3347
3348 " vec4 gatheredColor = textureGather(surface0, vec2(0.5), 0);\n"
3349 // This just grabbed four red components from a red surface
3350 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3351 " color = wrong;\n"
3352
3353 // Yes, this is using an offset of 0, we don't have enough fine grained
3354 // control of the texture contents here.
3355 " gatheredColor = textureGatherOffset(surface1, vec2(0.5), ivec2(0, 0), 1);\n"
3356 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3357 " color = wrong;\n"
3358
3359 " outColor = color;\n"
3360
3361 "}\n";
3362
3363 ASSERT_NO_FATAL_FAILURE(InitState());
3364 ASSERT_NO_FATAL_FAILURE(InitViewport());
3365
3366 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3367 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3368
3369 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
3370 VkSamplerObj sampler0(m_device);
3371 VkTextureObj texture0(m_device, tex_colors); // Red
3372 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
3373 VkSamplerObj sampler1(m_device);
3374 VkTextureObj texture1(m_device, tex_colors); // Green
3375 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
3376 VkSamplerObj sampler2(m_device);
3377 VkTextureObj texture2(m_device, tex_colors); // Blue
3378 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
3379 VkSamplerObj sampler3(m_device);
3380 VkTextureObj texture3(m_device, tex_colors); // Red and Blue
3381
3382 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003383 pipelineobj.AddColorAttachment();
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003384 pipelineobj.AddShader(&vs);
3385 pipelineobj.AddShader(&ps);
3386
3387 VkDescriptorSetObj descriptorSet(m_device);
3388 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3389 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
3390 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3391 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
3392
3393 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003394 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003395
Tony Barbour1490c912015-07-28 10:17:20 -06003396 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003397
3398 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06003399 Draw(0, 3, 0, 1);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003400
3401 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003402 EndCommandBuffer();
3403 QueueCommandBuffer();
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003404
3405 RecordImages(m_renderTargets);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003406}
3407
Cody Northropa44c2ff2015-04-15 11:19:06 -06003408TEST_F(VkRenderTest, GeometryShaderHelloWorld)
3409{
3410 // This test introduces a geometry shader that simply
3411 // changes the color of each vertex to red, green, blue
3412
3413 static const char *vertShaderText =
3414 "#version 140\n"
3415 "#extension GL_ARB_separate_shader_objects : enable\n"
3416 "#extension GL_ARB_shading_language_420pack : enable\n"
3417 "layout (location = 0) out vec4 color;"
3418 "void main() {\n"
3419
3420 // VS writes out red
3421 " color = vec4(1.0, 0.0, 0.0, 1.0);\n"
3422
3423 // generic position stuff
3424 " vec2 vertices;\n"
3425 " int vertexSelector = gl_VertexID;\n"
3426 " if (vertexSelector == 0)\n"
3427 " vertices = vec2(-0.5, -0.5);\n"
3428 " else if (vertexSelector == 1)\n"
3429 " vertices = vec2( 0.5, -0.5);\n"
3430 " else if (vertexSelector == 2)\n"
3431 " vertices = vec2( 0.5, 0.5);\n"
3432 " else\n"
3433 " vertices = vec2( 0.0, 0.0);\n"
3434 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3435
3436 "}\n";
3437
3438 static const char *geomShaderText =
3439 "#version 330\n"
3440 "#extension GL_ARB_separate_shader_objects : enable\n"
3441 "#extension GL_ARB_shading_language_420pack : enable\n"
3442 "layout( triangles ) in;\n"
3443 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3444 "layout( location = 0 ) in vec4 inColor[3];\n"
3445 "layout( location = 0 ) out vec4 outColor;\n"
3446 "void main()\n"
3447 "{\n"
3448
3449 // first vertex, pass through red
3450 " gl_Position = gl_in[0].gl_Position;\n"
3451 " outColor = inColor[0];\n"
3452 " EmitVertex();\n"
3453
3454 // second vertex, green
3455 " gl_Position = gl_in[1].gl_Position;\n"
3456 " outColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3457 " EmitVertex();\n"
3458
3459 // third vertex, blue
3460 " gl_Position = gl_in[2].gl_Position;\n"
3461 " outColor = vec4(0.0, 0.0, 1.0, 1.0);\n"
3462 " EmitVertex();\n"
3463
3464 // done
3465 " EndPrimitive();\n"
3466 "}\n";
3467
3468
3469 static const char *fragShaderText =
3470 "#version 140\n"
3471 "#extension GL_ARB_separate_shader_objects : enable\n"
3472 "#extension GL_ARB_shading_language_420pack : enable\n"
3473 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003474 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003475 "void main() {\n"
3476 // pass through
GregFd6ebdb32015-06-03 18:40:50 -06003477 " outColor = color;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003478 "}\n";
3479
3480
3481
3482 ASSERT_NO_FATAL_FAILURE(InitState());
3483 ASSERT_NO_FATAL_FAILURE(InitViewport());
3484
3485 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3486 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3487 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3488
3489 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003490 pipelineobj.AddColorAttachment();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003491 pipelineobj.AddShader(&vs);
3492 pipelineobj.AddShader(&gs);
3493 pipelineobj.AddShader(&ps);
3494
3495 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003496 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropa44c2ff2015-04-15 11:19:06 -06003497
3498 VkDescriptorSetObj descriptorSet(m_device);
3499
Tony Barbour1490c912015-07-28 10:17:20 -06003500 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003501
3502 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06003503 Draw(0, 3, 0, 1);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003504
3505 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003506 EndCommandBuffer();
3507 QueueCommandBuffer();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003508
3509 RecordImages(m_renderTargets);
3510}
3511
3512TEST_F(VkRenderTest, GSUniformBufferLayout)
3513{
3514 // This test is just like TriangleUniformBufferLayout but adds
3515 // geometry as a stage that also does UBO lookups
3516 // The expected result from this test is a green triangle
3517
3518 static const char *vertShaderText =
3519 "#version 140\n"
3520 "#extension GL_ARB_separate_shader_objects : enable\n"
3521 "#extension GL_ARB_shading_language_420pack : enable\n"
3522 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3523 " vec4 fRed;\n"
3524 " vec4 fGreen;\n"
3525 " layout(row_major) mat4 worldToProj;\n"
3526 " layout(row_major) mat4 projToWorld;\n"
3527 " layout(row_major) mat4 worldToView;\n"
3528 " layout(row_major) mat4 viewToProj;\n"
3529 " layout(row_major) mat4 worldToShadow[4];\n"
3530 " float fZero;\n"
3531 " float fOne;\n"
3532 " float fTwo;\n"
3533 " float fThree;\n"
3534 " vec3 fZeroZeroZero;\n"
3535 " float fFour;\n"
3536 " vec3 fZeroZeroOne;\n"
3537 " float fFive;\n"
3538 " vec3 fZeroOneZero;\n"
3539 " float fSix;\n"
3540 " float fSeven;\n"
3541 " float fEight;\n"
3542 " float fNine;\n"
3543 " vec2 fZeroZero;\n"
3544 " vec2 fZeroOne;\n"
3545 " vec4 fBlue;\n"
3546 " vec2 fOneZero;\n"
3547 " vec2 fOneOne;\n"
3548 " vec3 fZeroOneOne;\n"
3549 " float fTen;\n"
3550 " float fEleven;\n"
3551 " float fTwelve;\n"
3552 " vec3 fOneZeroZero;\n"
3553 " vec4 uvOffsets[4];\n"
3554 "};\n"
3555 "layout (location = 0) out vec4 color;"
3556 "void main() {\n"
3557
3558 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3559 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3560 " \n"
3561
3562 // do some exact comparisons, even though we should
3563 // really have an epsilon involved.
3564 " vec4 outColor = right;\n"
3565 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3566 " outColor = wrong;\n"
3567 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3568 " outColor = wrong;\n"
3569 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3570 " outColor = wrong;\n"
3571
3572 " color = outColor;\n"
3573
3574 // generic position stuff
3575 " vec2 vertices;\n"
3576 " int vertexSelector = gl_VertexID;\n"
3577 " if (vertexSelector == 0)\n"
3578 " vertices = vec2(-0.5, -0.5);\n"
3579 " else if (vertexSelector == 1)\n"
3580 " vertices = vec2( 0.5, -0.5);\n"
3581 " else if (vertexSelector == 2)\n"
3582 " vertices = vec2( 0.5, 0.5);\n"
3583 " else\n"
3584 " vertices = vec2( 0.0, 0.0);\n"
3585 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3586 "}\n";
3587
3588 static const char *geomShaderText =
3589 "#version 330\n"
3590 "#extension GL_ARB_separate_shader_objects : enable\n"
3591 "#extension GL_ARB_shading_language_420pack : enable\n"
3592
3593 // GS layout stuff
3594 "layout( triangles ) in;\n"
3595 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3596
3597 // Between stage IO
3598 "layout( location = 0 ) in vec4 inColor[3];\n"
3599 "layout( location = 0 ) out vec4 color;\n"
3600
3601 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3602 " vec4 fRed;\n"
3603 " vec4 fGreen;\n"
3604 " layout(row_major) mat4 worldToProj;\n"
3605 " layout(row_major) mat4 projToWorld;\n"
3606 " layout(row_major) mat4 worldToView;\n"
3607 " layout(row_major) mat4 viewToProj;\n"
3608 " layout(row_major) mat4 worldToShadow[4];\n"
3609 " float fZero;\n"
3610 " float fOne;\n"
3611 " float fTwo;\n"
3612 " float fThree;\n"
3613 " vec3 fZeroZeroZero;\n"
3614 " float fFour;\n"
3615 " vec3 fZeroZeroOne;\n"
3616 " float fFive;\n"
3617 " vec3 fZeroOneZero;\n"
3618 " float fSix;\n"
3619 " float fSeven;\n"
3620 " float fEight;\n"
3621 " float fNine;\n"
3622 " vec2 fZeroZero;\n"
3623 " vec2 fZeroOne;\n"
3624 " vec4 fBlue;\n"
3625 " vec2 fOneZero;\n"
3626 " vec2 fOneOne;\n"
3627 " vec3 fZeroOneOne;\n"
3628 " float fTen;\n"
3629 " float fEleven;\n"
3630 " float fTwelve;\n"
3631 " vec3 fOneZeroZero;\n"
3632 " vec4 uvOffsets[4];\n"
3633 "};\n"
3634
3635 "void main()\n"
3636 "{\n"
3637
3638 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3639 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3640
3641 // Each vertex will validate it can read VS output
3642 // then check a few values from the UBO
3643
3644 // first vertex
3645 " vec4 outColor = inColor[0];\n"
3646
3647 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3648 " outColor = wrong;\n"
3649 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3650 " outColor = wrong;\n"
3651 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3652 " outColor = wrong;\n"
3653 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3654 " outColor = wrong;\n"
3655
3656 " gl_Position = gl_in[0].gl_Position;\n"
3657 " color = outColor;\n"
3658 " EmitVertex();\n"
3659
3660 // second vertex
3661 " outColor = inColor[1];\n"
3662
3663 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3664 " outColor = wrong;\n"
3665 " if (fSix != 6.0)\n"
3666 " outColor = wrong;\n"
3667 " if (fOneOne != vec2(1.0, 1.0))\n"
3668 " outColor = wrong;\n"
3669
3670 " gl_Position = gl_in[1].gl_Position;\n"
3671 " color = outColor;\n"
3672 " EmitVertex();\n"
3673
3674 // third vertex
3675 " outColor = inColor[2];\n"
3676
3677 " if (fSeven != 7.0)\n"
3678 " outColor = wrong;\n"
3679 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3680 " outColor = wrong;\n"
3681
3682 " gl_Position = gl_in[2].gl_Position;\n"
3683 " color = outColor;\n"
3684 " EmitVertex();\n"
3685
3686 // done
3687 " EndPrimitive();\n"
3688 "}\n";
3689
3690 static const char *fragShaderText =
3691 "#version 140\n"
3692 "#extension GL_ARB_separate_shader_objects : enable\n"
3693 "#extension GL_ARB_shading_language_420pack : enable\n"
3694 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3695 " vec4 fRed;\n"
3696 " vec4 fGreen;\n"
3697 " layout(row_major) mat4 worldToProj;\n"
3698 " layout(row_major) mat4 projToWorld;\n"
3699 " layout(row_major) mat4 worldToView;\n"
3700 " layout(row_major) mat4 viewToProj;\n"
3701 " layout(row_major) mat4 worldToShadow[4];\n"
3702 " float fZero;\n"
3703 " float fOne;\n"
3704 " float fTwo;\n"
3705 " float fThree;\n"
3706 " vec3 fZeroZeroZero;\n"
3707 " float fFour;\n"
3708 " vec3 fZeroZeroOne;\n"
3709 " float fFive;\n"
3710 " vec3 fZeroOneZero;\n"
3711 " float fSix;\n"
3712 " float fSeven;\n"
3713 " float fEight;\n"
3714 " float fNine;\n"
3715 " vec2 fZeroZero;\n"
3716 " vec2 fZeroOne;\n"
3717 " vec4 fBlue;\n"
3718 " vec2 fOneZero;\n"
3719 " vec2 fOneOne;\n"
3720 " vec3 fZeroOneOne;\n"
3721 " float fTen;\n"
3722 " float fEleven;\n"
3723 " float fTwelve;\n"
3724 " vec3 fOneZeroZero;\n"
3725 " vec4 uvOffsets[4];\n"
3726 "};\n"
3727 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003728 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003729 "void main() {\n"
3730 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3731 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3732 " \n"
3733
3734 // start with GS value to ensure it passed
3735 " vec4 outColor = color;\n"
3736
3737 // do some exact comparisons, even though we should
3738 // really have an epsilon involved.
3739 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3740 " outColor = wrong;\n"
3741 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3742 " outColor = wrong;\n"
3743 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3744 " outColor = wrong;\n"
3745 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3746 " outColor = wrong;\n"
3747 " if (fTwo != 2.0)\n"
3748 " outColor = wrong;\n"
3749 " if (fOneOne != vec2(1.0, 1.0))\n"
3750 " outColor = wrong;\n"
3751 " if (fTen != 10.0)\n"
3752 " outColor = wrong;\n"
3753 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3754 " outColor = wrong;\n"
3755 " \n"
GregFd6ebdb32015-06-03 18:40:50 -06003756 " uFragColor = outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003757 "}\n";
3758
3759
Cody Northrop1684adb2015-08-05 11:15:02 -06003760 const float mixedVals[196] = { 1.0f, 0.0f, 0.0f, 1.0f, // vec4 fRed; // align
3761 0.0f, 1.0f, 0.0f, 1.0f, // vec4 fGreen; // align
3762 1.0f, 0.0f, 0.0f, 1.0f, // layout(row_major) mat4 worldToProj;
3763 0.0f, 1.0f, 0.0f, 1.0f, // align
3764 0.0f, 0.0f, 1.0f, 1.0f, // align
3765 0.0f, 0.0f, 0.0f, 1.0f, // align
3766 2.0f, 0.0f, 0.0f, 2.0f, // layout(row_major) mat4 projToWorld;
3767 0.0f, 2.0f, 0.0f, 2.0f, // align
3768 0.0f, 0.0f, 2.0f, 2.0f, // align
3769 0.0f, 0.0f, 0.0f, 2.0f, // align
3770 3.0f, 0.0f, 0.0f, 3.0f, // layout(row_major) mat4 worldToView;
3771 0.0f, 3.0f, 0.0f, 3.0f, // align
3772 0.0f, 0.0f, 3.0f, 3.0f, // align
3773 0.0f, 0.0f, 0.0f, 3.0f, // align
3774 4.0f, 0.0f, 0.0f, 4.0f, // layout(row_major) mat4 viewToProj;
3775 0.0f, 4.0f, 0.0f, 4.0f, // align
3776 0.0f, 0.0f, 4.0f, 4.0f, // align
3777 0.0f, 0.0f, 0.0f, 4.0f, // align
3778 5.0f, 0.0f, 0.0f, 5.0f, // layout(row_major) mat4 worldToShadow[4];
3779 0.0f, 5.0f, 0.0f, 5.0f, // align
3780 0.0f, 0.0f, 5.0f, 5.0f, // align
3781 0.0f, 0.0f, 0.0f, 5.0f, // align
3782 6.0f, 0.0f, 0.0f, 6.0f, // align
3783 0.0f, 6.0f, 0.0f, 6.0f, // align
3784 0.0f, 0.0f, 6.0f, 6.0f, // align
3785 0.0f, 0.0f, 0.0f, 6.0f, // align
3786 7.0f, 0.0f, 0.0f, 7.0f, // align
3787 0.0f, 7.0f, 0.0f, 7.0f, // align
3788 0.0f, 0.0f, 7.0f, 7.0f, // align
3789 0.0f, 0.0f, 0.0f, 7.0f, // align
3790 8.0f, 0.0f, 0.0f, 8.0f, // align
3791 0.0f, 8.0f, 0.0f, 8.0f, // align
3792 0.0f, 0.0f, 8.0f, 8.0f, // align
3793 0.0f, 0.0f, 0.0f, 8.0f, // align
3794 0.0f, // float fZero; // align
3795 1.0f, // float fOne; // pack
3796 2.0f, // float fTwo; // pack
3797 3.0f, // float fThree; // pack
3798 0.0f, 0.0f, 0.0f, // vec3 fZeroZeroZero; // align
3799 4.0f, // float fFour; // pack
3800 0.0f, 0.0f, 1.0f, // vec3 fZeroZeroOne; // align
3801 5.0f, // float fFive; // pack
3802 0.0f, 1.0f, 0.0f, // vec3 fZeroOneZero; // align
3803 6.0f, // float fSix; // pack
3804 7.0f, // float fSeven; // align
3805 8.0f, // float fEight; // pack
3806 9.0f, // float fNine; // pack
3807 0.0f, // BUFFER
3808 0.0f, 0.0f, // vec2 fZeroZero; // align
3809 0.0f, 1.0f, // vec2 fZeroOne; // pack
3810 0.0f, 0.0f, 1.0f, 1.0f, // vec4 fBlue; // align
3811 1.0f, 0.0f, // vec2 fOneZero; // align
3812 1.0f, 1.0f, // vec2 fOneOne; // pack
3813 0.0f, 1.0f, 1.0f, // vec3 fZeroOneOne; // align
3814 10.0f, // float fTen; // pack
3815 11.0f, // float fEleven; // align
3816 12.0f, // float fTwelve; // pack
3817 0.0f, 0.0f, // BUFFER
3818 1.0f, 0.0f, 0.0f, // vec3 fOneZeroZero; // align
3819 0.0f, // BUFFER
3820 0.1f, 0.2f, 0.3f, 0.4f, // vec4 uvOffsets[4];
3821 0.5f, 0.6f, 0.7f, 0.8f, // align
3822 0.9f, 1.0f, 1.1f, 1.2f, // align
3823 1.3f, 1.4f, 1.5f, 1.6f, // align
Cody Northropa44c2ff2015-04-15 11:19:06 -06003824 };
3825
3826
3827
3828 ASSERT_NO_FATAL_FAILURE(InitState());
3829 ASSERT_NO_FATAL_FAILURE(InitViewport());
3830
3831 const int constCount = sizeof(mixedVals) / sizeof(float);
3832
3833 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3834 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3835 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3836
3837 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
3838
3839 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003840 pipelineobj.AddColorAttachment();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003841 pipelineobj.AddShader(&vs);
3842 pipelineobj.AddShader(&gs);
3843 pipelineobj.AddShader(&ps);
3844
3845 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003846 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropa44c2ff2015-04-15 11:19:06 -06003847
3848 VkDescriptorSetObj descriptorSet(m_device);
3849 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
3850
Tony Barbour1490c912015-07-28 10:17:20 -06003851 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003852
3853 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06003854 Draw(0, 3, 0, 1);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003855
3856 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003857 EndCommandBuffer();
3858 QueueCommandBuffer();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003859
3860 RecordImages(m_renderTargets);
3861}
3862
3863TEST_F(VkRenderTest, GSPositions)
3864{
3865 // This test adds more inputs from the vertex shader and perturbs positions
3866 // Expected result is white triangle with weird positions
3867
3868 static const char *vertShaderText =
3869 "#version 140\n"
3870 "#extension GL_ARB_separate_shader_objects : enable\n"
3871 "#extension GL_ARB_shading_language_420pack : enable\n"
3872
3873 "layout(location = 0) out vec3 out_a;\n"
3874 "layout(location = 1) out vec3 out_b;\n"
3875 "layout(location = 2) out vec3 out_c;\n"
3876
3877 "void main() {\n"
3878
3879 // write a solid color to each
3880 " out_a = vec3(1.0, 0.0, 0.0);\n"
3881 " out_b = vec3(0.0, 1.0, 0.0);\n"
3882 " out_c = vec3(0.0, 0.0, 1.0);\n"
3883
3884 // generic position stuff
3885 " vec2 vertices;\n"
3886 " int vertexSelector = gl_VertexID;\n"
3887 " if (vertexSelector == 0)\n"
3888 " vertices = vec2(-0.5, -0.5);\n"
3889 " else if (vertexSelector == 1)\n"
3890 " vertices = vec2( 0.5, -0.5);\n"
3891 " else if (vertexSelector == 2)\n"
3892 " vertices = vec2( 0.5, 0.5);\n"
3893 " else\n"
3894 " vertices = vec2( 0.0, 0.0);\n"
3895 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3896
3897 "}\n";
3898
3899 static const char *geomShaderText =
3900 "#version 330\n"
3901 "#extension GL_ARB_separate_shader_objects : enable\n"
3902 "#extension GL_ARB_shading_language_420pack : enable\n"
3903 "layout( triangles ) in;\n"
3904 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3905
3906 "layout(location = 0) in vec3 in_a[3];\n"
3907 "layout(location = 1) in vec3 in_b[3];\n"
3908 "layout(location = 2) in vec3 in_c[3];\n"
3909
3910 "layout(location = 0) out vec3 out_a;\n"
3911 "layout(location = 1) out vec3 out_b;\n"
3912 "layout(location = 2) out vec3 out_c;\n"
3913
3914 "void main()\n"
3915 "{\n"
3916
3917 " gl_Position = gl_in[0].gl_Position;\n"
3918 " gl_Position.xy *= vec2(0.75);\n"
3919 " out_a = in_a[0];\n"
3920 " out_b = in_b[0];\n"
3921 " out_c = in_c[0];\n"
3922 " EmitVertex();\n"
3923
3924 " gl_Position = gl_in[1].gl_Position;\n"
3925 " gl_Position.xy *= vec2(1.5);\n"
3926 " out_a = in_a[1];\n"
3927 " out_b = in_b[1];\n"
3928 " out_c = in_c[1];\n"
3929 " EmitVertex();\n"
3930
3931 " gl_Position = gl_in[2].gl_Position;\n"
3932 " gl_Position.xy *= vec2(-0.1);\n"
3933 " out_a = in_a[2];\n"
3934 " out_b = in_b[2];\n"
3935 " out_c = in_c[2];\n"
3936 " EmitVertex();\n"
3937
3938 " EndPrimitive();\n"
3939 "}\n";
3940
3941
3942 static const char *fragShaderText =
3943 "#version 140\n"
3944 "#extension GL_ARB_separate_shader_objects : enable\n"
3945 "#extension GL_ARB_shading_language_420pack : enable\n"
3946
3947 "layout(location = 0) in vec3 in_a;\n"
3948 "layout(location = 1) in vec3 in_b;\n"
3949 "layout(location = 2) in vec3 in_c;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003950 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003951
3952 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06003953 " outColor = vec4(in_a.x, in_b.y, in_c.z, 1.0);\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003954 "}\n";
3955
3956
3957
3958 ASSERT_NO_FATAL_FAILURE(InitState());
3959 ASSERT_NO_FATAL_FAILURE(InitViewport());
3960
3961 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3962 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3963 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3964
3965 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003966 pipelineobj.AddColorAttachment();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003967 pipelineobj.AddShader(&vs);
3968 pipelineobj.AddShader(&gs);
3969 pipelineobj.AddShader(&ps);
3970
3971 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003972 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropa44c2ff2015-04-15 11:19:06 -06003973
3974 VkDescriptorSetObj descriptorSet(m_device);
3975
Tony Barbour1490c912015-07-28 10:17:20 -06003976 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003977
3978 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06003979 Draw(0, 3, 0, 1);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003980
3981 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003982 EndCommandBuffer();
3983 QueueCommandBuffer();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003984
3985 RecordImages(m_renderTargets);
3986}
3987
3988TEST_F(VkRenderTest, GSTriStrip)
3989{
3990 // This test emits multiple multiple triangles using a GS
3991 // Correct result is an multicolor circle
3992
3993 static const char *vertShaderText =
3994 "#version 140\n"
3995 "#extension GL_ARB_separate_shader_objects : enable\n"
3996 "#extension GL_ARB_shading_language_420pack : enable\n"
3997
3998 "void main() {\n"
3999
4000 // generic position stuff
4001 " vec2 vertices;\n"
4002 " int vertexSelector = gl_VertexID;\n"
4003 " if (vertexSelector == 0)\n"
4004 " vertices = vec2(-0.5, -0.5);\n"
4005 " else if (vertexSelector == 1)\n"
4006 " vertices = vec2( 0.5, -0.5);\n"
4007 " else if (vertexSelector == 2)\n"
4008 " vertices = vec2( 0.5, 0.5);\n"
4009 " else\n"
4010 " vertices = vec2( 0.0, 0.0);\n"
4011 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
4012
4013 "}\n";
4014
4015 static const char *geomShaderText =
4016 "#version 330\n"
4017 "#extension GL_ARB_separate_shader_objects : enable\n"
4018 "#extension GL_ARB_shading_language_420pack : enable\n"
4019 "layout( triangles ) in;\n"
4020 "layout( triangle_strip, max_vertices = 18 ) out;\n"
4021
4022 "layout(location = 0) out vec4 outColor;\n"
4023
4024 "void main()\n"
4025 "{\n"
4026 // init with first position to get zw
4027 " gl_Position = gl_in[0].gl_Position;\n"
4028
4029 " vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
4030 " vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
4031 " vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
4032 " vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
4033
4034 // different color per tri
4035 " vec4[6] colors = { red, white, \n"
4036 " yellow, white, \n"
4037 " blue, white }; \n"
4038
4039 // fan out the triangles
4040 " vec2[18] positions = { vec2(0.0, 0.0), vec2(-0.5, 0.0), vec2(-0.25, -0.5), \n"
4041 " vec2(0.0, 0.0), vec2(-0.25, -0.5), vec2( 0.25, -0.5), \n"
4042 " vec2(0.0, 0.0), vec2( 0.25, -0.5), vec2( 0.5, 0.0), \n"
4043 " vec2(0.0, 0.0), vec2( 0.5, 0.0), vec2( 0.25, 0.5), \n"
4044 " vec2(0.0, 0.0), vec2( 0.25, 0.5), vec2(-0.25, 0.5), \n"
4045 " vec2(0.0, 0.0), vec2(-0.25, 0.5), vec2(-0.5, 0.0) }; \n"
4046
4047 // make a triangle list of 6
4048 " for (int i = 0; i < 6; ++i) { \n"
4049 " outColor = colors[i]; \n"
4050 " for (int j = 0; j < 3; ++j) { \n"
4051 " gl_Position.xy = positions[i * 3 + j]; \n"
4052 " EmitVertex(); \n"
4053 " } \n"
4054 " EndPrimitive();\n"
4055 " } \n"
4056
4057 "}\n";
4058
4059
4060 static const char *fragShaderText =
4061 "#version 150\n"
4062 "#extension GL_ARB_separate_shader_objects : enable\n"
4063 "#extension GL_ARB_shading_language_420pack : enable\n"
4064
4065
4066 "layout(binding = 0) uniform windowDimensions {\n"
4067 " vec4 dimensions;\n"
4068 "};\n"
4069
4070 "layout(location = 0) in vec4 inColor;\n"
4071 "layout(origin_upper_left) in vec4 gl_FragCoord;\n"
GregFd6ebdb32015-06-03 18:40:50 -06004072 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06004073
4074 "void main() {\n"
4075
4076 // discard to make a nice circle
4077 " vec2 pos = abs(gl_FragCoord.xy) - vec2(dimensions.x, dimensions.y) / 2;\n"
4078 " float dist = sqrt(dot(pos, pos));\n"
4079 " if (dist > 50.0)\n"
4080 " discard;\n"
4081
GregFd6ebdb32015-06-03 18:40:50 -06004082 " outColor = inColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06004083
4084 "}\n";
4085
4086
4087
4088 ASSERT_NO_FATAL_FAILURE(InitState());
4089 ASSERT_NO_FATAL_FAILURE(InitViewport());
4090
4091 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
4092 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
4093 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
4094
4095 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004096 pipelineobj.AddColorAttachment();
Cody Northropa44c2ff2015-04-15 11:19:06 -06004097 pipelineobj.AddShader(&vs);
4098 pipelineobj.AddShader(&gs);
4099 pipelineobj.AddShader(&ps);
4100
4101 const float dimensions[4] = { VkRenderFramework::m_width, VkRenderFramework::m_height , 0.0, 0.0};
4102
4103 VkConstantBufferObj windowDimensions(m_device, sizeof(dimensions) / sizeof(dimensions[0]), sizeof(dimensions[0]), (const void*) dimensions);
4104
4105 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06004106 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropa44c2ff2015-04-15 11:19:06 -06004107
4108 VkDescriptorSetObj descriptorSet(m_device);
4109 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, windowDimensions);
4110
Tony Barbour1490c912015-07-28 10:17:20 -06004111 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northropa44c2ff2015-04-15 11:19:06 -06004112
4113 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06004114 Draw(0, 3, 0, 1);
Cody Northropa44c2ff2015-04-15 11:19:06 -06004115
4116 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06004117 EndCommandBuffer();
4118 QueueCommandBuffer();
Cody Northropa44c2ff2015-04-15 11:19:06 -06004119
4120 RecordImages(m_renderTargets);
4121}
4122
Chris Forbes23e6db62015-06-15 09:32:35 +12004123TEST_F(VkRenderTest, RenderPassLoadOpClear)
4124{
4125 ASSERT_NO_FATAL_FAILURE(InitState());
4126 ASSERT_NO_FATAL_FAILURE(InitViewport());
4127
4128 /* clear via load op to full green */
4129 m_clear_via_load_op = true;
Cody Northrop2563a032015-08-25 15:26:38 -06004130 m_clear_color.float32[0] = 0;
4131 m_clear_color.float32[1] = 1;
4132 m_clear_color.float32[2] = 0;
4133 m_clear_color.float32[3] = 0;
Chris Forbes23e6db62015-06-15 09:32:35 +12004134 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06004135 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Chris Forbes23e6db62015-06-15 09:32:35 +12004136 /* This command buffer contains ONLY the load op! */
Tony Barbour1490c912015-07-28 10:17:20 -06004137 EndCommandBuffer();
4138 QueueCommandBuffer();
Chris Forbes23e6db62015-06-15 09:32:35 +12004139
4140 RecordImages(m_renderTargets);
4141}
4142
Chris Forbes1e16cb82015-06-24 12:05:30 +12004143TEST_F(VkRenderTest, RenderPassAttachmentClear)
4144{
4145 ASSERT_NO_FATAL_FAILURE(InitState());
4146 ASSERT_NO_FATAL_FAILURE(InitViewport());
4147
4148 /* clear via load op to full red */
4149 m_clear_via_load_op = true;
Cody Northrop2563a032015-08-25 15:26:38 -06004150 m_clear_color.float32[0] = 1;
4151 m_clear_color.float32[1] = 0;
4152 m_clear_color.float32[2] = 0;
4153 m_clear_color.float32[3] = 0;
Chris Forbes1e16cb82015-06-24 12:05:30 +12004154 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06004155 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Chris Forbes1e16cb82015-06-24 12:05:30 +12004156
4157 /* Load op has cleared to red */
4158
4159 /* Draw, draw, draw... */
4160
4161 /* Now, partway through this renderpass we want to clear the color
4162 * attachment again, this time to green.
4163 */
Chris Forbese3105972015-06-24 14:34:53 +12004164 VkClearColorValue clear_color;
Cody Northrop2563a032015-08-25 15:26:38 -06004165 clear_color.float32[0] = 0;
4166 clear_color.float32[1] = 1;
4167 clear_color.float32[2] = 0;
4168 clear_color.float32[3] = 0;
Chris Forbes1e16cb82015-06-24 12:05:30 +12004169 VkRect3D clear_rect = { { 0, 0, 0 }, { (int)m_width, (int)m_height, 1 } };
Tony Barbour1490c912015-07-28 10:17:20 -06004170 vkCmdClearColorAttachment(m_cmdBuffer->handle(), 0,
Chris Forbes1e16cb82015-06-24 12:05:30 +12004171 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4172 &clear_color, 1, &clear_rect);
4173
Tony Barbour1490c912015-07-28 10:17:20 -06004174 EndCommandBuffer();
4175 QueueCommandBuffer();
Chris Forbes1e16cb82015-06-24 12:05:30 +12004176
4177 RecordImages(m_renderTargets);
4178}
4179
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004180int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004181 int result;
4182
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004183 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06004184 VkTestFramework::InitArgs(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004185
Chia-I Wu7133fdc2014-12-15 23:57:34 +08004186 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06004187
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004188 result = RUN_ALL_TESTS();
4189
Tony Barbour01999182015-04-09 12:58:51 -06004190 VkTestFramework::Finish();
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004191 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004192}