blob: 70d53eb0970ed0a25aaf0564da28ed101cfb6393 [file] [log] [blame]
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06001// Copyright 2005, Google Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14// * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060031// VK tests
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060032//
33// Copyright (C) 2014 LunarG, Inc.
34//
35// Permission is hereby granted, free of charge, to any person obtaining a
36// copy of this software and associated documentation files (the "Software"),
37// to deal in the Software without restriction, including without limitation
38// the rights to use, copy, modify, merge, publish, distribute, sublicense,
39// and/or sell copies of the Software, and to permit persons to whom the
40// Software is furnished to do so, subject to the following conditions:
41//
42// The above copyright notice and this permission notice shall be included
43// in all copies or substantial portions of the Software.
44//
45// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
48// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
49// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
50// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
51// DEALINGS IN THE SOFTWARE.
52
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060053// Basic rendering tests
54
55#include <stdlib.h>
56#include <stdio.h>
57#include <stdbool.h>
58#include <string.h>
Courtney Goeltzenleuchter76a643b2014-08-21 17:34:22 -060059#include <iostream>
60#include <fstream>
61using namespace std;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060062
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060063#include <vulkan.h>
Tobin Ehlis31446e52014-11-28 11:17:19 -070064#ifdef DUMP_STATE_DOT
65#include "../layers/draw_state.h"
66#endif
Tobin Ehlis3c26a542014-11-18 11:28:33 -070067#ifdef PRINT_OBJECTS
68#include "../layers/object_track.h"
69#endif
Tobin Ehlis791a49c2014-11-10 12:29:12 -070070#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060071#include <vk_debug_report_lunarg.h>
Tobin Ehlis791a49c2014-11-10 12:29:12 -070072#endif
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060073#include "gtest-1.7.0/include/gtest/gtest.h"
74
Cody Northropd4e020a2015-03-17 14:54:35 -060075#include "icd-spv.h"
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060076
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -060077#define GLM_FORCE_RADIANS
78#include "glm/glm.hpp"
79#include <glm/gtc/matrix_transform.hpp>
80
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060081#include "vkrenderframework.h"
Tobin Ehlis791a49c2014-11-10 12:29:12 -070082#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060083void VKAPI myDbgFunc(
84 VK_DBG_MSG_TYPE msgType,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060085 VkValidationLevel validationLevel,
Mike Stroyan230e6252015-04-17 12:36:38 -060086 VkObject srcObject,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060087 size_t location,
88 int32_t msgCode,
89 const char* pMsg,
90 void* pUserData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -070091{
Tobin Ehlis3c26a542014-11-18 11:28:33 -070092 switch (msgType)
93 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060094 case VK_DBG_MSG_WARNING:
Tobin Ehlis3c26a542014-11-18 11:28:33 -070095 printf("CALLBACK WARNING : %s\n", pMsg);
96 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060097 case VK_DBG_REPORT_ERROR_BIT:
Tobin Ehlis3c26a542014-11-18 11:28:33 -070098 printf("CALLBACK ERROR : %s\n", pMsg);
99 break;
100 default:
101 printf("EATING Msg of type %u\n", msgType);
102 break;
103 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700104}
105#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700106
107
108#undef ASSERT_NO_FATAL_FAILURE
109#define ASSERT_NO_FATAL_FAILURE(x) x
110
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600111//--------------------------------------------------------------------------------------
112// Mesh and VertexFormat Data
113//--------------------------------------------------------------------------------------
114struct Vertex
115{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600116 float posX, posY, posZ, posW; // Position data
117 float r, g, b, a; // Color
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600118};
119
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600120struct VertexUV
121{
122 float posX, posY, posZ, posW; // Position data
123 float u, v; // texture u,v
124};
125
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600126#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600127#define UV(_u_, _v_) (_u_), (_v_)
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600128
129static const Vertex g_vbData[] =
130{
131 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
132 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
133 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
134 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
135 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
136 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
137
138 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
139 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
140 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
141 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
142 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
143 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
144
145 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
146 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
147 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
148 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
149 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
150 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
151
152 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
153 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
154 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
155 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
156 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
157 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
158
159 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
160 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
161 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
162 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
163 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
164 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
165
166 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
167 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
168 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
169 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
170 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
171 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
172};
173
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600174static const Vertex g_vb_solid_face_colors_Data[] =
175{
176 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600177 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600178 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
179 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600180 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
181 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600182
183 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
184 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600185 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
186 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600187 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600188 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600189
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600190 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
191 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
192 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
193 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
194 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
195 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600196
197 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
198 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
199 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
200 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
201 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
202 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
203
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600204 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600205 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600206 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
207 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600208 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
209 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
210
211 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
212 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
213 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
214 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
215 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
216 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
217};
218
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600219static const VertexUV g_vb_texture_Data[] =
220{
221 { XYZ1( -1, -1, -1 ), UV( 0.f, 0.f ) },
222 { XYZ1( -1, 1, 1 ), UV( 1.f, 1.f ) },
223 { XYZ1( -1, -1, 1 ), UV( 1.f, 0.f ) },
224 { XYZ1( -1, 1, 1 ), UV( 1.f, 1.f ) },
225 { XYZ1( -1, -1, -1 ), UV( 0.f, 0.f ) },
226 { XYZ1( -1, 1, -1 ), UV( 0.f, 1.f ) },
227
228 { XYZ1( -1, -1, -1 ), UV( 1.f, 0.f ) },
229 { XYZ1( 1, -1, -1 ), UV( 0.f, 0.f ) },
230 { XYZ1( 1, 1, -1 ), UV( 0.f, 1.f ) },
231 { XYZ1( -1, -1, -1 ), UV( 1.f, 0.f ) },
232 { XYZ1( 1, 1, -1 ), UV( 0.f, 1.f ) },
233 { XYZ1( -1, 1, -1 ), UV( 1.f, 1.f ) },
234
235 { XYZ1( -1, -1, -1 ), UV( 1.f, 1.f ) },
236 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
237 { XYZ1( 1, -1, -1 ), UV( 1.f, 0.f ) },
238 { XYZ1( -1, -1, -1 ), UV( 1.f, 1.f ) },
239 { XYZ1( -1, -1, 1 ), UV( 0.f, 1.f ) },
240 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
241
242 { XYZ1( -1, 1, -1 ), UV( 1.f, 1.f ) },
243 { XYZ1( 1, 1, 1 ), UV( 0.f, 0.f ) },
244 { XYZ1( -1, 1, 1 ), UV( 0.f, 1.f ) },
245 { XYZ1( -1, 1, -1 ), UV( 1.f, 1.f ) },
246 { XYZ1( 1, 1, -1 ), UV( 1.f, 0.f ) },
247 { XYZ1( 1, 1, 1 ), UV( 0.f, 0.f ) },
248
249 { XYZ1( 1, 1, -1 ), UV( 1.f, 1.f ) },
250 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
251 { XYZ1( 1, 1, 1 ), UV( 0.f, 1.f ) },
252 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
253 { XYZ1( 1, 1, -1 ), UV( 1.f, 1.f ) },
254 { XYZ1( 1, -1, -1 ), UV( 1.f, 0.f ) },
255
256 { XYZ1( -1, 1, 1 ), UV( 0.f, 1.f ) },
257 { XYZ1( 1, 1, 1 ), UV( 1.f, 1.f ) },
258 { XYZ1( -1, -1, 1 ), UV( 0.f, 0.f ) },
259 { XYZ1( -1, -1, 1 ), UV( 0.f, 0.f ) },
260 { XYZ1( 1, 1, 1 ), UV( 1.f, 1.f ) },
261 { XYZ1( 1, -1, 1 ), UV( 1.f, 0.f ) },
262};
263
Tony Barbour01999182015-04-09 12:58:51 -0600264class VkRenderTest : public VkRenderFramework
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -0600265{
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600266public:
Cody Northrop4e6b4762014-10-09 21:25:22 -0600267
Tony Barbourf43b6982014-11-25 13:18:32 -0700268 void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbour01999182015-04-09 12:58:51 -0600269 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer);
270 void GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600271 void InitDepthStencil();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600272 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate);
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600273
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600274 VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer);
275 VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer);
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600276
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600277protected:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600278 VkImage m_texture;
279 VkImageView m_textureView;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800280 VkDescriptorInfo m_descriptorInfo;
Tony Barbour8205d902015-04-16 15:59:00 -0600281 VkDeviceMemory m_textureMem;
Cody Northrop350727b2014-10-06 15:42:00 -0600282
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600283 VkSampler m_sampler;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600284
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600285
286 virtual void SetUp() {
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600287
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600288 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600289 this->app_info.pNext = NULL;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800290 this->app_info.pAppName = "render_tests";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600291 this->app_info.appVersion = 1;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800292 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600293 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600294 this->app_info.apiVersion = VK_API_VERSION;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600295
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800296 memset(&m_descriptorInfo, 0, sizeof(m_descriptorInfo));
Cody Northrop350727b2014-10-06 15:42:00 -0600297
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600298 InitFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600299 }
300
301 virtual void TearDown() {
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600302 // Clean up resources before we reset
303 ShutdownFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600304 }
305};
306
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600307VkResult VkRenderTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600308{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600309 VkResult result;
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600310
311 result = cmdBuffer.BeginCommandBuffer();
312
313 /*
314 * For render test all drawing happens in a single render pass
315 * on a single command buffer.
316 */
Chris Forbesfe133ef2015-06-16 14:05:59 +1200317 if (VK_SUCCESS == result && renderPass()) {
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600318 cmdBuffer.BeginRenderPass(renderPass(), framebuffer());
319 }
320
321 return result;
322}
323
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600324VkResult VkRenderTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600325{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600326 VkResult result;
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600327
Chris Forbesfe133ef2015-06-16 14:05:59 +1200328 if (renderPass()) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +0800329 cmdBuffer.EndRenderPass();
Chris Forbesfe133ef2015-06-16 14:05:59 +1200330 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600331
332 result = cmdBuffer.EndCommandBuffer();
333
334 return result;
335}
336
337
Tony Barbour01999182015-04-09 12:58:51 -0600338void VkRenderTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet)
Tony Barbour02472db2015-01-08 17:08:28 -0700339{
Tony Barbour17c6ab12015-03-27 17:03:18 -0600340 if (m_depthStencil->Initialized()) {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600341 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Tony Barbour17c6ab12015-03-27 17:03:18 -0600342 } else {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600343 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour17c6ab12015-03-27 17:03:18 -0600344 }
345
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700346 cmdBuffer->PrepareAttachments();
Tony Barbour8205d902015-04-16 15:59:00 -0600347 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_RASTER, m_stateRaster);
348 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_VIEWPORT, m_stateViewport);
349 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_COLOR_BLEND, m_colorBlend);
350 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_DEPTH_STENCIL, m_stateDepthStencil);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600351 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
352 pipelineobj.CreateVKPipeline(descriptorSet);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600353 cmdBuffer->BindPipeline(pipelineobj);
Chia-I Wu862c5572015-03-28 15:23:55 +0800354 cmdBuffer->BindDescriptorSet(descriptorSet);
Tony Barbour02472db2015-01-08 17:08:28 -0700355}
Tony Barbourf43b6982014-11-25 13:18:32 -0700356
Tony Barbour01999182015-04-09 12:58:51 -0600357void VkRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
358 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer)
Tony Barbourdd4c9642015-01-09 12:55:14 -0700359{
360 int i;
361 glm::mat4 MVP;
362 int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600363 VkResult err;
Tony Barbourdd4c9642015-01-09 12:55:14 -0700364
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600365 /* Only do 3 positions to avoid back face cull */
366 for (i = 0; i < 3; i++) {
Tony Barbourdd4c9642015-01-09 12:55:14 -0700367 void *pData = constantBuffer->map();
368
369 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
370 MVP = Projection * View * Model;
371 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
372
373 constantBuffer->unmap();
374
375 // submit the command buffer to the universal queue
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600376 cmdBuffer->QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700377
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600378 err = vkQueueWaitIdle( m_device->m_queue );
379 ASSERT_VK_SUCCESS( err );
Tony Barbourdd4c9642015-01-09 12:55:14 -0700380
381 // Wait for work to finish before cleaning up.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600382 vkDeviceWaitIdle(m_device->device());
Tony Barbourdd4c9642015-01-09 12:55:14 -0700383
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700384 assert(m_renderTargets.size() == 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -0700385 RecordImage(m_renderTargets[0]);
386 }
387}
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600388
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600389void dumpMatrix(const char *note, glm::mat4 MVP)
390{
Chia-I Wu7133fdc2014-12-15 23:57:34 +0800391 int i;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600392
393 printf("%s: \n", note);
394 for (i=0; i<4; i++) {
395 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
396 }
397 printf("\n");
398 fflush(stdout);
399}
400
401void dumpVec4(const char *note, glm::vec4 vector)
402{
403 printf("%s: \n", note);
404 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
405 printf("\n");
406 fflush(stdout);
407}
408
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600409struct vktriangle_vs_uniform {
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600410 // Must start with MVP
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600411 float mvp[4][4];
412 float position[3][4];
413 float color[3][4];
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600414};
415
Tony Barbour01999182015-04-09 12:58:51 -0600416void VkRenderTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600417{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700418#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600419 vkDbgRegisterMsgCallback(inst, myDbgFunc, NULL);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700420#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600421 // Create identity matrix
422 int i;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600423 struct vktriangle_vs_uniform data;
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600424
425 glm::mat4 Projection = glm::mat4(1.0f);
426 glm::mat4 View = glm::mat4(1.0f);
427 glm::mat4 Model = glm::mat4(1.0f);
428 glm::mat4 MVP = Projection * View * Model;
429 const int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600430 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600431 memcpy(&data.mvp, &MVP[0][0], matrixSize);
432
433 static const Vertex tri_data[] =
434 {
435 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
436 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
437 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
438 };
439
440 for (i=0; i<3; i++) {
441 data.position[i][0] = tri_data[i].posX;
442 data.position[i][1] = tri_data[i].posY;
443 data.position[i][2] = tri_data[i].posZ;
444 data.position[i][3] = tri_data[i].posW;
445 data.color[i][0] = tri_data[i].r;
446 data.color[i][1] = tri_data[i].g;
447 data.color[i][2] = tri_data[i].b;
448 data.color[i][3] = tri_data[i].a;
449 }
450
Tony Barbourf43b6982014-11-25 13:18:32 -0700451 ASSERT_NO_FATAL_FAILURE(InitState());
452 ASSERT_NO_FATAL_FAILURE(InitViewport());
453
Tony Barbour01999182015-04-09 12:58:51 -0600454 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barbourf43b6982014-11-25 13:18:32 -0700455
Tony Barbour01999182015-04-09 12:58:51 -0600456 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
457 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700458
Tony Barbour01999182015-04-09 12:58:51 -0600459 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -0700460 pipelineobj.AddShader(&vs);
461 pipelineobj.AddShader(&ps);
462
Tony Barbour01999182015-04-09 12:58:51 -0600463 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600464 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700465
Tony Barbour71ba3612015-01-09 16:12:35 -0700466 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600467 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour71ba3612015-01-09 16:12:35 -0700468 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700469
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600470 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour71ba3612015-01-09 16:12:35 -0700471
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600472 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour71ba3612015-01-09 16:12:35 -0700473#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600474 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour71ba3612015-01-09 16:12:35 -0700475 pDSDumpDot((char*)"triTest2.dot");
476#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600477
Tony Barbour71ba3612015-01-09 16:12:35 -0700478 // render triangle
479 cmdBuffer.Draw(0, 3, 0, 1);
480
481 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600482 EndCommandBuffer(cmdBuffer);
483
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600484 cmdBuffer.QueueCommandBuffer();
Tony Barbour71ba3612015-01-09 16:12:35 -0700485
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600486 RecordImages(m_renderTargets);
Tony Barbour71ba3612015-01-09 16:12:35 -0700487
488 if (rotate)
Tobin Ehlis12ee35f2015-03-26 08:23:25 -0600489 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
Tony Barbour71ba3612015-01-09 16:12:35 -0700490
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700491#ifdef PRINT_OBJECTS
Mark Lobodzinski4e5016f2015-05-05 15:01:37 -0500492 OBJ_TRACK_GET_OBJECTS_COUNT pObjTrackGetObjectsCount = (OBJ_TRACK_GET_OBJECTS_COUNT)vkGetProcAddr(gpu(), (char*)"objTrackGetObjectsCount");
Mark Lobodzinski14305ad2015-06-23 11:35:12 -0600493 uint64_t numObjects = pObjTrackGetObjectsCount(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600494 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700495 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600496 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700497 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
Mark Lobodzinski14305ad2015-06-23 11:35:12 -0600498 pObjTrackGetObjs(m_device, numObjects, pObjNodeArray);
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700499 for (i=0; i < numObjects; i++) {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600500 printf("Object %i of type %s has objID (%p) and %lu uses\n", i, string_VkObjectType(pObjNodeArray[i].objType), pObjNodeArray[i].pObj, pObjNodeArray[i].numUses);
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700501 }
502 free(pObjNodeArray);
503#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700504
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600505}
506
Tony Barbour01999182015-04-09 12:58:51 -0600507TEST_F(VkRenderTest, VKTriangle_FragColor)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600508{
509 static const char *vertShaderText =
510 "#version 140\n"
511 "#extension GL_ARB_separate_shader_objects : enable\n"
512 "#extension GL_ARB_shading_language_420pack : enable\n"
513 "\n"
514 "layout(binding = 0) uniform buf {\n"
515 " mat4 MVP;\n"
516 " vec4 position[3];\n"
517 " vec4 color[3];\n"
518 "} ubuf;\n"
519 "\n"
520 "layout (location = 0) out vec4 outColor;\n"
521 "\n"
522 "void main() \n"
523 "{\n"
524 " outColor = ubuf.color[gl_VertexID];\n"
525 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
526 "}\n";
527
528 static const char *fragShaderText =
529 "#version 140\n"
530 "#extension GL_ARB_separate_shader_objects : enable\n"
531 "#extension GL_ARB_shading_language_420pack : enable\n"
532 "\n"
533 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600534 "layout (location = 0) out vec4 uFragColor;\n"
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600535 "\n"
536 "void main()\n"
537 "{\n"
GregFd6ebdb32015-06-03 18:40:50 -0600538 " uFragColor = inColor;\n"
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600539 "}\n";
540
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600541 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
542 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600543}
544
Tony Barbour01999182015-04-09 12:58:51 -0600545TEST_F(VkRenderTest, VKTriangle_OutputLocation)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600546{
547 static const char *vertShaderText =
548 "#version 140\n"
549 "#extension GL_ARB_separate_shader_objects : enable\n"
550 "#extension GL_ARB_shading_language_420pack : enable\n"
551 "\n"
552 "layout(binding = 0) uniform buf {\n"
553 " mat4 MVP;\n"
554 " vec4 position[3];\n"
555 " vec4 color[3];\n"
556 "} ubuf;\n"
557 "\n"
558 "layout (location = 0) out vec4 outColor;\n"
559 "\n"
560 "void main() \n"
561 "{\n"
562 " outColor = ubuf.color[gl_VertexID];\n"
563 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
564 "}\n";
565
566 static const char *fragShaderText =
567 "#version 140\n"
568 "#extension GL_ARB_separate_shader_objects : enable\n"
569 "#extension GL_ARB_shading_language_420pack : enable\n"
570 "\n"
571 "layout (location = 0) in vec4 inColor;\n"
572 "layout (location = 0) out vec4 outColor;\n"
573 "\n"
574 "void main()\n"
575 "{\n"
576 " outColor = inColor;\n"
577 "}\n";
578
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600579 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to output location 0, which should be the same as gl_FragColor");
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600580
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600581 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600582}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600583#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 -0600584TEST_F(VkRenderTest, SPV_VKTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700585{
Tony Barbourf43b6982014-11-25 13:18:32 -0700586 static const char *vertShaderText =
587 "#version 140\n"
588 "#extension GL_ARB_separate_shader_objects : enable\n"
589 "#extension GL_ARB_shading_language_420pack : enable\n"
590 "\n"
591 "layout(binding = 0) uniform buf {\n"
592 " mat4 MVP;\n"
593 " vec4 position[3];\n"
594 " vec4 color[3];\n"
595 "} ubuf;\n"
596 "\n"
597 "layout (location = 0) out vec4 outColor;\n"
598 "\n"
599 "void main() \n"
600 "{\n"
601 " outColor = ubuf.color[gl_VertexID];\n"
602 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
603 "}\n";
604
605 static const char *fragShaderText =
606 "#version 140\n"
607 "#extension GL_ARB_separate_shader_objects : enable\n"
608 "#extension GL_ARB_shading_language_420pack : enable\n"
609 "\n"
610 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600611 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700612 "\n"
613 "void main()\n"
614 "{\n"
GregFd6ebdb32015-06-03 18:40:50 -0600615 " outColor = inColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700616 "}\n";
617
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600618 TEST_DESCRIPTION("VK-style shaders, but force test framework to compile shader to SPV and pass SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700619
Cody Northrop1cfbd172015-06-03 16:49:20 -0600620 ScopedUseGlsl useGlsl(false);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600621 VKTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700622}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600623#endif
Tony Barbour01999182015-04-09 12:58:51 -0600624TEST_F(VkRenderTest, GreenTriangle)
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600625{
626 static const char *vertShaderText =
627 "#version 130\n"
628 "vec2 vertices[3];\n"
629 "void main() {\n"
630 " vertices[0] = vec2(-1.0, -1.0);\n"
631 " vertices[1] = vec2( 1.0, -1.0);\n"
632 " vertices[2] = vec2( 0.0, 1.0);\n"
633 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
634 "}\n";
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600635
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600636 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600637 "#version 140\n"
638 "#extension GL_ARB_separate_shader_objects : enable\n"
639 "#extension GL_ARB_shading_language_420pack : enable\n"
640 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600641 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600642 " outColor = vec4(0,1,0,1);\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600643 "}\n";
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600644
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600645 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
646
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600647 VKTriangleTest(vertShaderText, fragShaderText, false);
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600648}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600649#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 -0600650TEST_F(VkRenderTest, SPV_GreenTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700651{
Tony Barbourf43b6982014-11-25 13:18:32 -0700652 static const char *vertShaderText =
653 "#version 130\n"
654 "vec2 vertices[3];\n"
655 "void main() {\n"
656 " vertices[0] = vec2(-1.0, -1.0);\n"
657 " vertices[1] = vec2( 1.0, -1.0);\n"
658 " vertices[2] = vec2( 0.0, 1.0);\n"
659 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
660 "}\n";
661
662 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600663 "#version 140\n"
664 "#extension GL_ARB_separate_shader_objects : enable\n"
665 "#extension GL_ARB_shading_language_420pack : enable\n"
666 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700667 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600668 " outColor = vec4(0,1,0,1);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700669 "}\n";
670
Cody Northropacfb0492015-03-17 15:55:58 -0600671 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700672
Cody Northrop1cfbd172015-06-03 16:49:20 -0600673 ScopedUseGlsl useGlsl(false);
674
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600675 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700676}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600677#endif
Tony Barbour01999182015-04-09 12:58:51 -0600678TEST_F(VkRenderTest, YellowTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700679{
680 static const char *vertShaderText =
681 "#version 130\n"
682 "void main() {\n"
683 " vec2 vertices[3];"
684 " vertices[0] = vec2(-0.5, -0.5);\n"
685 " vertices[1] = vec2( 0.5, -0.5);\n"
686 " vertices[2] = vec2( 0.5, 0.5);\n"
687 " vec4 colors[3];\n"
688 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
689 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
690 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
691 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
692 "}\n";
693
694 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600695 "#version 140\n"
696 "#extension GL_ARB_separate_shader_objects : enable\n"
697 "#extension GL_ARB_shading_language_420pack : enable\n"
698 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700699 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600700 " outColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700701 "}\n";
702
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600703 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700704}
705
Tony Barbour01999182015-04-09 12:58:51 -0600706TEST_F(VkRenderTest, QuadWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600707{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600708 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600709 "#version 140\n"
710 "#extension GL_ARB_separate_shader_objects : enable\n"
711 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700712 //XYZ1( -1, -1, -1 )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600713 "layout (location = 0) in vec4 pos;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700714 //XYZ1( 0.f, 0.f, 0.f )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600715 "layout (location = 1) in vec4 inColor;\n"
716 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600717 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600718 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600719 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600720 "}\n";
721
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600722
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600723 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700724 "#version 140\n"
725 "#extension GL_ARB_separate_shader_objects : enable\n"
726 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600727 "layout (location = 0) in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700728 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600729 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700730 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600731 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600732
Tony Barbourf43b6982014-11-25 13:18:32 -0700733
734
735 ASSERT_NO_FATAL_FAILURE(InitState());
736 ASSERT_NO_FATAL_FAILURE(InitViewport());
737
Tony Barbour01999182015-04-09 12:58:51 -0600738 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000739 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700740
Tony Barbour01999182015-04-09 12:58:51 -0600741 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
742 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700743
Tony Barbour01999182015-04-09 12:58:51 -0600744 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -0700745 pipelineobj.AddShader(&vs);
746 pipelineobj.AddShader(&ps);
747
Tony Barbour01999182015-04-09 12:58:51 -0600748 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600749 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -0600750
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600751#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600752 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600753 MESH_BIND_ID, // binding ID
Tony Barbourf43b6982014-11-25 13:18:32 -0700754 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600755 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -0700756 };
757
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600758 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600759 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
760 vi_attribs[0].location = 0; // location, position
Tony Barbour8205d902015-04-16 15:59:00 -0600761 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600762 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
763 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
764 vi_attribs[1].location = 1; // location, color
Tony Barbour8205d902015-04-16 15:59:00 -0600765 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600766 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 -0700767
768 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
769 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600770 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -0700771
Tony Barboure4ed9942015-01-09 10:06:53 -0700772 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600773 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700774 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700775
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600776 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600777
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600778 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700779
Tony Barboure4ed9942015-01-09 10:06:53 -0700780 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
781
782 // render two triangles
783 cmdBuffer.Draw(0, 6, 0, 1);
784
785 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600786 EndCommandBuffer(cmdBuffer);
787
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600788 cmdBuffer.QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -0700789
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600790 RecordImages(m_renderTargets);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600791}
792
Tony Barbour01999182015-04-09 12:58:51 -0600793TEST_F(VkRenderTest, TriangleMRT)
Chia-I Wue09d1a72014-12-05 10:32:23 +0800794{
795 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600796 "#version 140\n"
797 "#extension GL_ARB_separate_shader_objects : enable\n"
798 "#extension GL_ARB_shading_language_420pack : enable\n"
799 "layout (location = 0) in vec4 pos;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800800 "void main() {\n"
801 " gl_Position = pos;\n"
802 "}\n";
803
804 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600805 "#version 140\n"
806 "#extension GL_ARB_separate_shader_objects : enable\n"
807 "#extension GL_ARB_shading_language_420pack : enable\n"
808 "layout (location = 0) out vec4 uFragData0;\n"
809 "layout (location = 1) out vec4 uFragData1;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800810 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600811 " uFragData0 = vec4(1.0, 0.0, 0.0, 1.0);\n"
812 " uFragData1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800813 "}\n";
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600814 const float vb_data[][2] = {
Chia-I Wue09d1a72014-12-05 10:32:23 +0800815 { -1.0f, -1.0f },
816 { 1.0f, -1.0f },
817 { -1.0f, 1.0f }
818 };
819
820 ASSERT_NO_FATAL_FAILURE(InitState());
821 ASSERT_NO_FATAL_FAILURE(InitViewport());
822
Tony Barbour01999182015-04-09 12:58:51 -0600823 VkConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000824 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800825
Tony Barbour01999182015-04-09 12:58:51 -0600826 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
827 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800828
Tony Barbour01999182015-04-09 12:58:51 -0600829 VkPipelineObj pipelineobj(m_device);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800830 pipelineobj.AddShader(&vs);
831 pipelineobj.AddShader(&ps);
832
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600833#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600834 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600835 MESH_BUF_ID, // Binding ID
836 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600837 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Chia-I Wue09d1a72014-12-05 10:32:23 +0800838 };
839
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600840 VkVertexInputAttributeDescription vi_attrib;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600841 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
842 vi_attrib.location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -0600843 vi_attrib.format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600844 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
Chia-I Wue09d1a72014-12-05 10:32:23 +0800845
846 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
847 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600848 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800849
Tony Barbour01999182015-04-09 12:58:51 -0600850 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600851 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800852
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700853 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
Chia-I Wue09d1a72014-12-05 10:32:23 +0800854
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600855 VkPipelineCbAttachmentState att = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600856 att.blendEnable = VK_FALSE;
Chia-I Wue09d1a72014-12-05 10:32:23 +0800857 att.format = m_render_target_fmt;
858 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700859 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800860
Tony Barbour01999182015-04-09 12:58:51 -0600861 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700862
Tony Barbour5ed79702015-01-07 14:31:52 -0700863 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
864 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barboure4ed9942015-01-09 10:06:53 -0700865
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600866 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour5ed79702015-01-07 14:31:52 -0700867
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600868 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700869
Tony Barbour5ed79702015-01-07 14:31:52 -0700870 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700871#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600872 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour5ed79702015-01-07 14:31:52 -0700873 pDSDumpDot((char*)"triTest2.dot");
874#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600875
Tony Barbour5ed79702015-01-07 14:31:52 -0700876 // render triangle
877 cmdBuffer.Draw(0, 3, 0, 1);
878
879 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600880 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600881 cmdBuffer.QueueCommandBuffer();
Tony Barbour5ed79702015-01-07 14:31:52 -0700882
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600883 RecordImages(m_renderTargets);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800884}
885
Tony Barbour01999182015-04-09 12:58:51 -0600886TEST_F(VkRenderTest, QuadWithIndexedVertexFetch)
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700887{
888 static const char *vertShaderText =
889 "#version 140\n"
890 "#extension GL_ARB_separate_shader_objects : enable\n"
891 "#extension GL_ARB_shading_language_420pack : enable\n"
892 "layout(location = 0) in vec4 pos;\n"
893 "layout(location = 1) in vec4 inColor;\n"
894 "layout(location = 0) out vec4 outColor;\n"
895 "void main() {\n"
896 " outColor = inColor;\n"
897 " gl_Position = pos;\n"
898 "}\n";
899
900
901 static const char *fragShaderText =
902 "#version 140\n"
903 "#extension GL_ARB_separate_shader_objects : enable\n"
904 "#extension GL_ARB_shading_language_420pack : enable\n"
905 "layout(location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600906 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700907 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600908 " outColor = color;\n"
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700909 "}\n";
910
911 const Vertex g_vbData[] =
912 {
913 // first tri
914 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
915 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
916 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
917
918 // second tri
919 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
920 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
921 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
922 };
923
924 const uint16_t g_idxData[6] = {
925 0, 1, 2,
926 3, 4, 5,
927 };
928
929 ASSERT_NO_FATAL_FAILURE(InitState());
930 ASSERT_NO_FATAL_FAILURE(InitViewport());
931
Tony Barbour01999182015-04-09 12:58:51 -0600932 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000933 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700934
Tony Barbour01999182015-04-09 12:58:51 -0600935 VkIndexBufferObj indexBuffer(m_device);
Tony Barbour8205d902015-04-16 15:59:00 -0600936 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), VK_INDEX_TYPE_UINT16, g_idxData);
Mark Lobodzinskid30f82a2015-02-16 14:24:23 -0600937 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700938
Tony Barbour01999182015-04-09 12:58:51 -0600939 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
940 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700941
Tony Barbour01999182015-04-09 12:58:51 -0600942 VkPipelineObj pipelineobj(m_device);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700943 pipelineobj.AddShader(&vs);
944 pipelineobj.AddShader(&ps);
945
Tony Barbour01999182015-04-09 12:58:51 -0600946 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600947 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
948 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, indexBuffer);
Tony Barbour83a83802015-04-02 15:43:15 -0600949
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700950
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600951#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600952 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600953 MESH_BIND_ID, // binding ID
954 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600955 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700956 };
957
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600958 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600959 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
960 vi_attribs[0].location = 0; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600961 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600962 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
963 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
964 vi_attribs[1].location = 1; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600965 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600966 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700967
968 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
969 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700970
971 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600972 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700973 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600974 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barboure4ed9942015-01-09 10:06:53 -0700975
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600976 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700977
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700978#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600979 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700980 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700981#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700982
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600983 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600984 cmdBuffer.BindIndexBuffer(&indexBuffer, 0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700985
986 // render two triangles
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700987 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700988
989 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600990 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600991 cmdBuffer.QueueCommandBuffer();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700992
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600993 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700994}
995
Tony Barbour01999182015-04-09 12:58:51 -0600996TEST_F(VkRenderTest, GreyandRedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -0700997{
998 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -0700999
GregF6bef1212014-12-02 15:41:44 -07001000 static const char *vertShaderText =
1001 "#version 140\n"
1002 "#extension GL_ARB_separate_shader_objects : enable\n"
1003 "#extension GL_ARB_shading_language_420pack : enable\n"
1004 "layout (location = 0) in vec4 pos;\n"
1005 "layout (location = 0) out vec4 outColor;\n"
1006 "layout (location = 1) out vec4 outColor2;\n"
1007 "void main() {\n"
1008 " gl_Position = pos;\n"
1009 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1010 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1011 "}\n";
1012
1013 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001014 "#version 330\n"
1015 "#extension GL_ARB_separate_shader_objects : enable\n"
1016 "#extension GL_ARB_shading_language_420pack : enable\n"
1017 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1018 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1019 "layout (location = 0) in vec4 color;\n"
1020 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001021 "layout (location = 0) out vec4 outColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001022 "void main() {\n"
1023 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1024 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001025 " outColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001026 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1027 " : color2;\n"
1028 "}\n";
1029
1030 ASSERT_NO_FATAL_FAILURE(InitState());
1031 ASSERT_NO_FATAL_FAILURE(InitViewport());
1032
Tony Barbour01999182015-04-09 12:58:51 -06001033 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001034 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001035
Tony Barbour01999182015-04-09 12:58:51 -06001036 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1037 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001038
Tony Barbour01999182015-04-09 12:58:51 -06001039 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001040 pipelineobj.AddShader(&vs);
1041 pipelineobj.AddShader(&ps);
1042
Tony Barbour01999182015-04-09 12:58:51 -06001043 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001044 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001045
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001046#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001047 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001048 MESH_BIND_ID, // binding ID
1049 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001050 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001051 };
1052
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001053 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001054 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1055 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001056 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001057 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001058
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001059 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001060 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001061 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001062
Tony Barbourdd4c9642015-01-09 12:55:14 -07001063 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001064 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001065 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1066
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001067 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001068
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001069 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001070
1071 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1072#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001073 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001074 pDSDumpDot((char*)"triTest2.dot");
1075#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001076
Tony Barbourdd4c9642015-01-09 12:55:14 -07001077 // render triangle
1078 cmdBuffer.Draw(0, 6, 0, 1);
1079
1080 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001081 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001082 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001083
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001084 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001085}
1086
Tony Barbour01999182015-04-09 12:58:51 -06001087TEST_F(VkRenderTest, RedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -07001088{
1089 // This tests that we correctly handle unread fragment inputs
1090
1091 static const char *vertShaderText =
1092 "#version 140\n"
1093 "#extension GL_ARB_separate_shader_objects : enable\n"
1094 "#extension GL_ARB_shading_language_420pack : enable\n"
1095 "layout (location = 0) in vec4 pos;\n"
1096 "layout (location = 0) out vec4 outColor;\n"
1097 "layout (location = 1) out vec4 outColor2;\n"
1098 "void main() {\n"
1099 " gl_Position = pos;\n"
1100 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1101 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1102 "}\n";
1103
1104 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001105 "#version 330\n"
1106 "#extension GL_ARB_separate_shader_objects : enable\n"
1107 "#extension GL_ARB_shading_language_420pack : enable\n"
1108 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1109 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1110 "layout (location = 0) in vec4 color;\n"
1111 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001112 "layout (location = 0) out vec4 outColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001113 "void main() {\n"
1114 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1115 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001116 " outColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001117 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1118 " : color2;\n"
1119 "}\n";
1120
1121 ASSERT_NO_FATAL_FAILURE(InitState());
1122 ASSERT_NO_FATAL_FAILURE(InitViewport());
1123
Tony Barbour01999182015-04-09 12:58:51 -06001124 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001125 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001126
Tony Barbour01999182015-04-09 12:58:51 -06001127 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1128 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001129
Tony Barbour01999182015-04-09 12:58:51 -06001130 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001131 pipelineobj.AddShader(&vs);
1132 pipelineobj.AddShader(&ps);
1133
Tony Barbour01999182015-04-09 12:58:51 -06001134 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001135 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001136
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001137#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001138 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001139 MESH_BIND_ID, // binding ID
1140 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001141 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001142 };
1143
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001144 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001145 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1146 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001147 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001148 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001149
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001150 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001151 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001152 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001153
Tony Barbourdd4c9642015-01-09 12:55:14 -07001154 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001155 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001156 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1157
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001158 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001159
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001160 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001161
1162 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1163#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001164 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001165 pDSDumpDot((char*)"triTest2.dot");
1166#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001167 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001168 cmdBuffer.Draw(0, 6, 0, 1);
1169
1170 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001171 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001172 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001173
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001174 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001175}
1176
Tony Barbour01999182015-04-09 12:58:51 -06001177TEST_F(VkRenderTest, GreyCirclesonBlueFade)
GregF6bef1212014-12-02 15:41:44 -07001178{
1179 // This tests reading gl_ClipDistance from FS
1180
1181 static const char *vertShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001182 //"#version 140\n"
GregF6bef1212014-12-02 15:41:44 -07001183 "#version 330\n"
1184 "#extension GL_ARB_separate_shader_objects : enable\n"
1185 "#extension GL_ARB_shading_language_420pack : enable\n"
1186 "out gl_PerVertex {\n"
1187 " vec4 gl_Position;\n"
1188 " float gl_ClipDistance[1];\n"
1189 "};\n"
1190 "layout (location = 0) in vec4 pos;\n"
1191 "layout (location = 0) out vec4 outColor;\n"
1192 "layout (location = 1) out vec4 outColor2;\n"
1193 "void main() {\n"
1194 " gl_Position = pos;\n"
1195 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1196 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1197 " float dists[3];\n"
1198 " dists[0] = 0.0;\n"
1199 " dists[1] = 1.0;\n"
1200 " dists[2] = 1.0;\n"
1201 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1202 "}\n";
1203
1204
1205 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001206 "#version 140\n"
1207 //"#version 330\n"
GregF6bef1212014-12-02 15:41:44 -07001208 "#extension GL_ARB_separate_shader_objects : enable\n"
1209 "#extension GL_ARB_shading_language_420pack : enable\n"
1210 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1211 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1212 "layout (location = 0) in vec4 color;\n"
1213 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001214 "layout (location = 0) out vec4 uFragColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001215 "void main() {\n"
1216 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1217 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001218 " uFragColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001219 " ? color * gl_ClipDistance[0]\n"
1220 " : color2;\n"
1221 "}\n";
1222
1223 ASSERT_NO_FATAL_FAILURE(InitState());
1224 ASSERT_NO_FATAL_FAILURE(InitViewport());
1225
Tony Barbour01999182015-04-09 12:58:51 -06001226 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001227 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001228
Tony Barbour01999182015-04-09 12:58:51 -06001229 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1230 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001231
Tony Barbour01999182015-04-09 12:58:51 -06001232 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001233 pipelineobj.AddShader(&vs);
1234 pipelineobj.AddShader(&ps);
1235
Tony Barbour01999182015-04-09 12:58:51 -06001236 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001237 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001238
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001239#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001240 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001241 MESH_BIND_ID, // binding ID
1242 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001243 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001244 };
1245
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001246 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001247 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1248 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001249 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001250 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001251
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001252 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001253 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001254 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001255
Tony Barbourdd4c9642015-01-09 12:55:14 -07001256 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001257 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001258 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF6bef1212014-12-02 15:41:44 -07001259
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001260 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001261
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001262 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001263
1264 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1265#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001266 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001267 pDSDumpDot((char*)"triTest2.dot");
1268#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001269
1270 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001271 cmdBuffer.Draw(0, 6, 0, 1);
1272
1273 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001274 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001275 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001276
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001277 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001278}
Tony Barbourf43b6982014-11-25 13:18:32 -07001279
Tony Barbour01999182015-04-09 12:58:51 -06001280TEST_F(VkRenderTest, GreyCirclesonBlueDiscard)
GregF7a23c792014-12-02 17:19:34 -07001281{
1282 static const char *vertShaderText =
1283 "#version 140\n"
1284 "#extension GL_ARB_separate_shader_objects : enable\n"
1285 "#extension GL_ARB_shading_language_420pack : enable\n"
1286 "layout (location = 0) in vec4 pos;\n"
1287 "layout (location = 0) out vec4 outColor;\n"
1288 "layout (location = 1) out vec4 outColor2;\n"
1289 "void main() {\n"
1290 " gl_Position = pos;\n"
1291 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1292 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1293 "}\n";
1294
1295
1296 static const char *fragShaderText =
GregF7a23c792014-12-02 17:19:34 -07001297 "#version 330\n"
1298 "#extension GL_ARB_separate_shader_objects : enable\n"
1299 "#extension GL_ARB_shading_language_420pack : enable\n"
1300 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1301 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1302 "layout (location = 0) in vec4 color;\n"
1303 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001304 "layout (location = 0) out vec4 outColor;\n"
GregF7a23c792014-12-02 17:19:34 -07001305 "void main() {\n"
1306 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1307 " float dist_squared = dot(pos, pos);\n"
1308 " if (dist_squared < 100.0)\n"
1309 " discard;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001310 " outColor = (dist_squared < 400.0)\n"
GregF7a23c792014-12-02 17:19:34 -07001311 " ? color\n"
1312 " : color2;\n"
1313 "}\n";
1314
1315 ASSERT_NO_FATAL_FAILURE(InitState());
1316 ASSERT_NO_FATAL_FAILURE(InitViewport());
1317
Tony Barbour01999182015-04-09 12:58:51 -06001318 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001319 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001320
Tony Barbour01999182015-04-09 12:58:51 -06001321 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1322 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF7a23c792014-12-02 17:19:34 -07001323
Tony Barbour01999182015-04-09 12:58:51 -06001324 VkPipelineObj pipelineobj(m_device);
GregF7a23c792014-12-02 17:19:34 -07001325 pipelineobj.AddShader(&vs);
1326 pipelineobj.AddShader(&ps);
1327
Tony Barbour01999182015-04-09 12:58:51 -06001328 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001329 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001330
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001331#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001332 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001333 MESH_BIND_ID, // binding ID
1334 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001335 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF7a23c792014-12-02 17:19:34 -07001336 };
1337
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001338 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001339 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1340 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001341 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001342 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF7a23c792014-12-02 17:19:34 -07001343
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001344 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF7a23c792014-12-02 17:19:34 -07001345 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001346 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF7a23c792014-12-02 17:19:34 -07001347
Tony Barbourdd4c9642015-01-09 12:55:14 -07001348 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001349 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001350 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1351
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001352 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001353
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001354 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001355
1356 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1357#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001358 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001359 pDSDumpDot((char*)"triTest2.dot");
1360#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001361
1362 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001363 cmdBuffer.Draw(0, 6, 0, 1);
1364
1365 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001366 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001367 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001368
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001369 RecordImages(m_renderTargets);
GregF7a23c792014-12-02 17:19:34 -07001370}
1371
1372
Tony Barbour01999182015-04-09 12:58:51 -06001373TEST_F(VkRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001374{
1375 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001376 "#version 140\n"
1377 "#extension GL_ARB_separate_shader_objects : enable\n"
1378 "#extension GL_ARB_shading_language_420pack : enable\n"
1379 "\n"
1380 "layout(binding = 0) uniform buf {\n"
1381 " mat4 MVP;\n"
1382 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001383 "void main() {\n"
1384 " vec2 vertices[3];"
1385 " vertices[0] = vec2(-0.5, -0.5);\n"
1386 " vertices[1] = vec2( 0.5, -0.5);\n"
1387 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001388 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001389 "}\n";
1390
1391 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001392 "#version 140\n"
1393 "#extension GL_ARB_separate_shader_objects : enable\n"
1394 "#extension GL_ARB_shading_language_420pack : enable\n"
1395 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001396 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001397 " outColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001398 "}\n";
1399
Tony Barbourf43b6982014-11-25 13:18:32 -07001400 ASSERT_NO_FATAL_FAILURE(InitState());
1401 ASSERT_NO_FATAL_FAILURE(InitViewport());
1402
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001403 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001404 glm::mat4 Projection = glm::mat4(1.0f);
1405 glm::mat4 View = glm::mat4(1.0f);
1406 glm::mat4 Model = glm::mat4(1.0f);
1407 glm::mat4 MVP = Projection * View * Model;
1408 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1409
Tony Barbour01999182015-04-09 12:58:51 -06001410 VkConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1411 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1412 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001413
Tony Barbour01999182015-04-09 12:58:51 -06001414 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001415 pipelineobj.AddShader(&vs);
1416 pipelineobj.AddShader(&ps);
1417
1418 // Create descriptor set and attach the constant buffer to it
Tony Barbour01999182015-04-09 12:58:51 -06001419 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001420 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001421
Tony Barbourdd4c9642015-01-09 12:55:14 -07001422 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001423 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001424 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001425
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001426 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001427
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001428 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001429
1430 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1431#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001432 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001433 pDSDumpDot((char*)"triTest2.dot");
1434#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001435
1436 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001437 cmdBuffer.Draw(0, 6, 0, 1);
1438
1439 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001440 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001441 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001442
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001443 RecordImages(m_renderTargets);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001444
1445 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001446}
1447
Tony Barbour01999182015-04-09 12:58:51 -06001448TEST_F(VkRenderTest, MixTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07001449{
1450 // This tests location applied to varyings. Notice that we have switched foo
1451 // and bar in the FS. The triangle should be blended with red, green and blue
1452 // corners.
1453 static const char *vertShaderText =
1454 "#version 140\n"
1455 "#extension GL_ARB_separate_shader_objects : enable\n"
1456 "#extension GL_ARB_shading_language_420pack : enable\n"
1457 "layout (location=0) out vec4 bar;\n"
1458 "layout (location=1) out vec4 foo;\n"
1459 "layout (location=2) out float scale;\n"
1460 "vec2 vertices[3];\n"
1461 "void main() {\n"
1462 " vertices[0] = vec2(-1.0, -1.0);\n"
1463 " vertices[1] = vec2( 1.0, -1.0);\n"
1464 " vertices[2] = vec2( 0.0, 1.0);\n"
1465 "vec4 colors[3];\n"
1466 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1467 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1468 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1469 " foo = colors[gl_VertexID % 3];\n"
1470 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1471 " scale = 1.0;\n"
1472 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1473 "}\n";
1474
1475 static const char *fragShaderText =
1476 "#version 140\n"
1477 "#extension GL_ARB_separate_shader_objects : enable\n"
1478 "#extension GL_ARB_shading_language_420pack : enable\n"
1479 "layout (location = 1) in vec4 bar;\n"
1480 "layout (location = 0) in vec4 foo;\n"
1481 "layout (location = 2) in float scale;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001482 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001483 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001484 " outColor = bar * scale + foo * (1.0-scale);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001485 "}\n";
1486
1487 ASSERT_NO_FATAL_FAILURE(InitState());
1488 ASSERT_NO_FATAL_FAILURE(InitViewport());
1489
Tony Barbour01999182015-04-09 12:58:51 -06001490 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1491 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001492
Tony Barbour01999182015-04-09 12:58:51 -06001493 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001494 pipelineobj.AddShader(&vs);
1495 pipelineobj.AddShader(&ps);
1496
Tony Barbour01999182015-04-09 12:58:51 -06001497 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06001498 descriptorSet.AppendDummy();
Tony Barbourf43b6982014-11-25 13:18:32 -07001499
Tony Barbourdd4c9642015-01-09 12:55:14 -07001500 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001501 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001502 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1503
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001504 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001505
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001506 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001507
1508#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001509 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001510 pDSDumpDot((char*)"triTest2.dot");
1511#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001512
Tony Barbourdd4c9642015-01-09 12:55:14 -07001513 // render triangle
1514 cmdBuffer.Draw(0, 3, 0, 1);
1515
1516 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001517 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001518 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001519
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001520 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001521}
1522
Tony Barbour01999182015-04-09 12:58:51 -06001523TEST_F(VkRenderTest, QuadVertFetchAndVertID)
Tony Barbourf43b6982014-11-25 13:18:32 -07001524{
1525 // This tests that attributes work in the presence of gl_VertexID
1526
1527 static const char *vertShaderText =
1528 "#version 140\n"
1529 "#extension GL_ARB_separate_shader_objects : enable\n"
1530 "#extension GL_ARB_shading_language_420pack : enable\n"
1531 //XYZ1( -1, -1, -1 )
1532 "layout (location = 0) in vec4 pos;\n"
1533 //XYZ1( 0.f, 0.f, 0.f )
1534 "layout (location = 1) in vec4 inColor;\n"
1535 "layout (location = 0) out vec4 outColor;\n"
1536 "void main() {\n"
1537 " outColor = inColor;\n"
1538 " vec4 vertices[3];"
1539 " vertices[gl_VertexID % 3] = pos;\n"
1540 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1541 "}\n";
1542
1543
1544 static const char *fragShaderText =
1545 "#version 140\n"
1546 "#extension GL_ARB_separate_shader_objects : enable\n"
1547 "#extension GL_ARB_shading_language_420pack : enable\n"
1548 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001549 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001550 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001551 " outColor = color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001552 "}\n";
1553
1554 ASSERT_NO_FATAL_FAILURE(InitState());
1555 ASSERT_NO_FATAL_FAILURE(InitViewport());
1556
Tony Barbour01999182015-04-09 12:58:51 -06001557 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001558 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001559
Tony Barbour01999182015-04-09 12:58:51 -06001560 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1561 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001562
Tony Barbour01999182015-04-09 12:58:51 -06001563 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001564 pipelineobj.AddShader(&vs);
1565 pipelineobj.AddShader(&ps);
1566
Tony Barbour01999182015-04-09 12:58:51 -06001567 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001568 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001569
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001570#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001571 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001572 MESH_BUF_ID, // Binding ID
1573 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001574 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001575 };
1576
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001577 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001578 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1579 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001580 vi_attribs[0].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001581 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1582 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1583 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001584 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001585 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001586
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001587 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001588 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001589 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001590
Tony Barbourdd4c9642015-01-09 12:55:14 -07001591 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001592 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001593 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1594
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001595 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001596
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001597 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001598
1599 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1600#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001601 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001602 pDSDumpDot((char*)"triTest2.dot");
1603#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001604
1605 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001606 cmdBuffer.Draw(0, 6, 0, 1);
1607
1608 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001609 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001610 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001611
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001612 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001613}
1614
Tony Barbour01999182015-04-09 12:58:51 -06001615TEST_F(VkRenderTest, QuadSparseVertFetch)
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001616{
1617 // This tests that attributes work in the presence of gl_VertexID
1618
1619 static const char *vertShaderText =
1620 "#version 140\n"
1621 "#extension GL_ARB_separate_shader_objects : enable\n"
1622 "#extension GL_ARB_shading_language_420pack : enable\n"
1623 //XYZ1( -1, -1, -1 )
1624 "layout (location = 1) in vec4 pos;\n"
1625 "layout (location = 4) in vec4 inColor;\n"
1626 //XYZ1( 0.f, 0.f, 0.f )
1627 "layout (location = 0) out vec4 outColor;\n"
1628 "void main() {\n"
1629 " outColor = inColor;\n"
1630 " gl_Position = pos;\n"
1631 "}\n";
1632
1633
1634 static const char *fragShaderText =
1635 "#version 140\n"
1636 "#extension GL_ARB_separate_shader_objects : enable\n"
1637 "#extension GL_ARB_shading_language_420pack : enable\n"
1638 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001639 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001640 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001641 " outColor = color;\n"
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001642 "}\n";
1643
1644 ASSERT_NO_FATAL_FAILURE(InitState());
1645 ASSERT_NO_FATAL_FAILURE(InitViewport());
1646
1647 struct VDATA
1648 {
1649 float t1, t2, t3, t4; // filler data
1650 float posX, posY, posZ, posW; // Position data
1651 float r, g, b, a; // Color
1652 };
1653 const struct VDATA vData[] =
1654 {
1655 { XYZ1(0, 0, 0), XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
1656 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1657 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1658 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1659 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1660 { XYZ1(0, 0, 0), XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
1661 };
1662
Tony Barbour01999182015-04-09 12:58:51 -06001663 VkConstantBufferObj meshBuffer(m_device,sizeof(vData)/sizeof(vData[0]),sizeof(vData[0]), vData);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001664 meshBuffer.BufferMemoryBarrier();
1665
Tony Barbour01999182015-04-09 12:58:51 -06001666 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1667 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001668
Tony Barbour01999182015-04-09 12:58:51 -06001669 VkPipelineObj pipelineobj(m_device);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001670 pipelineobj.AddShader(&vs);
1671 pipelineobj.AddShader(&ps);
1672
Tony Barbour01999182015-04-09 12:58:51 -06001673 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001674 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001675
1676#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001677 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001678 MESH_BUF_ID, // Binding ID
1679 sizeof(vData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001680 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001681 };
1682
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001683 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001684 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1685 vi_attribs[0].location = 4;
Tony Barbour8205d902015-04-16 15:59:00 -06001686 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001687 vi_attribs[0].offsetInBytes = sizeof(float) * 4 * 2; // Offset of first element in bytes from base of vertex
1688 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1689 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001690 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001691 vi_attribs[1].offsetInBytes = sizeof(float) * 4 * 1; // Offset of first element in bytes from base of vertex
1692
1693 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
1694 pipelineobj.AddVertexInputBindings(&vi_binding, 1);
1695 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
1696
1697 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001698 VkCommandBufferObj cmdBuffer(m_device);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001699 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1700
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001701 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001702
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001703 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001704
1705 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BUF_ID);
1706#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001707 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001708 pDSDumpDot((char*)"triTest2.dot");
1709#endif
1710
1711 // render two triangles
1712 cmdBuffer.Draw(0, 6, 0, 1);
1713
1714 // finalize recording of the command buffer
1715 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001716 cmdBuffer.QueueCommandBuffer();
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001717
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001718 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001719}
1720
Tony Barbour01999182015-04-09 12:58:51 -06001721TEST_F(VkRenderTest, TriVertFetchDeadAttr)
Tony Barbourf43b6982014-11-25 13:18:32 -07001722{
1723 // This tests that attributes work in the presence of gl_VertexID
1724 // and a dead attribute in position 0. Draws a triangle with yellow,
1725 // red and green corners, starting at top and going clockwise.
1726
1727 static const char *vertShaderText =
1728 "#version 140\n"
1729 "#extension GL_ARB_separate_shader_objects : enable\n"
1730 "#extension GL_ARB_shading_language_420pack : enable\n"
1731 //XYZ1( -1, -1, -1 )
1732 "layout (location = 0) in vec4 pos;\n"
1733 //XYZ1( 0.f, 0.f, 0.f )
1734 "layout (location = 1) in vec4 inColor;\n"
1735 "layout (location = 0) out vec4 outColor;\n"
1736 "void main() {\n"
1737 " outColor = inColor;\n"
1738 " vec2 vertices[3];"
1739 " vertices[0] = vec2(-1.0, -1.0);\n"
1740 " vertices[1] = vec2( 1.0, -1.0);\n"
1741 " vertices[2] = vec2( 0.0, 1.0);\n"
1742 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1743 "}\n";
1744
1745
1746 static const char *fragShaderText =
1747 "#version 140\n"
1748 "#extension GL_ARB_separate_shader_objects : enable\n"
1749 "#extension GL_ARB_shading_language_420pack : enable\n"
1750 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001751 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001752 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001753 " outColor = color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001754 "}\n";
1755
1756 ASSERT_NO_FATAL_FAILURE(InitState());
1757 ASSERT_NO_FATAL_FAILURE(InitViewport());
1758
Tony Barbour01999182015-04-09 12:58:51 -06001759 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001760 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001761
Tony Barbour01999182015-04-09 12:58:51 -06001762 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1763 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001764
Tony Barbour01999182015-04-09 12:58:51 -06001765 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001766 pipelineobj.AddShader(&vs);
1767 pipelineobj.AddShader(&ps);
1768
Tony Barbour01999182015-04-09 12:58:51 -06001769 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001770 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001771
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001772#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001773 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001774 MESH_BUF_ID, // Binding ID
1775 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001776 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001777 };
1778
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001779 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001780 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1781 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001782 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001783 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1784 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1785 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001786 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001787 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001788
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001789 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001790 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001791 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001792
Tony Barbourdd4c9642015-01-09 12:55:14 -07001793 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001794 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001795 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001796
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001797 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001798
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001799 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001800
1801 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1802#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001803 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001804 pDSDumpDot((char*)"triTest2.dot");
1805#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001806
1807 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001808 cmdBuffer.Draw(0, 6, 0, 1);
1809
1810 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001811 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001812 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001813
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001814 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001815}
1816
Tony Barbour01999182015-04-09 12:58:51 -06001817TEST_F(VkRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001818{
1819 static const char *vertShaderText =
1820 "#version 140\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001821 "#extension GL_ARB_separate_shader_objects : enable\n"
1822 "#extension GL_ARB_shading_language_420pack : enable\n"
GregFd6ebdb32015-06-03 18:40:50 -06001823 "layout (std140, binding = 0) uniform bufferVals {\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001824 " mat4 mvp;\n"
1825 "} myBufferVals;\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001826 "layout (location = 0) in vec4 pos;\n"
1827 "layout (location = 1) in vec4 inColor;\n"
Cody Northrop74a2d2c2015-06-16 17:32:04 -06001828 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001829 "void main() {\n"
1830 " outColor = inColor;\n"
1831 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001832 " gl_Position.y = -gl_Position.y;\n"
1833 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001834 "}\n";
1835
1836 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001837 "#version 140\n"
1838 "#extension GL_ARB_separate_shader_objects : enable\n"
1839 "#extension GL_ARB_shading_language_420pack : enable\n"
1840 "layout (location = 0) in vec4 color;\n"
1841 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001842 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001843 " outColor = color;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001844 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001845 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001846
Tony Barbourf43b6982014-11-25 13:18:32 -07001847 glm::mat4 View = glm::lookAt(
1848 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1849 glm::vec3(0,0,0), // and looks at the origin
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001850 glm::vec3(0,-1,0) // Head is up (set to 0,-1,0 to look upside-down)
Tony Barbourf43b6982014-11-25 13:18:32 -07001851 );
1852
1853 glm::mat4 Model = glm::mat4(1.0f);
1854
1855 glm::mat4 MVP = Projection * View * Model;
1856
1857 ASSERT_NO_FATAL_FAILURE(InitState());
1858 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour8bef8ee2015-05-22 09:44:58 -06001859 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07001860
Tony Barbour01999182015-04-09 12:58:51 -06001861 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 -07001862 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1863
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001864 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07001865
Tony Barbour01999182015-04-09 12:58:51 -06001866 VkConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1867 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1868 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001869
Tony Barbour01999182015-04-09 12:58:51 -06001870 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001871 pipelineobj.AddShader(&vs);
1872 pipelineobj.AddShader(&ps);
1873
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001874 VkPipelineDsStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001875 ds_state.depthTestEnable = VK_TRUE;
1876 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06001877 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001878 ds_state.depthBoundsEnable = VK_FALSE;
1879 ds_state.stencilTestEnable = VK_FALSE;
1880 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
1881 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
1882 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06001883 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
1884 ds_state.format = VK_FORMAT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001885 ds_state.front = ds_state.back;
1886 pipelineobj.SetDepthStencil(&ds_state);
1887
Tony Barbour01999182015-04-09 12:58:51 -06001888 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001889 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001890
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001891#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001892 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001893 MESH_BUF_ID, // Binding ID
1894 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001895 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001896 };
Tony Barbourf43b6982014-11-25 13:18:32 -07001897
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001898 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001899 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1900 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001901 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001902 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1903 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1904 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001905 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001906 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001907
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001908 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001909 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001910 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001911
Tony Barbour17c6ab12015-03-27 17:03:18 -06001912 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour17c6ab12015-03-27 17:03:18 -06001913
Tony Barbour01999182015-04-09 12:58:51 -06001914 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -07001915 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001916
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001917 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001918 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001919
Tony Barboure4ed9942015-01-09 10:06:53 -07001920 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1921#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001922 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barboure4ed9942015-01-09 10:06:53 -07001923 pDSDumpDot((char*)"triTest2.dot");
1924#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001925
1926 // render triangles
Tony Barboure4ed9942015-01-09 10:06:53 -07001927 cmdBuffer.Draw(0, 36, 0, 1);
1928
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001929
Tony Barboure4ed9942015-01-09 10:06:53 -07001930 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001931 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001932 cmdBuffer.QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -07001933
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001934 RecordImages(m_renderTargets);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001935}
1936
Tony Barbour01999182015-04-09 12:58:51 -06001937TEST_F(VkRenderTest, VSTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07001938{
1939 // The expected result from this test is a green and red triangle;
1940 // one red vertex on the left, two green vertices on the right.
1941 static const char *vertShaderText =
Cody Northrop74a2d2c2015-06-16 17:32:04 -06001942 "#version 140\n"
1943 "#extension GL_ARB_separate_shader_objects : enable\n"
1944 "#extension GL_ARB_shading_language_420pack : enable\n"
1945 "layout (location = 0) out vec4 texColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001946 "uniform sampler2D surface;\n"
1947 "void main() {\n"
1948 " vec2 vertices[3];"
1949 " vertices[0] = vec2(-0.5, -0.5);\n"
1950 " vertices[1] = vec2( 0.5, -0.5);\n"
1951 " vertices[2] = vec2( 0.5, 0.5);\n"
1952 " vec2 positions[3];"
1953 " positions[0] = vec2( 0.0, 0.0);\n"
1954 " positions[1] = vec2( 0.25, 0.1);\n"
1955 " positions[2] = vec2( 0.1, 0.25);\n"
1956 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1957 " texColor = textureLod(surface, samplePos, 0.0);\n"
1958 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1959 "}\n";
1960
1961 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001962 "#version 140\n"
1963 "#extension GL_ARB_separate_shader_objects : enable\n"
1964 "#extension GL_ARB_shading_language_420pack : enable\n"
1965 "layout (location = 0) in vec4 texColor;\n"
1966 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001967 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001968 " outColor = texColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001969 "}\n";
1970
1971 ASSERT_NO_FATAL_FAILURE(InitState());
1972 ASSERT_NO_FATAL_FAILURE(InitViewport());
1973
Tony Barbour01999182015-04-09 12:58:51 -06001974 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1975 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
1976 VkSamplerObj sampler(m_device);
1977 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001978
Tony Barbour01999182015-04-09 12:58:51 -06001979 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001980 pipelineobj.AddShader(&vs);
1981 pipelineobj.AddShader(&ps);
1982
Tony Barbour01999182015-04-09 12:58:51 -06001983 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001984 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001985
Tony Barbourdd4c9642015-01-09 12:55:14 -07001986 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001987 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001988 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001989
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001990 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001991
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001992 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001993
1994#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001995 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001996 pDSDumpDot((char*)"triTest2.dot");
1997#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001998
Tony Barbourdd4c9642015-01-09 12:55:14 -07001999 // render triangle
2000 cmdBuffer.Draw(0, 3, 0, 1);
2001
2002 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002003 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002004 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002005
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002006 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002007}
GregFd6ebdb32015-06-03 18:40:50 -06002008
2009
2010
Tony Barbour01999182015-04-09 12:58:51 -06002011TEST_F(VkRenderTest, TexturedTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002012{
2013 // The expected result from this test is a red and green checkered triangle
2014 static const char *vertShaderText =
2015 "#version 140\n"
2016 "#extension GL_ARB_separate_shader_objects : enable\n"
2017 "#extension GL_ARB_shading_language_420pack : enable\n"
2018 "layout (location = 0) out vec2 samplePos;\n"
2019 "void main() {\n"
2020 " vec2 vertices[3];"
2021 " vertices[0] = vec2(-0.5, -0.5);\n"
2022 " vertices[1] = vec2( 0.5, -0.5);\n"
2023 " vertices[2] = vec2( 0.5, 0.5);\n"
2024 " vec2 positions[3];"
2025 " positions[0] = vec2( 0.0, 0.0);\n"
2026 " positions[1] = vec2( 1.0, 0.0);\n"
2027 " positions[2] = vec2( 1.0, 1.0);\n"
2028 " samplePos = positions[gl_VertexID % 3];\n"
2029 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2030 "}\n";
2031
2032 static const char *fragShaderText =
2033 "#version 140\n"
2034 "#extension GL_ARB_separate_shader_objects : enable\n"
2035 "#extension GL_ARB_shading_language_420pack : enable\n"
2036 "layout (location = 0) in vec2 samplePos;\n"
2037 "layout (binding = 0) uniform sampler2D surface;\n"
2038 "layout (location=0) out vec4 outColor;\n"
2039 "void main() {\n"
2040 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2041 " outColor = texColor;\n"
2042 "}\n";
2043
2044 ASSERT_NO_FATAL_FAILURE(InitState());
2045 ASSERT_NO_FATAL_FAILURE(InitViewport());
2046
Tony Barbour01999182015-04-09 12:58:51 -06002047 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2048 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2049 VkSamplerObj sampler(m_device);
2050 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002051
Tony Barbour01999182015-04-09 12:58:51 -06002052 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002053 pipelineobj.AddShader(&vs);
2054 pipelineobj.AddShader(&ps);
2055
Tony Barbour01999182015-04-09 12:58:51 -06002056 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002057 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002058
Tony Barbourdd4c9642015-01-09 12:55:14 -07002059 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002060 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002061 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2062
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002063 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002064
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002065 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002066
2067#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002068 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002069 pDSDumpDot((char*)"triTest2.dot");
2070#endif
2071 // render triangle
2072 cmdBuffer.Draw(0, 3, 0, 1);
2073
2074 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002075 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002076 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002077
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002078 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002079}
Tony Barbour01999182015-04-09 12:58:51 -06002080TEST_F(VkRenderTest, TexturedTriangleClip)
Tony Barbourf43b6982014-11-25 13:18:32 -07002081{
2082 // The expected result from this test is a red and green checkered triangle
2083 static const char *vertShaderText =
2084 "#version 330\n"
2085 "#extension GL_ARB_separate_shader_objects : enable\n"
2086 "#extension GL_ARB_shading_language_420pack : enable\n"
2087 "layout (location = 0) out vec2 samplePos;\n"
2088 "out gl_PerVertex {\n"
2089 " vec4 gl_Position;\n"
2090 " float gl_ClipDistance[1];\n"
2091 "};\n"
2092 "void main() {\n"
2093 " vec2 vertices[3];"
2094 " vertices[0] = vec2(-0.5, -0.5);\n"
2095 " vertices[1] = vec2( 0.5, -0.5);\n"
2096 " vertices[2] = vec2( 0.5, 0.5);\n"
2097 " vec2 positions[3];"
2098 " positions[0] = vec2( 0.0, 0.0);\n"
2099 " positions[1] = vec2( 1.0, 0.0);\n"
2100 " positions[2] = vec2( 1.0, 1.0);\n"
2101 " float dists[3];\n"
2102 " dists[0] = 1.0;\n"
2103 " dists[1] = 1.0;\n"
2104 " dists[2] = -1.0;\n"
2105 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2106 " samplePos = positions[gl_VertexID % 3];\n"
2107 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2108 "}\n";
2109
2110 static const char *fragShaderText =
2111 "#version 140\n"
2112 "#extension GL_ARB_separate_shader_objects : enable\n"
2113 "#extension GL_ARB_shading_language_420pack : enable\n"
2114 "layout (location = 0) in vec2 samplePos;\n"
2115 "layout (binding = 0) uniform sampler2D surface;\n"
2116 "layout (location=0) out vec4 outColor;\n"
2117 "void main() {\n"
2118 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2119 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2120 " outColor = texColor;\n"
2121 "}\n";
2122
2123
2124 ASSERT_NO_FATAL_FAILURE(InitState());
2125 ASSERT_NO_FATAL_FAILURE(InitViewport());
2126
Tony Barbour01999182015-04-09 12:58:51 -06002127 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2128 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2129 VkSamplerObj sampler(m_device);
2130 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002131
Tony Barbour01999182015-04-09 12:58:51 -06002132 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002133 pipelineobj.AddShader(&vs);
2134 pipelineobj.AddShader(&ps);
2135
Tony Barbour01999182015-04-09 12:58:51 -06002136 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002137 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002138
Tony Barbourdd4c9642015-01-09 12:55:14 -07002139 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002140 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002141 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2142
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002143 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002144
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002145 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002146
2147#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002148 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002149 pDSDumpDot((char*)"triTest2.dot");
2150#endif
2151 // render triangle
2152 cmdBuffer.Draw(0, 3, 0, 1);
2153
2154 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002155 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002156 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002157
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002158 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002159}
GregFd6ebdb32015-06-03 18:40:50 -06002160
Tony Barbour01999182015-04-09 12:58:51 -06002161TEST_F(VkRenderTest, FSTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002162{
2163 // The expected result from this test is a red and green checkered triangle
2164 static const char *vertShaderText =
2165 "#version 140\n"
2166 "#extension GL_ARB_separate_shader_objects : enable\n"
2167 "#extension GL_ARB_shading_language_420pack : enable\n"
2168 "layout (location = 0) out vec2 samplePos;\n"
2169 "void main() {\n"
2170 " vec2 vertices[3];"
2171 " vertices[0] = vec2(-0.5, -0.5);\n"
2172 " vertices[1] = vec2( 0.5, -0.5);\n"
2173 " vertices[2] = vec2( 0.5, 0.5);\n"
2174 " vec2 positions[3];"
2175 " positions[0] = vec2( 0.0, 0.0);\n"
2176 " positions[1] = vec2( 1.0, 0.0);\n"
2177 " positions[2] = vec2( 1.0, 1.0);\n"
2178 " samplePos = positions[gl_VertexID % 3];\n"
2179 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2180 "}\n";
2181
2182 static const char *fragShaderText =
2183 "#version 140\n"
2184 "#extension GL_ARB_separate_shader_objects : enable\n"
2185 "#extension GL_ARB_shading_language_420pack : enable\n"
2186 "layout (location = 0) in vec2 samplePos;\n"
2187 "layout (binding = 0) uniform sampler2D surface;\n"
2188 "layout (location=0) out vec4 outColor;\n"
2189 "void main() {\n"
2190 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2191 " outColor = texColor;\n"
2192 "}\n";
2193
2194 ASSERT_NO_FATAL_FAILURE(InitState());
2195 ASSERT_NO_FATAL_FAILURE(InitViewport());
2196
Tony Barbour01999182015-04-09 12:58:51 -06002197 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2198 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2199 VkSamplerObj sampler(m_device);
2200 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002201
Tony Barbour01999182015-04-09 12:58:51 -06002202 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002203 pipelineobj.AddShader(&vs);
2204 pipelineobj.AddShader(&ps);
2205
Tony Barbour01999182015-04-09 12:58:51 -06002206 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002207 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002208
Tony Barbourdd4c9642015-01-09 12:55:14 -07002209 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002210 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002211 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2212
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002213 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002214
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002215 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002216
2217#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002218 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002219 pDSDumpDot((char*)"triTest2.dot");
2220#endif
2221 // render triangle
2222 cmdBuffer.Draw(0, 3, 0, 1);
2223
2224 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002225 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002226 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002227
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002228 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002229}
Tony Barbour01999182015-04-09 12:58:51 -06002230TEST_F(VkRenderTest, SamplerBindingsTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002231{
2232 // This test sets bindings on the samplers
2233 // For now we are asserting that sampler and texture pairs
2234 // march in lock step, and are set via GLSL binding. This can
2235 // and will probably change.
2236 // The sampler bindings should match the sampler and texture slot
2237 // number set up by the application.
2238 // This test will result in a blue triangle
2239 static const char *vertShaderText =
2240 "#version 140\n"
2241 "#extension GL_ARB_separate_shader_objects : enable\n"
2242 "#extension GL_ARB_shading_language_420pack : enable\n"
2243 "layout (location = 0) out vec4 samplePos;\n"
2244 "void main() {\n"
2245 " vec2 vertices[3];"
2246 " vertices[0] = vec2(-0.5, -0.5);\n"
2247 " vertices[1] = vec2( 0.5, -0.5);\n"
2248 " vertices[2] = vec2( 0.5, 0.5);\n"
2249 " vec2 positions[3];"
2250 " positions[0] = vec2( 0.0, 0.0);\n"
2251 " positions[1] = vec2( 1.0, 0.0);\n"
2252 " positions[2] = vec2( 1.0, 1.0);\n"
2253 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2254 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2255 "}\n";
2256
2257 static const char *fragShaderText =
2258 "#version 140\n"
2259 "#extension GL_ARB_separate_shader_objects : enable\n"
2260 "#extension GL_ARB_shading_language_420pack : enable\n"
2261 "layout (location = 0) in vec4 samplePos;\n"
2262 "layout (binding = 0) uniform sampler2D surface0;\n"
2263 "layout (binding = 1) uniform sampler2D surface1;\n"
2264 "layout (binding = 12) uniform sampler2D surface2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06002265 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002266 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002267 " outColor = textureLod(surface2, samplePos.xy, 0.0);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002268 "}\n";
2269
2270 ASSERT_NO_FATAL_FAILURE(InitState());
2271 ASSERT_NO_FATAL_FAILURE(InitViewport());
2272
Tony Barbour01999182015-04-09 12:58:51 -06002273 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2274 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002275
Tony Barbour01999182015-04-09 12:58:51 -06002276 VkSamplerObj sampler1(m_device);
2277 VkSamplerObj sampler2(m_device);
2278 VkSamplerObj sampler3(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002279
Tony Barbour2f421a02015-04-01 16:38:10 -06002280 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
Tony Barbour01999182015-04-09 12:58:51 -06002281 VkTextureObj texture1(m_device, tex_colors); // Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002282 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
Tony Barbour01999182015-04-09 12:58:51 -06002283 VkTextureObj texture2(m_device, tex_colors); // Green
Tony Barbour2f421a02015-04-01 16:38:10 -06002284 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
Tony Barbour01999182015-04-09 12:58:51 -06002285 VkTextureObj texture3(m_device, tex_colors); // Blue
Tony Barbourf43b6982014-11-25 13:18:32 -07002286
Tony Barbour01999182015-04-09 12:58:51 -06002287 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002288 pipelineobj.AddShader(&vs);
2289 pipelineobj.AddShader(&ps);
2290
Tony Barbour01999182015-04-09 12:58:51 -06002291 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002292 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2293 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2294 for (int i = 0; i < 10; i++)
2295 descriptorSet.AppendDummy();
2296 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002297
Tony Barbourdd4c9642015-01-09 12:55:14 -07002298 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002299 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002300 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2301
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002302 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002303
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002304 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002305
2306#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002307 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002308 pDSDumpDot((char*)"triTest2.dot");
2309#endif
2310 // render triangle
2311 cmdBuffer.Draw(0, 3, 0, 1);
2312
2313 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002314 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002315 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002316
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002317 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002318}
2319
Tony Barbour01999182015-04-09 12:58:51 -06002320TEST_F(VkRenderTest, TriangleVSUniformBlock)
Tony Barbourf43b6982014-11-25 13:18:32 -07002321{
2322 // The expected result from this test is a blue triangle
2323
2324 static const char *vertShaderText =
2325 "#version 140\n"
2326 "#extension GL_ARB_separate_shader_objects : enable\n"
2327 "#extension GL_ARB_shading_language_420pack : enable\n"
2328 "layout (location = 0) out vec4 outColor;\n"
2329 "layout (std140, binding = 0) uniform bufferVals {\n"
2330 " vec4 red;\n"
2331 " vec4 green;\n"
2332 " vec4 blue;\n"
2333 " vec4 white;\n"
2334 "} myBufferVals;\n"
2335 "void main() {\n"
2336 " vec2 vertices[3];"
2337 " vertices[0] = vec2(-0.5, -0.5);\n"
2338 " vertices[1] = vec2( 0.5, -0.5);\n"
2339 " vertices[2] = vec2( 0.5, 0.5);\n"
2340 " outColor = myBufferVals.blue;\n"
2341 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2342 "}\n";
2343
2344 static const char *fragShaderText =
2345 "#version 140\n"
2346 "#extension GL_ARB_separate_shader_objects : enable\n"
2347 "#extension GL_ARB_shading_language_420pack : enable\n"
2348 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -06002349 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002350 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002351 " outColor = inColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002352 "}\n";
2353
2354 ASSERT_NO_FATAL_FAILURE(InitState());
2355 ASSERT_NO_FATAL_FAILURE(InitViewport());
2356
Tony Barbour01999182015-04-09 12:58:51 -06002357 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2358 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002359
2360 // Let's populate our buffer with the following:
2361 // vec4 red;
2362 // vec4 green;
2363 // vec4 blue;
2364 // vec4 white;
2365 const int valCount = 4 * 4;
2366 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2367 0.0, 1.0, 0.0, 1.0,
2368 0.0, 0.0, 1.0, 1.0,
2369 1.0, 1.0, 1.0, 1.0 };
2370
Tony Barbour01999182015-04-09 12:58:51 -06002371 VkConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002372
Tony Barbour01999182015-04-09 12:58:51 -06002373 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002374 pipelineobj.AddShader(&vs);
2375 pipelineobj.AddShader(&ps);
2376
Tony Barbour01999182015-04-09 12:58:51 -06002377 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002378 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002379
Tony Barbourdd4c9642015-01-09 12:55:14 -07002380 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002381 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002382 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2383
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002384 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002385
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002386 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002387
2388#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002389 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002390 pDSDumpDot((char*)"triTest2.dot");
2391#endif
2392 // render triangle
2393 cmdBuffer.Draw(0, 3, 0, 1);
2394
2395 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002396 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002397 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002398
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002399 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002400}
2401
Tony Barbour01999182015-04-09 12:58:51 -06002402TEST_F(VkRenderTest, TriangleFSUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002403{
2404 // This test allows the shader to select which buffer it is
2405 // pulling from using layout binding qualifier.
2406 // There are corresponding changes in the compiler stack that
2407 // will select the buffer using binding directly.
2408 // The binding number should match the slot number set up by
2409 // the application.
2410 // The expected result from this test is a purple triangle
2411
2412 static const char *vertShaderText =
2413 "#version 140\n"
2414 "#extension GL_ARB_separate_shader_objects : enable\n"
2415 "#extension GL_ARB_shading_language_420pack : enable\n"
2416 "void main() {\n"
2417 " vec2 vertices[3];"
2418 " vertices[0] = vec2(-0.5, -0.5);\n"
2419 " vertices[1] = vec2( 0.5, -0.5);\n"
2420 " vertices[2] = vec2( 0.5, 0.5);\n"
2421 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2422 "}\n";
2423
2424 static const char *fragShaderText =
2425 "#version 140\n"
2426 "#extension GL_ARB_separate_shader_objects : enable\n"
2427 "#extension GL_ARB_shading_language_420pack : enable\n"
2428 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2429 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2430 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002431 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
GregFd6ebdb32015-06-03 18:40:50 -06002432 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002433 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002434 " outColor = myBlueVal.color;\n"
2435 " outColor += myRedVal.color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002436 "}\n";
2437
2438 ASSERT_NO_FATAL_FAILURE(InitState());
2439 ASSERT_NO_FATAL_FAILURE(InitViewport());
2440
Tony Barbour01999182015-04-09 12:58:51 -06002441 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2442 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002443
2444 // We're going to create a number of uniform buffers, and then allow
2445 // the shader to select which it wants to read from with a binding
2446
2447 // Let's populate the buffers with a single color each:
2448 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2449 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2450 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002451 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002452
2453 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2454 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2455 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2456 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2457
2458 const int redCount = sizeof(redVals) / sizeof(float);
2459 const int greenCount = sizeof(greenVals) / sizeof(float);
2460 const int blueCount = sizeof(blueVals) / sizeof(float);
2461 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2462
Tony Barbour01999182015-04-09 12:58:51 -06002463 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002464
Tony Barbour01999182015-04-09 12:58:51 -06002465 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002466
Tony Barbour01999182015-04-09 12:58:51 -06002467 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002468
Tony Barbour01999182015-04-09 12:58:51 -06002469 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002470
Tony Barbour01999182015-04-09 12:58:51 -06002471 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002472 pipelineobj.AddShader(&vs);
2473 pipelineobj.AddShader(&ps);
2474
Tony Barbour01999182015-04-09 12:58:51 -06002475 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002476 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2477 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2478 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2479 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002480
Tony Barbourdd4c9642015-01-09 12:55:14 -07002481 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002482 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002483 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002484
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002485 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002486
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002487 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002488
2489#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002490 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002491 pDSDumpDot((char*)"triTest2.dot");
2492#endif
2493 // render triangle
2494 cmdBuffer.Draw(0, 3, 0, 1);
2495
2496 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002497 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002498 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002499
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002500 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002501}
2502
Tony Barbour01999182015-04-09 12:58:51 -06002503TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002504{
2505 // This test is the same as TriangleFSUniformBlockBinding, but
2506 // it does not provide an instance name.
2507 // The expected result from this test is a purple triangle
2508
2509 static const char *vertShaderText =
2510 "#version 140\n"
2511 "#extension GL_ARB_separate_shader_objects : enable\n"
2512 "#extension GL_ARB_shading_language_420pack : enable\n"
2513 "void main() {\n"
2514 " vec2 vertices[3];"
2515 " vertices[0] = vec2(-0.5, -0.5);\n"
2516 " vertices[1] = vec2( 0.5, -0.5);\n"
2517 " vertices[2] = vec2( 0.5, 0.5);\n"
2518 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2519 "}\n";
2520
2521 static const char *fragShaderText =
2522 "#version 430\n"
2523 "#extension GL_ARB_separate_shader_objects : enable\n"
2524 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002525 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2526 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2527 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002528 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002529 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002530 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002531 " outColor = blue;\n"
2532 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002533 "}\n";
2534 ASSERT_NO_FATAL_FAILURE(InitState());
2535 ASSERT_NO_FATAL_FAILURE(InitViewport());
2536
Tony Barbour01999182015-04-09 12:58:51 -06002537 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2538 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002539
2540 // We're going to create a number of uniform buffers, and then allow
2541 // the shader to select which it wants to read from with a binding
2542
2543 // Let's populate the buffers with a single color each:
2544 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2545 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2546 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2547 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2548
2549 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2550 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2551 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2552 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2553
2554 const int redCount = sizeof(redVals) / sizeof(float);
2555 const int greenCount = sizeof(greenVals) / sizeof(float);
2556 const int blueCount = sizeof(blueVals) / sizeof(float);
2557 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2558
Tony Barbour01999182015-04-09 12:58:51 -06002559 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002560
Tony Barbour01999182015-04-09 12:58:51 -06002561 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002562
Tony Barbour01999182015-04-09 12:58:51 -06002563 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002564
Tony Barbour01999182015-04-09 12:58:51 -06002565 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002566
Tony Barbour01999182015-04-09 12:58:51 -06002567 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002568 pipelineobj.AddShader(&vs);
2569 pipelineobj.AddShader(&ps);
2570
Tony Barbour01999182015-04-09 12:58:51 -06002571 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002572 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2573 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2574 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2575 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002576
Tony Barbourdd4c9642015-01-09 12:55:14 -07002577 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002578 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002579 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2580
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002581 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002582
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002583 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002584
2585#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002586 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002587 pDSDumpDot((char*)"triTest2.dot");
2588#endif
2589 // render triangle
2590 cmdBuffer.Draw(0, 3, 0, 1);
2591
2592 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002593 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002594 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002595
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002596 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002597}
2598
GregF54a32172015-07-01 16:11:09 -06002599TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBindingWithStruct)
2600{
2601 // This test is the same as TriangleFSUniformBlockBinding, but
2602 // it does not provide an instance name.
2603 // The expected result from this test is a purple triangle
2604
2605 static const char *vertShaderText =
2606 "#version 140\n"
2607 "#extension GL_ARB_separate_shader_objects : enable\n"
2608 "#extension GL_ARB_shading_language_420pack : enable\n"
2609 "void main() {\n"
2610 " vec2 vertices[3];"
2611 " vertices[0] = vec2(-0.5, -0.5);\n"
2612 " vertices[1] = vec2( 0.5, -0.5);\n"
2613 " vertices[2] = vec2( 0.5, 0.5);\n"
2614 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2615 "}\n";
2616
2617 static const char *fragShaderText =
2618 "#version 430\n"
2619 "#extension GL_ARB_separate_shader_objects : enable\n"
2620 "#extension GL_ARB_shading_language_420pack : enable\n"
2621 "\n"
2622 " struct PS_INPUT {\n"
2623 " vec2 member0;\n"
2624 " vec4 member1;\n"
2625 " vec4 member2;\n"
2626 " vec4 member3;\n"
2627 " vec4 member4;\n"
2628 " vec4 member5;\n"
2629 " vec4 member6;\n"
2630 " vec4 member7;\n"
2631 " vec4 member8;\n"
2632 " vec4 member9;\n"
2633 " };\n"
2634 "\n"
2635 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2636 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2637 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2638 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
2639 "layout (location = 0) out vec4 outColor;\n"
2640 "PS_INPUT MainFs()\n"
2641 "{\n"
2642 " PS_INPUT o;\n"
2643 " o.member9 = red;\n"
2644 " return o;\n"
2645 "}\n"
2646 "\n"
2647 "void main()\n"
2648 "{\n"
2649 " PS_INPUT o;\n"
2650 " o = MainFs();\n"
2651 " outColor = blue;"
2652 " outColor += o.member9;\n"
2653 "}\n";;
2654 ASSERT_NO_FATAL_FAILURE(InitState());
2655 ASSERT_NO_FATAL_FAILURE(InitViewport());
2656
2657 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2658 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2659
2660 // We're going to create a number of uniform buffers, and then allow
2661 // the shader to select which it wants to read from with a binding
2662
2663 // Let's populate the buffers with a single color each:
2664 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2665 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2666 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2667 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2668
2669 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2670 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2671 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2672 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2673
2674 const int redCount = sizeof(redVals) / sizeof(float);
2675 const int greenCount = sizeof(greenVals) / sizeof(float);
2676 const int blueCount = sizeof(blueVals) / sizeof(float);
2677 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2678
2679 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2680
2681 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2682
2683 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2684
2685 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
2686
2687 VkPipelineObj pipelineobj(m_device);
2688 pipelineobj.AddShader(&vs);
2689 pipelineobj.AddShader(&ps);
2690
2691 VkDescriptorSetObj descriptorSet(m_device);
2692 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2693 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2694 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2695 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
2696
2697 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2698 VkCommandBufferObj cmdBuffer(m_device);
2699 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2700
2701 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
2702
2703 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
2704
2705#ifdef DUMP_STATE_DOT
2706 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
2707 pDSDumpDot((char*)"triTest2.dot");
2708#endif
2709 // render triangle
2710 cmdBuffer.Draw(0, 3, 0, 1);
2711
2712 // finalize recording of the command buffer
2713 EndCommandBuffer(cmdBuffer);
2714 cmdBuffer.QueueCommandBuffer();
2715
2716 RecordImages(m_renderTargets);
2717}
2718
Tony Barbour01999182015-04-09 12:58:51 -06002719TEST_F(VkRenderTest, CubeWithVertexFetchAndMVPAndTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07002720{
2721 static const char *vertShaderText =
2722 "#version 140\n"
2723 "#extension GL_ARB_separate_shader_objects : enable\n"
2724 "#extension GL_ARB_shading_language_420pack : enable\n"
2725 "layout (std140, binding=0) uniform bufferVals {\n"
2726 " mat4 mvp;\n"
2727 "} myBufferVals;\n"
2728 "layout (location=0) in vec4 pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002729 "layout (location=1) in vec2 input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002730 "layout (location=0) out vec2 UV;\n"
2731 "void main() {\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002732 " UV = input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002733 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002734 " gl_Position.y = -gl_Position.y;\n"
2735 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002736 "}\n";
2737
2738 static const char *fragShaderText =
2739 "#version 140\n"
2740 "#extension GL_ARB_separate_shader_objects : enable\n"
2741 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002742 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002743 "layout (location=0) out vec4 outColor;\n"
2744 "layout (location=0) in vec2 UV;\n"
2745 "void main() {\n"
2746 " outColor= textureLod(surface, UV, 0.0);\n"
2747 "}\n";
2748 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2749
2750 glm::mat4 View = glm::lookAt(
2751 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2752 glm::vec3(0,0,0), // and looks at the origin
2753 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2754 );
2755
2756 glm::mat4 Model = glm::mat4(1.0f);
2757
2758 glm::mat4 MVP = Projection * View * Model;
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002759 int num_verts = sizeof(g_vb_texture_Data) / sizeof(g_vb_texture_Data[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002760
2761
2762 ASSERT_NO_FATAL_FAILURE(InitState());
2763 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour8bef8ee2015-05-22 09:44:58 -06002764 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07002765
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002766 VkConstantBufferObj meshBuffer(m_device, num_verts,
2767 sizeof(g_vb_texture_Data[0]), g_vb_texture_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002768 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002769
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002770 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07002771
Tony Barbour01999182015-04-09 12:58:51 -06002772 VkConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2773 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2774 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2775 VkSamplerObj sampler(m_device);
2776 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002777
Tony Barbour01999182015-04-09 12:58:51 -06002778 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002779 pipelineobj.AddShader(&vs);
2780 pipelineobj.AddShader(&ps);
2781
Tony Barbour01999182015-04-09 12:58:51 -06002782 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002783 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mvpBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002784 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002785
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002786#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002787 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002788 MESH_BIND_ID, // binding ID
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002789 sizeof(g_vb_texture_Data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002790 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002791 };
Tony Barbourf43b6982014-11-25 13:18:32 -07002792
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002793 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002794 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2795 vi_attribs[0].location = 0; // location
Tony Barbour8205d902015-04-16 15:59:00 -06002796 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002797 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2798 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2799 vi_attribs[1].location = 1; // location
2800 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
2801 vi_attribs[1].offsetInBytes = 16; // Offset of uv components
Tony Barbourf43b6982014-11-25 13:18:32 -07002802
Tony Barbourf43b6982014-11-25 13:18:32 -07002803 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002804 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2805 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07002806
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002807 VkPipelineDsStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002808 ds_state.depthTestEnable = VK_TRUE;
2809 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06002810 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002811 ds_state.depthBoundsEnable = VK_FALSE;
2812 ds_state.stencilTestEnable = VK_FALSE;
2813 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
2814 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
2815 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06002816 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
2817 ds_state.format = VK_FORMAT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002818 ds_state.front = ds_state.back;
2819 pipelineobj.SetDepthStencil(&ds_state);
2820
Tony Barbour17c6ab12015-03-27 17:03:18 -06002821 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour01999182015-04-09 12:58:51 -06002822 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002823 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002824
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002825 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002826
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002827 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002828
2829 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2830#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002831 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002832 pDSDumpDot((char*)"triTest2.dot");
2833#endif
2834 // render triangle
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002835 cmdBuffer.Draw(0, num_verts, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002836
2837 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002838 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002839 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002840
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002841 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002842 RotateTriangleVSUniform(Projection, View, Model, &mvpBuffer, &cmdBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002843}
Cody Northropd1ce7842014-12-09 11:17:01 -07002844
Tony Barbour01999182015-04-09 12:58:51 -06002845TEST_F(VkRenderTest, TriangleMixedSamplerUniformBlockBinding)
Cody Northropd1ce7842014-12-09 11:17:01 -07002846{
2847 // This test mixes binding slots of textures and buffers, ensuring
2848 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002849 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002850 // you can modify it to move the desired result around.
2851
2852 static const char *vertShaderText =
2853 "#version 140\n"
2854 "#extension GL_ARB_separate_shader_objects : enable\n"
2855 "#extension GL_ARB_shading_language_420pack : enable\n"
2856 "void main() {\n"
2857 " vec2 vertices[3];"
2858 " vertices[0] = vec2(-0.5, -0.5);\n"
2859 " vertices[1] = vec2( 0.5, -0.5);\n"
2860 " vertices[2] = vec2( 0.5, 0.5);\n"
2861 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2862 "}\n";
2863
2864 static const char *fragShaderText =
2865 "#version 430\n"
2866 "#extension GL_ARB_separate_shader_objects : enable\n"
2867 "#extension GL_ARB_shading_language_420pack : enable\n"
2868 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002869 "layout (binding = 3) uniform sampler2D surface1;\n"
2870 "layout (binding = 1) uniform sampler2D surface2;\n"
2871 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002872
Cody Northropa0410942014-12-09 13:59:39 -07002873
Chia-I Wuf8385062015-01-04 16:27:24 +08002874 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2875 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2876 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2877 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002878 "layout (location = 0) out vec4 outColor;\n"
2879 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002880 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002881 " outColor += white * vec4(0.00001);\n"
2882 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002883 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002884 "}\n";
2885 ASSERT_NO_FATAL_FAILURE(InitState());
2886 ASSERT_NO_FATAL_FAILURE(InitViewport());
2887
Tony Barbour01999182015-04-09 12:58:51 -06002888 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2889 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northropd1ce7842014-12-09 11:17:01 -07002890
Cody Northropd1ce7842014-12-09 11:17:01 -07002891 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2892 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2893 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2894 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2895
2896 const int redCount = sizeof(redVals) / sizeof(float);
2897 const int greenCount = sizeof(greenVals) / sizeof(float);
2898 const int blueCount = sizeof(blueVals) / sizeof(float);
2899 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2900
Tony Barbour01999182015-04-09 12:58:51 -06002901 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2902 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2903 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2904 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002905
Tony Barbour2f421a02015-04-01 16:38:10 -06002906 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002907 VkSamplerObj sampler0(m_device);
2908 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002909 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002910 VkSamplerObj sampler2(m_device);
2911 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002912 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002913 VkSamplerObj sampler4(m_device);
2914 VkTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropa0410942014-12-09 13:59:39 -07002915
2916 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2917 // TODO: Get back here ASAP and understand why.
Tony Barbour2f421a02015-04-01 16:38:10 -06002918 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06002919 VkSamplerObj sampler7(m_device);
2920 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropd1ce7842014-12-09 11:17:01 -07002921
Tony Barbour01999182015-04-09 12:58:51 -06002922 VkPipelineObj pipelineobj(m_device);
Cody Northropd1ce7842014-12-09 11:17:01 -07002923 pipelineobj.AddShader(&vs);
2924 pipelineobj.AddShader(&ps);
2925
Tony Barbour01999182015-04-09 12:58:51 -06002926 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002927 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2928 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2929 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2930 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002931 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002932 // swap blue and green
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002933 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2934 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2935 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -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 Northropd1ce7842014-12-09 11:17:01 -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 Northropd1ce7842014-12-09 11:17:01 -07002957}
2958
Tony Barbour01999182015-04-09 12:58:51 -06002959TEST_F(VkRenderTest, TriangleMatchingSamplerUniformBlockBinding)
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002960{
2961 // This test matches binding slots of textures and buffers, requiring
2962 // the driver to give them distinct number spaces.
2963 // The expected result from this test is a red triangle, although
2964 // you can modify it to move the desired result around.
2965
2966 static const char *vertShaderText =
2967 "#version 140\n"
2968 "#extension GL_ARB_separate_shader_objects : enable\n"
2969 "#extension GL_ARB_shading_language_420pack : enable\n"
2970 "void main() {\n"
2971 " vec2 vertices[3];"
2972 " vertices[0] = vec2(-0.5, -0.5);\n"
2973 " vertices[1] = vec2( 0.5, -0.5);\n"
2974 " vertices[2] = vec2( 0.5, 0.5);\n"
2975 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2976 "}\n";
2977
2978 static const char *fragShaderText =
2979 "#version 430\n"
2980 "#extension GL_ARB_separate_shader_objects : enable\n"
2981 "#extension GL_ARB_shading_language_420pack : enable\n"
2982 "layout (binding = 0) uniform sampler2D surface0;\n"
2983 "layout (binding = 1) uniform sampler2D surface1;\n"
2984 "layout (binding = 2) uniform sampler2D surface2;\n"
2985 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002986 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2987 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2988 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2989 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002990 "layout (location = 0) out vec4 outColor;\n"
2991 "void main() {\n"
2992 " outColor = red;// * vec4(0.00001);\n"
2993 " outColor += white * vec4(0.00001);\n"
2994 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2995 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2996 "}\n";
2997 ASSERT_NO_FATAL_FAILURE(InitState());
2998 ASSERT_NO_FATAL_FAILURE(InitViewport());
2999
Tony Barbour01999182015-04-09 12:58:51 -06003000 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3001 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003002
3003 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
3004 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
3005 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
3006 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
3007
3008 const int redCount = sizeof(redVals) / sizeof(float);
3009 const int greenCount = sizeof(greenVals) / sizeof(float);
3010 const int blueCount = sizeof(blueVals) / sizeof(float);
3011 const int whiteCount = sizeof(whiteVals) / sizeof(float);
3012
Tony Barbour01999182015-04-09 12:58:51 -06003013 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
3014 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
3015 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
3016 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003017
Tony Barbour2f421a02015-04-01 16:38:10 -06003018 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06003019 VkSamplerObj sampler0(m_device);
3020 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06003021 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06003022 VkSamplerObj sampler2(m_device);
3023 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06003024 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06003025 VkSamplerObj sampler4(m_device);
3026 VkTextureObj texture4(m_device, tex_colors); // Light Green
Tony Barbour2f421a02015-04-01 16:38:10 -06003027 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06003028 VkSamplerObj sampler7(m_device);
3029 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003030
Tony Barbour01999182015-04-09 12:58:51 -06003031 VkPipelineObj pipelineobj(m_device);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003032 pipelineobj.AddShader(&vs);
3033 pipelineobj.AddShader(&ps);
3034
Tony Barbour01999182015-04-09 12:58:51 -06003035 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08003036 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3037 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3038 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
3039 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003040 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
3041 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
3042 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
3043 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003044
Tony Barbourdd4c9642015-01-09 12:55:14 -07003045 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06003046 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07003047 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003048
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003049 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07003050
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003051 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07003052
3053#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003054 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07003055 pDSDumpDot((char*)"triTest2.dot");
3056#endif
3057 // render triangle
3058 cmdBuffer.Draw(0, 3, 0, 1);
3059
3060 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003061 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003062 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07003063
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003064 RecordImages(m_renderTargets);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003065}
3066
Tony Barbour01999182015-04-09 12:58:51 -06003067TEST_F(VkRenderTest, TriangleUniformBufferLayout)
Cody Northrop02690bd2014-12-17 15:26:33 -07003068{
3069 // This test populates a buffer with a variety of different data
3070 // types, then reads them out with a shader.
3071 // The expected result from this test is a green triangle
3072
3073 static const char *vertShaderText =
3074 "#version 140\n"
3075 "#extension GL_ARB_separate_shader_objects : enable\n"
3076 "#extension GL_ARB_shading_language_420pack : enable\n"
3077 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3078 " vec4 fRed;\n"
3079 " vec4 fGreen;\n"
3080 " layout(row_major) mat4 worldToProj;\n"
3081 " layout(row_major) mat4 projToWorld;\n"
3082 " layout(row_major) mat4 worldToView;\n"
3083 " layout(row_major) mat4 viewToProj;\n"
3084 " layout(row_major) mat4 worldToShadow[4];\n"
3085 " float fZero;\n"
3086 " float fOne;\n"
3087 " float fTwo;\n"
3088 " float fThree;\n"
3089 " vec3 fZeroZeroZero;\n"
3090 " float fFour;\n"
3091 " vec3 fZeroZeroOne;\n"
3092 " float fFive;\n"
3093 " vec3 fZeroOneZero;\n"
3094 " float fSix;\n"
3095 " float fSeven;\n"
3096 " float fEight;\n"
3097 " float fNine;\n"
3098 " vec2 fZeroZero;\n"
3099 " vec2 fZeroOne;\n"
3100 " vec4 fBlue;\n"
3101 " vec2 fOneZero;\n"
3102 " vec2 fOneOne;\n"
3103 " vec3 fZeroOneOne;\n"
3104 " float fTen;\n"
3105 " float fEleven;\n"
3106 " float fTwelve;\n"
3107 " vec3 fOneZeroZero;\n"
3108 " vec4 uvOffsets[4];\n"
3109 "};\n"
3110 "layout (location = 0) out vec4 color;"
3111 "void main() {\n"
3112
3113 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3114 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3115 " \n"
3116
3117 // do some exact comparisons, even though we should
3118 // really have an epsilon involved.
3119 " vec4 outColor = right;\n"
3120 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3121 " outColor = wrong;\n"
3122 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3123 " outColor = wrong;\n"
3124 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3125 " outColor = wrong;\n"
3126
3127 " color = outColor;\n"
3128
3129 // generic position stuff
3130 " vec2 vertices;\n"
3131 " int vertexSelector = gl_VertexID;\n"
3132 " if (vertexSelector == 0)\n"
3133 " vertices = vec2(-0.5, -0.5);\n"
3134 " else if (vertexSelector == 1)\n"
3135 " vertices = vec2( 0.5, -0.5);\n"
3136 " else if (vertexSelector == 2)\n"
3137 " vertices = vec2( 0.5, 0.5);\n"
3138 " else\n"
3139 " vertices = vec2( 0.0, 0.0);\n"
3140 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3141 "}\n";
3142
3143 static const char *fragShaderText =
3144 "#version 140\n"
3145 "#extension GL_ARB_separate_shader_objects : enable\n"
3146 "#extension GL_ARB_shading_language_420pack : enable\n"
3147 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3148 " vec4 fRed;\n"
3149 " vec4 fGreen;\n"
3150 " layout(row_major) mat4 worldToProj;\n"
3151 " layout(row_major) mat4 projToWorld;\n"
3152 " layout(row_major) mat4 worldToView;\n"
3153 " layout(row_major) mat4 viewToProj;\n"
3154 " layout(row_major) mat4 worldToShadow[4];\n"
3155 " float fZero;\n"
3156 " float fOne;\n"
3157 " float fTwo;\n"
3158 " float fThree;\n"
3159 " vec3 fZeroZeroZero;\n"
3160 " float fFour;\n"
3161 " vec3 fZeroZeroOne;\n"
3162 " float fFive;\n"
3163 " vec3 fZeroOneZero;\n"
3164 " float fSix;\n"
3165 " float fSeven;\n"
3166 " float fEight;\n"
3167 " float fNine;\n"
3168 " vec2 fZeroZero;\n"
3169 " vec2 fZeroOne;\n"
3170 " vec4 fBlue;\n"
3171 " vec2 fOneZero;\n"
3172 " vec2 fOneOne;\n"
3173 " vec3 fZeroOneOne;\n"
3174 " float fTen;\n"
3175 " float fEleven;\n"
3176 " float fTwelve;\n"
3177 " vec3 fOneZeroZero;\n"
3178 " vec4 uvOffsets[4];\n"
3179 "};\n"
3180 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003181 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop02690bd2014-12-17 15:26:33 -07003182 "void main() {\n"
3183 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3184 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3185 " \n"
3186
3187 // start with VS value to ensure it passed
3188 " vec4 outColor = color;\n"
3189
3190 // do some exact comparisons, even though we should
3191 // really have an epsilon involved.
3192 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3193 " outColor = wrong;\n"
3194 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3195 " outColor = wrong;\n"
3196 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3197 " outColor = wrong;\n"
3198 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3199 " outColor = wrong;\n"
3200 " if (fTwo != 2.0)\n"
3201 " outColor = wrong;\n"
3202 " if (fOneOne != vec2(1.0, 1.0))\n"
3203 " outColor = wrong;\n"
3204 " if (fTen != 10.0)\n"
3205 " outColor = wrong;\n"
3206 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3207 " outColor = wrong;\n"
3208 " \n"
GregFd6ebdb32015-06-03 18:40:50 -06003209 " uFragColor = outColor;\n"
Cody Northrop02690bd2014-12-17 15:26:33 -07003210 "}\n";
3211
3212
3213 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3214 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3215 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3216 0.0, 1.0, 0.0, 1.0, // align
3217 0.0, 0.0, 1.0, 1.0, // align
3218 0.0, 0.0, 0.0, 1.0, // align
3219 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3220 0.0, 2.0, 0.0, 2.0, // align
3221 0.0, 0.0, 2.0, 2.0, // align
3222 0.0, 0.0, 0.0, 2.0, // align
3223 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3224 0.0, 3.0, 0.0, 3.0, // align
3225 0.0, 0.0, 3.0, 3.0, // align
3226 0.0, 0.0, 0.0, 3.0, // align
3227 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3228 0.0, 4.0, 0.0, 4.0, // align
3229 0.0, 0.0, 4.0, 4.0, // align
3230 0.0, 0.0, 0.0, 4.0, // align
3231 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3232 0.0, 5.0, 0.0, 5.0, // align
3233 0.0, 0.0, 5.0, 5.0, // align
3234 0.0, 0.0, 0.0, 5.0, // align
3235 6.0, 0.0, 0.0, 6.0, // align
3236 0.0, 6.0, 0.0, 6.0, // align
3237 0.0, 0.0, 6.0, 6.0, // align
3238 0.0, 0.0, 0.0, 6.0, // align
3239 7.0, 0.0, 0.0, 7.0, // align
3240 0.0, 7.0, 0.0, 7.0, // align
3241 0.0, 0.0, 7.0, 7.0, // align
3242 0.0, 0.0, 0.0, 7.0, // align
3243 8.0, 0.0, 0.0, 8.0, // align
3244 0.0, 8.0, 0.0, 8.0, // align
3245 0.0, 0.0, 8.0, 8.0, // align
3246 0.0, 0.0, 0.0, 8.0, // align
3247 0.0, // float fZero; // align
3248 1.0, // float fOne; // pack
3249 2.0, // float fTwo; // pack
3250 3.0, // float fThree; // pack
3251 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3252 4.0, // float fFour; // pack
3253 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3254 5.0, // float fFive; // pack
3255 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3256 6.0, // float fSix; // pack
3257 7.0, // float fSeven; // align
3258 8.0, // float fEight; // pack
3259 9.0, // float fNine; // pack
3260 0.0, // BUFFER
3261 0.0, 0.0, // vec2 fZeroZero; // align
3262 0.0, 1.0, // vec2 fZeroOne; // pack
3263 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3264 1.0, 0.0, // vec2 fOneZero; // align
3265 1.0, 1.0, // vec2 fOneOne; // pack
3266 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3267 10.0, // float fTen; // pack
3268 11.0, // float fEleven; // align
3269 12.0, // float fTwelve; // pack
3270 0.0, 0.0, // BUFFER
3271 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3272 0.0, // BUFFER
3273 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3274 0.5, 0.6, 0.7, 0.8, // align
3275 0.9, 1.0, 1.1, 1.2, // align
3276 1.3, 1.4, 1.5, 1.6, // align
3277 };
3278
3279 ASSERT_NO_FATAL_FAILURE(InitState());
3280 ASSERT_NO_FATAL_FAILURE(InitViewport());
3281
3282 const int constCount = sizeof(mixedVals) / sizeof(float);
3283
Tony Barbour01999182015-04-09 12:58:51 -06003284 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3285 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop02690bd2014-12-17 15:26:33 -07003286
Tony Barbour01999182015-04-09 12:58:51 -06003287 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003288
Tony Barbour01999182015-04-09 12:58:51 -06003289 VkPipelineObj pipelineobj(m_device);
Cody Northrop02690bd2014-12-17 15:26:33 -07003290 pipelineobj.AddShader(&vs);
3291 pipelineobj.AddShader(&ps);
3292
Tony Barbour01999182015-04-09 12:58:51 -06003293 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003294 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003295
3296 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06003297 VkCommandBufferObj cmdBuffer(m_device);
Cody Northrop02690bd2014-12-17 15:26:33 -07003298 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3299
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003300 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Cody Northrop02690bd2014-12-17 15:26:33 -07003301
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003302 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Cody Northrop02690bd2014-12-17 15:26:33 -07003303
3304#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003305 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop02690bd2014-12-17 15:26:33 -07003306 pDSDumpDot((char*)"triTest2.dot");
3307#endif
3308 // render triangle
3309 cmdBuffer.Draw(0, 3, 0, 1);
3310
3311 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003312 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003313 cmdBuffer.QueueCommandBuffer();
Cody Northrop02690bd2014-12-17 15:26:33 -07003314
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003315 RecordImages(m_renderTargets);
Cody Northrop02690bd2014-12-17 15:26:33 -07003316}
3317
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003318TEST_F(VkRenderTest, TextureGather)
3319{
3320 // This test introduces textureGather and textureGatherOffset
3321 // Each call is compared against an expected inline color result
3322 // Green triangle means everything worked as expected
3323 // Red means something went wrong
3324
3325 // disable SPV until texture gather is turned on in LunarGLASS
Cody Northrop1cfbd172015-06-03 16:49:20 -06003326 ScopedUseGlsl useGlsl(true);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003327
3328 static const char *vertShaderText =
3329 "#version 140\n"
3330 "#extension GL_ARB_separate_shader_objects : enable\n"
3331 "#extension GL_ARB_shading_language_420pack : enable\n"
3332 "void main() {\n"
3333 " vec2 vertices[3];"
3334 " vertices[0] = vec2(-0.5, -0.5);\n"
3335 " vertices[1] = vec2( 0.5, -0.5);\n"
3336 " vertices[2] = vec2( 0.5, 0.5);\n"
3337 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
3338 "}\n";
3339
3340 static const char *fragShaderText =
3341 "#version 430\n"
3342 "#extension GL_ARB_separate_shader_objects : enable\n"
3343 "#extension GL_ARB_shading_language_420pack : enable\n"
3344 "layout (binding = 0) uniform sampler2D surface0;\n"
3345 "layout (binding = 1) uniform sampler2D surface1;\n"
3346 "layout (binding = 2) uniform sampler2D surface2;\n"
3347 "layout (binding = 3) uniform sampler2D surface3;\n"
3348 "layout (location = 0) out vec4 outColor;\n"
3349 "void main() {\n"
3350
3351 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3352 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3353
3354 " vec4 color = right;\n"
3355
3356 // Grab a normal texture sample to ensure it can work in conjuntion
3357 // with textureGather (there are some intracacies in the backend)
3358 " vec4 sampledColor = textureLod(surface2, vec2(0.5), 0.0);\n"
3359 " if (sampledColor != vec4(0.0, 0.0, 1.0, 1.0))\n"
3360 " color = wrong;\n"
3361
3362 " vec4 gatheredColor = textureGather(surface0, vec2(0.5), 0);\n"
3363 // This just grabbed four red components from a red surface
3364 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3365 " color = wrong;\n"
3366
3367 // Yes, this is using an offset of 0, we don't have enough fine grained
3368 // control of the texture contents here.
3369 " gatheredColor = textureGatherOffset(surface1, vec2(0.5), ivec2(0, 0), 1);\n"
3370 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3371 " color = wrong;\n"
3372
3373 " outColor = color;\n"
3374
3375 "}\n";
3376
3377 ASSERT_NO_FATAL_FAILURE(InitState());
3378 ASSERT_NO_FATAL_FAILURE(InitViewport());
3379
3380 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3381 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3382
3383 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
3384 VkSamplerObj sampler0(m_device);
3385 VkTextureObj texture0(m_device, tex_colors); // Red
3386 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
3387 VkSamplerObj sampler1(m_device);
3388 VkTextureObj texture1(m_device, tex_colors); // Green
3389 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
3390 VkSamplerObj sampler2(m_device);
3391 VkTextureObj texture2(m_device, tex_colors); // Blue
3392 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
3393 VkSamplerObj sampler3(m_device);
3394 VkTextureObj texture3(m_device, tex_colors); // Red and Blue
3395
3396 VkPipelineObj pipelineobj(m_device);
3397 pipelineobj.AddShader(&vs);
3398 pipelineobj.AddShader(&ps);
3399
3400 VkDescriptorSetObj descriptorSet(m_device);
3401 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3402 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
3403 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3404 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
3405
3406 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3407 VkCommandBufferObj cmdBuffer(m_device);
3408 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3409
3410 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3411
3412 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3413
3414 // render triangle
3415 cmdBuffer.Draw(0, 3, 0, 1);
3416
3417 // finalize recording of the command buffer
3418 EndCommandBuffer(cmdBuffer);
3419 cmdBuffer.QueueCommandBuffer();
3420
3421 RecordImages(m_renderTargets);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003422}
3423
Cody Northropa44c2ff2015-04-15 11:19:06 -06003424TEST_F(VkRenderTest, GeometryShaderHelloWorld)
3425{
3426 // This test introduces a geometry shader that simply
3427 // changes the color of each vertex to red, green, blue
3428
3429 static const char *vertShaderText =
3430 "#version 140\n"
3431 "#extension GL_ARB_separate_shader_objects : enable\n"
3432 "#extension GL_ARB_shading_language_420pack : enable\n"
3433 "layout (location = 0) out vec4 color;"
3434 "void main() {\n"
3435
3436 // VS writes out red
3437 " color = vec4(1.0, 0.0, 0.0, 1.0);\n"
3438
3439 // generic position stuff
3440 " vec2 vertices;\n"
3441 " int vertexSelector = gl_VertexID;\n"
3442 " if (vertexSelector == 0)\n"
3443 " vertices = vec2(-0.5, -0.5);\n"
3444 " else if (vertexSelector == 1)\n"
3445 " vertices = vec2( 0.5, -0.5);\n"
3446 " else if (vertexSelector == 2)\n"
3447 " vertices = vec2( 0.5, 0.5);\n"
3448 " else\n"
3449 " vertices = vec2( 0.0, 0.0);\n"
3450 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3451
3452 "}\n";
3453
3454 static const char *geomShaderText =
3455 "#version 330\n"
3456 "#extension GL_ARB_separate_shader_objects : enable\n"
3457 "#extension GL_ARB_shading_language_420pack : enable\n"
3458 "layout( triangles ) in;\n"
3459 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3460 "layout( location = 0 ) in vec4 inColor[3];\n"
3461 "layout( location = 0 ) out vec4 outColor;\n"
3462 "void main()\n"
3463 "{\n"
3464
3465 // first vertex, pass through red
3466 " gl_Position = gl_in[0].gl_Position;\n"
3467 " outColor = inColor[0];\n"
3468 " EmitVertex();\n"
3469
3470 // second vertex, green
3471 " gl_Position = gl_in[1].gl_Position;\n"
3472 " outColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3473 " EmitVertex();\n"
3474
3475 // third vertex, blue
3476 " gl_Position = gl_in[2].gl_Position;\n"
3477 " outColor = vec4(0.0, 0.0, 1.0, 1.0);\n"
3478 " EmitVertex();\n"
3479
3480 // done
3481 " EndPrimitive();\n"
3482 "}\n";
3483
3484
3485 static const char *fragShaderText =
3486 "#version 140\n"
3487 "#extension GL_ARB_separate_shader_objects : enable\n"
3488 "#extension GL_ARB_shading_language_420pack : enable\n"
3489 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003490 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003491 "void main() {\n"
3492 // pass through
GregFd6ebdb32015-06-03 18:40:50 -06003493 " outColor = color;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003494 "}\n";
3495
3496
3497
3498 ASSERT_NO_FATAL_FAILURE(InitState());
3499 ASSERT_NO_FATAL_FAILURE(InitViewport());
3500
3501 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3502 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3503 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3504
3505 VkPipelineObj pipelineobj(m_device);
3506 pipelineobj.AddShader(&vs);
3507 pipelineobj.AddShader(&gs);
3508 pipelineobj.AddShader(&ps);
3509
3510 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3511 VkCommandBufferObj cmdBuffer(m_device);
3512 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3513
3514 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3515
3516 VkDescriptorSetObj descriptorSet(m_device);
3517
3518 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3519
3520 // render triangle
3521 cmdBuffer.Draw(0, 3, 0, 1);
3522
3523 // finalize recording of the command buffer
3524 EndCommandBuffer(cmdBuffer);
3525 cmdBuffer.QueueCommandBuffer();
3526
3527 RecordImages(m_renderTargets);
3528}
3529
3530TEST_F(VkRenderTest, GSUniformBufferLayout)
3531{
3532 // This test is just like TriangleUniformBufferLayout but adds
3533 // geometry as a stage that also does UBO lookups
3534 // The expected result from this test is a green triangle
3535
3536 static const char *vertShaderText =
3537 "#version 140\n"
3538 "#extension GL_ARB_separate_shader_objects : enable\n"
3539 "#extension GL_ARB_shading_language_420pack : enable\n"
3540 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3541 " vec4 fRed;\n"
3542 " vec4 fGreen;\n"
3543 " layout(row_major) mat4 worldToProj;\n"
3544 " layout(row_major) mat4 projToWorld;\n"
3545 " layout(row_major) mat4 worldToView;\n"
3546 " layout(row_major) mat4 viewToProj;\n"
3547 " layout(row_major) mat4 worldToShadow[4];\n"
3548 " float fZero;\n"
3549 " float fOne;\n"
3550 " float fTwo;\n"
3551 " float fThree;\n"
3552 " vec3 fZeroZeroZero;\n"
3553 " float fFour;\n"
3554 " vec3 fZeroZeroOne;\n"
3555 " float fFive;\n"
3556 " vec3 fZeroOneZero;\n"
3557 " float fSix;\n"
3558 " float fSeven;\n"
3559 " float fEight;\n"
3560 " float fNine;\n"
3561 " vec2 fZeroZero;\n"
3562 " vec2 fZeroOne;\n"
3563 " vec4 fBlue;\n"
3564 " vec2 fOneZero;\n"
3565 " vec2 fOneOne;\n"
3566 " vec3 fZeroOneOne;\n"
3567 " float fTen;\n"
3568 " float fEleven;\n"
3569 " float fTwelve;\n"
3570 " vec3 fOneZeroZero;\n"
3571 " vec4 uvOffsets[4];\n"
3572 "};\n"
3573 "layout (location = 0) out vec4 color;"
3574 "void main() {\n"
3575
3576 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3577 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3578 " \n"
3579
3580 // do some exact comparisons, even though we should
3581 // really have an epsilon involved.
3582 " vec4 outColor = right;\n"
3583 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3584 " outColor = wrong;\n"
3585 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3586 " outColor = wrong;\n"
3587 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3588 " outColor = wrong;\n"
3589
3590 " color = outColor;\n"
3591
3592 // generic position stuff
3593 " vec2 vertices;\n"
3594 " int vertexSelector = gl_VertexID;\n"
3595 " if (vertexSelector == 0)\n"
3596 " vertices = vec2(-0.5, -0.5);\n"
3597 " else if (vertexSelector == 1)\n"
3598 " vertices = vec2( 0.5, -0.5);\n"
3599 " else if (vertexSelector == 2)\n"
3600 " vertices = vec2( 0.5, 0.5);\n"
3601 " else\n"
3602 " vertices = vec2( 0.0, 0.0);\n"
3603 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3604 "}\n";
3605
3606 static const char *geomShaderText =
3607 "#version 330\n"
3608 "#extension GL_ARB_separate_shader_objects : enable\n"
3609 "#extension GL_ARB_shading_language_420pack : enable\n"
3610
3611 // GS layout stuff
3612 "layout( triangles ) in;\n"
3613 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3614
3615 // Between stage IO
3616 "layout( location = 0 ) in vec4 inColor[3];\n"
3617 "layout( location = 0 ) out vec4 color;\n"
3618
3619 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3620 " vec4 fRed;\n"
3621 " vec4 fGreen;\n"
3622 " layout(row_major) mat4 worldToProj;\n"
3623 " layout(row_major) mat4 projToWorld;\n"
3624 " layout(row_major) mat4 worldToView;\n"
3625 " layout(row_major) mat4 viewToProj;\n"
3626 " layout(row_major) mat4 worldToShadow[4];\n"
3627 " float fZero;\n"
3628 " float fOne;\n"
3629 " float fTwo;\n"
3630 " float fThree;\n"
3631 " vec3 fZeroZeroZero;\n"
3632 " float fFour;\n"
3633 " vec3 fZeroZeroOne;\n"
3634 " float fFive;\n"
3635 " vec3 fZeroOneZero;\n"
3636 " float fSix;\n"
3637 " float fSeven;\n"
3638 " float fEight;\n"
3639 " float fNine;\n"
3640 " vec2 fZeroZero;\n"
3641 " vec2 fZeroOne;\n"
3642 " vec4 fBlue;\n"
3643 " vec2 fOneZero;\n"
3644 " vec2 fOneOne;\n"
3645 " vec3 fZeroOneOne;\n"
3646 " float fTen;\n"
3647 " float fEleven;\n"
3648 " float fTwelve;\n"
3649 " vec3 fOneZeroZero;\n"
3650 " vec4 uvOffsets[4];\n"
3651 "};\n"
3652
3653 "void main()\n"
3654 "{\n"
3655
3656 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3657 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3658
3659 // Each vertex will validate it can read VS output
3660 // then check a few values from the UBO
3661
3662 // first vertex
3663 " vec4 outColor = inColor[0];\n"
3664
3665 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3666 " outColor = wrong;\n"
3667 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3668 " outColor = wrong;\n"
3669 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3670 " outColor = wrong;\n"
3671 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3672 " outColor = wrong;\n"
3673
3674 " gl_Position = gl_in[0].gl_Position;\n"
3675 " color = outColor;\n"
3676 " EmitVertex();\n"
3677
3678 // second vertex
3679 " outColor = inColor[1];\n"
3680
3681 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3682 " outColor = wrong;\n"
3683 " if (fSix != 6.0)\n"
3684 " outColor = wrong;\n"
3685 " if (fOneOne != vec2(1.0, 1.0))\n"
3686 " outColor = wrong;\n"
3687
3688 " gl_Position = gl_in[1].gl_Position;\n"
3689 " color = outColor;\n"
3690 " EmitVertex();\n"
3691
3692 // third vertex
3693 " outColor = inColor[2];\n"
3694
3695 " if (fSeven != 7.0)\n"
3696 " outColor = wrong;\n"
3697 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3698 " outColor = wrong;\n"
3699
3700 " gl_Position = gl_in[2].gl_Position;\n"
3701 " color = outColor;\n"
3702 " EmitVertex();\n"
3703
3704 // done
3705 " EndPrimitive();\n"
3706 "}\n";
3707
3708 static const char *fragShaderText =
3709 "#version 140\n"
3710 "#extension GL_ARB_separate_shader_objects : enable\n"
3711 "#extension GL_ARB_shading_language_420pack : enable\n"
3712 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3713 " vec4 fRed;\n"
3714 " vec4 fGreen;\n"
3715 " layout(row_major) mat4 worldToProj;\n"
3716 " layout(row_major) mat4 projToWorld;\n"
3717 " layout(row_major) mat4 worldToView;\n"
3718 " layout(row_major) mat4 viewToProj;\n"
3719 " layout(row_major) mat4 worldToShadow[4];\n"
3720 " float fZero;\n"
3721 " float fOne;\n"
3722 " float fTwo;\n"
3723 " float fThree;\n"
3724 " vec3 fZeroZeroZero;\n"
3725 " float fFour;\n"
3726 " vec3 fZeroZeroOne;\n"
3727 " float fFive;\n"
3728 " vec3 fZeroOneZero;\n"
3729 " float fSix;\n"
3730 " float fSeven;\n"
3731 " float fEight;\n"
3732 " float fNine;\n"
3733 " vec2 fZeroZero;\n"
3734 " vec2 fZeroOne;\n"
3735 " vec4 fBlue;\n"
3736 " vec2 fOneZero;\n"
3737 " vec2 fOneOne;\n"
3738 " vec3 fZeroOneOne;\n"
3739 " float fTen;\n"
3740 " float fEleven;\n"
3741 " float fTwelve;\n"
3742 " vec3 fOneZeroZero;\n"
3743 " vec4 uvOffsets[4];\n"
3744 "};\n"
3745 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003746 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003747 "void main() {\n"
3748 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3749 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3750 " \n"
3751
3752 // start with GS value to ensure it passed
3753 " vec4 outColor = color;\n"
3754
3755 // do some exact comparisons, even though we should
3756 // really have an epsilon involved.
3757 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3758 " outColor = wrong;\n"
3759 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3760 " outColor = wrong;\n"
3761 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3762 " outColor = wrong;\n"
3763 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3764 " outColor = wrong;\n"
3765 " if (fTwo != 2.0)\n"
3766 " outColor = wrong;\n"
3767 " if (fOneOne != vec2(1.0, 1.0))\n"
3768 " outColor = wrong;\n"
3769 " if (fTen != 10.0)\n"
3770 " outColor = wrong;\n"
3771 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3772 " outColor = wrong;\n"
3773 " \n"
GregFd6ebdb32015-06-03 18:40:50 -06003774 " uFragColor = outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003775 "}\n";
3776
3777
3778 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3779 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3780 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3781 0.0, 1.0, 0.0, 1.0, // align
3782 0.0, 0.0, 1.0, 1.0, // align
3783 0.0, 0.0, 0.0, 1.0, // align
3784 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3785 0.0, 2.0, 0.0, 2.0, // align
3786 0.0, 0.0, 2.0, 2.0, // align
3787 0.0, 0.0, 0.0, 2.0, // align
3788 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3789 0.0, 3.0, 0.0, 3.0, // align
3790 0.0, 0.0, 3.0, 3.0, // align
3791 0.0, 0.0, 0.0, 3.0, // align
3792 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3793 0.0, 4.0, 0.0, 4.0, // align
3794 0.0, 0.0, 4.0, 4.0, // align
3795 0.0, 0.0, 0.0, 4.0, // align
3796 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3797 0.0, 5.0, 0.0, 5.0, // align
3798 0.0, 0.0, 5.0, 5.0, // align
3799 0.0, 0.0, 0.0, 5.0, // align
3800 6.0, 0.0, 0.0, 6.0, // align
3801 0.0, 6.0, 0.0, 6.0, // align
3802 0.0, 0.0, 6.0, 6.0, // align
3803 0.0, 0.0, 0.0, 6.0, // align
3804 7.0, 0.0, 0.0, 7.0, // align
3805 0.0, 7.0, 0.0, 7.0, // align
3806 0.0, 0.0, 7.0, 7.0, // align
3807 0.0, 0.0, 0.0, 7.0, // align
3808 8.0, 0.0, 0.0, 8.0, // align
3809 0.0, 8.0, 0.0, 8.0, // align
3810 0.0, 0.0, 8.0, 8.0, // align
3811 0.0, 0.0, 0.0, 8.0, // align
3812 0.0, // float fZero; // align
3813 1.0, // float fOne; // pack
3814 2.0, // float fTwo; // pack
3815 3.0, // float fThree; // pack
3816 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3817 4.0, // float fFour; // pack
3818 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3819 5.0, // float fFive; // pack
3820 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3821 6.0, // float fSix; // pack
3822 7.0, // float fSeven; // align
3823 8.0, // float fEight; // pack
3824 9.0, // float fNine; // pack
3825 0.0, // BUFFER
3826 0.0, 0.0, // vec2 fZeroZero; // align
3827 0.0, 1.0, // vec2 fZeroOne; // pack
3828 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3829 1.0, 0.0, // vec2 fOneZero; // align
3830 1.0, 1.0, // vec2 fOneOne; // pack
3831 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3832 10.0, // float fTen; // pack
3833 11.0, // float fEleven; // align
3834 12.0, // float fTwelve; // pack
3835 0.0, 0.0, // BUFFER
3836 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3837 0.0, // BUFFER
3838 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3839 0.5, 0.6, 0.7, 0.8, // align
3840 0.9, 1.0, 1.1, 1.2, // align
3841 1.3, 1.4, 1.5, 1.6, // align
3842 };
3843
3844
3845
3846 ASSERT_NO_FATAL_FAILURE(InitState());
3847 ASSERT_NO_FATAL_FAILURE(InitViewport());
3848
3849 const int constCount = sizeof(mixedVals) / sizeof(float);
3850
3851 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3852 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3853 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3854
3855 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
3856
3857 VkPipelineObj pipelineobj(m_device);
3858 pipelineobj.AddShader(&vs);
3859 pipelineobj.AddShader(&gs);
3860 pipelineobj.AddShader(&ps);
3861
3862 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3863 VkCommandBufferObj cmdBuffer(m_device);
3864 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3865
3866 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3867
3868 VkDescriptorSetObj descriptorSet(m_device);
3869 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
3870
3871 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3872
3873 // render triangle
3874 cmdBuffer.Draw(0, 3, 0, 1);
3875
3876 // finalize recording of the command buffer
3877 EndCommandBuffer(cmdBuffer);
3878 cmdBuffer.QueueCommandBuffer();
3879
3880 RecordImages(m_renderTargets);
3881}
3882
3883TEST_F(VkRenderTest, GSPositions)
3884{
3885 // This test adds more inputs from the vertex shader and perturbs positions
3886 // Expected result is white triangle with weird positions
3887
3888 static const char *vertShaderText =
3889 "#version 140\n"
3890 "#extension GL_ARB_separate_shader_objects : enable\n"
3891 "#extension GL_ARB_shading_language_420pack : enable\n"
3892
3893 "layout(location = 0) out vec3 out_a;\n"
3894 "layout(location = 1) out vec3 out_b;\n"
3895 "layout(location = 2) out vec3 out_c;\n"
3896
3897 "void main() {\n"
3898
3899 // write a solid color to each
3900 " out_a = vec3(1.0, 0.0, 0.0);\n"
3901 " out_b = vec3(0.0, 1.0, 0.0);\n"
3902 " out_c = vec3(0.0, 0.0, 1.0);\n"
3903
3904 // generic position stuff
3905 " vec2 vertices;\n"
3906 " int vertexSelector = gl_VertexID;\n"
3907 " if (vertexSelector == 0)\n"
3908 " vertices = vec2(-0.5, -0.5);\n"
3909 " else if (vertexSelector == 1)\n"
3910 " vertices = vec2( 0.5, -0.5);\n"
3911 " else if (vertexSelector == 2)\n"
3912 " vertices = vec2( 0.5, 0.5);\n"
3913 " else\n"
3914 " vertices = vec2( 0.0, 0.0);\n"
3915 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3916
3917 "}\n";
3918
3919 static const char *geomShaderText =
3920 "#version 330\n"
3921 "#extension GL_ARB_separate_shader_objects : enable\n"
3922 "#extension GL_ARB_shading_language_420pack : enable\n"
3923 "layout( triangles ) in;\n"
3924 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3925
3926 "layout(location = 0) in vec3 in_a[3];\n"
3927 "layout(location = 1) in vec3 in_b[3];\n"
3928 "layout(location = 2) in vec3 in_c[3];\n"
3929
3930 "layout(location = 0) out vec3 out_a;\n"
3931 "layout(location = 1) out vec3 out_b;\n"
3932 "layout(location = 2) out vec3 out_c;\n"
3933
3934 "void main()\n"
3935 "{\n"
3936
3937 " gl_Position = gl_in[0].gl_Position;\n"
3938 " gl_Position.xy *= vec2(0.75);\n"
3939 " out_a = in_a[0];\n"
3940 " out_b = in_b[0];\n"
3941 " out_c = in_c[0];\n"
3942 " EmitVertex();\n"
3943
3944 " gl_Position = gl_in[1].gl_Position;\n"
3945 " gl_Position.xy *= vec2(1.5);\n"
3946 " out_a = in_a[1];\n"
3947 " out_b = in_b[1];\n"
3948 " out_c = in_c[1];\n"
3949 " EmitVertex();\n"
3950
3951 " gl_Position = gl_in[2].gl_Position;\n"
3952 " gl_Position.xy *= vec2(-0.1);\n"
3953 " out_a = in_a[2];\n"
3954 " out_b = in_b[2];\n"
3955 " out_c = in_c[2];\n"
3956 " EmitVertex();\n"
3957
3958 " EndPrimitive();\n"
3959 "}\n";
3960
3961
3962 static const char *fragShaderText =
3963 "#version 140\n"
3964 "#extension GL_ARB_separate_shader_objects : enable\n"
3965 "#extension GL_ARB_shading_language_420pack : enable\n"
3966
3967 "layout(location = 0) in vec3 in_a;\n"
3968 "layout(location = 1) in vec3 in_b;\n"
3969 "layout(location = 2) in vec3 in_c;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003970 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003971
3972 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06003973 " outColor = vec4(in_a.x, in_b.y, in_c.z, 1.0);\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003974 "}\n";
3975
3976
3977
3978 ASSERT_NO_FATAL_FAILURE(InitState());
3979 ASSERT_NO_FATAL_FAILURE(InitViewport());
3980
3981 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3982 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3983 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3984
3985 VkPipelineObj pipelineobj(m_device);
3986 pipelineobj.AddShader(&vs);
3987 pipelineobj.AddShader(&gs);
3988 pipelineobj.AddShader(&ps);
3989
3990 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3991 VkCommandBufferObj cmdBuffer(m_device);
3992 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3993
3994 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3995
3996 VkDescriptorSetObj descriptorSet(m_device);
3997
3998 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3999
4000 // render triangle
4001 cmdBuffer.Draw(0, 3, 0, 1);
4002
4003 // finalize recording of the command buffer
4004 EndCommandBuffer(cmdBuffer);
4005 cmdBuffer.QueueCommandBuffer();
4006
4007 RecordImages(m_renderTargets);
4008}
4009
4010TEST_F(VkRenderTest, GSTriStrip)
4011{
4012 // This test emits multiple multiple triangles using a GS
4013 // Correct result is an multicolor circle
4014
4015 static const char *vertShaderText =
4016 "#version 140\n"
4017 "#extension GL_ARB_separate_shader_objects : enable\n"
4018 "#extension GL_ARB_shading_language_420pack : enable\n"
4019
4020 "void main() {\n"
4021
4022 // generic position stuff
4023 " vec2 vertices;\n"
4024 " int vertexSelector = gl_VertexID;\n"
4025 " if (vertexSelector == 0)\n"
4026 " vertices = vec2(-0.5, -0.5);\n"
4027 " else if (vertexSelector == 1)\n"
4028 " vertices = vec2( 0.5, -0.5);\n"
4029 " else if (vertexSelector == 2)\n"
4030 " vertices = vec2( 0.5, 0.5);\n"
4031 " else\n"
4032 " vertices = vec2( 0.0, 0.0);\n"
4033 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
4034
4035 "}\n";
4036
4037 static const char *geomShaderText =
4038 "#version 330\n"
4039 "#extension GL_ARB_separate_shader_objects : enable\n"
4040 "#extension GL_ARB_shading_language_420pack : enable\n"
4041 "layout( triangles ) in;\n"
4042 "layout( triangle_strip, max_vertices = 18 ) out;\n"
4043
4044 "layout(location = 0) out vec4 outColor;\n"
4045
4046 "void main()\n"
4047 "{\n"
4048 // init with first position to get zw
4049 " gl_Position = gl_in[0].gl_Position;\n"
4050
4051 " vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
4052 " vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
4053 " vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
4054 " vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
4055
4056 // different color per tri
4057 " vec4[6] colors = { red, white, \n"
4058 " yellow, white, \n"
4059 " blue, white }; \n"
4060
4061 // fan out the triangles
4062 " vec2[18] positions = { vec2(0.0, 0.0), vec2(-0.5, 0.0), vec2(-0.25, -0.5), \n"
4063 " vec2(0.0, 0.0), vec2(-0.25, -0.5), vec2( 0.25, -0.5), \n"
4064 " vec2(0.0, 0.0), vec2( 0.25, -0.5), vec2( 0.5, 0.0), \n"
4065 " vec2(0.0, 0.0), vec2( 0.5, 0.0), vec2( 0.25, 0.5), \n"
4066 " vec2(0.0, 0.0), vec2( 0.25, 0.5), vec2(-0.25, 0.5), \n"
4067 " vec2(0.0, 0.0), vec2(-0.25, 0.5), vec2(-0.5, 0.0) }; \n"
4068
4069 // make a triangle list of 6
4070 " for (int i = 0; i < 6; ++i) { \n"
4071 " outColor = colors[i]; \n"
4072 " for (int j = 0; j < 3; ++j) { \n"
4073 " gl_Position.xy = positions[i * 3 + j]; \n"
4074 " EmitVertex(); \n"
4075 " } \n"
4076 " EndPrimitive();\n"
4077 " } \n"
4078
4079 "}\n";
4080
4081
4082 static const char *fragShaderText =
4083 "#version 150\n"
4084 "#extension GL_ARB_separate_shader_objects : enable\n"
4085 "#extension GL_ARB_shading_language_420pack : enable\n"
4086
4087
4088 "layout(binding = 0) uniform windowDimensions {\n"
4089 " vec4 dimensions;\n"
4090 "};\n"
4091
4092 "layout(location = 0) in vec4 inColor;\n"
4093 "layout(origin_upper_left) in vec4 gl_FragCoord;\n"
GregFd6ebdb32015-06-03 18:40:50 -06004094 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06004095
4096 "void main() {\n"
4097
4098 // discard to make a nice circle
4099 " vec2 pos = abs(gl_FragCoord.xy) - vec2(dimensions.x, dimensions.y) / 2;\n"
4100 " float dist = sqrt(dot(pos, pos));\n"
4101 " if (dist > 50.0)\n"
4102 " discard;\n"
4103
GregFd6ebdb32015-06-03 18:40:50 -06004104 " outColor = inColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06004105
4106 "}\n";
4107
4108
4109
4110 ASSERT_NO_FATAL_FAILURE(InitState());
4111 ASSERT_NO_FATAL_FAILURE(InitViewport());
4112
4113 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
4114 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
4115 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
4116
4117 VkPipelineObj pipelineobj(m_device);
4118 pipelineobj.AddShader(&vs);
4119 pipelineobj.AddShader(&gs);
4120 pipelineobj.AddShader(&ps);
4121
4122 const float dimensions[4] = { VkRenderFramework::m_width, VkRenderFramework::m_height , 0.0, 0.0};
4123
4124 VkConstantBufferObj windowDimensions(m_device, sizeof(dimensions) / sizeof(dimensions[0]), sizeof(dimensions[0]), (const void*) dimensions);
4125
4126 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4127 VkCommandBufferObj cmdBuffer(m_device);
4128 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
4129
4130 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
4131
4132 VkDescriptorSetObj descriptorSet(m_device);
4133 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, windowDimensions);
4134
4135 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
4136
4137 // render triangle
4138 cmdBuffer.Draw(0, 3, 0, 1);
4139
4140 // finalize recording of the command buffer
4141 EndCommandBuffer(cmdBuffer);
4142 cmdBuffer.QueueCommandBuffer();
4143
4144 RecordImages(m_renderTargets);
4145}
4146
Chris Forbes23e6db62015-06-15 09:32:35 +12004147TEST_F(VkRenderTest, RenderPassLoadOpClear)
4148{
4149 ASSERT_NO_FATAL_FAILURE(InitState());
4150 ASSERT_NO_FATAL_FAILURE(InitViewport());
4151
4152 /* clear via load op to full green */
4153 m_clear_via_load_op = true;
4154 m_clear_color.useRawValue = false;
4155 m_clear_color.color.floatColor[0] = 0;
4156 m_clear_color.color.floatColor[1] = 1;
4157 m_clear_color.color.floatColor[2] = 0;
4158 m_clear_color.color.floatColor[3] = 0;
4159 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4160
4161 VkCommandBufferObj cmdBuffer(m_device);
4162 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
4163 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
4164 /* This command buffer contains ONLY the load op! */
4165 EndCommandBuffer(cmdBuffer);
4166 cmdBuffer.QueueCommandBuffer();
4167
4168 RecordImages(m_renderTargets);
4169}
4170
Chris Forbes1e16cb82015-06-24 12:05:30 +12004171TEST_F(VkRenderTest, RenderPassAttachmentClear)
4172{
4173 ASSERT_NO_FATAL_FAILURE(InitState());
4174 ASSERT_NO_FATAL_FAILURE(InitViewport());
4175
4176 /* clear via load op to full red */
4177 m_clear_via_load_op = true;
4178 m_clear_color.useRawValue = false;
4179 m_clear_color.color.floatColor[0] = 1;
4180 m_clear_color.color.floatColor[1] = 0;
4181 m_clear_color.color.floatColor[2] = 0;
4182 m_clear_color.color.floatColor[3] = 0;
4183 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4184
4185 VkCommandBufferObj cmdBuffer(m_device);
4186 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
4187 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
4188
4189 /* Load op has cleared to red */
4190
4191 /* Draw, draw, draw... */
4192
4193 /* Now, partway through this renderpass we want to clear the color
4194 * attachment again, this time to green.
4195 */
4196 VkClearColor clear_color;
4197 clear_color.useRawValue = false;
4198 clear_color.color.floatColor[0] = 0;
4199 clear_color.color.floatColor[1] = 1;
4200 clear_color.color.floatColor[2] = 0;
4201 clear_color.color.floatColor[3] = 0;
4202 VkRect3D clear_rect = { { 0, 0, 0 }, { (int)m_width, (int)m_height, 1 } };
4203 vkCmdClearColorAttachment(cmdBuffer.obj(), 0,
4204 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4205 &clear_color, 1, &clear_rect);
4206
4207 EndCommandBuffer(cmdBuffer);
4208 cmdBuffer.QueueCommandBuffer();
4209
4210 RecordImages(m_renderTargets);
4211}
4212
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004213int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004214 int result;
4215
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004216 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06004217 VkTestFramework::InitArgs(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004218
Chia-I Wu7133fdc2014-12-15 23:57:34 +08004219 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06004220
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004221 result = RUN_ALL_TESTS();
4222
Tony Barbour01999182015-04-09 12:58:51 -06004223 VkTestFramework::Finish();
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004224 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004225}