blob: b7472e9a696fd658f3e5bc17176bef57eb3ba230 [file] [log] [blame]
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06001// Copyright 2005, Google Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14// * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060031// VK tests
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060032//
33// Copyright (C) 2014 LunarG, Inc.
34//
35// Permission is hereby granted, free of charge, to any person obtaining a
36// copy of this software and associated documentation files (the "Software"),
37// to deal in the Software without restriction, including without limitation
38// the rights to use, copy, modify, merge, publish, distribute, sublicense,
39// and/or sell copies of the Software, and to permit persons to whom the
40// Software is furnished to do so, subject to the following conditions:
41//
42// The above copyright notice and this permission notice shall be included
43// in all copies or substantial portions of the Software.
44//
45// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
48// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
49// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
50// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
51// DEALINGS IN THE SOFTWARE.
52
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060053// Basic rendering tests
54
55#include <stdlib.h>
56#include <stdio.h>
57#include <stdbool.h>
58#include <string.h>
Courtney Goeltzenleuchter76a643b2014-08-21 17:34:22 -060059#include <iostream>
60#include <fstream>
61using namespace std;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060062
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060063#include <vulkan.h>
Tobin Ehlis31446e52014-11-28 11:17:19 -070064#ifdef DUMP_STATE_DOT
65#include "../layers/draw_state.h"
66#endif
Tobin Ehlis3c26a542014-11-18 11:28:33 -070067#ifdef PRINT_OBJECTS
68#include "../layers/object_track.h"
69#endif
Tobin Ehlis791a49c2014-11-10 12:29:12 -070070#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060071#include <vkDbg.h>
Tobin Ehlis791a49c2014-11-10 12:29:12 -070072#endif
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060073#include "gtest-1.7.0/include/gtest/gtest.h"
74
Cody Northropd4e020a2015-03-17 14:54:35 -060075#include "icd-spv.h"
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060076
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -060077#define GLM_FORCE_RADIANS
78#include "glm/glm.hpp"
79#include <glm/gtc/matrix_transform.hpp>
80
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060081#include "vkrenderframework.h"
Tobin Ehlis791a49c2014-11-10 12:29:12 -070082#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060083void VKAPI myDbgFunc(
84 VK_DBG_MSG_TYPE msgType,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060085 VkValidationLevel validationLevel,
Mike Stroyan230e6252015-04-17 12:36:38 -060086 VkObject srcObject,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060087 size_t location,
88 int32_t msgCode,
89 const char* pMsg,
90 void* pUserData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -070091{
Tobin Ehlis3c26a542014-11-18 11:28:33 -070092 switch (msgType)
93 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060094 case VK_DBG_MSG_WARNING:
Tobin Ehlis3c26a542014-11-18 11:28:33 -070095 printf("CALLBACK WARNING : %s\n", pMsg);
96 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060097 case VK_DBG_MSG_ERROR:
Tobin Ehlis3c26a542014-11-18 11:28:33 -070098 printf("CALLBACK ERROR : %s\n", pMsg);
99 break;
100 default:
101 printf("EATING Msg of type %u\n", msgType);
102 break;
103 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700104}
105#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700106
107
108#undef ASSERT_NO_FATAL_FAILURE
109#define ASSERT_NO_FATAL_FAILURE(x) x
110
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600111//--------------------------------------------------------------------------------------
112// Mesh and VertexFormat Data
113//--------------------------------------------------------------------------------------
114struct Vertex
115{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600116 float posX, posY, posZ, posW; // Position data
117 float r, g, b, a; // Color
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600118};
119
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600120struct VertexUV
121{
122 float posX, posY, posZ, posW; // Position data
123 float u, v; // texture u,v
124};
125
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600126#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600127#define UV(_u_, _v_) (_u_), (_v_)
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600128
129static const Vertex g_vbData[] =
130{
131 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
132 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
133 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
134 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
135 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
136 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
137
138 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
139 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
140 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
141 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
142 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
143 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
144
145 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
146 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
147 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
148 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
149 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
150 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
151
152 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
153 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
154 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
155 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
156 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
157 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
158
159 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
160 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
161 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
162 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
163 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
164 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
165
166 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
167 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
168 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
169 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
170 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
171 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
172};
173
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600174static const Vertex g_vb_solid_face_colors_Data[] =
175{
176 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600177 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600178 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
179 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600180 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
181 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600182
183 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
184 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600185 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
186 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600187 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600188 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600189
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600190 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
191 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
192 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
193 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
194 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
195 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600196
197 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
198 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
199 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
200 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
201 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
202 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
203
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600204 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600205 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600206 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
207 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600208 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
209 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
210
211 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
212 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
213 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
214 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
215 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
216 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
217};
218
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600219static const VertexUV g_vb_texture_Data[] =
220{
221 { XYZ1( -1, -1, -1 ), UV( 0.f, 0.f ) },
222 { XYZ1( -1, 1, 1 ), UV( 1.f, 1.f ) },
223 { XYZ1( -1, -1, 1 ), UV( 1.f, 0.f ) },
224 { XYZ1( -1, 1, 1 ), UV( 1.f, 1.f ) },
225 { XYZ1( -1, -1, -1 ), UV( 0.f, 0.f ) },
226 { XYZ1( -1, 1, -1 ), UV( 0.f, 1.f ) },
227
228 { XYZ1( -1, -1, -1 ), UV( 1.f, 0.f ) },
229 { XYZ1( 1, -1, -1 ), UV( 0.f, 0.f ) },
230 { XYZ1( 1, 1, -1 ), UV( 0.f, 1.f ) },
231 { XYZ1( -1, -1, -1 ), UV( 1.f, 0.f ) },
232 { XYZ1( 1, 1, -1 ), UV( 0.f, 1.f ) },
233 { XYZ1( -1, 1, -1 ), UV( 1.f, 1.f ) },
234
235 { XYZ1( -1, -1, -1 ), UV( 1.f, 1.f ) },
236 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
237 { XYZ1( 1, -1, -1 ), UV( 1.f, 0.f ) },
238 { XYZ1( -1, -1, -1 ), UV( 1.f, 1.f ) },
239 { XYZ1( -1, -1, 1 ), UV( 0.f, 1.f ) },
240 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
241
242 { XYZ1( -1, 1, -1 ), UV( 1.f, 1.f ) },
243 { XYZ1( 1, 1, 1 ), UV( 0.f, 0.f ) },
244 { XYZ1( -1, 1, 1 ), UV( 0.f, 1.f ) },
245 { XYZ1( -1, 1, -1 ), UV( 1.f, 1.f ) },
246 { XYZ1( 1, 1, -1 ), UV( 1.f, 0.f ) },
247 { XYZ1( 1, 1, 1 ), UV( 0.f, 0.f ) },
248
249 { XYZ1( 1, 1, -1 ), UV( 1.f, 1.f ) },
250 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
251 { XYZ1( 1, 1, 1 ), UV( 0.f, 1.f ) },
252 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
253 { XYZ1( 1, 1, -1 ), UV( 1.f, 1.f ) },
254 { XYZ1( 1, -1, -1 ), UV( 1.f, 0.f ) },
255
256 { XYZ1( -1, 1, 1 ), UV( 0.f, 1.f ) },
257 { XYZ1( 1, 1, 1 ), UV( 1.f, 1.f ) },
258 { XYZ1( -1, -1, 1 ), UV( 0.f, 0.f ) },
259 { XYZ1( -1, -1, 1 ), UV( 0.f, 0.f ) },
260 { XYZ1( 1, 1, 1 ), UV( 1.f, 1.f ) },
261 { XYZ1( 1, -1, 1 ), UV( 1.f, 0.f ) },
262};
263
Tony Barbour01999182015-04-09 12:58:51 -0600264class VkRenderTest : public VkRenderFramework
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -0600265{
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600266public:
Cody Northrop4e6b4762014-10-09 21:25:22 -0600267
Tony Barbourf43b6982014-11-25 13:18:32 -0700268 void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbour01999182015-04-09 12:58:51 -0600269 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer);
270 void GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600271 void InitDepthStencil();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600272 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate);
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600273
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600274 VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer);
275 VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer);
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600276
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600277protected:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600278 VkImage m_texture;
279 VkImageView m_textureView;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800280 VkDescriptorInfo m_descriptorInfo;
Tony Barbour8205d902015-04-16 15:59:00 -0600281 VkDeviceMemory m_textureMem;
Cody Northrop350727b2014-10-06 15:42:00 -0600282
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600283 VkSampler m_sampler;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600284
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600285
286 virtual void SetUp() {
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600287
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600288 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600289 this->app_info.pNext = NULL;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800290 this->app_info.pAppName = "render_tests";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600291 this->app_info.appVersion = 1;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800292 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600293 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600294 this->app_info.apiVersion = VK_API_VERSION;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600295
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800296 memset(&m_descriptorInfo, 0, sizeof(m_descriptorInfo));
Cody Northrop350727b2014-10-06 15:42:00 -0600297
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600298 InitFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600299 }
300
301 virtual void TearDown() {
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600302 // Clean up resources before we reset
303 ShutdownFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600304 }
305};
306
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600307VkResult VkRenderTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600308{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600309 VkResult result;
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600310
311 result = cmdBuffer.BeginCommandBuffer();
312
313 /*
314 * For render test all drawing happens in a single render pass
315 * on a single command buffer.
316 */
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600317 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600318 cmdBuffer.BeginRenderPass(renderPass(), framebuffer());
319 }
320
321 return result;
322}
323
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600324VkResult VkRenderTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600325{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600326 VkResult result;
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600327
328 cmdBuffer.EndRenderPass(renderPass());
329
330 result = cmdBuffer.EndCommandBuffer();
331
332 return result;
333}
334
335
Tony Barbour01999182015-04-09 12:58:51 -0600336void VkRenderTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet)
Tony Barbour02472db2015-01-08 17:08:28 -0700337{
Tony Barbour17c6ab12015-03-27 17:03:18 -0600338 if (m_depthStencil->Initialized()) {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600339 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Tony Barbour17c6ab12015-03-27 17:03:18 -0600340 } else {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600341 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour17c6ab12015-03-27 17:03:18 -0600342 }
343
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700344 cmdBuffer->PrepareAttachments();
Tony Barbour8205d902015-04-16 15:59:00 -0600345 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_RASTER, m_stateRaster);
346 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_VIEWPORT, m_stateViewport);
347 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_COLOR_BLEND, m_colorBlend);
348 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_DEPTH_STENCIL, m_stateDepthStencil);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600349 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
350 pipelineobj.CreateVKPipeline(descriptorSet);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600351 cmdBuffer->BindPipeline(pipelineobj);
Chia-I Wu862c5572015-03-28 15:23:55 +0800352 cmdBuffer->BindDescriptorSet(descriptorSet);
Tony Barbour02472db2015-01-08 17:08:28 -0700353}
Tony Barbourf43b6982014-11-25 13:18:32 -0700354
Tony Barbour01999182015-04-09 12:58:51 -0600355void VkRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
356 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer)
Tony Barbourdd4c9642015-01-09 12:55:14 -0700357{
358 int i;
359 glm::mat4 MVP;
360 int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600361 VkResult err;
Tony Barbourdd4c9642015-01-09 12:55:14 -0700362
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600363 /* Only do 3 positions to avoid back face cull */
364 for (i = 0; i < 3; i++) {
Tony Barbourdd4c9642015-01-09 12:55:14 -0700365 void *pData = constantBuffer->map();
366
367 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
368 MVP = Projection * View * Model;
369 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
370
371 constantBuffer->unmap();
372
373 // submit the command buffer to the universal queue
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600374 cmdBuffer->QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700375
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600376 err = vkQueueWaitIdle( m_device->m_queue );
377 ASSERT_VK_SUCCESS( err );
Tony Barbourdd4c9642015-01-09 12:55:14 -0700378
379 // Wait for work to finish before cleaning up.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600380 vkDeviceWaitIdle(m_device->device());
Tony Barbourdd4c9642015-01-09 12:55:14 -0700381
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700382 assert(m_renderTargets.size() == 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -0700383 RecordImage(m_renderTargets[0]);
384 }
385}
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600386
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600387void dumpMatrix(const char *note, glm::mat4 MVP)
388{
Chia-I Wu7133fdc2014-12-15 23:57:34 +0800389 int i;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600390
391 printf("%s: \n", note);
392 for (i=0; i<4; i++) {
393 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
394 }
395 printf("\n");
396 fflush(stdout);
397}
398
399void dumpVec4(const char *note, glm::vec4 vector)
400{
401 printf("%s: \n", note);
402 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
403 printf("\n");
404 fflush(stdout);
405}
406
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600407struct vktriangle_vs_uniform {
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600408 // Must start with MVP
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600409 float mvp[4][4];
410 float position[3][4];
411 float color[3][4];
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600412};
413
Tony Barbour01999182015-04-09 12:58:51 -0600414void VkRenderTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600415{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700416#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600417 vkDbgRegisterMsgCallback(inst, myDbgFunc, NULL);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700418#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600419 // Create identity matrix
420 int i;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600421 struct vktriangle_vs_uniform data;
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600422
423 glm::mat4 Projection = glm::mat4(1.0f);
424 glm::mat4 View = glm::mat4(1.0f);
425 glm::mat4 Model = glm::mat4(1.0f);
426 glm::mat4 MVP = Projection * View * Model;
427 const int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600428 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600429 memcpy(&data.mvp, &MVP[0][0], matrixSize);
430
431 static const Vertex tri_data[] =
432 {
433 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
434 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
435 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
436 };
437
438 for (i=0; i<3; i++) {
439 data.position[i][0] = tri_data[i].posX;
440 data.position[i][1] = tri_data[i].posY;
441 data.position[i][2] = tri_data[i].posZ;
442 data.position[i][3] = tri_data[i].posW;
443 data.color[i][0] = tri_data[i].r;
444 data.color[i][1] = tri_data[i].g;
445 data.color[i][2] = tri_data[i].b;
446 data.color[i][3] = tri_data[i].a;
447 }
448
Tony Barbourf43b6982014-11-25 13:18:32 -0700449 ASSERT_NO_FATAL_FAILURE(InitState());
450 ASSERT_NO_FATAL_FAILURE(InitViewport());
451
Tony Barbour01999182015-04-09 12:58:51 -0600452 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barbourf43b6982014-11-25 13:18:32 -0700453
Tony Barbour01999182015-04-09 12:58:51 -0600454 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
455 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700456
Tony Barbour01999182015-04-09 12:58:51 -0600457 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -0700458 pipelineobj.AddShader(&vs);
459 pipelineobj.AddShader(&ps);
460
Tony Barbour01999182015-04-09 12:58:51 -0600461 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600462 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700463
Tony Barbour71ba3612015-01-09 16:12:35 -0700464 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600465 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour71ba3612015-01-09 16:12:35 -0700466 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700467
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600468 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour71ba3612015-01-09 16:12:35 -0700469
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600470 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour71ba3612015-01-09 16:12:35 -0700471#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600472 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour71ba3612015-01-09 16:12:35 -0700473 pDSDumpDot((char*)"triTest2.dot");
474#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600475
Tony Barbour71ba3612015-01-09 16:12:35 -0700476 // render triangle
477 cmdBuffer.Draw(0, 3, 0, 1);
478
479 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600480 EndCommandBuffer(cmdBuffer);
481
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600482 cmdBuffer.QueueCommandBuffer();
Tony Barbour71ba3612015-01-09 16:12:35 -0700483
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600484 RecordImages(m_renderTargets);
Tony Barbour71ba3612015-01-09 16:12:35 -0700485
486 if (rotate)
Tobin Ehlis12ee35f2015-03-26 08:23:25 -0600487 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
Tony Barbour71ba3612015-01-09 16:12:35 -0700488
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700489#ifdef PRINT_OBJECTS
Mark Lobodzinski4e5016f2015-05-05 15:01:37 -0500490 //uint64_t objTrackGetObjectCount(VkObjectType type)
491 OBJ_TRACK_GET_OBJECTS_COUNT pObjTrackGetObjectsCount = (OBJ_TRACK_GET_OBJECTS_COUNT)vkGetProcAddr(gpu(), (char*)"objTrackGetObjectsCount");
492 uint64_t numObjects = pObjTrackGetObjectsCount();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600493 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700494 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600495 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700496 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
Mark Lobodzinski4e5016f2015-05-05 15:01:37 -0500497 pObjTrackGetObjs(numObjects, pObjNodeArray);
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700498 for (i=0; i < numObjects; i++) {
Mark Lobodzinski4e5016f2015-05-05 15:01:37 -0500499 printf("Object %i of type %s has objID (%p) and %lu uses\n", i, string_from_vulkan_object_type(pObjNodeArray[i].objType), pObjNodeArray[i].vkObj, pObjNodeArray[i].numUses);
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700500 }
501 free(pObjNodeArray);
502#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700503
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600504}
505
Tony Barbour01999182015-04-09 12:58:51 -0600506TEST_F(VkRenderTest, VKTriangle_FragColor)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600507{
508 static const char *vertShaderText =
509 "#version 140\n"
510 "#extension GL_ARB_separate_shader_objects : enable\n"
511 "#extension GL_ARB_shading_language_420pack : enable\n"
512 "\n"
513 "layout(binding = 0) uniform buf {\n"
514 " mat4 MVP;\n"
515 " vec4 position[3];\n"
516 " vec4 color[3];\n"
517 "} ubuf;\n"
518 "\n"
519 "layout (location = 0) out vec4 outColor;\n"
520 "\n"
521 "void main() \n"
522 "{\n"
523 " outColor = ubuf.color[gl_VertexID];\n"
524 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
525 "}\n";
526
527 static const char *fragShaderText =
528 "#version 140\n"
529 "#extension GL_ARB_separate_shader_objects : enable\n"
530 "#extension GL_ARB_shading_language_420pack : enable\n"
531 "\n"
532 "layout (location = 0) in vec4 inColor;\n"
533 "\n"
534 "void main()\n"
535 "{\n"
536 " gl_FragColor = inColor;\n"
537 "}\n";
538
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600539 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
540 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600541}
542
Tony Barbour01999182015-04-09 12:58:51 -0600543TEST_F(VkRenderTest, VKTriangle_OutputLocation)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600544{
545 static const char *vertShaderText =
546 "#version 140\n"
547 "#extension GL_ARB_separate_shader_objects : enable\n"
548 "#extension GL_ARB_shading_language_420pack : enable\n"
549 "\n"
550 "layout(binding = 0) uniform buf {\n"
551 " mat4 MVP;\n"
552 " vec4 position[3];\n"
553 " vec4 color[3];\n"
554 "} ubuf;\n"
555 "\n"
556 "layout (location = 0) out vec4 outColor;\n"
557 "\n"
558 "void main() \n"
559 "{\n"
560 " outColor = ubuf.color[gl_VertexID];\n"
561 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
562 "}\n";
563
564 static const char *fragShaderText =
565 "#version 140\n"
566 "#extension GL_ARB_separate_shader_objects : enable\n"
567 "#extension GL_ARB_shading_language_420pack : enable\n"
568 "\n"
569 "layout (location = 0) in vec4 inColor;\n"
570 "layout (location = 0) out vec4 outColor;\n"
571 "\n"
572 "void main()\n"
573 "{\n"
574 " outColor = inColor;\n"
575 "}\n";
576
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600577 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to output location 0, which should be the same as gl_FragColor");
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600578
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600579 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600580}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600581#ifndef _WIN32 // Implicit (for now at least) in WIN32 is that we are using the Nvidia driver and it won't consume SPIRV yet
Tony Barbour01999182015-04-09 12:58:51 -0600582TEST_F(VkRenderTest, SPV_VKTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700583{
Tony Barbour01999182015-04-09 12:58:51 -0600584 bool saved_use_spv = VkTestFramework::m_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700585
586 static const char *vertShaderText =
587 "#version 140\n"
588 "#extension GL_ARB_separate_shader_objects : enable\n"
589 "#extension GL_ARB_shading_language_420pack : enable\n"
590 "\n"
591 "layout(binding = 0) uniform buf {\n"
592 " mat4 MVP;\n"
593 " vec4 position[3];\n"
594 " vec4 color[3];\n"
595 "} ubuf;\n"
596 "\n"
597 "layout (location = 0) out vec4 outColor;\n"
598 "\n"
599 "void main() \n"
600 "{\n"
601 " outColor = ubuf.color[gl_VertexID];\n"
602 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
603 "}\n";
604
605 static const char *fragShaderText =
606 "#version 140\n"
607 "#extension GL_ARB_separate_shader_objects : enable\n"
608 "#extension GL_ARB_shading_language_420pack : enable\n"
609 "\n"
610 "layout (location = 0) in vec4 inColor;\n"
611 "\n"
612 "void main()\n"
613 "{\n"
614 " gl_FragColor = inColor;\n"
615 "}\n";
616
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600617 TEST_DESCRIPTION("VK-style shaders, but force test framework to compile shader to SPV and pass SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700618
Tony Barbour01999182015-04-09 12:58:51 -0600619 VkTestFramework::m_use_spv = true;
Tony Barbourf43b6982014-11-25 13:18:32 -0700620
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600621 VKTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700622
Tony Barbour01999182015-04-09 12:58:51 -0600623 VkTestFramework::m_use_spv = saved_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700624}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600625#endif
Tony Barbour01999182015-04-09 12:58:51 -0600626TEST_F(VkRenderTest, GreenTriangle)
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600627{
628 static const char *vertShaderText =
629 "#version 130\n"
630 "vec2 vertices[3];\n"
631 "void main() {\n"
632 " vertices[0] = vec2(-1.0, -1.0);\n"
633 " vertices[1] = vec2( 1.0, -1.0);\n"
634 " vertices[2] = vec2( 0.0, 1.0);\n"
635 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
636 "}\n";
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600637
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600638 static const char *fragShaderText =
639 "#version 130\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600640 "void main() {\n"
Steve K10b32512014-10-10 08:54:29 -0600641 " gl_FragColor = vec4(0,1,0,1);\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600642 "}\n";
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600643
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600644 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
645
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600646 VKTriangleTest(vertShaderText, fragShaderText, false);
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600647}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600648#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 -0600649TEST_F(VkRenderTest, SPV_GreenTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700650{
Tony Barbour01999182015-04-09 12:58:51 -0600651 bool saved_use_spv = VkTestFramework::m_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700652
653 static const char *vertShaderText =
654 "#version 130\n"
655 "vec2 vertices[3];\n"
656 "void main() {\n"
657 " vertices[0] = vec2(-1.0, -1.0);\n"
658 " vertices[1] = vec2( 1.0, -1.0);\n"
659 " vertices[2] = vec2( 0.0, 1.0);\n"
660 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
661 "}\n";
662
663 static const char *fragShaderText =
664 "#version 130\n"
665 "void main() {\n"
666 " gl_FragColor = vec4(0,1,0,1);\n"
667 "}\n";
668
Cody Northropacfb0492015-03-17 15:55:58 -0600669 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700670
Tony Barbour01999182015-04-09 12:58:51 -0600671 VkTestFramework::m_use_spv = true;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600672 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbour01999182015-04-09 12:58:51 -0600673 VkTestFramework::m_use_spv = saved_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700674}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600675#endif
Tony Barbour01999182015-04-09 12:58:51 -0600676TEST_F(VkRenderTest, YellowTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700677{
678 static const char *vertShaderText =
679 "#version 130\n"
680 "void main() {\n"
681 " vec2 vertices[3];"
682 " vertices[0] = vec2(-0.5, -0.5);\n"
683 " vertices[1] = vec2( 0.5, -0.5);\n"
684 " vertices[2] = vec2( 0.5, 0.5);\n"
685 " vec4 colors[3];\n"
686 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
687 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
688 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
689 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
690 "}\n";
691
692 static const char *fragShaderText =
693 "#version 130\n"
694 "void main() {\n"
695 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
696 "}\n";
697
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600698 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700699}
700
Tony Barbour01999182015-04-09 12:58:51 -0600701TEST_F(VkRenderTest, QuadWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600702{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600703 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600704 "#version 140\n"
705 "#extension GL_ARB_separate_shader_objects : enable\n"
706 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700707 //XYZ1( -1, -1, -1 )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600708 "layout (location = 0) in vec4 pos;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700709 //XYZ1( 0.f, 0.f, 0.f )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600710 "layout (location = 1) in vec4 inColor;\n"
711 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600712 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600713 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600714 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600715 "}\n";
716
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600717
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600718 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700719 "#version 140\n"
720 "#extension GL_ARB_separate_shader_objects : enable\n"
721 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600722 "layout (location = 0) in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700723 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600724 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700725 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600726 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600727
Tony Barbourf43b6982014-11-25 13:18:32 -0700728
729
730 ASSERT_NO_FATAL_FAILURE(InitState());
731 ASSERT_NO_FATAL_FAILURE(InitViewport());
732
Tony Barbour01999182015-04-09 12:58:51 -0600733 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000734 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700735
Tony Barbour01999182015-04-09 12:58:51 -0600736 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
737 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700738
Tony Barbour01999182015-04-09 12:58:51 -0600739 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -0700740 pipelineobj.AddShader(&vs);
741 pipelineobj.AddShader(&ps);
742
Tony Barbour01999182015-04-09 12:58:51 -0600743 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600744 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -0600745
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600746#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600747 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600748 MESH_BIND_ID, // binding ID
Tony Barbourf43b6982014-11-25 13:18:32 -0700749 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600750 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -0700751 };
752
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600753 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600754 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
755 vi_attribs[0].location = 0; // location, position
Tony Barbour8205d902015-04-16 15:59:00 -0600756 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600757 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
758 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
759 vi_attribs[1].location = 1; // location, color
Tony Barbour8205d902015-04-16 15:59:00 -0600760 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600761 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 -0700762
763 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
764 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600765 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -0700766
Tony Barboure4ed9942015-01-09 10:06:53 -0700767 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600768 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700769 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700770
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600771 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600772
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600773 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700774
Tony Barboure4ed9942015-01-09 10:06:53 -0700775 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
776
777 // render two triangles
778 cmdBuffer.Draw(0, 6, 0, 1);
779
780 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600781 EndCommandBuffer(cmdBuffer);
782
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600783 cmdBuffer.QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -0700784
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600785 RecordImages(m_renderTargets);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600786}
787
Tony Barbour01999182015-04-09 12:58:51 -0600788TEST_F(VkRenderTest, TriangleMRT)
Chia-I Wue09d1a72014-12-05 10:32:23 +0800789{
790 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600791 "#version 140\n"
792 "#extension GL_ARB_separate_shader_objects : enable\n"
793 "#extension GL_ARB_shading_language_420pack : enable\n"
794 "layout (location = 0) in vec4 pos;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800795 "void main() {\n"
796 " gl_Position = pos;\n"
797 "}\n";
798
799 static const char *fragShaderText =
800 "#version 130\n"
801 "void main() {\n"
802 " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
803 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
804 "}\n";
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600805 const float vb_data[][2] = {
Chia-I Wue09d1a72014-12-05 10:32:23 +0800806 { -1.0f, -1.0f },
807 { 1.0f, -1.0f },
808 { -1.0f, 1.0f }
809 };
810
811 ASSERT_NO_FATAL_FAILURE(InitState());
812 ASSERT_NO_FATAL_FAILURE(InitViewport());
813
Tony Barbour01999182015-04-09 12:58:51 -0600814 VkConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000815 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800816
Tony Barbour01999182015-04-09 12:58:51 -0600817 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
818 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800819
Tony Barbour01999182015-04-09 12:58:51 -0600820 VkPipelineObj pipelineobj(m_device);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800821 pipelineobj.AddShader(&vs);
822 pipelineobj.AddShader(&ps);
823
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600824#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600825 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600826 MESH_BUF_ID, // Binding ID
827 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600828 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Chia-I Wue09d1a72014-12-05 10:32:23 +0800829 };
830
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600831 VkVertexInputAttributeDescription vi_attrib;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600832 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
833 vi_attrib.location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -0600834 vi_attrib.format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600835 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
Chia-I Wue09d1a72014-12-05 10:32:23 +0800836
837 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
838 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600839 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800840
Tony Barbour01999182015-04-09 12:58:51 -0600841 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600842 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800843
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700844 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
Chia-I Wue09d1a72014-12-05 10:32:23 +0800845
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600846 VkPipelineCbAttachmentState att = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600847 att.blendEnable = VK_FALSE;
Chia-I Wue09d1a72014-12-05 10:32:23 +0800848 att.format = m_render_target_fmt;
849 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700850 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800851
Tony Barbour01999182015-04-09 12:58:51 -0600852 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700853
Tony Barbour5ed79702015-01-07 14:31:52 -0700854 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
855 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barboure4ed9942015-01-09 10:06:53 -0700856
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600857 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour5ed79702015-01-07 14:31:52 -0700858
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600859 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700860
Tony Barbour5ed79702015-01-07 14:31:52 -0700861 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700862#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600863 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour5ed79702015-01-07 14:31:52 -0700864 pDSDumpDot((char*)"triTest2.dot");
865#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600866
Tony Barbour5ed79702015-01-07 14:31:52 -0700867 // render triangle
868 cmdBuffer.Draw(0, 3, 0, 1);
869
870 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600871 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600872 cmdBuffer.QueueCommandBuffer();
Tony Barbour5ed79702015-01-07 14:31:52 -0700873
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600874 RecordImages(m_renderTargets);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800875}
876
Tony Barbour01999182015-04-09 12:58:51 -0600877TEST_F(VkRenderTest, QuadWithIndexedVertexFetch)
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700878{
879 static const char *vertShaderText =
880 "#version 140\n"
881 "#extension GL_ARB_separate_shader_objects : enable\n"
882 "#extension GL_ARB_shading_language_420pack : enable\n"
883 "layout(location = 0) in vec4 pos;\n"
884 "layout(location = 1) in vec4 inColor;\n"
885 "layout(location = 0) out vec4 outColor;\n"
886 "void main() {\n"
887 " outColor = inColor;\n"
888 " gl_Position = pos;\n"
889 "}\n";
890
891
892 static const char *fragShaderText =
893 "#version 140\n"
894 "#extension GL_ARB_separate_shader_objects : enable\n"
895 "#extension GL_ARB_shading_language_420pack : enable\n"
896 "layout(location = 0) in vec4 color;\n"
897 "void main() {\n"
898 " gl_FragColor = color;\n"
899 "}\n";
900
901 const Vertex g_vbData[] =
902 {
903 // first tri
904 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
905 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
906 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
907
908 // second tri
909 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
910 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
911 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
912 };
913
914 const uint16_t g_idxData[6] = {
915 0, 1, 2,
916 3, 4, 5,
917 };
918
919 ASSERT_NO_FATAL_FAILURE(InitState());
920 ASSERT_NO_FATAL_FAILURE(InitViewport());
921
Tony Barbour01999182015-04-09 12:58:51 -0600922 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000923 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700924
Tony Barbour01999182015-04-09 12:58:51 -0600925 VkIndexBufferObj indexBuffer(m_device);
Tony Barbour8205d902015-04-16 15:59:00 -0600926 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), VK_INDEX_TYPE_UINT16, g_idxData);
Mark Lobodzinskid30f82a2015-02-16 14:24:23 -0600927 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700928
Tony Barbour01999182015-04-09 12:58:51 -0600929 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
930 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700931
Tony Barbour01999182015-04-09 12:58:51 -0600932 VkPipelineObj pipelineobj(m_device);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700933 pipelineobj.AddShader(&vs);
934 pipelineobj.AddShader(&ps);
935
Tony Barbour01999182015-04-09 12:58:51 -0600936 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600937 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
938 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, indexBuffer);
Tony Barbour83a83802015-04-02 15:43:15 -0600939
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700940
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600941#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600942 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600943 MESH_BIND_ID, // binding ID
944 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600945 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700946 };
947
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600948 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600949 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
950 vi_attribs[0].location = 0; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600951 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600952 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
953 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
954 vi_attribs[1].location = 1; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600955 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600956 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700957
958 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
959 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700960
961 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600962 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700963 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600964 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barboure4ed9942015-01-09 10:06:53 -0700965
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600966 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700967
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700968#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600969 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700970 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700971#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700972
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600973 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600974 cmdBuffer.BindIndexBuffer(&indexBuffer, 0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700975
976 // render two triangles
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700977 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700978
979 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600980 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600981 cmdBuffer.QueueCommandBuffer();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700982
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600983 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700984}
985
Tony Barbour01999182015-04-09 12:58:51 -0600986TEST_F(VkRenderTest, GreyandRedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -0700987{
988 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -0700989
GregF6bef1212014-12-02 15:41:44 -0700990 static const char *vertShaderText =
991 "#version 140\n"
992 "#extension GL_ARB_separate_shader_objects : enable\n"
993 "#extension GL_ARB_shading_language_420pack : enable\n"
994 "layout (location = 0) in vec4 pos;\n"
995 "layout (location = 0) out vec4 outColor;\n"
996 "layout (location = 1) out vec4 outColor2;\n"
997 "void main() {\n"
998 " gl_Position = pos;\n"
999 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1000 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1001 "}\n";
1002
1003 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001004 "#version 330\n"
1005 "#extension GL_ARB_separate_shader_objects : enable\n"
1006 "#extension GL_ARB_shading_language_420pack : enable\n"
1007 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1008 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1009 "layout (location = 0) in vec4 color;\n"
1010 "layout (location = 1) in vec4 color2;\n"
1011 "void main() {\n"
1012 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1013 " float dist_squared = dot(pos, pos);\n"
1014 " gl_FragColor = (dist_squared < 400.0)\n"
1015 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1016 " : color2;\n"
1017 "}\n";
1018
1019 ASSERT_NO_FATAL_FAILURE(InitState());
1020 ASSERT_NO_FATAL_FAILURE(InitViewport());
1021
Tony Barbour01999182015-04-09 12:58:51 -06001022 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001023 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001024
Tony Barbour01999182015-04-09 12:58:51 -06001025 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1026 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001027
Tony Barbour01999182015-04-09 12:58:51 -06001028 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001029 pipelineobj.AddShader(&vs);
1030 pipelineobj.AddShader(&ps);
1031
Tony Barbour01999182015-04-09 12:58:51 -06001032 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001033 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001034
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001035#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001036 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001037 MESH_BIND_ID, // binding ID
1038 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001039 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001040 };
1041
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001042 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001043 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1044 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001045 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001046 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001047
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001048 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001049 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001050 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001051
Tony Barbourdd4c9642015-01-09 12:55:14 -07001052 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001053 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001054 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1055
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001056 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001057
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001058 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001059
1060 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1061#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001062 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001063 pDSDumpDot((char*)"triTest2.dot");
1064#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001065
Tony Barbourdd4c9642015-01-09 12:55:14 -07001066 // render triangle
1067 cmdBuffer.Draw(0, 6, 0, 1);
1068
1069 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001070 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001071 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001072
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001073 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001074}
1075
Tony Barbour01999182015-04-09 12:58:51 -06001076TEST_F(VkRenderTest, RedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -07001077{
1078 // This tests that we correctly handle unread fragment inputs
1079
1080 static const char *vertShaderText =
1081 "#version 140\n"
1082 "#extension GL_ARB_separate_shader_objects : enable\n"
1083 "#extension GL_ARB_shading_language_420pack : enable\n"
1084 "layout (location = 0) in vec4 pos;\n"
1085 "layout (location = 0) out vec4 outColor;\n"
1086 "layout (location = 1) out vec4 outColor2;\n"
1087 "void main() {\n"
1088 " gl_Position = pos;\n"
1089 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1090 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1091 "}\n";
1092
1093 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001094 "#version 330\n"
1095 "#extension GL_ARB_separate_shader_objects : enable\n"
1096 "#extension GL_ARB_shading_language_420pack : enable\n"
1097 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1098 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1099 "layout (location = 0) in vec4 color;\n"
1100 "layout (location = 1) in vec4 color2;\n"
1101 "void main() {\n"
1102 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1103 " float dist_squared = dot(pos, pos);\n"
1104 " gl_FragColor = (dist_squared < 400.0)\n"
1105 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1106 " : color2;\n"
1107 "}\n";
1108
1109 ASSERT_NO_FATAL_FAILURE(InitState());
1110 ASSERT_NO_FATAL_FAILURE(InitViewport());
1111
Tony Barbour01999182015-04-09 12:58:51 -06001112 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001113 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001114
Tony Barbour01999182015-04-09 12:58:51 -06001115 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1116 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001117
Tony Barbour01999182015-04-09 12:58:51 -06001118 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001119 pipelineobj.AddShader(&vs);
1120 pipelineobj.AddShader(&ps);
1121
Tony Barbour01999182015-04-09 12:58:51 -06001122 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001123 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001124
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001125#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001126 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001127 MESH_BIND_ID, // binding ID
1128 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001129 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001130 };
1131
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001132 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001133 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1134 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001135 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001136 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001137
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001138 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001139 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001140 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001141
Tony Barbourdd4c9642015-01-09 12:55:14 -07001142 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001143 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001144 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1145
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001146 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001147
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001148 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001149
1150 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1151#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001152 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001153 pDSDumpDot((char*)"triTest2.dot");
1154#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001155 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001156 cmdBuffer.Draw(0, 6, 0, 1);
1157
1158 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001159 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001160 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001161
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001162 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001163}
1164
Tony Barbour01999182015-04-09 12:58:51 -06001165TEST_F(VkRenderTest, GreyCirclesonBlueFade)
GregF6bef1212014-12-02 15:41:44 -07001166{
1167 // This tests reading gl_ClipDistance from FS
1168
1169 static const char *vertShaderText =
1170 "#version 330\n"
1171 "#extension GL_ARB_separate_shader_objects : enable\n"
1172 "#extension GL_ARB_shading_language_420pack : enable\n"
1173 "out gl_PerVertex {\n"
1174 " vec4 gl_Position;\n"
1175 " float gl_ClipDistance[1];\n"
1176 "};\n"
1177 "layout (location = 0) in vec4 pos;\n"
1178 "layout (location = 0) out vec4 outColor;\n"
1179 "layout (location = 1) out vec4 outColor2;\n"
1180 "void main() {\n"
1181 " gl_Position = pos;\n"
1182 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1183 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1184 " float dists[3];\n"
1185 " dists[0] = 0.0;\n"
1186 " dists[1] = 1.0;\n"
1187 " dists[2] = 1.0;\n"
1188 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1189 "}\n";
1190
1191
1192 static const char *fragShaderText =
1193 //"#version 140\n"
1194 "#version 330\n"
1195 "#extension GL_ARB_separate_shader_objects : enable\n"
1196 "#extension GL_ARB_shading_language_420pack : enable\n"
1197 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1198 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1199 "layout (location = 0) in vec4 color;\n"
1200 "layout (location = 1) in vec4 color2;\n"
1201 "void main() {\n"
1202 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1203 " float dist_squared = dot(pos, pos);\n"
1204 " gl_FragColor = (dist_squared < 400.0)\n"
1205 " ? color * gl_ClipDistance[0]\n"
1206 " : color2;\n"
1207 "}\n";
1208
1209 ASSERT_NO_FATAL_FAILURE(InitState());
1210 ASSERT_NO_FATAL_FAILURE(InitViewport());
1211
Tony Barbour01999182015-04-09 12:58:51 -06001212 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001213 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001214
Tony Barbour01999182015-04-09 12:58:51 -06001215 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1216 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001217
Tony Barbour01999182015-04-09 12:58:51 -06001218 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001219 pipelineobj.AddShader(&vs);
1220 pipelineobj.AddShader(&ps);
1221
Tony Barbour01999182015-04-09 12:58:51 -06001222 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001223 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001224
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001225#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001226 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001227 MESH_BIND_ID, // binding ID
1228 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001229 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001230 };
1231
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001232 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001233 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1234 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001235 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001236 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001237
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001238 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001239 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001240 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001241
Tony Barbourdd4c9642015-01-09 12:55:14 -07001242 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001243 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001244 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF6bef1212014-12-02 15:41:44 -07001245
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001246 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001247
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001248 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001249
1250 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1251#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001252 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001253 pDSDumpDot((char*)"triTest2.dot");
1254#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001255
1256 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001257 cmdBuffer.Draw(0, 6, 0, 1);
1258
1259 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001260 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001261 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001262
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001263 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001264}
Tony Barbourf43b6982014-11-25 13:18:32 -07001265
Tony Barbour01999182015-04-09 12:58:51 -06001266TEST_F(VkRenderTest, GreyCirclesonBlueDiscard)
GregF7a23c792014-12-02 17:19:34 -07001267{
1268 static const char *vertShaderText =
1269 "#version 140\n"
1270 "#extension GL_ARB_separate_shader_objects : enable\n"
1271 "#extension GL_ARB_shading_language_420pack : enable\n"
1272 "layout (location = 0) in vec4 pos;\n"
1273 "layout (location = 0) out vec4 outColor;\n"
1274 "layout (location = 1) out vec4 outColor2;\n"
1275 "void main() {\n"
1276 " gl_Position = pos;\n"
1277 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1278 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1279 "}\n";
1280
1281
1282 static const char *fragShaderText =
GregF7a23c792014-12-02 17:19:34 -07001283 "#version 330\n"
1284 "#extension GL_ARB_separate_shader_objects : enable\n"
1285 "#extension GL_ARB_shading_language_420pack : enable\n"
1286 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1287 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1288 "layout (location = 0) in vec4 color;\n"
1289 "layout (location = 1) in vec4 color2;\n"
1290 "void main() {\n"
1291 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1292 " float dist_squared = dot(pos, pos);\n"
1293 " if (dist_squared < 100.0)\n"
1294 " discard;\n"
1295 " gl_FragColor = (dist_squared < 400.0)\n"
1296 " ? color\n"
1297 " : color2;\n"
1298 "}\n";
1299
1300 ASSERT_NO_FATAL_FAILURE(InitState());
1301 ASSERT_NO_FATAL_FAILURE(InitViewport());
1302
Tony Barbour01999182015-04-09 12:58:51 -06001303 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001304 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001305
Tony Barbour01999182015-04-09 12:58:51 -06001306 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1307 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF7a23c792014-12-02 17:19:34 -07001308
Tony Barbour01999182015-04-09 12:58:51 -06001309 VkPipelineObj pipelineobj(m_device);
GregF7a23c792014-12-02 17:19:34 -07001310 pipelineobj.AddShader(&vs);
1311 pipelineobj.AddShader(&ps);
1312
Tony Barbour01999182015-04-09 12:58:51 -06001313 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001314 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001315
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001316#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001317 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001318 MESH_BIND_ID, // binding ID
1319 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001320 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF7a23c792014-12-02 17:19:34 -07001321 };
1322
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001323 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001324 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1325 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001326 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001327 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF7a23c792014-12-02 17:19:34 -07001328
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001329 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF7a23c792014-12-02 17:19:34 -07001330 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001331 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF7a23c792014-12-02 17:19:34 -07001332
Tony Barbourdd4c9642015-01-09 12:55:14 -07001333 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001334 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001335 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1336
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001337 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001338
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001339 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001340
1341 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1342#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001343 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001344 pDSDumpDot((char*)"triTest2.dot");
1345#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001346
1347 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001348 cmdBuffer.Draw(0, 6, 0, 1);
1349
1350 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001351 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001352 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001353
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001354 RecordImages(m_renderTargets);
GregF7a23c792014-12-02 17:19:34 -07001355}
1356
1357
Tony Barbour01999182015-04-09 12:58:51 -06001358TEST_F(VkRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001359{
1360 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001361 "#version 140\n"
1362 "#extension GL_ARB_separate_shader_objects : enable\n"
1363 "#extension GL_ARB_shading_language_420pack : enable\n"
1364 "\n"
1365 "layout(binding = 0) uniform buf {\n"
1366 " mat4 MVP;\n"
1367 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001368 "void main() {\n"
1369 " vec2 vertices[3];"
1370 " vertices[0] = vec2(-0.5, -0.5);\n"
1371 " vertices[1] = vec2( 0.5, -0.5);\n"
1372 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001373 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001374 "}\n";
1375
1376 static const char *fragShaderText =
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001377 "#version 130\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001378 "void main() {\n"
Cody Northrop78eac042014-10-10 15:45:00 -06001379 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001380 "}\n";
1381
Tony Barbourf43b6982014-11-25 13:18:32 -07001382 ASSERT_NO_FATAL_FAILURE(InitState());
1383 ASSERT_NO_FATAL_FAILURE(InitViewport());
1384
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001385 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001386 glm::mat4 Projection = glm::mat4(1.0f);
1387 glm::mat4 View = glm::mat4(1.0f);
1388 glm::mat4 Model = glm::mat4(1.0f);
1389 glm::mat4 MVP = Projection * View * Model;
1390 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1391
Tony Barbour01999182015-04-09 12:58:51 -06001392 VkConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1393 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1394 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001395
Tony Barbour01999182015-04-09 12:58:51 -06001396 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001397 pipelineobj.AddShader(&vs);
1398 pipelineobj.AddShader(&ps);
1399
1400 // Create descriptor set and attach the constant buffer to it
Tony Barbour01999182015-04-09 12:58:51 -06001401 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001402 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001403
Tony Barbourdd4c9642015-01-09 12:55:14 -07001404 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001405 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001406 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001407
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001408 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001409
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001410 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001411
1412 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1413#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001414 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001415 pDSDumpDot((char*)"triTest2.dot");
1416#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001417
1418 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001419 cmdBuffer.Draw(0, 6, 0, 1);
1420
1421 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001422 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001423 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001424
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001425 RecordImages(m_renderTargets);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001426
1427 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001428}
1429
Tony Barbour01999182015-04-09 12:58:51 -06001430TEST_F(VkRenderTest, MixTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07001431{
1432 // This tests location applied to varyings. Notice that we have switched foo
1433 // and bar in the FS. The triangle should be blended with red, green and blue
1434 // corners.
1435 static const char *vertShaderText =
1436 "#version 140\n"
1437 "#extension GL_ARB_separate_shader_objects : enable\n"
1438 "#extension GL_ARB_shading_language_420pack : enable\n"
1439 "layout (location=0) out vec4 bar;\n"
1440 "layout (location=1) out vec4 foo;\n"
1441 "layout (location=2) out float scale;\n"
1442 "vec2 vertices[3];\n"
1443 "void main() {\n"
1444 " vertices[0] = vec2(-1.0, -1.0);\n"
1445 " vertices[1] = vec2( 1.0, -1.0);\n"
1446 " vertices[2] = vec2( 0.0, 1.0);\n"
1447 "vec4 colors[3];\n"
1448 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1449 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1450 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1451 " foo = colors[gl_VertexID % 3];\n"
1452 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1453 " scale = 1.0;\n"
1454 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1455 "}\n";
1456
1457 static const char *fragShaderText =
1458 "#version 140\n"
1459 "#extension GL_ARB_separate_shader_objects : enable\n"
1460 "#extension GL_ARB_shading_language_420pack : enable\n"
1461 "layout (location = 1) in vec4 bar;\n"
1462 "layout (location = 0) in vec4 foo;\n"
1463 "layout (location = 2) in float scale;\n"
1464 "void main() {\n"
1465 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
1466 "}\n";
1467
1468 ASSERT_NO_FATAL_FAILURE(InitState());
1469 ASSERT_NO_FATAL_FAILURE(InitViewport());
1470
Tony Barbour01999182015-04-09 12:58:51 -06001471 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1472 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001473
Tony Barbour01999182015-04-09 12:58:51 -06001474 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001475 pipelineobj.AddShader(&vs);
1476 pipelineobj.AddShader(&ps);
1477
Tony Barbour01999182015-04-09 12:58:51 -06001478 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06001479 descriptorSet.AppendDummy();
Tony Barbourf43b6982014-11-25 13:18:32 -07001480
Tony Barbourdd4c9642015-01-09 12:55:14 -07001481 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001482 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001483 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1484
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001485 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001486
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001487 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001488
1489#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001490 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001491 pDSDumpDot((char*)"triTest2.dot");
1492#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001493
Tony Barbourdd4c9642015-01-09 12:55:14 -07001494 // render triangle
1495 cmdBuffer.Draw(0, 3, 0, 1);
1496
1497 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001498 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001499 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001500
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001501 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001502}
1503
Tony Barbour01999182015-04-09 12:58:51 -06001504TEST_F(VkRenderTest, QuadVertFetchAndVertID)
Tony Barbourf43b6982014-11-25 13:18:32 -07001505{
1506 // This tests that attributes work in the presence of gl_VertexID
1507
1508 static const char *vertShaderText =
1509 "#version 140\n"
1510 "#extension GL_ARB_separate_shader_objects : enable\n"
1511 "#extension GL_ARB_shading_language_420pack : enable\n"
1512 //XYZ1( -1, -1, -1 )
1513 "layout (location = 0) in vec4 pos;\n"
1514 //XYZ1( 0.f, 0.f, 0.f )
1515 "layout (location = 1) in vec4 inColor;\n"
1516 "layout (location = 0) out vec4 outColor;\n"
1517 "void main() {\n"
1518 " outColor = inColor;\n"
1519 " vec4 vertices[3];"
1520 " vertices[gl_VertexID % 3] = pos;\n"
1521 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1522 "}\n";
1523
1524
1525 static const char *fragShaderText =
1526 "#version 140\n"
1527 "#extension GL_ARB_separate_shader_objects : enable\n"
1528 "#extension GL_ARB_shading_language_420pack : enable\n"
1529 "layout (location = 0) in vec4 color;\n"
1530 "void main() {\n"
1531 " gl_FragColor = color;\n"
1532 "}\n";
1533
1534 ASSERT_NO_FATAL_FAILURE(InitState());
1535 ASSERT_NO_FATAL_FAILURE(InitViewport());
1536
Tony Barbour01999182015-04-09 12:58:51 -06001537 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001538 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001539
Tony Barbour01999182015-04-09 12:58:51 -06001540 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1541 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001542
Tony Barbour01999182015-04-09 12:58:51 -06001543 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001544 pipelineobj.AddShader(&vs);
1545 pipelineobj.AddShader(&ps);
1546
Tony Barbour01999182015-04-09 12:58:51 -06001547 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001548 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001549
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001550#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001551 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001552 MESH_BUF_ID, // Binding ID
1553 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001554 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001555 };
1556
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001557 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001558 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1559 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001560 vi_attribs[0].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001561 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1562 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1563 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001564 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001565 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001566
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001567 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001568 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001569 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001570
Tony Barbourdd4c9642015-01-09 12:55:14 -07001571 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001572 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001573 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1574
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001575 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001576
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001577 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001578
1579 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1580#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001581 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001582 pDSDumpDot((char*)"triTest2.dot");
1583#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001584
1585 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001586 cmdBuffer.Draw(0, 6, 0, 1);
1587
1588 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001589 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001590 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001591
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001592 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001593}
1594
Tony Barbour01999182015-04-09 12:58:51 -06001595TEST_F(VkRenderTest, QuadSparseVertFetch)
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001596{
1597 // This tests that attributes work in the presence of gl_VertexID
1598
1599 static const char *vertShaderText =
1600 "#version 140\n"
1601 "#extension GL_ARB_separate_shader_objects : enable\n"
1602 "#extension GL_ARB_shading_language_420pack : enable\n"
1603 //XYZ1( -1, -1, -1 )
1604 "layout (location = 1) in vec4 pos;\n"
1605 "layout (location = 4) in vec4 inColor;\n"
1606 //XYZ1( 0.f, 0.f, 0.f )
1607 "layout (location = 0) out vec4 outColor;\n"
1608 "void main() {\n"
1609 " outColor = inColor;\n"
1610 " gl_Position = pos;\n"
1611 "}\n";
1612
1613
1614 static const char *fragShaderText =
1615 "#version 140\n"
1616 "#extension GL_ARB_separate_shader_objects : enable\n"
1617 "#extension GL_ARB_shading_language_420pack : enable\n"
1618 "layout (location = 0) in vec4 color;\n"
1619 "void main() {\n"
1620 " gl_FragColor = color;\n"
1621 "}\n";
1622
1623 ASSERT_NO_FATAL_FAILURE(InitState());
1624 ASSERT_NO_FATAL_FAILURE(InitViewport());
1625
1626 struct VDATA
1627 {
1628 float t1, t2, t3, t4; // filler data
1629 float posX, posY, posZ, posW; // Position data
1630 float r, g, b, a; // Color
1631 };
1632 const struct VDATA vData[] =
1633 {
1634 { XYZ1(0, 0, 0), XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
1635 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1636 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.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( 1.f, 0.f, 0.f ) },
1639 { XYZ1(0, 0, 0), XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
1640 };
1641
Tony Barbour01999182015-04-09 12:58:51 -06001642 VkConstantBufferObj meshBuffer(m_device,sizeof(vData)/sizeof(vData[0]),sizeof(vData[0]), vData);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001643 meshBuffer.BufferMemoryBarrier();
1644
Tony Barbour01999182015-04-09 12:58:51 -06001645 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1646 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001647
Tony Barbour01999182015-04-09 12:58:51 -06001648 VkPipelineObj pipelineobj(m_device);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001649 pipelineobj.AddShader(&vs);
1650 pipelineobj.AddShader(&ps);
1651
Tony Barbour01999182015-04-09 12:58:51 -06001652 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001653 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001654
1655#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001656 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001657 MESH_BUF_ID, // Binding ID
1658 sizeof(vData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001659 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001660 };
1661
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001662 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001663 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1664 vi_attribs[0].location = 4;
Tony Barbour8205d902015-04-16 15:59:00 -06001665 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001666 vi_attribs[0].offsetInBytes = sizeof(float) * 4 * 2; // Offset of first element in bytes from base of vertex
1667 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1668 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001669 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001670 vi_attribs[1].offsetInBytes = sizeof(float) * 4 * 1; // Offset of first element in bytes from base of vertex
1671
1672 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
1673 pipelineobj.AddVertexInputBindings(&vi_binding, 1);
1674 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
1675
1676 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001677 VkCommandBufferObj cmdBuffer(m_device);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001678 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1679
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001680 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001681
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001682 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001683
1684 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BUF_ID);
1685#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001686 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001687 pDSDumpDot((char*)"triTest2.dot");
1688#endif
1689
1690 // render two triangles
1691 cmdBuffer.Draw(0, 6, 0, 1);
1692
1693 // finalize recording of the command buffer
1694 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001695 cmdBuffer.QueueCommandBuffer();
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001696
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001697 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001698}
1699
Tony Barbour01999182015-04-09 12:58:51 -06001700TEST_F(VkRenderTest, TriVertFetchDeadAttr)
Tony Barbourf43b6982014-11-25 13:18:32 -07001701{
1702 // This tests that attributes work in the presence of gl_VertexID
1703 // and a dead attribute in position 0. Draws a triangle with yellow,
1704 // red and green corners, starting at top and going clockwise.
1705
1706 static const char *vertShaderText =
1707 "#version 140\n"
1708 "#extension GL_ARB_separate_shader_objects : enable\n"
1709 "#extension GL_ARB_shading_language_420pack : enable\n"
1710 //XYZ1( -1, -1, -1 )
1711 "layout (location = 0) in vec4 pos;\n"
1712 //XYZ1( 0.f, 0.f, 0.f )
1713 "layout (location = 1) in vec4 inColor;\n"
1714 "layout (location = 0) out vec4 outColor;\n"
1715 "void main() {\n"
1716 " outColor = inColor;\n"
1717 " vec2 vertices[3];"
1718 " vertices[0] = vec2(-1.0, -1.0);\n"
1719 " vertices[1] = vec2( 1.0, -1.0);\n"
1720 " vertices[2] = vec2( 0.0, 1.0);\n"
1721 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1722 "}\n";
1723
1724
1725 static const char *fragShaderText =
1726 "#version 140\n"
1727 "#extension GL_ARB_separate_shader_objects : enable\n"
1728 "#extension GL_ARB_shading_language_420pack : enable\n"
1729 "layout (location = 0) in vec4 color;\n"
1730 "void main() {\n"
1731 " gl_FragColor = color;\n"
1732 "}\n";
1733
1734 ASSERT_NO_FATAL_FAILURE(InitState());
1735 ASSERT_NO_FATAL_FAILURE(InitViewport());
1736
Tony Barbour01999182015-04-09 12:58:51 -06001737 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001738 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001739
Tony Barbour01999182015-04-09 12:58:51 -06001740 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1741 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001742
Tony Barbour01999182015-04-09 12:58:51 -06001743 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001744 pipelineobj.AddShader(&vs);
1745 pipelineobj.AddShader(&ps);
1746
Tony Barbour01999182015-04-09 12:58:51 -06001747 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001748 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001749
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001750#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001751 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001752 MESH_BUF_ID, // Binding ID
1753 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001754 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001755 };
1756
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001757 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001758 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1759 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001760 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001761 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1762 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1763 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001764 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001765 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001766
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001767 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001768 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001769 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001770
Tony Barbourdd4c9642015-01-09 12:55:14 -07001771 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001772 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001773 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001774
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001775 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001776
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001777 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001778
1779 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1780#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001781 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001782 pDSDumpDot((char*)"triTest2.dot");
1783#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001784
1785 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001786 cmdBuffer.Draw(0, 6, 0, 1);
1787
1788 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001789 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001790 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001791
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001792 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001793}
1794
Tony Barbour01999182015-04-09 12:58:51 -06001795TEST_F(VkRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001796{
1797 static const char *vertShaderText =
1798 "#version 140\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001799 "#extension GL_ARB_separate_shader_objects : enable\n"
1800 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001801 "layout (std140) uniform bufferVals {\n"
1802 " mat4 mvp;\n"
1803 "} myBufferVals;\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001804 "layout (location = 0) in vec4 pos;\n"
1805 "layout (location = 1) in vec4 inColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001806 "out vec4 outColor;\n"
1807 "void main() {\n"
1808 " outColor = inColor;\n"
1809 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001810 " gl_Position.y = -gl_Position.y;\n"
1811 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001812 "}\n";
1813
1814 static const char *fragShaderText =
1815 "#version 130\n"
1816 "in vec4 color;\n"
1817 "void main() {\n"
1818 " gl_FragColor = color;\n"
1819 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001820 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001821
Tony Barbourf43b6982014-11-25 13:18:32 -07001822 glm::mat4 View = glm::lookAt(
1823 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1824 glm::vec3(0,0,0), // and looks at the origin
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001825 glm::vec3(0,-1,0) // Head is up (set to 0,-1,0 to look upside-down)
Tony Barbourf43b6982014-11-25 13:18:32 -07001826 );
1827
1828 glm::mat4 Model = glm::mat4(1.0f);
1829
1830 glm::mat4 MVP = Projection * View * Model;
1831
1832 ASSERT_NO_FATAL_FAILURE(InitState());
1833 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour17c6ab12015-03-27 17:03:18 -06001834 m_depthStencil->Init(m_device, m_width, m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07001835
Tony Barbour01999182015-04-09 12:58:51 -06001836 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 -07001837 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1838
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001839 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07001840
Tony Barbour01999182015-04-09 12:58:51 -06001841 VkConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1842 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1843 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001844
Tony Barbour01999182015-04-09 12:58:51 -06001845 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001846 pipelineobj.AddShader(&vs);
1847 pipelineobj.AddShader(&ps);
1848
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001849 VkPipelineDsStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001850 ds_state.depthTestEnable = VK_TRUE;
1851 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06001852 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001853 ds_state.depthBoundsEnable = VK_FALSE;
1854 ds_state.stencilTestEnable = VK_FALSE;
1855 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
1856 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
1857 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06001858 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
1859 ds_state.format = VK_FORMAT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001860 ds_state.front = ds_state.back;
1861 pipelineobj.SetDepthStencil(&ds_state);
1862
Tony Barbour01999182015-04-09 12:58:51 -06001863 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001864 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001865
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001866#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001867 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001868 MESH_BUF_ID, // Binding ID
1869 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001870 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001871 };
Tony Barbourf43b6982014-11-25 13:18:32 -07001872
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001873 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001874 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1875 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001876 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001877 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1878 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1879 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001880 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001881 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001882
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001883 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001884 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001885 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001886
Tony Barbour17c6ab12015-03-27 17:03:18 -06001887 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour17c6ab12015-03-27 17:03:18 -06001888
Tony Barbour01999182015-04-09 12:58:51 -06001889 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -07001890 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001891
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001892 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001893 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001894
Tony Barboure4ed9942015-01-09 10:06:53 -07001895 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1896#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001897 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barboure4ed9942015-01-09 10:06:53 -07001898 pDSDumpDot((char*)"triTest2.dot");
1899#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001900
1901 // render triangles
Tony Barboure4ed9942015-01-09 10:06:53 -07001902 cmdBuffer.Draw(0, 36, 0, 1);
1903
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001904
Tony Barboure4ed9942015-01-09 10:06:53 -07001905 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001906 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001907 cmdBuffer.QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -07001908
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001909 RecordImages(m_renderTargets);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001910}
1911
Tony Barbour01999182015-04-09 12:58:51 -06001912TEST_F(VkRenderTest, VSTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07001913{
1914 // The expected result from this test is a green and red triangle;
1915 // one red vertex on the left, two green vertices on the right.
1916 static const char *vertShaderText =
1917 "#version 130\n"
1918 "out vec4 texColor;\n"
1919 "uniform sampler2D surface;\n"
1920 "void main() {\n"
1921 " vec2 vertices[3];"
1922 " vertices[0] = vec2(-0.5, -0.5);\n"
1923 " vertices[1] = vec2( 0.5, -0.5);\n"
1924 " vertices[2] = vec2( 0.5, 0.5);\n"
1925 " vec2 positions[3];"
1926 " positions[0] = vec2( 0.0, 0.0);\n"
1927 " positions[1] = vec2( 0.25, 0.1);\n"
1928 " positions[2] = vec2( 0.1, 0.25);\n"
1929 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1930 " texColor = textureLod(surface, samplePos, 0.0);\n"
1931 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1932 "}\n";
1933
1934 static const char *fragShaderText =
1935 "#version 130\n"
1936 "in vec4 texColor;\n"
1937 "void main() {\n"
1938 " gl_FragColor = texColor;\n"
1939 "}\n";
1940
1941 ASSERT_NO_FATAL_FAILURE(InitState());
1942 ASSERT_NO_FATAL_FAILURE(InitViewport());
1943
Tony Barbour01999182015-04-09 12:58:51 -06001944 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1945 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
1946 VkSamplerObj sampler(m_device);
1947 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001948
Tony Barbour01999182015-04-09 12:58:51 -06001949 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001950 pipelineobj.AddShader(&vs);
1951 pipelineobj.AddShader(&ps);
1952
Tony Barbour01999182015-04-09 12:58:51 -06001953 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001954 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001955
Tony Barbourdd4c9642015-01-09 12:55:14 -07001956 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001957 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001958 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001959
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001960 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001961
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001962 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001963
1964#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001965 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001966 pDSDumpDot((char*)"triTest2.dot");
1967#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001968
Tony Barbourdd4c9642015-01-09 12:55:14 -07001969 // render triangle
1970 cmdBuffer.Draw(0, 3, 0, 1);
1971
1972 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001973 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001974 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001975
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001976 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001977}
Tony Barbour01999182015-04-09 12:58:51 -06001978TEST_F(VkRenderTest, TexturedTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07001979{
1980 // The expected result from this test is a red and green checkered triangle
1981 static const char *vertShaderText =
1982 "#version 140\n"
1983 "#extension GL_ARB_separate_shader_objects : enable\n"
1984 "#extension GL_ARB_shading_language_420pack : enable\n"
1985 "layout (location = 0) out vec2 samplePos;\n"
1986 "void main() {\n"
1987 " vec2 vertices[3];"
1988 " vertices[0] = vec2(-0.5, -0.5);\n"
1989 " vertices[1] = vec2( 0.5, -0.5);\n"
1990 " vertices[2] = vec2( 0.5, 0.5);\n"
1991 " vec2 positions[3];"
1992 " positions[0] = vec2( 0.0, 0.0);\n"
1993 " positions[1] = vec2( 1.0, 0.0);\n"
1994 " positions[2] = vec2( 1.0, 1.0);\n"
1995 " samplePos = positions[gl_VertexID % 3];\n"
1996 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1997 "}\n";
1998
1999 static const char *fragShaderText =
2000 "#version 140\n"
2001 "#extension GL_ARB_separate_shader_objects : enable\n"
2002 "#extension GL_ARB_shading_language_420pack : enable\n"
2003 "layout (location = 0) in vec2 samplePos;\n"
2004 "layout (binding = 0) uniform sampler2D surface;\n"
2005 "layout (location=0) out vec4 outColor;\n"
2006 "void main() {\n"
2007 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2008 " outColor = texColor;\n"
2009 "}\n";
2010
2011 ASSERT_NO_FATAL_FAILURE(InitState());
2012 ASSERT_NO_FATAL_FAILURE(InitViewport());
2013
Tony Barbour01999182015-04-09 12:58:51 -06002014 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2015 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2016 VkSamplerObj sampler(m_device);
2017 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002018
Tony Barbour01999182015-04-09 12:58:51 -06002019 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002020 pipelineobj.AddShader(&vs);
2021 pipelineobj.AddShader(&ps);
2022
Tony Barbour01999182015-04-09 12:58:51 -06002023 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002024 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002025
Tony Barbourdd4c9642015-01-09 12:55:14 -07002026 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002027 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002028 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2029
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002030 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002031
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002032 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002033
2034#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002035 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002036 pDSDumpDot((char*)"triTest2.dot");
2037#endif
2038 // render triangle
2039 cmdBuffer.Draw(0, 3, 0, 1);
2040
2041 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002042 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002043 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002044
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002045 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002046}
Tony Barbour01999182015-04-09 12:58:51 -06002047TEST_F(VkRenderTest, TexturedTriangleClip)
Tony Barbourf43b6982014-11-25 13:18:32 -07002048{
2049 // The expected result from this test is a red and green checkered triangle
2050 static const char *vertShaderText =
2051 "#version 330\n"
2052 "#extension GL_ARB_separate_shader_objects : enable\n"
2053 "#extension GL_ARB_shading_language_420pack : enable\n"
2054 "layout (location = 0) out vec2 samplePos;\n"
2055 "out gl_PerVertex {\n"
2056 " vec4 gl_Position;\n"
2057 " float gl_ClipDistance[1];\n"
2058 "};\n"
2059 "void main() {\n"
2060 " vec2 vertices[3];"
2061 " vertices[0] = vec2(-0.5, -0.5);\n"
2062 " vertices[1] = vec2( 0.5, -0.5);\n"
2063 " vertices[2] = vec2( 0.5, 0.5);\n"
2064 " vec2 positions[3];"
2065 " positions[0] = vec2( 0.0, 0.0);\n"
2066 " positions[1] = vec2( 1.0, 0.0);\n"
2067 " positions[2] = vec2( 1.0, 1.0);\n"
2068 " float dists[3];\n"
2069 " dists[0] = 1.0;\n"
2070 " dists[1] = 1.0;\n"
2071 " dists[2] = -1.0;\n"
2072 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2073 " samplePos = positions[gl_VertexID % 3];\n"
2074 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2075 "}\n";
2076
2077 static const char *fragShaderText =
2078 "#version 140\n"
2079 "#extension GL_ARB_separate_shader_objects : enable\n"
2080 "#extension GL_ARB_shading_language_420pack : enable\n"
2081 "layout (location = 0) in vec2 samplePos;\n"
2082 "layout (binding = 0) uniform sampler2D surface;\n"
2083 "layout (location=0) out vec4 outColor;\n"
2084 "void main() {\n"
2085 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2086 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2087 " outColor = texColor;\n"
2088 "}\n";
2089
2090
2091 ASSERT_NO_FATAL_FAILURE(InitState());
2092 ASSERT_NO_FATAL_FAILURE(InitViewport());
2093
Tony Barbour01999182015-04-09 12:58:51 -06002094 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2095 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2096 VkSamplerObj sampler(m_device);
2097 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002098
Tony Barbour01999182015-04-09 12:58:51 -06002099 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002100 pipelineobj.AddShader(&vs);
2101 pipelineobj.AddShader(&ps);
2102
Tony Barbour01999182015-04-09 12:58:51 -06002103 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002104 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002105
Tony Barbourdd4c9642015-01-09 12:55:14 -07002106 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002107 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002108 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2109
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002110 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002111
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002112 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002113
2114#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002115 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002116 pDSDumpDot((char*)"triTest2.dot");
2117#endif
2118 // render triangle
2119 cmdBuffer.Draw(0, 3, 0, 1);
2120
2121 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002122 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002123 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002124
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002125 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002126}
Tony Barbour01999182015-04-09 12:58:51 -06002127TEST_F(VkRenderTest, FSTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002128{
2129 // The expected result from this test is a red and green checkered triangle
2130 static const char *vertShaderText =
2131 "#version 140\n"
2132 "#extension GL_ARB_separate_shader_objects : enable\n"
2133 "#extension GL_ARB_shading_language_420pack : enable\n"
2134 "layout (location = 0) out vec2 samplePos;\n"
2135 "void main() {\n"
2136 " vec2 vertices[3];"
2137 " vertices[0] = vec2(-0.5, -0.5);\n"
2138 " vertices[1] = vec2( 0.5, -0.5);\n"
2139 " vertices[2] = vec2( 0.5, 0.5);\n"
2140 " vec2 positions[3];"
2141 " positions[0] = vec2( 0.0, 0.0);\n"
2142 " positions[1] = vec2( 1.0, 0.0);\n"
2143 " positions[2] = vec2( 1.0, 1.0);\n"
2144 " samplePos = positions[gl_VertexID % 3];\n"
2145 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2146 "}\n";
2147
2148 static const char *fragShaderText =
2149 "#version 140\n"
2150 "#extension GL_ARB_separate_shader_objects : enable\n"
2151 "#extension GL_ARB_shading_language_420pack : enable\n"
2152 "layout (location = 0) in vec2 samplePos;\n"
2153 "layout (binding = 0) uniform sampler2D surface;\n"
2154 "layout (location=0) out vec4 outColor;\n"
2155 "void main() {\n"
2156 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2157 " outColor = texColor;\n"
2158 "}\n";
2159
2160 ASSERT_NO_FATAL_FAILURE(InitState());
2161 ASSERT_NO_FATAL_FAILURE(InitViewport());
2162
Tony Barbour01999182015-04-09 12:58:51 -06002163 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2164 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2165 VkSamplerObj sampler(m_device);
2166 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002167
Tony Barbour01999182015-04-09 12:58:51 -06002168 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002169 pipelineobj.AddShader(&vs);
2170 pipelineobj.AddShader(&ps);
2171
Tony Barbour01999182015-04-09 12:58:51 -06002172 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002173 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002174
Tony Barbourdd4c9642015-01-09 12:55:14 -07002175 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002176 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002177 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2178
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002179 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002180
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002181 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002182
2183#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002184 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002185 pDSDumpDot((char*)"triTest2.dot");
2186#endif
2187 // render triangle
2188 cmdBuffer.Draw(0, 3, 0, 1);
2189
2190 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002191 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002192 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002193
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002194 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002195}
Tony Barbour01999182015-04-09 12:58:51 -06002196TEST_F(VkRenderTest, SamplerBindingsTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002197{
2198 // This test sets bindings on the samplers
2199 // For now we are asserting that sampler and texture pairs
2200 // march in lock step, and are set via GLSL binding. This can
2201 // and will probably change.
2202 // The sampler bindings should match the sampler and texture slot
2203 // number set up by the application.
2204 // This test will result in a blue triangle
2205 static const char *vertShaderText =
2206 "#version 140\n"
2207 "#extension GL_ARB_separate_shader_objects : enable\n"
2208 "#extension GL_ARB_shading_language_420pack : enable\n"
2209 "layout (location = 0) out vec4 samplePos;\n"
2210 "void main() {\n"
2211 " vec2 vertices[3];"
2212 " vertices[0] = vec2(-0.5, -0.5);\n"
2213 " vertices[1] = vec2( 0.5, -0.5);\n"
2214 " vertices[2] = vec2( 0.5, 0.5);\n"
2215 " vec2 positions[3];"
2216 " positions[0] = vec2( 0.0, 0.0);\n"
2217 " positions[1] = vec2( 1.0, 0.0);\n"
2218 " positions[2] = vec2( 1.0, 1.0);\n"
2219 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2220 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2221 "}\n";
2222
2223 static const char *fragShaderText =
2224 "#version 140\n"
2225 "#extension GL_ARB_separate_shader_objects : enable\n"
2226 "#extension GL_ARB_shading_language_420pack : enable\n"
2227 "layout (location = 0) in vec4 samplePos;\n"
2228 "layout (binding = 0) uniform sampler2D surface0;\n"
2229 "layout (binding = 1) uniform sampler2D surface1;\n"
2230 "layout (binding = 12) uniform sampler2D surface2;\n"
2231 "void main() {\n"
2232 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
2233 "}\n";
2234
2235 ASSERT_NO_FATAL_FAILURE(InitState());
2236 ASSERT_NO_FATAL_FAILURE(InitViewport());
2237
Tony Barbour01999182015-04-09 12:58:51 -06002238 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2239 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002240
Tony Barbour01999182015-04-09 12:58:51 -06002241 VkSamplerObj sampler1(m_device);
2242 VkSamplerObj sampler2(m_device);
2243 VkSamplerObj sampler3(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002244
Tony Barbour2f421a02015-04-01 16:38:10 -06002245 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
Tony Barbour01999182015-04-09 12:58:51 -06002246 VkTextureObj texture1(m_device, tex_colors); // Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002247 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
Tony Barbour01999182015-04-09 12:58:51 -06002248 VkTextureObj texture2(m_device, tex_colors); // Green
Tony Barbour2f421a02015-04-01 16:38:10 -06002249 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
Tony Barbour01999182015-04-09 12:58:51 -06002250 VkTextureObj texture3(m_device, tex_colors); // Blue
Tony Barbourf43b6982014-11-25 13:18:32 -07002251
Tony Barbour01999182015-04-09 12:58:51 -06002252 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002253 pipelineobj.AddShader(&vs);
2254 pipelineobj.AddShader(&ps);
2255
Tony Barbour01999182015-04-09 12:58:51 -06002256 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002257 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2258 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2259 for (int i = 0; i < 10; i++)
2260 descriptorSet.AppendDummy();
2261 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002262
Tony Barbourdd4c9642015-01-09 12:55:14 -07002263 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002264 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002265 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2266
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002267 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002268
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002269 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002270
2271#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002272 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002273 pDSDumpDot((char*)"triTest2.dot");
2274#endif
2275 // render triangle
2276 cmdBuffer.Draw(0, 3, 0, 1);
2277
2278 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002279 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002280 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002281
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002282 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002283}
2284
Tony Barbour01999182015-04-09 12:58:51 -06002285TEST_F(VkRenderTest, TriangleVSUniformBlock)
Tony Barbourf43b6982014-11-25 13:18:32 -07002286{
2287 // The expected result from this test is a blue triangle
2288
2289 static const char *vertShaderText =
2290 "#version 140\n"
2291 "#extension GL_ARB_separate_shader_objects : enable\n"
2292 "#extension GL_ARB_shading_language_420pack : enable\n"
2293 "layout (location = 0) out vec4 outColor;\n"
2294 "layout (std140, binding = 0) uniform bufferVals {\n"
2295 " vec4 red;\n"
2296 " vec4 green;\n"
2297 " vec4 blue;\n"
2298 " vec4 white;\n"
2299 "} myBufferVals;\n"
2300 "void main() {\n"
2301 " vec2 vertices[3];"
2302 " vertices[0] = vec2(-0.5, -0.5);\n"
2303 " vertices[1] = vec2( 0.5, -0.5);\n"
2304 " vertices[2] = vec2( 0.5, 0.5);\n"
2305 " outColor = myBufferVals.blue;\n"
2306 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2307 "}\n";
2308
2309 static const char *fragShaderText =
2310 "#version 140\n"
2311 "#extension GL_ARB_separate_shader_objects : enable\n"
2312 "#extension GL_ARB_shading_language_420pack : enable\n"
2313 "layout (location = 0) in vec4 inColor;\n"
2314 "void main() {\n"
2315 " gl_FragColor = inColor;\n"
2316 "}\n";
2317
2318 ASSERT_NO_FATAL_FAILURE(InitState());
2319 ASSERT_NO_FATAL_FAILURE(InitViewport());
2320
Tony Barbour01999182015-04-09 12:58:51 -06002321 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2322 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002323
2324 // Let's populate our buffer with the following:
2325 // vec4 red;
2326 // vec4 green;
2327 // vec4 blue;
2328 // vec4 white;
2329 const int valCount = 4 * 4;
2330 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2331 0.0, 1.0, 0.0, 1.0,
2332 0.0, 0.0, 1.0, 1.0,
2333 1.0, 1.0, 1.0, 1.0 };
2334
Tony Barbour01999182015-04-09 12:58:51 -06002335 VkConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002336
Tony Barbour01999182015-04-09 12:58:51 -06002337 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002338 pipelineobj.AddShader(&vs);
2339 pipelineobj.AddShader(&ps);
2340
Tony Barbour01999182015-04-09 12:58:51 -06002341 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002342 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002343
Tony Barbourdd4c9642015-01-09 12:55:14 -07002344 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002345 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002346 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2347
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002348 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002349
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002350 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002351
2352#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002353 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002354 pDSDumpDot((char*)"triTest2.dot");
2355#endif
2356 // render triangle
2357 cmdBuffer.Draw(0, 3, 0, 1);
2358
2359 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002360 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002361 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002362
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002363 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002364}
2365
Tony Barbour01999182015-04-09 12:58:51 -06002366TEST_F(VkRenderTest, TriangleFSUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002367{
2368 // This test allows the shader to select which buffer it is
2369 // pulling from using layout binding qualifier.
2370 // There are corresponding changes in the compiler stack that
2371 // will select the buffer using binding directly.
2372 // The binding number should match the slot number set up by
2373 // the application.
2374 // The expected result from this test is a purple triangle
2375
2376 static const char *vertShaderText =
2377 "#version 140\n"
2378 "#extension GL_ARB_separate_shader_objects : enable\n"
2379 "#extension GL_ARB_shading_language_420pack : enable\n"
2380 "void main() {\n"
2381 " vec2 vertices[3];"
2382 " vertices[0] = vec2(-0.5, -0.5);\n"
2383 " vertices[1] = vec2( 0.5, -0.5);\n"
2384 " vertices[2] = vec2( 0.5, 0.5);\n"
2385 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2386 "}\n";
2387
2388 static const char *fragShaderText =
2389 "#version 140\n"
2390 "#extension GL_ARB_separate_shader_objects : enable\n"
2391 "#extension GL_ARB_shading_language_420pack : enable\n"
2392 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2393 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2394 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002395 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
Tony Barbourf43b6982014-11-25 13:18:32 -07002396 "void main() {\n"
2397 " gl_FragColor = myBlueVal.color;\n"
2398 " gl_FragColor += myRedVal.color;\n"
2399 "}\n";
2400
2401 ASSERT_NO_FATAL_FAILURE(InitState());
2402 ASSERT_NO_FATAL_FAILURE(InitViewport());
2403
Tony Barbour01999182015-04-09 12:58:51 -06002404 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2405 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002406
2407 // We're going to create a number of uniform buffers, and then allow
2408 // the shader to select which it wants to read from with a binding
2409
2410 // Let's populate the buffers with a single color each:
2411 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2412 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2413 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002414 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002415
2416 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2417 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2418 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2419 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2420
2421 const int redCount = sizeof(redVals) / sizeof(float);
2422 const int greenCount = sizeof(greenVals) / sizeof(float);
2423 const int blueCount = sizeof(blueVals) / sizeof(float);
2424 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2425
Tony Barbour01999182015-04-09 12:58:51 -06002426 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002427
Tony Barbour01999182015-04-09 12:58:51 -06002428 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002429
Tony Barbour01999182015-04-09 12:58:51 -06002430 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002431
Tony Barbour01999182015-04-09 12:58:51 -06002432 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002433
Tony Barbour01999182015-04-09 12:58:51 -06002434 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002435 pipelineobj.AddShader(&vs);
2436 pipelineobj.AddShader(&ps);
2437
Tony Barbour01999182015-04-09 12:58:51 -06002438 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002439 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2440 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2441 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2442 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002443
Tony Barbourdd4c9642015-01-09 12:55:14 -07002444 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002445 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002446 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002447
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002448 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002449
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002450 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002451
2452#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002453 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002454 pDSDumpDot((char*)"triTest2.dot");
2455#endif
2456 // render triangle
2457 cmdBuffer.Draw(0, 3, 0, 1);
2458
2459 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002460 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002461 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002462
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002463 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002464}
2465
Tony Barbour01999182015-04-09 12:58:51 -06002466TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002467{
2468 // This test is the same as TriangleFSUniformBlockBinding, but
2469 // it does not provide an instance name.
2470 // The expected result from this test is a purple triangle
2471
2472 static const char *vertShaderText =
2473 "#version 140\n"
2474 "#extension GL_ARB_separate_shader_objects : enable\n"
2475 "#extension GL_ARB_shading_language_420pack : enable\n"
2476 "void main() {\n"
2477 " vec2 vertices[3];"
2478 " vertices[0] = vec2(-0.5, -0.5);\n"
2479 " vertices[1] = vec2( 0.5, -0.5);\n"
2480 " vertices[2] = vec2( 0.5, 0.5);\n"
2481 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2482 "}\n";
2483
2484 static const char *fragShaderText =
2485 "#version 430\n"
2486 "#extension GL_ARB_separate_shader_objects : enable\n"
2487 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002488 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2489 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2490 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002491 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002492 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002493 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002494 " outColor = blue;\n"
2495 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002496 "}\n";
2497 ASSERT_NO_FATAL_FAILURE(InitState());
2498 ASSERT_NO_FATAL_FAILURE(InitViewport());
2499
Tony Barbour01999182015-04-09 12:58:51 -06002500 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2501 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002502
2503 // We're going to create a number of uniform buffers, and then allow
2504 // the shader to select which it wants to read from with a binding
2505
2506 // Let's populate the buffers with a single color each:
2507 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2508 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2509 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2510 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2511
2512 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2513 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2514 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2515 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2516
2517 const int redCount = sizeof(redVals) / sizeof(float);
2518 const int greenCount = sizeof(greenVals) / sizeof(float);
2519 const int blueCount = sizeof(blueVals) / sizeof(float);
2520 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2521
Tony Barbour01999182015-04-09 12:58:51 -06002522 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002523
Tony Barbour01999182015-04-09 12:58:51 -06002524 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002525
Tony Barbour01999182015-04-09 12:58:51 -06002526 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002527
Tony Barbour01999182015-04-09 12:58:51 -06002528 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002529
Tony Barbour01999182015-04-09 12:58:51 -06002530 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002531 pipelineobj.AddShader(&vs);
2532 pipelineobj.AddShader(&ps);
2533
Tony Barbour01999182015-04-09 12:58:51 -06002534 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002535 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2536 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2537 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2538 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002539
Tony Barbourdd4c9642015-01-09 12:55:14 -07002540 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002541 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002542 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2543
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002544 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002545
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002546 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002547
2548#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002549 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002550 pDSDumpDot((char*)"triTest2.dot");
2551#endif
2552 // render triangle
2553 cmdBuffer.Draw(0, 3, 0, 1);
2554
2555 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002556 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002557 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002558
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002559 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002560}
2561
Tony Barbour01999182015-04-09 12:58:51 -06002562TEST_F(VkRenderTest, CubeWithVertexFetchAndMVPAndTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07002563{
2564 static const char *vertShaderText =
2565 "#version 140\n"
2566 "#extension GL_ARB_separate_shader_objects : enable\n"
2567 "#extension GL_ARB_shading_language_420pack : enable\n"
2568 "layout (std140, binding=0) uniform bufferVals {\n"
2569 " mat4 mvp;\n"
2570 "} myBufferVals;\n"
2571 "layout (location=0) in vec4 pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002572 "layout (location=1) in vec2 input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002573 "layout (location=0) out vec2 UV;\n"
2574 "void main() {\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002575 " UV = input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002576 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002577 " gl_Position.y = -gl_Position.y;\n"
2578 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002579 "}\n";
2580
2581 static const char *fragShaderText =
2582 "#version 140\n"
2583 "#extension GL_ARB_separate_shader_objects : enable\n"
2584 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002585 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002586 "layout (location=0) out vec4 outColor;\n"
2587 "layout (location=0) in vec2 UV;\n"
2588 "void main() {\n"
2589 " outColor= textureLod(surface, UV, 0.0);\n"
2590 "}\n";
2591 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2592
2593 glm::mat4 View = glm::lookAt(
2594 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2595 glm::vec3(0,0,0), // and looks at the origin
2596 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2597 );
2598
2599 glm::mat4 Model = glm::mat4(1.0f);
2600
2601 glm::mat4 MVP = Projection * View * Model;
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002602 int num_verts = sizeof(g_vb_texture_Data) / sizeof(g_vb_texture_Data[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002603
2604
2605 ASSERT_NO_FATAL_FAILURE(InitState());
2606 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour17c6ab12015-03-27 17:03:18 -06002607 m_depthStencil->Init(m_device, m_width, m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07002608
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002609 VkConstantBufferObj meshBuffer(m_device, num_verts,
2610 sizeof(g_vb_texture_Data[0]), g_vb_texture_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002611 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002612
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002613 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07002614
Tony Barbour01999182015-04-09 12:58:51 -06002615 VkConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2616 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2617 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2618 VkSamplerObj sampler(m_device);
2619 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002620
Tony Barbour01999182015-04-09 12:58:51 -06002621 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002622 pipelineobj.AddShader(&vs);
2623 pipelineobj.AddShader(&ps);
2624
Tony Barbour01999182015-04-09 12:58:51 -06002625 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002626 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mvpBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002627 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002628
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002629#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002630 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002631 MESH_BIND_ID, // binding ID
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002632 sizeof(g_vb_texture_Data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002633 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002634 };
Tony Barbourf43b6982014-11-25 13:18:32 -07002635
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002636 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002637 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2638 vi_attribs[0].location = 0; // location
Tony Barbour8205d902015-04-16 15:59:00 -06002639 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002640 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2641 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2642 vi_attribs[1].location = 1; // location
2643 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
2644 vi_attribs[1].offsetInBytes = 16; // Offset of uv components
Tony Barbourf43b6982014-11-25 13:18:32 -07002645
Tony Barbourf43b6982014-11-25 13:18:32 -07002646 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002647 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2648 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07002649
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002650 VkPipelineDsStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002651 ds_state.depthTestEnable = VK_TRUE;
2652 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06002653 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002654 ds_state.depthBoundsEnable = VK_FALSE;
2655 ds_state.stencilTestEnable = VK_FALSE;
2656 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
2657 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
2658 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06002659 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
2660 ds_state.format = VK_FORMAT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002661 ds_state.front = ds_state.back;
2662 pipelineobj.SetDepthStencil(&ds_state);
2663
Tony Barbour17c6ab12015-03-27 17:03:18 -06002664 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour01999182015-04-09 12:58:51 -06002665 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002666 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002667
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002668 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002669
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002670 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002671
2672 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2673#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002674 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002675 pDSDumpDot((char*)"triTest2.dot");
2676#endif
2677 // render triangle
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002678 cmdBuffer.Draw(0, num_verts, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002679
2680 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002681 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002682 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002683
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002684 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002685 RotateTriangleVSUniform(Projection, View, Model, &mvpBuffer, &cmdBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002686}
Cody Northropd1ce7842014-12-09 11:17:01 -07002687
Tony Barbour01999182015-04-09 12:58:51 -06002688TEST_F(VkRenderTest, TriangleMixedSamplerUniformBlockBinding)
Cody Northropd1ce7842014-12-09 11:17:01 -07002689{
2690 // This test mixes binding slots of textures and buffers, ensuring
2691 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002692 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002693 // you can modify it to move the desired result around.
2694
2695 static const char *vertShaderText =
2696 "#version 140\n"
2697 "#extension GL_ARB_separate_shader_objects : enable\n"
2698 "#extension GL_ARB_shading_language_420pack : enable\n"
2699 "void main() {\n"
2700 " vec2 vertices[3];"
2701 " vertices[0] = vec2(-0.5, -0.5);\n"
2702 " vertices[1] = vec2( 0.5, -0.5);\n"
2703 " vertices[2] = vec2( 0.5, 0.5);\n"
2704 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2705 "}\n";
2706
2707 static const char *fragShaderText =
2708 "#version 430\n"
2709 "#extension GL_ARB_separate_shader_objects : enable\n"
2710 "#extension GL_ARB_shading_language_420pack : enable\n"
2711 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002712 "layout (binding = 3) uniform sampler2D surface1;\n"
2713 "layout (binding = 1) uniform sampler2D surface2;\n"
2714 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002715
Cody Northropa0410942014-12-09 13:59:39 -07002716
Chia-I Wuf8385062015-01-04 16:27:24 +08002717 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2718 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2719 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2720 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002721 "layout (location = 0) out vec4 outColor;\n"
2722 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002723 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002724 " outColor += white * vec4(0.00001);\n"
2725 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002726 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002727 "}\n";
2728 ASSERT_NO_FATAL_FAILURE(InitState());
2729 ASSERT_NO_FATAL_FAILURE(InitViewport());
2730
Tony Barbour01999182015-04-09 12:58:51 -06002731 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2732 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northropd1ce7842014-12-09 11:17:01 -07002733
Cody Northropd1ce7842014-12-09 11:17:01 -07002734 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2735 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2736 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2737 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2738
2739 const int redCount = sizeof(redVals) / sizeof(float);
2740 const int greenCount = sizeof(greenVals) / sizeof(float);
2741 const int blueCount = sizeof(blueVals) / sizeof(float);
2742 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2743
Tony Barbour01999182015-04-09 12:58:51 -06002744 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2745 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2746 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2747 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002748
Tony Barbour2f421a02015-04-01 16:38:10 -06002749 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002750 VkSamplerObj sampler0(m_device);
2751 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002752 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002753 VkSamplerObj sampler2(m_device);
2754 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002755 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002756 VkSamplerObj sampler4(m_device);
2757 VkTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropa0410942014-12-09 13:59:39 -07002758
2759 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2760 // TODO: Get back here ASAP and understand why.
Tony Barbour2f421a02015-04-01 16:38:10 -06002761 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06002762 VkSamplerObj sampler7(m_device);
2763 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropd1ce7842014-12-09 11:17:01 -07002764
Tony Barbour01999182015-04-09 12:58:51 -06002765 VkPipelineObj pipelineobj(m_device);
Cody Northropd1ce7842014-12-09 11:17:01 -07002766 pipelineobj.AddShader(&vs);
2767 pipelineobj.AddShader(&ps);
2768
Tony Barbour01999182015-04-09 12:58:51 -06002769 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002770 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2771 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2772 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2773 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002774 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002775 // swap blue and green
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002776 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2777 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2778 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002779
Tony Barbourdd4c9642015-01-09 12:55:14 -07002780 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002781 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002782 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002783
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002784 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002785
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002786 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002787
2788#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002789 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002790 pDSDumpDot((char*)"triTest2.dot");
2791#endif
2792 // render triangle
2793 cmdBuffer.Draw(0, 3, 0, 1);
2794
2795 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002796 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002797 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002798
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002799 RecordImages(m_renderTargets);
Cody Northropd1ce7842014-12-09 11:17:01 -07002800}
2801
Tony Barbour01999182015-04-09 12:58:51 -06002802TEST_F(VkRenderTest, TriangleMatchingSamplerUniformBlockBinding)
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002803{
2804 // This test matches binding slots of textures and buffers, requiring
2805 // the driver to give them distinct number spaces.
2806 // The expected result from this test is a red triangle, although
2807 // you can modify it to move the desired result around.
2808
2809 static const char *vertShaderText =
2810 "#version 140\n"
2811 "#extension GL_ARB_separate_shader_objects : enable\n"
2812 "#extension GL_ARB_shading_language_420pack : enable\n"
2813 "void main() {\n"
2814 " vec2 vertices[3];"
2815 " vertices[0] = vec2(-0.5, -0.5);\n"
2816 " vertices[1] = vec2( 0.5, -0.5);\n"
2817 " vertices[2] = vec2( 0.5, 0.5);\n"
2818 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2819 "}\n";
2820
2821 static const char *fragShaderText =
2822 "#version 430\n"
2823 "#extension GL_ARB_separate_shader_objects : enable\n"
2824 "#extension GL_ARB_shading_language_420pack : enable\n"
2825 "layout (binding = 0) uniform sampler2D surface0;\n"
2826 "layout (binding = 1) uniform sampler2D surface1;\n"
2827 "layout (binding = 2) uniform sampler2D surface2;\n"
2828 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002829 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2830 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2831 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2832 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002833 "layout (location = 0) out vec4 outColor;\n"
2834 "void main() {\n"
2835 " outColor = red;// * vec4(0.00001);\n"
2836 " outColor += white * vec4(0.00001);\n"
2837 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2838 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2839 "}\n";
2840 ASSERT_NO_FATAL_FAILURE(InitState());
2841 ASSERT_NO_FATAL_FAILURE(InitViewport());
2842
Tony Barbour01999182015-04-09 12:58:51 -06002843 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2844 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002845
2846 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2847 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2848 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2849 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2850
2851 const int redCount = sizeof(redVals) / sizeof(float);
2852 const int greenCount = sizeof(greenVals) / sizeof(float);
2853 const int blueCount = sizeof(blueVals) / sizeof(float);
2854 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2855
Tony Barbour01999182015-04-09 12:58:51 -06002856 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2857 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2858 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2859 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002860
Tony Barbour2f421a02015-04-01 16:38:10 -06002861 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002862 VkSamplerObj sampler0(m_device);
2863 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002864 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002865 VkSamplerObj sampler2(m_device);
2866 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002867 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002868 VkSamplerObj sampler4(m_device);
2869 VkTextureObj texture4(m_device, tex_colors); // Light Green
Tony Barbour2f421a02015-04-01 16:38:10 -06002870 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06002871 VkSamplerObj sampler7(m_device);
2872 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002873
Tony Barbour01999182015-04-09 12:58:51 -06002874 VkPipelineObj pipelineobj(m_device);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002875 pipelineobj.AddShader(&vs);
2876 pipelineobj.AddShader(&ps);
2877
Tony Barbour01999182015-04-09 12:58:51 -06002878 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002879 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2880 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2881 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2882 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002883 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2884 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2885 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2886 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002887
Tony Barbourdd4c9642015-01-09 12:55:14 -07002888 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002889 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002890 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002891
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002892 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002893
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002894 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002895
2896#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002897 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002898 pDSDumpDot((char*)"triTest2.dot");
2899#endif
2900 // render triangle
2901 cmdBuffer.Draw(0, 3, 0, 1);
2902
2903 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002904 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002905 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002906
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002907 RecordImages(m_renderTargets);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002908}
2909
Tony Barbour01999182015-04-09 12:58:51 -06002910TEST_F(VkRenderTest, TriangleUniformBufferLayout)
Cody Northrop02690bd2014-12-17 15:26:33 -07002911{
2912 // This test populates a buffer with a variety of different data
2913 // types, then reads them out with a shader.
2914 // The expected result from this test is a green triangle
2915
2916 static const char *vertShaderText =
2917 "#version 140\n"
2918 "#extension GL_ARB_separate_shader_objects : enable\n"
2919 "#extension GL_ARB_shading_language_420pack : enable\n"
2920 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2921 " vec4 fRed;\n"
2922 " vec4 fGreen;\n"
2923 " layout(row_major) mat4 worldToProj;\n"
2924 " layout(row_major) mat4 projToWorld;\n"
2925 " layout(row_major) mat4 worldToView;\n"
2926 " layout(row_major) mat4 viewToProj;\n"
2927 " layout(row_major) mat4 worldToShadow[4];\n"
2928 " float fZero;\n"
2929 " float fOne;\n"
2930 " float fTwo;\n"
2931 " float fThree;\n"
2932 " vec3 fZeroZeroZero;\n"
2933 " float fFour;\n"
2934 " vec3 fZeroZeroOne;\n"
2935 " float fFive;\n"
2936 " vec3 fZeroOneZero;\n"
2937 " float fSix;\n"
2938 " float fSeven;\n"
2939 " float fEight;\n"
2940 " float fNine;\n"
2941 " vec2 fZeroZero;\n"
2942 " vec2 fZeroOne;\n"
2943 " vec4 fBlue;\n"
2944 " vec2 fOneZero;\n"
2945 " vec2 fOneOne;\n"
2946 " vec3 fZeroOneOne;\n"
2947 " float fTen;\n"
2948 " float fEleven;\n"
2949 " float fTwelve;\n"
2950 " vec3 fOneZeroZero;\n"
2951 " vec4 uvOffsets[4];\n"
2952 "};\n"
2953 "layout (location = 0) out vec4 color;"
2954 "void main() {\n"
2955
2956 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2957 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2958 " \n"
2959
2960 // do some exact comparisons, even though we should
2961 // really have an epsilon involved.
2962 " vec4 outColor = right;\n"
2963 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
2964 " outColor = wrong;\n"
2965 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
2966 " outColor = wrong;\n"
2967 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
2968 " outColor = wrong;\n"
2969
2970 " color = outColor;\n"
2971
2972 // generic position stuff
2973 " vec2 vertices;\n"
2974 " int vertexSelector = gl_VertexID;\n"
2975 " if (vertexSelector == 0)\n"
2976 " vertices = vec2(-0.5, -0.5);\n"
2977 " else if (vertexSelector == 1)\n"
2978 " vertices = vec2( 0.5, -0.5);\n"
2979 " else if (vertexSelector == 2)\n"
2980 " vertices = vec2( 0.5, 0.5);\n"
2981 " else\n"
2982 " vertices = vec2( 0.0, 0.0);\n"
2983 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
2984 "}\n";
2985
2986 static const char *fragShaderText =
2987 "#version 140\n"
2988 "#extension GL_ARB_separate_shader_objects : enable\n"
2989 "#extension GL_ARB_shading_language_420pack : enable\n"
2990 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2991 " vec4 fRed;\n"
2992 " vec4 fGreen;\n"
2993 " layout(row_major) mat4 worldToProj;\n"
2994 " layout(row_major) mat4 projToWorld;\n"
2995 " layout(row_major) mat4 worldToView;\n"
2996 " layout(row_major) mat4 viewToProj;\n"
2997 " layout(row_major) mat4 worldToShadow[4];\n"
2998 " float fZero;\n"
2999 " float fOne;\n"
3000 " float fTwo;\n"
3001 " float fThree;\n"
3002 " vec3 fZeroZeroZero;\n"
3003 " float fFour;\n"
3004 " vec3 fZeroZeroOne;\n"
3005 " float fFive;\n"
3006 " vec3 fZeroOneZero;\n"
3007 " float fSix;\n"
3008 " float fSeven;\n"
3009 " float fEight;\n"
3010 " float fNine;\n"
3011 " vec2 fZeroZero;\n"
3012 " vec2 fZeroOne;\n"
3013 " vec4 fBlue;\n"
3014 " vec2 fOneZero;\n"
3015 " vec2 fOneOne;\n"
3016 " vec3 fZeroOneOne;\n"
3017 " float fTen;\n"
3018 " float fEleven;\n"
3019 " float fTwelve;\n"
3020 " vec3 fOneZeroZero;\n"
3021 " vec4 uvOffsets[4];\n"
3022 "};\n"
3023 "layout (location = 0) in vec4 color;\n"
3024 "void main() {\n"
3025 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3026 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3027 " \n"
3028
3029 // start with VS value to ensure it passed
3030 " vec4 outColor = color;\n"
3031
3032 // do some exact comparisons, even though we should
3033 // really have an epsilon involved.
3034 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3035 " outColor = wrong;\n"
3036 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3037 " outColor = wrong;\n"
3038 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3039 " outColor = wrong;\n"
3040 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3041 " outColor = wrong;\n"
3042 " if (fTwo != 2.0)\n"
3043 " outColor = wrong;\n"
3044 " if (fOneOne != vec2(1.0, 1.0))\n"
3045 " outColor = wrong;\n"
3046 " if (fTen != 10.0)\n"
3047 " outColor = wrong;\n"
3048 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3049 " outColor = wrong;\n"
3050 " \n"
3051 " gl_FragColor = outColor;\n"
3052 "}\n";
3053
3054
3055 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3056 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3057 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3058 0.0, 1.0, 0.0, 1.0, // align
3059 0.0, 0.0, 1.0, 1.0, // align
3060 0.0, 0.0, 0.0, 1.0, // align
3061 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3062 0.0, 2.0, 0.0, 2.0, // align
3063 0.0, 0.0, 2.0, 2.0, // align
3064 0.0, 0.0, 0.0, 2.0, // align
3065 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3066 0.0, 3.0, 0.0, 3.0, // align
3067 0.0, 0.0, 3.0, 3.0, // align
3068 0.0, 0.0, 0.0, 3.0, // align
3069 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3070 0.0, 4.0, 0.0, 4.0, // align
3071 0.0, 0.0, 4.0, 4.0, // align
3072 0.0, 0.0, 0.0, 4.0, // align
3073 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3074 0.0, 5.0, 0.0, 5.0, // align
3075 0.0, 0.0, 5.0, 5.0, // align
3076 0.0, 0.0, 0.0, 5.0, // align
3077 6.0, 0.0, 0.0, 6.0, // align
3078 0.0, 6.0, 0.0, 6.0, // align
3079 0.0, 0.0, 6.0, 6.0, // align
3080 0.0, 0.0, 0.0, 6.0, // align
3081 7.0, 0.0, 0.0, 7.0, // align
3082 0.0, 7.0, 0.0, 7.0, // align
3083 0.0, 0.0, 7.0, 7.0, // align
3084 0.0, 0.0, 0.0, 7.0, // align
3085 8.0, 0.0, 0.0, 8.0, // align
3086 0.0, 8.0, 0.0, 8.0, // align
3087 0.0, 0.0, 8.0, 8.0, // align
3088 0.0, 0.0, 0.0, 8.0, // align
3089 0.0, // float fZero; // align
3090 1.0, // float fOne; // pack
3091 2.0, // float fTwo; // pack
3092 3.0, // float fThree; // pack
3093 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3094 4.0, // float fFour; // pack
3095 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3096 5.0, // float fFive; // pack
3097 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3098 6.0, // float fSix; // pack
3099 7.0, // float fSeven; // align
3100 8.0, // float fEight; // pack
3101 9.0, // float fNine; // pack
3102 0.0, // BUFFER
3103 0.0, 0.0, // vec2 fZeroZero; // align
3104 0.0, 1.0, // vec2 fZeroOne; // pack
3105 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3106 1.0, 0.0, // vec2 fOneZero; // align
3107 1.0, 1.0, // vec2 fOneOne; // pack
3108 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3109 10.0, // float fTen; // pack
3110 11.0, // float fEleven; // align
3111 12.0, // float fTwelve; // pack
3112 0.0, 0.0, // BUFFER
3113 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3114 0.0, // BUFFER
3115 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3116 0.5, 0.6, 0.7, 0.8, // align
3117 0.9, 1.0, 1.1, 1.2, // align
3118 1.3, 1.4, 1.5, 1.6, // align
3119 };
3120
3121 ASSERT_NO_FATAL_FAILURE(InitState());
3122 ASSERT_NO_FATAL_FAILURE(InitViewport());
3123
3124 const int constCount = sizeof(mixedVals) / sizeof(float);
3125
Tony Barbour01999182015-04-09 12:58:51 -06003126 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3127 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop02690bd2014-12-17 15:26:33 -07003128
Tony Barbour01999182015-04-09 12:58:51 -06003129 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003130
Tony Barbour01999182015-04-09 12:58:51 -06003131 VkPipelineObj pipelineobj(m_device);
Cody Northrop02690bd2014-12-17 15:26:33 -07003132 pipelineobj.AddShader(&vs);
3133 pipelineobj.AddShader(&ps);
3134
Tony Barbour01999182015-04-09 12:58:51 -06003135 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003136 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003137
3138 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06003139 VkCommandBufferObj cmdBuffer(m_device);
Cody Northrop02690bd2014-12-17 15:26:33 -07003140 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3141
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003142 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Cody Northrop02690bd2014-12-17 15:26:33 -07003143
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003144 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Cody Northrop02690bd2014-12-17 15:26:33 -07003145
3146#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003147 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop02690bd2014-12-17 15:26:33 -07003148 pDSDumpDot((char*)"triTest2.dot");
3149#endif
3150 // render triangle
3151 cmdBuffer.Draw(0, 3, 0, 1);
3152
3153 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003154 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003155 cmdBuffer.QueueCommandBuffer();
Cody Northrop02690bd2014-12-17 15:26:33 -07003156
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003157 RecordImages(m_renderTargets);
Cody Northrop02690bd2014-12-17 15:26:33 -07003158}
3159
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003160TEST_F(VkRenderTest, TextureGather)
3161{
3162 // This test introduces textureGather and textureGatherOffset
3163 // Each call is compared against an expected inline color result
3164 // Green triangle means everything worked as expected
3165 // Red means something went wrong
3166
3167 // disable SPV until texture gather is turned on in LunarGLASS
3168 bool saved_use_spv = VkTestFramework::m_use_spv;
3169 VkTestFramework::m_use_spv = false;
3170
3171 static const char *vertShaderText =
3172 "#version 140\n"
3173 "#extension GL_ARB_separate_shader_objects : enable\n"
3174 "#extension GL_ARB_shading_language_420pack : enable\n"
3175 "void main() {\n"
3176 " vec2 vertices[3];"
3177 " vertices[0] = vec2(-0.5, -0.5);\n"
3178 " vertices[1] = vec2( 0.5, -0.5);\n"
3179 " vertices[2] = vec2( 0.5, 0.5);\n"
3180 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
3181 "}\n";
3182
3183 static const char *fragShaderText =
3184 "#version 430\n"
3185 "#extension GL_ARB_separate_shader_objects : enable\n"
3186 "#extension GL_ARB_shading_language_420pack : enable\n"
3187 "layout (binding = 0) uniform sampler2D surface0;\n"
3188 "layout (binding = 1) uniform sampler2D surface1;\n"
3189 "layout (binding = 2) uniform sampler2D surface2;\n"
3190 "layout (binding = 3) uniform sampler2D surface3;\n"
3191 "layout (location = 0) out vec4 outColor;\n"
3192 "void main() {\n"
3193
3194 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3195 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3196
3197 " vec4 color = right;\n"
3198
3199 // Grab a normal texture sample to ensure it can work in conjuntion
3200 // with textureGather (there are some intracacies in the backend)
3201 " vec4 sampledColor = textureLod(surface2, vec2(0.5), 0.0);\n"
3202 " if (sampledColor != vec4(0.0, 0.0, 1.0, 1.0))\n"
3203 " color = wrong;\n"
3204
3205 " vec4 gatheredColor = textureGather(surface0, vec2(0.5), 0);\n"
3206 // This just grabbed four red components from a red surface
3207 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3208 " color = wrong;\n"
3209
3210 // Yes, this is using an offset of 0, we don't have enough fine grained
3211 // control of the texture contents here.
3212 " gatheredColor = textureGatherOffset(surface1, vec2(0.5), ivec2(0, 0), 1);\n"
3213 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3214 " color = wrong;\n"
3215
3216 " outColor = color;\n"
3217
3218 "}\n";
3219
3220 ASSERT_NO_FATAL_FAILURE(InitState());
3221 ASSERT_NO_FATAL_FAILURE(InitViewport());
3222
3223 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3224 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3225
3226 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
3227 VkSamplerObj sampler0(m_device);
3228 VkTextureObj texture0(m_device, tex_colors); // Red
3229 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
3230 VkSamplerObj sampler1(m_device);
3231 VkTextureObj texture1(m_device, tex_colors); // Green
3232 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
3233 VkSamplerObj sampler2(m_device);
3234 VkTextureObj texture2(m_device, tex_colors); // Blue
3235 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
3236 VkSamplerObj sampler3(m_device);
3237 VkTextureObj texture3(m_device, tex_colors); // Red and Blue
3238
3239 VkPipelineObj pipelineobj(m_device);
3240 pipelineobj.AddShader(&vs);
3241 pipelineobj.AddShader(&ps);
3242
3243 VkDescriptorSetObj descriptorSet(m_device);
3244 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3245 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
3246 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3247 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
3248
3249 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3250 VkCommandBufferObj cmdBuffer(m_device);
3251 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3252
3253 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3254
3255 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3256
3257 // render triangle
3258 cmdBuffer.Draw(0, 3, 0, 1);
3259
3260 // finalize recording of the command buffer
3261 EndCommandBuffer(cmdBuffer);
3262 cmdBuffer.QueueCommandBuffer();
3263
3264 RecordImages(m_renderTargets);
3265
3266 // restore SPV setting
3267 VkTestFramework::m_use_spv = saved_use_spv;
3268}
3269
Cody Northropa44c2ff2015-04-15 11:19:06 -06003270TEST_F(VkRenderTest, GeometryShaderHelloWorld)
3271{
3272 // This test introduces a geometry shader that simply
3273 // changes the color of each vertex to red, green, blue
3274
3275 static const char *vertShaderText =
3276 "#version 140\n"
3277 "#extension GL_ARB_separate_shader_objects : enable\n"
3278 "#extension GL_ARB_shading_language_420pack : enable\n"
3279 "layout (location = 0) out vec4 color;"
3280 "void main() {\n"
3281
3282 // VS writes out red
3283 " color = vec4(1.0, 0.0, 0.0, 1.0);\n"
3284
3285 // generic position stuff
3286 " vec2 vertices;\n"
3287 " int vertexSelector = gl_VertexID;\n"
3288 " if (vertexSelector == 0)\n"
3289 " vertices = vec2(-0.5, -0.5);\n"
3290 " else if (vertexSelector == 1)\n"
3291 " vertices = vec2( 0.5, -0.5);\n"
3292 " else if (vertexSelector == 2)\n"
3293 " vertices = vec2( 0.5, 0.5);\n"
3294 " else\n"
3295 " vertices = vec2( 0.0, 0.0);\n"
3296 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3297
3298 "}\n";
3299
3300 static const char *geomShaderText =
3301 "#version 330\n"
3302 "#extension GL_ARB_separate_shader_objects : enable\n"
3303 "#extension GL_ARB_shading_language_420pack : enable\n"
3304 "layout( triangles ) in;\n"
3305 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3306 "layout( location = 0 ) in vec4 inColor[3];\n"
3307 "layout( location = 0 ) out vec4 outColor;\n"
3308 "void main()\n"
3309 "{\n"
3310
3311 // first vertex, pass through red
3312 " gl_Position = gl_in[0].gl_Position;\n"
3313 " outColor = inColor[0];\n"
3314 " EmitVertex();\n"
3315
3316 // second vertex, green
3317 " gl_Position = gl_in[1].gl_Position;\n"
3318 " outColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3319 " EmitVertex();\n"
3320
3321 // third vertex, blue
3322 " gl_Position = gl_in[2].gl_Position;\n"
3323 " outColor = vec4(0.0, 0.0, 1.0, 1.0);\n"
3324 " EmitVertex();\n"
3325
3326 // done
3327 " EndPrimitive();\n"
3328 "}\n";
3329
3330
3331 static const char *fragShaderText =
3332 "#version 140\n"
3333 "#extension GL_ARB_separate_shader_objects : enable\n"
3334 "#extension GL_ARB_shading_language_420pack : enable\n"
3335 "layout (location = 0) in vec4 color;\n"
3336 "void main() {\n"
3337 // pass through
3338 " gl_FragColor = color;\n"
3339 "}\n";
3340
3341
3342
3343 ASSERT_NO_FATAL_FAILURE(InitState());
3344 ASSERT_NO_FATAL_FAILURE(InitViewport());
3345
3346 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3347 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3348 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3349
3350 VkPipelineObj pipelineobj(m_device);
3351 pipelineobj.AddShader(&vs);
3352 pipelineobj.AddShader(&gs);
3353 pipelineobj.AddShader(&ps);
3354
3355 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3356 VkCommandBufferObj cmdBuffer(m_device);
3357 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3358
3359 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3360
3361 VkDescriptorSetObj descriptorSet(m_device);
3362
3363 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3364
3365 // render triangle
3366 cmdBuffer.Draw(0, 3, 0, 1);
3367
3368 // finalize recording of the command buffer
3369 EndCommandBuffer(cmdBuffer);
3370 cmdBuffer.QueueCommandBuffer();
3371
3372 RecordImages(m_renderTargets);
3373}
3374
3375TEST_F(VkRenderTest, GSUniformBufferLayout)
3376{
3377 // This test is just like TriangleUniformBufferLayout but adds
3378 // geometry as a stage that also does UBO lookups
3379 // The expected result from this test is a green triangle
3380
3381 static const char *vertShaderText =
3382 "#version 140\n"
3383 "#extension GL_ARB_separate_shader_objects : enable\n"
3384 "#extension GL_ARB_shading_language_420pack : enable\n"
3385 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3386 " vec4 fRed;\n"
3387 " vec4 fGreen;\n"
3388 " layout(row_major) mat4 worldToProj;\n"
3389 " layout(row_major) mat4 projToWorld;\n"
3390 " layout(row_major) mat4 worldToView;\n"
3391 " layout(row_major) mat4 viewToProj;\n"
3392 " layout(row_major) mat4 worldToShadow[4];\n"
3393 " float fZero;\n"
3394 " float fOne;\n"
3395 " float fTwo;\n"
3396 " float fThree;\n"
3397 " vec3 fZeroZeroZero;\n"
3398 " float fFour;\n"
3399 " vec3 fZeroZeroOne;\n"
3400 " float fFive;\n"
3401 " vec3 fZeroOneZero;\n"
3402 " float fSix;\n"
3403 " float fSeven;\n"
3404 " float fEight;\n"
3405 " float fNine;\n"
3406 " vec2 fZeroZero;\n"
3407 " vec2 fZeroOne;\n"
3408 " vec4 fBlue;\n"
3409 " vec2 fOneZero;\n"
3410 " vec2 fOneOne;\n"
3411 " vec3 fZeroOneOne;\n"
3412 " float fTen;\n"
3413 " float fEleven;\n"
3414 " float fTwelve;\n"
3415 " vec3 fOneZeroZero;\n"
3416 " vec4 uvOffsets[4];\n"
3417 "};\n"
3418 "layout (location = 0) out vec4 color;"
3419 "void main() {\n"
3420
3421 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3422 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3423 " \n"
3424
3425 // do some exact comparisons, even though we should
3426 // really have an epsilon involved.
3427 " vec4 outColor = right;\n"
3428 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3429 " outColor = wrong;\n"
3430 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3431 " outColor = wrong;\n"
3432 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3433 " outColor = wrong;\n"
3434
3435 " color = outColor;\n"
3436
3437 // generic position stuff
3438 " vec2 vertices;\n"
3439 " int vertexSelector = gl_VertexID;\n"
3440 " if (vertexSelector == 0)\n"
3441 " vertices = vec2(-0.5, -0.5);\n"
3442 " else if (vertexSelector == 1)\n"
3443 " vertices = vec2( 0.5, -0.5);\n"
3444 " else if (vertexSelector == 2)\n"
3445 " vertices = vec2( 0.5, 0.5);\n"
3446 " else\n"
3447 " vertices = vec2( 0.0, 0.0);\n"
3448 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3449 "}\n";
3450
3451 static const char *geomShaderText =
3452 "#version 330\n"
3453 "#extension GL_ARB_separate_shader_objects : enable\n"
3454 "#extension GL_ARB_shading_language_420pack : enable\n"
3455
3456 // GS layout stuff
3457 "layout( triangles ) in;\n"
3458 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3459
3460 // Between stage IO
3461 "layout( location = 0 ) in vec4 inColor[3];\n"
3462 "layout( location = 0 ) out vec4 color;\n"
3463
3464 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3465 " vec4 fRed;\n"
3466 " vec4 fGreen;\n"
3467 " layout(row_major) mat4 worldToProj;\n"
3468 " layout(row_major) mat4 projToWorld;\n"
3469 " layout(row_major) mat4 worldToView;\n"
3470 " layout(row_major) mat4 viewToProj;\n"
3471 " layout(row_major) mat4 worldToShadow[4];\n"
3472 " float fZero;\n"
3473 " float fOne;\n"
3474 " float fTwo;\n"
3475 " float fThree;\n"
3476 " vec3 fZeroZeroZero;\n"
3477 " float fFour;\n"
3478 " vec3 fZeroZeroOne;\n"
3479 " float fFive;\n"
3480 " vec3 fZeroOneZero;\n"
3481 " float fSix;\n"
3482 " float fSeven;\n"
3483 " float fEight;\n"
3484 " float fNine;\n"
3485 " vec2 fZeroZero;\n"
3486 " vec2 fZeroOne;\n"
3487 " vec4 fBlue;\n"
3488 " vec2 fOneZero;\n"
3489 " vec2 fOneOne;\n"
3490 " vec3 fZeroOneOne;\n"
3491 " float fTen;\n"
3492 " float fEleven;\n"
3493 " float fTwelve;\n"
3494 " vec3 fOneZeroZero;\n"
3495 " vec4 uvOffsets[4];\n"
3496 "};\n"
3497
3498 "void main()\n"
3499 "{\n"
3500
3501 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3502 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3503
3504 // Each vertex will validate it can read VS output
3505 // then check a few values from the UBO
3506
3507 // first vertex
3508 " vec4 outColor = inColor[0];\n"
3509
3510 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3511 " outColor = wrong;\n"
3512 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3513 " outColor = wrong;\n"
3514 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3515 " outColor = wrong;\n"
3516 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3517 " outColor = wrong;\n"
3518
3519 " gl_Position = gl_in[0].gl_Position;\n"
3520 " color = outColor;\n"
3521 " EmitVertex();\n"
3522
3523 // second vertex
3524 " outColor = inColor[1];\n"
3525
3526 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3527 " outColor = wrong;\n"
3528 " if (fSix != 6.0)\n"
3529 " outColor = wrong;\n"
3530 " if (fOneOne != vec2(1.0, 1.0))\n"
3531 " outColor = wrong;\n"
3532
3533 " gl_Position = gl_in[1].gl_Position;\n"
3534 " color = outColor;\n"
3535 " EmitVertex();\n"
3536
3537 // third vertex
3538 " outColor = inColor[2];\n"
3539
3540 " if (fSeven != 7.0)\n"
3541 " outColor = wrong;\n"
3542 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3543 " outColor = wrong;\n"
3544
3545 " gl_Position = gl_in[2].gl_Position;\n"
3546 " color = outColor;\n"
3547 " EmitVertex();\n"
3548
3549 // done
3550 " EndPrimitive();\n"
3551 "}\n";
3552
3553 static const char *fragShaderText =
3554 "#version 140\n"
3555 "#extension GL_ARB_separate_shader_objects : enable\n"
3556 "#extension GL_ARB_shading_language_420pack : enable\n"
3557 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3558 " vec4 fRed;\n"
3559 " vec4 fGreen;\n"
3560 " layout(row_major) mat4 worldToProj;\n"
3561 " layout(row_major) mat4 projToWorld;\n"
3562 " layout(row_major) mat4 worldToView;\n"
3563 " layout(row_major) mat4 viewToProj;\n"
3564 " layout(row_major) mat4 worldToShadow[4];\n"
3565 " float fZero;\n"
3566 " float fOne;\n"
3567 " float fTwo;\n"
3568 " float fThree;\n"
3569 " vec3 fZeroZeroZero;\n"
3570 " float fFour;\n"
3571 " vec3 fZeroZeroOne;\n"
3572 " float fFive;\n"
3573 " vec3 fZeroOneZero;\n"
3574 " float fSix;\n"
3575 " float fSeven;\n"
3576 " float fEight;\n"
3577 " float fNine;\n"
3578 " vec2 fZeroZero;\n"
3579 " vec2 fZeroOne;\n"
3580 " vec4 fBlue;\n"
3581 " vec2 fOneZero;\n"
3582 " vec2 fOneOne;\n"
3583 " vec3 fZeroOneOne;\n"
3584 " float fTen;\n"
3585 " float fEleven;\n"
3586 " float fTwelve;\n"
3587 " vec3 fOneZeroZero;\n"
3588 " vec4 uvOffsets[4];\n"
3589 "};\n"
3590 "layout (location = 0) in vec4 color;\n"
3591 "void main() {\n"
3592 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3593 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3594 " \n"
3595
3596 // start with GS value to ensure it passed
3597 " vec4 outColor = color;\n"
3598
3599 // do some exact comparisons, even though we should
3600 // really have an epsilon involved.
3601 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3602 " outColor = wrong;\n"
3603 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3604 " outColor = wrong;\n"
3605 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3606 " outColor = wrong;\n"
3607 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3608 " outColor = wrong;\n"
3609 " if (fTwo != 2.0)\n"
3610 " outColor = wrong;\n"
3611 " if (fOneOne != vec2(1.0, 1.0))\n"
3612 " outColor = wrong;\n"
3613 " if (fTen != 10.0)\n"
3614 " outColor = wrong;\n"
3615 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3616 " outColor = wrong;\n"
3617 " \n"
3618 " gl_FragColor = outColor;\n"
3619 "}\n";
3620
3621
3622 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3623 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3624 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3625 0.0, 1.0, 0.0, 1.0, // align
3626 0.0, 0.0, 1.0, 1.0, // align
3627 0.0, 0.0, 0.0, 1.0, // align
3628 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3629 0.0, 2.0, 0.0, 2.0, // align
3630 0.0, 0.0, 2.0, 2.0, // align
3631 0.0, 0.0, 0.0, 2.0, // align
3632 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3633 0.0, 3.0, 0.0, 3.0, // align
3634 0.0, 0.0, 3.0, 3.0, // align
3635 0.0, 0.0, 0.0, 3.0, // align
3636 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3637 0.0, 4.0, 0.0, 4.0, // align
3638 0.0, 0.0, 4.0, 4.0, // align
3639 0.0, 0.0, 0.0, 4.0, // align
3640 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3641 0.0, 5.0, 0.0, 5.0, // align
3642 0.0, 0.0, 5.0, 5.0, // align
3643 0.0, 0.0, 0.0, 5.0, // align
3644 6.0, 0.0, 0.0, 6.0, // align
3645 0.0, 6.0, 0.0, 6.0, // align
3646 0.0, 0.0, 6.0, 6.0, // align
3647 0.0, 0.0, 0.0, 6.0, // align
3648 7.0, 0.0, 0.0, 7.0, // align
3649 0.0, 7.0, 0.0, 7.0, // align
3650 0.0, 0.0, 7.0, 7.0, // align
3651 0.0, 0.0, 0.0, 7.0, // align
3652 8.0, 0.0, 0.0, 8.0, // align
3653 0.0, 8.0, 0.0, 8.0, // align
3654 0.0, 0.0, 8.0, 8.0, // align
3655 0.0, 0.0, 0.0, 8.0, // align
3656 0.0, // float fZero; // align
3657 1.0, // float fOne; // pack
3658 2.0, // float fTwo; // pack
3659 3.0, // float fThree; // pack
3660 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3661 4.0, // float fFour; // pack
3662 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3663 5.0, // float fFive; // pack
3664 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3665 6.0, // float fSix; // pack
3666 7.0, // float fSeven; // align
3667 8.0, // float fEight; // pack
3668 9.0, // float fNine; // pack
3669 0.0, // BUFFER
3670 0.0, 0.0, // vec2 fZeroZero; // align
3671 0.0, 1.0, // vec2 fZeroOne; // pack
3672 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3673 1.0, 0.0, // vec2 fOneZero; // align
3674 1.0, 1.0, // vec2 fOneOne; // pack
3675 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3676 10.0, // float fTen; // pack
3677 11.0, // float fEleven; // align
3678 12.0, // float fTwelve; // pack
3679 0.0, 0.0, // BUFFER
3680 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3681 0.0, // BUFFER
3682 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3683 0.5, 0.6, 0.7, 0.8, // align
3684 0.9, 1.0, 1.1, 1.2, // align
3685 1.3, 1.4, 1.5, 1.6, // align
3686 };
3687
3688
3689
3690 ASSERT_NO_FATAL_FAILURE(InitState());
3691 ASSERT_NO_FATAL_FAILURE(InitViewport());
3692
3693 const int constCount = sizeof(mixedVals) / sizeof(float);
3694
3695 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3696 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3697 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3698
3699 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
3700
3701 VkPipelineObj pipelineobj(m_device);
3702 pipelineobj.AddShader(&vs);
3703 pipelineobj.AddShader(&gs);
3704 pipelineobj.AddShader(&ps);
3705
3706 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3707 VkCommandBufferObj cmdBuffer(m_device);
3708 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3709
3710 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3711
3712 VkDescriptorSetObj descriptorSet(m_device);
3713 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
3714
3715 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3716
3717 // render triangle
3718 cmdBuffer.Draw(0, 3, 0, 1);
3719
3720 // finalize recording of the command buffer
3721 EndCommandBuffer(cmdBuffer);
3722 cmdBuffer.QueueCommandBuffer();
3723
3724 RecordImages(m_renderTargets);
3725}
3726
3727TEST_F(VkRenderTest, GSPositions)
3728{
3729 // This test adds more inputs from the vertex shader and perturbs positions
3730 // Expected result is white triangle with weird positions
3731
3732 static const char *vertShaderText =
3733 "#version 140\n"
3734 "#extension GL_ARB_separate_shader_objects : enable\n"
3735 "#extension GL_ARB_shading_language_420pack : enable\n"
3736
3737 "layout(location = 0) out vec3 out_a;\n"
3738 "layout(location = 1) out vec3 out_b;\n"
3739 "layout(location = 2) out vec3 out_c;\n"
3740
3741 "void main() {\n"
3742
3743 // write a solid color to each
3744 " out_a = vec3(1.0, 0.0, 0.0);\n"
3745 " out_b = vec3(0.0, 1.0, 0.0);\n"
3746 " out_c = vec3(0.0, 0.0, 1.0);\n"
3747
3748 // generic position stuff
3749 " vec2 vertices;\n"
3750 " int vertexSelector = gl_VertexID;\n"
3751 " if (vertexSelector == 0)\n"
3752 " vertices = vec2(-0.5, -0.5);\n"
3753 " else if (vertexSelector == 1)\n"
3754 " vertices = vec2( 0.5, -0.5);\n"
3755 " else if (vertexSelector == 2)\n"
3756 " vertices = vec2( 0.5, 0.5);\n"
3757 " else\n"
3758 " vertices = vec2( 0.0, 0.0);\n"
3759 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3760
3761 "}\n";
3762
3763 static const char *geomShaderText =
3764 "#version 330\n"
3765 "#extension GL_ARB_separate_shader_objects : enable\n"
3766 "#extension GL_ARB_shading_language_420pack : enable\n"
3767 "layout( triangles ) in;\n"
3768 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3769
3770 "layout(location = 0) in vec3 in_a[3];\n"
3771 "layout(location = 1) in vec3 in_b[3];\n"
3772 "layout(location = 2) in vec3 in_c[3];\n"
3773
3774 "layout(location = 0) out vec3 out_a;\n"
3775 "layout(location = 1) out vec3 out_b;\n"
3776 "layout(location = 2) out vec3 out_c;\n"
3777
3778 "void main()\n"
3779 "{\n"
3780
3781 " gl_Position = gl_in[0].gl_Position;\n"
3782 " gl_Position.xy *= vec2(0.75);\n"
3783 " out_a = in_a[0];\n"
3784 " out_b = in_b[0];\n"
3785 " out_c = in_c[0];\n"
3786 " EmitVertex();\n"
3787
3788 " gl_Position = gl_in[1].gl_Position;\n"
3789 " gl_Position.xy *= vec2(1.5);\n"
3790 " out_a = in_a[1];\n"
3791 " out_b = in_b[1];\n"
3792 " out_c = in_c[1];\n"
3793 " EmitVertex();\n"
3794
3795 " gl_Position = gl_in[2].gl_Position;\n"
3796 " gl_Position.xy *= vec2(-0.1);\n"
3797 " out_a = in_a[2];\n"
3798 " out_b = in_b[2];\n"
3799 " out_c = in_c[2];\n"
3800 " EmitVertex();\n"
3801
3802 " EndPrimitive();\n"
3803 "}\n";
3804
3805
3806 static const char *fragShaderText =
3807 "#version 140\n"
3808 "#extension GL_ARB_separate_shader_objects : enable\n"
3809 "#extension GL_ARB_shading_language_420pack : enable\n"
3810
3811 "layout(location = 0) in vec3 in_a;\n"
3812 "layout(location = 1) in vec3 in_b;\n"
3813 "layout(location = 2) in vec3 in_c;\n"
3814
3815 "void main() {\n"
3816 " gl_FragColor = vec4(in_a.x, in_b.y, in_c.z, 1.0);\n"
3817 "}\n";
3818
3819
3820
3821 ASSERT_NO_FATAL_FAILURE(InitState());
3822 ASSERT_NO_FATAL_FAILURE(InitViewport());
3823
3824 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3825 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3826 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3827
3828 VkPipelineObj pipelineobj(m_device);
3829 pipelineobj.AddShader(&vs);
3830 pipelineobj.AddShader(&gs);
3831 pipelineobj.AddShader(&ps);
3832
3833 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3834 VkCommandBufferObj cmdBuffer(m_device);
3835 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3836
3837 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3838
3839 VkDescriptorSetObj descriptorSet(m_device);
3840
3841 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3842
3843 // render triangle
3844 cmdBuffer.Draw(0, 3, 0, 1);
3845
3846 // finalize recording of the command buffer
3847 EndCommandBuffer(cmdBuffer);
3848 cmdBuffer.QueueCommandBuffer();
3849
3850 RecordImages(m_renderTargets);
3851}
3852
3853TEST_F(VkRenderTest, GSTriStrip)
3854{
3855 // This test emits multiple multiple triangles using a GS
3856 // Correct result is an multicolor circle
3857
3858 static const char *vertShaderText =
3859 "#version 140\n"
3860 "#extension GL_ARB_separate_shader_objects : enable\n"
3861 "#extension GL_ARB_shading_language_420pack : enable\n"
3862
3863 "void main() {\n"
3864
3865 // generic position stuff
3866 " vec2 vertices;\n"
3867 " int vertexSelector = gl_VertexID;\n"
3868 " if (vertexSelector == 0)\n"
3869 " vertices = vec2(-0.5, -0.5);\n"
3870 " else if (vertexSelector == 1)\n"
3871 " vertices = vec2( 0.5, -0.5);\n"
3872 " else if (vertexSelector == 2)\n"
3873 " vertices = vec2( 0.5, 0.5);\n"
3874 " else\n"
3875 " vertices = vec2( 0.0, 0.0);\n"
3876 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3877
3878 "}\n";
3879
3880 static const char *geomShaderText =
3881 "#version 330\n"
3882 "#extension GL_ARB_separate_shader_objects : enable\n"
3883 "#extension GL_ARB_shading_language_420pack : enable\n"
3884 "layout( triangles ) in;\n"
3885 "layout( triangle_strip, max_vertices = 18 ) out;\n"
3886
3887 "layout(location = 0) out vec4 outColor;\n"
3888
3889 "void main()\n"
3890 "{\n"
3891 // init with first position to get zw
3892 " gl_Position = gl_in[0].gl_Position;\n"
3893
3894 " vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3895 " vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
3896 " vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
3897 " vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
3898
3899 // different color per tri
3900 " vec4[6] colors = { red, white, \n"
3901 " yellow, white, \n"
3902 " blue, white }; \n"
3903
3904 // fan out the triangles
3905 " vec2[18] positions = { vec2(0.0, 0.0), vec2(-0.5, 0.0), vec2(-0.25, -0.5), \n"
3906 " vec2(0.0, 0.0), vec2(-0.25, -0.5), vec2( 0.25, -0.5), \n"
3907 " vec2(0.0, 0.0), vec2( 0.25, -0.5), vec2( 0.5, 0.0), \n"
3908 " vec2(0.0, 0.0), vec2( 0.5, 0.0), vec2( 0.25, 0.5), \n"
3909 " vec2(0.0, 0.0), vec2( 0.25, 0.5), vec2(-0.25, 0.5), \n"
3910 " vec2(0.0, 0.0), vec2(-0.25, 0.5), vec2(-0.5, 0.0) }; \n"
3911
3912 // make a triangle list of 6
3913 " for (int i = 0; i < 6; ++i) { \n"
3914 " outColor = colors[i]; \n"
3915 " for (int j = 0; j < 3; ++j) { \n"
3916 " gl_Position.xy = positions[i * 3 + j]; \n"
3917 " EmitVertex(); \n"
3918 " } \n"
3919 " EndPrimitive();\n"
3920 " } \n"
3921
3922 "}\n";
3923
3924
3925 static const char *fragShaderText =
3926 "#version 150\n"
3927 "#extension GL_ARB_separate_shader_objects : enable\n"
3928 "#extension GL_ARB_shading_language_420pack : enable\n"
3929
3930
3931 "layout(binding = 0) uniform windowDimensions {\n"
3932 " vec4 dimensions;\n"
3933 "};\n"
3934
3935 "layout(location = 0) in vec4 inColor;\n"
3936 "layout(origin_upper_left) in vec4 gl_FragCoord;\n"
3937
3938 "void main() {\n"
3939
3940 // discard to make a nice circle
3941 " vec2 pos = abs(gl_FragCoord.xy) - vec2(dimensions.x, dimensions.y) / 2;\n"
3942 " float dist = sqrt(dot(pos, pos));\n"
3943 " if (dist > 50.0)\n"
3944 " discard;\n"
3945
3946 " gl_FragColor = inColor;\n"
3947
3948 "}\n";
3949
3950
3951
3952 ASSERT_NO_FATAL_FAILURE(InitState());
3953 ASSERT_NO_FATAL_FAILURE(InitViewport());
3954
3955 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3956 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3957 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3958
3959 VkPipelineObj pipelineobj(m_device);
3960 pipelineobj.AddShader(&vs);
3961 pipelineobj.AddShader(&gs);
3962 pipelineobj.AddShader(&ps);
3963
3964 const float dimensions[4] = { VkRenderFramework::m_width, VkRenderFramework::m_height , 0.0, 0.0};
3965
3966 VkConstantBufferObj windowDimensions(m_device, sizeof(dimensions) / sizeof(dimensions[0]), sizeof(dimensions[0]), (const void*) dimensions);
3967
3968 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3969 VkCommandBufferObj cmdBuffer(m_device);
3970 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3971
3972 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3973
3974 VkDescriptorSetObj descriptorSet(m_device);
3975 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, windowDimensions);
3976
3977 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3978
3979 // render triangle
3980 cmdBuffer.Draw(0, 3, 0, 1);
3981
3982 // finalize recording of the command buffer
3983 EndCommandBuffer(cmdBuffer);
3984 cmdBuffer.QueueCommandBuffer();
3985
3986 RecordImages(m_renderTargets);
3987}
3988
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003989int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003990 int result;
3991
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003992 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06003993 VkTestFramework::InitArgs(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003994
Chia-I Wu7133fdc2014-12-15 23:57:34 +08003995 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06003996
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003997 result = RUN_ALL_TESTS();
3998
Tony Barbour01999182015-04-09 12:58:51 -06003999 VkTestFramework::Finish();
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004000 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004001}