blob: 8bfcfad4c0136b9cebf39846ce9637112b21045a [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 */
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600317 if (VK_SUCCESS == result) {
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
328 cmdBuffer.EndRenderPass(renderPass());
329
330 result = cmdBuffer.EndCommandBuffer();
331
332 return result;
333}
334
335
Tony Barbour01999182015-04-09 12:58:51 -0600336void VkRenderTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet)
Tony Barbour02472db2015-01-08 17:08:28 -0700337{
Tony Barbour17c6ab12015-03-27 17:03:18 -0600338 if (m_depthStencil->Initialized()) {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600339 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Tony Barbour17c6ab12015-03-27 17:03:18 -0600340 } else {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600341 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour17c6ab12015-03-27 17:03:18 -0600342 }
343
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700344 cmdBuffer->PrepareAttachments();
Tony Barbour8205d902015-04-16 15:59:00 -0600345 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_RASTER, m_stateRaster);
346 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_VIEWPORT, m_stateViewport);
347 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_COLOR_BLEND, m_colorBlend);
348 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_DEPTH_STENCIL, m_stateDepthStencil);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600349 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
350 pipelineobj.CreateVKPipeline(descriptorSet);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600351 cmdBuffer->BindPipeline(pipelineobj);
Chia-I Wu862c5572015-03-28 15:23:55 +0800352 cmdBuffer->BindDescriptorSet(descriptorSet);
Tony Barbour02472db2015-01-08 17:08:28 -0700353}
Tony Barbourf43b6982014-11-25 13:18:32 -0700354
Tony Barbour01999182015-04-09 12:58:51 -0600355void VkRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
356 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer)
Tony Barbourdd4c9642015-01-09 12:55:14 -0700357{
358 int i;
359 glm::mat4 MVP;
360 int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600361 VkResult err;
Tony Barbourdd4c9642015-01-09 12:55:14 -0700362
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600363 /* Only do 3 positions to avoid back face cull */
364 for (i = 0; i < 3; i++) {
Tony Barbourdd4c9642015-01-09 12:55:14 -0700365 void *pData = constantBuffer->map();
366
367 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
368 MVP = Projection * View * Model;
369 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
370
371 constantBuffer->unmap();
372
373 // submit the command buffer to the universal queue
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600374 cmdBuffer->QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700375
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600376 err = vkQueueWaitIdle( m_device->m_queue );
377 ASSERT_VK_SUCCESS( err );
Tony Barbourdd4c9642015-01-09 12:55:14 -0700378
379 // Wait for work to finish before cleaning up.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600380 vkDeviceWaitIdle(m_device->device());
Tony Barbourdd4c9642015-01-09 12:55:14 -0700381
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700382 assert(m_renderTargets.size() == 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -0700383 RecordImage(m_renderTargets[0]);
384 }
385}
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600386
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600387void dumpMatrix(const char *note, glm::mat4 MVP)
388{
Chia-I Wu7133fdc2014-12-15 23:57:34 +0800389 int i;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600390
391 printf("%s: \n", note);
392 for (i=0; i<4; i++) {
393 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
394 }
395 printf("\n");
396 fflush(stdout);
397}
398
399void dumpVec4(const char *note, glm::vec4 vector)
400{
401 printf("%s: \n", note);
402 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
403 printf("\n");
404 fflush(stdout);
405}
406
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600407struct vktriangle_vs_uniform {
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600408 // Must start with MVP
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600409 float mvp[4][4];
410 float position[3][4];
411 float color[3][4];
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600412};
413
Tony Barbour01999182015-04-09 12:58:51 -0600414void VkRenderTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600415{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700416#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600417 vkDbgRegisterMsgCallback(inst, myDbgFunc, NULL);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700418#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600419 // Create identity matrix
420 int i;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600421 struct vktriangle_vs_uniform data;
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600422
423 glm::mat4 Projection = glm::mat4(1.0f);
424 glm::mat4 View = glm::mat4(1.0f);
425 glm::mat4 Model = glm::mat4(1.0f);
426 glm::mat4 MVP = Projection * View * Model;
427 const int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600428 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600429 memcpy(&data.mvp, &MVP[0][0], matrixSize);
430
431 static const Vertex tri_data[] =
432 {
433 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
434 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
435 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
436 };
437
438 for (i=0; i<3; i++) {
439 data.position[i][0] = tri_data[i].posX;
440 data.position[i][1] = tri_data[i].posY;
441 data.position[i][2] = tri_data[i].posZ;
442 data.position[i][3] = tri_data[i].posW;
443 data.color[i][0] = tri_data[i].r;
444 data.color[i][1] = tri_data[i].g;
445 data.color[i][2] = tri_data[i].b;
446 data.color[i][3] = tri_data[i].a;
447 }
448
Tony Barbourf43b6982014-11-25 13:18:32 -0700449 ASSERT_NO_FATAL_FAILURE(InitState());
450 ASSERT_NO_FATAL_FAILURE(InitViewport());
451
Tony Barbour01999182015-04-09 12:58:51 -0600452 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barbourf43b6982014-11-25 13:18:32 -0700453
Tony Barbour01999182015-04-09 12:58:51 -0600454 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
455 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700456
Tony Barbour01999182015-04-09 12:58:51 -0600457 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -0700458 pipelineobj.AddShader(&vs);
459 pipelineobj.AddShader(&ps);
460
Tony Barbour01999182015-04-09 12:58:51 -0600461 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600462 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700463
Tony Barbour71ba3612015-01-09 16:12:35 -0700464 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600465 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour71ba3612015-01-09 16:12:35 -0700466 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700467
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600468 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour71ba3612015-01-09 16:12:35 -0700469
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600470 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour71ba3612015-01-09 16:12:35 -0700471#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600472 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour71ba3612015-01-09 16:12:35 -0700473 pDSDumpDot((char*)"triTest2.dot");
474#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600475
Tony Barbour71ba3612015-01-09 16:12:35 -0700476 // render triangle
477 cmdBuffer.Draw(0, 3, 0, 1);
478
479 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600480 EndCommandBuffer(cmdBuffer);
481
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600482 cmdBuffer.QueueCommandBuffer();
Tony Barbour71ba3612015-01-09 16:12:35 -0700483
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600484 RecordImages(m_renderTargets);
Tony Barbour71ba3612015-01-09 16:12:35 -0700485
486 if (rotate)
Tobin Ehlis12ee35f2015-03-26 08:23:25 -0600487 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
Tony Barbour71ba3612015-01-09 16:12:35 -0700488
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700489#ifdef PRINT_OBJECTS
Mark Lobodzinski4e5016f2015-05-05 15:01:37 -0500490 //uint64_t objTrackGetObjectCount(VkObjectType type)
491 OBJ_TRACK_GET_OBJECTS_COUNT pObjTrackGetObjectsCount = (OBJ_TRACK_GET_OBJECTS_COUNT)vkGetProcAddr(gpu(), (char*)"objTrackGetObjectsCount");
492 uint64_t numObjects = pObjTrackGetObjectsCount();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600493 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700494 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600495 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700496 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
Mark Lobodzinski4e5016f2015-05-05 15:01:37 -0500497 pObjTrackGetObjs(numObjects, pObjNodeArray);
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700498 for (i=0; i < numObjects; i++) {
Mark Lobodzinski4e5016f2015-05-05 15:01:37 -0500499 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 -0700500 }
501 free(pObjNodeArray);
502#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700503
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600504}
505
Tony Barbour01999182015-04-09 12:58:51 -0600506TEST_F(VkRenderTest, VKTriangle_FragColor)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600507{
508 static const char *vertShaderText =
509 "#version 140\n"
510 "#extension GL_ARB_separate_shader_objects : enable\n"
511 "#extension GL_ARB_shading_language_420pack : enable\n"
512 "\n"
513 "layout(binding = 0) uniform buf {\n"
514 " mat4 MVP;\n"
515 " vec4 position[3];\n"
516 " vec4 color[3];\n"
517 "} ubuf;\n"
518 "\n"
519 "layout (location = 0) out vec4 outColor;\n"
520 "\n"
521 "void main() \n"
522 "{\n"
523 " outColor = ubuf.color[gl_VertexID];\n"
524 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
525 "}\n";
526
527 static const char *fragShaderText =
528 "#version 140\n"
529 "#extension GL_ARB_separate_shader_objects : enable\n"
530 "#extension GL_ARB_shading_language_420pack : enable\n"
531 "\n"
532 "layout (location = 0) in vec4 inColor;\n"
533 "\n"
534 "void main()\n"
535 "{\n"
536 " gl_FragColor = inColor;\n"
537 "}\n";
538
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600539 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
540 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600541}
542
Tony Barbour01999182015-04-09 12:58:51 -0600543TEST_F(VkRenderTest, VKTriangle_OutputLocation)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600544{
545 static const char *vertShaderText =
546 "#version 140\n"
547 "#extension GL_ARB_separate_shader_objects : enable\n"
548 "#extension GL_ARB_shading_language_420pack : enable\n"
549 "\n"
550 "layout(binding = 0) uniform buf {\n"
551 " mat4 MVP;\n"
552 " vec4 position[3];\n"
553 " vec4 color[3];\n"
554 "} ubuf;\n"
555 "\n"
556 "layout (location = 0) out vec4 outColor;\n"
557 "\n"
558 "void main() \n"
559 "{\n"
560 " outColor = ubuf.color[gl_VertexID];\n"
561 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
562 "}\n";
563
564 static const char *fragShaderText =
565 "#version 140\n"
566 "#extension GL_ARB_separate_shader_objects : enable\n"
567 "#extension GL_ARB_shading_language_420pack : enable\n"
568 "\n"
569 "layout (location = 0) in vec4 inColor;\n"
570 "layout (location = 0) out vec4 outColor;\n"
571 "\n"
572 "void main()\n"
573 "{\n"
574 " outColor = inColor;\n"
575 "}\n";
576
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600577 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 -0600578
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600579 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600580}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600581#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 -0600582TEST_F(VkRenderTest, SPV_VKTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700583{
Tony Barbourf43b6982014-11-25 13:18:32 -0700584 static const char *vertShaderText =
585 "#version 140\n"
586 "#extension GL_ARB_separate_shader_objects : enable\n"
587 "#extension GL_ARB_shading_language_420pack : enable\n"
588 "\n"
589 "layout(binding = 0) uniform buf {\n"
590 " mat4 MVP;\n"
591 " vec4 position[3];\n"
592 " vec4 color[3];\n"
593 "} ubuf;\n"
594 "\n"
595 "layout (location = 0) out vec4 outColor;\n"
596 "\n"
597 "void main() \n"
598 "{\n"
599 " outColor = ubuf.color[gl_VertexID];\n"
600 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
601 "}\n";
602
603 static const char *fragShaderText =
604 "#version 140\n"
605 "#extension GL_ARB_separate_shader_objects : enable\n"
606 "#extension GL_ARB_shading_language_420pack : enable\n"
607 "\n"
608 "layout (location = 0) in vec4 inColor;\n"
609 "\n"
610 "void main()\n"
611 "{\n"
612 " gl_FragColor = inColor;\n"
613 "}\n";
614
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600615 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 -0700616
Chris Forbes2127e812015-05-25 11:13:04 +1200617 ScopedUseSpv spv(true);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600618 VKTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700619}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600620#endif
Tony Barbour01999182015-04-09 12:58:51 -0600621TEST_F(VkRenderTest, GreenTriangle)
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600622{
623 static const char *vertShaderText =
624 "#version 130\n"
625 "vec2 vertices[3];\n"
626 "void main() {\n"
627 " vertices[0] = vec2(-1.0, -1.0);\n"
628 " vertices[1] = vec2( 1.0, -1.0);\n"
629 " vertices[2] = vec2( 0.0, 1.0);\n"
630 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
631 "}\n";
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600632
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600633 static const char *fragShaderText =
634 "#version 130\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600635 "void main() {\n"
Steve K10b32512014-10-10 08:54:29 -0600636 " gl_FragColor = vec4(0,1,0,1);\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600637 "}\n";
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600638
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600639 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
640
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600641 VKTriangleTest(vertShaderText, fragShaderText, false);
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600642}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600643#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 -0600644TEST_F(VkRenderTest, SPV_GreenTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700645{
Tony Barbourf43b6982014-11-25 13:18:32 -0700646 static const char *vertShaderText =
647 "#version 130\n"
648 "vec2 vertices[3];\n"
649 "void main() {\n"
650 " vertices[0] = vec2(-1.0, -1.0);\n"
651 " vertices[1] = vec2( 1.0, -1.0);\n"
652 " vertices[2] = vec2( 0.0, 1.0);\n"
653 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
654 "}\n";
655
656 static const char *fragShaderText =
657 "#version 130\n"
658 "void main() {\n"
659 " gl_FragColor = vec4(0,1,0,1);\n"
660 "}\n";
661
Cody Northropacfb0492015-03-17 15:55:58 -0600662 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700663
Chris Forbes2127e812015-05-25 11:13:04 +1200664 ScopedUseSpv spv(true);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600665 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700666}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600667#endif
Tony Barbour01999182015-04-09 12:58:51 -0600668TEST_F(VkRenderTest, YellowTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700669{
670 static const char *vertShaderText =
671 "#version 130\n"
672 "void main() {\n"
673 " vec2 vertices[3];"
674 " vertices[0] = vec2(-0.5, -0.5);\n"
675 " vertices[1] = vec2( 0.5, -0.5);\n"
676 " vertices[2] = vec2( 0.5, 0.5);\n"
677 " vec4 colors[3];\n"
678 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
679 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
680 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
681 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
682 "}\n";
683
684 static const char *fragShaderText =
685 "#version 130\n"
686 "void main() {\n"
687 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
688 "}\n";
689
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600690 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700691}
692
Tony Barbour01999182015-04-09 12:58:51 -0600693TEST_F(VkRenderTest, QuadWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600694{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600695 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600696 "#version 140\n"
697 "#extension GL_ARB_separate_shader_objects : enable\n"
698 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700699 //XYZ1( -1, -1, -1 )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600700 "layout (location = 0) in vec4 pos;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700701 //XYZ1( 0.f, 0.f, 0.f )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600702 "layout (location = 1) in vec4 inColor;\n"
703 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600704 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600705 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600706 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600707 "}\n";
708
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600709
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600710 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700711 "#version 140\n"
712 "#extension GL_ARB_separate_shader_objects : enable\n"
713 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600714 "layout (location = 0) in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700715 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600716 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700717 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600718 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600719
Tony Barbourf43b6982014-11-25 13:18:32 -0700720
721
722 ASSERT_NO_FATAL_FAILURE(InitState());
723 ASSERT_NO_FATAL_FAILURE(InitViewport());
724
Tony Barbour01999182015-04-09 12:58:51 -0600725 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000726 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700727
Tony Barbour01999182015-04-09 12:58:51 -0600728 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
729 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700730
Tony Barbour01999182015-04-09 12:58:51 -0600731 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -0700732 pipelineobj.AddShader(&vs);
733 pipelineobj.AddShader(&ps);
734
Tony Barbour01999182015-04-09 12:58:51 -0600735 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600736 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -0600737
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600738#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600739 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600740 MESH_BIND_ID, // binding ID
Tony Barbourf43b6982014-11-25 13:18:32 -0700741 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600742 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -0700743 };
744
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600745 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600746 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
747 vi_attribs[0].location = 0; // location, position
Tony Barbour8205d902015-04-16 15:59:00 -0600748 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600749 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
750 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
751 vi_attribs[1].location = 1; // location, color
Tony Barbour8205d902015-04-16 15:59:00 -0600752 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600753 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 -0700754
755 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
756 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600757 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -0700758
Tony Barboure4ed9942015-01-09 10:06:53 -0700759 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600760 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700761 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700762
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600763 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600764
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600765 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700766
Tony Barboure4ed9942015-01-09 10:06:53 -0700767 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
768
769 // render two triangles
770 cmdBuffer.Draw(0, 6, 0, 1);
771
772 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600773 EndCommandBuffer(cmdBuffer);
774
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600775 cmdBuffer.QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -0700776
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600777 RecordImages(m_renderTargets);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600778}
779
Tony Barbour01999182015-04-09 12:58:51 -0600780TEST_F(VkRenderTest, TriangleMRT)
Chia-I Wue09d1a72014-12-05 10:32:23 +0800781{
782 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600783 "#version 140\n"
784 "#extension GL_ARB_separate_shader_objects : enable\n"
785 "#extension GL_ARB_shading_language_420pack : enable\n"
786 "layout (location = 0) in vec4 pos;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800787 "void main() {\n"
788 " gl_Position = pos;\n"
789 "}\n";
790
791 static const char *fragShaderText =
792 "#version 130\n"
793 "void main() {\n"
794 " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
795 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
796 "}\n";
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600797 const float vb_data[][2] = {
Chia-I Wue09d1a72014-12-05 10:32:23 +0800798 { -1.0f, -1.0f },
799 { 1.0f, -1.0f },
800 { -1.0f, 1.0f }
801 };
802
803 ASSERT_NO_FATAL_FAILURE(InitState());
804 ASSERT_NO_FATAL_FAILURE(InitViewport());
805
Tony Barbour01999182015-04-09 12:58:51 -0600806 VkConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000807 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800808
Tony Barbour01999182015-04-09 12:58:51 -0600809 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
810 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800811
Tony Barbour01999182015-04-09 12:58:51 -0600812 VkPipelineObj pipelineobj(m_device);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800813 pipelineobj.AddShader(&vs);
814 pipelineobj.AddShader(&ps);
815
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600816#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600817 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600818 MESH_BUF_ID, // Binding ID
819 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600820 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Chia-I Wue09d1a72014-12-05 10:32:23 +0800821 };
822
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600823 VkVertexInputAttributeDescription vi_attrib;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600824 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
825 vi_attrib.location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -0600826 vi_attrib.format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600827 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
Chia-I Wue09d1a72014-12-05 10:32:23 +0800828
829 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
830 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600831 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800832
Tony Barbour01999182015-04-09 12:58:51 -0600833 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600834 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800835
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700836 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
Chia-I Wue09d1a72014-12-05 10:32:23 +0800837
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600838 VkPipelineCbAttachmentState att = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600839 att.blendEnable = VK_FALSE;
Chia-I Wue09d1a72014-12-05 10:32:23 +0800840 att.format = m_render_target_fmt;
841 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700842 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800843
Tony Barbour01999182015-04-09 12:58:51 -0600844 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700845
Tony Barbour5ed79702015-01-07 14:31:52 -0700846 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
847 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barboure4ed9942015-01-09 10:06:53 -0700848
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600849 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour5ed79702015-01-07 14:31:52 -0700850
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600851 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700852
Tony Barbour5ed79702015-01-07 14:31:52 -0700853 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700854#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600855 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour5ed79702015-01-07 14:31:52 -0700856 pDSDumpDot((char*)"triTest2.dot");
857#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600858
Tony Barbour5ed79702015-01-07 14:31:52 -0700859 // render triangle
860 cmdBuffer.Draw(0, 3, 0, 1);
861
862 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600863 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600864 cmdBuffer.QueueCommandBuffer();
Tony Barbour5ed79702015-01-07 14:31:52 -0700865
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600866 RecordImages(m_renderTargets);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800867}
868
Tony Barbour01999182015-04-09 12:58:51 -0600869TEST_F(VkRenderTest, QuadWithIndexedVertexFetch)
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700870{
871 static const char *vertShaderText =
872 "#version 140\n"
873 "#extension GL_ARB_separate_shader_objects : enable\n"
874 "#extension GL_ARB_shading_language_420pack : enable\n"
875 "layout(location = 0) in vec4 pos;\n"
876 "layout(location = 1) in vec4 inColor;\n"
877 "layout(location = 0) out vec4 outColor;\n"
878 "void main() {\n"
879 " outColor = inColor;\n"
880 " gl_Position = pos;\n"
881 "}\n";
882
883
884 static const char *fragShaderText =
885 "#version 140\n"
886 "#extension GL_ARB_separate_shader_objects : enable\n"
887 "#extension GL_ARB_shading_language_420pack : enable\n"
888 "layout(location = 0) in vec4 color;\n"
889 "void main() {\n"
890 " gl_FragColor = color;\n"
891 "}\n";
892
893 const Vertex g_vbData[] =
894 {
895 // first tri
896 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
897 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
898 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
899
900 // second tri
901 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
902 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
903 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
904 };
905
906 const uint16_t g_idxData[6] = {
907 0, 1, 2,
908 3, 4, 5,
909 };
910
911 ASSERT_NO_FATAL_FAILURE(InitState());
912 ASSERT_NO_FATAL_FAILURE(InitViewport());
913
Tony Barbour01999182015-04-09 12:58:51 -0600914 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000915 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700916
Tony Barbour01999182015-04-09 12:58:51 -0600917 VkIndexBufferObj indexBuffer(m_device);
Tony Barbour8205d902015-04-16 15:59:00 -0600918 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), VK_INDEX_TYPE_UINT16, g_idxData);
Mark Lobodzinskid30f82a2015-02-16 14:24:23 -0600919 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700920
Tony Barbour01999182015-04-09 12:58:51 -0600921 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
922 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700923
Tony Barbour01999182015-04-09 12:58:51 -0600924 VkPipelineObj pipelineobj(m_device);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700925 pipelineobj.AddShader(&vs);
926 pipelineobj.AddShader(&ps);
927
Tony Barbour01999182015-04-09 12:58:51 -0600928 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600929 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
930 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, indexBuffer);
Tony Barbour83a83802015-04-02 15:43:15 -0600931
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700932
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600933#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600934 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600935 MESH_BIND_ID, // binding ID
936 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600937 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700938 };
939
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600940 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600941 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
942 vi_attribs[0].location = 0; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600943 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600944 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
945 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
946 vi_attribs[1].location = 1; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600947 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600948 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700949
950 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
951 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700952
953 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600954 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700955 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600956 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barboure4ed9942015-01-09 10:06:53 -0700957
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600958 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700959
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700960#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600961 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700962 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700963#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700964
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600965 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600966 cmdBuffer.BindIndexBuffer(&indexBuffer, 0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700967
968 // render two triangles
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700969 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700970
971 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600972 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600973 cmdBuffer.QueueCommandBuffer();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700974
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600975 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700976}
977
Tony Barbour01999182015-04-09 12:58:51 -0600978TEST_F(VkRenderTest, GreyandRedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -0700979{
980 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -0700981
GregF6bef1212014-12-02 15:41:44 -0700982 static const char *vertShaderText =
983 "#version 140\n"
984 "#extension GL_ARB_separate_shader_objects : enable\n"
985 "#extension GL_ARB_shading_language_420pack : enable\n"
986 "layout (location = 0) in vec4 pos;\n"
987 "layout (location = 0) out vec4 outColor;\n"
988 "layout (location = 1) out vec4 outColor2;\n"
989 "void main() {\n"
990 " gl_Position = pos;\n"
991 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
992 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
993 "}\n";
994
995 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -0700996 "#version 330\n"
997 "#extension GL_ARB_separate_shader_objects : enable\n"
998 "#extension GL_ARB_shading_language_420pack : enable\n"
999 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1000 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1001 "layout (location = 0) in vec4 color;\n"
1002 "layout (location = 1) in vec4 color2;\n"
1003 "void main() {\n"
1004 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1005 " float dist_squared = dot(pos, pos);\n"
1006 " gl_FragColor = (dist_squared < 400.0)\n"
1007 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1008 " : color2;\n"
1009 "}\n";
1010
1011 ASSERT_NO_FATAL_FAILURE(InitState());
1012 ASSERT_NO_FATAL_FAILURE(InitViewport());
1013
Tony Barbour01999182015-04-09 12:58:51 -06001014 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001015 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001016
Tony Barbour01999182015-04-09 12:58:51 -06001017 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1018 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001019
Tony Barbour01999182015-04-09 12:58:51 -06001020 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001021 pipelineobj.AddShader(&vs);
1022 pipelineobj.AddShader(&ps);
1023
Tony Barbour01999182015-04-09 12:58:51 -06001024 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001025 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001026
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001027#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001028 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001029 MESH_BIND_ID, // binding ID
1030 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001031 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001032 };
1033
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001034 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001035 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1036 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001037 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001038 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001039
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001040 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001041 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001042 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001043
Tony Barbourdd4c9642015-01-09 12:55:14 -07001044 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001045 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001046 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1047
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001048 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001049
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001050 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001051
1052 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1053#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001054 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001055 pDSDumpDot((char*)"triTest2.dot");
1056#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001057
Tony Barbourdd4c9642015-01-09 12:55:14 -07001058 // render triangle
1059 cmdBuffer.Draw(0, 6, 0, 1);
1060
1061 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001062 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001063 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001064
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001065 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001066}
1067
Tony Barbour01999182015-04-09 12:58:51 -06001068TEST_F(VkRenderTest, RedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -07001069{
1070 // This tests that we correctly handle unread fragment inputs
1071
1072 static const char *vertShaderText =
1073 "#version 140\n"
1074 "#extension GL_ARB_separate_shader_objects : enable\n"
1075 "#extension GL_ARB_shading_language_420pack : enable\n"
1076 "layout (location = 0) in vec4 pos;\n"
1077 "layout (location = 0) out vec4 outColor;\n"
1078 "layout (location = 1) out vec4 outColor2;\n"
1079 "void main() {\n"
1080 " gl_Position = pos;\n"
1081 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1082 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1083 "}\n";
1084
1085 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001086 "#version 330\n"
1087 "#extension GL_ARB_separate_shader_objects : enable\n"
1088 "#extension GL_ARB_shading_language_420pack : enable\n"
1089 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1090 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1091 "layout (location = 0) in vec4 color;\n"
1092 "layout (location = 1) in vec4 color2;\n"
1093 "void main() {\n"
1094 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1095 " float dist_squared = dot(pos, pos);\n"
1096 " gl_FragColor = (dist_squared < 400.0)\n"
1097 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1098 " : color2;\n"
1099 "}\n";
1100
1101 ASSERT_NO_FATAL_FAILURE(InitState());
1102 ASSERT_NO_FATAL_FAILURE(InitViewport());
1103
Tony Barbour01999182015-04-09 12:58:51 -06001104 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001105 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001106
Tony Barbour01999182015-04-09 12:58:51 -06001107 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1108 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001109
Tony Barbour01999182015-04-09 12:58:51 -06001110 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001111 pipelineobj.AddShader(&vs);
1112 pipelineobj.AddShader(&ps);
1113
Tony Barbour01999182015-04-09 12:58:51 -06001114 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001115 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001116
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001117#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001118 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001119 MESH_BIND_ID, // binding ID
1120 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001121 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001122 };
1123
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001124 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001125 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1126 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001127 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001128 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001129
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001130 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001131 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001132 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001133
Tony Barbourdd4c9642015-01-09 12:55:14 -07001134 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001135 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001136 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1137
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001138 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001139
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001140 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001141
1142 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1143#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001144 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001145 pDSDumpDot((char*)"triTest2.dot");
1146#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001147 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001148 cmdBuffer.Draw(0, 6, 0, 1);
1149
1150 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001151 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001152 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001153
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001154 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001155}
1156
Tony Barbour01999182015-04-09 12:58:51 -06001157TEST_F(VkRenderTest, GreyCirclesonBlueFade)
GregF6bef1212014-12-02 15:41:44 -07001158{
1159 // This tests reading gl_ClipDistance from FS
1160
1161 static const char *vertShaderText =
1162 "#version 330\n"
1163 "#extension GL_ARB_separate_shader_objects : enable\n"
1164 "#extension GL_ARB_shading_language_420pack : enable\n"
1165 "out gl_PerVertex {\n"
1166 " vec4 gl_Position;\n"
1167 " float gl_ClipDistance[1];\n"
1168 "};\n"
1169 "layout (location = 0) in vec4 pos;\n"
1170 "layout (location = 0) out vec4 outColor;\n"
1171 "layout (location = 1) out vec4 outColor2;\n"
1172 "void main() {\n"
1173 " gl_Position = pos;\n"
1174 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1175 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1176 " float dists[3];\n"
1177 " dists[0] = 0.0;\n"
1178 " dists[1] = 1.0;\n"
1179 " dists[2] = 1.0;\n"
1180 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1181 "}\n";
1182
1183
1184 static const char *fragShaderText =
1185 //"#version 140\n"
1186 "#version 330\n"
1187 "#extension GL_ARB_separate_shader_objects : enable\n"
1188 "#extension GL_ARB_shading_language_420pack : enable\n"
1189 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1190 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1191 "layout (location = 0) in vec4 color;\n"
1192 "layout (location = 1) in vec4 color2;\n"
1193 "void main() {\n"
1194 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1195 " float dist_squared = dot(pos, pos);\n"
1196 " gl_FragColor = (dist_squared < 400.0)\n"
1197 " ? color * gl_ClipDistance[0]\n"
1198 " : color2;\n"
1199 "}\n";
1200
1201 ASSERT_NO_FATAL_FAILURE(InitState());
1202 ASSERT_NO_FATAL_FAILURE(InitViewport());
1203
Tony Barbour01999182015-04-09 12:58:51 -06001204 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001205 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001206
Tony Barbour01999182015-04-09 12:58:51 -06001207 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1208 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001209
Tony Barbour01999182015-04-09 12:58:51 -06001210 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001211 pipelineobj.AddShader(&vs);
1212 pipelineobj.AddShader(&ps);
1213
Tony Barbour01999182015-04-09 12:58:51 -06001214 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001215 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001216
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001217#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001218 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001219 MESH_BIND_ID, // binding ID
1220 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001221 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001222 };
1223
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001224 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001225 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1226 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001227 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001228 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001229
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001230 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001231 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001232 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001233
Tony Barbourdd4c9642015-01-09 12:55:14 -07001234 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001235 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001236 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF6bef1212014-12-02 15:41:44 -07001237
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001238 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001239
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001240 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001241
1242 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1243#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001244 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001245 pDSDumpDot((char*)"triTest2.dot");
1246#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001247
1248 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001249 cmdBuffer.Draw(0, 6, 0, 1);
1250
1251 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001252 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001253 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001254
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001255 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001256}
Tony Barbourf43b6982014-11-25 13:18:32 -07001257
Tony Barbour01999182015-04-09 12:58:51 -06001258TEST_F(VkRenderTest, GreyCirclesonBlueDiscard)
GregF7a23c792014-12-02 17:19:34 -07001259{
1260 static const char *vertShaderText =
1261 "#version 140\n"
1262 "#extension GL_ARB_separate_shader_objects : enable\n"
1263 "#extension GL_ARB_shading_language_420pack : enable\n"
1264 "layout (location = 0) in vec4 pos;\n"
1265 "layout (location = 0) out vec4 outColor;\n"
1266 "layout (location = 1) out vec4 outColor2;\n"
1267 "void main() {\n"
1268 " gl_Position = pos;\n"
1269 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1270 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1271 "}\n";
1272
1273
1274 static const char *fragShaderText =
GregF7a23c792014-12-02 17:19:34 -07001275 "#version 330\n"
1276 "#extension GL_ARB_separate_shader_objects : enable\n"
1277 "#extension GL_ARB_shading_language_420pack : enable\n"
1278 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1279 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1280 "layout (location = 0) in vec4 color;\n"
1281 "layout (location = 1) in vec4 color2;\n"
1282 "void main() {\n"
1283 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1284 " float dist_squared = dot(pos, pos);\n"
1285 " if (dist_squared < 100.0)\n"
1286 " discard;\n"
1287 " gl_FragColor = (dist_squared < 400.0)\n"
1288 " ? color\n"
1289 " : color2;\n"
1290 "}\n";
1291
1292 ASSERT_NO_FATAL_FAILURE(InitState());
1293 ASSERT_NO_FATAL_FAILURE(InitViewport());
1294
Tony Barbour01999182015-04-09 12:58:51 -06001295 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001296 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001297
Tony Barbour01999182015-04-09 12:58:51 -06001298 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1299 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF7a23c792014-12-02 17:19:34 -07001300
Tony Barbour01999182015-04-09 12:58:51 -06001301 VkPipelineObj pipelineobj(m_device);
GregF7a23c792014-12-02 17:19:34 -07001302 pipelineobj.AddShader(&vs);
1303 pipelineobj.AddShader(&ps);
1304
Tony Barbour01999182015-04-09 12:58:51 -06001305 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001306 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001307
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001308#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001309 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001310 MESH_BIND_ID, // binding ID
1311 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001312 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF7a23c792014-12-02 17:19:34 -07001313 };
1314
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001315 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001316 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1317 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001318 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001319 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF7a23c792014-12-02 17:19:34 -07001320
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001321 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF7a23c792014-12-02 17:19:34 -07001322 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001323 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF7a23c792014-12-02 17:19:34 -07001324
Tony Barbourdd4c9642015-01-09 12:55:14 -07001325 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001326 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001327 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1328
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001329 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001330
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001331 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001332
1333 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1334#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001335 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001336 pDSDumpDot((char*)"triTest2.dot");
1337#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001338
1339 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001340 cmdBuffer.Draw(0, 6, 0, 1);
1341
1342 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001343 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001344 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001345
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001346 RecordImages(m_renderTargets);
GregF7a23c792014-12-02 17:19:34 -07001347}
1348
1349
Tony Barbour01999182015-04-09 12:58:51 -06001350TEST_F(VkRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001351{
1352 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001353 "#version 140\n"
1354 "#extension GL_ARB_separate_shader_objects : enable\n"
1355 "#extension GL_ARB_shading_language_420pack : enable\n"
1356 "\n"
1357 "layout(binding = 0) uniform buf {\n"
1358 " mat4 MVP;\n"
1359 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001360 "void main() {\n"
1361 " vec2 vertices[3];"
1362 " vertices[0] = vec2(-0.5, -0.5);\n"
1363 " vertices[1] = vec2( 0.5, -0.5);\n"
1364 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001365 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001366 "}\n";
1367
1368 static const char *fragShaderText =
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001369 "#version 130\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001370 "void main() {\n"
Cody Northrop78eac042014-10-10 15:45:00 -06001371 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001372 "}\n";
1373
Tony Barbourf43b6982014-11-25 13:18:32 -07001374 ASSERT_NO_FATAL_FAILURE(InitState());
1375 ASSERT_NO_FATAL_FAILURE(InitViewport());
1376
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001377 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001378 glm::mat4 Projection = glm::mat4(1.0f);
1379 glm::mat4 View = glm::mat4(1.0f);
1380 glm::mat4 Model = glm::mat4(1.0f);
1381 glm::mat4 MVP = Projection * View * Model;
1382 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1383
Tony Barbour01999182015-04-09 12:58:51 -06001384 VkConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1385 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1386 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001387
Tony Barbour01999182015-04-09 12:58:51 -06001388 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001389 pipelineobj.AddShader(&vs);
1390 pipelineobj.AddShader(&ps);
1391
1392 // Create descriptor set and attach the constant buffer to it
Tony Barbour01999182015-04-09 12:58:51 -06001393 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001394 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001395
Tony Barbourdd4c9642015-01-09 12:55:14 -07001396 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001397 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001398 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001399
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001400 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001401
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001402 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001403
1404 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1405#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001406 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001407 pDSDumpDot((char*)"triTest2.dot");
1408#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001409
1410 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001411 cmdBuffer.Draw(0, 6, 0, 1);
1412
1413 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001414 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001415 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001416
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001417 RecordImages(m_renderTargets);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001418
1419 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001420}
1421
Tony Barbour01999182015-04-09 12:58:51 -06001422TEST_F(VkRenderTest, MixTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07001423{
1424 // This tests location applied to varyings. Notice that we have switched foo
1425 // and bar in the FS. The triangle should be blended with red, green and blue
1426 // corners.
1427 static const char *vertShaderText =
1428 "#version 140\n"
1429 "#extension GL_ARB_separate_shader_objects : enable\n"
1430 "#extension GL_ARB_shading_language_420pack : enable\n"
1431 "layout (location=0) out vec4 bar;\n"
1432 "layout (location=1) out vec4 foo;\n"
1433 "layout (location=2) out float scale;\n"
1434 "vec2 vertices[3];\n"
1435 "void main() {\n"
1436 " vertices[0] = vec2(-1.0, -1.0);\n"
1437 " vertices[1] = vec2( 1.0, -1.0);\n"
1438 " vertices[2] = vec2( 0.0, 1.0);\n"
1439 "vec4 colors[3];\n"
1440 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1441 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1442 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1443 " foo = colors[gl_VertexID % 3];\n"
1444 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1445 " scale = 1.0;\n"
1446 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1447 "}\n";
1448
1449 static const char *fragShaderText =
1450 "#version 140\n"
1451 "#extension GL_ARB_separate_shader_objects : enable\n"
1452 "#extension GL_ARB_shading_language_420pack : enable\n"
1453 "layout (location = 1) in vec4 bar;\n"
1454 "layout (location = 0) in vec4 foo;\n"
1455 "layout (location = 2) in float scale;\n"
1456 "void main() {\n"
1457 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
1458 "}\n";
1459
1460 ASSERT_NO_FATAL_FAILURE(InitState());
1461 ASSERT_NO_FATAL_FAILURE(InitViewport());
1462
Tony Barbour01999182015-04-09 12:58:51 -06001463 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1464 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001465
Tony Barbour01999182015-04-09 12:58:51 -06001466 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001467 pipelineobj.AddShader(&vs);
1468 pipelineobj.AddShader(&ps);
1469
Tony Barbour01999182015-04-09 12:58:51 -06001470 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06001471 descriptorSet.AppendDummy();
Tony Barbourf43b6982014-11-25 13:18:32 -07001472
Tony Barbourdd4c9642015-01-09 12:55:14 -07001473 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001474 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001475 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1476
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001477 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001478
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001479 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001480
1481#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001482 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001483 pDSDumpDot((char*)"triTest2.dot");
1484#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001485
Tony Barbourdd4c9642015-01-09 12:55:14 -07001486 // render triangle
1487 cmdBuffer.Draw(0, 3, 0, 1);
1488
1489 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001490 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001491 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001492
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001493 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001494}
1495
Tony Barbour01999182015-04-09 12:58:51 -06001496TEST_F(VkRenderTest, QuadVertFetchAndVertID)
Tony Barbourf43b6982014-11-25 13:18:32 -07001497{
1498 // This tests that attributes work in the presence of gl_VertexID
1499
1500 static const char *vertShaderText =
1501 "#version 140\n"
1502 "#extension GL_ARB_separate_shader_objects : enable\n"
1503 "#extension GL_ARB_shading_language_420pack : enable\n"
1504 //XYZ1( -1, -1, -1 )
1505 "layout (location = 0) in vec4 pos;\n"
1506 //XYZ1( 0.f, 0.f, 0.f )
1507 "layout (location = 1) in vec4 inColor;\n"
1508 "layout (location = 0) out vec4 outColor;\n"
1509 "void main() {\n"
1510 " outColor = inColor;\n"
1511 " vec4 vertices[3];"
1512 " vertices[gl_VertexID % 3] = pos;\n"
1513 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1514 "}\n";
1515
1516
1517 static const char *fragShaderText =
1518 "#version 140\n"
1519 "#extension GL_ARB_separate_shader_objects : enable\n"
1520 "#extension GL_ARB_shading_language_420pack : enable\n"
1521 "layout (location = 0) in vec4 color;\n"
1522 "void main() {\n"
1523 " gl_FragColor = color;\n"
1524 "}\n";
1525
1526 ASSERT_NO_FATAL_FAILURE(InitState());
1527 ASSERT_NO_FATAL_FAILURE(InitViewport());
1528
Tony Barbour01999182015-04-09 12:58:51 -06001529 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001530 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001531
Tony Barbour01999182015-04-09 12:58:51 -06001532 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1533 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001534
Tony Barbour01999182015-04-09 12:58:51 -06001535 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001536 pipelineobj.AddShader(&vs);
1537 pipelineobj.AddShader(&ps);
1538
Tony Barbour01999182015-04-09 12:58:51 -06001539 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001540 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001541
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001542#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001543 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001544 MESH_BUF_ID, // Binding ID
1545 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001546 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001547 };
1548
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001549 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001550 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1551 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001552 vi_attribs[0].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001553 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1554 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1555 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001556 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001557 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001558
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001559 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001560 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001561 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001562
Tony Barbourdd4c9642015-01-09 12:55:14 -07001563 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001564 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001565 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1566
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001567 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001568
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001569 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001570
1571 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1572#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001573 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001574 pDSDumpDot((char*)"triTest2.dot");
1575#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001576
1577 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001578 cmdBuffer.Draw(0, 6, 0, 1);
1579
1580 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001581 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001582 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001583
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001584 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001585}
1586
Tony Barbour01999182015-04-09 12:58:51 -06001587TEST_F(VkRenderTest, QuadSparseVertFetch)
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001588{
1589 // This tests that attributes work in the presence of gl_VertexID
1590
1591 static const char *vertShaderText =
1592 "#version 140\n"
1593 "#extension GL_ARB_separate_shader_objects : enable\n"
1594 "#extension GL_ARB_shading_language_420pack : enable\n"
1595 //XYZ1( -1, -1, -1 )
1596 "layout (location = 1) in vec4 pos;\n"
1597 "layout (location = 4) in vec4 inColor;\n"
1598 //XYZ1( 0.f, 0.f, 0.f )
1599 "layout (location = 0) out vec4 outColor;\n"
1600 "void main() {\n"
1601 " outColor = inColor;\n"
1602 " gl_Position = pos;\n"
1603 "}\n";
1604
1605
1606 static const char *fragShaderText =
1607 "#version 140\n"
1608 "#extension GL_ARB_separate_shader_objects : enable\n"
1609 "#extension GL_ARB_shading_language_420pack : enable\n"
1610 "layout (location = 0) in vec4 color;\n"
1611 "void main() {\n"
1612 " gl_FragColor = color;\n"
1613 "}\n";
1614
1615 ASSERT_NO_FATAL_FAILURE(InitState());
1616 ASSERT_NO_FATAL_FAILURE(InitViewport());
1617
1618 struct VDATA
1619 {
1620 float t1, t2, t3, t4; // filler data
1621 float posX, posY, posZ, posW; // Position data
1622 float r, g, b, a; // Color
1623 };
1624 const struct VDATA vData[] =
1625 {
1626 { XYZ1(0, 0, 0), XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
1627 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1628 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1629 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1630 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1631 { XYZ1(0, 0, 0), XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
1632 };
1633
Tony Barbour01999182015-04-09 12:58:51 -06001634 VkConstantBufferObj meshBuffer(m_device,sizeof(vData)/sizeof(vData[0]),sizeof(vData[0]), vData);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001635 meshBuffer.BufferMemoryBarrier();
1636
Tony Barbour01999182015-04-09 12:58:51 -06001637 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1638 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001639
Tony Barbour01999182015-04-09 12:58:51 -06001640 VkPipelineObj pipelineobj(m_device);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001641 pipelineobj.AddShader(&vs);
1642 pipelineobj.AddShader(&ps);
1643
Tony Barbour01999182015-04-09 12:58:51 -06001644 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001645 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001646
1647#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001648 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001649 MESH_BUF_ID, // Binding ID
1650 sizeof(vData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001651 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001652 };
1653
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001654 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001655 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1656 vi_attribs[0].location = 4;
Tony Barbour8205d902015-04-16 15:59:00 -06001657 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001658 vi_attribs[0].offsetInBytes = sizeof(float) * 4 * 2; // Offset of first element in bytes from base of vertex
1659 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1660 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001661 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001662 vi_attribs[1].offsetInBytes = sizeof(float) * 4 * 1; // Offset of first element in bytes from base of vertex
1663
1664 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
1665 pipelineobj.AddVertexInputBindings(&vi_binding, 1);
1666 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
1667
1668 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001669 VkCommandBufferObj cmdBuffer(m_device);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001670 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1671
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001672 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001673
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001674 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001675
1676 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BUF_ID);
1677#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001678 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001679 pDSDumpDot((char*)"triTest2.dot");
1680#endif
1681
1682 // render two triangles
1683 cmdBuffer.Draw(0, 6, 0, 1);
1684
1685 // finalize recording of the command buffer
1686 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001687 cmdBuffer.QueueCommandBuffer();
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001688
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001689 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001690}
1691
Tony Barbour01999182015-04-09 12:58:51 -06001692TEST_F(VkRenderTest, TriVertFetchDeadAttr)
Tony Barbourf43b6982014-11-25 13:18:32 -07001693{
1694 // This tests that attributes work in the presence of gl_VertexID
1695 // and a dead attribute in position 0. Draws a triangle with yellow,
1696 // red and green corners, starting at top and going clockwise.
1697
1698 static const char *vertShaderText =
1699 "#version 140\n"
1700 "#extension GL_ARB_separate_shader_objects : enable\n"
1701 "#extension GL_ARB_shading_language_420pack : enable\n"
1702 //XYZ1( -1, -1, -1 )
1703 "layout (location = 0) in vec4 pos;\n"
1704 //XYZ1( 0.f, 0.f, 0.f )
1705 "layout (location = 1) in vec4 inColor;\n"
1706 "layout (location = 0) out vec4 outColor;\n"
1707 "void main() {\n"
1708 " outColor = inColor;\n"
1709 " vec2 vertices[3];"
1710 " vertices[0] = vec2(-1.0, -1.0);\n"
1711 " vertices[1] = vec2( 1.0, -1.0);\n"
1712 " vertices[2] = vec2( 0.0, 1.0);\n"
1713 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1714 "}\n";
1715
1716
1717 static const char *fragShaderText =
1718 "#version 140\n"
1719 "#extension GL_ARB_separate_shader_objects : enable\n"
1720 "#extension GL_ARB_shading_language_420pack : enable\n"
1721 "layout (location = 0) in vec4 color;\n"
1722 "void main() {\n"
1723 " gl_FragColor = color;\n"
1724 "}\n";
1725
1726 ASSERT_NO_FATAL_FAILURE(InitState());
1727 ASSERT_NO_FATAL_FAILURE(InitViewport());
1728
Tony Barbour01999182015-04-09 12:58:51 -06001729 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001730 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001731
Tony Barbour01999182015-04-09 12:58:51 -06001732 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1733 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001734
Tony Barbour01999182015-04-09 12:58:51 -06001735 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001736 pipelineobj.AddShader(&vs);
1737 pipelineobj.AddShader(&ps);
1738
Tony Barbour01999182015-04-09 12:58:51 -06001739 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001740 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001741
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001742#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001743 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001744 MESH_BUF_ID, // Binding ID
1745 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001746 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001747 };
1748
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001749 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001750 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1751 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001752 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001753 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1754 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1755 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001756 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001757 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001758
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001759 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001760 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001761 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001762
Tony Barbourdd4c9642015-01-09 12:55:14 -07001763 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001764 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001765 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001766
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001767 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001768
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001769 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001770
1771 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1772#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001773 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001774 pDSDumpDot((char*)"triTest2.dot");
1775#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001776
1777 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001778 cmdBuffer.Draw(0, 6, 0, 1);
1779
1780 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001781 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001782 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001783
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001784 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001785}
1786
Tony Barbour01999182015-04-09 12:58:51 -06001787TEST_F(VkRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001788{
1789 static const char *vertShaderText =
1790 "#version 140\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001791 "#extension GL_ARB_separate_shader_objects : enable\n"
1792 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001793 "layout (std140) uniform bufferVals {\n"
1794 " mat4 mvp;\n"
1795 "} myBufferVals;\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001796 "layout (location = 0) in vec4 pos;\n"
1797 "layout (location = 1) in vec4 inColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001798 "out vec4 outColor;\n"
1799 "void main() {\n"
1800 " outColor = inColor;\n"
1801 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001802 " gl_Position.y = -gl_Position.y;\n"
1803 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001804 "}\n";
1805
1806 static const char *fragShaderText =
1807 "#version 130\n"
1808 "in vec4 color;\n"
1809 "void main() {\n"
1810 " gl_FragColor = color;\n"
1811 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001812 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001813
Tony Barbourf43b6982014-11-25 13:18:32 -07001814 glm::mat4 View = glm::lookAt(
1815 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1816 glm::vec3(0,0,0), // and looks at the origin
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001817 glm::vec3(0,-1,0) // Head is up (set to 0,-1,0 to look upside-down)
Tony Barbourf43b6982014-11-25 13:18:32 -07001818 );
1819
1820 glm::mat4 Model = glm::mat4(1.0f);
1821
1822 glm::mat4 MVP = Projection * View * Model;
1823
1824 ASSERT_NO_FATAL_FAILURE(InitState());
1825 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour8bef8ee2015-05-22 09:44:58 -06001826 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07001827
Tony Barbour01999182015-04-09 12:58:51 -06001828 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 -07001829 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1830
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001831 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07001832
Tony Barbour01999182015-04-09 12:58:51 -06001833 VkConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1834 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1835 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001836
Tony Barbour01999182015-04-09 12:58:51 -06001837 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001838 pipelineobj.AddShader(&vs);
1839 pipelineobj.AddShader(&ps);
1840
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001841 VkPipelineDsStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001842 ds_state.depthTestEnable = VK_TRUE;
1843 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06001844 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001845 ds_state.depthBoundsEnable = VK_FALSE;
1846 ds_state.stencilTestEnable = VK_FALSE;
1847 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
1848 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
1849 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06001850 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
1851 ds_state.format = VK_FORMAT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001852 ds_state.front = ds_state.back;
1853 pipelineobj.SetDepthStencil(&ds_state);
1854
Tony Barbour01999182015-04-09 12:58:51 -06001855 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001856 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001857
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001858#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001859 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001860 MESH_BUF_ID, // Binding ID
1861 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001862 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001863 };
Tony Barbourf43b6982014-11-25 13:18:32 -07001864
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001865 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001866 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1867 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001868 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001869 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1870 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1871 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001872 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001873 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001874
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001875 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001876 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001877 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001878
Tony Barbour17c6ab12015-03-27 17:03:18 -06001879 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour17c6ab12015-03-27 17:03:18 -06001880
Tony Barbour01999182015-04-09 12:58:51 -06001881 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -07001882 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001883
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001884 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001885 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001886
Tony Barboure4ed9942015-01-09 10:06:53 -07001887 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1888#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001889 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barboure4ed9942015-01-09 10:06:53 -07001890 pDSDumpDot((char*)"triTest2.dot");
1891#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001892
1893 // render triangles
Tony Barboure4ed9942015-01-09 10:06:53 -07001894 cmdBuffer.Draw(0, 36, 0, 1);
1895
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001896
Tony Barboure4ed9942015-01-09 10:06:53 -07001897 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001898 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001899 cmdBuffer.QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -07001900
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001901 RecordImages(m_renderTargets);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001902}
1903
Tony Barbour01999182015-04-09 12:58:51 -06001904TEST_F(VkRenderTest, VSTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07001905{
1906 // The expected result from this test is a green and red triangle;
1907 // one red vertex on the left, two green vertices on the right.
1908 static const char *vertShaderText =
1909 "#version 130\n"
1910 "out vec4 texColor;\n"
1911 "uniform sampler2D surface;\n"
1912 "void main() {\n"
1913 " vec2 vertices[3];"
1914 " vertices[0] = vec2(-0.5, -0.5);\n"
1915 " vertices[1] = vec2( 0.5, -0.5);\n"
1916 " vertices[2] = vec2( 0.5, 0.5);\n"
1917 " vec2 positions[3];"
1918 " positions[0] = vec2( 0.0, 0.0);\n"
1919 " positions[1] = vec2( 0.25, 0.1);\n"
1920 " positions[2] = vec2( 0.1, 0.25);\n"
1921 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1922 " texColor = textureLod(surface, samplePos, 0.0);\n"
1923 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1924 "}\n";
1925
1926 static const char *fragShaderText =
1927 "#version 130\n"
1928 "in vec4 texColor;\n"
1929 "void main() {\n"
1930 " gl_FragColor = texColor;\n"
1931 "}\n";
1932
1933 ASSERT_NO_FATAL_FAILURE(InitState());
1934 ASSERT_NO_FATAL_FAILURE(InitViewport());
1935
Tony Barbour01999182015-04-09 12:58:51 -06001936 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1937 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
1938 VkSamplerObj sampler(m_device);
1939 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001940
Tony Barbour01999182015-04-09 12:58:51 -06001941 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001942 pipelineobj.AddShader(&vs);
1943 pipelineobj.AddShader(&ps);
1944
Tony Barbour01999182015-04-09 12:58:51 -06001945 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001946 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001947
Tony Barbourdd4c9642015-01-09 12:55:14 -07001948 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001949 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001950 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001951
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001952 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001953
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001954 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001955
1956#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001957 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001958 pDSDumpDot((char*)"triTest2.dot");
1959#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001960
Tony Barbourdd4c9642015-01-09 12:55:14 -07001961 // render triangle
1962 cmdBuffer.Draw(0, 3, 0, 1);
1963
1964 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001965 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001966 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001967
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001968 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001969}
Tony Barbour01999182015-04-09 12:58:51 -06001970TEST_F(VkRenderTest, TexturedTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07001971{
1972 // The expected result from this test is a red and green checkered triangle
1973 static const char *vertShaderText =
1974 "#version 140\n"
1975 "#extension GL_ARB_separate_shader_objects : enable\n"
1976 "#extension GL_ARB_shading_language_420pack : enable\n"
1977 "layout (location = 0) out vec2 samplePos;\n"
1978 "void main() {\n"
1979 " vec2 vertices[3];"
1980 " vertices[0] = vec2(-0.5, -0.5);\n"
1981 " vertices[1] = vec2( 0.5, -0.5);\n"
1982 " vertices[2] = vec2( 0.5, 0.5);\n"
1983 " vec2 positions[3];"
1984 " positions[0] = vec2( 0.0, 0.0);\n"
1985 " positions[1] = vec2( 1.0, 0.0);\n"
1986 " positions[2] = vec2( 1.0, 1.0);\n"
1987 " samplePos = positions[gl_VertexID % 3];\n"
1988 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1989 "}\n";
1990
1991 static const char *fragShaderText =
1992 "#version 140\n"
1993 "#extension GL_ARB_separate_shader_objects : enable\n"
1994 "#extension GL_ARB_shading_language_420pack : enable\n"
1995 "layout (location = 0) in vec2 samplePos;\n"
1996 "layout (binding = 0) uniform sampler2D surface;\n"
1997 "layout (location=0) out vec4 outColor;\n"
1998 "void main() {\n"
1999 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2000 " outColor = texColor;\n"
2001 "}\n";
2002
2003 ASSERT_NO_FATAL_FAILURE(InitState());
2004 ASSERT_NO_FATAL_FAILURE(InitViewport());
2005
Tony Barbour01999182015-04-09 12:58:51 -06002006 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2007 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2008 VkSamplerObj sampler(m_device);
2009 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002010
Tony Barbour01999182015-04-09 12:58:51 -06002011 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002012 pipelineobj.AddShader(&vs);
2013 pipelineobj.AddShader(&ps);
2014
Tony Barbour01999182015-04-09 12:58:51 -06002015 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002016 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002017
Tony Barbourdd4c9642015-01-09 12:55:14 -07002018 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002019 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002020 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2021
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002022 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002023
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002024 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002025
2026#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002027 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002028 pDSDumpDot((char*)"triTest2.dot");
2029#endif
2030 // render triangle
2031 cmdBuffer.Draw(0, 3, 0, 1);
2032
2033 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002034 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002035 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002036
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002037 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002038}
Tony Barbour01999182015-04-09 12:58:51 -06002039TEST_F(VkRenderTest, TexturedTriangleClip)
Tony Barbourf43b6982014-11-25 13:18:32 -07002040{
2041 // The expected result from this test is a red and green checkered triangle
2042 static const char *vertShaderText =
2043 "#version 330\n"
2044 "#extension GL_ARB_separate_shader_objects : enable\n"
2045 "#extension GL_ARB_shading_language_420pack : enable\n"
2046 "layout (location = 0) out vec2 samplePos;\n"
2047 "out gl_PerVertex {\n"
2048 " vec4 gl_Position;\n"
2049 " float gl_ClipDistance[1];\n"
2050 "};\n"
2051 "void main() {\n"
2052 " vec2 vertices[3];"
2053 " vertices[0] = vec2(-0.5, -0.5);\n"
2054 " vertices[1] = vec2( 0.5, -0.5);\n"
2055 " vertices[2] = vec2( 0.5, 0.5);\n"
2056 " vec2 positions[3];"
2057 " positions[0] = vec2( 0.0, 0.0);\n"
2058 " positions[1] = vec2( 1.0, 0.0);\n"
2059 " positions[2] = vec2( 1.0, 1.0);\n"
2060 " float dists[3];\n"
2061 " dists[0] = 1.0;\n"
2062 " dists[1] = 1.0;\n"
2063 " dists[2] = -1.0;\n"
2064 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2065 " samplePos = positions[gl_VertexID % 3];\n"
2066 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2067 "}\n";
2068
2069 static const char *fragShaderText =
2070 "#version 140\n"
2071 "#extension GL_ARB_separate_shader_objects : enable\n"
2072 "#extension GL_ARB_shading_language_420pack : enable\n"
2073 "layout (location = 0) in vec2 samplePos;\n"
2074 "layout (binding = 0) uniform sampler2D surface;\n"
2075 "layout (location=0) out vec4 outColor;\n"
2076 "void main() {\n"
2077 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2078 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2079 " outColor = texColor;\n"
2080 "}\n";
2081
2082
2083 ASSERT_NO_FATAL_FAILURE(InitState());
2084 ASSERT_NO_FATAL_FAILURE(InitViewport());
2085
Tony Barbour01999182015-04-09 12:58:51 -06002086 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2087 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2088 VkSamplerObj sampler(m_device);
2089 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002090
Tony Barbour01999182015-04-09 12:58:51 -06002091 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002092 pipelineobj.AddShader(&vs);
2093 pipelineobj.AddShader(&ps);
2094
Tony Barbour01999182015-04-09 12:58:51 -06002095 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002096 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002097
Tony Barbourdd4c9642015-01-09 12:55:14 -07002098 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002099 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002100 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2101
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002102 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002103
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002104 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002105
2106#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002107 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002108 pDSDumpDot((char*)"triTest2.dot");
2109#endif
2110 // render triangle
2111 cmdBuffer.Draw(0, 3, 0, 1);
2112
2113 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002114 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002115 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002116
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002117 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002118}
Tony Barbour01999182015-04-09 12:58:51 -06002119TEST_F(VkRenderTest, FSTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002120{
2121 // The expected result from this test is a red and green checkered triangle
2122 static const char *vertShaderText =
2123 "#version 140\n"
2124 "#extension GL_ARB_separate_shader_objects : enable\n"
2125 "#extension GL_ARB_shading_language_420pack : enable\n"
2126 "layout (location = 0) out vec2 samplePos;\n"
2127 "void main() {\n"
2128 " vec2 vertices[3];"
2129 " vertices[0] = vec2(-0.5, -0.5);\n"
2130 " vertices[1] = vec2( 0.5, -0.5);\n"
2131 " vertices[2] = vec2( 0.5, 0.5);\n"
2132 " vec2 positions[3];"
2133 " positions[0] = vec2( 0.0, 0.0);\n"
2134 " positions[1] = vec2( 1.0, 0.0);\n"
2135 " positions[2] = vec2( 1.0, 1.0);\n"
2136 " samplePos = positions[gl_VertexID % 3];\n"
2137 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2138 "}\n";
2139
2140 static const char *fragShaderText =
2141 "#version 140\n"
2142 "#extension GL_ARB_separate_shader_objects : enable\n"
2143 "#extension GL_ARB_shading_language_420pack : enable\n"
2144 "layout (location = 0) in vec2 samplePos;\n"
2145 "layout (binding = 0) uniform sampler2D surface;\n"
2146 "layout (location=0) out vec4 outColor;\n"
2147 "void main() {\n"
2148 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2149 " outColor = texColor;\n"
2150 "}\n";
2151
2152 ASSERT_NO_FATAL_FAILURE(InitState());
2153 ASSERT_NO_FATAL_FAILURE(InitViewport());
2154
Tony Barbour01999182015-04-09 12:58:51 -06002155 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2156 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2157 VkSamplerObj sampler(m_device);
2158 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002159
Tony Barbour01999182015-04-09 12:58:51 -06002160 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002161 pipelineobj.AddShader(&vs);
2162 pipelineobj.AddShader(&ps);
2163
Tony Barbour01999182015-04-09 12:58:51 -06002164 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002165 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002166
Tony Barbourdd4c9642015-01-09 12:55:14 -07002167 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002168 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002169 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2170
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002171 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002172
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002173 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002174
2175#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002176 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002177 pDSDumpDot((char*)"triTest2.dot");
2178#endif
2179 // render triangle
2180 cmdBuffer.Draw(0, 3, 0, 1);
2181
2182 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002183 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002184 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002185
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002186 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002187}
Tony Barbour01999182015-04-09 12:58:51 -06002188TEST_F(VkRenderTest, SamplerBindingsTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002189{
2190 // This test sets bindings on the samplers
2191 // For now we are asserting that sampler and texture pairs
2192 // march in lock step, and are set via GLSL binding. This can
2193 // and will probably change.
2194 // The sampler bindings should match the sampler and texture slot
2195 // number set up by the application.
2196 // This test will result in a blue triangle
2197 static const char *vertShaderText =
2198 "#version 140\n"
2199 "#extension GL_ARB_separate_shader_objects : enable\n"
2200 "#extension GL_ARB_shading_language_420pack : enable\n"
2201 "layout (location = 0) out vec4 samplePos;\n"
2202 "void main() {\n"
2203 " vec2 vertices[3];"
2204 " vertices[0] = vec2(-0.5, -0.5);\n"
2205 " vertices[1] = vec2( 0.5, -0.5);\n"
2206 " vertices[2] = vec2( 0.5, 0.5);\n"
2207 " vec2 positions[3];"
2208 " positions[0] = vec2( 0.0, 0.0);\n"
2209 " positions[1] = vec2( 1.0, 0.0);\n"
2210 " positions[2] = vec2( 1.0, 1.0);\n"
2211 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2212 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2213 "}\n";
2214
2215 static const char *fragShaderText =
2216 "#version 140\n"
2217 "#extension GL_ARB_separate_shader_objects : enable\n"
2218 "#extension GL_ARB_shading_language_420pack : enable\n"
2219 "layout (location = 0) in vec4 samplePos;\n"
2220 "layout (binding = 0) uniform sampler2D surface0;\n"
2221 "layout (binding = 1) uniform sampler2D surface1;\n"
2222 "layout (binding = 12) uniform sampler2D surface2;\n"
2223 "void main() {\n"
2224 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
2225 "}\n";
2226
2227 ASSERT_NO_FATAL_FAILURE(InitState());
2228 ASSERT_NO_FATAL_FAILURE(InitViewport());
2229
Tony Barbour01999182015-04-09 12:58:51 -06002230 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2231 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002232
Tony Barbour01999182015-04-09 12:58:51 -06002233 VkSamplerObj sampler1(m_device);
2234 VkSamplerObj sampler2(m_device);
2235 VkSamplerObj sampler3(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002236
Tony Barbour2f421a02015-04-01 16:38:10 -06002237 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
Tony Barbour01999182015-04-09 12:58:51 -06002238 VkTextureObj texture1(m_device, tex_colors); // Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002239 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
Tony Barbour01999182015-04-09 12:58:51 -06002240 VkTextureObj texture2(m_device, tex_colors); // Green
Tony Barbour2f421a02015-04-01 16:38:10 -06002241 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
Tony Barbour01999182015-04-09 12:58:51 -06002242 VkTextureObj texture3(m_device, tex_colors); // Blue
Tony Barbourf43b6982014-11-25 13:18:32 -07002243
Tony Barbour01999182015-04-09 12:58:51 -06002244 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002245 pipelineobj.AddShader(&vs);
2246 pipelineobj.AddShader(&ps);
2247
Tony Barbour01999182015-04-09 12:58:51 -06002248 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002249 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2250 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2251 for (int i = 0; i < 10; i++)
2252 descriptorSet.AppendDummy();
2253 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002254
Tony Barbourdd4c9642015-01-09 12:55:14 -07002255 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002256 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002257 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2258
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002259 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002260
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002261 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002262
2263#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002264 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002265 pDSDumpDot((char*)"triTest2.dot");
2266#endif
2267 // render triangle
2268 cmdBuffer.Draw(0, 3, 0, 1);
2269
2270 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002271 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002272 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002273
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002274 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002275}
2276
Tony Barbour01999182015-04-09 12:58:51 -06002277TEST_F(VkRenderTest, TriangleVSUniformBlock)
Tony Barbourf43b6982014-11-25 13:18:32 -07002278{
2279 // The expected result from this test is a blue triangle
2280
2281 static const char *vertShaderText =
2282 "#version 140\n"
2283 "#extension GL_ARB_separate_shader_objects : enable\n"
2284 "#extension GL_ARB_shading_language_420pack : enable\n"
2285 "layout (location = 0) out vec4 outColor;\n"
2286 "layout (std140, binding = 0) uniform bufferVals {\n"
2287 " vec4 red;\n"
2288 " vec4 green;\n"
2289 " vec4 blue;\n"
2290 " vec4 white;\n"
2291 "} myBufferVals;\n"
2292 "void main() {\n"
2293 " vec2 vertices[3];"
2294 " vertices[0] = vec2(-0.5, -0.5);\n"
2295 " vertices[1] = vec2( 0.5, -0.5);\n"
2296 " vertices[2] = vec2( 0.5, 0.5);\n"
2297 " outColor = myBufferVals.blue;\n"
2298 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2299 "}\n";
2300
2301 static const char *fragShaderText =
2302 "#version 140\n"
2303 "#extension GL_ARB_separate_shader_objects : enable\n"
2304 "#extension GL_ARB_shading_language_420pack : enable\n"
2305 "layout (location = 0) in vec4 inColor;\n"
2306 "void main() {\n"
2307 " gl_FragColor = inColor;\n"
2308 "}\n";
2309
2310 ASSERT_NO_FATAL_FAILURE(InitState());
2311 ASSERT_NO_FATAL_FAILURE(InitViewport());
2312
Tony Barbour01999182015-04-09 12:58:51 -06002313 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2314 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002315
2316 // Let's populate our buffer with the following:
2317 // vec4 red;
2318 // vec4 green;
2319 // vec4 blue;
2320 // vec4 white;
2321 const int valCount = 4 * 4;
2322 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2323 0.0, 1.0, 0.0, 1.0,
2324 0.0, 0.0, 1.0, 1.0,
2325 1.0, 1.0, 1.0, 1.0 };
2326
Tony Barbour01999182015-04-09 12:58:51 -06002327 VkConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002328
Tony Barbour01999182015-04-09 12:58:51 -06002329 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002330 pipelineobj.AddShader(&vs);
2331 pipelineobj.AddShader(&ps);
2332
Tony Barbour01999182015-04-09 12:58:51 -06002333 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002334 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002335
Tony Barbourdd4c9642015-01-09 12:55:14 -07002336 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002337 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002338 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2339
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002340 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002341
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002342 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002343
2344#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002345 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002346 pDSDumpDot((char*)"triTest2.dot");
2347#endif
2348 // render triangle
2349 cmdBuffer.Draw(0, 3, 0, 1);
2350
2351 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002352 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002353 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002354
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002355 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002356}
2357
Tony Barbour01999182015-04-09 12:58:51 -06002358TEST_F(VkRenderTest, TriangleFSUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002359{
2360 // This test allows the shader to select which buffer it is
2361 // pulling from using layout binding qualifier.
2362 // There are corresponding changes in the compiler stack that
2363 // will select the buffer using binding directly.
2364 // The binding number should match the slot number set up by
2365 // the application.
2366 // The expected result from this test is a purple triangle
2367
2368 static const char *vertShaderText =
2369 "#version 140\n"
2370 "#extension GL_ARB_separate_shader_objects : enable\n"
2371 "#extension GL_ARB_shading_language_420pack : enable\n"
2372 "void main() {\n"
2373 " vec2 vertices[3];"
2374 " vertices[0] = vec2(-0.5, -0.5);\n"
2375 " vertices[1] = vec2( 0.5, -0.5);\n"
2376 " vertices[2] = vec2( 0.5, 0.5);\n"
2377 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2378 "}\n";
2379
2380 static const char *fragShaderText =
2381 "#version 140\n"
2382 "#extension GL_ARB_separate_shader_objects : enable\n"
2383 "#extension GL_ARB_shading_language_420pack : enable\n"
2384 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2385 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2386 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002387 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
Tony Barbourf43b6982014-11-25 13:18:32 -07002388 "void main() {\n"
2389 " gl_FragColor = myBlueVal.color;\n"
2390 " gl_FragColor += myRedVal.color;\n"
2391 "}\n";
2392
2393 ASSERT_NO_FATAL_FAILURE(InitState());
2394 ASSERT_NO_FATAL_FAILURE(InitViewport());
2395
Tony Barbour01999182015-04-09 12:58:51 -06002396 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2397 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002398
2399 // We're going to create a number of uniform buffers, and then allow
2400 // the shader to select which it wants to read from with a binding
2401
2402 // Let's populate the buffers with a single color each:
2403 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2404 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2405 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002406 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002407
2408 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2409 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2410 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2411 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2412
2413 const int redCount = sizeof(redVals) / sizeof(float);
2414 const int greenCount = sizeof(greenVals) / sizeof(float);
2415 const int blueCount = sizeof(blueVals) / sizeof(float);
2416 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2417
Tony Barbour01999182015-04-09 12:58:51 -06002418 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002419
Tony Barbour01999182015-04-09 12:58:51 -06002420 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002421
Tony Barbour01999182015-04-09 12:58:51 -06002422 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002423
Tony Barbour01999182015-04-09 12:58:51 -06002424 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002425
Tony Barbour01999182015-04-09 12:58:51 -06002426 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002427 pipelineobj.AddShader(&vs);
2428 pipelineobj.AddShader(&ps);
2429
Tony Barbour01999182015-04-09 12:58:51 -06002430 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002431 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2432 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2433 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2434 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002435
Tony Barbourdd4c9642015-01-09 12:55:14 -07002436 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002437 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002438 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002439
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002440 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002441
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002442 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002443
2444#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002445 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002446 pDSDumpDot((char*)"triTest2.dot");
2447#endif
2448 // render triangle
2449 cmdBuffer.Draw(0, 3, 0, 1);
2450
2451 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002452 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002453 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002454
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002455 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002456}
2457
Tony Barbour01999182015-04-09 12:58:51 -06002458TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002459{
2460 // This test is the same as TriangleFSUniformBlockBinding, but
2461 // it does not provide an instance name.
2462 // The expected result from this test is a purple triangle
2463
2464 static const char *vertShaderText =
2465 "#version 140\n"
2466 "#extension GL_ARB_separate_shader_objects : enable\n"
2467 "#extension GL_ARB_shading_language_420pack : enable\n"
2468 "void main() {\n"
2469 " vec2 vertices[3];"
2470 " vertices[0] = vec2(-0.5, -0.5);\n"
2471 " vertices[1] = vec2( 0.5, -0.5);\n"
2472 " vertices[2] = vec2( 0.5, 0.5);\n"
2473 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2474 "}\n";
2475
2476 static const char *fragShaderText =
2477 "#version 430\n"
2478 "#extension GL_ARB_separate_shader_objects : enable\n"
2479 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002480 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2481 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2482 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002483 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002484 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002485 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002486 " outColor = blue;\n"
2487 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002488 "}\n";
2489 ASSERT_NO_FATAL_FAILURE(InitState());
2490 ASSERT_NO_FATAL_FAILURE(InitViewport());
2491
Tony Barbour01999182015-04-09 12:58:51 -06002492 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2493 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002494
2495 // We're going to create a number of uniform buffers, and then allow
2496 // the shader to select which it wants to read from with a binding
2497
2498 // Let's populate the buffers with a single color each:
2499 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2500 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2501 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2502 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2503
2504 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2505 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2506 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2507 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2508
2509 const int redCount = sizeof(redVals) / sizeof(float);
2510 const int greenCount = sizeof(greenVals) / sizeof(float);
2511 const int blueCount = sizeof(blueVals) / sizeof(float);
2512 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2513
Tony Barbour01999182015-04-09 12:58:51 -06002514 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002515
Tony Barbour01999182015-04-09 12:58:51 -06002516 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002517
Tony Barbour01999182015-04-09 12:58:51 -06002518 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002519
Tony Barbour01999182015-04-09 12:58:51 -06002520 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002521
Tony Barbour01999182015-04-09 12:58:51 -06002522 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002523 pipelineobj.AddShader(&vs);
2524 pipelineobj.AddShader(&ps);
2525
Tony Barbour01999182015-04-09 12:58:51 -06002526 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002527 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2528 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2529 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2530 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002531
Tony Barbourdd4c9642015-01-09 12:55:14 -07002532 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002533 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002534 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2535
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002536 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002537
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002538 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002539
2540#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002541 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002542 pDSDumpDot((char*)"triTest2.dot");
2543#endif
2544 // render triangle
2545 cmdBuffer.Draw(0, 3, 0, 1);
2546
2547 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002548 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002549 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002550
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002551 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002552}
2553
Tony Barbour01999182015-04-09 12:58:51 -06002554TEST_F(VkRenderTest, CubeWithVertexFetchAndMVPAndTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07002555{
2556 static const char *vertShaderText =
2557 "#version 140\n"
2558 "#extension GL_ARB_separate_shader_objects : enable\n"
2559 "#extension GL_ARB_shading_language_420pack : enable\n"
2560 "layout (std140, binding=0) uniform bufferVals {\n"
2561 " mat4 mvp;\n"
2562 "} myBufferVals;\n"
2563 "layout (location=0) in vec4 pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002564 "layout (location=1) in vec2 input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002565 "layout (location=0) out vec2 UV;\n"
2566 "void main() {\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002567 " UV = input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002568 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002569 " gl_Position.y = -gl_Position.y;\n"
2570 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002571 "}\n";
2572
2573 static const char *fragShaderText =
2574 "#version 140\n"
2575 "#extension GL_ARB_separate_shader_objects : enable\n"
2576 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002577 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002578 "layout (location=0) out vec4 outColor;\n"
2579 "layout (location=0) in vec2 UV;\n"
2580 "void main() {\n"
2581 " outColor= textureLod(surface, UV, 0.0);\n"
2582 "}\n";
2583 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2584
2585 glm::mat4 View = glm::lookAt(
2586 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2587 glm::vec3(0,0,0), // and looks at the origin
2588 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2589 );
2590
2591 glm::mat4 Model = glm::mat4(1.0f);
2592
2593 glm::mat4 MVP = Projection * View * Model;
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002594 int num_verts = sizeof(g_vb_texture_Data) / sizeof(g_vb_texture_Data[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002595
2596
2597 ASSERT_NO_FATAL_FAILURE(InitState());
2598 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour8bef8ee2015-05-22 09:44:58 -06002599 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07002600
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002601 VkConstantBufferObj meshBuffer(m_device, num_verts,
2602 sizeof(g_vb_texture_Data[0]), g_vb_texture_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002603 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002604
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002605 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07002606
Tony Barbour01999182015-04-09 12:58:51 -06002607 VkConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2608 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2609 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2610 VkSamplerObj sampler(m_device);
2611 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002612
Tony Barbour01999182015-04-09 12:58:51 -06002613 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002614 pipelineobj.AddShader(&vs);
2615 pipelineobj.AddShader(&ps);
2616
Tony Barbour01999182015-04-09 12:58:51 -06002617 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002618 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mvpBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002619 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002620
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002621#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002622 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002623 MESH_BIND_ID, // binding ID
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002624 sizeof(g_vb_texture_Data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002625 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002626 };
Tony Barbourf43b6982014-11-25 13:18:32 -07002627
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002628 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002629 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2630 vi_attribs[0].location = 0; // location
Tony Barbour8205d902015-04-16 15:59:00 -06002631 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002632 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2633 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2634 vi_attribs[1].location = 1; // location
2635 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
2636 vi_attribs[1].offsetInBytes = 16; // Offset of uv components
Tony Barbourf43b6982014-11-25 13:18:32 -07002637
Tony Barbourf43b6982014-11-25 13:18:32 -07002638 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002639 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2640 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07002641
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002642 VkPipelineDsStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002643 ds_state.depthTestEnable = VK_TRUE;
2644 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06002645 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002646 ds_state.depthBoundsEnable = VK_FALSE;
2647 ds_state.stencilTestEnable = VK_FALSE;
2648 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
2649 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
2650 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06002651 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
2652 ds_state.format = VK_FORMAT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002653 ds_state.front = ds_state.back;
2654 pipelineobj.SetDepthStencil(&ds_state);
2655
Tony Barbour17c6ab12015-03-27 17:03:18 -06002656 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour01999182015-04-09 12:58:51 -06002657 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002658 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002659
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002660 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002661
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002662 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002663
2664 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2665#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002666 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002667 pDSDumpDot((char*)"triTest2.dot");
2668#endif
2669 // render triangle
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002670 cmdBuffer.Draw(0, num_verts, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002671
2672 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002673 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002674 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002675
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002676 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002677 RotateTriangleVSUniform(Projection, View, Model, &mvpBuffer, &cmdBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002678}
Cody Northropd1ce7842014-12-09 11:17:01 -07002679
Tony Barbour01999182015-04-09 12:58:51 -06002680TEST_F(VkRenderTest, TriangleMixedSamplerUniformBlockBinding)
Cody Northropd1ce7842014-12-09 11:17:01 -07002681{
2682 // This test mixes binding slots of textures and buffers, ensuring
2683 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002684 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002685 // you can modify it to move the desired result around.
2686
2687 static const char *vertShaderText =
2688 "#version 140\n"
2689 "#extension GL_ARB_separate_shader_objects : enable\n"
2690 "#extension GL_ARB_shading_language_420pack : enable\n"
2691 "void main() {\n"
2692 " vec2 vertices[3];"
2693 " vertices[0] = vec2(-0.5, -0.5);\n"
2694 " vertices[1] = vec2( 0.5, -0.5);\n"
2695 " vertices[2] = vec2( 0.5, 0.5);\n"
2696 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2697 "}\n";
2698
2699 static const char *fragShaderText =
2700 "#version 430\n"
2701 "#extension GL_ARB_separate_shader_objects : enable\n"
2702 "#extension GL_ARB_shading_language_420pack : enable\n"
2703 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002704 "layout (binding = 3) uniform sampler2D surface1;\n"
2705 "layout (binding = 1) uniform sampler2D surface2;\n"
2706 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002707
Cody Northropa0410942014-12-09 13:59:39 -07002708
Chia-I Wuf8385062015-01-04 16:27:24 +08002709 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2710 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2711 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2712 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002713 "layout (location = 0) out vec4 outColor;\n"
2714 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002715 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002716 " outColor += white * vec4(0.00001);\n"
2717 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002718 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002719 "}\n";
2720 ASSERT_NO_FATAL_FAILURE(InitState());
2721 ASSERT_NO_FATAL_FAILURE(InitViewport());
2722
Tony Barbour01999182015-04-09 12:58:51 -06002723 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2724 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northropd1ce7842014-12-09 11:17:01 -07002725
Cody Northropd1ce7842014-12-09 11:17:01 -07002726 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2727 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2728 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2729 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2730
2731 const int redCount = sizeof(redVals) / sizeof(float);
2732 const int greenCount = sizeof(greenVals) / sizeof(float);
2733 const int blueCount = sizeof(blueVals) / sizeof(float);
2734 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2735
Tony Barbour01999182015-04-09 12:58:51 -06002736 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2737 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2738 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2739 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002740
Tony Barbour2f421a02015-04-01 16:38:10 -06002741 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002742 VkSamplerObj sampler0(m_device);
2743 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002744 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002745 VkSamplerObj sampler2(m_device);
2746 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002747 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002748 VkSamplerObj sampler4(m_device);
2749 VkTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropa0410942014-12-09 13:59:39 -07002750
2751 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2752 // TODO: Get back here ASAP and understand why.
Tony Barbour2f421a02015-04-01 16:38:10 -06002753 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06002754 VkSamplerObj sampler7(m_device);
2755 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropd1ce7842014-12-09 11:17:01 -07002756
Tony Barbour01999182015-04-09 12:58:51 -06002757 VkPipelineObj pipelineobj(m_device);
Cody Northropd1ce7842014-12-09 11:17:01 -07002758 pipelineobj.AddShader(&vs);
2759 pipelineobj.AddShader(&ps);
2760
Tony Barbour01999182015-04-09 12:58:51 -06002761 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002762 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2763 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2764 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2765 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002766 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002767 // swap blue and green
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002768 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2769 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2770 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002771
Tony Barbourdd4c9642015-01-09 12:55:14 -07002772 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002773 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002774 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002775
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002776 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002777
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002778 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002779
2780#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002781 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002782 pDSDumpDot((char*)"triTest2.dot");
2783#endif
2784 // render triangle
2785 cmdBuffer.Draw(0, 3, 0, 1);
2786
2787 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002788 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002789 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002790
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002791 RecordImages(m_renderTargets);
Cody Northropd1ce7842014-12-09 11:17:01 -07002792}
2793
Tony Barbour01999182015-04-09 12:58:51 -06002794TEST_F(VkRenderTest, TriangleMatchingSamplerUniformBlockBinding)
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002795{
2796 // This test matches binding slots of textures and buffers, requiring
2797 // the driver to give them distinct number spaces.
2798 // The expected result from this test is a red triangle, although
2799 // you can modify it to move the desired result around.
2800
2801 static const char *vertShaderText =
2802 "#version 140\n"
2803 "#extension GL_ARB_separate_shader_objects : enable\n"
2804 "#extension GL_ARB_shading_language_420pack : enable\n"
2805 "void main() {\n"
2806 " vec2 vertices[3];"
2807 " vertices[0] = vec2(-0.5, -0.5);\n"
2808 " vertices[1] = vec2( 0.5, -0.5);\n"
2809 " vertices[2] = vec2( 0.5, 0.5);\n"
2810 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2811 "}\n";
2812
2813 static const char *fragShaderText =
2814 "#version 430\n"
2815 "#extension GL_ARB_separate_shader_objects : enable\n"
2816 "#extension GL_ARB_shading_language_420pack : enable\n"
2817 "layout (binding = 0) uniform sampler2D surface0;\n"
2818 "layout (binding = 1) uniform sampler2D surface1;\n"
2819 "layout (binding = 2) uniform sampler2D surface2;\n"
2820 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002821 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2822 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2823 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2824 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002825 "layout (location = 0) out vec4 outColor;\n"
2826 "void main() {\n"
2827 " outColor = red;// * vec4(0.00001);\n"
2828 " outColor += white * vec4(0.00001);\n"
2829 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2830 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2831 "}\n";
2832 ASSERT_NO_FATAL_FAILURE(InitState());
2833 ASSERT_NO_FATAL_FAILURE(InitViewport());
2834
Tony Barbour01999182015-04-09 12:58:51 -06002835 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2836 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002837
2838 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2839 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2840 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2841 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2842
2843 const int redCount = sizeof(redVals) / sizeof(float);
2844 const int greenCount = sizeof(greenVals) / sizeof(float);
2845 const int blueCount = sizeof(blueVals) / sizeof(float);
2846 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2847
Tony Barbour01999182015-04-09 12:58:51 -06002848 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2849 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2850 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2851 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002852
Tony Barbour2f421a02015-04-01 16:38:10 -06002853 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002854 VkSamplerObj sampler0(m_device);
2855 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002856 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002857 VkSamplerObj sampler2(m_device);
2858 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002859 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002860 VkSamplerObj sampler4(m_device);
2861 VkTextureObj texture4(m_device, tex_colors); // Light Green
Tony Barbour2f421a02015-04-01 16:38:10 -06002862 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06002863 VkSamplerObj sampler7(m_device);
2864 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002865
Tony Barbour01999182015-04-09 12:58:51 -06002866 VkPipelineObj pipelineobj(m_device);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002867 pipelineobj.AddShader(&vs);
2868 pipelineobj.AddShader(&ps);
2869
Tony Barbour01999182015-04-09 12:58:51 -06002870 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002871 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2872 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2873 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2874 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002875 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2876 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2877 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2878 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002879
Tony Barbourdd4c9642015-01-09 12:55:14 -07002880 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002881 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002882 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002883
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002884 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002885
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002886 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002887
2888#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002889 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002890 pDSDumpDot((char*)"triTest2.dot");
2891#endif
2892 // render triangle
2893 cmdBuffer.Draw(0, 3, 0, 1);
2894
2895 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002896 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002897 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002898
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002899 RecordImages(m_renderTargets);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002900}
2901
Tony Barbour01999182015-04-09 12:58:51 -06002902TEST_F(VkRenderTest, TriangleUniformBufferLayout)
Cody Northrop02690bd2014-12-17 15:26:33 -07002903{
2904 // This test populates a buffer with a variety of different data
2905 // types, then reads them out with a shader.
2906 // The expected result from this test is a green triangle
2907
2908 static const char *vertShaderText =
2909 "#version 140\n"
2910 "#extension GL_ARB_separate_shader_objects : enable\n"
2911 "#extension GL_ARB_shading_language_420pack : enable\n"
2912 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2913 " vec4 fRed;\n"
2914 " vec4 fGreen;\n"
2915 " layout(row_major) mat4 worldToProj;\n"
2916 " layout(row_major) mat4 projToWorld;\n"
2917 " layout(row_major) mat4 worldToView;\n"
2918 " layout(row_major) mat4 viewToProj;\n"
2919 " layout(row_major) mat4 worldToShadow[4];\n"
2920 " float fZero;\n"
2921 " float fOne;\n"
2922 " float fTwo;\n"
2923 " float fThree;\n"
2924 " vec3 fZeroZeroZero;\n"
2925 " float fFour;\n"
2926 " vec3 fZeroZeroOne;\n"
2927 " float fFive;\n"
2928 " vec3 fZeroOneZero;\n"
2929 " float fSix;\n"
2930 " float fSeven;\n"
2931 " float fEight;\n"
2932 " float fNine;\n"
2933 " vec2 fZeroZero;\n"
2934 " vec2 fZeroOne;\n"
2935 " vec4 fBlue;\n"
2936 " vec2 fOneZero;\n"
2937 " vec2 fOneOne;\n"
2938 " vec3 fZeroOneOne;\n"
2939 " float fTen;\n"
2940 " float fEleven;\n"
2941 " float fTwelve;\n"
2942 " vec3 fOneZeroZero;\n"
2943 " vec4 uvOffsets[4];\n"
2944 "};\n"
2945 "layout (location = 0) out vec4 color;"
2946 "void main() {\n"
2947
2948 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2949 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2950 " \n"
2951
2952 // do some exact comparisons, even though we should
2953 // really have an epsilon involved.
2954 " vec4 outColor = right;\n"
2955 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
2956 " outColor = wrong;\n"
2957 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
2958 " outColor = wrong;\n"
2959 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
2960 " outColor = wrong;\n"
2961
2962 " color = outColor;\n"
2963
2964 // generic position stuff
2965 " vec2 vertices;\n"
2966 " int vertexSelector = gl_VertexID;\n"
2967 " if (vertexSelector == 0)\n"
2968 " vertices = vec2(-0.5, -0.5);\n"
2969 " else if (vertexSelector == 1)\n"
2970 " vertices = vec2( 0.5, -0.5);\n"
2971 " else if (vertexSelector == 2)\n"
2972 " vertices = vec2( 0.5, 0.5);\n"
2973 " else\n"
2974 " vertices = vec2( 0.0, 0.0);\n"
2975 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
2976 "}\n";
2977
2978 static const char *fragShaderText =
2979 "#version 140\n"
2980 "#extension GL_ARB_separate_shader_objects : enable\n"
2981 "#extension GL_ARB_shading_language_420pack : enable\n"
2982 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2983 " vec4 fRed;\n"
2984 " vec4 fGreen;\n"
2985 " layout(row_major) mat4 worldToProj;\n"
2986 " layout(row_major) mat4 projToWorld;\n"
2987 " layout(row_major) mat4 worldToView;\n"
2988 " layout(row_major) mat4 viewToProj;\n"
2989 " layout(row_major) mat4 worldToShadow[4];\n"
2990 " float fZero;\n"
2991 " float fOne;\n"
2992 " float fTwo;\n"
2993 " float fThree;\n"
2994 " vec3 fZeroZeroZero;\n"
2995 " float fFour;\n"
2996 " vec3 fZeroZeroOne;\n"
2997 " float fFive;\n"
2998 " vec3 fZeroOneZero;\n"
2999 " float fSix;\n"
3000 " float fSeven;\n"
3001 " float fEight;\n"
3002 " float fNine;\n"
3003 " vec2 fZeroZero;\n"
3004 " vec2 fZeroOne;\n"
3005 " vec4 fBlue;\n"
3006 " vec2 fOneZero;\n"
3007 " vec2 fOneOne;\n"
3008 " vec3 fZeroOneOne;\n"
3009 " float fTen;\n"
3010 " float fEleven;\n"
3011 " float fTwelve;\n"
3012 " vec3 fOneZeroZero;\n"
3013 " vec4 uvOffsets[4];\n"
3014 "};\n"
3015 "layout (location = 0) in vec4 color;\n"
3016 "void main() {\n"
3017 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3018 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3019 " \n"
3020
3021 // start with VS value to ensure it passed
3022 " vec4 outColor = color;\n"
3023
3024 // do some exact comparisons, even though we should
3025 // really have an epsilon involved.
3026 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3027 " outColor = wrong;\n"
3028 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3029 " outColor = wrong;\n"
3030 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3031 " outColor = wrong;\n"
3032 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3033 " outColor = wrong;\n"
3034 " if (fTwo != 2.0)\n"
3035 " outColor = wrong;\n"
3036 " if (fOneOne != vec2(1.0, 1.0))\n"
3037 " outColor = wrong;\n"
3038 " if (fTen != 10.0)\n"
3039 " outColor = wrong;\n"
3040 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3041 " outColor = wrong;\n"
3042 " \n"
3043 " gl_FragColor = outColor;\n"
3044 "}\n";
3045
3046
3047 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3048 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3049 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3050 0.0, 1.0, 0.0, 1.0, // align
3051 0.0, 0.0, 1.0, 1.0, // align
3052 0.0, 0.0, 0.0, 1.0, // align
3053 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3054 0.0, 2.0, 0.0, 2.0, // align
3055 0.0, 0.0, 2.0, 2.0, // align
3056 0.0, 0.0, 0.0, 2.0, // align
3057 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3058 0.0, 3.0, 0.0, 3.0, // align
3059 0.0, 0.0, 3.0, 3.0, // align
3060 0.0, 0.0, 0.0, 3.0, // align
3061 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3062 0.0, 4.0, 0.0, 4.0, // align
3063 0.0, 0.0, 4.0, 4.0, // align
3064 0.0, 0.0, 0.0, 4.0, // align
3065 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3066 0.0, 5.0, 0.0, 5.0, // align
3067 0.0, 0.0, 5.0, 5.0, // align
3068 0.0, 0.0, 0.0, 5.0, // align
3069 6.0, 0.0, 0.0, 6.0, // align
3070 0.0, 6.0, 0.0, 6.0, // align
3071 0.0, 0.0, 6.0, 6.0, // align
3072 0.0, 0.0, 0.0, 6.0, // align
3073 7.0, 0.0, 0.0, 7.0, // align
3074 0.0, 7.0, 0.0, 7.0, // align
3075 0.0, 0.0, 7.0, 7.0, // align
3076 0.0, 0.0, 0.0, 7.0, // align
3077 8.0, 0.0, 0.0, 8.0, // align
3078 0.0, 8.0, 0.0, 8.0, // align
3079 0.0, 0.0, 8.0, 8.0, // align
3080 0.0, 0.0, 0.0, 8.0, // align
3081 0.0, // float fZero; // align
3082 1.0, // float fOne; // pack
3083 2.0, // float fTwo; // pack
3084 3.0, // float fThree; // pack
3085 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3086 4.0, // float fFour; // pack
3087 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3088 5.0, // float fFive; // pack
3089 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3090 6.0, // float fSix; // pack
3091 7.0, // float fSeven; // align
3092 8.0, // float fEight; // pack
3093 9.0, // float fNine; // pack
3094 0.0, // BUFFER
3095 0.0, 0.0, // vec2 fZeroZero; // align
3096 0.0, 1.0, // vec2 fZeroOne; // pack
3097 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3098 1.0, 0.0, // vec2 fOneZero; // align
3099 1.0, 1.0, // vec2 fOneOne; // pack
3100 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3101 10.0, // float fTen; // pack
3102 11.0, // float fEleven; // align
3103 12.0, // float fTwelve; // pack
3104 0.0, 0.0, // BUFFER
3105 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3106 0.0, // BUFFER
3107 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3108 0.5, 0.6, 0.7, 0.8, // align
3109 0.9, 1.0, 1.1, 1.2, // align
3110 1.3, 1.4, 1.5, 1.6, // align
3111 };
3112
3113 ASSERT_NO_FATAL_FAILURE(InitState());
3114 ASSERT_NO_FATAL_FAILURE(InitViewport());
3115
3116 const int constCount = sizeof(mixedVals) / sizeof(float);
3117
Tony Barbour01999182015-04-09 12:58:51 -06003118 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3119 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop02690bd2014-12-17 15:26:33 -07003120
Tony Barbour01999182015-04-09 12:58:51 -06003121 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003122
Tony Barbour01999182015-04-09 12:58:51 -06003123 VkPipelineObj pipelineobj(m_device);
Cody Northrop02690bd2014-12-17 15:26:33 -07003124 pipelineobj.AddShader(&vs);
3125 pipelineobj.AddShader(&ps);
3126
Tony Barbour01999182015-04-09 12:58:51 -06003127 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003128 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003129
3130 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06003131 VkCommandBufferObj cmdBuffer(m_device);
Cody Northrop02690bd2014-12-17 15:26:33 -07003132 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3133
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003134 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Cody Northrop02690bd2014-12-17 15:26:33 -07003135
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003136 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Cody Northrop02690bd2014-12-17 15:26:33 -07003137
3138#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003139 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop02690bd2014-12-17 15:26:33 -07003140 pDSDumpDot((char*)"triTest2.dot");
3141#endif
3142 // render triangle
3143 cmdBuffer.Draw(0, 3, 0, 1);
3144
3145 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003146 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003147 cmdBuffer.QueueCommandBuffer();
Cody Northrop02690bd2014-12-17 15:26:33 -07003148
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003149 RecordImages(m_renderTargets);
Cody Northrop02690bd2014-12-17 15:26:33 -07003150}
3151
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003152TEST_F(VkRenderTest, TextureGather)
3153{
3154 // This test introduces textureGather and textureGatherOffset
3155 // Each call is compared against an expected inline color result
3156 // Green triangle means everything worked as expected
3157 // Red means something went wrong
3158
3159 // disable SPV until texture gather is turned on in LunarGLASS
3160 bool saved_use_spv = VkTestFramework::m_use_spv;
3161 VkTestFramework::m_use_spv = false;
3162
3163 static const char *vertShaderText =
3164 "#version 140\n"
3165 "#extension GL_ARB_separate_shader_objects : enable\n"
3166 "#extension GL_ARB_shading_language_420pack : enable\n"
3167 "void main() {\n"
3168 " vec2 vertices[3];"
3169 " vertices[0] = vec2(-0.5, -0.5);\n"
3170 " vertices[1] = vec2( 0.5, -0.5);\n"
3171 " vertices[2] = vec2( 0.5, 0.5);\n"
3172 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
3173 "}\n";
3174
3175 static const char *fragShaderText =
3176 "#version 430\n"
3177 "#extension GL_ARB_separate_shader_objects : enable\n"
3178 "#extension GL_ARB_shading_language_420pack : enable\n"
3179 "layout (binding = 0) uniform sampler2D surface0;\n"
3180 "layout (binding = 1) uniform sampler2D surface1;\n"
3181 "layout (binding = 2) uniform sampler2D surface2;\n"
3182 "layout (binding = 3) uniform sampler2D surface3;\n"
3183 "layout (location = 0) out vec4 outColor;\n"
3184 "void main() {\n"
3185
3186 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3187 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3188
3189 " vec4 color = right;\n"
3190
3191 // Grab a normal texture sample to ensure it can work in conjuntion
3192 // with textureGather (there are some intracacies in the backend)
3193 " vec4 sampledColor = textureLod(surface2, vec2(0.5), 0.0);\n"
3194 " if (sampledColor != vec4(0.0, 0.0, 1.0, 1.0))\n"
3195 " color = wrong;\n"
3196
3197 " vec4 gatheredColor = textureGather(surface0, vec2(0.5), 0);\n"
3198 // This just grabbed four red components from a red surface
3199 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3200 " color = wrong;\n"
3201
3202 // Yes, this is using an offset of 0, we don't have enough fine grained
3203 // control of the texture contents here.
3204 " gatheredColor = textureGatherOffset(surface1, vec2(0.5), ivec2(0, 0), 1);\n"
3205 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3206 " color = wrong;\n"
3207
3208 " outColor = color;\n"
3209
3210 "}\n";
3211
3212 ASSERT_NO_FATAL_FAILURE(InitState());
3213 ASSERT_NO_FATAL_FAILURE(InitViewport());
3214
3215 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3216 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3217
3218 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
3219 VkSamplerObj sampler0(m_device);
3220 VkTextureObj texture0(m_device, tex_colors); // Red
3221 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
3222 VkSamplerObj sampler1(m_device);
3223 VkTextureObj texture1(m_device, tex_colors); // Green
3224 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
3225 VkSamplerObj sampler2(m_device);
3226 VkTextureObj texture2(m_device, tex_colors); // Blue
3227 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
3228 VkSamplerObj sampler3(m_device);
3229 VkTextureObj texture3(m_device, tex_colors); // Red and Blue
3230
3231 VkPipelineObj pipelineobj(m_device);
3232 pipelineobj.AddShader(&vs);
3233 pipelineobj.AddShader(&ps);
3234
3235 VkDescriptorSetObj descriptorSet(m_device);
3236 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3237 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
3238 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3239 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
3240
3241 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3242 VkCommandBufferObj cmdBuffer(m_device);
3243 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3244
3245 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3246
3247 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3248
3249 // render triangle
3250 cmdBuffer.Draw(0, 3, 0, 1);
3251
3252 // finalize recording of the command buffer
3253 EndCommandBuffer(cmdBuffer);
3254 cmdBuffer.QueueCommandBuffer();
3255
3256 RecordImages(m_renderTargets);
3257
3258 // restore SPV setting
3259 VkTestFramework::m_use_spv = saved_use_spv;
3260}
3261
Cody Northropa44c2ff2015-04-15 11:19:06 -06003262TEST_F(VkRenderTest, GeometryShaderHelloWorld)
3263{
3264 // This test introduces a geometry shader that simply
3265 // changes the color of each vertex to red, green, blue
3266
3267 static const char *vertShaderText =
3268 "#version 140\n"
3269 "#extension GL_ARB_separate_shader_objects : enable\n"
3270 "#extension GL_ARB_shading_language_420pack : enable\n"
3271 "layout (location = 0) out vec4 color;"
3272 "void main() {\n"
3273
3274 // VS writes out red
3275 " color = vec4(1.0, 0.0, 0.0, 1.0);\n"
3276
3277 // generic position stuff
3278 " vec2 vertices;\n"
3279 " int vertexSelector = gl_VertexID;\n"
3280 " if (vertexSelector == 0)\n"
3281 " vertices = vec2(-0.5, -0.5);\n"
3282 " else if (vertexSelector == 1)\n"
3283 " vertices = vec2( 0.5, -0.5);\n"
3284 " else if (vertexSelector == 2)\n"
3285 " vertices = vec2( 0.5, 0.5);\n"
3286 " else\n"
3287 " vertices = vec2( 0.0, 0.0);\n"
3288 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3289
3290 "}\n";
3291
3292 static const char *geomShaderText =
3293 "#version 330\n"
3294 "#extension GL_ARB_separate_shader_objects : enable\n"
3295 "#extension GL_ARB_shading_language_420pack : enable\n"
3296 "layout( triangles ) in;\n"
3297 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3298 "layout( location = 0 ) in vec4 inColor[3];\n"
3299 "layout( location = 0 ) out vec4 outColor;\n"
3300 "void main()\n"
3301 "{\n"
3302
3303 // first vertex, pass through red
3304 " gl_Position = gl_in[0].gl_Position;\n"
3305 " outColor = inColor[0];\n"
3306 " EmitVertex();\n"
3307
3308 // second vertex, green
3309 " gl_Position = gl_in[1].gl_Position;\n"
3310 " outColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3311 " EmitVertex();\n"
3312
3313 // third vertex, blue
3314 " gl_Position = gl_in[2].gl_Position;\n"
3315 " outColor = vec4(0.0, 0.0, 1.0, 1.0);\n"
3316 " EmitVertex();\n"
3317
3318 // done
3319 " EndPrimitive();\n"
3320 "}\n";
3321
3322
3323 static const char *fragShaderText =
3324 "#version 140\n"
3325 "#extension GL_ARB_separate_shader_objects : enable\n"
3326 "#extension GL_ARB_shading_language_420pack : enable\n"
3327 "layout (location = 0) in vec4 color;\n"
3328 "void main() {\n"
3329 // pass through
3330 " gl_FragColor = color;\n"
3331 "}\n";
3332
3333
3334
3335 ASSERT_NO_FATAL_FAILURE(InitState());
3336 ASSERT_NO_FATAL_FAILURE(InitViewport());
3337
3338 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3339 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3340 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3341
3342 VkPipelineObj pipelineobj(m_device);
3343 pipelineobj.AddShader(&vs);
3344 pipelineobj.AddShader(&gs);
3345 pipelineobj.AddShader(&ps);
3346
3347 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3348 VkCommandBufferObj cmdBuffer(m_device);
3349 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3350
3351 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3352
3353 VkDescriptorSetObj descriptorSet(m_device);
3354
3355 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3356
3357 // render triangle
3358 cmdBuffer.Draw(0, 3, 0, 1);
3359
3360 // finalize recording of the command buffer
3361 EndCommandBuffer(cmdBuffer);
3362 cmdBuffer.QueueCommandBuffer();
3363
3364 RecordImages(m_renderTargets);
3365}
3366
3367TEST_F(VkRenderTest, GSUniformBufferLayout)
3368{
3369 // This test is just like TriangleUniformBufferLayout but adds
3370 // geometry as a stage that also does UBO lookups
3371 // The expected result from this test is a green triangle
3372
3373 static const char *vertShaderText =
3374 "#version 140\n"
3375 "#extension GL_ARB_separate_shader_objects : enable\n"
3376 "#extension GL_ARB_shading_language_420pack : enable\n"
3377 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3378 " vec4 fRed;\n"
3379 " vec4 fGreen;\n"
3380 " layout(row_major) mat4 worldToProj;\n"
3381 " layout(row_major) mat4 projToWorld;\n"
3382 " layout(row_major) mat4 worldToView;\n"
3383 " layout(row_major) mat4 viewToProj;\n"
3384 " layout(row_major) mat4 worldToShadow[4];\n"
3385 " float fZero;\n"
3386 " float fOne;\n"
3387 " float fTwo;\n"
3388 " float fThree;\n"
3389 " vec3 fZeroZeroZero;\n"
3390 " float fFour;\n"
3391 " vec3 fZeroZeroOne;\n"
3392 " float fFive;\n"
3393 " vec3 fZeroOneZero;\n"
3394 " float fSix;\n"
3395 " float fSeven;\n"
3396 " float fEight;\n"
3397 " float fNine;\n"
3398 " vec2 fZeroZero;\n"
3399 " vec2 fZeroOne;\n"
3400 " vec4 fBlue;\n"
3401 " vec2 fOneZero;\n"
3402 " vec2 fOneOne;\n"
3403 " vec3 fZeroOneOne;\n"
3404 " float fTen;\n"
3405 " float fEleven;\n"
3406 " float fTwelve;\n"
3407 " vec3 fOneZeroZero;\n"
3408 " vec4 uvOffsets[4];\n"
3409 "};\n"
3410 "layout (location = 0) out vec4 color;"
3411 "void main() {\n"
3412
3413 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3414 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3415 " \n"
3416
3417 // do some exact comparisons, even though we should
3418 // really have an epsilon involved.
3419 " vec4 outColor = right;\n"
3420 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3421 " outColor = wrong;\n"
3422 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3423 " outColor = wrong;\n"
3424 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3425 " outColor = wrong;\n"
3426
3427 " color = outColor;\n"
3428
3429 // generic position stuff
3430 " vec2 vertices;\n"
3431 " int vertexSelector = gl_VertexID;\n"
3432 " if (vertexSelector == 0)\n"
3433 " vertices = vec2(-0.5, -0.5);\n"
3434 " else if (vertexSelector == 1)\n"
3435 " vertices = vec2( 0.5, -0.5);\n"
3436 " else if (vertexSelector == 2)\n"
3437 " vertices = vec2( 0.5, 0.5);\n"
3438 " else\n"
3439 " vertices = vec2( 0.0, 0.0);\n"
3440 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3441 "}\n";
3442
3443 static const char *geomShaderText =
3444 "#version 330\n"
3445 "#extension GL_ARB_separate_shader_objects : enable\n"
3446 "#extension GL_ARB_shading_language_420pack : enable\n"
3447
3448 // GS layout stuff
3449 "layout( triangles ) in;\n"
3450 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3451
3452 // Between stage IO
3453 "layout( location = 0 ) in vec4 inColor[3];\n"
3454 "layout( location = 0 ) out vec4 color;\n"
3455
3456 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3457 " vec4 fRed;\n"
3458 " vec4 fGreen;\n"
3459 " layout(row_major) mat4 worldToProj;\n"
3460 " layout(row_major) mat4 projToWorld;\n"
3461 " layout(row_major) mat4 worldToView;\n"
3462 " layout(row_major) mat4 viewToProj;\n"
3463 " layout(row_major) mat4 worldToShadow[4];\n"
3464 " float fZero;\n"
3465 " float fOne;\n"
3466 " float fTwo;\n"
3467 " float fThree;\n"
3468 " vec3 fZeroZeroZero;\n"
3469 " float fFour;\n"
3470 " vec3 fZeroZeroOne;\n"
3471 " float fFive;\n"
3472 " vec3 fZeroOneZero;\n"
3473 " float fSix;\n"
3474 " float fSeven;\n"
3475 " float fEight;\n"
3476 " float fNine;\n"
3477 " vec2 fZeroZero;\n"
3478 " vec2 fZeroOne;\n"
3479 " vec4 fBlue;\n"
3480 " vec2 fOneZero;\n"
3481 " vec2 fOneOne;\n"
3482 " vec3 fZeroOneOne;\n"
3483 " float fTen;\n"
3484 " float fEleven;\n"
3485 " float fTwelve;\n"
3486 " vec3 fOneZeroZero;\n"
3487 " vec4 uvOffsets[4];\n"
3488 "};\n"
3489
3490 "void main()\n"
3491 "{\n"
3492
3493 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3494 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3495
3496 // Each vertex will validate it can read VS output
3497 // then check a few values from the UBO
3498
3499 // first vertex
3500 " vec4 outColor = inColor[0];\n"
3501
3502 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3503 " outColor = wrong;\n"
3504 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3505 " outColor = wrong;\n"
3506 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3507 " outColor = wrong;\n"
3508 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3509 " outColor = wrong;\n"
3510
3511 " gl_Position = gl_in[0].gl_Position;\n"
3512 " color = outColor;\n"
3513 " EmitVertex();\n"
3514
3515 // second vertex
3516 " outColor = inColor[1];\n"
3517
3518 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3519 " outColor = wrong;\n"
3520 " if (fSix != 6.0)\n"
3521 " outColor = wrong;\n"
3522 " if (fOneOne != vec2(1.0, 1.0))\n"
3523 " outColor = wrong;\n"
3524
3525 " gl_Position = gl_in[1].gl_Position;\n"
3526 " color = outColor;\n"
3527 " EmitVertex();\n"
3528
3529 // third vertex
3530 " outColor = inColor[2];\n"
3531
3532 " if (fSeven != 7.0)\n"
3533 " outColor = wrong;\n"
3534 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3535 " outColor = wrong;\n"
3536
3537 " gl_Position = gl_in[2].gl_Position;\n"
3538 " color = outColor;\n"
3539 " EmitVertex();\n"
3540
3541 // done
3542 " EndPrimitive();\n"
3543 "}\n";
3544
3545 static const char *fragShaderText =
3546 "#version 140\n"
3547 "#extension GL_ARB_separate_shader_objects : enable\n"
3548 "#extension GL_ARB_shading_language_420pack : enable\n"
3549 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3550 " vec4 fRed;\n"
3551 " vec4 fGreen;\n"
3552 " layout(row_major) mat4 worldToProj;\n"
3553 " layout(row_major) mat4 projToWorld;\n"
3554 " layout(row_major) mat4 worldToView;\n"
3555 " layout(row_major) mat4 viewToProj;\n"
3556 " layout(row_major) mat4 worldToShadow[4];\n"
3557 " float fZero;\n"
3558 " float fOne;\n"
3559 " float fTwo;\n"
3560 " float fThree;\n"
3561 " vec3 fZeroZeroZero;\n"
3562 " float fFour;\n"
3563 " vec3 fZeroZeroOne;\n"
3564 " float fFive;\n"
3565 " vec3 fZeroOneZero;\n"
3566 " float fSix;\n"
3567 " float fSeven;\n"
3568 " float fEight;\n"
3569 " float fNine;\n"
3570 " vec2 fZeroZero;\n"
3571 " vec2 fZeroOne;\n"
3572 " vec4 fBlue;\n"
3573 " vec2 fOneZero;\n"
3574 " vec2 fOneOne;\n"
3575 " vec3 fZeroOneOne;\n"
3576 " float fTen;\n"
3577 " float fEleven;\n"
3578 " float fTwelve;\n"
3579 " vec3 fOneZeroZero;\n"
3580 " vec4 uvOffsets[4];\n"
3581 "};\n"
3582 "layout (location = 0) in vec4 color;\n"
3583 "void main() {\n"
3584 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3585 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3586 " \n"
3587
3588 // start with GS value to ensure it passed
3589 " vec4 outColor = color;\n"
3590
3591 // do some exact comparisons, even though we should
3592 // really have an epsilon involved.
3593 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3594 " outColor = wrong;\n"
3595 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3596 " outColor = wrong;\n"
3597 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3598 " outColor = wrong;\n"
3599 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3600 " outColor = wrong;\n"
3601 " if (fTwo != 2.0)\n"
3602 " outColor = wrong;\n"
3603 " if (fOneOne != vec2(1.0, 1.0))\n"
3604 " outColor = wrong;\n"
3605 " if (fTen != 10.0)\n"
3606 " outColor = wrong;\n"
3607 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3608 " outColor = wrong;\n"
3609 " \n"
3610 " gl_FragColor = outColor;\n"
3611 "}\n";
3612
3613
3614 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3615 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3616 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3617 0.0, 1.0, 0.0, 1.0, // align
3618 0.0, 0.0, 1.0, 1.0, // align
3619 0.0, 0.0, 0.0, 1.0, // align
3620 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3621 0.0, 2.0, 0.0, 2.0, // align
3622 0.0, 0.0, 2.0, 2.0, // align
3623 0.0, 0.0, 0.0, 2.0, // align
3624 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3625 0.0, 3.0, 0.0, 3.0, // align
3626 0.0, 0.0, 3.0, 3.0, // align
3627 0.0, 0.0, 0.0, 3.0, // align
3628 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3629 0.0, 4.0, 0.0, 4.0, // align
3630 0.0, 0.0, 4.0, 4.0, // align
3631 0.0, 0.0, 0.0, 4.0, // align
3632 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3633 0.0, 5.0, 0.0, 5.0, // align
3634 0.0, 0.0, 5.0, 5.0, // align
3635 0.0, 0.0, 0.0, 5.0, // align
3636 6.0, 0.0, 0.0, 6.0, // align
3637 0.0, 6.0, 0.0, 6.0, // align
3638 0.0, 0.0, 6.0, 6.0, // align
3639 0.0, 0.0, 0.0, 6.0, // align
3640 7.0, 0.0, 0.0, 7.0, // align
3641 0.0, 7.0, 0.0, 7.0, // align
3642 0.0, 0.0, 7.0, 7.0, // align
3643 0.0, 0.0, 0.0, 7.0, // align
3644 8.0, 0.0, 0.0, 8.0, // align
3645 0.0, 8.0, 0.0, 8.0, // align
3646 0.0, 0.0, 8.0, 8.0, // align
3647 0.0, 0.0, 0.0, 8.0, // align
3648 0.0, // float fZero; // align
3649 1.0, // float fOne; // pack
3650 2.0, // float fTwo; // pack
3651 3.0, // float fThree; // pack
3652 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3653 4.0, // float fFour; // pack
3654 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3655 5.0, // float fFive; // pack
3656 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3657 6.0, // float fSix; // pack
3658 7.0, // float fSeven; // align
3659 8.0, // float fEight; // pack
3660 9.0, // float fNine; // pack
3661 0.0, // BUFFER
3662 0.0, 0.0, // vec2 fZeroZero; // align
3663 0.0, 1.0, // vec2 fZeroOne; // pack
3664 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3665 1.0, 0.0, // vec2 fOneZero; // align
3666 1.0, 1.0, // vec2 fOneOne; // pack
3667 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3668 10.0, // float fTen; // pack
3669 11.0, // float fEleven; // align
3670 12.0, // float fTwelve; // pack
3671 0.0, 0.0, // BUFFER
3672 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3673 0.0, // BUFFER
3674 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3675 0.5, 0.6, 0.7, 0.8, // align
3676 0.9, 1.0, 1.1, 1.2, // align
3677 1.3, 1.4, 1.5, 1.6, // align
3678 };
3679
3680
3681
3682 ASSERT_NO_FATAL_FAILURE(InitState());
3683 ASSERT_NO_FATAL_FAILURE(InitViewport());
3684
3685 const int constCount = sizeof(mixedVals) / sizeof(float);
3686
3687 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3688 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3689 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3690
3691 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
3692
3693 VkPipelineObj pipelineobj(m_device);
3694 pipelineobj.AddShader(&vs);
3695 pipelineobj.AddShader(&gs);
3696 pipelineobj.AddShader(&ps);
3697
3698 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3699 VkCommandBufferObj cmdBuffer(m_device);
3700 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3701
3702 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3703
3704 VkDescriptorSetObj descriptorSet(m_device);
3705 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
3706
3707 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3708
3709 // render triangle
3710 cmdBuffer.Draw(0, 3, 0, 1);
3711
3712 // finalize recording of the command buffer
3713 EndCommandBuffer(cmdBuffer);
3714 cmdBuffer.QueueCommandBuffer();
3715
3716 RecordImages(m_renderTargets);
3717}
3718
3719TEST_F(VkRenderTest, GSPositions)
3720{
3721 // This test adds more inputs from the vertex shader and perturbs positions
3722 // Expected result is white triangle with weird positions
3723
3724 static const char *vertShaderText =
3725 "#version 140\n"
3726 "#extension GL_ARB_separate_shader_objects : enable\n"
3727 "#extension GL_ARB_shading_language_420pack : enable\n"
3728
3729 "layout(location = 0) out vec3 out_a;\n"
3730 "layout(location = 1) out vec3 out_b;\n"
3731 "layout(location = 2) out vec3 out_c;\n"
3732
3733 "void main() {\n"
3734
3735 // write a solid color to each
3736 " out_a = vec3(1.0, 0.0, 0.0);\n"
3737 " out_b = vec3(0.0, 1.0, 0.0);\n"
3738 " out_c = vec3(0.0, 0.0, 1.0);\n"
3739
3740 // generic position stuff
3741 " vec2 vertices;\n"
3742 " int vertexSelector = gl_VertexID;\n"
3743 " if (vertexSelector == 0)\n"
3744 " vertices = vec2(-0.5, -0.5);\n"
3745 " else if (vertexSelector == 1)\n"
3746 " vertices = vec2( 0.5, -0.5);\n"
3747 " else if (vertexSelector == 2)\n"
3748 " vertices = vec2( 0.5, 0.5);\n"
3749 " else\n"
3750 " vertices = vec2( 0.0, 0.0);\n"
3751 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3752
3753 "}\n";
3754
3755 static const char *geomShaderText =
3756 "#version 330\n"
3757 "#extension GL_ARB_separate_shader_objects : enable\n"
3758 "#extension GL_ARB_shading_language_420pack : enable\n"
3759 "layout( triangles ) in;\n"
3760 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3761
3762 "layout(location = 0) in vec3 in_a[3];\n"
3763 "layout(location = 1) in vec3 in_b[3];\n"
3764 "layout(location = 2) in vec3 in_c[3];\n"
3765
3766 "layout(location = 0) out vec3 out_a;\n"
3767 "layout(location = 1) out vec3 out_b;\n"
3768 "layout(location = 2) out vec3 out_c;\n"
3769
3770 "void main()\n"
3771 "{\n"
3772
3773 " gl_Position = gl_in[0].gl_Position;\n"
3774 " gl_Position.xy *= vec2(0.75);\n"
3775 " out_a = in_a[0];\n"
3776 " out_b = in_b[0];\n"
3777 " out_c = in_c[0];\n"
3778 " EmitVertex();\n"
3779
3780 " gl_Position = gl_in[1].gl_Position;\n"
3781 " gl_Position.xy *= vec2(1.5);\n"
3782 " out_a = in_a[1];\n"
3783 " out_b = in_b[1];\n"
3784 " out_c = in_c[1];\n"
3785 " EmitVertex();\n"
3786
3787 " gl_Position = gl_in[2].gl_Position;\n"
3788 " gl_Position.xy *= vec2(-0.1);\n"
3789 " out_a = in_a[2];\n"
3790 " out_b = in_b[2];\n"
3791 " out_c = in_c[2];\n"
3792 " EmitVertex();\n"
3793
3794 " EndPrimitive();\n"
3795 "}\n";
3796
3797
3798 static const char *fragShaderText =
3799 "#version 140\n"
3800 "#extension GL_ARB_separate_shader_objects : enable\n"
3801 "#extension GL_ARB_shading_language_420pack : enable\n"
3802
3803 "layout(location = 0) in vec3 in_a;\n"
3804 "layout(location = 1) in vec3 in_b;\n"
3805 "layout(location = 2) in vec3 in_c;\n"
3806
3807 "void main() {\n"
3808 " gl_FragColor = vec4(in_a.x, in_b.y, in_c.z, 1.0);\n"
3809 "}\n";
3810
3811
3812
3813 ASSERT_NO_FATAL_FAILURE(InitState());
3814 ASSERT_NO_FATAL_FAILURE(InitViewport());
3815
3816 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3817 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3818 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3819
3820 VkPipelineObj pipelineobj(m_device);
3821 pipelineobj.AddShader(&vs);
3822 pipelineobj.AddShader(&gs);
3823 pipelineobj.AddShader(&ps);
3824
3825 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3826 VkCommandBufferObj cmdBuffer(m_device);
3827 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3828
3829 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3830
3831 VkDescriptorSetObj descriptorSet(m_device);
3832
3833 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3834
3835 // render triangle
3836 cmdBuffer.Draw(0, 3, 0, 1);
3837
3838 // finalize recording of the command buffer
3839 EndCommandBuffer(cmdBuffer);
3840 cmdBuffer.QueueCommandBuffer();
3841
3842 RecordImages(m_renderTargets);
3843}
3844
3845TEST_F(VkRenderTest, GSTriStrip)
3846{
3847 // This test emits multiple multiple triangles using a GS
3848 // Correct result is an multicolor circle
3849
3850 static const char *vertShaderText =
3851 "#version 140\n"
3852 "#extension GL_ARB_separate_shader_objects : enable\n"
3853 "#extension GL_ARB_shading_language_420pack : enable\n"
3854
3855 "void main() {\n"
3856
3857 // generic position stuff
3858 " vec2 vertices;\n"
3859 " int vertexSelector = gl_VertexID;\n"
3860 " if (vertexSelector == 0)\n"
3861 " vertices = vec2(-0.5, -0.5);\n"
3862 " else if (vertexSelector == 1)\n"
3863 " vertices = vec2( 0.5, -0.5);\n"
3864 " else if (vertexSelector == 2)\n"
3865 " vertices = vec2( 0.5, 0.5);\n"
3866 " else\n"
3867 " vertices = vec2( 0.0, 0.0);\n"
3868 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3869
3870 "}\n";
3871
3872 static const char *geomShaderText =
3873 "#version 330\n"
3874 "#extension GL_ARB_separate_shader_objects : enable\n"
3875 "#extension GL_ARB_shading_language_420pack : enable\n"
3876 "layout( triangles ) in;\n"
3877 "layout( triangle_strip, max_vertices = 18 ) out;\n"
3878
3879 "layout(location = 0) out vec4 outColor;\n"
3880
3881 "void main()\n"
3882 "{\n"
3883 // init with first position to get zw
3884 " gl_Position = gl_in[0].gl_Position;\n"
3885
3886 " vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3887 " vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
3888 " vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
3889 " vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
3890
3891 // different color per tri
3892 " vec4[6] colors = { red, white, \n"
3893 " yellow, white, \n"
3894 " blue, white }; \n"
3895
3896 // fan out the triangles
3897 " vec2[18] positions = { vec2(0.0, 0.0), vec2(-0.5, 0.0), vec2(-0.25, -0.5), \n"
3898 " vec2(0.0, 0.0), vec2(-0.25, -0.5), vec2( 0.25, -0.5), \n"
3899 " vec2(0.0, 0.0), vec2( 0.25, -0.5), vec2( 0.5, 0.0), \n"
3900 " vec2(0.0, 0.0), vec2( 0.5, 0.0), vec2( 0.25, 0.5), \n"
3901 " vec2(0.0, 0.0), vec2( 0.25, 0.5), vec2(-0.25, 0.5), \n"
3902 " vec2(0.0, 0.0), vec2(-0.25, 0.5), vec2(-0.5, 0.0) }; \n"
3903
3904 // make a triangle list of 6
3905 " for (int i = 0; i < 6; ++i) { \n"
3906 " outColor = colors[i]; \n"
3907 " for (int j = 0; j < 3; ++j) { \n"
3908 " gl_Position.xy = positions[i * 3 + j]; \n"
3909 " EmitVertex(); \n"
3910 " } \n"
3911 " EndPrimitive();\n"
3912 " } \n"
3913
3914 "}\n";
3915
3916
3917 static const char *fragShaderText =
3918 "#version 150\n"
3919 "#extension GL_ARB_separate_shader_objects : enable\n"
3920 "#extension GL_ARB_shading_language_420pack : enable\n"
3921
3922
3923 "layout(binding = 0) uniform windowDimensions {\n"
3924 " vec4 dimensions;\n"
3925 "};\n"
3926
3927 "layout(location = 0) in vec4 inColor;\n"
3928 "layout(origin_upper_left) in vec4 gl_FragCoord;\n"
3929
3930 "void main() {\n"
3931
3932 // discard to make a nice circle
3933 " vec2 pos = abs(gl_FragCoord.xy) - vec2(dimensions.x, dimensions.y) / 2;\n"
3934 " float dist = sqrt(dot(pos, pos));\n"
3935 " if (dist > 50.0)\n"
3936 " discard;\n"
3937
3938 " gl_FragColor = inColor;\n"
3939
3940 "}\n";
3941
3942
3943
3944 ASSERT_NO_FATAL_FAILURE(InitState());
3945 ASSERT_NO_FATAL_FAILURE(InitViewport());
3946
3947 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3948 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3949 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3950
3951 VkPipelineObj pipelineobj(m_device);
3952 pipelineobj.AddShader(&vs);
3953 pipelineobj.AddShader(&gs);
3954 pipelineobj.AddShader(&ps);
3955
3956 const float dimensions[4] = { VkRenderFramework::m_width, VkRenderFramework::m_height , 0.0, 0.0};
3957
3958 VkConstantBufferObj windowDimensions(m_device, sizeof(dimensions) / sizeof(dimensions[0]), sizeof(dimensions[0]), (const void*) dimensions);
3959
3960 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3961 VkCommandBufferObj cmdBuffer(m_device);
3962 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3963
3964 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3965
3966 VkDescriptorSetObj descriptorSet(m_device);
3967 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, windowDimensions);
3968
3969 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3970
3971 // render triangle
3972 cmdBuffer.Draw(0, 3, 0, 1);
3973
3974 // finalize recording of the command buffer
3975 EndCommandBuffer(cmdBuffer);
3976 cmdBuffer.QueueCommandBuffer();
3977
3978 RecordImages(m_renderTargets);
3979}
3980
Chris Forbes23e6db62015-06-15 09:32:35 +12003981TEST_F(VkRenderTest, RenderPassLoadOpClear)
3982{
3983 ASSERT_NO_FATAL_FAILURE(InitState());
3984 ASSERT_NO_FATAL_FAILURE(InitViewport());
3985
3986 /* clear via load op to full green */
3987 m_clear_via_load_op = true;
3988 m_clear_color.useRawValue = false;
3989 m_clear_color.color.floatColor[0] = 0;
3990 m_clear_color.color.floatColor[1] = 1;
3991 m_clear_color.color.floatColor[2] = 0;
3992 m_clear_color.color.floatColor[3] = 0;
3993 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3994
3995 VkCommandBufferObj cmdBuffer(m_device);
3996 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3997 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3998 /* This command buffer contains ONLY the load op! */
3999 EndCommandBuffer(cmdBuffer);
4000 cmdBuffer.QueueCommandBuffer();
4001
4002 RecordImages(m_renderTargets);
4003}
4004
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004005int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004006 int result;
4007
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004008 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06004009 VkTestFramework::InitArgs(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004010
Chia-I Wu7133fdc2014-12-15 23:57:34 +08004011 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06004012
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004013 result = RUN_ALL_TESTS();
4014
Tony Barbour01999182015-04-09 12:58:51 -06004015 VkTestFramework::Finish();
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004016 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004017}