blob: 03d27b3ea563b05efeaa665cd92e568608464502 [file] [log] [blame]
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06001// Copyright 2005, Google Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14// * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060031// VK tests
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060032//
33// Copyright (C) 2014 LunarG, Inc.
34//
35// Permission is hereby granted, free of charge, to any person obtaining a
36// copy of this software and associated documentation files (the "Software"),
37// to deal in the Software without restriction, including without limitation
38// the rights to use, copy, modify, merge, publish, distribute, sublicense,
39// and/or sell copies of the Software, and to permit persons to whom the
40// Software is furnished to do so, subject to the following conditions:
41//
42// The above copyright notice and this permission notice shall be included
43// in all copies or substantial portions of the Software.
44//
45// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
48// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
49// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
50// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
51// DEALINGS IN THE SOFTWARE.
52
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060053// Basic rendering tests
54
55#include <stdlib.h>
56#include <stdio.h>
57#include <stdbool.h>
58#include <string.h>
Courtney Goeltzenleuchter76a643b2014-08-21 17:34:22 -060059#include <iostream>
60#include <fstream>
61using namespace std;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060062
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060063#include <vulkan.h>
Tobin Ehlis31446e52014-11-28 11:17:19 -070064#ifdef DUMP_STATE_DOT
65#include "../layers/draw_state.h"
66#endif
Tobin Ehlis3c26a542014-11-18 11:28:33 -070067#ifdef PRINT_OBJECTS
68#include "../layers/object_track.h"
69#endif
Tobin Ehlis791a49c2014-11-10 12:29:12 -070070#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060071#include <vk_debug_report_lunarg.h>
Tobin Ehlis791a49c2014-11-10 12:29:12 -070072#endif
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060073#include "gtest-1.7.0/include/gtest/gtest.h"
74
Cody Northropd4e020a2015-03-17 14:54:35 -060075#include "icd-spv.h"
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060076
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -060077#define GLM_FORCE_RADIANS
78#include "glm/glm.hpp"
79#include <glm/gtc/matrix_transform.hpp>
80
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060081#include "vkrenderframework.h"
Tobin Ehlis791a49c2014-11-10 12:29:12 -070082#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060083void VKAPI myDbgFunc(
84 VK_DBG_MSG_TYPE msgType,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060085 VkValidationLevel validationLevel,
Mike Stroyan230e6252015-04-17 12:36:38 -060086 VkObject srcObject,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060087 size_t location,
88 int32_t msgCode,
89 const char* pMsg,
90 void* pUserData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -070091{
Tobin Ehlis3c26a542014-11-18 11:28:33 -070092 switch (msgType)
93 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060094 case VK_DBG_MSG_WARNING:
Tobin Ehlis3c26a542014-11-18 11:28:33 -070095 printf("CALLBACK WARNING : %s\n", pMsg);
96 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060097 case VK_DBG_REPORT_ERROR_BIT:
Tobin Ehlis3c26a542014-11-18 11:28:33 -070098 printf("CALLBACK ERROR : %s\n", pMsg);
99 break;
100 default:
101 printf("EATING Msg of type %u\n", msgType);
102 break;
103 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700104}
105#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700106
107
108#undef ASSERT_NO_FATAL_FAILURE
109#define ASSERT_NO_FATAL_FAILURE(x) x
110
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600111//--------------------------------------------------------------------------------------
112// Mesh and VertexFormat Data
113//--------------------------------------------------------------------------------------
114struct Vertex
115{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600116 float posX, posY, posZ, posW; // Position data
117 float r, g, b, a; // Color
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600118};
119
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600120struct VertexUV
121{
122 float posX, posY, posZ, posW; // Position data
123 float u, v; // texture u,v
124};
125
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600126#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600127#define UV(_u_, _v_) (_u_), (_v_)
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600128
129static const Vertex g_vbData[] =
130{
131 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
132 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
133 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
134 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
135 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
136 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
137
138 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
139 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
140 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
141 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
142 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
143 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
144
145 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
146 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
147 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
148 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
149 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
150 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
151
152 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
153 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
154 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
155 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
156 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
157 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
158
159 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
160 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
161 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
162 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
163 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
164 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
165
166 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
167 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
168 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
169 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
170 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
171 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
172};
173
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600174static const Vertex g_vb_solid_face_colors_Data[] =
175{
176 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600177 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600178 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
179 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600180 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
181 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600182
183 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
184 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600185 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
186 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600187 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600188 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600189
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600190 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
191 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
192 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
193 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
194 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
195 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600196
197 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
198 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
199 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
200 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
201 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
202 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
203
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600204 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600205 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600206 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
207 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600208 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
209 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
210
211 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
212 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
213 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
214 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
215 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
216 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
217};
218
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600219static const VertexUV g_vb_texture_Data[] =
220{
221 { XYZ1( -1, -1, -1 ), UV( 0.f, 0.f ) },
222 { XYZ1( -1, 1, 1 ), UV( 1.f, 1.f ) },
223 { XYZ1( -1, -1, 1 ), UV( 1.f, 0.f ) },
224 { XYZ1( -1, 1, 1 ), UV( 1.f, 1.f ) },
225 { XYZ1( -1, -1, -1 ), UV( 0.f, 0.f ) },
226 { XYZ1( -1, 1, -1 ), UV( 0.f, 1.f ) },
227
228 { XYZ1( -1, -1, -1 ), UV( 1.f, 0.f ) },
229 { XYZ1( 1, -1, -1 ), UV( 0.f, 0.f ) },
230 { XYZ1( 1, 1, -1 ), UV( 0.f, 1.f ) },
231 { XYZ1( -1, -1, -1 ), UV( 1.f, 0.f ) },
232 { XYZ1( 1, 1, -1 ), UV( 0.f, 1.f ) },
233 { XYZ1( -1, 1, -1 ), UV( 1.f, 1.f ) },
234
235 { XYZ1( -1, -1, -1 ), UV( 1.f, 1.f ) },
236 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
237 { XYZ1( 1, -1, -1 ), UV( 1.f, 0.f ) },
238 { XYZ1( -1, -1, -1 ), UV( 1.f, 1.f ) },
239 { XYZ1( -1, -1, 1 ), UV( 0.f, 1.f ) },
240 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
241
242 { XYZ1( -1, 1, -1 ), UV( 1.f, 1.f ) },
243 { XYZ1( 1, 1, 1 ), UV( 0.f, 0.f ) },
244 { XYZ1( -1, 1, 1 ), UV( 0.f, 1.f ) },
245 { XYZ1( -1, 1, -1 ), UV( 1.f, 1.f ) },
246 { XYZ1( 1, 1, -1 ), UV( 1.f, 0.f ) },
247 { XYZ1( 1, 1, 1 ), UV( 0.f, 0.f ) },
248
249 { XYZ1( 1, 1, -1 ), UV( 1.f, 1.f ) },
250 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
251 { XYZ1( 1, 1, 1 ), UV( 0.f, 1.f ) },
252 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
253 { XYZ1( 1, 1, -1 ), UV( 1.f, 1.f ) },
254 { XYZ1( 1, -1, -1 ), UV( 1.f, 0.f ) },
255
256 { XYZ1( -1, 1, 1 ), UV( 0.f, 1.f ) },
257 { XYZ1( 1, 1, 1 ), UV( 1.f, 1.f ) },
258 { XYZ1( -1, -1, 1 ), UV( 0.f, 0.f ) },
259 { XYZ1( -1, -1, 1 ), UV( 0.f, 0.f ) },
260 { XYZ1( 1, 1, 1 ), UV( 1.f, 1.f ) },
261 { XYZ1( 1, -1, 1 ), UV( 1.f, 0.f ) },
262};
263
Tony Barbour01999182015-04-09 12:58:51 -0600264class VkRenderTest : public VkRenderFramework
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -0600265{
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600266public:
Cody Northrop4e6b4762014-10-09 21:25:22 -0600267
Tony Barbourf43b6982014-11-25 13:18:32 -0700268 void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbour01999182015-04-09 12:58:51 -0600269 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer);
270 void GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600271 void InitDepthStencil();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600272 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate);
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600273
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600274 VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer);
275 VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer);
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600276
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600277protected:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600278 VkImage m_texture;
279 VkImageView m_textureView;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800280 VkDescriptorInfo m_descriptorInfo;
Tony Barbour8205d902015-04-16 15:59:00 -0600281 VkDeviceMemory m_textureMem;
Cody Northrop350727b2014-10-06 15:42:00 -0600282
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600283 VkSampler m_sampler;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600284
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600285
286 virtual void SetUp() {
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600287
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600288 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600289 this->app_info.pNext = NULL;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800290 this->app_info.pAppName = "render_tests";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600291 this->app_info.appVersion = 1;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800292 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600293 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600294 this->app_info.apiVersion = VK_API_VERSION;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600295
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800296 memset(&m_descriptorInfo, 0, sizeof(m_descriptorInfo));
Cody Northrop350727b2014-10-06 15:42:00 -0600297
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600298 InitFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600299 }
300
301 virtual void TearDown() {
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600302 // Clean up resources before we reset
303 ShutdownFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600304 }
305};
306
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600307VkResult VkRenderTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600308{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600309 VkResult result;
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600310
311 result = cmdBuffer.BeginCommandBuffer();
312
313 /*
314 * For render test all drawing happens in a single render pass
315 * on a single command buffer.
316 */
Chris Forbesfe133ef2015-06-16 14:05:59 +1200317 if (VK_SUCCESS == result && renderPass()) {
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600318 cmdBuffer.BeginRenderPass(renderPass(), framebuffer());
319 }
320
321 return result;
322}
323
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600324VkResult VkRenderTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600325{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600326 VkResult result;
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600327
Chris Forbesfe133ef2015-06-16 14:05:59 +1200328 if (renderPass()) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +0800329 cmdBuffer.EndRenderPass();
Chris Forbesfe133ef2015-06-16 14:05:59 +1200330 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600331
332 result = cmdBuffer.EndCommandBuffer();
333
334 return result;
335}
336
337
Tony Barbour01999182015-04-09 12:58:51 -0600338void VkRenderTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet)
Tony Barbour02472db2015-01-08 17:08:28 -0700339{
Tony Barbour17c6ab12015-03-27 17:03:18 -0600340 if (m_depthStencil->Initialized()) {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600341 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Tony Barbour17c6ab12015-03-27 17:03:18 -0600342 } else {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600343 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour17c6ab12015-03-27 17:03:18 -0600344 }
345
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700346 cmdBuffer->PrepareAttachments();
Tony Barbour8205d902015-04-16 15:59:00 -0600347 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_RASTER, m_stateRaster);
348 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_VIEWPORT, m_stateViewport);
349 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_COLOR_BLEND, m_colorBlend);
350 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_DEPTH_STENCIL, m_stateDepthStencil);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600351 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
352 pipelineobj.CreateVKPipeline(descriptorSet);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600353 cmdBuffer->BindPipeline(pipelineobj);
Chia-I Wu862c5572015-03-28 15:23:55 +0800354 cmdBuffer->BindDescriptorSet(descriptorSet);
Tony Barbour02472db2015-01-08 17:08:28 -0700355}
Tony Barbourf43b6982014-11-25 13:18:32 -0700356
Tony Barbour01999182015-04-09 12:58:51 -0600357void VkRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
358 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer)
Tony Barbourdd4c9642015-01-09 12:55:14 -0700359{
360 int i;
361 glm::mat4 MVP;
362 int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600363 VkResult err;
Tony Barbourdd4c9642015-01-09 12:55:14 -0700364
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600365 /* Only do 3 positions to avoid back face cull */
366 for (i = 0; i < 3; i++) {
Tony Barbourdd4c9642015-01-09 12:55:14 -0700367 void *pData = constantBuffer->map();
368
369 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
370 MVP = Projection * View * Model;
371 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
372
373 constantBuffer->unmap();
374
375 // submit the command buffer to the universal queue
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600376 cmdBuffer->QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700377
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600378 err = vkQueueWaitIdle( m_device->m_queue );
379 ASSERT_VK_SUCCESS( err );
Tony Barbourdd4c9642015-01-09 12:55:14 -0700380
381 // Wait for work to finish before cleaning up.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600382 vkDeviceWaitIdle(m_device->device());
Tony Barbourdd4c9642015-01-09 12:55:14 -0700383
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700384 assert(m_renderTargets.size() == 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -0700385 RecordImage(m_renderTargets[0]);
386 }
387}
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600388
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600389void dumpMatrix(const char *note, glm::mat4 MVP)
390{
Chia-I Wu7133fdc2014-12-15 23:57:34 +0800391 int i;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600392
393 printf("%s: \n", note);
394 for (i=0; i<4; i++) {
395 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
396 }
397 printf("\n");
398 fflush(stdout);
399}
400
401void dumpVec4(const char *note, glm::vec4 vector)
402{
403 printf("%s: \n", note);
404 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
405 printf("\n");
406 fflush(stdout);
407}
408
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600409struct vktriangle_vs_uniform {
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600410 // Must start with MVP
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600411 float mvp[4][4];
412 float position[3][4];
413 float color[3][4];
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600414};
415
Tony Barbour01999182015-04-09 12:58:51 -0600416void VkRenderTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600417{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700418#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600419 vkDbgRegisterMsgCallback(inst, myDbgFunc, NULL);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700420#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600421 // Create identity matrix
422 int i;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600423 struct vktriangle_vs_uniform data;
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600424
425 glm::mat4 Projection = glm::mat4(1.0f);
426 glm::mat4 View = glm::mat4(1.0f);
427 glm::mat4 Model = glm::mat4(1.0f);
428 glm::mat4 MVP = Projection * View * Model;
429 const int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600430 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600431 memcpy(&data.mvp, &MVP[0][0], matrixSize);
432
433 static const Vertex tri_data[] =
434 {
435 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
436 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
437 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
438 };
439
440 for (i=0; i<3; i++) {
441 data.position[i][0] = tri_data[i].posX;
442 data.position[i][1] = tri_data[i].posY;
443 data.position[i][2] = tri_data[i].posZ;
444 data.position[i][3] = tri_data[i].posW;
445 data.color[i][0] = tri_data[i].r;
446 data.color[i][1] = tri_data[i].g;
447 data.color[i][2] = tri_data[i].b;
448 data.color[i][3] = tri_data[i].a;
449 }
450
Tony Barbourf43b6982014-11-25 13:18:32 -0700451 ASSERT_NO_FATAL_FAILURE(InitState());
452 ASSERT_NO_FATAL_FAILURE(InitViewport());
453
Tony Barbour01999182015-04-09 12:58:51 -0600454 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barbourf43b6982014-11-25 13:18:32 -0700455
Tony Barbour01999182015-04-09 12:58:51 -0600456 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
457 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700458
Tony Barbour01999182015-04-09 12:58:51 -0600459 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -0700460 pipelineobj.AddShader(&vs);
461 pipelineobj.AddShader(&ps);
462
Tony Barbour01999182015-04-09 12:58:51 -0600463 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600464 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700465
Tony Barbour71ba3612015-01-09 16:12:35 -0700466 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600467 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour71ba3612015-01-09 16:12:35 -0700468 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700469
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600470 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour71ba3612015-01-09 16:12:35 -0700471
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600472 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour71ba3612015-01-09 16:12:35 -0700473#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600474 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour71ba3612015-01-09 16:12:35 -0700475 pDSDumpDot((char*)"triTest2.dot");
476#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600477
Tony Barbour71ba3612015-01-09 16:12:35 -0700478 // render triangle
479 cmdBuffer.Draw(0, 3, 0, 1);
480
481 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600482 EndCommandBuffer(cmdBuffer);
483
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600484 cmdBuffer.QueueCommandBuffer();
Tony Barbour71ba3612015-01-09 16:12:35 -0700485
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600486 RecordImages(m_renderTargets);
Tony Barbour71ba3612015-01-09 16:12:35 -0700487
488 if (rotate)
Tobin Ehlis12ee35f2015-03-26 08:23:25 -0600489 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
Tony Barbour71ba3612015-01-09 16:12:35 -0700490
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700491#ifdef PRINT_OBJECTS
Mark Lobodzinski4e5016f2015-05-05 15:01:37 -0500492 OBJ_TRACK_GET_OBJECTS_COUNT pObjTrackGetObjectsCount = (OBJ_TRACK_GET_OBJECTS_COUNT)vkGetProcAddr(gpu(), (char*)"objTrackGetObjectsCount");
Mark Lobodzinski14305ad2015-06-23 11:35:12 -0600493 uint64_t numObjects = pObjTrackGetObjectsCount(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600494 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700495 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600496 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700497 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
Mark Lobodzinski14305ad2015-06-23 11:35:12 -0600498 pObjTrackGetObjs(m_device, numObjects, pObjNodeArray);
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700499 for (i=0; i < numObjects; i++) {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600500 printf("Object %i of type %s has objID (%p) and %lu uses\n", i, string_VkObjectType(pObjNodeArray[i].objType), pObjNodeArray[i].pObj, pObjNodeArray[i].numUses);
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700501 }
502 free(pObjNodeArray);
503#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700504
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600505}
506
Tony Barbour01999182015-04-09 12:58:51 -0600507TEST_F(VkRenderTest, VKTriangle_FragColor)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600508{
509 static const char *vertShaderText =
510 "#version 140\n"
511 "#extension GL_ARB_separate_shader_objects : enable\n"
512 "#extension GL_ARB_shading_language_420pack : enable\n"
513 "\n"
514 "layout(binding = 0) uniform buf {\n"
515 " mat4 MVP;\n"
516 " vec4 position[3];\n"
517 " vec4 color[3];\n"
518 "} ubuf;\n"
519 "\n"
520 "layout (location = 0) out vec4 outColor;\n"
521 "\n"
522 "void main() \n"
523 "{\n"
524 " outColor = ubuf.color[gl_VertexID];\n"
525 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
526 "}\n";
527
528 static const char *fragShaderText =
529 "#version 140\n"
530 "#extension GL_ARB_separate_shader_objects : enable\n"
531 "#extension GL_ARB_shading_language_420pack : enable\n"
532 "\n"
533 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600534 "layout (location = 0) out vec4 uFragColor;\n"
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600535 "\n"
536 "void main()\n"
537 "{\n"
GregFd6ebdb32015-06-03 18:40:50 -0600538 " uFragColor = inColor;\n"
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600539 "}\n";
540
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600541 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
542 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600543}
544
Tony Barbour01999182015-04-09 12:58:51 -0600545TEST_F(VkRenderTest, VKTriangle_OutputLocation)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600546{
547 static const char *vertShaderText =
548 "#version 140\n"
549 "#extension GL_ARB_separate_shader_objects : enable\n"
550 "#extension GL_ARB_shading_language_420pack : enable\n"
551 "\n"
552 "layout(binding = 0) uniform buf {\n"
553 " mat4 MVP;\n"
554 " vec4 position[3];\n"
555 " vec4 color[3];\n"
556 "} ubuf;\n"
557 "\n"
558 "layout (location = 0) out vec4 outColor;\n"
559 "\n"
560 "void main() \n"
561 "{\n"
562 " outColor = ubuf.color[gl_VertexID];\n"
563 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
564 "}\n";
565
566 static const char *fragShaderText =
567 "#version 140\n"
568 "#extension GL_ARB_separate_shader_objects : enable\n"
569 "#extension GL_ARB_shading_language_420pack : enable\n"
570 "\n"
571 "layout (location = 0) in vec4 inColor;\n"
572 "layout (location = 0) out vec4 outColor;\n"
573 "\n"
574 "void main()\n"
575 "{\n"
576 " outColor = inColor;\n"
577 "}\n";
578
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600579 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to output location 0, which should be the same as gl_FragColor");
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600580
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600581 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600582}
Cody Northrop71727d22015-06-23 13:25:51 -0600583
Tony Barbour01999182015-04-09 12:58:51 -0600584TEST_F(VkRenderTest, SPV_VKTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700585{
Tony Barbourf43b6982014-11-25 13:18:32 -0700586 static const char *vertShaderText =
587 "#version 140\n"
588 "#extension GL_ARB_separate_shader_objects : enable\n"
589 "#extension GL_ARB_shading_language_420pack : enable\n"
590 "\n"
591 "layout(binding = 0) uniform buf {\n"
592 " mat4 MVP;\n"
593 " vec4 position[3];\n"
594 " vec4 color[3];\n"
595 "} ubuf;\n"
596 "\n"
597 "layout (location = 0) out vec4 outColor;\n"
598 "\n"
599 "void main() \n"
600 "{\n"
601 " outColor = ubuf.color[gl_VertexID];\n"
602 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
603 "}\n";
604
605 static const char *fragShaderText =
606 "#version 140\n"
607 "#extension GL_ARB_separate_shader_objects : enable\n"
608 "#extension GL_ARB_shading_language_420pack : enable\n"
609 "\n"
610 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600611 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700612 "\n"
613 "void main()\n"
614 "{\n"
GregFd6ebdb32015-06-03 18:40:50 -0600615 " outColor = inColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700616 "}\n";
617
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600618 TEST_DESCRIPTION("VK-style shaders, but force test framework to compile shader to SPV and pass SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700619
Cody Northrop1cfbd172015-06-03 16:49:20 -0600620 ScopedUseGlsl useGlsl(false);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600621 VKTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700622}
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600623
Tony Barbour01999182015-04-09 12:58:51 -0600624TEST_F(VkRenderTest, SPV_GreenTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700625{
Tony Barbourf43b6982014-11-25 13:18:32 -0700626 static const char *vertShaderText =
627 "#version 130\n"
628 "vec2 vertices[3];\n"
629 "void main() {\n"
630 " vertices[0] = vec2(-1.0, -1.0);\n"
631 " vertices[1] = vec2( 1.0, -1.0);\n"
632 " vertices[2] = vec2( 0.0, 1.0);\n"
633 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
634 "}\n";
635
636 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600637 "#version 140\n"
638 "#extension GL_ARB_separate_shader_objects : enable\n"
639 "#extension GL_ARB_shading_language_420pack : enable\n"
640 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700641 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600642 " outColor = vec4(0,1,0,1);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700643 "}\n";
644
Cody Northropacfb0492015-03-17 15:55:58 -0600645 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700646
Cody Northrop1cfbd172015-06-03 16:49:20 -0600647 ScopedUseGlsl useGlsl(false);
648
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600649 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700650}
Cody Northrop71727d22015-06-23 13:25:51 -0600651
Tony Barbour01999182015-04-09 12:58:51 -0600652TEST_F(VkRenderTest, YellowTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700653{
654 static const char *vertShaderText =
655 "#version 130\n"
656 "void main() {\n"
657 " vec2 vertices[3];"
658 " vertices[0] = vec2(-0.5, -0.5);\n"
659 " vertices[1] = vec2( 0.5, -0.5);\n"
660 " vertices[2] = vec2( 0.5, 0.5);\n"
661 " vec4 colors[3];\n"
662 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
663 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
664 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
665 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
666 "}\n";
667
668 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600669 "#version 140\n"
670 "#extension GL_ARB_separate_shader_objects : enable\n"
671 "#extension GL_ARB_shading_language_420pack : enable\n"
672 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700673 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600674 " outColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700675 "}\n";
676
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600677 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700678}
679
Tony Barbour01999182015-04-09 12:58:51 -0600680TEST_F(VkRenderTest, QuadWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600681{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600682 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600683 "#version 140\n"
684 "#extension GL_ARB_separate_shader_objects : enable\n"
685 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700686 //XYZ1( -1, -1, -1 )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600687 "layout (location = 0) in vec4 pos;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700688 //XYZ1( 0.f, 0.f, 0.f )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600689 "layout (location = 1) in vec4 inColor;\n"
690 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600691 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600692 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600693 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600694 "}\n";
695
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600696
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600697 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700698 "#version 140\n"
699 "#extension GL_ARB_separate_shader_objects : enable\n"
700 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600701 "layout (location = 0) in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700702 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600703 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700704 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600705 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600706
Tony Barbourf43b6982014-11-25 13:18:32 -0700707
708
709 ASSERT_NO_FATAL_FAILURE(InitState());
710 ASSERT_NO_FATAL_FAILURE(InitViewport());
711
Tony Barbour01999182015-04-09 12:58:51 -0600712 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000713 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700714
Tony Barbour01999182015-04-09 12:58:51 -0600715 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
716 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700717
Tony Barbour01999182015-04-09 12:58:51 -0600718 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -0700719 pipelineobj.AddShader(&vs);
720 pipelineobj.AddShader(&ps);
721
Tony Barbour01999182015-04-09 12:58:51 -0600722 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600723 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -0600724
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600725#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600726 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600727 MESH_BIND_ID, // binding ID
Tony Barbourf43b6982014-11-25 13:18:32 -0700728 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600729 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -0700730 };
731
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600732 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600733 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
734 vi_attribs[0].location = 0; // location, position
Tony Barbour8205d902015-04-16 15:59:00 -0600735 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600736 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
737 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
738 vi_attribs[1].location = 1; // location, color
Tony Barbour8205d902015-04-16 15:59:00 -0600739 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600740 vi_attribs[1].offsetInBytes = 1*sizeof(float)*4; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -0700741
742 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
743 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600744 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -0700745
Tony Barboure4ed9942015-01-09 10:06:53 -0700746 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600747 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700748 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700749
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600750 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600751
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600752 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700753
Tony Barboure4ed9942015-01-09 10:06:53 -0700754 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
755
756 // render two triangles
757 cmdBuffer.Draw(0, 6, 0, 1);
758
759 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600760 EndCommandBuffer(cmdBuffer);
761
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600762 cmdBuffer.QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -0700763
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600764 RecordImages(m_renderTargets);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600765}
766
Tony Barbour01999182015-04-09 12:58:51 -0600767TEST_F(VkRenderTest, TriangleMRT)
Chia-I Wue09d1a72014-12-05 10:32:23 +0800768{
769 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600770 "#version 140\n"
771 "#extension GL_ARB_separate_shader_objects : enable\n"
772 "#extension GL_ARB_shading_language_420pack : enable\n"
773 "layout (location = 0) in vec4 pos;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800774 "void main() {\n"
775 " gl_Position = pos;\n"
776 "}\n";
777
778 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600779 "#version 140\n"
780 "#extension GL_ARB_separate_shader_objects : enable\n"
781 "#extension GL_ARB_shading_language_420pack : enable\n"
782 "layout (location = 0) out vec4 uFragData0;\n"
783 "layout (location = 1) out vec4 uFragData1;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800784 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600785 " uFragData0 = vec4(1.0, 0.0, 0.0, 1.0);\n"
786 " uFragData1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800787 "}\n";
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600788 const float vb_data[][2] = {
Chia-I Wue09d1a72014-12-05 10:32:23 +0800789 { -1.0f, -1.0f },
790 { 1.0f, -1.0f },
791 { -1.0f, 1.0f }
792 };
793
794 ASSERT_NO_FATAL_FAILURE(InitState());
795 ASSERT_NO_FATAL_FAILURE(InitViewport());
796
Tony Barbour01999182015-04-09 12:58:51 -0600797 VkConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000798 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800799
Tony Barbour01999182015-04-09 12:58:51 -0600800 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
801 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800802
Tony Barbour01999182015-04-09 12:58:51 -0600803 VkPipelineObj pipelineobj(m_device);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800804 pipelineobj.AddShader(&vs);
805 pipelineobj.AddShader(&ps);
806
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600807#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600808 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600809 MESH_BUF_ID, // Binding ID
810 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600811 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Chia-I Wue09d1a72014-12-05 10:32:23 +0800812 };
813
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600814 VkVertexInputAttributeDescription vi_attrib;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600815 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
816 vi_attrib.location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -0600817 vi_attrib.format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600818 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
Chia-I Wue09d1a72014-12-05 10:32:23 +0800819
820 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
821 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600822 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800823
Tony Barbour01999182015-04-09 12:58:51 -0600824 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600825 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800826
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700827 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
Chia-I Wue09d1a72014-12-05 10:32:23 +0800828
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600829 VkPipelineCbAttachmentState att = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600830 att.blendEnable = VK_FALSE;
Chia-I Wue09d1a72014-12-05 10:32:23 +0800831 att.format = m_render_target_fmt;
832 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700833 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800834
Tony Barbour01999182015-04-09 12:58:51 -0600835 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700836
Tony Barbour5ed79702015-01-07 14:31:52 -0700837 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
838 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barboure4ed9942015-01-09 10:06:53 -0700839
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600840 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour5ed79702015-01-07 14:31:52 -0700841
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600842 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700843
Tony Barbour5ed79702015-01-07 14:31:52 -0700844 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700845#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600846 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour5ed79702015-01-07 14:31:52 -0700847 pDSDumpDot((char*)"triTest2.dot");
848#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600849
Tony Barbour5ed79702015-01-07 14:31:52 -0700850 // render triangle
851 cmdBuffer.Draw(0, 3, 0, 1);
852
853 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600854 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600855 cmdBuffer.QueueCommandBuffer();
Tony Barbour5ed79702015-01-07 14:31:52 -0700856
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600857 RecordImages(m_renderTargets);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800858}
859
Tony Barbour01999182015-04-09 12:58:51 -0600860TEST_F(VkRenderTest, QuadWithIndexedVertexFetch)
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700861{
862 static const char *vertShaderText =
863 "#version 140\n"
864 "#extension GL_ARB_separate_shader_objects : enable\n"
865 "#extension GL_ARB_shading_language_420pack : enable\n"
866 "layout(location = 0) in vec4 pos;\n"
867 "layout(location = 1) in vec4 inColor;\n"
868 "layout(location = 0) out vec4 outColor;\n"
869 "void main() {\n"
870 " outColor = inColor;\n"
871 " gl_Position = pos;\n"
872 "}\n";
873
874
875 static const char *fragShaderText =
876 "#version 140\n"
877 "#extension GL_ARB_separate_shader_objects : enable\n"
878 "#extension GL_ARB_shading_language_420pack : enable\n"
879 "layout(location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600880 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700881 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600882 " outColor = color;\n"
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700883 "}\n";
884
885 const Vertex g_vbData[] =
886 {
887 // first tri
888 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
889 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
890 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
891
892 // second tri
893 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
894 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
895 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
896 };
897
898 const uint16_t g_idxData[6] = {
899 0, 1, 2,
900 3, 4, 5,
901 };
902
903 ASSERT_NO_FATAL_FAILURE(InitState());
904 ASSERT_NO_FATAL_FAILURE(InitViewport());
905
Tony Barbour01999182015-04-09 12:58:51 -0600906 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000907 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700908
Tony Barbour01999182015-04-09 12:58:51 -0600909 VkIndexBufferObj indexBuffer(m_device);
Tony Barbour8205d902015-04-16 15:59:00 -0600910 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), VK_INDEX_TYPE_UINT16, g_idxData);
Mark Lobodzinskid30f82a2015-02-16 14:24:23 -0600911 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700912
Tony Barbour01999182015-04-09 12:58:51 -0600913 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
914 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700915
Tony Barbour01999182015-04-09 12:58:51 -0600916 VkPipelineObj pipelineobj(m_device);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700917 pipelineobj.AddShader(&vs);
918 pipelineobj.AddShader(&ps);
919
Tony Barbour01999182015-04-09 12:58:51 -0600920 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600921 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
922 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, indexBuffer);
Tony Barbour83a83802015-04-02 15:43:15 -0600923
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700924
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600925#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600926 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600927 MESH_BIND_ID, // binding ID
928 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600929 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700930 };
931
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600932 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600933 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
934 vi_attribs[0].location = 0; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600935 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600936 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
937 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
938 vi_attribs[1].location = 1; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600939 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600940 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700941
942 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
943 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700944
945 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600946 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700947 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600948 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barboure4ed9942015-01-09 10:06:53 -0700949
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600950 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700951
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700952#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600953 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700954 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700955#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700956
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600957 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600958 cmdBuffer.BindIndexBuffer(&indexBuffer, 0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700959
960 // render two triangles
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700961 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700962
963 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600964 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600965 cmdBuffer.QueueCommandBuffer();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700966
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600967 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700968}
969
Tony Barbour01999182015-04-09 12:58:51 -0600970TEST_F(VkRenderTest, GreyandRedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -0700971{
972 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -0700973
GregF6bef1212014-12-02 15:41:44 -0700974 static const char *vertShaderText =
975 "#version 140\n"
976 "#extension GL_ARB_separate_shader_objects : enable\n"
977 "#extension GL_ARB_shading_language_420pack : enable\n"
978 "layout (location = 0) in vec4 pos;\n"
979 "layout (location = 0) out vec4 outColor;\n"
980 "layout (location = 1) out vec4 outColor2;\n"
981 "void main() {\n"
982 " gl_Position = pos;\n"
983 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
984 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
985 "}\n";
986
987 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -0700988 "#version 330\n"
989 "#extension GL_ARB_separate_shader_objects : enable\n"
990 "#extension GL_ARB_shading_language_420pack : enable\n"
991 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
992 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
993 "layout (location = 0) in vec4 color;\n"
994 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600995 "layout (location = 0) out vec4 outColor;\n"
GregF6bef1212014-12-02 15:41:44 -0700996 "void main() {\n"
997 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
998 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -0600999 " outColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001000 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1001 " : color2;\n"
1002 "}\n";
1003
1004 ASSERT_NO_FATAL_FAILURE(InitState());
1005 ASSERT_NO_FATAL_FAILURE(InitViewport());
1006
Tony Barbour01999182015-04-09 12:58:51 -06001007 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001008 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001009
Tony Barbour01999182015-04-09 12:58:51 -06001010 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1011 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001012
Tony Barbour01999182015-04-09 12:58:51 -06001013 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001014 pipelineobj.AddShader(&vs);
1015 pipelineobj.AddShader(&ps);
1016
Tony Barbour01999182015-04-09 12:58:51 -06001017 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001018 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001019
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001020#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001021 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001022 MESH_BIND_ID, // binding ID
1023 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001024 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001025 };
1026
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001027 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001028 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1029 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001030 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001031 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001032
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001033 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001034 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001035 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001036
Tony Barbourdd4c9642015-01-09 12:55:14 -07001037 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001038 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001039 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1040
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001041 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001042
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001043 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001044
1045 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1046#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001047 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001048 pDSDumpDot((char*)"triTest2.dot");
1049#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001050
Tony Barbourdd4c9642015-01-09 12:55:14 -07001051 // render triangle
1052 cmdBuffer.Draw(0, 6, 0, 1);
1053
1054 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001055 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001056 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001057
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001058 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001059}
1060
Tony Barbour01999182015-04-09 12:58:51 -06001061TEST_F(VkRenderTest, RedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -07001062{
1063 // This tests that we correctly handle unread fragment inputs
1064
1065 static const char *vertShaderText =
1066 "#version 140\n"
1067 "#extension GL_ARB_separate_shader_objects : enable\n"
1068 "#extension GL_ARB_shading_language_420pack : enable\n"
1069 "layout (location = 0) in vec4 pos;\n"
1070 "layout (location = 0) out vec4 outColor;\n"
1071 "layout (location = 1) out vec4 outColor2;\n"
1072 "void main() {\n"
1073 " gl_Position = pos;\n"
1074 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1075 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1076 "}\n";
1077
1078 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001079 "#version 330\n"
1080 "#extension GL_ARB_separate_shader_objects : enable\n"
1081 "#extension GL_ARB_shading_language_420pack : enable\n"
1082 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1083 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1084 "layout (location = 0) in vec4 color;\n"
1085 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001086 "layout (location = 0) out vec4 outColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001087 "void main() {\n"
1088 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1089 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001090 " outColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001091 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1092 " : color2;\n"
1093 "}\n";
1094
1095 ASSERT_NO_FATAL_FAILURE(InitState());
1096 ASSERT_NO_FATAL_FAILURE(InitViewport());
1097
Tony Barbour01999182015-04-09 12:58:51 -06001098 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001099 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001100
Tony Barbour01999182015-04-09 12:58:51 -06001101 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1102 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001103
Tony Barbour01999182015-04-09 12:58:51 -06001104 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001105 pipelineobj.AddShader(&vs);
1106 pipelineobj.AddShader(&ps);
1107
Tony Barbour01999182015-04-09 12:58:51 -06001108 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001109 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001110
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001111#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001112 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001113 MESH_BIND_ID, // binding ID
1114 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001115 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001116 };
1117
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001118 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001119 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1120 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001121 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001122 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001123
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001124 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001125 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001126 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001127
Tony Barbourdd4c9642015-01-09 12:55:14 -07001128 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001129 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001130 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1131
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001132 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001133
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001134 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001135
1136 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1137#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001138 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001139 pDSDumpDot((char*)"triTest2.dot");
1140#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001141 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001142 cmdBuffer.Draw(0, 6, 0, 1);
1143
1144 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001145 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001146 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001147
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001148 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001149}
1150
Tony Barbour01999182015-04-09 12:58:51 -06001151TEST_F(VkRenderTest, GreyCirclesonBlueFade)
GregF6bef1212014-12-02 15:41:44 -07001152{
1153 // This tests reading gl_ClipDistance from FS
1154
1155 static const char *vertShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001156 //"#version 140\n"
GregF6bef1212014-12-02 15:41:44 -07001157 "#version 330\n"
1158 "#extension GL_ARB_separate_shader_objects : enable\n"
1159 "#extension GL_ARB_shading_language_420pack : enable\n"
1160 "out gl_PerVertex {\n"
1161 " vec4 gl_Position;\n"
1162 " float gl_ClipDistance[1];\n"
1163 "};\n"
1164 "layout (location = 0) in vec4 pos;\n"
1165 "layout (location = 0) out vec4 outColor;\n"
1166 "layout (location = 1) out vec4 outColor2;\n"
1167 "void main() {\n"
1168 " gl_Position = pos;\n"
1169 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1170 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1171 " float dists[3];\n"
1172 " dists[0] = 0.0;\n"
1173 " dists[1] = 1.0;\n"
1174 " dists[2] = 1.0;\n"
1175 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1176 "}\n";
1177
1178
1179 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001180 "#version 140\n"
1181 //"#version 330\n"
GregF6bef1212014-12-02 15:41:44 -07001182 "#extension GL_ARB_separate_shader_objects : enable\n"
1183 "#extension GL_ARB_shading_language_420pack : enable\n"
1184 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1185 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1186 "layout (location = 0) in vec4 color;\n"
1187 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001188 "layout (location = 0) out vec4 uFragColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001189 "void main() {\n"
1190 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1191 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001192 " uFragColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001193 " ? color * gl_ClipDistance[0]\n"
1194 " : color2;\n"
1195 "}\n";
1196
1197 ASSERT_NO_FATAL_FAILURE(InitState());
1198 ASSERT_NO_FATAL_FAILURE(InitViewport());
1199
Tony Barbour01999182015-04-09 12:58:51 -06001200 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001201 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001202
Tony Barbour01999182015-04-09 12:58:51 -06001203 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1204 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001205
Tony Barbour01999182015-04-09 12:58:51 -06001206 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001207 pipelineobj.AddShader(&vs);
1208 pipelineobj.AddShader(&ps);
1209
Tony Barbour01999182015-04-09 12:58:51 -06001210 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001211 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001212
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001213#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001214 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001215 MESH_BIND_ID, // binding ID
1216 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001217 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001218 };
1219
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001220 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001221 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1222 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001223 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001224 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001225
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001226 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001227 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001228 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001229
Tony Barbourdd4c9642015-01-09 12:55:14 -07001230 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001231 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001232 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF6bef1212014-12-02 15:41:44 -07001233
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001234 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001235
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001236 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001237
1238 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1239#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001240 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001241 pDSDumpDot((char*)"triTest2.dot");
1242#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001243
1244 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001245 cmdBuffer.Draw(0, 6, 0, 1);
1246
1247 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001248 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001249 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001250
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001251 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001252}
Tony Barbourf43b6982014-11-25 13:18:32 -07001253
Tony Barbour01999182015-04-09 12:58:51 -06001254TEST_F(VkRenderTest, GreyCirclesonBlueDiscard)
GregF7a23c792014-12-02 17:19:34 -07001255{
1256 static const char *vertShaderText =
1257 "#version 140\n"
1258 "#extension GL_ARB_separate_shader_objects : enable\n"
1259 "#extension GL_ARB_shading_language_420pack : enable\n"
1260 "layout (location = 0) in vec4 pos;\n"
1261 "layout (location = 0) out vec4 outColor;\n"
1262 "layout (location = 1) out vec4 outColor2;\n"
1263 "void main() {\n"
1264 " gl_Position = pos;\n"
1265 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1266 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1267 "}\n";
1268
1269
1270 static const char *fragShaderText =
GregF7a23c792014-12-02 17:19:34 -07001271 "#version 330\n"
1272 "#extension GL_ARB_separate_shader_objects : enable\n"
1273 "#extension GL_ARB_shading_language_420pack : enable\n"
1274 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1275 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1276 "layout (location = 0) in vec4 color;\n"
1277 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001278 "layout (location = 0) out vec4 outColor;\n"
GregF7a23c792014-12-02 17:19:34 -07001279 "void main() {\n"
1280 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1281 " float dist_squared = dot(pos, pos);\n"
1282 " if (dist_squared < 100.0)\n"
1283 " discard;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001284 " outColor = (dist_squared < 400.0)\n"
GregF7a23c792014-12-02 17:19:34 -07001285 " ? color\n"
1286 " : color2;\n"
1287 "}\n";
1288
1289 ASSERT_NO_FATAL_FAILURE(InitState());
1290 ASSERT_NO_FATAL_FAILURE(InitViewport());
1291
Tony Barbour01999182015-04-09 12:58:51 -06001292 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001293 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001294
Tony Barbour01999182015-04-09 12:58:51 -06001295 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1296 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF7a23c792014-12-02 17:19:34 -07001297
Tony Barbour01999182015-04-09 12:58:51 -06001298 VkPipelineObj pipelineobj(m_device);
GregF7a23c792014-12-02 17:19:34 -07001299 pipelineobj.AddShader(&vs);
1300 pipelineobj.AddShader(&ps);
1301
Tony Barbour01999182015-04-09 12:58:51 -06001302 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001303 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001304
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001305#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001306 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001307 MESH_BIND_ID, // binding ID
1308 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001309 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF7a23c792014-12-02 17:19:34 -07001310 };
1311
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001312 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001313 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1314 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001315 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001316 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF7a23c792014-12-02 17:19:34 -07001317
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001318 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF7a23c792014-12-02 17:19:34 -07001319 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001320 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF7a23c792014-12-02 17:19:34 -07001321
Tony Barbourdd4c9642015-01-09 12:55:14 -07001322 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001323 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001324 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1325
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001326 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001327
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001328 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001329
1330 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1331#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001332 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001333 pDSDumpDot((char*)"triTest2.dot");
1334#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001335
1336 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001337 cmdBuffer.Draw(0, 6, 0, 1);
1338
1339 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001340 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001341 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001342
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001343 RecordImages(m_renderTargets);
GregF7a23c792014-12-02 17:19:34 -07001344}
1345
1346
Tony Barbour01999182015-04-09 12:58:51 -06001347TEST_F(VkRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001348{
1349 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001350 "#version 140\n"
1351 "#extension GL_ARB_separate_shader_objects : enable\n"
1352 "#extension GL_ARB_shading_language_420pack : enable\n"
1353 "\n"
1354 "layout(binding = 0) uniform buf {\n"
1355 " mat4 MVP;\n"
1356 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001357 "void main() {\n"
1358 " vec2 vertices[3];"
1359 " vertices[0] = vec2(-0.5, -0.5);\n"
1360 " vertices[1] = vec2( 0.5, -0.5);\n"
1361 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001362 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001363 "}\n";
1364
1365 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001366 "#version 140\n"
1367 "#extension GL_ARB_separate_shader_objects : enable\n"
1368 "#extension GL_ARB_shading_language_420pack : enable\n"
1369 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001370 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001371 " outColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001372 "}\n";
1373
Tony Barbourf43b6982014-11-25 13:18:32 -07001374 ASSERT_NO_FATAL_FAILURE(InitState());
1375 ASSERT_NO_FATAL_FAILURE(InitViewport());
1376
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001377 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001378 glm::mat4 Projection = glm::mat4(1.0f);
1379 glm::mat4 View = glm::mat4(1.0f);
1380 glm::mat4 Model = glm::mat4(1.0f);
1381 glm::mat4 MVP = Projection * View * Model;
1382 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1383
Tony Barbour01999182015-04-09 12:58:51 -06001384 VkConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1385 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1386 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001387
Tony Barbour01999182015-04-09 12:58:51 -06001388 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001389 pipelineobj.AddShader(&vs);
1390 pipelineobj.AddShader(&ps);
1391
1392 // Create descriptor set and attach the constant buffer to it
Tony Barbour01999182015-04-09 12:58:51 -06001393 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001394 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001395
Tony Barbourdd4c9642015-01-09 12:55:14 -07001396 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001397 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001398 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001399
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001400 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001401
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001402 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001403
1404 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1405#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001406 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001407 pDSDumpDot((char*)"triTest2.dot");
1408#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001409
1410 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001411 cmdBuffer.Draw(0, 6, 0, 1);
1412
1413 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001414 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001415 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001416
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001417 RecordImages(m_renderTargets);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001418
1419 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001420}
1421
Tony Barbour01999182015-04-09 12:58:51 -06001422TEST_F(VkRenderTest, MixTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07001423{
1424 // This tests location applied to varyings. Notice that we have switched foo
1425 // and bar in the FS. The triangle should be blended with red, green and blue
1426 // corners.
1427 static const char *vertShaderText =
1428 "#version 140\n"
1429 "#extension GL_ARB_separate_shader_objects : enable\n"
1430 "#extension GL_ARB_shading_language_420pack : enable\n"
1431 "layout (location=0) out vec4 bar;\n"
1432 "layout (location=1) out vec4 foo;\n"
1433 "layout (location=2) out float scale;\n"
1434 "vec2 vertices[3];\n"
1435 "void main() {\n"
1436 " vertices[0] = vec2(-1.0, -1.0);\n"
1437 " vertices[1] = vec2( 1.0, -1.0);\n"
1438 " vertices[2] = vec2( 0.0, 1.0);\n"
1439 "vec4 colors[3];\n"
1440 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1441 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1442 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1443 " foo = colors[gl_VertexID % 3];\n"
1444 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1445 " scale = 1.0;\n"
1446 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1447 "}\n";
1448
1449 static const char *fragShaderText =
1450 "#version 140\n"
1451 "#extension GL_ARB_separate_shader_objects : enable\n"
1452 "#extension GL_ARB_shading_language_420pack : enable\n"
1453 "layout (location = 1) in vec4 bar;\n"
1454 "layout (location = 0) in vec4 foo;\n"
1455 "layout (location = 2) in float scale;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001456 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001457 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001458 " outColor = bar * scale + foo * (1.0-scale);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001459 "}\n";
1460
1461 ASSERT_NO_FATAL_FAILURE(InitState());
1462 ASSERT_NO_FATAL_FAILURE(InitViewport());
1463
Tony Barbour01999182015-04-09 12:58:51 -06001464 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1465 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001466
Tony Barbour01999182015-04-09 12:58:51 -06001467 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001468 pipelineobj.AddShader(&vs);
1469 pipelineobj.AddShader(&ps);
1470
Tony Barbour01999182015-04-09 12:58:51 -06001471 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06001472 descriptorSet.AppendDummy();
Tony Barbourf43b6982014-11-25 13:18:32 -07001473
Tony Barbourdd4c9642015-01-09 12:55:14 -07001474 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001475 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001476 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1477
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001478 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001479
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001480 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001481
1482#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001483 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001484 pDSDumpDot((char*)"triTest2.dot");
1485#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001486
Tony Barbourdd4c9642015-01-09 12:55:14 -07001487 // render triangle
1488 cmdBuffer.Draw(0, 3, 0, 1);
1489
1490 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001491 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001492 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001493
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001494 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001495}
1496
Tony Barbour01999182015-04-09 12:58:51 -06001497TEST_F(VkRenderTest, QuadVertFetchAndVertID)
Tony Barbourf43b6982014-11-25 13:18:32 -07001498{
1499 // This tests that attributes work in the presence of gl_VertexID
1500
1501 static const char *vertShaderText =
1502 "#version 140\n"
1503 "#extension GL_ARB_separate_shader_objects : enable\n"
1504 "#extension GL_ARB_shading_language_420pack : enable\n"
1505 //XYZ1( -1, -1, -1 )
1506 "layout (location = 0) in vec4 pos;\n"
1507 //XYZ1( 0.f, 0.f, 0.f )
1508 "layout (location = 1) in vec4 inColor;\n"
1509 "layout (location = 0) out vec4 outColor;\n"
1510 "void main() {\n"
1511 " outColor = inColor;\n"
1512 " vec4 vertices[3];"
1513 " vertices[gl_VertexID % 3] = pos;\n"
1514 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1515 "}\n";
1516
1517
1518 static const char *fragShaderText =
1519 "#version 140\n"
1520 "#extension GL_ARB_separate_shader_objects : enable\n"
1521 "#extension GL_ARB_shading_language_420pack : enable\n"
1522 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001523 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001524 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001525 " outColor = color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001526 "}\n";
1527
1528 ASSERT_NO_FATAL_FAILURE(InitState());
1529 ASSERT_NO_FATAL_FAILURE(InitViewport());
1530
Tony Barbour01999182015-04-09 12:58:51 -06001531 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001532 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001533
Tony Barbour01999182015-04-09 12:58:51 -06001534 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1535 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001536
Tony Barbour01999182015-04-09 12:58:51 -06001537 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001538 pipelineobj.AddShader(&vs);
1539 pipelineobj.AddShader(&ps);
1540
Tony Barbour01999182015-04-09 12:58:51 -06001541 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001542 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001543
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001544#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001545 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001546 MESH_BUF_ID, // Binding ID
1547 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001548 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001549 };
1550
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001551 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001552 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1553 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001554 vi_attribs[0].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001555 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1556 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1557 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001558 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001559 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001560
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001561 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001562 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001563 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001564
Tony Barbourdd4c9642015-01-09 12:55:14 -07001565 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001566 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001567 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1568
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001569 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001570
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001571 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001572
1573 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1574#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001575 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001576 pDSDumpDot((char*)"triTest2.dot");
1577#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001578
1579 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001580 cmdBuffer.Draw(0, 6, 0, 1);
1581
1582 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001583 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001584 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001585
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001586 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001587}
1588
Tony Barbour01999182015-04-09 12:58:51 -06001589TEST_F(VkRenderTest, QuadSparseVertFetch)
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001590{
1591 // This tests that attributes work in the presence of gl_VertexID
1592
1593 static const char *vertShaderText =
1594 "#version 140\n"
1595 "#extension GL_ARB_separate_shader_objects : enable\n"
1596 "#extension GL_ARB_shading_language_420pack : enable\n"
1597 //XYZ1( -1, -1, -1 )
1598 "layout (location = 1) in vec4 pos;\n"
1599 "layout (location = 4) in vec4 inColor;\n"
1600 //XYZ1( 0.f, 0.f, 0.f )
1601 "layout (location = 0) out vec4 outColor;\n"
1602 "void main() {\n"
1603 " outColor = inColor;\n"
1604 " gl_Position = pos;\n"
1605 "}\n";
1606
1607
1608 static const char *fragShaderText =
1609 "#version 140\n"
1610 "#extension GL_ARB_separate_shader_objects : enable\n"
1611 "#extension GL_ARB_shading_language_420pack : enable\n"
1612 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001613 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001614 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001615 " outColor = color;\n"
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001616 "}\n";
1617
1618 ASSERT_NO_FATAL_FAILURE(InitState());
1619 ASSERT_NO_FATAL_FAILURE(InitViewport());
1620
1621 struct VDATA
1622 {
1623 float t1, t2, t3, t4; // filler data
1624 float posX, posY, posZ, posW; // Position data
1625 float r, g, b, a; // Color
1626 };
1627 const struct VDATA vData[] =
1628 {
1629 { XYZ1(0, 0, 0), XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
1630 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1631 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1632 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1633 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1634 { XYZ1(0, 0, 0), XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
1635 };
1636
Tony Barbour01999182015-04-09 12:58:51 -06001637 VkConstantBufferObj meshBuffer(m_device,sizeof(vData)/sizeof(vData[0]),sizeof(vData[0]), vData);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001638 meshBuffer.BufferMemoryBarrier();
1639
Tony Barbour01999182015-04-09 12:58:51 -06001640 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1641 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001642
Tony Barbour01999182015-04-09 12:58:51 -06001643 VkPipelineObj pipelineobj(m_device);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001644 pipelineobj.AddShader(&vs);
1645 pipelineobj.AddShader(&ps);
1646
Tony Barbour01999182015-04-09 12:58:51 -06001647 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001648 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001649
1650#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001651 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001652 MESH_BUF_ID, // Binding ID
1653 sizeof(vData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001654 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001655 };
1656
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001657 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001658 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1659 vi_attribs[0].location = 4;
Tony Barbour8205d902015-04-16 15:59:00 -06001660 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001661 vi_attribs[0].offsetInBytes = sizeof(float) * 4 * 2; // Offset of first element in bytes from base of vertex
1662 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1663 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001664 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001665 vi_attribs[1].offsetInBytes = sizeof(float) * 4 * 1; // Offset of first element in bytes from base of vertex
1666
1667 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
1668 pipelineobj.AddVertexInputBindings(&vi_binding, 1);
1669 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
1670
1671 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001672 VkCommandBufferObj cmdBuffer(m_device);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001673 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1674
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001675 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001676
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001677 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001678
1679 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BUF_ID);
1680#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001681 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001682 pDSDumpDot((char*)"triTest2.dot");
1683#endif
1684
1685 // render two triangles
1686 cmdBuffer.Draw(0, 6, 0, 1);
1687
1688 // finalize recording of the command buffer
1689 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001690 cmdBuffer.QueueCommandBuffer();
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001691
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001692 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001693}
1694
Tony Barbour01999182015-04-09 12:58:51 -06001695TEST_F(VkRenderTest, TriVertFetchDeadAttr)
Tony Barbourf43b6982014-11-25 13:18:32 -07001696{
1697 // This tests that attributes work in the presence of gl_VertexID
1698 // and a dead attribute in position 0. Draws a triangle with yellow,
1699 // red and green corners, starting at top and going clockwise.
1700
1701 static const char *vertShaderText =
1702 "#version 140\n"
1703 "#extension GL_ARB_separate_shader_objects : enable\n"
1704 "#extension GL_ARB_shading_language_420pack : enable\n"
1705 //XYZ1( -1, -1, -1 )
1706 "layout (location = 0) in vec4 pos;\n"
1707 //XYZ1( 0.f, 0.f, 0.f )
1708 "layout (location = 1) in vec4 inColor;\n"
1709 "layout (location = 0) out vec4 outColor;\n"
1710 "void main() {\n"
1711 " outColor = inColor;\n"
1712 " vec2 vertices[3];"
1713 " vertices[0] = vec2(-1.0, -1.0);\n"
1714 " vertices[1] = vec2( 1.0, -1.0);\n"
1715 " vertices[2] = vec2( 0.0, 1.0);\n"
1716 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1717 "}\n";
1718
1719
1720 static const char *fragShaderText =
1721 "#version 140\n"
1722 "#extension GL_ARB_separate_shader_objects : enable\n"
1723 "#extension GL_ARB_shading_language_420pack : enable\n"
1724 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001725 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001726 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001727 " outColor = color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001728 "}\n";
1729
1730 ASSERT_NO_FATAL_FAILURE(InitState());
1731 ASSERT_NO_FATAL_FAILURE(InitViewport());
1732
Tony Barbour01999182015-04-09 12:58:51 -06001733 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001734 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001735
Tony Barbour01999182015-04-09 12:58:51 -06001736 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1737 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001738
Tony Barbour01999182015-04-09 12:58:51 -06001739 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001740 pipelineobj.AddShader(&vs);
1741 pipelineobj.AddShader(&ps);
1742
Tony Barbour01999182015-04-09 12:58:51 -06001743 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001744 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001745
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001746#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001747 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001748 MESH_BUF_ID, // Binding ID
1749 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001750 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001751 };
1752
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001753 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001754 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1755 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001756 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001757 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1758 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1759 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001760 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001761 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001762
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001763 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001764 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001765 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001766
Tony Barbourdd4c9642015-01-09 12:55:14 -07001767 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001768 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001769 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001770
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001771 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001772
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001773 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001774
1775 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1776#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001777 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001778 pDSDumpDot((char*)"triTest2.dot");
1779#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001780
1781 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001782 cmdBuffer.Draw(0, 6, 0, 1);
1783
1784 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001785 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001786 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001787
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001788 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001789}
1790
Tony Barbour01999182015-04-09 12:58:51 -06001791TEST_F(VkRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001792{
1793 static const char *vertShaderText =
1794 "#version 140\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001795 "#extension GL_ARB_separate_shader_objects : enable\n"
1796 "#extension GL_ARB_shading_language_420pack : enable\n"
GregFd6ebdb32015-06-03 18:40:50 -06001797 "layout (std140, binding = 0) uniform bufferVals {\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001798 " mat4 mvp;\n"
1799 "} myBufferVals;\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001800 "layout (location = 0) in vec4 pos;\n"
1801 "layout (location = 1) in vec4 inColor;\n"
Cody Northrop74a2d2c2015-06-16 17:32:04 -06001802 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001803 "void main() {\n"
1804 " outColor = inColor;\n"
1805 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001806 " gl_Position.y = -gl_Position.y;\n"
1807 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001808 "}\n";
1809
1810 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001811 "#version 140\n"
1812 "#extension GL_ARB_separate_shader_objects : enable\n"
1813 "#extension GL_ARB_shading_language_420pack : enable\n"
1814 "layout (location = 0) in vec4 color;\n"
1815 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001816 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001817 " outColor = color;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001818 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001819 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001820
Tony Barbourf43b6982014-11-25 13:18:32 -07001821 glm::mat4 View = glm::lookAt(
1822 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1823 glm::vec3(0,0,0), // and looks at the origin
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001824 glm::vec3(0,-1,0) // Head is up (set to 0,-1,0 to look upside-down)
Tony Barbourf43b6982014-11-25 13:18:32 -07001825 );
1826
1827 glm::mat4 Model = glm::mat4(1.0f);
1828
1829 glm::mat4 MVP = Projection * View * Model;
1830
1831 ASSERT_NO_FATAL_FAILURE(InitState());
1832 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour8bef8ee2015-05-22 09:44:58 -06001833 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07001834
Tony Barbour01999182015-04-09 12:58:51 -06001835 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 -07001836 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1837
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001838 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07001839
Tony Barbour01999182015-04-09 12:58:51 -06001840 VkConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1841 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1842 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001843
Tony Barbour01999182015-04-09 12:58:51 -06001844 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001845 pipelineobj.AddShader(&vs);
1846 pipelineobj.AddShader(&ps);
1847
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001848 VkPipelineDsStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001849 ds_state.depthTestEnable = VK_TRUE;
1850 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06001851 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001852 ds_state.depthBoundsEnable = VK_FALSE;
1853 ds_state.stencilTestEnable = VK_FALSE;
1854 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
1855 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
1856 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06001857 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
1858 ds_state.format = VK_FORMAT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001859 ds_state.front = ds_state.back;
1860 pipelineobj.SetDepthStencil(&ds_state);
1861
Tony Barbour01999182015-04-09 12:58:51 -06001862 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001863 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001864
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001865#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001866 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001867 MESH_BUF_ID, // Binding ID
1868 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001869 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001870 };
Tony Barbourf43b6982014-11-25 13:18:32 -07001871
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001872 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001873 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1874 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001875 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001876 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1877 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1878 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001879 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001880 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001881
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001882 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001883 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001884 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001885
Tony Barbour17c6ab12015-03-27 17:03:18 -06001886 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour17c6ab12015-03-27 17:03:18 -06001887
Tony Barbour01999182015-04-09 12:58:51 -06001888 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -07001889 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001890
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001891 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001892 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001893
Tony Barboure4ed9942015-01-09 10:06:53 -07001894 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1895#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001896 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barboure4ed9942015-01-09 10:06:53 -07001897 pDSDumpDot((char*)"triTest2.dot");
1898#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001899
1900 // render triangles
Tony Barboure4ed9942015-01-09 10:06:53 -07001901 cmdBuffer.Draw(0, 36, 0, 1);
1902
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001903
Tony Barboure4ed9942015-01-09 10:06:53 -07001904 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001905 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001906 cmdBuffer.QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -07001907
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001908 RecordImages(m_renderTargets);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001909}
1910
Tony Barbour01999182015-04-09 12:58:51 -06001911TEST_F(VkRenderTest, VSTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07001912{
1913 // The expected result from this test is a green and red triangle;
1914 // one red vertex on the left, two green vertices on the right.
1915 static const char *vertShaderText =
Cody Northrop74a2d2c2015-06-16 17:32:04 -06001916 "#version 140\n"
1917 "#extension GL_ARB_separate_shader_objects : enable\n"
1918 "#extension GL_ARB_shading_language_420pack : enable\n"
1919 "layout (location = 0) out vec4 texColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001920 "uniform sampler2D surface;\n"
1921 "void main() {\n"
1922 " vec2 vertices[3];"
1923 " vertices[0] = vec2(-0.5, -0.5);\n"
1924 " vertices[1] = vec2( 0.5, -0.5);\n"
1925 " vertices[2] = vec2( 0.5, 0.5);\n"
1926 " vec2 positions[3];"
1927 " positions[0] = vec2( 0.0, 0.0);\n"
1928 " positions[1] = vec2( 0.25, 0.1);\n"
1929 " positions[2] = vec2( 0.1, 0.25);\n"
1930 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1931 " texColor = textureLod(surface, samplePos, 0.0);\n"
1932 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1933 "}\n";
1934
1935 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001936 "#version 140\n"
1937 "#extension GL_ARB_separate_shader_objects : enable\n"
1938 "#extension GL_ARB_shading_language_420pack : enable\n"
1939 "layout (location = 0) in vec4 texColor;\n"
1940 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001941 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001942 " outColor = texColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001943 "}\n";
1944
1945 ASSERT_NO_FATAL_FAILURE(InitState());
1946 ASSERT_NO_FATAL_FAILURE(InitViewport());
1947
Tony Barbour01999182015-04-09 12:58:51 -06001948 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1949 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
1950 VkSamplerObj sampler(m_device);
1951 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001952
Tony Barbour01999182015-04-09 12:58:51 -06001953 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001954 pipelineobj.AddShader(&vs);
1955 pipelineobj.AddShader(&ps);
1956
Tony Barbour01999182015-04-09 12:58:51 -06001957 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001958 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001959
Tony Barbourdd4c9642015-01-09 12:55:14 -07001960 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001961 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001962 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001963
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001964 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001965
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001966 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001967
1968#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001969 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001970 pDSDumpDot((char*)"triTest2.dot");
1971#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001972
Tony Barbourdd4c9642015-01-09 12:55:14 -07001973 // render triangle
1974 cmdBuffer.Draw(0, 3, 0, 1);
1975
1976 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001977 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001978 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001979
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001980 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001981}
GregFd6ebdb32015-06-03 18:40:50 -06001982
1983
1984
Tony Barbour01999182015-04-09 12:58:51 -06001985TEST_F(VkRenderTest, TexturedTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07001986{
1987 // The expected result from this test is a red and green checkered triangle
1988 static const char *vertShaderText =
1989 "#version 140\n"
1990 "#extension GL_ARB_separate_shader_objects : enable\n"
1991 "#extension GL_ARB_shading_language_420pack : enable\n"
1992 "layout (location = 0) out vec2 samplePos;\n"
1993 "void main() {\n"
1994 " vec2 vertices[3];"
1995 " vertices[0] = vec2(-0.5, -0.5);\n"
1996 " vertices[1] = vec2( 0.5, -0.5);\n"
1997 " vertices[2] = vec2( 0.5, 0.5);\n"
1998 " vec2 positions[3];"
1999 " positions[0] = vec2( 0.0, 0.0);\n"
2000 " positions[1] = vec2( 1.0, 0.0);\n"
2001 " positions[2] = vec2( 1.0, 1.0);\n"
2002 " samplePos = positions[gl_VertexID % 3];\n"
2003 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2004 "}\n";
2005
2006 static const char *fragShaderText =
2007 "#version 140\n"
2008 "#extension GL_ARB_separate_shader_objects : enable\n"
2009 "#extension GL_ARB_shading_language_420pack : enable\n"
2010 "layout (location = 0) in vec2 samplePos;\n"
2011 "layout (binding = 0) uniform sampler2D surface;\n"
2012 "layout (location=0) out vec4 outColor;\n"
2013 "void main() {\n"
2014 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2015 " outColor = texColor;\n"
2016 "}\n";
2017
2018 ASSERT_NO_FATAL_FAILURE(InitState());
2019 ASSERT_NO_FATAL_FAILURE(InitViewport());
2020
Tony Barbour01999182015-04-09 12:58:51 -06002021 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2022 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2023 VkSamplerObj sampler(m_device);
2024 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002025
Tony Barbour01999182015-04-09 12:58:51 -06002026 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002027 pipelineobj.AddShader(&vs);
2028 pipelineobj.AddShader(&ps);
2029
Tony Barbour01999182015-04-09 12:58:51 -06002030 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002031 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002032
Tony Barbourdd4c9642015-01-09 12:55:14 -07002033 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002034 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002035 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2036
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002037 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002038
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002039 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002040
2041#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002042 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002043 pDSDumpDot((char*)"triTest2.dot");
2044#endif
2045 // render triangle
2046 cmdBuffer.Draw(0, 3, 0, 1);
2047
2048 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002049 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002050 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002051
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002052 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002053}
Tony Barbour01999182015-04-09 12:58:51 -06002054TEST_F(VkRenderTest, TexturedTriangleClip)
Tony Barbourf43b6982014-11-25 13:18:32 -07002055{
2056 // The expected result from this test is a red and green checkered triangle
2057 static const char *vertShaderText =
2058 "#version 330\n"
2059 "#extension GL_ARB_separate_shader_objects : enable\n"
2060 "#extension GL_ARB_shading_language_420pack : enable\n"
2061 "layout (location = 0) out vec2 samplePos;\n"
2062 "out gl_PerVertex {\n"
2063 " vec4 gl_Position;\n"
2064 " float gl_ClipDistance[1];\n"
2065 "};\n"
2066 "void main() {\n"
2067 " vec2 vertices[3];"
2068 " vertices[0] = vec2(-0.5, -0.5);\n"
2069 " vertices[1] = vec2( 0.5, -0.5);\n"
2070 " vertices[2] = vec2( 0.5, 0.5);\n"
2071 " vec2 positions[3];"
2072 " positions[0] = vec2( 0.0, 0.0);\n"
2073 " positions[1] = vec2( 1.0, 0.0);\n"
2074 " positions[2] = vec2( 1.0, 1.0);\n"
2075 " float dists[3];\n"
2076 " dists[0] = 1.0;\n"
2077 " dists[1] = 1.0;\n"
2078 " dists[2] = -1.0;\n"
2079 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2080 " samplePos = positions[gl_VertexID % 3];\n"
2081 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2082 "}\n";
2083
2084 static const char *fragShaderText =
2085 "#version 140\n"
2086 "#extension GL_ARB_separate_shader_objects : enable\n"
2087 "#extension GL_ARB_shading_language_420pack : enable\n"
2088 "layout (location = 0) in vec2 samplePos;\n"
2089 "layout (binding = 0) uniform sampler2D surface;\n"
2090 "layout (location=0) out vec4 outColor;\n"
2091 "void main() {\n"
2092 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2093 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2094 " outColor = texColor;\n"
2095 "}\n";
2096
2097
2098 ASSERT_NO_FATAL_FAILURE(InitState());
2099 ASSERT_NO_FATAL_FAILURE(InitViewport());
2100
Tony Barbour01999182015-04-09 12:58:51 -06002101 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2102 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2103 VkSamplerObj sampler(m_device);
2104 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002105
Tony Barbour01999182015-04-09 12:58:51 -06002106 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002107 pipelineobj.AddShader(&vs);
2108 pipelineobj.AddShader(&ps);
2109
Tony Barbour01999182015-04-09 12:58:51 -06002110 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002111 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002112
Tony Barbourdd4c9642015-01-09 12:55:14 -07002113 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002114 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002115 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2116
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002117 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002118
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002119 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002120
2121#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002122 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002123 pDSDumpDot((char*)"triTest2.dot");
2124#endif
2125 // render triangle
2126 cmdBuffer.Draw(0, 3, 0, 1);
2127
2128 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002129 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002130 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002131
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002132 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002133}
GregFd6ebdb32015-06-03 18:40:50 -06002134
Tony Barbour01999182015-04-09 12:58:51 -06002135TEST_F(VkRenderTest, FSTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002136{
2137 // The expected result from this test is a red and green checkered triangle
2138 static const char *vertShaderText =
2139 "#version 140\n"
2140 "#extension GL_ARB_separate_shader_objects : enable\n"
2141 "#extension GL_ARB_shading_language_420pack : enable\n"
2142 "layout (location = 0) out vec2 samplePos;\n"
2143 "void main() {\n"
2144 " vec2 vertices[3];"
2145 " vertices[0] = vec2(-0.5, -0.5);\n"
2146 " vertices[1] = vec2( 0.5, -0.5);\n"
2147 " vertices[2] = vec2( 0.5, 0.5);\n"
2148 " vec2 positions[3];"
2149 " positions[0] = vec2( 0.0, 0.0);\n"
2150 " positions[1] = vec2( 1.0, 0.0);\n"
2151 " positions[2] = vec2( 1.0, 1.0);\n"
2152 " samplePos = positions[gl_VertexID % 3];\n"
2153 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2154 "}\n";
2155
2156 static const char *fragShaderText =
2157 "#version 140\n"
2158 "#extension GL_ARB_separate_shader_objects : enable\n"
2159 "#extension GL_ARB_shading_language_420pack : enable\n"
2160 "layout (location = 0) in vec2 samplePos;\n"
2161 "layout (binding = 0) uniform sampler2D surface;\n"
2162 "layout (location=0) out vec4 outColor;\n"
2163 "void main() {\n"
2164 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2165 " outColor = texColor;\n"
2166 "}\n";
2167
2168 ASSERT_NO_FATAL_FAILURE(InitState());
2169 ASSERT_NO_FATAL_FAILURE(InitViewport());
2170
Tony Barbour01999182015-04-09 12:58:51 -06002171 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2172 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2173 VkSamplerObj sampler(m_device);
2174 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002175
Tony Barbour01999182015-04-09 12:58:51 -06002176 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002177 pipelineobj.AddShader(&vs);
2178 pipelineobj.AddShader(&ps);
2179
Tony Barbour01999182015-04-09 12:58:51 -06002180 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002181 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002182
Tony Barbourdd4c9642015-01-09 12:55:14 -07002183 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002184 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002185 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2186
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002187 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002188
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002189 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002190
2191#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002192 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002193 pDSDumpDot((char*)"triTest2.dot");
2194#endif
2195 // render triangle
2196 cmdBuffer.Draw(0, 3, 0, 1);
2197
2198 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002199 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002200 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002201
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002202 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002203}
Tony Barbour01999182015-04-09 12:58:51 -06002204TEST_F(VkRenderTest, SamplerBindingsTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002205{
2206 // This test sets bindings on the samplers
2207 // For now we are asserting that sampler and texture pairs
2208 // march in lock step, and are set via GLSL binding. This can
2209 // and will probably change.
2210 // The sampler bindings should match the sampler and texture slot
2211 // number set up by the application.
2212 // This test will result in a blue triangle
2213 static const char *vertShaderText =
2214 "#version 140\n"
2215 "#extension GL_ARB_separate_shader_objects : enable\n"
2216 "#extension GL_ARB_shading_language_420pack : enable\n"
2217 "layout (location = 0) out vec4 samplePos;\n"
2218 "void main() {\n"
2219 " vec2 vertices[3];"
2220 " vertices[0] = vec2(-0.5, -0.5);\n"
2221 " vertices[1] = vec2( 0.5, -0.5);\n"
2222 " vertices[2] = vec2( 0.5, 0.5);\n"
2223 " vec2 positions[3];"
2224 " positions[0] = vec2( 0.0, 0.0);\n"
2225 " positions[1] = vec2( 1.0, 0.0);\n"
2226 " positions[2] = vec2( 1.0, 1.0);\n"
2227 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2228 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2229 "}\n";
2230
2231 static const char *fragShaderText =
2232 "#version 140\n"
2233 "#extension GL_ARB_separate_shader_objects : enable\n"
2234 "#extension GL_ARB_shading_language_420pack : enable\n"
2235 "layout (location = 0) in vec4 samplePos;\n"
2236 "layout (binding = 0) uniform sampler2D surface0;\n"
2237 "layout (binding = 1) uniform sampler2D surface1;\n"
2238 "layout (binding = 12) uniform sampler2D surface2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06002239 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002240 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002241 " outColor = textureLod(surface2, samplePos.xy, 0.0);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002242 "}\n";
2243
2244 ASSERT_NO_FATAL_FAILURE(InitState());
2245 ASSERT_NO_FATAL_FAILURE(InitViewport());
2246
Tony Barbour01999182015-04-09 12:58:51 -06002247 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2248 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002249
Tony Barbour01999182015-04-09 12:58:51 -06002250 VkSamplerObj sampler1(m_device);
2251 VkSamplerObj sampler2(m_device);
2252 VkSamplerObj sampler3(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002253
Tony Barbour2f421a02015-04-01 16:38:10 -06002254 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
Tony Barbour01999182015-04-09 12:58:51 -06002255 VkTextureObj texture1(m_device, tex_colors); // Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002256 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
Tony Barbour01999182015-04-09 12:58:51 -06002257 VkTextureObj texture2(m_device, tex_colors); // Green
Tony Barbour2f421a02015-04-01 16:38:10 -06002258 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
Tony Barbour01999182015-04-09 12:58:51 -06002259 VkTextureObj texture3(m_device, tex_colors); // Blue
Tony Barbourf43b6982014-11-25 13:18:32 -07002260
Tony Barbour01999182015-04-09 12:58:51 -06002261 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002262 pipelineobj.AddShader(&vs);
2263 pipelineobj.AddShader(&ps);
2264
Tony Barbour01999182015-04-09 12:58:51 -06002265 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002266 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2267 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2268 for (int i = 0; i < 10; i++)
2269 descriptorSet.AppendDummy();
2270 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002271
Tony Barbourdd4c9642015-01-09 12:55:14 -07002272 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002273 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002274 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2275
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002276 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002277
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002278 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002279
2280#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002281 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002282 pDSDumpDot((char*)"triTest2.dot");
2283#endif
2284 // render triangle
2285 cmdBuffer.Draw(0, 3, 0, 1);
2286
2287 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002288 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002289 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002290
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002291 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002292}
2293
Tony Barbour01999182015-04-09 12:58:51 -06002294TEST_F(VkRenderTest, TriangleVSUniformBlock)
Tony Barbourf43b6982014-11-25 13:18:32 -07002295{
2296 // The expected result from this test is a blue triangle
2297
2298 static const char *vertShaderText =
2299 "#version 140\n"
2300 "#extension GL_ARB_separate_shader_objects : enable\n"
2301 "#extension GL_ARB_shading_language_420pack : enable\n"
2302 "layout (location = 0) out vec4 outColor;\n"
2303 "layout (std140, binding = 0) uniform bufferVals {\n"
2304 " vec4 red;\n"
2305 " vec4 green;\n"
2306 " vec4 blue;\n"
2307 " vec4 white;\n"
2308 "} myBufferVals;\n"
2309 "void main() {\n"
2310 " vec2 vertices[3];"
2311 " vertices[0] = vec2(-0.5, -0.5);\n"
2312 " vertices[1] = vec2( 0.5, -0.5);\n"
2313 " vertices[2] = vec2( 0.5, 0.5);\n"
2314 " outColor = myBufferVals.blue;\n"
2315 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2316 "}\n";
2317
2318 static const char *fragShaderText =
2319 "#version 140\n"
2320 "#extension GL_ARB_separate_shader_objects : enable\n"
2321 "#extension GL_ARB_shading_language_420pack : enable\n"
2322 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -06002323 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002324 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002325 " outColor = inColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002326 "}\n";
2327
2328 ASSERT_NO_FATAL_FAILURE(InitState());
2329 ASSERT_NO_FATAL_FAILURE(InitViewport());
2330
Tony Barbour01999182015-04-09 12:58:51 -06002331 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2332 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002333
2334 // Let's populate our buffer with the following:
2335 // vec4 red;
2336 // vec4 green;
2337 // vec4 blue;
2338 // vec4 white;
2339 const int valCount = 4 * 4;
2340 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2341 0.0, 1.0, 0.0, 1.0,
2342 0.0, 0.0, 1.0, 1.0,
2343 1.0, 1.0, 1.0, 1.0 };
2344
Tony Barbour01999182015-04-09 12:58:51 -06002345 VkConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002346
Tony Barbour01999182015-04-09 12:58:51 -06002347 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002348 pipelineobj.AddShader(&vs);
2349 pipelineobj.AddShader(&ps);
2350
Tony Barbour01999182015-04-09 12:58:51 -06002351 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002352 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002353
Tony Barbourdd4c9642015-01-09 12:55:14 -07002354 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002355 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002356 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2357
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002358 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002359
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002360 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002361
2362#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002363 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002364 pDSDumpDot((char*)"triTest2.dot");
2365#endif
2366 // render triangle
2367 cmdBuffer.Draw(0, 3, 0, 1);
2368
2369 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002370 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002371 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002372
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002373 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002374}
2375
Tony Barbour01999182015-04-09 12:58:51 -06002376TEST_F(VkRenderTest, TriangleFSUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002377{
2378 // This test allows the shader to select which buffer it is
2379 // pulling from using layout binding qualifier.
2380 // There are corresponding changes in the compiler stack that
2381 // will select the buffer using binding directly.
2382 // The binding number should match the slot number set up by
2383 // the application.
2384 // The expected result from this test is a purple triangle
2385
2386 static const char *vertShaderText =
2387 "#version 140\n"
2388 "#extension GL_ARB_separate_shader_objects : enable\n"
2389 "#extension GL_ARB_shading_language_420pack : enable\n"
2390 "void main() {\n"
2391 " vec2 vertices[3];"
2392 " vertices[0] = vec2(-0.5, -0.5);\n"
2393 " vertices[1] = vec2( 0.5, -0.5);\n"
2394 " vertices[2] = vec2( 0.5, 0.5);\n"
2395 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2396 "}\n";
2397
2398 static const char *fragShaderText =
2399 "#version 140\n"
2400 "#extension GL_ARB_separate_shader_objects : enable\n"
2401 "#extension GL_ARB_shading_language_420pack : enable\n"
2402 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2403 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2404 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002405 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
GregFd6ebdb32015-06-03 18:40:50 -06002406 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002407 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002408 " outColor = myBlueVal.color;\n"
2409 " outColor += myRedVal.color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002410 "}\n";
2411
2412 ASSERT_NO_FATAL_FAILURE(InitState());
2413 ASSERT_NO_FATAL_FAILURE(InitViewport());
2414
Tony Barbour01999182015-04-09 12:58:51 -06002415 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2416 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002417
2418 // We're going to create a number of uniform buffers, and then allow
2419 // the shader to select which it wants to read from with a binding
2420
2421 // Let's populate the buffers with a single color each:
2422 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2423 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2424 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002425 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002426
2427 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2428 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2429 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2430 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2431
2432 const int redCount = sizeof(redVals) / sizeof(float);
2433 const int greenCount = sizeof(greenVals) / sizeof(float);
2434 const int blueCount = sizeof(blueVals) / sizeof(float);
2435 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2436
Tony Barbour01999182015-04-09 12:58:51 -06002437 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002438
Tony Barbour01999182015-04-09 12:58:51 -06002439 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002440
Tony Barbour01999182015-04-09 12:58:51 -06002441 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002442
Tony Barbour01999182015-04-09 12:58:51 -06002443 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002444
Tony Barbour01999182015-04-09 12:58:51 -06002445 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002446 pipelineobj.AddShader(&vs);
2447 pipelineobj.AddShader(&ps);
2448
Tony Barbour01999182015-04-09 12:58:51 -06002449 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002450 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2451 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2452 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2453 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002454
Tony Barbourdd4c9642015-01-09 12:55:14 -07002455 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002456 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002457 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002458
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002459 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002460
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002461 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002462
2463#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002464 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002465 pDSDumpDot((char*)"triTest2.dot");
2466#endif
2467 // render triangle
2468 cmdBuffer.Draw(0, 3, 0, 1);
2469
2470 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002471 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002472 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002473
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002474 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002475}
2476
Tony Barbour01999182015-04-09 12:58:51 -06002477TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002478{
2479 // This test is the same as TriangleFSUniformBlockBinding, but
2480 // it does not provide an instance name.
2481 // The expected result from this test is a purple triangle
2482
2483 static const char *vertShaderText =
2484 "#version 140\n"
2485 "#extension GL_ARB_separate_shader_objects : enable\n"
2486 "#extension GL_ARB_shading_language_420pack : enable\n"
2487 "void main() {\n"
2488 " vec2 vertices[3];"
2489 " vertices[0] = vec2(-0.5, -0.5);\n"
2490 " vertices[1] = vec2( 0.5, -0.5);\n"
2491 " vertices[2] = vec2( 0.5, 0.5);\n"
2492 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2493 "}\n";
2494
2495 static const char *fragShaderText =
2496 "#version 430\n"
2497 "#extension GL_ARB_separate_shader_objects : enable\n"
2498 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002499 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2500 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2501 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002502 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002503 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002504 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002505 " outColor = blue;\n"
2506 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002507 "}\n";
2508 ASSERT_NO_FATAL_FAILURE(InitState());
2509 ASSERT_NO_FATAL_FAILURE(InitViewport());
2510
Tony Barbour01999182015-04-09 12:58:51 -06002511 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2512 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002513
2514 // We're going to create a number of uniform buffers, and then allow
2515 // the shader to select which it wants to read from with a binding
2516
2517 // Let's populate the buffers with a single color each:
2518 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2519 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2520 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2521 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2522
2523 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2524 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2525 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2526 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2527
2528 const int redCount = sizeof(redVals) / sizeof(float);
2529 const int greenCount = sizeof(greenVals) / sizeof(float);
2530 const int blueCount = sizeof(blueVals) / sizeof(float);
2531 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2532
Tony Barbour01999182015-04-09 12:58:51 -06002533 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002534
Tony Barbour01999182015-04-09 12:58:51 -06002535 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002536
Tony Barbour01999182015-04-09 12:58:51 -06002537 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002538
Tony Barbour01999182015-04-09 12:58:51 -06002539 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002540
Tony Barbour01999182015-04-09 12:58:51 -06002541 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002542 pipelineobj.AddShader(&vs);
2543 pipelineobj.AddShader(&ps);
2544
Tony Barbour01999182015-04-09 12:58:51 -06002545 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002546 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2547 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2548 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2549 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002550
Tony Barbourdd4c9642015-01-09 12:55:14 -07002551 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002552 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002553 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2554
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002555 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002556
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002557 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002558
2559#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002560 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002561 pDSDumpDot((char*)"triTest2.dot");
2562#endif
2563 // render triangle
2564 cmdBuffer.Draw(0, 3, 0, 1);
2565
2566 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002567 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002568 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002569
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002570 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002571}
2572
GregF54a32172015-07-01 16:11:09 -06002573TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBindingWithStruct)
2574{
2575 // This test is the same as TriangleFSUniformBlockBinding, but
2576 // it does not provide an instance name.
2577 // The expected result from this test is a purple triangle
2578
2579 static const char *vertShaderText =
2580 "#version 140\n"
2581 "#extension GL_ARB_separate_shader_objects : enable\n"
2582 "#extension GL_ARB_shading_language_420pack : enable\n"
2583 "void main() {\n"
2584 " vec2 vertices[3];"
2585 " vertices[0] = vec2(-0.5, -0.5);\n"
2586 " vertices[1] = vec2( 0.5, -0.5);\n"
2587 " vertices[2] = vec2( 0.5, 0.5);\n"
2588 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2589 "}\n";
2590
2591 static const char *fragShaderText =
2592 "#version 430\n"
2593 "#extension GL_ARB_separate_shader_objects : enable\n"
2594 "#extension GL_ARB_shading_language_420pack : enable\n"
2595 "\n"
2596 " struct PS_INPUT {\n"
2597 " vec2 member0;\n"
2598 " vec4 member1;\n"
2599 " vec4 member2;\n"
2600 " vec4 member3;\n"
2601 " vec4 member4;\n"
2602 " vec4 member5;\n"
2603 " vec4 member6;\n"
2604 " vec4 member7;\n"
2605 " vec4 member8;\n"
2606 " vec4 member9;\n"
2607 " };\n"
2608 "\n"
2609 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2610 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2611 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2612 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
2613 "layout (location = 0) out vec4 outColor;\n"
2614 "PS_INPUT MainFs()\n"
2615 "{\n"
2616 " PS_INPUT o;\n"
2617 " o.member9 = red;\n"
2618 " return o;\n"
2619 "}\n"
2620 "\n"
2621 "void main()\n"
2622 "{\n"
2623 " PS_INPUT o;\n"
2624 " o = MainFs();\n"
2625 " outColor = blue;"
2626 " outColor += o.member9;\n"
2627 "}\n";;
2628 ASSERT_NO_FATAL_FAILURE(InitState());
2629 ASSERT_NO_FATAL_FAILURE(InitViewport());
2630
2631 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2632 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2633
2634 // We're going to create a number of uniform buffers, and then allow
2635 // the shader to select which it wants to read from with a binding
2636
2637 // Let's populate the buffers with a single color each:
2638 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2639 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2640 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2641 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2642
2643 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2644 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2645 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2646 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2647
2648 const int redCount = sizeof(redVals) / sizeof(float);
2649 const int greenCount = sizeof(greenVals) / sizeof(float);
2650 const int blueCount = sizeof(blueVals) / sizeof(float);
2651 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2652
2653 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2654
2655 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2656
2657 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2658
2659 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
2660
2661 VkPipelineObj pipelineobj(m_device);
2662 pipelineobj.AddShader(&vs);
2663 pipelineobj.AddShader(&ps);
2664
2665 VkDescriptorSetObj descriptorSet(m_device);
2666 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2667 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2668 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2669 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
2670
2671 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2672 VkCommandBufferObj cmdBuffer(m_device);
2673 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2674
2675 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
2676
2677 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
2678
2679#ifdef DUMP_STATE_DOT
2680 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
2681 pDSDumpDot((char*)"triTest2.dot");
2682#endif
2683 // render triangle
2684 cmdBuffer.Draw(0, 3, 0, 1);
2685
2686 // finalize recording of the command buffer
2687 EndCommandBuffer(cmdBuffer);
2688 cmdBuffer.QueueCommandBuffer();
2689
2690 RecordImages(m_renderTargets);
2691}
2692
Tony Barbour01999182015-04-09 12:58:51 -06002693TEST_F(VkRenderTest, CubeWithVertexFetchAndMVPAndTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07002694{
2695 static const char *vertShaderText =
2696 "#version 140\n"
2697 "#extension GL_ARB_separate_shader_objects : enable\n"
2698 "#extension GL_ARB_shading_language_420pack : enable\n"
2699 "layout (std140, binding=0) uniform bufferVals {\n"
2700 " mat4 mvp;\n"
2701 "} myBufferVals;\n"
2702 "layout (location=0) in vec4 pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002703 "layout (location=1) in vec2 input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002704 "layout (location=0) out vec2 UV;\n"
2705 "void main() {\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002706 " UV = input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002707 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002708 " gl_Position.y = -gl_Position.y;\n"
2709 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002710 "}\n";
2711
2712 static const char *fragShaderText =
2713 "#version 140\n"
2714 "#extension GL_ARB_separate_shader_objects : enable\n"
2715 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002716 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002717 "layout (location=0) out vec4 outColor;\n"
2718 "layout (location=0) in vec2 UV;\n"
2719 "void main() {\n"
2720 " outColor= textureLod(surface, UV, 0.0);\n"
2721 "}\n";
2722 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2723
2724 glm::mat4 View = glm::lookAt(
2725 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2726 glm::vec3(0,0,0), // and looks at the origin
2727 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2728 );
2729
2730 glm::mat4 Model = glm::mat4(1.0f);
2731
2732 glm::mat4 MVP = Projection * View * Model;
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002733 int num_verts = sizeof(g_vb_texture_Data) / sizeof(g_vb_texture_Data[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002734
2735
2736 ASSERT_NO_FATAL_FAILURE(InitState());
2737 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour8bef8ee2015-05-22 09:44:58 -06002738 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07002739
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002740 VkConstantBufferObj meshBuffer(m_device, num_verts,
2741 sizeof(g_vb_texture_Data[0]), g_vb_texture_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002742 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002743
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002744 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07002745
Tony Barbour01999182015-04-09 12:58:51 -06002746 VkConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2747 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2748 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2749 VkSamplerObj sampler(m_device);
2750 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002751
Tony Barbour01999182015-04-09 12:58:51 -06002752 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002753 pipelineobj.AddShader(&vs);
2754 pipelineobj.AddShader(&ps);
2755
Tony Barbour01999182015-04-09 12:58:51 -06002756 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002757 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mvpBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002758 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002759
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002760#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002761 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002762 MESH_BIND_ID, // binding ID
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002763 sizeof(g_vb_texture_Data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002764 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002765 };
Tony Barbourf43b6982014-11-25 13:18:32 -07002766
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002767 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002768 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2769 vi_attribs[0].location = 0; // location
Tony Barbour8205d902015-04-16 15:59:00 -06002770 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002771 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2772 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2773 vi_attribs[1].location = 1; // location
2774 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
2775 vi_attribs[1].offsetInBytes = 16; // Offset of uv components
Tony Barbourf43b6982014-11-25 13:18:32 -07002776
Tony Barbourf43b6982014-11-25 13:18:32 -07002777 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002778 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2779 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07002780
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002781 VkPipelineDsStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002782 ds_state.depthTestEnable = VK_TRUE;
2783 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06002784 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002785 ds_state.depthBoundsEnable = VK_FALSE;
2786 ds_state.stencilTestEnable = VK_FALSE;
2787 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
2788 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
2789 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06002790 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
2791 ds_state.format = VK_FORMAT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002792 ds_state.front = ds_state.back;
2793 pipelineobj.SetDepthStencil(&ds_state);
2794
Tony Barbour17c6ab12015-03-27 17:03:18 -06002795 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour01999182015-04-09 12:58:51 -06002796 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002797 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002798
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002799 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002800
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002801 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002802
2803 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2804#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002805 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002806 pDSDumpDot((char*)"triTest2.dot");
2807#endif
2808 // render triangle
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002809 cmdBuffer.Draw(0, num_verts, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002810
2811 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002812 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002813 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002814
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002815 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002816 RotateTriangleVSUniform(Projection, View, Model, &mvpBuffer, &cmdBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002817}
Cody Northropd1ce7842014-12-09 11:17:01 -07002818
Tony Barbour01999182015-04-09 12:58:51 -06002819TEST_F(VkRenderTest, TriangleMixedSamplerUniformBlockBinding)
Cody Northropd1ce7842014-12-09 11:17:01 -07002820{
2821 // This test mixes binding slots of textures and buffers, ensuring
2822 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002823 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002824 // you can modify it to move the desired result around.
2825
2826 static const char *vertShaderText =
2827 "#version 140\n"
2828 "#extension GL_ARB_separate_shader_objects : enable\n"
2829 "#extension GL_ARB_shading_language_420pack : enable\n"
2830 "void main() {\n"
2831 " vec2 vertices[3];"
2832 " vertices[0] = vec2(-0.5, -0.5);\n"
2833 " vertices[1] = vec2( 0.5, -0.5);\n"
2834 " vertices[2] = vec2( 0.5, 0.5);\n"
2835 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2836 "}\n";
2837
2838 static const char *fragShaderText =
2839 "#version 430\n"
2840 "#extension GL_ARB_separate_shader_objects : enable\n"
2841 "#extension GL_ARB_shading_language_420pack : enable\n"
2842 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002843 "layout (binding = 3) uniform sampler2D surface1;\n"
2844 "layout (binding = 1) uniform sampler2D surface2;\n"
2845 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002846
Cody Northropa0410942014-12-09 13:59:39 -07002847
Chia-I Wuf8385062015-01-04 16:27:24 +08002848 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2849 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2850 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2851 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002852 "layout (location = 0) out vec4 outColor;\n"
2853 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002854 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002855 " outColor += white * vec4(0.00001);\n"
2856 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002857 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002858 "}\n";
2859 ASSERT_NO_FATAL_FAILURE(InitState());
2860 ASSERT_NO_FATAL_FAILURE(InitViewport());
2861
Tony Barbour01999182015-04-09 12:58:51 -06002862 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2863 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northropd1ce7842014-12-09 11:17:01 -07002864
Cody Northropd1ce7842014-12-09 11:17:01 -07002865 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2866 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2867 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2868 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2869
2870 const int redCount = sizeof(redVals) / sizeof(float);
2871 const int greenCount = sizeof(greenVals) / sizeof(float);
2872 const int blueCount = sizeof(blueVals) / sizeof(float);
2873 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2874
Tony Barbour01999182015-04-09 12:58:51 -06002875 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2876 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2877 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2878 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002879
Tony Barbour2f421a02015-04-01 16:38:10 -06002880 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002881 VkSamplerObj sampler0(m_device);
2882 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002883 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002884 VkSamplerObj sampler2(m_device);
2885 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002886 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002887 VkSamplerObj sampler4(m_device);
2888 VkTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropa0410942014-12-09 13:59:39 -07002889
2890 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2891 // TODO: Get back here ASAP and understand why.
Tony Barbour2f421a02015-04-01 16:38:10 -06002892 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06002893 VkSamplerObj sampler7(m_device);
2894 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropd1ce7842014-12-09 11:17:01 -07002895
Tony Barbour01999182015-04-09 12:58:51 -06002896 VkPipelineObj pipelineobj(m_device);
Cody Northropd1ce7842014-12-09 11:17:01 -07002897 pipelineobj.AddShader(&vs);
2898 pipelineobj.AddShader(&ps);
2899
Tony Barbour01999182015-04-09 12:58:51 -06002900 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002901 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2902 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2903 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2904 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002905 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002906 // swap blue and green
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002907 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2908 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2909 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002910
Tony Barbourdd4c9642015-01-09 12:55:14 -07002911 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002912 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002913 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002914
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002915 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002916
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002917 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002918
2919#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002920 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002921 pDSDumpDot((char*)"triTest2.dot");
2922#endif
2923 // render triangle
2924 cmdBuffer.Draw(0, 3, 0, 1);
2925
2926 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002927 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002928 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002929
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002930 RecordImages(m_renderTargets);
Cody Northropd1ce7842014-12-09 11:17:01 -07002931}
2932
Tony Barbour01999182015-04-09 12:58:51 -06002933TEST_F(VkRenderTest, TriangleMatchingSamplerUniformBlockBinding)
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002934{
2935 // This test matches binding slots of textures and buffers, requiring
2936 // the driver to give them distinct number spaces.
2937 // The expected result from this test is a red triangle, although
2938 // you can modify it to move the desired result around.
2939
2940 static const char *vertShaderText =
2941 "#version 140\n"
2942 "#extension GL_ARB_separate_shader_objects : enable\n"
2943 "#extension GL_ARB_shading_language_420pack : enable\n"
2944 "void main() {\n"
2945 " vec2 vertices[3];"
2946 " vertices[0] = vec2(-0.5, -0.5);\n"
2947 " vertices[1] = vec2( 0.5, -0.5);\n"
2948 " vertices[2] = vec2( 0.5, 0.5);\n"
2949 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2950 "}\n";
2951
2952 static const char *fragShaderText =
2953 "#version 430\n"
2954 "#extension GL_ARB_separate_shader_objects : enable\n"
2955 "#extension GL_ARB_shading_language_420pack : enable\n"
2956 "layout (binding = 0) uniform sampler2D surface0;\n"
2957 "layout (binding = 1) uniform sampler2D surface1;\n"
2958 "layout (binding = 2) uniform sampler2D surface2;\n"
2959 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002960 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2961 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2962 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2963 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002964 "layout (location = 0) out vec4 outColor;\n"
2965 "void main() {\n"
2966 " outColor = red;// * vec4(0.00001);\n"
2967 " outColor += white * vec4(0.00001);\n"
2968 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2969 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2970 "}\n";
2971 ASSERT_NO_FATAL_FAILURE(InitState());
2972 ASSERT_NO_FATAL_FAILURE(InitViewport());
2973
Tony Barbour01999182015-04-09 12:58:51 -06002974 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2975 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002976
2977 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2978 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2979 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2980 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2981
2982 const int redCount = sizeof(redVals) / sizeof(float);
2983 const int greenCount = sizeof(greenVals) / sizeof(float);
2984 const int blueCount = sizeof(blueVals) / sizeof(float);
2985 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2986
Tony Barbour01999182015-04-09 12:58:51 -06002987 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2988 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2989 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2990 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002991
Tony Barbour2f421a02015-04-01 16:38:10 -06002992 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002993 VkSamplerObj sampler0(m_device);
2994 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002995 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002996 VkSamplerObj sampler2(m_device);
2997 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002998 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002999 VkSamplerObj sampler4(m_device);
3000 VkTextureObj texture4(m_device, tex_colors); // Light Green
Tony Barbour2f421a02015-04-01 16:38:10 -06003001 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06003002 VkSamplerObj sampler7(m_device);
3003 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003004
Tony Barbour01999182015-04-09 12:58:51 -06003005 VkPipelineObj pipelineobj(m_device);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003006 pipelineobj.AddShader(&vs);
3007 pipelineobj.AddShader(&ps);
3008
Tony Barbour01999182015-04-09 12:58:51 -06003009 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08003010 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3011 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3012 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
3013 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003014 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
3015 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
3016 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
3017 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003018
Tony Barbourdd4c9642015-01-09 12:55:14 -07003019 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06003020 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07003021 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003022
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003023 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07003024
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003025 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07003026
3027#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003028 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07003029 pDSDumpDot((char*)"triTest2.dot");
3030#endif
3031 // render triangle
3032 cmdBuffer.Draw(0, 3, 0, 1);
3033
3034 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003035 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003036 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07003037
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003038 RecordImages(m_renderTargets);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003039}
3040
Tony Barbour01999182015-04-09 12:58:51 -06003041TEST_F(VkRenderTest, TriangleUniformBufferLayout)
Cody Northrop02690bd2014-12-17 15:26:33 -07003042{
3043 // This test populates a buffer with a variety of different data
3044 // types, then reads them out with a shader.
3045 // The expected result from this test is a green triangle
3046
3047 static const char *vertShaderText =
3048 "#version 140\n"
3049 "#extension GL_ARB_separate_shader_objects : enable\n"
3050 "#extension GL_ARB_shading_language_420pack : enable\n"
3051 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3052 " vec4 fRed;\n"
3053 " vec4 fGreen;\n"
3054 " layout(row_major) mat4 worldToProj;\n"
3055 " layout(row_major) mat4 projToWorld;\n"
3056 " layout(row_major) mat4 worldToView;\n"
3057 " layout(row_major) mat4 viewToProj;\n"
3058 " layout(row_major) mat4 worldToShadow[4];\n"
3059 " float fZero;\n"
3060 " float fOne;\n"
3061 " float fTwo;\n"
3062 " float fThree;\n"
3063 " vec3 fZeroZeroZero;\n"
3064 " float fFour;\n"
3065 " vec3 fZeroZeroOne;\n"
3066 " float fFive;\n"
3067 " vec3 fZeroOneZero;\n"
3068 " float fSix;\n"
3069 " float fSeven;\n"
3070 " float fEight;\n"
3071 " float fNine;\n"
3072 " vec2 fZeroZero;\n"
3073 " vec2 fZeroOne;\n"
3074 " vec4 fBlue;\n"
3075 " vec2 fOneZero;\n"
3076 " vec2 fOneOne;\n"
3077 " vec3 fZeroOneOne;\n"
3078 " float fTen;\n"
3079 " float fEleven;\n"
3080 " float fTwelve;\n"
3081 " vec3 fOneZeroZero;\n"
3082 " vec4 uvOffsets[4];\n"
3083 "};\n"
3084 "layout (location = 0) out vec4 color;"
3085 "void main() {\n"
3086
3087 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3088 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3089 " \n"
3090
3091 // do some exact comparisons, even though we should
3092 // really have an epsilon involved.
3093 " vec4 outColor = right;\n"
3094 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3095 " outColor = wrong;\n"
3096 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3097 " outColor = wrong;\n"
3098 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3099 " outColor = wrong;\n"
3100
3101 " color = outColor;\n"
3102
3103 // generic position stuff
3104 " vec2 vertices;\n"
3105 " int vertexSelector = gl_VertexID;\n"
3106 " if (vertexSelector == 0)\n"
3107 " vertices = vec2(-0.5, -0.5);\n"
3108 " else if (vertexSelector == 1)\n"
3109 " vertices = vec2( 0.5, -0.5);\n"
3110 " else if (vertexSelector == 2)\n"
3111 " vertices = vec2( 0.5, 0.5);\n"
3112 " else\n"
3113 " vertices = vec2( 0.0, 0.0);\n"
3114 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3115 "}\n";
3116
3117 static const char *fragShaderText =
3118 "#version 140\n"
3119 "#extension GL_ARB_separate_shader_objects : enable\n"
3120 "#extension GL_ARB_shading_language_420pack : enable\n"
3121 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3122 " vec4 fRed;\n"
3123 " vec4 fGreen;\n"
3124 " layout(row_major) mat4 worldToProj;\n"
3125 " layout(row_major) mat4 projToWorld;\n"
3126 " layout(row_major) mat4 worldToView;\n"
3127 " layout(row_major) mat4 viewToProj;\n"
3128 " layout(row_major) mat4 worldToShadow[4];\n"
3129 " float fZero;\n"
3130 " float fOne;\n"
3131 " float fTwo;\n"
3132 " float fThree;\n"
3133 " vec3 fZeroZeroZero;\n"
3134 " float fFour;\n"
3135 " vec3 fZeroZeroOne;\n"
3136 " float fFive;\n"
3137 " vec3 fZeroOneZero;\n"
3138 " float fSix;\n"
3139 " float fSeven;\n"
3140 " float fEight;\n"
3141 " float fNine;\n"
3142 " vec2 fZeroZero;\n"
3143 " vec2 fZeroOne;\n"
3144 " vec4 fBlue;\n"
3145 " vec2 fOneZero;\n"
3146 " vec2 fOneOne;\n"
3147 " vec3 fZeroOneOne;\n"
3148 " float fTen;\n"
3149 " float fEleven;\n"
3150 " float fTwelve;\n"
3151 " vec3 fOneZeroZero;\n"
3152 " vec4 uvOffsets[4];\n"
3153 "};\n"
3154 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003155 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop02690bd2014-12-17 15:26:33 -07003156 "void main() {\n"
3157 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3158 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3159 " \n"
3160
3161 // start with VS value to ensure it passed
3162 " vec4 outColor = color;\n"
3163
3164 // do some exact comparisons, even though we should
3165 // really have an epsilon involved.
3166 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3167 " outColor = wrong;\n"
3168 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3169 " outColor = wrong;\n"
3170 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3171 " outColor = wrong;\n"
3172 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3173 " outColor = wrong;\n"
3174 " if (fTwo != 2.0)\n"
3175 " outColor = wrong;\n"
3176 " if (fOneOne != vec2(1.0, 1.0))\n"
3177 " outColor = wrong;\n"
3178 " if (fTen != 10.0)\n"
3179 " outColor = wrong;\n"
3180 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3181 " outColor = wrong;\n"
3182 " \n"
GregFd6ebdb32015-06-03 18:40:50 -06003183 " uFragColor = outColor;\n"
Cody Northrop02690bd2014-12-17 15:26:33 -07003184 "}\n";
3185
3186
3187 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3188 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3189 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3190 0.0, 1.0, 0.0, 1.0, // align
3191 0.0, 0.0, 1.0, 1.0, // align
3192 0.0, 0.0, 0.0, 1.0, // align
3193 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3194 0.0, 2.0, 0.0, 2.0, // align
3195 0.0, 0.0, 2.0, 2.0, // align
3196 0.0, 0.0, 0.0, 2.0, // align
3197 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3198 0.0, 3.0, 0.0, 3.0, // align
3199 0.0, 0.0, 3.0, 3.0, // align
3200 0.0, 0.0, 0.0, 3.0, // align
3201 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3202 0.0, 4.0, 0.0, 4.0, // align
3203 0.0, 0.0, 4.0, 4.0, // align
3204 0.0, 0.0, 0.0, 4.0, // align
3205 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3206 0.0, 5.0, 0.0, 5.0, // align
3207 0.0, 0.0, 5.0, 5.0, // align
3208 0.0, 0.0, 0.0, 5.0, // align
3209 6.0, 0.0, 0.0, 6.0, // align
3210 0.0, 6.0, 0.0, 6.0, // align
3211 0.0, 0.0, 6.0, 6.0, // align
3212 0.0, 0.0, 0.0, 6.0, // align
3213 7.0, 0.0, 0.0, 7.0, // align
3214 0.0, 7.0, 0.0, 7.0, // align
3215 0.0, 0.0, 7.0, 7.0, // align
3216 0.0, 0.0, 0.0, 7.0, // align
3217 8.0, 0.0, 0.0, 8.0, // align
3218 0.0, 8.0, 0.0, 8.0, // align
3219 0.0, 0.0, 8.0, 8.0, // align
3220 0.0, 0.0, 0.0, 8.0, // align
3221 0.0, // float fZero; // align
3222 1.0, // float fOne; // pack
3223 2.0, // float fTwo; // pack
3224 3.0, // float fThree; // pack
3225 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3226 4.0, // float fFour; // pack
3227 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3228 5.0, // float fFive; // pack
3229 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3230 6.0, // float fSix; // pack
3231 7.0, // float fSeven; // align
3232 8.0, // float fEight; // pack
3233 9.0, // float fNine; // pack
3234 0.0, // BUFFER
3235 0.0, 0.0, // vec2 fZeroZero; // align
3236 0.0, 1.0, // vec2 fZeroOne; // pack
3237 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3238 1.0, 0.0, // vec2 fOneZero; // align
3239 1.0, 1.0, // vec2 fOneOne; // pack
3240 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3241 10.0, // float fTen; // pack
3242 11.0, // float fEleven; // align
3243 12.0, // float fTwelve; // pack
3244 0.0, 0.0, // BUFFER
3245 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3246 0.0, // BUFFER
3247 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3248 0.5, 0.6, 0.7, 0.8, // align
3249 0.9, 1.0, 1.1, 1.2, // align
3250 1.3, 1.4, 1.5, 1.6, // align
3251 };
3252
3253 ASSERT_NO_FATAL_FAILURE(InitState());
3254 ASSERT_NO_FATAL_FAILURE(InitViewport());
3255
3256 const int constCount = sizeof(mixedVals) / sizeof(float);
3257
Tony Barbour01999182015-04-09 12:58:51 -06003258 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3259 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop02690bd2014-12-17 15:26:33 -07003260
Tony Barbour01999182015-04-09 12:58:51 -06003261 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003262
Tony Barbour01999182015-04-09 12:58:51 -06003263 VkPipelineObj pipelineobj(m_device);
Cody Northrop02690bd2014-12-17 15:26:33 -07003264 pipelineobj.AddShader(&vs);
3265 pipelineobj.AddShader(&ps);
3266
Tony Barbour01999182015-04-09 12:58:51 -06003267 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003268 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003269
3270 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06003271 VkCommandBufferObj cmdBuffer(m_device);
Cody Northrop02690bd2014-12-17 15:26:33 -07003272 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3273
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003274 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Cody Northrop02690bd2014-12-17 15:26:33 -07003275
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003276 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Cody Northrop02690bd2014-12-17 15:26:33 -07003277
3278#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003279 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop02690bd2014-12-17 15:26:33 -07003280 pDSDumpDot((char*)"triTest2.dot");
3281#endif
3282 // render triangle
3283 cmdBuffer.Draw(0, 3, 0, 1);
3284
3285 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003286 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003287 cmdBuffer.QueueCommandBuffer();
Cody Northrop02690bd2014-12-17 15:26:33 -07003288
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003289 RecordImages(m_renderTargets);
Cody Northrop02690bd2014-12-17 15:26:33 -07003290}
3291
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003292TEST_F(VkRenderTest, TextureGather)
3293{
3294 // This test introduces textureGather and textureGatherOffset
3295 // Each call is compared against an expected inline color result
3296 // Green triangle means everything worked as expected
3297 // Red means something went wrong
3298
3299 // disable SPV until texture gather is turned on in LunarGLASS
Cody Northrop1cfbd172015-06-03 16:49:20 -06003300 ScopedUseGlsl useGlsl(true);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003301
3302 static const char *vertShaderText =
3303 "#version 140\n"
3304 "#extension GL_ARB_separate_shader_objects : enable\n"
3305 "#extension GL_ARB_shading_language_420pack : enable\n"
3306 "void main() {\n"
3307 " vec2 vertices[3];"
3308 " vertices[0] = vec2(-0.5, -0.5);\n"
3309 " vertices[1] = vec2( 0.5, -0.5);\n"
3310 " vertices[2] = vec2( 0.5, 0.5);\n"
3311 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
3312 "}\n";
3313
3314 static const char *fragShaderText =
3315 "#version 430\n"
3316 "#extension GL_ARB_separate_shader_objects : enable\n"
3317 "#extension GL_ARB_shading_language_420pack : enable\n"
3318 "layout (binding = 0) uniform sampler2D surface0;\n"
3319 "layout (binding = 1) uniform sampler2D surface1;\n"
3320 "layout (binding = 2) uniform sampler2D surface2;\n"
3321 "layout (binding = 3) uniform sampler2D surface3;\n"
3322 "layout (location = 0) out vec4 outColor;\n"
3323 "void main() {\n"
3324
3325 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3326 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3327
3328 " vec4 color = right;\n"
3329
3330 // Grab a normal texture sample to ensure it can work in conjuntion
3331 // with textureGather (there are some intracacies in the backend)
3332 " vec4 sampledColor = textureLod(surface2, vec2(0.5), 0.0);\n"
3333 " if (sampledColor != vec4(0.0, 0.0, 1.0, 1.0))\n"
3334 " color = wrong;\n"
3335
3336 " vec4 gatheredColor = textureGather(surface0, vec2(0.5), 0);\n"
3337 // This just grabbed four red components from a red surface
3338 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3339 " color = wrong;\n"
3340
3341 // Yes, this is using an offset of 0, we don't have enough fine grained
3342 // control of the texture contents here.
3343 " gatheredColor = textureGatherOffset(surface1, vec2(0.5), ivec2(0, 0), 1);\n"
3344 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3345 " color = wrong;\n"
3346
3347 " outColor = color;\n"
3348
3349 "}\n";
3350
3351 ASSERT_NO_FATAL_FAILURE(InitState());
3352 ASSERT_NO_FATAL_FAILURE(InitViewport());
3353
3354 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3355 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3356
3357 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
3358 VkSamplerObj sampler0(m_device);
3359 VkTextureObj texture0(m_device, tex_colors); // Red
3360 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
3361 VkSamplerObj sampler1(m_device);
3362 VkTextureObj texture1(m_device, tex_colors); // Green
3363 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
3364 VkSamplerObj sampler2(m_device);
3365 VkTextureObj texture2(m_device, tex_colors); // Blue
3366 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
3367 VkSamplerObj sampler3(m_device);
3368 VkTextureObj texture3(m_device, tex_colors); // Red and Blue
3369
3370 VkPipelineObj pipelineobj(m_device);
3371 pipelineobj.AddShader(&vs);
3372 pipelineobj.AddShader(&ps);
3373
3374 VkDescriptorSetObj descriptorSet(m_device);
3375 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3376 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
3377 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3378 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
3379
3380 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3381 VkCommandBufferObj cmdBuffer(m_device);
3382 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3383
3384 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3385
3386 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3387
3388 // render triangle
3389 cmdBuffer.Draw(0, 3, 0, 1);
3390
3391 // finalize recording of the command buffer
3392 EndCommandBuffer(cmdBuffer);
3393 cmdBuffer.QueueCommandBuffer();
3394
3395 RecordImages(m_renderTargets);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003396}
3397
Cody Northropa44c2ff2015-04-15 11:19:06 -06003398TEST_F(VkRenderTest, GeometryShaderHelloWorld)
3399{
3400 // This test introduces a geometry shader that simply
3401 // changes the color of each vertex to red, green, blue
3402
3403 static const char *vertShaderText =
3404 "#version 140\n"
3405 "#extension GL_ARB_separate_shader_objects : enable\n"
3406 "#extension GL_ARB_shading_language_420pack : enable\n"
3407 "layout (location = 0) out vec4 color;"
3408 "void main() {\n"
3409
3410 // VS writes out red
3411 " color = vec4(1.0, 0.0, 0.0, 1.0);\n"
3412
3413 // generic position stuff
3414 " vec2 vertices;\n"
3415 " int vertexSelector = gl_VertexID;\n"
3416 " if (vertexSelector == 0)\n"
3417 " vertices = vec2(-0.5, -0.5);\n"
3418 " else if (vertexSelector == 1)\n"
3419 " vertices = vec2( 0.5, -0.5);\n"
3420 " else if (vertexSelector == 2)\n"
3421 " vertices = vec2( 0.5, 0.5);\n"
3422 " else\n"
3423 " vertices = vec2( 0.0, 0.0);\n"
3424 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3425
3426 "}\n";
3427
3428 static const char *geomShaderText =
3429 "#version 330\n"
3430 "#extension GL_ARB_separate_shader_objects : enable\n"
3431 "#extension GL_ARB_shading_language_420pack : enable\n"
3432 "layout( triangles ) in;\n"
3433 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3434 "layout( location = 0 ) in vec4 inColor[3];\n"
3435 "layout( location = 0 ) out vec4 outColor;\n"
3436 "void main()\n"
3437 "{\n"
3438
3439 // first vertex, pass through red
3440 " gl_Position = gl_in[0].gl_Position;\n"
3441 " outColor = inColor[0];\n"
3442 " EmitVertex();\n"
3443
3444 // second vertex, green
3445 " gl_Position = gl_in[1].gl_Position;\n"
3446 " outColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3447 " EmitVertex();\n"
3448
3449 // third vertex, blue
3450 " gl_Position = gl_in[2].gl_Position;\n"
3451 " outColor = vec4(0.0, 0.0, 1.0, 1.0);\n"
3452 " EmitVertex();\n"
3453
3454 // done
3455 " EndPrimitive();\n"
3456 "}\n";
3457
3458
3459 static const char *fragShaderText =
3460 "#version 140\n"
3461 "#extension GL_ARB_separate_shader_objects : enable\n"
3462 "#extension GL_ARB_shading_language_420pack : enable\n"
3463 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003464 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003465 "void main() {\n"
3466 // pass through
GregFd6ebdb32015-06-03 18:40:50 -06003467 " outColor = color;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003468 "}\n";
3469
3470
3471
3472 ASSERT_NO_FATAL_FAILURE(InitState());
3473 ASSERT_NO_FATAL_FAILURE(InitViewport());
3474
3475 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3476 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3477 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3478
3479 VkPipelineObj pipelineobj(m_device);
3480 pipelineobj.AddShader(&vs);
3481 pipelineobj.AddShader(&gs);
3482 pipelineobj.AddShader(&ps);
3483
3484 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3485 VkCommandBufferObj cmdBuffer(m_device);
3486 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3487
3488 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3489
3490 VkDescriptorSetObj descriptorSet(m_device);
3491
3492 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3493
3494 // render triangle
3495 cmdBuffer.Draw(0, 3, 0, 1);
3496
3497 // finalize recording of the command buffer
3498 EndCommandBuffer(cmdBuffer);
3499 cmdBuffer.QueueCommandBuffer();
3500
3501 RecordImages(m_renderTargets);
3502}
3503
3504TEST_F(VkRenderTest, GSUniformBufferLayout)
3505{
3506 // This test is just like TriangleUniformBufferLayout but adds
3507 // geometry as a stage that also does UBO lookups
3508 // The expected result from this test is a green triangle
3509
3510 static const char *vertShaderText =
3511 "#version 140\n"
3512 "#extension GL_ARB_separate_shader_objects : enable\n"
3513 "#extension GL_ARB_shading_language_420pack : enable\n"
3514 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3515 " vec4 fRed;\n"
3516 " vec4 fGreen;\n"
3517 " layout(row_major) mat4 worldToProj;\n"
3518 " layout(row_major) mat4 projToWorld;\n"
3519 " layout(row_major) mat4 worldToView;\n"
3520 " layout(row_major) mat4 viewToProj;\n"
3521 " layout(row_major) mat4 worldToShadow[4];\n"
3522 " float fZero;\n"
3523 " float fOne;\n"
3524 " float fTwo;\n"
3525 " float fThree;\n"
3526 " vec3 fZeroZeroZero;\n"
3527 " float fFour;\n"
3528 " vec3 fZeroZeroOne;\n"
3529 " float fFive;\n"
3530 " vec3 fZeroOneZero;\n"
3531 " float fSix;\n"
3532 " float fSeven;\n"
3533 " float fEight;\n"
3534 " float fNine;\n"
3535 " vec2 fZeroZero;\n"
3536 " vec2 fZeroOne;\n"
3537 " vec4 fBlue;\n"
3538 " vec2 fOneZero;\n"
3539 " vec2 fOneOne;\n"
3540 " vec3 fZeroOneOne;\n"
3541 " float fTen;\n"
3542 " float fEleven;\n"
3543 " float fTwelve;\n"
3544 " vec3 fOneZeroZero;\n"
3545 " vec4 uvOffsets[4];\n"
3546 "};\n"
3547 "layout (location = 0) out vec4 color;"
3548 "void main() {\n"
3549
3550 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3551 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3552 " \n"
3553
3554 // do some exact comparisons, even though we should
3555 // really have an epsilon involved.
3556 " vec4 outColor = right;\n"
3557 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3558 " outColor = wrong;\n"
3559 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3560 " outColor = wrong;\n"
3561 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3562 " outColor = wrong;\n"
3563
3564 " color = outColor;\n"
3565
3566 // generic position stuff
3567 " vec2 vertices;\n"
3568 " int vertexSelector = gl_VertexID;\n"
3569 " if (vertexSelector == 0)\n"
3570 " vertices = vec2(-0.5, -0.5);\n"
3571 " else if (vertexSelector == 1)\n"
3572 " vertices = vec2( 0.5, -0.5);\n"
3573 " else if (vertexSelector == 2)\n"
3574 " vertices = vec2( 0.5, 0.5);\n"
3575 " else\n"
3576 " vertices = vec2( 0.0, 0.0);\n"
3577 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3578 "}\n";
3579
3580 static const char *geomShaderText =
3581 "#version 330\n"
3582 "#extension GL_ARB_separate_shader_objects : enable\n"
3583 "#extension GL_ARB_shading_language_420pack : enable\n"
3584
3585 // GS layout stuff
3586 "layout( triangles ) in;\n"
3587 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3588
3589 // Between stage IO
3590 "layout( location = 0 ) in vec4 inColor[3];\n"
3591 "layout( location = 0 ) out vec4 color;\n"
3592
3593 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3594 " vec4 fRed;\n"
3595 " vec4 fGreen;\n"
3596 " layout(row_major) mat4 worldToProj;\n"
3597 " layout(row_major) mat4 projToWorld;\n"
3598 " layout(row_major) mat4 worldToView;\n"
3599 " layout(row_major) mat4 viewToProj;\n"
3600 " layout(row_major) mat4 worldToShadow[4];\n"
3601 " float fZero;\n"
3602 " float fOne;\n"
3603 " float fTwo;\n"
3604 " float fThree;\n"
3605 " vec3 fZeroZeroZero;\n"
3606 " float fFour;\n"
3607 " vec3 fZeroZeroOne;\n"
3608 " float fFive;\n"
3609 " vec3 fZeroOneZero;\n"
3610 " float fSix;\n"
3611 " float fSeven;\n"
3612 " float fEight;\n"
3613 " float fNine;\n"
3614 " vec2 fZeroZero;\n"
3615 " vec2 fZeroOne;\n"
3616 " vec4 fBlue;\n"
3617 " vec2 fOneZero;\n"
3618 " vec2 fOneOne;\n"
3619 " vec3 fZeroOneOne;\n"
3620 " float fTen;\n"
3621 " float fEleven;\n"
3622 " float fTwelve;\n"
3623 " vec3 fOneZeroZero;\n"
3624 " vec4 uvOffsets[4];\n"
3625 "};\n"
3626
3627 "void main()\n"
3628 "{\n"
3629
3630 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3631 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3632
3633 // Each vertex will validate it can read VS output
3634 // then check a few values from the UBO
3635
3636 // first vertex
3637 " vec4 outColor = inColor[0];\n"
3638
3639 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3640 " outColor = wrong;\n"
3641 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3642 " outColor = wrong;\n"
3643 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3644 " outColor = wrong;\n"
3645 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3646 " outColor = wrong;\n"
3647
3648 " gl_Position = gl_in[0].gl_Position;\n"
3649 " color = outColor;\n"
3650 " EmitVertex();\n"
3651
3652 // second vertex
3653 " outColor = inColor[1];\n"
3654
3655 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3656 " outColor = wrong;\n"
3657 " if (fSix != 6.0)\n"
3658 " outColor = wrong;\n"
3659 " if (fOneOne != vec2(1.0, 1.0))\n"
3660 " outColor = wrong;\n"
3661
3662 " gl_Position = gl_in[1].gl_Position;\n"
3663 " color = outColor;\n"
3664 " EmitVertex();\n"
3665
3666 // third vertex
3667 " outColor = inColor[2];\n"
3668
3669 " if (fSeven != 7.0)\n"
3670 " outColor = wrong;\n"
3671 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3672 " outColor = wrong;\n"
3673
3674 " gl_Position = gl_in[2].gl_Position;\n"
3675 " color = outColor;\n"
3676 " EmitVertex();\n"
3677
3678 // done
3679 " EndPrimitive();\n"
3680 "}\n";
3681
3682 static const char *fragShaderText =
3683 "#version 140\n"
3684 "#extension GL_ARB_separate_shader_objects : enable\n"
3685 "#extension GL_ARB_shading_language_420pack : enable\n"
3686 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3687 " vec4 fRed;\n"
3688 " vec4 fGreen;\n"
3689 " layout(row_major) mat4 worldToProj;\n"
3690 " layout(row_major) mat4 projToWorld;\n"
3691 " layout(row_major) mat4 worldToView;\n"
3692 " layout(row_major) mat4 viewToProj;\n"
3693 " layout(row_major) mat4 worldToShadow[4];\n"
3694 " float fZero;\n"
3695 " float fOne;\n"
3696 " float fTwo;\n"
3697 " float fThree;\n"
3698 " vec3 fZeroZeroZero;\n"
3699 " float fFour;\n"
3700 " vec3 fZeroZeroOne;\n"
3701 " float fFive;\n"
3702 " vec3 fZeroOneZero;\n"
3703 " float fSix;\n"
3704 " float fSeven;\n"
3705 " float fEight;\n"
3706 " float fNine;\n"
3707 " vec2 fZeroZero;\n"
3708 " vec2 fZeroOne;\n"
3709 " vec4 fBlue;\n"
3710 " vec2 fOneZero;\n"
3711 " vec2 fOneOne;\n"
3712 " vec3 fZeroOneOne;\n"
3713 " float fTen;\n"
3714 " float fEleven;\n"
3715 " float fTwelve;\n"
3716 " vec3 fOneZeroZero;\n"
3717 " vec4 uvOffsets[4];\n"
3718 "};\n"
3719 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003720 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003721 "void main() {\n"
3722 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3723 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3724 " \n"
3725
3726 // start with GS value to ensure it passed
3727 " vec4 outColor = color;\n"
3728
3729 // do some exact comparisons, even though we should
3730 // really have an epsilon involved.
3731 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3732 " outColor = wrong;\n"
3733 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3734 " outColor = wrong;\n"
3735 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3736 " outColor = wrong;\n"
3737 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3738 " outColor = wrong;\n"
3739 " if (fTwo != 2.0)\n"
3740 " outColor = wrong;\n"
3741 " if (fOneOne != vec2(1.0, 1.0))\n"
3742 " outColor = wrong;\n"
3743 " if (fTen != 10.0)\n"
3744 " outColor = wrong;\n"
3745 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3746 " outColor = wrong;\n"
3747 " \n"
GregFd6ebdb32015-06-03 18:40:50 -06003748 " uFragColor = outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003749 "}\n";
3750
3751
3752 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3753 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3754 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3755 0.0, 1.0, 0.0, 1.0, // align
3756 0.0, 0.0, 1.0, 1.0, // align
3757 0.0, 0.0, 0.0, 1.0, // align
3758 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3759 0.0, 2.0, 0.0, 2.0, // align
3760 0.0, 0.0, 2.0, 2.0, // align
3761 0.0, 0.0, 0.0, 2.0, // align
3762 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3763 0.0, 3.0, 0.0, 3.0, // align
3764 0.0, 0.0, 3.0, 3.0, // align
3765 0.0, 0.0, 0.0, 3.0, // align
3766 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3767 0.0, 4.0, 0.0, 4.0, // align
3768 0.0, 0.0, 4.0, 4.0, // align
3769 0.0, 0.0, 0.0, 4.0, // align
3770 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3771 0.0, 5.0, 0.0, 5.0, // align
3772 0.0, 0.0, 5.0, 5.0, // align
3773 0.0, 0.0, 0.0, 5.0, // align
3774 6.0, 0.0, 0.0, 6.0, // align
3775 0.0, 6.0, 0.0, 6.0, // align
3776 0.0, 0.0, 6.0, 6.0, // align
3777 0.0, 0.0, 0.0, 6.0, // align
3778 7.0, 0.0, 0.0, 7.0, // align
3779 0.0, 7.0, 0.0, 7.0, // align
3780 0.0, 0.0, 7.0, 7.0, // align
3781 0.0, 0.0, 0.0, 7.0, // align
3782 8.0, 0.0, 0.0, 8.0, // align
3783 0.0, 8.0, 0.0, 8.0, // align
3784 0.0, 0.0, 8.0, 8.0, // align
3785 0.0, 0.0, 0.0, 8.0, // align
3786 0.0, // float fZero; // align
3787 1.0, // float fOne; // pack
3788 2.0, // float fTwo; // pack
3789 3.0, // float fThree; // pack
3790 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3791 4.0, // float fFour; // pack
3792 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3793 5.0, // float fFive; // pack
3794 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3795 6.0, // float fSix; // pack
3796 7.0, // float fSeven; // align
3797 8.0, // float fEight; // pack
3798 9.0, // float fNine; // pack
3799 0.0, // BUFFER
3800 0.0, 0.0, // vec2 fZeroZero; // align
3801 0.0, 1.0, // vec2 fZeroOne; // pack
3802 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3803 1.0, 0.0, // vec2 fOneZero; // align
3804 1.0, 1.0, // vec2 fOneOne; // pack
3805 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3806 10.0, // float fTen; // pack
3807 11.0, // float fEleven; // align
3808 12.0, // float fTwelve; // pack
3809 0.0, 0.0, // BUFFER
3810 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3811 0.0, // BUFFER
3812 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3813 0.5, 0.6, 0.7, 0.8, // align
3814 0.9, 1.0, 1.1, 1.2, // align
3815 1.3, 1.4, 1.5, 1.6, // align
3816 };
3817
3818
3819
3820 ASSERT_NO_FATAL_FAILURE(InitState());
3821 ASSERT_NO_FATAL_FAILURE(InitViewport());
3822
3823 const int constCount = sizeof(mixedVals) / sizeof(float);
3824
3825 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3826 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3827 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3828
3829 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
3830
3831 VkPipelineObj pipelineobj(m_device);
3832 pipelineobj.AddShader(&vs);
3833 pipelineobj.AddShader(&gs);
3834 pipelineobj.AddShader(&ps);
3835
3836 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3837 VkCommandBufferObj cmdBuffer(m_device);
3838 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3839
3840 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3841
3842 VkDescriptorSetObj descriptorSet(m_device);
3843 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
3844
3845 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3846
3847 // render triangle
3848 cmdBuffer.Draw(0, 3, 0, 1);
3849
3850 // finalize recording of the command buffer
3851 EndCommandBuffer(cmdBuffer);
3852 cmdBuffer.QueueCommandBuffer();
3853
3854 RecordImages(m_renderTargets);
3855}
3856
3857TEST_F(VkRenderTest, GSPositions)
3858{
3859 // This test adds more inputs from the vertex shader and perturbs positions
3860 // Expected result is white triangle with weird positions
3861
3862 static const char *vertShaderText =
3863 "#version 140\n"
3864 "#extension GL_ARB_separate_shader_objects : enable\n"
3865 "#extension GL_ARB_shading_language_420pack : enable\n"
3866
3867 "layout(location = 0) out vec3 out_a;\n"
3868 "layout(location = 1) out vec3 out_b;\n"
3869 "layout(location = 2) out vec3 out_c;\n"
3870
3871 "void main() {\n"
3872
3873 // write a solid color to each
3874 " out_a = vec3(1.0, 0.0, 0.0);\n"
3875 " out_b = vec3(0.0, 1.0, 0.0);\n"
3876 " out_c = vec3(0.0, 0.0, 1.0);\n"
3877
3878 // generic position stuff
3879 " vec2 vertices;\n"
3880 " int vertexSelector = gl_VertexID;\n"
3881 " if (vertexSelector == 0)\n"
3882 " vertices = vec2(-0.5, -0.5);\n"
3883 " else if (vertexSelector == 1)\n"
3884 " vertices = vec2( 0.5, -0.5);\n"
3885 " else if (vertexSelector == 2)\n"
3886 " vertices = vec2( 0.5, 0.5);\n"
3887 " else\n"
3888 " vertices = vec2( 0.0, 0.0);\n"
3889 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3890
3891 "}\n";
3892
3893 static const char *geomShaderText =
3894 "#version 330\n"
3895 "#extension GL_ARB_separate_shader_objects : enable\n"
3896 "#extension GL_ARB_shading_language_420pack : enable\n"
3897 "layout( triangles ) in;\n"
3898 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3899
3900 "layout(location = 0) in vec3 in_a[3];\n"
3901 "layout(location = 1) in vec3 in_b[3];\n"
3902 "layout(location = 2) in vec3 in_c[3];\n"
3903
3904 "layout(location = 0) out vec3 out_a;\n"
3905 "layout(location = 1) out vec3 out_b;\n"
3906 "layout(location = 2) out vec3 out_c;\n"
3907
3908 "void main()\n"
3909 "{\n"
3910
3911 " gl_Position = gl_in[0].gl_Position;\n"
3912 " gl_Position.xy *= vec2(0.75);\n"
3913 " out_a = in_a[0];\n"
3914 " out_b = in_b[0];\n"
3915 " out_c = in_c[0];\n"
3916 " EmitVertex();\n"
3917
3918 " gl_Position = gl_in[1].gl_Position;\n"
3919 " gl_Position.xy *= vec2(1.5);\n"
3920 " out_a = in_a[1];\n"
3921 " out_b = in_b[1];\n"
3922 " out_c = in_c[1];\n"
3923 " EmitVertex();\n"
3924
3925 " gl_Position = gl_in[2].gl_Position;\n"
3926 " gl_Position.xy *= vec2(-0.1);\n"
3927 " out_a = in_a[2];\n"
3928 " out_b = in_b[2];\n"
3929 " out_c = in_c[2];\n"
3930 " EmitVertex();\n"
3931
3932 " EndPrimitive();\n"
3933 "}\n";
3934
3935
3936 static const char *fragShaderText =
3937 "#version 140\n"
3938 "#extension GL_ARB_separate_shader_objects : enable\n"
3939 "#extension GL_ARB_shading_language_420pack : enable\n"
3940
3941 "layout(location = 0) in vec3 in_a;\n"
3942 "layout(location = 1) in vec3 in_b;\n"
3943 "layout(location = 2) in vec3 in_c;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003944 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003945
3946 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06003947 " outColor = vec4(in_a.x, in_b.y, in_c.z, 1.0);\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003948 "}\n";
3949
3950
3951
3952 ASSERT_NO_FATAL_FAILURE(InitState());
3953 ASSERT_NO_FATAL_FAILURE(InitViewport());
3954
3955 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3956 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3957 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3958
3959 VkPipelineObj pipelineobj(m_device);
3960 pipelineobj.AddShader(&vs);
3961 pipelineobj.AddShader(&gs);
3962 pipelineobj.AddShader(&ps);
3963
3964 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3965 VkCommandBufferObj cmdBuffer(m_device);
3966 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3967
3968 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3969
3970 VkDescriptorSetObj descriptorSet(m_device);
3971
3972 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3973
3974 // render triangle
3975 cmdBuffer.Draw(0, 3, 0, 1);
3976
3977 // finalize recording of the command buffer
3978 EndCommandBuffer(cmdBuffer);
3979 cmdBuffer.QueueCommandBuffer();
3980
3981 RecordImages(m_renderTargets);
3982}
3983
3984TEST_F(VkRenderTest, GSTriStrip)
3985{
3986 // This test emits multiple multiple triangles using a GS
3987 // Correct result is an multicolor circle
3988
3989 static const char *vertShaderText =
3990 "#version 140\n"
3991 "#extension GL_ARB_separate_shader_objects : enable\n"
3992 "#extension GL_ARB_shading_language_420pack : enable\n"
3993
3994 "void main() {\n"
3995
3996 // generic position stuff
3997 " vec2 vertices;\n"
3998 " int vertexSelector = gl_VertexID;\n"
3999 " if (vertexSelector == 0)\n"
4000 " vertices = vec2(-0.5, -0.5);\n"
4001 " else if (vertexSelector == 1)\n"
4002 " vertices = vec2( 0.5, -0.5);\n"
4003 " else if (vertexSelector == 2)\n"
4004 " vertices = vec2( 0.5, 0.5);\n"
4005 " else\n"
4006 " vertices = vec2( 0.0, 0.0);\n"
4007 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
4008
4009 "}\n";
4010
4011 static const char *geomShaderText =
4012 "#version 330\n"
4013 "#extension GL_ARB_separate_shader_objects : enable\n"
4014 "#extension GL_ARB_shading_language_420pack : enable\n"
4015 "layout( triangles ) in;\n"
4016 "layout( triangle_strip, max_vertices = 18 ) out;\n"
4017
4018 "layout(location = 0) out vec4 outColor;\n"
4019
4020 "void main()\n"
4021 "{\n"
4022 // init with first position to get zw
4023 " gl_Position = gl_in[0].gl_Position;\n"
4024
4025 " vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
4026 " vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
4027 " vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
4028 " vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
4029
4030 // different color per tri
4031 " vec4[6] colors = { red, white, \n"
4032 " yellow, white, \n"
4033 " blue, white }; \n"
4034
4035 // fan out the triangles
4036 " vec2[18] positions = { vec2(0.0, 0.0), vec2(-0.5, 0.0), vec2(-0.25, -0.5), \n"
4037 " vec2(0.0, 0.0), vec2(-0.25, -0.5), vec2( 0.25, -0.5), \n"
4038 " vec2(0.0, 0.0), vec2( 0.25, -0.5), vec2( 0.5, 0.0), \n"
4039 " vec2(0.0, 0.0), vec2( 0.5, 0.0), vec2( 0.25, 0.5), \n"
4040 " vec2(0.0, 0.0), vec2( 0.25, 0.5), vec2(-0.25, 0.5), \n"
4041 " vec2(0.0, 0.0), vec2(-0.25, 0.5), vec2(-0.5, 0.0) }; \n"
4042
4043 // make a triangle list of 6
4044 " for (int i = 0; i < 6; ++i) { \n"
4045 " outColor = colors[i]; \n"
4046 " for (int j = 0; j < 3; ++j) { \n"
4047 " gl_Position.xy = positions[i * 3 + j]; \n"
4048 " EmitVertex(); \n"
4049 " } \n"
4050 " EndPrimitive();\n"
4051 " } \n"
4052
4053 "}\n";
4054
4055
4056 static const char *fragShaderText =
4057 "#version 150\n"
4058 "#extension GL_ARB_separate_shader_objects : enable\n"
4059 "#extension GL_ARB_shading_language_420pack : enable\n"
4060
4061
4062 "layout(binding = 0) uniform windowDimensions {\n"
4063 " vec4 dimensions;\n"
4064 "};\n"
4065
4066 "layout(location = 0) in vec4 inColor;\n"
4067 "layout(origin_upper_left) in vec4 gl_FragCoord;\n"
GregFd6ebdb32015-06-03 18:40:50 -06004068 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06004069
4070 "void main() {\n"
4071
4072 // discard to make a nice circle
4073 " vec2 pos = abs(gl_FragCoord.xy) - vec2(dimensions.x, dimensions.y) / 2;\n"
4074 " float dist = sqrt(dot(pos, pos));\n"
4075 " if (dist > 50.0)\n"
4076 " discard;\n"
4077
GregFd6ebdb32015-06-03 18:40:50 -06004078 " outColor = inColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06004079
4080 "}\n";
4081
4082
4083
4084 ASSERT_NO_FATAL_FAILURE(InitState());
4085 ASSERT_NO_FATAL_FAILURE(InitViewport());
4086
4087 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
4088 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
4089 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
4090
4091 VkPipelineObj pipelineobj(m_device);
4092 pipelineobj.AddShader(&vs);
4093 pipelineobj.AddShader(&gs);
4094 pipelineobj.AddShader(&ps);
4095
4096 const float dimensions[4] = { VkRenderFramework::m_width, VkRenderFramework::m_height , 0.0, 0.0};
4097
4098 VkConstantBufferObj windowDimensions(m_device, sizeof(dimensions) / sizeof(dimensions[0]), sizeof(dimensions[0]), (const void*) dimensions);
4099
4100 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4101 VkCommandBufferObj cmdBuffer(m_device);
4102 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
4103
4104 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
4105
4106 VkDescriptorSetObj descriptorSet(m_device);
4107 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, windowDimensions);
4108
4109 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
4110
4111 // render triangle
4112 cmdBuffer.Draw(0, 3, 0, 1);
4113
4114 // finalize recording of the command buffer
4115 EndCommandBuffer(cmdBuffer);
4116 cmdBuffer.QueueCommandBuffer();
4117
4118 RecordImages(m_renderTargets);
4119}
4120
Chris Forbes23e6db62015-06-15 09:32:35 +12004121TEST_F(VkRenderTest, RenderPassLoadOpClear)
4122{
4123 ASSERT_NO_FATAL_FAILURE(InitState());
4124 ASSERT_NO_FATAL_FAILURE(InitViewport());
4125
4126 /* clear via load op to full green */
4127 m_clear_via_load_op = true;
Chris Forbese3105972015-06-24 14:34:53 +12004128 m_clear_color.f32[0] = 0;
4129 m_clear_color.f32[1] = 1;
4130 m_clear_color.f32[2] = 0;
4131 m_clear_color.f32[3] = 0;
Chris Forbes23e6db62015-06-15 09:32:35 +12004132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4133
4134 VkCommandBufferObj cmdBuffer(m_device);
4135 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
4136 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
4137 /* This command buffer contains ONLY the load op! */
4138 EndCommandBuffer(cmdBuffer);
4139 cmdBuffer.QueueCommandBuffer();
4140
4141 RecordImages(m_renderTargets);
4142}
4143
Chris Forbes1e16cb82015-06-24 12:05:30 +12004144TEST_F(VkRenderTest, RenderPassAttachmentClear)
4145{
4146 ASSERT_NO_FATAL_FAILURE(InitState());
4147 ASSERT_NO_FATAL_FAILURE(InitViewport());
4148
4149 /* clear via load op to full red */
4150 m_clear_via_load_op = true;
Chris Forbese3105972015-06-24 14:34:53 +12004151 m_clear_color.f32[0] = 1;
4152 m_clear_color.f32[1] = 0;
4153 m_clear_color.f32[2] = 0;
4154 m_clear_color.f32[3] = 0;
Chris Forbes1e16cb82015-06-24 12:05:30 +12004155 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4156
4157 VkCommandBufferObj cmdBuffer(m_device);
4158 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
4159 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
4160
4161 /* Load op has cleared to red */
4162
4163 /* Draw, draw, draw... */
4164
4165 /* Now, partway through this renderpass we want to clear the color
4166 * attachment again, this time to green.
4167 */
Chris Forbese3105972015-06-24 14:34:53 +12004168 VkClearColorValue clear_color;
4169 clear_color.f32[0] = 0;
4170 clear_color.f32[1] = 1;
4171 clear_color.f32[2] = 0;
4172 clear_color.f32[3] = 0;
Chris Forbes1e16cb82015-06-24 12:05:30 +12004173 VkRect3D clear_rect = { { 0, 0, 0 }, { (int)m_width, (int)m_height, 1 } };
4174 vkCmdClearColorAttachment(cmdBuffer.obj(), 0,
4175 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4176 &clear_color, 1, &clear_rect);
4177
4178 EndCommandBuffer(cmdBuffer);
4179 cmdBuffer.QueueCommandBuffer();
4180
4181 RecordImages(m_renderTargets);
4182}
4183
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004184int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004185 int result;
4186
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004187 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06004188 VkTestFramework::InitArgs(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004189
Chia-I Wu7133fdc2014-12-15 23:57:34 +08004190 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06004191
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004192 result = RUN_ALL_TESTS();
4193
Tony Barbour01999182015-04-09 12:58:51 -06004194 VkTestFramework::Finish();
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004195 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004196}