blob: 812656d7e55bbce8cfb101915b8dccf8a8be307d [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();
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600387 cmdBuffer->SetLineWidth(m_lineWidth);
388 cmdBuffer->SetDepthBias(m_depthBias, m_depthBiasClamp, m_slopeScaledDepthBias);
389 cmdBuffer->SetViewport(m_viewports.size(), m_viewports.data(), m_scissors.data());
390 cmdBuffer->SetBlendConstants(m_blendConst);
391 cmdBuffer->SetDepthBounds(m_minDepthBounds, m_maxDepthBounds);
392 cmdBuffer->SetStencilReadMask(VK_STENCIL_FACE_FRONT_BIT | VK_STENCIL_FACE_BACK_BIT, m_stencilCompareMask);
393 cmdBuffer->SetStencilWriteMask(VK_STENCIL_FACE_FRONT_BIT | VK_STENCIL_FACE_BACK_BIT, m_stencilWriteMask);
394 cmdBuffer->SetStencilReference(VK_STENCIL_FACE_FRONT_BIT | VK_STENCIL_FACE_BACK_BIT, m_stencilReference);
395
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600396 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
Cody Northropccfa96d2015-08-27 10:20:35 -0600397 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
398 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600399 cmdBuffer->BindPipeline(pipelineobj);
Chia-I Wu862c5572015-03-28 15:23:55 +0800400 cmdBuffer->BindDescriptorSet(descriptorSet);
Tony Barbour02472db2015-01-08 17:08:28 -0700401}
Tony Barbourf43b6982014-11-25 13:18:32 -0700402
Tony Barbour01999182015-04-09 12:58:51 -0600403void VkRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
404 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer)
Tony Barbourdd4c9642015-01-09 12:55:14 -0700405{
406 int i;
407 glm::mat4 MVP;
408 int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600409 VkResult err;
Tony Barbourdd4c9642015-01-09 12:55:14 -0700410
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600411 /* Only do 3 positions to avoid back face cull */
412 for (i = 0; i < 3; i++) {
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800413 void *pData = constantBuffer->memory().map();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700414
415 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
416 MVP = Projection * View * Model;
417 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
418
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800419 constantBuffer->memory().unmap();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700420
421 // submit the command buffer to the universal queue
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600422 cmdBuffer->QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700423
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600424 err = vkQueueWaitIdle( m_device->m_queue );
425 ASSERT_VK_SUCCESS( err );
Tony Barbourdd4c9642015-01-09 12:55:14 -0700426
427 // Wait for work to finish before cleaning up.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600428 vkDeviceWaitIdle(m_device->device());
Tony Barbourdd4c9642015-01-09 12:55:14 -0700429
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700430 assert(m_renderTargets.size() == 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -0700431 RecordImage(m_renderTargets[0]);
432 }
433}
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600434
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600435void dumpMatrix(const char *note, glm::mat4 MVP)
436{
Chia-I Wu7133fdc2014-12-15 23:57:34 +0800437 int i;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600438
439 printf("%s: \n", note);
440 for (i=0; i<4; i++) {
441 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
442 }
443 printf("\n");
444 fflush(stdout);
445}
446
447void dumpVec4(const char *note, glm::vec4 vector)
448{
449 printf("%s: \n", note);
450 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
451 printf("\n");
452 fflush(stdout);
453}
454
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600455struct vktriangle_vs_uniform {
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600456 // Must start with MVP
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600457 float mvp[4][4];
458 float position[3][4];
459 float color[3][4];
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600460};
461
Tony Barbour01999182015-04-09 12:58:51 -0600462void VkRenderTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600463{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700464#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600465 vkDbgRegisterMsgCallback(inst, myDbgFunc, NULL);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700466#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600467 // Create identity matrix
468 int i;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600469 struct vktriangle_vs_uniform data;
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600470
471 glm::mat4 Projection = glm::mat4(1.0f);
472 glm::mat4 View = glm::mat4(1.0f);
473 glm::mat4 Model = glm::mat4(1.0f);
474 glm::mat4 MVP = Projection * View * Model;
475 const int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600476 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600477 memcpy(&data.mvp, &MVP[0][0], matrixSize);
478
479 static const Vertex tri_data[] =
480 {
481 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
482 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
483 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
484 };
485
486 for (i=0; i<3; i++) {
487 data.position[i][0] = tri_data[i].posX;
488 data.position[i][1] = tri_data[i].posY;
489 data.position[i][2] = tri_data[i].posZ;
490 data.position[i][3] = tri_data[i].posW;
491 data.color[i][0] = tri_data[i].r;
492 data.color[i][1] = tri_data[i].g;
493 data.color[i][2] = tri_data[i].b;
494 data.color[i][3] = tri_data[i].a;
495 }
496
Tony Barbourf43b6982014-11-25 13:18:32 -0700497 ASSERT_NO_FATAL_FAILURE(InitState());
498 ASSERT_NO_FATAL_FAILURE(InitViewport());
499
Tony Barbour01999182015-04-09 12:58:51 -0600500 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barbourf43b6982014-11-25 13:18:32 -0700501
Tony Barbour01999182015-04-09 12:58:51 -0600502 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
503 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700504
Tony Barbour01999182015-04-09 12:58:51 -0600505 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800506 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -0700507 pipelineobj.AddShader(&vs);
508 pipelineobj.AddShader(&ps);
509
Tony Barbour01999182015-04-09 12:58:51 -0600510 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600511 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700512
Tony Barbour71ba3612015-01-09 16:12:35 -0700513 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis7f7b4422015-08-18 14:24:32 -0600514
515 VkCmdBufferBeginInfo cbBeginInfo;
516 memset(&cbBeginInfo, 0, sizeof(VkCmdBufferBeginInfo));
517 cbBeginInfo.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
518 cbBeginInfo.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT;
519 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barbourf43b6982014-11-25 13:18:32 -0700520
Tony Barbour1490c912015-07-28 10:17:20 -0600521 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbour71ba3612015-01-09 16:12:35 -0700522#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600523 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour71ba3612015-01-09 16:12:35 -0700524 pDSDumpDot((char*)"triTest2.dot");
525#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600526
Tony Barbour71ba3612015-01-09 16:12:35 -0700527 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -0600528 Draw(0, 3, 0, 1);
Tony Barbour71ba3612015-01-09 16:12:35 -0700529
530 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600531 ASSERT_VK_SUCCESS(EndCommandBuffer());
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600532
Tony Barbour1490c912015-07-28 10:17:20 -0600533 QueueCommandBuffer();
Tony Barbour71ba3612015-01-09 16:12:35 -0700534
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600535 RecordImages(m_renderTargets);
Tony Barbour71ba3612015-01-09 16:12:35 -0700536
537 if (rotate)
Tony Barbour1490c912015-07-28 10:17:20 -0600538 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer);
Tony Barbour71ba3612015-01-09 16:12:35 -0700539
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700540#ifdef PRINT_OBJECTS
Mark Lobodzinski4e5016f2015-05-05 15:01:37 -0500541 OBJ_TRACK_GET_OBJECTS_COUNT pObjTrackGetObjectsCount = (OBJ_TRACK_GET_OBJECTS_COUNT)vkGetProcAddr(gpu(), (char*)"objTrackGetObjectsCount");
Mark Lobodzinski14305ad2015-06-23 11:35:12 -0600542 uint64_t numObjects = pObjTrackGetObjectsCount(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600543 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700544 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600545 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700546 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
Mark Lobodzinski14305ad2015-06-23 11:35:12 -0600547 pObjTrackGetObjs(m_device, numObjects, pObjNodeArray);
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700548 for (i=0; i < numObjects; i++) {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600549 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 -0700550 }
551 free(pObjNodeArray);
552#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700553
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600554}
555
Tony Barbour01999182015-04-09 12:58:51 -0600556TEST_F(VkRenderTest, VKTriangle_FragColor)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600557{
558 static const char *vertShaderText =
559 "#version 140\n"
560 "#extension GL_ARB_separate_shader_objects : enable\n"
561 "#extension GL_ARB_shading_language_420pack : enable\n"
562 "\n"
563 "layout(binding = 0) uniform buf {\n"
564 " mat4 MVP;\n"
565 " vec4 position[3];\n"
566 " vec4 color[3];\n"
567 "} ubuf;\n"
568 "\n"
569 "layout (location = 0) out vec4 outColor;\n"
570 "\n"
571 "void main() \n"
572 "{\n"
573 " outColor = ubuf.color[gl_VertexID];\n"
574 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
575 "}\n";
576
577 static const char *fragShaderText =
578 "#version 140\n"
579 "#extension GL_ARB_separate_shader_objects : enable\n"
580 "#extension GL_ARB_shading_language_420pack : enable\n"
581 "\n"
582 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600583 "layout (location = 0) out vec4 uFragColor;\n"
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600584 "\n"
585 "void main()\n"
586 "{\n"
GregFd6ebdb32015-06-03 18:40:50 -0600587 " uFragColor = inColor;\n"
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600588 "}\n";
589
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600590 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
591 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600592}
593
Tony Barbour01999182015-04-09 12:58:51 -0600594TEST_F(VkRenderTest, VKTriangle_OutputLocation)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600595{
596 static const char *vertShaderText =
597 "#version 140\n"
598 "#extension GL_ARB_separate_shader_objects : enable\n"
599 "#extension GL_ARB_shading_language_420pack : enable\n"
600 "\n"
601 "layout(binding = 0) uniform buf {\n"
602 " mat4 MVP;\n"
603 " vec4 position[3];\n"
604 " vec4 color[3];\n"
605 "} ubuf;\n"
606 "\n"
607 "layout (location = 0) out vec4 outColor;\n"
608 "\n"
609 "void main() \n"
610 "{\n"
611 " outColor = ubuf.color[gl_VertexID];\n"
612 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
613 "}\n";
614
615 static const char *fragShaderText =
616 "#version 140\n"
617 "#extension GL_ARB_separate_shader_objects : enable\n"
618 "#extension GL_ARB_shading_language_420pack : enable\n"
619 "\n"
620 "layout (location = 0) in vec4 inColor;\n"
621 "layout (location = 0) out vec4 outColor;\n"
622 "\n"
623 "void main()\n"
624 "{\n"
625 " outColor = inColor;\n"
626 "}\n";
627
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600628 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 -0600629
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600630 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600631}
Cody Northrop71727d22015-06-23 13:25:51 -0600632
Tony Barbour01999182015-04-09 12:58:51 -0600633TEST_F(VkRenderTest, SPV_VKTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700634{
Tony Barbourf43b6982014-11-25 13:18:32 -0700635 static const char *vertShaderText =
636 "#version 140\n"
637 "#extension GL_ARB_separate_shader_objects : enable\n"
638 "#extension GL_ARB_shading_language_420pack : enable\n"
639 "\n"
640 "layout(binding = 0) uniform buf {\n"
641 " mat4 MVP;\n"
642 " vec4 position[3];\n"
643 " vec4 color[3];\n"
644 "} ubuf;\n"
645 "\n"
646 "layout (location = 0) out vec4 outColor;\n"
647 "\n"
648 "void main() \n"
649 "{\n"
650 " outColor = ubuf.color[gl_VertexID];\n"
651 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
652 "}\n";
653
654 static const char *fragShaderText =
655 "#version 140\n"
656 "#extension GL_ARB_separate_shader_objects : enable\n"
657 "#extension GL_ARB_shading_language_420pack : enable\n"
658 "\n"
659 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600660 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700661 "\n"
662 "void main()\n"
663 "{\n"
GregFd6ebdb32015-06-03 18:40:50 -0600664 " outColor = inColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700665 "}\n";
666
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600667 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 -0700668
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600669 VKTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700670}
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600671
Tony Barbour01999182015-04-09 12:58:51 -0600672TEST_F(VkRenderTest, SPV_GreenTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700673{
Tony Barbourf43b6982014-11-25 13:18:32 -0700674 static const char *vertShaderText =
675 "#version 130\n"
676 "vec2 vertices[3];\n"
677 "void main() {\n"
678 " vertices[0] = vec2(-1.0, -1.0);\n"
679 " vertices[1] = vec2( 1.0, -1.0);\n"
680 " vertices[2] = vec2( 0.0, 1.0);\n"
681 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
682 "}\n";
683
684 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600685 "#version 140\n"
686 "#extension GL_ARB_separate_shader_objects : enable\n"
687 "#extension GL_ARB_shading_language_420pack : enable\n"
688 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700689 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600690 " outColor = vec4(0,1,0,1);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700691 "}\n";
692
Cody Northropacfb0492015-03-17 15:55:58 -0600693 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700694
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);
Mark Lobodzinski15427102015-02-18 16:38:17 -0600770
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600771#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600772 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600773 MESH_BIND_ID, // binding ID
Tony Barbourf43b6982014-11-25 13:18:32 -0700774 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600775 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -0700776 };
777
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600778 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600779 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
780 vi_attribs[0].location = 0; // location, position
Tony Barbour8205d902015-04-16 15:59:00 -0600781 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600782 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
783 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
784 vi_attribs[1].location = 1; // location, color
Tony Barbour8205d902015-04-16 15:59:00 -0600785 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600786 vi_attribs[1].offsetInBytes = 1*sizeof(float)*4; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -0700787
788 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
789 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barbourf43b6982014-11-25 13:18:32 -0700790
Tony Barboure4ed9942015-01-09 10:06:53 -0700791 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -0600792 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourf43b6982014-11-25 13:18:32 -0700793
Tony Barbour1490c912015-07-28 10:17:20 -0600794 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600795
Tony Barbour1490c912015-07-28 10:17:20 -0600796 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barboure4ed9942015-01-09 10:06:53 -0700797
798 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -0600799 Draw(0, 6, 0, 1);
Tony Barboure4ed9942015-01-09 10:06:53 -0700800
801 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600802 ASSERT_VK_SUCCESS(EndCommandBuffer());
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600803
Tony Barbour1490c912015-07-28 10:17:20 -0600804 QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -0700805
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600806 RecordImages(m_renderTargets);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600807}
808
Tony Barbour01999182015-04-09 12:58:51 -0600809TEST_F(VkRenderTest, TriangleMRT)
Chia-I Wue09d1a72014-12-05 10:32:23 +0800810{
811 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600812 "#version 140\n"
813 "#extension GL_ARB_separate_shader_objects : enable\n"
814 "#extension GL_ARB_shading_language_420pack : enable\n"
815 "layout (location = 0) in vec4 pos;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800816 "void main() {\n"
817 " gl_Position = pos;\n"
818 "}\n";
819
820 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600821 "#version 140\n"
822 "#extension GL_ARB_separate_shader_objects : enable\n"
823 "#extension GL_ARB_shading_language_420pack : enable\n"
824 "layout (location = 0) out vec4 uFragData0;\n"
825 "layout (location = 1) out vec4 uFragData1;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800826 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600827 " uFragData0 = vec4(1.0, 0.0, 0.0, 1.0);\n"
828 " uFragData1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800829 "}\n";
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600830 const float vb_data[][2] = {
Chia-I Wue09d1a72014-12-05 10:32:23 +0800831 { -1.0f, -1.0f },
832 { 1.0f, -1.0f },
833 { -1.0f, 1.0f }
834 };
835
836 ASSERT_NO_FATAL_FAILURE(InitState());
837 ASSERT_NO_FATAL_FAILURE(InitViewport());
838
Tony Barbour01999182015-04-09 12:58:51 -0600839 VkConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000840 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800841
Tony Barbour01999182015-04-09 12:58:51 -0600842 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
843 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800844
Tony Barbour01999182015-04-09 12:58:51 -0600845 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800846 pipelineobj.AddColorAttachment();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800847 pipelineobj.AddShader(&vs);
848 pipelineobj.AddShader(&ps);
849
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600850#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600851 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600852 MESH_BUF_ID, // Binding ID
853 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600854 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Chia-I Wue09d1a72014-12-05 10:32:23 +0800855 };
856
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600857 VkVertexInputAttributeDescription vi_attrib;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600858 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
859 vi_attrib.location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -0600860 vi_attrib.format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600861 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
Chia-I Wue09d1a72014-12-05 10:32:23 +0800862
863 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
864 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800865
Tony Barbour01999182015-04-09 12:58:51 -0600866 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800867
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700868 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
Chia-I Wue09d1a72014-12-05 10:32:23 +0800869
Tony Barboure307f582015-07-10 15:29:03 -0600870 VkPipelineColorBlendAttachmentState att = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600871 att.blendEnable = VK_FALSE;
Chia-I Wue09d1a72014-12-05 10:32:23 +0800872 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700873 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800874
Tony Barbour1490c912015-07-28 10:17:20 -0600875 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure4ed9942015-01-09 10:06:53 -0700876
Tony Barbour1490c912015-07-28 10:17:20 -0600877 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700878
Tony Barbour1490c912015-07-28 10:17:20 -0600879 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700880#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600881 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour5ed79702015-01-07 14:31:52 -0700882 pDSDumpDot((char*)"triTest2.dot");
883#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600884
Tony Barbour5ed79702015-01-07 14:31:52 -0700885 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -0600886 Draw(0, 3, 0, 1);
Tony Barbour5ed79702015-01-07 14:31:52 -0700887
888 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600889 ASSERT_VK_SUCCESS(EndCommandBuffer());
890 QueueCommandBuffer();
Tony Barbour5ed79702015-01-07 14:31:52 -0700891
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600892 RecordImages(m_renderTargets);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800893}
894
Tony Barbour01999182015-04-09 12:58:51 -0600895TEST_F(VkRenderTest, QuadWithIndexedVertexFetch)
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700896{
897 static const char *vertShaderText =
898 "#version 140\n"
899 "#extension GL_ARB_separate_shader_objects : enable\n"
900 "#extension GL_ARB_shading_language_420pack : enable\n"
901 "layout(location = 0) in vec4 pos;\n"
902 "layout(location = 1) in vec4 inColor;\n"
903 "layout(location = 0) out vec4 outColor;\n"
904 "void main() {\n"
905 " outColor = inColor;\n"
906 " gl_Position = pos;\n"
907 "}\n";
908
909
910 static const char *fragShaderText =
911 "#version 140\n"
912 "#extension GL_ARB_separate_shader_objects : enable\n"
913 "#extension GL_ARB_shading_language_420pack : enable\n"
914 "layout(location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600915 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700916 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600917 " outColor = color;\n"
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700918 "}\n";
919
920 const Vertex g_vbData[] =
921 {
922 // first tri
923 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
924 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
925 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
926
927 // second tri
928 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
929 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
930 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
931 };
932
933 const uint16_t g_idxData[6] = {
934 0, 1, 2,
935 3, 4, 5,
936 };
937
938 ASSERT_NO_FATAL_FAILURE(InitState());
939 ASSERT_NO_FATAL_FAILURE(InitViewport());
940
Tony Barbour01999182015-04-09 12:58:51 -0600941 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000942 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700943
Tony Barbour01999182015-04-09 12:58:51 -0600944 VkIndexBufferObj indexBuffer(m_device);
Tony Barbour8205d902015-04-16 15:59:00 -0600945 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), VK_INDEX_TYPE_UINT16, g_idxData);
Mark Lobodzinskid30f82a2015-02-16 14:24:23 -0600946 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700947
Tony Barbour01999182015-04-09 12:58:51 -0600948 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
949 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700950
Tony Barbour01999182015-04-09 12:58:51 -0600951 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800952 pipelineobj.AddColorAttachment();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700953 pipelineobj.AddShader(&vs);
954 pipelineobj.AddShader(&ps);
955
Tony Barbour01999182015-04-09 12:58:51 -0600956 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -0600957
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700958
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600959#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600960 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600961 MESH_BIND_ID, // binding ID
962 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600963 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700964 };
965
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600966 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600967 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
968 vi_attribs[0].location = 0; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600969 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600970 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
971 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
972 vi_attribs[1].location = 1; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600973 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600974 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700975
976 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
977 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700978
979 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -0600980 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barboure4ed9942015-01-09 10:06:53 -0700981
Tony Barbour1490c912015-07-28 10:17:20 -0600982 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700983
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700984#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600985 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700986 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700987#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700988
Tony Barbour1490c912015-07-28 10:17:20 -0600989 BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
990 BindIndexBuffer(&indexBuffer, 0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700991
992 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -0600993 DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700994
995 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -0600996 ASSERT_VK_SUCCESS(EndCommandBuffer());
997 QueueCommandBuffer();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700998
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600999 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001000}
1001
Tony Barbour01999182015-04-09 12:58:51 -06001002TEST_F(VkRenderTest, GreyandRedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -07001003{
1004 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -07001005
GregF6bef1212014-12-02 15:41:44 -07001006 static const char *vertShaderText =
1007 "#version 140\n"
1008 "#extension GL_ARB_separate_shader_objects : enable\n"
1009 "#extension GL_ARB_shading_language_420pack : enable\n"
1010 "layout (location = 0) in vec4 pos;\n"
1011 "layout (location = 0) out vec4 outColor;\n"
1012 "layout (location = 1) out vec4 outColor2;\n"
1013 "void main() {\n"
1014 " gl_Position = pos;\n"
1015 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1016 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1017 "}\n";
1018
1019 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001020 "#version 330\n"
1021 "#extension GL_ARB_separate_shader_objects : enable\n"
1022 "#extension GL_ARB_shading_language_420pack : enable\n"
1023 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1024 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1025 "layout (location = 0) in vec4 color;\n"
1026 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001027 "layout (location = 0) out vec4 outColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001028 "void main() {\n"
1029 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1030 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001031 " outColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001032 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1033 " : color2;\n"
1034 "}\n";
1035
1036 ASSERT_NO_FATAL_FAILURE(InitState());
1037 ASSERT_NO_FATAL_FAILURE(InitViewport());
1038
Tony Barbour01999182015-04-09 12:58:51 -06001039 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001040 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001041
Tony Barbour01999182015-04-09 12:58:51 -06001042 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1043 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001044
Tony Barbour01999182015-04-09 12:58:51 -06001045 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001046 pipelineobj.AddColorAttachment();
GregF6bef1212014-12-02 15:41:44 -07001047 pipelineobj.AddShader(&vs);
1048 pipelineobj.AddShader(&ps);
1049
Tony Barbour01999182015-04-09 12:58:51 -06001050 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001051
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001052#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001053 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001054 MESH_BIND_ID, // binding ID
1055 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001056 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001057 };
1058
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001059 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001060 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1061 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001062 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001063 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001064
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001065 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001066 pipelineobj.AddVertexInputBindings(&vi_binding,1);
GregF6bef1212014-12-02 15:41:44 -07001067
Tony Barbourdd4c9642015-01-09 12:55:14 -07001068 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001069
Tony Barbour1490c912015-07-28 10:17:20 -06001070 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001071
Tony Barbour1490c912015-07-28 10:17:20 -06001072 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001073
Tony Barbour1490c912015-07-28 10:17:20 -06001074 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001075#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001076 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001077 pDSDumpDot((char*)"triTest2.dot");
1078#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001079
Tony Barbourdd4c9642015-01-09 12:55:14 -07001080 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06001081 Draw(0, 6, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001082
1083 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001084 EndCommandBuffer();
1085 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001086
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001087 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001088}
1089
Tony Barbour01999182015-04-09 12:58:51 -06001090TEST_F(VkRenderTest, RedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -07001091{
1092 // This tests that we correctly handle unread fragment inputs
1093
1094 static const char *vertShaderText =
1095 "#version 140\n"
1096 "#extension GL_ARB_separate_shader_objects : enable\n"
1097 "#extension GL_ARB_shading_language_420pack : enable\n"
1098 "layout (location = 0) in vec4 pos;\n"
1099 "layout (location = 0) out vec4 outColor;\n"
1100 "layout (location = 1) out vec4 outColor2;\n"
1101 "void main() {\n"
1102 " gl_Position = pos;\n"
1103 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1104 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1105 "}\n";
1106
1107 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001108 "#version 330\n"
1109 "#extension GL_ARB_separate_shader_objects : enable\n"
1110 "#extension GL_ARB_shading_language_420pack : enable\n"
1111 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1112 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1113 "layout (location = 0) in vec4 color;\n"
1114 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001115 "layout (location = 0) out vec4 outColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001116 "void main() {\n"
1117 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1118 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001119 " outColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001120 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1121 " : color2;\n"
1122 "}\n";
1123
1124 ASSERT_NO_FATAL_FAILURE(InitState());
1125 ASSERT_NO_FATAL_FAILURE(InitViewport());
1126
Tony Barbour01999182015-04-09 12:58:51 -06001127 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001128 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001129
Tony Barbour01999182015-04-09 12:58:51 -06001130 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1131 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001132
Tony Barbour01999182015-04-09 12:58:51 -06001133 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001134 pipelineobj.AddColorAttachment();
GregF6bef1212014-12-02 15:41:44 -07001135 pipelineobj.AddShader(&vs);
1136 pipelineobj.AddShader(&ps);
1137
Tony Barbour01999182015-04-09 12:58:51 -06001138 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001139
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001140#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001141 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001142 MESH_BIND_ID, // binding ID
1143 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001144 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001145 };
1146
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001147 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001148 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1149 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001150 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001151 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001152
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001153 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001154 pipelineobj.AddVertexInputBindings(&vi_binding,1);
GregF6bef1212014-12-02 15:41:44 -07001155
Tony Barbourdd4c9642015-01-09 12:55:14 -07001156 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06001157 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001158
Tony Barbour1490c912015-07-28 10:17:20 -06001159 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001160
Tony Barbour1490c912015-07-28 10:17:20 -06001161 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001162#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001163 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001164 pDSDumpDot((char*)"triTest2.dot");
1165#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001166 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001167 Draw(0, 6, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001168
1169 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001170 EndCommandBuffer();
1171 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001172
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001173 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001174}
1175
Tony Barbour01999182015-04-09 12:58:51 -06001176TEST_F(VkRenderTest, GreyCirclesonBlueFade)
GregF6bef1212014-12-02 15:41:44 -07001177{
1178 // This tests reading gl_ClipDistance from FS
1179
1180 static const char *vertShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001181 //"#version 140\n"
GregF6bef1212014-12-02 15:41:44 -07001182 "#version 330\n"
1183 "#extension GL_ARB_separate_shader_objects : enable\n"
1184 "#extension GL_ARB_shading_language_420pack : enable\n"
1185 "out gl_PerVertex {\n"
1186 " vec4 gl_Position;\n"
1187 " float gl_ClipDistance[1];\n"
1188 "};\n"
1189 "layout (location = 0) in vec4 pos;\n"
1190 "layout (location = 0) out vec4 outColor;\n"
1191 "layout (location = 1) out vec4 outColor2;\n"
1192 "void main() {\n"
1193 " gl_Position = pos;\n"
1194 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1195 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1196 " float dists[3];\n"
1197 " dists[0] = 0.0;\n"
1198 " dists[1] = 1.0;\n"
1199 " dists[2] = 1.0;\n"
1200 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1201 "}\n";
1202
1203
1204 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001205 "#version 140\n"
1206 //"#version 330\n"
GregF6bef1212014-12-02 15:41:44 -07001207 "#extension GL_ARB_separate_shader_objects : enable\n"
1208 "#extension GL_ARB_shading_language_420pack : enable\n"
1209 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1210 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1211 "layout (location = 0) in vec4 color;\n"
1212 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001213 "layout (location = 0) out vec4 uFragColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001214 "void main() {\n"
1215 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1216 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001217 " uFragColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001218 " ? color * gl_ClipDistance[0]\n"
1219 " : color2;\n"
1220 "}\n";
1221
1222 ASSERT_NO_FATAL_FAILURE(InitState());
1223 ASSERT_NO_FATAL_FAILURE(InitViewport());
1224
Tony Barbour01999182015-04-09 12:58:51 -06001225 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001226 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001227
Tony Barbour01999182015-04-09 12:58:51 -06001228 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1229 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001230
Tony Barbour01999182015-04-09 12:58:51 -06001231 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001232 pipelineobj.AddColorAttachment();
GregF6bef1212014-12-02 15:41:44 -07001233 pipelineobj.AddShader(&vs);
1234 pipelineobj.AddShader(&ps);
1235
Tony Barbour01999182015-04-09 12:58:51 -06001236 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001237
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001238#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001239 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001240 MESH_BIND_ID, // binding ID
1241 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001242 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001243 };
1244
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001245 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001246 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1247 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001248 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001249 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001250
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001251 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001252 pipelineobj.AddVertexInputBindings(&vi_binding,1);
GregF6bef1212014-12-02 15:41:44 -07001253
Tony Barbourdd4c9642015-01-09 12:55:14 -07001254 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
GregF6bef1212014-12-02 15:41:44 -07001255
Tony Barbour1490c912015-07-28 10:17:20 -06001256 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001257
Tony Barbour1490c912015-07-28 10:17:20 -06001258 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001259
Tony Barbour1490c912015-07-28 10:17:20 -06001260 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001261#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001262 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001263 pDSDumpDot((char*)"triTest2.dot");
1264#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001265
1266 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001267 Draw(0, 6, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001268
1269 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001270 EndCommandBuffer();
1271 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001272
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001273 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001274}
Tony Barbourf43b6982014-11-25 13:18:32 -07001275
Tony Barbour01999182015-04-09 12:58:51 -06001276TEST_F(VkRenderTest, GreyCirclesonBlueDiscard)
GregF7a23c792014-12-02 17:19:34 -07001277{
1278 static const char *vertShaderText =
1279 "#version 140\n"
1280 "#extension GL_ARB_separate_shader_objects : enable\n"
1281 "#extension GL_ARB_shading_language_420pack : enable\n"
1282 "layout (location = 0) in vec4 pos;\n"
1283 "layout (location = 0) out vec4 outColor;\n"
1284 "layout (location = 1) out vec4 outColor2;\n"
1285 "void main() {\n"
1286 " gl_Position = pos;\n"
1287 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1288 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1289 "}\n";
1290
1291
1292 static const char *fragShaderText =
GregF7a23c792014-12-02 17:19:34 -07001293 "#version 330\n"
1294 "#extension GL_ARB_separate_shader_objects : enable\n"
1295 "#extension GL_ARB_shading_language_420pack : enable\n"
1296 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1297 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1298 "layout (location = 0) in vec4 color;\n"
1299 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001300 "layout (location = 0) out vec4 outColor;\n"
GregF7a23c792014-12-02 17:19:34 -07001301 "void main() {\n"
1302 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1303 " float dist_squared = dot(pos, pos);\n"
1304 " if (dist_squared < 100.0)\n"
1305 " discard;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001306 " outColor = (dist_squared < 400.0)\n"
GregF7a23c792014-12-02 17:19:34 -07001307 " ? color\n"
1308 " : color2;\n"
1309 "}\n";
1310
1311 ASSERT_NO_FATAL_FAILURE(InitState());
1312 ASSERT_NO_FATAL_FAILURE(InitViewport());
1313
Tony Barbour01999182015-04-09 12:58:51 -06001314 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001315 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001316
Tony Barbour01999182015-04-09 12:58:51 -06001317 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1318 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF7a23c792014-12-02 17:19:34 -07001319
Tony Barbour01999182015-04-09 12:58:51 -06001320 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001321 pipelineobj.AddColorAttachment();
GregF7a23c792014-12-02 17:19:34 -07001322 pipelineobj.AddShader(&vs);
1323 pipelineobj.AddShader(&ps);
1324
Tony Barbour01999182015-04-09 12:58:51 -06001325 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001326
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001327#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001328 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001329 MESH_BIND_ID, // binding ID
1330 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001331 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF7a23c792014-12-02 17:19:34 -07001332 };
1333
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001334 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001335 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1336 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001337 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001338 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF7a23c792014-12-02 17:19:34 -07001339
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001340 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF7a23c792014-12-02 17:19:34 -07001341 pipelineobj.AddVertexInputBindings(&vi_binding,1);
GregF7a23c792014-12-02 17:19:34 -07001342
Tony Barbourdd4c9642015-01-09 12:55:14 -07001343 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001344
Tony Barbour1490c912015-07-28 10:17:20 -06001345 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001346
Tony Barbour1490c912015-07-28 10:17:20 -06001347 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001348
Tony Barbour1490c912015-07-28 10:17:20 -06001349 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001350#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001351 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001352 pDSDumpDot((char*)"triTest2.dot");
1353#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001354
1355 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001356 Draw(0, 6, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001357
1358 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001359 EndCommandBuffer();
1360 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001361
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001362 RecordImages(m_renderTargets);
GregF7a23c792014-12-02 17:19:34 -07001363}
1364
1365
Tony Barbour01999182015-04-09 12:58:51 -06001366TEST_F(VkRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001367{
1368 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001369 "#version 140\n"
1370 "#extension GL_ARB_separate_shader_objects : enable\n"
1371 "#extension GL_ARB_shading_language_420pack : enable\n"
1372 "\n"
1373 "layout(binding = 0) uniform buf {\n"
1374 " mat4 MVP;\n"
1375 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001376 "void main() {\n"
1377 " vec2 vertices[3];"
1378 " vertices[0] = vec2(-0.5, -0.5);\n"
1379 " vertices[1] = vec2( 0.5, -0.5);\n"
1380 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001381 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001382 "}\n";
1383
1384 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001385 "#version 140\n"
1386 "#extension GL_ARB_separate_shader_objects : enable\n"
1387 "#extension GL_ARB_shading_language_420pack : enable\n"
1388 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001389 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001390 " outColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001391 "}\n";
1392
Tony Barbourf43b6982014-11-25 13:18:32 -07001393 ASSERT_NO_FATAL_FAILURE(InitState());
1394 ASSERT_NO_FATAL_FAILURE(InitViewport());
1395
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001396 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001397 glm::mat4 Projection = glm::mat4(1.0f);
1398 glm::mat4 View = glm::mat4(1.0f);
1399 glm::mat4 Model = glm::mat4(1.0f);
1400 glm::mat4 MVP = Projection * View * Model;
1401 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1402
Tony Barbour01999182015-04-09 12:58:51 -06001403 VkConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1404 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1405 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001406
Tony Barbour01999182015-04-09 12:58:51 -06001407 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001408 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001409 pipelineobj.AddShader(&vs);
1410 pipelineobj.AddShader(&ps);
1411
1412 // Create descriptor set and attach the constant buffer to it
Tony Barbour01999182015-04-09 12:58:51 -06001413 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001414 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001415
Tony Barbourdd4c9642015-01-09 12:55:14 -07001416 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis7f7b4422015-08-18 14:24:32 -06001417
1418 VkCmdBufferBeginInfo cbBeginInfo;
1419 memset(&cbBeginInfo, 0, sizeof(VkCmdBufferBeginInfo));
1420 cbBeginInfo.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
1421 cbBeginInfo.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT;
1422 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barbourf43b6982014-11-25 13:18:32 -07001423
Tony Barbour1490c912015-07-28 10:17:20 -06001424 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001425
Tony Barbourdd4c9642015-01-09 12:55:14 -07001426#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001427 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001428 pDSDumpDot((char*)"triTest2.dot");
1429#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001430
1431 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001432 Draw(0, 6, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001433
1434 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001435 EndCommandBuffer();
1436 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001437
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001438 RecordImages(m_renderTargets);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001439
Tony Barbour1490c912015-07-28 10:17:20 -06001440 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001441}
1442
Tony Barbour01999182015-04-09 12:58:51 -06001443TEST_F(VkRenderTest, MixTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07001444{
1445 // This tests location applied to varyings. Notice that we have switched foo
1446 // and bar in the FS. The triangle should be blended with red, green and blue
1447 // corners.
1448 static const char *vertShaderText =
1449 "#version 140\n"
1450 "#extension GL_ARB_separate_shader_objects : enable\n"
1451 "#extension GL_ARB_shading_language_420pack : enable\n"
1452 "layout (location=0) out vec4 bar;\n"
1453 "layout (location=1) out vec4 foo;\n"
1454 "layout (location=2) out float scale;\n"
1455 "vec2 vertices[3];\n"
1456 "void main() {\n"
1457 " vertices[0] = vec2(-1.0, -1.0);\n"
1458 " vertices[1] = vec2( 1.0, -1.0);\n"
1459 " vertices[2] = vec2( 0.0, 1.0);\n"
1460 "vec4 colors[3];\n"
1461 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1462 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1463 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1464 " foo = colors[gl_VertexID % 3];\n"
1465 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1466 " scale = 1.0;\n"
1467 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1468 "}\n";
1469
1470 static const char *fragShaderText =
1471 "#version 140\n"
1472 "#extension GL_ARB_separate_shader_objects : enable\n"
1473 "#extension GL_ARB_shading_language_420pack : enable\n"
1474 "layout (location = 1) in vec4 bar;\n"
1475 "layout (location = 0) in vec4 foo;\n"
1476 "layout (location = 2) in float scale;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001477 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001478 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001479 " outColor = bar * scale + foo * (1.0-scale);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001480 "}\n";
1481
1482 ASSERT_NO_FATAL_FAILURE(InitState());
1483 ASSERT_NO_FATAL_FAILURE(InitViewport());
1484
Tony Barbour01999182015-04-09 12:58:51 -06001485 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1486 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001487
Tony Barbour01999182015-04-09 12:58:51 -06001488 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001489 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001490 pipelineobj.AddShader(&vs);
1491 pipelineobj.AddShader(&ps);
1492
Tony Barbour01999182015-04-09 12:58:51 -06001493 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06001494 descriptorSet.AppendDummy();
Tony Barbourf43b6982014-11-25 13:18:32 -07001495
Tony Barbourdd4c9642015-01-09 12:55:14 -07001496 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001497
Tony Barbour1490c912015-07-28 10:17:20 -06001498 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001499
Tony Barbour1490c912015-07-28 10:17:20 -06001500 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001501
1502#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001503 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001504 pDSDumpDot((char*)"triTest2.dot");
1505#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001506
Tony Barbourdd4c9642015-01-09 12:55:14 -07001507 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06001508 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001509
1510 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001511 EndCommandBuffer();
1512 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001513
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001514 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001515}
1516
Tony Barbour01999182015-04-09 12:58:51 -06001517TEST_F(VkRenderTest, QuadVertFetchAndVertID)
Tony Barbourf43b6982014-11-25 13:18:32 -07001518{
1519 // This tests that attributes work in the presence of gl_VertexID
1520
1521 static const char *vertShaderText =
1522 "#version 140\n"
1523 "#extension GL_ARB_separate_shader_objects : enable\n"
1524 "#extension GL_ARB_shading_language_420pack : enable\n"
1525 //XYZ1( -1, -1, -1 )
1526 "layout (location = 0) in vec4 pos;\n"
1527 //XYZ1( 0.f, 0.f, 0.f )
1528 "layout (location = 1) in vec4 inColor;\n"
1529 "layout (location = 0) out vec4 outColor;\n"
1530 "void main() {\n"
1531 " outColor = inColor;\n"
1532 " vec4 vertices[3];"
1533 " vertices[gl_VertexID % 3] = pos;\n"
1534 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1535 "}\n";
1536
1537
1538 static const char *fragShaderText =
1539 "#version 140\n"
1540 "#extension GL_ARB_separate_shader_objects : enable\n"
1541 "#extension GL_ARB_shading_language_420pack : enable\n"
1542 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001543 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001544 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001545 " outColor = color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001546 "}\n";
1547
1548 ASSERT_NO_FATAL_FAILURE(InitState());
1549 ASSERT_NO_FATAL_FAILURE(InitViewport());
1550
Tony Barbour01999182015-04-09 12:58:51 -06001551 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001552 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001553
Tony Barbour01999182015-04-09 12:58:51 -06001554 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1555 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001556
Tony Barbour01999182015-04-09 12:58:51 -06001557 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001558 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001559 pipelineobj.AddShader(&vs);
1560 pipelineobj.AddShader(&ps);
1561
Tony Barbour01999182015-04-09 12:58:51 -06001562 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001563
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001564#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001565 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001566 MESH_BUF_ID, // Binding ID
1567 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001568 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001569 };
1570
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001571 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001572 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1573 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001574 vi_attribs[0].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001575 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1576 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1577 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001578 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001579 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001580
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001581 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001582 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barbourf43b6982014-11-25 13:18:32 -07001583
Tony Barbourdd4c9642015-01-09 12:55:14 -07001584 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001585
Tony Barbour1490c912015-07-28 10:17:20 -06001586 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001587
Tony Barbour1490c912015-07-28 10:17:20 -06001588 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001589
Tony Barbour1490c912015-07-28 10:17:20 -06001590 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001591#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001592 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001593 pDSDumpDot((char*)"triTest2.dot");
1594#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001595
1596 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001597 Draw(0, 6, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001598
1599 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001600 EndCommandBuffer();
1601 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001602
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001603 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001604}
1605
Tony Barbour01999182015-04-09 12:58:51 -06001606TEST_F(VkRenderTest, QuadSparseVertFetch)
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001607{
1608 // This tests that attributes work in the presence of gl_VertexID
1609
1610 static const char *vertShaderText =
1611 "#version 140\n"
1612 "#extension GL_ARB_separate_shader_objects : enable\n"
1613 "#extension GL_ARB_shading_language_420pack : enable\n"
1614 //XYZ1( -1, -1, -1 )
1615 "layout (location = 1) in vec4 pos;\n"
1616 "layout (location = 4) in vec4 inColor;\n"
1617 //XYZ1( 0.f, 0.f, 0.f )
1618 "layout (location = 0) out vec4 outColor;\n"
1619 "void main() {\n"
1620 " outColor = inColor;\n"
1621 " gl_Position = pos;\n"
1622 "}\n";
1623
1624
1625 static const char *fragShaderText =
1626 "#version 140\n"
1627 "#extension GL_ARB_separate_shader_objects : enable\n"
1628 "#extension GL_ARB_shading_language_420pack : enable\n"
1629 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001630 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001631 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001632 " outColor = color;\n"
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001633 "}\n";
1634
1635 ASSERT_NO_FATAL_FAILURE(InitState());
1636 ASSERT_NO_FATAL_FAILURE(InitViewport());
1637
1638 struct VDATA
1639 {
1640 float t1, t2, t3, t4; // filler data
1641 float posX, posY, posZ, posW; // Position data
1642 float r, g, b, a; // Color
1643 };
1644 const struct VDATA vData[] =
1645 {
1646 { XYZ1(0, 0, 0), XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
1647 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1648 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1649 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1650 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1651 { XYZ1(0, 0, 0), XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
1652 };
1653
Tony Barbour01999182015-04-09 12:58:51 -06001654 VkConstantBufferObj meshBuffer(m_device,sizeof(vData)/sizeof(vData[0]),sizeof(vData[0]), vData);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001655 meshBuffer.BufferMemoryBarrier();
1656
Tony Barbour01999182015-04-09 12:58:51 -06001657 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1658 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001659
Tony Barbour01999182015-04-09 12:58:51 -06001660 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001661 pipelineobj.AddColorAttachment();
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001662 pipelineobj.AddShader(&vs);
1663 pipelineobj.AddShader(&ps);
1664
Tony Barbour01999182015-04-09 12:58:51 -06001665 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001666
1667#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001668 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001669 MESH_BUF_ID, // Binding ID
1670 sizeof(vData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001671 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001672 };
1673
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001674 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001675 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1676 vi_attribs[0].location = 4;
Tony Barbour8205d902015-04-16 15:59:00 -06001677 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001678 vi_attribs[0].offsetInBytes = sizeof(float) * 4 * 2; // Offset of first element in bytes from base of vertex
1679 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1680 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001681 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001682 vi_attribs[1].offsetInBytes = sizeof(float) * 4 * 1; // Offset of first element in bytes from base of vertex
1683
1684 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
1685 pipelineobj.AddVertexInputBindings(&vi_binding, 1);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001686
1687 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001688
Tony Barbour1490c912015-07-28 10:17:20 -06001689 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001690
Tony Barbour1490c912015-07-28 10:17:20 -06001691 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001692
Tony Barbour1490c912015-07-28 10:17:20 -06001693 BindVertexBuffer(&meshBuffer, 0, MESH_BUF_ID);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001694#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001695 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001696 pDSDumpDot((char*)"triTest2.dot");
1697#endif
1698
1699 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001700 Draw(0, 6, 0, 1);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001701
1702 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001703 EndCommandBuffer();
1704 QueueCommandBuffer();
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001705
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001706 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001707}
1708
Tony Barbour01999182015-04-09 12:58:51 -06001709TEST_F(VkRenderTest, TriVertFetchDeadAttr)
Tony Barbourf43b6982014-11-25 13:18:32 -07001710{
1711 // This tests that attributes work in the presence of gl_VertexID
1712 // and a dead attribute in position 0. Draws a triangle with yellow,
1713 // red and green corners, starting at top and going clockwise.
1714
1715 static const char *vertShaderText =
1716 "#version 140\n"
1717 "#extension GL_ARB_separate_shader_objects : enable\n"
1718 "#extension GL_ARB_shading_language_420pack : enable\n"
1719 //XYZ1( -1, -1, -1 )
1720 "layout (location = 0) in vec4 pos;\n"
1721 //XYZ1( 0.f, 0.f, 0.f )
1722 "layout (location = 1) in vec4 inColor;\n"
1723 "layout (location = 0) out vec4 outColor;\n"
1724 "void main() {\n"
1725 " outColor = inColor;\n"
1726 " vec2 vertices[3];"
1727 " vertices[0] = vec2(-1.0, -1.0);\n"
1728 " vertices[1] = vec2( 1.0, -1.0);\n"
1729 " vertices[2] = vec2( 0.0, 1.0);\n"
1730 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1731 "}\n";
1732
1733
1734 static const char *fragShaderText =
1735 "#version 140\n"
1736 "#extension GL_ARB_separate_shader_objects : enable\n"
1737 "#extension GL_ARB_shading_language_420pack : enable\n"
1738 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001739 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001740 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001741 " outColor = color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001742 "}\n";
1743
1744 ASSERT_NO_FATAL_FAILURE(InitState());
1745 ASSERT_NO_FATAL_FAILURE(InitViewport());
1746
Tony Barbour01999182015-04-09 12:58:51 -06001747 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001748 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001749
Tony Barbour01999182015-04-09 12:58:51 -06001750 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1751 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001752
Tony Barbour01999182015-04-09 12:58:51 -06001753 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001754 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001755 pipelineobj.AddShader(&vs);
1756 pipelineobj.AddShader(&ps);
1757
Tony Barbour01999182015-04-09 12:58:51 -06001758 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001759
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001760#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001761 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001762 MESH_BUF_ID, // Binding ID
1763 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001764 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001765 };
1766
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001767 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001768 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1769 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001770 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001771 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1772 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1773 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001774 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001775 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001776
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001777 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001778 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barbourf43b6982014-11-25 13:18:32 -07001779
Tony Barbourdd4c9642015-01-09 12:55:14 -07001780 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourf43b6982014-11-25 13:18:32 -07001781
Tony Barbour1490c912015-07-28 10:17:20 -06001782 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001783
Tony Barbour1490c912015-07-28 10:17:20 -06001784 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001785
Tony Barbour1490c912015-07-28 10:17:20 -06001786 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001787#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001788 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001789 pDSDumpDot((char*)"triTest2.dot");
1790#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001791
1792 // render two triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001793 Draw(0, 6, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001794
1795 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001796 EndCommandBuffer();
1797 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001798
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001799 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001800}
1801
Tony Barbour01999182015-04-09 12:58:51 -06001802TEST_F(VkRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001803{
1804 static const char *vertShaderText =
1805 "#version 140\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001806 "#extension GL_ARB_separate_shader_objects : enable\n"
1807 "#extension GL_ARB_shading_language_420pack : enable\n"
GregFd6ebdb32015-06-03 18:40:50 -06001808 "layout (std140, binding = 0) uniform bufferVals {\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001809 " mat4 mvp;\n"
1810 "} myBufferVals;\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001811 "layout (location = 0) in vec4 pos;\n"
1812 "layout (location = 1) in vec4 inColor;\n"
Cody Northrop74a2d2c2015-06-16 17:32:04 -06001813 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001814 "void main() {\n"
1815 " outColor = inColor;\n"
1816 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001817 " gl_Position.y = -gl_Position.y;\n"
1818 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001819 "}\n";
1820
1821 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001822 "#version 140\n"
1823 "#extension GL_ARB_separate_shader_objects : enable\n"
1824 "#extension GL_ARB_shading_language_420pack : enable\n"
1825 "layout (location = 0) in vec4 color;\n"
1826 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001827 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001828 " outColor = color;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001829 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001830 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001831
Tony Barbourf43b6982014-11-25 13:18:32 -07001832 glm::mat4 View = glm::lookAt(
1833 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1834 glm::vec3(0,0,0), // and looks at the origin
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001835 glm::vec3(0,-1,0) // Head is up (set to 0,-1,0 to look upside-down)
Tony Barbourf43b6982014-11-25 13:18:32 -07001836 );
1837
1838 glm::mat4 Model = glm::mat4(1.0f);
1839
1840 glm::mat4 MVP = Projection * View * Model;
1841
1842 ASSERT_NO_FATAL_FAILURE(InitState());
1843 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wu9e81ebb2015-07-09 10:16:34 +08001844 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Chia-I Wuc278df82015-07-07 11:50:03 +08001845 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height, m_depth_stencil_fmt);
Tony Barbourf43b6982014-11-25 13:18:32 -07001846
Tony Barbour01999182015-04-09 12:58:51 -06001847 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 -07001848 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1849
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001850 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07001851
Tony Barbour01999182015-04-09 12:58:51 -06001852 VkConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1853 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1854 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001855
Tony Barbour01999182015-04-09 12:58:51 -06001856 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001857 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001858 pipelineobj.AddShader(&vs);
1859 pipelineobj.AddShader(&ps);
1860
Tony Barboure307f582015-07-10 15:29:03 -06001861 VkPipelineDepthStencilStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001862 ds_state.depthTestEnable = VK_TRUE;
1863 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06001864 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Cody Northrope4bc6942015-08-26 10:01:32 -06001865 ds_state.depthBoundsTestEnable = VK_FALSE;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001866 ds_state.stencilTestEnable = VK_FALSE;
1867 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
1868 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
1869 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06001870 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001871 ds_state.front = ds_state.back;
1872 pipelineobj.SetDepthStencil(&ds_state);
1873
Tony Barbour01999182015-04-09 12:58:51 -06001874 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001875 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001876
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001877#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001878 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001879 MESH_BUF_ID, // Binding ID
1880 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001881 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001882 };
Tony Barbourf43b6982014-11-25 13:18:32 -07001883
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001884 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001885 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1886 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001887 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001888 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1889 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1890 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001891 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001892 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001893
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001894 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001895 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barbourf43b6982014-11-25 13:18:32 -07001896
Tony Barbour17c6ab12015-03-27 17:03:18 -06001897 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour17c6ab12015-03-27 17:03:18 -06001898
Tony Barbour1490c912015-07-28 10:17:20 -06001899 ASSERT_VK_SUCCESS(BeginCommandBuffer());
1900 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001901
Tony Barbour1490c912015-07-28 10:17:20 -06001902 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barboure4ed9942015-01-09 10:06:53 -07001903#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001904 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barboure4ed9942015-01-09 10:06:53 -07001905 pDSDumpDot((char*)"triTest2.dot");
1906#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001907
1908 // render triangles
Tony Barbour1490c912015-07-28 10:17:20 -06001909 Draw(0, 36, 0, 1);
Tony Barboure4ed9942015-01-09 10:06:53 -07001910
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001911
Tony Barboure4ed9942015-01-09 10:06:53 -07001912 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001913 EndCommandBuffer();
1914 QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -07001915
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001916 RecordImages(m_renderTargets);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001917}
1918
Tony Barbour01999182015-04-09 12:58:51 -06001919TEST_F(VkRenderTest, VSTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07001920{
1921 // The expected result from this test is a green and red triangle;
1922 // one red vertex on the left, two green vertices on the right.
1923 static const char *vertShaderText =
Cody Northrop74a2d2c2015-06-16 17:32:04 -06001924 "#version 140\n"
1925 "#extension GL_ARB_separate_shader_objects : enable\n"
1926 "#extension GL_ARB_shading_language_420pack : enable\n"
1927 "layout (location = 0) out vec4 texColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001928 "uniform sampler2D surface;\n"
1929 "void main() {\n"
1930 " vec2 vertices[3];"
1931 " vertices[0] = vec2(-0.5, -0.5);\n"
1932 " vertices[1] = vec2( 0.5, -0.5);\n"
1933 " vertices[2] = vec2( 0.5, 0.5);\n"
1934 " vec2 positions[3];"
1935 " positions[0] = vec2( 0.0, 0.0);\n"
1936 " positions[1] = vec2( 0.25, 0.1);\n"
1937 " positions[2] = vec2( 0.1, 0.25);\n"
1938 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1939 " texColor = textureLod(surface, samplePos, 0.0);\n"
1940 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1941 "}\n";
1942
1943 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001944 "#version 140\n"
1945 "#extension GL_ARB_separate_shader_objects : enable\n"
1946 "#extension GL_ARB_shading_language_420pack : enable\n"
1947 "layout (location = 0) in vec4 texColor;\n"
1948 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001949 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001950 " outColor = texColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001951 "}\n";
1952
1953 ASSERT_NO_FATAL_FAILURE(InitState());
1954 ASSERT_NO_FATAL_FAILURE(InitViewport());
1955
Tony Barbour01999182015-04-09 12:58:51 -06001956 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1957 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
1958 VkSamplerObj sampler(m_device);
1959 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001960
Tony Barbour01999182015-04-09 12:58:51 -06001961 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001962 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001963 pipelineobj.AddShader(&vs);
1964 pipelineobj.AddShader(&ps);
1965
Tony Barbour01999182015-04-09 12:58:51 -06001966 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001967 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001968
Tony Barbourdd4c9642015-01-09 12:55:14 -07001969 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06001970 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourf43b6982014-11-25 13:18:32 -07001971
Tony Barbour1490c912015-07-28 10:17:20 -06001972 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001973
1974#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001975 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001976 pDSDumpDot((char*)"triTest2.dot");
1977#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001978
Tony Barbourdd4c9642015-01-09 12:55:14 -07001979 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06001980 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001981
1982 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06001983 EndCommandBuffer();
1984 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001985
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001986 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001987}
GregFd6ebdb32015-06-03 18:40:50 -06001988
1989
1990
Tony Barbour01999182015-04-09 12:58:51 -06001991TEST_F(VkRenderTest, TexturedTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07001992{
1993 // The expected result from this test is a red and green checkered triangle
1994 static const char *vertShaderText =
1995 "#version 140\n"
1996 "#extension GL_ARB_separate_shader_objects : enable\n"
1997 "#extension GL_ARB_shading_language_420pack : enable\n"
1998 "layout (location = 0) out vec2 samplePos;\n"
1999 "void main() {\n"
2000 " vec2 vertices[3];"
2001 " vertices[0] = vec2(-0.5, -0.5);\n"
2002 " vertices[1] = vec2( 0.5, -0.5);\n"
2003 " vertices[2] = vec2( 0.5, 0.5);\n"
2004 " vec2 positions[3];"
2005 " positions[0] = vec2( 0.0, 0.0);\n"
2006 " positions[1] = vec2( 1.0, 0.0);\n"
2007 " positions[2] = vec2( 1.0, 1.0);\n"
2008 " samplePos = positions[gl_VertexID % 3];\n"
2009 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2010 "}\n";
2011
2012 static const char *fragShaderText =
2013 "#version 140\n"
2014 "#extension GL_ARB_separate_shader_objects : enable\n"
2015 "#extension GL_ARB_shading_language_420pack : enable\n"
2016 "layout (location = 0) in vec2 samplePos;\n"
2017 "layout (binding = 0) uniform sampler2D surface;\n"
2018 "layout (location=0) out vec4 outColor;\n"
2019 "void main() {\n"
2020 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2021 " outColor = texColor;\n"
2022 "}\n";
2023
2024 ASSERT_NO_FATAL_FAILURE(InitState());
2025 ASSERT_NO_FATAL_FAILURE(InitViewport());
2026
Tony Barbour01999182015-04-09 12:58:51 -06002027 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2028 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2029 VkSamplerObj sampler(m_device);
2030 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002031
Tony Barbour01999182015-04-09 12:58:51 -06002032 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002033 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002034 pipelineobj.AddShader(&vs);
2035 pipelineobj.AddShader(&ps);
2036
Tony Barbour01999182015-04-09 12:58:51 -06002037 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002038 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002039
Tony Barbourdd4c9642015-01-09 12:55:14 -07002040 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002041 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002042
Tony Barbour1490c912015-07-28 10:17:20 -06002043 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002044
2045#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002046 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002047 pDSDumpDot((char*)"triTest2.dot");
2048#endif
2049 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002050 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002051
2052 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002053 EndCommandBuffer();
2054 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002055
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002056 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002057}
Tony Barbour01999182015-04-09 12:58:51 -06002058TEST_F(VkRenderTest, TexturedTriangleClip)
Tony Barbourf43b6982014-11-25 13:18:32 -07002059{
2060 // The expected result from this test is a red and green checkered triangle
2061 static const char *vertShaderText =
2062 "#version 330\n"
2063 "#extension GL_ARB_separate_shader_objects : enable\n"
2064 "#extension GL_ARB_shading_language_420pack : enable\n"
2065 "layout (location = 0) out vec2 samplePos;\n"
2066 "out gl_PerVertex {\n"
2067 " vec4 gl_Position;\n"
2068 " float gl_ClipDistance[1];\n"
2069 "};\n"
2070 "void main() {\n"
2071 " vec2 vertices[3];"
2072 " vertices[0] = vec2(-0.5, -0.5);\n"
2073 " vertices[1] = vec2( 0.5, -0.5);\n"
2074 " vertices[2] = vec2( 0.5, 0.5);\n"
2075 " vec2 positions[3];"
2076 " positions[0] = vec2( 0.0, 0.0);\n"
2077 " positions[1] = vec2( 1.0, 0.0);\n"
2078 " positions[2] = vec2( 1.0, 1.0);\n"
2079 " float dists[3];\n"
2080 " dists[0] = 1.0;\n"
2081 " dists[1] = 1.0;\n"
2082 " dists[2] = -1.0;\n"
2083 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2084 " samplePos = positions[gl_VertexID % 3];\n"
2085 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2086 "}\n";
2087
2088 static const char *fragShaderText =
2089 "#version 140\n"
2090 "#extension GL_ARB_separate_shader_objects : enable\n"
2091 "#extension GL_ARB_shading_language_420pack : enable\n"
2092 "layout (location = 0) in vec2 samplePos;\n"
2093 "layout (binding = 0) uniform sampler2D surface;\n"
2094 "layout (location=0) out vec4 outColor;\n"
2095 "void main() {\n"
2096 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2097 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2098 " outColor = texColor;\n"
2099 "}\n";
2100
2101
2102 ASSERT_NO_FATAL_FAILURE(InitState());
2103 ASSERT_NO_FATAL_FAILURE(InitViewport());
2104
Tony Barbour01999182015-04-09 12:58:51 -06002105 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2106 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2107 VkSamplerObj sampler(m_device);
2108 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002109
Tony Barbour01999182015-04-09 12:58:51 -06002110 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002111 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002112 pipelineobj.AddShader(&vs);
2113 pipelineobj.AddShader(&ps);
2114
Tony Barbour01999182015-04-09 12:58:51 -06002115 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002116 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002117
Tony Barbourdd4c9642015-01-09 12:55:14 -07002118 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002119 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002120
Tony Barbour1490c912015-07-28 10:17:20 -06002121 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002122
2123#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002124 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002125 pDSDumpDot((char*)"triTest2.dot");
2126#endif
2127 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002128 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002129
2130 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002131 EndCommandBuffer();
2132 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002133
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002134 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002135}
GregFd6ebdb32015-06-03 18:40:50 -06002136
Tony Barbour01999182015-04-09 12:58:51 -06002137TEST_F(VkRenderTest, FSTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002138{
2139 // The expected result from this test is a red and green checkered triangle
2140 static const char *vertShaderText =
2141 "#version 140\n"
2142 "#extension GL_ARB_separate_shader_objects : enable\n"
2143 "#extension GL_ARB_shading_language_420pack : enable\n"
2144 "layout (location = 0) out vec2 samplePos;\n"
2145 "void main() {\n"
2146 " vec2 vertices[3];"
2147 " vertices[0] = vec2(-0.5, -0.5);\n"
2148 " vertices[1] = vec2( 0.5, -0.5);\n"
2149 " vertices[2] = vec2( 0.5, 0.5);\n"
2150 " vec2 positions[3];"
2151 " positions[0] = vec2( 0.0, 0.0);\n"
2152 " positions[1] = vec2( 1.0, 0.0);\n"
2153 " positions[2] = vec2( 1.0, 1.0);\n"
2154 " samplePos = positions[gl_VertexID % 3];\n"
2155 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2156 "}\n";
2157
2158 static const char *fragShaderText =
2159 "#version 140\n"
2160 "#extension GL_ARB_separate_shader_objects : enable\n"
2161 "#extension GL_ARB_shading_language_420pack : enable\n"
2162 "layout (location = 0) in vec2 samplePos;\n"
2163 "layout (binding = 0) uniform sampler2D surface;\n"
2164 "layout (location=0) out vec4 outColor;\n"
2165 "void main() {\n"
2166 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2167 " outColor = texColor;\n"
2168 "}\n";
2169
2170 ASSERT_NO_FATAL_FAILURE(InitState());
2171 ASSERT_NO_FATAL_FAILURE(InitViewport());
2172
Tony Barbour01999182015-04-09 12:58:51 -06002173 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2174 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2175 VkSamplerObj sampler(m_device);
2176 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002177
Tony Barbour01999182015-04-09 12:58:51 -06002178 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002179 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002180 pipelineobj.AddShader(&vs);
2181 pipelineobj.AddShader(&ps);
2182
Tony Barbour01999182015-04-09 12:58:51 -06002183 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002184 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002185
Tony Barbourdd4c9642015-01-09 12:55:14 -07002186 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002187 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002188
Tony Barbour1490c912015-07-28 10:17:20 -06002189 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002190
2191#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002192 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002193 pDSDumpDot((char*)"triTest2.dot");
2194#endif
2195 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002196 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002197
2198 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002199 EndCommandBuffer();
2200 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002201
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002202 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002203}
Tony Barbour01999182015-04-09 12:58:51 -06002204TEST_F(VkRenderTest, SamplerBindingsTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002205{
2206 // This test sets bindings on the samplers
2207 // For now we are asserting that sampler and texture pairs
2208 // march in lock step, and are set via GLSL binding. This can
2209 // and will probably change.
2210 // The sampler bindings should match the sampler and texture slot
2211 // number set up by the application.
2212 // This test will result in a blue triangle
2213 static const char *vertShaderText =
2214 "#version 140\n"
2215 "#extension GL_ARB_separate_shader_objects : enable\n"
2216 "#extension GL_ARB_shading_language_420pack : enable\n"
2217 "layout (location = 0) out vec4 samplePos;\n"
2218 "void main() {\n"
2219 " vec2 vertices[3];"
2220 " vertices[0] = vec2(-0.5, -0.5);\n"
2221 " vertices[1] = vec2( 0.5, -0.5);\n"
2222 " vertices[2] = vec2( 0.5, 0.5);\n"
2223 " vec2 positions[3];"
2224 " positions[0] = vec2( 0.0, 0.0);\n"
2225 " positions[1] = vec2( 1.0, 0.0);\n"
2226 " positions[2] = vec2( 1.0, 1.0);\n"
2227 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2228 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2229 "}\n";
2230
2231 static const char *fragShaderText =
2232 "#version 140\n"
2233 "#extension GL_ARB_separate_shader_objects : enable\n"
2234 "#extension GL_ARB_shading_language_420pack : enable\n"
2235 "layout (location = 0) in vec4 samplePos;\n"
2236 "layout (binding = 0) uniform sampler2D surface0;\n"
2237 "layout (binding = 1) uniform sampler2D surface1;\n"
2238 "layout (binding = 12) uniform sampler2D surface2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06002239 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002240 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002241 " outColor = textureLod(surface2, samplePos.xy, 0.0);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002242 "}\n";
2243
2244 ASSERT_NO_FATAL_FAILURE(InitState());
2245 ASSERT_NO_FATAL_FAILURE(InitViewport());
2246
Tony Barbour01999182015-04-09 12:58:51 -06002247 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2248 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002249
Tony Barbour01999182015-04-09 12:58:51 -06002250 VkSamplerObj sampler1(m_device);
2251 VkSamplerObj sampler2(m_device);
2252 VkSamplerObj sampler3(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002253
Tony Barbour2f421a02015-04-01 16:38:10 -06002254 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
Tony Barbour01999182015-04-09 12:58:51 -06002255 VkTextureObj texture1(m_device, tex_colors); // Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002256 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
Tony Barbour01999182015-04-09 12:58:51 -06002257 VkTextureObj texture2(m_device, tex_colors); // Green
Tony Barbour2f421a02015-04-01 16:38:10 -06002258 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
Tony Barbour01999182015-04-09 12:58:51 -06002259 VkTextureObj texture3(m_device, tex_colors); // Blue
Tony Barbourf43b6982014-11-25 13:18:32 -07002260
Tony Barbour01999182015-04-09 12:58:51 -06002261 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002262 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002263 pipelineobj.AddShader(&vs);
2264 pipelineobj.AddShader(&ps);
2265
Tony Barbour01999182015-04-09 12:58:51 -06002266 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002267 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2268 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2269 for (int i = 0; i < 10; i++)
2270 descriptorSet.AppendDummy();
2271 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002272
Tony Barbourdd4c9642015-01-09 12:55:14 -07002273 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002274 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002275
Tony Barbour1490c912015-07-28 10:17:20 -06002276 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002277
2278#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002279 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002280 pDSDumpDot((char*)"triTest2.dot");
2281#endif
2282 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002283 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002284
2285 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002286 EndCommandBuffer();
2287 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002288
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002289 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002290}
2291
Tony Barbour01999182015-04-09 12:58:51 -06002292TEST_F(VkRenderTest, TriangleVSUniformBlock)
Tony Barbourf43b6982014-11-25 13:18:32 -07002293{
2294 // The expected result from this test is a blue triangle
2295
2296 static const char *vertShaderText =
2297 "#version 140\n"
2298 "#extension GL_ARB_separate_shader_objects : enable\n"
2299 "#extension GL_ARB_shading_language_420pack : enable\n"
2300 "layout (location = 0) out vec4 outColor;\n"
2301 "layout (std140, binding = 0) uniform bufferVals {\n"
2302 " vec4 red;\n"
2303 " vec4 green;\n"
2304 " vec4 blue;\n"
2305 " vec4 white;\n"
2306 "} myBufferVals;\n"
2307 "void main() {\n"
2308 " vec2 vertices[3];"
2309 " vertices[0] = vec2(-0.5, -0.5);\n"
2310 " vertices[1] = vec2( 0.5, -0.5);\n"
2311 " vertices[2] = vec2( 0.5, 0.5);\n"
2312 " outColor = myBufferVals.blue;\n"
2313 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2314 "}\n";
2315
2316 static const char *fragShaderText =
2317 "#version 140\n"
2318 "#extension GL_ARB_separate_shader_objects : enable\n"
2319 "#extension GL_ARB_shading_language_420pack : enable\n"
2320 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -06002321 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002322 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002323 " outColor = inColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002324 "}\n";
2325
2326 ASSERT_NO_FATAL_FAILURE(InitState());
2327 ASSERT_NO_FATAL_FAILURE(InitViewport());
2328
Tony Barbour01999182015-04-09 12:58:51 -06002329 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2330 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002331
2332 // Let's populate our buffer with the following:
2333 // vec4 red;
2334 // vec4 green;
2335 // vec4 blue;
2336 // vec4 white;
2337 const int valCount = 4 * 4;
2338 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2339 0.0, 1.0, 0.0, 1.0,
2340 0.0, 0.0, 1.0, 1.0,
2341 1.0, 1.0, 1.0, 1.0 };
2342
Tony Barbour01999182015-04-09 12:58:51 -06002343 VkConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002344
Tony Barbour01999182015-04-09 12:58:51 -06002345 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002346 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002347 pipelineobj.AddShader(&vs);
2348 pipelineobj.AddShader(&ps);
2349
Tony Barbour01999182015-04-09 12:58:51 -06002350 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002351 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002352
Tony Barbourdd4c9642015-01-09 12:55:14 -07002353 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002354 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002355
Tony Barbour1490c912015-07-28 10:17:20 -06002356 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002357
2358#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002359 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002360 pDSDumpDot((char*)"triTest2.dot");
2361#endif
2362 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002363 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002364
2365 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002366 EndCommandBuffer();
2367 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002368
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002369 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002370}
2371
Tony Barbour01999182015-04-09 12:58:51 -06002372TEST_F(VkRenderTest, TriangleFSUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002373{
2374 // This test allows the shader to select which buffer it is
2375 // pulling from using layout binding qualifier.
2376 // There are corresponding changes in the compiler stack that
2377 // will select the buffer using binding directly.
2378 // The binding number should match the slot number set up by
2379 // the application.
2380 // The expected result from this test is a purple triangle
2381
2382 static const char *vertShaderText =
2383 "#version 140\n"
2384 "#extension GL_ARB_separate_shader_objects : enable\n"
2385 "#extension GL_ARB_shading_language_420pack : enable\n"
2386 "void main() {\n"
2387 " vec2 vertices[3];"
2388 " vertices[0] = vec2(-0.5, -0.5);\n"
2389 " vertices[1] = vec2( 0.5, -0.5);\n"
2390 " vertices[2] = vec2( 0.5, 0.5);\n"
2391 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2392 "}\n";
2393
2394 static const char *fragShaderText =
2395 "#version 140\n"
2396 "#extension GL_ARB_separate_shader_objects : enable\n"
2397 "#extension GL_ARB_shading_language_420pack : enable\n"
2398 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2399 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2400 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002401 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
GregFd6ebdb32015-06-03 18:40:50 -06002402 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002403 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002404 " outColor = myBlueVal.color;\n"
2405 " outColor += myRedVal.color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002406 "}\n";
2407
2408 ASSERT_NO_FATAL_FAILURE(InitState());
2409 ASSERT_NO_FATAL_FAILURE(InitViewport());
2410
Tony Barbour01999182015-04-09 12:58:51 -06002411 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2412 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002413
2414 // We're going to create a number of uniform buffers, and then allow
2415 // the shader to select which it wants to read from with a binding
2416
2417 // Let's populate the buffers with a single color each:
2418 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2419 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2420 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002421 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002422
2423 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2424 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2425 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2426 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2427
2428 const int redCount = sizeof(redVals) / sizeof(float);
2429 const int greenCount = sizeof(greenVals) / sizeof(float);
2430 const int blueCount = sizeof(blueVals) / sizeof(float);
2431 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2432
Tony Barbour01999182015-04-09 12:58:51 -06002433 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002434
Tony Barbour01999182015-04-09 12:58:51 -06002435 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002436
Tony Barbour01999182015-04-09 12:58:51 -06002437 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002438
Tony Barbour01999182015-04-09 12:58:51 -06002439 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002440
Tony Barbour01999182015-04-09 12:58:51 -06002441 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002442 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002443 pipelineobj.AddShader(&vs);
2444 pipelineobj.AddShader(&ps);
2445
Tony Barbour01999182015-04-09 12:58:51 -06002446 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002447 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2448 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2449 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2450 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002451
Tony Barbourdd4c9642015-01-09 12:55:14 -07002452 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002453 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourf43b6982014-11-25 13:18:32 -07002454
Tony Barbour1490c912015-07-28 10:17:20 -06002455 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002456
2457#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002458 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002459 pDSDumpDot((char*)"triTest2.dot");
2460#endif
2461 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002462 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002463
2464 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002465 EndCommandBuffer();
2466 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002467
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002468 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002469}
2470
Tony Barbour01999182015-04-09 12:58:51 -06002471TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002472{
2473 // This test is the same as TriangleFSUniformBlockBinding, but
2474 // it does not provide an instance name.
2475 // The expected result from this test is a purple triangle
2476
2477 static const char *vertShaderText =
2478 "#version 140\n"
2479 "#extension GL_ARB_separate_shader_objects : enable\n"
2480 "#extension GL_ARB_shading_language_420pack : enable\n"
2481 "void main() {\n"
2482 " vec2 vertices[3];"
2483 " vertices[0] = vec2(-0.5, -0.5);\n"
2484 " vertices[1] = vec2( 0.5, -0.5);\n"
2485 " vertices[2] = vec2( 0.5, 0.5);\n"
2486 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2487 "}\n";
2488
2489 static const char *fragShaderText =
2490 "#version 430\n"
2491 "#extension GL_ARB_separate_shader_objects : enable\n"
2492 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002493 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2494 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2495 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002496 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002497 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002498 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002499 " outColor = blue;\n"
2500 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002501 "}\n";
2502 ASSERT_NO_FATAL_FAILURE(InitState());
2503 ASSERT_NO_FATAL_FAILURE(InitViewport());
2504
Tony Barbour01999182015-04-09 12:58:51 -06002505 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2506 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002507
2508 // We're going to create a number of uniform buffers, and then allow
2509 // the shader to select which it wants to read from with a binding
2510
2511 // Let's populate the buffers with a single color each:
2512 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2513 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2514 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2515 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2516
2517 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2518 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2519 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2520 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2521
2522 const int redCount = sizeof(redVals) / sizeof(float);
2523 const int greenCount = sizeof(greenVals) / sizeof(float);
2524 const int blueCount = sizeof(blueVals) / sizeof(float);
2525 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2526
Tony Barbour01999182015-04-09 12:58:51 -06002527 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002528
Tony Barbour01999182015-04-09 12:58:51 -06002529 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002530
Tony Barbour01999182015-04-09 12:58:51 -06002531 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002532
Tony Barbour01999182015-04-09 12:58:51 -06002533 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002534
Tony Barbour01999182015-04-09 12:58:51 -06002535 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002536 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002537 pipelineobj.AddShader(&vs);
2538 pipelineobj.AddShader(&ps);
2539
Tony Barbour01999182015-04-09 12:58:51 -06002540 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002541 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2542 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2543 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2544 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002545
Tony Barbourdd4c9642015-01-09 12:55:14 -07002546 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002547 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002548
Tony Barbour1490c912015-07-28 10:17:20 -06002549 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002550
2551#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002552 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002553 pDSDumpDot((char*)"triTest2.dot");
2554#endif
2555 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002556 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002557
2558 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002559 EndCommandBuffer();
2560 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002561
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002562 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002563}
2564
GregF54a32172015-07-01 16:11:09 -06002565TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBindingWithStruct)
2566{
2567 // This test is the same as TriangleFSUniformBlockBinding, but
2568 // it does not provide an instance name.
2569 // The expected result from this test is a purple triangle
2570
2571 static const char *vertShaderText =
2572 "#version 140\n"
2573 "#extension GL_ARB_separate_shader_objects : enable\n"
2574 "#extension GL_ARB_shading_language_420pack : enable\n"
2575 "void main() {\n"
2576 " vec2 vertices[3];"
2577 " vertices[0] = vec2(-0.5, -0.5);\n"
2578 " vertices[1] = vec2( 0.5, -0.5);\n"
2579 " vertices[2] = vec2( 0.5, 0.5);\n"
2580 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2581 "}\n";
2582
2583 static const char *fragShaderText =
2584 "#version 430\n"
2585 "#extension GL_ARB_separate_shader_objects : enable\n"
2586 "#extension GL_ARB_shading_language_420pack : enable\n"
2587 "\n"
2588 " struct PS_INPUT {\n"
2589 " vec2 member0;\n"
2590 " vec4 member1;\n"
2591 " vec4 member2;\n"
2592 " vec4 member3;\n"
2593 " vec4 member4;\n"
2594 " vec4 member5;\n"
2595 " vec4 member6;\n"
2596 " vec4 member7;\n"
2597 " vec4 member8;\n"
2598 " vec4 member9;\n"
2599 " };\n"
2600 "\n"
2601 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2602 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2603 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2604 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
2605 "layout (location = 0) out vec4 outColor;\n"
2606 "PS_INPUT MainFs()\n"
2607 "{\n"
2608 " PS_INPUT o;\n"
2609 " o.member9 = red;\n"
2610 " return o;\n"
2611 "}\n"
2612 "\n"
2613 "void main()\n"
2614 "{\n"
2615 " PS_INPUT o;\n"
2616 " o = MainFs();\n"
2617 " outColor = blue;"
2618 " outColor += o.member9;\n"
2619 "}\n";;
2620 ASSERT_NO_FATAL_FAILURE(InitState());
2621 ASSERT_NO_FATAL_FAILURE(InitViewport());
2622
2623 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2624 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2625
2626 // We're going to create a number of uniform buffers, and then allow
2627 // the shader to select which it wants to read from with a binding
2628
2629 // Let's populate the buffers with a single color each:
2630 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2631 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2632 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2633 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2634
2635 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2636 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2637 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2638 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2639
2640 const int redCount = sizeof(redVals) / sizeof(float);
2641 const int greenCount = sizeof(greenVals) / sizeof(float);
2642 const int blueCount = sizeof(blueVals) / sizeof(float);
2643 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2644
2645 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2646
2647 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2648
2649 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2650
2651 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
2652
2653 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002654 pipelineobj.AddColorAttachment();
GregF54a32172015-07-01 16:11:09 -06002655 pipelineobj.AddShader(&vs);
2656 pipelineobj.AddShader(&ps);
2657
2658 VkDescriptorSetObj descriptorSet(m_device);
2659 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2660 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2661 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2662 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
2663
2664 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002665 ASSERT_VK_SUCCESS(BeginCommandBuffer());
GregF54a32172015-07-01 16:11:09 -06002666
Tony Barbour1490c912015-07-28 10:17:20 -06002667 GenericDrawPreparation(pipelineobj, descriptorSet);
GregF54a32172015-07-01 16:11:09 -06002668
2669#ifdef DUMP_STATE_DOT
2670 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
2671 pDSDumpDot((char*)"triTest2.dot");
2672#endif
2673 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002674 Draw(0, 3, 0, 1);
GregF54a32172015-07-01 16:11:09 -06002675
2676 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002677 EndCommandBuffer();
2678 QueueCommandBuffer();
GregF54a32172015-07-01 16:11:09 -06002679
2680 RecordImages(m_renderTargets);
2681}
2682
Tony Barbour01999182015-04-09 12:58:51 -06002683TEST_F(VkRenderTest, CubeWithVertexFetchAndMVPAndTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07002684{
2685 static const char *vertShaderText =
2686 "#version 140\n"
2687 "#extension GL_ARB_separate_shader_objects : enable\n"
2688 "#extension GL_ARB_shading_language_420pack : enable\n"
2689 "layout (std140, binding=0) uniform bufferVals {\n"
2690 " mat4 mvp;\n"
2691 "} myBufferVals;\n"
2692 "layout (location=0) in vec4 pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002693 "layout (location=1) in vec2 input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002694 "layout (location=0) out vec2 UV;\n"
2695 "void main() {\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002696 " UV = input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002697 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002698 " gl_Position.y = -gl_Position.y;\n"
2699 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002700 "}\n";
2701
2702 static const char *fragShaderText =
2703 "#version 140\n"
2704 "#extension GL_ARB_separate_shader_objects : enable\n"
2705 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002706 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002707 "layout (location=0) out vec4 outColor;\n"
2708 "layout (location=0) in vec2 UV;\n"
2709 "void main() {\n"
2710 " outColor= textureLod(surface, UV, 0.0);\n"
2711 "}\n";
2712 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2713
2714 glm::mat4 View = glm::lookAt(
2715 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2716 glm::vec3(0,0,0), // and looks at the origin
2717 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2718 );
2719
2720 glm::mat4 Model = glm::mat4(1.0f);
2721
2722 glm::mat4 MVP = Projection * View * Model;
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002723 int num_verts = sizeof(g_vb_texture_Data) / sizeof(g_vb_texture_Data[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002724
2725
2726 ASSERT_NO_FATAL_FAILURE(InitState());
2727 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wu9e81ebb2015-07-09 10:16:34 +08002728 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Chia-I Wuc278df82015-07-07 11:50:03 +08002729 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height, m_depth_stencil_fmt);
Tony Barbourf43b6982014-11-25 13:18:32 -07002730
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002731 VkConstantBufferObj meshBuffer(m_device, num_verts,
2732 sizeof(g_vb_texture_Data[0]), g_vb_texture_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002733 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002734
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002735 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07002736
Tony Barbour01999182015-04-09 12:58:51 -06002737 VkConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2738 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2739 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2740 VkSamplerObj sampler(m_device);
2741 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002742
Tony Barbour01999182015-04-09 12:58:51 -06002743 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002744 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002745 pipelineobj.AddShader(&vs);
2746 pipelineobj.AddShader(&ps);
2747
Tony Barbour01999182015-04-09 12:58:51 -06002748 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002749 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mvpBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002750 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002751
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002752#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002753 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002754 MESH_BIND_ID, // binding ID
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002755 sizeof(g_vb_texture_Data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002756 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002757 };
Tony Barbourf43b6982014-11-25 13:18:32 -07002758
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002759 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002760 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2761 vi_attribs[0].location = 0; // location
Tony Barbour8205d902015-04-16 15:59:00 -06002762 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002763 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2764 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2765 vi_attribs[1].location = 1; // location
2766 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
2767 vi_attribs[1].offsetInBytes = 16; // Offset of uv components
Tony Barbourf43b6982014-11-25 13:18:32 -07002768
Tony Barbourf43b6982014-11-25 13:18:32 -07002769 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002770 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Tony Barbourf43b6982014-11-25 13:18:32 -07002771
Tony Barboure307f582015-07-10 15:29:03 -06002772 VkPipelineDepthStencilStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002773 ds_state.depthTestEnable = VK_TRUE;
2774 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06002775 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Cody Northrope4bc6942015-08-26 10:01:32 -06002776 ds_state.depthBoundsTestEnable = VK_FALSE;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002777 ds_state.stencilTestEnable = VK_FALSE;
2778 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
2779 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
2780 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06002781 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002782 ds_state.front = ds_state.back;
2783 pipelineobj.SetDepthStencil(&ds_state);
2784
Tony Barbour17c6ab12015-03-27 17:03:18 -06002785 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tobin Ehlis7f7b4422015-08-18 14:24:32 -06002786
2787 VkCmdBufferBeginInfo cbBeginInfo;
2788 memset(&cbBeginInfo, 0, sizeof(VkCmdBufferBeginInfo));
2789 cbBeginInfo.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
2790 cbBeginInfo.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT;
2791 ASSERT_VK_SUCCESS(BeginCommandBuffer(&cbBeginInfo));
Tony Barbourf43b6982014-11-25 13:18:32 -07002792
Tony Barbour1490c912015-07-28 10:17:20 -06002793 GenericDrawPreparation(pipelineobj, descriptorSet);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002794
Tony Barbour1490c912015-07-28 10:17:20 -06002795 BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002796#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002797 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002798 pDSDumpDot((char*)"triTest2.dot");
2799#endif
2800 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002801 Draw(0, num_verts, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002802
2803 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002804 EndCommandBuffer();
2805 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002806
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002807 RecordImages(m_renderTargets);
Tony Barbour1490c912015-07-28 10:17:20 -06002808 RotateTriangleVSUniform(Projection, View, Model, &mvpBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002809}
Cody Northropd1ce7842014-12-09 11:17:01 -07002810
Tony Barbour01999182015-04-09 12:58:51 -06002811TEST_F(VkRenderTest, TriangleMixedSamplerUniformBlockBinding)
Cody Northropd1ce7842014-12-09 11:17:01 -07002812{
2813 // This test mixes binding slots of textures and buffers, ensuring
2814 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002815 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002816 // you can modify it to move the desired result around.
2817
2818 static const char *vertShaderText =
2819 "#version 140\n"
2820 "#extension GL_ARB_separate_shader_objects : enable\n"
2821 "#extension GL_ARB_shading_language_420pack : enable\n"
2822 "void main() {\n"
2823 " vec2 vertices[3];"
2824 " vertices[0] = vec2(-0.5, -0.5);\n"
2825 " vertices[1] = vec2( 0.5, -0.5);\n"
2826 " vertices[2] = vec2( 0.5, 0.5);\n"
2827 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2828 "}\n";
2829
2830 static const char *fragShaderText =
2831 "#version 430\n"
2832 "#extension GL_ARB_separate_shader_objects : enable\n"
2833 "#extension GL_ARB_shading_language_420pack : enable\n"
2834 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002835 "layout (binding = 3) uniform sampler2D surface1;\n"
2836 "layout (binding = 1) uniform sampler2D surface2;\n"
2837 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002838
Cody Northropa0410942014-12-09 13:59:39 -07002839
Chia-I Wuf8385062015-01-04 16:27:24 +08002840 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2841 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2842 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2843 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002844 "layout (location = 0) out vec4 outColor;\n"
2845 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002846 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002847 " outColor += white * vec4(0.00001);\n"
2848 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002849 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002850 "}\n";
2851 ASSERT_NO_FATAL_FAILURE(InitState());
2852 ASSERT_NO_FATAL_FAILURE(InitViewport());
2853
Tony Barbour01999182015-04-09 12:58:51 -06002854 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2855 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northropd1ce7842014-12-09 11:17:01 -07002856
Cody Northropd1ce7842014-12-09 11:17:01 -07002857 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2858 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2859 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2860 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2861
2862 const int redCount = sizeof(redVals) / sizeof(float);
2863 const int greenCount = sizeof(greenVals) / sizeof(float);
2864 const int blueCount = sizeof(blueVals) / sizeof(float);
2865 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2866
Tony Barbour01999182015-04-09 12:58:51 -06002867 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2868 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2869 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2870 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002871
Tony Barbour2f421a02015-04-01 16:38:10 -06002872 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002873 VkSamplerObj sampler0(m_device);
2874 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002875 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002876 VkSamplerObj sampler2(m_device);
2877 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002878 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002879 VkSamplerObj sampler4(m_device);
2880 VkTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropa0410942014-12-09 13:59:39 -07002881
2882 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2883 // TODO: Get back here ASAP and understand why.
Tony Barbour2f421a02015-04-01 16:38:10 -06002884 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06002885 VkSamplerObj sampler7(m_device);
2886 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropd1ce7842014-12-09 11:17:01 -07002887
Tony Barbour01999182015-04-09 12:58:51 -06002888 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002889 pipelineobj.AddColorAttachment();
Cody Northropd1ce7842014-12-09 11:17:01 -07002890 pipelineobj.AddShader(&vs);
2891 pipelineobj.AddShader(&ps);
2892
Tony Barbour01999182015-04-09 12:58:51 -06002893 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002894 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2895 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2896 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2897 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002898 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002899 // swap blue and green
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002900 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2901 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2902 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002903
Tony Barbourdd4c9642015-01-09 12:55:14 -07002904 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06002905 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropd1ce7842014-12-09 11:17:01 -07002906
Tony Barbour1490c912015-07-28 10:17:20 -06002907 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002908
2909#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002910 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002911 pDSDumpDot((char*)"triTest2.dot");
2912#endif
2913 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06002914 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002915
2916 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06002917 EndCommandBuffer();
2918 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002919
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002920 RecordImages(m_renderTargets);
Cody Northropd1ce7842014-12-09 11:17:01 -07002921}
2922
Tony Barbour01999182015-04-09 12:58:51 -06002923TEST_F(VkRenderTest, TriangleMatchingSamplerUniformBlockBinding)
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002924{
2925 // This test matches binding slots of textures and buffers, requiring
2926 // the driver to give them distinct number spaces.
2927 // The expected result from this test is a red triangle, although
2928 // you can modify it to move the desired result around.
2929
2930 static const char *vertShaderText =
2931 "#version 140\n"
2932 "#extension GL_ARB_separate_shader_objects : enable\n"
2933 "#extension GL_ARB_shading_language_420pack : enable\n"
2934 "void main() {\n"
2935 " vec2 vertices[3];"
2936 " vertices[0] = vec2(-0.5, -0.5);\n"
2937 " vertices[1] = vec2( 0.5, -0.5);\n"
2938 " vertices[2] = vec2( 0.5, 0.5);\n"
2939 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2940 "}\n";
2941
2942 static const char *fragShaderText =
2943 "#version 430\n"
2944 "#extension GL_ARB_separate_shader_objects : enable\n"
2945 "#extension GL_ARB_shading_language_420pack : enable\n"
2946 "layout (binding = 0) uniform sampler2D surface0;\n"
2947 "layout (binding = 1) uniform sampler2D surface1;\n"
2948 "layout (binding = 2) uniform sampler2D surface2;\n"
2949 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002950 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2951 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2952 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2953 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002954 "layout (location = 0) out vec4 outColor;\n"
2955 "void main() {\n"
2956 " outColor = red;// * vec4(0.00001);\n"
2957 " outColor += white * vec4(0.00001);\n"
2958 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2959 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2960 "}\n";
2961 ASSERT_NO_FATAL_FAILURE(InitState());
2962 ASSERT_NO_FATAL_FAILURE(InitViewport());
2963
Tony Barbour01999182015-04-09 12:58:51 -06002964 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2965 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002966
2967 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2968 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2969 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2970 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2971
2972 const int redCount = sizeof(redVals) / sizeof(float);
2973 const int greenCount = sizeof(greenVals) / sizeof(float);
2974 const int blueCount = sizeof(blueVals) / sizeof(float);
2975 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2976
Tony Barbour01999182015-04-09 12:58:51 -06002977 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2978 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2979 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2980 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002981
Tony Barbour2f421a02015-04-01 16:38:10 -06002982 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002983 VkSamplerObj sampler0(m_device);
2984 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002985 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002986 VkSamplerObj sampler2(m_device);
2987 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002988 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002989 VkSamplerObj sampler4(m_device);
2990 VkTextureObj texture4(m_device, tex_colors); // Light Green
Tony Barbour2f421a02015-04-01 16:38:10 -06002991 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06002992 VkSamplerObj sampler7(m_device);
2993 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002994
Tony Barbour01999182015-04-09 12:58:51 -06002995 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002996 pipelineobj.AddColorAttachment();
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002997 pipelineobj.AddShader(&vs);
2998 pipelineobj.AddShader(&ps);
2999
Tony Barbour01999182015-04-09 12:58:51 -06003000 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08003001 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3002 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3003 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
3004 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003005 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
3006 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
3007 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
3008 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003009
Tony Barbourdd4c9642015-01-09 12:55:14 -07003010 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003011 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003012
Tony Barbour1490c912015-07-28 10:17:20 -06003013 GenericDrawPreparation(pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07003014
3015#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003016 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07003017 pDSDumpDot((char*)"triTest2.dot");
3018#endif
3019 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06003020 Draw(0, 3, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07003021
3022 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003023 EndCommandBuffer();
3024 QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07003025
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003026 RecordImages(m_renderTargets);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003027}
3028
Tony Barbour01999182015-04-09 12:58:51 -06003029TEST_F(VkRenderTest, TriangleUniformBufferLayout)
Cody Northrop02690bd2014-12-17 15:26:33 -07003030{
3031 // This test populates a buffer with a variety of different data
3032 // types, then reads them out with a shader.
3033 // The expected result from this test is a green triangle
3034
3035 static const char *vertShaderText =
3036 "#version 140\n"
3037 "#extension GL_ARB_separate_shader_objects : enable\n"
3038 "#extension GL_ARB_shading_language_420pack : enable\n"
3039 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3040 " vec4 fRed;\n"
3041 " vec4 fGreen;\n"
3042 " layout(row_major) mat4 worldToProj;\n"
3043 " layout(row_major) mat4 projToWorld;\n"
3044 " layout(row_major) mat4 worldToView;\n"
3045 " layout(row_major) mat4 viewToProj;\n"
3046 " layout(row_major) mat4 worldToShadow[4];\n"
3047 " float fZero;\n"
3048 " float fOne;\n"
3049 " float fTwo;\n"
3050 " float fThree;\n"
3051 " vec3 fZeroZeroZero;\n"
3052 " float fFour;\n"
3053 " vec3 fZeroZeroOne;\n"
3054 " float fFive;\n"
3055 " vec3 fZeroOneZero;\n"
3056 " float fSix;\n"
3057 " float fSeven;\n"
3058 " float fEight;\n"
3059 " float fNine;\n"
3060 " vec2 fZeroZero;\n"
3061 " vec2 fZeroOne;\n"
3062 " vec4 fBlue;\n"
3063 " vec2 fOneZero;\n"
3064 " vec2 fOneOne;\n"
3065 " vec3 fZeroOneOne;\n"
3066 " float fTen;\n"
3067 " float fEleven;\n"
3068 " float fTwelve;\n"
3069 " vec3 fOneZeroZero;\n"
3070 " vec4 uvOffsets[4];\n"
3071 "};\n"
3072 "layout (location = 0) out vec4 color;"
3073 "void main() {\n"
3074
3075 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3076 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3077 " \n"
3078
3079 // do some exact comparisons, even though we should
3080 // really have an epsilon involved.
3081 " vec4 outColor = right;\n"
3082 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3083 " outColor = wrong;\n"
3084 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3085 " outColor = wrong;\n"
3086 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3087 " outColor = wrong;\n"
3088
3089 " color = outColor;\n"
3090
3091 // generic position stuff
3092 " vec2 vertices;\n"
3093 " int vertexSelector = gl_VertexID;\n"
3094 " if (vertexSelector == 0)\n"
3095 " vertices = vec2(-0.5, -0.5);\n"
3096 " else if (vertexSelector == 1)\n"
3097 " vertices = vec2( 0.5, -0.5);\n"
3098 " else if (vertexSelector == 2)\n"
3099 " vertices = vec2( 0.5, 0.5);\n"
3100 " else\n"
3101 " vertices = vec2( 0.0, 0.0);\n"
3102 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3103 "}\n";
3104
3105 static const char *fragShaderText =
3106 "#version 140\n"
3107 "#extension GL_ARB_separate_shader_objects : enable\n"
3108 "#extension GL_ARB_shading_language_420pack : enable\n"
3109 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3110 " vec4 fRed;\n"
3111 " vec4 fGreen;\n"
3112 " layout(row_major) mat4 worldToProj;\n"
3113 " layout(row_major) mat4 projToWorld;\n"
3114 " layout(row_major) mat4 worldToView;\n"
3115 " layout(row_major) mat4 viewToProj;\n"
3116 " layout(row_major) mat4 worldToShadow[4];\n"
3117 " float fZero;\n"
3118 " float fOne;\n"
3119 " float fTwo;\n"
3120 " float fThree;\n"
3121 " vec3 fZeroZeroZero;\n"
3122 " float fFour;\n"
3123 " vec3 fZeroZeroOne;\n"
3124 " float fFive;\n"
3125 " vec3 fZeroOneZero;\n"
3126 " float fSix;\n"
3127 " float fSeven;\n"
3128 " float fEight;\n"
3129 " float fNine;\n"
3130 " vec2 fZeroZero;\n"
3131 " vec2 fZeroOne;\n"
3132 " vec4 fBlue;\n"
3133 " vec2 fOneZero;\n"
3134 " vec2 fOneOne;\n"
3135 " vec3 fZeroOneOne;\n"
3136 " float fTen;\n"
3137 " float fEleven;\n"
3138 " float fTwelve;\n"
3139 " vec3 fOneZeroZero;\n"
3140 " vec4 uvOffsets[4];\n"
3141 "};\n"
3142 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003143 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop02690bd2014-12-17 15:26:33 -07003144 "void main() {\n"
3145 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3146 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3147 " \n"
3148
3149 // start with VS value to ensure it passed
3150 " vec4 outColor = color;\n"
3151
3152 // do some exact comparisons, even though we should
3153 // really have an epsilon involved.
3154 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3155 " outColor = wrong;\n"
3156 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3157 " outColor = wrong;\n"
3158 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3159 " outColor = wrong;\n"
3160 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3161 " outColor = wrong;\n"
3162 " if (fTwo != 2.0)\n"
3163 " outColor = wrong;\n"
3164 " if (fOneOne != vec2(1.0, 1.0))\n"
3165 " outColor = wrong;\n"
3166 " if (fTen != 10.0)\n"
3167 " outColor = wrong;\n"
3168 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3169 " outColor = wrong;\n"
3170 " \n"
GregFd6ebdb32015-06-03 18:40:50 -06003171 " uFragColor = outColor;\n"
Cody Northrop02690bd2014-12-17 15:26:33 -07003172 "}\n";
3173
3174
Cody Northrop1684adb2015-08-05 11:15:02 -06003175 const float mixedVals[196] = { 1.0f, 0.0f, 0.0f, 1.0f, // vec4 fRed; // align
3176 0.0f, 1.0f, 0.0f, 1.0f, // vec4 fGreen; // align
3177 1.0f, 0.0f, 0.0f, 1.0f, // layout(row_major) mat4 worldToProj;
3178 0.0f, 1.0f, 0.0f, 1.0f, // align
3179 0.0f, 0.0f, 1.0f, 1.0f, // align
3180 0.0f, 0.0f, 0.0f, 1.0f, // align
3181 2.0f, 0.0f, 0.0f, 2.0f, // layout(row_major) mat4 projToWorld;
3182 0.0f, 2.0f, 0.0f, 2.0f, // align
3183 0.0f, 0.0f, 2.0f, 2.0f, // align
3184 0.0f, 0.0f, 0.0f, 2.0f, // align
3185 3.0f, 0.0f, 0.0f, 3.0f, // layout(row_major) mat4 worldToView;
3186 0.0f, 3.0f, 0.0f, 3.0f, // align
3187 0.0f, 0.0f, 3.0f, 3.0f, // align
3188 0.0f, 0.0f, 0.0f, 3.0f, // align
3189 4.0f, 0.0f, 0.0f, 4.0f, // layout(row_major) mat4 viewToProj;
3190 0.0f, 4.0f, 0.0f, 4.0f, // align
3191 0.0f, 0.0f, 4.0f, 4.0f, // align
3192 0.0f, 0.0f, 0.0f, 4.0f, // align
3193 5.0f, 0.0f, 0.0f, 5.0f, // layout(row_major) mat4 worldToShadow[4];
3194 0.0f, 5.0f, 0.0f, 5.0f, // align
3195 0.0f, 0.0f, 5.0f, 5.0f, // align
3196 0.0f, 0.0f, 0.0f, 5.0f, // align
3197 6.0f, 0.0f, 0.0f, 6.0f, // align
3198 0.0f, 6.0f, 0.0f, 6.0f, // align
3199 0.0f, 0.0f, 6.0f, 6.0f, // align
3200 0.0f, 0.0f, 0.0f, 6.0f, // align
3201 7.0f, 0.0f, 0.0f, 7.0f, // align
3202 0.0f, 7.0f, 0.0f, 7.0f, // align
3203 0.0f, 0.0f, 7.0f, 7.0f, // align
3204 0.0f, 0.0f, 0.0f, 7.0f, // align
3205 8.0f, 0.0f, 0.0f, 8.0f, // align
3206 0.0f, 8.0f, 0.0f, 8.0f, // align
3207 0.0f, 0.0f, 8.0f, 8.0f, // align
3208 0.0f, 0.0f, 0.0f, 8.0f, // align
3209 0.0f, // float fZero; // align
3210 1.0f, // float fOne; // pack
3211 2.0f, // float fTwo; // pack
3212 3.0f, // float fThree; // pack
3213 0.0f, 0.0f, 0.0f, // vec3 fZeroZeroZero; // align
3214 4.0f, // float fFour; // pack
3215 0.0f, 0.0f, 1.0f, // vec3 fZeroZeroOne; // align
3216 5.0f, // float fFive; // pack
3217 0.0f, 1.0f, 0.0f, // vec3 fZeroOneZero; // align
3218 6.0f, // float fSix; // pack
3219 7.0f, // float fSeven; // align
3220 8.0f, // float fEight; // pack
3221 9.0f, // float fNine; // pack
3222 0.0f, // BUFFER
3223 0.0f, 0.0f, // vec2 fZeroZero; // align
3224 0.0f, 1.0f, // vec2 fZeroOne; // pack
3225 0.0f, 0.0f, 1.0f, 1.0f, // vec4 fBlue; // align
3226 1.0f, 0.0f, // vec2 fOneZero; // align
3227 1.0f, 1.0f, // vec2 fOneOne; // pack
3228 0.0f, 1.0f, 1.0f, // vec3 fZeroOneOne; // align
3229 10.0f, // float fTen; // pack
3230 11.0f, // float fEleven; // align
3231 12.0f, // float fTwelve; // pack
3232 0.0f, 0.0f, // BUFFER
3233 1.0f, 0.0f, 0.0f, // vec3 fOneZeroZero; // align
3234 0.0f, // BUFFER
3235 0.1f, 0.2f, 0.3f, 0.4f, // vec4 uvOffsets[4];
3236 0.5f, 0.6f, 0.7f, 0.8f, // align
3237 0.9f, 1.0f, 1.1f, 1.2f, // align
3238 1.3f, 1.4f, 1.5f, 1.6f, // align
Cody Northrop02690bd2014-12-17 15:26:33 -07003239 };
3240
3241 ASSERT_NO_FATAL_FAILURE(InitState());
3242 ASSERT_NO_FATAL_FAILURE(InitViewport());
3243
3244 const int constCount = sizeof(mixedVals) / sizeof(float);
3245
Tony Barbour01999182015-04-09 12:58:51 -06003246 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3247 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop02690bd2014-12-17 15:26:33 -07003248
Tony Barbour01999182015-04-09 12:58:51 -06003249 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003250
Tony Barbour01999182015-04-09 12:58:51 -06003251 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003252 pipelineobj.AddColorAttachment();
Cody Northrop02690bd2014-12-17 15:26:33 -07003253 pipelineobj.AddShader(&vs);
3254 pipelineobj.AddShader(&ps);
3255
Tony Barbour01999182015-04-09 12:58:51 -06003256 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003257 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003258
3259 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003260 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop02690bd2014-12-17 15:26:33 -07003261
Tony Barbour1490c912015-07-28 10:17:20 -06003262 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop02690bd2014-12-17 15:26:33 -07003263
3264#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003265 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop02690bd2014-12-17 15:26:33 -07003266 pDSDumpDot((char*)"triTest2.dot");
3267#endif
3268 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06003269 Draw(0, 3, 0, 1);
Cody Northrop02690bd2014-12-17 15:26:33 -07003270
3271 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003272 EndCommandBuffer();
3273 QueueCommandBuffer();
Cody Northrop02690bd2014-12-17 15:26:33 -07003274
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003275 RecordImages(m_renderTargets);
Cody Northrop02690bd2014-12-17 15:26:33 -07003276}
3277
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003278TEST_F(VkRenderTest, TextureGather)
3279{
3280 // This test introduces textureGather and textureGatherOffset
3281 // Each call is compared against an expected inline color result
3282 // Green triangle means everything worked as expected
3283 // Red means something went wrong
3284
Cody Northropbe701ac2015-08-06 13:18:13 -06003285 // disable SPV until texture gather is turned on in glsl->SPV
3286 if (!m_use_glsl) {
3287 printf("Skipping test that requires GLSL path (TextureGather)\n");
3288 return;
3289 }
3290
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003291 static const char *vertShaderText =
3292 "#version 140\n"
3293 "#extension GL_ARB_separate_shader_objects : enable\n"
3294 "#extension GL_ARB_shading_language_420pack : enable\n"
3295 "void main() {\n"
3296 " vec2 vertices[3];"
3297 " vertices[0] = vec2(-0.5, -0.5);\n"
3298 " vertices[1] = vec2( 0.5, -0.5);\n"
3299 " vertices[2] = vec2( 0.5, 0.5);\n"
3300 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
3301 "}\n";
3302
3303 static const char *fragShaderText =
3304 "#version 430\n"
3305 "#extension GL_ARB_separate_shader_objects : enable\n"
3306 "#extension GL_ARB_shading_language_420pack : enable\n"
3307 "layout (binding = 0) uniform sampler2D surface0;\n"
3308 "layout (binding = 1) uniform sampler2D surface1;\n"
3309 "layout (binding = 2) uniform sampler2D surface2;\n"
3310 "layout (binding = 3) uniform sampler2D surface3;\n"
3311 "layout (location = 0) out vec4 outColor;\n"
3312 "void main() {\n"
3313
3314 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3315 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3316
3317 " vec4 color = right;\n"
3318
3319 // Grab a normal texture sample to ensure it can work in conjuntion
3320 // with textureGather (there are some intracacies in the backend)
3321 " vec4 sampledColor = textureLod(surface2, vec2(0.5), 0.0);\n"
3322 " if (sampledColor != vec4(0.0, 0.0, 1.0, 1.0))\n"
3323 " color = wrong;\n"
3324
3325 " vec4 gatheredColor = textureGather(surface0, vec2(0.5), 0);\n"
3326 // This just grabbed four red components from a red surface
3327 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3328 " color = wrong;\n"
3329
3330 // Yes, this is using an offset of 0, we don't have enough fine grained
3331 // control of the texture contents here.
3332 " gatheredColor = textureGatherOffset(surface1, vec2(0.5), ivec2(0, 0), 1);\n"
3333 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3334 " color = wrong;\n"
3335
3336 " outColor = color;\n"
3337
3338 "}\n";
3339
3340 ASSERT_NO_FATAL_FAILURE(InitState());
3341 ASSERT_NO_FATAL_FAILURE(InitViewport());
3342
3343 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3344 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3345
3346 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
3347 VkSamplerObj sampler0(m_device);
3348 VkTextureObj texture0(m_device, tex_colors); // Red
3349 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
3350 VkSamplerObj sampler1(m_device);
3351 VkTextureObj texture1(m_device, tex_colors); // Green
3352 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
3353 VkSamplerObj sampler2(m_device);
3354 VkTextureObj texture2(m_device, tex_colors); // Blue
3355 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
3356 VkSamplerObj sampler3(m_device);
3357 VkTextureObj texture3(m_device, tex_colors); // Red and Blue
3358
3359 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003360 pipelineobj.AddColorAttachment();
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003361 pipelineobj.AddShader(&vs);
3362 pipelineobj.AddShader(&ps);
3363
3364 VkDescriptorSetObj descriptorSet(m_device);
3365 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3366 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
3367 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3368 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
3369
3370 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003371 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003372
Tony Barbour1490c912015-07-28 10:17:20 -06003373 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003374
3375 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06003376 Draw(0, 3, 0, 1);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003377
3378 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003379 EndCommandBuffer();
3380 QueueCommandBuffer();
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003381
3382 RecordImages(m_renderTargets);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003383}
3384
Cody Northropa44c2ff2015-04-15 11:19:06 -06003385TEST_F(VkRenderTest, GeometryShaderHelloWorld)
3386{
3387 // This test introduces a geometry shader that simply
3388 // changes the color of each vertex to red, green, blue
3389
3390 static const char *vertShaderText =
3391 "#version 140\n"
3392 "#extension GL_ARB_separate_shader_objects : enable\n"
3393 "#extension GL_ARB_shading_language_420pack : enable\n"
3394 "layout (location = 0) out vec4 color;"
3395 "void main() {\n"
3396
3397 // VS writes out red
3398 " color = vec4(1.0, 0.0, 0.0, 1.0);\n"
3399
3400 // generic position stuff
3401 " vec2 vertices;\n"
3402 " int vertexSelector = gl_VertexID;\n"
3403 " if (vertexSelector == 0)\n"
3404 " vertices = vec2(-0.5, -0.5);\n"
3405 " else if (vertexSelector == 1)\n"
3406 " vertices = vec2( 0.5, -0.5);\n"
3407 " else if (vertexSelector == 2)\n"
3408 " vertices = vec2( 0.5, 0.5);\n"
3409 " else\n"
3410 " vertices = vec2( 0.0, 0.0);\n"
3411 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3412
3413 "}\n";
3414
3415 static const char *geomShaderText =
3416 "#version 330\n"
3417 "#extension GL_ARB_separate_shader_objects : enable\n"
3418 "#extension GL_ARB_shading_language_420pack : enable\n"
3419 "layout( triangles ) in;\n"
3420 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3421 "layout( location = 0 ) in vec4 inColor[3];\n"
3422 "layout( location = 0 ) out vec4 outColor;\n"
3423 "void main()\n"
3424 "{\n"
3425
3426 // first vertex, pass through red
3427 " gl_Position = gl_in[0].gl_Position;\n"
3428 " outColor = inColor[0];\n"
3429 " EmitVertex();\n"
3430
3431 // second vertex, green
3432 " gl_Position = gl_in[1].gl_Position;\n"
3433 " outColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3434 " EmitVertex();\n"
3435
3436 // third vertex, blue
3437 " gl_Position = gl_in[2].gl_Position;\n"
3438 " outColor = vec4(0.0, 0.0, 1.0, 1.0);\n"
3439 " EmitVertex();\n"
3440
3441 // done
3442 " EndPrimitive();\n"
3443 "}\n";
3444
3445
3446 static const char *fragShaderText =
3447 "#version 140\n"
3448 "#extension GL_ARB_separate_shader_objects : enable\n"
3449 "#extension GL_ARB_shading_language_420pack : enable\n"
3450 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003451 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003452 "void main() {\n"
3453 // pass through
GregFd6ebdb32015-06-03 18:40:50 -06003454 " outColor = color;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003455 "}\n";
3456
3457
3458
3459 ASSERT_NO_FATAL_FAILURE(InitState());
3460 ASSERT_NO_FATAL_FAILURE(InitViewport());
3461
3462 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3463 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3464 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3465
3466 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003467 pipelineobj.AddColorAttachment();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003468 pipelineobj.AddShader(&vs);
3469 pipelineobj.AddShader(&gs);
3470 pipelineobj.AddShader(&ps);
3471
3472 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003473 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropa44c2ff2015-04-15 11:19:06 -06003474
3475 VkDescriptorSetObj descriptorSet(m_device);
3476
Tony Barbour1490c912015-07-28 10:17:20 -06003477 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003478
3479 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06003480 Draw(0, 3, 0, 1);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003481
3482 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003483 EndCommandBuffer();
3484 QueueCommandBuffer();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003485
3486 RecordImages(m_renderTargets);
3487}
3488
3489TEST_F(VkRenderTest, GSUniformBufferLayout)
3490{
3491 // This test is just like TriangleUniformBufferLayout but adds
3492 // geometry as a stage that also does UBO lookups
3493 // The expected result from this test is a green triangle
3494
3495 static const char *vertShaderText =
3496 "#version 140\n"
3497 "#extension GL_ARB_separate_shader_objects : enable\n"
3498 "#extension GL_ARB_shading_language_420pack : enable\n"
3499 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3500 " vec4 fRed;\n"
3501 " vec4 fGreen;\n"
3502 " layout(row_major) mat4 worldToProj;\n"
3503 " layout(row_major) mat4 projToWorld;\n"
3504 " layout(row_major) mat4 worldToView;\n"
3505 " layout(row_major) mat4 viewToProj;\n"
3506 " layout(row_major) mat4 worldToShadow[4];\n"
3507 " float fZero;\n"
3508 " float fOne;\n"
3509 " float fTwo;\n"
3510 " float fThree;\n"
3511 " vec3 fZeroZeroZero;\n"
3512 " float fFour;\n"
3513 " vec3 fZeroZeroOne;\n"
3514 " float fFive;\n"
3515 " vec3 fZeroOneZero;\n"
3516 " float fSix;\n"
3517 " float fSeven;\n"
3518 " float fEight;\n"
3519 " float fNine;\n"
3520 " vec2 fZeroZero;\n"
3521 " vec2 fZeroOne;\n"
3522 " vec4 fBlue;\n"
3523 " vec2 fOneZero;\n"
3524 " vec2 fOneOne;\n"
3525 " vec3 fZeroOneOne;\n"
3526 " float fTen;\n"
3527 " float fEleven;\n"
3528 " float fTwelve;\n"
3529 " vec3 fOneZeroZero;\n"
3530 " vec4 uvOffsets[4];\n"
3531 "};\n"
3532 "layout (location = 0) out vec4 color;"
3533 "void main() {\n"
3534
3535 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3536 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3537 " \n"
3538
3539 // do some exact comparisons, even though we should
3540 // really have an epsilon involved.
3541 " vec4 outColor = right;\n"
3542 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3543 " outColor = wrong;\n"
3544 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3545 " outColor = wrong;\n"
3546 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3547 " outColor = wrong;\n"
3548
3549 " color = outColor;\n"
3550
3551 // generic position stuff
3552 " vec2 vertices;\n"
3553 " int vertexSelector = gl_VertexID;\n"
3554 " if (vertexSelector == 0)\n"
3555 " vertices = vec2(-0.5, -0.5);\n"
3556 " else if (vertexSelector == 1)\n"
3557 " vertices = vec2( 0.5, -0.5);\n"
3558 " else if (vertexSelector == 2)\n"
3559 " vertices = vec2( 0.5, 0.5);\n"
3560 " else\n"
3561 " vertices = vec2( 0.0, 0.0);\n"
3562 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3563 "}\n";
3564
3565 static const char *geomShaderText =
3566 "#version 330\n"
3567 "#extension GL_ARB_separate_shader_objects : enable\n"
3568 "#extension GL_ARB_shading_language_420pack : enable\n"
3569
3570 // GS layout stuff
3571 "layout( triangles ) in;\n"
3572 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3573
3574 // Between stage IO
3575 "layout( location = 0 ) in vec4 inColor[3];\n"
3576 "layout( location = 0 ) out vec4 color;\n"
3577
3578 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3579 " vec4 fRed;\n"
3580 " vec4 fGreen;\n"
3581 " layout(row_major) mat4 worldToProj;\n"
3582 " layout(row_major) mat4 projToWorld;\n"
3583 " layout(row_major) mat4 worldToView;\n"
3584 " layout(row_major) mat4 viewToProj;\n"
3585 " layout(row_major) mat4 worldToShadow[4];\n"
3586 " float fZero;\n"
3587 " float fOne;\n"
3588 " float fTwo;\n"
3589 " float fThree;\n"
3590 " vec3 fZeroZeroZero;\n"
3591 " float fFour;\n"
3592 " vec3 fZeroZeroOne;\n"
3593 " float fFive;\n"
3594 " vec3 fZeroOneZero;\n"
3595 " float fSix;\n"
3596 " float fSeven;\n"
3597 " float fEight;\n"
3598 " float fNine;\n"
3599 " vec2 fZeroZero;\n"
3600 " vec2 fZeroOne;\n"
3601 " vec4 fBlue;\n"
3602 " vec2 fOneZero;\n"
3603 " vec2 fOneOne;\n"
3604 " vec3 fZeroOneOne;\n"
3605 " float fTen;\n"
3606 " float fEleven;\n"
3607 " float fTwelve;\n"
3608 " vec3 fOneZeroZero;\n"
3609 " vec4 uvOffsets[4];\n"
3610 "};\n"
3611
3612 "void main()\n"
3613 "{\n"
3614
3615 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3616 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3617
3618 // Each vertex will validate it can read VS output
3619 // then check a few values from the UBO
3620
3621 // first vertex
3622 " vec4 outColor = inColor[0];\n"
3623
3624 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3625 " outColor = wrong;\n"
3626 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3627 " outColor = wrong;\n"
3628 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3629 " outColor = wrong;\n"
3630 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3631 " outColor = wrong;\n"
3632
3633 " gl_Position = gl_in[0].gl_Position;\n"
3634 " color = outColor;\n"
3635 " EmitVertex();\n"
3636
3637 // second vertex
3638 " outColor = inColor[1];\n"
3639
3640 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3641 " outColor = wrong;\n"
3642 " if (fSix != 6.0)\n"
3643 " outColor = wrong;\n"
3644 " if (fOneOne != vec2(1.0, 1.0))\n"
3645 " outColor = wrong;\n"
3646
3647 " gl_Position = gl_in[1].gl_Position;\n"
3648 " color = outColor;\n"
3649 " EmitVertex();\n"
3650
3651 // third vertex
3652 " outColor = inColor[2];\n"
3653
3654 " if (fSeven != 7.0)\n"
3655 " outColor = wrong;\n"
3656 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3657 " outColor = wrong;\n"
3658
3659 " gl_Position = gl_in[2].gl_Position;\n"
3660 " color = outColor;\n"
3661 " EmitVertex();\n"
3662
3663 // done
3664 " EndPrimitive();\n"
3665 "}\n";
3666
3667 static const char *fragShaderText =
3668 "#version 140\n"
3669 "#extension GL_ARB_separate_shader_objects : enable\n"
3670 "#extension GL_ARB_shading_language_420pack : enable\n"
3671 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3672 " vec4 fRed;\n"
3673 " vec4 fGreen;\n"
3674 " layout(row_major) mat4 worldToProj;\n"
3675 " layout(row_major) mat4 projToWorld;\n"
3676 " layout(row_major) mat4 worldToView;\n"
3677 " layout(row_major) mat4 viewToProj;\n"
3678 " layout(row_major) mat4 worldToShadow[4];\n"
3679 " float fZero;\n"
3680 " float fOne;\n"
3681 " float fTwo;\n"
3682 " float fThree;\n"
3683 " vec3 fZeroZeroZero;\n"
3684 " float fFour;\n"
3685 " vec3 fZeroZeroOne;\n"
3686 " float fFive;\n"
3687 " vec3 fZeroOneZero;\n"
3688 " float fSix;\n"
3689 " float fSeven;\n"
3690 " float fEight;\n"
3691 " float fNine;\n"
3692 " vec2 fZeroZero;\n"
3693 " vec2 fZeroOne;\n"
3694 " vec4 fBlue;\n"
3695 " vec2 fOneZero;\n"
3696 " vec2 fOneOne;\n"
3697 " vec3 fZeroOneOne;\n"
3698 " float fTen;\n"
3699 " float fEleven;\n"
3700 " float fTwelve;\n"
3701 " vec3 fOneZeroZero;\n"
3702 " vec4 uvOffsets[4];\n"
3703 "};\n"
3704 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003705 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003706 "void main() {\n"
3707 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3708 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3709 " \n"
3710
3711 // start with GS value to ensure it passed
3712 " vec4 outColor = color;\n"
3713
3714 // do some exact comparisons, even though we should
3715 // really have an epsilon involved.
3716 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3717 " outColor = wrong;\n"
3718 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3719 " outColor = wrong;\n"
3720 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3721 " outColor = wrong;\n"
3722 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3723 " outColor = wrong;\n"
3724 " if (fTwo != 2.0)\n"
3725 " outColor = wrong;\n"
3726 " if (fOneOne != vec2(1.0, 1.0))\n"
3727 " outColor = wrong;\n"
3728 " if (fTen != 10.0)\n"
3729 " outColor = wrong;\n"
3730 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3731 " outColor = wrong;\n"
3732 " \n"
GregFd6ebdb32015-06-03 18:40:50 -06003733 " uFragColor = outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003734 "}\n";
3735
3736
Cody Northrop1684adb2015-08-05 11:15:02 -06003737 const float mixedVals[196] = { 1.0f, 0.0f, 0.0f, 1.0f, // vec4 fRed; // align
3738 0.0f, 1.0f, 0.0f, 1.0f, // vec4 fGreen; // align
3739 1.0f, 0.0f, 0.0f, 1.0f, // layout(row_major) mat4 worldToProj;
3740 0.0f, 1.0f, 0.0f, 1.0f, // align
3741 0.0f, 0.0f, 1.0f, 1.0f, // align
3742 0.0f, 0.0f, 0.0f, 1.0f, // align
3743 2.0f, 0.0f, 0.0f, 2.0f, // layout(row_major) mat4 projToWorld;
3744 0.0f, 2.0f, 0.0f, 2.0f, // align
3745 0.0f, 0.0f, 2.0f, 2.0f, // align
3746 0.0f, 0.0f, 0.0f, 2.0f, // align
3747 3.0f, 0.0f, 0.0f, 3.0f, // layout(row_major) mat4 worldToView;
3748 0.0f, 3.0f, 0.0f, 3.0f, // align
3749 0.0f, 0.0f, 3.0f, 3.0f, // align
3750 0.0f, 0.0f, 0.0f, 3.0f, // align
3751 4.0f, 0.0f, 0.0f, 4.0f, // layout(row_major) mat4 viewToProj;
3752 0.0f, 4.0f, 0.0f, 4.0f, // align
3753 0.0f, 0.0f, 4.0f, 4.0f, // align
3754 0.0f, 0.0f, 0.0f, 4.0f, // align
3755 5.0f, 0.0f, 0.0f, 5.0f, // layout(row_major) mat4 worldToShadow[4];
3756 0.0f, 5.0f, 0.0f, 5.0f, // align
3757 0.0f, 0.0f, 5.0f, 5.0f, // align
3758 0.0f, 0.0f, 0.0f, 5.0f, // align
3759 6.0f, 0.0f, 0.0f, 6.0f, // align
3760 0.0f, 6.0f, 0.0f, 6.0f, // align
3761 0.0f, 0.0f, 6.0f, 6.0f, // align
3762 0.0f, 0.0f, 0.0f, 6.0f, // align
3763 7.0f, 0.0f, 0.0f, 7.0f, // align
3764 0.0f, 7.0f, 0.0f, 7.0f, // align
3765 0.0f, 0.0f, 7.0f, 7.0f, // align
3766 0.0f, 0.0f, 0.0f, 7.0f, // align
3767 8.0f, 0.0f, 0.0f, 8.0f, // align
3768 0.0f, 8.0f, 0.0f, 8.0f, // align
3769 0.0f, 0.0f, 8.0f, 8.0f, // align
3770 0.0f, 0.0f, 0.0f, 8.0f, // align
3771 0.0f, // float fZero; // align
3772 1.0f, // float fOne; // pack
3773 2.0f, // float fTwo; // pack
3774 3.0f, // float fThree; // pack
3775 0.0f, 0.0f, 0.0f, // vec3 fZeroZeroZero; // align
3776 4.0f, // float fFour; // pack
3777 0.0f, 0.0f, 1.0f, // vec3 fZeroZeroOne; // align
3778 5.0f, // float fFive; // pack
3779 0.0f, 1.0f, 0.0f, // vec3 fZeroOneZero; // align
3780 6.0f, // float fSix; // pack
3781 7.0f, // float fSeven; // align
3782 8.0f, // float fEight; // pack
3783 9.0f, // float fNine; // pack
3784 0.0f, // BUFFER
3785 0.0f, 0.0f, // vec2 fZeroZero; // align
3786 0.0f, 1.0f, // vec2 fZeroOne; // pack
3787 0.0f, 0.0f, 1.0f, 1.0f, // vec4 fBlue; // align
3788 1.0f, 0.0f, // vec2 fOneZero; // align
3789 1.0f, 1.0f, // vec2 fOneOne; // pack
3790 0.0f, 1.0f, 1.0f, // vec3 fZeroOneOne; // align
3791 10.0f, // float fTen; // pack
3792 11.0f, // float fEleven; // align
3793 12.0f, // float fTwelve; // pack
3794 0.0f, 0.0f, // BUFFER
3795 1.0f, 0.0f, 0.0f, // vec3 fOneZeroZero; // align
3796 0.0f, // BUFFER
3797 0.1f, 0.2f, 0.3f, 0.4f, // vec4 uvOffsets[4];
3798 0.5f, 0.6f, 0.7f, 0.8f, // align
3799 0.9f, 1.0f, 1.1f, 1.2f, // align
3800 1.3f, 1.4f, 1.5f, 1.6f, // align
Cody Northropa44c2ff2015-04-15 11:19:06 -06003801 };
3802
3803
3804
3805 ASSERT_NO_FATAL_FAILURE(InitState());
3806 ASSERT_NO_FATAL_FAILURE(InitViewport());
3807
3808 const int constCount = sizeof(mixedVals) / sizeof(float);
3809
3810 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3811 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3812 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3813
3814 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
3815
3816 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003817 pipelineobj.AddColorAttachment();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003818 pipelineobj.AddShader(&vs);
3819 pipelineobj.AddShader(&gs);
3820 pipelineobj.AddShader(&ps);
3821
3822 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003823 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropa44c2ff2015-04-15 11:19:06 -06003824
3825 VkDescriptorSetObj descriptorSet(m_device);
3826 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
3827
Tony Barbour1490c912015-07-28 10:17:20 -06003828 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003829
3830 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06003831 Draw(0, 3, 0, 1);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003832
3833 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003834 EndCommandBuffer();
3835 QueueCommandBuffer();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003836
3837 RecordImages(m_renderTargets);
3838}
3839
3840TEST_F(VkRenderTest, GSPositions)
3841{
3842 // This test adds more inputs from the vertex shader and perturbs positions
3843 // Expected result is white triangle with weird positions
3844
3845 static const char *vertShaderText =
3846 "#version 140\n"
3847 "#extension GL_ARB_separate_shader_objects : enable\n"
3848 "#extension GL_ARB_shading_language_420pack : enable\n"
3849
3850 "layout(location = 0) out vec3 out_a;\n"
3851 "layout(location = 1) out vec3 out_b;\n"
3852 "layout(location = 2) out vec3 out_c;\n"
3853
3854 "void main() {\n"
3855
3856 // write a solid color to each
3857 " out_a = vec3(1.0, 0.0, 0.0);\n"
3858 " out_b = vec3(0.0, 1.0, 0.0);\n"
3859 " out_c = vec3(0.0, 0.0, 1.0);\n"
3860
3861 // generic position stuff
3862 " vec2 vertices;\n"
3863 " int vertexSelector = gl_VertexID;\n"
3864 " if (vertexSelector == 0)\n"
3865 " vertices = vec2(-0.5, -0.5);\n"
3866 " else if (vertexSelector == 1)\n"
3867 " vertices = vec2( 0.5, -0.5);\n"
3868 " else if (vertexSelector == 2)\n"
3869 " vertices = vec2( 0.5, 0.5);\n"
3870 " else\n"
3871 " vertices = vec2( 0.0, 0.0);\n"
3872 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3873
3874 "}\n";
3875
3876 static const char *geomShaderText =
3877 "#version 330\n"
3878 "#extension GL_ARB_separate_shader_objects : enable\n"
3879 "#extension GL_ARB_shading_language_420pack : enable\n"
3880 "layout( triangles ) in;\n"
3881 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3882
3883 "layout(location = 0) in vec3 in_a[3];\n"
3884 "layout(location = 1) in vec3 in_b[3];\n"
3885 "layout(location = 2) in vec3 in_c[3];\n"
3886
3887 "layout(location = 0) out vec3 out_a;\n"
3888 "layout(location = 1) out vec3 out_b;\n"
3889 "layout(location = 2) out vec3 out_c;\n"
3890
3891 "void main()\n"
3892 "{\n"
3893
3894 " gl_Position = gl_in[0].gl_Position;\n"
3895 " gl_Position.xy *= vec2(0.75);\n"
3896 " out_a = in_a[0];\n"
3897 " out_b = in_b[0];\n"
3898 " out_c = in_c[0];\n"
3899 " EmitVertex();\n"
3900
3901 " gl_Position = gl_in[1].gl_Position;\n"
3902 " gl_Position.xy *= vec2(1.5);\n"
3903 " out_a = in_a[1];\n"
3904 " out_b = in_b[1];\n"
3905 " out_c = in_c[1];\n"
3906 " EmitVertex();\n"
3907
3908 " gl_Position = gl_in[2].gl_Position;\n"
3909 " gl_Position.xy *= vec2(-0.1);\n"
3910 " out_a = in_a[2];\n"
3911 " out_b = in_b[2];\n"
3912 " out_c = in_c[2];\n"
3913 " EmitVertex();\n"
3914
3915 " EndPrimitive();\n"
3916 "}\n";
3917
3918
3919 static const char *fragShaderText =
3920 "#version 140\n"
3921 "#extension GL_ARB_separate_shader_objects : enable\n"
3922 "#extension GL_ARB_shading_language_420pack : enable\n"
3923
3924 "layout(location = 0) in vec3 in_a;\n"
3925 "layout(location = 1) in vec3 in_b;\n"
3926 "layout(location = 2) in vec3 in_c;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003927 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003928
3929 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06003930 " outColor = vec4(in_a.x, in_b.y, in_c.z, 1.0);\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003931 "}\n";
3932
3933
3934
3935 ASSERT_NO_FATAL_FAILURE(InitState());
3936 ASSERT_NO_FATAL_FAILURE(InitViewport());
3937
3938 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3939 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3940 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3941
3942 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003943 pipelineobj.AddColorAttachment();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003944 pipelineobj.AddShader(&vs);
3945 pipelineobj.AddShader(&gs);
3946 pipelineobj.AddShader(&ps);
3947
3948 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06003949 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropa44c2ff2015-04-15 11:19:06 -06003950
3951 VkDescriptorSetObj descriptorSet(m_device);
3952
Tony Barbour1490c912015-07-28 10:17:20 -06003953 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003954
3955 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06003956 Draw(0, 3, 0, 1);
Cody Northropa44c2ff2015-04-15 11:19:06 -06003957
3958 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06003959 EndCommandBuffer();
3960 QueueCommandBuffer();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003961
3962 RecordImages(m_renderTargets);
3963}
3964
3965TEST_F(VkRenderTest, GSTriStrip)
3966{
3967 // This test emits multiple multiple triangles using a GS
3968 // Correct result is an multicolor circle
3969
3970 static const char *vertShaderText =
3971 "#version 140\n"
3972 "#extension GL_ARB_separate_shader_objects : enable\n"
3973 "#extension GL_ARB_shading_language_420pack : enable\n"
3974
3975 "void main() {\n"
3976
3977 // generic position stuff
3978 " vec2 vertices;\n"
3979 " int vertexSelector = gl_VertexID;\n"
3980 " if (vertexSelector == 0)\n"
3981 " vertices = vec2(-0.5, -0.5);\n"
3982 " else if (vertexSelector == 1)\n"
3983 " vertices = vec2( 0.5, -0.5);\n"
3984 " else if (vertexSelector == 2)\n"
3985 " vertices = vec2( 0.5, 0.5);\n"
3986 " else\n"
3987 " vertices = vec2( 0.0, 0.0);\n"
3988 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3989
3990 "}\n";
3991
3992 static const char *geomShaderText =
3993 "#version 330\n"
3994 "#extension GL_ARB_separate_shader_objects : enable\n"
3995 "#extension GL_ARB_shading_language_420pack : enable\n"
3996 "layout( triangles ) in;\n"
3997 "layout( triangle_strip, max_vertices = 18 ) out;\n"
3998
3999 "layout(location = 0) out vec4 outColor;\n"
4000
4001 "void main()\n"
4002 "{\n"
4003 // init with first position to get zw
4004 " gl_Position = gl_in[0].gl_Position;\n"
4005
4006 " vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
4007 " vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
4008 " vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
4009 " vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
4010
4011 // different color per tri
4012 " vec4[6] colors = { red, white, \n"
4013 " yellow, white, \n"
4014 " blue, white }; \n"
4015
4016 // fan out the triangles
4017 " vec2[18] positions = { vec2(0.0, 0.0), vec2(-0.5, 0.0), vec2(-0.25, -0.5), \n"
4018 " vec2(0.0, 0.0), vec2(-0.25, -0.5), vec2( 0.25, -0.5), \n"
4019 " vec2(0.0, 0.0), vec2( 0.25, -0.5), vec2( 0.5, 0.0), \n"
4020 " vec2(0.0, 0.0), vec2( 0.5, 0.0), vec2( 0.25, 0.5), \n"
4021 " vec2(0.0, 0.0), vec2( 0.25, 0.5), vec2(-0.25, 0.5), \n"
4022 " vec2(0.0, 0.0), vec2(-0.25, 0.5), vec2(-0.5, 0.0) }; \n"
4023
4024 // make a triangle list of 6
4025 " for (int i = 0; i < 6; ++i) { \n"
4026 " outColor = colors[i]; \n"
4027 " for (int j = 0; j < 3; ++j) { \n"
4028 " gl_Position.xy = positions[i * 3 + j]; \n"
4029 " EmitVertex(); \n"
4030 " } \n"
4031 " EndPrimitive();\n"
4032 " } \n"
4033
4034 "}\n";
4035
4036
4037 static const char *fragShaderText =
4038 "#version 150\n"
4039 "#extension GL_ARB_separate_shader_objects : enable\n"
4040 "#extension GL_ARB_shading_language_420pack : enable\n"
4041
4042
4043 "layout(binding = 0) uniform windowDimensions {\n"
4044 " vec4 dimensions;\n"
4045 "};\n"
4046
4047 "layout(location = 0) in vec4 inColor;\n"
4048 "layout(origin_upper_left) in vec4 gl_FragCoord;\n"
GregFd6ebdb32015-06-03 18:40:50 -06004049 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06004050
4051 "void main() {\n"
4052
4053 // discard to make a nice circle
4054 " vec2 pos = abs(gl_FragCoord.xy) - vec2(dimensions.x, dimensions.y) / 2;\n"
4055 " float dist = sqrt(dot(pos, pos));\n"
4056 " if (dist > 50.0)\n"
4057 " discard;\n"
4058
GregFd6ebdb32015-06-03 18:40:50 -06004059 " outColor = inColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06004060
4061 "}\n";
4062
4063
4064
4065 ASSERT_NO_FATAL_FAILURE(InitState());
4066 ASSERT_NO_FATAL_FAILURE(InitViewport());
4067
4068 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
4069 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
4070 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
4071
4072 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004073 pipelineobj.AddColorAttachment();
Cody Northropa44c2ff2015-04-15 11:19:06 -06004074 pipelineobj.AddShader(&vs);
4075 pipelineobj.AddShader(&gs);
4076 pipelineobj.AddShader(&ps);
4077
4078 const float dimensions[4] = { VkRenderFramework::m_width, VkRenderFramework::m_height , 0.0, 0.0};
4079
4080 VkConstantBufferObj windowDimensions(m_device, sizeof(dimensions) / sizeof(dimensions[0]), sizeof(dimensions[0]), (const void*) dimensions);
4081
4082 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06004083 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Cody Northropa44c2ff2015-04-15 11:19:06 -06004084
4085 VkDescriptorSetObj descriptorSet(m_device);
4086 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, windowDimensions);
4087
Tony Barbour1490c912015-07-28 10:17:20 -06004088 GenericDrawPreparation(pipelineobj, descriptorSet);
Cody Northropa44c2ff2015-04-15 11:19:06 -06004089
4090 // render triangle
Tony Barbour1490c912015-07-28 10:17:20 -06004091 Draw(0, 3, 0, 1);
Cody Northropa44c2ff2015-04-15 11:19:06 -06004092
4093 // finalize recording of the command buffer
Tony Barbour1490c912015-07-28 10:17:20 -06004094 EndCommandBuffer();
4095 QueueCommandBuffer();
Cody Northropa44c2ff2015-04-15 11:19:06 -06004096
4097 RecordImages(m_renderTargets);
4098}
4099
Chris Forbes23e6db62015-06-15 09:32:35 +12004100TEST_F(VkRenderTest, RenderPassLoadOpClear)
4101{
4102 ASSERT_NO_FATAL_FAILURE(InitState());
4103 ASSERT_NO_FATAL_FAILURE(InitViewport());
4104
4105 /* clear via load op to full green */
4106 m_clear_via_load_op = true;
Cody Northrop2563a032015-08-25 15:26:38 -06004107 m_clear_color.float32[0] = 0;
4108 m_clear_color.float32[1] = 1;
4109 m_clear_color.float32[2] = 0;
4110 m_clear_color.float32[3] = 0;
Chris Forbes23e6db62015-06-15 09:32:35 +12004111 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06004112 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Chris Forbes23e6db62015-06-15 09:32:35 +12004113 /* This command buffer contains ONLY the load op! */
Tony Barbour1490c912015-07-28 10:17:20 -06004114 EndCommandBuffer();
4115 QueueCommandBuffer();
Chris Forbes23e6db62015-06-15 09:32:35 +12004116
4117 RecordImages(m_renderTargets);
4118}
4119
Chris Forbes1e16cb82015-06-24 12:05:30 +12004120TEST_F(VkRenderTest, RenderPassAttachmentClear)
4121{
4122 ASSERT_NO_FATAL_FAILURE(InitState());
4123 ASSERT_NO_FATAL_FAILURE(InitViewport());
4124
4125 /* clear via load op to full red */
4126 m_clear_via_load_op = true;
Cody Northrop2563a032015-08-25 15:26:38 -06004127 m_clear_color.float32[0] = 1;
4128 m_clear_color.float32[1] = 0;
4129 m_clear_color.float32[2] = 0;
4130 m_clear_color.float32[3] = 0;
Chris Forbes1e16cb82015-06-24 12:05:30 +12004131 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour1490c912015-07-28 10:17:20 -06004132 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Chris Forbes1e16cb82015-06-24 12:05:30 +12004133
4134 /* Load op has cleared to red */
4135
4136 /* Draw, draw, draw... */
4137
4138 /* Now, partway through this renderpass we want to clear the color
4139 * attachment again, this time to green.
4140 */
Chris Forbese3105972015-06-24 14:34:53 +12004141 VkClearColorValue clear_color;
Cody Northrop2563a032015-08-25 15:26:38 -06004142 clear_color.float32[0] = 0;
4143 clear_color.float32[1] = 1;
4144 clear_color.float32[2] = 0;
4145 clear_color.float32[3] = 0;
Chris Forbes1e16cb82015-06-24 12:05:30 +12004146 VkRect3D clear_rect = { { 0, 0, 0 }, { (int)m_width, (int)m_height, 1 } };
Tony Barbour1490c912015-07-28 10:17:20 -06004147 vkCmdClearColorAttachment(m_cmdBuffer->handle(), 0,
Chris Forbes1e16cb82015-06-24 12:05:30 +12004148 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4149 &clear_color, 1, &clear_rect);
4150
Tony Barbour1490c912015-07-28 10:17:20 -06004151 EndCommandBuffer();
4152 QueueCommandBuffer();
Chris Forbes1e16cb82015-06-24 12:05:30 +12004153
4154 RecordImages(m_renderTargets);
4155}
4156
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004157int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004158 int result;
4159
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004160 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06004161 VkTestFramework::InitArgs(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004162
Chia-I Wu7133fdc2014-12-15 23:57:34 +08004163 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06004164
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004165 result = RUN_ALL_TESTS();
4166
Tony Barbour01999182015-04-09 12:58:51 -06004167 VkTestFramework::Finish();
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004168 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004169}