blob: ccffeb14cc5c6b672540de20cdb0539a5187a905 [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;
280 VkImageViewAttachInfo m_textureViewInfo;
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
Cody Northrop350727b2014-10-06 15:42:00 -0600296 memset(&m_textureViewInfo, 0, sizeof(m_textureViewInfo));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600297 m_textureViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO;
Cody Northrop350727b2014-10-06 15:42:00 -0600298
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600299 InitFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600300 }
301
302 virtual void TearDown() {
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600303 // Clean up resources before we reset
304 ShutdownFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600305 }
306};
307
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600308VkResult VkRenderTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600309{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600310 VkResult result;
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600311
312 result = cmdBuffer.BeginCommandBuffer();
313
314 /*
315 * For render test all drawing happens in a single render pass
316 * on a single command buffer.
317 */
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600318 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600319 cmdBuffer.BeginRenderPass(renderPass(), framebuffer());
320 }
321
322 return result;
323}
324
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600325VkResult VkRenderTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600326{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600327 VkResult result;
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600328
329 cmdBuffer.EndRenderPass(renderPass());
330
331 result = cmdBuffer.EndCommandBuffer();
332
333 return result;
334}
335
336
Tony Barbour01999182015-04-09 12:58:51 -0600337void VkRenderTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet)
Tony Barbour02472db2015-01-08 17:08:28 -0700338{
Tony Barbour17c6ab12015-03-27 17:03:18 -0600339 if (m_depthStencil->Initialized()) {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600340 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Tony Barbour17c6ab12015-03-27 17:03:18 -0600341 } else {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600342 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour17c6ab12015-03-27 17:03:18 -0600343 }
344
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700345 cmdBuffer->PrepareAttachments();
Tony Barbour8205d902015-04-16 15:59:00 -0600346 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_RASTER, m_stateRaster);
347 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_VIEWPORT, m_stateViewport);
348 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_COLOR_BLEND, m_colorBlend);
349 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_DEPTH_STENCIL, m_stateDepthStencil);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600350 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
351 pipelineobj.CreateVKPipeline(descriptorSet);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600352 cmdBuffer->BindPipeline(pipelineobj);
Chia-I Wu862c5572015-03-28 15:23:55 +0800353 cmdBuffer->BindDescriptorSet(descriptorSet);
Tony Barbour02472db2015-01-08 17:08:28 -0700354}
Tony Barbourf43b6982014-11-25 13:18:32 -0700355
Tony Barbour01999182015-04-09 12:58:51 -0600356void VkRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
357 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer)
Tony Barbourdd4c9642015-01-09 12:55:14 -0700358{
359 int i;
360 glm::mat4 MVP;
361 int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600362 VkResult err;
Tony Barbourdd4c9642015-01-09 12:55:14 -0700363
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600364 /* Only do 3 positions to avoid back face cull */
365 for (i = 0; i < 3; i++) {
Tony Barbourdd4c9642015-01-09 12:55:14 -0700366 void *pData = constantBuffer->map();
367
368 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
369 MVP = Projection * View * Model;
370 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
371
372 constantBuffer->unmap();
373
374 // submit the command buffer to the universal queue
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600375 cmdBuffer->QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700376
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600377 err = vkQueueWaitIdle( m_device->m_queue );
378 ASSERT_VK_SUCCESS( err );
Tony Barbourdd4c9642015-01-09 12:55:14 -0700379
380 // Wait for work to finish before cleaning up.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600381 vkDeviceWaitIdle(m_device->device());
Tony Barbourdd4c9642015-01-09 12:55:14 -0700382
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700383 assert(m_renderTargets.size() == 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -0700384 RecordImage(m_renderTargets[0]);
385 }
386}
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600387
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600388void dumpMatrix(const char *note, glm::mat4 MVP)
389{
Chia-I Wu7133fdc2014-12-15 23:57:34 +0800390 int i;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600391
392 printf("%s: \n", note);
393 for (i=0; i<4; i++) {
394 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
395 }
396 printf("\n");
397 fflush(stdout);
398}
399
400void dumpVec4(const char *note, glm::vec4 vector)
401{
402 printf("%s: \n", note);
403 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
404 printf("\n");
405 fflush(stdout);
406}
407
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600408struct vktriangle_vs_uniform {
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600409 // Must start with MVP
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600410 float mvp[4][4];
411 float position[3][4];
412 float color[3][4];
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600413};
414
Tony Barbour01999182015-04-09 12:58:51 -0600415void VkRenderTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600416{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700417#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600418 vkDbgRegisterMsgCallback(inst, myDbgFunc, NULL);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700419#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600420 // Create identity matrix
421 int i;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600422 struct vktriangle_vs_uniform data;
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600423
424 glm::mat4 Projection = glm::mat4(1.0f);
425 glm::mat4 View = glm::mat4(1.0f);
426 glm::mat4 Model = glm::mat4(1.0f);
427 glm::mat4 MVP = Projection * View * Model;
428 const int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600429 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600430 memcpy(&data.mvp, &MVP[0][0], matrixSize);
431
432 static const Vertex tri_data[] =
433 {
434 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
435 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
436 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
437 };
438
439 for (i=0; i<3; i++) {
440 data.position[i][0] = tri_data[i].posX;
441 data.position[i][1] = tri_data[i].posY;
442 data.position[i][2] = tri_data[i].posZ;
443 data.position[i][3] = tri_data[i].posW;
444 data.color[i][0] = tri_data[i].r;
445 data.color[i][1] = tri_data[i].g;
446 data.color[i][2] = tri_data[i].b;
447 data.color[i][3] = tri_data[i].a;
448 }
449
Tony Barbourf43b6982014-11-25 13:18:32 -0700450 ASSERT_NO_FATAL_FAILURE(InitState());
451 ASSERT_NO_FATAL_FAILURE(InitViewport());
452
Tony Barbour01999182015-04-09 12:58:51 -0600453 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barbourf43b6982014-11-25 13:18:32 -0700454
Tony Barbour01999182015-04-09 12:58:51 -0600455 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
456 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700457
Tony Barbour01999182015-04-09 12:58:51 -0600458 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -0700459 pipelineobj.AddShader(&vs);
460 pipelineobj.AddShader(&ps);
461
Tony Barbour01999182015-04-09 12:58:51 -0600462 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600463 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700464
Tony Barbour71ba3612015-01-09 16:12:35 -0700465 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600466 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour71ba3612015-01-09 16:12:35 -0700467 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700468
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600469 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour71ba3612015-01-09 16:12:35 -0700470
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600471 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour71ba3612015-01-09 16:12:35 -0700472#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600473 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour71ba3612015-01-09 16:12:35 -0700474 pDSDumpDot((char*)"triTest2.dot");
475#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600476
Tony Barbour71ba3612015-01-09 16:12:35 -0700477 // render triangle
478 cmdBuffer.Draw(0, 3, 0, 1);
479
480 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600481 EndCommandBuffer(cmdBuffer);
482
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600483 cmdBuffer.QueueCommandBuffer();
Tony Barbour71ba3612015-01-09 16:12:35 -0700484
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600485 RecordImages(m_renderTargets);
Tony Barbour71ba3612015-01-09 16:12:35 -0700486
487 if (rotate)
Tobin Ehlis12ee35f2015-03-26 08:23:25 -0600488 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
Tony Barbour71ba3612015-01-09 16:12:35 -0700489
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700490#ifdef PRINT_OBJECTS
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600491 //uint64_t objTrackGetObjectCount(VK_OBJECT_TYPE type)
492 OBJ_TRACK_GET_OBJECT_COUNT pObjTrackGetObjectCount = (OBJ_TRACK_GET_OBJECT_COUNT)vkGetProcAddr(gpu(), (char*)"objTrackGetObjectCount");
493 uint64_t numObjects = pObjTrackGetObjectCount(VK_OBJECT_TYPE_ANY);
494 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700495 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600496 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700497 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600498 pObjTrackGetObjs(VK_OBJECT_TYPE_ANY, numObjects, pObjNodeArray);
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700499 for (i=0; i < numObjects; i++) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600500 printf("Object %i of type %s has objID (%p) and %lu uses\n", i, string_VK_OBJECT_TYPE(pObjNodeArray[i].objType), pObjNodeArray[i].pObj, pObjNodeArray[i].numUses);
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700501 }
502 free(pObjNodeArray);
503#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700504
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600505}
506
Tony Barbour01999182015-04-09 12:58:51 -0600507TEST_F(VkRenderTest, VKTriangle_FragColor)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600508{
509 static const char *vertShaderText =
510 "#version 140\n"
511 "#extension GL_ARB_separate_shader_objects : enable\n"
512 "#extension GL_ARB_shading_language_420pack : enable\n"
513 "\n"
514 "layout(binding = 0) uniform buf {\n"
515 " mat4 MVP;\n"
516 " vec4 position[3];\n"
517 " vec4 color[3];\n"
518 "} ubuf;\n"
519 "\n"
520 "layout (location = 0) out vec4 outColor;\n"
521 "\n"
522 "void main() \n"
523 "{\n"
524 " outColor = ubuf.color[gl_VertexID];\n"
525 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
526 "}\n";
527
528 static const char *fragShaderText =
529 "#version 140\n"
530 "#extension GL_ARB_separate_shader_objects : enable\n"
531 "#extension GL_ARB_shading_language_420pack : enable\n"
532 "\n"
533 "layout (location = 0) in vec4 inColor;\n"
534 "\n"
535 "void main()\n"
536 "{\n"
537 " gl_FragColor = inColor;\n"
538 "}\n";
539
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600540 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
541 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600542}
543
Tony Barbour01999182015-04-09 12:58:51 -0600544TEST_F(VkRenderTest, VKTriangle_OutputLocation)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600545{
546 static const char *vertShaderText =
547 "#version 140\n"
548 "#extension GL_ARB_separate_shader_objects : enable\n"
549 "#extension GL_ARB_shading_language_420pack : enable\n"
550 "\n"
551 "layout(binding = 0) uniform buf {\n"
552 " mat4 MVP;\n"
553 " vec4 position[3];\n"
554 " vec4 color[3];\n"
555 "} ubuf;\n"
556 "\n"
557 "layout (location = 0) out vec4 outColor;\n"
558 "\n"
559 "void main() \n"
560 "{\n"
561 " outColor = ubuf.color[gl_VertexID];\n"
562 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
563 "}\n";
564
565 static const char *fragShaderText =
566 "#version 140\n"
567 "#extension GL_ARB_separate_shader_objects : enable\n"
568 "#extension GL_ARB_shading_language_420pack : enable\n"
569 "\n"
570 "layout (location = 0) in vec4 inColor;\n"
571 "layout (location = 0) out vec4 outColor;\n"
572 "\n"
573 "void main()\n"
574 "{\n"
575 " outColor = inColor;\n"
576 "}\n";
577
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600578 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 -0600579
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600580 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600581}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600582#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 -0600583TEST_F(VkRenderTest, SPV_VKTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700584{
Tony Barbour01999182015-04-09 12:58:51 -0600585 bool saved_use_spv = VkTestFramework::m_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700586
587 static const char *vertShaderText =
588 "#version 140\n"
589 "#extension GL_ARB_separate_shader_objects : enable\n"
590 "#extension GL_ARB_shading_language_420pack : enable\n"
591 "\n"
592 "layout(binding = 0) uniform buf {\n"
593 " mat4 MVP;\n"
594 " vec4 position[3];\n"
595 " vec4 color[3];\n"
596 "} ubuf;\n"
597 "\n"
598 "layout (location = 0) out vec4 outColor;\n"
599 "\n"
600 "void main() \n"
601 "{\n"
602 " outColor = ubuf.color[gl_VertexID];\n"
603 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
604 "}\n";
605
606 static const char *fragShaderText =
607 "#version 140\n"
608 "#extension GL_ARB_separate_shader_objects : enable\n"
609 "#extension GL_ARB_shading_language_420pack : enable\n"
610 "\n"
611 "layout (location = 0) in vec4 inColor;\n"
612 "\n"
613 "void main()\n"
614 "{\n"
615 " gl_FragColor = inColor;\n"
616 "}\n";
617
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600618 TEST_DESCRIPTION("VK-style shaders, but force test framework to compile shader to SPV and pass SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700619
Tony Barbour01999182015-04-09 12:58:51 -0600620 VkTestFramework::m_use_spv = true;
Tony Barbourf43b6982014-11-25 13:18:32 -0700621
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600622 VKTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700623
Tony Barbour01999182015-04-09 12:58:51 -0600624 VkTestFramework::m_use_spv = saved_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700625}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600626#endif
Tony Barbour01999182015-04-09 12:58:51 -0600627TEST_F(VkRenderTest, GreenTriangle)
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600628{
629 static const char *vertShaderText =
630 "#version 130\n"
631 "vec2 vertices[3];\n"
632 "void main() {\n"
633 " vertices[0] = vec2(-1.0, -1.0);\n"
634 " vertices[1] = vec2( 1.0, -1.0);\n"
635 " vertices[2] = vec2( 0.0, 1.0);\n"
636 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
637 "}\n";
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600638
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600639 static const char *fragShaderText =
640 "#version 130\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600641 "void main() {\n"
Steve K10b32512014-10-10 08:54:29 -0600642 " gl_FragColor = vec4(0,1,0,1);\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600643 "}\n";
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600644
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600645 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
646
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600647 VKTriangleTest(vertShaderText, fragShaderText, false);
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600648}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600649#ifndef _WIN32 // Implicit (for now at least) in WIN32 is that we are using the Nvidia driver and it won't consume SPIRV yet
Tony Barbour01999182015-04-09 12:58:51 -0600650TEST_F(VkRenderTest, SPV_GreenTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700651{
Tony Barbour01999182015-04-09 12:58:51 -0600652 bool saved_use_spv = VkTestFramework::m_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700653
654 static const char *vertShaderText =
655 "#version 130\n"
656 "vec2 vertices[3];\n"
657 "void main() {\n"
658 " vertices[0] = vec2(-1.0, -1.0);\n"
659 " vertices[1] = vec2( 1.0, -1.0);\n"
660 " vertices[2] = vec2( 0.0, 1.0);\n"
661 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
662 "}\n";
663
664 static const char *fragShaderText =
665 "#version 130\n"
666 "void main() {\n"
667 " gl_FragColor = vec4(0,1,0,1);\n"
668 "}\n";
669
Cody Northropacfb0492015-03-17 15:55:58 -0600670 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700671
Tony Barbour01999182015-04-09 12:58:51 -0600672 VkTestFramework::m_use_spv = true;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600673 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbour01999182015-04-09 12:58:51 -0600674 VkTestFramework::m_use_spv = saved_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700675}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600676#endif
Tony Barbour01999182015-04-09 12:58:51 -0600677TEST_F(VkRenderTest, YellowTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700678{
679 static const char *vertShaderText =
680 "#version 130\n"
681 "void main() {\n"
682 " vec2 vertices[3];"
683 " vertices[0] = vec2(-0.5, -0.5);\n"
684 " vertices[1] = vec2( 0.5, -0.5);\n"
685 " vertices[2] = vec2( 0.5, 0.5);\n"
686 " vec4 colors[3];\n"
687 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
688 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
689 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
690 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
691 "}\n";
692
693 static const char *fragShaderText =
694 "#version 130\n"
695 "void main() {\n"
696 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
697 "}\n";
698
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600699 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700700}
701
Tony Barbour01999182015-04-09 12:58:51 -0600702TEST_F(VkRenderTest, QuadWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600703{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600704 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600705 "#version 140\n"
706 "#extension GL_ARB_separate_shader_objects : enable\n"
707 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700708 //XYZ1( -1, -1, -1 )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600709 "layout (location = 0) in vec4 pos;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700710 //XYZ1( 0.f, 0.f, 0.f )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600711 "layout (location = 1) in vec4 inColor;\n"
712 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600713 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600714 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600715 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600716 "}\n";
717
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600718
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600719 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700720 "#version 140\n"
721 "#extension GL_ARB_separate_shader_objects : enable\n"
722 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600723 "layout (location = 0) in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700724 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600725 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700726 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600727 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600728
Tony Barbourf43b6982014-11-25 13:18:32 -0700729
730
731 ASSERT_NO_FATAL_FAILURE(InitState());
732 ASSERT_NO_FATAL_FAILURE(InitViewport());
733
Tony Barbour01999182015-04-09 12:58:51 -0600734 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000735 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700736
Tony Barbour01999182015-04-09 12:58:51 -0600737 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
738 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700739
Tony Barbour01999182015-04-09 12:58:51 -0600740 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -0700741 pipelineobj.AddShader(&vs);
742 pipelineobj.AddShader(&ps);
743
Tony Barbour01999182015-04-09 12:58:51 -0600744 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600745 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -0600746
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600747#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600748 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600749 MESH_BIND_ID, // binding ID
Tony Barbourf43b6982014-11-25 13:18:32 -0700750 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600751 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -0700752 };
753
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600754 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600755 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
756 vi_attribs[0].location = 0; // location, position
Tony Barbour8205d902015-04-16 15:59:00 -0600757 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600758 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
759 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
760 vi_attribs[1].location = 1; // location, color
Tony Barbour8205d902015-04-16 15:59:00 -0600761 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600762 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 -0700763
764 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
765 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600766 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -0700767
Tony Barboure4ed9942015-01-09 10:06:53 -0700768 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600769 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700770 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700771
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600772 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600773
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600774 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700775
Tony Barboure4ed9942015-01-09 10:06:53 -0700776 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
777
778 // render two triangles
779 cmdBuffer.Draw(0, 6, 0, 1);
780
781 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600782 EndCommandBuffer(cmdBuffer);
783
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600784 cmdBuffer.QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -0700785
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600786 RecordImages(m_renderTargets);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600787}
788
Tony Barbour01999182015-04-09 12:58:51 -0600789TEST_F(VkRenderTest, TriangleMRT)
Chia-I Wue09d1a72014-12-05 10:32:23 +0800790{
791 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600792 "#version 140\n"
793 "#extension GL_ARB_separate_shader_objects : enable\n"
794 "#extension GL_ARB_shading_language_420pack : enable\n"
795 "layout (location = 0) in vec4 pos;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800796 "void main() {\n"
797 " gl_Position = pos;\n"
798 "}\n";
799
800 static const char *fragShaderText =
801 "#version 130\n"
802 "void main() {\n"
803 " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
804 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
805 "}\n";
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600806 const float vb_data[][2] = {
Chia-I Wue09d1a72014-12-05 10:32:23 +0800807 { -1.0f, -1.0f },
808 { 1.0f, -1.0f },
809 { -1.0f, 1.0f }
810 };
811
812 ASSERT_NO_FATAL_FAILURE(InitState());
813 ASSERT_NO_FATAL_FAILURE(InitViewport());
814
Tony Barbour01999182015-04-09 12:58:51 -0600815 VkConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000816 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800817
Tony Barbour01999182015-04-09 12:58:51 -0600818 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
819 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800820
Tony Barbour01999182015-04-09 12:58:51 -0600821 VkPipelineObj pipelineobj(m_device);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800822 pipelineobj.AddShader(&vs);
823 pipelineobj.AddShader(&ps);
824
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600825#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600826 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600827 MESH_BUF_ID, // Binding ID
828 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600829 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Chia-I Wue09d1a72014-12-05 10:32:23 +0800830 };
831
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600832 VkVertexInputAttributeDescription vi_attrib;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600833 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
834 vi_attrib.location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -0600835 vi_attrib.format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600836 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
Chia-I Wue09d1a72014-12-05 10:32:23 +0800837
838 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
839 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600840 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800841
Tony Barbour01999182015-04-09 12:58:51 -0600842 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600843 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800844
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700845 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
Chia-I Wue09d1a72014-12-05 10:32:23 +0800846
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600847 VkPipelineCbAttachmentState att = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600848 att.blendEnable = VK_FALSE;
Chia-I Wue09d1a72014-12-05 10:32:23 +0800849 att.format = m_render_target_fmt;
850 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700851 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800852
Tony Barbour01999182015-04-09 12:58:51 -0600853 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700854
Tony Barbour5ed79702015-01-07 14:31:52 -0700855 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
856 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barboure4ed9942015-01-09 10:06:53 -0700857
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600858 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour5ed79702015-01-07 14:31:52 -0700859
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600860 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700861
Tony Barbour5ed79702015-01-07 14:31:52 -0700862 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700863#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600864 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour5ed79702015-01-07 14:31:52 -0700865 pDSDumpDot((char*)"triTest2.dot");
866#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600867
Tony Barbour5ed79702015-01-07 14:31:52 -0700868 // render triangle
869 cmdBuffer.Draw(0, 3, 0, 1);
870
871 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600872 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600873 cmdBuffer.QueueCommandBuffer();
Tony Barbour5ed79702015-01-07 14:31:52 -0700874
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600875 RecordImages(m_renderTargets);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800876}
877
Tony Barbour01999182015-04-09 12:58:51 -0600878TEST_F(VkRenderTest, QuadWithIndexedVertexFetch)
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700879{
880 static const char *vertShaderText =
881 "#version 140\n"
882 "#extension GL_ARB_separate_shader_objects : enable\n"
883 "#extension GL_ARB_shading_language_420pack : enable\n"
884 "layout(location = 0) in vec4 pos;\n"
885 "layout(location = 1) in vec4 inColor;\n"
886 "layout(location = 0) out vec4 outColor;\n"
887 "void main() {\n"
888 " outColor = inColor;\n"
889 " gl_Position = pos;\n"
890 "}\n";
891
892
893 static const char *fragShaderText =
894 "#version 140\n"
895 "#extension GL_ARB_separate_shader_objects : enable\n"
896 "#extension GL_ARB_shading_language_420pack : enable\n"
897 "layout(location = 0) in vec4 color;\n"
898 "void main() {\n"
899 " gl_FragColor = color;\n"
900 "}\n";
901
902 const Vertex g_vbData[] =
903 {
904 // first tri
905 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
906 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
907 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
908
909 // second tri
910 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
911 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
912 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
913 };
914
915 const uint16_t g_idxData[6] = {
916 0, 1, 2,
917 3, 4, 5,
918 };
919
920 ASSERT_NO_FATAL_FAILURE(InitState());
921 ASSERT_NO_FATAL_FAILURE(InitViewport());
922
Tony Barbour01999182015-04-09 12:58:51 -0600923 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000924 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700925
Tony Barbour01999182015-04-09 12:58:51 -0600926 VkIndexBufferObj indexBuffer(m_device);
Tony Barbour8205d902015-04-16 15:59:00 -0600927 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), VK_INDEX_TYPE_UINT16, g_idxData);
Mark Lobodzinskid30f82a2015-02-16 14:24:23 -0600928 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700929
Tony Barbour01999182015-04-09 12:58:51 -0600930 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
931 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700932
Tony Barbour01999182015-04-09 12:58:51 -0600933 VkPipelineObj pipelineobj(m_device);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700934 pipelineobj.AddShader(&vs);
935 pipelineobj.AddShader(&ps);
936
Tony Barbour01999182015-04-09 12:58:51 -0600937 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600938 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
939 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, indexBuffer);
Tony Barbour83a83802015-04-02 15:43:15 -0600940
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700941
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600942#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600943 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600944 MESH_BIND_ID, // binding ID
945 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600946 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700947 };
948
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600949 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600950 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
951 vi_attribs[0].location = 0; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600952 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600953 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
954 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
955 vi_attribs[1].location = 1; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600956 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600957 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700958
959 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
960 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700961
962 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600963 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700964 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600965 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barboure4ed9942015-01-09 10:06:53 -0700966
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600967 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700968
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700969#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600970 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700971 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700972#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700973
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600974 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600975 cmdBuffer.BindIndexBuffer(&indexBuffer, 0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700976
977 // render two triangles
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700978 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700979
980 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600981 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600982 cmdBuffer.QueueCommandBuffer();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700983
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600984 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700985}
986
Tony Barbour01999182015-04-09 12:58:51 -0600987TEST_F(VkRenderTest, GreyandRedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -0700988{
989 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -0700990
GregF6bef1212014-12-02 15:41:44 -0700991 static const char *vertShaderText =
992 "#version 140\n"
993 "#extension GL_ARB_separate_shader_objects : enable\n"
994 "#extension GL_ARB_shading_language_420pack : enable\n"
995 "layout (location = 0) in vec4 pos;\n"
996 "layout (location = 0) out vec4 outColor;\n"
997 "layout (location = 1) out vec4 outColor2;\n"
998 "void main() {\n"
999 " gl_Position = pos;\n"
1000 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1001 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1002 "}\n";
1003
1004 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001005 "#version 330\n"
1006 "#extension GL_ARB_separate_shader_objects : enable\n"
1007 "#extension GL_ARB_shading_language_420pack : enable\n"
1008 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1009 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1010 "layout (location = 0) in vec4 color;\n"
1011 "layout (location = 1) in vec4 color2;\n"
1012 "void main() {\n"
1013 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1014 " float dist_squared = dot(pos, pos);\n"
1015 " gl_FragColor = (dist_squared < 400.0)\n"
1016 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1017 " : color2;\n"
1018 "}\n";
1019
1020 ASSERT_NO_FATAL_FAILURE(InitState());
1021 ASSERT_NO_FATAL_FAILURE(InitViewport());
1022
Tony Barbour01999182015-04-09 12:58:51 -06001023 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001024 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001025
Tony Barbour01999182015-04-09 12:58:51 -06001026 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1027 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001028
Tony Barbour01999182015-04-09 12:58:51 -06001029 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001030 pipelineobj.AddShader(&vs);
1031 pipelineobj.AddShader(&ps);
1032
Tony Barbour01999182015-04-09 12:58:51 -06001033 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001034 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001035
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001036#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001037 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001038 MESH_BIND_ID, // binding ID
1039 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001040 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001041 };
1042
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001043 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001044 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1045 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001046 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001047 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001048
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001049 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001050 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001051 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001052
Tony Barbourdd4c9642015-01-09 12:55:14 -07001053 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001054 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001055 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1056
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001057 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001058
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001059 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001060
1061 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1062#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001063 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001064 pDSDumpDot((char*)"triTest2.dot");
1065#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001066
Tony Barbourdd4c9642015-01-09 12:55:14 -07001067 // render triangle
1068 cmdBuffer.Draw(0, 6, 0, 1);
1069
1070 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001071 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001072 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001073
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001074 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001075}
1076
Tony Barbour01999182015-04-09 12:58:51 -06001077TEST_F(VkRenderTest, RedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -07001078{
1079 // This tests that we correctly handle unread fragment inputs
1080
1081 static const char *vertShaderText =
1082 "#version 140\n"
1083 "#extension GL_ARB_separate_shader_objects : enable\n"
1084 "#extension GL_ARB_shading_language_420pack : enable\n"
1085 "layout (location = 0) in vec4 pos;\n"
1086 "layout (location = 0) out vec4 outColor;\n"
1087 "layout (location = 1) out vec4 outColor2;\n"
1088 "void main() {\n"
1089 " gl_Position = pos;\n"
1090 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1091 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1092 "}\n";
1093
1094 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001095 "#version 330\n"
1096 "#extension GL_ARB_separate_shader_objects : enable\n"
1097 "#extension GL_ARB_shading_language_420pack : enable\n"
1098 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1099 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1100 "layout (location = 0) in vec4 color;\n"
1101 "layout (location = 1) in vec4 color2;\n"
1102 "void main() {\n"
1103 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1104 " float dist_squared = dot(pos, pos);\n"
1105 " gl_FragColor = (dist_squared < 400.0)\n"
1106 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1107 " : color2;\n"
1108 "}\n";
1109
1110 ASSERT_NO_FATAL_FAILURE(InitState());
1111 ASSERT_NO_FATAL_FAILURE(InitViewport());
1112
Tony Barbour01999182015-04-09 12:58:51 -06001113 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001114 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001115
Tony Barbour01999182015-04-09 12:58:51 -06001116 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1117 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001118
Tony Barbour01999182015-04-09 12:58:51 -06001119 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001120 pipelineobj.AddShader(&vs);
1121 pipelineobj.AddShader(&ps);
1122
Tony Barbour01999182015-04-09 12:58:51 -06001123 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001124 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001125
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001126#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001127 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001128 MESH_BIND_ID, // binding ID
1129 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001130 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001131 };
1132
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001133 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001134 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1135 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001136 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001137 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001138
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001139 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001140 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001141 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001142
Tony Barbourdd4c9642015-01-09 12:55:14 -07001143 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001144 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001145 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1146
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001147 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001148
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001149 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001150
1151 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1152#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001153 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001154 pDSDumpDot((char*)"triTest2.dot");
1155#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001156 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001157 cmdBuffer.Draw(0, 6, 0, 1);
1158
1159 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001160 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001161 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001162
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001163 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001164}
1165
Tony Barbour01999182015-04-09 12:58:51 -06001166TEST_F(VkRenderTest, GreyCirclesonBlueFade)
GregF6bef1212014-12-02 15:41:44 -07001167{
1168 // This tests reading gl_ClipDistance from FS
1169
1170 static const char *vertShaderText =
1171 "#version 330\n"
1172 "#extension GL_ARB_separate_shader_objects : enable\n"
1173 "#extension GL_ARB_shading_language_420pack : enable\n"
1174 "out gl_PerVertex {\n"
1175 " vec4 gl_Position;\n"
1176 " float gl_ClipDistance[1];\n"
1177 "};\n"
1178 "layout (location = 0) in vec4 pos;\n"
1179 "layout (location = 0) out vec4 outColor;\n"
1180 "layout (location = 1) out vec4 outColor2;\n"
1181 "void main() {\n"
1182 " gl_Position = pos;\n"
1183 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1184 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1185 " float dists[3];\n"
1186 " dists[0] = 0.0;\n"
1187 " dists[1] = 1.0;\n"
1188 " dists[2] = 1.0;\n"
1189 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1190 "}\n";
1191
1192
1193 static const char *fragShaderText =
1194 //"#version 140\n"
1195 "#version 330\n"
1196 "#extension GL_ARB_separate_shader_objects : enable\n"
1197 "#extension GL_ARB_shading_language_420pack : enable\n"
1198 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1199 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1200 "layout (location = 0) in vec4 color;\n"
1201 "layout (location = 1) in vec4 color2;\n"
1202 "void main() {\n"
1203 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1204 " float dist_squared = dot(pos, pos);\n"
1205 " gl_FragColor = (dist_squared < 400.0)\n"
1206 " ? color * gl_ClipDistance[0]\n"
1207 " : color2;\n"
1208 "}\n";
1209
1210 ASSERT_NO_FATAL_FAILURE(InitState());
1211 ASSERT_NO_FATAL_FAILURE(InitViewport());
1212
Tony Barbour01999182015-04-09 12:58:51 -06001213 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001214 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001215
Tony Barbour01999182015-04-09 12:58:51 -06001216 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1217 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001218
Tony Barbour01999182015-04-09 12:58:51 -06001219 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001220 pipelineobj.AddShader(&vs);
1221 pipelineobj.AddShader(&ps);
1222
Tony Barbour01999182015-04-09 12:58:51 -06001223 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001224 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001225
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001226#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001227 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001228 MESH_BIND_ID, // binding ID
1229 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001230 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001231 };
1232
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001233 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001234 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1235 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001236 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001237 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001238
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001239 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001240 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001241 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001242
Tony Barbourdd4c9642015-01-09 12:55:14 -07001243 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001244 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001245 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF6bef1212014-12-02 15:41:44 -07001246
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001247 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001248
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001249 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001250
1251 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1252#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001253 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001254 pDSDumpDot((char*)"triTest2.dot");
1255#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001256
1257 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001258 cmdBuffer.Draw(0, 6, 0, 1);
1259
1260 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001261 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001262 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001263
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001264 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001265}
Tony Barbourf43b6982014-11-25 13:18:32 -07001266
Tony Barbour01999182015-04-09 12:58:51 -06001267TEST_F(VkRenderTest, GreyCirclesonBlueDiscard)
GregF7a23c792014-12-02 17:19:34 -07001268{
1269 static const char *vertShaderText =
1270 "#version 140\n"
1271 "#extension GL_ARB_separate_shader_objects : enable\n"
1272 "#extension GL_ARB_shading_language_420pack : enable\n"
1273 "layout (location = 0) in vec4 pos;\n"
1274 "layout (location = 0) out vec4 outColor;\n"
1275 "layout (location = 1) out vec4 outColor2;\n"
1276 "void main() {\n"
1277 " gl_Position = pos;\n"
1278 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1279 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1280 "}\n";
1281
1282
1283 static const char *fragShaderText =
GregF7a23c792014-12-02 17:19:34 -07001284 "#version 330\n"
1285 "#extension GL_ARB_separate_shader_objects : enable\n"
1286 "#extension GL_ARB_shading_language_420pack : enable\n"
1287 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1288 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1289 "layout (location = 0) in vec4 color;\n"
1290 "layout (location = 1) in vec4 color2;\n"
1291 "void main() {\n"
1292 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1293 " float dist_squared = dot(pos, pos);\n"
1294 " if (dist_squared < 100.0)\n"
1295 " discard;\n"
1296 " gl_FragColor = (dist_squared < 400.0)\n"
1297 " ? color\n"
1298 " : color2;\n"
1299 "}\n";
1300
1301 ASSERT_NO_FATAL_FAILURE(InitState());
1302 ASSERT_NO_FATAL_FAILURE(InitViewport());
1303
Tony Barbour01999182015-04-09 12:58:51 -06001304 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001305 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001306
Tony Barbour01999182015-04-09 12:58:51 -06001307 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1308 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF7a23c792014-12-02 17:19:34 -07001309
Tony Barbour01999182015-04-09 12:58:51 -06001310 VkPipelineObj pipelineobj(m_device);
GregF7a23c792014-12-02 17:19:34 -07001311 pipelineobj.AddShader(&vs);
1312 pipelineobj.AddShader(&ps);
1313
Tony Barbour01999182015-04-09 12:58:51 -06001314 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001315 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001316
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001317#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001318 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001319 MESH_BIND_ID, // binding ID
1320 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001321 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF7a23c792014-12-02 17:19:34 -07001322 };
1323
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001324 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001325 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1326 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001327 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001328 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF7a23c792014-12-02 17:19:34 -07001329
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001330 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF7a23c792014-12-02 17:19:34 -07001331 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001332 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF7a23c792014-12-02 17:19:34 -07001333
Tony Barbourdd4c9642015-01-09 12:55:14 -07001334 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001335 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001336 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1337
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001338 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001339
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001340 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001341
1342 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1343#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001344 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001345 pDSDumpDot((char*)"triTest2.dot");
1346#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001347
1348 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001349 cmdBuffer.Draw(0, 6, 0, 1);
1350
1351 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001352 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001353 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001354
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001355 RecordImages(m_renderTargets);
GregF7a23c792014-12-02 17:19:34 -07001356}
1357
1358
Tony Barbour01999182015-04-09 12:58:51 -06001359TEST_F(VkRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001360{
1361 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001362 "#version 140\n"
1363 "#extension GL_ARB_separate_shader_objects : enable\n"
1364 "#extension GL_ARB_shading_language_420pack : enable\n"
1365 "\n"
1366 "layout(binding = 0) uniform buf {\n"
1367 " mat4 MVP;\n"
1368 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001369 "void main() {\n"
1370 " vec2 vertices[3];"
1371 " vertices[0] = vec2(-0.5, -0.5);\n"
1372 " vertices[1] = vec2( 0.5, -0.5);\n"
1373 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001374 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001375 "}\n";
1376
1377 static const char *fragShaderText =
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001378 "#version 130\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001379 "void main() {\n"
Cody Northrop78eac042014-10-10 15:45:00 -06001380 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001381 "}\n";
1382
Tony Barbourf43b6982014-11-25 13:18:32 -07001383 ASSERT_NO_FATAL_FAILURE(InitState());
1384 ASSERT_NO_FATAL_FAILURE(InitViewport());
1385
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001386 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001387 glm::mat4 Projection = glm::mat4(1.0f);
1388 glm::mat4 View = glm::mat4(1.0f);
1389 glm::mat4 Model = glm::mat4(1.0f);
1390 glm::mat4 MVP = Projection * View * Model;
1391 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1392
Tony Barbour01999182015-04-09 12:58:51 -06001393 VkConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1394 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1395 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001396
Tony Barbour01999182015-04-09 12:58:51 -06001397 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001398 pipelineobj.AddShader(&vs);
1399 pipelineobj.AddShader(&ps);
1400
1401 // Create descriptor set and attach the constant buffer to it
Tony Barbour01999182015-04-09 12:58:51 -06001402 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001403 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001404
Tony Barbourdd4c9642015-01-09 12:55:14 -07001405 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001406 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001407 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001408
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001409 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001410
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001411 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001412
1413 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1414#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001415 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001416 pDSDumpDot((char*)"triTest2.dot");
1417#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001418
1419 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001420 cmdBuffer.Draw(0, 6, 0, 1);
1421
1422 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001423 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001424 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001425
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001426 RecordImages(m_renderTargets);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001427
1428 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001429}
1430
Tony Barbour01999182015-04-09 12:58:51 -06001431TEST_F(VkRenderTest, MixTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07001432{
1433 // This tests location applied to varyings. Notice that we have switched foo
1434 // and bar in the FS. The triangle should be blended with red, green and blue
1435 // corners.
1436 static const char *vertShaderText =
1437 "#version 140\n"
1438 "#extension GL_ARB_separate_shader_objects : enable\n"
1439 "#extension GL_ARB_shading_language_420pack : enable\n"
1440 "layout (location=0) out vec4 bar;\n"
1441 "layout (location=1) out vec4 foo;\n"
1442 "layout (location=2) out float scale;\n"
1443 "vec2 vertices[3];\n"
1444 "void main() {\n"
1445 " vertices[0] = vec2(-1.0, -1.0);\n"
1446 " vertices[1] = vec2( 1.0, -1.0);\n"
1447 " vertices[2] = vec2( 0.0, 1.0);\n"
1448 "vec4 colors[3];\n"
1449 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1450 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1451 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1452 " foo = colors[gl_VertexID % 3];\n"
1453 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1454 " scale = 1.0;\n"
1455 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1456 "}\n";
1457
1458 static const char *fragShaderText =
1459 "#version 140\n"
1460 "#extension GL_ARB_separate_shader_objects : enable\n"
1461 "#extension GL_ARB_shading_language_420pack : enable\n"
1462 "layout (location = 1) in vec4 bar;\n"
1463 "layout (location = 0) in vec4 foo;\n"
1464 "layout (location = 2) in float scale;\n"
1465 "void main() {\n"
1466 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
1467 "}\n";
1468
1469 ASSERT_NO_FATAL_FAILURE(InitState());
1470 ASSERT_NO_FATAL_FAILURE(InitViewport());
1471
Tony Barbour01999182015-04-09 12:58:51 -06001472 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1473 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001474
Tony Barbour01999182015-04-09 12:58:51 -06001475 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001476 pipelineobj.AddShader(&vs);
1477 pipelineobj.AddShader(&ps);
1478
Tony Barbour01999182015-04-09 12:58:51 -06001479 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06001480 descriptorSet.AppendDummy();
Tony Barbourf43b6982014-11-25 13:18:32 -07001481
Tony Barbourdd4c9642015-01-09 12:55:14 -07001482 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001483 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001484 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1485
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001486 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001487
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001488 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001489
1490#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001491 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001492 pDSDumpDot((char*)"triTest2.dot");
1493#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001494
Tony Barbourdd4c9642015-01-09 12:55:14 -07001495 // render triangle
1496 cmdBuffer.Draw(0, 3, 0, 1);
1497
1498 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001499 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001500 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001501
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001502 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001503}
1504
Tony Barbour01999182015-04-09 12:58:51 -06001505TEST_F(VkRenderTest, QuadVertFetchAndVertID)
Tony Barbourf43b6982014-11-25 13:18:32 -07001506{
1507 // This tests that attributes work in the presence of gl_VertexID
1508
1509 static const char *vertShaderText =
1510 "#version 140\n"
1511 "#extension GL_ARB_separate_shader_objects : enable\n"
1512 "#extension GL_ARB_shading_language_420pack : enable\n"
1513 //XYZ1( -1, -1, -1 )
1514 "layout (location = 0) in vec4 pos;\n"
1515 //XYZ1( 0.f, 0.f, 0.f )
1516 "layout (location = 1) in vec4 inColor;\n"
1517 "layout (location = 0) out vec4 outColor;\n"
1518 "void main() {\n"
1519 " outColor = inColor;\n"
1520 " vec4 vertices[3];"
1521 " vertices[gl_VertexID % 3] = pos;\n"
1522 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1523 "}\n";
1524
1525
1526 static const char *fragShaderText =
1527 "#version 140\n"
1528 "#extension GL_ARB_separate_shader_objects : enable\n"
1529 "#extension GL_ARB_shading_language_420pack : enable\n"
1530 "layout (location = 0) in vec4 color;\n"
1531 "void main() {\n"
1532 " gl_FragColor = color;\n"
1533 "}\n";
1534
1535 ASSERT_NO_FATAL_FAILURE(InitState());
1536 ASSERT_NO_FATAL_FAILURE(InitViewport());
1537
Tony Barbour01999182015-04-09 12:58:51 -06001538 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001539 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001540
Tony Barbour01999182015-04-09 12:58:51 -06001541 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1542 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001543
Tony Barbour01999182015-04-09 12:58:51 -06001544 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001545 pipelineobj.AddShader(&vs);
1546 pipelineobj.AddShader(&ps);
1547
Tony Barbour01999182015-04-09 12:58:51 -06001548 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001549 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001550
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001551#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001552 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001553 MESH_BUF_ID, // Binding ID
1554 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001555 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001556 };
1557
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001558 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001559 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1560 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001561 vi_attribs[0].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001562 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1563 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1564 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001565 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001566 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001567
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001568 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001569 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001570 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001571
Tony Barbourdd4c9642015-01-09 12:55:14 -07001572 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001573 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001574 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1575
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001576 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001577
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001578 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001579
1580 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1581#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001582 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001583 pDSDumpDot((char*)"triTest2.dot");
1584#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001585
1586 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001587 cmdBuffer.Draw(0, 6, 0, 1);
1588
1589 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001590 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001591 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001592
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001593 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001594}
1595
Tony Barbour01999182015-04-09 12:58:51 -06001596TEST_F(VkRenderTest, QuadSparseVertFetch)
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001597{
1598 // This tests that attributes work in the presence of gl_VertexID
1599
1600 static const char *vertShaderText =
1601 "#version 140\n"
1602 "#extension GL_ARB_separate_shader_objects : enable\n"
1603 "#extension GL_ARB_shading_language_420pack : enable\n"
1604 //XYZ1( -1, -1, -1 )
1605 "layout (location = 1) in vec4 pos;\n"
1606 "layout (location = 4) in vec4 inColor;\n"
1607 //XYZ1( 0.f, 0.f, 0.f )
1608 "layout (location = 0) out vec4 outColor;\n"
1609 "void main() {\n"
1610 " outColor = inColor;\n"
1611 " gl_Position = pos;\n"
1612 "}\n";
1613
1614
1615 static const char *fragShaderText =
1616 "#version 140\n"
1617 "#extension GL_ARB_separate_shader_objects : enable\n"
1618 "#extension GL_ARB_shading_language_420pack : enable\n"
1619 "layout (location = 0) in vec4 color;\n"
1620 "void main() {\n"
1621 " gl_FragColor = color;\n"
1622 "}\n";
1623
1624 ASSERT_NO_FATAL_FAILURE(InitState());
1625 ASSERT_NO_FATAL_FAILURE(InitViewport());
1626
1627 struct VDATA
1628 {
1629 float t1, t2, t3, t4; // filler data
1630 float posX, posY, posZ, posW; // Position data
1631 float r, g, b, a; // Color
1632 };
1633 const struct VDATA vData[] =
1634 {
1635 { XYZ1(0, 0, 0), XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
1636 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1637 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1638 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1639 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1640 { XYZ1(0, 0, 0), XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
1641 };
1642
Tony Barbour01999182015-04-09 12:58:51 -06001643 VkConstantBufferObj meshBuffer(m_device,sizeof(vData)/sizeof(vData[0]),sizeof(vData[0]), vData);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001644 meshBuffer.BufferMemoryBarrier();
1645
Tony Barbour01999182015-04-09 12:58:51 -06001646 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1647 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001648
Tony Barbour01999182015-04-09 12:58:51 -06001649 VkPipelineObj pipelineobj(m_device);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001650 pipelineobj.AddShader(&vs);
1651 pipelineobj.AddShader(&ps);
1652
Tony Barbour01999182015-04-09 12:58:51 -06001653 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001654 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001655
1656#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001657 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001658 MESH_BUF_ID, // Binding ID
1659 sizeof(vData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001660 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001661 };
1662
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001663 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001664 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1665 vi_attribs[0].location = 4;
Tony Barbour8205d902015-04-16 15:59:00 -06001666 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001667 vi_attribs[0].offsetInBytes = sizeof(float) * 4 * 2; // Offset of first element in bytes from base of vertex
1668 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1669 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001670 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001671 vi_attribs[1].offsetInBytes = sizeof(float) * 4 * 1; // Offset of first element in bytes from base of vertex
1672
1673 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
1674 pipelineobj.AddVertexInputBindings(&vi_binding, 1);
1675 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
1676
1677 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001678 VkCommandBufferObj cmdBuffer(m_device);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001679 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1680
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001681 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001682
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001683 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001684
1685 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BUF_ID);
1686#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001687 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001688 pDSDumpDot((char*)"triTest2.dot");
1689#endif
1690
1691 // render two triangles
1692 cmdBuffer.Draw(0, 6, 0, 1);
1693
1694 // finalize recording of the command buffer
1695 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001696 cmdBuffer.QueueCommandBuffer();
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001697
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001698 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001699}
1700
Tony Barbour01999182015-04-09 12:58:51 -06001701TEST_F(VkRenderTest, TriVertFetchDeadAttr)
Tony Barbourf43b6982014-11-25 13:18:32 -07001702{
1703 // This tests that attributes work in the presence of gl_VertexID
1704 // and a dead attribute in position 0. Draws a triangle with yellow,
1705 // red and green corners, starting at top and going clockwise.
1706
1707 static const char *vertShaderText =
1708 "#version 140\n"
1709 "#extension GL_ARB_separate_shader_objects : enable\n"
1710 "#extension GL_ARB_shading_language_420pack : enable\n"
1711 //XYZ1( -1, -1, -1 )
1712 "layout (location = 0) in vec4 pos;\n"
1713 //XYZ1( 0.f, 0.f, 0.f )
1714 "layout (location = 1) in vec4 inColor;\n"
1715 "layout (location = 0) out vec4 outColor;\n"
1716 "void main() {\n"
1717 " outColor = inColor;\n"
1718 " vec2 vertices[3];"
1719 " vertices[0] = vec2(-1.0, -1.0);\n"
1720 " vertices[1] = vec2( 1.0, -1.0);\n"
1721 " vertices[2] = vec2( 0.0, 1.0);\n"
1722 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1723 "}\n";
1724
1725
1726 static const char *fragShaderText =
1727 "#version 140\n"
1728 "#extension GL_ARB_separate_shader_objects : enable\n"
1729 "#extension GL_ARB_shading_language_420pack : enable\n"
1730 "layout (location = 0) in vec4 color;\n"
1731 "void main() {\n"
1732 " gl_FragColor = color;\n"
1733 "}\n";
1734
1735 ASSERT_NO_FATAL_FAILURE(InitState());
1736 ASSERT_NO_FATAL_FAILURE(InitViewport());
1737
Tony Barbour01999182015-04-09 12:58:51 -06001738 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001739 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001740
Tony Barbour01999182015-04-09 12:58:51 -06001741 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1742 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001743
Tony Barbour01999182015-04-09 12:58:51 -06001744 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001745 pipelineobj.AddShader(&vs);
1746 pipelineobj.AddShader(&ps);
1747
Tony Barbour01999182015-04-09 12:58:51 -06001748 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001749 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001750
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001751#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001752 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001753 MESH_BUF_ID, // Binding ID
1754 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001755 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001756 };
1757
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001758 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001759 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1760 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001761 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001762 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1763 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1764 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001765 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001766 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001767
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001768 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001769 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001770 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001771
Tony Barbourdd4c9642015-01-09 12:55:14 -07001772 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001773 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001774 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001775
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001776 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001777
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001778 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001779
1780 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1781#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001782 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001783 pDSDumpDot((char*)"triTest2.dot");
1784#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001785
1786 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001787 cmdBuffer.Draw(0, 6, 0, 1);
1788
1789 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001790 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001791 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001792
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001793 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001794}
1795
Tony Barbour01999182015-04-09 12:58:51 -06001796TEST_F(VkRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001797{
1798 static const char *vertShaderText =
1799 "#version 140\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001800 "#extension GL_ARB_separate_shader_objects : enable\n"
1801 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001802 "layout (std140) uniform bufferVals {\n"
1803 " mat4 mvp;\n"
1804 "} myBufferVals;\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001805 "layout (location = 0) in vec4 pos;\n"
1806 "layout (location = 1) in vec4 inColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001807 "out vec4 outColor;\n"
1808 "void main() {\n"
1809 " outColor = inColor;\n"
1810 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001811 " gl_Position.y = -gl_Position.y;\n"
1812 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001813 "}\n";
1814
1815 static const char *fragShaderText =
1816 "#version 130\n"
1817 "in vec4 color;\n"
1818 "void main() {\n"
1819 " gl_FragColor = color;\n"
1820 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001821 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001822
Tony Barbourf43b6982014-11-25 13:18:32 -07001823 glm::mat4 View = glm::lookAt(
1824 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1825 glm::vec3(0,0,0), // and looks at the origin
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001826 glm::vec3(0,-1,0) // Head is up (set to 0,-1,0 to look upside-down)
Tony Barbourf43b6982014-11-25 13:18:32 -07001827 );
1828
1829 glm::mat4 Model = glm::mat4(1.0f);
1830
1831 glm::mat4 MVP = Projection * View * Model;
1832
1833 ASSERT_NO_FATAL_FAILURE(InitState());
1834 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour17c6ab12015-03-27 17:03:18 -06001835 m_depthStencil->Init(m_device, m_width, m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07001836
Tony Barbour01999182015-04-09 12:58:51 -06001837 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 -07001838 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1839
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001840 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07001841
Tony Barbour01999182015-04-09 12:58:51 -06001842 VkConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1843 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1844 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001845
Tony Barbour01999182015-04-09 12:58:51 -06001846 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001847 pipelineobj.AddShader(&vs);
1848 pipelineobj.AddShader(&ps);
1849
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001850 VkPipelineDsStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001851 ds_state.depthTestEnable = VK_TRUE;
1852 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06001853 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001854 ds_state.depthBoundsEnable = VK_FALSE;
1855 ds_state.stencilTestEnable = VK_FALSE;
1856 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
1857 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
1858 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06001859 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
1860 ds_state.format = VK_FORMAT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001861 ds_state.front = ds_state.back;
1862 pipelineobj.SetDepthStencil(&ds_state);
1863
Tony Barbour01999182015-04-09 12:58:51 -06001864 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001865 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001866
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001867#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001868 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001869 MESH_BUF_ID, // Binding ID
1870 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001871 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001872 };
Tony Barbourf43b6982014-11-25 13:18:32 -07001873
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001874 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001875 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1876 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001877 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001878 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1879 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1880 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001881 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001882 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001883
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001884 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001885 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001886 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001887
Tony Barbour17c6ab12015-03-27 17:03:18 -06001888 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour17c6ab12015-03-27 17:03:18 -06001889
Tony Barbour01999182015-04-09 12:58:51 -06001890 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -07001891 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001892
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001893 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001894 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001895
Tony Barboure4ed9942015-01-09 10:06:53 -07001896 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1897#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001898 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barboure4ed9942015-01-09 10:06:53 -07001899 pDSDumpDot((char*)"triTest2.dot");
1900#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001901
1902 // render triangles
Tony Barboure4ed9942015-01-09 10:06:53 -07001903 cmdBuffer.Draw(0, 36, 0, 1);
1904
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001905
Tony Barboure4ed9942015-01-09 10:06:53 -07001906 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001907 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001908 cmdBuffer.QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -07001909
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001910 RecordImages(m_renderTargets);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001911}
1912
Tony Barbour01999182015-04-09 12:58:51 -06001913TEST_F(VkRenderTest, VSTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07001914{
1915 // The expected result from this test is a green and red triangle;
1916 // one red vertex on the left, two green vertices on the right.
1917 static const char *vertShaderText =
1918 "#version 130\n"
1919 "out vec4 texColor;\n"
1920 "uniform sampler2D surface;\n"
1921 "void main() {\n"
1922 " vec2 vertices[3];"
1923 " vertices[0] = vec2(-0.5, -0.5);\n"
1924 " vertices[1] = vec2( 0.5, -0.5);\n"
1925 " vertices[2] = vec2( 0.5, 0.5);\n"
1926 " vec2 positions[3];"
1927 " positions[0] = vec2( 0.0, 0.0);\n"
1928 " positions[1] = vec2( 0.25, 0.1);\n"
1929 " positions[2] = vec2( 0.1, 0.25);\n"
1930 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1931 " texColor = textureLod(surface, samplePos, 0.0);\n"
1932 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1933 "}\n";
1934
1935 static const char *fragShaderText =
1936 "#version 130\n"
1937 "in vec4 texColor;\n"
1938 "void main() {\n"
1939 " gl_FragColor = texColor;\n"
1940 "}\n";
1941
1942 ASSERT_NO_FATAL_FAILURE(InitState());
1943 ASSERT_NO_FATAL_FAILURE(InitViewport());
1944
Tony Barbour01999182015-04-09 12:58:51 -06001945 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1946 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
1947 VkSamplerObj sampler(m_device);
1948 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001949
Tony Barbour01999182015-04-09 12:58:51 -06001950 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001951 pipelineobj.AddShader(&vs);
1952 pipelineobj.AddShader(&ps);
1953
Tony Barbour01999182015-04-09 12:58:51 -06001954 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001955 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001956
Tony Barbourdd4c9642015-01-09 12:55:14 -07001957 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001958 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001959 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001960
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001961 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001962
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001963 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001964
1965#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001966 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001967 pDSDumpDot((char*)"triTest2.dot");
1968#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001969
Tony Barbourdd4c9642015-01-09 12:55:14 -07001970 // render triangle
1971 cmdBuffer.Draw(0, 3, 0, 1);
1972
1973 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001974 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001975 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001976
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001977 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001978}
Tony Barbour01999182015-04-09 12:58:51 -06001979TEST_F(VkRenderTest, TexturedTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07001980{
1981 // The expected result from this test is a red and green checkered triangle
1982 static const char *vertShaderText =
1983 "#version 140\n"
1984 "#extension GL_ARB_separate_shader_objects : enable\n"
1985 "#extension GL_ARB_shading_language_420pack : enable\n"
1986 "layout (location = 0) out vec2 samplePos;\n"
1987 "void main() {\n"
1988 " vec2 vertices[3];"
1989 " vertices[0] = vec2(-0.5, -0.5);\n"
1990 " vertices[1] = vec2( 0.5, -0.5);\n"
1991 " vertices[2] = vec2( 0.5, 0.5);\n"
1992 " vec2 positions[3];"
1993 " positions[0] = vec2( 0.0, 0.0);\n"
1994 " positions[1] = vec2( 1.0, 0.0);\n"
1995 " positions[2] = vec2( 1.0, 1.0);\n"
1996 " samplePos = positions[gl_VertexID % 3];\n"
1997 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1998 "}\n";
1999
2000 static const char *fragShaderText =
2001 "#version 140\n"
2002 "#extension GL_ARB_separate_shader_objects : enable\n"
2003 "#extension GL_ARB_shading_language_420pack : enable\n"
2004 "layout (location = 0) in vec2 samplePos;\n"
2005 "layout (binding = 0) uniform sampler2D surface;\n"
2006 "layout (location=0) out vec4 outColor;\n"
2007 "void main() {\n"
2008 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2009 " outColor = texColor;\n"
2010 "}\n";
2011
2012 ASSERT_NO_FATAL_FAILURE(InitState());
2013 ASSERT_NO_FATAL_FAILURE(InitViewport());
2014
Tony Barbour01999182015-04-09 12:58:51 -06002015 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2016 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2017 VkSamplerObj sampler(m_device);
2018 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002019
Tony Barbour01999182015-04-09 12:58:51 -06002020 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002021 pipelineobj.AddShader(&vs);
2022 pipelineobj.AddShader(&ps);
2023
Tony Barbour01999182015-04-09 12:58:51 -06002024 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002025 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002026
Tony Barbourdd4c9642015-01-09 12:55:14 -07002027 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002028 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002029 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2030
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002031 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002032
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002033 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002034
2035#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002036 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002037 pDSDumpDot((char*)"triTest2.dot");
2038#endif
2039 // render triangle
2040 cmdBuffer.Draw(0, 3, 0, 1);
2041
2042 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002043 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002044 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002045
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002046 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002047}
Tony Barbour01999182015-04-09 12:58:51 -06002048TEST_F(VkRenderTest, TexturedTriangleClip)
Tony Barbourf43b6982014-11-25 13:18:32 -07002049{
2050 // The expected result from this test is a red and green checkered triangle
2051 static const char *vertShaderText =
2052 "#version 330\n"
2053 "#extension GL_ARB_separate_shader_objects : enable\n"
2054 "#extension GL_ARB_shading_language_420pack : enable\n"
2055 "layout (location = 0) out vec2 samplePos;\n"
2056 "out gl_PerVertex {\n"
2057 " vec4 gl_Position;\n"
2058 " float gl_ClipDistance[1];\n"
2059 "};\n"
2060 "void main() {\n"
2061 " vec2 vertices[3];"
2062 " vertices[0] = vec2(-0.5, -0.5);\n"
2063 " vertices[1] = vec2( 0.5, -0.5);\n"
2064 " vertices[2] = vec2( 0.5, 0.5);\n"
2065 " vec2 positions[3];"
2066 " positions[0] = vec2( 0.0, 0.0);\n"
2067 " positions[1] = vec2( 1.0, 0.0);\n"
2068 " positions[2] = vec2( 1.0, 1.0);\n"
2069 " float dists[3];\n"
2070 " dists[0] = 1.0;\n"
2071 " dists[1] = 1.0;\n"
2072 " dists[2] = -1.0;\n"
2073 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2074 " samplePos = positions[gl_VertexID % 3];\n"
2075 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2076 "}\n";
2077
2078 static const char *fragShaderText =
2079 "#version 140\n"
2080 "#extension GL_ARB_separate_shader_objects : enable\n"
2081 "#extension GL_ARB_shading_language_420pack : enable\n"
2082 "layout (location = 0) in vec2 samplePos;\n"
2083 "layout (binding = 0) uniform sampler2D surface;\n"
2084 "layout (location=0) out vec4 outColor;\n"
2085 "void main() {\n"
2086 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2087 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2088 " outColor = texColor;\n"
2089 "}\n";
2090
2091
2092 ASSERT_NO_FATAL_FAILURE(InitState());
2093 ASSERT_NO_FATAL_FAILURE(InitViewport());
2094
Tony Barbour01999182015-04-09 12:58:51 -06002095 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2096 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2097 VkSamplerObj sampler(m_device);
2098 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002099
Tony Barbour01999182015-04-09 12:58:51 -06002100 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002101 pipelineobj.AddShader(&vs);
2102 pipelineobj.AddShader(&ps);
2103
Tony Barbour01999182015-04-09 12:58:51 -06002104 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002105 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002106
Tony Barbourdd4c9642015-01-09 12:55:14 -07002107 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002108 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002109 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2110
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002111 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002112
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002113 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002114
2115#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002116 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002117 pDSDumpDot((char*)"triTest2.dot");
2118#endif
2119 // render triangle
2120 cmdBuffer.Draw(0, 3, 0, 1);
2121
2122 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002123 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002124 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002125
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002126 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002127}
Tony Barbour01999182015-04-09 12:58:51 -06002128TEST_F(VkRenderTest, FSTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002129{
2130 // The expected result from this test is a red and green checkered triangle
2131 static const char *vertShaderText =
2132 "#version 140\n"
2133 "#extension GL_ARB_separate_shader_objects : enable\n"
2134 "#extension GL_ARB_shading_language_420pack : enable\n"
2135 "layout (location = 0) out vec2 samplePos;\n"
2136 "void main() {\n"
2137 " vec2 vertices[3];"
2138 " vertices[0] = vec2(-0.5, -0.5);\n"
2139 " vertices[1] = vec2( 0.5, -0.5);\n"
2140 " vertices[2] = vec2( 0.5, 0.5);\n"
2141 " vec2 positions[3];"
2142 " positions[0] = vec2( 0.0, 0.0);\n"
2143 " positions[1] = vec2( 1.0, 0.0);\n"
2144 " positions[2] = vec2( 1.0, 1.0);\n"
2145 " samplePos = positions[gl_VertexID % 3];\n"
2146 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2147 "}\n";
2148
2149 static const char *fragShaderText =
2150 "#version 140\n"
2151 "#extension GL_ARB_separate_shader_objects : enable\n"
2152 "#extension GL_ARB_shading_language_420pack : enable\n"
2153 "layout (location = 0) in vec2 samplePos;\n"
2154 "layout (binding = 0) uniform sampler2D surface;\n"
2155 "layout (location=0) out vec4 outColor;\n"
2156 "void main() {\n"
2157 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2158 " outColor = texColor;\n"
2159 "}\n";
2160
2161 ASSERT_NO_FATAL_FAILURE(InitState());
2162 ASSERT_NO_FATAL_FAILURE(InitViewport());
2163
Tony Barbour01999182015-04-09 12:58:51 -06002164 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2165 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2166 VkSamplerObj sampler(m_device);
2167 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002168
Tony Barbour01999182015-04-09 12:58:51 -06002169 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002170 pipelineobj.AddShader(&vs);
2171 pipelineobj.AddShader(&ps);
2172
Tony Barbour01999182015-04-09 12:58:51 -06002173 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002174 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002175
Tony Barbourdd4c9642015-01-09 12:55:14 -07002176 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002177 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002178 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2179
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002180 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002181
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002182 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002183
2184#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002185 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002186 pDSDumpDot((char*)"triTest2.dot");
2187#endif
2188 // render triangle
2189 cmdBuffer.Draw(0, 3, 0, 1);
2190
2191 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002192 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002193 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002194
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002195 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002196}
Tony Barbour01999182015-04-09 12:58:51 -06002197TEST_F(VkRenderTest, SamplerBindingsTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002198{
2199 // This test sets bindings on the samplers
2200 // For now we are asserting that sampler and texture pairs
2201 // march in lock step, and are set via GLSL binding. This can
2202 // and will probably change.
2203 // The sampler bindings should match the sampler and texture slot
2204 // number set up by the application.
2205 // This test will result in a blue triangle
2206 static const char *vertShaderText =
2207 "#version 140\n"
2208 "#extension GL_ARB_separate_shader_objects : enable\n"
2209 "#extension GL_ARB_shading_language_420pack : enable\n"
2210 "layout (location = 0) out vec4 samplePos;\n"
2211 "void main() {\n"
2212 " vec2 vertices[3];"
2213 " vertices[0] = vec2(-0.5, -0.5);\n"
2214 " vertices[1] = vec2( 0.5, -0.5);\n"
2215 " vertices[2] = vec2( 0.5, 0.5);\n"
2216 " vec2 positions[3];"
2217 " positions[0] = vec2( 0.0, 0.0);\n"
2218 " positions[1] = vec2( 1.0, 0.0);\n"
2219 " positions[2] = vec2( 1.0, 1.0);\n"
2220 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2221 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2222 "}\n";
2223
2224 static const char *fragShaderText =
2225 "#version 140\n"
2226 "#extension GL_ARB_separate_shader_objects : enable\n"
2227 "#extension GL_ARB_shading_language_420pack : enable\n"
2228 "layout (location = 0) in vec4 samplePos;\n"
2229 "layout (binding = 0) uniform sampler2D surface0;\n"
2230 "layout (binding = 1) uniform sampler2D surface1;\n"
2231 "layout (binding = 12) uniform sampler2D surface2;\n"
2232 "void main() {\n"
2233 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
2234 "}\n";
2235
2236 ASSERT_NO_FATAL_FAILURE(InitState());
2237 ASSERT_NO_FATAL_FAILURE(InitViewport());
2238
Tony Barbour01999182015-04-09 12:58:51 -06002239 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2240 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002241
Tony Barbour01999182015-04-09 12:58:51 -06002242 VkSamplerObj sampler1(m_device);
2243 VkSamplerObj sampler2(m_device);
2244 VkSamplerObj sampler3(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002245
Tony Barbour2f421a02015-04-01 16:38:10 -06002246 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
Tony Barbour01999182015-04-09 12:58:51 -06002247 VkTextureObj texture1(m_device, tex_colors); // Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002248 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
Tony Barbour01999182015-04-09 12:58:51 -06002249 VkTextureObj texture2(m_device, tex_colors); // Green
Tony Barbour2f421a02015-04-01 16:38:10 -06002250 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
Tony Barbour01999182015-04-09 12:58:51 -06002251 VkTextureObj texture3(m_device, tex_colors); // Blue
Tony Barbourf43b6982014-11-25 13:18:32 -07002252
Tony Barbour01999182015-04-09 12:58:51 -06002253 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002254 pipelineobj.AddShader(&vs);
2255 pipelineobj.AddShader(&ps);
2256
Tony Barbour01999182015-04-09 12:58:51 -06002257 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002258 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2259 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2260 for (int i = 0; i < 10; i++)
2261 descriptorSet.AppendDummy();
2262 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002263
Tony Barbourdd4c9642015-01-09 12:55:14 -07002264 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002265 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002266 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2267
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002268 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002269
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002270 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002271
2272#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002273 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002274 pDSDumpDot((char*)"triTest2.dot");
2275#endif
2276 // render triangle
2277 cmdBuffer.Draw(0, 3, 0, 1);
2278
2279 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002280 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002281 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002282
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002283 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002284}
2285
Tony Barbour01999182015-04-09 12:58:51 -06002286TEST_F(VkRenderTest, TriangleVSUniformBlock)
Tony Barbourf43b6982014-11-25 13:18:32 -07002287{
2288 // The expected result from this test is a blue triangle
2289
2290 static const char *vertShaderText =
2291 "#version 140\n"
2292 "#extension GL_ARB_separate_shader_objects : enable\n"
2293 "#extension GL_ARB_shading_language_420pack : enable\n"
2294 "layout (location = 0) out vec4 outColor;\n"
2295 "layout (std140, binding = 0) uniform bufferVals {\n"
2296 " vec4 red;\n"
2297 " vec4 green;\n"
2298 " vec4 blue;\n"
2299 " vec4 white;\n"
2300 "} myBufferVals;\n"
2301 "void main() {\n"
2302 " vec2 vertices[3];"
2303 " vertices[0] = vec2(-0.5, -0.5);\n"
2304 " vertices[1] = vec2( 0.5, -0.5);\n"
2305 " vertices[2] = vec2( 0.5, 0.5);\n"
2306 " outColor = myBufferVals.blue;\n"
2307 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2308 "}\n";
2309
2310 static const char *fragShaderText =
2311 "#version 140\n"
2312 "#extension GL_ARB_separate_shader_objects : enable\n"
2313 "#extension GL_ARB_shading_language_420pack : enable\n"
2314 "layout (location = 0) in vec4 inColor;\n"
2315 "void main() {\n"
2316 " gl_FragColor = inColor;\n"
2317 "}\n";
2318
2319 ASSERT_NO_FATAL_FAILURE(InitState());
2320 ASSERT_NO_FATAL_FAILURE(InitViewport());
2321
Tony Barbour01999182015-04-09 12:58:51 -06002322 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2323 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002324
2325 // Let's populate our buffer with the following:
2326 // vec4 red;
2327 // vec4 green;
2328 // vec4 blue;
2329 // vec4 white;
2330 const int valCount = 4 * 4;
2331 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2332 0.0, 1.0, 0.0, 1.0,
2333 0.0, 0.0, 1.0, 1.0,
2334 1.0, 1.0, 1.0, 1.0 };
2335
Tony Barbour01999182015-04-09 12:58:51 -06002336 VkConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002337
Tony Barbour01999182015-04-09 12:58:51 -06002338 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002339 pipelineobj.AddShader(&vs);
2340 pipelineobj.AddShader(&ps);
2341
Tony Barbour01999182015-04-09 12:58:51 -06002342 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002343 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002344
Tony Barbourdd4c9642015-01-09 12:55:14 -07002345 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002346 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002347 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2348
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002349 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002350
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002351 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002352
2353#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002354 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002355 pDSDumpDot((char*)"triTest2.dot");
2356#endif
2357 // render triangle
2358 cmdBuffer.Draw(0, 3, 0, 1);
2359
2360 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002361 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002362 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002363
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002364 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002365}
2366
Tony Barbour01999182015-04-09 12:58:51 -06002367TEST_F(VkRenderTest, TriangleFSUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002368{
2369 // This test allows the shader to select which buffer it is
2370 // pulling from using layout binding qualifier.
2371 // There are corresponding changes in the compiler stack that
2372 // will select the buffer using binding directly.
2373 // The binding number should match the slot number set up by
2374 // the application.
2375 // The expected result from this test is a purple triangle
2376
2377 static const char *vertShaderText =
2378 "#version 140\n"
2379 "#extension GL_ARB_separate_shader_objects : enable\n"
2380 "#extension GL_ARB_shading_language_420pack : enable\n"
2381 "void main() {\n"
2382 " vec2 vertices[3];"
2383 " vertices[0] = vec2(-0.5, -0.5);\n"
2384 " vertices[1] = vec2( 0.5, -0.5);\n"
2385 " vertices[2] = vec2( 0.5, 0.5);\n"
2386 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2387 "}\n";
2388
2389 static const char *fragShaderText =
2390 "#version 140\n"
2391 "#extension GL_ARB_separate_shader_objects : enable\n"
2392 "#extension GL_ARB_shading_language_420pack : enable\n"
2393 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2394 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2395 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002396 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
Tony Barbourf43b6982014-11-25 13:18:32 -07002397 "void main() {\n"
2398 " gl_FragColor = myBlueVal.color;\n"
2399 " gl_FragColor += myRedVal.color;\n"
2400 "}\n";
2401
2402 ASSERT_NO_FATAL_FAILURE(InitState());
2403 ASSERT_NO_FATAL_FAILURE(InitViewport());
2404
Tony Barbour01999182015-04-09 12:58:51 -06002405 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2406 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002407
2408 // We're going to create a number of uniform buffers, and then allow
2409 // the shader to select which it wants to read from with a binding
2410
2411 // Let's populate the buffers with a single color each:
2412 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2413 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2414 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002415 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002416
2417 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2418 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2419 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2420 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2421
2422 const int redCount = sizeof(redVals) / sizeof(float);
2423 const int greenCount = sizeof(greenVals) / sizeof(float);
2424 const int blueCount = sizeof(blueVals) / sizeof(float);
2425 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2426
Tony Barbour01999182015-04-09 12:58:51 -06002427 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002428
Tony Barbour01999182015-04-09 12:58:51 -06002429 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002430
Tony Barbour01999182015-04-09 12:58:51 -06002431 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002432
Tony Barbour01999182015-04-09 12:58:51 -06002433 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002434
Tony Barbour01999182015-04-09 12:58:51 -06002435 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002436 pipelineobj.AddShader(&vs);
2437 pipelineobj.AddShader(&ps);
2438
Tony Barbour01999182015-04-09 12:58:51 -06002439 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002440 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2441 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2442 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2443 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002444
Tony Barbourdd4c9642015-01-09 12:55:14 -07002445 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002446 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002447 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002448
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002449 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002450
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002451 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002452
2453#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002454 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002455 pDSDumpDot((char*)"triTest2.dot");
2456#endif
2457 // render triangle
2458 cmdBuffer.Draw(0, 3, 0, 1);
2459
2460 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002461 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002462 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002463
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002464 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002465}
2466
Tony Barbour01999182015-04-09 12:58:51 -06002467TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002468{
2469 // This test is the same as TriangleFSUniformBlockBinding, but
2470 // it does not provide an instance name.
2471 // The expected result from this test is a purple triangle
2472
2473 static const char *vertShaderText =
2474 "#version 140\n"
2475 "#extension GL_ARB_separate_shader_objects : enable\n"
2476 "#extension GL_ARB_shading_language_420pack : enable\n"
2477 "void main() {\n"
2478 " vec2 vertices[3];"
2479 " vertices[0] = vec2(-0.5, -0.5);\n"
2480 " vertices[1] = vec2( 0.5, -0.5);\n"
2481 " vertices[2] = vec2( 0.5, 0.5);\n"
2482 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2483 "}\n";
2484
2485 static const char *fragShaderText =
2486 "#version 430\n"
2487 "#extension GL_ARB_separate_shader_objects : enable\n"
2488 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002489 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2490 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2491 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002492 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002493 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002494 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002495 " outColor = blue;\n"
2496 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002497 "}\n";
2498 ASSERT_NO_FATAL_FAILURE(InitState());
2499 ASSERT_NO_FATAL_FAILURE(InitViewport());
2500
Tony Barbour01999182015-04-09 12:58:51 -06002501 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2502 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002503
2504 // We're going to create a number of uniform buffers, and then allow
2505 // the shader to select which it wants to read from with a binding
2506
2507 // Let's populate the buffers with a single color each:
2508 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2509 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2510 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2511 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2512
2513 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2514 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2515 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2516 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2517
2518 const int redCount = sizeof(redVals) / sizeof(float);
2519 const int greenCount = sizeof(greenVals) / sizeof(float);
2520 const int blueCount = sizeof(blueVals) / sizeof(float);
2521 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2522
Tony Barbour01999182015-04-09 12:58:51 -06002523 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002524
Tony Barbour01999182015-04-09 12:58:51 -06002525 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002526
Tony Barbour01999182015-04-09 12:58:51 -06002527 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002528
Tony Barbour01999182015-04-09 12:58:51 -06002529 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002530
Tony Barbour01999182015-04-09 12:58:51 -06002531 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002532 pipelineobj.AddShader(&vs);
2533 pipelineobj.AddShader(&ps);
2534
Tony Barbour01999182015-04-09 12:58:51 -06002535 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002536 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2537 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2538 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2539 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002540
Tony Barbourdd4c9642015-01-09 12:55:14 -07002541 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002542 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002543 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2544
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002545 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002546
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002547 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002548
2549#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002550 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002551 pDSDumpDot((char*)"triTest2.dot");
2552#endif
2553 // render triangle
2554 cmdBuffer.Draw(0, 3, 0, 1);
2555
2556 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002557 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002558 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002559
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002560 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002561}
2562
Tony Barbour01999182015-04-09 12:58:51 -06002563TEST_F(VkRenderTest, CubeWithVertexFetchAndMVPAndTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07002564{
2565 static const char *vertShaderText =
2566 "#version 140\n"
2567 "#extension GL_ARB_separate_shader_objects : enable\n"
2568 "#extension GL_ARB_shading_language_420pack : enable\n"
2569 "layout (std140, binding=0) uniform bufferVals {\n"
2570 " mat4 mvp;\n"
2571 "} myBufferVals;\n"
2572 "layout (location=0) in vec4 pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002573 "layout (location=1) in vec2 input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002574 "layout (location=0) out vec2 UV;\n"
2575 "void main() {\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002576 " UV = input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002577 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002578 " gl_Position.y = -gl_Position.y;\n"
2579 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002580 "}\n";
2581
2582 static const char *fragShaderText =
2583 "#version 140\n"
2584 "#extension GL_ARB_separate_shader_objects : enable\n"
2585 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002586 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002587 "layout (location=0) out vec4 outColor;\n"
2588 "layout (location=0) in vec2 UV;\n"
2589 "void main() {\n"
2590 " outColor= textureLod(surface, UV, 0.0);\n"
2591 "}\n";
2592 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2593
2594 glm::mat4 View = glm::lookAt(
2595 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2596 glm::vec3(0,0,0), // and looks at the origin
2597 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2598 );
2599
2600 glm::mat4 Model = glm::mat4(1.0f);
2601
2602 glm::mat4 MVP = Projection * View * Model;
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002603 int num_verts = sizeof(g_vb_texture_Data) / sizeof(g_vb_texture_Data[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002604
2605
2606 ASSERT_NO_FATAL_FAILURE(InitState());
2607 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour17c6ab12015-03-27 17:03:18 -06002608 m_depthStencil->Init(m_device, m_width, m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07002609
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002610 VkConstantBufferObj meshBuffer(m_device, num_verts,
2611 sizeof(g_vb_texture_Data[0]), g_vb_texture_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002612 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002613
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002614 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07002615
Tony Barbour01999182015-04-09 12:58:51 -06002616 VkConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2617 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2618 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2619 VkSamplerObj sampler(m_device);
2620 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002621
Tony Barbour01999182015-04-09 12:58:51 -06002622 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002623 pipelineobj.AddShader(&vs);
2624 pipelineobj.AddShader(&ps);
2625
Tony Barbour01999182015-04-09 12:58:51 -06002626 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002627 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mvpBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002628 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002629
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002630#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002631 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002632 MESH_BIND_ID, // binding ID
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002633 sizeof(g_vb_texture_Data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002634 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002635 };
Tony Barbourf43b6982014-11-25 13:18:32 -07002636
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002637 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002638 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2639 vi_attribs[0].location = 0; // location
Tony Barbour8205d902015-04-16 15:59:00 -06002640 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002641 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2642 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2643 vi_attribs[1].location = 1; // location
2644 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
2645 vi_attribs[1].offsetInBytes = 16; // Offset of uv components
Tony Barbourf43b6982014-11-25 13:18:32 -07002646
Tony Barbourf43b6982014-11-25 13:18:32 -07002647 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002648 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2649 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07002650
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002651 VkPipelineDsStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002652 ds_state.depthTestEnable = VK_TRUE;
2653 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06002654 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002655 ds_state.depthBoundsEnable = VK_FALSE;
2656 ds_state.stencilTestEnable = VK_FALSE;
2657 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
2658 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
2659 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06002660 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
2661 ds_state.format = VK_FORMAT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002662 ds_state.front = ds_state.back;
2663 pipelineobj.SetDepthStencil(&ds_state);
2664
Tony Barbour17c6ab12015-03-27 17:03:18 -06002665 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour01999182015-04-09 12:58:51 -06002666 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002667 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002668
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002669 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002670
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002671 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002672
2673 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2674#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002675 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002676 pDSDumpDot((char*)"triTest2.dot");
2677#endif
2678 // render triangle
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002679 cmdBuffer.Draw(0, num_verts, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002680
2681 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002682 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002683 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002684
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002685 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002686 RotateTriangleVSUniform(Projection, View, Model, &mvpBuffer, &cmdBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002687}
Cody Northropd1ce7842014-12-09 11:17:01 -07002688
Tony Barbour01999182015-04-09 12:58:51 -06002689TEST_F(VkRenderTest, TriangleMixedSamplerUniformBlockBinding)
Cody Northropd1ce7842014-12-09 11:17:01 -07002690{
2691 // This test mixes binding slots of textures and buffers, ensuring
2692 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002693 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002694 // you can modify it to move the desired result around.
2695
2696 static const char *vertShaderText =
2697 "#version 140\n"
2698 "#extension GL_ARB_separate_shader_objects : enable\n"
2699 "#extension GL_ARB_shading_language_420pack : enable\n"
2700 "void main() {\n"
2701 " vec2 vertices[3];"
2702 " vertices[0] = vec2(-0.5, -0.5);\n"
2703 " vertices[1] = vec2( 0.5, -0.5);\n"
2704 " vertices[2] = vec2( 0.5, 0.5);\n"
2705 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2706 "}\n";
2707
2708 static const char *fragShaderText =
2709 "#version 430\n"
2710 "#extension GL_ARB_separate_shader_objects : enable\n"
2711 "#extension GL_ARB_shading_language_420pack : enable\n"
2712 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002713 "layout (binding = 3) uniform sampler2D surface1;\n"
2714 "layout (binding = 1) uniform sampler2D surface2;\n"
2715 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002716
Cody Northropa0410942014-12-09 13:59:39 -07002717
Chia-I Wuf8385062015-01-04 16:27:24 +08002718 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2719 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2720 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2721 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002722 "layout (location = 0) out vec4 outColor;\n"
2723 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002724 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002725 " outColor += white * vec4(0.00001);\n"
2726 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002727 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002728 "}\n";
2729 ASSERT_NO_FATAL_FAILURE(InitState());
2730 ASSERT_NO_FATAL_FAILURE(InitViewport());
2731
Tony Barbour01999182015-04-09 12:58:51 -06002732 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2733 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northropd1ce7842014-12-09 11:17:01 -07002734
Cody Northropd1ce7842014-12-09 11:17:01 -07002735 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2736 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2737 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2738 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2739
2740 const int redCount = sizeof(redVals) / sizeof(float);
2741 const int greenCount = sizeof(greenVals) / sizeof(float);
2742 const int blueCount = sizeof(blueVals) / sizeof(float);
2743 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2744
Tony Barbour01999182015-04-09 12:58:51 -06002745 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2746 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2747 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2748 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002749
Tony Barbour2f421a02015-04-01 16:38:10 -06002750 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002751 VkSamplerObj sampler0(m_device);
2752 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002753 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002754 VkSamplerObj sampler2(m_device);
2755 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002756 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002757 VkSamplerObj sampler4(m_device);
2758 VkTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropa0410942014-12-09 13:59:39 -07002759
2760 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2761 // TODO: Get back here ASAP and understand why.
Tony Barbour2f421a02015-04-01 16:38:10 -06002762 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06002763 VkSamplerObj sampler7(m_device);
2764 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropd1ce7842014-12-09 11:17:01 -07002765
Tony Barbour01999182015-04-09 12:58:51 -06002766 VkPipelineObj pipelineobj(m_device);
Cody Northropd1ce7842014-12-09 11:17:01 -07002767 pipelineobj.AddShader(&vs);
2768 pipelineobj.AddShader(&ps);
2769
Tony Barbour01999182015-04-09 12:58:51 -06002770 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002771 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2772 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2773 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2774 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002775 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002776 // swap blue and green
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002777 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2778 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2779 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002780
Tony Barbourdd4c9642015-01-09 12:55:14 -07002781 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002782 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002783 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002784
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002785 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002786
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002787 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002788
2789#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002790 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002791 pDSDumpDot((char*)"triTest2.dot");
2792#endif
2793 // render triangle
2794 cmdBuffer.Draw(0, 3, 0, 1);
2795
2796 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002797 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002798 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002799
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002800 RecordImages(m_renderTargets);
Cody Northropd1ce7842014-12-09 11:17:01 -07002801}
2802
Tony Barbour01999182015-04-09 12:58:51 -06002803TEST_F(VkRenderTest, TriangleMatchingSamplerUniformBlockBinding)
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002804{
2805 // This test matches binding slots of textures and buffers, requiring
2806 // the driver to give them distinct number spaces.
2807 // The expected result from this test is a red triangle, although
2808 // you can modify it to move the desired result around.
2809
2810 static const char *vertShaderText =
2811 "#version 140\n"
2812 "#extension GL_ARB_separate_shader_objects : enable\n"
2813 "#extension GL_ARB_shading_language_420pack : enable\n"
2814 "void main() {\n"
2815 " vec2 vertices[3];"
2816 " vertices[0] = vec2(-0.5, -0.5);\n"
2817 " vertices[1] = vec2( 0.5, -0.5);\n"
2818 " vertices[2] = vec2( 0.5, 0.5);\n"
2819 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2820 "}\n";
2821
2822 static const char *fragShaderText =
2823 "#version 430\n"
2824 "#extension GL_ARB_separate_shader_objects : enable\n"
2825 "#extension GL_ARB_shading_language_420pack : enable\n"
2826 "layout (binding = 0) uniform sampler2D surface0;\n"
2827 "layout (binding = 1) uniform sampler2D surface1;\n"
2828 "layout (binding = 2) uniform sampler2D surface2;\n"
2829 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002830 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2831 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2832 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2833 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002834 "layout (location = 0) out vec4 outColor;\n"
2835 "void main() {\n"
2836 " outColor = red;// * vec4(0.00001);\n"
2837 " outColor += white * vec4(0.00001);\n"
2838 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2839 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2840 "}\n";
2841 ASSERT_NO_FATAL_FAILURE(InitState());
2842 ASSERT_NO_FATAL_FAILURE(InitViewport());
2843
Tony Barbour01999182015-04-09 12:58:51 -06002844 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2845 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002846
2847 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2848 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2849 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2850 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2851
2852 const int redCount = sizeof(redVals) / sizeof(float);
2853 const int greenCount = sizeof(greenVals) / sizeof(float);
2854 const int blueCount = sizeof(blueVals) / sizeof(float);
2855 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2856
Tony Barbour01999182015-04-09 12:58:51 -06002857 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2858 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2859 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2860 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002861
Tony Barbour2f421a02015-04-01 16:38:10 -06002862 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002863 VkSamplerObj sampler0(m_device);
2864 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002865 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002866 VkSamplerObj sampler2(m_device);
2867 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002868 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002869 VkSamplerObj sampler4(m_device);
2870 VkTextureObj texture4(m_device, tex_colors); // Light Green
Tony Barbour2f421a02015-04-01 16:38:10 -06002871 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06002872 VkSamplerObj sampler7(m_device);
2873 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002874
Tony Barbour01999182015-04-09 12:58:51 -06002875 VkPipelineObj pipelineobj(m_device);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002876 pipelineobj.AddShader(&vs);
2877 pipelineobj.AddShader(&ps);
2878
Tony Barbour01999182015-04-09 12:58:51 -06002879 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002880 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2881 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2882 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2883 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002884 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2885 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2886 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2887 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002888
Tony Barbourdd4c9642015-01-09 12:55:14 -07002889 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002890 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002891 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002892
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002893 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002894
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002895 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002896
2897#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002898 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002899 pDSDumpDot((char*)"triTest2.dot");
2900#endif
2901 // render triangle
2902 cmdBuffer.Draw(0, 3, 0, 1);
2903
2904 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002905 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002906 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002907
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002908 RecordImages(m_renderTargets);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002909}
2910
Tony Barbour01999182015-04-09 12:58:51 -06002911TEST_F(VkRenderTest, TriangleUniformBufferLayout)
Cody Northrop02690bd2014-12-17 15:26:33 -07002912{
2913 // This test populates a buffer with a variety of different data
2914 // types, then reads them out with a shader.
2915 // The expected result from this test is a green triangle
2916
2917 static const char *vertShaderText =
2918 "#version 140\n"
2919 "#extension GL_ARB_separate_shader_objects : enable\n"
2920 "#extension GL_ARB_shading_language_420pack : enable\n"
2921 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2922 " vec4 fRed;\n"
2923 " vec4 fGreen;\n"
2924 " layout(row_major) mat4 worldToProj;\n"
2925 " layout(row_major) mat4 projToWorld;\n"
2926 " layout(row_major) mat4 worldToView;\n"
2927 " layout(row_major) mat4 viewToProj;\n"
2928 " layout(row_major) mat4 worldToShadow[4];\n"
2929 " float fZero;\n"
2930 " float fOne;\n"
2931 " float fTwo;\n"
2932 " float fThree;\n"
2933 " vec3 fZeroZeroZero;\n"
2934 " float fFour;\n"
2935 " vec3 fZeroZeroOne;\n"
2936 " float fFive;\n"
2937 " vec3 fZeroOneZero;\n"
2938 " float fSix;\n"
2939 " float fSeven;\n"
2940 " float fEight;\n"
2941 " float fNine;\n"
2942 " vec2 fZeroZero;\n"
2943 " vec2 fZeroOne;\n"
2944 " vec4 fBlue;\n"
2945 " vec2 fOneZero;\n"
2946 " vec2 fOneOne;\n"
2947 " vec3 fZeroOneOne;\n"
2948 " float fTen;\n"
2949 " float fEleven;\n"
2950 " float fTwelve;\n"
2951 " vec3 fOneZeroZero;\n"
2952 " vec4 uvOffsets[4];\n"
2953 "};\n"
2954 "layout (location = 0) out vec4 color;"
2955 "void main() {\n"
2956
2957 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2958 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2959 " \n"
2960
2961 // do some exact comparisons, even though we should
2962 // really have an epsilon involved.
2963 " vec4 outColor = right;\n"
2964 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
2965 " outColor = wrong;\n"
2966 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
2967 " outColor = wrong;\n"
2968 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
2969 " outColor = wrong;\n"
2970
2971 " color = outColor;\n"
2972
2973 // generic position stuff
2974 " vec2 vertices;\n"
2975 " int vertexSelector = gl_VertexID;\n"
2976 " if (vertexSelector == 0)\n"
2977 " vertices = vec2(-0.5, -0.5);\n"
2978 " else if (vertexSelector == 1)\n"
2979 " vertices = vec2( 0.5, -0.5);\n"
2980 " else if (vertexSelector == 2)\n"
2981 " vertices = vec2( 0.5, 0.5);\n"
2982 " else\n"
2983 " vertices = vec2( 0.0, 0.0);\n"
2984 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
2985 "}\n";
2986
2987 static const char *fragShaderText =
2988 "#version 140\n"
2989 "#extension GL_ARB_separate_shader_objects : enable\n"
2990 "#extension GL_ARB_shading_language_420pack : enable\n"
2991 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2992 " vec4 fRed;\n"
2993 " vec4 fGreen;\n"
2994 " layout(row_major) mat4 worldToProj;\n"
2995 " layout(row_major) mat4 projToWorld;\n"
2996 " layout(row_major) mat4 worldToView;\n"
2997 " layout(row_major) mat4 viewToProj;\n"
2998 " layout(row_major) mat4 worldToShadow[4];\n"
2999 " float fZero;\n"
3000 " float fOne;\n"
3001 " float fTwo;\n"
3002 " float fThree;\n"
3003 " vec3 fZeroZeroZero;\n"
3004 " float fFour;\n"
3005 " vec3 fZeroZeroOne;\n"
3006 " float fFive;\n"
3007 " vec3 fZeroOneZero;\n"
3008 " float fSix;\n"
3009 " float fSeven;\n"
3010 " float fEight;\n"
3011 " float fNine;\n"
3012 " vec2 fZeroZero;\n"
3013 " vec2 fZeroOne;\n"
3014 " vec4 fBlue;\n"
3015 " vec2 fOneZero;\n"
3016 " vec2 fOneOne;\n"
3017 " vec3 fZeroOneOne;\n"
3018 " float fTen;\n"
3019 " float fEleven;\n"
3020 " float fTwelve;\n"
3021 " vec3 fOneZeroZero;\n"
3022 " vec4 uvOffsets[4];\n"
3023 "};\n"
3024 "layout (location = 0) in vec4 color;\n"
3025 "void main() {\n"
3026 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3027 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3028 " \n"
3029
3030 // start with VS value to ensure it passed
3031 " vec4 outColor = color;\n"
3032
3033 // do some exact comparisons, even though we should
3034 // really have an epsilon involved.
3035 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3036 " outColor = wrong;\n"
3037 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3038 " outColor = wrong;\n"
3039 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3040 " outColor = wrong;\n"
3041 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3042 " outColor = wrong;\n"
3043 " if (fTwo != 2.0)\n"
3044 " outColor = wrong;\n"
3045 " if (fOneOne != vec2(1.0, 1.0))\n"
3046 " outColor = wrong;\n"
3047 " if (fTen != 10.0)\n"
3048 " outColor = wrong;\n"
3049 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3050 " outColor = wrong;\n"
3051 " \n"
3052 " gl_FragColor = outColor;\n"
3053 "}\n";
3054
3055
3056 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3057 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3058 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3059 0.0, 1.0, 0.0, 1.0, // align
3060 0.0, 0.0, 1.0, 1.0, // align
3061 0.0, 0.0, 0.0, 1.0, // align
3062 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3063 0.0, 2.0, 0.0, 2.0, // align
3064 0.0, 0.0, 2.0, 2.0, // align
3065 0.0, 0.0, 0.0, 2.0, // align
3066 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3067 0.0, 3.0, 0.0, 3.0, // align
3068 0.0, 0.0, 3.0, 3.0, // align
3069 0.0, 0.0, 0.0, 3.0, // align
3070 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3071 0.0, 4.0, 0.0, 4.0, // align
3072 0.0, 0.0, 4.0, 4.0, // align
3073 0.0, 0.0, 0.0, 4.0, // align
3074 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3075 0.0, 5.0, 0.0, 5.0, // align
3076 0.0, 0.0, 5.0, 5.0, // align
3077 0.0, 0.0, 0.0, 5.0, // align
3078 6.0, 0.0, 0.0, 6.0, // align
3079 0.0, 6.0, 0.0, 6.0, // align
3080 0.0, 0.0, 6.0, 6.0, // align
3081 0.0, 0.0, 0.0, 6.0, // align
3082 7.0, 0.0, 0.0, 7.0, // align
3083 0.0, 7.0, 0.0, 7.0, // align
3084 0.0, 0.0, 7.0, 7.0, // align
3085 0.0, 0.0, 0.0, 7.0, // align
3086 8.0, 0.0, 0.0, 8.0, // align
3087 0.0, 8.0, 0.0, 8.0, // align
3088 0.0, 0.0, 8.0, 8.0, // align
3089 0.0, 0.0, 0.0, 8.0, // align
3090 0.0, // float fZero; // align
3091 1.0, // float fOne; // pack
3092 2.0, // float fTwo; // pack
3093 3.0, // float fThree; // pack
3094 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3095 4.0, // float fFour; // pack
3096 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3097 5.0, // float fFive; // pack
3098 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3099 6.0, // float fSix; // pack
3100 7.0, // float fSeven; // align
3101 8.0, // float fEight; // pack
3102 9.0, // float fNine; // pack
3103 0.0, // BUFFER
3104 0.0, 0.0, // vec2 fZeroZero; // align
3105 0.0, 1.0, // vec2 fZeroOne; // pack
3106 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3107 1.0, 0.0, // vec2 fOneZero; // align
3108 1.0, 1.0, // vec2 fOneOne; // pack
3109 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3110 10.0, // float fTen; // pack
3111 11.0, // float fEleven; // align
3112 12.0, // float fTwelve; // pack
3113 0.0, 0.0, // BUFFER
3114 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3115 0.0, // BUFFER
3116 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3117 0.5, 0.6, 0.7, 0.8, // align
3118 0.9, 1.0, 1.1, 1.2, // align
3119 1.3, 1.4, 1.5, 1.6, // align
3120 };
3121
3122 ASSERT_NO_FATAL_FAILURE(InitState());
3123 ASSERT_NO_FATAL_FAILURE(InitViewport());
3124
3125 const int constCount = sizeof(mixedVals) / sizeof(float);
3126
Tony Barbour01999182015-04-09 12:58:51 -06003127 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3128 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop02690bd2014-12-17 15:26:33 -07003129
Tony Barbour01999182015-04-09 12:58:51 -06003130 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003131
Tony Barbour01999182015-04-09 12:58:51 -06003132 VkPipelineObj pipelineobj(m_device);
Cody Northrop02690bd2014-12-17 15:26:33 -07003133 pipelineobj.AddShader(&vs);
3134 pipelineobj.AddShader(&ps);
3135
Tony Barbour01999182015-04-09 12:58:51 -06003136 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003137 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003138
3139 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06003140 VkCommandBufferObj cmdBuffer(m_device);
Cody Northrop02690bd2014-12-17 15:26:33 -07003141 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3142
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003143 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Cody Northrop02690bd2014-12-17 15:26:33 -07003144
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003145 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Cody Northrop02690bd2014-12-17 15:26:33 -07003146
3147#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003148 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop02690bd2014-12-17 15:26:33 -07003149 pDSDumpDot((char*)"triTest2.dot");
3150#endif
3151 // render triangle
3152 cmdBuffer.Draw(0, 3, 0, 1);
3153
3154 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003155 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003156 cmdBuffer.QueueCommandBuffer();
Cody Northrop02690bd2014-12-17 15:26:33 -07003157
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003158 RecordImages(m_renderTargets);
Cody Northrop02690bd2014-12-17 15:26:33 -07003159}
3160
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003161int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003162 int result;
3163
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003164 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06003165 VkTestFramework::InitArgs(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003166
Chia-I Wu7133fdc2014-12-15 23:57:34 +08003167 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06003168
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003169 result = RUN_ALL_TESTS();
3170
Tony Barbour01999182015-04-09 12:58:51 -06003171 VkTestFramework::Finish();
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003172 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003173}