blob: e741c4e66c17e0be8cccbb9d949baf8bd319b83a [file] [log] [blame]
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06001// Copyright 2005, Google Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14// * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060031// VK tests
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060032//
33// Copyright (C) 2014 LunarG, Inc.
34//
35// Permission is hereby granted, free of charge, to any person obtaining a
36// copy of this software and associated documentation files (the "Software"),
37// to deal in the Software without restriction, including without limitation
38// the rights to use, copy, modify, merge, publish, distribute, sublicense,
39// and/or sell copies of the Software, and to permit persons to whom the
40// Software is furnished to do so, subject to the following conditions:
41//
42// The above copyright notice and this permission notice shall be included
43// in all copies or substantial portions of the Software.
44//
45// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
48// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
49// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
50// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
51// DEALINGS IN THE SOFTWARE.
52
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060053// Basic rendering tests
54
55#include <stdlib.h>
56#include <stdio.h>
57#include <stdbool.h>
58#include <string.h>
Courtney Goeltzenleuchter76a643b2014-08-21 17:34:22 -060059#include <iostream>
60#include <fstream>
61using namespace std;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060062
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060063#include <vulkan.h>
Tobin Ehlis31446e52014-11-28 11:17:19 -070064#ifdef DUMP_STATE_DOT
65#include "../layers/draw_state.h"
66#endif
Tobin Ehlis3c26a542014-11-18 11:28:33 -070067#ifdef PRINT_OBJECTS
68#include "../layers/object_track.h"
69#endif
Tobin Ehlis791a49c2014-11-10 12:29:12 -070070#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060071#include <vkDbg.h>
Tobin Ehlis791a49c2014-11-10 12:29:12 -070072#endif
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060073#include "gtest-1.7.0/include/gtest/gtest.h"
74
Cody Northropd4e020a2015-03-17 14:54:35 -060075#include "icd-spv.h"
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060076
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -060077#define GLM_FORCE_RADIANS
78#include "glm/glm.hpp"
79#include <glm/gtc/matrix_transform.hpp>
80
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060081#include "vkrenderframework.h"
Tobin Ehlis791a49c2014-11-10 12:29:12 -070082#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060083void VKAPI myDbgFunc(
84 VK_DBG_MSG_TYPE msgType,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060085 VkValidationLevel validationLevel,
Mike Stroyan230e6252015-04-17 12:36:38 -060086 VkObject srcObject,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060087 size_t location,
88 int32_t msgCode,
89 const char* pMsg,
90 void* pUserData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -070091{
Tobin Ehlis3c26a542014-11-18 11:28:33 -070092 switch (msgType)
93 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060094 case VK_DBG_MSG_WARNING:
Tobin Ehlis3c26a542014-11-18 11:28:33 -070095 printf("CALLBACK WARNING : %s\n", pMsg);
96 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060097 case VK_DBG_MSG_ERROR:
Tobin Ehlis3c26a542014-11-18 11:28:33 -070098 printf("CALLBACK ERROR : %s\n", pMsg);
99 break;
100 default:
101 printf("EATING Msg of type %u\n", msgType);
102 break;
103 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700104}
105#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700106
107
108#undef ASSERT_NO_FATAL_FAILURE
109#define ASSERT_NO_FATAL_FAILURE(x) x
110
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600111//--------------------------------------------------------------------------------------
112// Mesh and VertexFormat Data
113//--------------------------------------------------------------------------------------
114struct Vertex
115{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600116 float posX, posY, posZ, posW; // Position data
117 float r, g, b, a; // Color
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600118};
119
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600120struct VertexUV
121{
122 float posX, posY, posZ, posW; // Position data
123 float u, v; // texture u,v
124};
125
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600126#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600127#define UV(_u_, _v_) (_u_), (_v_)
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600128
129static const Vertex g_vbData[] =
130{
131 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
132 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
133 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
134 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
135 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
136 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
137
138 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
139 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
140 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
141 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
142 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
143 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
144
145 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
146 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
147 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
148 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
149 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
150 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
151
152 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
153 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
154 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
155 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
156 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
157 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
158
159 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
160 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
161 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
162 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
163 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
164 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
165
166 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
167 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
168 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
169 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
170 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
171 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
172};
173
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600174static const Vertex g_vb_solid_face_colors_Data[] =
175{
176 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600177 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600178 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
179 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600180 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
181 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600182
183 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
184 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600185 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
186 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600187 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600188 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600189
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600190 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
191 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
192 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
193 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
194 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
195 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600196
197 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
198 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
199 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
200 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
201 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
202 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
203
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600204 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600205 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600206 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
207 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600208 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
209 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
210
211 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
212 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
213 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
214 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
215 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
216 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
217};
218
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600219static const VertexUV g_vb_texture_Data[] =
220{
221 { XYZ1( -1, -1, -1 ), UV( 0.f, 0.f ) },
222 { XYZ1( -1, 1, 1 ), UV( 1.f, 1.f ) },
223 { XYZ1( -1, -1, 1 ), UV( 1.f, 0.f ) },
224 { XYZ1( -1, 1, 1 ), UV( 1.f, 1.f ) },
225 { XYZ1( -1, -1, -1 ), UV( 0.f, 0.f ) },
226 { XYZ1( -1, 1, -1 ), UV( 0.f, 1.f ) },
227
228 { XYZ1( -1, -1, -1 ), UV( 1.f, 0.f ) },
229 { XYZ1( 1, -1, -1 ), UV( 0.f, 0.f ) },
230 { XYZ1( 1, 1, -1 ), UV( 0.f, 1.f ) },
231 { XYZ1( -1, -1, -1 ), UV( 1.f, 0.f ) },
232 { XYZ1( 1, 1, -1 ), UV( 0.f, 1.f ) },
233 { XYZ1( -1, 1, -1 ), UV( 1.f, 1.f ) },
234
235 { XYZ1( -1, -1, -1 ), UV( 1.f, 1.f ) },
236 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
237 { XYZ1( 1, -1, -1 ), UV( 1.f, 0.f ) },
238 { XYZ1( -1, -1, -1 ), UV( 1.f, 1.f ) },
239 { XYZ1( -1, -1, 1 ), UV( 0.f, 1.f ) },
240 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
241
242 { XYZ1( -1, 1, -1 ), UV( 1.f, 1.f ) },
243 { XYZ1( 1, 1, 1 ), UV( 0.f, 0.f ) },
244 { XYZ1( -1, 1, 1 ), UV( 0.f, 1.f ) },
245 { XYZ1( -1, 1, -1 ), UV( 1.f, 1.f ) },
246 { XYZ1( 1, 1, -1 ), UV( 1.f, 0.f ) },
247 { XYZ1( 1, 1, 1 ), UV( 0.f, 0.f ) },
248
249 { XYZ1( 1, 1, -1 ), UV( 1.f, 1.f ) },
250 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
251 { XYZ1( 1, 1, 1 ), UV( 0.f, 1.f ) },
252 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
253 { XYZ1( 1, 1, -1 ), UV( 1.f, 1.f ) },
254 { XYZ1( 1, -1, -1 ), UV( 1.f, 0.f ) },
255
256 { XYZ1( -1, 1, 1 ), UV( 0.f, 1.f ) },
257 { XYZ1( 1, 1, 1 ), UV( 1.f, 1.f ) },
258 { XYZ1( -1, -1, 1 ), UV( 0.f, 0.f ) },
259 { XYZ1( -1, -1, 1 ), UV( 0.f, 0.f ) },
260 { XYZ1( 1, 1, 1 ), UV( 1.f, 1.f ) },
261 { XYZ1( 1, -1, 1 ), UV( 1.f, 0.f ) },
262};
263
Tony Barbour01999182015-04-09 12:58:51 -0600264class VkRenderTest : public VkRenderFramework
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -0600265{
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600266public:
Cody Northrop4e6b4762014-10-09 21:25:22 -0600267
Tony Barbourf43b6982014-11-25 13:18:32 -0700268 void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbour01999182015-04-09 12:58:51 -0600269 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer);
270 void GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600271 void InitDepthStencil();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600272 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate);
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600273
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600274 VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer);
275 VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer);
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600276
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600277protected:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600278 VkImage m_texture;
279 VkImageView m_textureView;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800280 VkDescriptorInfo m_descriptorInfo;
Tony Barbour8205d902015-04-16 15:59:00 -0600281 VkDeviceMemory m_textureMem;
Cody Northrop350727b2014-10-06 15:42:00 -0600282
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600283 VkSampler m_sampler;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600284
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600285
286 virtual void SetUp() {
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600287
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600288 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600289 this->app_info.pNext = NULL;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800290 this->app_info.pAppName = "render_tests";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600291 this->app_info.appVersion = 1;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800292 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600293 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600294 this->app_info.apiVersion = VK_API_VERSION;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600295
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800296 memset(&m_descriptorInfo, 0, sizeof(m_descriptorInfo));
Cody Northrop350727b2014-10-06 15:42:00 -0600297
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600298 InitFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600299 }
300
301 virtual void TearDown() {
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600302 // Clean up resources before we reset
303 ShutdownFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600304 }
305};
306
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600307VkResult VkRenderTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600308{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600309 VkResult result;
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600310
311 result = cmdBuffer.BeginCommandBuffer();
312
313 /*
314 * For render test all drawing happens in a single render pass
315 * on a single command buffer.
316 */
Chris Forbesfe133ef2015-06-16 14:05:59 +1200317 if (VK_SUCCESS == result && renderPass()) {
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600318 cmdBuffer.BeginRenderPass(renderPass(), framebuffer());
319 }
320
321 return result;
322}
323
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600324VkResult VkRenderTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600325{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600326 VkResult result;
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600327
Chris Forbesfe133ef2015-06-16 14:05:59 +1200328 if (renderPass()) {
329 cmdBuffer.EndRenderPass(renderPass());
330 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600331
332 result = cmdBuffer.EndCommandBuffer();
333
334 return result;
335}
336
337
Tony Barbour01999182015-04-09 12:58:51 -0600338void VkRenderTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet)
Tony Barbour02472db2015-01-08 17:08:28 -0700339{
Tony Barbour17c6ab12015-03-27 17:03:18 -0600340 if (m_depthStencil->Initialized()) {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600341 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Tony Barbour17c6ab12015-03-27 17:03:18 -0600342 } else {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600343 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour17c6ab12015-03-27 17:03:18 -0600344 }
345
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700346 cmdBuffer->PrepareAttachments();
Tony Barbour8205d902015-04-16 15:59:00 -0600347 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_RASTER, m_stateRaster);
348 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_VIEWPORT, m_stateViewport);
349 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_COLOR_BLEND, m_colorBlend);
350 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_DEPTH_STENCIL, m_stateDepthStencil);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600351 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
352 pipelineobj.CreateVKPipeline(descriptorSet);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600353 cmdBuffer->BindPipeline(pipelineobj);
Chia-I Wu862c5572015-03-28 15:23:55 +0800354 cmdBuffer->BindDescriptorSet(descriptorSet);
Tony Barbour02472db2015-01-08 17:08:28 -0700355}
Tony Barbourf43b6982014-11-25 13:18:32 -0700356
Tony Barbour01999182015-04-09 12:58:51 -0600357void VkRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
358 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer)
Tony Barbourdd4c9642015-01-09 12:55:14 -0700359{
360 int i;
361 glm::mat4 MVP;
362 int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600363 VkResult err;
Tony Barbourdd4c9642015-01-09 12:55:14 -0700364
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600365 /* Only do 3 positions to avoid back face cull */
366 for (i = 0; i < 3; i++) {
Tony Barbourdd4c9642015-01-09 12:55:14 -0700367 void *pData = constantBuffer->map();
368
369 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
370 MVP = Projection * View * Model;
371 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
372
373 constantBuffer->unmap();
374
375 // submit the command buffer to the universal queue
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600376 cmdBuffer->QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700377
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600378 err = vkQueueWaitIdle( m_device->m_queue );
379 ASSERT_VK_SUCCESS( err );
Tony Barbourdd4c9642015-01-09 12:55:14 -0700380
381 // Wait for work to finish before cleaning up.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600382 vkDeviceWaitIdle(m_device->device());
Tony Barbourdd4c9642015-01-09 12:55:14 -0700383
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700384 assert(m_renderTargets.size() == 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -0700385 RecordImage(m_renderTargets[0]);
386 }
387}
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600388
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600389void dumpMatrix(const char *note, glm::mat4 MVP)
390{
Chia-I Wu7133fdc2014-12-15 23:57:34 +0800391 int i;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600392
393 printf("%s: \n", note);
394 for (i=0; i<4; i++) {
395 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
396 }
397 printf("\n");
398 fflush(stdout);
399}
400
401void dumpVec4(const char *note, glm::vec4 vector)
402{
403 printf("%s: \n", note);
404 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
405 printf("\n");
406 fflush(stdout);
407}
408
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600409struct vktriangle_vs_uniform {
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600410 // Must start with MVP
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600411 float mvp[4][4];
412 float position[3][4];
413 float color[3][4];
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600414};
415
Tony Barbour01999182015-04-09 12:58:51 -0600416void VkRenderTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600417{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700418#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600419 vkDbgRegisterMsgCallback(inst, myDbgFunc, NULL);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700420#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600421 // Create identity matrix
422 int i;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600423 struct vktriangle_vs_uniform data;
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600424
425 glm::mat4 Projection = glm::mat4(1.0f);
426 glm::mat4 View = glm::mat4(1.0f);
427 glm::mat4 Model = glm::mat4(1.0f);
428 glm::mat4 MVP = Projection * View * Model;
429 const int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600430 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600431 memcpy(&data.mvp, &MVP[0][0], matrixSize);
432
433 static const Vertex tri_data[] =
434 {
435 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
436 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
437 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
438 };
439
440 for (i=0; i<3; i++) {
441 data.position[i][0] = tri_data[i].posX;
442 data.position[i][1] = tri_data[i].posY;
443 data.position[i][2] = tri_data[i].posZ;
444 data.position[i][3] = tri_data[i].posW;
445 data.color[i][0] = tri_data[i].r;
446 data.color[i][1] = tri_data[i].g;
447 data.color[i][2] = tri_data[i].b;
448 data.color[i][3] = tri_data[i].a;
449 }
450
Tony Barbourf43b6982014-11-25 13:18:32 -0700451 ASSERT_NO_FATAL_FAILURE(InitState());
452 ASSERT_NO_FATAL_FAILURE(InitViewport());
453
Tony Barbour01999182015-04-09 12:58:51 -0600454 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barbourf43b6982014-11-25 13:18:32 -0700455
Tony Barbour01999182015-04-09 12:58:51 -0600456 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
457 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700458
Tony Barbour01999182015-04-09 12:58:51 -0600459 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -0700460 pipelineobj.AddShader(&vs);
461 pipelineobj.AddShader(&ps);
462
Tony Barbour01999182015-04-09 12:58:51 -0600463 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600464 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700465
Tony Barbour71ba3612015-01-09 16:12:35 -0700466 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600467 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour71ba3612015-01-09 16:12:35 -0700468 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700469
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600470 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour71ba3612015-01-09 16:12:35 -0700471
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600472 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour71ba3612015-01-09 16:12:35 -0700473#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600474 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour71ba3612015-01-09 16:12:35 -0700475 pDSDumpDot((char*)"triTest2.dot");
476#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600477
Tony Barbour71ba3612015-01-09 16:12:35 -0700478 // render triangle
479 cmdBuffer.Draw(0, 3, 0, 1);
480
481 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600482 EndCommandBuffer(cmdBuffer);
483
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600484 cmdBuffer.QueueCommandBuffer();
Tony Barbour71ba3612015-01-09 16:12:35 -0700485
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600486 RecordImages(m_renderTargets);
Tony Barbour71ba3612015-01-09 16:12:35 -0700487
488 if (rotate)
Tobin Ehlis12ee35f2015-03-26 08:23:25 -0600489 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
Tony Barbour71ba3612015-01-09 16:12:35 -0700490
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700491#ifdef PRINT_OBJECTS
Mark Lobodzinski4e5016f2015-05-05 15:01:37 -0500492 //uint64_t objTrackGetObjectCount(VkObjectType type)
493 OBJ_TRACK_GET_OBJECTS_COUNT pObjTrackGetObjectsCount = (OBJ_TRACK_GET_OBJECTS_COUNT)vkGetProcAddr(gpu(), (char*)"objTrackGetObjectsCount");
494 uint64_t numObjects = pObjTrackGetObjectsCount();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600495 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700496 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600497 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700498 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
Mark Lobodzinski4e5016f2015-05-05 15:01:37 -0500499 pObjTrackGetObjs(numObjects, pObjNodeArray);
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700500 for (i=0; i < numObjects; i++) {
Mark Lobodzinski4e5016f2015-05-05 15:01:37 -0500501 printf("Object %i of type %s has objID (%p) and %lu uses\n", i, string_from_vulkan_object_type(pObjNodeArray[i].objType), pObjNodeArray[i].vkObj, pObjNodeArray[i].numUses);
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700502 }
503 free(pObjNodeArray);
504#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700505
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600506}
507
Tony Barbour01999182015-04-09 12:58:51 -0600508TEST_F(VkRenderTest, VKTriangle_FragColor)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600509{
510 static const char *vertShaderText =
511 "#version 140\n"
512 "#extension GL_ARB_separate_shader_objects : enable\n"
513 "#extension GL_ARB_shading_language_420pack : enable\n"
514 "\n"
515 "layout(binding = 0) uniform buf {\n"
516 " mat4 MVP;\n"
517 " vec4 position[3];\n"
518 " vec4 color[3];\n"
519 "} ubuf;\n"
520 "\n"
521 "layout (location = 0) out vec4 outColor;\n"
522 "\n"
523 "void main() \n"
524 "{\n"
525 " outColor = ubuf.color[gl_VertexID];\n"
526 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
527 "}\n";
528
529 static const char *fragShaderText =
530 "#version 140\n"
531 "#extension GL_ARB_separate_shader_objects : enable\n"
532 "#extension GL_ARB_shading_language_420pack : enable\n"
533 "\n"
534 "layout (location = 0) in vec4 inColor;\n"
535 "\n"
536 "void main()\n"
537 "{\n"
538 " gl_FragColor = inColor;\n"
539 "}\n";
540
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600541 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
542 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600543}
544
Tony Barbour01999182015-04-09 12:58:51 -0600545TEST_F(VkRenderTest, VKTriangle_OutputLocation)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600546{
547 static const char *vertShaderText =
548 "#version 140\n"
549 "#extension GL_ARB_separate_shader_objects : enable\n"
550 "#extension GL_ARB_shading_language_420pack : enable\n"
551 "\n"
552 "layout(binding = 0) uniform buf {\n"
553 " mat4 MVP;\n"
554 " vec4 position[3];\n"
555 " vec4 color[3];\n"
556 "} ubuf;\n"
557 "\n"
558 "layout (location = 0) out vec4 outColor;\n"
559 "\n"
560 "void main() \n"
561 "{\n"
562 " outColor = ubuf.color[gl_VertexID];\n"
563 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
564 "}\n";
565
566 static const char *fragShaderText =
567 "#version 140\n"
568 "#extension GL_ARB_separate_shader_objects : enable\n"
569 "#extension GL_ARB_shading_language_420pack : enable\n"
570 "\n"
571 "layout (location = 0) in vec4 inColor;\n"
572 "layout (location = 0) out vec4 outColor;\n"
573 "\n"
574 "void main()\n"
575 "{\n"
576 " outColor = inColor;\n"
577 "}\n";
578
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600579 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to output location 0, which should be the same as gl_FragColor");
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600580
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600581 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600582}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600583#ifndef _WIN32 // Implicit (for now at least) in WIN32 is that we are using the Nvidia driver and it won't consume SPIRV yet
Tony Barbour01999182015-04-09 12:58:51 -0600584TEST_F(VkRenderTest, SPV_VKTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700585{
Tony Barbourf43b6982014-11-25 13:18:32 -0700586 static const char *vertShaderText =
587 "#version 140\n"
588 "#extension GL_ARB_separate_shader_objects : enable\n"
589 "#extension GL_ARB_shading_language_420pack : enable\n"
590 "\n"
591 "layout(binding = 0) uniform buf {\n"
592 " mat4 MVP;\n"
593 " vec4 position[3];\n"
594 " vec4 color[3];\n"
595 "} ubuf;\n"
596 "\n"
597 "layout (location = 0) out vec4 outColor;\n"
598 "\n"
599 "void main() \n"
600 "{\n"
601 " outColor = ubuf.color[gl_VertexID];\n"
602 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
603 "}\n";
604
605 static const char *fragShaderText =
606 "#version 140\n"
607 "#extension GL_ARB_separate_shader_objects : enable\n"
608 "#extension GL_ARB_shading_language_420pack : enable\n"
609 "\n"
610 "layout (location = 0) in vec4 inColor;\n"
611 "\n"
612 "void main()\n"
613 "{\n"
614 " gl_FragColor = inColor;\n"
615 "}\n";
616
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600617 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 -0700618
Cody Northrop1cfbd172015-06-03 16:49:20 -0600619 ScopedUseGlsl useGlsl(false);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600620 VKTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700621}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600622#endif
Tony Barbour01999182015-04-09 12:58:51 -0600623TEST_F(VkRenderTest, GreenTriangle)
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600624{
625 static const char *vertShaderText =
626 "#version 130\n"
627 "vec2 vertices[3];\n"
628 "void main() {\n"
629 " vertices[0] = vec2(-1.0, -1.0);\n"
630 " vertices[1] = vec2( 1.0, -1.0);\n"
631 " vertices[2] = vec2( 0.0, 1.0);\n"
632 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
633 "}\n";
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600634
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600635 static const char *fragShaderText =
636 "#version 130\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600637 "void main() {\n"
Steve K10b32512014-10-10 08:54:29 -0600638 " gl_FragColor = vec4(0,1,0,1);\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600639 "}\n";
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600640
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600641 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
642
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600643 VKTriangleTest(vertShaderText, fragShaderText, false);
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600644}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600645#ifndef _WIN32 // Implicit (for now at least) in WIN32 is that we are using the Nvidia driver and it won't consume SPIRV yet
Tony Barbour01999182015-04-09 12:58:51 -0600646TEST_F(VkRenderTest, SPV_GreenTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700647{
Tony Barbourf43b6982014-11-25 13:18:32 -0700648 static const char *vertShaderText =
649 "#version 130\n"
650 "vec2 vertices[3];\n"
651 "void main() {\n"
652 " vertices[0] = vec2(-1.0, -1.0);\n"
653 " vertices[1] = vec2( 1.0, -1.0);\n"
654 " vertices[2] = vec2( 0.0, 1.0);\n"
655 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
656 "}\n";
657
658 static const char *fragShaderText =
659 "#version 130\n"
660 "void main() {\n"
661 " gl_FragColor = vec4(0,1,0,1);\n"
662 "}\n";
663
Cody Northropacfb0492015-03-17 15:55:58 -0600664 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700665
Cody Northrop1cfbd172015-06-03 16:49:20 -0600666 ScopedUseGlsl useGlsl(false);
667
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600668 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700669}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600670#endif
Tony Barbour01999182015-04-09 12:58:51 -0600671TEST_F(VkRenderTest, YellowTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700672{
673 static const char *vertShaderText =
674 "#version 130\n"
675 "void main() {\n"
676 " vec2 vertices[3];"
677 " vertices[0] = vec2(-0.5, -0.5);\n"
678 " vertices[1] = vec2( 0.5, -0.5);\n"
679 " vertices[2] = vec2( 0.5, 0.5);\n"
680 " vec4 colors[3];\n"
681 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
682 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
683 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
684 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
685 "}\n";
686
687 static const char *fragShaderText =
688 "#version 130\n"
689 "void main() {\n"
690 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
691 "}\n";
692
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600693 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700694}
695
Tony Barbour01999182015-04-09 12:58:51 -0600696TEST_F(VkRenderTest, QuadWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600697{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600698 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600699 "#version 140\n"
700 "#extension GL_ARB_separate_shader_objects : enable\n"
701 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700702 //XYZ1( -1, -1, -1 )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600703 "layout (location = 0) in vec4 pos;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700704 //XYZ1( 0.f, 0.f, 0.f )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600705 "layout (location = 1) in vec4 inColor;\n"
706 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600707 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600708 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600709 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600710 "}\n";
711
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600712
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600713 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700714 "#version 140\n"
715 "#extension GL_ARB_separate_shader_objects : enable\n"
716 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600717 "layout (location = 0) in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700718 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600719 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700720 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600721 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600722
Tony Barbourf43b6982014-11-25 13:18:32 -0700723
724
725 ASSERT_NO_FATAL_FAILURE(InitState());
726 ASSERT_NO_FATAL_FAILURE(InitViewport());
727
Tony Barbour01999182015-04-09 12:58:51 -0600728 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000729 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700730
Tony Barbour01999182015-04-09 12:58:51 -0600731 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
732 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700733
Tony Barbour01999182015-04-09 12:58:51 -0600734 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -0700735 pipelineobj.AddShader(&vs);
736 pipelineobj.AddShader(&ps);
737
Tony Barbour01999182015-04-09 12:58:51 -0600738 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600739 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -0600740
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600741#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600742 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600743 MESH_BIND_ID, // binding ID
Tony Barbourf43b6982014-11-25 13:18:32 -0700744 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600745 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -0700746 };
747
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600748 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600749 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
750 vi_attribs[0].location = 0; // location, position
Tony Barbour8205d902015-04-16 15:59:00 -0600751 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600752 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
753 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
754 vi_attribs[1].location = 1; // location, color
Tony Barbour8205d902015-04-16 15:59:00 -0600755 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600756 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 -0700757
758 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
759 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600760 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -0700761
Tony Barboure4ed9942015-01-09 10:06:53 -0700762 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600763 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700764 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700765
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600766 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600767
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600768 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700769
Tony Barboure4ed9942015-01-09 10:06:53 -0700770 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
771
772 // render two triangles
773 cmdBuffer.Draw(0, 6, 0, 1);
774
775 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600776 EndCommandBuffer(cmdBuffer);
777
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600778 cmdBuffer.QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -0700779
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600780 RecordImages(m_renderTargets);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600781}
782
Tony Barbour01999182015-04-09 12:58:51 -0600783TEST_F(VkRenderTest, TriangleMRT)
Chia-I Wue09d1a72014-12-05 10:32:23 +0800784{
785 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600786 "#version 140\n"
787 "#extension GL_ARB_separate_shader_objects : enable\n"
788 "#extension GL_ARB_shading_language_420pack : enable\n"
789 "layout (location = 0) in vec4 pos;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800790 "void main() {\n"
791 " gl_Position = pos;\n"
792 "}\n";
793
794 static const char *fragShaderText =
795 "#version 130\n"
796 "void main() {\n"
797 " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
798 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
799 "}\n";
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600800 const float vb_data[][2] = {
Chia-I Wue09d1a72014-12-05 10:32:23 +0800801 { -1.0f, -1.0f },
802 { 1.0f, -1.0f },
803 { -1.0f, 1.0f }
804 };
805
806 ASSERT_NO_FATAL_FAILURE(InitState());
807 ASSERT_NO_FATAL_FAILURE(InitViewport());
808
Tony Barbour01999182015-04-09 12:58:51 -0600809 VkConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000810 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800811
Tony Barbour01999182015-04-09 12:58:51 -0600812 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
813 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800814
Tony Barbour01999182015-04-09 12:58:51 -0600815 VkPipelineObj pipelineobj(m_device);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800816 pipelineobj.AddShader(&vs);
817 pipelineobj.AddShader(&ps);
818
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600819#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600820 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600821 MESH_BUF_ID, // Binding ID
822 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600823 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Chia-I Wue09d1a72014-12-05 10:32:23 +0800824 };
825
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600826 VkVertexInputAttributeDescription vi_attrib;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600827 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
828 vi_attrib.location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -0600829 vi_attrib.format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600830 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
Chia-I Wue09d1a72014-12-05 10:32:23 +0800831
832 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
833 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600834 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800835
Tony Barbour01999182015-04-09 12:58:51 -0600836 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600837 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800838
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700839 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
Chia-I Wue09d1a72014-12-05 10:32:23 +0800840
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600841 VkPipelineCbAttachmentState att = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600842 att.blendEnable = VK_FALSE;
Chia-I Wue09d1a72014-12-05 10:32:23 +0800843 att.format = m_render_target_fmt;
844 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700845 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800846
Tony Barbour01999182015-04-09 12:58:51 -0600847 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700848
Tony Barbour5ed79702015-01-07 14:31:52 -0700849 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
850 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barboure4ed9942015-01-09 10:06:53 -0700851
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600852 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour5ed79702015-01-07 14:31:52 -0700853
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600854 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700855
Tony Barbour5ed79702015-01-07 14:31:52 -0700856 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700857#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600858 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour5ed79702015-01-07 14:31:52 -0700859 pDSDumpDot((char*)"triTest2.dot");
860#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600861
Tony Barbour5ed79702015-01-07 14:31:52 -0700862 // render triangle
863 cmdBuffer.Draw(0, 3, 0, 1);
864
865 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600866 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600867 cmdBuffer.QueueCommandBuffer();
Tony Barbour5ed79702015-01-07 14:31:52 -0700868
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600869 RecordImages(m_renderTargets);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800870}
871
Tony Barbour01999182015-04-09 12:58:51 -0600872TEST_F(VkRenderTest, QuadWithIndexedVertexFetch)
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700873{
874 static const char *vertShaderText =
875 "#version 140\n"
876 "#extension GL_ARB_separate_shader_objects : enable\n"
877 "#extension GL_ARB_shading_language_420pack : enable\n"
878 "layout(location = 0) in vec4 pos;\n"
879 "layout(location = 1) in vec4 inColor;\n"
880 "layout(location = 0) out vec4 outColor;\n"
881 "void main() {\n"
882 " outColor = inColor;\n"
883 " gl_Position = pos;\n"
884 "}\n";
885
886
887 static const char *fragShaderText =
888 "#version 140\n"
889 "#extension GL_ARB_separate_shader_objects : enable\n"
890 "#extension GL_ARB_shading_language_420pack : enable\n"
891 "layout(location = 0) in vec4 color;\n"
892 "void main() {\n"
893 " gl_FragColor = color;\n"
894 "}\n";
895
896 const Vertex g_vbData[] =
897 {
898 // first tri
899 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
900 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
901 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
902
903 // second tri
904 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
905 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
906 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
907 };
908
909 const uint16_t g_idxData[6] = {
910 0, 1, 2,
911 3, 4, 5,
912 };
913
914 ASSERT_NO_FATAL_FAILURE(InitState());
915 ASSERT_NO_FATAL_FAILURE(InitViewport());
916
Tony Barbour01999182015-04-09 12:58:51 -0600917 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000918 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700919
Tony Barbour01999182015-04-09 12:58:51 -0600920 VkIndexBufferObj indexBuffer(m_device);
Tony Barbour8205d902015-04-16 15:59:00 -0600921 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), VK_INDEX_TYPE_UINT16, g_idxData);
Mark Lobodzinskid30f82a2015-02-16 14:24:23 -0600922 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700923
Tony Barbour01999182015-04-09 12:58:51 -0600924 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
925 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700926
Tony Barbour01999182015-04-09 12:58:51 -0600927 VkPipelineObj pipelineobj(m_device);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700928 pipelineobj.AddShader(&vs);
929 pipelineobj.AddShader(&ps);
930
Tony Barbour01999182015-04-09 12:58:51 -0600931 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600932 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
933 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, indexBuffer);
Tony Barbour83a83802015-04-02 15:43:15 -0600934
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700935
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600936#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600937 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600938 MESH_BIND_ID, // binding ID
939 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600940 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700941 };
942
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600943 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600944 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
945 vi_attribs[0].location = 0; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600946 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600947 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
948 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
949 vi_attribs[1].location = 1; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600950 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600951 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700952
953 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
954 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700955
956 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600957 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700958 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600959 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barboure4ed9942015-01-09 10:06:53 -0700960
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600961 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700962
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700963#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600964 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700965 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700966#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700967
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600968 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600969 cmdBuffer.BindIndexBuffer(&indexBuffer, 0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700970
971 // render two triangles
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700972 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700973
974 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600975 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600976 cmdBuffer.QueueCommandBuffer();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700977
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600978 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700979}
980
Tony Barbour01999182015-04-09 12:58:51 -0600981TEST_F(VkRenderTest, GreyandRedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -0700982{
983 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -0700984
GregF6bef1212014-12-02 15:41:44 -0700985 static const char *vertShaderText =
986 "#version 140\n"
987 "#extension GL_ARB_separate_shader_objects : enable\n"
988 "#extension GL_ARB_shading_language_420pack : enable\n"
989 "layout (location = 0) in vec4 pos;\n"
990 "layout (location = 0) out vec4 outColor;\n"
991 "layout (location = 1) out vec4 outColor2;\n"
992 "void main() {\n"
993 " gl_Position = pos;\n"
994 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
995 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
996 "}\n";
997
998 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -0700999 "#version 330\n"
1000 "#extension GL_ARB_separate_shader_objects : enable\n"
1001 "#extension GL_ARB_shading_language_420pack : enable\n"
1002 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1003 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1004 "layout (location = 0) in vec4 color;\n"
1005 "layout (location = 1) in vec4 color2;\n"
1006 "void main() {\n"
1007 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1008 " float dist_squared = dot(pos, pos);\n"
1009 " gl_FragColor = (dist_squared < 400.0)\n"
1010 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1011 " : color2;\n"
1012 "}\n";
1013
1014 ASSERT_NO_FATAL_FAILURE(InitState());
1015 ASSERT_NO_FATAL_FAILURE(InitViewport());
1016
Tony Barbour01999182015-04-09 12:58:51 -06001017 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001018 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001019
Tony Barbour01999182015-04-09 12:58:51 -06001020 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1021 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001022
Tony Barbour01999182015-04-09 12:58:51 -06001023 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001024 pipelineobj.AddShader(&vs);
1025 pipelineobj.AddShader(&ps);
1026
Tony Barbour01999182015-04-09 12:58:51 -06001027 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001028 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001029
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001030#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001031 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001032 MESH_BIND_ID, // binding ID
1033 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001034 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001035 };
1036
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001037 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001038 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1039 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001040 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001041 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001042
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001043 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001044 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001045 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001046
Tony Barbourdd4c9642015-01-09 12:55:14 -07001047 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001048 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001049 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1050
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001051 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001052
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001053 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001054
1055 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1056#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001057 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001058 pDSDumpDot((char*)"triTest2.dot");
1059#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001060
Tony Barbourdd4c9642015-01-09 12:55:14 -07001061 // render triangle
1062 cmdBuffer.Draw(0, 6, 0, 1);
1063
1064 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001065 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001066 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001067
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001068 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001069}
1070
Tony Barbour01999182015-04-09 12:58:51 -06001071TEST_F(VkRenderTest, RedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -07001072{
1073 // This tests that we correctly handle unread fragment inputs
1074
1075 static const char *vertShaderText =
1076 "#version 140\n"
1077 "#extension GL_ARB_separate_shader_objects : enable\n"
1078 "#extension GL_ARB_shading_language_420pack : enable\n"
1079 "layout (location = 0) in vec4 pos;\n"
1080 "layout (location = 0) out vec4 outColor;\n"
1081 "layout (location = 1) out vec4 outColor2;\n"
1082 "void main() {\n"
1083 " gl_Position = pos;\n"
1084 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1085 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1086 "}\n";
1087
1088 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001089 "#version 330\n"
1090 "#extension GL_ARB_separate_shader_objects : enable\n"
1091 "#extension GL_ARB_shading_language_420pack : enable\n"
1092 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1093 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1094 "layout (location = 0) in vec4 color;\n"
1095 "layout (location = 1) in vec4 color2;\n"
1096 "void main() {\n"
1097 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1098 " float dist_squared = dot(pos, pos);\n"
1099 " gl_FragColor = (dist_squared < 400.0)\n"
1100 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1101 " : color2;\n"
1102 "}\n";
1103
1104 ASSERT_NO_FATAL_FAILURE(InitState());
1105 ASSERT_NO_FATAL_FAILURE(InitViewport());
1106
Tony Barbour01999182015-04-09 12:58:51 -06001107 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001108 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001109
Tony Barbour01999182015-04-09 12:58:51 -06001110 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1111 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001112
Tony Barbour01999182015-04-09 12:58:51 -06001113 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001114 pipelineobj.AddShader(&vs);
1115 pipelineobj.AddShader(&ps);
1116
Tony Barbour01999182015-04-09 12:58:51 -06001117 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001118 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001119
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001120#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001121 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001122 MESH_BIND_ID, // binding ID
1123 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001124 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001125 };
1126
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001127 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001128 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1129 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001130 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001131 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001132
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001133 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001134 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001135 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001136
Tony Barbourdd4c9642015-01-09 12:55:14 -07001137 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001138 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001139 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1140
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001141 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001142
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001143 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001144
1145 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1146#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001147 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001148 pDSDumpDot((char*)"triTest2.dot");
1149#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001150 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001151 cmdBuffer.Draw(0, 6, 0, 1);
1152
1153 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001154 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001155 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001156
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001157 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001158}
1159
Tony Barbour01999182015-04-09 12:58:51 -06001160TEST_F(VkRenderTest, GreyCirclesonBlueFade)
GregF6bef1212014-12-02 15:41:44 -07001161{
1162 // This tests reading gl_ClipDistance from FS
1163
1164 static const char *vertShaderText =
1165 "#version 330\n"
1166 "#extension GL_ARB_separate_shader_objects : enable\n"
1167 "#extension GL_ARB_shading_language_420pack : enable\n"
1168 "out gl_PerVertex {\n"
1169 " vec4 gl_Position;\n"
1170 " float gl_ClipDistance[1];\n"
1171 "};\n"
1172 "layout (location = 0) in vec4 pos;\n"
1173 "layout (location = 0) out vec4 outColor;\n"
1174 "layout (location = 1) out vec4 outColor2;\n"
1175 "void main() {\n"
1176 " gl_Position = pos;\n"
1177 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1178 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1179 " float dists[3];\n"
1180 " dists[0] = 0.0;\n"
1181 " dists[1] = 1.0;\n"
1182 " dists[2] = 1.0;\n"
1183 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1184 "}\n";
1185
1186
1187 static const char *fragShaderText =
1188 //"#version 140\n"
1189 "#version 330\n"
1190 "#extension GL_ARB_separate_shader_objects : enable\n"
1191 "#extension GL_ARB_shading_language_420pack : enable\n"
1192 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1193 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1194 "layout (location = 0) in vec4 color;\n"
1195 "layout (location = 1) in vec4 color2;\n"
1196 "void main() {\n"
1197 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1198 " float dist_squared = dot(pos, pos);\n"
1199 " gl_FragColor = (dist_squared < 400.0)\n"
1200 " ? color * gl_ClipDistance[0]\n"
1201 " : color2;\n"
1202 "}\n";
1203
1204 ASSERT_NO_FATAL_FAILURE(InitState());
1205 ASSERT_NO_FATAL_FAILURE(InitViewport());
1206
Tony Barbour01999182015-04-09 12:58:51 -06001207 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001208 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001209
Tony Barbour01999182015-04-09 12:58:51 -06001210 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1211 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001212
Tony Barbour01999182015-04-09 12:58:51 -06001213 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001214 pipelineobj.AddShader(&vs);
1215 pipelineobj.AddShader(&ps);
1216
Tony Barbour01999182015-04-09 12:58:51 -06001217 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001218 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001219
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001220#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001221 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001222 MESH_BIND_ID, // binding ID
1223 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001224 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001225 };
1226
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001227 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001228 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1229 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001230 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001231 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001232
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001233 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001234 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001235 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001236
Tony Barbourdd4c9642015-01-09 12:55:14 -07001237 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001238 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001239 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF6bef1212014-12-02 15:41:44 -07001240
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001241 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001242
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001243 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001244
1245 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1246#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001247 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001248 pDSDumpDot((char*)"triTest2.dot");
1249#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001250
1251 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001252 cmdBuffer.Draw(0, 6, 0, 1);
1253
1254 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001255 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001256 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001257
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001258 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001259}
Tony Barbourf43b6982014-11-25 13:18:32 -07001260
Tony Barbour01999182015-04-09 12:58:51 -06001261TEST_F(VkRenderTest, GreyCirclesonBlueDiscard)
GregF7a23c792014-12-02 17:19:34 -07001262{
1263 static const char *vertShaderText =
1264 "#version 140\n"
1265 "#extension GL_ARB_separate_shader_objects : enable\n"
1266 "#extension GL_ARB_shading_language_420pack : enable\n"
1267 "layout (location = 0) in vec4 pos;\n"
1268 "layout (location = 0) out vec4 outColor;\n"
1269 "layout (location = 1) out vec4 outColor2;\n"
1270 "void main() {\n"
1271 " gl_Position = pos;\n"
1272 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1273 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1274 "}\n";
1275
1276
1277 static const char *fragShaderText =
GregF7a23c792014-12-02 17:19:34 -07001278 "#version 330\n"
1279 "#extension GL_ARB_separate_shader_objects : enable\n"
1280 "#extension GL_ARB_shading_language_420pack : enable\n"
1281 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1282 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1283 "layout (location = 0) in vec4 color;\n"
1284 "layout (location = 1) in vec4 color2;\n"
1285 "void main() {\n"
1286 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1287 " float dist_squared = dot(pos, pos);\n"
1288 " if (dist_squared < 100.0)\n"
1289 " discard;\n"
1290 " gl_FragColor = (dist_squared < 400.0)\n"
1291 " ? color\n"
1292 " : color2;\n"
1293 "}\n";
1294
1295 ASSERT_NO_FATAL_FAILURE(InitState());
1296 ASSERT_NO_FATAL_FAILURE(InitViewport());
1297
Tony Barbour01999182015-04-09 12:58:51 -06001298 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001299 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001300
Tony Barbour01999182015-04-09 12:58:51 -06001301 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1302 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF7a23c792014-12-02 17:19:34 -07001303
Tony Barbour01999182015-04-09 12:58:51 -06001304 VkPipelineObj pipelineobj(m_device);
GregF7a23c792014-12-02 17:19:34 -07001305 pipelineobj.AddShader(&vs);
1306 pipelineobj.AddShader(&ps);
1307
Tony Barbour01999182015-04-09 12:58:51 -06001308 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001309 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001310
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001311#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001312 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001313 MESH_BIND_ID, // binding ID
1314 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001315 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF7a23c792014-12-02 17:19:34 -07001316 };
1317
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001318 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001319 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1320 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001321 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001322 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF7a23c792014-12-02 17:19:34 -07001323
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001324 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF7a23c792014-12-02 17:19:34 -07001325 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001326 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF7a23c792014-12-02 17:19:34 -07001327
Tony Barbourdd4c9642015-01-09 12:55:14 -07001328 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001329 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001330 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1331
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001332 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001333
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001334 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001335
1336 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1337#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001338 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001339 pDSDumpDot((char*)"triTest2.dot");
1340#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001341
1342 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001343 cmdBuffer.Draw(0, 6, 0, 1);
1344
1345 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001346 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001347 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001348
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001349 RecordImages(m_renderTargets);
GregF7a23c792014-12-02 17:19:34 -07001350}
1351
1352
Tony Barbour01999182015-04-09 12:58:51 -06001353TEST_F(VkRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001354{
1355 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001356 "#version 140\n"
1357 "#extension GL_ARB_separate_shader_objects : enable\n"
1358 "#extension GL_ARB_shading_language_420pack : enable\n"
1359 "\n"
1360 "layout(binding = 0) uniform buf {\n"
1361 " mat4 MVP;\n"
1362 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001363 "void main() {\n"
1364 " vec2 vertices[3];"
1365 " vertices[0] = vec2(-0.5, -0.5);\n"
1366 " vertices[1] = vec2( 0.5, -0.5);\n"
1367 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001368 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001369 "}\n";
1370
1371 static const char *fragShaderText =
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001372 "#version 130\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001373 "void main() {\n"
Cody Northrop78eac042014-10-10 15:45:00 -06001374 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001375 "}\n";
1376
Tony Barbourf43b6982014-11-25 13:18:32 -07001377 ASSERT_NO_FATAL_FAILURE(InitState());
1378 ASSERT_NO_FATAL_FAILURE(InitViewport());
1379
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001380 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001381 glm::mat4 Projection = glm::mat4(1.0f);
1382 glm::mat4 View = glm::mat4(1.0f);
1383 glm::mat4 Model = glm::mat4(1.0f);
1384 glm::mat4 MVP = Projection * View * Model;
1385 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1386
Tony Barbour01999182015-04-09 12:58:51 -06001387 VkConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1388 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1389 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001390
Tony Barbour01999182015-04-09 12:58:51 -06001391 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001392 pipelineobj.AddShader(&vs);
1393 pipelineobj.AddShader(&ps);
1394
1395 // Create descriptor set and attach the constant buffer to it
Tony Barbour01999182015-04-09 12:58:51 -06001396 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001397 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001398
Tony Barbourdd4c9642015-01-09 12:55:14 -07001399 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001400 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001401 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001402
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001403 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001404
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001405 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001406
1407 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1408#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001409 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001410 pDSDumpDot((char*)"triTest2.dot");
1411#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001412
1413 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001414 cmdBuffer.Draw(0, 6, 0, 1);
1415
1416 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001417 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001418 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001419
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001420 RecordImages(m_renderTargets);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001421
1422 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001423}
1424
Tony Barbour01999182015-04-09 12:58:51 -06001425TEST_F(VkRenderTest, MixTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07001426{
1427 // This tests location applied to varyings. Notice that we have switched foo
1428 // and bar in the FS. The triangle should be blended with red, green and blue
1429 // corners.
1430 static const char *vertShaderText =
1431 "#version 140\n"
1432 "#extension GL_ARB_separate_shader_objects : enable\n"
1433 "#extension GL_ARB_shading_language_420pack : enable\n"
1434 "layout (location=0) out vec4 bar;\n"
1435 "layout (location=1) out vec4 foo;\n"
1436 "layout (location=2) out float scale;\n"
1437 "vec2 vertices[3];\n"
1438 "void main() {\n"
1439 " vertices[0] = vec2(-1.0, -1.0);\n"
1440 " vertices[1] = vec2( 1.0, -1.0);\n"
1441 " vertices[2] = vec2( 0.0, 1.0);\n"
1442 "vec4 colors[3];\n"
1443 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1444 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1445 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1446 " foo = colors[gl_VertexID % 3];\n"
1447 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1448 " scale = 1.0;\n"
1449 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1450 "}\n";
1451
1452 static const char *fragShaderText =
1453 "#version 140\n"
1454 "#extension GL_ARB_separate_shader_objects : enable\n"
1455 "#extension GL_ARB_shading_language_420pack : enable\n"
1456 "layout (location = 1) in vec4 bar;\n"
1457 "layout (location = 0) in vec4 foo;\n"
1458 "layout (location = 2) in float scale;\n"
1459 "void main() {\n"
1460 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
1461 "}\n";
1462
1463 ASSERT_NO_FATAL_FAILURE(InitState());
1464 ASSERT_NO_FATAL_FAILURE(InitViewport());
1465
Tony Barbour01999182015-04-09 12:58:51 -06001466 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1467 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001468
Tony Barbour01999182015-04-09 12:58:51 -06001469 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001470 pipelineobj.AddShader(&vs);
1471 pipelineobj.AddShader(&ps);
1472
Tony Barbour01999182015-04-09 12:58:51 -06001473 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06001474 descriptorSet.AppendDummy();
Tony Barbourf43b6982014-11-25 13:18:32 -07001475
Tony Barbourdd4c9642015-01-09 12:55:14 -07001476 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001477 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001478 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1479
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001480 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001481
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001482 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001483
1484#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001485 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001486 pDSDumpDot((char*)"triTest2.dot");
1487#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001488
Tony Barbourdd4c9642015-01-09 12:55:14 -07001489 // render triangle
1490 cmdBuffer.Draw(0, 3, 0, 1);
1491
1492 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001493 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001494 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001495
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001496 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001497}
1498
Tony Barbour01999182015-04-09 12:58:51 -06001499TEST_F(VkRenderTest, QuadVertFetchAndVertID)
Tony Barbourf43b6982014-11-25 13:18:32 -07001500{
1501 // This tests that attributes work in the presence of gl_VertexID
1502
1503 static const char *vertShaderText =
1504 "#version 140\n"
1505 "#extension GL_ARB_separate_shader_objects : enable\n"
1506 "#extension GL_ARB_shading_language_420pack : enable\n"
1507 //XYZ1( -1, -1, -1 )
1508 "layout (location = 0) in vec4 pos;\n"
1509 //XYZ1( 0.f, 0.f, 0.f )
1510 "layout (location = 1) in vec4 inColor;\n"
1511 "layout (location = 0) out vec4 outColor;\n"
1512 "void main() {\n"
1513 " outColor = inColor;\n"
1514 " vec4 vertices[3];"
1515 " vertices[gl_VertexID % 3] = pos;\n"
1516 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1517 "}\n";
1518
1519
1520 static const char *fragShaderText =
1521 "#version 140\n"
1522 "#extension GL_ARB_separate_shader_objects : enable\n"
1523 "#extension GL_ARB_shading_language_420pack : enable\n"
1524 "layout (location = 0) in vec4 color;\n"
1525 "void main() {\n"
1526 " gl_FragColor = color;\n"
1527 "}\n";
1528
1529 ASSERT_NO_FATAL_FAILURE(InitState());
1530 ASSERT_NO_FATAL_FAILURE(InitViewport());
1531
Tony Barbour01999182015-04-09 12:58:51 -06001532 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001533 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001534
Tony Barbour01999182015-04-09 12:58:51 -06001535 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1536 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001537
Tony Barbour01999182015-04-09 12:58:51 -06001538 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001539 pipelineobj.AddShader(&vs);
1540 pipelineobj.AddShader(&ps);
1541
Tony Barbour01999182015-04-09 12:58:51 -06001542 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001543 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001544
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001545#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001546 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001547 MESH_BUF_ID, // Binding ID
1548 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001549 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001550 };
1551
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001552 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001553 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1554 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001555 vi_attribs[0].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001556 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1557 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1558 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001559 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001560 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001561
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001562 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001563 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001564 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001565
Tony Barbourdd4c9642015-01-09 12:55:14 -07001566 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001567 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001568 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1569
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001570 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001571
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001572 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001573
1574 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1575#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001576 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001577 pDSDumpDot((char*)"triTest2.dot");
1578#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001579
1580 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001581 cmdBuffer.Draw(0, 6, 0, 1);
1582
1583 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001584 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001585 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001586
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001587 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001588}
1589
Tony Barbour01999182015-04-09 12:58:51 -06001590TEST_F(VkRenderTest, QuadSparseVertFetch)
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001591{
1592 // This tests that attributes work in the presence of gl_VertexID
1593
1594 static const char *vertShaderText =
1595 "#version 140\n"
1596 "#extension GL_ARB_separate_shader_objects : enable\n"
1597 "#extension GL_ARB_shading_language_420pack : enable\n"
1598 //XYZ1( -1, -1, -1 )
1599 "layout (location = 1) in vec4 pos;\n"
1600 "layout (location = 4) in vec4 inColor;\n"
1601 //XYZ1( 0.f, 0.f, 0.f )
1602 "layout (location = 0) out vec4 outColor;\n"
1603 "void main() {\n"
1604 " outColor = inColor;\n"
1605 " gl_Position = pos;\n"
1606 "}\n";
1607
1608
1609 static const char *fragShaderText =
1610 "#version 140\n"
1611 "#extension GL_ARB_separate_shader_objects : enable\n"
1612 "#extension GL_ARB_shading_language_420pack : enable\n"
1613 "layout (location = 0) in vec4 color;\n"
1614 "void main() {\n"
1615 " gl_FragColor = color;\n"
1616 "}\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"
1725 "void main() {\n"
1726 " gl_FragColor = color;\n"
1727 "}\n";
1728
1729 ASSERT_NO_FATAL_FAILURE(InitState());
1730 ASSERT_NO_FATAL_FAILURE(InitViewport());
1731
Tony Barbour01999182015-04-09 12:58:51 -06001732 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001733 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001734
Tony Barbour01999182015-04-09 12:58:51 -06001735 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1736 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001737
Tony Barbour01999182015-04-09 12:58:51 -06001738 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001739 pipelineobj.AddShader(&vs);
1740 pipelineobj.AddShader(&ps);
1741
Tony Barbour01999182015-04-09 12:58:51 -06001742 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001743 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001744
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001745#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001746 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001747 MESH_BUF_ID, // Binding ID
1748 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001749 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001750 };
1751
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001752 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001753 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1754 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001755 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001756 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1757 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1758 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001759 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001760 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001761
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001762 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001763 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001764 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001765
Tony Barbourdd4c9642015-01-09 12:55:14 -07001766 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001767 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001768 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001769
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001770 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001771
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001772 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001773
1774 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1775#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001776 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001777 pDSDumpDot((char*)"triTest2.dot");
1778#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001779
1780 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001781 cmdBuffer.Draw(0, 6, 0, 1);
1782
1783 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001784 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001785 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001786
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001787 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001788}
1789
Tony Barbour01999182015-04-09 12:58:51 -06001790TEST_F(VkRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001791{
1792 static const char *vertShaderText =
1793 "#version 140\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001794 "#extension GL_ARB_separate_shader_objects : enable\n"
1795 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001796 "layout (std140) uniform bufferVals {\n"
1797 " mat4 mvp;\n"
1798 "} myBufferVals;\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001799 "layout (location = 0) in vec4 pos;\n"
1800 "layout (location = 1) in vec4 inColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001801 "out vec4 outColor;\n"
1802 "void main() {\n"
1803 " outColor = inColor;\n"
1804 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001805 " gl_Position.y = -gl_Position.y;\n"
1806 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001807 "}\n";
1808
1809 static const char *fragShaderText =
1810 "#version 130\n"
1811 "in vec4 color;\n"
1812 "void main() {\n"
1813 " gl_FragColor = color;\n"
1814 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001815 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001816
Tony Barbourf43b6982014-11-25 13:18:32 -07001817 glm::mat4 View = glm::lookAt(
1818 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1819 glm::vec3(0,0,0), // and looks at the origin
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001820 glm::vec3(0,-1,0) // Head is up (set to 0,-1,0 to look upside-down)
Tony Barbourf43b6982014-11-25 13:18:32 -07001821 );
1822
1823 glm::mat4 Model = glm::mat4(1.0f);
1824
1825 glm::mat4 MVP = Projection * View * Model;
1826
1827 ASSERT_NO_FATAL_FAILURE(InitState());
1828 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour8bef8ee2015-05-22 09:44:58 -06001829 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07001830
Tony Barbour01999182015-04-09 12:58:51 -06001831 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 -07001832 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1833
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001834 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07001835
Tony Barbour01999182015-04-09 12:58:51 -06001836 VkConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1837 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1838 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001839
Tony Barbour01999182015-04-09 12:58:51 -06001840 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001841 pipelineobj.AddShader(&vs);
1842 pipelineobj.AddShader(&ps);
1843
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001844 VkPipelineDsStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001845 ds_state.depthTestEnable = VK_TRUE;
1846 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06001847 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001848 ds_state.depthBoundsEnable = VK_FALSE;
1849 ds_state.stencilTestEnable = VK_FALSE;
1850 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
1851 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
1852 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06001853 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
1854 ds_state.format = VK_FORMAT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001855 ds_state.front = ds_state.back;
1856 pipelineobj.SetDepthStencil(&ds_state);
1857
Tony Barbour01999182015-04-09 12:58:51 -06001858 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001859 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001860
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001861#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001862 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001863 MESH_BUF_ID, // Binding ID
1864 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001865 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001866 };
Tony Barbourf43b6982014-11-25 13:18:32 -07001867
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001868 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001869 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1870 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001871 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001872 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1873 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1874 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001875 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001876 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001877
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001878 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001879 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001880 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001881
Tony Barbour17c6ab12015-03-27 17:03:18 -06001882 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour17c6ab12015-03-27 17:03:18 -06001883
Tony Barbour01999182015-04-09 12:58:51 -06001884 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -07001885 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001886
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001887 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001888 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001889
Tony Barboure4ed9942015-01-09 10:06:53 -07001890 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1891#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001892 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barboure4ed9942015-01-09 10:06:53 -07001893 pDSDumpDot((char*)"triTest2.dot");
1894#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001895
1896 // render triangles
Tony Barboure4ed9942015-01-09 10:06:53 -07001897 cmdBuffer.Draw(0, 36, 0, 1);
1898
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001899
Tony Barboure4ed9942015-01-09 10:06:53 -07001900 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001901 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001902 cmdBuffer.QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -07001903
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001904 RecordImages(m_renderTargets);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001905}
1906
Tony Barbour01999182015-04-09 12:58:51 -06001907TEST_F(VkRenderTest, VSTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07001908{
1909 // The expected result from this test is a green and red triangle;
1910 // one red vertex on the left, two green vertices on the right.
1911 static const char *vertShaderText =
1912 "#version 130\n"
1913 "out vec4 texColor;\n"
1914 "uniform sampler2D surface;\n"
1915 "void main() {\n"
1916 " vec2 vertices[3];"
1917 " vertices[0] = vec2(-0.5, -0.5);\n"
1918 " vertices[1] = vec2( 0.5, -0.5);\n"
1919 " vertices[2] = vec2( 0.5, 0.5);\n"
1920 " vec2 positions[3];"
1921 " positions[0] = vec2( 0.0, 0.0);\n"
1922 " positions[1] = vec2( 0.25, 0.1);\n"
1923 " positions[2] = vec2( 0.1, 0.25);\n"
1924 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1925 " texColor = textureLod(surface, samplePos, 0.0);\n"
1926 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1927 "}\n";
1928
1929 static const char *fragShaderText =
1930 "#version 130\n"
1931 "in vec4 texColor;\n"
1932 "void main() {\n"
1933 " gl_FragColor = texColor;\n"
1934 "}\n";
1935
1936 ASSERT_NO_FATAL_FAILURE(InitState());
1937 ASSERT_NO_FATAL_FAILURE(InitViewport());
1938
Tony Barbour01999182015-04-09 12:58:51 -06001939 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1940 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
1941 VkSamplerObj sampler(m_device);
1942 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001943
Tony Barbour01999182015-04-09 12:58:51 -06001944 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001945 pipelineobj.AddShader(&vs);
1946 pipelineobj.AddShader(&ps);
1947
Tony Barbour01999182015-04-09 12:58:51 -06001948 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001949 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001950
Tony Barbourdd4c9642015-01-09 12:55:14 -07001951 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001952 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001953 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001954
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001955 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001956
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001957 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001958
1959#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001960 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001961 pDSDumpDot((char*)"triTest2.dot");
1962#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001963
Tony Barbourdd4c9642015-01-09 12:55:14 -07001964 // render triangle
1965 cmdBuffer.Draw(0, 3, 0, 1);
1966
1967 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001968 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001969 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001970
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001971 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001972}
Tony Barbour01999182015-04-09 12:58:51 -06001973TEST_F(VkRenderTest, TexturedTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07001974{
1975 // The expected result from this test is a red and green checkered triangle
1976 static const char *vertShaderText =
1977 "#version 140\n"
1978 "#extension GL_ARB_separate_shader_objects : enable\n"
1979 "#extension GL_ARB_shading_language_420pack : enable\n"
1980 "layout (location = 0) out vec2 samplePos;\n"
1981 "void main() {\n"
1982 " vec2 vertices[3];"
1983 " vertices[0] = vec2(-0.5, -0.5);\n"
1984 " vertices[1] = vec2( 0.5, -0.5);\n"
1985 " vertices[2] = vec2( 0.5, 0.5);\n"
1986 " vec2 positions[3];"
1987 " positions[0] = vec2( 0.0, 0.0);\n"
1988 " positions[1] = vec2( 1.0, 0.0);\n"
1989 " positions[2] = vec2( 1.0, 1.0);\n"
1990 " samplePos = positions[gl_VertexID % 3];\n"
1991 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1992 "}\n";
1993
1994 static const char *fragShaderText =
1995 "#version 140\n"
1996 "#extension GL_ARB_separate_shader_objects : enable\n"
1997 "#extension GL_ARB_shading_language_420pack : enable\n"
1998 "layout (location = 0) in vec2 samplePos;\n"
1999 "layout (binding = 0) uniform sampler2D surface;\n"
2000 "layout (location=0) out vec4 outColor;\n"
2001 "void main() {\n"
2002 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2003 " outColor = texColor;\n"
2004 "}\n";
2005
2006 ASSERT_NO_FATAL_FAILURE(InitState());
2007 ASSERT_NO_FATAL_FAILURE(InitViewport());
2008
Tony Barbour01999182015-04-09 12:58:51 -06002009 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2010 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2011 VkSamplerObj sampler(m_device);
2012 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002013
Tony Barbour01999182015-04-09 12:58:51 -06002014 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002015 pipelineobj.AddShader(&vs);
2016 pipelineobj.AddShader(&ps);
2017
Tony Barbour01999182015-04-09 12:58:51 -06002018 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002019 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002020
Tony Barbourdd4c9642015-01-09 12:55:14 -07002021 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002022 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002023 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2024
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002025 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002026
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002027 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002028
2029#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002030 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002031 pDSDumpDot((char*)"triTest2.dot");
2032#endif
2033 // render triangle
2034 cmdBuffer.Draw(0, 3, 0, 1);
2035
2036 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002037 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002038 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002039
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002040 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002041}
Tony Barbour01999182015-04-09 12:58:51 -06002042TEST_F(VkRenderTest, TexturedTriangleClip)
Tony Barbourf43b6982014-11-25 13:18:32 -07002043{
2044 // The expected result from this test is a red and green checkered triangle
2045 static const char *vertShaderText =
2046 "#version 330\n"
2047 "#extension GL_ARB_separate_shader_objects : enable\n"
2048 "#extension GL_ARB_shading_language_420pack : enable\n"
2049 "layout (location = 0) out vec2 samplePos;\n"
2050 "out gl_PerVertex {\n"
2051 " vec4 gl_Position;\n"
2052 " float gl_ClipDistance[1];\n"
2053 "};\n"
2054 "void main() {\n"
2055 " vec2 vertices[3];"
2056 " vertices[0] = vec2(-0.5, -0.5);\n"
2057 " vertices[1] = vec2( 0.5, -0.5);\n"
2058 " vertices[2] = vec2( 0.5, 0.5);\n"
2059 " vec2 positions[3];"
2060 " positions[0] = vec2( 0.0, 0.0);\n"
2061 " positions[1] = vec2( 1.0, 0.0);\n"
2062 " positions[2] = vec2( 1.0, 1.0);\n"
2063 " float dists[3];\n"
2064 " dists[0] = 1.0;\n"
2065 " dists[1] = 1.0;\n"
2066 " dists[2] = -1.0;\n"
2067 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2068 " samplePos = positions[gl_VertexID % 3];\n"
2069 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2070 "}\n";
2071
2072 static const char *fragShaderText =
2073 "#version 140\n"
2074 "#extension GL_ARB_separate_shader_objects : enable\n"
2075 "#extension GL_ARB_shading_language_420pack : enable\n"
2076 "layout (location = 0) in vec2 samplePos;\n"
2077 "layout (binding = 0) uniform sampler2D surface;\n"
2078 "layout (location=0) out vec4 outColor;\n"
2079 "void main() {\n"
2080 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2081 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2082 " outColor = texColor;\n"
2083 "}\n";
2084
2085
2086 ASSERT_NO_FATAL_FAILURE(InitState());
2087 ASSERT_NO_FATAL_FAILURE(InitViewport());
2088
Tony Barbour01999182015-04-09 12:58:51 -06002089 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2090 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2091 VkSamplerObj sampler(m_device);
2092 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002093
Tony Barbour01999182015-04-09 12:58:51 -06002094 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002095 pipelineobj.AddShader(&vs);
2096 pipelineobj.AddShader(&ps);
2097
Tony Barbour01999182015-04-09 12:58:51 -06002098 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002099 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002100
Tony Barbourdd4c9642015-01-09 12:55:14 -07002101 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002102 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002103 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2104
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002105 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002106
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002107 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002108
2109#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002110 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002111 pDSDumpDot((char*)"triTest2.dot");
2112#endif
2113 // render triangle
2114 cmdBuffer.Draw(0, 3, 0, 1);
2115
2116 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002117 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002118 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002119
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002120 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002121}
Tony Barbour01999182015-04-09 12:58:51 -06002122TEST_F(VkRenderTest, FSTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002123{
2124 // The expected result from this test is a red and green checkered triangle
2125 static const char *vertShaderText =
2126 "#version 140\n"
2127 "#extension GL_ARB_separate_shader_objects : enable\n"
2128 "#extension GL_ARB_shading_language_420pack : enable\n"
2129 "layout (location = 0) out vec2 samplePos;\n"
2130 "void main() {\n"
2131 " vec2 vertices[3];"
2132 " vertices[0] = vec2(-0.5, -0.5);\n"
2133 " vertices[1] = vec2( 0.5, -0.5);\n"
2134 " vertices[2] = vec2( 0.5, 0.5);\n"
2135 " vec2 positions[3];"
2136 " positions[0] = vec2( 0.0, 0.0);\n"
2137 " positions[1] = vec2( 1.0, 0.0);\n"
2138 " positions[2] = vec2( 1.0, 1.0);\n"
2139 " samplePos = positions[gl_VertexID % 3];\n"
2140 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2141 "}\n";
2142
2143 static const char *fragShaderText =
2144 "#version 140\n"
2145 "#extension GL_ARB_separate_shader_objects : enable\n"
2146 "#extension GL_ARB_shading_language_420pack : enable\n"
2147 "layout (location = 0) in vec2 samplePos;\n"
2148 "layout (binding = 0) uniform sampler2D surface;\n"
2149 "layout (location=0) out vec4 outColor;\n"
2150 "void main() {\n"
2151 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2152 " outColor = texColor;\n"
2153 "}\n";
2154
2155 ASSERT_NO_FATAL_FAILURE(InitState());
2156 ASSERT_NO_FATAL_FAILURE(InitViewport());
2157
Tony Barbour01999182015-04-09 12:58:51 -06002158 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2159 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2160 VkSamplerObj sampler(m_device);
2161 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002162
Tony Barbour01999182015-04-09 12:58:51 -06002163 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002164 pipelineobj.AddShader(&vs);
2165 pipelineobj.AddShader(&ps);
2166
Tony Barbour01999182015-04-09 12:58:51 -06002167 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002168 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002169
Tony Barbourdd4c9642015-01-09 12:55:14 -07002170 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002171 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002172 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2173
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002174 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002175
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002176 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002177
2178#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002179 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002180 pDSDumpDot((char*)"triTest2.dot");
2181#endif
2182 // render triangle
2183 cmdBuffer.Draw(0, 3, 0, 1);
2184
2185 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002186 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002187 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002188
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002189 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002190}
Tony Barbour01999182015-04-09 12:58:51 -06002191TEST_F(VkRenderTest, SamplerBindingsTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002192{
2193 // This test sets bindings on the samplers
2194 // For now we are asserting that sampler and texture pairs
2195 // march in lock step, and are set via GLSL binding. This can
2196 // and will probably change.
2197 // The sampler bindings should match the sampler and texture slot
2198 // number set up by the application.
2199 // This test will result in a blue triangle
2200 static const char *vertShaderText =
2201 "#version 140\n"
2202 "#extension GL_ARB_separate_shader_objects : enable\n"
2203 "#extension GL_ARB_shading_language_420pack : enable\n"
2204 "layout (location = 0) out vec4 samplePos;\n"
2205 "void main() {\n"
2206 " vec2 vertices[3];"
2207 " vertices[0] = vec2(-0.5, -0.5);\n"
2208 " vertices[1] = vec2( 0.5, -0.5);\n"
2209 " vertices[2] = vec2( 0.5, 0.5);\n"
2210 " vec2 positions[3];"
2211 " positions[0] = vec2( 0.0, 0.0);\n"
2212 " positions[1] = vec2( 1.0, 0.0);\n"
2213 " positions[2] = vec2( 1.0, 1.0);\n"
2214 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2215 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2216 "}\n";
2217
2218 static const char *fragShaderText =
2219 "#version 140\n"
2220 "#extension GL_ARB_separate_shader_objects : enable\n"
2221 "#extension GL_ARB_shading_language_420pack : enable\n"
2222 "layout (location = 0) in vec4 samplePos;\n"
2223 "layout (binding = 0) uniform sampler2D surface0;\n"
2224 "layout (binding = 1) uniform sampler2D surface1;\n"
2225 "layout (binding = 12) uniform sampler2D surface2;\n"
2226 "void main() {\n"
2227 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
2228 "}\n";
2229
2230 ASSERT_NO_FATAL_FAILURE(InitState());
2231 ASSERT_NO_FATAL_FAILURE(InitViewport());
2232
Tony Barbour01999182015-04-09 12:58:51 -06002233 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2234 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002235
Tony Barbour01999182015-04-09 12:58:51 -06002236 VkSamplerObj sampler1(m_device);
2237 VkSamplerObj sampler2(m_device);
2238 VkSamplerObj sampler3(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002239
Tony Barbour2f421a02015-04-01 16:38:10 -06002240 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
Tony Barbour01999182015-04-09 12:58:51 -06002241 VkTextureObj texture1(m_device, tex_colors); // Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002242 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
Tony Barbour01999182015-04-09 12:58:51 -06002243 VkTextureObj texture2(m_device, tex_colors); // Green
Tony Barbour2f421a02015-04-01 16:38:10 -06002244 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
Tony Barbour01999182015-04-09 12:58:51 -06002245 VkTextureObj texture3(m_device, tex_colors); // Blue
Tony Barbourf43b6982014-11-25 13:18:32 -07002246
Tony Barbour01999182015-04-09 12:58:51 -06002247 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002248 pipelineobj.AddShader(&vs);
2249 pipelineobj.AddShader(&ps);
2250
Tony Barbour01999182015-04-09 12:58:51 -06002251 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002252 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2253 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2254 for (int i = 0; i < 10; i++)
2255 descriptorSet.AppendDummy();
2256 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002257
Tony Barbourdd4c9642015-01-09 12:55:14 -07002258 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002259 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002260 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2261
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002262 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002263
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002264 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002265
2266#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002267 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002268 pDSDumpDot((char*)"triTest2.dot");
2269#endif
2270 // render triangle
2271 cmdBuffer.Draw(0, 3, 0, 1);
2272
2273 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002274 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002275 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002276
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002277 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002278}
2279
Tony Barbour01999182015-04-09 12:58:51 -06002280TEST_F(VkRenderTest, TriangleVSUniformBlock)
Tony Barbourf43b6982014-11-25 13:18:32 -07002281{
2282 // The expected result from this test is a blue triangle
2283
2284 static const char *vertShaderText =
2285 "#version 140\n"
2286 "#extension GL_ARB_separate_shader_objects : enable\n"
2287 "#extension GL_ARB_shading_language_420pack : enable\n"
2288 "layout (location = 0) out vec4 outColor;\n"
2289 "layout (std140, binding = 0) uniform bufferVals {\n"
2290 " vec4 red;\n"
2291 " vec4 green;\n"
2292 " vec4 blue;\n"
2293 " vec4 white;\n"
2294 "} myBufferVals;\n"
2295 "void main() {\n"
2296 " vec2 vertices[3];"
2297 " vertices[0] = vec2(-0.5, -0.5);\n"
2298 " vertices[1] = vec2( 0.5, -0.5);\n"
2299 " vertices[2] = vec2( 0.5, 0.5);\n"
2300 " outColor = myBufferVals.blue;\n"
2301 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2302 "}\n";
2303
2304 static const char *fragShaderText =
2305 "#version 140\n"
2306 "#extension GL_ARB_separate_shader_objects : enable\n"
2307 "#extension GL_ARB_shading_language_420pack : enable\n"
2308 "layout (location = 0) in vec4 inColor;\n"
2309 "void main() {\n"
2310 " gl_FragColor = inColor;\n"
2311 "}\n";
2312
2313 ASSERT_NO_FATAL_FAILURE(InitState());
2314 ASSERT_NO_FATAL_FAILURE(InitViewport());
2315
Tony Barbour01999182015-04-09 12:58:51 -06002316 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2317 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002318
2319 // Let's populate our buffer with the following:
2320 // vec4 red;
2321 // vec4 green;
2322 // vec4 blue;
2323 // vec4 white;
2324 const int valCount = 4 * 4;
2325 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2326 0.0, 1.0, 0.0, 1.0,
2327 0.0, 0.0, 1.0, 1.0,
2328 1.0, 1.0, 1.0, 1.0 };
2329
Tony Barbour01999182015-04-09 12:58:51 -06002330 VkConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002331
Tony Barbour01999182015-04-09 12:58:51 -06002332 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002333 pipelineobj.AddShader(&vs);
2334 pipelineobj.AddShader(&ps);
2335
Tony Barbour01999182015-04-09 12:58:51 -06002336 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002337 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002338
Tony Barbourdd4c9642015-01-09 12:55:14 -07002339 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002340 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002341 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2342
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002343 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002344
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002345 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002346
2347#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002348 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002349 pDSDumpDot((char*)"triTest2.dot");
2350#endif
2351 // render triangle
2352 cmdBuffer.Draw(0, 3, 0, 1);
2353
2354 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002355 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002356 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002357
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002358 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002359}
2360
Tony Barbour01999182015-04-09 12:58:51 -06002361TEST_F(VkRenderTest, TriangleFSUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002362{
2363 // This test allows the shader to select which buffer it is
2364 // pulling from using layout binding qualifier.
2365 // There are corresponding changes in the compiler stack that
2366 // will select the buffer using binding directly.
2367 // The binding number should match the slot number set up by
2368 // the application.
2369 // The expected result from this test is a purple triangle
2370
2371 static const char *vertShaderText =
2372 "#version 140\n"
2373 "#extension GL_ARB_separate_shader_objects : enable\n"
2374 "#extension GL_ARB_shading_language_420pack : enable\n"
2375 "void main() {\n"
2376 " vec2 vertices[3];"
2377 " vertices[0] = vec2(-0.5, -0.5);\n"
2378 " vertices[1] = vec2( 0.5, -0.5);\n"
2379 " vertices[2] = vec2( 0.5, 0.5);\n"
2380 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2381 "}\n";
2382
2383 static const char *fragShaderText =
2384 "#version 140\n"
2385 "#extension GL_ARB_separate_shader_objects : enable\n"
2386 "#extension GL_ARB_shading_language_420pack : enable\n"
2387 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2388 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2389 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002390 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
Tony Barbourf43b6982014-11-25 13:18:32 -07002391 "void main() {\n"
2392 " gl_FragColor = myBlueVal.color;\n"
2393 " gl_FragColor += myRedVal.color;\n"
2394 "}\n";
2395
2396 ASSERT_NO_FATAL_FAILURE(InitState());
2397 ASSERT_NO_FATAL_FAILURE(InitViewport());
2398
Tony Barbour01999182015-04-09 12:58:51 -06002399 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2400 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002401
2402 // We're going to create a number of uniform buffers, and then allow
2403 // the shader to select which it wants to read from with a binding
2404
2405 // Let's populate the buffers with a single color each:
2406 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2407 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2408 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002409 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002410
2411 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2412 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2413 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2414 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2415
2416 const int redCount = sizeof(redVals) / sizeof(float);
2417 const int greenCount = sizeof(greenVals) / sizeof(float);
2418 const int blueCount = sizeof(blueVals) / sizeof(float);
2419 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2420
Tony Barbour01999182015-04-09 12:58:51 -06002421 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002422
Tony Barbour01999182015-04-09 12:58:51 -06002423 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002424
Tony Barbour01999182015-04-09 12:58:51 -06002425 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002426
Tony Barbour01999182015-04-09 12:58:51 -06002427 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002428
Tony Barbour01999182015-04-09 12:58:51 -06002429 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002430 pipelineobj.AddShader(&vs);
2431 pipelineobj.AddShader(&ps);
2432
Tony Barbour01999182015-04-09 12:58:51 -06002433 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002434 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2435 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2436 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2437 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002438
Tony Barbourdd4c9642015-01-09 12:55:14 -07002439 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002440 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002441 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002442
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002443 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002444
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002445 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002446
2447#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002448 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002449 pDSDumpDot((char*)"triTest2.dot");
2450#endif
2451 // render triangle
2452 cmdBuffer.Draw(0, 3, 0, 1);
2453
2454 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002455 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002456 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002457
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002458 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002459}
2460
Tony Barbour01999182015-04-09 12:58:51 -06002461TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002462{
2463 // This test is the same as TriangleFSUniformBlockBinding, but
2464 // it does not provide an instance name.
2465 // The expected result from this test is a purple triangle
2466
2467 static const char *vertShaderText =
2468 "#version 140\n"
2469 "#extension GL_ARB_separate_shader_objects : enable\n"
2470 "#extension GL_ARB_shading_language_420pack : enable\n"
2471 "void main() {\n"
2472 " vec2 vertices[3];"
2473 " vertices[0] = vec2(-0.5, -0.5);\n"
2474 " vertices[1] = vec2( 0.5, -0.5);\n"
2475 " vertices[2] = vec2( 0.5, 0.5);\n"
2476 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2477 "}\n";
2478
2479 static const char *fragShaderText =
2480 "#version 430\n"
2481 "#extension GL_ARB_separate_shader_objects : enable\n"
2482 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002483 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2484 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2485 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002486 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002487 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002488 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002489 " outColor = blue;\n"
2490 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002491 "}\n";
2492 ASSERT_NO_FATAL_FAILURE(InitState());
2493 ASSERT_NO_FATAL_FAILURE(InitViewport());
2494
Tony Barbour01999182015-04-09 12:58:51 -06002495 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2496 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002497
2498 // We're going to create a number of uniform buffers, and then allow
2499 // the shader to select which it wants to read from with a binding
2500
2501 // Let's populate the buffers with a single color each:
2502 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2503 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2504 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2505 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2506
2507 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2508 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2509 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2510 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2511
2512 const int redCount = sizeof(redVals) / sizeof(float);
2513 const int greenCount = sizeof(greenVals) / sizeof(float);
2514 const int blueCount = sizeof(blueVals) / sizeof(float);
2515 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2516
Tony Barbour01999182015-04-09 12:58:51 -06002517 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002518
Tony Barbour01999182015-04-09 12:58:51 -06002519 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002520
Tony Barbour01999182015-04-09 12:58:51 -06002521 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002522
Tony Barbour01999182015-04-09 12:58:51 -06002523 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002524
Tony Barbour01999182015-04-09 12:58:51 -06002525 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002526 pipelineobj.AddShader(&vs);
2527 pipelineobj.AddShader(&ps);
2528
Tony Barbour01999182015-04-09 12:58:51 -06002529 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002530 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2531 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2532 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2533 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002534
Tony Barbourdd4c9642015-01-09 12:55:14 -07002535 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002536 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002537 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2538
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002539 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002540
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002541 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002542
2543#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002544 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002545 pDSDumpDot((char*)"triTest2.dot");
2546#endif
2547 // render triangle
2548 cmdBuffer.Draw(0, 3, 0, 1);
2549
2550 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002551 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002552 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002553
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002554 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002555}
2556
Tony Barbour01999182015-04-09 12:58:51 -06002557TEST_F(VkRenderTest, CubeWithVertexFetchAndMVPAndTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07002558{
2559 static const char *vertShaderText =
2560 "#version 140\n"
2561 "#extension GL_ARB_separate_shader_objects : enable\n"
2562 "#extension GL_ARB_shading_language_420pack : enable\n"
2563 "layout (std140, binding=0) uniform bufferVals {\n"
2564 " mat4 mvp;\n"
2565 "} myBufferVals;\n"
2566 "layout (location=0) in vec4 pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002567 "layout (location=1) in vec2 input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002568 "layout (location=0) out vec2 UV;\n"
2569 "void main() {\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002570 " UV = input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002571 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002572 " gl_Position.y = -gl_Position.y;\n"
2573 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002574 "}\n";
2575
2576 static const char *fragShaderText =
2577 "#version 140\n"
2578 "#extension GL_ARB_separate_shader_objects : enable\n"
2579 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002580 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002581 "layout (location=0) out vec4 outColor;\n"
2582 "layout (location=0) in vec2 UV;\n"
2583 "void main() {\n"
2584 " outColor= textureLod(surface, UV, 0.0);\n"
2585 "}\n";
2586 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2587
2588 glm::mat4 View = glm::lookAt(
2589 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2590 glm::vec3(0,0,0), // and looks at the origin
2591 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2592 );
2593
2594 glm::mat4 Model = glm::mat4(1.0f);
2595
2596 glm::mat4 MVP = Projection * View * Model;
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002597 int num_verts = sizeof(g_vb_texture_Data) / sizeof(g_vb_texture_Data[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002598
2599
2600 ASSERT_NO_FATAL_FAILURE(InitState());
2601 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour8bef8ee2015-05-22 09:44:58 -06002602 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07002603
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002604 VkConstantBufferObj meshBuffer(m_device, num_verts,
2605 sizeof(g_vb_texture_Data[0]), g_vb_texture_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002606 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002607
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002608 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07002609
Tony Barbour01999182015-04-09 12:58:51 -06002610 VkConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2611 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2612 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2613 VkSamplerObj sampler(m_device);
2614 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002615
Tony Barbour01999182015-04-09 12:58:51 -06002616 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002617 pipelineobj.AddShader(&vs);
2618 pipelineobj.AddShader(&ps);
2619
Tony Barbour01999182015-04-09 12:58:51 -06002620 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002621 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mvpBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002622 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002623
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002624#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002625 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002626 MESH_BIND_ID, // binding ID
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002627 sizeof(g_vb_texture_Data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002628 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002629 };
Tony Barbourf43b6982014-11-25 13:18:32 -07002630
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002631 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002632 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2633 vi_attribs[0].location = 0; // location
Tony Barbour8205d902015-04-16 15:59:00 -06002634 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002635 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2636 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2637 vi_attribs[1].location = 1; // location
2638 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
2639 vi_attribs[1].offsetInBytes = 16; // Offset of uv components
Tony Barbourf43b6982014-11-25 13:18:32 -07002640
Tony Barbourf43b6982014-11-25 13:18:32 -07002641 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002642 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2643 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07002644
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002645 VkPipelineDsStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002646 ds_state.depthTestEnable = VK_TRUE;
2647 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06002648 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002649 ds_state.depthBoundsEnable = VK_FALSE;
2650 ds_state.stencilTestEnable = VK_FALSE;
2651 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
2652 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
2653 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06002654 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
2655 ds_state.format = VK_FORMAT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002656 ds_state.front = ds_state.back;
2657 pipelineobj.SetDepthStencil(&ds_state);
2658
Tony Barbour17c6ab12015-03-27 17:03:18 -06002659 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour01999182015-04-09 12:58:51 -06002660 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002661 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002662
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002663 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002664
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002665 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002666
2667 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2668#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002669 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002670 pDSDumpDot((char*)"triTest2.dot");
2671#endif
2672 // render triangle
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002673 cmdBuffer.Draw(0, num_verts, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002674
2675 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002676 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002677 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002678
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002679 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002680 RotateTriangleVSUniform(Projection, View, Model, &mvpBuffer, &cmdBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002681}
Cody Northropd1ce7842014-12-09 11:17:01 -07002682
Tony Barbour01999182015-04-09 12:58:51 -06002683TEST_F(VkRenderTest, TriangleMixedSamplerUniformBlockBinding)
Cody Northropd1ce7842014-12-09 11:17:01 -07002684{
2685 // This test mixes binding slots of textures and buffers, ensuring
2686 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002687 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002688 // you can modify it to move the desired result around.
2689
2690 static const char *vertShaderText =
2691 "#version 140\n"
2692 "#extension GL_ARB_separate_shader_objects : enable\n"
2693 "#extension GL_ARB_shading_language_420pack : enable\n"
2694 "void main() {\n"
2695 " vec2 vertices[3];"
2696 " vertices[0] = vec2(-0.5, -0.5);\n"
2697 " vertices[1] = vec2( 0.5, -0.5);\n"
2698 " vertices[2] = vec2( 0.5, 0.5);\n"
2699 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2700 "}\n";
2701
2702 static const char *fragShaderText =
2703 "#version 430\n"
2704 "#extension GL_ARB_separate_shader_objects : enable\n"
2705 "#extension GL_ARB_shading_language_420pack : enable\n"
2706 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002707 "layout (binding = 3) uniform sampler2D surface1;\n"
2708 "layout (binding = 1) uniform sampler2D surface2;\n"
2709 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002710
Cody Northropa0410942014-12-09 13:59:39 -07002711
Chia-I Wuf8385062015-01-04 16:27:24 +08002712 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2713 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2714 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2715 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002716 "layout (location = 0) out vec4 outColor;\n"
2717 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002718 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002719 " outColor += white * vec4(0.00001);\n"
2720 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002721 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002722 "}\n";
2723 ASSERT_NO_FATAL_FAILURE(InitState());
2724 ASSERT_NO_FATAL_FAILURE(InitViewport());
2725
Tony Barbour01999182015-04-09 12:58:51 -06002726 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2727 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northropd1ce7842014-12-09 11:17:01 -07002728
Cody Northropd1ce7842014-12-09 11:17:01 -07002729 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2730 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2731 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2732 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2733
2734 const int redCount = sizeof(redVals) / sizeof(float);
2735 const int greenCount = sizeof(greenVals) / sizeof(float);
2736 const int blueCount = sizeof(blueVals) / sizeof(float);
2737 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2738
Tony Barbour01999182015-04-09 12:58:51 -06002739 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2740 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2741 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2742 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002743
Tony Barbour2f421a02015-04-01 16:38:10 -06002744 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002745 VkSamplerObj sampler0(m_device);
2746 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002747 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002748 VkSamplerObj sampler2(m_device);
2749 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002750 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002751 VkSamplerObj sampler4(m_device);
2752 VkTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropa0410942014-12-09 13:59:39 -07002753
2754 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2755 // TODO: Get back here ASAP and understand why.
Tony Barbour2f421a02015-04-01 16:38:10 -06002756 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06002757 VkSamplerObj sampler7(m_device);
2758 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropd1ce7842014-12-09 11:17:01 -07002759
Tony Barbour01999182015-04-09 12:58:51 -06002760 VkPipelineObj pipelineobj(m_device);
Cody Northropd1ce7842014-12-09 11:17:01 -07002761 pipelineobj.AddShader(&vs);
2762 pipelineobj.AddShader(&ps);
2763
Tony Barbour01999182015-04-09 12:58:51 -06002764 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002765 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2766 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2767 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2768 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002769 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002770 // swap blue and green
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002771 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2772 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2773 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002774
Tony Barbourdd4c9642015-01-09 12:55:14 -07002775 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002776 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002777 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002778
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002779 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002780
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002781 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002782
2783#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002784 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002785 pDSDumpDot((char*)"triTest2.dot");
2786#endif
2787 // render triangle
2788 cmdBuffer.Draw(0, 3, 0, 1);
2789
2790 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002791 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002792 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002793
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002794 RecordImages(m_renderTargets);
Cody Northropd1ce7842014-12-09 11:17:01 -07002795}
2796
Tony Barbour01999182015-04-09 12:58:51 -06002797TEST_F(VkRenderTest, TriangleMatchingSamplerUniformBlockBinding)
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002798{
2799 // This test matches binding slots of textures and buffers, requiring
2800 // the driver to give them distinct number spaces.
2801 // The expected result from this test is a red triangle, although
2802 // you can modify it to move the desired result around.
2803
2804 static const char *vertShaderText =
2805 "#version 140\n"
2806 "#extension GL_ARB_separate_shader_objects : enable\n"
2807 "#extension GL_ARB_shading_language_420pack : enable\n"
2808 "void main() {\n"
2809 " vec2 vertices[3];"
2810 " vertices[0] = vec2(-0.5, -0.5);\n"
2811 " vertices[1] = vec2( 0.5, -0.5);\n"
2812 " vertices[2] = vec2( 0.5, 0.5);\n"
2813 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2814 "}\n";
2815
2816 static const char *fragShaderText =
2817 "#version 430\n"
2818 "#extension GL_ARB_separate_shader_objects : enable\n"
2819 "#extension GL_ARB_shading_language_420pack : enable\n"
2820 "layout (binding = 0) uniform sampler2D surface0;\n"
2821 "layout (binding = 1) uniform sampler2D surface1;\n"
2822 "layout (binding = 2) uniform sampler2D surface2;\n"
2823 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002824 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2825 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2826 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2827 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002828 "layout (location = 0) out vec4 outColor;\n"
2829 "void main() {\n"
2830 " outColor = red;// * vec4(0.00001);\n"
2831 " outColor += white * vec4(0.00001);\n"
2832 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2833 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2834 "}\n";
2835 ASSERT_NO_FATAL_FAILURE(InitState());
2836 ASSERT_NO_FATAL_FAILURE(InitViewport());
2837
Tony Barbour01999182015-04-09 12:58:51 -06002838 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2839 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002840
2841 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2842 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2843 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2844 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2845
2846 const int redCount = sizeof(redVals) / sizeof(float);
2847 const int greenCount = sizeof(greenVals) / sizeof(float);
2848 const int blueCount = sizeof(blueVals) / sizeof(float);
2849 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2850
Tony Barbour01999182015-04-09 12:58:51 -06002851 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2852 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2853 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2854 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002855
Tony Barbour2f421a02015-04-01 16:38:10 -06002856 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002857 VkSamplerObj sampler0(m_device);
2858 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002859 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002860 VkSamplerObj sampler2(m_device);
2861 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002862 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002863 VkSamplerObj sampler4(m_device);
2864 VkTextureObj texture4(m_device, tex_colors); // Light Green
Tony Barbour2f421a02015-04-01 16:38:10 -06002865 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06002866 VkSamplerObj sampler7(m_device);
2867 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002868
Tony Barbour01999182015-04-09 12:58:51 -06002869 VkPipelineObj pipelineobj(m_device);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002870 pipelineobj.AddShader(&vs);
2871 pipelineobj.AddShader(&ps);
2872
Tony Barbour01999182015-04-09 12:58:51 -06002873 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002874 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2875 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2876 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2877 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002878 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2879 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2880 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2881 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002882
Tony Barbourdd4c9642015-01-09 12:55:14 -07002883 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002884 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002885 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002886
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002887 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002888
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002889 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002890
2891#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002892 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002893 pDSDumpDot((char*)"triTest2.dot");
2894#endif
2895 // render triangle
2896 cmdBuffer.Draw(0, 3, 0, 1);
2897
2898 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002899 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002900 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002901
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002902 RecordImages(m_renderTargets);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002903}
2904
Tony Barbour01999182015-04-09 12:58:51 -06002905TEST_F(VkRenderTest, TriangleUniformBufferLayout)
Cody Northrop02690bd2014-12-17 15:26:33 -07002906{
2907 // This test populates a buffer with a variety of different data
2908 // types, then reads them out with a shader.
2909 // The expected result from this test is a green triangle
2910
2911 static const char *vertShaderText =
2912 "#version 140\n"
2913 "#extension GL_ARB_separate_shader_objects : enable\n"
2914 "#extension GL_ARB_shading_language_420pack : enable\n"
2915 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2916 " vec4 fRed;\n"
2917 " vec4 fGreen;\n"
2918 " layout(row_major) mat4 worldToProj;\n"
2919 " layout(row_major) mat4 projToWorld;\n"
2920 " layout(row_major) mat4 worldToView;\n"
2921 " layout(row_major) mat4 viewToProj;\n"
2922 " layout(row_major) mat4 worldToShadow[4];\n"
2923 " float fZero;\n"
2924 " float fOne;\n"
2925 " float fTwo;\n"
2926 " float fThree;\n"
2927 " vec3 fZeroZeroZero;\n"
2928 " float fFour;\n"
2929 " vec3 fZeroZeroOne;\n"
2930 " float fFive;\n"
2931 " vec3 fZeroOneZero;\n"
2932 " float fSix;\n"
2933 " float fSeven;\n"
2934 " float fEight;\n"
2935 " float fNine;\n"
2936 " vec2 fZeroZero;\n"
2937 " vec2 fZeroOne;\n"
2938 " vec4 fBlue;\n"
2939 " vec2 fOneZero;\n"
2940 " vec2 fOneOne;\n"
2941 " vec3 fZeroOneOne;\n"
2942 " float fTen;\n"
2943 " float fEleven;\n"
2944 " float fTwelve;\n"
2945 " vec3 fOneZeroZero;\n"
2946 " vec4 uvOffsets[4];\n"
2947 "};\n"
2948 "layout (location = 0) out vec4 color;"
2949 "void main() {\n"
2950
2951 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2952 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2953 " \n"
2954
2955 // do some exact comparisons, even though we should
2956 // really have an epsilon involved.
2957 " vec4 outColor = right;\n"
2958 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
2959 " outColor = wrong;\n"
2960 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
2961 " outColor = wrong;\n"
2962 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
2963 " outColor = wrong;\n"
2964
2965 " color = outColor;\n"
2966
2967 // generic position stuff
2968 " vec2 vertices;\n"
2969 " int vertexSelector = gl_VertexID;\n"
2970 " if (vertexSelector == 0)\n"
2971 " vertices = vec2(-0.5, -0.5);\n"
2972 " else if (vertexSelector == 1)\n"
2973 " vertices = vec2( 0.5, -0.5);\n"
2974 " else if (vertexSelector == 2)\n"
2975 " vertices = vec2( 0.5, 0.5);\n"
2976 " else\n"
2977 " vertices = vec2( 0.0, 0.0);\n"
2978 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
2979 "}\n";
2980
2981 static const char *fragShaderText =
2982 "#version 140\n"
2983 "#extension GL_ARB_separate_shader_objects : enable\n"
2984 "#extension GL_ARB_shading_language_420pack : enable\n"
2985 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2986 " vec4 fRed;\n"
2987 " vec4 fGreen;\n"
2988 " layout(row_major) mat4 worldToProj;\n"
2989 " layout(row_major) mat4 projToWorld;\n"
2990 " layout(row_major) mat4 worldToView;\n"
2991 " layout(row_major) mat4 viewToProj;\n"
2992 " layout(row_major) mat4 worldToShadow[4];\n"
2993 " float fZero;\n"
2994 " float fOne;\n"
2995 " float fTwo;\n"
2996 " float fThree;\n"
2997 " vec3 fZeroZeroZero;\n"
2998 " float fFour;\n"
2999 " vec3 fZeroZeroOne;\n"
3000 " float fFive;\n"
3001 " vec3 fZeroOneZero;\n"
3002 " float fSix;\n"
3003 " float fSeven;\n"
3004 " float fEight;\n"
3005 " float fNine;\n"
3006 " vec2 fZeroZero;\n"
3007 " vec2 fZeroOne;\n"
3008 " vec4 fBlue;\n"
3009 " vec2 fOneZero;\n"
3010 " vec2 fOneOne;\n"
3011 " vec3 fZeroOneOne;\n"
3012 " float fTen;\n"
3013 " float fEleven;\n"
3014 " float fTwelve;\n"
3015 " vec3 fOneZeroZero;\n"
3016 " vec4 uvOffsets[4];\n"
3017 "};\n"
3018 "layout (location = 0) in vec4 color;\n"
3019 "void main() {\n"
3020 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3021 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3022 " \n"
3023
3024 // start with VS value to ensure it passed
3025 " vec4 outColor = color;\n"
3026
3027 // do some exact comparisons, even though we should
3028 // really have an epsilon involved.
3029 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3030 " outColor = wrong;\n"
3031 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3032 " outColor = wrong;\n"
3033 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3034 " outColor = wrong;\n"
3035 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3036 " outColor = wrong;\n"
3037 " if (fTwo != 2.0)\n"
3038 " outColor = wrong;\n"
3039 " if (fOneOne != vec2(1.0, 1.0))\n"
3040 " outColor = wrong;\n"
3041 " if (fTen != 10.0)\n"
3042 " outColor = wrong;\n"
3043 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3044 " outColor = wrong;\n"
3045 " \n"
3046 " gl_FragColor = outColor;\n"
3047 "}\n";
3048
3049
3050 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3051 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3052 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3053 0.0, 1.0, 0.0, 1.0, // align
3054 0.0, 0.0, 1.0, 1.0, // align
3055 0.0, 0.0, 0.0, 1.0, // align
3056 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3057 0.0, 2.0, 0.0, 2.0, // align
3058 0.0, 0.0, 2.0, 2.0, // align
3059 0.0, 0.0, 0.0, 2.0, // align
3060 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3061 0.0, 3.0, 0.0, 3.0, // align
3062 0.0, 0.0, 3.0, 3.0, // align
3063 0.0, 0.0, 0.0, 3.0, // align
3064 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3065 0.0, 4.0, 0.0, 4.0, // align
3066 0.0, 0.0, 4.0, 4.0, // align
3067 0.0, 0.0, 0.0, 4.0, // align
3068 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3069 0.0, 5.0, 0.0, 5.0, // align
3070 0.0, 0.0, 5.0, 5.0, // align
3071 0.0, 0.0, 0.0, 5.0, // align
3072 6.0, 0.0, 0.0, 6.0, // align
3073 0.0, 6.0, 0.0, 6.0, // align
3074 0.0, 0.0, 6.0, 6.0, // align
3075 0.0, 0.0, 0.0, 6.0, // align
3076 7.0, 0.0, 0.0, 7.0, // align
3077 0.0, 7.0, 0.0, 7.0, // align
3078 0.0, 0.0, 7.0, 7.0, // align
3079 0.0, 0.0, 0.0, 7.0, // align
3080 8.0, 0.0, 0.0, 8.0, // align
3081 0.0, 8.0, 0.0, 8.0, // align
3082 0.0, 0.0, 8.0, 8.0, // align
3083 0.0, 0.0, 0.0, 8.0, // align
3084 0.0, // float fZero; // align
3085 1.0, // float fOne; // pack
3086 2.0, // float fTwo; // pack
3087 3.0, // float fThree; // pack
3088 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3089 4.0, // float fFour; // pack
3090 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3091 5.0, // float fFive; // pack
3092 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3093 6.0, // float fSix; // pack
3094 7.0, // float fSeven; // align
3095 8.0, // float fEight; // pack
3096 9.0, // float fNine; // pack
3097 0.0, // BUFFER
3098 0.0, 0.0, // vec2 fZeroZero; // align
3099 0.0, 1.0, // vec2 fZeroOne; // pack
3100 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3101 1.0, 0.0, // vec2 fOneZero; // align
3102 1.0, 1.0, // vec2 fOneOne; // pack
3103 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3104 10.0, // float fTen; // pack
3105 11.0, // float fEleven; // align
3106 12.0, // float fTwelve; // pack
3107 0.0, 0.0, // BUFFER
3108 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3109 0.0, // BUFFER
3110 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3111 0.5, 0.6, 0.7, 0.8, // align
3112 0.9, 1.0, 1.1, 1.2, // align
3113 1.3, 1.4, 1.5, 1.6, // align
3114 };
3115
3116 ASSERT_NO_FATAL_FAILURE(InitState());
3117 ASSERT_NO_FATAL_FAILURE(InitViewport());
3118
3119 const int constCount = sizeof(mixedVals) / sizeof(float);
3120
Tony Barbour01999182015-04-09 12:58:51 -06003121 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3122 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop02690bd2014-12-17 15:26:33 -07003123
Tony Barbour01999182015-04-09 12:58:51 -06003124 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003125
Tony Barbour01999182015-04-09 12:58:51 -06003126 VkPipelineObj pipelineobj(m_device);
Cody Northrop02690bd2014-12-17 15:26:33 -07003127 pipelineobj.AddShader(&vs);
3128 pipelineobj.AddShader(&ps);
3129
Tony Barbour01999182015-04-09 12:58:51 -06003130 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003131 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003132
3133 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06003134 VkCommandBufferObj cmdBuffer(m_device);
Cody Northrop02690bd2014-12-17 15:26:33 -07003135 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3136
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003137 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Cody Northrop02690bd2014-12-17 15:26:33 -07003138
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003139 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Cody Northrop02690bd2014-12-17 15:26:33 -07003140
3141#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003142 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop02690bd2014-12-17 15:26:33 -07003143 pDSDumpDot((char*)"triTest2.dot");
3144#endif
3145 // render triangle
3146 cmdBuffer.Draw(0, 3, 0, 1);
3147
3148 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003149 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003150 cmdBuffer.QueueCommandBuffer();
Cody Northrop02690bd2014-12-17 15:26:33 -07003151
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003152 RecordImages(m_renderTargets);
Cody Northrop02690bd2014-12-17 15:26:33 -07003153}
3154
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003155TEST_F(VkRenderTest, TextureGather)
3156{
3157 // This test introduces textureGather and textureGatherOffset
3158 // Each call is compared against an expected inline color result
3159 // Green triangle means everything worked as expected
3160 // Red means something went wrong
3161
3162 // disable SPV until texture gather is turned on in LunarGLASS
Cody Northrop1cfbd172015-06-03 16:49:20 -06003163 ScopedUseGlsl useGlsl(true);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003164
3165 static const char *vertShaderText =
3166 "#version 140\n"
3167 "#extension GL_ARB_separate_shader_objects : enable\n"
3168 "#extension GL_ARB_shading_language_420pack : enable\n"
3169 "void main() {\n"
3170 " vec2 vertices[3];"
3171 " vertices[0] = vec2(-0.5, -0.5);\n"
3172 " vertices[1] = vec2( 0.5, -0.5);\n"
3173 " vertices[2] = vec2( 0.5, 0.5);\n"
3174 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
3175 "}\n";
3176
3177 static const char *fragShaderText =
3178 "#version 430\n"
3179 "#extension GL_ARB_separate_shader_objects : enable\n"
3180 "#extension GL_ARB_shading_language_420pack : enable\n"
3181 "layout (binding = 0) uniform sampler2D surface0;\n"
3182 "layout (binding = 1) uniform sampler2D surface1;\n"
3183 "layout (binding = 2) uniform sampler2D surface2;\n"
3184 "layout (binding = 3) uniform sampler2D surface3;\n"
3185 "layout (location = 0) out vec4 outColor;\n"
3186 "void main() {\n"
3187
3188 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3189 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3190
3191 " vec4 color = right;\n"
3192
3193 // Grab a normal texture sample to ensure it can work in conjuntion
3194 // with textureGather (there are some intracacies in the backend)
3195 " vec4 sampledColor = textureLod(surface2, vec2(0.5), 0.0);\n"
3196 " if (sampledColor != vec4(0.0, 0.0, 1.0, 1.0))\n"
3197 " color = wrong;\n"
3198
3199 " vec4 gatheredColor = textureGather(surface0, vec2(0.5), 0);\n"
3200 // This just grabbed four red components from a red surface
3201 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3202 " color = wrong;\n"
3203
3204 // Yes, this is using an offset of 0, we don't have enough fine grained
3205 // control of the texture contents here.
3206 " gatheredColor = textureGatherOffset(surface1, vec2(0.5), ivec2(0, 0), 1);\n"
3207 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3208 " color = wrong;\n"
3209
3210 " outColor = color;\n"
3211
3212 "}\n";
3213
3214 ASSERT_NO_FATAL_FAILURE(InitState());
3215 ASSERT_NO_FATAL_FAILURE(InitViewport());
3216
3217 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3218 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3219
3220 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
3221 VkSamplerObj sampler0(m_device);
3222 VkTextureObj texture0(m_device, tex_colors); // Red
3223 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
3224 VkSamplerObj sampler1(m_device);
3225 VkTextureObj texture1(m_device, tex_colors); // Green
3226 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
3227 VkSamplerObj sampler2(m_device);
3228 VkTextureObj texture2(m_device, tex_colors); // Blue
3229 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
3230 VkSamplerObj sampler3(m_device);
3231 VkTextureObj texture3(m_device, tex_colors); // Red and Blue
3232
3233 VkPipelineObj pipelineobj(m_device);
3234 pipelineobj.AddShader(&vs);
3235 pipelineobj.AddShader(&ps);
3236
3237 VkDescriptorSetObj descriptorSet(m_device);
3238 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3239 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
3240 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3241 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
3242
3243 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3244 VkCommandBufferObj cmdBuffer(m_device);
3245 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3246
3247 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3248
3249 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3250
3251 // render triangle
3252 cmdBuffer.Draw(0, 3, 0, 1);
3253
3254 // finalize recording of the command buffer
3255 EndCommandBuffer(cmdBuffer);
3256 cmdBuffer.QueueCommandBuffer();
3257
3258 RecordImages(m_renderTargets);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003259}
3260
Cody Northropa44c2ff2015-04-15 11:19:06 -06003261TEST_F(VkRenderTest, GeometryShaderHelloWorld)
3262{
3263 // This test introduces a geometry shader that simply
3264 // changes the color of each vertex to red, green, blue
3265
3266 static const char *vertShaderText =
3267 "#version 140\n"
3268 "#extension GL_ARB_separate_shader_objects : enable\n"
3269 "#extension GL_ARB_shading_language_420pack : enable\n"
3270 "layout (location = 0) out vec4 color;"
3271 "void main() {\n"
3272
3273 // VS writes out red
3274 " color = vec4(1.0, 0.0, 0.0, 1.0);\n"
3275
3276 // generic position stuff
3277 " vec2 vertices;\n"
3278 " int vertexSelector = gl_VertexID;\n"
3279 " if (vertexSelector == 0)\n"
3280 " vertices = vec2(-0.5, -0.5);\n"
3281 " else if (vertexSelector == 1)\n"
3282 " vertices = vec2( 0.5, -0.5);\n"
3283 " else if (vertexSelector == 2)\n"
3284 " vertices = vec2( 0.5, 0.5);\n"
3285 " else\n"
3286 " vertices = vec2( 0.0, 0.0);\n"
3287 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3288
3289 "}\n";
3290
3291 static const char *geomShaderText =
3292 "#version 330\n"
3293 "#extension GL_ARB_separate_shader_objects : enable\n"
3294 "#extension GL_ARB_shading_language_420pack : enable\n"
3295 "layout( triangles ) in;\n"
3296 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3297 "layout( location = 0 ) in vec4 inColor[3];\n"
3298 "layout( location = 0 ) out vec4 outColor;\n"
3299 "void main()\n"
3300 "{\n"
3301
3302 // first vertex, pass through red
3303 " gl_Position = gl_in[0].gl_Position;\n"
3304 " outColor = inColor[0];\n"
3305 " EmitVertex();\n"
3306
3307 // second vertex, green
3308 " gl_Position = gl_in[1].gl_Position;\n"
3309 " outColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3310 " EmitVertex();\n"
3311
3312 // third vertex, blue
3313 " gl_Position = gl_in[2].gl_Position;\n"
3314 " outColor = vec4(0.0, 0.0, 1.0, 1.0);\n"
3315 " EmitVertex();\n"
3316
3317 // done
3318 " EndPrimitive();\n"
3319 "}\n";
3320
3321
3322 static const char *fragShaderText =
3323 "#version 140\n"
3324 "#extension GL_ARB_separate_shader_objects : enable\n"
3325 "#extension GL_ARB_shading_language_420pack : enable\n"
3326 "layout (location = 0) in vec4 color;\n"
3327 "void main() {\n"
3328 // pass through
3329 " gl_FragColor = color;\n"
3330 "}\n";
3331
3332
3333
3334 ASSERT_NO_FATAL_FAILURE(InitState());
3335 ASSERT_NO_FATAL_FAILURE(InitViewport());
3336
3337 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3338 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3339 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3340
3341 VkPipelineObj pipelineobj(m_device);
3342 pipelineobj.AddShader(&vs);
3343 pipelineobj.AddShader(&gs);
3344 pipelineobj.AddShader(&ps);
3345
3346 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3347 VkCommandBufferObj cmdBuffer(m_device);
3348 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3349
3350 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3351
3352 VkDescriptorSetObj descriptorSet(m_device);
3353
3354 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3355
3356 // render triangle
3357 cmdBuffer.Draw(0, 3, 0, 1);
3358
3359 // finalize recording of the command buffer
3360 EndCommandBuffer(cmdBuffer);
3361 cmdBuffer.QueueCommandBuffer();
3362
3363 RecordImages(m_renderTargets);
3364}
3365
3366TEST_F(VkRenderTest, GSUniformBufferLayout)
3367{
3368 // This test is just like TriangleUniformBufferLayout but adds
3369 // geometry as a stage that also does UBO lookups
3370 // The expected result from this test is a green triangle
3371
3372 static const char *vertShaderText =
3373 "#version 140\n"
3374 "#extension GL_ARB_separate_shader_objects : enable\n"
3375 "#extension GL_ARB_shading_language_420pack : enable\n"
3376 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3377 " vec4 fRed;\n"
3378 " vec4 fGreen;\n"
3379 " layout(row_major) mat4 worldToProj;\n"
3380 " layout(row_major) mat4 projToWorld;\n"
3381 " layout(row_major) mat4 worldToView;\n"
3382 " layout(row_major) mat4 viewToProj;\n"
3383 " layout(row_major) mat4 worldToShadow[4];\n"
3384 " float fZero;\n"
3385 " float fOne;\n"
3386 " float fTwo;\n"
3387 " float fThree;\n"
3388 " vec3 fZeroZeroZero;\n"
3389 " float fFour;\n"
3390 " vec3 fZeroZeroOne;\n"
3391 " float fFive;\n"
3392 " vec3 fZeroOneZero;\n"
3393 " float fSix;\n"
3394 " float fSeven;\n"
3395 " float fEight;\n"
3396 " float fNine;\n"
3397 " vec2 fZeroZero;\n"
3398 " vec2 fZeroOne;\n"
3399 " vec4 fBlue;\n"
3400 " vec2 fOneZero;\n"
3401 " vec2 fOneOne;\n"
3402 " vec3 fZeroOneOne;\n"
3403 " float fTen;\n"
3404 " float fEleven;\n"
3405 " float fTwelve;\n"
3406 " vec3 fOneZeroZero;\n"
3407 " vec4 uvOffsets[4];\n"
3408 "};\n"
3409 "layout (location = 0) out vec4 color;"
3410 "void main() {\n"
3411
3412 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3413 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3414 " \n"
3415
3416 // do some exact comparisons, even though we should
3417 // really have an epsilon involved.
3418 " vec4 outColor = right;\n"
3419 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3420 " outColor = wrong;\n"
3421 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3422 " outColor = wrong;\n"
3423 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3424 " outColor = wrong;\n"
3425
3426 " color = outColor;\n"
3427
3428 // generic position stuff
3429 " vec2 vertices;\n"
3430 " int vertexSelector = gl_VertexID;\n"
3431 " if (vertexSelector == 0)\n"
3432 " vertices = vec2(-0.5, -0.5);\n"
3433 " else if (vertexSelector == 1)\n"
3434 " vertices = vec2( 0.5, -0.5);\n"
3435 " else if (vertexSelector == 2)\n"
3436 " vertices = vec2( 0.5, 0.5);\n"
3437 " else\n"
3438 " vertices = vec2( 0.0, 0.0);\n"
3439 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3440 "}\n";
3441
3442 static const char *geomShaderText =
3443 "#version 330\n"
3444 "#extension GL_ARB_separate_shader_objects : enable\n"
3445 "#extension GL_ARB_shading_language_420pack : enable\n"
3446
3447 // GS layout stuff
3448 "layout( triangles ) in;\n"
3449 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3450
3451 // Between stage IO
3452 "layout( location = 0 ) in vec4 inColor[3];\n"
3453 "layout( location = 0 ) out vec4 color;\n"
3454
3455 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3456 " vec4 fRed;\n"
3457 " vec4 fGreen;\n"
3458 " layout(row_major) mat4 worldToProj;\n"
3459 " layout(row_major) mat4 projToWorld;\n"
3460 " layout(row_major) mat4 worldToView;\n"
3461 " layout(row_major) mat4 viewToProj;\n"
3462 " layout(row_major) mat4 worldToShadow[4];\n"
3463 " float fZero;\n"
3464 " float fOne;\n"
3465 " float fTwo;\n"
3466 " float fThree;\n"
3467 " vec3 fZeroZeroZero;\n"
3468 " float fFour;\n"
3469 " vec3 fZeroZeroOne;\n"
3470 " float fFive;\n"
3471 " vec3 fZeroOneZero;\n"
3472 " float fSix;\n"
3473 " float fSeven;\n"
3474 " float fEight;\n"
3475 " float fNine;\n"
3476 " vec2 fZeroZero;\n"
3477 " vec2 fZeroOne;\n"
3478 " vec4 fBlue;\n"
3479 " vec2 fOneZero;\n"
3480 " vec2 fOneOne;\n"
3481 " vec3 fZeroOneOne;\n"
3482 " float fTen;\n"
3483 " float fEleven;\n"
3484 " float fTwelve;\n"
3485 " vec3 fOneZeroZero;\n"
3486 " vec4 uvOffsets[4];\n"
3487 "};\n"
3488
3489 "void main()\n"
3490 "{\n"
3491
3492 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3493 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3494
3495 // Each vertex will validate it can read VS output
3496 // then check a few values from the UBO
3497
3498 // first vertex
3499 " vec4 outColor = inColor[0];\n"
3500
3501 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3502 " outColor = wrong;\n"
3503 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3504 " outColor = wrong;\n"
3505 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3506 " outColor = wrong;\n"
3507 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3508 " outColor = wrong;\n"
3509
3510 " gl_Position = gl_in[0].gl_Position;\n"
3511 " color = outColor;\n"
3512 " EmitVertex();\n"
3513
3514 // second vertex
3515 " outColor = inColor[1];\n"
3516
3517 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3518 " outColor = wrong;\n"
3519 " if (fSix != 6.0)\n"
3520 " outColor = wrong;\n"
3521 " if (fOneOne != vec2(1.0, 1.0))\n"
3522 " outColor = wrong;\n"
3523
3524 " gl_Position = gl_in[1].gl_Position;\n"
3525 " color = outColor;\n"
3526 " EmitVertex();\n"
3527
3528 // third vertex
3529 " outColor = inColor[2];\n"
3530
3531 " if (fSeven != 7.0)\n"
3532 " outColor = wrong;\n"
3533 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3534 " outColor = wrong;\n"
3535
3536 " gl_Position = gl_in[2].gl_Position;\n"
3537 " color = outColor;\n"
3538 " EmitVertex();\n"
3539
3540 // done
3541 " EndPrimitive();\n"
3542 "}\n";
3543
3544 static const char *fragShaderText =
3545 "#version 140\n"
3546 "#extension GL_ARB_separate_shader_objects : enable\n"
3547 "#extension GL_ARB_shading_language_420pack : enable\n"
3548 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3549 " vec4 fRed;\n"
3550 " vec4 fGreen;\n"
3551 " layout(row_major) mat4 worldToProj;\n"
3552 " layout(row_major) mat4 projToWorld;\n"
3553 " layout(row_major) mat4 worldToView;\n"
3554 " layout(row_major) mat4 viewToProj;\n"
3555 " layout(row_major) mat4 worldToShadow[4];\n"
3556 " float fZero;\n"
3557 " float fOne;\n"
3558 " float fTwo;\n"
3559 " float fThree;\n"
3560 " vec3 fZeroZeroZero;\n"
3561 " float fFour;\n"
3562 " vec3 fZeroZeroOne;\n"
3563 " float fFive;\n"
3564 " vec3 fZeroOneZero;\n"
3565 " float fSix;\n"
3566 " float fSeven;\n"
3567 " float fEight;\n"
3568 " float fNine;\n"
3569 " vec2 fZeroZero;\n"
3570 " vec2 fZeroOne;\n"
3571 " vec4 fBlue;\n"
3572 " vec2 fOneZero;\n"
3573 " vec2 fOneOne;\n"
3574 " vec3 fZeroOneOne;\n"
3575 " float fTen;\n"
3576 " float fEleven;\n"
3577 " float fTwelve;\n"
3578 " vec3 fOneZeroZero;\n"
3579 " vec4 uvOffsets[4];\n"
3580 "};\n"
3581 "layout (location = 0) in vec4 color;\n"
3582 "void main() {\n"
3583 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3584 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3585 " \n"
3586
3587 // start with GS value to ensure it passed
3588 " vec4 outColor = color;\n"
3589
3590 // do some exact comparisons, even though we should
3591 // really have an epsilon involved.
3592 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3593 " outColor = wrong;\n"
3594 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3595 " outColor = wrong;\n"
3596 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3597 " outColor = wrong;\n"
3598 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3599 " outColor = wrong;\n"
3600 " if (fTwo != 2.0)\n"
3601 " outColor = wrong;\n"
3602 " if (fOneOne != vec2(1.0, 1.0))\n"
3603 " outColor = wrong;\n"
3604 " if (fTen != 10.0)\n"
3605 " outColor = wrong;\n"
3606 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3607 " outColor = wrong;\n"
3608 " \n"
3609 " gl_FragColor = outColor;\n"
3610 "}\n";
3611
3612
3613 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3614 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3615 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3616 0.0, 1.0, 0.0, 1.0, // align
3617 0.0, 0.0, 1.0, 1.0, // align
3618 0.0, 0.0, 0.0, 1.0, // align
3619 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3620 0.0, 2.0, 0.0, 2.0, // align
3621 0.0, 0.0, 2.0, 2.0, // align
3622 0.0, 0.0, 0.0, 2.0, // align
3623 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3624 0.0, 3.0, 0.0, 3.0, // align
3625 0.0, 0.0, 3.0, 3.0, // align
3626 0.0, 0.0, 0.0, 3.0, // align
3627 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3628 0.0, 4.0, 0.0, 4.0, // align
3629 0.0, 0.0, 4.0, 4.0, // align
3630 0.0, 0.0, 0.0, 4.0, // align
3631 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3632 0.0, 5.0, 0.0, 5.0, // align
3633 0.0, 0.0, 5.0, 5.0, // align
3634 0.0, 0.0, 0.0, 5.0, // align
3635 6.0, 0.0, 0.0, 6.0, // align
3636 0.0, 6.0, 0.0, 6.0, // align
3637 0.0, 0.0, 6.0, 6.0, // align
3638 0.0, 0.0, 0.0, 6.0, // align
3639 7.0, 0.0, 0.0, 7.0, // align
3640 0.0, 7.0, 0.0, 7.0, // align
3641 0.0, 0.0, 7.0, 7.0, // align
3642 0.0, 0.0, 0.0, 7.0, // align
3643 8.0, 0.0, 0.0, 8.0, // align
3644 0.0, 8.0, 0.0, 8.0, // align
3645 0.0, 0.0, 8.0, 8.0, // align
3646 0.0, 0.0, 0.0, 8.0, // align
3647 0.0, // float fZero; // align
3648 1.0, // float fOne; // pack
3649 2.0, // float fTwo; // pack
3650 3.0, // float fThree; // pack
3651 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3652 4.0, // float fFour; // pack
3653 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3654 5.0, // float fFive; // pack
3655 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3656 6.0, // float fSix; // pack
3657 7.0, // float fSeven; // align
3658 8.0, // float fEight; // pack
3659 9.0, // float fNine; // pack
3660 0.0, // BUFFER
3661 0.0, 0.0, // vec2 fZeroZero; // align
3662 0.0, 1.0, // vec2 fZeroOne; // pack
3663 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3664 1.0, 0.0, // vec2 fOneZero; // align
3665 1.0, 1.0, // vec2 fOneOne; // pack
3666 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3667 10.0, // float fTen; // pack
3668 11.0, // float fEleven; // align
3669 12.0, // float fTwelve; // pack
3670 0.0, 0.0, // BUFFER
3671 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3672 0.0, // BUFFER
3673 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3674 0.5, 0.6, 0.7, 0.8, // align
3675 0.9, 1.0, 1.1, 1.2, // align
3676 1.3, 1.4, 1.5, 1.6, // align
3677 };
3678
3679
3680
3681 ASSERT_NO_FATAL_FAILURE(InitState());
3682 ASSERT_NO_FATAL_FAILURE(InitViewport());
3683
3684 const int constCount = sizeof(mixedVals) / sizeof(float);
3685
3686 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3687 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3688 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3689
3690 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
3691
3692 VkPipelineObj pipelineobj(m_device);
3693 pipelineobj.AddShader(&vs);
3694 pipelineobj.AddShader(&gs);
3695 pipelineobj.AddShader(&ps);
3696
3697 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3698 VkCommandBufferObj cmdBuffer(m_device);
3699 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3700
3701 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3702
3703 VkDescriptorSetObj descriptorSet(m_device);
3704 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
3705
3706 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3707
3708 // render triangle
3709 cmdBuffer.Draw(0, 3, 0, 1);
3710
3711 // finalize recording of the command buffer
3712 EndCommandBuffer(cmdBuffer);
3713 cmdBuffer.QueueCommandBuffer();
3714
3715 RecordImages(m_renderTargets);
3716}
3717
3718TEST_F(VkRenderTest, GSPositions)
3719{
3720 // This test adds more inputs from the vertex shader and perturbs positions
3721 // Expected result is white triangle with weird positions
3722
3723 static const char *vertShaderText =
3724 "#version 140\n"
3725 "#extension GL_ARB_separate_shader_objects : enable\n"
3726 "#extension GL_ARB_shading_language_420pack : enable\n"
3727
3728 "layout(location = 0) out vec3 out_a;\n"
3729 "layout(location = 1) out vec3 out_b;\n"
3730 "layout(location = 2) out vec3 out_c;\n"
3731
3732 "void main() {\n"
3733
3734 // write a solid color to each
3735 " out_a = vec3(1.0, 0.0, 0.0);\n"
3736 " out_b = vec3(0.0, 1.0, 0.0);\n"
3737 " out_c = vec3(0.0, 0.0, 1.0);\n"
3738
3739 // generic position stuff
3740 " vec2 vertices;\n"
3741 " int vertexSelector = gl_VertexID;\n"
3742 " if (vertexSelector == 0)\n"
3743 " vertices = vec2(-0.5, -0.5);\n"
3744 " else if (vertexSelector == 1)\n"
3745 " vertices = vec2( 0.5, -0.5);\n"
3746 " else if (vertexSelector == 2)\n"
3747 " vertices = vec2( 0.5, 0.5);\n"
3748 " else\n"
3749 " vertices = vec2( 0.0, 0.0);\n"
3750 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3751
3752 "}\n";
3753
3754 static const char *geomShaderText =
3755 "#version 330\n"
3756 "#extension GL_ARB_separate_shader_objects : enable\n"
3757 "#extension GL_ARB_shading_language_420pack : enable\n"
3758 "layout( triangles ) in;\n"
3759 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3760
3761 "layout(location = 0) in vec3 in_a[3];\n"
3762 "layout(location = 1) in vec3 in_b[3];\n"
3763 "layout(location = 2) in vec3 in_c[3];\n"
3764
3765 "layout(location = 0) out vec3 out_a;\n"
3766 "layout(location = 1) out vec3 out_b;\n"
3767 "layout(location = 2) out vec3 out_c;\n"
3768
3769 "void main()\n"
3770 "{\n"
3771
3772 " gl_Position = gl_in[0].gl_Position;\n"
3773 " gl_Position.xy *= vec2(0.75);\n"
3774 " out_a = in_a[0];\n"
3775 " out_b = in_b[0];\n"
3776 " out_c = in_c[0];\n"
3777 " EmitVertex();\n"
3778
3779 " gl_Position = gl_in[1].gl_Position;\n"
3780 " gl_Position.xy *= vec2(1.5);\n"
3781 " out_a = in_a[1];\n"
3782 " out_b = in_b[1];\n"
3783 " out_c = in_c[1];\n"
3784 " EmitVertex();\n"
3785
3786 " gl_Position = gl_in[2].gl_Position;\n"
3787 " gl_Position.xy *= vec2(-0.1);\n"
3788 " out_a = in_a[2];\n"
3789 " out_b = in_b[2];\n"
3790 " out_c = in_c[2];\n"
3791 " EmitVertex();\n"
3792
3793 " EndPrimitive();\n"
3794 "}\n";
3795
3796
3797 static const char *fragShaderText =
3798 "#version 140\n"
3799 "#extension GL_ARB_separate_shader_objects : enable\n"
3800 "#extension GL_ARB_shading_language_420pack : enable\n"
3801
3802 "layout(location = 0) in vec3 in_a;\n"
3803 "layout(location = 1) in vec3 in_b;\n"
3804 "layout(location = 2) in vec3 in_c;\n"
3805
3806 "void main() {\n"
3807 " gl_FragColor = vec4(in_a.x, in_b.y, in_c.z, 1.0);\n"
3808 "}\n";
3809
3810
3811
3812 ASSERT_NO_FATAL_FAILURE(InitState());
3813 ASSERT_NO_FATAL_FAILURE(InitViewport());
3814
3815 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3816 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3817 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3818
3819 VkPipelineObj pipelineobj(m_device);
3820 pipelineobj.AddShader(&vs);
3821 pipelineobj.AddShader(&gs);
3822 pipelineobj.AddShader(&ps);
3823
3824 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3825 VkCommandBufferObj cmdBuffer(m_device);
3826 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3827
3828 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3829
3830 VkDescriptorSetObj descriptorSet(m_device);
3831
3832 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3833
3834 // render triangle
3835 cmdBuffer.Draw(0, 3, 0, 1);
3836
3837 // finalize recording of the command buffer
3838 EndCommandBuffer(cmdBuffer);
3839 cmdBuffer.QueueCommandBuffer();
3840
3841 RecordImages(m_renderTargets);
3842}
3843
3844TEST_F(VkRenderTest, GSTriStrip)
3845{
3846 // This test emits multiple multiple triangles using a GS
3847 // Correct result is an multicolor circle
3848
3849 static const char *vertShaderText =
3850 "#version 140\n"
3851 "#extension GL_ARB_separate_shader_objects : enable\n"
3852 "#extension GL_ARB_shading_language_420pack : enable\n"
3853
3854 "void main() {\n"
3855
3856 // generic position stuff
3857 " vec2 vertices;\n"
3858 " int vertexSelector = gl_VertexID;\n"
3859 " if (vertexSelector == 0)\n"
3860 " vertices = vec2(-0.5, -0.5);\n"
3861 " else if (vertexSelector == 1)\n"
3862 " vertices = vec2( 0.5, -0.5);\n"
3863 " else if (vertexSelector == 2)\n"
3864 " vertices = vec2( 0.5, 0.5);\n"
3865 " else\n"
3866 " vertices = vec2( 0.0, 0.0);\n"
3867 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3868
3869 "}\n";
3870
3871 static const char *geomShaderText =
3872 "#version 330\n"
3873 "#extension GL_ARB_separate_shader_objects : enable\n"
3874 "#extension GL_ARB_shading_language_420pack : enable\n"
3875 "layout( triangles ) in;\n"
3876 "layout( triangle_strip, max_vertices = 18 ) out;\n"
3877
3878 "layout(location = 0) out vec4 outColor;\n"
3879
3880 "void main()\n"
3881 "{\n"
3882 // init with first position to get zw
3883 " gl_Position = gl_in[0].gl_Position;\n"
3884
3885 " vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3886 " vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
3887 " vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
3888 " vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
3889
3890 // different color per tri
3891 " vec4[6] colors = { red, white, \n"
3892 " yellow, white, \n"
3893 " blue, white }; \n"
3894
3895 // fan out the triangles
3896 " vec2[18] positions = { vec2(0.0, 0.0), vec2(-0.5, 0.0), vec2(-0.25, -0.5), \n"
3897 " vec2(0.0, 0.0), vec2(-0.25, -0.5), vec2( 0.25, -0.5), \n"
3898 " vec2(0.0, 0.0), vec2( 0.25, -0.5), vec2( 0.5, 0.0), \n"
3899 " vec2(0.0, 0.0), vec2( 0.5, 0.0), vec2( 0.25, 0.5), \n"
3900 " vec2(0.0, 0.0), vec2( 0.25, 0.5), vec2(-0.25, 0.5), \n"
3901 " vec2(0.0, 0.0), vec2(-0.25, 0.5), vec2(-0.5, 0.0) }; \n"
3902
3903 // make a triangle list of 6
3904 " for (int i = 0; i < 6; ++i) { \n"
3905 " outColor = colors[i]; \n"
3906 " for (int j = 0; j < 3; ++j) { \n"
3907 " gl_Position.xy = positions[i * 3 + j]; \n"
3908 " EmitVertex(); \n"
3909 " } \n"
3910 " EndPrimitive();\n"
3911 " } \n"
3912
3913 "}\n";
3914
3915
3916 static const char *fragShaderText =
3917 "#version 150\n"
3918 "#extension GL_ARB_separate_shader_objects : enable\n"
3919 "#extension GL_ARB_shading_language_420pack : enable\n"
3920
3921
3922 "layout(binding = 0) uniform windowDimensions {\n"
3923 " vec4 dimensions;\n"
3924 "};\n"
3925
3926 "layout(location = 0) in vec4 inColor;\n"
3927 "layout(origin_upper_left) in vec4 gl_FragCoord;\n"
3928
3929 "void main() {\n"
3930
3931 // discard to make a nice circle
3932 " vec2 pos = abs(gl_FragCoord.xy) - vec2(dimensions.x, dimensions.y) / 2;\n"
3933 " float dist = sqrt(dot(pos, pos));\n"
3934 " if (dist > 50.0)\n"
3935 " discard;\n"
3936
3937 " gl_FragColor = inColor;\n"
3938
3939 "}\n";
3940
3941
3942
3943 ASSERT_NO_FATAL_FAILURE(InitState());
3944 ASSERT_NO_FATAL_FAILURE(InitViewport());
3945
3946 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3947 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3948 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3949
3950 VkPipelineObj pipelineobj(m_device);
3951 pipelineobj.AddShader(&vs);
3952 pipelineobj.AddShader(&gs);
3953 pipelineobj.AddShader(&ps);
3954
3955 const float dimensions[4] = { VkRenderFramework::m_width, VkRenderFramework::m_height , 0.0, 0.0};
3956
3957 VkConstantBufferObj windowDimensions(m_device, sizeof(dimensions) / sizeof(dimensions[0]), sizeof(dimensions[0]), (const void*) dimensions);
3958
3959 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3960 VkCommandBufferObj cmdBuffer(m_device);
3961 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3962
3963 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3964
3965 VkDescriptorSetObj descriptorSet(m_device);
3966 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, windowDimensions);
3967
3968 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3969
3970 // render triangle
3971 cmdBuffer.Draw(0, 3, 0, 1);
3972
3973 // finalize recording of the command buffer
3974 EndCommandBuffer(cmdBuffer);
3975 cmdBuffer.QueueCommandBuffer();
3976
3977 RecordImages(m_renderTargets);
3978}
3979
Chris Forbes23e6db62015-06-15 09:32:35 +12003980TEST_F(VkRenderTest, RenderPassLoadOpClear)
3981{
3982 ASSERT_NO_FATAL_FAILURE(InitState());
3983 ASSERT_NO_FATAL_FAILURE(InitViewport());
3984
3985 /* clear via load op to full green */
3986 m_clear_via_load_op = true;
3987 m_clear_color.useRawValue = false;
3988 m_clear_color.color.floatColor[0] = 0;
3989 m_clear_color.color.floatColor[1] = 1;
3990 m_clear_color.color.floatColor[2] = 0;
3991 m_clear_color.color.floatColor[3] = 0;
3992 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3993
3994 VkCommandBufferObj cmdBuffer(m_device);
3995 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3996 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3997 /* This command buffer contains ONLY the load op! */
3998 EndCommandBuffer(cmdBuffer);
3999 cmdBuffer.QueueCommandBuffer();
4000
4001 RecordImages(m_renderTargets);
4002}
4003
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004004int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004005 int result;
4006
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004007 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06004008 VkTestFramework::InitArgs(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004009
Chia-I Wu7133fdc2014-12-15 23:57:34 +08004010 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06004011
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004012 result = RUN_ALL_TESTS();
4013
Tony Barbour01999182015-04-09 12:58:51 -06004014 VkTestFramework::Finish();
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004015 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004016}