blob: 49aeefc3e00ceced53cb697218c15b72b9a7a197 [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);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600271 void InitDepthStencil();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600272 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate);
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600273
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600274 VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer);
275 VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer);
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600276
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600277protected:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600278 VkImage m_texture;
279 VkImageView m_textureView;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800280 VkDescriptorInfo m_descriptorInfo;
Tony Barbour8205d902015-04-16 15:59:00 -0600281 VkDeviceMemory m_textureMem;
Cody Northrop350727b2014-10-06 15:42:00 -0600282
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600283 VkSampler m_sampler;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600284
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600285
286 virtual void SetUp() {
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600287
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600288 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600289 this->app_info.pNext = NULL;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800290 this->app_info.pAppName = "render_tests";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600291 this->app_info.appVersion = 1;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800292 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600293 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600294 this->app_info.apiVersion = VK_API_VERSION;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600295
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800296 memset(&m_descriptorInfo, 0, sizeof(m_descriptorInfo));
Cody Northrop350727b2014-10-06 15:42:00 -0600297
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600298 InitFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600299 }
300
301 virtual void TearDown() {
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600302 // Clean up resources before we reset
303 ShutdownFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600304 }
305};
306
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600307VkResult VkRenderTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600308{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600309 VkResult result;
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600310
311 result = cmdBuffer.BeginCommandBuffer();
312
313 /*
314 * For render test all drawing happens in a single render pass
315 * on a single command buffer.
316 */
Chris Forbesfe133ef2015-06-16 14:05:59 +1200317 if (VK_SUCCESS == result && renderPass()) {
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600318 cmdBuffer.BeginRenderPass(renderPass(), framebuffer());
319 }
320
321 return result;
322}
323
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600324VkResult VkRenderTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600325{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600326 VkResult result;
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600327
Chris Forbesfe133ef2015-06-16 14:05:59 +1200328 if (renderPass()) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +0800329 cmdBuffer.EndRenderPass();
Chris Forbesfe133ef2015-06-16 14:05:59 +1200330 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600331
332 result = cmdBuffer.EndCommandBuffer();
333
334 return result;
335}
336
337
Tony Barbour01999182015-04-09 12:58:51 -0600338void VkRenderTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet)
Tony Barbour02472db2015-01-08 17:08:28 -0700339{
Tony Barbour17c6ab12015-03-27 17:03:18 -0600340 if (m_depthStencil->Initialized()) {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600341 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Tony Barbour17c6ab12015-03-27 17:03:18 -0600342 } else {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600343 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour17c6ab12015-03-27 17:03:18 -0600344 }
345
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700346 cmdBuffer->PrepareAttachments();
Tony Barbour8205d902015-04-16 15:59:00 -0600347 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_RASTER, m_stateRaster);
348 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_VIEWPORT, m_stateViewport);
349 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_COLOR_BLEND, m_colorBlend);
350 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_DEPTH_STENCIL, m_stateDepthStencil);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600351 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
352 pipelineobj.CreateVKPipeline(descriptorSet);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600353 cmdBuffer->BindPipeline(pipelineobj);
Chia-I Wu862c5572015-03-28 15:23:55 +0800354 cmdBuffer->BindDescriptorSet(descriptorSet);
Tony Barbour02472db2015-01-08 17:08:28 -0700355}
Tony Barbourf43b6982014-11-25 13:18:32 -0700356
Tony Barbour01999182015-04-09 12:58:51 -0600357void VkRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
358 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer)
Tony Barbourdd4c9642015-01-09 12:55:14 -0700359{
360 int i;
361 glm::mat4 MVP;
362 int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600363 VkResult err;
Tony Barbourdd4c9642015-01-09 12:55:14 -0700364
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600365 /* Only do 3 positions to avoid back face cull */
366 for (i = 0; i < 3; i++) {
Tony Barbourdd4c9642015-01-09 12:55:14 -0700367 void *pData = constantBuffer->map();
368
369 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
370 MVP = Projection * View * Model;
371 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
372
373 constantBuffer->unmap();
374
375 // submit the command buffer to the universal queue
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600376 cmdBuffer->QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700377
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600378 err = vkQueueWaitIdle( m_device->m_queue );
379 ASSERT_VK_SUCCESS( err );
Tony Barbourdd4c9642015-01-09 12:55:14 -0700380
381 // Wait for work to finish before cleaning up.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600382 vkDeviceWaitIdle(m_device->device());
Tony Barbourdd4c9642015-01-09 12:55:14 -0700383
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700384 assert(m_renderTargets.size() == 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -0700385 RecordImage(m_renderTargets[0]);
386 }
387}
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600388
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600389void dumpMatrix(const char *note, glm::mat4 MVP)
390{
Chia-I Wu7133fdc2014-12-15 23:57:34 +0800391 int i;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600392
393 printf("%s: \n", note);
394 for (i=0; i<4; i++) {
395 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
396 }
397 printf("\n");
398 fflush(stdout);
399}
400
401void dumpVec4(const char *note, glm::vec4 vector)
402{
403 printf("%s: \n", note);
404 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
405 printf("\n");
406 fflush(stdout);
407}
408
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600409struct vktriangle_vs_uniform {
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600410 // Must start with MVP
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600411 float mvp[4][4];
412 float position[3][4];
413 float color[3][4];
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600414};
415
Tony Barbour01999182015-04-09 12:58:51 -0600416void VkRenderTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600417{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700418#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600419 vkDbgRegisterMsgCallback(inst, myDbgFunc, NULL);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700420#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600421 // Create identity matrix
422 int i;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600423 struct vktriangle_vs_uniform data;
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600424
425 glm::mat4 Projection = glm::mat4(1.0f);
426 glm::mat4 View = glm::mat4(1.0f);
427 glm::mat4 Model = glm::mat4(1.0f);
428 glm::mat4 MVP = Projection * View * Model;
429 const int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600430 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600431 memcpy(&data.mvp, &MVP[0][0], matrixSize);
432
433 static const Vertex tri_data[] =
434 {
435 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
436 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
437 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
438 };
439
440 for (i=0; i<3; i++) {
441 data.position[i][0] = tri_data[i].posX;
442 data.position[i][1] = tri_data[i].posY;
443 data.position[i][2] = tri_data[i].posZ;
444 data.position[i][3] = tri_data[i].posW;
445 data.color[i][0] = tri_data[i].r;
446 data.color[i][1] = tri_data[i].g;
447 data.color[i][2] = tri_data[i].b;
448 data.color[i][3] = tri_data[i].a;
449 }
450
Tony Barbourf43b6982014-11-25 13:18:32 -0700451 ASSERT_NO_FATAL_FAILURE(InitState());
452 ASSERT_NO_FATAL_FAILURE(InitViewport());
453
Tony Barbour01999182015-04-09 12:58:51 -0600454 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barbourf43b6982014-11-25 13:18:32 -0700455
Tony Barbour01999182015-04-09 12:58:51 -0600456 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
457 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700458
Tony Barbour01999182015-04-09 12:58:51 -0600459 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -0700460 pipelineobj.AddShader(&vs);
461 pipelineobj.AddShader(&ps);
462
Tony Barbour01999182015-04-09 12:58:51 -0600463 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600464 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700465
Tony Barbour71ba3612015-01-09 16:12:35 -0700466 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600467 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour71ba3612015-01-09 16:12:35 -0700468 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700469
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600470 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour71ba3612015-01-09 16:12:35 -0700471
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600472 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour71ba3612015-01-09 16:12:35 -0700473#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600474 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour71ba3612015-01-09 16:12:35 -0700475 pDSDumpDot((char*)"triTest2.dot");
476#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600477
Tony Barbour71ba3612015-01-09 16:12:35 -0700478 // render triangle
479 cmdBuffer.Draw(0, 3, 0, 1);
480
481 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600482 EndCommandBuffer(cmdBuffer);
483
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600484 cmdBuffer.QueueCommandBuffer();
Tony Barbour71ba3612015-01-09 16:12:35 -0700485
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600486 RecordImages(m_renderTargets);
Tony Barbour71ba3612015-01-09 16:12:35 -0700487
488 if (rotate)
Tobin Ehlis12ee35f2015-03-26 08:23:25 -0600489 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
Tony Barbour71ba3612015-01-09 16:12:35 -0700490
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700491#ifdef PRINT_OBJECTS
Mark Lobodzinski4e5016f2015-05-05 15:01:37 -0500492 OBJ_TRACK_GET_OBJECTS_COUNT pObjTrackGetObjectsCount = (OBJ_TRACK_GET_OBJECTS_COUNT)vkGetProcAddr(gpu(), (char*)"objTrackGetObjectsCount");
Mark Lobodzinski14305ad2015-06-23 11:35:12 -0600493 uint64_t numObjects = pObjTrackGetObjectsCount(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600494 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700495 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600496 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700497 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
Mark Lobodzinski14305ad2015-06-23 11:35:12 -0600498 pObjTrackGetObjs(m_device, numObjects, pObjNodeArray);
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700499 for (i=0; i < numObjects; i++) {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600500 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 -0700501 }
502 free(pObjNodeArray);
503#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700504
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600505}
506
Tony Barbour01999182015-04-09 12:58:51 -0600507TEST_F(VkRenderTest, VKTriangle_FragColor)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600508{
509 static const char *vertShaderText =
510 "#version 140\n"
511 "#extension GL_ARB_separate_shader_objects : enable\n"
512 "#extension GL_ARB_shading_language_420pack : enable\n"
513 "\n"
514 "layout(binding = 0) uniform buf {\n"
515 " mat4 MVP;\n"
516 " vec4 position[3];\n"
517 " vec4 color[3];\n"
518 "} ubuf;\n"
519 "\n"
520 "layout (location = 0) out vec4 outColor;\n"
521 "\n"
522 "void main() \n"
523 "{\n"
524 " outColor = ubuf.color[gl_VertexID];\n"
525 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
526 "}\n";
527
528 static const char *fragShaderText =
529 "#version 140\n"
530 "#extension GL_ARB_separate_shader_objects : enable\n"
531 "#extension GL_ARB_shading_language_420pack : enable\n"
532 "\n"
533 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600534 "layout (location = 0) out vec4 uFragColor;\n"
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600535 "\n"
536 "void main()\n"
537 "{\n"
GregFd6ebdb32015-06-03 18:40:50 -0600538 " uFragColor = inColor;\n"
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600539 "}\n";
540
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600541 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
542 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600543}
544
Tony Barbour01999182015-04-09 12:58:51 -0600545TEST_F(VkRenderTest, VKTriangle_OutputLocation)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600546{
547 static const char *vertShaderText =
548 "#version 140\n"
549 "#extension GL_ARB_separate_shader_objects : enable\n"
550 "#extension GL_ARB_shading_language_420pack : enable\n"
551 "\n"
552 "layout(binding = 0) uniform buf {\n"
553 " mat4 MVP;\n"
554 " vec4 position[3];\n"
555 " vec4 color[3];\n"
556 "} ubuf;\n"
557 "\n"
558 "layout (location = 0) out vec4 outColor;\n"
559 "\n"
560 "void main() \n"
561 "{\n"
562 " outColor = ubuf.color[gl_VertexID];\n"
563 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
564 "}\n";
565
566 static const char *fragShaderText =
567 "#version 140\n"
568 "#extension GL_ARB_separate_shader_objects : enable\n"
569 "#extension GL_ARB_shading_language_420pack : enable\n"
570 "\n"
571 "layout (location = 0) in vec4 inColor;\n"
572 "layout (location = 0) out vec4 outColor;\n"
573 "\n"
574 "void main()\n"
575 "{\n"
576 " outColor = inColor;\n"
577 "}\n";
578
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600579 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 -0600580
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600581 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600582}
Cody Northrop71727d22015-06-23 13:25:51 -0600583
Tony Barbour01999182015-04-09 12:58:51 -0600584TEST_F(VkRenderTest, SPV_VKTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700585{
Tony Barbourf43b6982014-11-25 13:18:32 -0700586 static const char *vertShaderText =
587 "#version 140\n"
588 "#extension GL_ARB_separate_shader_objects : enable\n"
589 "#extension GL_ARB_shading_language_420pack : enable\n"
590 "\n"
591 "layout(binding = 0) uniform buf {\n"
592 " mat4 MVP;\n"
593 " vec4 position[3];\n"
594 " vec4 color[3];\n"
595 "} ubuf;\n"
596 "\n"
597 "layout (location = 0) out vec4 outColor;\n"
598 "\n"
599 "void main() \n"
600 "{\n"
601 " outColor = ubuf.color[gl_VertexID];\n"
602 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
603 "}\n";
604
605 static const char *fragShaderText =
606 "#version 140\n"
607 "#extension GL_ARB_separate_shader_objects : enable\n"
608 "#extension GL_ARB_shading_language_420pack : enable\n"
609 "\n"
610 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600611 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700612 "\n"
613 "void main()\n"
614 "{\n"
GregFd6ebdb32015-06-03 18:40:50 -0600615 " outColor = inColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700616 "}\n";
617
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600618 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 -0700619
Cody Northrop1cfbd172015-06-03 16:49:20 -0600620 ScopedUseGlsl useGlsl(false);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600621 VKTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700622}
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600623
Tony Barbour01999182015-04-09 12:58:51 -0600624TEST_F(VkRenderTest, SPV_GreenTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700625{
Tony Barbourf43b6982014-11-25 13:18:32 -0700626 static const char *vertShaderText =
627 "#version 130\n"
628 "vec2 vertices[3];\n"
629 "void main() {\n"
630 " vertices[0] = vec2(-1.0, -1.0);\n"
631 " vertices[1] = vec2( 1.0, -1.0);\n"
632 " vertices[2] = vec2( 0.0, 1.0);\n"
633 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
634 "}\n";
635
636 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600637 "#version 140\n"
638 "#extension GL_ARB_separate_shader_objects : enable\n"
639 "#extension GL_ARB_shading_language_420pack : enable\n"
640 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700641 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600642 " outColor = vec4(0,1,0,1);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700643 "}\n";
644
Cody Northropacfb0492015-03-17 15:55:58 -0600645 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700646
Cody Northrop1cfbd172015-06-03 16:49:20 -0600647 ScopedUseGlsl useGlsl(false);
648
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600649 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700650}
Cody Northrop71727d22015-06-23 13:25:51 -0600651
Tony Barbour01999182015-04-09 12:58:51 -0600652TEST_F(VkRenderTest, YellowTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700653{
654 static const char *vertShaderText =
655 "#version 130\n"
656 "void main() {\n"
657 " vec2 vertices[3];"
658 " vertices[0] = vec2(-0.5, -0.5);\n"
659 " vertices[1] = vec2( 0.5, -0.5);\n"
660 " vertices[2] = vec2( 0.5, 0.5);\n"
661 " vec4 colors[3];\n"
662 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
663 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
664 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
665 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
666 "}\n";
667
668 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600669 "#version 140\n"
670 "#extension GL_ARB_separate_shader_objects : enable\n"
671 "#extension GL_ARB_shading_language_420pack : enable\n"
672 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700673 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600674 " outColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700675 "}\n";
676
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600677 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700678}
679
Tony Barbour01999182015-04-09 12:58:51 -0600680TEST_F(VkRenderTest, QuadWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600681{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600682 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600683 "#version 140\n"
684 "#extension GL_ARB_separate_shader_objects : enable\n"
685 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700686 //XYZ1( -1, -1, -1 )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600687 "layout (location = 0) in vec4 pos;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700688 //XYZ1( 0.f, 0.f, 0.f )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600689 "layout (location = 1) in vec4 inColor;\n"
690 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600691 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600692 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600693 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600694 "}\n";
695
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600696
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600697 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700698 "#version 140\n"
699 "#extension GL_ARB_separate_shader_objects : enable\n"
700 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600701 "layout (location = 0) in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700702 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600703 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700704 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600705 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600706
Tony Barbourf43b6982014-11-25 13:18:32 -0700707
708
709 ASSERT_NO_FATAL_FAILURE(InitState());
710 ASSERT_NO_FATAL_FAILURE(InitViewport());
711
Tony Barbour01999182015-04-09 12:58:51 -0600712 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000713 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700714
Tony Barbour01999182015-04-09 12:58:51 -0600715 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
716 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700717
Tony Barbour01999182015-04-09 12:58:51 -0600718 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -0700719 pipelineobj.AddShader(&vs);
720 pipelineobj.AddShader(&ps);
721
Tony Barbour01999182015-04-09 12:58:51 -0600722 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600723 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -0600724
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600725#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600726 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600727 MESH_BIND_ID, // binding ID
Tony Barbourf43b6982014-11-25 13:18:32 -0700728 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600729 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -0700730 };
731
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600732 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600733 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
734 vi_attribs[0].location = 0; // location, position
Tony Barbour8205d902015-04-16 15:59:00 -0600735 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600736 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
737 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
738 vi_attribs[1].location = 1; // location, color
Tony Barbour8205d902015-04-16 15:59:00 -0600739 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600740 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 -0700741
742 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
743 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600744 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -0700745
Tony Barboure4ed9942015-01-09 10:06:53 -0700746 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600747 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700748 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700749
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600750 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600751
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600752 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700753
Tony Barboure4ed9942015-01-09 10:06:53 -0700754 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
755
756 // render two triangles
757 cmdBuffer.Draw(0, 6, 0, 1);
758
759 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600760 EndCommandBuffer(cmdBuffer);
761
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600762 cmdBuffer.QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -0700763
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600764 RecordImages(m_renderTargets);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600765}
766
Tony Barbour01999182015-04-09 12:58:51 -0600767TEST_F(VkRenderTest, TriangleMRT)
Chia-I Wue09d1a72014-12-05 10:32:23 +0800768{
769 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600770 "#version 140\n"
771 "#extension GL_ARB_separate_shader_objects : enable\n"
772 "#extension GL_ARB_shading_language_420pack : enable\n"
773 "layout (location = 0) in vec4 pos;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800774 "void main() {\n"
775 " gl_Position = pos;\n"
776 "}\n";
777
778 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600779 "#version 140\n"
780 "#extension GL_ARB_separate_shader_objects : enable\n"
781 "#extension GL_ARB_shading_language_420pack : enable\n"
782 "layout (location = 0) out vec4 uFragData0;\n"
783 "layout (location = 1) out vec4 uFragData1;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800784 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600785 " uFragData0 = vec4(1.0, 0.0, 0.0, 1.0);\n"
786 " uFragData1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800787 "}\n";
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600788 const float vb_data[][2] = {
Chia-I Wue09d1a72014-12-05 10:32:23 +0800789 { -1.0f, -1.0f },
790 { 1.0f, -1.0f },
791 { -1.0f, 1.0f }
792 };
793
794 ASSERT_NO_FATAL_FAILURE(InitState());
795 ASSERT_NO_FATAL_FAILURE(InitViewport());
796
Tony Barbour01999182015-04-09 12:58:51 -0600797 VkConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000798 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800799
Tony Barbour01999182015-04-09 12:58:51 -0600800 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
801 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800802
Tony Barbour01999182015-04-09 12:58:51 -0600803 VkPipelineObj pipelineobj(m_device);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800804 pipelineobj.AddShader(&vs);
805 pipelineobj.AddShader(&ps);
806
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600807#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600808 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600809 MESH_BUF_ID, // Binding ID
810 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600811 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Chia-I Wue09d1a72014-12-05 10:32:23 +0800812 };
813
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600814 VkVertexInputAttributeDescription vi_attrib;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600815 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
816 vi_attrib.location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -0600817 vi_attrib.format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600818 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
Chia-I Wue09d1a72014-12-05 10:32:23 +0800819
820 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
821 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600822 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800823
Tony Barbour01999182015-04-09 12:58:51 -0600824 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600825 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800826
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700827 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
Chia-I Wue09d1a72014-12-05 10:32:23 +0800828
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600829 VkPipelineCbAttachmentState att = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600830 att.blendEnable = VK_FALSE;
Chia-I Wue09d1a72014-12-05 10:32:23 +0800831 att.format = m_render_target_fmt;
832 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700833 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800834
Tony Barbour01999182015-04-09 12:58:51 -0600835 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700836
Tony Barbour5ed79702015-01-07 14:31:52 -0700837 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
838 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barboure4ed9942015-01-09 10:06:53 -0700839
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600840 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour5ed79702015-01-07 14:31:52 -0700841
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600842 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700843
Tony Barbour5ed79702015-01-07 14:31:52 -0700844 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700845#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600846 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour5ed79702015-01-07 14:31:52 -0700847 pDSDumpDot((char*)"triTest2.dot");
848#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600849
Tony Barbour5ed79702015-01-07 14:31:52 -0700850 // render triangle
851 cmdBuffer.Draw(0, 3, 0, 1);
852
853 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600854 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600855 cmdBuffer.QueueCommandBuffer();
Tony Barbour5ed79702015-01-07 14:31:52 -0700856
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600857 RecordImages(m_renderTargets);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800858}
859
Tony Barbour01999182015-04-09 12:58:51 -0600860TEST_F(VkRenderTest, QuadWithIndexedVertexFetch)
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700861{
862 static const char *vertShaderText =
863 "#version 140\n"
864 "#extension GL_ARB_separate_shader_objects : enable\n"
865 "#extension GL_ARB_shading_language_420pack : enable\n"
866 "layout(location = 0) in vec4 pos;\n"
867 "layout(location = 1) in vec4 inColor;\n"
868 "layout(location = 0) out vec4 outColor;\n"
869 "void main() {\n"
870 " outColor = inColor;\n"
871 " gl_Position = pos;\n"
872 "}\n";
873
874
875 static const char *fragShaderText =
876 "#version 140\n"
877 "#extension GL_ARB_separate_shader_objects : enable\n"
878 "#extension GL_ARB_shading_language_420pack : enable\n"
879 "layout(location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600880 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700881 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600882 " outColor = color;\n"
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700883 "}\n";
884
885 const Vertex g_vbData[] =
886 {
887 // first tri
888 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
889 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
890 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
891
892 // second tri
893 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
894 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
895 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
896 };
897
898 const uint16_t g_idxData[6] = {
899 0, 1, 2,
900 3, 4, 5,
901 };
902
903 ASSERT_NO_FATAL_FAILURE(InitState());
904 ASSERT_NO_FATAL_FAILURE(InitViewport());
905
Tony Barbour01999182015-04-09 12:58:51 -0600906 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000907 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700908
Tony Barbour01999182015-04-09 12:58:51 -0600909 VkIndexBufferObj indexBuffer(m_device);
Tony Barbour8205d902015-04-16 15:59:00 -0600910 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), VK_INDEX_TYPE_UINT16, g_idxData);
Mark Lobodzinskid30f82a2015-02-16 14:24:23 -0600911 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700912
Tony Barbour01999182015-04-09 12:58:51 -0600913 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
914 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700915
Tony Barbour01999182015-04-09 12:58:51 -0600916 VkPipelineObj pipelineobj(m_device);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700917 pipelineobj.AddShader(&vs);
918 pipelineobj.AddShader(&ps);
919
Tony Barbour01999182015-04-09 12:58:51 -0600920 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600921 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
922 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, indexBuffer);
Tony Barbour83a83802015-04-02 15:43:15 -0600923
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700924
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600925#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600926 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600927 MESH_BIND_ID, // binding ID
928 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600929 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700930 };
931
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600932 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600933 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
934 vi_attribs[0].location = 0; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600935 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600936 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
937 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
938 vi_attribs[1].location = 1; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600939 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600940 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700941
942 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
943 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700944
945 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600946 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700947 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600948 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barboure4ed9942015-01-09 10:06:53 -0700949
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600950 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700951
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700952#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600953 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700954 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700955#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700956
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600957 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600958 cmdBuffer.BindIndexBuffer(&indexBuffer, 0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700959
960 // render two triangles
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700961 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700962
963 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600964 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600965 cmdBuffer.QueueCommandBuffer();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700966
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600967 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700968}
969
Tony Barbour01999182015-04-09 12:58:51 -0600970TEST_F(VkRenderTest, GreyandRedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -0700971{
972 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -0700973
GregF6bef1212014-12-02 15:41:44 -0700974 static const char *vertShaderText =
975 "#version 140\n"
976 "#extension GL_ARB_separate_shader_objects : enable\n"
977 "#extension GL_ARB_shading_language_420pack : enable\n"
978 "layout (location = 0) in vec4 pos;\n"
979 "layout (location = 0) out vec4 outColor;\n"
980 "layout (location = 1) out vec4 outColor2;\n"
981 "void main() {\n"
982 " gl_Position = pos;\n"
983 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
984 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
985 "}\n";
986
987 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -0700988 "#version 330\n"
989 "#extension GL_ARB_separate_shader_objects : enable\n"
990 "#extension GL_ARB_shading_language_420pack : enable\n"
991 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
992 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
993 "layout (location = 0) in vec4 color;\n"
994 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600995 "layout (location = 0) out vec4 outColor;\n"
GregF6bef1212014-12-02 15:41:44 -0700996 "void main() {\n"
997 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
998 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -0600999 " outColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001000 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1001 " : color2;\n"
1002 "}\n";
1003
1004 ASSERT_NO_FATAL_FAILURE(InitState());
1005 ASSERT_NO_FATAL_FAILURE(InitViewport());
1006
Tony Barbour01999182015-04-09 12:58:51 -06001007 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001008 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001009
Tony Barbour01999182015-04-09 12:58:51 -06001010 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1011 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001012
Tony Barbour01999182015-04-09 12:58:51 -06001013 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001014 pipelineobj.AddShader(&vs);
1015 pipelineobj.AddShader(&ps);
1016
Tony Barbour01999182015-04-09 12:58:51 -06001017 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001018 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001019
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001020#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001021 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001022 MESH_BIND_ID, // binding ID
1023 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001024 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001025 };
1026
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001027 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001028 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1029 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001030 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001031 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001032
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001033 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001034 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001035 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001036
Tony Barbourdd4c9642015-01-09 12:55:14 -07001037 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001038 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001039 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1040
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001041 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001042
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001043 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001044
1045 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1046#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001047 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001048 pDSDumpDot((char*)"triTest2.dot");
1049#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001050
Tony Barbourdd4c9642015-01-09 12:55:14 -07001051 // render triangle
1052 cmdBuffer.Draw(0, 6, 0, 1);
1053
1054 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001055 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001056 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001057
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001058 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001059}
1060
Tony Barbour01999182015-04-09 12:58:51 -06001061TEST_F(VkRenderTest, RedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -07001062{
1063 // This tests that we correctly handle unread fragment inputs
1064
1065 static const char *vertShaderText =
1066 "#version 140\n"
1067 "#extension GL_ARB_separate_shader_objects : enable\n"
1068 "#extension GL_ARB_shading_language_420pack : enable\n"
1069 "layout (location = 0) in vec4 pos;\n"
1070 "layout (location = 0) out vec4 outColor;\n"
1071 "layout (location = 1) out vec4 outColor2;\n"
1072 "void main() {\n"
1073 " gl_Position = pos;\n"
1074 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1075 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1076 "}\n";
1077
1078 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001079 "#version 330\n"
1080 "#extension GL_ARB_separate_shader_objects : enable\n"
1081 "#extension GL_ARB_shading_language_420pack : enable\n"
1082 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1083 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1084 "layout (location = 0) in vec4 color;\n"
1085 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001086 "layout (location = 0) out vec4 outColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001087 "void main() {\n"
1088 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1089 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001090 " outColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001091 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1092 " : color2;\n"
1093 "}\n";
1094
1095 ASSERT_NO_FATAL_FAILURE(InitState());
1096 ASSERT_NO_FATAL_FAILURE(InitViewport());
1097
Tony Barbour01999182015-04-09 12:58:51 -06001098 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001099 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001100
Tony Barbour01999182015-04-09 12:58:51 -06001101 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1102 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001103
Tony Barbour01999182015-04-09 12:58:51 -06001104 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001105 pipelineobj.AddShader(&vs);
1106 pipelineobj.AddShader(&ps);
1107
Tony Barbour01999182015-04-09 12:58:51 -06001108 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001109 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001110
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001111#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001112 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001113 MESH_BIND_ID, // binding ID
1114 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001115 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001116 };
1117
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001118 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001119 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1120 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001121 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001122 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001123
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001124 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001125 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001126 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001127
Tony Barbourdd4c9642015-01-09 12:55:14 -07001128 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001129 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001130 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1131
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001132 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001133
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001134 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001135
1136 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1137#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001138 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001139 pDSDumpDot((char*)"triTest2.dot");
1140#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001141 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001142 cmdBuffer.Draw(0, 6, 0, 1);
1143
1144 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001145 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001146 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001147
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001148 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001149}
1150
Tony Barbour01999182015-04-09 12:58:51 -06001151TEST_F(VkRenderTest, GreyCirclesonBlueFade)
GregF6bef1212014-12-02 15:41:44 -07001152{
1153 // This tests reading gl_ClipDistance from FS
1154
1155 static const char *vertShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001156 //"#version 140\n"
GregF6bef1212014-12-02 15:41:44 -07001157 "#version 330\n"
1158 "#extension GL_ARB_separate_shader_objects : enable\n"
1159 "#extension GL_ARB_shading_language_420pack : enable\n"
1160 "out gl_PerVertex {\n"
1161 " vec4 gl_Position;\n"
1162 " float gl_ClipDistance[1];\n"
1163 "};\n"
1164 "layout (location = 0) in vec4 pos;\n"
1165 "layout (location = 0) out vec4 outColor;\n"
1166 "layout (location = 1) out vec4 outColor2;\n"
1167 "void main() {\n"
1168 " gl_Position = pos;\n"
1169 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1170 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1171 " float dists[3];\n"
1172 " dists[0] = 0.0;\n"
1173 " dists[1] = 1.0;\n"
1174 " dists[2] = 1.0;\n"
1175 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1176 "}\n";
1177
1178
1179 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001180 "#version 140\n"
1181 //"#version 330\n"
GregF6bef1212014-12-02 15:41:44 -07001182 "#extension GL_ARB_separate_shader_objects : enable\n"
1183 "#extension GL_ARB_shading_language_420pack : enable\n"
1184 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1185 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1186 "layout (location = 0) in vec4 color;\n"
1187 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001188 "layout (location = 0) out vec4 uFragColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001189 "void main() {\n"
1190 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1191 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001192 " uFragColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001193 " ? color * gl_ClipDistance[0]\n"
1194 " : color2;\n"
1195 "}\n";
1196
1197 ASSERT_NO_FATAL_FAILURE(InitState());
1198 ASSERT_NO_FATAL_FAILURE(InitViewport());
1199
Tony Barbour01999182015-04-09 12:58:51 -06001200 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001201 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001202
Tony Barbour01999182015-04-09 12:58:51 -06001203 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1204 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001205
Tony Barbour01999182015-04-09 12:58:51 -06001206 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001207 pipelineobj.AddShader(&vs);
1208 pipelineobj.AddShader(&ps);
1209
Tony Barbour01999182015-04-09 12:58:51 -06001210 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001211 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001212
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001213#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001214 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001215 MESH_BIND_ID, // binding ID
1216 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001217 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001218 };
1219
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001220 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001221 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1222 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001223 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001224 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001225
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001226 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001227 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001228 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001229
Tony Barbourdd4c9642015-01-09 12:55:14 -07001230 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001231 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001232 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF6bef1212014-12-02 15:41:44 -07001233
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001234 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001235
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001236 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001237
1238 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1239#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001240 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001241 pDSDumpDot((char*)"triTest2.dot");
1242#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001243
1244 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001245 cmdBuffer.Draw(0, 6, 0, 1);
1246
1247 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001248 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001249 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001250
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001251 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001252}
Tony Barbourf43b6982014-11-25 13:18:32 -07001253
Tony Barbour01999182015-04-09 12:58:51 -06001254TEST_F(VkRenderTest, GreyCirclesonBlueDiscard)
GregF7a23c792014-12-02 17:19:34 -07001255{
1256 static const char *vertShaderText =
1257 "#version 140\n"
1258 "#extension GL_ARB_separate_shader_objects : enable\n"
1259 "#extension GL_ARB_shading_language_420pack : enable\n"
1260 "layout (location = 0) in vec4 pos;\n"
1261 "layout (location = 0) out vec4 outColor;\n"
1262 "layout (location = 1) out vec4 outColor2;\n"
1263 "void main() {\n"
1264 " gl_Position = pos;\n"
1265 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1266 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1267 "}\n";
1268
1269
1270 static const char *fragShaderText =
GregF7a23c792014-12-02 17:19:34 -07001271 "#version 330\n"
1272 "#extension GL_ARB_separate_shader_objects : enable\n"
1273 "#extension GL_ARB_shading_language_420pack : enable\n"
1274 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1275 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1276 "layout (location = 0) in vec4 color;\n"
1277 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001278 "layout (location = 0) out vec4 outColor;\n"
GregF7a23c792014-12-02 17:19:34 -07001279 "void main() {\n"
1280 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1281 " float dist_squared = dot(pos, pos);\n"
1282 " if (dist_squared < 100.0)\n"
1283 " discard;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001284 " outColor = (dist_squared < 400.0)\n"
GregF7a23c792014-12-02 17:19:34 -07001285 " ? color\n"
1286 " : color2;\n"
1287 "}\n";
1288
1289 ASSERT_NO_FATAL_FAILURE(InitState());
1290 ASSERT_NO_FATAL_FAILURE(InitViewport());
1291
Tony Barbour01999182015-04-09 12:58:51 -06001292 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001293 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001294
Tony Barbour01999182015-04-09 12:58:51 -06001295 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1296 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF7a23c792014-12-02 17:19:34 -07001297
Tony Barbour01999182015-04-09 12:58:51 -06001298 VkPipelineObj pipelineobj(m_device);
GregF7a23c792014-12-02 17:19:34 -07001299 pipelineobj.AddShader(&vs);
1300 pipelineobj.AddShader(&ps);
1301
Tony Barbour01999182015-04-09 12:58:51 -06001302 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001303 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001304
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001305#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001306 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001307 MESH_BIND_ID, // binding ID
1308 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001309 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF7a23c792014-12-02 17:19:34 -07001310 };
1311
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001312 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001313 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1314 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001315 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001316 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF7a23c792014-12-02 17:19:34 -07001317
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001318 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF7a23c792014-12-02 17:19:34 -07001319 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001320 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF7a23c792014-12-02 17:19:34 -07001321
Tony Barbourdd4c9642015-01-09 12:55:14 -07001322 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001323 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001324 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1325
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001326 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001327
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001328 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001329
1330 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1331#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001332 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001333 pDSDumpDot((char*)"triTest2.dot");
1334#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001335
1336 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001337 cmdBuffer.Draw(0, 6, 0, 1);
1338
1339 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001340 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001341 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001342
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001343 RecordImages(m_renderTargets);
GregF7a23c792014-12-02 17:19:34 -07001344}
1345
1346
Tony Barbour01999182015-04-09 12:58:51 -06001347TEST_F(VkRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001348{
1349 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001350 "#version 140\n"
1351 "#extension GL_ARB_separate_shader_objects : enable\n"
1352 "#extension GL_ARB_shading_language_420pack : enable\n"
1353 "\n"
1354 "layout(binding = 0) uniform buf {\n"
1355 " mat4 MVP;\n"
1356 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001357 "void main() {\n"
1358 " vec2 vertices[3];"
1359 " vertices[0] = vec2(-0.5, -0.5);\n"
1360 " vertices[1] = vec2( 0.5, -0.5);\n"
1361 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001362 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001363 "}\n";
1364
1365 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001366 "#version 140\n"
1367 "#extension GL_ARB_separate_shader_objects : enable\n"
1368 "#extension GL_ARB_shading_language_420pack : enable\n"
1369 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001370 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001371 " outColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001372 "}\n";
1373
Tony Barbourf43b6982014-11-25 13:18:32 -07001374 ASSERT_NO_FATAL_FAILURE(InitState());
1375 ASSERT_NO_FATAL_FAILURE(InitViewport());
1376
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001377 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001378 glm::mat4 Projection = glm::mat4(1.0f);
1379 glm::mat4 View = glm::mat4(1.0f);
1380 glm::mat4 Model = glm::mat4(1.0f);
1381 glm::mat4 MVP = Projection * View * Model;
1382 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1383
Tony Barbour01999182015-04-09 12:58:51 -06001384 VkConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1385 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1386 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001387
Tony Barbour01999182015-04-09 12:58:51 -06001388 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001389 pipelineobj.AddShader(&vs);
1390 pipelineobj.AddShader(&ps);
1391
1392 // Create descriptor set and attach the constant buffer to it
Tony Barbour01999182015-04-09 12:58:51 -06001393 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001394 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001395
Tony Barbourdd4c9642015-01-09 12:55:14 -07001396 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001397 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001398 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001399
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001400 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001401
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001402 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001403
1404 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1405#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001406 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001407 pDSDumpDot((char*)"triTest2.dot");
1408#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001409
1410 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001411 cmdBuffer.Draw(0, 6, 0, 1);
1412
1413 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001414 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001415 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001416
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001417 RecordImages(m_renderTargets);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001418
1419 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001420}
1421
Tony Barbour01999182015-04-09 12:58:51 -06001422TEST_F(VkRenderTest, MixTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07001423{
1424 // This tests location applied to varyings. Notice that we have switched foo
1425 // and bar in the FS. The triangle should be blended with red, green and blue
1426 // corners.
1427 static const char *vertShaderText =
1428 "#version 140\n"
1429 "#extension GL_ARB_separate_shader_objects : enable\n"
1430 "#extension GL_ARB_shading_language_420pack : enable\n"
1431 "layout (location=0) out vec4 bar;\n"
1432 "layout (location=1) out vec4 foo;\n"
1433 "layout (location=2) out float scale;\n"
1434 "vec2 vertices[3];\n"
1435 "void main() {\n"
1436 " vertices[0] = vec2(-1.0, -1.0);\n"
1437 " vertices[1] = vec2( 1.0, -1.0);\n"
1438 " vertices[2] = vec2( 0.0, 1.0);\n"
1439 "vec4 colors[3];\n"
1440 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1441 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1442 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1443 " foo = colors[gl_VertexID % 3];\n"
1444 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1445 " scale = 1.0;\n"
1446 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1447 "}\n";
1448
1449 static const char *fragShaderText =
1450 "#version 140\n"
1451 "#extension GL_ARB_separate_shader_objects : enable\n"
1452 "#extension GL_ARB_shading_language_420pack : enable\n"
1453 "layout (location = 1) in vec4 bar;\n"
1454 "layout (location = 0) in vec4 foo;\n"
1455 "layout (location = 2) in float scale;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001456 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001457 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001458 " outColor = bar * scale + foo * (1.0-scale);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001459 "}\n";
1460
1461 ASSERT_NO_FATAL_FAILURE(InitState());
1462 ASSERT_NO_FATAL_FAILURE(InitViewport());
1463
Tony Barbour01999182015-04-09 12:58:51 -06001464 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1465 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001466
Tony Barbour01999182015-04-09 12:58:51 -06001467 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001468 pipelineobj.AddShader(&vs);
1469 pipelineobj.AddShader(&ps);
1470
Tony Barbour01999182015-04-09 12:58:51 -06001471 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06001472 descriptorSet.AppendDummy();
Tony Barbourf43b6982014-11-25 13:18:32 -07001473
Tony Barbourdd4c9642015-01-09 12:55:14 -07001474 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001475 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001476 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1477
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001478 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001479
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001480 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001481
1482#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001483 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001484 pDSDumpDot((char*)"triTest2.dot");
1485#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001486
Tony Barbourdd4c9642015-01-09 12:55:14 -07001487 // render triangle
1488 cmdBuffer.Draw(0, 3, 0, 1);
1489
1490 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001491 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001492 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001493
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001494 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001495}
1496
Tony Barbour01999182015-04-09 12:58:51 -06001497TEST_F(VkRenderTest, QuadVertFetchAndVertID)
Tony Barbourf43b6982014-11-25 13:18:32 -07001498{
1499 // This tests that attributes work in the presence of gl_VertexID
1500
1501 static const char *vertShaderText =
1502 "#version 140\n"
1503 "#extension GL_ARB_separate_shader_objects : enable\n"
1504 "#extension GL_ARB_shading_language_420pack : enable\n"
1505 //XYZ1( -1, -1, -1 )
1506 "layout (location = 0) in vec4 pos;\n"
1507 //XYZ1( 0.f, 0.f, 0.f )
1508 "layout (location = 1) in vec4 inColor;\n"
1509 "layout (location = 0) out vec4 outColor;\n"
1510 "void main() {\n"
1511 " outColor = inColor;\n"
1512 " vec4 vertices[3];"
1513 " vertices[gl_VertexID % 3] = pos;\n"
1514 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1515 "}\n";
1516
1517
1518 static const char *fragShaderText =
1519 "#version 140\n"
1520 "#extension GL_ARB_separate_shader_objects : enable\n"
1521 "#extension GL_ARB_shading_language_420pack : enable\n"
1522 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001523 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001524 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001525 " outColor = color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001526 "}\n";
1527
1528 ASSERT_NO_FATAL_FAILURE(InitState());
1529 ASSERT_NO_FATAL_FAILURE(InitViewport());
1530
Tony Barbour01999182015-04-09 12:58:51 -06001531 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001532 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001533
Tony Barbour01999182015-04-09 12:58:51 -06001534 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1535 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001536
Tony Barbour01999182015-04-09 12:58:51 -06001537 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001538 pipelineobj.AddShader(&vs);
1539 pipelineobj.AddShader(&ps);
1540
Tony Barbour01999182015-04-09 12:58:51 -06001541 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001542 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001543
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001544#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001545 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001546 MESH_BUF_ID, // Binding ID
1547 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001548 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001549 };
1550
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001551 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001552 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1553 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001554 vi_attribs[0].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001555 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1556 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1557 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001558 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001559 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001560
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001561 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001562 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001563 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001564
Tony Barbourdd4c9642015-01-09 12:55:14 -07001565 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001566 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001567 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1568
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001569 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001570
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001571 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001572
1573 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1574#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001575 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001576 pDSDumpDot((char*)"triTest2.dot");
1577#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001578
1579 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001580 cmdBuffer.Draw(0, 6, 0, 1);
1581
1582 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001583 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001584 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001585
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001586 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001587}
1588
Tony Barbour01999182015-04-09 12:58:51 -06001589TEST_F(VkRenderTest, QuadSparseVertFetch)
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001590{
1591 // This tests that attributes work in the presence of gl_VertexID
1592
1593 static const char *vertShaderText =
1594 "#version 140\n"
1595 "#extension GL_ARB_separate_shader_objects : enable\n"
1596 "#extension GL_ARB_shading_language_420pack : enable\n"
1597 //XYZ1( -1, -1, -1 )
1598 "layout (location = 1) in vec4 pos;\n"
1599 "layout (location = 4) in vec4 inColor;\n"
1600 //XYZ1( 0.f, 0.f, 0.f )
1601 "layout (location = 0) out vec4 outColor;\n"
1602 "void main() {\n"
1603 " outColor = inColor;\n"
1604 " gl_Position = pos;\n"
1605 "}\n";
1606
1607
1608 static const char *fragShaderText =
1609 "#version 140\n"
1610 "#extension GL_ARB_separate_shader_objects : enable\n"
1611 "#extension GL_ARB_shading_language_420pack : enable\n"
1612 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001613 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001614 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001615 " outColor = color;\n"
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001616 "}\n";
1617
1618 ASSERT_NO_FATAL_FAILURE(InitState());
1619 ASSERT_NO_FATAL_FAILURE(InitViewport());
1620
1621 struct VDATA
1622 {
1623 float t1, t2, t3, t4; // filler data
1624 float posX, posY, posZ, posW; // Position data
1625 float r, g, b, a; // Color
1626 };
1627 const struct VDATA vData[] =
1628 {
1629 { XYZ1(0, 0, 0), XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
1630 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1631 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1632 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1633 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1634 { XYZ1(0, 0, 0), XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
1635 };
1636
Tony Barbour01999182015-04-09 12:58:51 -06001637 VkConstantBufferObj meshBuffer(m_device,sizeof(vData)/sizeof(vData[0]),sizeof(vData[0]), vData);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001638 meshBuffer.BufferMemoryBarrier();
1639
Tony Barbour01999182015-04-09 12:58:51 -06001640 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1641 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001642
Tony Barbour01999182015-04-09 12:58:51 -06001643 VkPipelineObj pipelineobj(m_device);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001644 pipelineobj.AddShader(&vs);
1645 pipelineobj.AddShader(&ps);
1646
Tony Barbour01999182015-04-09 12:58:51 -06001647 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001648 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001649
1650#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001651 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001652 MESH_BUF_ID, // Binding ID
1653 sizeof(vData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001654 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001655 };
1656
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001657 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001658 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1659 vi_attribs[0].location = 4;
Tony Barbour8205d902015-04-16 15:59:00 -06001660 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001661 vi_attribs[0].offsetInBytes = sizeof(float) * 4 * 2; // Offset of first element in bytes from base of vertex
1662 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1663 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001664 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001665 vi_attribs[1].offsetInBytes = sizeof(float) * 4 * 1; // Offset of first element in bytes from base of vertex
1666
1667 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
1668 pipelineobj.AddVertexInputBindings(&vi_binding, 1);
1669 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
1670
1671 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001672 VkCommandBufferObj cmdBuffer(m_device);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001673 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1674
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001675 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001676
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001677 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001678
1679 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BUF_ID);
1680#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001681 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001682 pDSDumpDot((char*)"triTest2.dot");
1683#endif
1684
1685 // render two triangles
1686 cmdBuffer.Draw(0, 6, 0, 1);
1687
1688 // finalize recording of the command buffer
1689 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001690 cmdBuffer.QueueCommandBuffer();
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001691
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001692 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001693}
1694
Tony Barbour01999182015-04-09 12:58:51 -06001695TEST_F(VkRenderTest, TriVertFetchDeadAttr)
Tony Barbourf43b6982014-11-25 13:18:32 -07001696{
1697 // This tests that attributes work in the presence of gl_VertexID
1698 // and a dead attribute in position 0. Draws a triangle with yellow,
1699 // red and green corners, starting at top and going clockwise.
1700
1701 static const char *vertShaderText =
1702 "#version 140\n"
1703 "#extension GL_ARB_separate_shader_objects : enable\n"
1704 "#extension GL_ARB_shading_language_420pack : enable\n"
1705 //XYZ1( -1, -1, -1 )
1706 "layout (location = 0) in vec4 pos;\n"
1707 //XYZ1( 0.f, 0.f, 0.f )
1708 "layout (location = 1) in vec4 inColor;\n"
1709 "layout (location = 0) out vec4 outColor;\n"
1710 "void main() {\n"
1711 " outColor = inColor;\n"
1712 " vec2 vertices[3];"
1713 " vertices[0] = vec2(-1.0, -1.0);\n"
1714 " vertices[1] = vec2( 1.0, -1.0);\n"
1715 " vertices[2] = vec2( 0.0, 1.0);\n"
1716 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1717 "}\n";
1718
1719
1720 static const char *fragShaderText =
1721 "#version 140\n"
1722 "#extension GL_ARB_separate_shader_objects : enable\n"
1723 "#extension GL_ARB_shading_language_420pack : enable\n"
1724 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001725 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001726 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001727 " outColor = color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001728 "}\n";
1729
1730 ASSERT_NO_FATAL_FAILURE(InitState());
1731 ASSERT_NO_FATAL_FAILURE(InitViewport());
1732
Tony Barbour01999182015-04-09 12:58:51 -06001733 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001734 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001735
Tony Barbour01999182015-04-09 12:58:51 -06001736 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1737 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001738
Tony Barbour01999182015-04-09 12:58:51 -06001739 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001740 pipelineobj.AddShader(&vs);
1741 pipelineobj.AddShader(&ps);
1742
Tony Barbour01999182015-04-09 12:58:51 -06001743 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001744 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001745
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001746#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001747 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001748 MESH_BUF_ID, // Binding ID
1749 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001750 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001751 };
1752
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001753 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001754 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1755 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001756 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001757 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1758 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1759 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001760 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001761 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001762
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001763 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001764 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001765 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001766
Tony Barbourdd4c9642015-01-09 12:55:14 -07001767 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001768 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001769 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001770
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001771 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001772
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001773 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001774
1775 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1776#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001777 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001778 pDSDumpDot((char*)"triTest2.dot");
1779#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001780
1781 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001782 cmdBuffer.Draw(0, 6, 0, 1);
1783
1784 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001785 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001786 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001787
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001788 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001789}
1790
Tony Barbour01999182015-04-09 12:58:51 -06001791TEST_F(VkRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001792{
1793 static const char *vertShaderText =
1794 "#version 140\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001795 "#extension GL_ARB_separate_shader_objects : enable\n"
1796 "#extension GL_ARB_shading_language_420pack : enable\n"
GregFd6ebdb32015-06-03 18:40:50 -06001797 "layout (std140, binding = 0) uniform bufferVals {\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001798 " mat4 mvp;\n"
1799 "} myBufferVals;\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001800 "layout (location = 0) in vec4 pos;\n"
1801 "layout (location = 1) in vec4 inColor;\n"
Cody Northrop74a2d2c2015-06-16 17:32:04 -06001802 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001803 "void main() {\n"
1804 " outColor = inColor;\n"
1805 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001806 " gl_Position.y = -gl_Position.y;\n"
1807 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001808 "}\n";
1809
1810 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001811 "#version 140\n"
1812 "#extension GL_ARB_separate_shader_objects : enable\n"
1813 "#extension GL_ARB_shading_language_420pack : enable\n"
1814 "layout (location = 0) in vec4 color;\n"
1815 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001816 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001817 " outColor = color;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001818 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001819 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001820
Tony Barbourf43b6982014-11-25 13:18:32 -07001821 glm::mat4 View = glm::lookAt(
1822 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1823 glm::vec3(0,0,0), // and looks at the origin
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001824 glm::vec3(0,-1,0) // Head is up (set to 0,-1,0 to look upside-down)
Tony Barbourf43b6982014-11-25 13:18:32 -07001825 );
1826
1827 glm::mat4 Model = glm::mat4(1.0f);
1828
1829 glm::mat4 MVP = Projection * View * Model;
1830
1831 ASSERT_NO_FATAL_FAILURE(InitState());
1832 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wu9e81ebb2015-07-09 10:16:34 +08001833 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Tony Barbour8bef8ee2015-05-22 09:44:58 -06001834 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07001835
Tony Barbour01999182015-04-09 12:58:51 -06001836 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 -07001837 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1838
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001839 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07001840
Tony Barbour01999182015-04-09 12:58:51 -06001841 VkConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1842 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1843 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001844
Tony Barbour01999182015-04-09 12:58:51 -06001845 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001846 pipelineobj.AddShader(&vs);
1847 pipelineobj.AddShader(&ps);
1848
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001849 VkPipelineDsStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001850 ds_state.depthTestEnable = VK_TRUE;
1851 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06001852 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001853 ds_state.depthBoundsEnable = VK_FALSE;
1854 ds_state.stencilTestEnable = VK_FALSE;
1855 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
1856 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
1857 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06001858 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
1859 ds_state.format = VK_FORMAT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001860 ds_state.front = ds_state.back;
1861 pipelineobj.SetDepthStencil(&ds_state);
1862
Tony Barbour01999182015-04-09 12:58:51 -06001863 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001864 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001865
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001866#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001867 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001868 MESH_BUF_ID, // Binding ID
1869 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001870 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001871 };
Tony Barbourf43b6982014-11-25 13:18:32 -07001872
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001873 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001874 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1875 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001876 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001877 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1878 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1879 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001880 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001881 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001882
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001883 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001884 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001885 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001886
Tony Barbour17c6ab12015-03-27 17:03:18 -06001887 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour17c6ab12015-03-27 17:03:18 -06001888
Tony Barbour01999182015-04-09 12:58:51 -06001889 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -07001890 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001891
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001892 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001893 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001894
Tony Barboure4ed9942015-01-09 10:06:53 -07001895 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1896#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001897 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barboure4ed9942015-01-09 10:06:53 -07001898 pDSDumpDot((char*)"triTest2.dot");
1899#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001900
1901 // render triangles
Tony Barboure4ed9942015-01-09 10:06:53 -07001902 cmdBuffer.Draw(0, 36, 0, 1);
1903
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001904
Tony Barboure4ed9942015-01-09 10:06:53 -07001905 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001906 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001907 cmdBuffer.QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -07001908
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001909 RecordImages(m_renderTargets);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001910}
1911
Tony Barbour01999182015-04-09 12:58:51 -06001912TEST_F(VkRenderTest, VSTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07001913{
1914 // The expected result from this test is a green and red triangle;
1915 // one red vertex on the left, two green vertices on the right.
1916 static const char *vertShaderText =
Cody Northrop74a2d2c2015-06-16 17:32:04 -06001917 "#version 140\n"
1918 "#extension GL_ARB_separate_shader_objects : enable\n"
1919 "#extension GL_ARB_shading_language_420pack : enable\n"
1920 "layout (location = 0) out vec4 texColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001921 "uniform sampler2D surface;\n"
1922 "void main() {\n"
1923 " vec2 vertices[3];"
1924 " vertices[0] = vec2(-0.5, -0.5);\n"
1925 " vertices[1] = vec2( 0.5, -0.5);\n"
1926 " vertices[2] = vec2( 0.5, 0.5);\n"
1927 " vec2 positions[3];"
1928 " positions[0] = vec2( 0.0, 0.0);\n"
1929 " positions[1] = vec2( 0.25, 0.1);\n"
1930 " positions[2] = vec2( 0.1, 0.25);\n"
1931 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1932 " texColor = textureLod(surface, samplePos, 0.0);\n"
1933 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1934 "}\n";
1935
1936 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001937 "#version 140\n"
1938 "#extension GL_ARB_separate_shader_objects : enable\n"
1939 "#extension GL_ARB_shading_language_420pack : enable\n"
1940 "layout (location = 0) in vec4 texColor;\n"
1941 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001942 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001943 " outColor = texColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001944 "}\n";
1945
1946 ASSERT_NO_FATAL_FAILURE(InitState());
1947 ASSERT_NO_FATAL_FAILURE(InitViewport());
1948
Tony Barbour01999182015-04-09 12:58:51 -06001949 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1950 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
1951 VkSamplerObj sampler(m_device);
1952 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001953
Tony Barbour01999182015-04-09 12:58:51 -06001954 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001955 pipelineobj.AddShader(&vs);
1956 pipelineobj.AddShader(&ps);
1957
Tony Barbour01999182015-04-09 12:58:51 -06001958 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001959 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001960
Tony Barbourdd4c9642015-01-09 12:55:14 -07001961 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001962 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001963 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001964
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001965 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001966
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001967 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001968
1969#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001970 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001971 pDSDumpDot((char*)"triTest2.dot");
1972#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001973
Tony Barbourdd4c9642015-01-09 12:55:14 -07001974 // render triangle
1975 cmdBuffer.Draw(0, 3, 0, 1);
1976
1977 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001978 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001979 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001980
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001981 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001982}
GregFd6ebdb32015-06-03 18:40:50 -06001983
1984
1985
Tony Barbour01999182015-04-09 12:58:51 -06001986TEST_F(VkRenderTest, TexturedTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07001987{
1988 // The expected result from this test is a red and green checkered triangle
1989 static const char *vertShaderText =
1990 "#version 140\n"
1991 "#extension GL_ARB_separate_shader_objects : enable\n"
1992 "#extension GL_ARB_shading_language_420pack : enable\n"
1993 "layout (location = 0) out vec2 samplePos;\n"
1994 "void main() {\n"
1995 " vec2 vertices[3];"
1996 " vertices[0] = vec2(-0.5, -0.5);\n"
1997 " vertices[1] = vec2( 0.5, -0.5);\n"
1998 " vertices[2] = vec2( 0.5, 0.5);\n"
1999 " vec2 positions[3];"
2000 " positions[0] = vec2( 0.0, 0.0);\n"
2001 " positions[1] = vec2( 1.0, 0.0);\n"
2002 " positions[2] = vec2( 1.0, 1.0);\n"
2003 " samplePos = positions[gl_VertexID % 3];\n"
2004 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2005 "}\n";
2006
2007 static const char *fragShaderText =
2008 "#version 140\n"
2009 "#extension GL_ARB_separate_shader_objects : enable\n"
2010 "#extension GL_ARB_shading_language_420pack : enable\n"
2011 "layout (location = 0) in vec2 samplePos;\n"
2012 "layout (binding = 0) uniform sampler2D surface;\n"
2013 "layout (location=0) out vec4 outColor;\n"
2014 "void main() {\n"
2015 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2016 " outColor = texColor;\n"
2017 "}\n";
2018
2019 ASSERT_NO_FATAL_FAILURE(InitState());
2020 ASSERT_NO_FATAL_FAILURE(InitViewport());
2021
Tony Barbour01999182015-04-09 12:58:51 -06002022 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2023 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2024 VkSamplerObj sampler(m_device);
2025 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002026
Tony Barbour01999182015-04-09 12:58:51 -06002027 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002028 pipelineobj.AddShader(&vs);
2029 pipelineobj.AddShader(&ps);
2030
Tony Barbour01999182015-04-09 12:58:51 -06002031 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002032 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002033
Tony Barbourdd4c9642015-01-09 12:55:14 -07002034 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002035 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002036 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2037
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002038 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002039
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002040 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002041
2042#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002043 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002044 pDSDumpDot((char*)"triTest2.dot");
2045#endif
2046 // render triangle
2047 cmdBuffer.Draw(0, 3, 0, 1);
2048
2049 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002050 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002051 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002052
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002053 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002054}
Tony Barbour01999182015-04-09 12:58:51 -06002055TEST_F(VkRenderTest, TexturedTriangleClip)
Tony Barbourf43b6982014-11-25 13:18:32 -07002056{
2057 // The expected result from this test is a red and green checkered triangle
2058 static const char *vertShaderText =
2059 "#version 330\n"
2060 "#extension GL_ARB_separate_shader_objects : enable\n"
2061 "#extension GL_ARB_shading_language_420pack : enable\n"
2062 "layout (location = 0) out vec2 samplePos;\n"
2063 "out gl_PerVertex {\n"
2064 " vec4 gl_Position;\n"
2065 " float gl_ClipDistance[1];\n"
2066 "};\n"
2067 "void main() {\n"
2068 " vec2 vertices[3];"
2069 " vertices[0] = vec2(-0.5, -0.5);\n"
2070 " vertices[1] = vec2( 0.5, -0.5);\n"
2071 " vertices[2] = vec2( 0.5, 0.5);\n"
2072 " vec2 positions[3];"
2073 " positions[0] = vec2( 0.0, 0.0);\n"
2074 " positions[1] = vec2( 1.0, 0.0);\n"
2075 " positions[2] = vec2( 1.0, 1.0);\n"
2076 " float dists[3];\n"
2077 " dists[0] = 1.0;\n"
2078 " dists[1] = 1.0;\n"
2079 " dists[2] = -1.0;\n"
2080 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2081 " samplePos = positions[gl_VertexID % 3];\n"
2082 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2083 "}\n";
2084
2085 static const char *fragShaderText =
2086 "#version 140\n"
2087 "#extension GL_ARB_separate_shader_objects : enable\n"
2088 "#extension GL_ARB_shading_language_420pack : enable\n"
2089 "layout (location = 0) in vec2 samplePos;\n"
2090 "layout (binding = 0) uniform sampler2D surface;\n"
2091 "layout (location=0) out vec4 outColor;\n"
2092 "void main() {\n"
2093 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2094 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2095 " outColor = texColor;\n"
2096 "}\n";
2097
2098
2099 ASSERT_NO_FATAL_FAILURE(InitState());
2100 ASSERT_NO_FATAL_FAILURE(InitViewport());
2101
Tony Barbour01999182015-04-09 12:58:51 -06002102 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2103 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2104 VkSamplerObj sampler(m_device);
2105 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002106
Tony Barbour01999182015-04-09 12:58:51 -06002107 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002108 pipelineobj.AddShader(&vs);
2109 pipelineobj.AddShader(&ps);
2110
Tony Barbour01999182015-04-09 12:58:51 -06002111 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002112 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002113
Tony Barbourdd4c9642015-01-09 12:55:14 -07002114 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002115 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002116 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2117
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002118 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002119
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002120 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002121
2122#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002123 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002124 pDSDumpDot((char*)"triTest2.dot");
2125#endif
2126 // render triangle
2127 cmdBuffer.Draw(0, 3, 0, 1);
2128
2129 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002130 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002131 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002132
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002133 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002134}
GregFd6ebdb32015-06-03 18:40:50 -06002135
Tony Barbour01999182015-04-09 12:58:51 -06002136TEST_F(VkRenderTest, FSTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002137{
2138 // The expected result from this test is a red and green checkered triangle
2139 static const char *vertShaderText =
2140 "#version 140\n"
2141 "#extension GL_ARB_separate_shader_objects : enable\n"
2142 "#extension GL_ARB_shading_language_420pack : enable\n"
2143 "layout (location = 0) out vec2 samplePos;\n"
2144 "void main() {\n"
2145 " vec2 vertices[3];"
2146 " vertices[0] = vec2(-0.5, -0.5);\n"
2147 " vertices[1] = vec2( 0.5, -0.5);\n"
2148 " vertices[2] = vec2( 0.5, 0.5);\n"
2149 " vec2 positions[3];"
2150 " positions[0] = vec2( 0.0, 0.0);\n"
2151 " positions[1] = vec2( 1.0, 0.0);\n"
2152 " positions[2] = vec2( 1.0, 1.0);\n"
2153 " samplePos = positions[gl_VertexID % 3];\n"
2154 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2155 "}\n";
2156
2157 static const char *fragShaderText =
2158 "#version 140\n"
2159 "#extension GL_ARB_separate_shader_objects : enable\n"
2160 "#extension GL_ARB_shading_language_420pack : enable\n"
2161 "layout (location = 0) in vec2 samplePos;\n"
2162 "layout (binding = 0) uniform sampler2D surface;\n"
2163 "layout (location=0) out vec4 outColor;\n"
2164 "void main() {\n"
2165 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2166 " outColor = texColor;\n"
2167 "}\n";
2168
2169 ASSERT_NO_FATAL_FAILURE(InitState());
2170 ASSERT_NO_FATAL_FAILURE(InitViewport());
2171
Tony Barbour01999182015-04-09 12:58:51 -06002172 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2173 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2174 VkSamplerObj sampler(m_device);
2175 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002176
Tony Barbour01999182015-04-09 12:58:51 -06002177 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002178 pipelineobj.AddShader(&vs);
2179 pipelineobj.AddShader(&ps);
2180
Tony Barbour01999182015-04-09 12:58:51 -06002181 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002182 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002183
Tony Barbourdd4c9642015-01-09 12:55:14 -07002184 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002185 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002186 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2187
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002188 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002189
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002190 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002191
2192#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002193 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002194 pDSDumpDot((char*)"triTest2.dot");
2195#endif
2196 // render triangle
2197 cmdBuffer.Draw(0, 3, 0, 1);
2198
2199 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002200 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002201 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002202
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002203 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002204}
Tony Barbour01999182015-04-09 12:58:51 -06002205TEST_F(VkRenderTest, SamplerBindingsTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002206{
2207 // This test sets bindings on the samplers
2208 // For now we are asserting that sampler and texture pairs
2209 // march in lock step, and are set via GLSL binding. This can
2210 // and will probably change.
2211 // The sampler bindings should match the sampler and texture slot
2212 // number set up by the application.
2213 // This test will result in a blue triangle
2214 static const char *vertShaderText =
2215 "#version 140\n"
2216 "#extension GL_ARB_separate_shader_objects : enable\n"
2217 "#extension GL_ARB_shading_language_420pack : enable\n"
2218 "layout (location = 0) out vec4 samplePos;\n"
2219 "void main() {\n"
2220 " vec2 vertices[3];"
2221 " vertices[0] = vec2(-0.5, -0.5);\n"
2222 " vertices[1] = vec2( 0.5, -0.5);\n"
2223 " vertices[2] = vec2( 0.5, 0.5);\n"
2224 " vec2 positions[3];"
2225 " positions[0] = vec2( 0.0, 0.0);\n"
2226 " positions[1] = vec2( 1.0, 0.0);\n"
2227 " positions[2] = vec2( 1.0, 1.0);\n"
2228 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2229 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2230 "}\n";
2231
2232 static const char *fragShaderText =
2233 "#version 140\n"
2234 "#extension GL_ARB_separate_shader_objects : enable\n"
2235 "#extension GL_ARB_shading_language_420pack : enable\n"
2236 "layout (location = 0) in vec4 samplePos;\n"
2237 "layout (binding = 0) uniform sampler2D surface0;\n"
2238 "layout (binding = 1) uniform sampler2D surface1;\n"
2239 "layout (binding = 12) uniform sampler2D surface2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06002240 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002241 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002242 " outColor = textureLod(surface2, samplePos.xy, 0.0);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002243 "}\n";
2244
2245 ASSERT_NO_FATAL_FAILURE(InitState());
2246 ASSERT_NO_FATAL_FAILURE(InitViewport());
2247
Tony Barbour01999182015-04-09 12:58:51 -06002248 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2249 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002250
Tony Barbour01999182015-04-09 12:58:51 -06002251 VkSamplerObj sampler1(m_device);
2252 VkSamplerObj sampler2(m_device);
2253 VkSamplerObj sampler3(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002254
Tony Barbour2f421a02015-04-01 16:38:10 -06002255 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
Tony Barbour01999182015-04-09 12:58:51 -06002256 VkTextureObj texture1(m_device, tex_colors); // Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002257 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
Tony Barbour01999182015-04-09 12:58:51 -06002258 VkTextureObj texture2(m_device, tex_colors); // Green
Tony Barbour2f421a02015-04-01 16:38:10 -06002259 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
Tony Barbour01999182015-04-09 12:58:51 -06002260 VkTextureObj texture3(m_device, tex_colors); // Blue
Tony Barbourf43b6982014-11-25 13:18:32 -07002261
Tony Barbour01999182015-04-09 12:58:51 -06002262 VkPipelineObj pipelineobj(m_device);
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 Barbour01999182015-04-09 12:58:51 -06002274 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002275 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2276
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002277 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002278
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002279 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002280
2281#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002282 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002283 pDSDumpDot((char*)"triTest2.dot");
2284#endif
2285 // render triangle
2286 cmdBuffer.Draw(0, 3, 0, 1);
2287
2288 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002289 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002290 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002291
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002292 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002293}
2294
Tony Barbour01999182015-04-09 12:58:51 -06002295TEST_F(VkRenderTest, TriangleVSUniformBlock)
Tony Barbourf43b6982014-11-25 13:18:32 -07002296{
2297 // The expected result from this test is a blue triangle
2298
2299 static const char *vertShaderText =
2300 "#version 140\n"
2301 "#extension GL_ARB_separate_shader_objects : enable\n"
2302 "#extension GL_ARB_shading_language_420pack : enable\n"
2303 "layout (location = 0) out vec4 outColor;\n"
2304 "layout (std140, binding = 0) uniform bufferVals {\n"
2305 " vec4 red;\n"
2306 " vec4 green;\n"
2307 " vec4 blue;\n"
2308 " vec4 white;\n"
2309 "} myBufferVals;\n"
2310 "void main() {\n"
2311 " vec2 vertices[3];"
2312 " vertices[0] = vec2(-0.5, -0.5);\n"
2313 " vertices[1] = vec2( 0.5, -0.5);\n"
2314 " vertices[2] = vec2( 0.5, 0.5);\n"
2315 " outColor = myBufferVals.blue;\n"
2316 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2317 "}\n";
2318
2319 static const char *fragShaderText =
2320 "#version 140\n"
2321 "#extension GL_ARB_separate_shader_objects : enable\n"
2322 "#extension GL_ARB_shading_language_420pack : enable\n"
2323 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -06002324 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002325 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002326 " outColor = inColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002327 "}\n";
2328
2329 ASSERT_NO_FATAL_FAILURE(InitState());
2330 ASSERT_NO_FATAL_FAILURE(InitViewport());
2331
Tony Barbour01999182015-04-09 12:58:51 -06002332 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2333 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002334
2335 // Let's populate our buffer with the following:
2336 // vec4 red;
2337 // vec4 green;
2338 // vec4 blue;
2339 // vec4 white;
2340 const int valCount = 4 * 4;
2341 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2342 0.0, 1.0, 0.0, 1.0,
2343 0.0, 0.0, 1.0, 1.0,
2344 1.0, 1.0, 1.0, 1.0 };
2345
Tony Barbour01999182015-04-09 12:58:51 -06002346 VkConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002347
Tony Barbour01999182015-04-09 12:58:51 -06002348 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002349 pipelineobj.AddShader(&vs);
2350 pipelineobj.AddShader(&ps);
2351
Tony Barbour01999182015-04-09 12:58:51 -06002352 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002353 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002354
Tony Barbourdd4c9642015-01-09 12:55:14 -07002355 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002356 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002357 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2358
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002359 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002360
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002361 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002362
2363#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002364 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002365 pDSDumpDot((char*)"triTest2.dot");
2366#endif
2367 // render triangle
2368 cmdBuffer.Draw(0, 3, 0, 1);
2369
2370 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002371 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002372 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002373
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002374 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002375}
2376
Tony Barbour01999182015-04-09 12:58:51 -06002377TEST_F(VkRenderTest, TriangleFSUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002378{
2379 // This test allows the shader to select which buffer it is
2380 // pulling from using layout binding qualifier.
2381 // There are corresponding changes in the compiler stack that
2382 // will select the buffer using binding directly.
2383 // The binding number should match the slot number set up by
2384 // the application.
2385 // The expected result from this test is a purple triangle
2386
2387 static const char *vertShaderText =
2388 "#version 140\n"
2389 "#extension GL_ARB_separate_shader_objects : enable\n"
2390 "#extension GL_ARB_shading_language_420pack : enable\n"
2391 "void main() {\n"
2392 " vec2 vertices[3];"
2393 " vertices[0] = vec2(-0.5, -0.5);\n"
2394 " vertices[1] = vec2( 0.5, -0.5);\n"
2395 " vertices[2] = vec2( 0.5, 0.5);\n"
2396 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2397 "}\n";
2398
2399 static const char *fragShaderText =
2400 "#version 140\n"
2401 "#extension GL_ARB_separate_shader_objects : enable\n"
2402 "#extension GL_ARB_shading_language_420pack : enable\n"
2403 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2404 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2405 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002406 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
GregFd6ebdb32015-06-03 18:40:50 -06002407 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002408 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002409 " outColor = myBlueVal.color;\n"
2410 " outColor += myRedVal.color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002411 "}\n";
2412
2413 ASSERT_NO_FATAL_FAILURE(InitState());
2414 ASSERT_NO_FATAL_FAILURE(InitViewport());
2415
Tony Barbour01999182015-04-09 12:58:51 -06002416 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2417 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002418
2419 // We're going to create a number of uniform buffers, and then allow
2420 // the shader to select which it wants to read from with a binding
2421
2422 // Let's populate the buffers with a single color each:
2423 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2424 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2425 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002426 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002427
2428 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2429 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2430 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2431 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2432
2433 const int redCount = sizeof(redVals) / sizeof(float);
2434 const int greenCount = sizeof(greenVals) / sizeof(float);
2435 const int blueCount = sizeof(blueVals) / sizeof(float);
2436 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2437
Tony Barbour01999182015-04-09 12:58:51 -06002438 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002439
Tony Barbour01999182015-04-09 12:58:51 -06002440 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002441
Tony Barbour01999182015-04-09 12:58:51 -06002442 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002443
Tony Barbour01999182015-04-09 12:58:51 -06002444 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002445
Tony Barbour01999182015-04-09 12:58:51 -06002446 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002447 pipelineobj.AddShader(&vs);
2448 pipelineobj.AddShader(&ps);
2449
Tony Barbour01999182015-04-09 12:58:51 -06002450 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002451 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2452 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2453 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2454 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002455
Tony Barbourdd4c9642015-01-09 12:55:14 -07002456 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002457 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002458 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002459
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002460 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002461
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002462 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002463
2464#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002465 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002466 pDSDumpDot((char*)"triTest2.dot");
2467#endif
2468 // render triangle
2469 cmdBuffer.Draw(0, 3, 0, 1);
2470
2471 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002472 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002473 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002474
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002475 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002476}
2477
Tony Barbour01999182015-04-09 12:58:51 -06002478TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002479{
2480 // This test is the same as TriangleFSUniformBlockBinding, but
2481 // it does not provide an instance name.
2482 // The expected result from this test is a purple triangle
2483
2484 static const char *vertShaderText =
2485 "#version 140\n"
2486 "#extension GL_ARB_separate_shader_objects : enable\n"
2487 "#extension GL_ARB_shading_language_420pack : enable\n"
2488 "void main() {\n"
2489 " vec2 vertices[3];"
2490 " vertices[0] = vec2(-0.5, -0.5);\n"
2491 " vertices[1] = vec2( 0.5, -0.5);\n"
2492 " vertices[2] = vec2( 0.5, 0.5);\n"
2493 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2494 "}\n";
2495
2496 static const char *fragShaderText =
2497 "#version 430\n"
2498 "#extension GL_ARB_separate_shader_objects : enable\n"
2499 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002500 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2501 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2502 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002503 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002504 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002505 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002506 " outColor = blue;\n"
2507 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002508 "}\n";
2509 ASSERT_NO_FATAL_FAILURE(InitState());
2510 ASSERT_NO_FATAL_FAILURE(InitViewport());
2511
Tony Barbour01999182015-04-09 12:58:51 -06002512 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2513 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002514
2515 // We're going to create a number of uniform buffers, and then allow
2516 // the shader to select which it wants to read from with a binding
2517
2518 // Let's populate the buffers with a single color each:
2519 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2520 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2521 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2522 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2523
2524 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2525 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2526 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2527 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2528
2529 const int redCount = sizeof(redVals) / sizeof(float);
2530 const int greenCount = sizeof(greenVals) / sizeof(float);
2531 const int blueCount = sizeof(blueVals) / sizeof(float);
2532 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2533
Tony Barbour01999182015-04-09 12:58:51 -06002534 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002535
Tony Barbour01999182015-04-09 12:58:51 -06002536 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002537
Tony Barbour01999182015-04-09 12:58:51 -06002538 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002539
Tony Barbour01999182015-04-09 12:58:51 -06002540 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002541
Tony Barbour01999182015-04-09 12:58:51 -06002542 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002543 pipelineobj.AddShader(&vs);
2544 pipelineobj.AddShader(&ps);
2545
Tony Barbour01999182015-04-09 12:58:51 -06002546 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002547 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2548 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2549 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2550 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002551
Tony Barbourdd4c9642015-01-09 12:55:14 -07002552 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002553 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002554 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2555
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002556 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002557
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002558 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002559
2560#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002561 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002562 pDSDumpDot((char*)"triTest2.dot");
2563#endif
2564 // render triangle
2565 cmdBuffer.Draw(0, 3, 0, 1);
2566
2567 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002568 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002569 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002570
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002571 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002572}
2573
GregF54a32172015-07-01 16:11:09 -06002574TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBindingWithStruct)
2575{
2576 // This test is the same as TriangleFSUniformBlockBinding, but
2577 // it does not provide an instance name.
2578 // The expected result from this test is a purple triangle
2579
2580 static const char *vertShaderText =
2581 "#version 140\n"
2582 "#extension GL_ARB_separate_shader_objects : enable\n"
2583 "#extension GL_ARB_shading_language_420pack : enable\n"
2584 "void main() {\n"
2585 " vec2 vertices[3];"
2586 " vertices[0] = vec2(-0.5, -0.5);\n"
2587 " vertices[1] = vec2( 0.5, -0.5);\n"
2588 " vertices[2] = vec2( 0.5, 0.5);\n"
2589 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2590 "}\n";
2591
2592 static const char *fragShaderText =
2593 "#version 430\n"
2594 "#extension GL_ARB_separate_shader_objects : enable\n"
2595 "#extension GL_ARB_shading_language_420pack : enable\n"
2596 "\n"
2597 " struct PS_INPUT {\n"
2598 " vec2 member0;\n"
2599 " vec4 member1;\n"
2600 " vec4 member2;\n"
2601 " vec4 member3;\n"
2602 " vec4 member4;\n"
2603 " vec4 member5;\n"
2604 " vec4 member6;\n"
2605 " vec4 member7;\n"
2606 " vec4 member8;\n"
2607 " vec4 member9;\n"
2608 " };\n"
2609 "\n"
2610 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2611 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2612 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2613 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
2614 "layout (location = 0) out vec4 outColor;\n"
2615 "PS_INPUT MainFs()\n"
2616 "{\n"
2617 " PS_INPUT o;\n"
2618 " o.member9 = red;\n"
2619 " return o;\n"
2620 "}\n"
2621 "\n"
2622 "void main()\n"
2623 "{\n"
2624 " PS_INPUT o;\n"
2625 " o = MainFs();\n"
2626 " outColor = blue;"
2627 " outColor += o.member9;\n"
2628 "}\n";;
2629 ASSERT_NO_FATAL_FAILURE(InitState());
2630 ASSERT_NO_FATAL_FAILURE(InitViewport());
2631
2632 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2633 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2634
2635 // We're going to create a number of uniform buffers, and then allow
2636 // the shader to select which it wants to read from with a binding
2637
2638 // Let's populate the buffers with a single color each:
2639 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2640 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2641 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2642 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2643
2644 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2645 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2646 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2647 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2648
2649 const int redCount = sizeof(redVals) / sizeof(float);
2650 const int greenCount = sizeof(greenVals) / sizeof(float);
2651 const int blueCount = sizeof(blueVals) / sizeof(float);
2652 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2653
2654 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2655
2656 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2657
2658 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2659
2660 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
2661
2662 VkPipelineObj pipelineobj(m_device);
2663 pipelineobj.AddShader(&vs);
2664 pipelineobj.AddShader(&ps);
2665
2666 VkDescriptorSetObj descriptorSet(m_device);
2667 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2668 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2669 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2670 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
2671
2672 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2673 VkCommandBufferObj cmdBuffer(m_device);
2674 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2675
2676 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
2677
2678 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
2679
2680#ifdef DUMP_STATE_DOT
2681 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
2682 pDSDumpDot((char*)"triTest2.dot");
2683#endif
2684 // render triangle
2685 cmdBuffer.Draw(0, 3, 0, 1);
2686
2687 // finalize recording of the command buffer
2688 EndCommandBuffer(cmdBuffer);
2689 cmdBuffer.QueueCommandBuffer();
2690
2691 RecordImages(m_renderTargets);
2692}
2693
Tony Barbour01999182015-04-09 12:58:51 -06002694TEST_F(VkRenderTest, CubeWithVertexFetchAndMVPAndTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07002695{
2696 static const char *vertShaderText =
2697 "#version 140\n"
2698 "#extension GL_ARB_separate_shader_objects : enable\n"
2699 "#extension GL_ARB_shading_language_420pack : enable\n"
2700 "layout (std140, binding=0) uniform bufferVals {\n"
2701 " mat4 mvp;\n"
2702 "} myBufferVals;\n"
2703 "layout (location=0) in vec4 pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002704 "layout (location=1) in vec2 input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002705 "layout (location=0) out vec2 UV;\n"
2706 "void main() {\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002707 " UV = input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002708 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002709 " gl_Position.y = -gl_Position.y;\n"
2710 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002711 "}\n";
2712
2713 static const char *fragShaderText =
2714 "#version 140\n"
2715 "#extension GL_ARB_separate_shader_objects : enable\n"
2716 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002717 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002718 "layout (location=0) out vec4 outColor;\n"
2719 "layout (location=0) in vec2 UV;\n"
2720 "void main() {\n"
2721 " outColor= textureLod(surface, UV, 0.0);\n"
2722 "}\n";
2723 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2724
2725 glm::mat4 View = glm::lookAt(
2726 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2727 glm::vec3(0,0,0), // and looks at the origin
2728 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2729 );
2730
2731 glm::mat4 Model = glm::mat4(1.0f);
2732
2733 glm::mat4 MVP = Projection * View * Model;
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002734 int num_verts = sizeof(g_vb_texture_Data) / sizeof(g_vb_texture_Data[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002735
2736
2737 ASSERT_NO_FATAL_FAILURE(InitState());
2738 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wu9e81ebb2015-07-09 10:16:34 +08002739 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Tony Barbour8bef8ee2015-05-22 09:44:58 -06002740 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07002741
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002742 VkConstantBufferObj meshBuffer(m_device, num_verts,
2743 sizeof(g_vb_texture_Data[0]), g_vb_texture_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002744 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002745
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002746 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07002747
Tony Barbour01999182015-04-09 12:58:51 -06002748 VkConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2749 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2750 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2751 VkSamplerObj sampler(m_device);
2752 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002753
Tony Barbour01999182015-04-09 12:58:51 -06002754 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002755 pipelineobj.AddShader(&vs);
2756 pipelineobj.AddShader(&ps);
2757
Tony Barbour01999182015-04-09 12:58:51 -06002758 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002759 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mvpBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002760 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002761
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002762#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002763 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002764 MESH_BIND_ID, // binding ID
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002765 sizeof(g_vb_texture_Data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002766 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002767 };
Tony Barbourf43b6982014-11-25 13:18:32 -07002768
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002769 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002770 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2771 vi_attribs[0].location = 0; // location
Tony Barbour8205d902015-04-16 15:59:00 -06002772 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002773 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2774 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2775 vi_attribs[1].location = 1; // location
2776 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
2777 vi_attribs[1].offsetInBytes = 16; // Offset of uv components
Tony Barbourf43b6982014-11-25 13:18:32 -07002778
Tony Barbourf43b6982014-11-25 13:18:32 -07002779 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002780 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2781 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07002782
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002783 VkPipelineDsStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002784 ds_state.depthTestEnable = VK_TRUE;
2785 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06002786 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002787 ds_state.depthBoundsEnable = VK_FALSE;
2788 ds_state.stencilTestEnable = VK_FALSE;
2789 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
2790 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
2791 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06002792 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
2793 ds_state.format = VK_FORMAT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002794 ds_state.front = ds_state.back;
2795 pipelineobj.SetDepthStencil(&ds_state);
2796
Tony Barbour17c6ab12015-03-27 17:03:18 -06002797 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour01999182015-04-09 12:58:51 -06002798 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002799 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002800
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002801 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002802
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002803 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002804
2805 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2806#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002807 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002808 pDSDumpDot((char*)"triTest2.dot");
2809#endif
2810 // render triangle
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002811 cmdBuffer.Draw(0, num_verts, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002812
2813 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002814 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002815 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002816
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002817 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002818 RotateTriangleVSUniform(Projection, View, Model, &mvpBuffer, &cmdBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002819}
Cody Northropd1ce7842014-12-09 11:17:01 -07002820
Tony Barbour01999182015-04-09 12:58:51 -06002821TEST_F(VkRenderTest, TriangleMixedSamplerUniformBlockBinding)
Cody Northropd1ce7842014-12-09 11:17:01 -07002822{
2823 // This test mixes binding slots of textures and buffers, ensuring
2824 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002825 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002826 // you can modify it to move the desired result around.
2827
2828 static const char *vertShaderText =
2829 "#version 140\n"
2830 "#extension GL_ARB_separate_shader_objects : enable\n"
2831 "#extension GL_ARB_shading_language_420pack : enable\n"
2832 "void main() {\n"
2833 " vec2 vertices[3];"
2834 " vertices[0] = vec2(-0.5, -0.5);\n"
2835 " vertices[1] = vec2( 0.5, -0.5);\n"
2836 " vertices[2] = vec2( 0.5, 0.5);\n"
2837 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2838 "}\n";
2839
2840 static const char *fragShaderText =
2841 "#version 430\n"
2842 "#extension GL_ARB_separate_shader_objects : enable\n"
2843 "#extension GL_ARB_shading_language_420pack : enable\n"
2844 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002845 "layout (binding = 3) uniform sampler2D surface1;\n"
2846 "layout (binding = 1) uniform sampler2D surface2;\n"
2847 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002848
Cody Northropa0410942014-12-09 13:59:39 -07002849
Chia-I Wuf8385062015-01-04 16:27:24 +08002850 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2851 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2852 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2853 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002854 "layout (location = 0) out vec4 outColor;\n"
2855 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002856 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002857 " outColor += white * vec4(0.00001);\n"
2858 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002859 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002860 "}\n";
2861 ASSERT_NO_FATAL_FAILURE(InitState());
2862 ASSERT_NO_FATAL_FAILURE(InitViewport());
2863
Tony Barbour01999182015-04-09 12:58:51 -06002864 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2865 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northropd1ce7842014-12-09 11:17:01 -07002866
Cody Northropd1ce7842014-12-09 11:17:01 -07002867 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2868 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2869 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2870 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2871
2872 const int redCount = sizeof(redVals) / sizeof(float);
2873 const int greenCount = sizeof(greenVals) / sizeof(float);
2874 const int blueCount = sizeof(blueVals) / sizeof(float);
2875 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2876
Tony Barbour01999182015-04-09 12:58:51 -06002877 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2878 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2879 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2880 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002881
Tony Barbour2f421a02015-04-01 16:38:10 -06002882 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002883 VkSamplerObj sampler0(m_device);
2884 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002885 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002886 VkSamplerObj sampler2(m_device);
2887 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002888 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002889 VkSamplerObj sampler4(m_device);
2890 VkTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropa0410942014-12-09 13:59:39 -07002891
2892 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2893 // TODO: Get back here ASAP and understand why.
Tony Barbour2f421a02015-04-01 16:38:10 -06002894 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06002895 VkSamplerObj sampler7(m_device);
2896 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropd1ce7842014-12-09 11:17:01 -07002897
Tony Barbour01999182015-04-09 12:58:51 -06002898 VkPipelineObj pipelineobj(m_device);
Cody Northropd1ce7842014-12-09 11:17:01 -07002899 pipelineobj.AddShader(&vs);
2900 pipelineobj.AddShader(&ps);
2901
Tony Barbour01999182015-04-09 12:58:51 -06002902 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002903 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2904 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2905 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2906 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002907 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002908 // swap blue and green
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002909 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2910 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2911 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002912
Tony Barbourdd4c9642015-01-09 12:55:14 -07002913 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002914 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002915 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002916
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002917 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002918
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002919 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002920
2921#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002922 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002923 pDSDumpDot((char*)"triTest2.dot");
2924#endif
2925 // render triangle
2926 cmdBuffer.Draw(0, 3, 0, 1);
2927
2928 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002929 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002930 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002931
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002932 RecordImages(m_renderTargets);
Cody Northropd1ce7842014-12-09 11:17:01 -07002933}
2934
Tony Barbour01999182015-04-09 12:58:51 -06002935TEST_F(VkRenderTest, TriangleMatchingSamplerUniformBlockBinding)
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002936{
2937 // This test matches binding slots of textures and buffers, requiring
2938 // the driver to give them distinct number spaces.
2939 // The expected result from this test is a red triangle, although
2940 // you can modify it to move the desired result around.
2941
2942 static const char *vertShaderText =
2943 "#version 140\n"
2944 "#extension GL_ARB_separate_shader_objects : enable\n"
2945 "#extension GL_ARB_shading_language_420pack : enable\n"
2946 "void main() {\n"
2947 " vec2 vertices[3];"
2948 " vertices[0] = vec2(-0.5, -0.5);\n"
2949 " vertices[1] = vec2( 0.5, -0.5);\n"
2950 " vertices[2] = vec2( 0.5, 0.5);\n"
2951 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2952 "}\n";
2953
2954 static const char *fragShaderText =
2955 "#version 430\n"
2956 "#extension GL_ARB_separate_shader_objects : enable\n"
2957 "#extension GL_ARB_shading_language_420pack : enable\n"
2958 "layout (binding = 0) uniform sampler2D surface0;\n"
2959 "layout (binding = 1) uniform sampler2D surface1;\n"
2960 "layout (binding = 2) uniform sampler2D surface2;\n"
2961 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002962 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2963 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2964 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2965 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002966 "layout (location = 0) out vec4 outColor;\n"
2967 "void main() {\n"
2968 " outColor = red;// * vec4(0.00001);\n"
2969 " outColor += white * vec4(0.00001);\n"
2970 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2971 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2972 "}\n";
2973 ASSERT_NO_FATAL_FAILURE(InitState());
2974 ASSERT_NO_FATAL_FAILURE(InitViewport());
2975
Tony Barbour01999182015-04-09 12:58:51 -06002976 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2977 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002978
2979 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2980 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2981 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2982 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2983
2984 const int redCount = sizeof(redVals) / sizeof(float);
2985 const int greenCount = sizeof(greenVals) / sizeof(float);
2986 const int blueCount = sizeof(blueVals) / sizeof(float);
2987 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2988
Tony Barbour01999182015-04-09 12:58:51 -06002989 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2990 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2991 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2992 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002993
Tony Barbour2f421a02015-04-01 16:38:10 -06002994 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002995 VkSamplerObj sampler0(m_device);
2996 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002997 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002998 VkSamplerObj sampler2(m_device);
2999 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06003000 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06003001 VkSamplerObj sampler4(m_device);
3002 VkTextureObj texture4(m_device, tex_colors); // Light Green
Tony Barbour2f421a02015-04-01 16:38:10 -06003003 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06003004 VkSamplerObj sampler7(m_device);
3005 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003006
Tony Barbour01999182015-04-09 12:58:51 -06003007 VkPipelineObj pipelineobj(m_device);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003008 pipelineobj.AddShader(&vs);
3009 pipelineobj.AddShader(&ps);
3010
Tony Barbour01999182015-04-09 12:58:51 -06003011 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08003012 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3013 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3014 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
3015 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003016 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
3017 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
3018 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
3019 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003020
Tony Barbourdd4c9642015-01-09 12:55:14 -07003021 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06003022 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07003023 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003024
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003025 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07003026
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003027 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07003028
3029#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003030 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07003031 pDSDumpDot((char*)"triTest2.dot");
3032#endif
3033 // render triangle
3034 cmdBuffer.Draw(0, 3, 0, 1);
3035
3036 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003037 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003038 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07003039
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003040 RecordImages(m_renderTargets);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003041}
3042
Tony Barbour01999182015-04-09 12:58:51 -06003043TEST_F(VkRenderTest, TriangleUniformBufferLayout)
Cody Northrop02690bd2014-12-17 15:26:33 -07003044{
3045 // This test populates a buffer with a variety of different data
3046 // types, then reads them out with a shader.
3047 // The expected result from this test is a green triangle
3048
3049 static const char *vertShaderText =
3050 "#version 140\n"
3051 "#extension GL_ARB_separate_shader_objects : enable\n"
3052 "#extension GL_ARB_shading_language_420pack : enable\n"
3053 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3054 " vec4 fRed;\n"
3055 " vec4 fGreen;\n"
3056 " layout(row_major) mat4 worldToProj;\n"
3057 " layout(row_major) mat4 projToWorld;\n"
3058 " layout(row_major) mat4 worldToView;\n"
3059 " layout(row_major) mat4 viewToProj;\n"
3060 " layout(row_major) mat4 worldToShadow[4];\n"
3061 " float fZero;\n"
3062 " float fOne;\n"
3063 " float fTwo;\n"
3064 " float fThree;\n"
3065 " vec3 fZeroZeroZero;\n"
3066 " float fFour;\n"
3067 " vec3 fZeroZeroOne;\n"
3068 " float fFive;\n"
3069 " vec3 fZeroOneZero;\n"
3070 " float fSix;\n"
3071 " float fSeven;\n"
3072 " float fEight;\n"
3073 " float fNine;\n"
3074 " vec2 fZeroZero;\n"
3075 " vec2 fZeroOne;\n"
3076 " vec4 fBlue;\n"
3077 " vec2 fOneZero;\n"
3078 " vec2 fOneOne;\n"
3079 " vec3 fZeroOneOne;\n"
3080 " float fTen;\n"
3081 " float fEleven;\n"
3082 " float fTwelve;\n"
3083 " vec3 fOneZeroZero;\n"
3084 " vec4 uvOffsets[4];\n"
3085 "};\n"
3086 "layout (location = 0) out vec4 color;"
3087 "void main() {\n"
3088
3089 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3090 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3091 " \n"
3092
3093 // do some exact comparisons, even though we should
3094 // really have an epsilon involved.
3095 " vec4 outColor = right;\n"
3096 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3097 " outColor = wrong;\n"
3098 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3099 " outColor = wrong;\n"
3100 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3101 " outColor = wrong;\n"
3102
3103 " color = outColor;\n"
3104
3105 // generic position stuff
3106 " vec2 vertices;\n"
3107 " int vertexSelector = gl_VertexID;\n"
3108 " if (vertexSelector == 0)\n"
3109 " vertices = vec2(-0.5, -0.5);\n"
3110 " else if (vertexSelector == 1)\n"
3111 " vertices = vec2( 0.5, -0.5);\n"
3112 " else if (vertexSelector == 2)\n"
3113 " vertices = vec2( 0.5, 0.5);\n"
3114 " else\n"
3115 " vertices = vec2( 0.0, 0.0);\n"
3116 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3117 "}\n";
3118
3119 static const char *fragShaderText =
3120 "#version 140\n"
3121 "#extension GL_ARB_separate_shader_objects : enable\n"
3122 "#extension GL_ARB_shading_language_420pack : enable\n"
3123 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3124 " vec4 fRed;\n"
3125 " vec4 fGreen;\n"
3126 " layout(row_major) mat4 worldToProj;\n"
3127 " layout(row_major) mat4 projToWorld;\n"
3128 " layout(row_major) mat4 worldToView;\n"
3129 " layout(row_major) mat4 viewToProj;\n"
3130 " layout(row_major) mat4 worldToShadow[4];\n"
3131 " float fZero;\n"
3132 " float fOne;\n"
3133 " float fTwo;\n"
3134 " float fThree;\n"
3135 " vec3 fZeroZeroZero;\n"
3136 " float fFour;\n"
3137 " vec3 fZeroZeroOne;\n"
3138 " float fFive;\n"
3139 " vec3 fZeroOneZero;\n"
3140 " float fSix;\n"
3141 " float fSeven;\n"
3142 " float fEight;\n"
3143 " float fNine;\n"
3144 " vec2 fZeroZero;\n"
3145 " vec2 fZeroOne;\n"
3146 " vec4 fBlue;\n"
3147 " vec2 fOneZero;\n"
3148 " vec2 fOneOne;\n"
3149 " vec3 fZeroOneOne;\n"
3150 " float fTen;\n"
3151 " float fEleven;\n"
3152 " float fTwelve;\n"
3153 " vec3 fOneZeroZero;\n"
3154 " vec4 uvOffsets[4];\n"
3155 "};\n"
3156 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003157 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop02690bd2014-12-17 15:26:33 -07003158 "void main() {\n"
3159 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3160 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3161 " \n"
3162
3163 // start with VS value to ensure it passed
3164 " vec4 outColor = color;\n"
3165
3166 // do some exact comparisons, even though we should
3167 // really have an epsilon involved.
3168 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3169 " outColor = wrong;\n"
3170 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3171 " outColor = wrong;\n"
3172 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3173 " outColor = wrong;\n"
3174 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3175 " outColor = wrong;\n"
3176 " if (fTwo != 2.0)\n"
3177 " outColor = wrong;\n"
3178 " if (fOneOne != vec2(1.0, 1.0))\n"
3179 " outColor = wrong;\n"
3180 " if (fTen != 10.0)\n"
3181 " outColor = wrong;\n"
3182 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3183 " outColor = wrong;\n"
3184 " \n"
GregFd6ebdb32015-06-03 18:40:50 -06003185 " uFragColor = outColor;\n"
Cody Northrop02690bd2014-12-17 15:26:33 -07003186 "}\n";
3187
3188
3189 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3190 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3191 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3192 0.0, 1.0, 0.0, 1.0, // align
3193 0.0, 0.0, 1.0, 1.0, // align
3194 0.0, 0.0, 0.0, 1.0, // align
3195 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3196 0.0, 2.0, 0.0, 2.0, // align
3197 0.0, 0.0, 2.0, 2.0, // align
3198 0.0, 0.0, 0.0, 2.0, // align
3199 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3200 0.0, 3.0, 0.0, 3.0, // align
3201 0.0, 0.0, 3.0, 3.0, // align
3202 0.0, 0.0, 0.0, 3.0, // align
3203 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3204 0.0, 4.0, 0.0, 4.0, // align
3205 0.0, 0.0, 4.0, 4.0, // align
3206 0.0, 0.0, 0.0, 4.0, // align
3207 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3208 0.0, 5.0, 0.0, 5.0, // align
3209 0.0, 0.0, 5.0, 5.0, // align
3210 0.0, 0.0, 0.0, 5.0, // align
3211 6.0, 0.0, 0.0, 6.0, // align
3212 0.0, 6.0, 0.0, 6.0, // align
3213 0.0, 0.0, 6.0, 6.0, // align
3214 0.0, 0.0, 0.0, 6.0, // align
3215 7.0, 0.0, 0.0, 7.0, // align
3216 0.0, 7.0, 0.0, 7.0, // align
3217 0.0, 0.0, 7.0, 7.0, // align
3218 0.0, 0.0, 0.0, 7.0, // align
3219 8.0, 0.0, 0.0, 8.0, // align
3220 0.0, 8.0, 0.0, 8.0, // align
3221 0.0, 0.0, 8.0, 8.0, // align
3222 0.0, 0.0, 0.0, 8.0, // align
3223 0.0, // float fZero; // align
3224 1.0, // float fOne; // pack
3225 2.0, // float fTwo; // pack
3226 3.0, // float fThree; // pack
3227 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3228 4.0, // float fFour; // pack
3229 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3230 5.0, // float fFive; // pack
3231 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3232 6.0, // float fSix; // pack
3233 7.0, // float fSeven; // align
3234 8.0, // float fEight; // pack
3235 9.0, // float fNine; // pack
3236 0.0, // BUFFER
3237 0.0, 0.0, // vec2 fZeroZero; // align
3238 0.0, 1.0, // vec2 fZeroOne; // pack
3239 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3240 1.0, 0.0, // vec2 fOneZero; // align
3241 1.0, 1.0, // vec2 fOneOne; // pack
3242 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3243 10.0, // float fTen; // pack
3244 11.0, // float fEleven; // align
3245 12.0, // float fTwelve; // pack
3246 0.0, 0.0, // BUFFER
3247 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3248 0.0, // BUFFER
3249 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3250 0.5, 0.6, 0.7, 0.8, // align
3251 0.9, 1.0, 1.1, 1.2, // align
3252 1.3, 1.4, 1.5, 1.6, // align
3253 };
3254
3255 ASSERT_NO_FATAL_FAILURE(InitState());
3256 ASSERT_NO_FATAL_FAILURE(InitViewport());
3257
3258 const int constCount = sizeof(mixedVals) / sizeof(float);
3259
Tony Barbour01999182015-04-09 12:58:51 -06003260 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3261 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop02690bd2014-12-17 15:26:33 -07003262
Tony Barbour01999182015-04-09 12:58:51 -06003263 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003264
Tony Barbour01999182015-04-09 12:58:51 -06003265 VkPipelineObj pipelineobj(m_device);
Cody Northrop02690bd2014-12-17 15:26:33 -07003266 pipelineobj.AddShader(&vs);
3267 pipelineobj.AddShader(&ps);
3268
Tony Barbour01999182015-04-09 12:58:51 -06003269 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003270 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003271
3272 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06003273 VkCommandBufferObj cmdBuffer(m_device);
Cody Northrop02690bd2014-12-17 15:26:33 -07003274 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3275
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003276 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Cody Northrop02690bd2014-12-17 15:26:33 -07003277
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003278 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Cody Northrop02690bd2014-12-17 15:26:33 -07003279
3280#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003281 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop02690bd2014-12-17 15:26:33 -07003282 pDSDumpDot((char*)"triTest2.dot");
3283#endif
3284 // render triangle
3285 cmdBuffer.Draw(0, 3, 0, 1);
3286
3287 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003288 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003289 cmdBuffer.QueueCommandBuffer();
Cody Northrop02690bd2014-12-17 15:26:33 -07003290
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003291 RecordImages(m_renderTargets);
Cody Northrop02690bd2014-12-17 15:26:33 -07003292}
3293
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003294TEST_F(VkRenderTest, TextureGather)
3295{
3296 // This test introduces textureGather and textureGatherOffset
3297 // Each call is compared against an expected inline color result
3298 // Green triangle means everything worked as expected
3299 // Red means something went wrong
3300
3301 // disable SPV until texture gather is turned on in LunarGLASS
Cody Northrop1cfbd172015-06-03 16:49:20 -06003302 ScopedUseGlsl useGlsl(true);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003303
3304 static const char *vertShaderText =
3305 "#version 140\n"
3306 "#extension GL_ARB_separate_shader_objects : enable\n"
3307 "#extension GL_ARB_shading_language_420pack : enable\n"
3308 "void main() {\n"
3309 " vec2 vertices[3];"
3310 " vertices[0] = vec2(-0.5, -0.5);\n"
3311 " vertices[1] = vec2( 0.5, -0.5);\n"
3312 " vertices[2] = vec2( 0.5, 0.5);\n"
3313 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
3314 "}\n";
3315
3316 static const char *fragShaderText =
3317 "#version 430\n"
3318 "#extension GL_ARB_separate_shader_objects : enable\n"
3319 "#extension GL_ARB_shading_language_420pack : enable\n"
3320 "layout (binding = 0) uniform sampler2D surface0;\n"
3321 "layout (binding = 1) uniform sampler2D surface1;\n"
3322 "layout (binding = 2) uniform sampler2D surface2;\n"
3323 "layout (binding = 3) uniform sampler2D surface3;\n"
3324 "layout (location = 0) out vec4 outColor;\n"
3325 "void main() {\n"
3326
3327 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3328 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3329
3330 " vec4 color = right;\n"
3331
3332 // Grab a normal texture sample to ensure it can work in conjuntion
3333 // with textureGather (there are some intracacies in the backend)
3334 " vec4 sampledColor = textureLod(surface2, vec2(0.5), 0.0);\n"
3335 " if (sampledColor != vec4(0.0, 0.0, 1.0, 1.0))\n"
3336 " color = wrong;\n"
3337
3338 " vec4 gatheredColor = textureGather(surface0, vec2(0.5), 0);\n"
3339 // This just grabbed four red components from a red surface
3340 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3341 " color = wrong;\n"
3342
3343 // Yes, this is using an offset of 0, we don't have enough fine grained
3344 // control of the texture contents here.
3345 " gatheredColor = textureGatherOffset(surface1, vec2(0.5), ivec2(0, 0), 1);\n"
3346 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3347 " color = wrong;\n"
3348
3349 " outColor = color;\n"
3350
3351 "}\n";
3352
3353 ASSERT_NO_FATAL_FAILURE(InitState());
3354 ASSERT_NO_FATAL_FAILURE(InitViewport());
3355
3356 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3357 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3358
3359 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
3360 VkSamplerObj sampler0(m_device);
3361 VkTextureObj texture0(m_device, tex_colors); // Red
3362 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
3363 VkSamplerObj sampler1(m_device);
3364 VkTextureObj texture1(m_device, tex_colors); // Green
3365 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
3366 VkSamplerObj sampler2(m_device);
3367 VkTextureObj texture2(m_device, tex_colors); // Blue
3368 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
3369 VkSamplerObj sampler3(m_device);
3370 VkTextureObj texture3(m_device, tex_colors); // Red and Blue
3371
3372 VkPipelineObj pipelineobj(m_device);
3373 pipelineobj.AddShader(&vs);
3374 pipelineobj.AddShader(&ps);
3375
3376 VkDescriptorSetObj descriptorSet(m_device);
3377 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3378 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
3379 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3380 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
3381
3382 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3383 VkCommandBufferObj cmdBuffer(m_device);
3384 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3385
3386 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3387
3388 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3389
3390 // render triangle
3391 cmdBuffer.Draw(0, 3, 0, 1);
3392
3393 // finalize recording of the command buffer
3394 EndCommandBuffer(cmdBuffer);
3395 cmdBuffer.QueueCommandBuffer();
3396
3397 RecordImages(m_renderTargets);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003398}
3399
Cody Northropa44c2ff2015-04-15 11:19:06 -06003400TEST_F(VkRenderTest, GeometryShaderHelloWorld)
3401{
3402 // This test introduces a geometry shader that simply
3403 // changes the color of each vertex to red, green, blue
3404
3405 static const char *vertShaderText =
3406 "#version 140\n"
3407 "#extension GL_ARB_separate_shader_objects : enable\n"
3408 "#extension GL_ARB_shading_language_420pack : enable\n"
3409 "layout (location = 0) out vec4 color;"
3410 "void main() {\n"
3411
3412 // VS writes out red
3413 " color = vec4(1.0, 0.0, 0.0, 1.0);\n"
3414
3415 // generic position stuff
3416 " vec2 vertices;\n"
3417 " int vertexSelector = gl_VertexID;\n"
3418 " if (vertexSelector == 0)\n"
3419 " vertices = vec2(-0.5, -0.5);\n"
3420 " else if (vertexSelector == 1)\n"
3421 " vertices = vec2( 0.5, -0.5);\n"
3422 " else if (vertexSelector == 2)\n"
3423 " vertices = vec2( 0.5, 0.5);\n"
3424 " else\n"
3425 " vertices = vec2( 0.0, 0.0);\n"
3426 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3427
3428 "}\n";
3429
3430 static const char *geomShaderText =
3431 "#version 330\n"
3432 "#extension GL_ARB_separate_shader_objects : enable\n"
3433 "#extension GL_ARB_shading_language_420pack : enable\n"
3434 "layout( triangles ) in;\n"
3435 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3436 "layout( location = 0 ) in vec4 inColor[3];\n"
3437 "layout( location = 0 ) out vec4 outColor;\n"
3438 "void main()\n"
3439 "{\n"
3440
3441 // first vertex, pass through red
3442 " gl_Position = gl_in[0].gl_Position;\n"
3443 " outColor = inColor[0];\n"
3444 " EmitVertex();\n"
3445
3446 // second vertex, green
3447 " gl_Position = gl_in[1].gl_Position;\n"
3448 " outColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3449 " EmitVertex();\n"
3450
3451 // third vertex, blue
3452 " gl_Position = gl_in[2].gl_Position;\n"
3453 " outColor = vec4(0.0, 0.0, 1.0, 1.0);\n"
3454 " EmitVertex();\n"
3455
3456 // done
3457 " EndPrimitive();\n"
3458 "}\n";
3459
3460
3461 static const char *fragShaderText =
3462 "#version 140\n"
3463 "#extension GL_ARB_separate_shader_objects : enable\n"
3464 "#extension GL_ARB_shading_language_420pack : enable\n"
3465 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003466 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003467 "void main() {\n"
3468 // pass through
GregFd6ebdb32015-06-03 18:40:50 -06003469 " outColor = color;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003470 "}\n";
3471
3472
3473
3474 ASSERT_NO_FATAL_FAILURE(InitState());
3475 ASSERT_NO_FATAL_FAILURE(InitViewport());
3476
3477 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3478 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3479 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3480
3481 VkPipelineObj pipelineobj(m_device);
3482 pipelineobj.AddShader(&vs);
3483 pipelineobj.AddShader(&gs);
3484 pipelineobj.AddShader(&ps);
3485
3486 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3487 VkCommandBufferObj cmdBuffer(m_device);
3488 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3489
3490 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3491
3492 VkDescriptorSetObj descriptorSet(m_device);
3493
3494 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3495
3496 // render triangle
3497 cmdBuffer.Draw(0, 3, 0, 1);
3498
3499 // finalize recording of the command buffer
3500 EndCommandBuffer(cmdBuffer);
3501 cmdBuffer.QueueCommandBuffer();
3502
3503 RecordImages(m_renderTargets);
3504}
3505
3506TEST_F(VkRenderTest, GSUniformBufferLayout)
3507{
3508 // This test is just like TriangleUniformBufferLayout but adds
3509 // geometry as a stage that also does UBO lookups
3510 // The expected result from this test is a green triangle
3511
3512 static const char *vertShaderText =
3513 "#version 140\n"
3514 "#extension GL_ARB_separate_shader_objects : enable\n"
3515 "#extension GL_ARB_shading_language_420pack : enable\n"
3516 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3517 " vec4 fRed;\n"
3518 " vec4 fGreen;\n"
3519 " layout(row_major) mat4 worldToProj;\n"
3520 " layout(row_major) mat4 projToWorld;\n"
3521 " layout(row_major) mat4 worldToView;\n"
3522 " layout(row_major) mat4 viewToProj;\n"
3523 " layout(row_major) mat4 worldToShadow[4];\n"
3524 " float fZero;\n"
3525 " float fOne;\n"
3526 " float fTwo;\n"
3527 " float fThree;\n"
3528 " vec3 fZeroZeroZero;\n"
3529 " float fFour;\n"
3530 " vec3 fZeroZeroOne;\n"
3531 " float fFive;\n"
3532 " vec3 fZeroOneZero;\n"
3533 " float fSix;\n"
3534 " float fSeven;\n"
3535 " float fEight;\n"
3536 " float fNine;\n"
3537 " vec2 fZeroZero;\n"
3538 " vec2 fZeroOne;\n"
3539 " vec4 fBlue;\n"
3540 " vec2 fOneZero;\n"
3541 " vec2 fOneOne;\n"
3542 " vec3 fZeroOneOne;\n"
3543 " float fTen;\n"
3544 " float fEleven;\n"
3545 " float fTwelve;\n"
3546 " vec3 fOneZeroZero;\n"
3547 " vec4 uvOffsets[4];\n"
3548 "};\n"
3549 "layout (location = 0) out vec4 color;"
3550 "void main() {\n"
3551
3552 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3553 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3554 " \n"
3555
3556 // do some exact comparisons, even though we should
3557 // really have an epsilon involved.
3558 " vec4 outColor = right;\n"
3559 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3560 " outColor = wrong;\n"
3561 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3562 " outColor = wrong;\n"
3563 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3564 " outColor = wrong;\n"
3565
3566 " color = outColor;\n"
3567
3568 // generic position stuff
3569 " vec2 vertices;\n"
3570 " int vertexSelector = gl_VertexID;\n"
3571 " if (vertexSelector == 0)\n"
3572 " vertices = vec2(-0.5, -0.5);\n"
3573 " else if (vertexSelector == 1)\n"
3574 " vertices = vec2( 0.5, -0.5);\n"
3575 " else if (vertexSelector == 2)\n"
3576 " vertices = vec2( 0.5, 0.5);\n"
3577 " else\n"
3578 " vertices = vec2( 0.0, 0.0);\n"
3579 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3580 "}\n";
3581
3582 static const char *geomShaderText =
3583 "#version 330\n"
3584 "#extension GL_ARB_separate_shader_objects : enable\n"
3585 "#extension GL_ARB_shading_language_420pack : enable\n"
3586
3587 // GS layout stuff
3588 "layout( triangles ) in;\n"
3589 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3590
3591 // Between stage IO
3592 "layout( location = 0 ) in vec4 inColor[3];\n"
3593 "layout( location = 0 ) out vec4 color;\n"
3594
3595 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3596 " vec4 fRed;\n"
3597 " vec4 fGreen;\n"
3598 " layout(row_major) mat4 worldToProj;\n"
3599 " layout(row_major) mat4 projToWorld;\n"
3600 " layout(row_major) mat4 worldToView;\n"
3601 " layout(row_major) mat4 viewToProj;\n"
3602 " layout(row_major) mat4 worldToShadow[4];\n"
3603 " float fZero;\n"
3604 " float fOne;\n"
3605 " float fTwo;\n"
3606 " float fThree;\n"
3607 " vec3 fZeroZeroZero;\n"
3608 " float fFour;\n"
3609 " vec3 fZeroZeroOne;\n"
3610 " float fFive;\n"
3611 " vec3 fZeroOneZero;\n"
3612 " float fSix;\n"
3613 " float fSeven;\n"
3614 " float fEight;\n"
3615 " float fNine;\n"
3616 " vec2 fZeroZero;\n"
3617 " vec2 fZeroOne;\n"
3618 " vec4 fBlue;\n"
3619 " vec2 fOneZero;\n"
3620 " vec2 fOneOne;\n"
3621 " vec3 fZeroOneOne;\n"
3622 " float fTen;\n"
3623 " float fEleven;\n"
3624 " float fTwelve;\n"
3625 " vec3 fOneZeroZero;\n"
3626 " vec4 uvOffsets[4];\n"
3627 "};\n"
3628
3629 "void main()\n"
3630 "{\n"
3631
3632 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3633 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3634
3635 // Each vertex will validate it can read VS output
3636 // then check a few values from the UBO
3637
3638 // first vertex
3639 " vec4 outColor = inColor[0];\n"
3640
3641 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3642 " outColor = wrong;\n"
3643 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3644 " outColor = wrong;\n"
3645 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3646 " outColor = wrong;\n"
3647 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3648 " outColor = wrong;\n"
3649
3650 " gl_Position = gl_in[0].gl_Position;\n"
3651 " color = outColor;\n"
3652 " EmitVertex();\n"
3653
3654 // second vertex
3655 " outColor = inColor[1];\n"
3656
3657 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3658 " outColor = wrong;\n"
3659 " if (fSix != 6.0)\n"
3660 " outColor = wrong;\n"
3661 " if (fOneOne != vec2(1.0, 1.0))\n"
3662 " outColor = wrong;\n"
3663
3664 " gl_Position = gl_in[1].gl_Position;\n"
3665 " color = outColor;\n"
3666 " EmitVertex();\n"
3667
3668 // third vertex
3669 " outColor = inColor[2];\n"
3670
3671 " if (fSeven != 7.0)\n"
3672 " outColor = wrong;\n"
3673 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3674 " outColor = wrong;\n"
3675
3676 " gl_Position = gl_in[2].gl_Position;\n"
3677 " color = outColor;\n"
3678 " EmitVertex();\n"
3679
3680 // done
3681 " EndPrimitive();\n"
3682 "}\n";
3683
3684 static const char *fragShaderText =
3685 "#version 140\n"
3686 "#extension GL_ARB_separate_shader_objects : enable\n"
3687 "#extension GL_ARB_shading_language_420pack : enable\n"
3688 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3689 " vec4 fRed;\n"
3690 " vec4 fGreen;\n"
3691 " layout(row_major) mat4 worldToProj;\n"
3692 " layout(row_major) mat4 projToWorld;\n"
3693 " layout(row_major) mat4 worldToView;\n"
3694 " layout(row_major) mat4 viewToProj;\n"
3695 " layout(row_major) mat4 worldToShadow[4];\n"
3696 " float fZero;\n"
3697 " float fOne;\n"
3698 " float fTwo;\n"
3699 " float fThree;\n"
3700 " vec3 fZeroZeroZero;\n"
3701 " float fFour;\n"
3702 " vec3 fZeroZeroOne;\n"
3703 " float fFive;\n"
3704 " vec3 fZeroOneZero;\n"
3705 " float fSix;\n"
3706 " float fSeven;\n"
3707 " float fEight;\n"
3708 " float fNine;\n"
3709 " vec2 fZeroZero;\n"
3710 " vec2 fZeroOne;\n"
3711 " vec4 fBlue;\n"
3712 " vec2 fOneZero;\n"
3713 " vec2 fOneOne;\n"
3714 " vec3 fZeroOneOne;\n"
3715 " float fTen;\n"
3716 " float fEleven;\n"
3717 " float fTwelve;\n"
3718 " vec3 fOneZeroZero;\n"
3719 " vec4 uvOffsets[4];\n"
3720 "};\n"
3721 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003722 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003723 "void main() {\n"
3724 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3725 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3726 " \n"
3727
3728 // start with GS value to ensure it passed
3729 " vec4 outColor = color;\n"
3730
3731 // do some exact comparisons, even though we should
3732 // really have an epsilon involved.
3733 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3734 " outColor = wrong;\n"
3735 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3736 " outColor = wrong;\n"
3737 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3738 " outColor = wrong;\n"
3739 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3740 " outColor = wrong;\n"
3741 " if (fTwo != 2.0)\n"
3742 " outColor = wrong;\n"
3743 " if (fOneOne != vec2(1.0, 1.0))\n"
3744 " outColor = wrong;\n"
3745 " if (fTen != 10.0)\n"
3746 " outColor = wrong;\n"
3747 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3748 " outColor = wrong;\n"
3749 " \n"
GregFd6ebdb32015-06-03 18:40:50 -06003750 " uFragColor = outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003751 "}\n";
3752
3753
3754 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3755 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3756 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3757 0.0, 1.0, 0.0, 1.0, // align
3758 0.0, 0.0, 1.0, 1.0, // align
3759 0.0, 0.0, 0.0, 1.0, // align
3760 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3761 0.0, 2.0, 0.0, 2.0, // align
3762 0.0, 0.0, 2.0, 2.0, // align
3763 0.0, 0.0, 0.0, 2.0, // align
3764 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3765 0.0, 3.0, 0.0, 3.0, // align
3766 0.0, 0.0, 3.0, 3.0, // align
3767 0.0, 0.0, 0.0, 3.0, // align
3768 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3769 0.0, 4.0, 0.0, 4.0, // align
3770 0.0, 0.0, 4.0, 4.0, // align
3771 0.0, 0.0, 0.0, 4.0, // align
3772 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3773 0.0, 5.0, 0.0, 5.0, // align
3774 0.0, 0.0, 5.0, 5.0, // align
3775 0.0, 0.0, 0.0, 5.0, // align
3776 6.0, 0.0, 0.0, 6.0, // align
3777 0.0, 6.0, 0.0, 6.0, // align
3778 0.0, 0.0, 6.0, 6.0, // align
3779 0.0, 0.0, 0.0, 6.0, // align
3780 7.0, 0.0, 0.0, 7.0, // align
3781 0.0, 7.0, 0.0, 7.0, // align
3782 0.0, 0.0, 7.0, 7.0, // align
3783 0.0, 0.0, 0.0, 7.0, // align
3784 8.0, 0.0, 0.0, 8.0, // align
3785 0.0, 8.0, 0.0, 8.0, // align
3786 0.0, 0.0, 8.0, 8.0, // align
3787 0.0, 0.0, 0.0, 8.0, // align
3788 0.0, // float fZero; // align
3789 1.0, // float fOne; // pack
3790 2.0, // float fTwo; // pack
3791 3.0, // float fThree; // pack
3792 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3793 4.0, // float fFour; // pack
3794 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3795 5.0, // float fFive; // pack
3796 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3797 6.0, // float fSix; // pack
3798 7.0, // float fSeven; // align
3799 8.0, // float fEight; // pack
3800 9.0, // float fNine; // pack
3801 0.0, // BUFFER
3802 0.0, 0.0, // vec2 fZeroZero; // align
3803 0.0, 1.0, // vec2 fZeroOne; // pack
3804 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3805 1.0, 0.0, // vec2 fOneZero; // align
3806 1.0, 1.0, // vec2 fOneOne; // pack
3807 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3808 10.0, // float fTen; // pack
3809 11.0, // float fEleven; // align
3810 12.0, // float fTwelve; // pack
3811 0.0, 0.0, // BUFFER
3812 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3813 0.0, // BUFFER
3814 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3815 0.5, 0.6, 0.7, 0.8, // align
3816 0.9, 1.0, 1.1, 1.2, // align
3817 1.3, 1.4, 1.5, 1.6, // align
3818 };
3819
3820
3821
3822 ASSERT_NO_FATAL_FAILURE(InitState());
3823 ASSERT_NO_FATAL_FAILURE(InitViewport());
3824
3825 const int constCount = sizeof(mixedVals) / sizeof(float);
3826
3827 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3828 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3829 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3830
3831 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
3832
3833 VkPipelineObj pipelineobj(m_device);
3834 pipelineobj.AddShader(&vs);
3835 pipelineobj.AddShader(&gs);
3836 pipelineobj.AddShader(&ps);
3837
3838 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3839 VkCommandBufferObj cmdBuffer(m_device);
3840 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3841
3842 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3843
3844 VkDescriptorSetObj descriptorSet(m_device);
3845 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
3846
3847 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3848
3849 // render triangle
3850 cmdBuffer.Draw(0, 3, 0, 1);
3851
3852 // finalize recording of the command buffer
3853 EndCommandBuffer(cmdBuffer);
3854 cmdBuffer.QueueCommandBuffer();
3855
3856 RecordImages(m_renderTargets);
3857}
3858
3859TEST_F(VkRenderTest, GSPositions)
3860{
3861 // This test adds more inputs from the vertex shader and perturbs positions
3862 // Expected result is white triangle with weird positions
3863
3864 static const char *vertShaderText =
3865 "#version 140\n"
3866 "#extension GL_ARB_separate_shader_objects : enable\n"
3867 "#extension GL_ARB_shading_language_420pack : enable\n"
3868
3869 "layout(location = 0) out vec3 out_a;\n"
3870 "layout(location = 1) out vec3 out_b;\n"
3871 "layout(location = 2) out vec3 out_c;\n"
3872
3873 "void main() {\n"
3874
3875 // write a solid color to each
3876 " out_a = vec3(1.0, 0.0, 0.0);\n"
3877 " out_b = vec3(0.0, 1.0, 0.0);\n"
3878 " out_c = vec3(0.0, 0.0, 1.0);\n"
3879
3880 // generic position stuff
3881 " vec2 vertices;\n"
3882 " int vertexSelector = gl_VertexID;\n"
3883 " if (vertexSelector == 0)\n"
3884 " vertices = vec2(-0.5, -0.5);\n"
3885 " else if (vertexSelector == 1)\n"
3886 " vertices = vec2( 0.5, -0.5);\n"
3887 " else if (vertexSelector == 2)\n"
3888 " vertices = vec2( 0.5, 0.5);\n"
3889 " else\n"
3890 " vertices = vec2( 0.0, 0.0);\n"
3891 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3892
3893 "}\n";
3894
3895 static const char *geomShaderText =
3896 "#version 330\n"
3897 "#extension GL_ARB_separate_shader_objects : enable\n"
3898 "#extension GL_ARB_shading_language_420pack : enable\n"
3899 "layout( triangles ) in;\n"
3900 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3901
3902 "layout(location = 0) in vec3 in_a[3];\n"
3903 "layout(location = 1) in vec3 in_b[3];\n"
3904 "layout(location = 2) in vec3 in_c[3];\n"
3905
3906 "layout(location = 0) out vec3 out_a;\n"
3907 "layout(location = 1) out vec3 out_b;\n"
3908 "layout(location = 2) out vec3 out_c;\n"
3909
3910 "void main()\n"
3911 "{\n"
3912
3913 " gl_Position = gl_in[0].gl_Position;\n"
3914 " gl_Position.xy *= vec2(0.75);\n"
3915 " out_a = in_a[0];\n"
3916 " out_b = in_b[0];\n"
3917 " out_c = in_c[0];\n"
3918 " EmitVertex();\n"
3919
3920 " gl_Position = gl_in[1].gl_Position;\n"
3921 " gl_Position.xy *= vec2(1.5);\n"
3922 " out_a = in_a[1];\n"
3923 " out_b = in_b[1];\n"
3924 " out_c = in_c[1];\n"
3925 " EmitVertex();\n"
3926
3927 " gl_Position = gl_in[2].gl_Position;\n"
3928 " gl_Position.xy *= vec2(-0.1);\n"
3929 " out_a = in_a[2];\n"
3930 " out_b = in_b[2];\n"
3931 " out_c = in_c[2];\n"
3932 " EmitVertex();\n"
3933
3934 " EndPrimitive();\n"
3935 "}\n";
3936
3937
3938 static const char *fragShaderText =
3939 "#version 140\n"
3940 "#extension GL_ARB_separate_shader_objects : enable\n"
3941 "#extension GL_ARB_shading_language_420pack : enable\n"
3942
3943 "layout(location = 0) in vec3 in_a;\n"
3944 "layout(location = 1) in vec3 in_b;\n"
3945 "layout(location = 2) in vec3 in_c;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003946 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003947
3948 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06003949 " outColor = vec4(in_a.x, in_b.y, in_c.z, 1.0);\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003950 "}\n";
3951
3952
3953
3954 ASSERT_NO_FATAL_FAILURE(InitState());
3955 ASSERT_NO_FATAL_FAILURE(InitViewport());
3956
3957 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3958 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3959 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3960
3961 VkPipelineObj pipelineobj(m_device);
3962 pipelineobj.AddShader(&vs);
3963 pipelineobj.AddShader(&gs);
3964 pipelineobj.AddShader(&ps);
3965
3966 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3967 VkCommandBufferObj cmdBuffer(m_device);
3968 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3969
3970 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3971
3972 VkDescriptorSetObj descriptorSet(m_device);
3973
3974 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3975
3976 // render triangle
3977 cmdBuffer.Draw(0, 3, 0, 1);
3978
3979 // finalize recording of the command buffer
3980 EndCommandBuffer(cmdBuffer);
3981 cmdBuffer.QueueCommandBuffer();
3982
3983 RecordImages(m_renderTargets);
3984}
3985
3986TEST_F(VkRenderTest, GSTriStrip)
3987{
3988 // This test emits multiple multiple triangles using a GS
3989 // Correct result is an multicolor circle
3990
3991 static const char *vertShaderText =
3992 "#version 140\n"
3993 "#extension GL_ARB_separate_shader_objects : enable\n"
3994 "#extension GL_ARB_shading_language_420pack : enable\n"
3995
3996 "void main() {\n"
3997
3998 // generic position stuff
3999 " vec2 vertices;\n"
4000 " int vertexSelector = gl_VertexID;\n"
4001 " if (vertexSelector == 0)\n"
4002 " vertices = vec2(-0.5, -0.5);\n"
4003 " else if (vertexSelector == 1)\n"
4004 " vertices = vec2( 0.5, -0.5);\n"
4005 " else if (vertexSelector == 2)\n"
4006 " vertices = vec2( 0.5, 0.5);\n"
4007 " else\n"
4008 " vertices = vec2( 0.0, 0.0);\n"
4009 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
4010
4011 "}\n";
4012
4013 static const char *geomShaderText =
4014 "#version 330\n"
4015 "#extension GL_ARB_separate_shader_objects : enable\n"
4016 "#extension GL_ARB_shading_language_420pack : enable\n"
4017 "layout( triangles ) in;\n"
4018 "layout( triangle_strip, max_vertices = 18 ) out;\n"
4019
4020 "layout(location = 0) out vec4 outColor;\n"
4021
4022 "void main()\n"
4023 "{\n"
4024 // init with first position to get zw
4025 " gl_Position = gl_in[0].gl_Position;\n"
4026
4027 " vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
4028 " vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
4029 " vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
4030 " vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
4031
4032 // different color per tri
4033 " vec4[6] colors = { red, white, \n"
4034 " yellow, white, \n"
4035 " blue, white }; \n"
4036
4037 // fan out the triangles
4038 " vec2[18] positions = { vec2(0.0, 0.0), vec2(-0.5, 0.0), vec2(-0.25, -0.5), \n"
4039 " vec2(0.0, 0.0), vec2(-0.25, -0.5), vec2( 0.25, -0.5), \n"
4040 " vec2(0.0, 0.0), vec2( 0.25, -0.5), vec2( 0.5, 0.0), \n"
4041 " vec2(0.0, 0.0), vec2( 0.5, 0.0), vec2( 0.25, 0.5), \n"
4042 " vec2(0.0, 0.0), vec2( 0.25, 0.5), vec2(-0.25, 0.5), \n"
4043 " vec2(0.0, 0.0), vec2(-0.25, 0.5), vec2(-0.5, 0.0) }; \n"
4044
4045 // make a triangle list of 6
4046 " for (int i = 0; i < 6; ++i) { \n"
4047 " outColor = colors[i]; \n"
4048 " for (int j = 0; j < 3; ++j) { \n"
4049 " gl_Position.xy = positions[i * 3 + j]; \n"
4050 " EmitVertex(); \n"
4051 " } \n"
4052 " EndPrimitive();\n"
4053 " } \n"
4054
4055 "}\n";
4056
4057
4058 static const char *fragShaderText =
4059 "#version 150\n"
4060 "#extension GL_ARB_separate_shader_objects : enable\n"
4061 "#extension GL_ARB_shading_language_420pack : enable\n"
4062
4063
4064 "layout(binding = 0) uniform windowDimensions {\n"
4065 " vec4 dimensions;\n"
4066 "};\n"
4067
4068 "layout(location = 0) in vec4 inColor;\n"
4069 "layout(origin_upper_left) in vec4 gl_FragCoord;\n"
GregFd6ebdb32015-06-03 18:40:50 -06004070 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06004071
4072 "void main() {\n"
4073
4074 // discard to make a nice circle
4075 " vec2 pos = abs(gl_FragCoord.xy) - vec2(dimensions.x, dimensions.y) / 2;\n"
4076 " float dist = sqrt(dot(pos, pos));\n"
4077 " if (dist > 50.0)\n"
4078 " discard;\n"
4079
GregFd6ebdb32015-06-03 18:40:50 -06004080 " outColor = inColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06004081
4082 "}\n";
4083
4084
4085
4086 ASSERT_NO_FATAL_FAILURE(InitState());
4087 ASSERT_NO_FATAL_FAILURE(InitViewport());
4088
4089 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
4090 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
4091 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
4092
4093 VkPipelineObj pipelineobj(m_device);
4094 pipelineobj.AddShader(&vs);
4095 pipelineobj.AddShader(&gs);
4096 pipelineobj.AddShader(&ps);
4097
4098 const float dimensions[4] = { VkRenderFramework::m_width, VkRenderFramework::m_height , 0.0, 0.0};
4099
4100 VkConstantBufferObj windowDimensions(m_device, sizeof(dimensions) / sizeof(dimensions[0]), sizeof(dimensions[0]), (const void*) dimensions);
4101
4102 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4103 VkCommandBufferObj cmdBuffer(m_device);
4104 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
4105
4106 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
4107
4108 VkDescriptorSetObj descriptorSet(m_device);
4109 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, windowDimensions);
4110
4111 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
4112
4113 // render triangle
4114 cmdBuffer.Draw(0, 3, 0, 1);
4115
4116 // finalize recording of the command buffer
4117 EndCommandBuffer(cmdBuffer);
4118 cmdBuffer.QueueCommandBuffer();
4119
4120 RecordImages(m_renderTargets);
4121}
4122
Chris Forbes23e6db62015-06-15 09:32:35 +12004123TEST_F(VkRenderTest, RenderPassLoadOpClear)
4124{
4125 ASSERT_NO_FATAL_FAILURE(InitState());
4126 ASSERT_NO_FATAL_FAILURE(InitViewport());
4127
4128 /* clear via load op to full green */
4129 m_clear_via_load_op = true;
Chris Forbese3105972015-06-24 14:34:53 +12004130 m_clear_color.f32[0] = 0;
4131 m_clear_color.f32[1] = 1;
4132 m_clear_color.f32[2] = 0;
4133 m_clear_color.f32[3] = 0;
Chris Forbes23e6db62015-06-15 09:32:35 +12004134 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4135
4136 VkCommandBufferObj cmdBuffer(m_device);
4137 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
4138 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
4139 /* This command buffer contains ONLY the load op! */
4140 EndCommandBuffer(cmdBuffer);
4141 cmdBuffer.QueueCommandBuffer();
4142
4143 RecordImages(m_renderTargets);
4144}
4145
Chris Forbes1e16cb82015-06-24 12:05:30 +12004146TEST_F(VkRenderTest, RenderPassAttachmentClear)
4147{
4148 ASSERT_NO_FATAL_FAILURE(InitState());
4149 ASSERT_NO_FATAL_FAILURE(InitViewport());
4150
4151 /* clear via load op to full red */
4152 m_clear_via_load_op = true;
Chris Forbese3105972015-06-24 14:34:53 +12004153 m_clear_color.f32[0] = 1;
4154 m_clear_color.f32[1] = 0;
4155 m_clear_color.f32[2] = 0;
4156 m_clear_color.f32[3] = 0;
Chris Forbes1e16cb82015-06-24 12:05:30 +12004157 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4158
4159 VkCommandBufferObj cmdBuffer(m_device);
4160 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
4161 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
4162
4163 /* Load op has cleared to red */
4164
4165 /* Draw, draw, draw... */
4166
4167 /* Now, partway through this renderpass we want to clear the color
4168 * attachment again, this time to green.
4169 */
Chris Forbese3105972015-06-24 14:34:53 +12004170 VkClearColorValue clear_color;
4171 clear_color.f32[0] = 0;
4172 clear_color.f32[1] = 1;
4173 clear_color.f32[2] = 0;
4174 clear_color.f32[3] = 0;
Chris Forbes1e16cb82015-06-24 12:05:30 +12004175 VkRect3D clear_rect = { { 0, 0, 0 }, { (int)m_width, (int)m_height, 1 } };
4176 vkCmdClearColorAttachment(cmdBuffer.obj(), 0,
4177 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4178 &clear_color, 1, &clear_rect);
4179
4180 EndCommandBuffer(cmdBuffer);
4181 cmdBuffer.QueueCommandBuffer();
4182
4183 RecordImages(m_renderTargets);
4184}
4185
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004186int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004187 int result;
4188
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004189 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06004190 VkTestFramework::InitArgs(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004191
Chia-I Wu7133fdc2014-12-15 23:57:34 +08004192 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06004193
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004194 result = RUN_ALL_TESTS();
4195
Tony Barbour01999182015-04-09 12:58:51 -06004196 VkTestFramework::Finish();
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004197 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004198}