blob: 0283370d7c19d1cf2a37c5fd9483ba8701a260fb [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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060071#include <vkDbg.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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060097 case VK_DBG_MSG_ERROR:
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()) {
329 cmdBuffer.EndRenderPass(renderPass());
330 }
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 //uint64_t objTrackGetObjectCount(VkObjectType type)
493 OBJ_TRACK_GET_OBJECTS_COUNT pObjTrackGetObjectsCount = (OBJ_TRACK_GET_OBJECTS_COUNT)vkGetProcAddr(gpu(), (char*)"objTrackGetObjectsCount");
494 uint64_t numObjects = pObjTrackGetObjectsCount();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600495 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700496 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600497 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700498 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
Mark Lobodzinski4e5016f2015-05-05 15:01:37 -0500499 pObjTrackGetObjs(numObjects, pObjNodeArray);
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700500 for (i=0; i < numObjects; i++) {
Mark Lobodzinski4e5016f2015-05-05 15:01:37 -0500501 printf("Object %i of type %s has objID (%p) and %lu uses\n", i, string_from_vulkan_object_type(pObjNodeArray[i].objType), pObjNodeArray[i].vkObj, pObjNodeArray[i].numUses);
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700502 }
503 free(pObjNodeArray);
504#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700505
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600506}
507
GregFd6ebdb32015-06-03 18:40:50 -0600508#if 0
509
Tony Barbour01999182015-04-09 12:58:51 -0600510TEST_F(VkRenderTest, VKTriangle_FragColor)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600511{
512 static const char *vertShaderText =
513 "#version 140\n"
514 "#extension GL_ARB_separate_shader_objects : enable\n"
515 "#extension GL_ARB_shading_language_420pack : enable\n"
516 "\n"
517 "layout(binding = 0) uniform buf {\n"
518 " mat4 MVP;\n"
519 " vec4 position[3];\n"
520 " vec4 color[3];\n"
521 "} ubuf;\n"
522 "\n"
523 "layout (location = 0) out vec4 outColor;\n"
524 "\n"
525 "void main() \n"
526 "{\n"
527 " outColor = ubuf.color[gl_VertexID];\n"
528 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
529 "}\n";
530
531 static const char *fragShaderText =
532 "#version 140\n"
533 "#extension GL_ARB_separate_shader_objects : enable\n"
534 "#extension GL_ARB_shading_language_420pack : enable\n"
535 "\n"
536 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600537 "layout (location = 0) out vec4 uFragColor;\n"
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600538 "\n"
539 "void main()\n"
540 "{\n"
GregFd6ebdb32015-06-03 18:40:50 -0600541 " uFragColor = inColor;\n"
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600542 "}\n";
543
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600544 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
545 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600546}
547
Tony Barbour01999182015-04-09 12:58:51 -0600548TEST_F(VkRenderTest, VKTriangle_OutputLocation)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600549{
550 static const char *vertShaderText =
551 "#version 140\n"
552 "#extension GL_ARB_separate_shader_objects : enable\n"
553 "#extension GL_ARB_shading_language_420pack : enable\n"
554 "\n"
555 "layout(binding = 0) uniform buf {\n"
556 " mat4 MVP;\n"
557 " vec4 position[3];\n"
558 " vec4 color[3];\n"
559 "} ubuf;\n"
560 "\n"
561 "layout (location = 0) out vec4 outColor;\n"
562 "\n"
563 "void main() \n"
564 "{\n"
565 " outColor = ubuf.color[gl_VertexID];\n"
566 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
567 "}\n";
568
569 static const char *fragShaderText =
570 "#version 140\n"
571 "#extension GL_ARB_separate_shader_objects : enable\n"
572 "#extension GL_ARB_shading_language_420pack : enable\n"
573 "\n"
574 "layout (location = 0) in vec4 inColor;\n"
575 "layout (location = 0) out vec4 outColor;\n"
576 "\n"
577 "void main()\n"
578 "{\n"
579 " outColor = inColor;\n"
580 "}\n";
581
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600582 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 -0600583
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600584 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600585}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600586#ifndef _WIN32 // Implicit (for now at least) in WIN32 is that we are using the Nvidia driver and it won't consume SPIRV yet
Tony Barbour01999182015-04-09 12:58:51 -0600587TEST_F(VkRenderTest, SPV_VKTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700588{
Tony Barbourf43b6982014-11-25 13:18:32 -0700589 static const char *vertShaderText =
590 "#version 140\n"
591 "#extension GL_ARB_separate_shader_objects : enable\n"
592 "#extension GL_ARB_shading_language_420pack : enable\n"
593 "\n"
594 "layout(binding = 0) uniform buf {\n"
595 " mat4 MVP;\n"
596 " vec4 position[3];\n"
597 " vec4 color[3];\n"
598 "} ubuf;\n"
599 "\n"
600 "layout (location = 0) out vec4 outColor;\n"
601 "\n"
602 "void main() \n"
603 "{\n"
604 " outColor = ubuf.color[gl_VertexID];\n"
605 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
606 "}\n";
607
608 static const char *fragShaderText =
609 "#version 140\n"
610 "#extension GL_ARB_separate_shader_objects : enable\n"
611 "#extension GL_ARB_shading_language_420pack : enable\n"
612 "\n"
613 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600614 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700615 "\n"
616 "void main()\n"
617 "{\n"
GregFd6ebdb32015-06-03 18:40:50 -0600618 " outColor = inColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700619 "}\n";
620
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600621 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 -0700622
Cody Northrop1cfbd172015-06-03 16:49:20 -0600623 ScopedUseGlsl useGlsl(false);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600624 VKTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700625}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600626#endif
Tony Barbour01999182015-04-09 12:58:51 -0600627TEST_F(VkRenderTest, GreenTriangle)
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600628{
629 static const char *vertShaderText =
630 "#version 130\n"
631 "vec2 vertices[3];\n"
632 "void main() {\n"
633 " vertices[0] = vec2(-1.0, -1.0);\n"
634 " vertices[1] = vec2( 1.0, -1.0);\n"
635 " vertices[2] = vec2( 0.0, 1.0);\n"
636 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
637 "}\n";
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600638
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600639 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600640 "#version 140\n"
641 "#extension GL_ARB_separate_shader_objects : enable\n"
642 "#extension GL_ARB_shading_language_420pack : enable\n"
643 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600644 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600645 " outColor = vec4(0,1,0,1);\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600646 "}\n";
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600647
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600648 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
649
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600650 VKTriangleTest(vertShaderText, fragShaderText, false);
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600651}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600652#ifndef _WIN32 // Implicit (for now at least) in WIN32 is that we are using the Nvidia driver and it won't consume SPIRV yet
Tony Barbour01999182015-04-09 12:58:51 -0600653TEST_F(VkRenderTest, SPV_GreenTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700654{
Tony Barbourf43b6982014-11-25 13:18:32 -0700655 static const char *vertShaderText =
656 "#version 130\n"
657 "vec2 vertices[3];\n"
658 "void main() {\n"
659 " vertices[0] = vec2(-1.0, -1.0);\n"
660 " vertices[1] = vec2( 1.0, -1.0);\n"
661 " vertices[2] = vec2( 0.0, 1.0);\n"
662 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
663 "}\n";
664
665 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600666 "#version 140\n"
667 "#extension GL_ARB_separate_shader_objects : enable\n"
668 "#extension GL_ARB_shading_language_420pack : enable\n"
669 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700670 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600671 " outColor = vec4(0,1,0,1);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700672 "}\n";
673
Cody Northropacfb0492015-03-17 15:55:58 -0600674 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700675
Cody Northrop1cfbd172015-06-03 16:49:20 -0600676 ScopedUseGlsl useGlsl(false);
677
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600678 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700679}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600680#endif
Tony Barbour01999182015-04-09 12:58:51 -0600681TEST_F(VkRenderTest, YellowTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700682{
683 static const char *vertShaderText =
684 "#version 130\n"
685 "void main() {\n"
686 " vec2 vertices[3];"
687 " vertices[0] = vec2(-0.5, -0.5);\n"
688 " vertices[1] = vec2( 0.5, -0.5);\n"
689 " vertices[2] = vec2( 0.5, 0.5);\n"
690 " vec4 colors[3];\n"
691 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
692 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
693 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
694 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
695 "}\n";
696
697 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600698 "#version 140\n"
699 "#extension GL_ARB_separate_shader_objects : enable\n"
700 "#extension GL_ARB_shading_language_420pack : enable\n"
701 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700702 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600703 " outColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700704 "}\n";
705
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600706 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700707}
708
Tony Barbour01999182015-04-09 12:58:51 -0600709TEST_F(VkRenderTest, QuadWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600710{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600711 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600712 "#version 140\n"
713 "#extension GL_ARB_separate_shader_objects : enable\n"
714 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700715 //XYZ1( -1, -1, -1 )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600716 "layout (location = 0) in vec4 pos;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700717 //XYZ1( 0.f, 0.f, 0.f )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600718 "layout (location = 1) in vec4 inColor;\n"
719 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600720 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600721 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600722 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600723 "}\n";
724
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600725
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600726 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700727 "#version 140\n"
728 "#extension GL_ARB_separate_shader_objects : enable\n"
729 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600730 "layout (location = 0) in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700731 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600732 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700733 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600734 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600735
Tony Barbourf43b6982014-11-25 13:18:32 -0700736
737
738 ASSERT_NO_FATAL_FAILURE(InitState());
739 ASSERT_NO_FATAL_FAILURE(InitViewport());
740
Tony Barbour01999182015-04-09 12:58:51 -0600741 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000742 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700743
Tony Barbour01999182015-04-09 12:58:51 -0600744 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
745 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700746
Tony Barbour01999182015-04-09 12:58:51 -0600747 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -0700748 pipelineobj.AddShader(&vs);
749 pipelineobj.AddShader(&ps);
750
Tony Barbour01999182015-04-09 12:58:51 -0600751 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600752 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -0600753
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600754#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600755 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600756 MESH_BIND_ID, // binding ID
Tony Barbourf43b6982014-11-25 13:18:32 -0700757 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600758 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -0700759 };
760
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600761 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600762 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
763 vi_attribs[0].location = 0; // location, position
Tony Barbour8205d902015-04-16 15:59:00 -0600764 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600765 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
766 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
767 vi_attribs[1].location = 1; // location, color
Tony Barbour8205d902015-04-16 15:59:00 -0600768 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600769 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 -0700770
771 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
772 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600773 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -0700774
Tony Barboure4ed9942015-01-09 10:06:53 -0700775 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600776 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700777 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700778
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600779 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600780
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600781 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700782
Tony Barboure4ed9942015-01-09 10:06:53 -0700783 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
784
785 // render two triangles
786 cmdBuffer.Draw(0, 6, 0, 1);
787
788 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600789 EndCommandBuffer(cmdBuffer);
790
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600791 cmdBuffer.QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -0700792
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600793 RecordImages(m_renderTargets);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600794}
795
Tony Barbour01999182015-04-09 12:58:51 -0600796TEST_F(VkRenderTest, TriangleMRT)
Chia-I Wue09d1a72014-12-05 10:32:23 +0800797{
798 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600799 "#version 140\n"
800 "#extension GL_ARB_separate_shader_objects : enable\n"
801 "#extension GL_ARB_shading_language_420pack : enable\n"
802 "layout (location = 0) in vec4 pos;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800803 "void main() {\n"
804 " gl_Position = pos;\n"
805 "}\n";
806
807 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600808 "#version 140\n"
809 "#extension GL_ARB_separate_shader_objects : enable\n"
810 "#extension GL_ARB_shading_language_420pack : enable\n"
811 "layout (location = 0) out vec4 uFragData0;\n"
812 "layout (location = 1) out vec4 uFragData1;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800813 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600814 " uFragData0 = vec4(1.0, 0.0, 0.0, 1.0);\n"
815 " uFragData1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800816 "}\n";
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600817 const float vb_data[][2] = {
Chia-I Wue09d1a72014-12-05 10:32:23 +0800818 { -1.0f, -1.0f },
819 { 1.0f, -1.0f },
820 { -1.0f, 1.0f }
821 };
822
823 ASSERT_NO_FATAL_FAILURE(InitState());
824 ASSERT_NO_FATAL_FAILURE(InitViewport());
825
Tony Barbour01999182015-04-09 12:58:51 -0600826 VkConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000827 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800828
Tony Barbour01999182015-04-09 12:58:51 -0600829 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
830 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800831
Tony Barbour01999182015-04-09 12:58:51 -0600832 VkPipelineObj pipelineobj(m_device);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800833 pipelineobj.AddShader(&vs);
834 pipelineobj.AddShader(&ps);
835
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600836#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600837 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600838 MESH_BUF_ID, // Binding ID
839 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600840 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Chia-I Wue09d1a72014-12-05 10:32:23 +0800841 };
842
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600843 VkVertexInputAttributeDescription vi_attrib;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600844 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
845 vi_attrib.location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -0600846 vi_attrib.format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600847 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
Chia-I Wue09d1a72014-12-05 10:32:23 +0800848
849 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
850 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600851 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800852
Tony Barbour01999182015-04-09 12:58:51 -0600853 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600854 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800855
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700856 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
Chia-I Wue09d1a72014-12-05 10:32:23 +0800857
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600858 VkPipelineCbAttachmentState att = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600859 att.blendEnable = VK_FALSE;
Chia-I Wue09d1a72014-12-05 10:32:23 +0800860 att.format = m_render_target_fmt;
861 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700862 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800863
Tony Barbour01999182015-04-09 12:58:51 -0600864 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700865
Tony Barbour5ed79702015-01-07 14:31:52 -0700866 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
867 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barboure4ed9942015-01-09 10:06:53 -0700868
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600869 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour5ed79702015-01-07 14:31:52 -0700870
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600871 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700872
Tony Barbour5ed79702015-01-07 14:31:52 -0700873 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700874#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600875 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour5ed79702015-01-07 14:31:52 -0700876 pDSDumpDot((char*)"triTest2.dot");
877#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600878
Tony Barbour5ed79702015-01-07 14:31:52 -0700879 // render triangle
880 cmdBuffer.Draw(0, 3, 0, 1);
881
882 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600883 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600884 cmdBuffer.QueueCommandBuffer();
Tony Barbour5ed79702015-01-07 14:31:52 -0700885
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600886 RecordImages(m_renderTargets);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800887}
888
Tony Barbour01999182015-04-09 12:58:51 -0600889TEST_F(VkRenderTest, QuadWithIndexedVertexFetch)
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700890{
891 static const char *vertShaderText =
892 "#version 140\n"
893 "#extension GL_ARB_separate_shader_objects : enable\n"
894 "#extension GL_ARB_shading_language_420pack : enable\n"
895 "layout(location = 0) in vec4 pos;\n"
896 "layout(location = 1) in vec4 inColor;\n"
897 "layout(location = 0) out vec4 outColor;\n"
898 "void main() {\n"
899 " outColor = inColor;\n"
900 " gl_Position = pos;\n"
901 "}\n";
902
903
904 static const char *fragShaderText =
905 "#version 140\n"
906 "#extension GL_ARB_separate_shader_objects : enable\n"
907 "#extension GL_ARB_shading_language_420pack : enable\n"
908 "layout(location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600909 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700910 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600911 " outColor = color;\n"
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700912 "}\n";
913
914 const Vertex g_vbData[] =
915 {
916 // first tri
917 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
918 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
919 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
920
921 // second tri
922 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
923 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
924 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
925 };
926
927 const uint16_t g_idxData[6] = {
928 0, 1, 2,
929 3, 4, 5,
930 };
931
932 ASSERT_NO_FATAL_FAILURE(InitState());
933 ASSERT_NO_FATAL_FAILURE(InitViewport());
934
Tony Barbour01999182015-04-09 12:58:51 -0600935 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000936 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700937
Tony Barbour01999182015-04-09 12:58:51 -0600938 VkIndexBufferObj indexBuffer(m_device);
Tony Barbour8205d902015-04-16 15:59:00 -0600939 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), VK_INDEX_TYPE_UINT16, g_idxData);
Mark Lobodzinskid30f82a2015-02-16 14:24:23 -0600940 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700941
Tony Barbour01999182015-04-09 12:58:51 -0600942 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
943 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700944
Tony Barbour01999182015-04-09 12:58:51 -0600945 VkPipelineObj pipelineobj(m_device);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700946 pipelineobj.AddShader(&vs);
947 pipelineobj.AddShader(&ps);
948
Tony Barbour01999182015-04-09 12:58:51 -0600949 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600950 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
951 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, indexBuffer);
Tony Barbour83a83802015-04-02 15:43:15 -0600952
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700953
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600954#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600955 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600956 MESH_BIND_ID, // binding ID
957 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600958 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700959 };
960
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600961 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600962 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
963 vi_attribs[0].location = 0; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600964 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600965 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
966 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
967 vi_attribs[1].location = 1; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600968 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600969 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700970
971 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
972 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700973
974 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600975 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700976 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600977 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barboure4ed9942015-01-09 10:06:53 -0700978
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600979 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700980
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700981#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600982 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700983 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700984#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700985
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600986 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600987 cmdBuffer.BindIndexBuffer(&indexBuffer, 0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700988
989 // render two triangles
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700990 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700991
992 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600993 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600994 cmdBuffer.QueueCommandBuffer();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700995
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600996 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700997}
998
Tony Barbour01999182015-04-09 12:58:51 -0600999TEST_F(VkRenderTest, GreyandRedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -07001000{
1001 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -07001002
GregF6bef1212014-12-02 15:41:44 -07001003 static const char *vertShaderText =
1004 "#version 140\n"
1005 "#extension GL_ARB_separate_shader_objects : enable\n"
1006 "#extension GL_ARB_shading_language_420pack : enable\n"
1007 "layout (location = 0) in vec4 pos;\n"
1008 "layout (location = 0) out vec4 outColor;\n"
1009 "layout (location = 1) out vec4 outColor2;\n"
1010 "void main() {\n"
1011 " gl_Position = pos;\n"
1012 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1013 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1014 "}\n";
1015
1016 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001017 "#version 330\n"
1018 "#extension GL_ARB_separate_shader_objects : enable\n"
1019 "#extension GL_ARB_shading_language_420pack : enable\n"
1020 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1021 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1022 "layout (location = 0) in vec4 color;\n"
1023 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001024 "layout (location = 0) out vec4 outColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001025 "void main() {\n"
1026 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1027 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001028 " outColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001029 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1030 " : color2;\n"
1031 "}\n";
1032
1033 ASSERT_NO_FATAL_FAILURE(InitState());
1034 ASSERT_NO_FATAL_FAILURE(InitViewport());
1035
Tony Barbour01999182015-04-09 12:58:51 -06001036 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001037 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001038
Tony Barbour01999182015-04-09 12:58:51 -06001039 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1040 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001041
Tony Barbour01999182015-04-09 12:58:51 -06001042 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001043 pipelineobj.AddShader(&vs);
1044 pipelineobj.AddShader(&ps);
1045
Tony Barbour01999182015-04-09 12:58:51 -06001046 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001047 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001048
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001049#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001050 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001051 MESH_BIND_ID, // binding ID
1052 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001053 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001054 };
1055
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001056 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001057 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1058 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001059 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001060 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001061
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001062 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001063 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001064 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001065
Tony Barbourdd4c9642015-01-09 12:55:14 -07001066 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001067 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001068 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1069
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001070 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001071
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001072 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001073
1074 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1075#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001076 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001077 pDSDumpDot((char*)"triTest2.dot");
1078#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001079
Tony Barbourdd4c9642015-01-09 12:55:14 -07001080 // render triangle
1081 cmdBuffer.Draw(0, 6, 0, 1);
1082
1083 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001084 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001085 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001086
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001087 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001088}
1089
GregFd6ebdb32015-06-03 18:40:50 -06001090//good
1091
1092
1093
Tony Barbour01999182015-04-09 12:58:51 -06001094TEST_F(VkRenderTest, RedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -07001095{
1096 // This tests that we correctly handle unread fragment inputs
1097
1098 static const char *vertShaderText =
1099 "#version 140\n"
1100 "#extension GL_ARB_separate_shader_objects : enable\n"
1101 "#extension GL_ARB_shading_language_420pack : enable\n"
1102 "layout (location = 0) in vec4 pos;\n"
1103 "layout (location = 0) out vec4 outColor;\n"
1104 "layout (location = 1) out vec4 outColor2;\n"
1105 "void main() {\n"
1106 " gl_Position = pos;\n"
1107 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1108 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1109 "}\n";
1110
1111 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001112 "#version 330\n"
1113 "#extension GL_ARB_separate_shader_objects : enable\n"
1114 "#extension GL_ARB_shading_language_420pack : enable\n"
1115 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1116 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1117 "layout (location = 0) in vec4 color;\n"
1118 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001119 "layout (location = 0) out vec4 outColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001120 "void main() {\n"
1121 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1122 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001123 " outColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001124 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1125 " : color2;\n"
1126 "}\n";
1127
1128 ASSERT_NO_FATAL_FAILURE(InitState());
1129 ASSERT_NO_FATAL_FAILURE(InitViewport());
1130
Tony Barbour01999182015-04-09 12:58:51 -06001131 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001132 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001133
Tony Barbour01999182015-04-09 12:58:51 -06001134 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1135 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001136
Tony Barbour01999182015-04-09 12:58:51 -06001137 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001138 pipelineobj.AddShader(&vs);
1139 pipelineobj.AddShader(&ps);
1140
Tony Barbour01999182015-04-09 12:58:51 -06001141 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001142 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001143
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001144#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001145 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001146 MESH_BIND_ID, // binding ID
1147 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001148 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001149 };
1150
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001151 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001152 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1153 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001154 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001155 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001156
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001157 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001158 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001159 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001160
Tony Barbourdd4c9642015-01-09 12:55:14 -07001161 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001162 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001163 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1164
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001165 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001166
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001167 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001168
1169 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1170#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001171 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001172 pDSDumpDot((char*)"triTest2.dot");
1173#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001174 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001175 cmdBuffer.Draw(0, 6, 0, 1);
1176
1177 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001178 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001179 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001180
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001181 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001182}
1183
Tony Barbour01999182015-04-09 12:58:51 -06001184TEST_F(VkRenderTest, GreyCirclesonBlueFade)
GregF6bef1212014-12-02 15:41:44 -07001185{
1186 // This tests reading gl_ClipDistance from FS
1187
1188 static const char *vertShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001189 //"#version 140\n"
GregF6bef1212014-12-02 15:41:44 -07001190 "#version 330\n"
1191 "#extension GL_ARB_separate_shader_objects : enable\n"
1192 "#extension GL_ARB_shading_language_420pack : enable\n"
1193 "out gl_PerVertex {\n"
1194 " vec4 gl_Position;\n"
1195 " float gl_ClipDistance[1];\n"
1196 "};\n"
1197 "layout (location = 0) in vec4 pos;\n"
1198 "layout (location = 0) out vec4 outColor;\n"
1199 "layout (location = 1) out vec4 outColor2;\n"
1200 "void main() {\n"
1201 " gl_Position = pos;\n"
1202 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1203 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1204 " float dists[3];\n"
1205 " dists[0] = 0.0;\n"
1206 " dists[1] = 1.0;\n"
1207 " dists[2] = 1.0;\n"
1208 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1209 "}\n";
1210
1211
1212 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001213 "#version 140\n"
1214 //"#version 330\n"
GregF6bef1212014-12-02 15:41:44 -07001215 "#extension GL_ARB_separate_shader_objects : enable\n"
1216 "#extension GL_ARB_shading_language_420pack : enable\n"
1217 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1218 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1219 "layout (location = 0) in vec4 color;\n"
1220 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001221 "layout (location = 0) out vec4 uFragColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001222 "void main() {\n"
1223 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1224 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001225 " uFragColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001226 " ? color * gl_ClipDistance[0]\n"
1227 " : color2;\n"
1228 "}\n";
1229
1230 ASSERT_NO_FATAL_FAILURE(InitState());
1231 ASSERT_NO_FATAL_FAILURE(InitViewport());
1232
Tony Barbour01999182015-04-09 12:58:51 -06001233 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001234 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001235
Tony Barbour01999182015-04-09 12:58:51 -06001236 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1237 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001238
Tony Barbour01999182015-04-09 12:58:51 -06001239 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001240 pipelineobj.AddShader(&vs);
1241 pipelineobj.AddShader(&ps);
1242
Tony Barbour01999182015-04-09 12:58:51 -06001243 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001244 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001245
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001246#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001247 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001248 MESH_BIND_ID, // binding ID
1249 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001250 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001251 };
1252
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001253 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001254 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1255 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001256 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001257 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001258
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001259 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001260 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001261 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001262
Tony Barbourdd4c9642015-01-09 12:55:14 -07001263 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001264 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001265 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF6bef1212014-12-02 15:41:44 -07001266
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001267 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001268
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001269 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001270
1271 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1272#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001273 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001274 pDSDumpDot((char*)"triTest2.dot");
1275#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001276
1277 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001278 cmdBuffer.Draw(0, 6, 0, 1);
1279
1280 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001281 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001282 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001283
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001284 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001285}
Tony Barbourf43b6982014-11-25 13:18:32 -07001286
Tony Barbour01999182015-04-09 12:58:51 -06001287TEST_F(VkRenderTest, GreyCirclesonBlueDiscard)
GregF7a23c792014-12-02 17:19:34 -07001288{
1289 static const char *vertShaderText =
1290 "#version 140\n"
1291 "#extension GL_ARB_separate_shader_objects : enable\n"
1292 "#extension GL_ARB_shading_language_420pack : enable\n"
1293 "layout (location = 0) in vec4 pos;\n"
1294 "layout (location = 0) out vec4 outColor;\n"
1295 "layout (location = 1) out vec4 outColor2;\n"
1296 "void main() {\n"
1297 " gl_Position = pos;\n"
1298 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1299 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1300 "}\n";
1301
1302
1303 static const char *fragShaderText =
GregF7a23c792014-12-02 17:19:34 -07001304 "#version 330\n"
1305 "#extension GL_ARB_separate_shader_objects : enable\n"
1306 "#extension GL_ARB_shading_language_420pack : enable\n"
1307 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1308 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1309 "layout (location = 0) in vec4 color;\n"
1310 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001311 "layout (location = 0) out vec4 outColor;\n"
GregF7a23c792014-12-02 17:19:34 -07001312 "void main() {\n"
1313 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1314 " float dist_squared = dot(pos, pos);\n"
1315 " if (dist_squared < 100.0)\n"
1316 " discard;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001317 " outColor = (dist_squared < 400.0)\n"
GregF7a23c792014-12-02 17:19:34 -07001318 " ? color\n"
1319 " : color2;\n"
1320 "}\n";
1321
1322 ASSERT_NO_FATAL_FAILURE(InitState());
1323 ASSERT_NO_FATAL_FAILURE(InitViewport());
1324
Tony Barbour01999182015-04-09 12:58:51 -06001325 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001326 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001327
Tony Barbour01999182015-04-09 12:58:51 -06001328 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1329 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF7a23c792014-12-02 17:19:34 -07001330
Tony Barbour01999182015-04-09 12:58:51 -06001331 VkPipelineObj pipelineobj(m_device);
GregF7a23c792014-12-02 17:19:34 -07001332 pipelineobj.AddShader(&vs);
1333 pipelineobj.AddShader(&ps);
1334
Tony Barbour01999182015-04-09 12:58:51 -06001335 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001336 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001337
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001338#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001339 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001340 MESH_BIND_ID, // binding ID
1341 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001342 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF7a23c792014-12-02 17:19:34 -07001343 };
1344
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001345 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001346 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1347 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001348 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001349 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF7a23c792014-12-02 17:19:34 -07001350
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001351 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF7a23c792014-12-02 17:19:34 -07001352 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001353 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF7a23c792014-12-02 17:19:34 -07001354
Tony Barbourdd4c9642015-01-09 12:55:14 -07001355 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001356 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001357 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1358
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001359 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001360
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001361 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001362
1363 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1364#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001365 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001366 pDSDumpDot((char*)"triTest2.dot");
1367#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001368
1369 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001370 cmdBuffer.Draw(0, 6, 0, 1);
1371
1372 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001373 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001374 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001375
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001376 RecordImages(m_renderTargets);
GregF7a23c792014-12-02 17:19:34 -07001377}
1378
1379
Tony Barbour01999182015-04-09 12:58:51 -06001380TEST_F(VkRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001381{
1382 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001383 "#version 140\n"
1384 "#extension GL_ARB_separate_shader_objects : enable\n"
1385 "#extension GL_ARB_shading_language_420pack : enable\n"
1386 "\n"
1387 "layout(binding = 0) uniform buf {\n"
1388 " mat4 MVP;\n"
1389 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001390 "void main() {\n"
1391 " vec2 vertices[3];"
1392 " vertices[0] = vec2(-0.5, -0.5);\n"
1393 " vertices[1] = vec2( 0.5, -0.5);\n"
1394 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001395 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001396 "}\n";
1397
1398 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001399 "#version 140\n"
1400 "#extension GL_ARB_separate_shader_objects : enable\n"
1401 "#extension GL_ARB_shading_language_420pack : enable\n"
1402 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001403 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001404 " outColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001405 "}\n";
1406
Tony Barbourf43b6982014-11-25 13:18:32 -07001407 ASSERT_NO_FATAL_FAILURE(InitState());
1408 ASSERT_NO_FATAL_FAILURE(InitViewport());
1409
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001410 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001411 glm::mat4 Projection = glm::mat4(1.0f);
1412 glm::mat4 View = glm::mat4(1.0f);
1413 glm::mat4 Model = glm::mat4(1.0f);
1414 glm::mat4 MVP = Projection * View * Model;
1415 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1416
Tony Barbour01999182015-04-09 12:58:51 -06001417 VkConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1418 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1419 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001420
Tony Barbour01999182015-04-09 12:58:51 -06001421 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001422 pipelineobj.AddShader(&vs);
1423 pipelineobj.AddShader(&ps);
1424
1425 // Create descriptor set and attach the constant buffer to it
Tony Barbour01999182015-04-09 12:58:51 -06001426 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001427 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001428
Tony Barbourdd4c9642015-01-09 12:55:14 -07001429 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001430 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001431 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001432
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001433 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001434
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001435 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001436
1437 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1438#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001439 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001440 pDSDumpDot((char*)"triTest2.dot");
1441#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001442
1443 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001444 cmdBuffer.Draw(0, 6, 0, 1);
1445
1446 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001447 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001448 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001449
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001450 RecordImages(m_renderTargets);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001451
1452 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001453}
1454
Tony Barbour01999182015-04-09 12:58:51 -06001455TEST_F(VkRenderTest, MixTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07001456{
1457 // This tests location applied to varyings. Notice that we have switched foo
1458 // and bar in the FS. The triangle should be blended with red, green and blue
1459 // corners.
1460 static const char *vertShaderText =
1461 "#version 140\n"
1462 "#extension GL_ARB_separate_shader_objects : enable\n"
1463 "#extension GL_ARB_shading_language_420pack : enable\n"
1464 "layout (location=0) out vec4 bar;\n"
1465 "layout (location=1) out vec4 foo;\n"
1466 "layout (location=2) out float scale;\n"
1467 "vec2 vertices[3];\n"
1468 "void main() {\n"
1469 " vertices[0] = vec2(-1.0, -1.0);\n"
1470 " vertices[1] = vec2( 1.0, -1.0);\n"
1471 " vertices[2] = vec2( 0.0, 1.0);\n"
1472 "vec4 colors[3];\n"
1473 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1474 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1475 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1476 " foo = colors[gl_VertexID % 3];\n"
1477 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1478 " scale = 1.0;\n"
1479 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1480 "}\n";
1481
1482 static const char *fragShaderText =
1483 "#version 140\n"
1484 "#extension GL_ARB_separate_shader_objects : enable\n"
1485 "#extension GL_ARB_shading_language_420pack : enable\n"
1486 "layout (location = 1) in vec4 bar;\n"
1487 "layout (location = 0) in vec4 foo;\n"
1488 "layout (location = 2) in float scale;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001489 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001490 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001491 " outColor = bar * scale + foo * (1.0-scale);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001492 "}\n";
1493
1494 ASSERT_NO_FATAL_FAILURE(InitState());
1495 ASSERT_NO_FATAL_FAILURE(InitViewport());
1496
Tony Barbour01999182015-04-09 12:58:51 -06001497 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1498 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001499
Tony Barbour01999182015-04-09 12:58:51 -06001500 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001501 pipelineobj.AddShader(&vs);
1502 pipelineobj.AddShader(&ps);
1503
Tony Barbour01999182015-04-09 12:58:51 -06001504 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06001505 descriptorSet.AppendDummy();
Tony Barbourf43b6982014-11-25 13:18:32 -07001506
Tony Barbourdd4c9642015-01-09 12:55:14 -07001507 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001508 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001509 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1510
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001511 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001512
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001513 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001514
1515#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001516 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001517 pDSDumpDot((char*)"triTest2.dot");
1518#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001519
Tony Barbourdd4c9642015-01-09 12:55:14 -07001520 // render triangle
1521 cmdBuffer.Draw(0, 3, 0, 1);
1522
1523 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001524 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001525 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001526
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001527 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001528}
1529
Tony Barbour01999182015-04-09 12:58:51 -06001530TEST_F(VkRenderTest, QuadVertFetchAndVertID)
Tony Barbourf43b6982014-11-25 13:18:32 -07001531{
1532 // This tests that attributes work in the presence of gl_VertexID
1533
1534 static const char *vertShaderText =
1535 "#version 140\n"
1536 "#extension GL_ARB_separate_shader_objects : enable\n"
1537 "#extension GL_ARB_shading_language_420pack : enable\n"
1538 //XYZ1( -1, -1, -1 )
1539 "layout (location = 0) in vec4 pos;\n"
1540 //XYZ1( 0.f, 0.f, 0.f )
1541 "layout (location = 1) in vec4 inColor;\n"
1542 "layout (location = 0) out vec4 outColor;\n"
1543 "void main() {\n"
1544 " outColor = inColor;\n"
1545 " vec4 vertices[3];"
1546 " vertices[gl_VertexID % 3] = pos;\n"
1547 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1548 "}\n";
1549
1550
1551 static const char *fragShaderText =
1552 "#version 140\n"
1553 "#extension GL_ARB_separate_shader_objects : enable\n"
1554 "#extension GL_ARB_shading_language_420pack : enable\n"
1555 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001556 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001557 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001558 " outColor = color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001559 "}\n";
1560
1561 ASSERT_NO_FATAL_FAILURE(InitState());
1562 ASSERT_NO_FATAL_FAILURE(InitViewport());
1563
Tony Barbour01999182015-04-09 12:58:51 -06001564 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001565 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001566
Tony Barbour01999182015-04-09 12:58:51 -06001567 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1568 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001569
Tony Barbour01999182015-04-09 12:58:51 -06001570 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001571 pipelineobj.AddShader(&vs);
1572 pipelineobj.AddShader(&ps);
1573
Tony Barbour01999182015-04-09 12:58:51 -06001574 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001575 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001576
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001577#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001578 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001579 MESH_BUF_ID, // Binding ID
1580 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001581 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001582 };
1583
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001584 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001585 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1586 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001587 vi_attribs[0].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001588 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1589 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1590 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001591 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001592 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001593
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001594 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001595 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001596 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001597
Tony Barbourdd4c9642015-01-09 12:55:14 -07001598 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001599 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001600 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1601
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001602 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001603
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001604 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001605
1606 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1607#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001608 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001609 pDSDumpDot((char*)"triTest2.dot");
1610#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001611
1612 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001613 cmdBuffer.Draw(0, 6, 0, 1);
1614
1615 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001616 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001617 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001618
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001619 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001620}
1621
Tony Barbour01999182015-04-09 12:58:51 -06001622TEST_F(VkRenderTest, QuadSparseVertFetch)
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001623{
1624 // This tests that attributes work in the presence of gl_VertexID
1625
1626 static const char *vertShaderText =
1627 "#version 140\n"
1628 "#extension GL_ARB_separate_shader_objects : enable\n"
1629 "#extension GL_ARB_shading_language_420pack : enable\n"
1630 //XYZ1( -1, -1, -1 )
1631 "layout (location = 1) in vec4 pos;\n"
1632 "layout (location = 4) in vec4 inColor;\n"
1633 //XYZ1( 0.f, 0.f, 0.f )
1634 "layout (location = 0) out vec4 outColor;\n"
1635 "void main() {\n"
1636 " outColor = inColor;\n"
1637 " gl_Position = pos;\n"
1638 "}\n";
1639
1640
1641 static const char *fragShaderText =
1642 "#version 140\n"
1643 "#extension GL_ARB_separate_shader_objects : enable\n"
1644 "#extension GL_ARB_shading_language_420pack : enable\n"
1645 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001646 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001647 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001648 " outColor = color;\n"
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001649 "}\n";
1650
1651 ASSERT_NO_FATAL_FAILURE(InitState());
1652 ASSERT_NO_FATAL_FAILURE(InitViewport());
1653
1654 struct VDATA
1655 {
1656 float t1, t2, t3, t4; // filler data
1657 float posX, posY, posZ, posW; // Position data
1658 float r, g, b, a; // Color
1659 };
1660 const struct VDATA vData[] =
1661 {
1662 { XYZ1(0, 0, 0), XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
1663 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1664 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1665 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1666 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1667 { XYZ1(0, 0, 0), XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
1668 };
1669
Tony Barbour01999182015-04-09 12:58:51 -06001670 VkConstantBufferObj meshBuffer(m_device,sizeof(vData)/sizeof(vData[0]),sizeof(vData[0]), vData);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001671 meshBuffer.BufferMemoryBarrier();
1672
Tony Barbour01999182015-04-09 12:58:51 -06001673 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1674 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001675
Tony Barbour01999182015-04-09 12:58:51 -06001676 VkPipelineObj pipelineobj(m_device);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001677 pipelineobj.AddShader(&vs);
1678 pipelineobj.AddShader(&ps);
1679
Tony Barbour01999182015-04-09 12:58:51 -06001680 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001681 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001682
1683#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001684 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001685 MESH_BUF_ID, // Binding ID
1686 sizeof(vData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001687 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001688 };
1689
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001690 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001691 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1692 vi_attribs[0].location = 4;
Tony Barbour8205d902015-04-16 15:59:00 -06001693 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001694 vi_attribs[0].offsetInBytes = sizeof(float) * 4 * 2; // Offset of first element in bytes from base of vertex
1695 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1696 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001697 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001698 vi_attribs[1].offsetInBytes = sizeof(float) * 4 * 1; // Offset of first element in bytes from base of vertex
1699
1700 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
1701 pipelineobj.AddVertexInputBindings(&vi_binding, 1);
1702 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
1703
1704 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001705 VkCommandBufferObj cmdBuffer(m_device);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001706 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1707
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001708 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001709
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001710 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001711
1712 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BUF_ID);
1713#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001714 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001715 pDSDumpDot((char*)"triTest2.dot");
1716#endif
1717
1718 // render two triangles
1719 cmdBuffer.Draw(0, 6, 0, 1);
1720
1721 // finalize recording of the command buffer
1722 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001723 cmdBuffer.QueueCommandBuffer();
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001724
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001725 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001726}
1727
Tony Barbour01999182015-04-09 12:58:51 -06001728TEST_F(VkRenderTest, TriVertFetchDeadAttr)
Tony Barbourf43b6982014-11-25 13:18:32 -07001729{
1730 // This tests that attributes work in the presence of gl_VertexID
1731 // and a dead attribute in position 0. Draws a triangle with yellow,
1732 // red and green corners, starting at top and going clockwise.
1733
1734 static const char *vertShaderText =
1735 "#version 140\n"
1736 "#extension GL_ARB_separate_shader_objects : enable\n"
1737 "#extension GL_ARB_shading_language_420pack : enable\n"
1738 //XYZ1( -1, -1, -1 )
1739 "layout (location = 0) in vec4 pos;\n"
1740 //XYZ1( 0.f, 0.f, 0.f )
1741 "layout (location = 1) in vec4 inColor;\n"
1742 "layout (location = 0) out vec4 outColor;\n"
1743 "void main() {\n"
1744 " outColor = inColor;\n"
1745 " vec2 vertices[3];"
1746 " vertices[0] = vec2(-1.0, -1.0);\n"
1747 " vertices[1] = vec2( 1.0, -1.0);\n"
1748 " vertices[2] = vec2( 0.0, 1.0);\n"
1749 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1750 "}\n";
1751
1752
1753 static const char *fragShaderText =
1754 "#version 140\n"
1755 "#extension GL_ARB_separate_shader_objects : enable\n"
1756 "#extension GL_ARB_shading_language_420pack : enable\n"
1757 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001758 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001759 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001760 " outColor = color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001761 "}\n";
1762
1763 ASSERT_NO_FATAL_FAILURE(InitState());
1764 ASSERT_NO_FATAL_FAILURE(InitViewport());
1765
Tony Barbour01999182015-04-09 12:58:51 -06001766 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001767 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001768
Tony Barbour01999182015-04-09 12:58:51 -06001769 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1770 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001771
Tony Barbour01999182015-04-09 12:58:51 -06001772 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001773 pipelineobj.AddShader(&vs);
1774 pipelineobj.AddShader(&ps);
1775
Tony Barbour01999182015-04-09 12:58:51 -06001776 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001777 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001778
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001779#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001780 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001781 MESH_BUF_ID, // Binding ID
1782 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001783 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001784 };
1785
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001786 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001787 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1788 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001789 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001790 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1791 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1792 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001793 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001794 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001795
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001796 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001797 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001798 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001799
Tony Barbourdd4c9642015-01-09 12:55:14 -07001800 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001801 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001802 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001803
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001804 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001805
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001806 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001807
1808 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1809#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001810 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001811 pDSDumpDot((char*)"triTest2.dot");
1812#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001813
1814 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001815 cmdBuffer.Draw(0, 6, 0, 1);
1816
1817 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001818 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001819 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001820
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001821 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001822}
1823
GregFd6ebdb32015-06-03 18:40:50 -06001824
1825// good
1826
1827
Tony Barbour01999182015-04-09 12:58:51 -06001828TEST_F(VkRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001829{
1830 static const char *vertShaderText =
1831 "#version 140\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001832 "#extension GL_ARB_separate_shader_objects : enable\n"
1833 "#extension GL_ARB_shading_language_420pack : enable\n"
GregFd6ebdb32015-06-03 18:40:50 -06001834 "layout (std140, binding = 0) uniform bufferVals {\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001835 " mat4 mvp;\n"
1836 "} myBufferVals;\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001837 "layout (location = 0) in vec4 pos;\n"
1838 "layout (location = 1) in vec4 inColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001839 "out vec4 outColor;\n"
1840 "void main() {\n"
1841 " outColor = inColor;\n"
1842 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001843 " gl_Position.y = -gl_Position.y;\n"
1844 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001845 "}\n";
1846
1847 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001848 "#version 140\n"
1849 "#extension GL_ARB_separate_shader_objects : enable\n"
1850 "#extension GL_ARB_shading_language_420pack : enable\n"
1851 "layout (location = 0) in vec4 color;\n"
1852 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001853 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001854 " outColor = color;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001855 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001856 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001857
Tony Barbourf43b6982014-11-25 13:18:32 -07001858 glm::mat4 View = glm::lookAt(
1859 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1860 glm::vec3(0,0,0), // and looks at the origin
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001861 glm::vec3(0,-1,0) // Head is up (set to 0,-1,0 to look upside-down)
Tony Barbourf43b6982014-11-25 13:18:32 -07001862 );
1863
1864 glm::mat4 Model = glm::mat4(1.0f);
1865
1866 glm::mat4 MVP = Projection * View * Model;
1867
1868 ASSERT_NO_FATAL_FAILURE(InitState());
1869 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour8bef8ee2015-05-22 09:44:58 -06001870 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07001871
Tony Barbour01999182015-04-09 12:58:51 -06001872 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 -07001873 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1874
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001875 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07001876
Tony Barbour01999182015-04-09 12:58:51 -06001877 VkConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1878 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1879 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001880
Tony Barbour01999182015-04-09 12:58:51 -06001881 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001882 pipelineobj.AddShader(&vs);
1883 pipelineobj.AddShader(&ps);
1884
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001885 VkPipelineDsStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001886 ds_state.depthTestEnable = VK_TRUE;
1887 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06001888 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001889 ds_state.depthBoundsEnable = VK_FALSE;
1890 ds_state.stencilTestEnable = VK_FALSE;
1891 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
1892 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
1893 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06001894 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
1895 ds_state.format = VK_FORMAT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001896 ds_state.front = ds_state.back;
1897 pipelineobj.SetDepthStencil(&ds_state);
1898
Tony Barbour01999182015-04-09 12:58:51 -06001899 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001900 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001901
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001902#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001903 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001904 MESH_BUF_ID, // Binding ID
1905 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001906 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001907 };
Tony Barbourf43b6982014-11-25 13:18:32 -07001908
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001909 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001910 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1911 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001912 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001913 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1914 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1915 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001916 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001917 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001918
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001919 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001920 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001921 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001922
Tony Barbour17c6ab12015-03-27 17:03:18 -06001923 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour17c6ab12015-03-27 17:03:18 -06001924
Tony Barbour01999182015-04-09 12:58:51 -06001925 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -07001926 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001927
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001928 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001929 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001930
Tony Barboure4ed9942015-01-09 10:06:53 -07001931 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1932#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001933 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barboure4ed9942015-01-09 10:06:53 -07001934 pDSDumpDot((char*)"triTest2.dot");
1935#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001936
1937 // render triangles
Tony Barboure4ed9942015-01-09 10:06:53 -07001938 cmdBuffer.Draw(0, 36, 0, 1);
1939
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001940
Tony Barboure4ed9942015-01-09 10:06:53 -07001941 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001942 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001943 cmdBuffer.QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -07001944
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001945 RecordImages(m_renderTargets);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001946}
1947
Tony Barbour01999182015-04-09 12:58:51 -06001948TEST_F(VkRenderTest, VSTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07001949{
1950 // The expected result from this test is a green and red triangle;
1951 // one red vertex on the left, two green vertices on the right.
1952 static const char *vertShaderText =
1953 "#version 130\n"
1954 "out vec4 texColor;\n"
1955 "uniform sampler2D surface;\n"
1956 "void main() {\n"
1957 " vec2 vertices[3];"
1958 " vertices[0] = vec2(-0.5, -0.5);\n"
1959 " vertices[1] = vec2( 0.5, -0.5);\n"
1960 " vertices[2] = vec2( 0.5, 0.5);\n"
1961 " vec2 positions[3];"
1962 " positions[0] = vec2( 0.0, 0.0);\n"
1963 " positions[1] = vec2( 0.25, 0.1);\n"
1964 " positions[2] = vec2( 0.1, 0.25);\n"
1965 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1966 " texColor = textureLod(surface, samplePos, 0.0);\n"
1967 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1968 "}\n";
1969
1970 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001971 "#version 140\n"
1972 "#extension GL_ARB_separate_shader_objects : enable\n"
1973 "#extension GL_ARB_shading_language_420pack : enable\n"
1974 "layout (location = 0) in vec4 texColor;\n"
1975 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001976 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001977 " outColor = texColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001978 "}\n";
1979
1980 ASSERT_NO_FATAL_FAILURE(InitState());
1981 ASSERT_NO_FATAL_FAILURE(InitViewport());
1982
Tony Barbour01999182015-04-09 12:58:51 -06001983 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1984 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
1985 VkSamplerObj sampler(m_device);
1986 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001987
Tony Barbour01999182015-04-09 12:58:51 -06001988 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001989 pipelineobj.AddShader(&vs);
1990 pipelineobj.AddShader(&ps);
1991
Tony Barbour01999182015-04-09 12:58:51 -06001992 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001993 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001994
Tony Barbourdd4c9642015-01-09 12:55:14 -07001995 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001996 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001997 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001998
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001999 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002000
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002001 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002002
2003#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002004 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002005 pDSDumpDot((char*)"triTest2.dot");
2006#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002007
Tony Barbourdd4c9642015-01-09 12:55:14 -07002008 // render triangle
2009 cmdBuffer.Draw(0, 3, 0, 1);
2010
2011 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002012 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002013 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002014
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002015 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002016}
GregFd6ebdb32015-06-03 18:40:50 -06002017
2018
2019
Tony Barbour01999182015-04-09 12:58:51 -06002020TEST_F(VkRenderTest, TexturedTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002021{
2022 // The expected result from this test is a red and green checkered triangle
2023 static const char *vertShaderText =
2024 "#version 140\n"
2025 "#extension GL_ARB_separate_shader_objects : enable\n"
2026 "#extension GL_ARB_shading_language_420pack : enable\n"
2027 "layout (location = 0) out vec2 samplePos;\n"
2028 "void main() {\n"
2029 " vec2 vertices[3];"
2030 " vertices[0] = vec2(-0.5, -0.5);\n"
2031 " vertices[1] = vec2( 0.5, -0.5);\n"
2032 " vertices[2] = vec2( 0.5, 0.5);\n"
2033 " vec2 positions[3];"
2034 " positions[0] = vec2( 0.0, 0.0);\n"
2035 " positions[1] = vec2( 1.0, 0.0);\n"
2036 " positions[2] = vec2( 1.0, 1.0);\n"
2037 " samplePos = positions[gl_VertexID % 3];\n"
2038 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2039 "}\n";
2040
2041 static const char *fragShaderText =
2042 "#version 140\n"
2043 "#extension GL_ARB_separate_shader_objects : enable\n"
2044 "#extension GL_ARB_shading_language_420pack : enable\n"
2045 "layout (location = 0) in vec2 samplePos;\n"
2046 "layout (binding = 0) uniform sampler2D surface;\n"
2047 "layout (location=0) out vec4 outColor;\n"
2048 "void main() {\n"
2049 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2050 " outColor = texColor;\n"
2051 "}\n";
2052
2053 ASSERT_NO_FATAL_FAILURE(InitState());
2054 ASSERT_NO_FATAL_FAILURE(InitViewport());
2055
Tony Barbour01999182015-04-09 12:58:51 -06002056 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2057 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2058 VkSamplerObj sampler(m_device);
2059 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002060
Tony Barbour01999182015-04-09 12:58:51 -06002061 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002062 pipelineobj.AddShader(&vs);
2063 pipelineobj.AddShader(&ps);
2064
Tony Barbour01999182015-04-09 12:58:51 -06002065 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002066 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002067
Tony Barbourdd4c9642015-01-09 12:55:14 -07002068 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002069 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002070 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2071
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002072 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002073
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002074 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002075
2076#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002077 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002078 pDSDumpDot((char*)"triTest2.dot");
2079#endif
2080 // render triangle
2081 cmdBuffer.Draw(0, 3, 0, 1);
2082
2083 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002084 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002085 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002086
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002087 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002088}
Tony Barbour01999182015-04-09 12:58:51 -06002089TEST_F(VkRenderTest, TexturedTriangleClip)
Tony Barbourf43b6982014-11-25 13:18:32 -07002090{
2091 // The expected result from this test is a red and green checkered triangle
2092 static const char *vertShaderText =
2093 "#version 330\n"
2094 "#extension GL_ARB_separate_shader_objects : enable\n"
2095 "#extension GL_ARB_shading_language_420pack : enable\n"
2096 "layout (location = 0) out vec2 samplePos;\n"
2097 "out gl_PerVertex {\n"
2098 " vec4 gl_Position;\n"
2099 " float gl_ClipDistance[1];\n"
2100 "};\n"
2101 "void main() {\n"
2102 " vec2 vertices[3];"
2103 " vertices[0] = vec2(-0.5, -0.5);\n"
2104 " vertices[1] = vec2( 0.5, -0.5);\n"
2105 " vertices[2] = vec2( 0.5, 0.5);\n"
2106 " vec2 positions[3];"
2107 " positions[0] = vec2( 0.0, 0.0);\n"
2108 " positions[1] = vec2( 1.0, 0.0);\n"
2109 " positions[2] = vec2( 1.0, 1.0);\n"
2110 " float dists[3];\n"
2111 " dists[0] = 1.0;\n"
2112 " dists[1] = 1.0;\n"
2113 " dists[2] = -1.0;\n"
2114 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2115 " samplePos = positions[gl_VertexID % 3];\n"
2116 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2117 "}\n";
2118
2119 static const char *fragShaderText =
2120 "#version 140\n"
2121 "#extension GL_ARB_separate_shader_objects : enable\n"
2122 "#extension GL_ARB_shading_language_420pack : enable\n"
2123 "layout (location = 0) in vec2 samplePos;\n"
2124 "layout (binding = 0) uniform sampler2D surface;\n"
2125 "layout (location=0) out vec4 outColor;\n"
2126 "void main() {\n"
2127 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2128 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2129 " outColor = texColor;\n"
2130 "}\n";
2131
2132
2133 ASSERT_NO_FATAL_FAILURE(InitState());
2134 ASSERT_NO_FATAL_FAILURE(InitViewport());
2135
Tony Barbour01999182015-04-09 12:58:51 -06002136 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2137 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2138 VkSamplerObj sampler(m_device);
2139 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002140
Tony Barbour01999182015-04-09 12:58:51 -06002141 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002142 pipelineobj.AddShader(&vs);
2143 pipelineobj.AddShader(&ps);
2144
Tony Barbour01999182015-04-09 12:58:51 -06002145 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002146 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002147
Tony Barbourdd4c9642015-01-09 12:55:14 -07002148 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002149 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002150 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2151
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002152 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002153
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002154 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002155
2156#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002157 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002158 pDSDumpDot((char*)"triTest2.dot");
2159#endif
2160 // render triangle
2161 cmdBuffer.Draw(0, 3, 0, 1);
2162
2163 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002164 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002165 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002166
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002167 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002168}
GregFd6ebdb32015-06-03 18:40:50 -06002169
2170//bad
2171
2172
Tony Barbour01999182015-04-09 12:58:51 -06002173TEST_F(VkRenderTest, FSTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002174{
2175 // The expected result from this test is a red and green checkered triangle
2176 static const char *vertShaderText =
2177 "#version 140\n"
2178 "#extension GL_ARB_separate_shader_objects : enable\n"
2179 "#extension GL_ARB_shading_language_420pack : enable\n"
2180 "layout (location = 0) out vec2 samplePos;\n"
2181 "void main() {\n"
2182 " vec2 vertices[3];"
2183 " vertices[0] = vec2(-0.5, -0.5);\n"
2184 " vertices[1] = vec2( 0.5, -0.5);\n"
2185 " vertices[2] = vec2( 0.5, 0.5);\n"
2186 " vec2 positions[3];"
2187 " positions[0] = vec2( 0.0, 0.0);\n"
2188 " positions[1] = vec2( 1.0, 0.0);\n"
2189 " positions[2] = vec2( 1.0, 1.0);\n"
2190 " samplePos = positions[gl_VertexID % 3];\n"
2191 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2192 "}\n";
2193
2194 static const char *fragShaderText =
2195 "#version 140\n"
2196 "#extension GL_ARB_separate_shader_objects : enable\n"
2197 "#extension GL_ARB_shading_language_420pack : enable\n"
2198 "layout (location = 0) in vec2 samplePos;\n"
2199 "layout (binding = 0) uniform sampler2D surface;\n"
2200 "layout (location=0) out vec4 outColor;\n"
2201 "void main() {\n"
2202 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2203 " outColor = texColor;\n"
2204 "}\n";
2205
2206 ASSERT_NO_FATAL_FAILURE(InitState());
2207 ASSERT_NO_FATAL_FAILURE(InitViewport());
2208
Tony Barbour01999182015-04-09 12:58:51 -06002209 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2210 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2211 VkSamplerObj sampler(m_device);
2212 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002213
Tony Barbour01999182015-04-09 12:58:51 -06002214 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002215 pipelineobj.AddShader(&vs);
2216 pipelineobj.AddShader(&ps);
2217
Tony Barbour01999182015-04-09 12:58:51 -06002218 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002219 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002220
Tony Barbourdd4c9642015-01-09 12:55:14 -07002221 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002222 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002223 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2224
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002225 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002226
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002227 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002228
2229#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002230 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002231 pDSDumpDot((char*)"triTest2.dot");
2232#endif
2233 // render triangle
2234 cmdBuffer.Draw(0, 3, 0, 1);
2235
2236 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002237 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002238 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002239
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002240 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002241}
Tony Barbour01999182015-04-09 12:58:51 -06002242TEST_F(VkRenderTest, SamplerBindingsTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002243{
2244 // This test sets bindings on the samplers
2245 // For now we are asserting that sampler and texture pairs
2246 // march in lock step, and are set via GLSL binding. This can
2247 // and will probably change.
2248 // The sampler bindings should match the sampler and texture slot
2249 // number set up by the application.
2250 // This test will result in a blue triangle
2251 static const char *vertShaderText =
2252 "#version 140\n"
2253 "#extension GL_ARB_separate_shader_objects : enable\n"
2254 "#extension GL_ARB_shading_language_420pack : enable\n"
2255 "layout (location = 0) out vec4 samplePos;\n"
2256 "void main() {\n"
2257 " vec2 vertices[3];"
2258 " vertices[0] = vec2(-0.5, -0.5);\n"
2259 " vertices[1] = vec2( 0.5, -0.5);\n"
2260 " vertices[2] = vec2( 0.5, 0.5);\n"
2261 " vec2 positions[3];"
2262 " positions[0] = vec2( 0.0, 0.0);\n"
2263 " positions[1] = vec2( 1.0, 0.0);\n"
2264 " positions[2] = vec2( 1.0, 1.0);\n"
2265 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2266 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2267 "}\n";
2268
2269 static const char *fragShaderText =
2270 "#version 140\n"
2271 "#extension GL_ARB_separate_shader_objects : enable\n"
2272 "#extension GL_ARB_shading_language_420pack : enable\n"
2273 "layout (location = 0) in vec4 samplePos;\n"
2274 "layout (binding = 0) uniform sampler2D surface0;\n"
2275 "layout (binding = 1) uniform sampler2D surface1;\n"
2276 "layout (binding = 12) uniform sampler2D surface2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06002277 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002278 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002279 " outColor = textureLod(surface2, samplePos.xy, 0.0);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002280 "}\n";
2281
2282 ASSERT_NO_FATAL_FAILURE(InitState());
2283 ASSERT_NO_FATAL_FAILURE(InitViewport());
2284
Tony Barbour01999182015-04-09 12:58:51 -06002285 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2286 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002287
Tony Barbour01999182015-04-09 12:58:51 -06002288 VkSamplerObj sampler1(m_device);
2289 VkSamplerObj sampler2(m_device);
2290 VkSamplerObj sampler3(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002291
Tony Barbour2f421a02015-04-01 16:38:10 -06002292 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
Tony Barbour01999182015-04-09 12:58:51 -06002293 VkTextureObj texture1(m_device, tex_colors); // Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002294 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
Tony Barbour01999182015-04-09 12:58:51 -06002295 VkTextureObj texture2(m_device, tex_colors); // Green
Tony Barbour2f421a02015-04-01 16:38:10 -06002296 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
Tony Barbour01999182015-04-09 12:58:51 -06002297 VkTextureObj texture3(m_device, tex_colors); // Blue
Tony Barbourf43b6982014-11-25 13:18:32 -07002298
Tony Barbour01999182015-04-09 12:58:51 -06002299 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002300 pipelineobj.AddShader(&vs);
2301 pipelineobj.AddShader(&ps);
2302
Tony Barbour01999182015-04-09 12:58:51 -06002303 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002304 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2305 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2306 for (int i = 0; i < 10; i++)
2307 descriptorSet.AppendDummy();
2308 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002309
Tony Barbourdd4c9642015-01-09 12:55:14 -07002310 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002311 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002312 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2313
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002314 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002315
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002316 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002317
2318#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002319 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002320 pDSDumpDot((char*)"triTest2.dot");
2321#endif
2322 // render triangle
2323 cmdBuffer.Draw(0, 3, 0, 1);
2324
2325 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002326 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002327 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002328
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002329 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002330}
2331
Tony Barbour01999182015-04-09 12:58:51 -06002332TEST_F(VkRenderTest, TriangleVSUniformBlock)
Tony Barbourf43b6982014-11-25 13:18:32 -07002333{
2334 // The expected result from this test is a blue triangle
2335
2336 static const char *vertShaderText =
2337 "#version 140\n"
2338 "#extension GL_ARB_separate_shader_objects : enable\n"
2339 "#extension GL_ARB_shading_language_420pack : enable\n"
2340 "layout (location = 0) out vec4 outColor;\n"
2341 "layout (std140, binding = 0) uniform bufferVals {\n"
2342 " vec4 red;\n"
2343 " vec4 green;\n"
2344 " vec4 blue;\n"
2345 " vec4 white;\n"
2346 "} myBufferVals;\n"
2347 "void main() {\n"
2348 " vec2 vertices[3];"
2349 " vertices[0] = vec2(-0.5, -0.5);\n"
2350 " vertices[1] = vec2( 0.5, -0.5);\n"
2351 " vertices[2] = vec2( 0.5, 0.5);\n"
2352 " outColor = myBufferVals.blue;\n"
2353 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2354 "}\n";
2355
2356 static const char *fragShaderText =
2357 "#version 140\n"
2358 "#extension GL_ARB_separate_shader_objects : enable\n"
2359 "#extension GL_ARB_shading_language_420pack : enable\n"
2360 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -06002361 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002362 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002363 " outColor = inColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002364 "}\n";
2365
2366 ASSERT_NO_FATAL_FAILURE(InitState());
2367 ASSERT_NO_FATAL_FAILURE(InitViewport());
2368
Tony Barbour01999182015-04-09 12:58:51 -06002369 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2370 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002371
2372 // Let's populate our buffer with the following:
2373 // vec4 red;
2374 // vec4 green;
2375 // vec4 blue;
2376 // vec4 white;
2377 const int valCount = 4 * 4;
2378 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2379 0.0, 1.0, 0.0, 1.0,
2380 0.0, 0.0, 1.0, 1.0,
2381 1.0, 1.0, 1.0, 1.0 };
2382
Tony Barbour01999182015-04-09 12:58:51 -06002383 VkConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002384
Tony Barbour01999182015-04-09 12:58:51 -06002385 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002386 pipelineobj.AddShader(&vs);
2387 pipelineobj.AddShader(&ps);
2388
Tony Barbour01999182015-04-09 12:58:51 -06002389 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002390 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002391
Tony Barbourdd4c9642015-01-09 12:55:14 -07002392 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002393 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002394 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2395
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002396 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002397
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002398 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002399
2400#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002401 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002402 pDSDumpDot((char*)"triTest2.dot");
2403#endif
2404 // render triangle
2405 cmdBuffer.Draw(0, 3, 0, 1);
2406
2407 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002408 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002409 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002410
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002411 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002412}
2413
Tony Barbour01999182015-04-09 12:58:51 -06002414TEST_F(VkRenderTest, TriangleFSUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002415{
2416 // This test allows the shader to select which buffer it is
2417 // pulling from using layout binding qualifier.
2418 // There are corresponding changes in the compiler stack that
2419 // will select the buffer using binding directly.
2420 // The binding number should match the slot number set up by
2421 // the application.
2422 // The expected result from this test is a purple triangle
2423
2424 static const char *vertShaderText =
2425 "#version 140\n"
2426 "#extension GL_ARB_separate_shader_objects : enable\n"
2427 "#extension GL_ARB_shading_language_420pack : enable\n"
2428 "void main() {\n"
2429 " vec2 vertices[3];"
2430 " vertices[0] = vec2(-0.5, -0.5);\n"
2431 " vertices[1] = vec2( 0.5, -0.5);\n"
2432 " vertices[2] = vec2( 0.5, 0.5);\n"
2433 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2434 "}\n";
2435
2436 static const char *fragShaderText =
2437 "#version 140\n"
2438 "#extension GL_ARB_separate_shader_objects : enable\n"
2439 "#extension GL_ARB_shading_language_420pack : enable\n"
2440 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2441 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2442 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002443 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
GregFd6ebdb32015-06-03 18:40:50 -06002444 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002445 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002446 " outColor = myBlueVal.color;\n"
2447 " outColor += myRedVal.color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002448 "}\n";
2449
2450 ASSERT_NO_FATAL_FAILURE(InitState());
2451 ASSERT_NO_FATAL_FAILURE(InitViewport());
2452
Tony Barbour01999182015-04-09 12:58:51 -06002453 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2454 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002455
2456 // We're going to create a number of uniform buffers, and then allow
2457 // the shader to select which it wants to read from with a binding
2458
2459 // Let's populate the buffers with a single color each:
2460 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2461 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2462 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002463 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002464
2465 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2466 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2467 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2468 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2469
2470 const int redCount = sizeof(redVals) / sizeof(float);
2471 const int greenCount = sizeof(greenVals) / sizeof(float);
2472 const int blueCount = sizeof(blueVals) / sizeof(float);
2473 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2474
Tony Barbour01999182015-04-09 12:58:51 -06002475 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002476
Tony Barbour01999182015-04-09 12:58:51 -06002477 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002478
Tony Barbour01999182015-04-09 12:58:51 -06002479 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002480
Tony Barbour01999182015-04-09 12:58:51 -06002481 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002482
Tony Barbour01999182015-04-09 12:58:51 -06002483 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002484 pipelineobj.AddShader(&vs);
2485 pipelineobj.AddShader(&ps);
2486
Tony Barbour01999182015-04-09 12:58:51 -06002487 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002488 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2489 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2490 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2491 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002492
Tony Barbourdd4c9642015-01-09 12:55:14 -07002493 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002494 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002495 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002496
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002497 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002498
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002499 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002500
2501#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002502 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002503 pDSDumpDot((char*)"triTest2.dot");
2504#endif
2505 // render triangle
2506 cmdBuffer.Draw(0, 3, 0, 1);
2507
2508 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002509 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002510 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002511
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002512 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002513}
2514
Tony Barbour01999182015-04-09 12:58:51 -06002515TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002516{
2517 // This test is the same as TriangleFSUniformBlockBinding, but
2518 // it does not provide an instance name.
2519 // The expected result from this test is a purple triangle
2520
2521 static const char *vertShaderText =
2522 "#version 140\n"
2523 "#extension GL_ARB_separate_shader_objects : enable\n"
2524 "#extension GL_ARB_shading_language_420pack : enable\n"
2525 "void main() {\n"
2526 " vec2 vertices[3];"
2527 " vertices[0] = vec2(-0.5, -0.5);\n"
2528 " vertices[1] = vec2( 0.5, -0.5);\n"
2529 " vertices[2] = vec2( 0.5, 0.5);\n"
2530 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2531 "}\n";
2532
2533 static const char *fragShaderText =
2534 "#version 430\n"
2535 "#extension GL_ARB_separate_shader_objects : enable\n"
2536 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002537 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2538 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2539 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002540 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002541 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002542 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002543 " outColor = blue;\n"
2544 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002545 "}\n";
2546 ASSERT_NO_FATAL_FAILURE(InitState());
2547 ASSERT_NO_FATAL_FAILURE(InitViewport());
2548
Tony Barbour01999182015-04-09 12:58:51 -06002549 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2550 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002551
2552 // We're going to create a number of uniform buffers, and then allow
2553 // the shader to select which it wants to read from with a binding
2554
2555 // Let's populate the buffers with a single color each:
2556 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2557 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2558 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2559 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2560
2561 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2562 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2563 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2564 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2565
2566 const int redCount = sizeof(redVals) / sizeof(float);
2567 const int greenCount = sizeof(greenVals) / sizeof(float);
2568 const int blueCount = sizeof(blueVals) / sizeof(float);
2569 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2570
Tony Barbour01999182015-04-09 12:58:51 -06002571 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002572
Tony Barbour01999182015-04-09 12:58:51 -06002573 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002574
Tony Barbour01999182015-04-09 12:58:51 -06002575 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002576
Tony Barbour01999182015-04-09 12:58:51 -06002577 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002578
Tony Barbour01999182015-04-09 12:58:51 -06002579 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002580 pipelineobj.AddShader(&vs);
2581 pipelineobj.AddShader(&ps);
2582
Tony Barbour01999182015-04-09 12:58:51 -06002583 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002584 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2585 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2586 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2587 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002588
Tony Barbourdd4c9642015-01-09 12:55:14 -07002589 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002590 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002591 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2592
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002593 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002594
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002595 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002596
2597#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002598 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002599 pDSDumpDot((char*)"triTest2.dot");
2600#endif
2601 // render triangle
2602 cmdBuffer.Draw(0, 3, 0, 1);
2603
2604 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002605 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002606 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002607
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002608 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002609}
2610
Tony Barbour01999182015-04-09 12:58:51 -06002611TEST_F(VkRenderTest, CubeWithVertexFetchAndMVPAndTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07002612{
2613 static const char *vertShaderText =
2614 "#version 140\n"
2615 "#extension GL_ARB_separate_shader_objects : enable\n"
2616 "#extension GL_ARB_shading_language_420pack : enable\n"
2617 "layout (std140, binding=0) uniform bufferVals {\n"
2618 " mat4 mvp;\n"
2619 "} myBufferVals;\n"
2620 "layout (location=0) in vec4 pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002621 "layout (location=1) in vec2 input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002622 "layout (location=0) out vec2 UV;\n"
2623 "void main() {\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002624 " UV = input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002625 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002626 " gl_Position.y = -gl_Position.y;\n"
2627 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002628 "}\n";
2629
2630 static const char *fragShaderText =
2631 "#version 140\n"
2632 "#extension GL_ARB_separate_shader_objects : enable\n"
2633 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002634 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002635 "layout (location=0) out vec4 outColor;\n"
2636 "layout (location=0) in vec2 UV;\n"
2637 "void main() {\n"
2638 " outColor= textureLod(surface, UV, 0.0);\n"
2639 "}\n";
2640 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2641
2642 glm::mat4 View = glm::lookAt(
2643 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2644 glm::vec3(0,0,0), // and looks at the origin
2645 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2646 );
2647
2648 glm::mat4 Model = glm::mat4(1.0f);
2649
2650 glm::mat4 MVP = Projection * View * Model;
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002651 int num_verts = sizeof(g_vb_texture_Data) / sizeof(g_vb_texture_Data[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002652
2653
2654 ASSERT_NO_FATAL_FAILURE(InitState());
2655 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour8bef8ee2015-05-22 09:44:58 -06002656 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07002657
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002658 VkConstantBufferObj meshBuffer(m_device, num_verts,
2659 sizeof(g_vb_texture_Data[0]), g_vb_texture_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002660 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002661
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002662 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07002663
Tony Barbour01999182015-04-09 12:58:51 -06002664 VkConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2665 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2666 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2667 VkSamplerObj sampler(m_device);
2668 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002669
Tony Barbour01999182015-04-09 12:58:51 -06002670 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002671 pipelineobj.AddShader(&vs);
2672 pipelineobj.AddShader(&ps);
2673
Tony Barbour01999182015-04-09 12:58:51 -06002674 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002675 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mvpBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002676 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002677
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002678#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002679 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002680 MESH_BIND_ID, // binding ID
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002681 sizeof(g_vb_texture_Data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002682 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002683 };
Tony Barbourf43b6982014-11-25 13:18:32 -07002684
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002685 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002686 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2687 vi_attribs[0].location = 0; // location
Tony Barbour8205d902015-04-16 15:59:00 -06002688 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002689 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2690 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2691 vi_attribs[1].location = 1; // location
2692 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
2693 vi_attribs[1].offsetInBytes = 16; // Offset of uv components
Tony Barbourf43b6982014-11-25 13:18:32 -07002694
Tony Barbourf43b6982014-11-25 13:18:32 -07002695 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002696 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2697 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07002698
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002699 VkPipelineDsStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002700 ds_state.depthTestEnable = VK_TRUE;
2701 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06002702 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002703 ds_state.depthBoundsEnable = VK_FALSE;
2704 ds_state.stencilTestEnable = VK_FALSE;
2705 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
2706 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
2707 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06002708 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
2709 ds_state.format = VK_FORMAT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002710 ds_state.front = ds_state.back;
2711 pipelineobj.SetDepthStencil(&ds_state);
2712
Tony Barbour17c6ab12015-03-27 17:03:18 -06002713 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour01999182015-04-09 12:58:51 -06002714 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002715 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002716
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002717 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002718
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002719 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002720
2721 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2722#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002723 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002724 pDSDumpDot((char*)"triTest2.dot");
2725#endif
2726 // render triangle
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002727 cmdBuffer.Draw(0, num_verts, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002728
2729 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002730 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002731 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002732
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002733 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002734 RotateTriangleVSUniform(Projection, View, Model, &mvpBuffer, &cmdBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002735}
Cody Northropd1ce7842014-12-09 11:17:01 -07002736
Tony Barbour01999182015-04-09 12:58:51 -06002737TEST_F(VkRenderTest, TriangleMixedSamplerUniformBlockBinding)
Cody Northropd1ce7842014-12-09 11:17:01 -07002738{
2739 // This test mixes binding slots of textures and buffers, ensuring
2740 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002741 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002742 // you can modify it to move the desired result around.
2743
2744 static const char *vertShaderText =
2745 "#version 140\n"
2746 "#extension GL_ARB_separate_shader_objects : enable\n"
2747 "#extension GL_ARB_shading_language_420pack : enable\n"
2748 "void main() {\n"
2749 " vec2 vertices[3];"
2750 " vertices[0] = vec2(-0.5, -0.5);\n"
2751 " vertices[1] = vec2( 0.5, -0.5);\n"
2752 " vertices[2] = vec2( 0.5, 0.5);\n"
2753 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2754 "}\n";
2755
2756 static const char *fragShaderText =
2757 "#version 430\n"
2758 "#extension GL_ARB_separate_shader_objects : enable\n"
2759 "#extension GL_ARB_shading_language_420pack : enable\n"
2760 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002761 "layout (binding = 3) uniform sampler2D surface1;\n"
2762 "layout (binding = 1) uniform sampler2D surface2;\n"
2763 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002764
Cody Northropa0410942014-12-09 13:59:39 -07002765
Chia-I Wuf8385062015-01-04 16:27:24 +08002766 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2767 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2768 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2769 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002770 "layout (location = 0) out vec4 outColor;\n"
2771 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002772 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002773 " outColor += white * vec4(0.00001);\n"
2774 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002775 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002776 "}\n";
2777 ASSERT_NO_FATAL_FAILURE(InitState());
2778 ASSERT_NO_FATAL_FAILURE(InitViewport());
2779
Tony Barbour01999182015-04-09 12:58:51 -06002780 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2781 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northropd1ce7842014-12-09 11:17:01 -07002782
Cody Northropd1ce7842014-12-09 11:17:01 -07002783 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2784 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2785 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2786 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2787
2788 const int redCount = sizeof(redVals) / sizeof(float);
2789 const int greenCount = sizeof(greenVals) / sizeof(float);
2790 const int blueCount = sizeof(blueVals) / sizeof(float);
2791 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2792
Tony Barbour01999182015-04-09 12:58:51 -06002793 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2794 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2795 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2796 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002797
Tony Barbour2f421a02015-04-01 16:38:10 -06002798 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002799 VkSamplerObj sampler0(m_device);
2800 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002801 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002802 VkSamplerObj sampler2(m_device);
2803 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002804 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002805 VkSamplerObj sampler4(m_device);
2806 VkTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropa0410942014-12-09 13:59:39 -07002807
2808 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2809 // TODO: Get back here ASAP and understand why.
Tony Barbour2f421a02015-04-01 16:38:10 -06002810 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06002811 VkSamplerObj sampler7(m_device);
2812 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropd1ce7842014-12-09 11:17:01 -07002813
Tony Barbour01999182015-04-09 12:58:51 -06002814 VkPipelineObj pipelineobj(m_device);
Cody Northropd1ce7842014-12-09 11:17:01 -07002815 pipelineobj.AddShader(&vs);
2816 pipelineobj.AddShader(&ps);
2817
Tony Barbour01999182015-04-09 12:58:51 -06002818 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002819 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2820 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2821 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2822 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002823 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002824 // swap blue and green
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002825 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2826 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2827 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002828
Tony Barbourdd4c9642015-01-09 12:55:14 -07002829 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002830 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002831 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002832
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002833 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002834
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002835 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002836
2837#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002838 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002839 pDSDumpDot((char*)"triTest2.dot");
2840#endif
2841 // render triangle
2842 cmdBuffer.Draw(0, 3, 0, 1);
2843
2844 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002845 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002846 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002847
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002848 RecordImages(m_renderTargets);
Cody Northropd1ce7842014-12-09 11:17:01 -07002849}
2850
Tony Barbour01999182015-04-09 12:58:51 -06002851TEST_F(VkRenderTest, TriangleMatchingSamplerUniformBlockBinding)
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002852{
2853 // This test matches binding slots of textures and buffers, requiring
2854 // the driver to give them distinct number spaces.
2855 // The expected result from this test is a red triangle, although
2856 // you can modify it to move the desired result around.
2857
2858 static const char *vertShaderText =
2859 "#version 140\n"
2860 "#extension GL_ARB_separate_shader_objects : enable\n"
2861 "#extension GL_ARB_shading_language_420pack : enable\n"
2862 "void main() {\n"
2863 " vec2 vertices[3];"
2864 " vertices[0] = vec2(-0.5, -0.5);\n"
2865 " vertices[1] = vec2( 0.5, -0.5);\n"
2866 " vertices[2] = vec2( 0.5, 0.5);\n"
2867 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2868 "}\n";
2869
2870 static const char *fragShaderText =
2871 "#version 430\n"
2872 "#extension GL_ARB_separate_shader_objects : enable\n"
2873 "#extension GL_ARB_shading_language_420pack : enable\n"
2874 "layout (binding = 0) uniform sampler2D surface0;\n"
2875 "layout (binding = 1) uniform sampler2D surface1;\n"
2876 "layout (binding = 2) uniform sampler2D surface2;\n"
2877 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002878 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2879 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2880 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2881 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002882 "layout (location = 0) out vec4 outColor;\n"
2883 "void main() {\n"
2884 " outColor = red;// * vec4(0.00001);\n"
2885 " outColor += white * vec4(0.00001);\n"
2886 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2887 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2888 "}\n";
2889 ASSERT_NO_FATAL_FAILURE(InitState());
2890 ASSERT_NO_FATAL_FAILURE(InitViewport());
2891
Tony Barbour01999182015-04-09 12:58:51 -06002892 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2893 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002894
2895 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2896 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2897 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2898 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2899
2900 const int redCount = sizeof(redVals) / sizeof(float);
2901 const int greenCount = sizeof(greenVals) / sizeof(float);
2902 const int blueCount = sizeof(blueVals) / sizeof(float);
2903 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2904
Tony Barbour01999182015-04-09 12:58:51 -06002905 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2906 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2907 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2908 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002909
Tony Barbour2f421a02015-04-01 16:38:10 -06002910 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002911 VkSamplerObj sampler0(m_device);
2912 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002913 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002914 VkSamplerObj sampler2(m_device);
2915 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002916 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002917 VkSamplerObj sampler4(m_device);
2918 VkTextureObj texture4(m_device, tex_colors); // Light Green
Tony Barbour2f421a02015-04-01 16:38:10 -06002919 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06002920 VkSamplerObj sampler7(m_device);
2921 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002922
Tony Barbour01999182015-04-09 12:58:51 -06002923 VkPipelineObj pipelineobj(m_device);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002924 pipelineobj.AddShader(&vs);
2925 pipelineobj.AddShader(&ps);
2926
Tony Barbour01999182015-04-09 12:58:51 -06002927 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002928 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2929 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2930 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2931 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002932 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2933 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2934 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2935 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002936
Tony Barbourdd4c9642015-01-09 12:55:14 -07002937 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002938 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002939 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002940
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002941 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002942
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002943 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002944
2945#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002946 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002947 pDSDumpDot((char*)"triTest2.dot");
2948#endif
2949 // render triangle
2950 cmdBuffer.Draw(0, 3, 0, 1);
2951
2952 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002953 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002954 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002955
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002956 RecordImages(m_renderTargets);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002957}
2958
Tony Barbour01999182015-04-09 12:58:51 -06002959TEST_F(VkRenderTest, TriangleUniformBufferLayout)
Cody Northrop02690bd2014-12-17 15:26:33 -07002960{
2961 // This test populates a buffer with a variety of different data
2962 // types, then reads them out with a shader.
2963 // The expected result from this test is a green triangle
2964
2965 static const char *vertShaderText =
2966 "#version 140\n"
2967 "#extension GL_ARB_separate_shader_objects : enable\n"
2968 "#extension GL_ARB_shading_language_420pack : enable\n"
2969 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2970 " vec4 fRed;\n"
2971 " vec4 fGreen;\n"
2972 " layout(row_major) mat4 worldToProj;\n"
2973 " layout(row_major) mat4 projToWorld;\n"
2974 " layout(row_major) mat4 worldToView;\n"
2975 " layout(row_major) mat4 viewToProj;\n"
2976 " layout(row_major) mat4 worldToShadow[4];\n"
2977 " float fZero;\n"
2978 " float fOne;\n"
2979 " float fTwo;\n"
2980 " float fThree;\n"
2981 " vec3 fZeroZeroZero;\n"
2982 " float fFour;\n"
2983 " vec3 fZeroZeroOne;\n"
2984 " float fFive;\n"
2985 " vec3 fZeroOneZero;\n"
2986 " float fSix;\n"
2987 " float fSeven;\n"
2988 " float fEight;\n"
2989 " float fNine;\n"
2990 " vec2 fZeroZero;\n"
2991 " vec2 fZeroOne;\n"
2992 " vec4 fBlue;\n"
2993 " vec2 fOneZero;\n"
2994 " vec2 fOneOne;\n"
2995 " vec3 fZeroOneOne;\n"
2996 " float fTen;\n"
2997 " float fEleven;\n"
2998 " float fTwelve;\n"
2999 " vec3 fOneZeroZero;\n"
3000 " vec4 uvOffsets[4];\n"
3001 "};\n"
3002 "layout (location = 0) out vec4 color;"
3003 "void main() {\n"
3004
3005 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3006 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3007 " \n"
3008
3009 // do some exact comparisons, even though we should
3010 // really have an epsilon involved.
3011 " vec4 outColor = right;\n"
3012 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3013 " outColor = wrong;\n"
3014 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3015 " outColor = wrong;\n"
3016 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3017 " outColor = wrong;\n"
3018
3019 " color = outColor;\n"
3020
3021 // generic position stuff
3022 " vec2 vertices;\n"
3023 " int vertexSelector = gl_VertexID;\n"
3024 " if (vertexSelector == 0)\n"
3025 " vertices = vec2(-0.5, -0.5);\n"
3026 " else if (vertexSelector == 1)\n"
3027 " vertices = vec2( 0.5, -0.5);\n"
3028 " else if (vertexSelector == 2)\n"
3029 " vertices = vec2( 0.5, 0.5);\n"
3030 " else\n"
3031 " vertices = vec2( 0.0, 0.0);\n"
3032 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3033 "}\n";
3034
3035 static const char *fragShaderText =
3036 "#version 140\n"
3037 "#extension GL_ARB_separate_shader_objects : enable\n"
3038 "#extension GL_ARB_shading_language_420pack : enable\n"
3039 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3040 " vec4 fRed;\n"
3041 " vec4 fGreen;\n"
3042 " layout(row_major) mat4 worldToProj;\n"
3043 " layout(row_major) mat4 projToWorld;\n"
3044 " layout(row_major) mat4 worldToView;\n"
3045 " layout(row_major) mat4 viewToProj;\n"
3046 " layout(row_major) mat4 worldToShadow[4];\n"
3047 " float fZero;\n"
3048 " float fOne;\n"
3049 " float fTwo;\n"
3050 " float fThree;\n"
3051 " vec3 fZeroZeroZero;\n"
3052 " float fFour;\n"
3053 " vec3 fZeroZeroOne;\n"
3054 " float fFive;\n"
3055 " vec3 fZeroOneZero;\n"
3056 " float fSix;\n"
3057 " float fSeven;\n"
3058 " float fEight;\n"
3059 " float fNine;\n"
3060 " vec2 fZeroZero;\n"
3061 " vec2 fZeroOne;\n"
3062 " vec4 fBlue;\n"
3063 " vec2 fOneZero;\n"
3064 " vec2 fOneOne;\n"
3065 " vec3 fZeroOneOne;\n"
3066 " float fTen;\n"
3067 " float fEleven;\n"
3068 " float fTwelve;\n"
3069 " vec3 fOneZeroZero;\n"
3070 " vec4 uvOffsets[4];\n"
3071 "};\n"
3072 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003073 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop02690bd2014-12-17 15:26:33 -07003074 "void main() {\n"
3075 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3076 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3077 " \n"
3078
3079 // start with VS value to ensure it passed
3080 " vec4 outColor = color;\n"
3081
3082 // do some exact comparisons, even though we should
3083 // really have an epsilon involved.
3084 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3085 " outColor = wrong;\n"
3086 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3087 " outColor = wrong;\n"
3088 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3089 " outColor = wrong;\n"
3090 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3091 " outColor = wrong;\n"
3092 " if (fTwo != 2.0)\n"
3093 " outColor = wrong;\n"
3094 " if (fOneOne != vec2(1.0, 1.0))\n"
3095 " outColor = wrong;\n"
3096 " if (fTen != 10.0)\n"
3097 " outColor = wrong;\n"
3098 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3099 " outColor = wrong;\n"
3100 " \n"
GregFd6ebdb32015-06-03 18:40:50 -06003101 " uFragColor = outColor;\n"
Cody Northrop02690bd2014-12-17 15:26:33 -07003102 "}\n";
3103
3104
3105 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3106 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3107 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3108 0.0, 1.0, 0.0, 1.0, // align
3109 0.0, 0.0, 1.0, 1.0, // align
3110 0.0, 0.0, 0.0, 1.0, // align
3111 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3112 0.0, 2.0, 0.0, 2.0, // align
3113 0.0, 0.0, 2.0, 2.0, // align
3114 0.0, 0.0, 0.0, 2.0, // align
3115 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3116 0.0, 3.0, 0.0, 3.0, // align
3117 0.0, 0.0, 3.0, 3.0, // align
3118 0.0, 0.0, 0.0, 3.0, // align
3119 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3120 0.0, 4.0, 0.0, 4.0, // align
3121 0.0, 0.0, 4.0, 4.0, // align
3122 0.0, 0.0, 0.0, 4.0, // align
3123 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3124 0.0, 5.0, 0.0, 5.0, // align
3125 0.0, 0.0, 5.0, 5.0, // align
3126 0.0, 0.0, 0.0, 5.0, // align
3127 6.0, 0.0, 0.0, 6.0, // align
3128 0.0, 6.0, 0.0, 6.0, // align
3129 0.0, 0.0, 6.0, 6.0, // align
3130 0.0, 0.0, 0.0, 6.0, // align
3131 7.0, 0.0, 0.0, 7.0, // align
3132 0.0, 7.0, 0.0, 7.0, // align
3133 0.0, 0.0, 7.0, 7.0, // align
3134 0.0, 0.0, 0.0, 7.0, // align
3135 8.0, 0.0, 0.0, 8.0, // align
3136 0.0, 8.0, 0.0, 8.0, // align
3137 0.0, 0.0, 8.0, 8.0, // align
3138 0.0, 0.0, 0.0, 8.0, // align
3139 0.0, // float fZero; // align
3140 1.0, // float fOne; // pack
3141 2.0, // float fTwo; // pack
3142 3.0, // float fThree; // pack
3143 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3144 4.0, // float fFour; // pack
3145 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3146 5.0, // float fFive; // pack
3147 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3148 6.0, // float fSix; // pack
3149 7.0, // float fSeven; // align
3150 8.0, // float fEight; // pack
3151 9.0, // float fNine; // pack
3152 0.0, // BUFFER
3153 0.0, 0.0, // vec2 fZeroZero; // align
3154 0.0, 1.0, // vec2 fZeroOne; // pack
3155 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3156 1.0, 0.0, // vec2 fOneZero; // align
3157 1.0, 1.0, // vec2 fOneOne; // pack
3158 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3159 10.0, // float fTen; // pack
3160 11.0, // float fEleven; // align
3161 12.0, // float fTwelve; // pack
3162 0.0, 0.0, // BUFFER
3163 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3164 0.0, // BUFFER
3165 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3166 0.5, 0.6, 0.7, 0.8, // align
3167 0.9, 1.0, 1.1, 1.2, // align
3168 1.3, 1.4, 1.5, 1.6, // align
3169 };
3170
3171 ASSERT_NO_FATAL_FAILURE(InitState());
3172 ASSERT_NO_FATAL_FAILURE(InitViewport());
3173
3174 const int constCount = sizeof(mixedVals) / sizeof(float);
3175
Tony Barbour01999182015-04-09 12:58:51 -06003176 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3177 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop02690bd2014-12-17 15:26:33 -07003178
Tony Barbour01999182015-04-09 12:58:51 -06003179 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003180
Tony Barbour01999182015-04-09 12:58:51 -06003181 VkPipelineObj pipelineobj(m_device);
Cody Northrop02690bd2014-12-17 15:26:33 -07003182 pipelineobj.AddShader(&vs);
3183 pipelineobj.AddShader(&ps);
3184
Tony Barbour01999182015-04-09 12:58:51 -06003185 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003186 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003187
3188 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06003189 VkCommandBufferObj cmdBuffer(m_device);
Cody Northrop02690bd2014-12-17 15:26:33 -07003190 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3191
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003192 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Cody Northrop02690bd2014-12-17 15:26:33 -07003193
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003194 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Cody Northrop02690bd2014-12-17 15:26:33 -07003195
3196#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003197 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop02690bd2014-12-17 15:26:33 -07003198 pDSDumpDot((char*)"triTest2.dot");
3199#endif
3200 // render triangle
3201 cmdBuffer.Draw(0, 3, 0, 1);
3202
3203 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003204 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003205 cmdBuffer.QueueCommandBuffer();
Cody Northrop02690bd2014-12-17 15:26:33 -07003206
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003207 RecordImages(m_renderTargets);
Cody Northrop02690bd2014-12-17 15:26:33 -07003208}
3209
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003210TEST_F(VkRenderTest, TextureGather)
3211{
3212 // This test introduces textureGather and textureGatherOffset
3213 // Each call is compared against an expected inline color result
3214 // Green triangle means everything worked as expected
3215 // Red means something went wrong
3216
3217 // disable SPV until texture gather is turned on in LunarGLASS
Cody Northrop1cfbd172015-06-03 16:49:20 -06003218 ScopedUseGlsl useGlsl(true);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003219
3220 static const char *vertShaderText =
3221 "#version 140\n"
3222 "#extension GL_ARB_separate_shader_objects : enable\n"
3223 "#extension GL_ARB_shading_language_420pack : enable\n"
3224 "void main() {\n"
3225 " vec2 vertices[3];"
3226 " vertices[0] = vec2(-0.5, -0.5);\n"
3227 " vertices[1] = vec2( 0.5, -0.5);\n"
3228 " vertices[2] = vec2( 0.5, 0.5);\n"
3229 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
3230 "}\n";
3231
3232 static const char *fragShaderText =
3233 "#version 430\n"
3234 "#extension GL_ARB_separate_shader_objects : enable\n"
3235 "#extension GL_ARB_shading_language_420pack : enable\n"
3236 "layout (binding = 0) uniform sampler2D surface0;\n"
3237 "layout (binding = 1) uniform sampler2D surface1;\n"
3238 "layout (binding = 2) uniform sampler2D surface2;\n"
3239 "layout (binding = 3) uniform sampler2D surface3;\n"
3240 "layout (location = 0) out vec4 outColor;\n"
3241 "void main() {\n"
3242
3243 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3244 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3245
3246 " vec4 color = right;\n"
3247
3248 // Grab a normal texture sample to ensure it can work in conjuntion
3249 // with textureGather (there are some intracacies in the backend)
3250 " vec4 sampledColor = textureLod(surface2, vec2(0.5), 0.0);\n"
3251 " if (sampledColor != vec4(0.0, 0.0, 1.0, 1.0))\n"
3252 " color = wrong;\n"
3253
3254 " vec4 gatheredColor = textureGather(surface0, vec2(0.5), 0);\n"
3255 // This just grabbed four red components from a red surface
3256 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3257 " color = wrong;\n"
3258
3259 // Yes, this is using an offset of 0, we don't have enough fine grained
3260 // control of the texture contents here.
3261 " gatheredColor = textureGatherOffset(surface1, vec2(0.5), ivec2(0, 0), 1);\n"
3262 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3263 " color = wrong;\n"
3264
3265 " outColor = color;\n"
3266
3267 "}\n";
3268
3269 ASSERT_NO_FATAL_FAILURE(InitState());
3270 ASSERT_NO_FATAL_FAILURE(InitViewport());
3271
3272 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3273 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3274
3275 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
3276 VkSamplerObj sampler0(m_device);
3277 VkTextureObj texture0(m_device, tex_colors); // Red
3278 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
3279 VkSamplerObj sampler1(m_device);
3280 VkTextureObj texture1(m_device, tex_colors); // Green
3281 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
3282 VkSamplerObj sampler2(m_device);
3283 VkTextureObj texture2(m_device, tex_colors); // Blue
3284 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
3285 VkSamplerObj sampler3(m_device);
3286 VkTextureObj texture3(m_device, tex_colors); // Red and Blue
3287
3288 VkPipelineObj pipelineobj(m_device);
3289 pipelineobj.AddShader(&vs);
3290 pipelineobj.AddShader(&ps);
3291
3292 VkDescriptorSetObj descriptorSet(m_device);
3293 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3294 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
3295 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3296 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
3297
3298 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3299 VkCommandBufferObj cmdBuffer(m_device);
3300 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3301
3302 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3303
3304 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3305
3306 // render triangle
3307 cmdBuffer.Draw(0, 3, 0, 1);
3308
3309 // finalize recording of the command buffer
3310 EndCommandBuffer(cmdBuffer);
3311 cmdBuffer.QueueCommandBuffer();
3312
3313 RecordImages(m_renderTargets);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003314}
3315
Cody Northropa44c2ff2015-04-15 11:19:06 -06003316TEST_F(VkRenderTest, GeometryShaderHelloWorld)
3317{
3318 // This test introduces a geometry shader that simply
3319 // changes the color of each vertex to red, green, blue
3320
3321 static const char *vertShaderText =
3322 "#version 140\n"
3323 "#extension GL_ARB_separate_shader_objects : enable\n"
3324 "#extension GL_ARB_shading_language_420pack : enable\n"
3325 "layout (location = 0) out vec4 color;"
3326 "void main() {\n"
3327
3328 // VS writes out red
3329 " color = vec4(1.0, 0.0, 0.0, 1.0);\n"
3330
3331 // generic position stuff
3332 " vec2 vertices;\n"
3333 " int vertexSelector = gl_VertexID;\n"
3334 " if (vertexSelector == 0)\n"
3335 " vertices = vec2(-0.5, -0.5);\n"
3336 " else if (vertexSelector == 1)\n"
3337 " vertices = vec2( 0.5, -0.5);\n"
3338 " else if (vertexSelector == 2)\n"
3339 " vertices = vec2( 0.5, 0.5);\n"
3340 " else\n"
3341 " vertices = vec2( 0.0, 0.0);\n"
3342 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3343
3344 "}\n";
3345
3346 static const char *geomShaderText =
3347 "#version 330\n"
3348 "#extension GL_ARB_separate_shader_objects : enable\n"
3349 "#extension GL_ARB_shading_language_420pack : enable\n"
3350 "layout( triangles ) in;\n"
3351 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3352 "layout( location = 0 ) in vec4 inColor[3];\n"
3353 "layout( location = 0 ) out vec4 outColor;\n"
3354 "void main()\n"
3355 "{\n"
3356
3357 // first vertex, pass through red
3358 " gl_Position = gl_in[0].gl_Position;\n"
3359 " outColor = inColor[0];\n"
3360 " EmitVertex();\n"
3361
3362 // second vertex, green
3363 " gl_Position = gl_in[1].gl_Position;\n"
3364 " outColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3365 " EmitVertex();\n"
3366
3367 // third vertex, blue
3368 " gl_Position = gl_in[2].gl_Position;\n"
3369 " outColor = vec4(0.0, 0.0, 1.0, 1.0);\n"
3370 " EmitVertex();\n"
3371
3372 // done
3373 " EndPrimitive();\n"
3374 "}\n";
3375
3376
3377 static const char *fragShaderText =
3378 "#version 140\n"
3379 "#extension GL_ARB_separate_shader_objects : enable\n"
3380 "#extension GL_ARB_shading_language_420pack : enable\n"
3381 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003382 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003383 "void main() {\n"
3384 // pass through
GregFd6ebdb32015-06-03 18:40:50 -06003385 " outColor = color;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003386 "}\n";
3387
3388
3389
3390 ASSERT_NO_FATAL_FAILURE(InitState());
3391 ASSERT_NO_FATAL_FAILURE(InitViewport());
3392
3393 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3394 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3395 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3396
3397 VkPipelineObj pipelineobj(m_device);
3398 pipelineobj.AddShader(&vs);
3399 pipelineobj.AddShader(&gs);
3400 pipelineobj.AddShader(&ps);
3401
3402 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3403 VkCommandBufferObj cmdBuffer(m_device);
3404 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3405
3406 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3407
3408 VkDescriptorSetObj descriptorSet(m_device);
3409
3410 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3411
3412 // render triangle
3413 cmdBuffer.Draw(0, 3, 0, 1);
3414
3415 // finalize recording of the command buffer
3416 EndCommandBuffer(cmdBuffer);
3417 cmdBuffer.QueueCommandBuffer();
3418
3419 RecordImages(m_renderTargets);
3420}
3421
3422TEST_F(VkRenderTest, GSUniformBufferLayout)
3423{
3424 // This test is just like TriangleUniformBufferLayout but adds
3425 // geometry as a stage that also does UBO lookups
3426 // The expected result from this test is a green triangle
3427
3428 static const char *vertShaderText =
3429 "#version 140\n"
3430 "#extension GL_ARB_separate_shader_objects : enable\n"
3431 "#extension GL_ARB_shading_language_420pack : enable\n"
3432 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3433 " vec4 fRed;\n"
3434 " vec4 fGreen;\n"
3435 " layout(row_major) mat4 worldToProj;\n"
3436 " layout(row_major) mat4 projToWorld;\n"
3437 " layout(row_major) mat4 worldToView;\n"
3438 " layout(row_major) mat4 viewToProj;\n"
3439 " layout(row_major) mat4 worldToShadow[4];\n"
3440 " float fZero;\n"
3441 " float fOne;\n"
3442 " float fTwo;\n"
3443 " float fThree;\n"
3444 " vec3 fZeroZeroZero;\n"
3445 " float fFour;\n"
3446 " vec3 fZeroZeroOne;\n"
3447 " float fFive;\n"
3448 " vec3 fZeroOneZero;\n"
3449 " float fSix;\n"
3450 " float fSeven;\n"
3451 " float fEight;\n"
3452 " float fNine;\n"
3453 " vec2 fZeroZero;\n"
3454 " vec2 fZeroOne;\n"
3455 " vec4 fBlue;\n"
3456 " vec2 fOneZero;\n"
3457 " vec2 fOneOne;\n"
3458 " vec3 fZeroOneOne;\n"
3459 " float fTen;\n"
3460 " float fEleven;\n"
3461 " float fTwelve;\n"
3462 " vec3 fOneZeroZero;\n"
3463 " vec4 uvOffsets[4];\n"
3464 "};\n"
3465 "layout (location = 0) out vec4 color;"
3466 "void main() {\n"
3467
3468 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3469 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3470 " \n"
3471
3472 // do some exact comparisons, even though we should
3473 // really have an epsilon involved.
3474 " vec4 outColor = right;\n"
3475 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3476 " outColor = wrong;\n"
3477 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3478 " outColor = wrong;\n"
3479 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3480 " outColor = wrong;\n"
3481
3482 " color = outColor;\n"
3483
3484 // generic position stuff
3485 " vec2 vertices;\n"
3486 " int vertexSelector = gl_VertexID;\n"
3487 " if (vertexSelector == 0)\n"
3488 " vertices = vec2(-0.5, -0.5);\n"
3489 " else if (vertexSelector == 1)\n"
3490 " vertices = vec2( 0.5, -0.5);\n"
3491 " else if (vertexSelector == 2)\n"
3492 " vertices = vec2( 0.5, 0.5);\n"
3493 " else\n"
3494 " vertices = vec2( 0.0, 0.0);\n"
3495 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3496 "}\n";
3497
3498 static const char *geomShaderText =
3499 "#version 330\n"
3500 "#extension GL_ARB_separate_shader_objects : enable\n"
3501 "#extension GL_ARB_shading_language_420pack : enable\n"
3502
3503 // GS layout stuff
3504 "layout( triangles ) in;\n"
3505 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3506
3507 // Between stage IO
3508 "layout( location = 0 ) in vec4 inColor[3];\n"
3509 "layout( location = 0 ) out vec4 color;\n"
3510
3511 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3512 " vec4 fRed;\n"
3513 " vec4 fGreen;\n"
3514 " layout(row_major) mat4 worldToProj;\n"
3515 " layout(row_major) mat4 projToWorld;\n"
3516 " layout(row_major) mat4 worldToView;\n"
3517 " layout(row_major) mat4 viewToProj;\n"
3518 " layout(row_major) mat4 worldToShadow[4];\n"
3519 " float fZero;\n"
3520 " float fOne;\n"
3521 " float fTwo;\n"
3522 " float fThree;\n"
3523 " vec3 fZeroZeroZero;\n"
3524 " float fFour;\n"
3525 " vec3 fZeroZeroOne;\n"
3526 " float fFive;\n"
3527 " vec3 fZeroOneZero;\n"
3528 " float fSix;\n"
3529 " float fSeven;\n"
3530 " float fEight;\n"
3531 " float fNine;\n"
3532 " vec2 fZeroZero;\n"
3533 " vec2 fZeroOne;\n"
3534 " vec4 fBlue;\n"
3535 " vec2 fOneZero;\n"
3536 " vec2 fOneOne;\n"
3537 " vec3 fZeroOneOne;\n"
3538 " float fTen;\n"
3539 " float fEleven;\n"
3540 " float fTwelve;\n"
3541 " vec3 fOneZeroZero;\n"
3542 " vec4 uvOffsets[4];\n"
3543 "};\n"
3544
3545 "void main()\n"
3546 "{\n"
3547
3548 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3549 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3550
3551 // Each vertex will validate it can read VS output
3552 // then check a few values from the UBO
3553
3554 // first vertex
3555 " vec4 outColor = inColor[0];\n"
3556
3557 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3558 " outColor = wrong;\n"
3559 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3560 " outColor = wrong;\n"
3561 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3562 " outColor = wrong;\n"
3563 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3564 " outColor = wrong;\n"
3565
3566 " gl_Position = gl_in[0].gl_Position;\n"
3567 " color = outColor;\n"
3568 " EmitVertex();\n"
3569
3570 // second vertex
3571 " outColor = inColor[1];\n"
3572
3573 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3574 " outColor = wrong;\n"
3575 " if (fSix != 6.0)\n"
3576 " outColor = wrong;\n"
3577 " if (fOneOne != vec2(1.0, 1.0))\n"
3578 " outColor = wrong;\n"
3579
3580 " gl_Position = gl_in[1].gl_Position;\n"
3581 " color = outColor;\n"
3582 " EmitVertex();\n"
3583
3584 // third vertex
3585 " outColor = inColor[2];\n"
3586
3587 " if (fSeven != 7.0)\n"
3588 " outColor = wrong;\n"
3589 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3590 " outColor = wrong;\n"
3591
3592 " gl_Position = gl_in[2].gl_Position;\n"
3593 " color = outColor;\n"
3594 " EmitVertex();\n"
3595
3596 // done
3597 " EndPrimitive();\n"
3598 "}\n";
3599
3600 static const char *fragShaderText =
3601 "#version 140\n"
3602 "#extension GL_ARB_separate_shader_objects : enable\n"
3603 "#extension GL_ARB_shading_language_420pack : enable\n"
3604 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3605 " vec4 fRed;\n"
3606 " vec4 fGreen;\n"
3607 " layout(row_major) mat4 worldToProj;\n"
3608 " layout(row_major) mat4 projToWorld;\n"
3609 " layout(row_major) mat4 worldToView;\n"
3610 " layout(row_major) mat4 viewToProj;\n"
3611 " layout(row_major) mat4 worldToShadow[4];\n"
3612 " float fZero;\n"
3613 " float fOne;\n"
3614 " float fTwo;\n"
3615 " float fThree;\n"
3616 " vec3 fZeroZeroZero;\n"
3617 " float fFour;\n"
3618 " vec3 fZeroZeroOne;\n"
3619 " float fFive;\n"
3620 " vec3 fZeroOneZero;\n"
3621 " float fSix;\n"
3622 " float fSeven;\n"
3623 " float fEight;\n"
3624 " float fNine;\n"
3625 " vec2 fZeroZero;\n"
3626 " vec2 fZeroOne;\n"
3627 " vec4 fBlue;\n"
3628 " vec2 fOneZero;\n"
3629 " vec2 fOneOne;\n"
3630 " vec3 fZeroOneOne;\n"
3631 " float fTen;\n"
3632 " float fEleven;\n"
3633 " float fTwelve;\n"
3634 " vec3 fOneZeroZero;\n"
3635 " vec4 uvOffsets[4];\n"
3636 "};\n"
3637 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003638 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003639 "void main() {\n"
3640 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3641 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3642 " \n"
3643
3644 // start with GS value to ensure it passed
3645 " vec4 outColor = color;\n"
3646
3647 // do some exact comparisons, even though we should
3648 // really have an epsilon involved.
3649 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3650 " outColor = wrong;\n"
3651 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3652 " outColor = wrong;\n"
3653 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3654 " outColor = wrong;\n"
3655 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3656 " outColor = wrong;\n"
3657 " if (fTwo != 2.0)\n"
3658 " outColor = wrong;\n"
3659 " if (fOneOne != vec2(1.0, 1.0))\n"
3660 " outColor = wrong;\n"
3661 " if (fTen != 10.0)\n"
3662 " outColor = wrong;\n"
3663 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3664 " outColor = wrong;\n"
3665 " \n"
GregFd6ebdb32015-06-03 18:40:50 -06003666 " uFragColor = outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003667 "}\n";
3668
3669
3670 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3671 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3672 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3673 0.0, 1.0, 0.0, 1.0, // align
3674 0.0, 0.0, 1.0, 1.0, // align
3675 0.0, 0.0, 0.0, 1.0, // align
3676 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3677 0.0, 2.0, 0.0, 2.0, // align
3678 0.0, 0.0, 2.0, 2.0, // align
3679 0.0, 0.0, 0.0, 2.0, // align
3680 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3681 0.0, 3.0, 0.0, 3.0, // align
3682 0.0, 0.0, 3.0, 3.0, // align
3683 0.0, 0.0, 0.0, 3.0, // align
3684 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3685 0.0, 4.0, 0.0, 4.0, // align
3686 0.0, 0.0, 4.0, 4.0, // align
3687 0.0, 0.0, 0.0, 4.0, // align
3688 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3689 0.0, 5.0, 0.0, 5.0, // align
3690 0.0, 0.0, 5.0, 5.0, // align
3691 0.0, 0.0, 0.0, 5.0, // align
3692 6.0, 0.0, 0.0, 6.0, // align
3693 0.0, 6.0, 0.0, 6.0, // align
3694 0.0, 0.0, 6.0, 6.0, // align
3695 0.0, 0.0, 0.0, 6.0, // align
3696 7.0, 0.0, 0.0, 7.0, // align
3697 0.0, 7.0, 0.0, 7.0, // align
3698 0.0, 0.0, 7.0, 7.0, // align
3699 0.0, 0.0, 0.0, 7.0, // align
3700 8.0, 0.0, 0.0, 8.0, // align
3701 0.0, 8.0, 0.0, 8.0, // align
3702 0.0, 0.0, 8.0, 8.0, // align
3703 0.0, 0.0, 0.0, 8.0, // align
3704 0.0, // float fZero; // align
3705 1.0, // float fOne; // pack
3706 2.0, // float fTwo; // pack
3707 3.0, // float fThree; // pack
3708 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3709 4.0, // float fFour; // pack
3710 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3711 5.0, // float fFive; // pack
3712 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3713 6.0, // float fSix; // pack
3714 7.0, // float fSeven; // align
3715 8.0, // float fEight; // pack
3716 9.0, // float fNine; // pack
3717 0.0, // BUFFER
3718 0.0, 0.0, // vec2 fZeroZero; // align
3719 0.0, 1.0, // vec2 fZeroOne; // pack
3720 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3721 1.0, 0.0, // vec2 fOneZero; // align
3722 1.0, 1.0, // vec2 fOneOne; // pack
3723 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3724 10.0, // float fTen; // pack
3725 11.0, // float fEleven; // align
3726 12.0, // float fTwelve; // pack
3727 0.0, 0.0, // BUFFER
3728 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3729 0.0, // BUFFER
3730 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3731 0.5, 0.6, 0.7, 0.8, // align
3732 0.9, 1.0, 1.1, 1.2, // align
3733 1.3, 1.4, 1.5, 1.6, // align
3734 };
3735
3736
3737
3738 ASSERT_NO_FATAL_FAILURE(InitState());
3739 ASSERT_NO_FATAL_FAILURE(InitViewport());
3740
3741 const int constCount = sizeof(mixedVals) / sizeof(float);
3742
3743 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3744 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3745 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3746
3747 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
3748
3749 VkPipelineObj pipelineobj(m_device);
3750 pipelineobj.AddShader(&vs);
3751 pipelineobj.AddShader(&gs);
3752 pipelineobj.AddShader(&ps);
3753
3754 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3755 VkCommandBufferObj cmdBuffer(m_device);
3756 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3757
3758 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3759
3760 VkDescriptorSetObj descriptorSet(m_device);
3761 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
3762
3763 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3764
3765 // render triangle
3766 cmdBuffer.Draw(0, 3, 0, 1);
3767
3768 // finalize recording of the command buffer
3769 EndCommandBuffer(cmdBuffer);
3770 cmdBuffer.QueueCommandBuffer();
3771
3772 RecordImages(m_renderTargets);
3773}
3774
3775TEST_F(VkRenderTest, GSPositions)
3776{
3777 // This test adds more inputs from the vertex shader and perturbs positions
3778 // Expected result is white triangle with weird positions
3779
3780 static const char *vertShaderText =
3781 "#version 140\n"
3782 "#extension GL_ARB_separate_shader_objects : enable\n"
3783 "#extension GL_ARB_shading_language_420pack : enable\n"
3784
3785 "layout(location = 0) out vec3 out_a;\n"
3786 "layout(location = 1) out vec3 out_b;\n"
3787 "layout(location = 2) out vec3 out_c;\n"
3788
3789 "void main() {\n"
3790
3791 // write a solid color to each
3792 " out_a = vec3(1.0, 0.0, 0.0);\n"
3793 " out_b = vec3(0.0, 1.0, 0.0);\n"
3794 " out_c = vec3(0.0, 0.0, 1.0);\n"
3795
3796 // generic position stuff
3797 " vec2 vertices;\n"
3798 " int vertexSelector = gl_VertexID;\n"
3799 " if (vertexSelector == 0)\n"
3800 " vertices = vec2(-0.5, -0.5);\n"
3801 " else if (vertexSelector == 1)\n"
3802 " vertices = vec2( 0.5, -0.5);\n"
3803 " else if (vertexSelector == 2)\n"
3804 " vertices = vec2( 0.5, 0.5);\n"
3805 " else\n"
3806 " vertices = vec2( 0.0, 0.0);\n"
3807 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3808
3809 "}\n";
3810
3811 static const char *geomShaderText =
3812 "#version 330\n"
3813 "#extension GL_ARB_separate_shader_objects : enable\n"
3814 "#extension GL_ARB_shading_language_420pack : enable\n"
3815 "layout( triangles ) in;\n"
3816 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3817
3818 "layout(location = 0) in vec3 in_a[3];\n"
3819 "layout(location = 1) in vec3 in_b[3];\n"
3820 "layout(location = 2) in vec3 in_c[3];\n"
3821
3822 "layout(location = 0) out vec3 out_a;\n"
3823 "layout(location = 1) out vec3 out_b;\n"
3824 "layout(location = 2) out vec3 out_c;\n"
3825
3826 "void main()\n"
3827 "{\n"
3828
3829 " gl_Position = gl_in[0].gl_Position;\n"
3830 " gl_Position.xy *= vec2(0.75);\n"
3831 " out_a = in_a[0];\n"
3832 " out_b = in_b[0];\n"
3833 " out_c = in_c[0];\n"
3834 " EmitVertex();\n"
3835
3836 " gl_Position = gl_in[1].gl_Position;\n"
3837 " gl_Position.xy *= vec2(1.5);\n"
3838 " out_a = in_a[1];\n"
3839 " out_b = in_b[1];\n"
3840 " out_c = in_c[1];\n"
3841 " EmitVertex();\n"
3842
3843 " gl_Position = gl_in[2].gl_Position;\n"
3844 " gl_Position.xy *= vec2(-0.1);\n"
3845 " out_a = in_a[2];\n"
3846 " out_b = in_b[2];\n"
3847 " out_c = in_c[2];\n"
3848 " EmitVertex();\n"
3849
3850 " EndPrimitive();\n"
3851 "}\n";
3852
3853
3854 static const char *fragShaderText =
3855 "#version 140\n"
3856 "#extension GL_ARB_separate_shader_objects : enable\n"
3857 "#extension GL_ARB_shading_language_420pack : enable\n"
3858
3859 "layout(location = 0) in vec3 in_a;\n"
3860 "layout(location = 1) in vec3 in_b;\n"
3861 "layout(location = 2) in vec3 in_c;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003862 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003863
3864 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06003865 " outColor = vec4(in_a.x, in_b.y, in_c.z, 1.0);\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003866 "}\n";
3867
3868
3869
3870 ASSERT_NO_FATAL_FAILURE(InitState());
3871 ASSERT_NO_FATAL_FAILURE(InitViewport());
3872
3873 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3874 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3875 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3876
3877 VkPipelineObj pipelineobj(m_device);
3878 pipelineobj.AddShader(&vs);
3879 pipelineobj.AddShader(&gs);
3880 pipelineobj.AddShader(&ps);
3881
3882 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3883 VkCommandBufferObj cmdBuffer(m_device);
3884 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3885
3886 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3887
3888 VkDescriptorSetObj descriptorSet(m_device);
3889
3890 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3891
3892 // render triangle
3893 cmdBuffer.Draw(0, 3, 0, 1);
3894
3895 // finalize recording of the command buffer
3896 EndCommandBuffer(cmdBuffer);
3897 cmdBuffer.QueueCommandBuffer();
3898
3899 RecordImages(m_renderTargets);
3900}
3901
GregFd6ebdb32015-06-03 18:40:50 -06003902#endif
3903
Cody Northropa44c2ff2015-04-15 11:19:06 -06003904TEST_F(VkRenderTest, GSTriStrip)
3905{
3906 // This test emits multiple multiple triangles using a GS
3907 // Correct result is an multicolor circle
3908
3909 static const char *vertShaderText =
3910 "#version 140\n"
3911 "#extension GL_ARB_separate_shader_objects : enable\n"
3912 "#extension GL_ARB_shading_language_420pack : enable\n"
3913
3914 "void main() {\n"
3915
3916 // generic position stuff
3917 " vec2 vertices;\n"
3918 " int vertexSelector = gl_VertexID;\n"
3919 " if (vertexSelector == 0)\n"
3920 " vertices = vec2(-0.5, -0.5);\n"
3921 " else if (vertexSelector == 1)\n"
3922 " vertices = vec2( 0.5, -0.5);\n"
3923 " else if (vertexSelector == 2)\n"
3924 " vertices = vec2( 0.5, 0.5);\n"
3925 " else\n"
3926 " vertices = vec2( 0.0, 0.0);\n"
3927 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3928
3929 "}\n";
3930
3931 static const char *geomShaderText =
3932 "#version 330\n"
3933 "#extension GL_ARB_separate_shader_objects : enable\n"
3934 "#extension GL_ARB_shading_language_420pack : enable\n"
3935 "layout( triangles ) in;\n"
3936 "layout( triangle_strip, max_vertices = 18 ) out;\n"
3937
3938 "layout(location = 0) out vec4 outColor;\n"
3939
3940 "void main()\n"
3941 "{\n"
3942 // init with first position to get zw
3943 " gl_Position = gl_in[0].gl_Position;\n"
3944
3945 " vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3946 " vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
3947 " vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
3948 " vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
3949
3950 // different color per tri
3951 " vec4[6] colors = { red, white, \n"
3952 " yellow, white, \n"
3953 " blue, white }; \n"
3954
3955 // fan out the triangles
3956 " vec2[18] positions = { vec2(0.0, 0.0), vec2(-0.5, 0.0), vec2(-0.25, -0.5), \n"
3957 " vec2(0.0, 0.0), vec2(-0.25, -0.5), vec2( 0.25, -0.5), \n"
3958 " vec2(0.0, 0.0), vec2( 0.25, -0.5), vec2( 0.5, 0.0), \n"
3959 " vec2(0.0, 0.0), vec2( 0.5, 0.0), vec2( 0.25, 0.5), \n"
3960 " vec2(0.0, 0.0), vec2( 0.25, 0.5), vec2(-0.25, 0.5), \n"
3961 " vec2(0.0, 0.0), vec2(-0.25, 0.5), vec2(-0.5, 0.0) }; \n"
3962
3963 // make a triangle list of 6
3964 " for (int i = 0; i < 6; ++i) { \n"
3965 " outColor = colors[i]; \n"
3966 " for (int j = 0; j < 3; ++j) { \n"
3967 " gl_Position.xy = positions[i * 3 + j]; \n"
3968 " EmitVertex(); \n"
3969 " } \n"
3970 " EndPrimitive();\n"
3971 " } \n"
3972
3973 "}\n";
3974
3975
3976 static const char *fragShaderText =
3977 "#version 150\n"
3978 "#extension GL_ARB_separate_shader_objects : enable\n"
3979 "#extension GL_ARB_shading_language_420pack : enable\n"
3980
3981
3982 "layout(binding = 0) uniform windowDimensions {\n"
3983 " vec4 dimensions;\n"
3984 "};\n"
3985
3986 "layout(location = 0) in vec4 inColor;\n"
3987 "layout(origin_upper_left) in vec4 gl_FragCoord;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003988 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003989
3990 "void main() {\n"
3991
3992 // discard to make a nice circle
3993 " vec2 pos = abs(gl_FragCoord.xy) - vec2(dimensions.x, dimensions.y) / 2;\n"
3994 " float dist = sqrt(dot(pos, pos));\n"
3995 " if (dist > 50.0)\n"
3996 " discard;\n"
3997
GregFd6ebdb32015-06-03 18:40:50 -06003998 " outColor = inColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003999
4000 "}\n";
4001
4002
4003
4004 ASSERT_NO_FATAL_FAILURE(InitState());
4005 ASSERT_NO_FATAL_FAILURE(InitViewport());
4006
4007 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
4008 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
4009 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
4010
4011 VkPipelineObj pipelineobj(m_device);
4012 pipelineobj.AddShader(&vs);
4013 pipelineobj.AddShader(&gs);
4014 pipelineobj.AddShader(&ps);
4015
4016 const float dimensions[4] = { VkRenderFramework::m_width, VkRenderFramework::m_height , 0.0, 0.0};
4017
4018 VkConstantBufferObj windowDimensions(m_device, sizeof(dimensions) / sizeof(dimensions[0]), sizeof(dimensions[0]), (const void*) dimensions);
4019
4020 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4021 VkCommandBufferObj cmdBuffer(m_device);
4022 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
4023
4024 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
4025
4026 VkDescriptorSetObj descriptorSet(m_device);
4027 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, windowDimensions);
4028
4029 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
4030
4031 // render triangle
4032 cmdBuffer.Draw(0, 3, 0, 1);
4033
4034 // finalize recording of the command buffer
4035 EndCommandBuffer(cmdBuffer);
4036 cmdBuffer.QueueCommandBuffer();
4037
4038 RecordImages(m_renderTargets);
4039}
4040
Chris Forbes23e6db62015-06-15 09:32:35 +12004041TEST_F(VkRenderTest, RenderPassLoadOpClear)
4042{
4043 ASSERT_NO_FATAL_FAILURE(InitState());
4044 ASSERT_NO_FATAL_FAILURE(InitViewport());
4045
4046 /* clear via load op to full green */
4047 m_clear_via_load_op = true;
4048 m_clear_color.useRawValue = false;
4049 m_clear_color.color.floatColor[0] = 0;
4050 m_clear_color.color.floatColor[1] = 1;
4051 m_clear_color.color.floatColor[2] = 0;
4052 m_clear_color.color.floatColor[3] = 0;
4053 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4054
4055 VkCommandBufferObj cmdBuffer(m_device);
4056 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
4057 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
4058 /* This command buffer contains ONLY the load op! */
4059 EndCommandBuffer(cmdBuffer);
4060 cmdBuffer.QueueCommandBuffer();
4061
4062 RecordImages(m_renderTargets);
4063}
4064
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004065int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004066 int result;
4067
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004068 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06004069 VkTestFramework::InitArgs(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004070
Chia-I Wu7133fdc2014-12-15 23:57:34 +08004071 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06004072
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004073 result = RUN_ALL_TESTS();
4074
Tony Barbour01999182015-04-09 12:58:51 -06004075 VkTestFramework::Finish();
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004076 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004077}