blob: 6ed17d0826c27e46a6c4e668f29dc4cb6337de91 [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()) {
329 cmdBuffer.EndRenderPass(renderPass());
330 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600331
332 result = cmdBuffer.EndCommandBuffer();
333
334 return result;
335}
336
337
Tony Barbour01999182015-04-09 12:58:51 -0600338void VkRenderTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet)
Tony Barbour02472db2015-01-08 17:08:28 -0700339{
Tony Barbour17c6ab12015-03-27 17:03:18 -0600340 if (m_depthStencil->Initialized()) {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600341 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Tony Barbour17c6ab12015-03-27 17:03:18 -0600342 } else {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600343 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour17c6ab12015-03-27 17:03:18 -0600344 }
345
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700346 cmdBuffer->PrepareAttachments();
Tony Barbour8205d902015-04-16 15:59:00 -0600347 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_RASTER, m_stateRaster);
348 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_VIEWPORT, m_stateViewport);
349 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_COLOR_BLEND, m_colorBlend);
350 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_DEPTH_STENCIL, m_stateDepthStencil);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600351 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
352 pipelineobj.CreateVKPipeline(descriptorSet);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600353 cmdBuffer->BindPipeline(pipelineobj);
Chia-I Wu862c5572015-03-28 15:23:55 +0800354 cmdBuffer->BindDescriptorSet(descriptorSet);
Tony Barbour02472db2015-01-08 17:08:28 -0700355}
Tony Barbourf43b6982014-11-25 13:18:32 -0700356
Tony Barbour01999182015-04-09 12:58:51 -0600357void VkRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
358 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer)
Tony Barbourdd4c9642015-01-09 12:55:14 -0700359{
360 int i;
361 glm::mat4 MVP;
362 int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600363 VkResult err;
Tony Barbourdd4c9642015-01-09 12:55:14 -0700364
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600365 /* Only do 3 positions to avoid back face cull */
366 for (i = 0; i < 3; i++) {
Tony Barbourdd4c9642015-01-09 12:55:14 -0700367 void *pData = constantBuffer->map();
368
369 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
370 MVP = Projection * View * Model;
371 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
372
373 constantBuffer->unmap();
374
375 // submit the command buffer to the universal queue
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600376 cmdBuffer->QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700377
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600378 err = vkQueueWaitIdle( m_device->m_queue );
379 ASSERT_VK_SUCCESS( err );
Tony Barbourdd4c9642015-01-09 12:55:14 -0700380
381 // Wait for work to finish before cleaning up.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600382 vkDeviceWaitIdle(m_device->device());
Tony Barbourdd4c9642015-01-09 12:55:14 -0700383
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700384 assert(m_renderTargets.size() == 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -0700385 RecordImage(m_renderTargets[0]);
386 }
387}
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600388
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600389void dumpMatrix(const char *note, glm::mat4 MVP)
390{
Chia-I Wu7133fdc2014-12-15 23:57:34 +0800391 int i;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600392
393 printf("%s: \n", note);
394 for (i=0; i<4; i++) {
395 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
396 }
397 printf("\n");
398 fflush(stdout);
399}
400
401void dumpVec4(const char *note, glm::vec4 vector)
402{
403 printf("%s: \n", note);
404 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
405 printf("\n");
406 fflush(stdout);
407}
408
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600409struct vktriangle_vs_uniform {
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600410 // Must start with MVP
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600411 float mvp[4][4];
412 float position[3][4];
413 float color[3][4];
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600414};
415
Tony Barbour01999182015-04-09 12:58:51 -0600416void VkRenderTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600417{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700418#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600419 vkDbgRegisterMsgCallback(inst, myDbgFunc, NULL);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700420#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600421 // Create identity matrix
422 int i;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600423 struct vktriangle_vs_uniform data;
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600424
425 glm::mat4 Projection = glm::mat4(1.0f);
426 glm::mat4 View = glm::mat4(1.0f);
427 glm::mat4 Model = glm::mat4(1.0f);
428 glm::mat4 MVP = Projection * View * Model;
429 const int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600430 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600431 memcpy(&data.mvp, &MVP[0][0], matrixSize);
432
433 static const Vertex tri_data[] =
434 {
435 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
436 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
437 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
438 };
439
440 for (i=0; i<3; i++) {
441 data.position[i][0] = tri_data[i].posX;
442 data.position[i][1] = tri_data[i].posY;
443 data.position[i][2] = tri_data[i].posZ;
444 data.position[i][3] = tri_data[i].posW;
445 data.color[i][0] = tri_data[i].r;
446 data.color[i][1] = tri_data[i].g;
447 data.color[i][2] = tri_data[i].b;
448 data.color[i][3] = tri_data[i].a;
449 }
450
Tony Barbourf43b6982014-11-25 13:18:32 -0700451 ASSERT_NO_FATAL_FAILURE(InitState());
452 ASSERT_NO_FATAL_FAILURE(InitViewport());
453
Tony Barbour01999182015-04-09 12:58:51 -0600454 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barbourf43b6982014-11-25 13:18:32 -0700455
Tony Barbour01999182015-04-09 12:58:51 -0600456 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
457 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700458
Tony Barbour01999182015-04-09 12:58:51 -0600459 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -0700460 pipelineobj.AddShader(&vs);
461 pipelineobj.AddShader(&ps);
462
Tony Barbour01999182015-04-09 12:58:51 -0600463 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600464 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700465
Tony Barbour71ba3612015-01-09 16:12:35 -0700466 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600467 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour71ba3612015-01-09 16:12:35 -0700468 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700469
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600470 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour71ba3612015-01-09 16:12:35 -0700471
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600472 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour71ba3612015-01-09 16:12:35 -0700473#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600474 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour71ba3612015-01-09 16:12:35 -0700475 pDSDumpDot((char*)"triTest2.dot");
476#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600477
Tony Barbour71ba3612015-01-09 16:12:35 -0700478 // render triangle
479 cmdBuffer.Draw(0, 3, 0, 1);
480
481 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600482 EndCommandBuffer(cmdBuffer);
483
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600484 cmdBuffer.QueueCommandBuffer();
Tony Barbour71ba3612015-01-09 16:12:35 -0700485
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600486 RecordImages(m_renderTargets);
Tony Barbour71ba3612015-01-09 16:12:35 -0700487
488 if (rotate)
Tobin Ehlis12ee35f2015-03-26 08:23:25 -0600489 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
Tony Barbour71ba3612015-01-09 16:12:35 -0700490
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700491#ifdef PRINT_OBJECTS
Mark Lobodzinski4e5016f2015-05-05 15:01:37 -0500492 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
Tony Barbour01999182015-04-09 12:58:51 -06002599TEST_F(VkRenderTest, CubeWithVertexFetchAndMVPAndTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07002600{
2601 static const char *vertShaderText =
2602 "#version 140\n"
2603 "#extension GL_ARB_separate_shader_objects : enable\n"
2604 "#extension GL_ARB_shading_language_420pack : enable\n"
2605 "layout (std140, binding=0) uniform bufferVals {\n"
2606 " mat4 mvp;\n"
2607 "} myBufferVals;\n"
2608 "layout (location=0) in vec4 pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002609 "layout (location=1) in vec2 input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002610 "layout (location=0) out vec2 UV;\n"
2611 "void main() {\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002612 " UV = input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002613 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002614 " gl_Position.y = -gl_Position.y;\n"
2615 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002616 "}\n";
2617
2618 static const char *fragShaderText =
2619 "#version 140\n"
2620 "#extension GL_ARB_separate_shader_objects : enable\n"
2621 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002622 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002623 "layout (location=0) out vec4 outColor;\n"
2624 "layout (location=0) in vec2 UV;\n"
2625 "void main() {\n"
2626 " outColor= textureLod(surface, UV, 0.0);\n"
2627 "}\n";
2628 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2629
2630 glm::mat4 View = glm::lookAt(
2631 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2632 glm::vec3(0,0,0), // and looks at the origin
2633 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2634 );
2635
2636 glm::mat4 Model = glm::mat4(1.0f);
2637
2638 glm::mat4 MVP = Projection * View * Model;
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002639 int num_verts = sizeof(g_vb_texture_Data) / sizeof(g_vb_texture_Data[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002640
2641
2642 ASSERT_NO_FATAL_FAILURE(InitState());
2643 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour8bef8ee2015-05-22 09:44:58 -06002644 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07002645
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002646 VkConstantBufferObj meshBuffer(m_device, num_verts,
2647 sizeof(g_vb_texture_Data[0]), g_vb_texture_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002648 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002649
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002650 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07002651
Tony Barbour01999182015-04-09 12:58:51 -06002652 VkConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2653 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2654 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2655 VkSamplerObj sampler(m_device);
2656 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002657
Tony Barbour01999182015-04-09 12:58:51 -06002658 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002659 pipelineobj.AddShader(&vs);
2660 pipelineobj.AddShader(&ps);
2661
Tony Barbour01999182015-04-09 12:58:51 -06002662 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002663 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mvpBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002664 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002665
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002666#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002667 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002668 MESH_BIND_ID, // binding ID
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002669 sizeof(g_vb_texture_Data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002670 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002671 };
Tony Barbourf43b6982014-11-25 13:18:32 -07002672
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002673 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002674 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2675 vi_attribs[0].location = 0; // location
Tony Barbour8205d902015-04-16 15:59:00 -06002676 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002677 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2678 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2679 vi_attribs[1].location = 1; // location
2680 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
2681 vi_attribs[1].offsetInBytes = 16; // Offset of uv components
Tony Barbourf43b6982014-11-25 13:18:32 -07002682
Tony Barbourf43b6982014-11-25 13:18:32 -07002683 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002684 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2685 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07002686
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002687 VkPipelineDsStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002688 ds_state.depthTestEnable = VK_TRUE;
2689 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06002690 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002691 ds_state.depthBoundsEnable = VK_FALSE;
2692 ds_state.stencilTestEnable = VK_FALSE;
2693 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
2694 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
2695 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06002696 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
2697 ds_state.format = VK_FORMAT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002698 ds_state.front = ds_state.back;
2699 pipelineobj.SetDepthStencil(&ds_state);
2700
Tony Barbour17c6ab12015-03-27 17:03:18 -06002701 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour01999182015-04-09 12:58:51 -06002702 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002703 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002704
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002705 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002706
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002707 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002708
2709 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2710#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002711 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002712 pDSDumpDot((char*)"triTest2.dot");
2713#endif
2714 // render triangle
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002715 cmdBuffer.Draw(0, num_verts, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002716
2717 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002718 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002719 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002720
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002721 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002722 RotateTriangleVSUniform(Projection, View, Model, &mvpBuffer, &cmdBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002723}
Cody Northropd1ce7842014-12-09 11:17:01 -07002724
Tony Barbour01999182015-04-09 12:58:51 -06002725TEST_F(VkRenderTest, TriangleMixedSamplerUniformBlockBinding)
Cody Northropd1ce7842014-12-09 11:17:01 -07002726{
2727 // This test mixes binding slots of textures and buffers, ensuring
2728 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002729 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002730 // you can modify it to move the desired result around.
2731
2732 static const char *vertShaderText =
2733 "#version 140\n"
2734 "#extension GL_ARB_separate_shader_objects : enable\n"
2735 "#extension GL_ARB_shading_language_420pack : enable\n"
2736 "void main() {\n"
2737 " vec2 vertices[3];"
2738 " vertices[0] = vec2(-0.5, -0.5);\n"
2739 " vertices[1] = vec2( 0.5, -0.5);\n"
2740 " vertices[2] = vec2( 0.5, 0.5);\n"
2741 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2742 "}\n";
2743
2744 static const char *fragShaderText =
2745 "#version 430\n"
2746 "#extension GL_ARB_separate_shader_objects : enable\n"
2747 "#extension GL_ARB_shading_language_420pack : enable\n"
2748 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002749 "layout (binding = 3) uniform sampler2D surface1;\n"
2750 "layout (binding = 1) uniform sampler2D surface2;\n"
2751 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002752
Cody Northropa0410942014-12-09 13:59:39 -07002753
Chia-I Wuf8385062015-01-04 16:27:24 +08002754 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2755 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2756 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2757 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002758 "layout (location = 0) out vec4 outColor;\n"
2759 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002760 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002761 " outColor += white * vec4(0.00001);\n"
2762 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002763 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002764 "}\n";
2765 ASSERT_NO_FATAL_FAILURE(InitState());
2766 ASSERT_NO_FATAL_FAILURE(InitViewport());
2767
Tony Barbour01999182015-04-09 12:58:51 -06002768 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2769 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northropd1ce7842014-12-09 11:17:01 -07002770
Cody Northropd1ce7842014-12-09 11:17:01 -07002771 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2772 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2773 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2774 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2775
2776 const int redCount = sizeof(redVals) / sizeof(float);
2777 const int greenCount = sizeof(greenVals) / sizeof(float);
2778 const int blueCount = sizeof(blueVals) / sizeof(float);
2779 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2780
Tony Barbour01999182015-04-09 12:58:51 -06002781 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2782 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2783 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2784 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002785
Tony Barbour2f421a02015-04-01 16:38:10 -06002786 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002787 VkSamplerObj sampler0(m_device);
2788 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002789 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002790 VkSamplerObj sampler2(m_device);
2791 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002792 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002793 VkSamplerObj sampler4(m_device);
2794 VkTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropa0410942014-12-09 13:59:39 -07002795
2796 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2797 // TODO: Get back here ASAP and understand why.
Tony Barbour2f421a02015-04-01 16:38:10 -06002798 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06002799 VkSamplerObj sampler7(m_device);
2800 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropd1ce7842014-12-09 11:17:01 -07002801
Tony Barbour01999182015-04-09 12:58:51 -06002802 VkPipelineObj pipelineobj(m_device);
Cody Northropd1ce7842014-12-09 11:17:01 -07002803 pipelineobj.AddShader(&vs);
2804 pipelineobj.AddShader(&ps);
2805
Tony Barbour01999182015-04-09 12:58:51 -06002806 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002807 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2808 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2809 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2810 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002811 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002812 // swap blue and green
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002813 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2814 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2815 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002816
Tony Barbourdd4c9642015-01-09 12:55:14 -07002817 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002818 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002819 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002820
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002821 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002822
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002823 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002824
2825#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002826 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002827 pDSDumpDot((char*)"triTest2.dot");
2828#endif
2829 // render triangle
2830 cmdBuffer.Draw(0, 3, 0, 1);
2831
2832 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002833 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002834 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002835
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002836 RecordImages(m_renderTargets);
Cody Northropd1ce7842014-12-09 11:17:01 -07002837}
2838
Tony Barbour01999182015-04-09 12:58:51 -06002839TEST_F(VkRenderTest, TriangleMatchingSamplerUniformBlockBinding)
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002840{
2841 // This test matches binding slots of textures and buffers, requiring
2842 // the driver to give them distinct number spaces.
2843 // The expected result from this test is a red triangle, although
2844 // you can modify it to move the desired result around.
2845
2846 static const char *vertShaderText =
2847 "#version 140\n"
2848 "#extension GL_ARB_separate_shader_objects : enable\n"
2849 "#extension GL_ARB_shading_language_420pack : enable\n"
2850 "void main() {\n"
2851 " vec2 vertices[3];"
2852 " vertices[0] = vec2(-0.5, -0.5);\n"
2853 " vertices[1] = vec2( 0.5, -0.5);\n"
2854 " vertices[2] = vec2( 0.5, 0.5);\n"
2855 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2856 "}\n";
2857
2858 static const char *fragShaderText =
2859 "#version 430\n"
2860 "#extension GL_ARB_separate_shader_objects : enable\n"
2861 "#extension GL_ARB_shading_language_420pack : enable\n"
2862 "layout (binding = 0) uniform sampler2D surface0;\n"
2863 "layout (binding = 1) uniform sampler2D surface1;\n"
2864 "layout (binding = 2) uniform sampler2D surface2;\n"
2865 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002866 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2867 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2868 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2869 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002870 "layout (location = 0) out vec4 outColor;\n"
2871 "void main() {\n"
2872 " outColor = red;// * vec4(0.00001);\n"
2873 " outColor += white * vec4(0.00001);\n"
2874 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2875 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2876 "}\n";
2877 ASSERT_NO_FATAL_FAILURE(InitState());
2878 ASSERT_NO_FATAL_FAILURE(InitViewport());
2879
Tony Barbour01999182015-04-09 12:58:51 -06002880 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2881 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002882
2883 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2884 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2885 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2886 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2887
2888 const int redCount = sizeof(redVals) / sizeof(float);
2889 const int greenCount = sizeof(greenVals) / sizeof(float);
2890 const int blueCount = sizeof(blueVals) / sizeof(float);
2891 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2892
Tony Barbour01999182015-04-09 12:58:51 -06002893 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2894 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2895 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2896 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002897
Tony Barbour2f421a02015-04-01 16:38:10 -06002898 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002899 VkSamplerObj sampler0(m_device);
2900 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002901 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002902 VkSamplerObj sampler2(m_device);
2903 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002904 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002905 VkSamplerObj sampler4(m_device);
2906 VkTextureObj texture4(m_device, tex_colors); // Light Green
Tony Barbour2f421a02015-04-01 16:38:10 -06002907 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06002908 VkSamplerObj sampler7(m_device);
2909 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002910
Tony Barbour01999182015-04-09 12:58:51 -06002911 VkPipelineObj pipelineobj(m_device);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002912 pipelineobj.AddShader(&vs);
2913 pipelineobj.AddShader(&ps);
2914
Tony Barbour01999182015-04-09 12:58:51 -06002915 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002916 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2917 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2918 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2919 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002920 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2921 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2922 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2923 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002924
Tony Barbourdd4c9642015-01-09 12:55:14 -07002925 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002926 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002927 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002928
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002929 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002930
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002931 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002932
2933#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002934 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002935 pDSDumpDot((char*)"triTest2.dot");
2936#endif
2937 // render triangle
2938 cmdBuffer.Draw(0, 3, 0, 1);
2939
2940 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002941 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002942 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002943
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002944 RecordImages(m_renderTargets);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002945}
2946
Tony Barbour01999182015-04-09 12:58:51 -06002947TEST_F(VkRenderTest, TriangleUniformBufferLayout)
Cody Northrop02690bd2014-12-17 15:26:33 -07002948{
2949 // This test populates a buffer with a variety of different data
2950 // types, then reads them out with a shader.
2951 // The expected result from this test is a green triangle
2952
2953 static const char *vertShaderText =
2954 "#version 140\n"
2955 "#extension GL_ARB_separate_shader_objects : enable\n"
2956 "#extension GL_ARB_shading_language_420pack : enable\n"
2957 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2958 " vec4 fRed;\n"
2959 " vec4 fGreen;\n"
2960 " layout(row_major) mat4 worldToProj;\n"
2961 " layout(row_major) mat4 projToWorld;\n"
2962 " layout(row_major) mat4 worldToView;\n"
2963 " layout(row_major) mat4 viewToProj;\n"
2964 " layout(row_major) mat4 worldToShadow[4];\n"
2965 " float fZero;\n"
2966 " float fOne;\n"
2967 " float fTwo;\n"
2968 " float fThree;\n"
2969 " vec3 fZeroZeroZero;\n"
2970 " float fFour;\n"
2971 " vec3 fZeroZeroOne;\n"
2972 " float fFive;\n"
2973 " vec3 fZeroOneZero;\n"
2974 " float fSix;\n"
2975 " float fSeven;\n"
2976 " float fEight;\n"
2977 " float fNine;\n"
2978 " vec2 fZeroZero;\n"
2979 " vec2 fZeroOne;\n"
2980 " vec4 fBlue;\n"
2981 " vec2 fOneZero;\n"
2982 " vec2 fOneOne;\n"
2983 " vec3 fZeroOneOne;\n"
2984 " float fTen;\n"
2985 " float fEleven;\n"
2986 " float fTwelve;\n"
2987 " vec3 fOneZeroZero;\n"
2988 " vec4 uvOffsets[4];\n"
2989 "};\n"
2990 "layout (location = 0) out vec4 color;"
2991 "void main() {\n"
2992
2993 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2994 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2995 " \n"
2996
2997 // do some exact comparisons, even though we should
2998 // really have an epsilon involved.
2999 " vec4 outColor = right;\n"
3000 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3001 " outColor = wrong;\n"
3002 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3003 " outColor = wrong;\n"
3004 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3005 " outColor = wrong;\n"
3006
3007 " color = outColor;\n"
3008
3009 // generic position stuff
3010 " vec2 vertices;\n"
3011 " int vertexSelector = gl_VertexID;\n"
3012 " if (vertexSelector == 0)\n"
3013 " vertices = vec2(-0.5, -0.5);\n"
3014 " else if (vertexSelector == 1)\n"
3015 " vertices = vec2( 0.5, -0.5);\n"
3016 " else if (vertexSelector == 2)\n"
3017 " vertices = vec2( 0.5, 0.5);\n"
3018 " else\n"
3019 " vertices = vec2( 0.0, 0.0);\n"
3020 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3021 "}\n";
3022
3023 static const char *fragShaderText =
3024 "#version 140\n"
3025 "#extension GL_ARB_separate_shader_objects : enable\n"
3026 "#extension GL_ARB_shading_language_420pack : enable\n"
3027 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3028 " vec4 fRed;\n"
3029 " vec4 fGreen;\n"
3030 " layout(row_major) mat4 worldToProj;\n"
3031 " layout(row_major) mat4 projToWorld;\n"
3032 " layout(row_major) mat4 worldToView;\n"
3033 " layout(row_major) mat4 viewToProj;\n"
3034 " layout(row_major) mat4 worldToShadow[4];\n"
3035 " float fZero;\n"
3036 " float fOne;\n"
3037 " float fTwo;\n"
3038 " float fThree;\n"
3039 " vec3 fZeroZeroZero;\n"
3040 " float fFour;\n"
3041 " vec3 fZeroZeroOne;\n"
3042 " float fFive;\n"
3043 " vec3 fZeroOneZero;\n"
3044 " float fSix;\n"
3045 " float fSeven;\n"
3046 " float fEight;\n"
3047 " float fNine;\n"
3048 " vec2 fZeroZero;\n"
3049 " vec2 fZeroOne;\n"
3050 " vec4 fBlue;\n"
3051 " vec2 fOneZero;\n"
3052 " vec2 fOneOne;\n"
3053 " vec3 fZeroOneOne;\n"
3054 " float fTen;\n"
3055 " float fEleven;\n"
3056 " float fTwelve;\n"
3057 " vec3 fOneZeroZero;\n"
3058 " vec4 uvOffsets[4];\n"
3059 "};\n"
3060 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003061 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop02690bd2014-12-17 15:26:33 -07003062 "void main() {\n"
3063 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3064 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3065 " \n"
3066
3067 // start with VS value to ensure it passed
3068 " vec4 outColor = color;\n"
3069
3070 // do some exact comparisons, even though we should
3071 // really have an epsilon involved.
3072 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3073 " outColor = wrong;\n"
3074 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3075 " outColor = wrong;\n"
3076 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3077 " outColor = wrong;\n"
3078 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3079 " outColor = wrong;\n"
3080 " if (fTwo != 2.0)\n"
3081 " outColor = wrong;\n"
3082 " if (fOneOne != vec2(1.0, 1.0))\n"
3083 " outColor = wrong;\n"
3084 " if (fTen != 10.0)\n"
3085 " outColor = wrong;\n"
3086 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3087 " outColor = wrong;\n"
3088 " \n"
GregFd6ebdb32015-06-03 18:40:50 -06003089 " uFragColor = outColor;\n"
Cody Northrop02690bd2014-12-17 15:26:33 -07003090 "}\n";
3091
3092
3093 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3094 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3095 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3096 0.0, 1.0, 0.0, 1.0, // align
3097 0.0, 0.0, 1.0, 1.0, // align
3098 0.0, 0.0, 0.0, 1.0, // align
3099 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3100 0.0, 2.0, 0.0, 2.0, // align
3101 0.0, 0.0, 2.0, 2.0, // align
3102 0.0, 0.0, 0.0, 2.0, // align
3103 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3104 0.0, 3.0, 0.0, 3.0, // align
3105 0.0, 0.0, 3.0, 3.0, // align
3106 0.0, 0.0, 0.0, 3.0, // align
3107 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3108 0.0, 4.0, 0.0, 4.0, // align
3109 0.0, 0.0, 4.0, 4.0, // align
3110 0.0, 0.0, 0.0, 4.0, // align
3111 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3112 0.0, 5.0, 0.0, 5.0, // align
3113 0.0, 0.0, 5.0, 5.0, // align
3114 0.0, 0.0, 0.0, 5.0, // align
3115 6.0, 0.0, 0.0, 6.0, // align
3116 0.0, 6.0, 0.0, 6.0, // align
3117 0.0, 0.0, 6.0, 6.0, // align
3118 0.0, 0.0, 0.0, 6.0, // align
3119 7.0, 0.0, 0.0, 7.0, // align
3120 0.0, 7.0, 0.0, 7.0, // align
3121 0.0, 0.0, 7.0, 7.0, // align
3122 0.0, 0.0, 0.0, 7.0, // align
3123 8.0, 0.0, 0.0, 8.0, // align
3124 0.0, 8.0, 0.0, 8.0, // align
3125 0.0, 0.0, 8.0, 8.0, // align
3126 0.0, 0.0, 0.0, 8.0, // align
3127 0.0, // float fZero; // align
3128 1.0, // float fOne; // pack
3129 2.0, // float fTwo; // pack
3130 3.0, // float fThree; // pack
3131 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3132 4.0, // float fFour; // pack
3133 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3134 5.0, // float fFive; // pack
3135 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3136 6.0, // float fSix; // pack
3137 7.0, // float fSeven; // align
3138 8.0, // float fEight; // pack
3139 9.0, // float fNine; // pack
3140 0.0, // BUFFER
3141 0.0, 0.0, // vec2 fZeroZero; // align
3142 0.0, 1.0, // vec2 fZeroOne; // pack
3143 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3144 1.0, 0.0, // vec2 fOneZero; // align
3145 1.0, 1.0, // vec2 fOneOne; // pack
3146 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3147 10.0, // float fTen; // pack
3148 11.0, // float fEleven; // align
3149 12.0, // float fTwelve; // pack
3150 0.0, 0.0, // BUFFER
3151 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3152 0.0, // BUFFER
3153 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3154 0.5, 0.6, 0.7, 0.8, // align
3155 0.9, 1.0, 1.1, 1.2, // align
3156 1.3, 1.4, 1.5, 1.6, // align
3157 };
3158
3159 ASSERT_NO_FATAL_FAILURE(InitState());
3160 ASSERT_NO_FATAL_FAILURE(InitViewport());
3161
3162 const int constCount = sizeof(mixedVals) / sizeof(float);
3163
Tony Barbour01999182015-04-09 12:58:51 -06003164 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3165 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop02690bd2014-12-17 15:26:33 -07003166
Tony Barbour01999182015-04-09 12:58:51 -06003167 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003168
Tony Barbour01999182015-04-09 12:58:51 -06003169 VkPipelineObj pipelineobj(m_device);
Cody Northrop02690bd2014-12-17 15:26:33 -07003170 pipelineobj.AddShader(&vs);
3171 pipelineobj.AddShader(&ps);
3172
Tony Barbour01999182015-04-09 12:58:51 -06003173 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003174 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003175
3176 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06003177 VkCommandBufferObj cmdBuffer(m_device);
Cody Northrop02690bd2014-12-17 15:26:33 -07003178 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3179
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003180 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Cody Northrop02690bd2014-12-17 15:26:33 -07003181
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003182 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Cody Northrop02690bd2014-12-17 15:26:33 -07003183
3184#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003185 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop02690bd2014-12-17 15:26:33 -07003186 pDSDumpDot((char*)"triTest2.dot");
3187#endif
3188 // render triangle
3189 cmdBuffer.Draw(0, 3, 0, 1);
3190
3191 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003192 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003193 cmdBuffer.QueueCommandBuffer();
Cody Northrop02690bd2014-12-17 15:26:33 -07003194
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003195 RecordImages(m_renderTargets);
Cody Northrop02690bd2014-12-17 15:26:33 -07003196}
3197
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003198TEST_F(VkRenderTest, TextureGather)
3199{
3200 // This test introduces textureGather and textureGatherOffset
3201 // Each call is compared against an expected inline color result
3202 // Green triangle means everything worked as expected
3203 // Red means something went wrong
3204
3205 // disable SPV until texture gather is turned on in LunarGLASS
Cody Northrop1cfbd172015-06-03 16:49:20 -06003206 ScopedUseGlsl useGlsl(true);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003207
3208 static const char *vertShaderText =
3209 "#version 140\n"
3210 "#extension GL_ARB_separate_shader_objects : enable\n"
3211 "#extension GL_ARB_shading_language_420pack : enable\n"
3212 "void main() {\n"
3213 " vec2 vertices[3];"
3214 " vertices[0] = vec2(-0.5, -0.5);\n"
3215 " vertices[1] = vec2( 0.5, -0.5);\n"
3216 " vertices[2] = vec2( 0.5, 0.5);\n"
3217 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
3218 "}\n";
3219
3220 static const char *fragShaderText =
3221 "#version 430\n"
3222 "#extension GL_ARB_separate_shader_objects : enable\n"
3223 "#extension GL_ARB_shading_language_420pack : enable\n"
3224 "layout (binding = 0) uniform sampler2D surface0;\n"
3225 "layout (binding = 1) uniform sampler2D surface1;\n"
3226 "layout (binding = 2) uniform sampler2D surface2;\n"
3227 "layout (binding = 3) uniform sampler2D surface3;\n"
3228 "layout (location = 0) out vec4 outColor;\n"
3229 "void main() {\n"
3230
3231 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3232 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3233
3234 " vec4 color = right;\n"
3235
3236 // Grab a normal texture sample to ensure it can work in conjuntion
3237 // with textureGather (there are some intracacies in the backend)
3238 " vec4 sampledColor = textureLod(surface2, vec2(0.5), 0.0);\n"
3239 " if (sampledColor != vec4(0.0, 0.0, 1.0, 1.0))\n"
3240 " color = wrong;\n"
3241
3242 " vec4 gatheredColor = textureGather(surface0, vec2(0.5), 0);\n"
3243 // This just grabbed four red components from a red surface
3244 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3245 " color = wrong;\n"
3246
3247 // Yes, this is using an offset of 0, we don't have enough fine grained
3248 // control of the texture contents here.
3249 " gatheredColor = textureGatherOffset(surface1, vec2(0.5), ivec2(0, 0), 1);\n"
3250 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3251 " color = wrong;\n"
3252
3253 " outColor = color;\n"
3254
3255 "}\n";
3256
3257 ASSERT_NO_FATAL_FAILURE(InitState());
3258 ASSERT_NO_FATAL_FAILURE(InitViewport());
3259
3260 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3261 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3262
3263 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
3264 VkSamplerObj sampler0(m_device);
3265 VkTextureObj texture0(m_device, tex_colors); // Red
3266 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
3267 VkSamplerObj sampler1(m_device);
3268 VkTextureObj texture1(m_device, tex_colors); // Green
3269 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
3270 VkSamplerObj sampler2(m_device);
3271 VkTextureObj texture2(m_device, tex_colors); // Blue
3272 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
3273 VkSamplerObj sampler3(m_device);
3274 VkTextureObj texture3(m_device, tex_colors); // Red and Blue
3275
3276 VkPipelineObj pipelineobj(m_device);
3277 pipelineobj.AddShader(&vs);
3278 pipelineobj.AddShader(&ps);
3279
3280 VkDescriptorSetObj descriptorSet(m_device);
3281 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3282 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
3283 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3284 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
3285
3286 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3287 VkCommandBufferObj cmdBuffer(m_device);
3288 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3289
3290 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3291
3292 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3293
3294 // render triangle
3295 cmdBuffer.Draw(0, 3, 0, 1);
3296
3297 // finalize recording of the command buffer
3298 EndCommandBuffer(cmdBuffer);
3299 cmdBuffer.QueueCommandBuffer();
3300
3301 RecordImages(m_renderTargets);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003302}
3303
Cody Northropa44c2ff2015-04-15 11:19:06 -06003304TEST_F(VkRenderTest, GeometryShaderHelloWorld)
3305{
3306 // This test introduces a geometry shader that simply
3307 // changes the color of each vertex to red, green, blue
3308
3309 static const char *vertShaderText =
3310 "#version 140\n"
3311 "#extension GL_ARB_separate_shader_objects : enable\n"
3312 "#extension GL_ARB_shading_language_420pack : enable\n"
3313 "layout (location = 0) out vec4 color;"
3314 "void main() {\n"
3315
3316 // VS writes out red
3317 " color = vec4(1.0, 0.0, 0.0, 1.0);\n"
3318
3319 // generic position stuff
3320 " vec2 vertices;\n"
3321 " int vertexSelector = gl_VertexID;\n"
3322 " if (vertexSelector == 0)\n"
3323 " vertices = vec2(-0.5, -0.5);\n"
3324 " else if (vertexSelector == 1)\n"
3325 " vertices = vec2( 0.5, -0.5);\n"
3326 " else if (vertexSelector == 2)\n"
3327 " vertices = vec2( 0.5, 0.5);\n"
3328 " else\n"
3329 " vertices = vec2( 0.0, 0.0);\n"
3330 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3331
3332 "}\n";
3333
3334 static const char *geomShaderText =
3335 "#version 330\n"
3336 "#extension GL_ARB_separate_shader_objects : enable\n"
3337 "#extension GL_ARB_shading_language_420pack : enable\n"
3338 "layout( triangles ) in;\n"
3339 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3340 "layout( location = 0 ) in vec4 inColor[3];\n"
3341 "layout( location = 0 ) out vec4 outColor;\n"
3342 "void main()\n"
3343 "{\n"
3344
3345 // first vertex, pass through red
3346 " gl_Position = gl_in[0].gl_Position;\n"
3347 " outColor = inColor[0];\n"
3348 " EmitVertex();\n"
3349
3350 // second vertex, green
3351 " gl_Position = gl_in[1].gl_Position;\n"
3352 " outColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3353 " EmitVertex();\n"
3354
3355 // third vertex, blue
3356 " gl_Position = gl_in[2].gl_Position;\n"
3357 " outColor = vec4(0.0, 0.0, 1.0, 1.0);\n"
3358 " EmitVertex();\n"
3359
3360 // done
3361 " EndPrimitive();\n"
3362 "}\n";
3363
3364
3365 static const char *fragShaderText =
3366 "#version 140\n"
3367 "#extension GL_ARB_separate_shader_objects : enable\n"
3368 "#extension GL_ARB_shading_language_420pack : enable\n"
3369 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003370 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003371 "void main() {\n"
3372 // pass through
GregFd6ebdb32015-06-03 18:40:50 -06003373 " outColor = color;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003374 "}\n";
3375
3376
3377
3378 ASSERT_NO_FATAL_FAILURE(InitState());
3379 ASSERT_NO_FATAL_FAILURE(InitViewport());
3380
3381 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3382 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3383 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3384
3385 VkPipelineObj pipelineobj(m_device);
3386 pipelineobj.AddShader(&vs);
3387 pipelineobj.AddShader(&gs);
3388 pipelineobj.AddShader(&ps);
3389
3390 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3391 VkCommandBufferObj cmdBuffer(m_device);
3392 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3393
3394 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3395
3396 VkDescriptorSetObj descriptorSet(m_device);
3397
3398 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3399
3400 // render triangle
3401 cmdBuffer.Draw(0, 3, 0, 1);
3402
3403 // finalize recording of the command buffer
3404 EndCommandBuffer(cmdBuffer);
3405 cmdBuffer.QueueCommandBuffer();
3406
3407 RecordImages(m_renderTargets);
3408}
3409
3410TEST_F(VkRenderTest, GSUniformBufferLayout)
3411{
3412 // This test is just like TriangleUniformBufferLayout but adds
3413 // geometry as a stage that also does UBO lookups
3414 // The expected result from this test is a green triangle
3415
3416 static const char *vertShaderText =
3417 "#version 140\n"
3418 "#extension GL_ARB_separate_shader_objects : enable\n"
3419 "#extension GL_ARB_shading_language_420pack : enable\n"
3420 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3421 " vec4 fRed;\n"
3422 " vec4 fGreen;\n"
3423 " layout(row_major) mat4 worldToProj;\n"
3424 " layout(row_major) mat4 projToWorld;\n"
3425 " layout(row_major) mat4 worldToView;\n"
3426 " layout(row_major) mat4 viewToProj;\n"
3427 " layout(row_major) mat4 worldToShadow[4];\n"
3428 " float fZero;\n"
3429 " float fOne;\n"
3430 " float fTwo;\n"
3431 " float fThree;\n"
3432 " vec3 fZeroZeroZero;\n"
3433 " float fFour;\n"
3434 " vec3 fZeroZeroOne;\n"
3435 " float fFive;\n"
3436 " vec3 fZeroOneZero;\n"
3437 " float fSix;\n"
3438 " float fSeven;\n"
3439 " float fEight;\n"
3440 " float fNine;\n"
3441 " vec2 fZeroZero;\n"
3442 " vec2 fZeroOne;\n"
3443 " vec4 fBlue;\n"
3444 " vec2 fOneZero;\n"
3445 " vec2 fOneOne;\n"
3446 " vec3 fZeroOneOne;\n"
3447 " float fTen;\n"
3448 " float fEleven;\n"
3449 " float fTwelve;\n"
3450 " vec3 fOneZeroZero;\n"
3451 " vec4 uvOffsets[4];\n"
3452 "};\n"
3453 "layout (location = 0) out vec4 color;"
3454 "void main() {\n"
3455
3456 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3457 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3458 " \n"
3459
3460 // do some exact comparisons, even though we should
3461 // really have an epsilon involved.
3462 " vec4 outColor = right;\n"
3463 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3464 " outColor = wrong;\n"
3465 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3466 " outColor = wrong;\n"
3467 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3468 " outColor = wrong;\n"
3469
3470 " color = outColor;\n"
3471
3472 // generic position stuff
3473 " vec2 vertices;\n"
3474 " int vertexSelector = gl_VertexID;\n"
3475 " if (vertexSelector == 0)\n"
3476 " vertices = vec2(-0.5, -0.5);\n"
3477 " else if (vertexSelector == 1)\n"
3478 " vertices = vec2( 0.5, -0.5);\n"
3479 " else if (vertexSelector == 2)\n"
3480 " vertices = vec2( 0.5, 0.5);\n"
3481 " else\n"
3482 " vertices = vec2( 0.0, 0.0);\n"
3483 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3484 "}\n";
3485
3486 static const char *geomShaderText =
3487 "#version 330\n"
3488 "#extension GL_ARB_separate_shader_objects : enable\n"
3489 "#extension GL_ARB_shading_language_420pack : enable\n"
3490
3491 // GS layout stuff
3492 "layout( triangles ) in;\n"
3493 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3494
3495 // Between stage IO
3496 "layout( location = 0 ) in vec4 inColor[3];\n"
3497 "layout( location = 0 ) out vec4 color;\n"
3498
3499 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3500 " vec4 fRed;\n"
3501 " vec4 fGreen;\n"
3502 " layout(row_major) mat4 worldToProj;\n"
3503 " layout(row_major) mat4 projToWorld;\n"
3504 " layout(row_major) mat4 worldToView;\n"
3505 " layout(row_major) mat4 viewToProj;\n"
3506 " layout(row_major) mat4 worldToShadow[4];\n"
3507 " float fZero;\n"
3508 " float fOne;\n"
3509 " float fTwo;\n"
3510 " float fThree;\n"
3511 " vec3 fZeroZeroZero;\n"
3512 " float fFour;\n"
3513 " vec3 fZeroZeroOne;\n"
3514 " float fFive;\n"
3515 " vec3 fZeroOneZero;\n"
3516 " float fSix;\n"
3517 " float fSeven;\n"
3518 " float fEight;\n"
3519 " float fNine;\n"
3520 " vec2 fZeroZero;\n"
3521 " vec2 fZeroOne;\n"
3522 " vec4 fBlue;\n"
3523 " vec2 fOneZero;\n"
3524 " vec2 fOneOne;\n"
3525 " vec3 fZeroOneOne;\n"
3526 " float fTen;\n"
3527 " float fEleven;\n"
3528 " float fTwelve;\n"
3529 " vec3 fOneZeroZero;\n"
3530 " vec4 uvOffsets[4];\n"
3531 "};\n"
3532
3533 "void main()\n"
3534 "{\n"
3535
3536 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3537 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3538
3539 // Each vertex will validate it can read VS output
3540 // then check a few values from the UBO
3541
3542 // first vertex
3543 " vec4 outColor = inColor[0];\n"
3544
3545 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3546 " outColor = wrong;\n"
3547 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3548 " outColor = wrong;\n"
3549 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3550 " outColor = wrong;\n"
3551 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3552 " outColor = wrong;\n"
3553
3554 " gl_Position = gl_in[0].gl_Position;\n"
3555 " color = outColor;\n"
3556 " EmitVertex();\n"
3557
3558 // second vertex
3559 " outColor = inColor[1];\n"
3560
3561 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3562 " outColor = wrong;\n"
3563 " if (fSix != 6.0)\n"
3564 " outColor = wrong;\n"
3565 " if (fOneOne != vec2(1.0, 1.0))\n"
3566 " outColor = wrong;\n"
3567
3568 " gl_Position = gl_in[1].gl_Position;\n"
3569 " color = outColor;\n"
3570 " EmitVertex();\n"
3571
3572 // third vertex
3573 " outColor = inColor[2];\n"
3574
3575 " if (fSeven != 7.0)\n"
3576 " outColor = wrong;\n"
3577 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3578 " outColor = wrong;\n"
3579
3580 " gl_Position = gl_in[2].gl_Position;\n"
3581 " color = outColor;\n"
3582 " EmitVertex();\n"
3583
3584 // done
3585 " EndPrimitive();\n"
3586 "}\n";
3587
3588 static const char *fragShaderText =
3589 "#version 140\n"
3590 "#extension GL_ARB_separate_shader_objects : enable\n"
3591 "#extension GL_ARB_shading_language_420pack : enable\n"
3592 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3593 " vec4 fRed;\n"
3594 " vec4 fGreen;\n"
3595 " layout(row_major) mat4 worldToProj;\n"
3596 " layout(row_major) mat4 projToWorld;\n"
3597 " layout(row_major) mat4 worldToView;\n"
3598 " layout(row_major) mat4 viewToProj;\n"
3599 " layout(row_major) mat4 worldToShadow[4];\n"
3600 " float fZero;\n"
3601 " float fOne;\n"
3602 " float fTwo;\n"
3603 " float fThree;\n"
3604 " vec3 fZeroZeroZero;\n"
3605 " float fFour;\n"
3606 " vec3 fZeroZeroOne;\n"
3607 " float fFive;\n"
3608 " vec3 fZeroOneZero;\n"
3609 " float fSix;\n"
3610 " float fSeven;\n"
3611 " float fEight;\n"
3612 " float fNine;\n"
3613 " vec2 fZeroZero;\n"
3614 " vec2 fZeroOne;\n"
3615 " vec4 fBlue;\n"
3616 " vec2 fOneZero;\n"
3617 " vec2 fOneOne;\n"
3618 " vec3 fZeroOneOne;\n"
3619 " float fTen;\n"
3620 " float fEleven;\n"
3621 " float fTwelve;\n"
3622 " vec3 fOneZeroZero;\n"
3623 " vec4 uvOffsets[4];\n"
3624 "};\n"
3625 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003626 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003627 "void main() {\n"
3628 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3629 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3630 " \n"
3631
3632 // start with GS value to ensure it passed
3633 " vec4 outColor = color;\n"
3634
3635 // do some exact comparisons, even though we should
3636 // really have an epsilon involved.
3637 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3638 " outColor = wrong;\n"
3639 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3640 " outColor = wrong;\n"
3641 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3642 " outColor = wrong;\n"
3643 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3644 " outColor = wrong;\n"
3645 " if (fTwo != 2.0)\n"
3646 " outColor = wrong;\n"
3647 " if (fOneOne != vec2(1.0, 1.0))\n"
3648 " outColor = wrong;\n"
3649 " if (fTen != 10.0)\n"
3650 " outColor = wrong;\n"
3651 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3652 " outColor = wrong;\n"
3653 " \n"
GregFd6ebdb32015-06-03 18:40:50 -06003654 " uFragColor = outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003655 "}\n";
3656
3657
3658 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3659 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3660 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3661 0.0, 1.0, 0.0, 1.0, // align
3662 0.0, 0.0, 1.0, 1.0, // align
3663 0.0, 0.0, 0.0, 1.0, // align
3664 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3665 0.0, 2.0, 0.0, 2.0, // align
3666 0.0, 0.0, 2.0, 2.0, // align
3667 0.0, 0.0, 0.0, 2.0, // align
3668 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3669 0.0, 3.0, 0.0, 3.0, // align
3670 0.0, 0.0, 3.0, 3.0, // align
3671 0.0, 0.0, 0.0, 3.0, // align
3672 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3673 0.0, 4.0, 0.0, 4.0, // align
3674 0.0, 0.0, 4.0, 4.0, // align
3675 0.0, 0.0, 0.0, 4.0, // align
3676 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3677 0.0, 5.0, 0.0, 5.0, // align
3678 0.0, 0.0, 5.0, 5.0, // align
3679 0.0, 0.0, 0.0, 5.0, // align
3680 6.0, 0.0, 0.0, 6.0, // align
3681 0.0, 6.0, 0.0, 6.0, // align
3682 0.0, 0.0, 6.0, 6.0, // align
3683 0.0, 0.0, 0.0, 6.0, // align
3684 7.0, 0.0, 0.0, 7.0, // align
3685 0.0, 7.0, 0.0, 7.0, // align
3686 0.0, 0.0, 7.0, 7.0, // align
3687 0.0, 0.0, 0.0, 7.0, // align
3688 8.0, 0.0, 0.0, 8.0, // align
3689 0.0, 8.0, 0.0, 8.0, // align
3690 0.0, 0.0, 8.0, 8.0, // align
3691 0.0, 0.0, 0.0, 8.0, // align
3692 0.0, // float fZero; // align
3693 1.0, // float fOne; // pack
3694 2.0, // float fTwo; // pack
3695 3.0, // float fThree; // pack
3696 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3697 4.0, // float fFour; // pack
3698 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3699 5.0, // float fFive; // pack
3700 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3701 6.0, // float fSix; // pack
3702 7.0, // float fSeven; // align
3703 8.0, // float fEight; // pack
3704 9.0, // float fNine; // pack
3705 0.0, // BUFFER
3706 0.0, 0.0, // vec2 fZeroZero; // align
3707 0.0, 1.0, // vec2 fZeroOne; // pack
3708 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3709 1.0, 0.0, // vec2 fOneZero; // align
3710 1.0, 1.0, // vec2 fOneOne; // pack
3711 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3712 10.0, // float fTen; // pack
3713 11.0, // float fEleven; // align
3714 12.0, // float fTwelve; // pack
3715 0.0, 0.0, // BUFFER
3716 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3717 0.0, // BUFFER
3718 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3719 0.5, 0.6, 0.7, 0.8, // align
3720 0.9, 1.0, 1.1, 1.2, // align
3721 1.3, 1.4, 1.5, 1.6, // align
3722 };
3723
3724
3725
3726 ASSERT_NO_FATAL_FAILURE(InitState());
3727 ASSERT_NO_FATAL_FAILURE(InitViewport());
3728
3729 const int constCount = sizeof(mixedVals) / sizeof(float);
3730
3731 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3732 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3733 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3734
3735 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
3736
3737 VkPipelineObj pipelineobj(m_device);
3738 pipelineobj.AddShader(&vs);
3739 pipelineobj.AddShader(&gs);
3740 pipelineobj.AddShader(&ps);
3741
3742 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3743 VkCommandBufferObj cmdBuffer(m_device);
3744 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3745
3746 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3747
3748 VkDescriptorSetObj descriptorSet(m_device);
3749 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
3750
3751 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3752
3753 // render triangle
3754 cmdBuffer.Draw(0, 3, 0, 1);
3755
3756 // finalize recording of the command buffer
3757 EndCommandBuffer(cmdBuffer);
3758 cmdBuffer.QueueCommandBuffer();
3759
3760 RecordImages(m_renderTargets);
3761}
3762
3763TEST_F(VkRenderTest, GSPositions)
3764{
3765 // This test adds more inputs from the vertex shader and perturbs positions
3766 // Expected result is white triangle with weird positions
3767
3768 static const char *vertShaderText =
3769 "#version 140\n"
3770 "#extension GL_ARB_separate_shader_objects : enable\n"
3771 "#extension GL_ARB_shading_language_420pack : enable\n"
3772
3773 "layout(location = 0) out vec3 out_a;\n"
3774 "layout(location = 1) out vec3 out_b;\n"
3775 "layout(location = 2) out vec3 out_c;\n"
3776
3777 "void main() {\n"
3778
3779 // write a solid color to each
3780 " out_a = vec3(1.0, 0.0, 0.0);\n"
3781 " out_b = vec3(0.0, 1.0, 0.0);\n"
3782 " out_c = vec3(0.0, 0.0, 1.0);\n"
3783
3784 // generic position stuff
3785 " vec2 vertices;\n"
3786 " int vertexSelector = gl_VertexID;\n"
3787 " if (vertexSelector == 0)\n"
3788 " vertices = vec2(-0.5, -0.5);\n"
3789 " else if (vertexSelector == 1)\n"
3790 " vertices = vec2( 0.5, -0.5);\n"
3791 " else if (vertexSelector == 2)\n"
3792 " vertices = vec2( 0.5, 0.5);\n"
3793 " else\n"
3794 " vertices = vec2( 0.0, 0.0);\n"
3795 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3796
3797 "}\n";
3798
3799 static const char *geomShaderText =
3800 "#version 330\n"
3801 "#extension GL_ARB_separate_shader_objects : enable\n"
3802 "#extension GL_ARB_shading_language_420pack : enable\n"
3803 "layout( triangles ) in;\n"
3804 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3805
3806 "layout(location = 0) in vec3 in_a[3];\n"
3807 "layout(location = 1) in vec3 in_b[3];\n"
3808 "layout(location = 2) in vec3 in_c[3];\n"
3809
3810 "layout(location = 0) out vec3 out_a;\n"
3811 "layout(location = 1) out vec3 out_b;\n"
3812 "layout(location = 2) out vec3 out_c;\n"
3813
3814 "void main()\n"
3815 "{\n"
3816
3817 " gl_Position = gl_in[0].gl_Position;\n"
3818 " gl_Position.xy *= vec2(0.75);\n"
3819 " out_a = in_a[0];\n"
3820 " out_b = in_b[0];\n"
3821 " out_c = in_c[0];\n"
3822 " EmitVertex();\n"
3823
3824 " gl_Position = gl_in[1].gl_Position;\n"
3825 " gl_Position.xy *= vec2(1.5);\n"
3826 " out_a = in_a[1];\n"
3827 " out_b = in_b[1];\n"
3828 " out_c = in_c[1];\n"
3829 " EmitVertex();\n"
3830
3831 " gl_Position = gl_in[2].gl_Position;\n"
3832 " gl_Position.xy *= vec2(-0.1);\n"
3833 " out_a = in_a[2];\n"
3834 " out_b = in_b[2];\n"
3835 " out_c = in_c[2];\n"
3836 " EmitVertex();\n"
3837
3838 " EndPrimitive();\n"
3839 "}\n";
3840
3841
3842 static const char *fragShaderText =
3843 "#version 140\n"
3844 "#extension GL_ARB_separate_shader_objects : enable\n"
3845 "#extension GL_ARB_shading_language_420pack : enable\n"
3846
3847 "layout(location = 0) in vec3 in_a;\n"
3848 "layout(location = 1) in vec3 in_b;\n"
3849 "layout(location = 2) in vec3 in_c;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003850 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003851
3852 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06003853 " outColor = vec4(in_a.x, in_b.y, in_c.z, 1.0);\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003854 "}\n";
3855
3856
3857
3858 ASSERT_NO_FATAL_FAILURE(InitState());
3859 ASSERT_NO_FATAL_FAILURE(InitViewport());
3860
3861 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3862 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3863 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3864
3865 VkPipelineObj pipelineobj(m_device);
3866 pipelineobj.AddShader(&vs);
3867 pipelineobj.AddShader(&gs);
3868 pipelineobj.AddShader(&ps);
3869
3870 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3871 VkCommandBufferObj cmdBuffer(m_device);
3872 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3873
3874 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3875
3876 VkDescriptorSetObj descriptorSet(m_device);
3877
3878 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3879
3880 // render triangle
3881 cmdBuffer.Draw(0, 3, 0, 1);
3882
3883 // finalize recording of the command buffer
3884 EndCommandBuffer(cmdBuffer);
3885 cmdBuffer.QueueCommandBuffer();
3886
3887 RecordImages(m_renderTargets);
3888}
3889
3890TEST_F(VkRenderTest, GSTriStrip)
3891{
3892 // This test emits multiple multiple triangles using a GS
3893 // Correct result is an multicolor circle
3894
3895 static const char *vertShaderText =
3896 "#version 140\n"
3897 "#extension GL_ARB_separate_shader_objects : enable\n"
3898 "#extension GL_ARB_shading_language_420pack : enable\n"
3899
3900 "void main() {\n"
3901
3902 // generic position stuff
3903 " vec2 vertices;\n"
3904 " int vertexSelector = gl_VertexID;\n"
3905 " if (vertexSelector == 0)\n"
3906 " vertices = vec2(-0.5, -0.5);\n"
3907 " else if (vertexSelector == 1)\n"
3908 " vertices = vec2( 0.5, -0.5);\n"
3909 " else if (vertexSelector == 2)\n"
3910 " vertices = vec2( 0.5, 0.5);\n"
3911 " else\n"
3912 " vertices = vec2( 0.0, 0.0);\n"
3913 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3914
3915 "}\n";
3916
3917 static const char *geomShaderText =
3918 "#version 330\n"
3919 "#extension GL_ARB_separate_shader_objects : enable\n"
3920 "#extension GL_ARB_shading_language_420pack : enable\n"
3921 "layout( triangles ) in;\n"
3922 "layout( triangle_strip, max_vertices = 18 ) out;\n"
3923
3924 "layout(location = 0) out vec4 outColor;\n"
3925
3926 "void main()\n"
3927 "{\n"
3928 // init with first position to get zw
3929 " gl_Position = gl_in[0].gl_Position;\n"
3930
3931 " vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3932 " vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
3933 " vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
3934 " vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
3935
3936 // different color per tri
3937 " vec4[6] colors = { red, white, \n"
3938 " yellow, white, \n"
3939 " blue, white }; \n"
3940
3941 // fan out the triangles
3942 " vec2[18] positions = { vec2(0.0, 0.0), vec2(-0.5, 0.0), vec2(-0.25, -0.5), \n"
3943 " vec2(0.0, 0.0), vec2(-0.25, -0.5), vec2( 0.25, -0.5), \n"
3944 " vec2(0.0, 0.0), vec2( 0.25, -0.5), vec2( 0.5, 0.0), \n"
3945 " vec2(0.0, 0.0), vec2( 0.5, 0.0), vec2( 0.25, 0.5), \n"
3946 " vec2(0.0, 0.0), vec2( 0.25, 0.5), vec2(-0.25, 0.5), \n"
3947 " vec2(0.0, 0.0), vec2(-0.25, 0.5), vec2(-0.5, 0.0) }; \n"
3948
3949 // make a triangle list of 6
3950 " for (int i = 0; i < 6; ++i) { \n"
3951 " outColor = colors[i]; \n"
3952 " for (int j = 0; j < 3; ++j) { \n"
3953 " gl_Position.xy = positions[i * 3 + j]; \n"
3954 " EmitVertex(); \n"
3955 " } \n"
3956 " EndPrimitive();\n"
3957 " } \n"
3958
3959 "}\n";
3960
3961
3962 static const char *fragShaderText =
3963 "#version 150\n"
3964 "#extension GL_ARB_separate_shader_objects : enable\n"
3965 "#extension GL_ARB_shading_language_420pack : enable\n"
3966
3967
3968 "layout(binding = 0) uniform windowDimensions {\n"
3969 " vec4 dimensions;\n"
3970 "};\n"
3971
3972 "layout(location = 0) in vec4 inColor;\n"
3973 "layout(origin_upper_left) in vec4 gl_FragCoord;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003974 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003975
3976 "void main() {\n"
3977
3978 // discard to make a nice circle
3979 " vec2 pos = abs(gl_FragCoord.xy) - vec2(dimensions.x, dimensions.y) / 2;\n"
3980 " float dist = sqrt(dot(pos, pos));\n"
3981 " if (dist > 50.0)\n"
3982 " discard;\n"
3983
GregFd6ebdb32015-06-03 18:40:50 -06003984 " outColor = inColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003985
3986 "}\n";
3987
3988
3989
3990 ASSERT_NO_FATAL_FAILURE(InitState());
3991 ASSERT_NO_FATAL_FAILURE(InitViewport());
3992
3993 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3994 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3995 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3996
3997 VkPipelineObj pipelineobj(m_device);
3998 pipelineobj.AddShader(&vs);
3999 pipelineobj.AddShader(&gs);
4000 pipelineobj.AddShader(&ps);
4001
4002 const float dimensions[4] = { VkRenderFramework::m_width, VkRenderFramework::m_height , 0.0, 0.0};
4003
4004 VkConstantBufferObj windowDimensions(m_device, sizeof(dimensions) / sizeof(dimensions[0]), sizeof(dimensions[0]), (const void*) dimensions);
4005
4006 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4007 VkCommandBufferObj cmdBuffer(m_device);
4008 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
4009
4010 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
4011
4012 VkDescriptorSetObj descriptorSet(m_device);
4013 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, windowDimensions);
4014
4015 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
4016
4017 // render triangle
4018 cmdBuffer.Draw(0, 3, 0, 1);
4019
4020 // finalize recording of the command buffer
4021 EndCommandBuffer(cmdBuffer);
4022 cmdBuffer.QueueCommandBuffer();
4023
4024 RecordImages(m_renderTargets);
4025}
4026
Chris Forbes23e6db62015-06-15 09:32:35 +12004027TEST_F(VkRenderTest, RenderPassLoadOpClear)
4028{
4029 ASSERT_NO_FATAL_FAILURE(InitState());
4030 ASSERT_NO_FATAL_FAILURE(InitViewport());
4031
4032 /* clear via load op to full green */
4033 m_clear_via_load_op = true;
4034 m_clear_color.useRawValue = false;
4035 m_clear_color.color.floatColor[0] = 0;
4036 m_clear_color.color.floatColor[1] = 1;
4037 m_clear_color.color.floatColor[2] = 0;
4038 m_clear_color.color.floatColor[3] = 0;
4039 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4040
4041 VkCommandBufferObj cmdBuffer(m_device);
4042 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
4043 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
4044 /* This command buffer contains ONLY the load op! */
4045 EndCommandBuffer(cmdBuffer);
4046 cmdBuffer.QueueCommandBuffer();
4047
4048 RecordImages(m_renderTargets);
4049}
4050
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004051int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004052 int result;
4053
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004054 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06004055 VkTestFramework::InitArgs(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004056
Chia-I Wu7133fdc2014-12-15 23:57:34 +08004057 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06004058
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004059 result = RUN_ALL_TESTS();
4060
Tony Barbour01999182015-04-09 12:58:51 -06004061 VkTestFramework::Finish();
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004062 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004063}