blob: 3d763cf4fc8856f3f5ad8d849b4d1a950726af57 [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 Northrope4bc6942015-08-26 10:01:32 -0600387 cmdBuffer->BindDynamicLineWidthState(m_stateLineWidth);
388 cmdBuffer->BindDynamicDepthBiasState(m_stateDepthBias);
Tony Barboure84a8d62015-07-10 14:10:27 -0600389 cmdBuffer->BindDynamicViewportState(m_stateViewport);
Cody Northrope4bc6942015-08-26 10:01:32 -0600390 cmdBuffer->BindDynamicBlendState(m_stateBlend);
391 cmdBuffer->BindDynamicDepthBoundsState(m_stateDepthBounds);
Cody Northrop2605cb02015-08-18 15:21:16 -0600392 cmdBuffer->BindDynamicStencilState(m_stateStencil);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600393 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
Cody Northropccfa96d2015-08-27 10:20:35 -0600394 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
395 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600396 cmdBuffer->BindPipeline(pipelineobj);
Chia-I Wu862c5572015-03-28 15:23:55 +0800397 cmdBuffer->BindDescriptorSet(descriptorSet);
Tony Barbour02472db2015-01-08 17:08:28 -0700398}
Tony Barbourf43b6982014-11-25 13:18:32 -0700399
Tony Barbour01999182015-04-09 12:58:51 -0600400void VkRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
401 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer)
Tony Barbourdd4c9642015-01-09 12:55:14 -0700402{
403 int i;
404 glm::mat4 MVP;
405 int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600406 VkResult err;
Tony Barbourdd4c9642015-01-09 12:55:14 -0700407
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600408 /* Only do 3 positions to avoid back face cull */
409 for (i = 0; i < 3; i++) {
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800410 void *pData = constantBuffer->memory().map();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700411
412 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
413 MVP = Projection * View * Model;
414 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
415
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800416 constantBuffer->memory().unmap();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700417
418 // submit the command buffer to the universal queue
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600419 cmdBuffer->QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700420
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600421 err = vkQueueWaitIdle( m_device->m_queue );
422 ASSERT_VK_SUCCESS( err );
Tony Barbourdd4c9642015-01-09 12:55:14 -0700423
424 // Wait for work to finish before cleaning up.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600425 vkDeviceWaitIdle(m_device->device());
Tony Barbourdd4c9642015-01-09 12:55:14 -0700426
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700427 assert(m_renderTargets.size() == 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -0700428 RecordImage(m_renderTargets[0]);
429 }
430}
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600431
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600432void dumpMatrix(const char *note, glm::mat4 MVP)
433{
Chia-I Wu7133fdc2014-12-15 23:57:34 +0800434 int i;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600435
436 printf("%s: \n", note);
437 for (i=0; i<4; i++) {
438 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
439 }
440 printf("\n");
441 fflush(stdout);
442}
443
444void dumpVec4(const char *note, glm::vec4 vector)
445{
446 printf("%s: \n", note);
447 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
448 printf("\n");
449 fflush(stdout);
450}
451
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600452struct vktriangle_vs_uniform {
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600453 // Must start with MVP
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600454 float mvp[4][4];
455 float position[3][4];
456 float color[3][4];
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600457};
458
Tony Barbour01999182015-04-09 12:58:51 -0600459void VkRenderTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600460{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700461#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600462 vkDbgRegisterMsgCallback(inst, myDbgFunc, NULL);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700463#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600464 // Create identity matrix
465 int i;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600466 struct vktriangle_vs_uniform data;
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600467
468 glm::mat4 Projection = glm::mat4(1.0f);
469 glm::mat4 View = glm::mat4(1.0f);
470 glm::mat4 Model = glm::mat4(1.0f);
471 glm::mat4 MVP = Projection * View * Model;
472 const int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600473 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600474 memcpy(&data.mvp, &MVP[0][0], matrixSize);
475
476 static const Vertex tri_data[] =
477 {
478 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
479 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
480 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
481 };
482
483 for (i=0; i<3; i++) {
484 data.position[i][0] = tri_data[i].posX;
485 data.position[i][1] = tri_data[i].posY;
486 data.position[i][2] = tri_data[i].posZ;
487 data.position[i][3] = tri_data[i].posW;
488 data.color[i][0] = tri_data[i].r;
489 data.color[i][1] = tri_data[i].g;
490 data.color[i][2] = tri_data[i].b;
491 data.color[i][3] = tri_data[i].a;
492 }
493
Tony Barbourf43b6982014-11-25 13:18:32 -0700494 ASSERT_NO_FATAL_FAILURE(InitState());
495 ASSERT_NO_FATAL_FAILURE(InitViewport());
496
Tony Barbour01999182015-04-09 12:58:51 -0600497 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barbourf43b6982014-11-25 13:18:32 -0700498
Tony Barbour01999182015-04-09 12:58:51 -0600499 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
500 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700501
Tony Barbour01999182015-04-09 12:58:51 -0600502 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800503 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -0700504 pipelineobj.AddShader(&vs);
505 pipelineobj.AddShader(&ps);
506
Tony Barbour01999182015-04-09 12:58:51 -0600507 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600508 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700509
Tony Barbour71ba3612015-01-09 16:12:35 -0700510 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis7f7b4422015-08-18 14:24:32 -0600511
512 VkCmdBufferBeginInfo cbBeginInfo;
513 memset(&cbBeginInfo, 0, sizeof(VkCmdBufferBeginInfo));
514 cbBeginInfo.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
515 cbBeginInfo.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT;
516 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barbourf43b6982014-11-25 13:18:32 -0700517
Tony Barbour1490c912015-07-28 10:17:20 -0600518 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour71ba3612015-01-09 16:12:35 -0700519#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600520 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour71ba3612015-01-09 16:12:35 -0700521 pDSDumpDot((char*)"triTest2.dot");
522#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600523
Tony Barbour71ba3612015-01-09 16:12:35 -0700524 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -0600525 Draw(0, 3, 0, 1);
Tony Barbour71ba3612015-01-09 16:12:35 -0700526
527 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600528 ASSERT_VK_SUCCESS(EndCommandBuffer());
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600529
Tony Barbour1490c912015-07-28 10:17:20 -0600530 QueueCommandBuffer();
Tony Barbour71ba3612015-01-09 16:12:35 -0700531
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600532 RecordImages(m_renderTargets);
Tony Barbour71ba3612015-01-09 16:12:35 -0700533
534 if (rotate)
Tony Barbour1490c912015-07-28 10:17:20 -0600535 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer);
Tony Barbour71ba3612015-01-09 16:12:35 -0700536
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700537#ifdef PRINT_OBJECTS
Mark Lobodzinski4e5016f2015-05-05 15:01:37 -0500538 OBJ_TRACK_GET_OBJECTS_COUNT pObjTrackGetObjectsCount = (OBJ_TRACK_GET_OBJECTS_COUNT)vkGetProcAddr(gpu(), (char*)"objTrackGetObjectsCount");
Mark Lobodzinski14305ad2015-06-23 11:35:12 -0600539 uint64_t numObjects = pObjTrackGetObjectsCount(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600540 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700541 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600542 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700543 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
Mark Lobodzinski14305ad2015-06-23 11:35:12 -0600544 pObjTrackGetObjs(m_device, numObjects, pObjNodeArray);
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700545 for (i=0; i < numObjects; i++) {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600546 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 -0700547 }
548 free(pObjNodeArray);
549#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700550
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600551}
552
Tony Barbour01999182015-04-09 12:58:51 -0600553TEST_F(VkRenderTest, VKTriangle_FragColor)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600554{
555 static const char *vertShaderText =
556 "#version 140\n"
557 "#extension GL_ARB_separate_shader_objects : enable\n"
558 "#extension GL_ARB_shading_language_420pack : enable\n"
559 "\n"
560 "layout(binding = 0) uniform buf {\n"
561 " mat4 MVP;\n"
562 " vec4 position[3];\n"
563 " vec4 color[3];\n"
564 "} ubuf;\n"
565 "\n"
566 "layout (location = 0) out vec4 outColor;\n"
567 "\n"
568 "void main() \n"
569 "{\n"
570 " outColor = ubuf.color[gl_VertexID];\n"
571 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
572 "}\n";
573
574 static const char *fragShaderText =
575 "#version 140\n"
576 "#extension GL_ARB_separate_shader_objects : enable\n"
577 "#extension GL_ARB_shading_language_420pack : enable\n"
578 "\n"
579 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600580 "layout (location = 0) out vec4 uFragColor;\n"
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600581 "\n"
582 "void main()\n"
583 "{\n"
GregFd6ebdb32015-06-03 18:40:50 -0600584 " uFragColor = inColor;\n"
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600585 "}\n";
586
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600587 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
588 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600589}
590
Tony Barbour01999182015-04-09 12:58:51 -0600591TEST_F(VkRenderTest, VKTriangle_OutputLocation)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600592{
593 static const char *vertShaderText =
594 "#version 140\n"
595 "#extension GL_ARB_separate_shader_objects : enable\n"
596 "#extension GL_ARB_shading_language_420pack : enable\n"
597 "\n"
598 "layout(binding = 0) uniform buf {\n"
599 " mat4 MVP;\n"
600 " vec4 position[3];\n"
601 " vec4 color[3];\n"
602 "} ubuf;\n"
603 "\n"
604 "layout (location = 0) out vec4 outColor;\n"
605 "\n"
606 "void main() \n"
607 "{\n"
608 " outColor = ubuf.color[gl_VertexID];\n"
609 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
610 "}\n";
611
612 static const char *fragShaderText =
613 "#version 140\n"
614 "#extension GL_ARB_separate_shader_objects : enable\n"
615 "#extension GL_ARB_shading_language_420pack : enable\n"
616 "\n"
617 "layout (location = 0) in vec4 inColor;\n"
618 "layout (location = 0) out vec4 outColor;\n"
619 "\n"
620 "void main()\n"
621 "{\n"
622 " outColor = inColor;\n"
623 "}\n";
624
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600625 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 -0600626
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600627 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600628}
Cody Northrop71727d22015-06-23 13:25:51 -0600629
Tony Barbour01999182015-04-09 12:58:51 -0600630TEST_F(VkRenderTest, SPV_VKTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700631{
Tony Barbourf43b6982014-11-25 13:18:32 -0700632 static const char *vertShaderText =
633 "#version 140\n"
634 "#extension GL_ARB_separate_shader_objects : enable\n"
635 "#extension GL_ARB_shading_language_420pack : enable\n"
636 "\n"
637 "layout(binding = 0) uniform buf {\n"
638 " mat4 MVP;\n"
639 " vec4 position[3];\n"
640 " vec4 color[3];\n"
641 "} ubuf;\n"
642 "\n"
643 "layout (location = 0) out vec4 outColor;\n"
644 "\n"
645 "void main() \n"
646 "{\n"
647 " outColor = ubuf.color[gl_VertexID];\n"
648 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
649 "}\n";
650
651 static const char *fragShaderText =
652 "#version 140\n"
653 "#extension GL_ARB_separate_shader_objects : enable\n"
654 "#extension GL_ARB_shading_language_420pack : enable\n"
655 "\n"
656 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600657 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700658 "\n"
659 "void main()\n"
660 "{\n"
GregFd6ebdb32015-06-03 18:40:50 -0600661 " outColor = inColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700662 "}\n";
663
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600664 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 -0700665
Cody Northrop1cfbd172015-06-03 16:49:20 -0600666 ScopedUseGlsl useGlsl(false);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600667 VKTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700668}
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600669
Tony Barbour01999182015-04-09 12:58:51 -0600670TEST_F(VkRenderTest, SPV_GreenTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700671{
Tony Barbourf43b6982014-11-25 13:18:32 -0700672 static const char *vertShaderText =
673 "#version 130\n"
674 "vec2 vertices[3];\n"
675 "void main() {\n"
676 " vertices[0] = vec2(-1.0, -1.0);\n"
677 " vertices[1] = vec2( 1.0, -1.0);\n"
678 " vertices[2] = vec2( 0.0, 1.0);\n"
679 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
680 "}\n";
681
682 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600683 "#version 140\n"
684 "#extension GL_ARB_separate_shader_objects : enable\n"
685 "#extension GL_ARB_shading_language_420pack : enable\n"
686 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700687 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600688 " outColor = vec4(0,1,0,1);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700689 "}\n";
690
Cody Northropacfb0492015-03-17 15:55:58 -0600691 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700692
Cody Northrop1cfbd172015-06-03 16:49:20 -0600693 ScopedUseGlsl useGlsl(false);
694
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600695 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700696}
Cody Northrop71727d22015-06-23 13:25:51 -0600697
Tony Barbour01999182015-04-09 12:58:51 -0600698TEST_F(VkRenderTest, YellowTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700699{
700 static const char *vertShaderText =
701 "#version 130\n"
702 "void main() {\n"
703 " vec2 vertices[3];"
704 " vertices[0] = vec2(-0.5, -0.5);\n"
705 " vertices[1] = vec2( 0.5, -0.5);\n"
706 " vertices[2] = vec2( 0.5, 0.5);\n"
707 " vec4 colors[3];\n"
708 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
709 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
710 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
711 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
712 "}\n";
713
714 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600715 "#version 140\n"
716 "#extension GL_ARB_separate_shader_objects : enable\n"
717 "#extension GL_ARB_shading_language_420pack : enable\n"
718 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700719 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600720 " outColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700721 "}\n";
722
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600723 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700724}
725
Tony Barbour01999182015-04-09 12:58:51 -0600726TEST_F(VkRenderTest, QuadWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600727{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600728 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600729 "#version 140\n"
730 "#extension GL_ARB_separate_shader_objects : enable\n"
731 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700732 //XYZ1( -1, -1, -1 )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600733 "layout (location = 0) in vec4 pos;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700734 //XYZ1( 0.f, 0.f, 0.f )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600735 "layout (location = 1) in vec4 inColor;\n"
736 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600737 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600738 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600739 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600740 "}\n";
741
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600742
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600743 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700744 "#version 140\n"
745 "#extension GL_ARB_separate_shader_objects : enable\n"
746 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600747 "layout (location = 0) in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700748 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600749 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700750 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600751 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600752
Tony Barbourf43b6982014-11-25 13:18:32 -0700753
754
755 ASSERT_NO_FATAL_FAILURE(InitState());
756 ASSERT_NO_FATAL_FAILURE(InitViewport());
757
Tony Barbour01999182015-04-09 12:58:51 -0600758 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000759 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700760
Tony Barbour01999182015-04-09 12:58:51 -0600761 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
762 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700763
Tony Barbour01999182015-04-09 12:58:51 -0600764 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800765 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -0700766 pipelineobj.AddShader(&vs);
767 pipelineobj.AddShader(&ps);
768
Tony Barbour01999182015-04-09 12:58:51 -0600769 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600770 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -0600771
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600772#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600773 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600774 MESH_BIND_ID, // binding ID
Tony Barbourf43b6982014-11-25 13:18:32 -0700775 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600776 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -0700777 };
778
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600779 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600780 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
781 vi_attribs[0].location = 0; // location, position
Tony Barbour8205d902015-04-16 15:59:00 -0600782 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600783 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
784 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
785 vi_attribs[1].location = 1; // location, color
Tony Barbour8205d902015-04-16 15:59:00 -0600786 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600787 vi_attribs[1].offsetInBytes = 1*sizeof(float)*4; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -0700788
789 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
790 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600791 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -0700792
Tony Barboure4ed9942015-01-09 10:06:53 -0700793 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -0600794 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourf43b6982014-11-25 13:18:32 -0700795
Tony Barbour1490c912015-07-28 10:17:20 -0600796 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600797
Tony Barbour1490c912015-07-28 10:17:20 -0600798 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barboure4ed9942015-01-09 10:06:53 -0700799
800 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -0600801 Draw(0, 6, 0, 1);
Tony Barboure4ed9942015-01-09 10:06:53 -0700802
803 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600804 ASSERT_VK_SUCCESS(EndCommandBuffer());
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600805
Tony Barbour1490c912015-07-28 10:17:20 -0600806 QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -0700807
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600808 RecordImages(m_renderTargets);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600809}
810
Tony Barbour01999182015-04-09 12:58:51 -0600811TEST_F(VkRenderTest, TriangleMRT)
Chia-I Wue09d1a72014-12-05 10:32:23 +0800812{
813 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600814 "#version 140\n"
815 "#extension GL_ARB_separate_shader_objects : enable\n"
816 "#extension GL_ARB_shading_language_420pack : enable\n"
817 "layout (location = 0) in vec4 pos;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800818 "void main() {\n"
819 " gl_Position = pos;\n"
820 "}\n";
821
822 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600823 "#version 140\n"
824 "#extension GL_ARB_separate_shader_objects : enable\n"
825 "#extension GL_ARB_shading_language_420pack : enable\n"
826 "layout (location = 0) out vec4 uFragData0;\n"
827 "layout (location = 1) out vec4 uFragData1;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800828 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600829 " uFragData0 = vec4(1.0, 0.0, 0.0, 1.0);\n"
830 " uFragData1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800831 "}\n";
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600832 const float vb_data[][2] = {
Chia-I Wue09d1a72014-12-05 10:32:23 +0800833 { -1.0f, -1.0f },
834 { 1.0f, -1.0f },
835 { -1.0f, 1.0f }
836 };
837
838 ASSERT_NO_FATAL_FAILURE(InitState());
839 ASSERT_NO_FATAL_FAILURE(InitViewport());
840
Tony Barbour01999182015-04-09 12:58:51 -0600841 VkConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000842 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800843
Tony Barbour01999182015-04-09 12:58:51 -0600844 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
845 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800846
Tony Barbour01999182015-04-09 12:58:51 -0600847 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800848 pipelineobj.AddColorAttachment();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800849 pipelineobj.AddShader(&vs);
850 pipelineobj.AddShader(&ps);
851
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600852#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600853 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600854 MESH_BUF_ID, // Binding ID
855 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600856 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Chia-I Wue09d1a72014-12-05 10:32:23 +0800857 };
858
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600859 VkVertexInputAttributeDescription vi_attrib;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600860 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
861 vi_attrib.location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -0600862 vi_attrib.format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600863 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
Chia-I Wue09d1a72014-12-05 10:32:23 +0800864
865 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
866 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600867 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800868
Tony Barbour01999182015-04-09 12:58:51 -0600869 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600870 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800871
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700872 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
Chia-I Wue09d1a72014-12-05 10:32:23 +0800873
Tony Barboure307f582015-07-10 15:29:03 -0600874 VkPipelineColorBlendAttachmentState att = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600875 att.blendEnable = VK_FALSE;
Chia-I Wue09d1a72014-12-05 10:32:23 +0800876 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700877 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800878
Tony Barbour1490c912015-07-28 10:17:20 -0600879 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure4ed9942015-01-09 10:06:53 -0700880
Tony Barbour1490c912015-07-28 10:17:20 -0600881 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700882
Tony Barbour1490c912015-07-28 10:17:20 -0600883 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700884#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600885 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour5ed79702015-01-07 14:31:52 -0700886 pDSDumpDot((char*)"triTest2.dot");
887#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600888
Tony Barbour5ed79702015-01-07 14:31:52 -0700889 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -0600890 Draw(0, 3, 0, 1);
Tony Barbour5ed79702015-01-07 14:31:52 -0700891
892 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600893 ASSERT_VK_SUCCESS(EndCommandBuffer());
894 QueueCommandBuffer();
Tony Barbour5ed79702015-01-07 14:31:52 -0700895
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600896 RecordImages(m_renderTargets);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800897}
898
Tony Barbour01999182015-04-09 12:58:51 -0600899TEST_F(VkRenderTest, QuadWithIndexedVertexFetch)
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700900{
901 static const char *vertShaderText =
902 "#version 140\n"
903 "#extension GL_ARB_separate_shader_objects : enable\n"
904 "#extension GL_ARB_shading_language_420pack : enable\n"
905 "layout(location = 0) in vec4 pos;\n"
906 "layout(location = 1) in vec4 inColor;\n"
907 "layout(location = 0) out vec4 outColor;\n"
908 "void main() {\n"
909 " outColor = inColor;\n"
910 " gl_Position = pos;\n"
911 "}\n";
912
913
914 static const char *fragShaderText =
915 "#version 140\n"
916 "#extension GL_ARB_separate_shader_objects : enable\n"
917 "#extension GL_ARB_shading_language_420pack : enable\n"
918 "layout(location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600919 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700920 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600921 " outColor = color;\n"
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700922 "}\n";
923
924 const Vertex g_vbData[] =
925 {
926 // first tri
927 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
928 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
929 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
930
931 // second tri
932 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
933 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
934 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
935 };
936
937 const uint16_t g_idxData[6] = {
938 0, 1, 2,
939 3, 4, 5,
940 };
941
942 ASSERT_NO_FATAL_FAILURE(InitState());
943 ASSERT_NO_FATAL_FAILURE(InitViewport());
944
Tony Barbour01999182015-04-09 12:58:51 -0600945 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000946 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700947
Tony Barbour01999182015-04-09 12:58:51 -0600948 VkIndexBufferObj indexBuffer(m_device);
Tony Barbour8205d902015-04-16 15:59:00 -0600949 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), VK_INDEX_TYPE_UINT16, g_idxData);
Mark Lobodzinskid30f82a2015-02-16 14:24:23 -0600950 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700951
Tony Barbour01999182015-04-09 12:58:51 -0600952 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
953 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700954
Tony Barbour01999182015-04-09 12:58:51 -0600955 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800956 pipelineobj.AddColorAttachment();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700957 pipelineobj.AddShader(&vs);
958 pipelineobj.AddShader(&ps);
959
Tony Barbour01999182015-04-09 12:58:51 -0600960 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600961 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
962 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, indexBuffer);
Tony Barbour83a83802015-04-02 15:43:15 -0600963
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700964
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600965#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600966 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600967 MESH_BIND_ID, // binding ID
968 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600969 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700970 };
971
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600972 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600973 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
974 vi_attribs[0].location = 0; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600975 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600976 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
977 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
978 vi_attribs[1].location = 1; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600979 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600980 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700981
982 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
983 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700984
985 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -0600986 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure4ed9942015-01-09 10:06:53 -0700987
Tony Barbour1490c912015-07-28 10:17:20 -0600988 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700989
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700990#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600991 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700992 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700993#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700994
Tony Barbour1490c912015-07-28 10:17:20 -0600995 BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
996 BindIndexBuffer(&indexBuffer, 0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700997
998 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -0600999 DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001000
1001 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001002 ASSERT_VK_SUCCESS(EndCommandBuffer());
1003 QueueCommandBuffer();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001004
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001005 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001006}
1007
Tony Barbour01999182015-04-09 12:58:51 -06001008TEST_F(VkRenderTest, GreyandRedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -07001009{
1010 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -07001011
GregF6bef1212014-12-02 15:41:44 -07001012 static const char *vertShaderText =
1013 "#version 140\n"
1014 "#extension GL_ARB_separate_shader_objects : enable\n"
1015 "#extension GL_ARB_shading_language_420pack : enable\n"
1016 "layout (location = 0) in vec4 pos;\n"
1017 "layout (location = 0) out vec4 outColor;\n"
1018 "layout (location = 1) out vec4 outColor2;\n"
1019 "void main() {\n"
1020 " gl_Position = pos;\n"
1021 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1022 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1023 "}\n";
1024
1025 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001026 "#version 330\n"
1027 "#extension GL_ARB_separate_shader_objects : enable\n"
1028 "#extension GL_ARB_shading_language_420pack : enable\n"
1029 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1030 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1031 "layout (location = 0) in vec4 color;\n"
1032 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001033 "layout (location = 0) out vec4 outColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001034 "void main() {\n"
1035 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1036 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001037 " outColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001038 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1039 " : color2;\n"
1040 "}\n";
1041
1042 ASSERT_NO_FATAL_FAILURE(InitState());
1043 ASSERT_NO_FATAL_FAILURE(InitViewport());
1044
Tony Barbour01999182015-04-09 12:58:51 -06001045 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001046 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001047
Tony Barbour01999182015-04-09 12:58:51 -06001048 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1049 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001050
Tony Barbour01999182015-04-09 12:58:51 -06001051 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001052 pipelineobj.AddColorAttachment();
GregF6bef1212014-12-02 15:41:44 -07001053 pipelineobj.AddShader(&vs);
1054 pipelineobj.AddShader(&ps);
1055
Tony Barbour01999182015-04-09 12:58:51 -06001056 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001057 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001058
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001059#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001060 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001061 MESH_BIND_ID, // binding ID
1062 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001063 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001064 };
1065
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001066 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001067 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1068 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001069 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001070 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001071
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001072 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001073 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001074 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001075
Tony Barbourdd4c9642015-01-09 12:55:14 -07001076 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001077
Tony Barbour1490c912015-07-28 10:17:20 -06001078 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001079
Tony Barbour1490c912015-07-28 10:17:20 -06001080 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001081
Tony Barbour1490c912015-07-28 10:17:20 -06001082 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001083#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001084 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001085 pDSDumpDot((char*)"triTest2.dot");
1086#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001087
Tony Barbourdd4c9642015-01-09 12:55:14 -07001088 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06001089 Draw(0, 6, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001090
1091 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001092 EndCommandBuffer();
1093 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001094
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001095 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001096}
1097
Tony Barbour01999182015-04-09 12:58:51 -06001098TEST_F(VkRenderTest, RedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -07001099{
1100 // This tests that we correctly handle unread fragment inputs
1101
1102 static const char *vertShaderText =
1103 "#version 140\n"
1104 "#extension GL_ARB_separate_shader_objects : enable\n"
1105 "#extension GL_ARB_shading_language_420pack : enable\n"
1106 "layout (location = 0) in vec4 pos;\n"
1107 "layout (location = 0) out vec4 outColor;\n"
1108 "layout (location = 1) out vec4 outColor2;\n"
1109 "void main() {\n"
1110 " gl_Position = pos;\n"
1111 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1112 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1113 "}\n";
1114
1115 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001116 "#version 330\n"
1117 "#extension GL_ARB_separate_shader_objects : enable\n"
1118 "#extension GL_ARB_shading_language_420pack : enable\n"
1119 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1120 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1121 "layout (location = 0) in vec4 color;\n"
1122 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001123 "layout (location = 0) out vec4 outColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001124 "void main() {\n"
1125 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1126 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001127 " outColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001128 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1129 " : color2;\n"
1130 "}\n";
1131
1132 ASSERT_NO_FATAL_FAILURE(InitState());
1133 ASSERT_NO_FATAL_FAILURE(InitViewport());
1134
Tony Barbour01999182015-04-09 12:58:51 -06001135 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001136 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001137
Tony Barbour01999182015-04-09 12:58:51 -06001138 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1139 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001140
Tony Barbour01999182015-04-09 12:58:51 -06001141 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001142 pipelineobj.AddColorAttachment();
GregF6bef1212014-12-02 15:41:44 -07001143 pipelineobj.AddShader(&vs);
1144 pipelineobj.AddShader(&ps);
1145
Tony Barbour01999182015-04-09 12:58:51 -06001146 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001147 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001148
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001149#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001150 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001151 MESH_BIND_ID, // binding ID
1152 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001153 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001154 };
1155
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001156 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001157 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1158 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001159 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001160 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001161
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001162 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001163 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001164 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001165
Tony Barbourdd4c9642015-01-09 12:55:14 -07001166 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06001167 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001168
Tony Barbour1490c912015-07-28 10:17:20 -06001169 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001170
Tony Barbour1490c912015-07-28 10:17:20 -06001171 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001172#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001173 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001174 pDSDumpDot((char*)"triTest2.dot");
1175#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001176 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001177 Draw(0, 6, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001178
1179 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001180 EndCommandBuffer();
1181 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001182
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001183 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001184}
1185
Tony Barbour01999182015-04-09 12:58:51 -06001186TEST_F(VkRenderTest, GreyCirclesonBlueFade)
GregF6bef1212014-12-02 15:41:44 -07001187{
1188 // This tests reading gl_ClipDistance from FS
1189
1190 static const char *vertShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001191 //"#version 140\n"
GregF6bef1212014-12-02 15:41:44 -07001192 "#version 330\n"
1193 "#extension GL_ARB_separate_shader_objects : enable\n"
1194 "#extension GL_ARB_shading_language_420pack : enable\n"
1195 "out gl_PerVertex {\n"
1196 " vec4 gl_Position;\n"
1197 " float gl_ClipDistance[1];\n"
1198 "};\n"
1199 "layout (location = 0) in vec4 pos;\n"
1200 "layout (location = 0) out vec4 outColor;\n"
1201 "layout (location = 1) out vec4 outColor2;\n"
1202 "void main() {\n"
1203 " gl_Position = pos;\n"
1204 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1205 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1206 " float dists[3];\n"
1207 " dists[0] = 0.0;\n"
1208 " dists[1] = 1.0;\n"
1209 " dists[2] = 1.0;\n"
1210 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1211 "}\n";
1212
1213
1214 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001215 "#version 140\n"
1216 //"#version 330\n"
GregF6bef1212014-12-02 15:41:44 -07001217 "#extension GL_ARB_separate_shader_objects : enable\n"
1218 "#extension GL_ARB_shading_language_420pack : enable\n"
1219 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1220 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1221 "layout (location = 0) in vec4 color;\n"
1222 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001223 "layout (location = 0) out vec4 uFragColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001224 "void main() {\n"
1225 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1226 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001227 " uFragColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001228 " ? color * gl_ClipDistance[0]\n"
1229 " : color2;\n"
1230 "}\n";
1231
1232 ASSERT_NO_FATAL_FAILURE(InitState());
1233 ASSERT_NO_FATAL_FAILURE(InitViewport());
1234
Tony Barbour01999182015-04-09 12:58:51 -06001235 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001236 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001237
Tony Barbour01999182015-04-09 12:58:51 -06001238 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1239 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001240
Tony Barbour01999182015-04-09 12:58:51 -06001241 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001242 pipelineobj.AddColorAttachment();
GregF6bef1212014-12-02 15:41:44 -07001243 pipelineobj.AddShader(&vs);
1244 pipelineobj.AddShader(&ps);
1245
Tony Barbour01999182015-04-09 12:58:51 -06001246 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001247 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001248
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001249#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001250 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001251 MESH_BIND_ID, // binding ID
1252 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001253 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001254 };
1255
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001256 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001257 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1258 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001259 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001260 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001261
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001262 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001263 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001264 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001265
Tony Barbourdd4c9642015-01-09 12:55:14 -07001266 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
GregF6bef1212014-12-02 15:41:44 -07001267
Tony Barbour1490c912015-07-28 10:17:20 -06001268 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001269
Tony Barbour1490c912015-07-28 10:17:20 -06001270 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001271
Tony Barbour1490c912015-07-28 10:17:20 -06001272 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001273#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001274 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001275 pDSDumpDot((char*)"triTest2.dot");
1276#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001277
1278 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001279 Draw(0, 6, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001280
1281 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001282 EndCommandBuffer();
1283 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001284
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001285 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001286}
Tony Barbourf43b6982014-11-25 13:18:32 -07001287
Tony Barbour01999182015-04-09 12:58:51 -06001288TEST_F(VkRenderTest, GreyCirclesonBlueDiscard)
GregF7a23c792014-12-02 17:19:34 -07001289{
1290 static const char *vertShaderText =
1291 "#version 140\n"
1292 "#extension GL_ARB_separate_shader_objects : enable\n"
1293 "#extension GL_ARB_shading_language_420pack : enable\n"
1294 "layout (location = 0) in vec4 pos;\n"
1295 "layout (location = 0) out vec4 outColor;\n"
1296 "layout (location = 1) out vec4 outColor2;\n"
1297 "void main() {\n"
1298 " gl_Position = pos;\n"
1299 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1300 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1301 "}\n";
1302
1303
1304 static const char *fragShaderText =
GregF7a23c792014-12-02 17:19:34 -07001305 "#version 330\n"
1306 "#extension GL_ARB_separate_shader_objects : enable\n"
1307 "#extension GL_ARB_shading_language_420pack : enable\n"
1308 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1309 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1310 "layout (location = 0) in vec4 color;\n"
1311 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001312 "layout (location = 0) out vec4 outColor;\n"
GregF7a23c792014-12-02 17:19:34 -07001313 "void main() {\n"
1314 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1315 " float dist_squared = dot(pos, pos);\n"
1316 " if (dist_squared < 100.0)\n"
1317 " discard;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001318 " outColor = (dist_squared < 400.0)\n"
GregF7a23c792014-12-02 17:19:34 -07001319 " ? color\n"
1320 " : color2;\n"
1321 "}\n";
1322
1323 ASSERT_NO_FATAL_FAILURE(InitState());
1324 ASSERT_NO_FATAL_FAILURE(InitViewport());
1325
Tony Barbour01999182015-04-09 12:58:51 -06001326 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001327 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001328
Tony Barbour01999182015-04-09 12:58:51 -06001329 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1330 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF7a23c792014-12-02 17:19:34 -07001331
Tony Barbour01999182015-04-09 12:58:51 -06001332 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001333 pipelineobj.AddColorAttachment();
GregF7a23c792014-12-02 17:19:34 -07001334 pipelineobj.AddShader(&vs);
1335 pipelineobj.AddShader(&ps);
1336
Tony Barbour01999182015-04-09 12:58:51 -06001337 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001338 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001339
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001340#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001341 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001342 MESH_BIND_ID, // binding ID
1343 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001344 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF7a23c792014-12-02 17:19:34 -07001345 };
1346
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001347 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001348 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1349 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001350 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001351 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF7a23c792014-12-02 17:19:34 -07001352
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001353 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF7a23c792014-12-02 17:19:34 -07001354 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001355 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF7a23c792014-12-02 17:19:34 -07001356
Tony Barbourdd4c9642015-01-09 12:55:14 -07001357 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001358
Tony Barbour1490c912015-07-28 10:17:20 -06001359 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001360
Tony Barbour1490c912015-07-28 10:17:20 -06001361 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001362
Tony Barbour1490c912015-07-28 10:17:20 -06001363 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001364#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001365 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001366 pDSDumpDot((char*)"triTest2.dot");
1367#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001368
1369 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001370 Draw(0, 6, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001371
1372 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001373 EndCommandBuffer();
1374 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001375
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001376 RecordImages(m_renderTargets);
GregF7a23c792014-12-02 17:19:34 -07001377}
1378
1379
Tony Barbour01999182015-04-09 12:58:51 -06001380TEST_F(VkRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001381{
1382 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001383 "#version 140\n"
1384 "#extension GL_ARB_separate_shader_objects : enable\n"
1385 "#extension GL_ARB_shading_language_420pack : enable\n"
1386 "\n"
1387 "layout(binding = 0) uniform buf {\n"
1388 " mat4 MVP;\n"
1389 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001390 "void main() {\n"
1391 " vec2 vertices[3];"
1392 " vertices[0] = vec2(-0.5, -0.5);\n"
1393 " vertices[1] = vec2( 0.5, -0.5);\n"
1394 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001395 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001396 "}\n";
1397
1398 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001399 "#version 140\n"
1400 "#extension GL_ARB_separate_shader_objects : enable\n"
1401 "#extension GL_ARB_shading_language_420pack : enable\n"
1402 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001403 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001404 " outColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001405 "}\n";
1406
Tony Barbourf43b6982014-11-25 13:18:32 -07001407 ASSERT_NO_FATAL_FAILURE(InitState());
1408 ASSERT_NO_FATAL_FAILURE(InitViewport());
1409
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001410 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001411 glm::mat4 Projection = glm::mat4(1.0f);
1412 glm::mat4 View = glm::mat4(1.0f);
1413 glm::mat4 Model = glm::mat4(1.0f);
1414 glm::mat4 MVP = Projection * View * Model;
1415 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1416
Tony Barbour01999182015-04-09 12:58:51 -06001417 VkConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1418 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1419 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001420
Tony Barbour01999182015-04-09 12:58:51 -06001421 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001422 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001423 pipelineobj.AddShader(&vs);
1424 pipelineobj.AddShader(&ps);
1425
1426 // Create descriptor set and attach the constant buffer to it
Tony Barbour01999182015-04-09 12:58:51 -06001427 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001428 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001429
Tony Barbourdd4c9642015-01-09 12:55:14 -07001430 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis7f7b4422015-08-18 14:24:32 -06001431
1432 VkCmdBufferBeginInfo cbBeginInfo;
1433 memset(&cbBeginInfo, 0, sizeof(VkCmdBufferBeginInfo));
1434 cbBeginInfo.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1435 cbBeginInfo.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT;
1436 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barbourf43b6982014-11-25 13:18:32 -07001437
Tony Barbour1490c912015-07-28 10:17:20 -06001438 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001439
Tony Barbourdd4c9642015-01-09 12:55:14 -07001440#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001441 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001442 pDSDumpDot((char*)"triTest2.dot");
1443#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001444
1445 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001446 Draw(0, 6, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001447
1448 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001449 EndCommandBuffer();
1450 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001451
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001452 RecordImages(m_renderTargets);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001453
Tony Barbour1490c912015-07-28 10:17:20 -06001454 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001455}
1456
Tony Barbour01999182015-04-09 12:58:51 -06001457TEST_F(VkRenderTest, MixTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07001458{
1459 // This tests location applied to varyings. Notice that we have switched foo
1460 // and bar in the FS. The triangle should be blended with red, green and blue
1461 // corners.
1462 static const char *vertShaderText =
1463 "#version 140\n"
1464 "#extension GL_ARB_separate_shader_objects : enable\n"
1465 "#extension GL_ARB_shading_language_420pack : enable\n"
1466 "layout (location=0) out vec4 bar;\n"
1467 "layout (location=1) out vec4 foo;\n"
1468 "layout (location=2) out float scale;\n"
1469 "vec2 vertices[3];\n"
1470 "void main() {\n"
1471 " vertices[0] = vec2(-1.0, -1.0);\n"
1472 " vertices[1] = vec2( 1.0, -1.0);\n"
1473 " vertices[2] = vec2( 0.0, 1.0);\n"
1474 "vec4 colors[3];\n"
1475 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1476 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1477 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1478 " foo = colors[gl_VertexID % 3];\n"
1479 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1480 " scale = 1.0;\n"
1481 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1482 "}\n";
1483
1484 static const char *fragShaderText =
1485 "#version 140\n"
1486 "#extension GL_ARB_separate_shader_objects : enable\n"
1487 "#extension GL_ARB_shading_language_420pack : enable\n"
1488 "layout (location = 1) in vec4 bar;\n"
1489 "layout (location = 0) in vec4 foo;\n"
1490 "layout (location = 2) in float scale;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001491 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001492 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001493 " outColor = bar * scale + foo * (1.0-scale);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001494 "}\n";
1495
1496 ASSERT_NO_FATAL_FAILURE(InitState());
1497 ASSERT_NO_FATAL_FAILURE(InitViewport());
1498
Tony Barbour01999182015-04-09 12:58:51 -06001499 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1500 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001501
Tony Barbour01999182015-04-09 12:58:51 -06001502 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001503 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001504 pipelineobj.AddShader(&vs);
1505 pipelineobj.AddShader(&ps);
1506
Tony Barbour01999182015-04-09 12:58:51 -06001507 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06001508 descriptorSet.AppendDummy();
Tony Barbourf43b6982014-11-25 13:18:32 -07001509
Tony Barbourdd4c9642015-01-09 12:55:14 -07001510 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001511
Tony Barbour1490c912015-07-28 10:17:20 -06001512 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001513
Tony Barbour1490c912015-07-28 10:17:20 -06001514 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001515
1516#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001517 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001518 pDSDumpDot((char*)"triTest2.dot");
1519#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001520
Tony Barbourdd4c9642015-01-09 12:55:14 -07001521 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06001522 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001523
1524 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001525 EndCommandBuffer();
1526 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001527
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001528 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001529}
1530
Tony Barbour01999182015-04-09 12:58:51 -06001531TEST_F(VkRenderTest, QuadVertFetchAndVertID)
Tony Barbourf43b6982014-11-25 13:18:32 -07001532{
1533 // This tests that attributes work in the presence of gl_VertexID
1534
1535 static const char *vertShaderText =
1536 "#version 140\n"
1537 "#extension GL_ARB_separate_shader_objects : enable\n"
1538 "#extension GL_ARB_shading_language_420pack : enable\n"
1539 //XYZ1( -1, -1, -1 )
1540 "layout (location = 0) in vec4 pos;\n"
1541 //XYZ1( 0.f, 0.f, 0.f )
1542 "layout (location = 1) in vec4 inColor;\n"
1543 "layout (location = 0) out vec4 outColor;\n"
1544 "void main() {\n"
1545 " outColor = inColor;\n"
1546 " vec4 vertices[3];"
1547 " vertices[gl_VertexID % 3] = pos;\n"
1548 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1549 "}\n";
1550
1551
1552 static const char *fragShaderText =
1553 "#version 140\n"
1554 "#extension GL_ARB_separate_shader_objects : enable\n"
1555 "#extension GL_ARB_shading_language_420pack : enable\n"
1556 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001557 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001558 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001559 " outColor = color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001560 "}\n";
1561
1562 ASSERT_NO_FATAL_FAILURE(InitState());
1563 ASSERT_NO_FATAL_FAILURE(InitViewport());
1564
Tony Barbour01999182015-04-09 12:58:51 -06001565 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001566 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001567
Tony Barbour01999182015-04-09 12:58:51 -06001568 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1569 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001570
Tony Barbour01999182015-04-09 12:58:51 -06001571 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001572 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001573 pipelineobj.AddShader(&vs);
1574 pipelineobj.AddShader(&ps);
1575
Tony Barbour01999182015-04-09 12:58:51 -06001576 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001577 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001578
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001579#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001580 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001581 MESH_BUF_ID, // Binding ID
1582 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001583 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001584 };
1585
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001586 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001587 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1588 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001589 vi_attribs[0].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001590 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1591 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1592 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001593 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001594 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001595
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001596 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001597 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001598 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001599
Tony Barbourdd4c9642015-01-09 12:55:14 -07001600 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001601
Tony Barbour1490c912015-07-28 10:17:20 -06001602 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001603
Tony Barbour1490c912015-07-28 10:17:20 -06001604 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001605
Tony Barbour1490c912015-07-28 10:17:20 -06001606 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001607#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001608 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001609 pDSDumpDot((char*)"triTest2.dot");
1610#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001611
1612 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001613 Draw(0, 6, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001614
1615 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001616 EndCommandBuffer();
1617 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001618
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001619 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001620}
1621
Tony Barbour01999182015-04-09 12:58:51 -06001622TEST_F(VkRenderTest, QuadSparseVertFetch)
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001623{
1624 // This tests that attributes work in the presence of gl_VertexID
1625
1626 static const char *vertShaderText =
1627 "#version 140\n"
1628 "#extension GL_ARB_separate_shader_objects : enable\n"
1629 "#extension GL_ARB_shading_language_420pack : enable\n"
1630 //XYZ1( -1, -1, -1 )
1631 "layout (location = 1) in vec4 pos;\n"
1632 "layout (location = 4) in vec4 inColor;\n"
1633 //XYZ1( 0.f, 0.f, 0.f )
1634 "layout (location = 0) out vec4 outColor;\n"
1635 "void main() {\n"
1636 " outColor = inColor;\n"
1637 " gl_Position = pos;\n"
1638 "}\n";
1639
1640
1641 static const char *fragShaderText =
1642 "#version 140\n"
1643 "#extension GL_ARB_separate_shader_objects : enable\n"
1644 "#extension GL_ARB_shading_language_420pack : enable\n"
1645 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001646 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001647 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001648 " outColor = color;\n"
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001649 "}\n";
1650
1651 ASSERT_NO_FATAL_FAILURE(InitState());
1652 ASSERT_NO_FATAL_FAILURE(InitViewport());
1653
1654 struct VDATA
1655 {
1656 float t1, t2, t3, t4; // filler data
1657 float posX, posY, posZ, posW; // Position data
1658 float r, g, b, a; // Color
1659 };
1660 const struct VDATA vData[] =
1661 {
1662 { XYZ1(0, 0, 0), XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
1663 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.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( 0.f, 1.f, 0.f ) },
1666 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1667 { XYZ1(0, 0, 0), XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
1668 };
1669
Tony Barbour01999182015-04-09 12:58:51 -06001670 VkConstantBufferObj meshBuffer(m_device,sizeof(vData)/sizeof(vData[0]),sizeof(vData[0]), vData);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001671 meshBuffer.BufferMemoryBarrier();
1672
Tony Barbour01999182015-04-09 12:58:51 -06001673 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1674 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001675
Tony Barbour01999182015-04-09 12:58:51 -06001676 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001677 pipelineobj.AddColorAttachment();
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001678 pipelineobj.AddShader(&vs);
1679 pipelineobj.AddShader(&ps);
1680
Tony Barbour01999182015-04-09 12:58:51 -06001681 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001682 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001683
1684#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001685 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001686 MESH_BUF_ID, // Binding ID
1687 sizeof(vData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001688 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001689 };
1690
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001691 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001692 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1693 vi_attribs[0].location = 4;
Tony Barbour8205d902015-04-16 15:59:00 -06001694 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001695 vi_attribs[0].offsetInBytes = sizeof(float) * 4 * 2; // Offset of first element in bytes from base of vertex
1696 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1697 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001698 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001699 vi_attribs[1].offsetInBytes = sizeof(float) * 4 * 1; // Offset of first element in bytes from base of vertex
1700
1701 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
1702 pipelineobj.AddVertexInputBindings(&vi_binding, 1);
1703 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
1704
1705 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001706
Tony Barbour1490c912015-07-28 10:17:20 -06001707 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001708
Tony Barbour1490c912015-07-28 10:17:20 -06001709 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001710
Tony Barbour1490c912015-07-28 10:17:20 -06001711 BindVertexBuffer(&meshBuffer, 0, MESH_BUF_ID);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001712#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001713 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001714 pDSDumpDot((char*)"triTest2.dot");
1715#endif
1716
1717 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001718 Draw(0, 6, 0, 1);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001719
1720 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001721 EndCommandBuffer();
1722 QueueCommandBuffer();
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001723
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001724 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001725}
1726
Tony Barbour01999182015-04-09 12:58:51 -06001727TEST_F(VkRenderTest, TriVertFetchDeadAttr)
Tony Barbourf43b6982014-11-25 13:18:32 -07001728{
1729 // This tests that attributes work in the presence of gl_VertexID
1730 // and a dead attribute in position 0. Draws a triangle with yellow,
1731 // red and green corners, starting at top and going clockwise.
1732
1733 static const char *vertShaderText =
1734 "#version 140\n"
1735 "#extension GL_ARB_separate_shader_objects : enable\n"
1736 "#extension GL_ARB_shading_language_420pack : enable\n"
1737 //XYZ1( -1, -1, -1 )
1738 "layout (location = 0) in vec4 pos;\n"
1739 //XYZ1( 0.f, 0.f, 0.f )
1740 "layout (location = 1) in vec4 inColor;\n"
1741 "layout (location = 0) out vec4 outColor;\n"
1742 "void main() {\n"
1743 " outColor = inColor;\n"
1744 " vec2 vertices[3];"
1745 " vertices[0] = vec2(-1.0, -1.0);\n"
1746 " vertices[1] = vec2( 1.0, -1.0);\n"
1747 " vertices[2] = vec2( 0.0, 1.0);\n"
1748 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1749 "}\n";
1750
1751
1752 static const char *fragShaderText =
1753 "#version 140\n"
1754 "#extension GL_ARB_separate_shader_objects : enable\n"
1755 "#extension GL_ARB_shading_language_420pack : enable\n"
1756 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001757 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001758 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001759 " outColor = color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001760 "}\n";
1761
1762 ASSERT_NO_FATAL_FAILURE(InitState());
1763 ASSERT_NO_FATAL_FAILURE(InitViewport());
1764
Tony Barbour01999182015-04-09 12:58:51 -06001765 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001766 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001767
Tony Barbour01999182015-04-09 12:58:51 -06001768 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1769 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001770
Tony Barbour01999182015-04-09 12:58:51 -06001771 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001772 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001773 pipelineobj.AddShader(&vs);
1774 pipelineobj.AddShader(&ps);
1775
Tony Barbour01999182015-04-09 12:58:51 -06001776 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001777 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001778
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001779#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001780 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001781 MESH_BUF_ID, // Binding ID
1782 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001783 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001784 };
1785
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001786 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001787 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1788 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001789 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001790 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1791 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1792 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001793 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001794 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001795
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001796 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001797 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001798 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001799
Tony Barbourdd4c9642015-01-09 12:55:14 -07001800 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourf43b6982014-11-25 13:18:32 -07001801
Tony Barbour1490c912015-07-28 10:17:20 -06001802 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001803
Tony Barbour1490c912015-07-28 10:17:20 -06001804 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001805
Tony Barbour1490c912015-07-28 10:17:20 -06001806 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001807#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001808 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001809 pDSDumpDot((char*)"triTest2.dot");
1810#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001811
1812 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001813 Draw(0, 6, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001814
1815 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001816 EndCommandBuffer();
1817 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001818
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001819 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001820}
1821
Tony Barbour01999182015-04-09 12:58:51 -06001822TEST_F(VkRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001823{
1824 static const char *vertShaderText =
1825 "#version 140\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001826 "#extension GL_ARB_separate_shader_objects : enable\n"
1827 "#extension GL_ARB_shading_language_420pack : enable\n"
GregFd6ebdb32015-06-03 18:40:50 -06001828 "layout (std140, binding = 0) uniform bufferVals {\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001829 " mat4 mvp;\n"
1830 "} myBufferVals;\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001831 "layout (location = 0) in vec4 pos;\n"
1832 "layout (location = 1) in vec4 inColor;\n"
Cody Northrop74a2d2c2015-06-16 17:32:04 -06001833 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001834 "void main() {\n"
1835 " outColor = inColor;\n"
1836 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001837 " gl_Position.y = -gl_Position.y;\n"
1838 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001839 "}\n";
1840
1841 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001842 "#version 140\n"
1843 "#extension GL_ARB_separate_shader_objects : enable\n"
1844 "#extension GL_ARB_shading_language_420pack : enable\n"
1845 "layout (location = 0) in vec4 color;\n"
1846 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001847 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001848 " outColor = color;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001849 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001850 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001851
Tony Barbourf43b6982014-11-25 13:18:32 -07001852 glm::mat4 View = glm::lookAt(
1853 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1854 glm::vec3(0,0,0), // and looks at the origin
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001855 glm::vec3(0,-1,0) // Head is up (set to 0,-1,0 to look upside-down)
Tony Barbourf43b6982014-11-25 13:18:32 -07001856 );
1857
1858 glm::mat4 Model = glm::mat4(1.0f);
1859
1860 glm::mat4 MVP = Projection * View * Model;
1861
1862 ASSERT_NO_FATAL_FAILURE(InitState());
1863 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wu9e81ebb2015-07-09 10:16:34 +08001864 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Chia-I Wuc278df82015-07-07 11:50:03 +08001865 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height, m_depth_stencil_fmt);
Tony Barbourf43b6982014-11-25 13:18:32 -07001866
Tony Barbour01999182015-04-09 12:58:51 -06001867 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 -07001868 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1869
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001870 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07001871
Tony Barbour01999182015-04-09 12:58:51 -06001872 VkConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1873 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1874 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001875
Tony Barbour01999182015-04-09 12:58:51 -06001876 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001877 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001878 pipelineobj.AddShader(&vs);
1879 pipelineobj.AddShader(&ps);
1880
Tony Barboure307f582015-07-10 15:29:03 -06001881 VkPipelineDepthStencilStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001882 ds_state.depthTestEnable = VK_TRUE;
1883 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06001884 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Cody Northrope4bc6942015-08-26 10:01:32 -06001885 ds_state.depthBoundsTestEnable = VK_FALSE;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001886 ds_state.stencilTestEnable = VK_FALSE;
1887 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
1888 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
1889 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06001890 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001891 ds_state.front = ds_state.back;
1892 pipelineobj.SetDepthStencil(&ds_state);
1893
Tony Barbour01999182015-04-09 12:58:51 -06001894 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001895 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001896
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001897#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001898 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001899 MESH_BUF_ID, // Binding ID
1900 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001901 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001902 };
Tony Barbourf43b6982014-11-25 13:18:32 -07001903
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001904 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001905 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1906 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001907 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001908 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1909 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1910 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001911 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001912 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001913
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001914 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001915 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001916 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001917
Tony Barbour17c6ab12015-03-27 17:03:18 -06001918 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour17c6ab12015-03-27 17:03:18 -06001919
Tony Barbour1490c912015-07-28 10:17:20 -06001920 ASSERT_VK_SUCCESS(BeginCommandBuffer());
1921 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001922
Tony Barbour1490c912015-07-28 10:17:20 -06001923 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barboure4ed9942015-01-09 10:06:53 -07001924#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001925 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barboure4ed9942015-01-09 10:06:53 -07001926 pDSDumpDot((char*)"triTest2.dot");
1927#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001928
1929 // render triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001930 Draw(0, 36, 0, 1);
Tony Barboure4ed9942015-01-09 10:06:53 -07001931
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001932
Tony Barboure4ed9942015-01-09 10:06:53 -07001933 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001934 EndCommandBuffer();
1935 QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -07001936
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001937 RecordImages(m_renderTargets);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001938}
1939
Tony Barbour01999182015-04-09 12:58:51 -06001940TEST_F(VkRenderTest, VSTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07001941{
1942 // The expected result from this test is a green and red triangle;
1943 // one red vertex on the left, two green vertices on the right.
1944 static const char *vertShaderText =
Cody Northrop74a2d2c2015-06-16 17:32:04 -06001945 "#version 140\n"
1946 "#extension GL_ARB_separate_shader_objects : enable\n"
1947 "#extension GL_ARB_shading_language_420pack : enable\n"
1948 "layout (location = 0) out vec4 texColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001949 "uniform sampler2D surface;\n"
1950 "void main() {\n"
1951 " vec2 vertices[3];"
1952 " vertices[0] = vec2(-0.5, -0.5);\n"
1953 " vertices[1] = vec2( 0.5, -0.5);\n"
1954 " vertices[2] = vec2( 0.5, 0.5);\n"
1955 " vec2 positions[3];"
1956 " positions[0] = vec2( 0.0, 0.0);\n"
1957 " positions[1] = vec2( 0.25, 0.1);\n"
1958 " positions[2] = vec2( 0.1, 0.25);\n"
1959 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1960 " texColor = textureLod(surface, samplePos, 0.0);\n"
1961 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1962 "}\n";
1963
1964 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001965 "#version 140\n"
1966 "#extension GL_ARB_separate_shader_objects : enable\n"
1967 "#extension GL_ARB_shading_language_420pack : enable\n"
1968 "layout (location = 0) in vec4 texColor;\n"
1969 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001970 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001971 " outColor = texColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001972 "}\n";
1973
1974 ASSERT_NO_FATAL_FAILURE(InitState());
1975 ASSERT_NO_FATAL_FAILURE(InitViewport());
1976
Tony Barbour01999182015-04-09 12:58:51 -06001977 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1978 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
1979 VkSamplerObj sampler(m_device);
1980 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001981
Tony Barbour01999182015-04-09 12:58:51 -06001982 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001983 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001984 pipelineobj.AddShader(&vs);
1985 pipelineobj.AddShader(&ps);
1986
Tony Barbour01999182015-04-09 12:58:51 -06001987 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001988 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001989
Tony Barbourdd4c9642015-01-09 12:55:14 -07001990 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06001991 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourf43b6982014-11-25 13:18:32 -07001992
Tony Barbour1490c912015-07-28 10:17:20 -06001993 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001994
1995#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001996 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001997 pDSDumpDot((char*)"triTest2.dot");
1998#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001999
Tony Barbourdd4c9642015-01-09 12:55:14 -07002000 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002001 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002002
2003 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002004 EndCommandBuffer();
2005 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002006
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002007 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002008}
GregFd6ebdb32015-06-03 18:40:50 -06002009
2010
2011
Tony Barbour01999182015-04-09 12:58:51 -06002012TEST_F(VkRenderTest, TexturedTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002013{
2014 // The expected result from this test is a red and green checkered triangle
2015 static const char *vertShaderText =
2016 "#version 140\n"
2017 "#extension GL_ARB_separate_shader_objects : enable\n"
2018 "#extension GL_ARB_shading_language_420pack : enable\n"
2019 "layout (location = 0) out vec2 samplePos;\n"
2020 "void main() {\n"
2021 " vec2 vertices[3];"
2022 " vertices[0] = vec2(-0.5, -0.5);\n"
2023 " vertices[1] = vec2( 0.5, -0.5);\n"
2024 " vertices[2] = vec2( 0.5, 0.5);\n"
2025 " vec2 positions[3];"
2026 " positions[0] = vec2( 0.0, 0.0);\n"
2027 " positions[1] = vec2( 1.0, 0.0);\n"
2028 " positions[2] = vec2( 1.0, 1.0);\n"
2029 " samplePos = positions[gl_VertexID % 3];\n"
2030 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2031 "}\n";
2032
2033 static const char *fragShaderText =
2034 "#version 140\n"
2035 "#extension GL_ARB_separate_shader_objects : enable\n"
2036 "#extension GL_ARB_shading_language_420pack : enable\n"
2037 "layout (location = 0) in vec2 samplePos;\n"
2038 "layout (binding = 0) uniform sampler2D surface;\n"
2039 "layout (location=0) out vec4 outColor;\n"
2040 "void main() {\n"
2041 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2042 " outColor = texColor;\n"
2043 "}\n";
2044
2045 ASSERT_NO_FATAL_FAILURE(InitState());
2046 ASSERT_NO_FATAL_FAILURE(InitViewport());
2047
Tony Barbour01999182015-04-09 12:58:51 -06002048 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2049 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2050 VkSamplerObj sampler(m_device);
2051 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002052
Tony Barbour01999182015-04-09 12:58:51 -06002053 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002054 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002055 pipelineobj.AddShader(&vs);
2056 pipelineobj.AddShader(&ps);
2057
Tony Barbour01999182015-04-09 12:58:51 -06002058 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002059 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002060
Tony Barbourdd4c9642015-01-09 12:55:14 -07002061 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002062 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002063
Tony Barbour1490c912015-07-28 10:17:20 -06002064 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002065
2066#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002067 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002068 pDSDumpDot((char*)"triTest2.dot");
2069#endif
2070 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002071 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002072
2073 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002074 EndCommandBuffer();
2075 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002076
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002077 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002078}
Tony Barbour01999182015-04-09 12:58:51 -06002079TEST_F(VkRenderTest, TexturedTriangleClip)
Tony Barbourf43b6982014-11-25 13:18:32 -07002080{
2081 // The expected result from this test is a red and green checkered triangle
2082 static const char *vertShaderText =
2083 "#version 330\n"
2084 "#extension GL_ARB_separate_shader_objects : enable\n"
2085 "#extension GL_ARB_shading_language_420pack : enable\n"
2086 "layout (location = 0) out vec2 samplePos;\n"
2087 "out gl_PerVertex {\n"
2088 " vec4 gl_Position;\n"
2089 " float gl_ClipDistance[1];\n"
2090 "};\n"
2091 "void main() {\n"
2092 " vec2 vertices[3];"
2093 " vertices[0] = vec2(-0.5, -0.5);\n"
2094 " vertices[1] = vec2( 0.5, -0.5);\n"
2095 " vertices[2] = vec2( 0.5, 0.5);\n"
2096 " vec2 positions[3];"
2097 " positions[0] = vec2( 0.0, 0.0);\n"
2098 " positions[1] = vec2( 1.0, 0.0);\n"
2099 " positions[2] = vec2( 1.0, 1.0);\n"
2100 " float dists[3];\n"
2101 " dists[0] = 1.0;\n"
2102 " dists[1] = 1.0;\n"
2103 " dists[2] = -1.0;\n"
2104 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2105 " samplePos = positions[gl_VertexID % 3];\n"
2106 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2107 "}\n";
2108
2109 static const char *fragShaderText =
2110 "#version 140\n"
2111 "#extension GL_ARB_separate_shader_objects : enable\n"
2112 "#extension GL_ARB_shading_language_420pack : enable\n"
2113 "layout (location = 0) in vec2 samplePos;\n"
2114 "layout (binding = 0) uniform sampler2D surface;\n"
2115 "layout (location=0) out vec4 outColor;\n"
2116 "void main() {\n"
2117 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2118 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2119 " outColor = texColor;\n"
2120 "}\n";
2121
2122
2123 ASSERT_NO_FATAL_FAILURE(InitState());
2124 ASSERT_NO_FATAL_FAILURE(InitViewport());
2125
Tony Barbour01999182015-04-09 12:58:51 -06002126 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2127 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2128 VkSamplerObj sampler(m_device);
2129 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002130
Tony Barbour01999182015-04-09 12:58:51 -06002131 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002132 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002133 pipelineobj.AddShader(&vs);
2134 pipelineobj.AddShader(&ps);
2135
Tony Barbour01999182015-04-09 12:58:51 -06002136 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002137 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002138
Tony Barbourdd4c9642015-01-09 12:55:14 -07002139 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002140 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002141
Tony Barbour1490c912015-07-28 10:17:20 -06002142 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002143
2144#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002145 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002146 pDSDumpDot((char*)"triTest2.dot");
2147#endif
2148 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002149 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002150
2151 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002152 EndCommandBuffer();
2153 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002154
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002155 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002156}
GregFd6ebdb32015-06-03 18:40:50 -06002157
Tony Barbour01999182015-04-09 12:58:51 -06002158TEST_F(VkRenderTest, FSTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002159{
2160 // The expected result from this test is a red and green checkered triangle
2161 static const char *vertShaderText =
2162 "#version 140\n"
2163 "#extension GL_ARB_separate_shader_objects : enable\n"
2164 "#extension GL_ARB_shading_language_420pack : enable\n"
2165 "layout (location = 0) out vec2 samplePos;\n"
2166 "void main() {\n"
2167 " vec2 vertices[3];"
2168 " vertices[0] = vec2(-0.5, -0.5);\n"
2169 " vertices[1] = vec2( 0.5, -0.5);\n"
2170 " vertices[2] = vec2( 0.5, 0.5);\n"
2171 " vec2 positions[3];"
2172 " positions[0] = vec2( 0.0, 0.0);\n"
2173 " positions[1] = vec2( 1.0, 0.0);\n"
2174 " positions[2] = vec2( 1.0, 1.0);\n"
2175 " samplePos = positions[gl_VertexID % 3];\n"
2176 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2177 "}\n";
2178
2179 static const char *fragShaderText =
2180 "#version 140\n"
2181 "#extension GL_ARB_separate_shader_objects : enable\n"
2182 "#extension GL_ARB_shading_language_420pack : enable\n"
2183 "layout (location = 0) in vec2 samplePos;\n"
2184 "layout (binding = 0) uniform sampler2D surface;\n"
2185 "layout (location=0) out vec4 outColor;\n"
2186 "void main() {\n"
2187 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2188 " outColor = texColor;\n"
2189 "}\n";
2190
2191 ASSERT_NO_FATAL_FAILURE(InitState());
2192 ASSERT_NO_FATAL_FAILURE(InitViewport());
2193
Tony Barbour01999182015-04-09 12:58:51 -06002194 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2195 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2196 VkSamplerObj sampler(m_device);
2197 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002198
Tony Barbour01999182015-04-09 12:58:51 -06002199 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002200 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002201 pipelineobj.AddShader(&vs);
2202 pipelineobj.AddShader(&ps);
2203
Tony Barbour01999182015-04-09 12:58:51 -06002204 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002205 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002206
Tony Barbourdd4c9642015-01-09 12:55:14 -07002207 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002208 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002209
Tony Barbour1490c912015-07-28 10:17:20 -06002210 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002211
2212#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002213 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002214 pDSDumpDot((char*)"triTest2.dot");
2215#endif
2216 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002217 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002218
2219 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002220 EndCommandBuffer();
2221 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002222
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002223 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002224}
Tony Barbour01999182015-04-09 12:58:51 -06002225TEST_F(VkRenderTest, SamplerBindingsTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002226{
2227 // This test sets bindings on the samplers
2228 // For now we are asserting that sampler and texture pairs
2229 // march in lock step, and are set via GLSL binding. This can
2230 // and will probably change.
2231 // The sampler bindings should match the sampler and texture slot
2232 // number set up by the application.
2233 // This test will result in a blue triangle
2234 static const char *vertShaderText =
2235 "#version 140\n"
2236 "#extension GL_ARB_separate_shader_objects : enable\n"
2237 "#extension GL_ARB_shading_language_420pack : enable\n"
2238 "layout (location = 0) out vec4 samplePos;\n"
2239 "void main() {\n"
2240 " vec2 vertices[3];"
2241 " vertices[0] = vec2(-0.5, -0.5);\n"
2242 " vertices[1] = vec2( 0.5, -0.5);\n"
2243 " vertices[2] = vec2( 0.5, 0.5);\n"
2244 " vec2 positions[3];"
2245 " positions[0] = vec2( 0.0, 0.0);\n"
2246 " positions[1] = vec2( 1.0, 0.0);\n"
2247 " positions[2] = vec2( 1.0, 1.0);\n"
2248 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2249 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2250 "}\n";
2251
2252 static const char *fragShaderText =
2253 "#version 140\n"
2254 "#extension GL_ARB_separate_shader_objects : enable\n"
2255 "#extension GL_ARB_shading_language_420pack : enable\n"
2256 "layout (location = 0) in vec4 samplePos;\n"
2257 "layout (binding = 0) uniform sampler2D surface0;\n"
2258 "layout (binding = 1) uniform sampler2D surface1;\n"
2259 "layout (binding = 12) uniform sampler2D surface2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06002260 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002261 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002262 " outColor = textureLod(surface2, samplePos.xy, 0.0);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002263 "}\n";
2264
2265 ASSERT_NO_FATAL_FAILURE(InitState());
2266 ASSERT_NO_FATAL_FAILURE(InitViewport());
2267
Tony Barbour01999182015-04-09 12:58:51 -06002268 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2269 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002270
Tony Barbour01999182015-04-09 12:58:51 -06002271 VkSamplerObj sampler1(m_device);
2272 VkSamplerObj sampler2(m_device);
2273 VkSamplerObj sampler3(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002274
Tony Barbour2f421a02015-04-01 16:38:10 -06002275 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
Tony Barbour01999182015-04-09 12:58:51 -06002276 VkTextureObj texture1(m_device, tex_colors); // Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002277 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
Tony Barbour01999182015-04-09 12:58:51 -06002278 VkTextureObj texture2(m_device, tex_colors); // Green
Tony Barbour2f421a02015-04-01 16:38:10 -06002279 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
Tony Barbour01999182015-04-09 12:58:51 -06002280 VkTextureObj texture3(m_device, tex_colors); // Blue
Tony Barbourf43b6982014-11-25 13:18:32 -07002281
Tony Barbour01999182015-04-09 12:58:51 -06002282 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002283 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002284 pipelineobj.AddShader(&vs);
2285 pipelineobj.AddShader(&ps);
2286
Tony Barbour01999182015-04-09 12:58:51 -06002287 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002288 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2289 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2290 for (int i = 0; i < 10; i++)
2291 descriptorSet.AppendDummy();
2292 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002293
Tony Barbourdd4c9642015-01-09 12:55:14 -07002294 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002295 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002296
Tony Barbour1490c912015-07-28 10:17:20 -06002297 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002298
2299#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002300 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002301 pDSDumpDot((char*)"triTest2.dot");
2302#endif
2303 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002304 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002305
2306 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002307 EndCommandBuffer();
2308 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002309
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002310 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002311}
2312
Tony Barbour01999182015-04-09 12:58:51 -06002313TEST_F(VkRenderTest, TriangleVSUniformBlock)
Tony Barbourf43b6982014-11-25 13:18:32 -07002314{
2315 // The expected result from this test is a blue triangle
2316
2317 static const char *vertShaderText =
2318 "#version 140\n"
2319 "#extension GL_ARB_separate_shader_objects : enable\n"
2320 "#extension GL_ARB_shading_language_420pack : enable\n"
2321 "layout (location = 0) out vec4 outColor;\n"
2322 "layout (std140, binding = 0) uniform bufferVals {\n"
2323 " vec4 red;\n"
2324 " vec4 green;\n"
2325 " vec4 blue;\n"
2326 " vec4 white;\n"
2327 "} myBufferVals;\n"
2328 "void main() {\n"
2329 " vec2 vertices[3];"
2330 " vertices[0] = vec2(-0.5, -0.5);\n"
2331 " vertices[1] = vec2( 0.5, -0.5);\n"
2332 " vertices[2] = vec2( 0.5, 0.5);\n"
2333 " outColor = myBufferVals.blue;\n"
2334 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2335 "}\n";
2336
2337 static const char *fragShaderText =
2338 "#version 140\n"
2339 "#extension GL_ARB_separate_shader_objects : enable\n"
2340 "#extension GL_ARB_shading_language_420pack : enable\n"
2341 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -06002342 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002343 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002344 " outColor = inColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002345 "}\n";
2346
2347 ASSERT_NO_FATAL_FAILURE(InitState());
2348 ASSERT_NO_FATAL_FAILURE(InitViewport());
2349
Tony Barbour01999182015-04-09 12:58:51 -06002350 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2351 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002352
2353 // Let's populate our buffer with the following:
2354 // vec4 red;
2355 // vec4 green;
2356 // vec4 blue;
2357 // vec4 white;
2358 const int valCount = 4 * 4;
2359 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2360 0.0, 1.0, 0.0, 1.0,
2361 0.0, 0.0, 1.0, 1.0,
2362 1.0, 1.0, 1.0, 1.0 };
2363
Tony Barbour01999182015-04-09 12:58:51 -06002364 VkConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002365
Tony Barbour01999182015-04-09 12:58:51 -06002366 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002367 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002368 pipelineobj.AddShader(&vs);
2369 pipelineobj.AddShader(&ps);
2370
Tony Barbour01999182015-04-09 12:58:51 -06002371 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002372 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002373
Tony Barbourdd4c9642015-01-09 12:55:14 -07002374 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002375 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002376
Tony Barbour1490c912015-07-28 10:17:20 -06002377 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002378
2379#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002380 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002381 pDSDumpDot((char*)"triTest2.dot");
2382#endif
2383 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002384 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002385
2386 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002387 EndCommandBuffer();
2388 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002389
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002390 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002391}
2392
Tony Barbour01999182015-04-09 12:58:51 -06002393TEST_F(VkRenderTest, TriangleFSUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002394{
2395 // This test allows the shader to select which buffer it is
2396 // pulling from using layout binding qualifier.
2397 // There are corresponding changes in the compiler stack that
2398 // will select the buffer using binding directly.
2399 // The binding number should match the slot number set up by
2400 // the application.
2401 // The expected result from this test is a purple triangle
2402
2403 static const char *vertShaderText =
2404 "#version 140\n"
2405 "#extension GL_ARB_separate_shader_objects : enable\n"
2406 "#extension GL_ARB_shading_language_420pack : enable\n"
2407 "void main() {\n"
2408 " vec2 vertices[3];"
2409 " vertices[0] = vec2(-0.5, -0.5);\n"
2410 " vertices[1] = vec2( 0.5, -0.5);\n"
2411 " vertices[2] = vec2( 0.5, 0.5);\n"
2412 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2413 "}\n";
2414
2415 static const char *fragShaderText =
2416 "#version 140\n"
2417 "#extension GL_ARB_separate_shader_objects : enable\n"
2418 "#extension GL_ARB_shading_language_420pack : enable\n"
2419 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2420 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2421 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002422 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
GregFd6ebdb32015-06-03 18:40:50 -06002423 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002424 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002425 " outColor = myBlueVal.color;\n"
2426 " outColor += myRedVal.color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002427 "}\n";
2428
2429 ASSERT_NO_FATAL_FAILURE(InitState());
2430 ASSERT_NO_FATAL_FAILURE(InitViewport());
2431
Tony Barbour01999182015-04-09 12:58:51 -06002432 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2433 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002434
2435 // We're going to create a number of uniform buffers, and then allow
2436 // the shader to select which it wants to read from with a binding
2437
2438 // Let's populate the buffers with a single color each:
2439 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2440 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2441 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002442 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002443
2444 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2445 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2446 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2447 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2448
2449 const int redCount = sizeof(redVals) / sizeof(float);
2450 const int greenCount = sizeof(greenVals) / sizeof(float);
2451 const int blueCount = sizeof(blueVals) / sizeof(float);
2452 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2453
Tony Barbour01999182015-04-09 12:58:51 -06002454 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002455
Tony Barbour01999182015-04-09 12:58:51 -06002456 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002457
Tony Barbour01999182015-04-09 12:58:51 -06002458 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002459
Tony Barbour01999182015-04-09 12:58:51 -06002460 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002461
Tony Barbour01999182015-04-09 12:58:51 -06002462 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002463 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002464 pipelineobj.AddShader(&vs);
2465 pipelineobj.AddShader(&ps);
2466
Tony Barbour01999182015-04-09 12:58:51 -06002467 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002468 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2469 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2470 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2471 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002472
Tony Barbourdd4c9642015-01-09 12:55:14 -07002473 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002474 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourf43b6982014-11-25 13:18:32 -07002475
Tony Barbour1490c912015-07-28 10:17:20 -06002476 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002477
2478#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002479 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002480 pDSDumpDot((char*)"triTest2.dot");
2481#endif
2482 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002483 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002484
2485 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002486 EndCommandBuffer();
2487 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002488
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002489 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002490}
2491
Tony Barbour01999182015-04-09 12:58:51 -06002492TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002493{
2494 // This test is the same as TriangleFSUniformBlockBinding, but
2495 // it does not provide an instance name.
2496 // The expected result from this test is a purple triangle
2497
2498 static const char *vertShaderText =
2499 "#version 140\n"
2500 "#extension GL_ARB_separate_shader_objects : enable\n"
2501 "#extension GL_ARB_shading_language_420pack : enable\n"
2502 "void main() {\n"
2503 " vec2 vertices[3];"
2504 " vertices[0] = vec2(-0.5, -0.5);\n"
2505 " vertices[1] = vec2( 0.5, -0.5);\n"
2506 " vertices[2] = vec2( 0.5, 0.5);\n"
2507 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2508 "}\n";
2509
2510 static const char *fragShaderText =
2511 "#version 430\n"
2512 "#extension GL_ARB_separate_shader_objects : enable\n"
2513 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002514 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2515 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2516 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002517 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002518 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002519 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002520 " outColor = blue;\n"
2521 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002522 "}\n";
2523 ASSERT_NO_FATAL_FAILURE(InitState());
2524 ASSERT_NO_FATAL_FAILURE(InitViewport());
2525
Tony Barbour01999182015-04-09 12:58:51 -06002526 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2527 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002528
2529 // We're going to create a number of uniform buffers, and then allow
2530 // the shader to select which it wants to read from with a binding
2531
2532 // Let's populate the buffers with a single color each:
2533 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2534 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2535 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2536 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2537
2538 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2539 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2540 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2541 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2542
2543 const int redCount = sizeof(redVals) / sizeof(float);
2544 const int greenCount = sizeof(greenVals) / sizeof(float);
2545 const int blueCount = sizeof(blueVals) / sizeof(float);
2546 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2547
Tony Barbour01999182015-04-09 12:58:51 -06002548 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002549
Tony Barbour01999182015-04-09 12:58:51 -06002550 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002551
Tony Barbour01999182015-04-09 12:58:51 -06002552 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002553
Tony Barbour01999182015-04-09 12:58:51 -06002554 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002555
Tony Barbour01999182015-04-09 12:58:51 -06002556 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002557 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002558 pipelineobj.AddShader(&vs);
2559 pipelineobj.AddShader(&ps);
2560
Tony Barbour01999182015-04-09 12:58:51 -06002561 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002562 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2563 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2564 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2565 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002566
Tony Barbourdd4c9642015-01-09 12:55:14 -07002567 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002568 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002569
Tony Barbour1490c912015-07-28 10:17:20 -06002570 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002571
2572#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002573 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002574 pDSDumpDot((char*)"triTest2.dot");
2575#endif
2576 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002577 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002578
2579 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002580 EndCommandBuffer();
2581 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002582
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002583 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002584}
2585
GregF54a32172015-07-01 16:11:09 -06002586TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBindingWithStruct)
2587{
2588 // This test is the same as TriangleFSUniformBlockBinding, but
2589 // it does not provide an instance name.
2590 // The expected result from this test is a purple triangle
2591
2592 static const char *vertShaderText =
2593 "#version 140\n"
2594 "#extension GL_ARB_separate_shader_objects : enable\n"
2595 "#extension GL_ARB_shading_language_420pack : enable\n"
2596 "void main() {\n"
2597 " vec2 vertices[3];"
2598 " vertices[0] = vec2(-0.5, -0.5);\n"
2599 " vertices[1] = vec2( 0.5, -0.5);\n"
2600 " vertices[2] = vec2( 0.5, 0.5);\n"
2601 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2602 "}\n";
2603
2604 static const char *fragShaderText =
2605 "#version 430\n"
2606 "#extension GL_ARB_separate_shader_objects : enable\n"
2607 "#extension GL_ARB_shading_language_420pack : enable\n"
2608 "\n"
2609 " struct PS_INPUT {\n"
2610 " vec2 member0;\n"
2611 " vec4 member1;\n"
2612 " vec4 member2;\n"
2613 " vec4 member3;\n"
2614 " vec4 member4;\n"
2615 " vec4 member5;\n"
2616 " vec4 member6;\n"
2617 " vec4 member7;\n"
2618 " vec4 member8;\n"
2619 " vec4 member9;\n"
2620 " };\n"
2621 "\n"
2622 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2623 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2624 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2625 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
2626 "layout (location = 0) out vec4 outColor;\n"
2627 "PS_INPUT MainFs()\n"
2628 "{\n"
2629 " PS_INPUT o;\n"
2630 " o.member9 = red;\n"
2631 " return o;\n"
2632 "}\n"
2633 "\n"
2634 "void main()\n"
2635 "{\n"
2636 " PS_INPUT o;\n"
2637 " o = MainFs();\n"
2638 " outColor = blue;"
2639 " outColor += o.member9;\n"
2640 "}\n";;
2641 ASSERT_NO_FATAL_FAILURE(InitState());
2642 ASSERT_NO_FATAL_FAILURE(InitViewport());
2643
2644 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2645 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2646
2647 // We're going to create a number of uniform buffers, and then allow
2648 // the shader to select which it wants to read from with a binding
2649
2650 // Let's populate the buffers with a single color each:
2651 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2652 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2653 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2654 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2655
2656 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2657 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2658 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2659 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2660
2661 const int redCount = sizeof(redVals) / sizeof(float);
2662 const int greenCount = sizeof(greenVals) / sizeof(float);
2663 const int blueCount = sizeof(blueVals) / sizeof(float);
2664 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2665
2666 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2667
2668 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2669
2670 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2671
2672 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
2673
2674 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002675 pipelineobj.AddColorAttachment();
GregF54a32172015-07-01 16:11:09 -06002676 pipelineobj.AddShader(&vs);
2677 pipelineobj.AddShader(&ps);
2678
2679 VkDescriptorSetObj descriptorSet(m_device);
2680 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2681 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2682 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2683 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
2684
2685 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002686 ASSERT_VK_SUCCESS(BeginCommandBuffer());
GregF54a32172015-07-01 16:11:09 -06002687
Tony Barbour1490c912015-07-28 10:17:20 -06002688 GenericDrawPreparation(pipelineobj, descriptorSet);
GregF54a32172015-07-01 16:11:09 -06002689
2690#ifdef DUMP_STATE_DOT
2691 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
2692 pDSDumpDot((char*)"triTest2.dot");
2693#endif
2694 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002695 Draw(0, 3, 0, 1);
GregF54a32172015-07-01 16:11:09 -06002696
2697 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002698 EndCommandBuffer();
2699 QueueCommandBuffer();
GregF54a32172015-07-01 16:11:09 -06002700
2701 RecordImages(m_renderTargets);
2702}
2703
Tony Barbour01999182015-04-09 12:58:51 -06002704TEST_F(VkRenderTest, CubeWithVertexFetchAndMVPAndTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07002705{
2706 static const char *vertShaderText =
2707 "#version 140\n"
2708 "#extension GL_ARB_separate_shader_objects : enable\n"
2709 "#extension GL_ARB_shading_language_420pack : enable\n"
2710 "layout (std140, binding=0) uniform bufferVals {\n"
2711 " mat4 mvp;\n"
2712 "} myBufferVals;\n"
2713 "layout (location=0) in vec4 pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002714 "layout (location=1) in vec2 input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002715 "layout (location=0) out vec2 UV;\n"
2716 "void main() {\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002717 " UV = input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002718 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002719 " gl_Position.y = -gl_Position.y;\n"
2720 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002721 "}\n";
2722
2723 static const char *fragShaderText =
2724 "#version 140\n"
2725 "#extension GL_ARB_separate_shader_objects : enable\n"
2726 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002727 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002728 "layout (location=0) out vec4 outColor;\n"
2729 "layout (location=0) in vec2 UV;\n"
2730 "void main() {\n"
2731 " outColor= textureLod(surface, UV, 0.0);\n"
2732 "}\n";
2733 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2734
2735 glm::mat4 View = glm::lookAt(
2736 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2737 glm::vec3(0,0,0), // and looks at the origin
2738 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2739 );
2740
2741 glm::mat4 Model = glm::mat4(1.0f);
2742
2743 glm::mat4 MVP = Projection * View * Model;
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002744 int num_verts = sizeof(g_vb_texture_Data) / sizeof(g_vb_texture_Data[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002745
2746
2747 ASSERT_NO_FATAL_FAILURE(InitState());
2748 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wu9e81ebb2015-07-09 10:16:34 +08002749 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Chia-I Wuc278df82015-07-07 11:50:03 +08002750 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height, m_depth_stencil_fmt);
Tony Barbourf43b6982014-11-25 13:18:32 -07002751
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002752 VkConstantBufferObj meshBuffer(m_device, num_verts,
2753 sizeof(g_vb_texture_Data[0]), g_vb_texture_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002754 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002755
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002756 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07002757
Tony Barbour01999182015-04-09 12:58:51 -06002758 VkConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2759 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2760 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2761 VkSamplerObj sampler(m_device);
2762 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002763
Tony Barbour01999182015-04-09 12:58:51 -06002764 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002765 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002766 pipelineobj.AddShader(&vs);
2767 pipelineobj.AddShader(&ps);
2768
Tony Barbour01999182015-04-09 12:58:51 -06002769 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002770 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mvpBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002771 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002772
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002773#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002774 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002775 MESH_BIND_ID, // binding ID
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002776 sizeof(g_vb_texture_Data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002777 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002778 };
Tony Barbourf43b6982014-11-25 13:18:32 -07002779
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002780 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002781 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2782 vi_attribs[0].location = 0; // location
Tony Barbour8205d902015-04-16 15:59:00 -06002783 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002784 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2785 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2786 vi_attribs[1].location = 1; // location
2787 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
2788 vi_attribs[1].offsetInBytes = 16; // Offset of uv components
Tony Barbourf43b6982014-11-25 13:18:32 -07002789
Tony Barbourf43b6982014-11-25 13:18:32 -07002790 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002791 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2792 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07002793
Tony Barboure307f582015-07-10 15:29:03 -06002794 VkPipelineDepthStencilStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002795 ds_state.depthTestEnable = VK_TRUE;
2796 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06002797 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Cody Northrope4bc6942015-08-26 10:01:32 -06002798 ds_state.depthBoundsTestEnable = VK_FALSE;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002799 ds_state.stencilTestEnable = VK_FALSE;
2800 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
2801 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
2802 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06002803 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002804 ds_state.front = ds_state.back;
2805 pipelineobj.SetDepthStencil(&ds_state);
2806
Tony Barbour17c6ab12015-03-27 17:03:18 -06002807 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tobin Ehlis7f7b4422015-08-18 14:24:32 -06002808
2809 VkCmdBufferBeginInfo cbBeginInfo;
2810 memset(&cbBeginInfo, 0, sizeof(VkCmdBufferBeginInfo));
2811 cbBeginInfo.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
2812 cbBeginInfo.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT;
2813 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barbourf43b6982014-11-25 13:18:32 -07002814
Tony Barbour1490c912015-07-28 10:17:20 -06002815 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002816
Tony Barbour1490c912015-07-28 10:17:20 -06002817 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002818#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002819 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002820 pDSDumpDot((char*)"triTest2.dot");
2821#endif
2822 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002823 Draw(0, num_verts, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002824
2825 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002826 EndCommandBuffer();
2827 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002828
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002829 RecordImages(m_renderTargets);
Tony Barbour1490c912015-07-28 10:17:20 -06002830 RotateTriangleVSUniform(Projection, View, Model, &mvpBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002831}
Cody Northropd1ce7842014-12-09 11:17:01 -07002832
Tony Barbour01999182015-04-09 12:58:51 -06002833TEST_F(VkRenderTest, TriangleMixedSamplerUniformBlockBinding)
Cody Northropd1ce7842014-12-09 11:17:01 -07002834{
2835 // This test mixes binding slots of textures and buffers, ensuring
2836 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002837 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002838 // you can modify it to move the desired result around.
2839
2840 static const char *vertShaderText =
2841 "#version 140\n"
2842 "#extension GL_ARB_separate_shader_objects : enable\n"
2843 "#extension GL_ARB_shading_language_420pack : enable\n"
2844 "void main() {\n"
2845 " vec2 vertices[3];"
2846 " vertices[0] = vec2(-0.5, -0.5);\n"
2847 " vertices[1] = vec2( 0.5, -0.5);\n"
2848 " vertices[2] = vec2( 0.5, 0.5);\n"
2849 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2850 "}\n";
2851
2852 static const char *fragShaderText =
2853 "#version 430\n"
2854 "#extension GL_ARB_separate_shader_objects : enable\n"
2855 "#extension GL_ARB_shading_language_420pack : enable\n"
2856 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002857 "layout (binding = 3) uniform sampler2D surface1;\n"
2858 "layout (binding = 1) uniform sampler2D surface2;\n"
2859 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002860
Cody Northropa0410942014-12-09 13:59:39 -07002861
Chia-I Wuf8385062015-01-04 16:27:24 +08002862 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2863 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2864 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2865 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002866 "layout (location = 0) out vec4 outColor;\n"
2867 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002868 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002869 " outColor += white * vec4(0.00001);\n"
2870 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002871 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002872 "}\n";
2873 ASSERT_NO_FATAL_FAILURE(InitState());
2874 ASSERT_NO_FATAL_FAILURE(InitViewport());
2875
Tony Barbour01999182015-04-09 12:58:51 -06002876 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2877 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northropd1ce7842014-12-09 11:17:01 -07002878
Cody Northropd1ce7842014-12-09 11:17:01 -07002879 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2880 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2881 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2882 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2883
2884 const int redCount = sizeof(redVals) / sizeof(float);
2885 const int greenCount = sizeof(greenVals) / sizeof(float);
2886 const int blueCount = sizeof(blueVals) / sizeof(float);
2887 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2888
Tony Barbour01999182015-04-09 12:58:51 -06002889 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2890 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2891 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2892 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002893
Tony Barbour2f421a02015-04-01 16:38:10 -06002894 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002895 VkSamplerObj sampler0(m_device);
2896 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002897 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002898 VkSamplerObj sampler2(m_device);
2899 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002900 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002901 VkSamplerObj sampler4(m_device);
2902 VkTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropa0410942014-12-09 13:59:39 -07002903
2904 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2905 // TODO: Get back here ASAP and understand why.
Tony Barbour2f421a02015-04-01 16:38:10 -06002906 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06002907 VkSamplerObj sampler7(m_device);
2908 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropd1ce7842014-12-09 11:17:01 -07002909
Tony Barbour01999182015-04-09 12:58:51 -06002910 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002911 pipelineobj.AddColorAttachment();
Cody Northropd1ce7842014-12-09 11:17:01 -07002912 pipelineobj.AddShader(&vs);
2913 pipelineobj.AddShader(&ps);
2914
Tony Barbour01999182015-04-09 12:58:51 -06002915 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002916 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2917 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2918 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2919 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002920 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002921 // swap blue and green
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002922 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2923 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2924 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002925
Tony Barbourdd4c9642015-01-09 12:55:14 -07002926 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002927 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropd1ce7842014-12-09 11:17:01 -07002928
Tony Barbour1490c912015-07-28 10:17:20 -06002929 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002930
2931#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002932 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002933 pDSDumpDot((char*)"triTest2.dot");
2934#endif
2935 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002936 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002937
2938 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002939 EndCommandBuffer();
2940 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002941
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002942 RecordImages(m_renderTargets);
Cody Northropd1ce7842014-12-09 11:17:01 -07002943}
2944
Tony Barbour01999182015-04-09 12:58:51 -06002945TEST_F(VkRenderTest, TriangleMatchingSamplerUniformBlockBinding)
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002946{
2947 // This test matches binding slots of textures and buffers, requiring
2948 // the driver to give them distinct number spaces.
2949 // The expected result from this test is a red triangle, although
2950 // you can modify it to move the desired result around.
2951
2952 static const char *vertShaderText =
2953 "#version 140\n"
2954 "#extension GL_ARB_separate_shader_objects : enable\n"
2955 "#extension GL_ARB_shading_language_420pack : enable\n"
2956 "void main() {\n"
2957 " vec2 vertices[3];"
2958 " vertices[0] = vec2(-0.5, -0.5);\n"
2959 " vertices[1] = vec2( 0.5, -0.5);\n"
2960 " vertices[2] = vec2( 0.5, 0.5);\n"
2961 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2962 "}\n";
2963
2964 static const char *fragShaderText =
2965 "#version 430\n"
2966 "#extension GL_ARB_separate_shader_objects : enable\n"
2967 "#extension GL_ARB_shading_language_420pack : enable\n"
2968 "layout (binding = 0) uniform sampler2D surface0;\n"
2969 "layout (binding = 1) uniform sampler2D surface1;\n"
2970 "layout (binding = 2) uniform sampler2D surface2;\n"
2971 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002972 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2973 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2974 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2975 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002976 "layout (location = 0) out vec4 outColor;\n"
2977 "void main() {\n"
2978 " outColor = red;// * vec4(0.00001);\n"
2979 " outColor += white * vec4(0.00001);\n"
2980 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2981 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2982 "}\n";
2983 ASSERT_NO_FATAL_FAILURE(InitState());
2984 ASSERT_NO_FATAL_FAILURE(InitViewport());
2985
Tony Barbour01999182015-04-09 12:58:51 -06002986 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2987 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002988
2989 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2990 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2991 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2992 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2993
2994 const int redCount = sizeof(redVals) / sizeof(float);
2995 const int greenCount = sizeof(greenVals) / sizeof(float);
2996 const int blueCount = sizeof(blueVals) / sizeof(float);
2997 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2998
Tony Barbour01999182015-04-09 12:58:51 -06002999 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
3000 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
3001 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
3002 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003003
Tony Barbour2f421a02015-04-01 16:38:10 -06003004 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06003005 VkSamplerObj sampler0(m_device);
3006 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06003007 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06003008 VkSamplerObj sampler2(m_device);
3009 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06003010 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06003011 VkSamplerObj sampler4(m_device);
3012 VkTextureObj texture4(m_device, tex_colors); // Light Green
Tony Barbour2f421a02015-04-01 16:38:10 -06003013 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06003014 VkSamplerObj sampler7(m_device);
3015 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003016
Tony Barbour01999182015-04-09 12:58:51 -06003017 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003018 pipelineobj.AddColorAttachment();
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003019 pipelineobj.AddShader(&vs);
3020 pipelineobj.AddShader(&ps);
3021
Tony Barbour01999182015-04-09 12:58:51 -06003022 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08003023 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3024 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3025 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
3026 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003027 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
3028 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
3029 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
3030 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003031
Tony Barbourdd4c9642015-01-09 12:55:14 -07003032 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003033 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003034
Tony Barbour1490c912015-07-28 10:17:20 -06003035 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07003036
3037#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003038 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07003039 pDSDumpDot((char*)"triTest2.dot");
3040#endif
3041 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06003042 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07003043
3044 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003045 EndCommandBuffer();
3046 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07003047
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003048 RecordImages(m_renderTargets);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003049}
3050
Tony Barbour01999182015-04-09 12:58:51 -06003051TEST_F(VkRenderTest, TriangleUniformBufferLayout)
Cody Northrop02690bd2014-12-17 15:26:33 -07003052{
3053 // This test populates a buffer with a variety of different data
3054 // types, then reads them out with a shader.
3055 // The expected result from this test is a green triangle
3056
3057 static const char *vertShaderText =
3058 "#version 140\n"
3059 "#extension GL_ARB_separate_shader_objects : enable\n"
3060 "#extension GL_ARB_shading_language_420pack : enable\n"
3061 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3062 " vec4 fRed;\n"
3063 " vec4 fGreen;\n"
3064 " layout(row_major) mat4 worldToProj;\n"
3065 " layout(row_major) mat4 projToWorld;\n"
3066 " layout(row_major) mat4 worldToView;\n"
3067 " layout(row_major) mat4 viewToProj;\n"
3068 " layout(row_major) mat4 worldToShadow[4];\n"
3069 " float fZero;\n"
3070 " float fOne;\n"
3071 " float fTwo;\n"
3072 " float fThree;\n"
3073 " vec3 fZeroZeroZero;\n"
3074 " float fFour;\n"
3075 " vec3 fZeroZeroOne;\n"
3076 " float fFive;\n"
3077 " vec3 fZeroOneZero;\n"
3078 " float fSix;\n"
3079 " float fSeven;\n"
3080 " float fEight;\n"
3081 " float fNine;\n"
3082 " vec2 fZeroZero;\n"
3083 " vec2 fZeroOne;\n"
3084 " vec4 fBlue;\n"
3085 " vec2 fOneZero;\n"
3086 " vec2 fOneOne;\n"
3087 " vec3 fZeroOneOne;\n"
3088 " float fTen;\n"
3089 " float fEleven;\n"
3090 " float fTwelve;\n"
3091 " vec3 fOneZeroZero;\n"
3092 " vec4 uvOffsets[4];\n"
3093 "};\n"
3094 "layout (location = 0) out vec4 color;"
3095 "void main() {\n"
3096
3097 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3098 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3099 " \n"
3100
3101 // do some exact comparisons, even though we should
3102 // really have an epsilon involved.
3103 " vec4 outColor = right;\n"
3104 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3105 " outColor = wrong;\n"
3106 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3107 " outColor = wrong;\n"
3108 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3109 " outColor = wrong;\n"
3110
3111 " color = outColor;\n"
3112
3113 // generic position stuff
3114 " vec2 vertices;\n"
3115 " int vertexSelector = gl_VertexID;\n"
3116 " if (vertexSelector == 0)\n"
3117 " vertices = vec2(-0.5, -0.5);\n"
3118 " else if (vertexSelector == 1)\n"
3119 " vertices = vec2( 0.5, -0.5);\n"
3120 " else if (vertexSelector == 2)\n"
3121 " vertices = vec2( 0.5, 0.5);\n"
3122 " else\n"
3123 " vertices = vec2( 0.0, 0.0);\n"
3124 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3125 "}\n";
3126
3127 static const char *fragShaderText =
3128 "#version 140\n"
3129 "#extension GL_ARB_separate_shader_objects : enable\n"
3130 "#extension GL_ARB_shading_language_420pack : enable\n"
3131 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3132 " vec4 fRed;\n"
3133 " vec4 fGreen;\n"
3134 " layout(row_major) mat4 worldToProj;\n"
3135 " layout(row_major) mat4 projToWorld;\n"
3136 " layout(row_major) mat4 worldToView;\n"
3137 " layout(row_major) mat4 viewToProj;\n"
3138 " layout(row_major) mat4 worldToShadow[4];\n"
3139 " float fZero;\n"
3140 " float fOne;\n"
3141 " float fTwo;\n"
3142 " float fThree;\n"
3143 " vec3 fZeroZeroZero;\n"
3144 " float fFour;\n"
3145 " vec3 fZeroZeroOne;\n"
3146 " float fFive;\n"
3147 " vec3 fZeroOneZero;\n"
3148 " float fSix;\n"
3149 " float fSeven;\n"
3150 " float fEight;\n"
3151 " float fNine;\n"
3152 " vec2 fZeroZero;\n"
3153 " vec2 fZeroOne;\n"
3154 " vec4 fBlue;\n"
3155 " vec2 fOneZero;\n"
3156 " vec2 fOneOne;\n"
3157 " vec3 fZeroOneOne;\n"
3158 " float fTen;\n"
3159 " float fEleven;\n"
3160 " float fTwelve;\n"
3161 " vec3 fOneZeroZero;\n"
3162 " vec4 uvOffsets[4];\n"
3163 "};\n"
3164 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003165 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop02690bd2014-12-17 15:26:33 -07003166 "void main() {\n"
3167 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3168 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3169 " \n"
3170
3171 // start with VS value to ensure it passed
3172 " vec4 outColor = color;\n"
3173
3174 // do some exact comparisons, even though we should
3175 // really have an epsilon involved.
3176 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3177 " outColor = wrong;\n"
3178 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3179 " outColor = wrong;\n"
3180 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3181 " outColor = wrong;\n"
3182 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3183 " outColor = wrong;\n"
3184 " if (fTwo != 2.0)\n"
3185 " outColor = wrong;\n"
3186 " if (fOneOne != vec2(1.0, 1.0))\n"
3187 " outColor = wrong;\n"
3188 " if (fTen != 10.0)\n"
3189 " outColor = wrong;\n"
3190 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3191 " outColor = wrong;\n"
3192 " \n"
GregFd6ebdb32015-06-03 18:40:50 -06003193 " uFragColor = outColor;\n"
Cody Northrop02690bd2014-12-17 15:26:33 -07003194 "}\n";
3195
3196
Cody Northrop1684adb2015-08-05 11:15:02 -06003197 const float mixedVals[196] = { 1.0f, 0.0f, 0.0f, 1.0f, // vec4 fRed; // align
3198 0.0f, 1.0f, 0.0f, 1.0f, // vec4 fGreen; // align
3199 1.0f, 0.0f, 0.0f, 1.0f, // layout(row_major) mat4 worldToProj;
3200 0.0f, 1.0f, 0.0f, 1.0f, // align
3201 0.0f, 0.0f, 1.0f, 1.0f, // align
3202 0.0f, 0.0f, 0.0f, 1.0f, // align
3203 2.0f, 0.0f, 0.0f, 2.0f, // layout(row_major) mat4 projToWorld;
3204 0.0f, 2.0f, 0.0f, 2.0f, // align
3205 0.0f, 0.0f, 2.0f, 2.0f, // align
3206 0.0f, 0.0f, 0.0f, 2.0f, // align
3207 3.0f, 0.0f, 0.0f, 3.0f, // layout(row_major) mat4 worldToView;
3208 0.0f, 3.0f, 0.0f, 3.0f, // align
3209 0.0f, 0.0f, 3.0f, 3.0f, // align
3210 0.0f, 0.0f, 0.0f, 3.0f, // align
3211 4.0f, 0.0f, 0.0f, 4.0f, // layout(row_major) mat4 viewToProj;
3212 0.0f, 4.0f, 0.0f, 4.0f, // align
3213 0.0f, 0.0f, 4.0f, 4.0f, // align
3214 0.0f, 0.0f, 0.0f, 4.0f, // align
3215 5.0f, 0.0f, 0.0f, 5.0f, // layout(row_major) mat4 worldToShadow[4];
3216 0.0f, 5.0f, 0.0f, 5.0f, // align
3217 0.0f, 0.0f, 5.0f, 5.0f, // align
3218 0.0f, 0.0f, 0.0f, 5.0f, // align
3219 6.0f, 0.0f, 0.0f, 6.0f, // align
3220 0.0f, 6.0f, 0.0f, 6.0f, // align
3221 0.0f, 0.0f, 6.0f, 6.0f, // align
3222 0.0f, 0.0f, 0.0f, 6.0f, // align
3223 7.0f, 0.0f, 0.0f, 7.0f, // align
3224 0.0f, 7.0f, 0.0f, 7.0f, // align
3225 0.0f, 0.0f, 7.0f, 7.0f, // align
3226 0.0f, 0.0f, 0.0f, 7.0f, // align
3227 8.0f, 0.0f, 0.0f, 8.0f, // align
3228 0.0f, 8.0f, 0.0f, 8.0f, // align
3229 0.0f, 0.0f, 8.0f, 8.0f, // align
3230 0.0f, 0.0f, 0.0f, 8.0f, // align
3231 0.0f, // float fZero; // align
3232 1.0f, // float fOne; // pack
3233 2.0f, // float fTwo; // pack
3234 3.0f, // float fThree; // pack
3235 0.0f, 0.0f, 0.0f, // vec3 fZeroZeroZero; // align
3236 4.0f, // float fFour; // pack
3237 0.0f, 0.0f, 1.0f, // vec3 fZeroZeroOne; // align
3238 5.0f, // float fFive; // pack
3239 0.0f, 1.0f, 0.0f, // vec3 fZeroOneZero; // align
3240 6.0f, // float fSix; // pack
3241 7.0f, // float fSeven; // align
3242 8.0f, // float fEight; // pack
3243 9.0f, // float fNine; // pack
3244 0.0f, // BUFFER
3245 0.0f, 0.0f, // vec2 fZeroZero; // align
3246 0.0f, 1.0f, // vec2 fZeroOne; // pack
3247 0.0f, 0.0f, 1.0f, 1.0f, // vec4 fBlue; // align
3248 1.0f, 0.0f, // vec2 fOneZero; // align
3249 1.0f, 1.0f, // vec2 fOneOne; // pack
3250 0.0f, 1.0f, 1.0f, // vec3 fZeroOneOne; // align
3251 10.0f, // float fTen; // pack
3252 11.0f, // float fEleven; // align
3253 12.0f, // float fTwelve; // pack
3254 0.0f, 0.0f, // BUFFER
3255 1.0f, 0.0f, 0.0f, // vec3 fOneZeroZero; // align
3256 0.0f, // BUFFER
3257 0.1f, 0.2f, 0.3f, 0.4f, // vec4 uvOffsets[4];
3258 0.5f, 0.6f, 0.7f, 0.8f, // align
3259 0.9f, 1.0f, 1.1f, 1.2f, // align
3260 1.3f, 1.4f, 1.5f, 1.6f, // align
Cody Northrop02690bd2014-12-17 15:26:33 -07003261 };
3262
3263 ASSERT_NO_FATAL_FAILURE(InitState());
3264 ASSERT_NO_FATAL_FAILURE(InitViewport());
3265
3266 const int constCount = sizeof(mixedVals) / sizeof(float);
3267
Tony Barbour01999182015-04-09 12:58:51 -06003268 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3269 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop02690bd2014-12-17 15:26:33 -07003270
Tony Barbour01999182015-04-09 12:58:51 -06003271 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003272
Tony Barbour01999182015-04-09 12:58:51 -06003273 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003274 pipelineobj.AddColorAttachment();
Cody Northrop02690bd2014-12-17 15:26:33 -07003275 pipelineobj.AddShader(&vs);
3276 pipelineobj.AddShader(&ps);
3277
Tony Barbour01999182015-04-09 12:58:51 -06003278 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003279 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003280
3281 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003282 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop02690bd2014-12-17 15:26:33 -07003283
Tony Barbour1490c912015-07-28 10:17:20 -06003284 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop02690bd2014-12-17 15:26:33 -07003285
3286#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003287 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop02690bd2014-12-17 15:26:33 -07003288 pDSDumpDot((char*)"triTest2.dot");
3289#endif
3290 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06003291 Draw(0, 3, 0, 1);
Cody Northrop02690bd2014-12-17 15:26:33 -07003292
3293 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003294 EndCommandBuffer();
3295 QueueCommandBuffer();
Cody Northrop02690bd2014-12-17 15:26:33 -07003296
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003297 RecordImages(m_renderTargets);
Cody Northrop02690bd2014-12-17 15:26:33 -07003298}
3299
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003300TEST_F(VkRenderTest, TextureGather)
3301{
3302 // This test introduces textureGather and textureGatherOffset
3303 // Each call is compared against an expected inline color result
3304 // Green triangle means everything worked as expected
3305 // Red means something went wrong
3306
Cody Northropbe701ac2015-08-06 13:18:13 -06003307 // disable SPV until texture gather is turned on in glsl->SPV
3308 if (!m_use_glsl) {
3309 printf("Skipping test that requires GLSL path (TextureGather)\n");
3310 return;
3311 }
3312
Cody Northrop1cfbd172015-06-03 16:49:20 -06003313 ScopedUseGlsl useGlsl(true);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003314
3315 static const char *vertShaderText =
3316 "#version 140\n"
3317 "#extension GL_ARB_separate_shader_objects : enable\n"
3318 "#extension GL_ARB_shading_language_420pack : enable\n"
3319 "void main() {\n"
3320 " vec2 vertices[3];"
3321 " vertices[0] = vec2(-0.5, -0.5);\n"
3322 " vertices[1] = vec2( 0.5, -0.5);\n"
3323 " vertices[2] = vec2( 0.5, 0.5);\n"
3324 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
3325 "}\n";
3326
3327 static const char *fragShaderText =
3328 "#version 430\n"
3329 "#extension GL_ARB_separate_shader_objects : enable\n"
3330 "#extension GL_ARB_shading_language_420pack : enable\n"
3331 "layout (binding = 0) uniform sampler2D surface0;\n"
3332 "layout (binding = 1) uniform sampler2D surface1;\n"
3333 "layout (binding = 2) uniform sampler2D surface2;\n"
3334 "layout (binding = 3) uniform sampler2D surface3;\n"
3335 "layout (location = 0) out vec4 outColor;\n"
3336 "void main() {\n"
3337
3338 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3339 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3340
3341 " vec4 color = right;\n"
3342
3343 // Grab a normal texture sample to ensure it can work in conjuntion
3344 // with textureGather (there are some intracacies in the backend)
3345 " vec4 sampledColor = textureLod(surface2, vec2(0.5), 0.0);\n"
3346 " if (sampledColor != vec4(0.0, 0.0, 1.0, 1.0))\n"
3347 " color = wrong;\n"
3348
3349 " vec4 gatheredColor = textureGather(surface0, vec2(0.5), 0);\n"
3350 // This just grabbed four red components from a red surface
3351 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3352 " color = wrong;\n"
3353
3354 // Yes, this is using an offset of 0, we don't have enough fine grained
3355 // control of the texture contents here.
3356 " gatheredColor = textureGatherOffset(surface1, vec2(0.5), ivec2(0, 0), 1);\n"
3357 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3358 " color = wrong;\n"
3359
3360 " outColor = color;\n"
3361
3362 "}\n";
3363
3364 ASSERT_NO_FATAL_FAILURE(InitState());
3365 ASSERT_NO_FATAL_FAILURE(InitViewport());
3366
3367 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3368 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3369
3370 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
3371 VkSamplerObj sampler0(m_device);
3372 VkTextureObj texture0(m_device, tex_colors); // Red
3373 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
3374 VkSamplerObj sampler1(m_device);
3375 VkTextureObj texture1(m_device, tex_colors); // Green
3376 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
3377 VkSamplerObj sampler2(m_device);
3378 VkTextureObj texture2(m_device, tex_colors); // Blue
3379 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
3380 VkSamplerObj sampler3(m_device);
3381 VkTextureObj texture3(m_device, tex_colors); // Red and Blue
3382
3383 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003384 pipelineobj.AddColorAttachment();
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003385 pipelineobj.AddShader(&vs);
3386 pipelineobj.AddShader(&ps);
3387
3388 VkDescriptorSetObj descriptorSet(m_device);
3389 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3390 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
3391 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3392 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
3393
3394 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003395 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003396
Tony Barbour1490c912015-07-28 10:17:20 -06003397 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003398
3399 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06003400 Draw(0, 3, 0, 1);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003401
3402 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003403 EndCommandBuffer();
3404 QueueCommandBuffer();
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003405
3406 RecordImages(m_renderTargets);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003407}
3408
Cody Northropa44c2ff2015-04-15 11:19:06 -06003409TEST_F(VkRenderTest, GeometryShaderHelloWorld)
3410{
3411 // This test introduces a geometry shader that simply
3412 // changes the color of each vertex to red, green, blue
3413
3414 static const char *vertShaderText =
3415 "#version 140\n"
3416 "#extension GL_ARB_separate_shader_objects : enable\n"
3417 "#extension GL_ARB_shading_language_420pack : enable\n"
3418 "layout (location = 0) out vec4 color;"
3419 "void main() {\n"
3420
3421 // VS writes out red
3422 " color = vec4(1.0, 0.0, 0.0, 1.0);\n"
3423
3424 // generic position stuff
3425 " vec2 vertices;\n"
3426 " int vertexSelector = gl_VertexID;\n"
3427 " if (vertexSelector == 0)\n"
3428 " vertices = vec2(-0.5, -0.5);\n"
3429 " else if (vertexSelector == 1)\n"
3430 " vertices = vec2( 0.5, -0.5);\n"
3431 " else if (vertexSelector == 2)\n"
3432 " vertices = vec2( 0.5, 0.5);\n"
3433 " else\n"
3434 " vertices = vec2( 0.0, 0.0);\n"
3435 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3436
3437 "}\n";
3438
3439 static const char *geomShaderText =
3440 "#version 330\n"
3441 "#extension GL_ARB_separate_shader_objects : enable\n"
3442 "#extension GL_ARB_shading_language_420pack : enable\n"
3443 "layout( triangles ) in;\n"
3444 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3445 "layout( location = 0 ) in vec4 inColor[3];\n"
3446 "layout( location = 0 ) out vec4 outColor;\n"
3447 "void main()\n"
3448 "{\n"
3449
3450 // first vertex, pass through red
3451 " gl_Position = gl_in[0].gl_Position;\n"
3452 " outColor = inColor[0];\n"
3453 " EmitVertex();\n"
3454
3455 // second vertex, green
3456 " gl_Position = gl_in[1].gl_Position;\n"
3457 " outColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3458 " EmitVertex();\n"
3459
3460 // third vertex, blue
3461 " gl_Position = gl_in[2].gl_Position;\n"
3462 " outColor = vec4(0.0, 0.0, 1.0, 1.0);\n"
3463 " EmitVertex();\n"
3464
3465 // done
3466 " EndPrimitive();\n"
3467 "}\n";
3468
3469
3470 static const char *fragShaderText =
3471 "#version 140\n"
3472 "#extension GL_ARB_separate_shader_objects : enable\n"
3473 "#extension GL_ARB_shading_language_420pack : enable\n"
3474 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003475 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003476 "void main() {\n"
3477 // pass through
GregFd6ebdb32015-06-03 18:40:50 -06003478 " outColor = color;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003479 "}\n";
3480
3481
3482
3483 ASSERT_NO_FATAL_FAILURE(InitState());
3484 ASSERT_NO_FATAL_FAILURE(InitViewport());
3485
3486 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3487 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3488 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3489
3490 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003491 pipelineobj.AddColorAttachment();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003492 pipelineobj.AddShader(&vs);
3493 pipelineobj.AddShader(&gs);
3494 pipelineobj.AddShader(&ps);
3495
3496 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003497 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropa44c2ff2015-04-15 11:19:06 -06003498
3499 VkDescriptorSetObj descriptorSet(m_device);
3500
Tony Barbour1490c912015-07-28 10:17:20 -06003501 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003502
3503 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06003504 Draw(0, 3, 0, 1);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003505
3506 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003507 EndCommandBuffer();
3508 QueueCommandBuffer();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003509
3510 RecordImages(m_renderTargets);
3511}
3512
3513TEST_F(VkRenderTest, GSUniformBufferLayout)
3514{
3515 // This test is just like TriangleUniformBufferLayout but adds
3516 // geometry as a stage that also does UBO lookups
3517 // The expected result from this test is a green triangle
3518
3519 static const char *vertShaderText =
3520 "#version 140\n"
3521 "#extension GL_ARB_separate_shader_objects : enable\n"
3522 "#extension GL_ARB_shading_language_420pack : enable\n"
3523 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3524 " vec4 fRed;\n"
3525 " vec4 fGreen;\n"
3526 " layout(row_major) mat4 worldToProj;\n"
3527 " layout(row_major) mat4 projToWorld;\n"
3528 " layout(row_major) mat4 worldToView;\n"
3529 " layout(row_major) mat4 viewToProj;\n"
3530 " layout(row_major) mat4 worldToShadow[4];\n"
3531 " float fZero;\n"
3532 " float fOne;\n"
3533 " float fTwo;\n"
3534 " float fThree;\n"
3535 " vec3 fZeroZeroZero;\n"
3536 " float fFour;\n"
3537 " vec3 fZeroZeroOne;\n"
3538 " float fFive;\n"
3539 " vec3 fZeroOneZero;\n"
3540 " float fSix;\n"
3541 " float fSeven;\n"
3542 " float fEight;\n"
3543 " float fNine;\n"
3544 " vec2 fZeroZero;\n"
3545 " vec2 fZeroOne;\n"
3546 " vec4 fBlue;\n"
3547 " vec2 fOneZero;\n"
3548 " vec2 fOneOne;\n"
3549 " vec3 fZeroOneOne;\n"
3550 " float fTen;\n"
3551 " float fEleven;\n"
3552 " float fTwelve;\n"
3553 " vec3 fOneZeroZero;\n"
3554 " vec4 uvOffsets[4];\n"
3555 "};\n"
3556 "layout (location = 0) out vec4 color;"
3557 "void main() {\n"
3558
3559 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3560 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3561 " \n"
3562
3563 // do some exact comparisons, even though we should
3564 // really have an epsilon involved.
3565 " vec4 outColor = right;\n"
3566 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3567 " outColor = wrong;\n"
3568 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3569 " outColor = wrong;\n"
3570 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3571 " outColor = wrong;\n"
3572
3573 " color = outColor;\n"
3574
3575 // generic position stuff
3576 " vec2 vertices;\n"
3577 " int vertexSelector = gl_VertexID;\n"
3578 " if (vertexSelector == 0)\n"
3579 " vertices = vec2(-0.5, -0.5);\n"
3580 " else if (vertexSelector == 1)\n"
3581 " vertices = vec2( 0.5, -0.5);\n"
3582 " else if (vertexSelector == 2)\n"
3583 " vertices = vec2( 0.5, 0.5);\n"
3584 " else\n"
3585 " vertices = vec2( 0.0, 0.0);\n"
3586 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3587 "}\n";
3588
3589 static const char *geomShaderText =
3590 "#version 330\n"
3591 "#extension GL_ARB_separate_shader_objects : enable\n"
3592 "#extension GL_ARB_shading_language_420pack : enable\n"
3593
3594 // GS layout stuff
3595 "layout( triangles ) in;\n"
3596 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3597
3598 // Between stage IO
3599 "layout( location = 0 ) in vec4 inColor[3];\n"
3600 "layout( location = 0 ) out vec4 color;\n"
3601
3602 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3603 " vec4 fRed;\n"
3604 " vec4 fGreen;\n"
3605 " layout(row_major) mat4 worldToProj;\n"
3606 " layout(row_major) mat4 projToWorld;\n"
3607 " layout(row_major) mat4 worldToView;\n"
3608 " layout(row_major) mat4 viewToProj;\n"
3609 " layout(row_major) mat4 worldToShadow[4];\n"
3610 " float fZero;\n"
3611 " float fOne;\n"
3612 " float fTwo;\n"
3613 " float fThree;\n"
3614 " vec3 fZeroZeroZero;\n"
3615 " float fFour;\n"
3616 " vec3 fZeroZeroOne;\n"
3617 " float fFive;\n"
3618 " vec3 fZeroOneZero;\n"
3619 " float fSix;\n"
3620 " float fSeven;\n"
3621 " float fEight;\n"
3622 " float fNine;\n"
3623 " vec2 fZeroZero;\n"
3624 " vec2 fZeroOne;\n"
3625 " vec4 fBlue;\n"
3626 " vec2 fOneZero;\n"
3627 " vec2 fOneOne;\n"
3628 " vec3 fZeroOneOne;\n"
3629 " float fTen;\n"
3630 " float fEleven;\n"
3631 " float fTwelve;\n"
3632 " vec3 fOneZeroZero;\n"
3633 " vec4 uvOffsets[4];\n"
3634 "};\n"
3635
3636 "void main()\n"
3637 "{\n"
3638
3639 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3640 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3641
3642 // Each vertex will validate it can read VS output
3643 // then check a few values from the UBO
3644
3645 // first vertex
3646 " vec4 outColor = inColor[0];\n"
3647
3648 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3649 " outColor = wrong;\n"
3650 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3651 " outColor = wrong;\n"
3652 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3653 " outColor = wrong;\n"
3654 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3655 " outColor = wrong;\n"
3656
3657 " gl_Position = gl_in[0].gl_Position;\n"
3658 " color = outColor;\n"
3659 " EmitVertex();\n"
3660
3661 // second vertex
3662 " outColor = inColor[1];\n"
3663
3664 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3665 " outColor = wrong;\n"
3666 " if (fSix != 6.0)\n"
3667 " outColor = wrong;\n"
3668 " if (fOneOne != vec2(1.0, 1.0))\n"
3669 " outColor = wrong;\n"
3670
3671 " gl_Position = gl_in[1].gl_Position;\n"
3672 " color = outColor;\n"
3673 " EmitVertex();\n"
3674
3675 // third vertex
3676 " outColor = inColor[2];\n"
3677
3678 " if (fSeven != 7.0)\n"
3679 " outColor = wrong;\n"
3680 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3681 " outColor = wrong;\n"
3682
3683 " gl_Position = gl_in[2].gl_Position;\n"
3684 " color = outColor;\n"
3685 " EmitVertex();\n"
3686
3687 // done
3688 " EndPrimitive();\n"
3689 "}\n";
3690
3691 static const char *fragShaderText =
3692 "#version 140\n"
3693 "#extension GL_ARB_separate_shader_objects : enable\n"
3694 "#extension GL_ARB_shading_language_420pack : enable\n"
3695 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3696 " vec4 fRed;\n"
3697 " vec4 fGreen;\n"
3698 " layout(row_major) mat4 worldToProj;\n"
3699 " layout(row_major) mat4 projToWorld;\n"
3700 " layout(row_major) mat4 worldToView;\n"
3701 " layout(row_major) mat4 viewToProj;\n"
3702 " layout(row_major) mat4 worldToShadow[4];\n"
3703 " float fZero;\n"
3704 " float fOne;\n"
3705 " float fTwo;\n"
3706 " float fThree;\n"
3707 " vec3 fZeroZeroZero;\n"
3708 " float fFour;\n"
3709 " vec3 fZeroZeroOne;\n"
3710 " float fFive;\n"
3711 " vec3 fZeroOneZero;\n"
3712 " float fSix;\n"
3713 " float fSeven;\n"
3714 " float fEight;\n"
3715 " float fNine;\n"
3716 " vec2 fZeroZero;\n"
3717 " vec2 fZeroOne;\n"
3718 " vec4 fBlue;\n"
3719 " vec2 fOneZero;\n"
3720 " vec2 fOneOne;\n"
3721 " vec3 fZeroOneOne;\n"
3722 " float fTen;\n"
3723 " float fEleven;\n"
3724 " float fTwelve;\n"
3725 " vec3 fOneZeroZero;\n"
3726 " vec4 uvOffsets[4];\n"
3727 "};\n"
3728 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003729 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003730 "void main() {\n"
3731 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3732 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3733 " \n"
3734
3735 // start with GS value to ensure it passed
3736 " vec4 outColor = color;\n"
3737
3738 // do some exact comparisons, even though we should
3739 // really have an epsilon involved.
3740 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3741 " outColor = wrong;\n"
3742 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3743 " outColor = wrong;\n"
3744 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3745 " outColor = wrong;\n"
3746 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3747 " outColor = wrong;\n"
3748 " if (fTwo != 2.0)\n"
3749 " outColor = wrong;\n"
3750 " if (fOneOne != vec2(1.0, 1.0))\n"
3751 " outColor = wrong;\n"
3752 " if (fTen != 10.0)\n"
3753 " outColor = wrong;\n"
3754 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3755 " outColor = wrong;\n"
3756 " \n"
GregFd6ebdb32015-06-03 18:40:50 -06003757 " uFragColor = outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003758 "}\n";
3759
3760
Cody Northrop1684adb2015-08-05 11:15:02 -06003761 const float mixedVals[196] = { 1.0f, 0.0f, 0.0f, 1.0f, // vec4 fRed; // align
3762 0.0f, 1.0f, 0.0f, 1.0f, // vec4 fGreen; // align
3763 1.0f, 0.0f, 0.0f, 1.0f, // layout(row_major) mat4 worldToProj;
3764 0.0f, 1.0f, 0.0f, 1.0f, // align
3765 0.0f, 0.0f, 1.0f, 1.0f, // align
3766 0.0f, 0.0f, 0.0f, 1.0f, // align
3767 2.0f, 0.0f, 0.0f, 2.0f, // layout(row_major) mat4 projToWorld;
3768 0.0f, 2.0f, 0.0f, 2.0f, // align
3769 0.0f, 0.0f, 2.0f, 2.0f, // align
3770 0.0f, 0.0f, 0.0f, 2.0f, // align
3771 3.0f, 0.0f, 0.0f, 3.0f, // layout(row_major) mat4 worldToView;
3772 0.0f, 3.0f, 0.0f, 3.0f, // align
3773 0.0f, 0.0f, 3.0f, 3.0f, // align
3774 0.0f, 0.0f, 0.0f, 3.0f, // align
3775 4.0f, 0.0f, 0.0f, 4.0f, // layout(row_major) mat4 viewToProj;
3776 0.0f, 4.0f, 0.0f, 4.0f, // align
3777 0.0f, 0.0f, 4.0f, 4.0f, // align
3778 0.0f, 0.0f, 0.0f, 4.0f, // align
3779 5.0f, 0.0f, 0.0f, 5.0f, // layout(row_major) mat4 worldToShadow[4];
3780 0.0f, 5.0f, 0.0f, 5.0f, // align
3781 0.0f, 0.0f, 5.0f, 5.0f, // align
3782 0.0f, 0.0f, 0.0f, 5.0f, // align
3783 6.0f, 0.0f, 0.0f, 6.0f, // align
3784 0.0f, 6.0f, 0.0f, 6.0f, // align
3785 0.0f, 0.0f, 6.0f, 6.0f, // align
3786 0.0f, 0.0f, 0.0f, 6.0f, // align
3787 7.0f, 0.0f, 0.0f, 7.0f, // align
3788 0.0f, 7.0f, 0.0f, 7.0f, // align
3789 0.0f, 0.0f, 7.0f, 7.0f, // align
3790 0.0f, 0.0f, 0.0f, 7.0f, // align
3791 8.0f, 0.0f, 0.0f, 8.0f, // align
3792 0.0f, 8.0f, 0.0f, 8.0f, // align
3793 0.0f, 0.0f, 8.0f, 8.0f, // align
3794 0.0f, 0.0f, 0.0f, 8.0f, // align
3795 0.0f, // float fZero; // align
3796 1.0f, // float fOne; // pack
3797 2.0f, // float fTwo; // pack
3798 3.0f, // float fThree; // pack
3799 0.0f, 0.0f, 0.0f, // vec3 fZeroZeroZero; // align
3800 4.0f, // float fFour; // pack
3801 0.0f, 0.0f, 1.0f, // vec3 fZeroZeroOne; // align
3802 5.0f, // float fFive; // pack
3803 0.0f, 1.0f, 0.0f, // vec3 fZeroOneZero; // align
3804 6.0f, // float fSix; // pack
3805 7.0f, // float fSeven; // align
3806 8.0f, // float fEight; // pack
3807 9.0f, // float fNine; // pack
3808 0.0f, // BUFFER
3809 0.0f, 0.0f, // vec2 fZeroZero; // align
3810 0.0f, 1.0f, // vec2 fZeroOne; // pack
3811 0.0f, 0.0f, 1.0f, 1.0f, // vec4 fBlue; // align
3812 1.0f, 0.0f, // vec2 fOneZero; // align
3813 1.0f, 1.0f, // vec2 fOneOne; // pack
3814 0.0f, 1.0f, 1.0f, // vec3 fZeroOneOne; // align
3815 10.0f, // float fTen; // pack
3816 11.0f, // float fEleven; // align
3817 12.0f, // float fTwelve; // pack
3818 0.0f, 0.0f, // BUFFER
3819 1.0f, 0.0f, 0.0f, // vec3 fOneZeroZero; // align
3820 0.0f, // BUFFER
3821 0.1f, 0.2f, 0.3f, 0.4f, // vec4 uvOffsets[4];
3822 0.5f, 0.6f, 0.7f, 0.8f, // align
3823 0.9f, 1.0f, 1.1f, 1.2f, // align
3824 1.3f, 1.4f, 1.5f, 1.6f, // align
Cody Northropa44c2ff2015-04-15 11:19:06 -06003825 };
3826
3827
3828
3829 ASSERT_NO_FATAL_FAILURE(InitState());
3830 ASSERT_NO_FATAL_FAILURE(InitViewport());
3831
3832 const int constCount = sizeof(mixedVals) / sizeof(float);
3833
3834 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3835 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3836 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3837
3838 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
3839
3840 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003841 pipelineobj.AddColorAttachment();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003842 pipelineobj.AddShader(&vs);
3843 pipelineobj.AddShader(&gs);
3844 pipelineobj.AddShader(&ps);
3845
3846 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003847 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropa44c2ff2015-04-15 11:19:06 -06003848
3849 VkDescriptorSetObj descriptorSet(m_device);
3850 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
3851
Tony Barbour1490c912015-07-28 10:17:20 -06003852 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003853
3854 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06003855 Draw(0, 3, 0, 1);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003856
3857 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003858 EndCommandBuffer();
3859 QueueCommandBuffer();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003860
3861 RecordImages(m_renderTargets);
3862}
3863
3864TEST_F(VkRenderTest, GSPositions)
3865{
3866 // This test adds more inputs from the vertex shader and perturbs positions
3867 // Expected result is white triangle with weird positions
3868
3869 static const char *vertShaderText =
3870 "#version 140\n"
3871 "#extension GL_ARB_separate_shader_objects : enable\n"
3872 "#extension GL_ARB_shading_language_420pack : enable\n"
3873
3874 "layout(location = 0) out vec3 out_a;\n"
3875 "layout(location = 1) out vec3 out_b;\n"
3876 "layout(location = 2) out vec3 out_c;\n"
3877
3878 "void main() {\n"
3879
3880 // write a solid color to each
3881 " out_a = vec3(1.0, 0.0, 0.0);\n"
3882 " out_b = vec3(0.0, 1.0, 0.0);\n"
3883 " out_c = vec3(0.0, 0.0, 1.0);\n"
3884
3885 // generic position stuff
3886 " vec2 vertices;\n"
3887 " int vertexSelector = gl_VertexID;\n"
3888 " if (vertexSelector == 0)\n"
3889 " vertices = vec2(-0.5, -0.5);\n"
3890 " else if (vertexSelector == 1)\n"
3891 " vertices = vec2( 0.5, -0.5);\n"
3892 " else if (vertexSelector == 2)\n"
3893 " vertices = vec2( 0.5, 0.5);\n"
3894 " else\n"
3895 " vertices = vec2( 0.0, 0.0);\n"
3896 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3897
3898 "}\n";
3899
3900 static const char *geomShaderText =
3901 "#version 330\n"
3902 "#extension GL_ARB_separate_shader_objects : enable\n"
3903 "#extension GL_ARB_shading_language_420pack : enable\n"
3904 "layout( triangles ) in;\n"
3905 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3906
3907 "layout(location = 0) in vec3 in_a[3];\n"
3908 "layout(location = 1) in vec3 in_b[3];\n"
3909 "layout(location = 2) in vec3 in_c[3];\n"
3910
3911 "layout(location = 0) out vec3 out_a;\n"
3912 "layout(location = 1) out vec3 out_b;\n"
3913 "layout(location = 2) out vec3 out_c;\n"
3914
3915 "void main()\n"
3916 "{\n"
3917
3918 " gl_Position = gl_in[0].gl_Position;\n"
3919 " gl_Position.xy *= vec2(0.75);\n"
3920 " out_a = in_a[0];\n"
3921 " out_b = in_b[0];\n"
3922 " out_c = in_c[0];\n"
3923 " EmitVertex();\n"
3924
3925 " gl_Position = gl_in[1].gl_Position;\n"
3926 " gl_Position.xy *= vec2(1.5);\n"
3927 " out_a = in_a[1];\n"
3928 " out_b = in_b[1];\n"
3929 " out_c = in_c[1];\n"
3930 " EmitVertex();\n"
3931
3932 " gl_Position = gl_in[2].gl_Position;\n"
3933 " gl_Position.xy *= vec2(-0.1);\n"
3934 " out_a = in_a[2];\n"
3935 " out_b = in_b[2];\n"
3936 " out_c = in_c[2];\n"
3937 " EmitVertex();\n"
3938
3939 " EndPrimitive();\n"
3940 "}\n";
3941
3942
3943 static const char *fragShaderText =
3944 "#version 140\n"
3945 "#extension GL_ARB_separate_shader_objects : enable\n"
3946 "#extension GL_ARB_shading_language_420pack : enable\n"
3947
3948 "layout(location = 0) in vec3 in_a;\n"
3949 "layout(location = 1) in vec3 in_b;\n"
3950 "layout(location = 2) in vec3 in_c;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003951 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003952
3953 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06003954 " outColor = vec4(in_a.x, in_b.y, in_c.z, 1.0);\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003955 "}\n";
3956
3957
3958
3959 ASSERT_NO_FATAL_FAILURE(InitState());
3960 ASSERT_NO_FATAL_FAILURE(InitViewport());
3961
3962 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3963 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3964 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3965
3966 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003967 pipelineobj.AddColorAttachment();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003968 pipelineobj.AddShader(&vs);
3969 pipelineobj.AddShader(&gs);
3970 pipelineobj.AddShader(&ps);
3971
3972 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003973 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropa44c2ff2015-04-15 11:19:06 -06003974
3975 VkDescriptorSetObj descriptorSet(m_device);
3976
Tony Barbour1490c912015-07-28 10:17:20 -06003977 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003978
3979 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06003980 Draw(0, 3, 0, 1);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003981
3982 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003983 EndCommandBuffer();
3984 QueueCommandBuffer();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003985
3986 RecordImages(m_renderTargets);
3987}
3988
3989TEST_F(VkRenderTest, GSTriStrip)
3990{
3991 // This test emits multiple multiple triangles using a GS
3992 // Correct result is an multicolor circle
3993
3994 static const char *vertShaderText =
3995 "#version 140\n"
3996 "#extension GL_ARB_separate_shader_objects : enable\n"
3997 "#extension GL_ARB_shading_language_420pack : enable\n"
3998
3999 "void main() {\n"
4000
4001 // generic position stuff
4002 " vec2 vertices;\n"
4003 " int vertexSelector = gl_VertexID;\n"
4004 " if (vertexSelector == 0)\n"
4005 " vertices = vec2(-0.5, -0.5);\n"
4006 " else if (vertexSelector == 1)\n"
4007 " vertices = vec2( 0.5, -0.5);\n"
4008 " else if (vertexSelector == 2)\n"
4009 " vertices = vec2( 0.5, 0.5);\n"
4010 " else\n"
4011 " vertices = vec2( 0.0, 0.0);\n"
4012 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
4013
4014 "}\n";
4015
4016 static const char *geomShaderText =
4017 "#version 330\n"
4018 "#extension GL_ARB_separate_shader_objects : enable\n"
4019 "#extension GL_ARB_shading_language_420pack : enable\n"
4020 "layout( triangles ) in;\n"
4021 "layout( triangle_strip, max_vertices = 18 ) out;\n"
4022
4023 "layout(location = 0) out vec4 outColor;\n"
4024
4025 "void main()\n"
4026 "{\n"
4027 // init with first position to get zw
4028 " gl_Position = gl_in[0].gl_Position;\n"
4029
4030 " vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
4031 " vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
4032 " vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
4033 " vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
4034
4035 // different color per tri
4036 " vec4[6] colors = { red, white, \n"
4037 " yellow, white, \n"
4038 " blue, white }; \n"
4039
4040 // fan out the triangles
4041 " vec2[18] positions = { vec2(0.0, 0.0), vec2(-0.5, 0.0), vec2(-0.25, -0.5), \n"
4042 " vec2(0.0, 0.0), vec2(-0.25, -0.5), vec2( 0.25, -0.5), \n"
4043 " vec2(0.0, 0.0), vec2( 0.25, -0.5), vec2( 0.5, 0.0), \n"
4044 " vec2(0.0, 0.0), vec2( 0.5, 0.0), vec2( 0.25, 0.5), \n"
4045 " vec2(0.0, 0.0), vec2( 0.25, 0.5), vec2(-0.25, 0.5), \n"
4046 " vec2(0.0, 0.0), vec2(-0.25, 0.5), vec2(-0.5, 0.0) }; \n"
4047
4048 // make a triangle list of 6
4049 " for (int i = 0; i < 6; ++i) { \n"
4050 " outColor = colors[i]; \n"
4051 " for (int j = 0; j < 3; ++j) { \n"
4052 " gl_Position.xy = positions[i * 3 + j]; \n"
4053 " EmitVertex(); \n"
4054 " } \n"
4055 " EndPrimitive();\n"
4056 " } \n"
4057
4058 "}\n";
4059
4060
4061 static const char *fragShaderText =
4062 "#version 150\n"
4063 "#extension GL_ARB_separate_shader_objects : enable\n"
4064 "#extension GL_ARB_shading_language_420pack : enable\n"
4065
4066
4067 "layout(binding = 0) uniform windowDimensions {\n"
4068 " vec4 dimensions;\n"
4069 "};\n"
4070
4071 "layout(location = 0) in vec4 inColor;\n"
4072 "layout(origin_upper_left) in vec4 gl_FragCoord;\n"
GregFd6ebdb32015-06-03 18:40:50 -06004073 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06004074
4075 "void main() {\n"
4076
4077 // discard to make a nice circle
4078 " vec2 pos = abs(gl_FragCoord.xy) - vec2(dimensions.x, dimensions.y) / 2;\n"
4079 " float dist = sqrt(dot(pos, pos));\n"
4080 " if (dist > 50.0)\n"
4081 " discard;\n"
4082
GregFd6ebdb32015-06-03 18:40:50 -06004083 " outColor = inColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06004084
4085 "}\n";
4086
4087
4088
4089 ASSERT_NO_FATAL_FAILURE(InitState());
4090 ASSERT_NO_FATAL_FAILURE(InitViewport());
4091
4092 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
4093 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
4094 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
4095
4096 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004097 pipelineobj.AddColorAttachment();
Cody Northropa44c2ff2015-04-15 11:19:06 -06004098 pipelineobj.AddShader(&vs);
4099 pipelineobj.AddShader(&gs);
4100 pipelineobj.AddShader(&ps);
4101
4102 const float dimensions[4] = { VkRenderFramework::m_width, VkRenderFramework::m_height , 0.0, 0.0};
4103
4104 VkConstantBufferObj windowDimensions(m_device, sizeof(dimensions) / sizeof(dimensions[0]), sizeof(dimensions[0]), (const void*) dimensions);
4105
4106 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06004107 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropa44c2ff2015-04-15 11:19:06 -06004108
4109 VkDescriptorSetObj descriptorSet(m_device);
4110 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, windowDimensions);
4111
Tony Barbour1490c912015-07-28 10:17:20 -06004112 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northropa44c2ff2015-04-15 11:19:06 -06004113
4114 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06004115 Draw(0, 3, 0, 1);
Cody Northropa44c2ff2015-04-15 11:19:06 -06004116
4117 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06004118 EndCommandBuffer();
4119 QueueCommandBuffer();
Cody Northropa44c2ff2015-04-15 11:19:06 -06004120
4121 RecordImages(m_renderTargets);
4122}
4123
Chris Forbes23e6db62015-06-15 09:32:35 +12004124TEST_F(VkRenderTest, RenderPassLoadOpClear)
4125{
4126 ASSERT_NO_FATAL_FAILURE(InitState());
4127 ASSERT_NO_FATAL_FAILURE(InitViewport());
4128
4129 /* clear via load op to full green */
4130 m_clear_via_load_op = true;
Cody Northrop2563a032015-08-25 15:26:38 -06004131 m_clear_color.float32[0] = 0;
4132 m_clear_color.float32[1] = 1;
4133 m_clear_color.float32[2] = 0;
4134 m_clear_color.float32[3] = 0;
Chris Forbes23e6db62015-06-15 09:32:35 +12004135 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06004136 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Chris Forbes23e6db62015-06-15 09:32:35 +12004137 /* This command buffer contains ONLY the load op! */
Tony Barbour1490c912015-07-28 10:17:20 -06004138 EndCommandBuffer();
4139 QueueCommandBuffer();
Chris Forbes23e6db62015-06-15 09:32:35 +12004140
4141 RecordImages(m_renderTargets);
4142}
4143
Chris Forbes1e16cb82015-06-24 12:05:30 +12004144TEST_F(VkRenderTest, RenderPassAttachmentClear)
4145{
4146 ASSERT_NO_FATAL_FAILURE(InitState());
4147 ASSERT_NO_FATAL_FAILURE(InitViewport());
4148
4149 /* clear via load op to full red */
4150 m_clear_via_load_op = true;
Cody Northrop2563a032015-08-25 15:26:38 -06004151 m_clear_color.float32[0] = 1;
4152 m_clear_color.float32[1] = 0;
4153 m_clear_color.float32[2] = 0;
4154 m_clear_color.float32[3] = 0;
Chris Forbes1e16cb82015-06-24 12:05:30 +12004155 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06004156 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Chris Forbes1e16cb82015-06-24 12:05:30 +12004157
4158 /* Load op has cleared to red */
4159
4160 /* Draw, draw, draw... */
4161
4162 /* Now, partway through this renderpass we want to clear the color
4163 * attachment again, this time to green.
4164 */
Chris Forbese3105972015-06-24 14:34:53 +12004165 VkClearColorValue clear_color;
Cody Northrop2563a032015-08-25 15:26:38 -06004166 clear_color.float32[0] = 0;
4167 clear_color.float32[1] = 1;
4168 clear_color.float32[2] = 0;
4169 clear_color.float32[3] = 0;
Chris Forbes1e16cb82015-06-24 12:05:30 +12004170 VkRect3D clear_rect = { { 0, 0, 0 }, { (int)m_width, (int)m_height, 1 } };
Tony Barbour1490c912015-07-28 10:17:20 -06004171 vkCmdClearColorAttachment(m_cmdBuffer->handle(), 0,
Chris Forbes1e16cb82015-06-24 12:05:30 +12004172 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4173 &clear_color, 1, &clear_rect);
4174
Tony Barbour1490c912015-07-28 10:17:20 -06004175 EndCommandBuffer();
4176 QueueCommandBuffer();
Chris Forbes1e16cb82015-06-24 12:05:30 +12004177
4178 RecordImages(m_renderTargets);
4179}
4180
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004181int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004182 int result;
4183
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004184 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06004185 VkTestFramework::InitArgs(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004186
Chia-I Wu7133fdc2014-12-15 23:57:34 +08004187 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06004188
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004189 result = RUN_ALL_TESTS();
4190
Tony Barbour01999182015-04-09 12:58:51 -06004191 VkTestFramework::Finish();
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004192 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004193}