blob: 1c860ad455d8fc8014a55c82017cf359831b03df [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
Chris Forbes2127e812015-05-25 11:13:04 +1200619 ScopedUseSpv spv(true);
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
Chris Forbes2127e812015-05-25 11:13:04 +1200666 ScopedUseSpv spv(true);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600667 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700668}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600669#endif
Tony Barbour01999182015-04-09 12:58:51 -0600670TEST_F(VkRenderTest, YellowTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700671{
672 static const char *vertShaderText =
673 "#version 130\n"
674 "void main() {\n"
675 " vec2 vertices[3];"
676 " vertices[0] = vec2(-0.5, -0.5);\n"
677 " vertices[1] = vec2( 0.5, -0.5);\n"
678 " vertices[2] = vec2( 0.5, 0.5);\n"
679 " vec4 colors[3];\n"
680 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
681 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
682 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
683 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
684 "}\n";
685
686 static const char *fragShaderText =
687 "#version 130\n"
688 "void main() {\n"
689 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
690 "}\n";
691
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600692 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700693}
694
Tony Barbour01999182015-04-09 12:58:51 -0600695TEST_F(VkRenderTest, QuadWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600696{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600697 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600698 "#version 140\n"
699 "#extension GL_ARB_separate_shader_objects : enable\n"
700 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700701 //XYZ1( -1, -1, -1 )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600702 "layout (location = 0) in vec4 pos;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700703 //XYZ1( 0.f, 0.f, 0.f )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600704 "layout (location = 1) in vec4 inColor;\n"
705 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600706 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600707 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600708 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600709 "}\n";
710
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600711
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600712 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700713 "#version 140\n"
714 "#extension GL_ARB_separate_shader_objects : enable\n"
715 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600716 "layout (location = 0) in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700717 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600718 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700719 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600720 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600721
Tony Barbourf43b6982014-11-25 13:18:32 -0700722
723
724 ASSERT_NO_FATAL_FAILURE(InitState());
725 ASSERT_NO_FATAL_FAILURE(InitViewport());
726
Tony Barbour01999182015-04-09 12:58:51 -0600727 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000728 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700729
Tony Barbour01999182015-04-09 12:58:51 -0600730 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
731 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700732
Tony Barbour01999182015-04-09 12:58:51 -0600733 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -0700734 pipelineobj.AddShader(&vs);
735 pipelineobj.AddShader(&ps);
736
Tony Barbour01999182015-04-09 12:58:51 -0600737 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600738 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -0600739
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600740#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600741 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600742 MESH_BIND_ID, // binding ID
Tony Barbourf43b6982014-11-25 13:18:32 -0700743 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600744 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -0700745 };
746
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600747 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600748 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
749 vi_attribs[0].location = 0; // location, position
Tony Barbour8205d902015-04-16 15:59:00 -0600750 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600751 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
752 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
753 vi_attribs[1].location = 1; // location, color
Tony Barbour8205d902015-04-16 15:59:00 -0600754 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600755 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 -0700756
757 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
758 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600759 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -0700760
Tony Barboure4ed9942015-01-09 10:06:53 -0700761 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600762 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700763 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700764
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600765 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600766
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600767 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700768
Tony Barboure4ed9942015-01-09 10:06:53 -0700769 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
770
771 // render two triangles
772 cmdBuffer.Draw(0, 6, 0, 1);
773
774 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600775 EndCommandBuffer(cmdBuffer);
776
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600777 cmdBuffer.QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -0700778
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600779 RecordImages(m_renderTargets);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600780}
781
Tony Barbour01999182015-04-09 12:58:51 -0600782TEST_F(VkRenderTest, TriangleMRT)
Chia-I Wue09d1a72014-12-05 10:32:23 +0800783{
784 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600785 "#version 140\n"
786 "#extension GL_ARB_separate_shader_objects : enable\n"
787 "#extension GL_ARB_shading_language_420pack : enable\n"
788 "layout (location = 0) in vec4 pos;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800789 "void main() {\n"
790 " gl_Position = pos;\n"
791 "}\n";
792
793 static const char *fragShaderText =
794 "#version 130\n"
795 "void main() {\n"
796 " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
797 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
798 "}\n";
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600799 const float vb_data[][2] = {
Chia-I Wue09d1a72014-12-05 10:32:23 +0800800 { -1.0f, -1.0f },
801 { 1.0f, -1.0f },
802 { -1.0f, 1.0f }
803 };
804
805 ASSERT_NO_FATAL_FAILURE(InitState());
806 ASSERT_NO_FATAL_FAILURE(InitViewport());
807
Tony Barbour01999182015-04-09 12:58:51 -0600808 VkConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000809 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800810
Tony Barbour01999182015-04-09 12:58:51 -0600811 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
812 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800813
Tony Barbour01999182015-04-09 12:58:51 -0600814 VkPipelineObj pipelineobj(m_device);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800815 pipelineobj.AddShader(&vs);
816 pipelineobj.AddShader(&ps);
817
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600818#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600819 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600820 MESH_BUF_ID, // Binding ID
821 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600822 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Chia-I Wue09d1a72014-12-05 10:32:23 +0800823 };
824
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600825 VkVertexInputAttributeDescription vi_attrib;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600826 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
827 vi_attrib.location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -0600828 vi_attrib.format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600829 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
Chia-I Wue09d1a72014-12-05 10:32:23 +0800830
831 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
832 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600833 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800834
Tony Barbour01999182015-04-09 12:58:51 -0600835 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600836 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800837
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700838 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
Chia-I Wue09d1a72014-12-05 10:32:23 +0800839
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600840 VkPipelineCbAttachmentState att = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600841 att.blendEnable = VK_FALSE;
Chia-I Wue09d1a72014-12-05 10:32:23 +0800842 att.format = m_render_target_fmt;
843 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700844 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800845
Tony Barbour01999182015-04-09 12:58:51 -0600846 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700847
Tony Barbour5ed79702015-01-07 14:31:52 -0700848 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
849 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barboure4ed9942015-01-09 10:06:53 -0700850
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600851 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour5ed79702015-01-07 14:31:52 -0700852
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600853 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700854
Tony Barbour5ed79702015-01-07 14:31:52 -0700855 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700856#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600857 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour5ed79702015-01-07 14:31:52 -0700858 pDSDumpDot((char*)"triTest2.dot");
859#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600860
Tony Barbour5ed79702015-01-07 14:31:52 -0700861 // render triangle
862 cmdBuffer.Draw(0, 3, 0, 1);
863
864 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600865 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600866 cmdBuffer.QueueCommandBuffer();
Tony Barbour5ed79702015-01-07 14:31:52 -0700867
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600868 RecordImages(m_renderTargets);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800869}
870
Tony Barbour01999182015-04-09 12:58:51 -0600871TEST_F(VkRenderTest, QuadWithIndexedVertexFetch)
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700872{
873 static const char *vertShaderText =
874 "#version 140\n"
875 "#extension GL_ARB_separate_shader_objects : enable\n"
876 "#extension GL_ARB_shading_language_420pack : enable\n"
877 "layout(location = 0) in vec4 pos;\n"
878 "layout(location = 1) in vec4 inColor;\n"
879 "layout(location = 0) out vec4 outColor;\n"
880 "void main() {\n"
881 " outColor = inColor;\n"
882 " gl_Position = pos;\n"
883 "}\n";
884
885
886 static const char *fragShaderText =
887 "#version 140\n"
888 "#extension GL_ARB_separate_shader_objects : enable\n"
889 "#extension GL_ARB_shading_language_420pack : enable\n"
890 "layout(location = 0) in vec4 color;\n"
891 "void main() {\n"
892 " gl_FragColor = color;\n"
893 "}\n";
894
895 const Vertex g_vbData[] =
896 {
897 // first tri
898 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
899 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
900 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
901
902 // second tri
903 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
904 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
905 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
906 };
907
908 const uint16_t g_idxData[6] = {
909 0, 1, 2,
910 3, 4, 5,
911 };
912
913 ASSERT_NO_FATAL_FAILURE(InitState());
914 ASSERT_NO_FATAL_FAILURE(InitViewport());
915
Tony Barbour01999182015-04-09 12:58:51 -0600916 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000917 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700918
Tony Barbour01999182015-04-09 12:58:51 -0600919 VkIndexBufferObj indexBuffer(m_device);
Tony Barbour8205d902015-04-16 15:59:00 -0600920 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), VK_INDEX_TYPE_UINT16, g_idxData);
Mark Lobodzinskid30f82a2015-02-16 14:24:23 -0600921 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700922
Tony Barbour01999182015-04-09 12:58:51 -0600923 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
924 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700925
Tony Barbour01999182015-04-09 12:58:51 -0600926 VkPipelineObj pipelineobj(m_device);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700927 pipelineobj.AddShader(&vs);
928 pipelineobj.AddShader(&ps);
929
Tony Barbour01999182015-04-09 12:58:51 -0600930 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600931 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
932 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, indexBuffer);
Tony Barbour83a83802015-04-02 15:43:15 -0600933
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700934
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600935#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600936 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600937 MESH_BIND_ID, // binding ID
938 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600939 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700940 };
941
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600942 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600943 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
944 vi_attribs[0].location = 0; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600945 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600946 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
947 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
948 vi_attribs[1].location = 1; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600949 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600950 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700951
952 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
953 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700954
955 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600956 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700957 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600958 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barboure4ed9942015-01-09 10:06:53 -0700959
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600960 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700961
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700962#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600963 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700964 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700965#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700966
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600967 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600968 cmdBuffer.BindIndexBuffer(&indexBuffer, 0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700969
970 // render two triangles
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700971 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700972
973 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600974 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600975 cmdBuffer.QueueCommandBuffer();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700976
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600977 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700978}
979
Tony Barbour01999182015-04-09 12:58:51 -0600980TEST_F(VkRenderTest, GreyandRedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -0700981{
982 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -0700983
GregF6bef1212014-12-02 15:41:44 -0700984 static const char *vertShaderText =
985 "#version 140\n"
986 "#extension GL_ARB_separate_shader_objects : enable\n"
987 "#extension GL_ARB_shading_language_420pack : enable\n"
988 "layout (location = 0) in vec4 pos;\n"
989 "layout (location = 0) out vec4 outColor;\n"
990 "layout (location = 1) out vec4 outColor2;\n"
991 "void main() {\n"
992 " gl_Position = pos;\n"
993 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
994 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
995 "}\n";
996
997 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -0700998 "#version 330\n"
999 "#extension GL_ARB_separate_shader_objects : enable\n"
1000 "#extension GL_ARB_shading_language_420pack : enable\n"
1001 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1002 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1003 "layout (location = 0) in vec4 color;\n"
1004 "layout (location = 1) in vec4 color2;\n"
1005 "void main() {\n"
1006 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1007 " float dist_squared = dot(pos, pos);\n"
1008 " gl_FragColor = (dist_squared < 400.0)\n"
1009 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1010 " : color2;\n"
1011 "}\n";
1012
1013 ASSERT_NO_FATAL_FAILURE(InitState());
1014 ASSERT_NO_FATAL_FAILURE(InitViewport());
1015
Tony Barbour01999182015-04-09 12:58:51 -06001016 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001017 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001018
Tony Barbour01999182015-04-09 12:58:51 -06001019 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1020 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001021
Tony Barbour01999182015-04-09 12:58:51 -06001022 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001023 pipelineobj.AddShader(&vs);
1024 pipelineobj.AddShader(&ps);
1025
Tony Barbour01999182015-04-09 12:58:51 -06001026 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001027 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001028
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001029#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001030 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001031 MESH_BIND_ID, // binding ID
1032 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001033 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001034 };
1035
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001036 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001037 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1038 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001039 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001040 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001041
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001042 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001043 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001044 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001045
Tony Barbourdd4c9642015-01-09 12:55:14 -07001046 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001047 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001048 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1049
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001050 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001051
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001052 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001053
1054 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1055#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001056 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001057 pDSDumpDot((char*)"triTest2.dot");
1058#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001059
Tony Barbourdd4c9642015-01-09 12:55:14 -07001060 // render triangle
1061 cmdBuffer.Draw(0, 6, 0, 1);
1062
1063 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001064 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001065 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001066
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001067 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001068}
1069
Tony Barbour01999182015-04-09 12:58:51 -06001070TEST_F(VkRenderTest, RedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -07001071{
1072 // This tests that we correctly handle unread fragment inputs
1073
1074 static const char *vertShaderText =
1075 "#version 140\n"
1076 "#extension GL_ARB_separate_shader_objects : enable\n"
1077 "#extension GL_ARB_shading_language_420pack : enable\n"
1078 "layout (location = 0) in vec4 pos;\n"
1079 "layout (location = 0) out vec4 outColor;\n"
1080 "layout (location = 1) out vec4 outColor2;\n"
1081 "void main() {\n"
1082 " gl_Position = pos;\n"
1083 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1084 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1085 "}\n";
1086
1087 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001088 "#version 330\n"
1089 "#extension GL_ARB_separate_shader_objects : enable\n"
1090 "#extension GL_ARB_shading_language_420pack : enable\n"
1091 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1092 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1093 "layout (location = 0) in vec4 color;\n"
1094 "layout (location = 1) in vec4 color2;\n"
1095 "void main() {\n"
1096 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1097 " float dist_squared = dot(pos, pos);\n"
1098 " gl_FragColor = (dist_squared < 400.0)\n"
1099 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1100 " : color2;\n"
1101 "}\n";
1102
1103 ASSERT_NO_FATAL_FAILURE(InitState());
1104 ASSERT_NO_FATAL_FAILURE(InitViewport());
1105
Tony Barbour01999182015-04-09 12:58:51 -06001106 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001107 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001108
Tony Barbour01999182015-04-09 12:58:51 -06001109 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1110 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001111
Tony Barbour01999182015-04-09 12:58:51 -06001112 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001113 pipelineobj.AddShader(&vs);
1114 pipelineobj.AddShader(&ps);
1115
Tony Barbour01999182015-04-09 12:58:51 -06001116 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001117 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001118
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001119#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001120 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001121 MESH_BIND_ID, // binding ID
1122 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001123 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001124 };
1125
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001126 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001127 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1128 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001129 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001130 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001131
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001132 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001133 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001134 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001135
Tony Barbourdd4c9642015-01-09 12:55:14 -07001136 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001137 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001138 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1139
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001140 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001141
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001142 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001143
1144 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1145#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001146 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001147 pDSDumpDot((char*)"triTest2.dot");
1148#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001149 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001150 cmdBuffer.Draw(0, 6, 0, 1);
1151
1152 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001153 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001154 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001155
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001156 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001157}
1158
Tony Barbour01999182015-04-09 12:58:51 -06001159TEST_F(VkRenderTest, GreyCirclesonBlueFade)
GregF6bef1212014-12-02 15:41:44 -07001160{
1161 // This tests reading gl_ClipDistance from FS
1162
1163 static const char *vertShaderText =
1164 "#version 330\n"
1165 "#extension GL_ARB_separate_shader_objects : enable\n"
1166 "#extension GL_ARB_shading_language_420pack : enable\n"
1167 "out gl_PerVertex {\n"
1168 " vec4 gl_Position;\n"
1169 " float gl_ClipDistance[1];\n"
1170 "};\n"
1171 "layout (location = 0) in vec4 pos;\n"
1172 "layout (location = 0) out vec4 outColor;\n"
1173 "layout (location = 1) out vec4 outColor2;\n"
1174 "void main() {\n"
1175 " gl_Position = pos;\n"
1176 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1177 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1178 " float dists[3];\n"
1179 " dists[0] = 0.0;\n"
1180 " dists[1] = 1.0;\n"
1181 " dists[2] = 1.0;\n"
1182 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1183 "}\n";
1184
1185
1186 static const char *fragShaderText =
1187 //"#version 140\n"
1188 "#version 330\n"
1189 "#extension GL_ARB_separate_shader_objects : enable\n"
1190 "#extension GL_ARB_shading_language_420pack : enable\n"
1191 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1192 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1193 "layout (location = 0) in vec4 color;\n"
1194 "layout (location = 1) in vec4 color2;\n"
1195 "void main() {\n"
1196 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1197 " float dist_squared = dot(pos, pos);\n"
1198 " gl_FragColor = (dist_squared < 400.0)\n"
1199 " ? color * gl_ClipDistance[0]\n"
1200 " : color2;\n"
1201 "}\n";
1202
1203 ASSERT_NO_FATAL_FAILURE(InitState());
1204 ASSERT_NO_FATAL_FAILURE(InitViewport());
1205
Tony Barbour01999182015-04-09 12:58:51 -06001206 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001207 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001208
Tony Barbour01999182015-04-09 12:58:51 -06001209 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1210 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001211
Tony Barbour01999182015-04-09 12:58:51 -06001212 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001213 pipelineobj.AddShader(&vs);
1214 pipelineobj.AddShader(&ps);
1215
Tony Barbour01999182015-04-09 12:58:51 -06001216 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001217 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001218
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001219#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001220 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001221 MESH_BIND_ID, // binding ID
1222 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001223 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001224 };
1225
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001226 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001227 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1228 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001229 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001230 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001231
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001232 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001233 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001234 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001235
Tony Barbourdd4c9642015-01-09 12:55:14 -07001236 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001237 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001238 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF6bef1212014-12-02 15:41:44 -07001239
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001240 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001241
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001242 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001243
1244 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1245#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001246 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001247 pDSDumpDot((char*)"triTest2.dot");
1248#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001249
1250 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001251 cmdBuffer.Draw(0, 6, 0, 1);
1252
1253 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001254 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001255 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001256
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001257 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001258}
Tony Barbourf43b6982014-11-25 13:18:32 -07001259
Tony Barbour01999182015-04-09 12:58:51 -06001260TEST_F(VkRenderTest, GreyCirclesonBlueDiscard)
GregF7a23c792014-12-02 17:19:34 -07001261{
1262 static const char *vertShaderText =
1263 "#version 140\n"
1264 "#extension GL_ARB_separate_shader_objects : enable\n"
1265 "#extension GL_ARB_shading_language_420pack : enable\n"
1266 "layout (location = 0) in vec4 pos;\n"
1267 "layout (location = 0) out vec4 outColor;\n"
1268 "layout (location = 1) out vec4 outColor2;\n"
1269 "void main() {\n"
1270 " gl_Position = pos;\n"
1271 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1272 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1273 "}\n";
1274
1275
1276 static const char *fragShaderText =
GregF7a23c792014-12-02 17:19:34 -07001277 "#version 330\n"
1278 "#extension GL_ARB_separate_shader_objects : enable\n"
1279 "#extension GL_ARB_shading_language_420pack : enable\n"
1280 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1281 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1282 "layout (location = 0) in vec4 color;\n"
1283 "layout (location = 1) in vec4 color2;\n"
1284 "void main() {\n"
1285 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1286 " float dist_squared = dot(pos, pos);\n"
1287 " if (dist_squared < 100.0)\n"
1288 " discard;\n"
1289 " gl_FragColor = (dist_squared < 400.0)\n"
1290 " ? color\n"
1291 " : color2;\n"
1292 "}\n";
1293
1294 ASSERT_NO_FATAL_FAILURE(InitState());
1295 ASSERT_NO_FATAL_FAILURE(InitViewport());
1296
Tony Barbour01999182015-04-09 12:58:51 -06001297 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001298 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001299
Tony Barbour01999182015-04-09 12:58:51 -06001300 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1301 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF7a23c792014-12-02 17:19:34 -07001302
Tony Barbour01999182015-04-09 12:58:51 -06001303 VkPipelineObj pipelineobj(m_device);
GregF7a23c792014-12-02 17:19:34 -07001304 pipelineobj.AddShader(&vs);
1305 pipelineobj.AddShader(&ps);
1306
Tony Barbour01999182015-04-09 12:58:51 -06001307 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001308 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001309
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001310#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001311 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001312 MESH_BIND_ID, // binding ID
1313 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001314 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF7a23c792014-12-02 17:19:34 -07001315 };
1316
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001317 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001318 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1319 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001320 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001321 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF7a23c792014-12-02 17:19:34 -07001322
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001323 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF7a23c792014-12-02 17:19:34 -07001324 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001325 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF7a23c792014-12-02 17:19:34 -07001326
Tony Barbourdd4c9642015-01-09 12:55:14 -07001327 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001328 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001329 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1330
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001331 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001332
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001333 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001334
1335 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1336#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001337 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001338 pDSDumpDot((char*)"triTest2.dot");
1339#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001340
1341 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001342 cmdBuffer.Draw(0, 6, 0, 1);
1343
1344 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001345 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001346 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001347
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001348 RecordImages(m_renderTargets);
GregF7a23c792014-12-02 17:19:34 -07001349}
1350
1351
Tony Barbour01999182015-04-09 12:58:51 -06001352TEST_F(VkRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001353{
1354 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001355 "#version 140\n"
1356 "#extension GL_ARB_separate_shader_objects : enable\n"
1357 "#extension GL_ARB_shading_language_420pack : enable\n"
1358 "\n"
1359 "layout(binding = 0) uniform buf {\n"
1360 " mat4 MVP;\n"
1361 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001362 "void main() {\n"
1363 " vec2 vertices[3];"
1364 " vertices[0] = vec2(-0.5, -0.5);\n"
1365 " vertices[1] = vec2( 0.5, -0.5);\n"
1366 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001367 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001368 "}\n";
1369
1370 static const char *fragShaderText =
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001371 "#version 130\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001372 "void main() {\n"
Cody Northrop78eac042014-10-10 15:45:00 -06001373 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001374 "}\n";
1375
Tony Barbourf43b6982014-11-25 13:18:32 -07001376 ASSERT_NO_FATAL_FAILURE(InitState());
1377 ASSERT_NO_FATAL_FAILURE(InitViewport());
1378
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001379 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001380 glm::mat4 Projection = glm::mat4(1.0f);
1381 glm::mat4 View = glm::mat4(1.0f);
1382 glm::mat4 Model = glm::mat4(1.0f);
1383 glm::mat4 MVP = Projection * View * Model;
1384 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1385
Tony Barbour01999182015-04-09 12:58:51 -06001386 VkConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1387 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1388 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001389
Tony Barbour01999182015-04-09 12:58:51 -06001390 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001391 pipelineobj.AddShader(&vs);
1392 pipelineobj.AddShader(&ps);
1393
1394 // Create descriptor set and attach the constant buffer to it
Tony Barbour01999182015-04-09 12:58:51 -06001395 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001396 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001397
Tony Barbourdd4c9642015-01-09 12:55:14 -07001398 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001399 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001400 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001401
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001402 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001403
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001404 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001405
1406 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1407#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001408 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001409 pDSDumpDot((char*)"triTest2.dot");
1410#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001411
1412 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001413 cmdBuffer.Draw(0, 6, 0, 1);
1414
1415 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001416 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001417 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001418
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001419 RecordImages(m_renderTargets);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001420
1421 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001422}
1423
Tony Barbour01999182015-04-09 12:58:51 -06001424TEST_F(VkRenderTest, MixTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07001425{
1426 // This tests location applied to varyings. Notice that we have switched foo
1427 // and bar in the FS. The triangle should be blended with red, green and blue
1428 // corners.
1429 static const char *vertShaderText =
1430 "#version 140\n"
1431 "#extension GL_ARB_separate_shader_objects : enable\n"
1432 "#extension GL_ARB_shading_language_420pack : enable\n"
1433 "layout (location=0) out vec4 bar;\n"
1434 "layout (location=1) out vec4 foo;\n"
1435 "layout (location=2) out float scale;\n"
1436 "vec2 vertices[3];\n"
1437 "void main() {\n"
1438 " vertices[0] = vec2(-1.0, -1.0);\n"
1439 " vertices[1] = vec2( 1.0, -1.0);\n"
1440 " vertices[2] = vec2( 0.0, 1.0);\n"
1441 "vec4 colors[3];\n"
1442 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1443 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1444 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1445 " foo = colors[gl_VertexID % 3];\n"
1446 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1447 " scale = 1.0;\n"
1448 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1449 "}\n";
1450
1451 static const char *fragShaderText =
1452 "#version 140\n"
1453 "#extension GL_ARB_separate_shader_objects : enable\n"
1454 "#extension GL_ARB_shading_language_420pack : enable\n"
1455 "layout (location = 1) in vec4 bar;\n"
1456 "layout (location = 0) in vec4 foo;\n"
1457 "layout (location = 2) in float scale;\n"
1458 "void main() {\n"
1459 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
1460 "}\n";
1461
1462 ASSERT_NO_FATAL_FAILURE(InitState());
1463 ASSERT_NO_FATAL_FAILURE(InitViewport());
1464
Tony Barbour01999182015-04-09 12:58:51 -06001465 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1466 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001467
Tony Barbour01999182015-04-09 12:58:51 -06001468 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001469 pipelineobj.AddShader(&vs);
1470 pipelineobj.AddShader(&ps);
1471
Tony Barbour01999182015-04-09 12:58:51 -06001472 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06001473 descriptorSet.AppendDummy();
Tony Barbourf43b6982014-11-25 13:18:32 -07001474
Tony Barbourdd4c9642015-01-09 12:55:14 -07001475 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001476 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001477 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1478
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001479 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001480
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001481 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001482
1483#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001484 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001485 pDSDumpDot((char*)"triTest2.dot");
1486#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001487
Tony Barbourdd4c9642015-01-09 12:55:14 -07001488 // render triangle
1489 cmdBuffer.Draw(0, 3, 0, 1);
1490
1491 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001492 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001493 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001494
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001495 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001496}
1497
Tony Barbour01999182015-04-09 12:58:51 -06001498TEST_F(VkRenderTest, QuadVertFetchAndVertID)
Tony Barbourf43b6982014-11-25 13:18:32 -07001499{
1500 // This tests that attributes work in the presence of gl_VertexID
1501
1502 static const char *vertShaderText =
1503 "#version 140\n"
1504 "#extension GL_ARB_separate_shader_objects : enable\n"
1505 "#extension GL_ARB_shading_language_420pack : enable\n"
1506 //XYZ1( -1, -1, -1 )
1507 "layout (location = 0) in vec4 pos;\n"
1508 //XYZ1( 0.f, 0.f, 0.f )
1509 "layout (location = 1) in vec4 inColor;\n"
1510 "layout (location = 0) out vec4 outColor;\n"
1511 "void main() {\n"
1512 " outColor = inColor;\n"
1513 " vec4 vertices[3];"
1514 " vertices[gl_VertexID % 3] = pos;\n"
1515 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1516 "}\n";
1517
1518
1519 static const char *fragShaderText =
1520 "#version 140\n"
1521 "#extension GL_ARB_separate_shader_objects : enable\n"
1522 "#extension GL_ARB_shading_language_420pack : enable\n"
1523 "layout (location = 0) in vec4 color;\n"
1524 "void main() {\n"
1525 " gl_FragColor = color;\n"
1526 "}\n";
1527
1528 ASSERT_NO_FATAL_FAILURE(InitState());
1529 ASSERT_NO_FATAL_FAILURE(InitViewport());
1530
Tony Barbour01999182015-04-09 12:58:51 -06001531 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001532 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001533
Tony Barbour01999182015-04-09 12:58:51 -06001534 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1535 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001536
Tony Barbour01999182015-04-09 12:58:51 -06001537 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001538 pipelineobj.AddShader(&vs);
1539 pipelineobj.AddShader(&ps);
1540
Tony Barbour01999182015-04-09 12:58:51 -06001541 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001542 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001543
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001544#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001545 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001546 MESH_BUF_ID, // Binding ID
1547 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001548 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001549 };
1550
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001551 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001552 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1553 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001554 vi_attribs[0].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001555 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1556 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1557 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001558 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001559 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001560
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001561 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001562 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001563 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001564
Tony Barbourdd4c9642015-01-09 12:55:14 -07001565 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001566 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001567 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1568
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001569 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001570
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001571 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001572
1573 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1574#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001575 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001576 pDSDumpDot((char*)"triTest2.dot");
1577#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001578
1579 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001580 cmdBuffer.Draw(0, 6, 0, 1);
1581
1582 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001583 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001584 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001585
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001586 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001587}
1588
Tony Barbour01999182015-04-09 12:58:51 -06001589TEST_F(VkRenderTest, QuadSparseVertFetch)
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001590{
1591 // This tests that attributes work in the presence of gl_VertexID
1592
1593 static const char *vertShaderText =
1594 "#version 140\n"
1595 "#extension GL_ARB_separate_shader_objects : enable\n"
1596 "#extension GL_ARB_shading_language_420pack : enable\n"
1597 //XYZ1( -1, -1, -1 )
1598 "layout (location = 1) in vec4 pos;\n"
1599 "layout (location = 4) in vec4 inColor;\n"
1600 //XYZ1( 0.f, 0.f, 0.f )
1601 "layout (location = 0) out vec4 outColor;\n"
1602 "void main() {\n"
1603 " outColor = inColor;\n"
1604 " gl_Position = pos;\n"
1605 "}\n";
1606
1607
1608 static const char *fragShaderText =
1609 "#version 140\n"
1610 "#extension GL_ARB_separate_shader_objects : enable\n"
1611 "#extension GL_ARB_shading_language_420pack : enable\n"
1612 "layout (location = 0) in vec4 color;\n"
1613 "void main() {\n"
1614 " gl_FragColor = color;\n"
1615 "}\n";
1616
1617 ASSERT_NO_FATAL_FAILURE(InitState());
1618 ASSERT_NO_FATAL_FAILURE(InitViewport());
1619
1620 struct VDATA
1621 {
1622 float t1, t2, t3, t4; // filler data
1623 float posX, posY, posZ, posW; // Position data
1624 float r, g, b, a; // Color
1625 };
1626 const struct VDATA vData[] =
1627 {
1628 { XYZ1(0, 0, 0), XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
1629 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1630 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.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( 1.f, 0.f, 0.f ) },
1633 { XYZ1(0, 0, 0), XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
1634 };
1635
Tony Barbour01999182015-04-09 12:58:51 -06001636 VkConstantBufferObj meshBuffer(m_device,sizeof(vData)/sizeof(vData[0]),sizeof(vData[0]), vData);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001637 meshBuffer.BufferMemoryBarrier();
1638
Tony Barbour01999182015-04-09 12:58:51 -06001639 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1640 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001641
Tony Barbour01999182015-04-09 12:58:51 -06001642 VkPipelineObj pipelineobj(m_device);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001643 pipelineobj.AddShader(&vs);
1644 pipelineobj.AddShader(&ps);
1645
Tony Barbour01999182015-04-09 12:58:51 -06001646 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001647 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001648
1649#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001650 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001651 MESH_BUF_ID, // Binding ID
1652 sizeof(vData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001653 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001654 };
1655
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001656 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001657 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1658 vi_attribs[0].location = 4;
Tony Barbour8205d902015-04-16 15:59:00 -06001659 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001660 vi_attribs[0].offsetInBytes = sizeof(float) * 4 * 2; // Offset of first element in bytes from base of vertex
1661 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1662 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001663 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001664 vi_attribs[1].offsetInBytes = sizeof(float) * 4 * 1; // Offset of first element in bytes from base of vertex
1665
1666 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
1667 pipelineobj.AddVertexInputBindings(&vi_binding, 1);
1668 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
1669
1670 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001671 VkCommandBufferObj cmdBuffer(m_device);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001672 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1673
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001674 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001675
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001676 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001677
1678 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BUF_ID);
1679#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001680 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001681 pDSDumpDot((char*)"triTest2.dot");
1682#endif
1683
1684 // render two triangles
1685 cmdBuffer.Draw(0, 6, 0, 1);
1686
1687 // finalize recording of the command buffer
1688 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001689 cmdBuffer.QueueCommandBuffer();
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001690
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001691 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001692}
1693
Tony Barbour01999182015-04-09 12:58:51 -06001694TEST_F(VkRenderTest, TriVertFetchDeadAttr)
Tony Barbourf43b6982014-11-25 13:18:32 -07001695{
1696 // This tests that attributes work in the presence of gl_VertexID
1697 // and a dead attribute in position 0. Draws a triangle with yellow,
1698 // red and green corners, starting at top and going clockwise.
1699
1700 static const char *vertShaderText =
1701 "#version 140\n"
1702 "#extension GL_ARB_separate_shader_objects : enable\n"
1703 "#extension GL_ARB_shading_language_420pack : enable\n"
1704 //XYZ1( -1, -1, -1 )
1705 "layout (location = 0) in vec4 pos;\n"
1706 //XYZ1( 0.f, 0.f, 0.f )
1707 "layout (location = 1) in vec4 inColor;\n"
1708 "layout (location = 0) out vec4 outColor;\n"
1709 "void main() {\n"
1710 " outColor = inColor;\n"
1711 " vec2 vertices[3];"
1712 " vertices[0] = vec2(-1.0, -1.0);\n"
1713 " vertices[1] = vec2( 1.0, -1.0);\n"
1714 " vertices[2] = vec2( 0.0, 1.0);\n"
1715 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1716 "}\n";
1717
1718
1719 static const char *fragShaderText =
1720 "#version 140\n"
1721 "#extension GL_ARB_separate_shader_objects : enable\n"
1722 "#extension GL_ARB_shading_language_420pack : enable\n"
1723 "layout (location = 0) in vec4 color;\n"
1724 "void main() {\n"
1725 " gl_FragColor = color;\n"
1726 "}\n";
1727
1728 ASSERT_NO_FATAL_FAILURE(InitState());
1729 ASSERT_NO_FATAL_FAILURE(InitViewport());
1730
Tony Barbour01999182015-04-09 12:58:51 -06001731 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001732 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001733
Tony Barbour01999182015-04-09 12:58:51 -06001734 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1735 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001736
Tony Barbour01999182015-04-09 12:58:51 -06001737 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001738 pipelineobj.AddShader(&vs);
1739 pipelineobj.AddShader(&ps);
1740
Tony Barbour01999182015-04-09 12:58:51 -06001741 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001742 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001743
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001744#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001745 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001746 MESH_BUF_ID, // Binding ID
1747 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001748 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001749 };
1750
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001751 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001752 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1753 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001754 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001755 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1756 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1757 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001758 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001759 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001760
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001761 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001762 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001763 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001764
Tony Barbourdd4c9642015-01-09 12:55:14 -07001765 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001766 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001767 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001768
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001769 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001770
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001771 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001772
1773 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1774#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001775 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001776 pDSDumpDot((char*)"triTest2.dot");
1777#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001778
1779 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001780 cmdBuffer.Draw(0, 6, 0, 1);
1781
1782 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001783 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001784 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001785
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001786 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001787}
1788
Tony Barbour01999182015-04-09 12:58:51 -06001789TEST_F(VkRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001790{
1791 static const char *vertShaderText =
1792 "#version 140\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001793 "#extension GL_ARB_separate_shader_objects : enable\n"
1794 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001795 "layout (std140) uniform bufferVals {\n"
1796 " mat4 mvp;\n"
1797 "} myBufferVals;\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001798 "layout (location = 0) in vec4 pos;\n"
1799 "layout (location = 1) in vec4 inColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001800 "out vec4 outColor;\n"
1801 "void main() {\n"
1802 " outColor = inColor;\n"
1803 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001804 " gl_Position.y = -gl_Position.y;\n"
1805 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001806 "}\n";
1807
1808 static const char *fragShaderText =
1809 "#version 130\n"
1810 "in vec4 color;\n"
1811 "void main() {\n"
1812 " gl_FragColor = color;\n"
1813 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001814 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001815
Tony Barbourf43b6982014-11-25 13:18:32 -07001816 glm::mat4 View = glm::lookAt(
1817 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1818 glm::vec3(0,0,0), // and looks at the origin
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001819 glm::vec3(0,-1,0) // Head is up (set to 0,-1,0 to look upside-down)
Tony Barbourf43b6982014-11-25 13:18:32 -07001820 );
1821
1822 glm::mat4 Model = glm::mat4(1.0f);
1823
1824 glm::mat4 MVP = Projection * View * Model;
1825
1826 ASSERT_NO_FATAL_FAILURE(InitState());
1827 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour8bef8ee2015-05-22 09:44:58 -06001828 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07001829
Tony Barbour01999182015-04-09 12:58:51 -06001830 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 -07001831 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1832
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001833 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07001834
Tony Barbour01999182015-04-09 12:58:51 -06001835 VkConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1836 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1837 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001838
Tony Barbour01999182015-04-09 12:58:51 -06001839 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001840 pipelineobj.AddShader(&vs);
1841 pipelineobj.AddShader(&ps);
1842
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001843 VkPipelineDsStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001844 ds_state.depthTestEnable = VK_TRUE;
1845 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06001846 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001847 ds_state.depthBoundsEnable = VK_FALSE;
1848 ds_state.stencilTestEnable = VK_FALSE;
1849 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
1850 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
1851 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06001852 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
1853 ds_state.format = VK_FORMAT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001854 ds_state.front = ds_state.back;
1855 pipelineobj.SetDepthStencil(&ds_state);
1856
Tony Barbour01999182015-04-09 12:58:51 -06001857 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001858 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001859
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001860#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001861 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001862 MESH_BUF_ID, // Binding ID
1863 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001864 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001865 };
Tony Barbourf43b6982014-11-25 13:18:32 -07001866
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001867 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001868 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1869 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001870 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001871 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1872 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1873 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001874 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001875 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001876
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001877 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001878 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001879 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001880
Tony Barbour17c6ab12015-03-27 17:03:18 -06001881 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour17c6ab12015-03-27 17:03:18 -06001882
Tony Barbour01999182015-04-09 12:58:51 -06001883 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -07001884 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001885
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001886 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001887 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001888
Tony Barboure4ed9942015-01-09 10:06:53 -07001889 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1890#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001891 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barboure4ed9942015-01-09 10:06:53 -07001892 pDSDumpDot((char*)"triTest2.dot");
1893#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001894
1895 // render triangles
Tony Barboure4ed9942015-01-09 10:06:53 -07001896 cmdBuffer.Draw(0, 36, 0, 1);
1897
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001898
Tony Barboure4ed9942015-01-09 10:06:53 -07001899 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001900 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001901 cmdBuffer.QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -07001902
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001903 RecordImages(m_renderTargets);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001904}
1905
Tony Barbour01999182015-04-09 12:58:51 -06001906TEST_F(VkRenderTest, VSTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07001907{
1908 // The expected result from this test is a green and red triangle;
1909 // one red vertex on the left, two green vertices on the right.
1910 static const char *vertShaderText =
1911 "#version 130\n"
1912 "out vec4 texColor;\n"
1913 "uniform sampler2D surface;\n"
1914 "void main() {\n"
1915 " vec2 vertices[3];"
1916 " vertices[0] = vec2(-0.5, -0.5);\n"
1917 " vertices[1] = vec2( 0.5, -0.5);\n"
1918 " vertices[2] = vec2( 0.5, 0.5);\n"
1919 " vec2 positions[3];"
1920 " positions[0] = vec2( 0.0, 0.0);\n"
1921 " positions[1] = vec2( 0.25, 0.1);\n"
1922 " positions[2] = vec2( 0.1, 0.25);\n"
1923 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1924 " texColor = textureLod(surface, samplePos, 0.0);\n"
1925 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1926 "}\n";
1927
1928 static const char *fragShaderText =
1929 "#version 130\n"
1930 "in vec4 texColor;\n"
1931 "void main() {\n"
1932 " gl_FragColor = texColor;\n"
1933 "}\n";
1934
1935 ASSERT_NO_FATAL_FAILURE(InitState());
1936 ASSERT_NO_FATAL_FAILURE(InitViewport());
1937
Tony Barbour01999182015-04-09 12:58:51 -06001938 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1939 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
1940 VkSamplerObj sampler(m_device);
1941 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001942
Tony Barbour01999182015-04-09 12:58:51 -06001943 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001944 pipelineobj.AddShader(&vs);
1945 pipelineobj.AddShader(&ps);
1946
Tony Barbour01999182015-04-09 12:58:51 -06001947 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001948 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001949
Tony Barbourdd4c9642015-01-09 12:55:14 -07001950 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001951 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001952 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001953
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001954 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001955
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001956 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001957
1958#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001959 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001960 pDSDumpDot((char*)"triTest2.dot");
1961#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001962
Tony Barbourdd4c9642015-01-09 12:55:14 -07001963 // render triangle
1964 cmdBuffer.Draw(0, 3, 0, 1);
1965
1966 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001967 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001968 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001969
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001970 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001971}
Tony Barbour01999182015-04-09 12:58:51 -06001972TEST_F(VkRenderTest, TexturedTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07001973{
1974 // The expected result from this test is a red and green checkered triangle
1975 static const char *vertShaderText =
1976 "#version 140\n"
1977 "#extension GL_ARB_separate_shader_objects : enable\n"
1978 "#extension GL_ARB_shading_language_420pack : enable\n"
1979 "layout (location = 0) out vec2 samplePos;\n"
1980 "void main() {\n"
1981 " vec2 vertices[3];"
1982 " vertices[0] = vec2(-0.5, -0.5);\n"
1983 " vertices[1] = vec2( 0.5, -0.5);\n"
1984 " vertices[2] = vec2( 0.5, 0.5);\n"
1985 " vec2 positions[3];"
1986 " positions[0] = vec2( 0.0, 0.0);\n"
1987 " positions[1] = vec2( 1.0, 0.0);\n"
1988 " positions[2] = vec2( 1.0, 1.0);\n"
1989 " samplePos = positions[gl_VertexID % 3];\n"
1990 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1991 "}\n";
1992
1993 static const char *fragShaderText =
1994 "#version 140\n"
1995 "#extension GL_ARB_separate_shader_objects : enable\n"
1996 "#extension GL_ARB_shading_language_420pack : enable\n"
1997 "layout (location = 0) in vec2 samplePos;\n"
1998 "layout (binding = 0) uniform sampler2D surface;\n"
1999 "layout (location=0) out vec4 outColor;\n"
2000 "void main() {\n"
2001 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2002 " outColor = texColor;\n"
2003 "}\n";
2004
2005 ASSERT_NO_FATAL_FAILURE(InitState());
2006 ASSERT_NO_FATAL_FAILURE(InitViewport());
2007
Tony Barbour01999182015-04-09 12:58:51 -06002008 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2009 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2010 VkSamplerObj sampler(m_device);
2011 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002012
Tony Barbour01999182015-04-09 12:58:51 -06002013 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002014 pipelineobj.AddShader(&vs);
2015 pipelineobj.AddShader(&ps);
2016
Tony Barbour01999182015-04-09 12:58:51 -06002017 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002018 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002019
Tony Barbourdd4c9642015-01-09 12:55:14 -07002020 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002021 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002022 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2023
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002024 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002025
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002026 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002027
2028#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002029 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002030 pDSDumpDot((char*)"triTest2.dot");
2031#endif
2032 // render triangle
2033 cmdBuffer.Draw(0, 3, 0, 1);
2034
2035 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002036 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002037 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002038
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002039 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002040}
Tony Barbour01999182015-04-09 12:58:51 -06002041TEST_F(VkRenderTest, TexturedTriangleClip)
Tony Barbourf43b6982014-11-25 13:18:32 -07002042{
2043 // The expected result from this test is a red and green checkered triangle
2044 static const char *vertShaderText =
2045 "#version 330\n"
2046 "#extension GL_ARB_separate_shader_objects : enable\n"
2047 "#extension GL_ARB_shading_language_420pack : enable\n"
2048 "layout (location = 0) out vec2 samplePos;\n"
2049 "out gl_PerVertex {\n"
2050 " vec4 gl_Position;\n"
2051 " float gl_ClipDistance[1];\n"
2052 "};\n"
2053 "void main() {\n"
2054 " vec2 vertices[3];"
2055 " vertices[0] = vec2(-0.5, -0.5);\n"
2056 " vertices[1] = vec2( 0.5, -0.5);\n"
2057 " vertices[2] = vec2( 0.5, 0.5);\n"
2058 " vec2 positions[3];"
2059 " positions[0] = vec2( 0.0, 0.0);\n"
2060 " positions[1] = vec2( 1.0, 0.0);\n"
2061 " positions[2] = vec2( 1.0, 1.0);\n"
2062 " float dists[3];\n"
2063 " dists[0] = 1.0;\n"
2064 " dists[1] = 1.0;\n"
2065 " dists[2] = -1.0;\n"
2066 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2067 " samplePos = positions[gl_VertexID % 3];\n"
2068 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2069 "}\n";
2070
2071 static const char *fragShaderText =
2072 "#version 140\n"
2073 "#extension GL_ARB_separate_shader_objects : enable\n"
2074 "#extension GL_ARB_shading_language_420pack : enable\n"
2075 "layout (location = 0) in vec2 samplePos;\n"
2076 "layout (binding = 0) uniform sampler2D surface;\n"
2077 "layout (location=0) out vec4 outColor;\n"
2078 "void main() {\n"
2079 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2080 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2081 " outColor = texColor;\n"
2082 "}\n";
2083
2084
2085 ASSERT_NO_FATAL_FAILURE(InitState());
2086 ASSERT_NO_FATAL_FAILURE(InitViewport());
2087
Tony Barbour01999182015-04-09 12:58:51 -06002088 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2089 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2090 VkSamplerObj sampler(m_device);
2091 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002092
Tony Barbour01999182015-04-09 12:58:51 -06002093 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002094 pipelineobj.AddShader(&vs);
2095 pipelineobj.AddShader(&ps);
2096
Tony Barbour01999182015-04-09 12:58:51 -06002097 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002098 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002099
Tony Barbourdd4c9642015-01-09 12:55:14 -07002100 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002101 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002102 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2103
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002104 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002105
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002106 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002107
2108#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002109 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002110 pDSDumpDot((char*)"triTest2.dot");
2111#endif
2112 // render triangle
2113 cmdBuffer.Draw(0, 3, 0, 1);
2114
2115 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002116 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002117 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002118
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002119 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002120}
Tony Barbour01999182015-04-09 12:58:51 -06002121TEST_F(VkRenderTest, FSTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002122{
2123 // The expected result from this test is a red and green checkered triangle
2124 static const char *vertShaderText =
2125 "#version 140\n"
2126 "#extension GL_ARB_separate_shader_objects : enable\n"
2127 "#extension GL_ARB_shading_language_420pack : enable\n"
2128 "layout (location = 0) out vec2 samplePos;\n"
2129 "void main() {\n"
2130 " vec2 vertices[3];"
2131 " vertices[0] = vec2(-0.5, -0.5);\n"
2132 " vertices[1] = vec2( 0.5, -0.5);\n"
2133 " vertices[2] = vec2( 0.5, 0.5);\n"
2134 " vec2 positions[3];"
2135 " positions[0] = vec2( 0.0, 0.0);\n"
2136 " positions[1] = vec2( 1.0, 0.0);\n"
2137 " positions[2] = vec2( 1.0, 1.0);\n"
2138 " samplePos = positions[gl_VertexID % 3];\n"
2139 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2140 "}\n";
2141
2142 static const char *fragShaderText =
2143 "#version 140\n"
2144 "#extension GL_ARB_separate_shader_objects : enable\n"
2145 "#extension GL_ARB_shading_language_420pack : enable\n"
2146 "layout (location = 0) in vec2 samplePos;\n"
2147 "layout (binding = 0) uniform sampler2D surface;\n"
2148 "layout (location=0) out vec4 outColor;\n"
2149 "void main() {\n"
2150 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2151 " outColor = texColor;\n"
2152 "}\n";
2153
2154 ASSERT_NO_FATAL_FAILURE(InitState());
2155 ASSERT_NO_FATAL_FAILURE(InitViewport());
2156
Tony Barbour01999182015-04-09 12:58:51 -06002157 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2158 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2159 VkSamplerObj sampler(m_device);
2160 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002161
Tony Barbour01999182015-04-09 12:58:51 -06002162 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002163 pipelineobj.AddShader(&vs);
2164 pipelineobj.AddShader(&ps);
2165
Tony Barbour01999182015-04-09 12:58:51 -06002166 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002167 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002168
Tony Barbourdd4c9642015-01-09 12:55:14 -07002169 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002170 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002171 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2172
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002173 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002174
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002175 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002176
2177#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002178 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002179 pDSDumpDot((char*)"triTest2.dot");
2180#endif
2181 // render triangle
2182 cmdBuffer.Draw(0, 3, 0, 1);
2183
2184 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002185 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002186 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002187
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002188 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002189}
Tony Barbour01999182015-04-09 12:58:51 -06002190TEST_F(VkRenderTest, SamplerBindingsTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002191{
2192 // This test sets bindings on the samplers
2193 // For now we are asserting that sampler and texture pairs
2194 // march in lock step, and are set via GLSL binding. This can
2195 // and will probably change.
2196 // The sampler bindings should match the sampler and texture slot
2197 // number set up by the application.
2198 // This test will result in a blue triangle
2199 static const char *vertShaderText =
2200 "#version 140\n"
2201 "#extension GL_ARB_separate_shader_objects : enable\n"
2202 "#extension GL_ARB_shading_language_420pack : enable\n"
2203 "layout (location = 0) out vec4 samplePos;\n"
2204 "void main() {\n"
2205 " vec2 vertices[3];"
2206 " vertices[0] = vec2(-0.5, -0.5);\n"
2207 " vertices[1] = vec2( 0.5, -0.5);\n"
2208 " vertices[2] = vec2( 0.5, 0.5);\n"
2209 " vec2 positions[3];"
2210 " positions[0] = vec2( 0.0, 0.0);\n"
2211 " positions[1] = vec2( 1.0, 0.0);\n"
2212 " positions[2] = vec2( 1.0, 1.0);\n"
2213 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2214 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2215 "}\n";
2216
2217 static const char *fragShaderText =
2218 "#version 140\n"
2219 "#extension GL_ARB_separate_shader_objects : enable\n"
2220 "#extension GL_ARB_shading_language_420pack : enable\n"
2221 "layout (location = 0) in vec4 samplePos;\n"
2222 "layout (binding = 0) uniform sampler2D surface0;\n"
2223 "layout (binding = 1) uniform sampler2D surface1;\n"
2224 "layout (binding = 12) uniform sampler2D surface2;\n"
2225 "void main() {\n"
2226 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
2227 "}\n";
2228
2229 ASSERT_NO_FATAL_FAILURE(InitState());
2230 ASSERT_NO_FATAL_FAILURE(InitViewport());
2231
Tony Barbour01999182015-04-09 12:58:51 -06002232 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2233 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002234
Tony Barbour01999182015-04-09 12:58:51 -06002235 VkSamplerObj sampler1(m_device);
2236 VkSamplerObj sampler2(m_device);
2237 VkSamplerObj sampler3(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002238
Tony Barbour2f421a02015-04-01 16:38:10 -06002239 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
Tony Barbour01999182015-04-09 12:58:51 -06002240 VkTextureObj texture1(m_device, tex_colors); // Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002241 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
Tony Barbour01999182015-04-09 12:58:51 -06002242 VkTextureObj texture2(m_device, tex_colors); // Green
Tony Barbour2f421a02015-04-01 16:38:10 -06002243 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
Tony Barbour01999182015-04-09 12:58:51 -06002244 VkTextureObj texture3(m_device, tex_colors); // Blue
Tony Barbourf43b6982014-11-25 13:18:32 -07002245
Tony Barbour01999182015-04-09 12:58:51 -06002246 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002247 pipelineobj.AddShader(&vs);
2248 pipelineobj.AddShader(&ps);
2249
Tony Barbour01999182015-04-09 12:58:51 -06002250 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002251 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2252 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2253 for (int i = 0; i < 10; i++)
2254 descriptorSet.AppendDummy();
2255 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002256
Tony Barbourdd4c9642015-01-09 12:55:14 -07002257 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002258 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002259 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2260
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002261 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002262
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002263 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002264
2265#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002266 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002267 pDSDumpDot((char*)"triTest2.dot");
2268#endif
2269 // render triangle
2270 cmdBuffer.Draw(0, 3, 0, 1);
2271
2272 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002273 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002274 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002275
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002276 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002277}
2278
Tony Barbour01999182015-04-09 12:58:51 -06002279TEST_F(VkRenderTest, TriangleVSUniformBlock)
Tony Barbourf43b6982014-11-25 13:18:32 -07002280{
2281 // The expected result from this test is a blue triangle
2282
2283 static const char *vertShaderText =
2284 "#version 140\n"
2285 "#extension GL_ARB_separate_shader_objects : enable\n"
2286 "#extension GL_ARB_shading_language_420pack : enable\n"
2287 "layout (location = 0) out vec4 outColor;\n"
2288 "layout (std140, binding = 0) uniform bufferVals {\n"
2289 " vec4 red;\n"
2290 " vec4 green;\n"
2291 " vec4 blue;\n"
2292 " vec4 white;\n"
2293 "} myBufferVals;\n"
2294 "void main() {\n"
2295 " vec2 vertices[3];"
2296 " vertices[0] = vec2(-0.5, -0.5);\n"
2297 " vertices[1] = vec2( 0.5, -0.5);\n"
2298 " vertices[2] = vec2( 0.5, 0.5);\n"
2299 " outColor = myBufferVals.blue;\n"
2300 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2301 "}\n";
2302
2303 static const char *fragShaderText =
2304 "#version 140\n"
2305 "#extension GL_ARB_separate_shader_objects : enable\n"
2306 "#extension GL_ARB_shading_language_420pack : enable\n"
2307 "layout (location = 0) in vec4 inColor;\n"
2308 "void main() {\n"
2309 " gl_FragColor = inColor;\n"
2310 "}\n";
2311
2312 ASSERT_NO_FATAL_FAILURE(InitState());
2313 ASSERT_NO_FATAL_FAILURE(InitViewport());
2314
Tony Barbour01999182015-04-09 12:58:51 -06002315 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2316 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002317
2318 // Let's populate our buffer with the following:
2319 // vec4 red;
2320 // vec4 green;
2321 // vec4 blue;
2322 // vec4 white;
2323 const int valCount = 4 * 4;
2324 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2325 0.0, 1.0, 0.0, 1.0,
2326 0.0, 0.0, 1.0, 1.0,
2327 1.0, 1.0, 1.0, 1.0 };
2328
Tony Barbour01999182015-04-09 12:58:51 -06002329 VkConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002330
Tony Barbour01999182015-04-09 12:58:51 -06002331 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002332 pipelineobj.AddShader(&vs);
2333 pipelineobj.AddShader(&ps);
2334
Tony Barbour01999182015-04-09 12:58:51 -06002335 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002336 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002337
Tony Barbourdd4c9642015-01-09 12:55:14 -07002338 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002339 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002340 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2341
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002342 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002343
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002344 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002345
2346#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002347 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002348 pDSDumpDot((char*)"triTest2.dot");
2349#endif
2350 // render triangle
2351 cmdBuffer.Draw(0, 3, 0, 1);
2352
2353 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002354 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002355 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002356
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002357 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002358}
2359
Tony Barbour01999182015-04-09 12:58:51 -06002360TEST_F(VkRenderTest, TriangleFSUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002361{
2362 // This test allows the shader to select which buffer it is
2363 // pulling from using layout binding qualifier.
2364 // There are corresponding changes in the compiler stack that
2365 // will select the buffer using binding directly.
2366 // The binding number should match the slot number set up by
2367 // the application.
2368 // The expected result from this test is a purple triangle
2369
2370 static const char *vertShaderText =
2371 "#version 140\n"
2372 "#extension GL_ARB_separate_shader_objects : enable\n"
2373 "#extension GL_ARB_shading_language_420pack : enable\n"
2374 "void main() {\n"
2375 " vec2 vertices[3];"
2376 " vertices[0] = vec2(-0.5, -0.5);\n"
2377 " vertices[1] = vec2( 0.5, -0.5);\n"
2378 " vertices[2] = vec2( 0.5, 0.5);\n"
2379 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2380 "}\n";
2381
2382 static const char *fragShaderText =
2383 "#version 140\n"
2384 "#extension GL_ARB_separate_shader_objects : enable\n"
2385 "#extension GL_ARB_shading_language_420pack : enable\n"
2386 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2387 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2388 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002389 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
Tony Barbourf43b6982014-11-25 13:18:32 -07002390 "void main() {\n"
2391 " gl_FragColor = myBlueVal.color;\n"
2392 " gl_FragColor += myRedVal.color;\n"
2393 "}\n";
2394
2395 ASSERT_NO_FATAL_FAILURE(InitState());
2396 ASSERT_NO_FATAL_FAILURE(InitViewport());
2397
Tony Barbour01999182015-04-09 12:58:51 -06002398 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2399 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002400
2401 // We're going to create a number of uniform buffers, and then allow
2402 // the shader to select which it wants to read from with a binding
2403
2404 // Let's populate the buffers with a single color each:
2405 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2406 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2407 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002408 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002409
2410 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2411 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2412 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2413 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2414
2415 const int redCount = sizeof(redVals) / sizeof(float);
2416 const int greenCount = sizeof(greenVals) / sizeof(float);
2417 const int blueCount = sizeof(blueVals) / sizeof(float);
2418 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2419
Tony Barbour01999182015-04-09 12:58:51 -06002420 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002421
Tony Barbour01999182015-04-09 12:58:51 -06002422 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002423
Tony Barbour01999182015-04-09 12:58:51 -06002424 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002425
Tony Barbour01999182015-04-09 12:58:51 -06002426 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002427
Tony Barbour01999182015-04-09 12:58:51 -06002428 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002429 pipelineobj.AddShader(&vs);
2430 pipelineobj.AddShader(&ps);
2431
Tony Barbour01999182015-04-09 12:58:51 -06002432 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002433 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2434 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2435 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2436 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002437
Tony Barbourdd4c9642015-01-09 12:55:14 -07002438 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002439 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002440 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002441
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002442 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002443
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002444 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002445
2446#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002447 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002448 pDSDumpDot((char*)"triTest2.dot");
2449#endif
2450 // render triangle
2451 cmdBuffer.Draw(0, 3, 0, 1);
2452
2453 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002454 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002455 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002456
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002457 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002458}
2459
Tony Barbour01999182015-04-09 12:58:51 -06002460TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002461{
2462 // This test is the same as TriangleFSUniformBlockBinding, but
2463 // it does not provide an instance name.
2464 // The expected result from this test is a purple triangle
2465
2466 static const char *vertShaderText =
2467 "#version 140\n"
2468 "#extension GL_ARB_separate_shader_objects : enable\n"
2469 "#extension GL_ARB_shading_language_420pack : enable\n"
2470 "void main() {\n"
2471 " vec2 vertices[3];"
2472 " vertices[0] = vec2(-0.5, -0.5);\n"
2473 " vertices[1] = vec2( 0.5, -0.5);\n"
2474 " vertices[2] = vec2( 0.5, 0.5);\n"
2475 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2476 "}\n";
2477
2478 static const char *fragShaderText =
2479 "#version 430\n"
2480 "#extension GL_ARB_separate_shader_objects : enable\n"
2481 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002482 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2483 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2484 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002485 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002486 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002487 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002488 " outColor = blue;\n"
2489 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002490 "}\n";
2491 ASSERT_NO_FATAL_FAILURE(InitState());
2492 ASSERT_NO_FATAL_FAILURE(InitViewport());
2493
Tony Barbour01999182015-04-09 12:58:51 -06002494 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2495 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002496
2497 // We're going to create a number of uniform buffers, and then allow
2498 // the shader to select which it wants to read from with a binding
2499
2500 // Let's populate the buffers with a single color each:
2501 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2502 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2503 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2504 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2505
2506 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2507 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2508 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2509 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2510
2511 const int redCount = sizeof(redVals) / sizeof(float);
2512 const int greenCount = sizeof(greenVals) / sizeof(float);
2513 const int blueCount = sizeof(blueVals) / sizeof(float);
2514 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2515
Tony Barbour01999182015-04-09 12:58:51 -06002516 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002517
Tony Barbour01999182015-04-09 12:58:51 -06002518 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002519
Tony Barbour01999182015-04-09 12:58:51 -06002520 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002521
Tony Barbour01999182015-04-09 12:58:51 -06002522 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002523
Tony Barbour01999182015-04-09 12:58:51 -06002524 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002525 pipelineobj.AddShader(&vs);
2526 pipelineobj.AddShader(&ps);
2527
Tony Barbour01999182015-04-09 12:58:51 -06002528 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002529 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2530 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2531 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2532 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002533
Tony Barbourdd4c9642015-01-09 12:55:14 -07002534 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002535 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002536 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2537
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002538 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002539
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002540 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002541
2542#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002543 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002544 pDSDumpDot((char*)"triTest2.dot");
2545#endif
2546 // render triangle
2547 cmdBuffer.Draw(0, 3, 0, 1);
2548
2549 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002550 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002551 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002552
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002553 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002554}
2555
Tony Barbour01999182015-04-09 12:58:51 -06002556TEST_F(VkRenderTest, CubeWithVertexFetchAndMVPAndTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07002557{
2558 static const char *vertShaderText =
2559 "#version 140\n"
2560 "#extension GL_ARB_separate_shader_objects : enable\n"
2561 "#extension GL_ARB_shading_language_420pack : enable\n"
2562 "layout (std140, binding=0) uniform bufferVals {\n"
2563 " mat4 mvp;\n"
2564 "} myBufferVals;\n"
2565 "layout (location=0) in vec4 pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002566 "layout (location=1) in vec2 input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002567 "layout (location=0) out vec2 UV;\n"
2568 "void main() {\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002569 " UV = input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002570 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002571 " gl_Position.y = -gl_Position.y;\n"
2572 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002573 "}\n";
2574
2575 static const char *fragShaderText =
2576 "#version 140\n"
2577 "#extension GL_ARB_separate_shader_objects : enable\n"
2578 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002579 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002580 "layout (location=0) out vec4 outColor;\n"
2581 "layout (location=0) in vec2 UV;\n"
2582 "void main() {\n"
2583 " outColor= textureLod(surface, UV, 0.0);\n"
2584 "}\n";
2585 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2586
2587 glm::mat4 View = glm::lookAt(
2588 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2589 glm::vec3(0,0,0), // and looks at the origin
2590 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2591 );
2592
2593 glm::mat4 Model = glm::mat4(1.0f);
2594
2595 glm::mat4 MVP = Projection * View * Model;
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002596 int num_verts = sizeof(g_vb_texture_Data) / sizeof(g_vb_texture_Data[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002597
2598
2599 ASSERT_NO_FATAL_FAILURE(InitState());
2600 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour8bef8ee2015-05-22 09:44:58 -06002601 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07002602
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002603 VkConstantBufferObj meshBuffer(m_device, num_verts,
2604 sizeof(g_vb_texture_Data[0]), g_vb_texture_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002605 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002606
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002607 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07002608
Tony Barbour01999182015-04-09 12:58:51 -06002609 VkConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2610 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2611 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2612 VkSamplerObj sampler(m_device);
2613 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002614
Tony Barbour01999182015-04-09 12:58:51 -06002615 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002616 pipelineobj.AddShader(&vs);
2617 pipelineobj.AddShader(&ps);
2618
Tony Barbour01999182015-04-09 12:58:51 -06002619 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002620 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mvpBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002621 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002622
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002623#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002624 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002625 MESH_BIND_ID, // binding ID
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002626 sizeof(g_vb_texture_Data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002627 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002628 };
Tony Barbourf43b6982014-11-25 13:18:32 -07002629
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002630 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002631 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2632 vi_attribs[0].location = 0; // location
Tony Barbour8205d902015-04-16 15:59:00 -06002633 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002634 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2635 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2636 vi_attribs[1].location = 1; // location
2637 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
2638 vi_attribs[1].offsetInBytes = 16; // Offset of uv components
Tony Barbourf43b6982014-11-25 13:18:32 -07002639
Tony Barbourf43b6982014-11-25 13:18:32 -07002640 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002641 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2642 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07002643
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002644 VkPipelineDsStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002645 ds_state.depthTestEnable = VK_TRUE;
2646 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06002647 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002648 ds_state.depthBoundsEnable = VK_FALSE;
2649 ds_state.stencilTestEnable = VK_FALSE;
2650 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
2651 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
2652 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06002653 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
2654 ds_state.format = VK_FORMAT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002655 ds_state.front = ds_state.back;
2656 pipelineobj.SetDepthStencil(&ds_state);
2657
Tony Barbour17c6ab12015-03-27 17:03:18 -06002658 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour01999182015-04-09 12:58:51 -06002659 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002660 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002661
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002662 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002663
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002664 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002665
2666 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2667#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002668 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002669 pDSDumpDot((char*)"triTest2.dot");
2670#endif
2671 // render triangle
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002672 cmdBuffer.Draw(0, num_verts, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002673
2674 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002675 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002676 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002677
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002678 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002679 RotateTriangleVSUniform(Projection, View, Model, &mvpBuffer, &cmdBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002680}
Cody Northropd1ce7842014-12-09 11:17:01 -07002681
Tony Barbour01999182015-04-09 12:58:51 -06002682TEST_F(VkRenderTest, TriangleMixedSamplerUniformBlockBinding)
Cody Northropd1ce7842014-12-09 11:17:01 -07002683{
2684 // This test mixes binding slots of textures and buffers, ensuring
2685 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002686 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002687 // you can modify it to move the desired result around.
2688
2689 static const char *vertShaderText =
2690 "#version 140\n"
2691 "#extension GL_ARB_separate_shader_objects : enable\n"
2692 "#extension GL_ARB_shading_language_420pack : enable\n"
2693 "void main() {\n"
2694 " vec2 vertices[3];"
2695 " vertices[0] = vec2(-0.5, -0.5);\n"
2696 " vertices[1] = vec2( 0.5, -0.5);\n"
2697 " vertices[2] = vec2( 0.5, 0.5);\n"
2698 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2699 "}\n";
2700
2701 static const char *fragShaderText =
2702 "#version 430\n"
2703 "#extension GL_ARB_separate_shader_objects : enable\n"
2704 "#extension GL_ARB_shading_language_420pack : enable\n"
2705 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002706 "layout (binding = 3) uniform sampler2D surface1;\n"
2707 "layout (binding = 1) uniform sampler2D surface2;\n"
2708 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002709
Cody Northropa0410942014-12-09 13:59:39 -07002710
Chia-I Wuf8385062015-01-04 16:27:24 +08002711 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2712 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2713 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2714 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002715 "layout (location = 0) out vec4 outColor;\n"
2716 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002717 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002718 " outColor += white * vec4(0.00001);\n"
2719 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002720 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002721 "}\n";
2722 ASSERT_NO_FATAL_FAILURE(InitState());
2723 ASSERT_NO_FATAL_FAILURE(InitViewport());
2724
Tony Barbour01999182015-04-09 12:58:51 -06002725 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2726 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northropd1ce7842014-12-09 11:17:01 -07002727
Cody Northropd1ce7842014-12-09 11:17:01 -07002728 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2729 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2730 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2731 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2732
2733 const int redCount = sizeof(redVals) / sizeof(float);
2734 const int greenCount = sizeof(greenVals) / sizeof(float);
2735 const int blueCount = sizeof(blueVals) / sizeof(float);
2736 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2737
Tony Barbour01999182015-04-09 12:58:51 -06002738 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2739 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2740 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2741 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002742
Tony Barbour2f421a02015-04-01 16:38:10 -06002743 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002744 VkSamplerObj sampler0(m_device);
2745 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002746 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002747 VkSamplerObj sampler2(m_device);
2748 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002749 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002750 VkSamplerObj sampler4(m_device);
2751 VkTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropa0410942014-12-09 13:59:39 -07002752
2753 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2754 // TODO: Get back here ASAP and understand why.
Tony Barbour2f421a02015-04-01 16:38:10 -06002755 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06002756 VkSamplerObj sampler7(m_device);
2757 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropd1ce7842014-12-09 11:17:01 -07002758
Tony Barbour01999182015-04-09 12:58:51 -06002759 VkPipelineObj pipelineobj(m_device);
Cody Northropd1ce7842014-12-09 11:17:01 -07002760 pipelineobj.AddShader(&vs);
2761 pipelineobj.AddShader(&ps);
2762
Tony Barbour01999182015-04-09 12:58:51 -06002763 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002764 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2765 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2766 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2767 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002768 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002769 // swap blue and green
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002770 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2771 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2772 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002773
Tony Barbourdd4c9642015-01-09 12:55:14 -07002774 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002775 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002776 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002777
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002778 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002779
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002780 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002781
2782#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002783 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002784 pDSDumpDot((char*)"triTest2.dot");
2785#endif
2786 // render triangle
2787 cmdBuffer.Draw(0, 3, 0, 1);
2788
2789 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002790 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002791 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002792
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002793 RecordImages(m_renderTargets);
Cody Northropd1ce7842014-12-09 11:17:01 -07002794}
2795
Tony Barbour01999182015-04-09 12:58:51 -06002796TEST_F(VkRenderTest, TriangleMatchingSamplerUniformBlockBinding)
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002797{
2798 // This test matches binding slots of textures and buffers, requiring
2799 // the driver to give them distinct number spaces.
2800 // The expected result from this test is a red triangle, although
2801 // you can modify it to move the desired result around.
2802
2803 static const char *vertShaderText =
2804 "#version 140\n"
2805 "#extension GL_ARB_separate_shader_objects : enable\n"
2806 "#extension GL_ARB_shading_language_420pack : enable\n"
2807 "void main() {\n"
2808 " vec2 vertices[3];"
2809 " vertices[0] = vec2(-0.5, -0.5);\n"
2810 " vertices[1] = vec2( 0.5, -0.5);\n"
2811 " vertices[2] = vec2( 0.5, 0.5);\n"
2812 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2813 "}\n";
2814
2815 static const char *fragShaderText =
2816 "#version 430\n"
2817 "#extension GL_ARB_separate_shader_objects : enable\n"
2818 "#extension GL_ARB_shading_language_420pack : enable\n"
2819 "layout (binding = 0) uniform sampler2D surface0;\n"
2820 "layout (binding = 1) uniform sampler2D surface1;\n"
2821 "layout (binding = 2) uniform sampler2D surface2;\n"
2822 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002823 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2824 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2825 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2826 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002827 "layout (location = 0) out vec4 outColor;\n"
2828 "void main() {\n"
2829 " outColor = red;// * vec4(0.00001);\n"
2830 " outColor += white * vec4(0.00001);\n"
2831 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2832 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2833 "}\n";
2834 ASSERT_NO_FATAL_FAILURE(InitState());
2835 ASSERT_NO_FATAL_FAILURE(InitViewport());
2836
Tony Barbour01999182015-04-09 12:58:51 -06002837 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2838 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002839
2840 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2841 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2842 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2843 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2844
2845 const int redCount = sizeof(redVals) / sizeof(float);
2846 const int greenCount = sizeof(greenVals) / sizeof(float);
2847 const int blueCount = sizeof(blueVals) / sizeof(float);
2848 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2849
Tony Barbour01999182015-04-09 12:58:51 -06002850 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2851 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2852 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2853 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002854
Tony Barbour2f421a02015-04-01 16:38:10 -06002855 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002856 VkSamplerObj sampler0(m_device);
2857 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002858 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002859 VkSamplerObj sampler2(m_device);
2860 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002861 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002862 VkSamplerObj sampler4(m_device);
2863 VkTextureObj texture4(m_device, tex_colors); // Light Green
Tony Barbour2f421a02015-04-01 16:38:10 -06002864 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06002865 VkSamplerObj sampler7(m_device);
2866 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002867
Tony Barbour01999182015-04-09 12:58:51 -06002868 VkPipelineObj pipelineobj(m_device);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002869 pipelineobj.AddShader(&vs);
2870 pipelineobj.AddShader(&ps);
2871
Tony Barbour01999182015-04-09 12:58:51 -06002872 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002873 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2874 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2875 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2876 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002877 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2878 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2879 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2880 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002881
Tony Barbourdd4c9642015-01-09 12:55:14 -07002882 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002883 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002884 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002885
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002886 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002887
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002888 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002889
2890#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002891 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002892 pDSDumpDot((char*)"triTest2.dot");
2893#endif
2894 // render triangle
2895 cmdBuffer.Draw(0, 3, 0, 1);
2896
2897 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002898 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002899 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002900
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002901 RecordImages(m_renderTargets);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002902}
2903
Tony Barbour01999182015-04-09 12:58:51 -06002904TEST_F(VkRenderTest, TriangleUniformBufferLayout)
Cody Northrop02690bd2014-12-17 15:26:33 -07002905{
2906 // This test populates a buffer with a variety of different data
2907 // types, then reads them out with a shader.
2908 // The expected result from this test is a green triangle
2909
2910 static const char *vertShaderText =
2911 "#version 140\n"
2912 "#extension GL_ARB_separate_shader_objects : enable\n"
2913 "#extension GL_ARB_shading_language_420pack : enable\n"
2914 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2915 " vec4 fRed;\n"
2916 " vec4 fGreen;\n"
2917 " layout(row_major) mat4 worldToProj;\n"
2918 " layout(row_major) mat4 projToWorld;\n"
2919 " layout(row_major) mat4 worldToView;\n"
2920 " layout(row_major) mat4 viewToProj;\n"
2921 " layout(row_major) mat4 worldToShadow[4];\n"
2922 " float fZero;\n"
2923 " float fOne;\n"
2924 " float fTwo;\n"
2925 " float fThree;\n"
2926 " vec3 fZeroZeroZero;\n"
2927 " float fFour;\n"
2928 " vec3 fZeroZeroOne;\n"
2929 " float fFive;\n"
2930 " vec3 fZeroOneZero;\n"
2931 " float fSix;\n"
2932 " float fSeven;\n"
2933 " float fEight;\n"
2934 " float fNine;\n"
2935 " vec2 fZeroZero;\n"
2936 " vec2 fZeroOne;\n"
2937 " vec4 fBlue;\n"
2938 " vec2 fOneZero;\n"
2939 " vec2 fOneOne;\n"
2940 " vec3 fZeroOneOne;\n"
2941 " float fTen;\n"
2942 " float fEleven;\n"
2943 " float fTwelve;\n"
2944 " vec3 fOneZeroZero;\n"
2945 " vec4 uvOffsets[4];\n"
2946 "};\n"
2947 "layout (location = 0) out vec4 color;"
2948 "void main() {\n"
2949
2950 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2951 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2952 " \n"
2953
2954 // do some exact comparisons, even though we should
2955 // really have an epsilon involved.
2956 " vec4 outColor = right;\n"
2957 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
2958 " outColor = wrong;\n"
2959 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
2960 " outColor = wrong;\n"
2961 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
2962 " outColor = wrong;\n"
2963
2964 " color = outColor;\n"
2965
2966 // generic position stuff
2967 " vec2 vertices;\n"
2968 " int vertexSelector = gl_VertexID;\n"
2969 " if (vertexSelector == 0)\n"
2970 " vertices = vec2(-0.5, -0.5);\n"
2971 " else if (vertexSelector == 1)\n"
2972 " vertices = vec2( 0.5, -0.5);\n"
2973 " else if (vertexSelector == 2)\n"
2974 " vertices = vec2( 0.5, 0.5);\n"
2975 " else\n"
2976 " vertices = vec2( 0.0, 0.0);\n"
2977 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
2978 "}\n";
2979
2980 static const char *fragShaderText =
2981 "#version 140\n"
2982 "#extension GL_ARB_separate_shader_objects : enable\n"
2983 "#extension GL_ARB_shading_language_420pack : enable\n"
2984 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2985 " vec4 fRed;\n"
2986 " vec4 fGreen;\n"
2987 " layout(row_major) mat4 worldToProj;\n"
2988 " layout(row_major) mat4 projToWorld;\n"
2989 " layout(row_major) mat4 worldToView;\n"
2990 " layout(row_major) mat4 viewToProj;\n"
2991 " layout(row_major) mat4 worldToShadow[4];\n"
2992 " float fZero;\n"
2993 " float fOne;\n"
2994 " float fTwo;\n"
2995 " float fThree;\n"
2996 " vec3 fZeroZeroZero;\n"
2997 " float fFour;\n"
2998 " vec3 fZeroZeroOne;\n"
2999 " float fFive;\n"
3000 " vec3 fZeroOneZero;\n"
3001 " float fSix;\n"
3002 " float fSeven;\n"
3003 " float fEight;\n"
3004 " float fNine;\n"
3005 " vec2 fZeroZero;\n"
3006 " vec2 fZeroOne;\n"
3007 " vec4 fBlue;\n"
3008 " vec2 fOneZero;\n"
3009 " vec2 fOneOne;\n"
3010 " vec3 fZeroOneOne;\n"
3011 " float fTen;\n"
3012 " float fEleven;\n"
3013 " float fTwelve;\n"
3014 " vec3 fOneZeroZero;\n"
3015 " vec4 uvOffsets[4];\n"
3016 "};\n"
3017 "layout (location = 0) in vec4 color;\n"
3018 "void main() {\n"
3019 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3020 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3021 " \n"
3022
3023 // start with VS value to ensure it passed
3024 " vec4 outColor = color;\n"
3025
3026 // do some exact comparisons, even though we should
3027 // really have an epsilon involved.
3028 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3029 " outColor = wrong;\n"
3030 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3031 " outColor = wrong;\n"
3032 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3033 " outColor = wrong;\n"
3034 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3035 " outColor = wrong;\n"
3036 " if (fTwo != 2.0)\n"
3037 " outColor = wrong;\n"
3038 " if (fOneOne != vec2(1.0, 1.0))\n"
3039 " outColor = wrong;\n"
3040 " if (fTen != 10.0)\n"
3041 " outColor = wrong;\n"
3042 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3043 " outColor = wrong;\n"
3044 " \n"
3045 " gl_FragColor = outColor;\n"
3046 "}\n";
3047
3048
3049 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3050 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3051 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3052 0.0, 1.0, 0.0, 1.0, // align
3053 0.0, 0.0, 1.0, 1.0, // align
3054 0.0, 0.0, 0.0, 1.0, // align
3055 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3056 0.0, 2.0, 0.0, 2.0, // align
3057 0.0, 0.0, 2.0, 2.0, // align
3058 0.0, 0.0, 0.0, 2.0, // align
3059 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3060 0.0, 3.0, 0.0, 3.0, // align
3061 0.0, 0.0, 3.0, 3.0, // align
3062 0.0, 0.0, 0.0, 3.0, // align
3063 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3064 0.0, 4.0, 0.0, 4.0, // align
3065 0.0, 0.0, 4.0, 4.0, // align
3066 0.0, 0.0, 0.0, 4.0, // align
3067 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3068 0.0, 5.0, 0.0, 5.0, // align
3069 0.0, 0.0, 5.0, 5.0, // align
3070 0.0, 0.0, 0.0, 5.0, // align
3071 6.0, 0.0, 0.0, 6.0, // align
3072 0.0, 6.0, 0.0, 6.0, // align
3073 0.0, 0.0, 6.0, 6.0, // align
3074 0.0, 0.0, 0.0, 6.0, // align
3075 7.0, 0.0, 0.0, 7.0, // align
3076 0.0, 7.0, 0.0, 7.0, // align
3077 0.0, 0.0, 7.0, 7.0, // align
3078 0.0, 0.0, 0.0, 7.0, // align
3079 8.0, 0.0, 0.0, 8.0, // align
3080 0.0, 8.0, 0.0, 8.0, // align
3081 0.0, 0.0, 8.0, 8.0, // align
3082 0.0, 0.0, 0.0, 8.0, // align
3083 0.0, // float fZero; // align
3084 1.0, // float fOne; // pack
3085 2.0, // float fTwo; // pack
3086 3.0, // float fThree; // pack
3087 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3088 4.0, // float fFour; // pack
3089 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3090 5.0, // float fFive; // pack
3091 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3092 6.0, // float fSix; // pack
3093 7.0, // float fSeven; // align
3094 8.0, // float fEight; // pack
3095 9.0, // float fNine; // pack
3096 0.0, // BUFFER
3097 0.0, 0.0, // vec2 fZeroZero; // align
3098 0.0, 1.0, // vec2 fZeroOne; // pack
3099 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3100 1.0, 0.0, // vec2 fOneZero; // align
3101 1.0, 1.0, // vec2 fOneOne; // pack
3102 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3103 10.0, // float fTen; // pack
3104 11.0, // float fEleven; // align
3105 12.0, // float fTwelve; // pack
3106 0.0, 0.0, // BUFFER
3107 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3108 0.0, // BUFFER
3109 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3110 0.5, 0.6, 0.7, 0.8, // align
3111 0.9, 1.0, 1.1, 1.2, // align
3112 1.3, 1.4, 1.5, 1.6, // align
3113 };
3114
3115 ASSERT_NO_FATAL_FAILURE(InitState());
3116 ASSERT_NO_FATAL_FAILURE(InitViewport());
3117
3118 const int constCount = sizeof(mixedVals) / sizeof(float);
3119
Tony Barbour01999182015-04-09 12:58:51 -06003120 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3121 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop02690bd2014-12-17 15:26:33 -07003122
Tony Barbour01999182015-04-09 12:58:51 -06003123 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003124
Tony Barbour01999182015-04-09 12:58:51 -06003125 VkPipelineObj pipelineobj(m_device);
Cody Northrop02690bd2014-12-17 15:26:33 -07003126 pipelineobj.AddShader(&vs);
3127 pipelineobj.AddShader(&ps);
3128
Tony Barbour01999182015-04-09 12:58:51 -06003129 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003130 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003131
3132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06003133 VkCommandBufferObj cmdBuffer(m_device);
Cody Northrop02690bd2014-12-17 15:26:33 -07003134 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3135
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003136 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Cody Northrop02690bd2014-12-17 15:26:33 -07003137
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003138 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Cody Northrop02690bd2014-12-17 15:26:33 -07003139
3140#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003141 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop02690bd2014-12-17 15:26:33 -07003142 pDSDumpDot((char*)"triTest2.dot");
3143#endif
3144 // render triangle
3145 cmdBuffer.Draw(0, 3, 0, 1);
3146
3147 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003148 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003149 cmdBuffer.QueueCommandBuffer();
Cody Northrop02690bd2014-12-17 15:26:33 -07003150
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003151 RecordImages(m_renderTargets);
Cody Northrop02690bd2014-12-17 15:26:33 -07003152}
3153
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003154TEST_F(VkRenderTest, TextureGather)
3155{
3156 // This test introduces textureGather and textureGatherOffset
3157 // Each call is compared against an expected inline color result
3158 // Green triangle means everything worked as expected
3159 // Red means something went wrong
3160
3161 // disable SPV until texture gather is turned on in LunarGLASS
3162 bool saved_use_spv = VkTestFramework::m_use_spv;
3163 VkTestFramework::m_use_spv = false;
3164
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);
3259
3260 // restore SPV setting
3261 VkTestFramework::m_use_spv = saved_use_spv;
3262}
3263
Cody Northropa44c2ff2015-04-15 11:19:06 -06003264TEST_F(VkRenderTest, GeometryShaderHelloWorld)
3265{
3266 // This test introduces a geometry shader that simply
3267 // changes the color of each vertex to red, green, blue
3268
3269 static const char *vertShaderText =
3270 "#version 140\n"
3271 "#extension GL_ARB_separate_shader_objects : enable\n"
3272 "#extension GL_ARB_shading_language_420pack : enable\n"
3273 "layout (location = 0) out vec4 color;"
3274 "void main() {\n"
3275
3276 // VS writes out red
3277 " color = vec4(1.0, 0.0, 0.0, 1.0);\n"
3278
3279 // generic position stuff
3280 " vec2 vertices;\n"
3281 " int vertexSelector = gl_VertexID;\n"
3282 " if (vertexSelector == 0)\n"
3283 " vertices = vec2(-0.5, -0.5);\n"
3284 " else if (vertexSelector == 1)\n"
3285 " vertices = vec2( 0.5, -0.5);\n"
3286 " else if (vertexSelector == 2)\n"
3287 " vertices = vec2( 0.5, 0.5);\n"
3288 " else\n"
3289 " vertices = vec2( 0.0, 0.0);\n"
3290 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3291
3292 "}\n";
3293
3294 static const char *geomShaderText =
3295 "#version 330\n"
3296 "#extension GL_ARB_separate_shader_objects : enable\n"
3297 "#extension GL_ARB_shading_language_420pack : enable\n"
3298 "layout( triangles ) in;\n"
3299 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3300 "layout( location = 0 ) in vec4 inColor[3];\n"
3301 "layout( location = 0 ) out vec4 outColor;\n"
3302 "void main()\n"
3303 "{\n"
3304
3305 // first vertex, pass through red
3306 " gl_Position = gl_in[0].gl_Position;\n"
3307 " outColor = inColor[0];\n"
3308 " EmitVertex();\n"
3309
3310 // second vertex, green
3311 " gl_Position = gl_in[1].gl_Position;\n"
3312 " outColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3313 " EmitVertex();\n"
3314
3315 // third vertex, blue
3316 " gl_Position = gl_in[2].gl_Position;\n"
3317 " outColor = vec4(0.0, 0.0, 1.0, 1.0);\n"
3318 " EmitVertex();\n"
3319
3320 // done
3321 " EndPrimitive();\n"
3322 "}\n";
3323
3324
3325 static const char *fragShaderText =
3326 "#version 140\n"
3327 "#extension GL_ARB_separate_shader_objects : enable\n"
3328 "#extension GL_ARB_shading_language_420pack : enable\n"
3329 "layout (location = 0) in vec4 color;\n"
3330 "void main() {\n"
3331 // pass through
3332 " gl_FragColor = color;\n"
3333 "}\n";
3334
3335
3336
3337 ASSERT_NO_FATAL_FAILURE(InitState());
3338 ASSERT_NO_FATAL_FAILURE(InitViewport());
3339
3340 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3341 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3342 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3343
3344 VkPipelineObj pipelineobj(m_device);
3345 pipelineobj.AddShader(&vs);
3346 pipelineobj.AddShader(&gs);
3347 pipelineobj.AddShader(&ps);
3348
3349 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3350 VkCommandBufferObj cmdBuffer(m_device);
3351 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3352
3353 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3354
3355 VkDescriptorSetObj descriptorSet(m_device);
3356
3357 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3358
3359 // render triangle
3360 cmdBuffer.Draw(0, 3, 0, 1);
3361
3362 // finalize recording of the command buffer
3363 EndCommandBuffer(cmdBuffer);
3364 cmdBuffer.QueueCommandBuffer();
3365
3366 RecordImages(m_renderTargets);
3367}
3368
3369TEST_F(VkRenderTest, GSUniformBufferLayout)
3370{
3371 // This test is just like TriangleUniformBufferLayout but adds
3372 // geometry as a stage that also does UBO lookups
3373 // The expected result from this test is a green triangle
3374
3375 static const char *vertShaderText =
3376 "#version 140\n"
3377 "#extension GL_ARB_separate_shader_objects : enable\n"
3378 "#extension GL_ARB_shading_language_420pack : enable\n"
3379 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3380 " vec4 fRed;\n"
3381 " vec4 fGreen;\n"
3382 " layout(row_major) mat4 worldToProj;\n"
3383 " layout(row_major) mat4 projToWorld;\n"
3384 " layout(row_major) mat4 worldToView;\n"
3385 " layout(row_major) mat4 viewToProj;\n"
3386 " layout(row_major) mat4 worldToShadow[4];\n"
3387 " float fZero;\n"
3388 " float fOne;\n"
3389 " float fTwo;\n"
3390 " float fThree;\n"
3391 " vec3 fZeroZeroZero;\n"
3392 " float fFour;\n"
3393 " vec3 fZeroZeroOne;\n"
3394 " float fFive;\n"
3395 " vec3 fZeroOneZero;\n"
3396 " float fSix;\n"
3397 " float fSeven;\n"
3398 " float fEight;\n"
3399 " float fNine;\n"
3400 " vec2 fZeroZero;\n"
3401 " vec2 fZeroOne;\n"
3402 " vec4 fBlue;\n"
3403 " vec2 fOneZero;\n"
3404 " vec2 fOneOne;\n"
3405 " vec3 fZeroOneOne;\n"
3406 " float fTen;\n"
3407 " float fEleven;\n"
3408 " float fTwelve;\n"
3409 " vec3 fOneZeroZero;\n"
3410 " vec4 uvOffsets[4];\n"
3411 "};\n"
3412 "layout (location = 0) out vec4 color;"
3413 "void main() {\n"
3414
3415 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3416 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3417 " \n"
3418
3419 // do some exact comparisons, even though we should
3420 // really have an epsilon involved.
3421 " vec4 outColor = right;\n"
3422 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3423 " outColor = wrong;\n"
3424 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3425 " outColor = wrong;\n"
3426 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3427 " outColor = wrong;\n"
3428
3429 " color = outColor;\n"
3430
3431 // generic position stuff
3432 " vec2 vertices;\n"
3433 " int vertexSelector = gl_VertexID;\n"
3434 " if (vertexSelector == 0)\n"
3435 " vertices = vec2(-0.5, -0.5);\n"
3436 " else if (vertexSelector == 1)\n"
3437 " vertices = vec2( 0.5, -0.5);\n"
3438 " else if (vertexSelector == 2)\n"
3439 " vertices = vec2( 0.5, 0.5);\n"
3440 " else\n"
3441 " vertices = vec2( 0.0, 0.0);\n"
3442 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3443 "}\n";
3444
3445 static const char *geomShaderText =
3446 "#version 330\n"
3447 "#extension GL_ARB_separate_shader_objects : enable\n"
3448 "#extension GL_ARB_shading_language_420pack : enable\n"
3449
3450 // GS layout stuff
3451 "layout( triangles ) in;\n"
3452 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3453
3454 // Between stage IO
3455 "layout( location = 0 ) in vec4 inColor[3];\n"
3456 "layout( location = 0 ) out vec4 color;\n"
3457
3458 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3459 " vec4 fRed;\n"
3460 " vec4 fGreen;\n"
3461 " layout(row_major) mat4 worldToProj;\n"
3462 " layout(row_major) mat4 projToWorld;\n"
3463 " layout(row_major) mat4 worldToView;\n"
3464 " layout(row_major) mat4 viewToProj;\n"
3465 " layout(row_major) mat4 worldToShadow[4];\n"
3466 " float fZero;\n"
3467 " float fOne;\n"
3468 " float fTwo;\n"
3469 " float fThree;\n"
3470 " vec3 fZeroZeroZero;\n"
3471 " float fFour;\n"
3472 " vec3 fZeroZeroOne;\n"
3473 " float fFive;\n"
3474 " vec3 fZeroOneZero;\n"
3475 " float fSix;\n"
3476 " float fSeven;\n"
3477 " float fEight;\n"
3478 " float fNine;\n"
3479 " vec2 fZeroZero;\n"
3480 " vec2 fZeroOne;\n"
3481 " vec4 fBlue;\n"
3482 " vec2 fOneZero;\n"
3483 " vec2 fOneOne;\n"
3484 " vec3 fZeroOneOne;\n"
3485 " float fTen;\n"
3486 " float fEleven;\n"
3487 " float fTwelve;\n"
3488 " vec3 fOneZeroZero;\n"
3489 " vec4 uvOffsets[4];\n"
3490 "};\n"
3491
3492 "void main()\n"
3493 "{\n"
3494
3495 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3496 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3497
3498 // Each vertex will validate it can read VS output
3499 // then check a few values from the UBO
3500
3501 // first vertex
3502 " vec4 outColor = inColor[0];\n"
3503
3504 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3505 " outColor = wrong;\n"
3506 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3507 " outColor = wrong;\n"
3508 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3509 " outColor = wrong;\n"
3510 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3511 " outColor = wrong;\n"
3512
3513 " gl_Position = gl_in[0].gl_Position;\n"
3514 " color = outColor;\n"
3515 " EmitVertex();\n"
3516
3517 // second vertex
3518 " outColor = inColor[1];\n"
3519
3520 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3521 " outColor = wrong;\n"
3522 " if (fSix != 6.0)\n"
3523 " outColor = wrong;\n"
3524 " if (fOneOne != vec2(1.0, 1.0))\n"
3525 " outColor = wrong;\n"
3526
3527 " gl_Position = gl_in[1].gl_Position;\n"
3528 " color = outColor;\n"
3529 " EmitVertex();\n"
3530
3531 // third vertex
3532 " outColor = inColor[2];\n"
3533
3534 " if (fSeven != 7.0)\n"
3535 " outColor = wrong;\n"
3536 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3537 " outColor = wrong;\n"
3538
3539 " gl_Position = gl_in[2].gl_Position;\n"
3540 " color = outColor;\n"
3541 " EmitVertex();\n"
3542
3543 // done
3544 " EndPrimitive();\n"
3545 "}\n";
3546
3547 static const char *fragShaderText =
3548 "#version 140\n"
3549 "#extension GL_ARB_separate_shader_objects : enable\n"
3550 "#extension GL_ARB_shading_language_420pack : enable\n"
3551 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3552 " vec4 fRed;\n"
3553 " vec4 fGreen;\n"
3554 " layout(row_major) mat4 worldToProj;\n"
3555 " layout(row_major) mat4 projToWorld;\n"
3556 " layout(row_major) mat4 worldToView;\n"
3557 " layout(row_major) mat4 viewToProj;\n"
3558 " layout(row_major) mat4 worldToShadow[4];\n"
3559 " float fZero;\n"
3560 " float fOne;\n"
3561 " float fTwo;\n"
3562 " float fThree;\n"
3563 " vec3 fZeroZeroZero;\n"
3564 " float fFour;\n"
3565 " vec3 fZeroZeroOne;\n"
3566 " float fFive;\n"
3567 " vec3 fZeroOneZero;\n"
3568 " float fSix;\n"
3569 " float fSeven;\n"
3570 " float fEight;\n"
3571 " float fNine;\n"
3572 " vec2 fZeroZero;\n"
3573 " vec2 fZeroOne;\n"
3574 " vec4 fBlue;\n"
3575 " vec2 fOneZero;\n"
3576 " vec2 fOneOne;\n"
3577 " vec3 fZeroOneOne;\n"
3578 " float fTen;\n"
3579 " float fEleven;\n"
3580 " float fTwelve;\n"
3581 " vec3 fOneZeroZero;\n"
3582 " vec4 uvOffsets[4];\n"
3583 "};\n"
3584 "layout (location = 0) in vec4 color;\n"
3585 "void main() {\n"
3586 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3587 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3588 " \n"
3589
3590 // start with GS value to ensure it passed
3591 " vec4 outColor = color;\n"
3592
3593 // do some exact comparisons, even though we should
3594 // really have an epsilon involved.
3595 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3596 " outColor = wrong;\n"
3597 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3598 " outColor = wrong;\n"
3599 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3600 " outColor = wrong;\n"
3601 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3602 " outColor = wrong;\n"
3603 " if (fTwo != 2.0)\n"
3604 " outColor = wrong;\n"
3605 " if (fOneOne != vec2(1.0, 1.0))\n"
3606 " outColor = wrong;\n"
3607 " if (fTen != 10.0)\n"
3608 " outColor = wrong;\n"
3609 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3610 " outColor = wrong;\n"
3611 " \n"
3612 " gl_FragColor = outColor;\n"
3613 "}\n";
3614
3615
3616 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3617 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3618 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3619 0.0, 1.0, 0.0, 1.0, // align
3620 0.0, 0.0, 1.0, 1.0, // align
3621 0.0, 0.0, 0.0, 1.0, // align
3622 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3623 0.0, 2.0, 0.0, 2.0, // align
3624 0.0, 0.0, 2.0, 2.0, // align
3625 0.0, 0.0, 0.0, 2.0, // align
3626 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3627 0.0, 3.0, 0.0, 3.0, // align
3628 0.0, 0.0, 3.0, 3.0, // align
3629 0.0, 0.0, 0.0, 3.0, // align
3630 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3631 0.0, 4.0, 0.0, 4.0, // align
3632 0.0, 0.0, 4.0, 4.0, // align
3633 0.0, 0.0, 0.0, 4.0, // align
3634 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3635 0.0, 5.0, 0.0, 5.0, // align
3636 0.0, 0.0, 5.0, 5.0, // align
3637 0.0, 0.0, 0.0, 5.0, // align
3638 6.0, 0.0, 0.0, 6.0, // align
3639 0.0, 6.0, 0.0, 6.0, // align
3640 0.0, 0.0, 6.0, 6.0, // align
3641 0.0, 0.0, 0.0, 6.0, // align
3642 7.0, 0.0, 0.0, 7.0, // align
3643 0.0, 7.0, 0.0, 7.0, // align
3644 0.0, 0.0, 7.0, 7.0, // align
3645 0.0, 0.0, 0.0, 7.0, // align
3646 8.0, 0.0, 0.0, 8.0, // align
3647 0.0, 8.0, 0.0, 8.0, // align
3648 0.0, 0.0, 8.0, 8.0, // align
3649 0.0, 0.0, 0.0, 8.0, // align
3650 0.0, // float fZero; // align
3651 1.0, // float fOne; // pack
3652 2.0, // float fTwo; // pack
3653 3.0, // float fThree; // pack
3654 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3655 4.0, // float fFour; // pack
3656 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3657 5.0, // float fFive; // pack
3658 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3659 6.0, // float fSix; // pack
3660 7.0, // float fSeven; // align
3661 8.0, // float fEight; // pack
3662 9.0, // float fNine; // pack
3663 0.0, // BUFFER
3664 0.0, 0.0, // vec2 fZeroZero; // align
3665 0.0, 1.0, // vec2 fZeroOne; // pack
3666 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3667 1.0, 0.0, // vec2 fOneZero; // align
3668 1.0, 1.0, // vec2 fOneOne; // pack
3669 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3670 10.0, // float fTen; // pack
3671 11.0, // float fEleven; // align
3672 12.0, // float fTwelve; // pack
3673 0.0, 0.0, // BUFFER
3674 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3675 0.0, // BUFFER
3676 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3677 0.5, 0.6, 0.7, 0.8, // align
3678 0.9, 1.0, 1.1, 1.2, // align
3679 1.3, 1.4, 1.5, 1.6, // align
3680 };
3681
3682
3683
3684 ASSERT_NO_FATAL_FAILURE(InitState());
3685 ASSERT_NO_FATAL_FAILURE(InitViewport());
3686
3687 const int constCount = sizeof(mixedVals) / sizeof(float);
3688
3689 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3690 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3691 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3692
3693 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
3694
3695 VkPipelineObj pipelineobj(m_device);
3696 pipelineobj.AddShader(&vs);
3697 pipelineobj.AddShader(&gs);
3698 pipelineobj.AddShader(&ps);
3699
3700 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3701 VkCommandBufferObj cmdBuffer(m_device);
3702 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3703
3704 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3705
3706 VkDescriptorSetObj descriptorSet(m_device);
3707 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
3708
3709 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3710
3711 // render triangle
3712 cmdBuffer.Draw(0, 3, 0, 1);
3713
3714 // finalize recording of the command buffer
3715 EndCommandBuffer(cmdBuffer);
3716 cmdBuffer.QueueCommandBuffer();
3717
3718 RecordImages(m_renderTargets);
3719}
3720
3721TEST_F(VkRenderTest, GSPositions)
3722{
3723 // This test adds more inputs from the vertex shader and perturbs positions
3724 // Expected result is white triangle with weird positions
3725
3726 static const char *vertShaderText =
3727 "#version 140\n"
3728 "#extension GL_ARB_separate_shader_objects : enable\n"
3729 "#extension GL_ARB_shading_language_420pack : enable\n"
3730
3731 "layout(location = 0) out vec3 out_a;\n"
3732 "layout(location = 1) out vec3 out_b;\n"
3733 "layout(location = 2) out vec3 out_c;\n"
3734
3735 "void main() {\n"
3736
3737 // write a solid color to each
3738 " out_a = vec3(1.0, 0.0, 0.0);\n"
3739 " out_b = vec3(0.0, 1.0, 0.0);\n"
3740 " out_c = vec3(0.0, 0.0, 1.0);\n"
3741
3742 // generic position stuff
3743 " vec2 vertices;\n"
3744 " int vertexSelector = gl_VertexID;\n"
3745 " if (vertexSelector == 0)\n"
3746 " vertices = vec2(-0.5, -0.5);\n"
3747 " else if (vertexSelector == 1)\n"
3748 " vertices = vec2( 0.5, -0.5);\n"
3749 " else if (vertexSelector == 2)\n"
3750 " vertices = vec2( 0.5, 0.5);\n"
3751 " else\n"
3752 " vertices = vec2( 0.0, 0.0);\n"
3753 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3754
3755 "}\n";
3756
3757 static const char *geomShaderText =
3758 "#version 330\n"
3759 "#extension GL_ARB_separate_shader_objects : enable\n"
3760 "#extension GL_ARB_shading_language_420pack : enable\n"
3761 "layout( triangles ) in;\n"
3762 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3763
3764 "layout(location = 0) in vec3 in_a[3];\n"
3765 "layout(location = 1) in vec3 in_b[3];\n"
3766 "layout(location = 2) in vec3 in_c[3];\n"
3767
3768 "layout(location = 0) out vec3 out_a;\n"
3769 "layout(location = 1) out vec3 out_b;\n"
3770 "layout(location = 2) out vec3 out_c;\n"
3771
3772 "void main()\n"
3773 "{\n"
3774
3775 " gl_Position = gl_in[0].gl_Position;\n"
3776 " gl_Position.xy *= vec2(0.75);\n"
3777 " out_a = in_a[0];\n"
3778 " out_b = in_b[0];\n"
3779 " out_c = in_c[0];\n"
3780 " EmitVertex();\n"
3781
3782 " gl_Position = gl_in[1].gl_Position;\n"
3783 " gl_Position.xy *= vec2(1.5);\n"
3784 " out_a = in_a[1];\n"
3785 " out_b = in_b[1];\n"
3786 " out_c = in_c[1];\n"
3787 " EmitVertex();\n"
3788
3789 " gl_Position = gl_in[2].gl_Position;\n"
3790 " gl_Position.xy *= vec2(-0.1);\n"
3791 " out_a = in_a[2];\n"
3792 " out_b = in_b[2];\n"
3793 " out_c = in_c[2];\n"
3794 " EmitVertex();\n"
3795
3796 " EndPrimitive();\n"
3797 "}\n";
3798
3799
3800 static const char *fragShaderText =
3801 "#version 140\n"
3802 "#extension GL_ARB_separate_shader_objects : enable\n"
3803 "#extension GL_ARB_shading_language_420pack : enable\n"
3804
3805 "layout(location = 0) in vec3 in_a;\n"
3806 "layout(location = 1) in vec3 in_b;\n"
3807 "layout(location = 2) in vec3 in_c;\n"
3808
3809 "void main() {\n"
3810 " gl_FragColor = vec4(in_a.x, in_b.y, in_c.z, 1.0);\n"
3811 "}\n";
3812
3813
3814
3815 ASSERT_NO_FATAL_FAILURE(InitState());
3816 ASSERT_NO_FATAL_FAILURE(InitViewport());
3817
3818 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3819 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3820 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3821
3822 VkPipelineObj pipelineobj(m_device);
3823 pipelineobj.AddShader(&vs);
3824 pipelineobj.AddShader(&gs);
3825 pipelineobj.AddShader(&ps);
3826
3827 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3828 VkCommandBufferObj cmdBuffer(m_device);
3829 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3830
3831 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3832
3833 VkDescriptorSetObj descriptorSet(m_device);
3834
3835 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3836
3837 // render triangle
3838 cmdBuffer.Draw(0, 3, 0, 1);
3839
3840 // finalize recording of the command buffer
3841 EndCommandBuffer(cmdBuffer);
3842 cmdBuffer.QueueCommandBuffer();
3843
3844 RecordImages(m_renderTargets);
3845}
3846
3847TEST_F(VkRenderTest, GSTriStrip)
3848{
3849 // This test emits multiple multiple triangles using a GS
3850 // Correct result is an multicolor circle
3851
3852 static const char *vertShaderText =
3853 "#version 140\n"
3854 "#extension GL_ARB_separate_shader_objects : enable\n"
3855 "#extension GL_ARB_shading_language_420pack : enable\n"
3856
3857 "void main() {\n"
3858
3859 // generic position stuff
3860 " vec2 vertices;\n"
3861 " int vertexSelector = gl_VertexID;\n"
3862 " if (vertexSelector == 0)\n"
3863 " vertices = vec2(-0.5, -0.5);\n"
3864 " else if (vertexSelector == 1)\n"
3865 " vertices = vec2( 0.5, -0.5);\n"
3866 " else if (vertexSelector == 2)\n"
3867 " vertices = vec2( 0.5, 0.5);\n"
3868 " else\n"
3869 " vertices = vec2( 0.0, 0.0);\n"
3870 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3871
3872 "}\n";
3873
3874 static const char *geomShaderText =
3875 "#version 330\n"
3876 "#extension GL_ARB_separate_shader_objects : enable\n"
3877 "#extension GL_ARB_shading_language_420pack : enable\n"
3878 "layout( triangles ) in;\n"
3879 "layout( triangle_strip, max_vertices = 18 ) out;\n"
3880
3881 "layout(location = 0) out vec4 outColor;\n"
3882
3883 "void main()\n"
3884 "{\n"
3885 // init with first position to get zw
3886 " gl_Position = gl_in[0].gl_Position;\n"
3887
3888 " vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3889 " vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
3890 " vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
3891 " vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
3892
3893 // different color per tri
3894 " vec4[6] colors = { red, white, \n"
3895 " yellow, white, \n"
3896 " blue, white }; \n"
3897
3898 // fan out the triangles
3899 " vec2[18] positions = { 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 " vec2(0.0, 0.0), vec2( 0.5, 0.0), vec2( 0.25, 0.5), \n"
3903 " vec2(0.0, 0.0), vec2( 0.25, 0.5), vec2(-0.25, 0.5), \n"
3904 " vec2(0.0, 0.0), vec2(-0.25, 0.5), vec2(-0.5, 0.0) }; \n"
3905
3906 // make a triangle list of 6
3907 " for (int i = 0; i < 6; ++i) { \n"
3908 " outColor = colors[i]; \n"
3909 " for (int j = 0; j < 3; ++j) { \n"
3910 " gl_Position.xy = positions[i * 3 + j]; \n"
3911 " EmitVertex(); \n"
3912 " } \n"
3913 " EndPrimitive();\n"
3914 " } \n"
3915
3916 "}\n";
3917
3918
3919 static const char *fragShaderText =
3920 "#version 150\n"
3921 "#extension GL_ARB_separate_shader_objects : enable\n"
3922 "#extension GL_ARB_shading_language_420pack : enable\n"
3923
3924
3925 "layout(binding = 0) uniform windowDimensions {\n"
3926 " vec4 dimensions;\n"
3927 "};\n"
3928
3929 "layout(location = 0) in vec4 inColor;\n"
3930 "layout(origin_upper_left) in vec4 gl_FragCoord;\n"
3931
3932 "void main() {\n"
3933
3934 // discard to make a nice circle
3935 " vec2 pos = abs(gl_FragCoord.xy) - vec2(dimensions.x, dimensions.y) / 2;\n"
3936 " float dist = sqrt(dot(pos, pos));\n"
3937 " if (dist > 50.0)\n"
3938 " discard;\n"
3939
3940 " gl_FragColor = inColor;\n"
3941
3942 "}\n";
3943
3944
3945
3946 ASSERT_NO_FATAL_FAILURE(InitState());
3947 ASSERT_NO_FATAL_FAILURE(InitViewport());
3948
3949 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3950 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3951 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3952
3953 VkPipelineObj pipelineobj(m_device);
3954 pipelineobj.AddShader(&vs);
3955 pipelineobj.AddShader(&gs);
3956 pipelineobj.AddShader(&ps);
3957
3958 const float dimensions[4] = { VkRenderFramework::m_width, VkRenderFramework::m_height , 0.0, 0.0};
3959
3960 VkConstantBufferObj windowDimensions(m_device, sizeof(dimensions) / sizeof(dimensions[0]), sizeof(dimensions[0]), (const void*) dimensions);
3961
3962 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3963 VkCommandBufferObj cmdBuffer(m_device);
3964 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3965
3966 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3967
3968 VkDescriptorSetObj descriptorSet(m_device);
3969 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, windowDimensions);
3970
3971 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3972
3973 // render triangle
3974 cmdBuffer.Draw(0, 3, 0, 1);
3975
3976 // finalize recording of the command buffer
3977 EndCommandBuffer(cmdBuffer);
3978 cmdBuffer.QueueCommandBuffer();
3979
3980 RecordImages(m_renderTargets);
3981}
3982
Chris Forbes23e6db62015-06-15 09:32:35 +12003983TEST_F(VkRenderTest, RenderPassLoadOpClear)
3984{
3985 ASSERT_NO_FATAL_FAILURE(InitState());
3986 ASSERT_NO_FATAL_FAILURE(InitViewport());
3987
3988 /* clear via load op to full green */
3989 m_clear_via_load_op = true;
3990 m_clear_color.useRawValue = false;
3991 m_clear_color.color.floatColor[0] = 0;
3992 m_clear_color.color.floatColor[1] = 1;
3993 m_clear_color.color.floatColor[2] = 0;
3994 m_clear_color.color.floatColor[3] = 0;
3995 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3996
3997 VkCommandBufferObj cmdBuffer(m_device);
3998 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3999 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
4000 /* This command buffer contains ONLY the load op! */
4001 EndCommandBuffer(cmdBuffer);
4002 cmdBuffer.QueueCommandBuffer();
4003
4004 RecordImages(m_renderTargets);
4005}
4006
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004007int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004008 int result;
4009
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004010 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06004011 VkTestFramework::InitArgs(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004012
Chia-I Wu7133fdc2014-12-15 23:57:34 +08004013 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06004014
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004015 result = RUN_ALL_TESTS();
4016
Tony Barbour01999182015-04-09 12:58:51 -06004017 VkTestFramework::Finish();
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004018 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004019}