blob: a9669fbd79f9ba9bfb3401c20258f9f700db072f [file] [log] [blame]
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06001// Copyright 2005, Google Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14// * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060031// VK tests
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060032//
33// Copyright (C) 2014 LunarG, Inc.
34//
35// Permission is hereby granted, free of charge, to any person obtaining a
36// copy of this software and associated documentation files (the "Software"),
37// to deal in the Software without restriction, including without limitation
38// the rights to use, copy, modify, merge, publish, distribute, sublicense,
39// and/or sell copies of the Software, and to permit persons to whom the
40// Software is furnished to do so, subject to the following conditions:
41//
42// The above copyright notice and this permission notice shall be included
43// in all copies or substantial portions of the Software.
44//
45// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
48// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
49// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
50// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
51// DEALINGS IN THE SOFTWARE.
52
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060053// Basic rendering tests
54
55#include <stdlib.h>
56#include <stdio.h>
57#include <stdbool.h>
58#include <string.h>
Courtney Goeltzenleuchter76a643b2014-08-21 17:34:22 -060059#include <iostream>
60#include <fstream>
61using namespace std;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060062
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060063#include <vulkan.h>
Tobin Ehlis31446e52014-11-28 11:17:19 -070064#ifdef DUMP_STATE_DOT
65#include "../layers/draw_state.h"
66#endif
Tobin Ehlis3c26a542014-11-18 11:28:33 -070067#ifdef PRINT_OBJECTS
68#include "../layers/object_track.h"
69#endif
Tobin Ehlis791a49c2014-11-10 12:29:12 -070070#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060071#include <vkDbg.h>
Tobin Ehlis791a49c2014-11-10 12:29:12 -070072#endif
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060073#include "gtest-1.7.0/include/gtest/gtest.h"
74
Cody Northropd4e020a2015-03-17 14:54:35 -060075#include "icd-spv.h"
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060076
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -060077#define GLM_FORCE_RADIANS
78#include "glm/glm.hpp"
79#include <glm/gtc/matrix_transform.hpp>
80
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060081#include "vkrenderframework.h"
Tobin Ehlis791a49c2014-11-10 12:29:12 -070082#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060083void VKAPI myDbgFunc(
84 VK_DBG_MSG_TYPE msgType,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060085 VkValidationLevel validationLevel,
Mike Stroyan230e6252015-04-17 12:36:38 -060086 VkObject srcObject,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060087 size_t location,
88 int32_t msgCode,
89 const char* pMsg,
90 void* pUserData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -070091{
Tobin Ehlis3c26a542014-11-18 11:28:33 -070092 switch (msgType)
93 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060094 case VK_DBG_MSG_WARNING:
Tobin Ehlis3c26a542014-11-18 11:28:33 -070095 printf("CALLBACK WARNING : %s\n", pMsg);
96 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060097 case VK_DBG_MSG_ERROR:
Tobin Ehlis3c26a542014-11-18 11:28:33 -070098 printf("CALLBACK ERROR : %s\n", pMsg);
99 break;
100 default:
101 printf("EATING Msg of type %u\n", msgType);
102 break;
103 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700104}
105#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700106
107
108#undef ASSERT_NO_FATAL_FAILURE
109#define ASSERT_NO_FATAL_FAILURE(x) x
110
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600111//--------------------------------------------------------------------------------------
112// Mesh and VertexFormat Data
113//--------------------------------------------------------------------------------------
114struct Vertex
115{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600116 float posX, posY, posZ, posW; // Position data
117 float r, g, b, a; // Color
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600118};
119
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600120struct VertexUV
121{
122 float posX, posY, posZ, posW; // Position data
123 float u, v; // texture u,v
124};
125
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600126#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600127#define UV(_u_, _v_) (_u_), (_v_)
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600128
129static const Vertex g_vbData[] =
130{
131 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
132 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
133 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
134 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
135 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
136 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
137
138 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
139 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
140 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
141 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
142 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
143 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
144
145 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
146 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
147 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
148 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
149 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
150 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
151
152 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
153 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
154 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
155 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
156 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
157 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
158
159 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
160 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
161 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
162 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
163 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
164 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
165
166 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
167 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
168 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
169 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
170 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
171 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
172};
173
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600174static const Vertex g_vb_solid_face_colors_Data[] =
175{
176 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600177 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600178 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
179 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600180 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
181 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600182
183 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
184 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600185 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
186 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600187 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600188 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600189
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600190 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
191 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
192 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
193 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
194 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
195 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600196
197 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
198 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
199 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
200 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
201 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
202 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
203
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600204 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600205 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600206 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
207 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600208 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
209 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
210
211 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
212 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
213 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
214 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
215 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
216 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
217};
218
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600219static const VertexUV g_vb_texture_Data[] =
220{
221 { XYZ1( -1, -1, -1 ), UV( 0.f, 0.f ) },
222 { XYZ1( -1, 1, 1 ), UV( 1.f, 1.f ) },
223 { XYZ1( -1, -1, 1 ), UV( 1.f, 0.f ) },
224 { XYZ1( -1, 1, 1 ), UV( 1.f, 1.f ) },
225 { XYZ1( -1, -1, -1 ), UV( 0.f, 0.f ) },
226 { XYZ1( -1, 1, -1 ), UV( 0.f, 1.f ) },
227
228 { XYZ1( -1, -1, -1 ), UV( 1.f, 0.f ) },
229 { XYZ1( 1, -1, -1 ), UV( 0.f, 0.f ) },
230 { XYZ1( 1, 1, -1 ), UV( 0.f, 1.f ) },
231 { XYZ1( -1, -1, -1 ), UV( 1.f, 0.f ) },
232 { XYZ1( 1, 1, -1 ), UV( 0.f, 1.f ) },
233 { XYZ1( -1, 1, -1 ), UV( 1.f, 1.f ) },
234
235 { XYZ1( -1, -1, -1 ), UV( 1.f, 1.f ) },
236 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
237 { XYZ1( 1, -1, -1 ), UV( 1.f, 0.f ) },
238 { XYZ1( -1, -1, -1 ), UV( 1.f, 1.f ) },
239 { XYZ1( -1, -1, 1 ), UV( 0.f, 1.f ) },
240 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
241
242 { XYZ1( -1, 1, -1 ), UV( 1.f, 1.f ) },
243 { XYZ1( 1, 1, 1 ), UV( 0.f, 0.f ) },
244 { XYZ1( -1, 1, 1 ), UV( 0.f, 1.f ) },
245 { XYZ1( -1, 1, -1 ), UV( 1.f, 1.f ) },
246 { XYZ1( 1, 1, -1 ), UV( 1.f, 0.f ) },
247 { XYZ1( 1, 1, 1 ), UV( 0.f, 0.f ) },
248
249 { XYZ1( 1, 1, -1 ), UV( 1.f, 1.f ) },
250 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
251 { XYZ1( 1, 1, 1 ), UV( 0.f, 1.f ) },
252 { XYZ1( 1, -1, 1 ), UV( 0.f, 0.f ) },
253 { XYZ1( 1, 1, -1 ), UV( 1.f, 1.f ) },
254 { XYZ1( 1, -1, -1 ), UV( 1.f, 0.f ) },
255
256 { XYZ1( -1, 1, 1 ), UV( 0.f, 1.f ) },
257 { XYZ1( 1, 1, 1 ), UV( 1.f, 1.f ) },
258 { XYZ1( -1, -1, 1 ), UV( 0.f, 0.f ) },
259 { XYZ1( -1, -1, 1 ), UV( 0.f, 0.f ) },
260 { XYZ1( 1, 1, 1 ), UV( 1.f, 1.f ) },
261 { XYZ1( 1, -1, 1 ), UV( 1.f, 0.f ) },
262};
263
Tony Barbour01999182015-04-09 12:58:51 -0600264class VkRenderTest : public VkRenderFramework
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -0600265{
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600266public:
Cody Northrop4e6b4762014-10-09 21:25:22 -0600267
Tony Barbourf43b6982014-11-25 13:18:32 -0700268 void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbour01999182015-04-09 12:58:51 -0600269 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer);
270 void GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600271 void InitDepthStencil();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600272 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate);
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600273
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600274 VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer);
275 VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer);
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600276
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600277protected:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600278 VkImage m_texture;
279 VkImageView m_textureView;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800280 VkDescriptorInfo m_descriptorInfo;
Tony Barbour8205d902015-04-16 15:59:00 -0600281 VkDeviceMemory m_textureMem;
Cody Northrop350727b2014-10-06 15:42:00 -0600282
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600283 VkSampler m_sampler;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600284
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600285
286 virtual void SetUp() {
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600287
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600288 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600289 this->app_info.pNext = NULL;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800290 this->app_info.pAppName = "render_tests";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600291 this->app_info.appVersion = 1;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800292 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600293 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600294 this->app_info.apiVersion = VK_API_VERSION;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600295
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800296 memset(&m_descriptorInfo, 0, sizeof(m_descriptorInfo));
Cody Northrop350727b2014-10-06 15:42:00 -0600297
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600298 InitFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600299 }
300
301 virtual void TearDown() {
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600302 // Clean up resources before we reset
303 ShutdownFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600304 }
305};
306
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600307VkResult VkRenderTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600308{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600309 VkResult result;
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600310
311 result = cmdBuffer.BeginCommandBuffer();
312
313 /*
314 * For render test all drawing happens in a single render pass
315 * on a single command buffer.
316 */
Chris Forbesfe133ef2015-06-16 14:05:59 +1200317 if (VK_SUCCESS == result && renderPass()) {
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600318 cmdBuffer.BeginRenderPass(renderPass(), framebuffer());
319 }
320
321 return result;
322}
323
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600324VkResult VkRenderTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600325{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600326 VkResult result;
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600327
Chris Forbesfe133ef2015-06-16 14:05:59 +1200328 if (renderPass()) {
329 cmdBuffer.EndRenderPass(renderPass());
330 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600331
332 result = cmdBuffer.EndCommandBuffer();
333
334 return result;
335}
336
337
Tony Barbour01999182015-04-09 12:58:51 -0600338void VkRenderTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet)
Tony Barbour02472db2015-01-08 17:08:28 -0700339{
Tony Barbour17c6ab12015-03-27 17:03:18 -0600340 if (m_depthStencil->Initialized()) {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600341 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Tony Barbour17c6ab12015-03-27 17:03:18 -0600342 } else {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600343 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour17c6ab12015-03-27 17:03:18 -0600344 }
345
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700346 cmdBuffer->PrepareAttachments();
Tony Barbour8205d902015-04-16 15:59:00 -0600347 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_RASTER, m_stateRaster);
348 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_VIEWPORT, m_stateViewport);
349 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_COLOR_BLEND, m_colorBlend);
350 cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_DEPTH_STENCIL, m_stateDepthStencil);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600351 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
352 pipelineobj.CreateVKPipeline(descriptorSet);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600353 cmdBuffer->BindPipeline(pipelineobj);
Chia-I Wu862c5572015-03-28 15:23:55 +0800354 cmdBuffer->BindDescriptorSet(descriptorSet);
Tony Barbour02472db2015-01-08 17:08:28 -0700355}
Tony Barbourf43b6982014-11-25 13:18:32 -0700356
Tony Barbour01999182015-04-09 12:58:51 -0600357void VkRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
358 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer)
Tony Barbourdd4c9642015-01-09 12:55:14 -0700359{
360 int i;
361 glm::mat4 MVP;
362 int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600363 VkResult err;
Tony Barbourdd4c9642015-01-09 12:55:14 -0700364
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600365 /* Only do 3 positions to avoid back face cull */
366 for (i = 0; i < 3; i++) {
Tony Barbourdd4c9642015-01-09 12:55:14 -0700367 void *pData = constantBuffer->map();
368
369 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
370 MVP = Projection * View * Model;
371 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
372
373 constantBuffer->unmap();
374
375 // submit the command buffer to the universal queue
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600376 cmdBuffer->QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700377
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600378 err = vkQueueWaitIdle( m_device->m_queue );
379 ASSERT_VK_SUCCESS( err );
Tony Barbourdd4c9642015-01-09 12:55:14 -0700380
381 // Wait for work to finish before cleaning up.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600382 vkDeviceWaitIdle(m_device->device());
Tony Barbourdd4c9642015-01-09 12:55:14 -0700383
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700384 assert(m_renderTargets.size() == 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -0700385 RecordImage(m_renderTargets[0]);
386 }
387}
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600388
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600389void dumpMatrix(const char *note, glm::mat4 MVP)
390{
Chia-I Wu7133fdc2014-12-15 23:57:34 +0800391 int i;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600392
393 printf("%s: \n", note);
394 for (i=0; i<4; i++) {
395 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
396 }
397 printf("\n");
398 fflush(stdout);
399}
400
401void dumpVec4(const char *note, glm::vec4 vector)
402{
403 printf("%s: \n", note);
404 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
405 printf("\n");
406 fflush(stdout);
407}
408
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600409struct vktriangle_vs_uniform {
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600410 // Must start with MVP
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600411 float mvp[4][4];
412 float position[3][4];
413 float color[3][4];
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600414};
415
Tony Barbour01999182015-04-09 12:58:51 -0600416void VkRenderTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600417{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700418#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600419 vkDbgRegisterMsgCallback(inst, myDbgFunc, NULL);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700420#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600421 // Create identity matrix
422 int i;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600423 struct vktriangle_vs_uniform data;
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600424
425 glm::mat4 Projection = glm::mat4(1.0f);
426 glm::mat4 View = glm::mat4(1.0f);
427 glm::mat4 Model = glm::mat4(1.0f);
428 glm::mat4 MVP = Projection * View * Model;
429 const int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600430 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600431 memcpy(&data.mvp, &MVP[0][0], matrixSize);
432
433 static const Vertex tri_data[] =
434 {
435 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
436 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
437 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
438 };
439
440 for (i=0; i<3; i++) {
441 data.position[i][0] = tri_data[i].posX;
442 data.position[i][1] = tri_data[i].posY;
443 data.position[i][2] = tri_data[i].posZ;
444 data.position[i][3] = tri_data[i].posW;
445 data.color[i][0] = tri_data[i].r;
446 data.color[i][1] = tri_data[i].g;
447 data.color[i][2] = tri_data[i].b;
448 data.color[i][3] = tri_data[i].a;
449 }
450
Tony Barbourf43b6982014-11-25 13:18:32 -0700451 ASSERT_NO_FATAL_FAILURE(InitState());
452 ASSERT_NO_FATAL_FAILURE(InitViewport());
453
Tony Barbour01999182015-04-09 12:58:51 -0600454 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barbourf43b6982014-11-25 13:18:32 -0700455
Tony Barbour01999182015-04-09 12:58:51 -0600456 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
457 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700458
Tony Barbour01999182015-04-09 12:58:51 -0600459 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -0700460 pipelineobj.AddShader(&vs);
461 pipelineobj.AddShader(&ps);
462
Tony Barbour01999182015-04-09 12:58:51 -0600463 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600464 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700465
Tony Barbour71ba3612015-01-09 16:12:35 -0700466 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600467 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour71ba3612015-01-09 16:12:35 -0700468 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700469
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600470 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour71ba3612015-01-09 16:12:35 -0700471
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600472 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour71ba3612015-01-09 16:12:35 -0700473#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600474 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour71ba3612015-01-09 16:12:35 -0700475 pDSDumpDot((char*)"triTest2.dot");
476#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600477
Tony Barbour71ba3612015-01-09 16:12:35 -0700478 // render triangle
479 cmdBuffer.Draw(0, 3, 0, 1);
480
481 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600482 EndCommandBuffer(cmdBuffer);
483
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600484 cmdBuffer.QueueCommandBuffer();
Tony Barbour71ba3612015-01-09 16:12:35 -0700485
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600486 RecordImages(m_renderTargets);
Tony Barbour71ba3612015-01-09 16:12:35 -0700487
488 if (rotate)
Tobin Ehlis12ee35f2015-03-26 08:23:25 -0600489 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
Tony Barbour71ba3612015-01-09 16:12:35 -0700490
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700491#ifdef PRINT_OBJECTS
Mark Lobodzinski4e5016f2015-05-05 15:01:37 -0500492 //uint64_t objTrackGetObjectCount(VkObjectType type)
493 OBJ_TRACK_GET_OBJECTS_COUNT pObjTrackGetObjectsCount = (OBJ_TRACK_GET_OBJECTS_COUNT)vkGetProcAddr(gpu(), (char*)"objTrackGetObjectsCount");
494 uint64_t numObjects = pObjTrackGetObjectsCount();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600495 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700496 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600497 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700498 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
Mark Lobodzinski4e5016f2015-05-05 15:01:37 -0500499 pObjTrackGetObjs(numObjects, pObjNodeArray);
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700500 for (i=0; i < numObjects; i++) {
Mark Lobodzinski4e5016f2015-05-05 15:01:37 -0500501 printf("Object %i of type %s has objID (%p) and %lu uses\n", i, string_from_vulkan_object_type(pObjNodeArray[i].objType), pObjNodeArray[i].vkObj, pObjNodeArray[i].numUses);
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700502 }
503 free(pObjNodeArray);
504#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700505
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600506}
507
GregFd6ebdb32015-06-03 18:40:50 -0600508#if 0
509
Tony Barbour01999182015-04-09 12:58:51 -0600510TEST_F(VkRenderTest, VKTriangle_FragColor)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600511{
512 static const char *vertShaderText =
513 "#version 140\n"
514 "#extension GL_ARB_separate_shader_objects : enable\n"
515 "#extension GL_ARB_shading_language_420pack : enable\n"
516 "\n"
517 "layout(binding = 0) uniform buf {\n"
518 " mat4 MVP;\n"
519 " vec4 position[3];\n"
520 " vec4 color[3];\n"
521 "} ubuf;\n"
522 "\n"
523 "layout (location = 0) out vec4 outColor;\n"
524 "\n"
525 "void main() \n"
526 "{\n"
527 " outColor = ubuf.color[gl_VertexID];\n"
528 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
529 "}\n";
530
531 static const char *fragShaderText =
532 "#version 140\n"
533 "#extension GL_ARB_separate_shader_objects : enable\n"
534 "#extension GL_ARB_shading_language_420pack : enable\n"
535 "\n"
536 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600537 "layout (location = 0) out vec4 uFragColor;\n"
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600538 "\n"
539 "void main()\n"
540 "{\n"
GregFd6ebdb32015-06-03 18:40:50 -0600541 " uFragColor = inColor;\n"
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600542 "}\n";
543
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600544 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
545 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600546}
547
Tony Barbour01999182015-04-09 12:58:51 -0600548TEST_F(VkRenderTest, VKTriangle_OutputLocation)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600549{
550 static const char *vertShaderText =
551 "#version 140\n"
552 "#extension GL_ARB_separate_shader_objects : enable\n"
553 "#extension GL_ARB_shading_language_420pack : enable\n"
554 "\n"
555 "layout(binding = 0) uniform buf {\n"
556 " mat4 MVP;\n"
557 " vec4 position[3];\n"
558 " vec4 color[3];\n"
559 "} ubuf;\n"
560 "\n"
561 "layout (location = 0) out vec4 outColor;\n"
562 "\n"
563 "void main() \n"
564 "{\n"
565 " outColor = ubuf.color[gl_VertexID];\n"
566 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
567 "}\n";
568
569 static const char *fragShaderText =
570 "#version 140\n"
571 "#extension GL_ARB_separate_shader_objects : enable\n"
572 "#extension GL_ARB_shading_language_420pack : enable\n"
573 "\n"
574 "layout (location = 0) in vec4 inColor;\n"
575 "layout (location = 0) out vec4 outColor;\n"
576 "\n"
577 "void main()\n"
578 "{\n"
579 " outColor = inColor;\n"
580 "}\n";
581
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600582 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 -0600583
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600584 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600585}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600586#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 -0600587TEST_F(VkRenderTest, SPV_VKTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700588{
Tony Barbourf43b6982014-11-25 13:18:32 -0700589 static const char *vertShaderText =
590 "#version 140\n"
591 "#extension GL_ARB_separate_shader_objects : enable\n"
592 "#extension GL_ARB_shading_language_420pack : enable\n"
593 "\n"
594 "layout(binding = 0) uniform buf {\n"
595 " mat4 MVP;\n"
596 " vec4 position[3];\n"
597 " vec4 color[3];\n"
598 "} ubuf;\n"
599 "\n"
600 "layout (location = 0) out vec4 outColor;\n"
601 "\n"
602 "void main() \n"
603 "{\n"
604 " outColor = ubuf.color[gl_VertexID];\n"
605 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
606 "}\n";
607
608 static const char *fragShaderText =
609 "#version 140\n"
610 "#extension GL_ARB_separate_shader_objects : enable\n"
611 "#extension GL_ARB_shading_language_420pack : enable\n"
612 "\n"
613 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600614 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700615 "\n"
616 "void main()\n"
617 "{\n"
GregFd6ebdb32015-06-03 18:40:50 -0600618 " outColor = inColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700619 "}\n";
620
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600621 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 -0700622
Cody Northrop1cfbd172015-06-03 16:49:20 -0600623 ScopedUseGlsl useGlsl(false);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600624 VKTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700625}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600626#endif
Tony Barbour01999182015-04-09 12:58:51 -0600627TEST_F(VkRenderTest, GreenTriangle)
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600628{
629 static const char *vertShaderText =
630 "#version 130\n"
631 "vec2 vertices[3];\n"
632 "void main() {\n"
633 " vertices[0] = vec2(-1.0, -1.0);\n"
634 " vertices[1] = vec2( 1.0, -1.0);\n"
635 " vertices[2] = vec2( 0.0, 1.0);\n"
636 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
637 "}\n";
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600638
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600639 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600640 "#version 140\n"
641 "#extension GL_ARB_separate_shader_objects : enable\n"
642 "#extension GL_ARB_shading_language_420pack : enable\n"
643 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600644 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600645 " outColor = vec4(0,1,0,1);\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600646 "}\n";
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600647
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600648 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
649
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600650 VKTriangleTest(vertShaderText, fragShaderText, false);
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600651}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600652#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 -0600653TEST_F(VkRenderTest, SPV_GreenTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700654{
Tony Barbourf43b6982014-11-25 13:18:32 -0700655 static const char *vertShaderText =
656 "#version 130\n"
657 "vec2 vertices[3];\n"
658 "void main() {\n"
659 " vertices[0] = vec2(-1.0, -1.0);\n"
660 " vertices[1] = vec2( 1.0, -1.0);\n"
661 " vertices[2] = vec2( 0.0, 1.0);\n"
662 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
663 "}\n";
664
665 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600666 "#version 140\n"
667 "#extension GL_ARB_separate_shader_objects : enable\n"
668 "#extension GL_ARB_shading_language_420pack : enable\n"
669 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700670 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600671 " outColor = vec4(0,1,0,1);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700672 "}\n";
673
Cody Northropacfb0492015-03-17 15:55:58 -0600674 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700675
Cody Northrop1cfbd172015-06-03 16:49:20 -0600676 ScopedUseGlsl useGlsl(false);
677
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600678 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700679}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600680#endif
Tony Barbour01999182015-04-09 12:58:51 -0600681TEST_F(VkRenderTest, YellowTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700682{
683 static const char *vertShaderText =
684 "#version 130\n"
685 "void main() {\n"
686 " vec2 vertices[3];"
687 " vertices[0] = vec2(-0.5, -0.5);\n"
688 " vertices[1] = vec2( 0.5, -0.5);\n"
689 " vertices[2] = vec2( 0.5, 0.5);\n"
690 " vec4 colors[3];\n"
691 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
692 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
693 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
694 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
695 "}\n";
696
697 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600698 "#version 140\n"
699 "#extension GL_ARB_separate_shader_objects : enable\n"
700 "#extension GL_ARB_shading_language_420pack : enable\n"
701 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700702 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600703 " outColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700704 "}\n";
705
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600706 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700707}
708
Tony Barbour01999182015-04-09 12:58:51 -0600709TEST_F(VkRenderTest, QuadWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600710{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600711 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600712 "#version 140\n"
713 "#extension GL_ARB_separate_shader_objects : enable\n"
714 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700715 //XYZ1( -1, -1, -1 )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600716 "layout (location = 0) in vec4 pos;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700717 //XYZ1( 0.f, 0.f, 0.f )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600718 "layout (location = 1) in vec4 inColor;\n"
719 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600720 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600721 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600722 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600723 "}\n";
724
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600725
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600726 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700727 "#version 140\n"
728 "#extension GL_ARB_separate_shader_objects : enable\n"
729 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600730 "layout (location = 0) in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700731 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600732 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700733 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600734 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600735
Tony Barbourf43b6982014-11-25 13:18:32 -0700736
737
738 ASSERT_NO_FATAL_FAILURE(InitState());
739 ASSERT_NO_FATAL_FAILURE(InitViewport());
740
Tony Barbour01999182015-04-09 12:58:51 -0600741 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000742 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700743
Tony Barbour01999182015-04-09 12:58:51 -0600744 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
745 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700746
Tony Barbour01999182015-04-09 12:58:51 -0600747 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -0700748 pipelineobj.AddShader(&vs);
749 pipelineobj.AddShader(&ps);
750
Tony Barbour01999182015-04-09 12:58:51 -0600751 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600752 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -0600753
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600754#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600755 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600756 MESH_BIND_ID, // binding ID
Tony Barbourf43b6982014-11-25 13:18:32 -0700757 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600758 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -0700759 };
760
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600761 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600762 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
763 vi_attribs[0].location = 0; // location, position
Tony Barbour8205d902015-04-16 15:59:00 -0600764 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600765 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
766 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
767 vi_attribs[1].location = 1; // location, color
Tony Barbour8205d902015-04-16 15:59:00 -0600768 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600769 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 -0700770
771 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
772 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600773 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -0700774
Tony Barboure4ed9942015-01-09 10:06:53 -0700775 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600776 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700777 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700778
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600779 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600780
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600781 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700782
Tony Barboure4ed9942015-01-09 10:06:53 -0700783 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
784
785 // render two triangles
786 cmdBuffer.Draw(0, 6, 0, 1);
787
788 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600789 EndCommandBuffer(cmdBuffer);
790
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600791 cmdBuffer.QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -0700792
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600793 RecordImages(m_renderTargets);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600794}
795
Tony Barbour01999182015-04-09 12:58:51 -0600796TEST_F(VkRenderTest, TriangleMRT)
Chia-I Wue09d1a72014-12-05 10:32:23 +0800797{
798 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600799 "#version 140\n"
800 "#extension GL_ARB_separate_shader_objects : enable\n"
801 "#extension GL_ARB_shading_language_420pack : enable\n"
802 "layout (location = 0) in vec4 pos;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800803 "void main() {\n"
804 " gl_Position = pos;\n"
805 "}\n";
806
807 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600808 "#version 140\n"
809 "#extension GL_ARB_separate_shader_objects : enable\n"
810 "#extension GL_ARB_shading_language_420pack : enable\n"
811 "layout (location = 0) out vec4 uFragData0;\n"
812 "layout (location = 1) out vec4 uFragData1;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800813 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600814 " uFragData0 = vec4(1.0, 0.0, 0.0, 1.0);\n"
815 " uFragData1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800816 "}\n";
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600817 const float vb_data[][2] = {
Chia-I Wue09d1a72014-12-05 10:32:23 +0800818 { -1.0f, -1.0f },
819 { 1.0f, -1.0f },
820 { -1.0f, 1.0f }
821 };
822
823 ASSERT_NO_FATAL_FAILURE(InitState());
824 ASSERT_NO_FATAL_FAILURE(InitViewport());
825
Tony Barbour01999182015-04-09 12:58:51 -0600826 VkConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000827 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800828
Tony Barbour01999182015-04-09 12:58:51 -0600829 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
830 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800831
Tony Barbour01999182015-04-09 12:58:51 -0600832 VkPipelineObj pipelineobj(m_device);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800833 pipelineobj.AddShader(&vs);
834 pipelineobj.AddShader(&ps);
835
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600836#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600837 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600838 MESH_BUF_ID, // Binding ID
839 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600840 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Chia-I Wue09d1a72014-12-05 10:32:23 +0800841 };
842
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600843 VkVertexInputAttributeDescription vi_attrib;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600844 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
845 vi_attrib.location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -0600846 vi_attrib.format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600847 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
Chia-I Wue09d1a72014-12-05 10:32:23 +0800848
849 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
850 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600851 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800852
Tony Barbour01999182015-04-09 12:58:51 -0600853 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600854 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800855
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700856 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
Chia-I Wue09d1a72014-12-05 10:32:23 +0800857
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600858 VkPipelineCbAttachmentState att = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600859 att.blendEnable = VK_FALSE;
Chia-I Wue09d1a72014-12-05 10:32:23 +0800860 att.format = m_render_target_fmt;
861 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700862 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800863
Tony Barbour01999182015-04-09 12:58:51 -0600864 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700865
Tony Barbour5ed79702015-01-07 14:31:52 -0700866 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
867 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barboure4ed9942015-01-09 10:06:53 -0700868
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600869 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour5ed79702015-01-07 14:31:52 -0700870
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600871 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700872
Tony Barbour5ed79702015-01-07 14:31:52 -0700873 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700874#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600875 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour5ed79702015-01-07 14:31:52 -0700876 pDSDumpDot((char*)"triTest2.dot");
877#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600878
Tony Barbour5ed79702015-01-07 14:31:52 -0700879 // render triangle
880 cmdBuffer.Draw(0, 3, 0, 1);
881
882 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600883 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600884 cmdBuffer.QueueCommandBuffer();
Tony Barbour5ed79702015-01-07 14:31:52 -0700885
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600886 RecordImages(m_renderTargets);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800887}
888
Tony Barbour01999182015-04-09 12:58:51 -0600889TEST_F(VkRenderTest, QuadWithIndexedVertexFetch)
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700890{
891 static const char *vertShaderText =
892 "#version 140\n"
893 "#extension GL_ARB_separate_shader_objects : enable\n"
894 "#extension GL_ARB_shading_language_420pack : enable\n"
895 "layout(location = 0) in vec4 pos;\n"
896 "layout(location = 1) in vec4 inColor;\n"
897 "layout(location = 0) out vec4 outColor;\n"
898 "void main() {\n"
899 " outColor = inColor;\n"
900 " gl_Position = pos;\n"
901 "}\n";
902
903
904 static const char *fragShaderText =
905 "#version 140\n"
906 "#extension GL_ARB_separate_shader_objects : enable\n"
907 "#extension GL_ARB_shading_language_420pack : enable\n"
908 "layout(location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600909 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700910 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600911 " outColor = color;\n"
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700912 "}\n";
913
914 const Vertex g_vbData[] =
915 {
916 // first tri
917 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
918 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
919 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
920
921 // second tri
922 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
923 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
924 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
925 };
926
927 const uint16_t g_idxData[6] = {
928 0, 1, 2,
929 3, 4, 5,
930 };
931
932 ASSERT_NO_FATAL_FAILURE(InitState());
933 ASSERT_NO_FATAL_FAILURE(InitViewport());
934
Tony Barbour01999182015-04-09 12:58:51 -0600935 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000936 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700937
Tony Barbour01999182015-04-09 12:58:51 -0600938 VkIndexBufferObj indexBuffer(m_device);
Tony Barbour8205d902015-04-16 15:59:00 -0600939 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), VK_INDEX_TYPE_UINT16, g_idxData);
Mark Lobodzinskid30f82a2015-02-16 14:24:23 -0600940 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700941
Tony Barbour01999182015-04-09 12:58:51 -0600942 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
943 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700944
Tony Barbour01999182015-04-09 12:58:51 -0600945 VkPipelineObj pipelineobj(m_device);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700946 pipelineobj.AddShader(&vs);
947 pipelineobj.AddShader(&ps);
948
Tony Barbour01999182015-04-09 12:58:51 -0600949 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600950 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
951 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, indexBuffer);
Tony Barbour83a83802015-04-02 15:43:15 -0600952
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700953
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600954#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600955 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600956 MESH_BIND_ID, // binding ID
957 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600958 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700959 };
960
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600961 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600962 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
963 vi_attribs[0].location = 0; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600964 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600965 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
966 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
967 vi_attribs[1].location = 1; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600968 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600969 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700970
971 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
972 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700973
974 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600975 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700976 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600977 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barboure4ed9942015-01-09 10:06:53 -0700978
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600979 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700980
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700981#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600982 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700983 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700984#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700985
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600986 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600987 cmdBuffer.BindIndexBuffer(&indexBuffer, 0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700988
989 // render two triangles
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700990 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700991
992 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600993 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600994 cmdBuffer.QueueCommandBuffer();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700995
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600996 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700997}
998
Tony Barbour01999182015-04-09 12:58:51 -0600999TEST_F(VkRenderTest, GreyandRedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -07001000{
1001 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -07001002
GregF6bef1212014-12-02 15:41:44 -07001003 static const char *vertShaderText =
1004 "#version 140\n"
1005 "#extension GL_ARB_separate_shader_objects : enable\n"
1006 "#extension GL_ARB_shading_language_420pack : enable\n"
1007 "layout (location = 0) in vec4 pos;\n"
1008 "layout (location = 0) out vec4 outColor;\n"
1009 "layout (location = 1) out vec4 outColor2;\n"
1010 "void main() {\n"
1011 " gl_Position = pos;\n"
1012 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1013 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1014 "}\n";
1015
1016 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001017 "#version 330\n"
1018 "#extension GL_ARB_separate_shader_objects : enable\n"
1019 "#extension GL_ARB_shading_language_420pack : enable\n"
1020 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1021 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1022 "layout (location = 0) in vec4 color;\n"
1023 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001024 "layout (location = 0) out vec4 outColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001025 "void main() {\n"
1026 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1027 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001028 " outColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001029 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1030 " : color2;\n"
1031 "}\n";
1032
1033 ASSERT_NO_FATAL_FAILURE(InitState());
1034 ASSERT_NO_FATAL_FAILURE(InitViewport());
1035
Tony Barbour01999182015-04-09 12:58:51 -06001036 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001037 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001038
Tony Barbour01999182015-04-09 12:58:51 -06001039 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1040 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001041
Tony Barbour01999182015-04-09 12:58:51 -06001042 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001043 pipelineobj.AddShader(&vs);
1044 pipelineobj.AddShader(&ps);
1045
Tony Barbour01999182015-04-09 12:58:51 -06001046 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001047 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001048
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001049#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001050 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001051 MESH_BIND_ID, // binding ID
1052 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001053 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001054 };
1055
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001056 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001057 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1058 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001059 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001060 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001061
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001062 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001063 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001064 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001065
Tony Barbourdd4c9642015-01-09 12:55:14 -07001066 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001067 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001068 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1069
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001070 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001071
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001072 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001073
1074 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1075#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001076 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001077 pDSDumpDot((char*)"triTest2.dot");
1078#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001079
Tony Barbourdd4c9642015-01-09 12:55:14 -07001080 // render triangle
1081 cmdBuffer.Draw(0, 6, 0, 1);
1082
1083 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001084 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001085 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001086
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001087 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001088}
1089
GregFd6ebdb32015-06-03 18:40:50 -06001090//good
1091
1092
1093
Tony Barbour01999182015-04-09 12:58:51 -06001094TEST_F(VkRenderTest, RedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -07001095{
1096 // This tests that we correctly handle unread fragment inputs
1097
1098 static const char *vertShaderText =
1099 "#version 140\n"
1100 "#extension GL_ARB_separate_shader_objects : enable\n"
1101 "#extension GL_ARB_shading_language_420pack : enable\n"
1102 "layout (location = 0) in vec4 pos;\n"
1103 "layout (location = 0) out vec4 outColor;\n"
1104 "layout (location = 1) out vec4 outColor2;\n"
1105 "void main() {\n"
1106 " gl_Position = pos;\n"
1107 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1108 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1109 "}\n";
1110
1111 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001112 "#version 330\n"
1113 "#extension GL_ARB_separate_shader_objects : enable\n"
1114 "#extension GL_ARB_shading_language_420pack : enable\n"
1115 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1116 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1117 "layout (location = 0) in vec4 color;\n"
1118 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001119 "layout (location = 0) out vec4 outColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001120 "void main() {\n"
1121 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1122 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001123 " outColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001124 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1125 " : color2;\n"
1126 "}\n";
1127
1128 ASSERT_NO_FATAL_FAILURE(InitState());
1129 ASSERT_NO_FATAL_FAILURE(InitViewport());
1130
Tony Barbour01999182015-04-09 12:58:51 -06001131 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001132 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001133
Tony Barbour01999182015-04-09 12:58:51 -06001134 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1135 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001136
Tony Barbour01999182015-04-09 12:58:51 -06001137 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001138 pipelineobj.AddShader(&vs);
1139 pipelineobj.AddShader(&ps);
1140
Tony Barbour01999182015-04-09 12:58:51 -06001141 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001142 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001143
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001144#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001145 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001146 MESH_BIND_ID, // binding ID
1147 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001148 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001149 };
1150
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001151 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001152 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1153 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001154 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001155 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001156
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001157 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001158 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001159 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001160
Tony Barbourdd4c9642015-01-09 12:55:14 -07001161 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001162 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001163 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1164
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001165 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001166
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001167 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001168
1169 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1170#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001171 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001172 pDSDumpDot((char*)"triTest2.dot");
1173#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001174 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001175 cmdBuffer.Draw(0, 6, 0, 1);
1176
1177 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001178 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001179 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001180
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001181 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001182}
1183
Tony Barbour01999182015-04-09 12:58:51 -06001184TEST_F(VkRenderTest, GreyCirclesonBlueFade)
GregF6bef1212014-12-02 15:41:44 -07001185{
1186 // This tests reading gl_ClipDistance from FS
1187
1188 static const char *vertShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001189 //"#version 140\n"
GregF6bef1212014-12-02 15:41:44 -07001190 "#version 330\n"
1191 "#extension GL_ARB_separate_shader_objects : enable\n"
1192 "#extension GL_ARB_shading_language_420pack : enable\n"
1193 "out gl_PerVertex {\n"
1194 " vec4 gl_Position;\n"
1195 " float gl_ClipDistance[1];\n"
1196 "};\n"
1197 "layout (location = 0) in vec4 pos;\n"
1198 "layout (location = 0) out vec4 outColor;\n"
1199 "layout (location = 1) out vec4 outColor2;\n"
1200 "void main() {\n"
1201 " gl_Position = pos;\n"
1202 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1203 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1204 " float dists[3];\n"
1205 " dists[0] = 0.0;\n"
1206 " dists[1] = 1.0;\n"
1207 " dists[2] = 1.0;\n"
1208 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1209 "}\n";
1210
1211
1212 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001213 "#version 140\n"
1214 //"#version 330\n"
GregF6bef1212014-12-02 15:41:44 -07001215 "#extension GL_ARB_separate_shader_objects : enable\n"
1216 "#extension GL_ARB_shading_language_420pack : enable\n"
1217 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1218 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1219 "layout (location = 0) in vec4 color;\n"
1220 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001221 "layout (location = 0) out vec4 uFragColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001222 "void main() {\n"
1223 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1224 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001225 " uFragColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001226 " ? color * gl_ClipDistance[0]\n"
1227 " : color2;\n"
1228 "}\n";
1229
1230 ASSERT_NO_FATAL_FAILURE(InitState());
1231 ASSERT_NO_FATAL_FAILURE(InitViewport());
1232
Tony Barbour01999182015-04-09 12:58:51 -06001233 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001234 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001235
Tony Barbour01999182015-04-09 12:58:51 -06001236 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1237 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001238
Tony Barbour01999182015-04-09 12:58:51 -06001239 VkPipelineObj pipelineobj(m_device);
GregF6bef1212014-12-02 15:41:44 -07001240 pipelineobj.AddShader(&vs);
1241 pipelineobj.AddShader(&ps);
1242
Tony Barbour01999182015-04-09 12:58:51 -06001243 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001244 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001245
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001246#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001247 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001248 MESH_BIND_ID, // binding ID
1249 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001250 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001251 };
1252
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001253 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001254 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1255 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001256 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001257 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001258
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001259 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001260 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001261 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001262
Tony Barbourdd4c9642015-01-09 12:55:14 -07001263 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001264 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001265 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF6bef1212014-12-02 15:41:44 -07001266
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001267 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001268
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001269 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001270
1271 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1272#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001273 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001274 pDSDumpDot((char*)"triTest2.dot");
1275#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001276
1277 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001278 cmdBuffer.Draw(0, 6, 0, 1);
1279
1280 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001281 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001282 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001283
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001284 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001285}
Tony Barbourf43b6982014-11-25 13:18:32 -07001286
Tony Barbour01999182015-04-09 12:58:51 -06001287TEST_F(VkRenderTest, GreyCirclesonBlueDiscard)
GregF7a23c792014-12-02 17:19:34 -07001288{
1289 static const char *vertShaderText =
1290 "#version 140\n"
1291 "#extension GL_ARB_separate_shader_objects : enable\n"
1292 "#extension GL_ARB_shading_language_420pack : enable\n"
1293 "layout (location = 0) in vec4 pos;\n"
1294 "layout (location = 0) out vec4 outColor;\n"
1295 "layout (location = 1) out vec4 outColor2;\n"
1296 "void main() {\n"
1297 " gl_Position = pos;\n"
1298 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1299 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1300 "}\n";
1301
1302
1303 static const char *fragShaderText =
GregF7a23c792014-12-02 17:19:34 -07001304 "#version 330\n"
1305 "#extension GL_ARB_separate_shader_objects : enable\n"
1306 "#extension GL_ARB_shading_language_420pack : enable\n"
1307 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1308 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1309 "layout (location = 0) in vec4 color;\n"
1310 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001311 "layout (location = 0) out vec4 outColor;\n"
GregF7a23c792014-12-02 17:19:34 -07001312 "void main() {\n"
1313 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1314 " float dist_squared = dot(pos, pos);\n"
1315 " if (dist_squared < 100.0)\n"
1316 " discard;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001317 " outColor = (dist_squared < 400.0)\n"
GregF7a23c792014-12-02 17:19:34 -07001318 " ? color\n"
1319 " : color2;\n"
1320 "}\n";
1321
1322 ASSERT_NO_FATAL_FAILURE(InitState());
1323 ASSERT_NO_FATAL_FAILURE(InitViewport());
1324
Tony Barbour01999182015-04-09 12:58:51 -06001325 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001326 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001327
Tony Barbour01999182015-04-09 12:58:51 -06001328 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1329 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF7a23c792014-12-02 17:19:34 -07001330
Tony Barbour01999182015-04-09 12:58:51 -06001331 VkPipelineObj pipelineobj(m_device);
GregF7a23c792014-12-02 17:19:34 -07001332 pipelineobj.AddShader(&vs);
1333 pipelineobj.AddShader(&ps);
1334
Tony Barbour01999182015-04-09 12:58:51 -06001335 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001336 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001337
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001338#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001339 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001340 MESH_BIND_ID, // binding ID
1341 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001342 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF7a23c792014-12-02 17:19:34 -07001343 };
1344
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001345 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001346 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1347 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001348 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001349 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF7a23c792014-12-02 17:19:34 -07001350
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001351 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF7a23c792014-12-02 17:19:34 -07001352 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001353 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF7a23c792014-12-02 17:19:34 -07001354
Tony Barbourdd4c9642015-01-09 12:55:14 -07001355 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001356 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001357 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1358
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001359 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001360
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001361 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001362
1363 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1364#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001365 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001366 pDSDumpDot((char*)"triTest2.dot");
1367#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001368
1369 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001370 cmdBuffer.Draw(0, 6, 0, 1);
1371
1372 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001373 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001374 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001375
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001376 RecordImages(m_renderTargets);
GregF7a23c792014-12-02 17:19:34 -07001377}
1378
1379
Tony Barbour01999182015-04-09 12:58:51 -06001380TEST_F(VkRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001381{
1382 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001383 "#version 140\n"
1384 "#extension GL_ARB_separate_shader_objects : enable\n"
1385 "#extension GL_ARB_shading_language_420pack : enable\n"
1386 "\n"
1387 "layout(binding = 0) uniform buf {\n"
1388 " mat4 MVP;\n"
1389 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001390 "void main() {\n"
1391 " vec2 vertices[3];"
1392 " vertices[0] = vec2(-0.5, -0.5);\n"
1393 " vertices[1] = vec2( 0.5, -0.5);\n"
1394 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001395 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001396 "}\n";
1397
1398 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001399 "#version 140\n"
1400 "#extension GL_ARB_separate_shader_objects : enable\n"
1401 "#extension GL_ARB_shading_language_420pack : enable\n"
1402 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001403 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001404 " outColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001405 "}\n";
1406
Tony Barbourf43b6982014-11-25 13:18:32 -07001407 ASSERT_NO_FATAL_FAILURE(InitState());
1408 ASSERT_NO_FATAL_FAILURE(InitViewport());
1409
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001410 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001411 glm::mat4 Projection = glm::mat4(1.0f);
1412 glm::mat4 View = glm::mat4(1.0f);
1413 glm::mat4 Model = glm::mat4(1.0f);
1414 glm::mat4 MVP = Projection * View * Model;
1415 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1416
Tony Barbour01999182015-04-09 12:58:51 -06001417 VkConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1418 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1419 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001420
Tony Barbour01999182015-04-09 12:58:51 -06001421 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001422 pipelineobj.AddShader(&vs);
1423 pipelineobj.AddShader(&ps);
1424
1425 // Create descriptor set and attach the constant buffer to it
Tony Barbour01999182015-04-09 12:58:51 -06001426 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001427 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001428
Tony Barbourdd4c9642015-01-09 12:55:14 -07001429 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001430 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001431 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001432
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001433 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001434
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001435 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001436
1437 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1438#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001439 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001440 pDSDumpDot((char*)"triTest2.dot");
1441#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001442
1443 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001444 cmdBuffer.Draw(0, 6, 0, 1);
1445
1446 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001447 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001448 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001449
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001450 RecordImages(m_renderTargets);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001451
1452 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001453}
1454
Tony Barbour01999182015-04-09 12:58:51 -06001455TEST_F(VkRenderTest, MixTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07001456{
1457 // This tests location applied to varyings. Notice that we have switched foo
1458 // and bar in the FS. The triangle should be blended with red, green and blue
1459 // corners.
1460 static const char *vertShaderText =
1461 "#version 140\n"
1462 "#extension GL_ARB_separate_shader_objects : enable\n"
1463 "#extension GL_ARB_shading_language_420pack : enable\n"
1464 "layout (location=0) out vec4 bar;\n"
1465 "layout (location=1) out vec4 foo;\n"
1466 "layout (location=2) out float scale;\n"
1467 "vec2 vertices[3];\n"
1468 "void main() {\n"
1469 " vertices[0] = vec2(-1.0, -1.0);\n"
1470 " vertices[1] = vec2( 1.0, -1.0);\n"
1471 " vertices[2] = vec2( 0.0, 1.0);\n"
1472 "vec4 colors[3];\n"
1473 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1474 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1475 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1476 " foo = colors[gl_VertexID % 3];\n"
1477 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1478 " scale = 1.0;\n"
1479 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1480 "}\n";
1481
1482 static const char *fragShaderText =
1483 "#version 140\n"
1484 "#extension GL_ARB_separate_shader_objects : enable\n"
1485 "#extension GL_ARB_shading_language_420pack : enable\n"
1486 "layout (location = 1) in vec4 bar;\n"
1487 "layout (location = 0) in vec4 foo;\n"
1488 "layout (location = 2) in float scale;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001489 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001490 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001491 " outColor = bar * scale + foo * (1.0-scale);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001492 "}\n";
1493
1494 ASSERT_NO_FATAL_FAILURE(InitState());
1495 ASSERT_NO_FATAL_FAILURE(InitViewport());
1496
Tony Barbour01999182015-04-09 12:58:51 -06001497 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1498 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001499
Tony Barbour01999182015-04-09 12:58:51 -06001500 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001501 pipelineobj.AddShader(&vs);
1502 pipelineobj.AddShader(&ps);
1503
Tony Barbour01999182015-04-09 12:58:51 -06001504 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06001505 descriptorSet.AppendDummy();
Tony Barbourf43b6982014-11-25 13:18:32 -07001506
Tony Barbourdd4c9642015-01-09 12:55:14 -07001507 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001508 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001509 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1510
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001511 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001512
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001513 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001514
1515#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001516 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001517 pDSDumpDot((char*)"triTest2.dot");
1518#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001519
Tony Barbourdd4c9642015-01-09 12:55:14 -07001520 // render triangle
1521 cmdBuffer.Draw(0, 3, 0, 1);
1522
1523 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001524 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001525 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001526
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001527 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001528}
1529
Tony Barbour01999182015-04-09 12:58:51 -06001530TEST_F(VkRenderTest, QuadVertFetchAndVertID)
Tony Barbourf43b6982014-11-25 13:18:32 -07001531{
1532 // This tests that attributes work in the presence of gl_VertexID
1533
1534 static const char *vertShaderText =
1535 "#version 140\n"
1536 "#extension GL_ARB_separate_shader_objects : enable\n"
1537 "#extension GL_ARB_shading_language_420pack : enable\n"
1538 //XYZ1( -1, -1, -1 )
1539 "layout (location = 0) in vec4 pos;\n"
1540 //XYZ1( 0.f, 0.f, 0.f )
1541 "layout (location = 1) in vec4 inColor;\n"
1542 "layout (location = 0) out vec4 outColor;\n"
1543 "void main() {\n"
1544 " outColor = inColor;\n"
1545 " vec4 vertices[3];"
1546 " vertices[gl_VertexID % 3] = pos;\n"
1547 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1548 "}\n";
1549
1550
1551 static const char *fragShaderText =
1552 "#version 140\n"
1553 "#extension GL_ARB_separate_shader_objects : enable\n"
1554 "#extension GL_ARB_shading_language_420pack : enable\n"
1555 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001556 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001557 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001558 " outColor = color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001559 "}\n";
1560
1561 ASSERT_NO_FATAL_FAILURE(InitState());
1562 ASSERT_NO_FATAL_FAILURE(InitViewport());
1563
Tony Barbour01999182015-04-09 12:58:51 -06001564 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001565 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001566
Tony Barbour01999182015-04-09 12:58:51 -06001567 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1568 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001569
Tony Barbour01999182015-04-09 12:58:51 -06001570 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001571 pipelineobj.AddShader(&vs);
1572 pipelineobj.AddShader(&ps);
1573
Tony Barbour01999182015-04-09 12:58:51 -06001574 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001575 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001576
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001577#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001578 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001579 MESH_BUF_ID, // Binding ID
1580 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001581 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001582 };
1583
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001584 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001585 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1586 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001587 vi_attribs[0].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001588 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1589 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1590 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001591 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001592 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001593
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001594 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001595 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001596 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001597
Tony Barbourdd4c9642015-01-09 12:55:14 -07001598 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001599 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001600 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1601
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001602 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001603
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001604 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001605
1606 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1607#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001608 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001609 pDSDumpDot((char*)"triTest2.dot");
1610#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001611
1612 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001613 cmdBuffer.Draw(0, 6, 0, 1);
1614
1615 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001616 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001617 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001618
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001619 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001620}
1621
Tony Barbour01999182015-04-09 12:58:51 -06001622TEST_F(VkRenderTest, QuadSparseVertFetch)
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001623{
1624 // This tests that attributes work in the presence of gl_VertexID
1625
1626 static const char *vertShaderText =
1627 "#version 140\n"
1628 "#extension GL_ARB_separate_shader_objects : enable\n"
1629 "#extension GL_ARB_shading_language_420pack : enable\n"
1630 //XYZ1( -1, -1, -1 )
1631 "layout (location = 1) in vec4 pos;\n"
1632 "layout (location = 4) in vec4 inColor;\n"
1633 //XYZ1( 0.f, 0.f, 0.f )
1634 "layout (location = 0) out vec4 outColor;\n"
1635 "void main() {\n"
1636 " outColor = inColor;\n"
1637 " gl_Position = pos;\n"
1638 "}\n";
1639
1640
1641 static const char *fragShaderText =
1642 "#version 140\n"
1643 "#extension GL_ARB_separate_shader_objects : enable\n"
1644 "#extension GL_ARB_shading_language_420pack : enable\n"
1645 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001646 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001647 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001648 " outColor = color;\n"
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001649 "}\n";
1650
1651 ASSERT_NO_FATAL_FAILURE(InitState());
1652 ASSERT_NO_FATAL_FAILURE(InitViewport());
1653
1654 struct VDATA
1655 {
1656 float t1, t2, t3, t4; // filler data
1657 float posX, posY, posZ, posW; // Position data
1658 float r, g, b, a; // Color
1659 };
1660 const struct VDATA vData[] =
1661 {
1662 { XYZ1(0, 0, 0), XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
1663 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1664 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1665 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1666 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1667 { XYZ1(0, 0, 0), XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
1668 };
1669
Tony Barbour01999182015-04-09 12:58:51 -06001670 VkConstantBufferObj meshBuffer(m_device,sizeof(vData)/sizeof(vData[0]),sizeof(vData[0]), vData);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001671 meshBuffer.BufferMemoryBarrier();
1672
Tony Barbour01999182015-04-09 12:58:51 -06001673 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1674 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001675
Tony Barbour01999182015-04-09 12:58:51 -06001676 VkPipelineObj pipelineobj(m_device);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001677 pipelineobj.AddShader(&vs);
1678 pipelineobj.AddShader(&ps);
1679
Tony Barbour01999182015-04-09 12:58:51 -06001680 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001681 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001682
1683#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001684 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001685 MESH_BUF_ID, // Binding ID
1686 sizeof(vData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001687 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001688 };
1689
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001690 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001691 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1692 vi_attribs[0].location = 4;
Tony Barbour8205d902015-04-16 15:59:00 -06001693 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001694 vi_attribs[0].offsetInBytes = sizeof(float) * 4 * 2; // Offset of first element in bytes from base of vertex
1695 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1696 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001697 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001698 vi_attribs[1].offsetInBytes = sizeof(float) * 4 * 1; // Offset of first element in bytes from base of vertex
1699
1700 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
1701 pipelineobj.AddVertexInputBindings(&vi_binding, 1);
1702 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
1703
1704 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001705 VkCommandBufferObj cmdBuffer(m_device);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001706 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1707
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001708 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001709
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001710 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001711
1712 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BUF_ID);
1713#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001714 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001715 pDSDumpDot((char*)"triTest2.dot");
1716#endif
1717
1718 // render two triangles
1719 cmdBuffer.Draw(0, 6, 0, 1);
1720
1721 // finalize recording of the command buffer
1722 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001723 cmdBuffer.QueueCommandBuffer();
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001724
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001725 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001726}
1727
Tony Barbour01999182015-04-09 12:58:51 -06001728TEST_F(VkRenderTest, TriVertFetchDeadAttr)
Tony Barbourf43b6982014-11-25 13:18:32 -07001729{
1730 // This tests that attributes work in the presence of gl_VertexID
1731 // and a dead attribute in position 0. Draws a triangle with yellow,
1732 // red and green corners, starting at top and going clockwise.
1733
1734 static const char *vertShaderText =
1735 "#version 140\n"
1736 "#extension GL_ARB_separate_shader_objects : enable\n"
1737 "#extension GL_ARB_shading_language_420pack : enable\n"
1738 //XYZ1( -1, -1, -1 )
1739 "layout (location = 0) in vec4 pos;\n"
1740 //XYZ1( 0.f, 0.f, 0.f )
1741 "layout (location = 1) in vec4 inColor;\n"
1742 "layout (location = 0) out vec4 outColor;\n"
1743 "void main() {\n"
1744 " outColor = inColor;\n"
1745 " vec2 vertices[3];"
1746 " vertices[0] = vec2(-1.0, -1.0);\n"
1747 " vertices[1] = vec2( 1.0, -1.0);\n"
1748 " vertices[2] = vec2( 0.0, 1.0);\n"
1749 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1750 "}\n";
1751
1752
1753 static const char *fragShaderText =
1754 "#version 140\n"
1755 "#extension GL_ARB_separate_shader_objects : enable\n"
1756 "#extension GL_ARB_shading_language_420pack : enable\n"
1757 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001758 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001759 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001760 " outColor = color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001761 "}\n";
1762
1763 ASSERT_NO_FATAL_FAILURE(InitState());
1764 ASSERT_NO_FATAL_FAILURE(InitViewport());
1765
Tony Barbour01999182015-04-09 12:58:51 -06001766 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001767 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001768
Tony Barbour01999182015-04-09 12:58:51 -06001769 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1770 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001771
Tony Barbour01999182015-04-09 12:58:51 -06001772 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001773 pipelineobj.AddShader(&vs);
1774 pipelineobj.AddShader(&ps);
1775
Tony Barbour01999182015-04-09 12:58:51 -06001776 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001777 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001778
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001779#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001780 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001781 MESH_BUF_ID, // Binding ID
1782 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001783 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001784 };
1785
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001786 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001787 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1788 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001789 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001790 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1791 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1792 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001793 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001794 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001795
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001796 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001797 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001798 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001799
Tony Barbourdd4c9642015-01-09 12:55:14 -07001800 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001801 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001802 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001803
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001804 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001805
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001806 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001807
1808 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1809#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001810 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001811 pDSDumpDot((char*)"triTest2.dot");
1812#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001813
1814 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001815 cmdBuffer.Draw(0, 6, 0, 1);
1816
1817 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001818 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001819 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001820
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001821 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001822}
1823
GregFd6ebdb32015-06-03 18:40:50 -06001824
1825// good
1826
1827
Tony Barbour01999182015-04-09 12:58:51 -06001828TEST_F(VkRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001829{
1830 static const char *vertShaderText =
1831 "#version 140\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001832 "#extension GL_ARB_separate_shader_objects : enable\n"
1833 "#extension GL_ARB_shading_language_420pack : enable\n"
GregFd6ebdb32015-06-03 18:40:50 -06001834 "layout (std140, binding = 0) uniform bufferVals {\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001835 " mat4 mvp;\n"
1836 "} myBufferVals;\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001837 "layout (location = 0) in vec4 pos;\n"
1838 "layout (location = 1) in vec4 inColor;\n"
Cody Northrop74a2d2c2015-06-16 17:32:04 -06001839 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001840 "void main() {\n"
1841 " outColor = inColor;\n"
1842 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001843 " gl_Position.y = -gl_Position.y;\n"
1844 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001845 "}\n";
1846
1847 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001848 "#version 140\n"
1849 "#extension GL_ARB_separate_shader_objects : enable\n"
1850 "#extension GL_ARB_shading_language_420pack : enable\n"
1851 "layout (location = 0) in vec4 color;\n"
1852 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001853 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001854 " outColor = color;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001855 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001856 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001857
Tony Barbourf43b6982014-11-25 13:18:32 -07001858 glm::mat4 View = glm::lookAt(
1859 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1860 glm::vec3(0,0,0), // and looks at the origin
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001861 glm::vec3(0,-1,0) // Head is up (set to 0,-1,0 to look upside-down)
Tony Barbourf43b6982014-11-25 13:18:32 -07001862 );
1863
1864 glm::mat4 Model = glm::mat4(1.0f);
1865
1866 glm::mat4 MVP = Projection * View * Model;
1867
1868 ASSERT_NO_FATAL_FAILURE(InitState());
1869 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour8bef8ee2015-05-22 09:44:58 -06001870 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07001871
Tony Barbour01999182015-04-09 12:58:51 -06001872 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 -07001873 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1874
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001875 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07001876
Tony Barbour01999182015-04-09 12:58:51 -06001877 VkConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1878 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1879 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001880
Tony Barbour01999182015-04-09 12:58:51 -06001881 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001882 pipelineobj.AddShader(&vs);
1883 pipelineobj.AddShader(&ps);
1884
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001885 VkPipelineDsStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001886 ds_state.depthTestEnable = VK_TRUE;
1887 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06001888 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001889 ds_state.depthBoundsEnable = VK_FALSE;
1890 ds_state.stencilTestEnable = VK_FALSE;
1891 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
1892 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
1893 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06001894 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
1895 ds_state.format = VK_FORMAT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001896 ds_state.front = ds_state.back;
1897 pipelineobj.SetDepthStencil(&ds_state);
1898
Tony Barbour01999182015-04-09 12:58:51 -06001899 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001900 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001901
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001902#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001903 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001904 MESH_BUF_ID, // Binding ID
1905 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001906 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001907 };
Tony Barbourf43b6982014-11-25 13:18:32 -07001908
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001909 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001910 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1911 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001912 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001913 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1914 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1915 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001916 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001917 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001918
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001919 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001920 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001921 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001922
Tony Barbour17c6ab12015-03-27 17:03:18 -06001923 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour17c6ab12015-03-27 17:03:18 -06001924
Tony Barbour01999182015-04-09 12:58:51 -06001925 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -07001926 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001927
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001928 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001929 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001930
Tony Barboure4ed9942015-01-09 10:06:53 -07001931 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1932#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001933 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barboure4ed9942015-01-09 10:06:53 -07001934 pDSDumpDot((char*)"triTest2.dot");
1935#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001936
1937 // render triangles
Tony Barboure4ed9942015-01-09 10:06:53 -07001938 cmdBuffer.Draw(0, 36, 0, 1);
1939
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001940
Tony Barboure4ed9942015-01-09 10:06:53 -07001941 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001942 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001943 cmdBuffer.QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -07001944
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001945 RecordImages(m_renderTargets);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001946}
1947
Tony Barbour01999182015-04-09 12:58:51 -06001948TEST_F(VkRenderTest, VSTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07001949{
1950 // The expected result from this test is a green and red triangle;
1951 // one red vertex on the left, two green vertices on the right.
1952 static const char *vertShaderText =
Cody Northrop74a2d2c2015-06-16 17:32:04 -06001953 "#version 140\n"
1954 "#extension GL_ARB_separate_shader_objects : enable\n"
1955 "#extension GL_ARB_shading_language_420pack : enable\n"
1956 "layout (location = 0) out vec4 texColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001957 "uniform sampler2D surface;\n"
1958 "void main() {\n"
1959 " vec2 vertices[3];"
1960 " vertices[0] = vec2(-0.5, -0.5);\n"
1961 " vertices[1] = vec2( 0.5, -0.5);\n"
1962 " vertices[2] = vec2( 0.5, 0.5);\n"
1963 " vec2 positions[3];"
1964 " positions[0] = vec2( 0.0, 0.0);\n"
1965 " positions[1] = vec2( 0.25, 0.1);\n"
1966 " positions[2] = vec2( 0.1, 0.25);\n"
1967 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1968 " texColor = textureLod(surface, samplePos, 0.0);\n"
1969 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1970 "}\n";
1971
1972 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001973 "#version 140\n"
1974 "#extension GL_ARB_separate_shader_objects : enable\n"
1975 "#extension GL_ARB_shading_language_420pack : enable\n"
1976 "layout (location = 0) in vec4 texColor;\n"
1977 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001978 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001979 " outColor = texColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001980 "}\n";
1981
1982 ASSERT_NO_FATAL_FAILURE(InitState());
1983 ASSERT_NO_FATAL_FAILURE(InitViewport());
1984
Tony Barbour01999182015-04-09 12:58:51 -06001985 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1986 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
1987 VkSamplerObj sampler(m_device);
1988 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001989
Tony Barbour01999182015-04-09 12:58:51 -06001990 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001991 pipelineobj.AddShader(&vs);
1992 pipelineobj.AddShader(&ps);
1993
Tony Barbour01999182015-04-09 12:58:51 -06001994 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001995 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001996
Tony Barbourdd4c9642015-01-09 12:55:14 -07001997 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001998 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001999 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002000
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002001 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002002
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002003 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002004
2005#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002006 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002007 pDSDumpDot((char*)"triTest2.dot");
2008#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002009
Tony Barbourdd4c9642015-01-09 12:55:14 -07002010 // render triangle
2011 cmdBuffer.Draw(0, 3, 0, 1);
2012
2013 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002014 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002015 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002016
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002017 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002018}
GregFd6ebdb32015-06-03 18:40:50 -06002019
2020
2021
Tony Barbour01999182015-04-09 12:58:51 -06002022TEST_F(VkRenderTest, TexturedTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002023{
2024 // The expected result from this test is a red and green checkered triangle
2025 static const char *vertShaderText =
2026 "#version 140\n"
2027 "#extension GL_ARB_separate_shader_objects : enable\n"
2028 "#extension GL_ARB_shading_language_420pack : enable\n"
2029 "layout (location = 0) out vec2 samplePos;\n"
2030 "void main() {\n"
2031 " vec2 vertices[3];"
2032 " vertices[0] = vec2(-0.5, -0.5);\n"
2033 " vertices[1] = vec2( 0.5, -0.5);\n"
2034 " vertices[2] = vec2( 0.5, 0.5);\n"
2035 " vec2 positions[3];"
2036 " positions[0] = vec2( 0.0, 0.0);\n"
2037 " positions[1] = vec2( 1.0, 0.0);\n"
2038 " positions[2] = vec2( 1.0, 1.0);\n"
2039 " samplePos = positions[gl_VertexID % 3];\n"
2040 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2041 "}\n";
2042
2043 static const char *fragShaderText =
2044 "#version 140\n"
2045 "#extension GL_ARB_separate_shader_objects : enable\n"
2046 "#extension GL_ARB_shading_language_420pack : enable\n"
2047 "layout (location = 0) in vec2 samplePos;\n"
2048 "layout (binding = 0) uniform sampler2D surface;\n"
2049 "layout (location=0) out vec4 outColor;\n"
2050 "void main() {\n"
2051 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2052 " outColor = texColor;\n"
2053 "}\n";
2054
2055 ASSERT_NO_FATAL_FAILURE(InitState());
2056 ASSERT_NO_FATAL_FAILURE(InitViewport());
2057
Tony Barbour01999182015-04-09 12:58:51 -06002058 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2059 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2060 VkSamplerObj sampler(m_device);
2061 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002062
Tony Barbour01999182015-04-09 12:58:51 -06002063 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002064 pipelineobj.AddShader(&vs);
2065 pipelineobj.AddShader(&ps);
2066
Tony Barbour01999182015-04-09 12:58:51 -06002067 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002068 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002069
Tony Barbourdd4c9642015-01-09 12:55:14 -07002070 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002071 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002072 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2073
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002074 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002075
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002076 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002077
2078#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002079 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002080 pDSDumpDot((char*)"triTest2.dot");
2081#endif
2082 // render triangle
2083 cmdBuffer.Draw(0, 3, 0, 1);
2084
2085 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002086 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002087 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002088
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002089 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002090}
Tony Barbour01999182015-04-09 12:58:51 -06002091TEST_F(VkRenderTest, TexturedTriangleClip)
Tony Barbourf43b6982014-11-25 13:18:32 -07002092{
2093 // The expected result from this test is a red and green checkered triangle
2094 static const char *vertShaderText =
2095 "#version 330\n"
2096 "#extension GL_ARB_separate_shader_objects : enable\n"
2097 "#extension GL_ARB_shading_language_420pack : enable\n"
2098 "layout (location = 0) out vec2 samplePos;\n"
2099 "out gl_PerVertex {\n"
2100 " vec4 gl_Position;\n"
2101 " float gl_ClipDistance[1];\n"
2102 "};\n"
2103 "void main() {\n"
2104 " vec2 vertices[3];"
2105 " vertices[0] = vec2(-0.5, -0.5);\n"
2106 " vertices[1] = vec2( 0.5, -0.5);\n"
2107 " vertices[2] = vec2( 0.5, 0.5);\n"
2108 " vec2 positions[3];"
2109 " positions[0] = vec2( 0.0, 0.0);\n"
2110 " positions[1] = vec2( 1.0, 0.0);\n"
2111 " positions[2] = vec2( 1.0, 1.0);\n"
2112 " float dists[3];\n"
2113 " dists[0] = 1.0;\n"
2114 " dists[1] = 1.0;\n"
2115 " dists[2] = -1.0;\n"
2116 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2117 " samplePos = positions[gl_VertexID % 3];\n"
2118 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2119 "}\n";
2120
2121 static const char *fragShaderText =
2122 "#version 140\n"
2123 "#extension GL_ARB_separate_shader_objects : enable\n"
2124 "#extension GL_ARB_shading_language_420pack : enable\n"
2125 "layout (location = 0) in vec2 samplePos;\n"
2126 "layout (binding = 0) uniform sampler2D surface;\n"
2127 "layout (location=0) out vec4 outColor;\n"
2128 "void main() {\n"
2129 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2130 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2131 " outColor = texColor;\n"
2132 "}\n";
2133
2134
2135 ASSERT_NO_FATAL_FAILURE(InitState());
2136 ASSERT_NO_FATAL_FAILURE(InitViewport());
2137
Tony Barbour01999182015-04-09 12:58:51 -06002138 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2139 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2140 VkSamplerObj sampler(m_device);
2141 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002142
Tony Barbour01999182015-04-09 12:58:51 -06002143 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002144 pipelineobj.AddShader(&vs);
2145 pipelineobj.AddShader(&ps);
2146
Tony Barbour01999182015-04-09 12:58:51 -06002147 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002148 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002149
Tony Barbourdd4c9642015-01-09 12:55:14 -07002150 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002151 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002152 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2153
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002154 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002155
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002156 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002157
2158#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002159 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002160 pDSDumpDot((char*)"triTest2.dot");
2161#endif
2162 // render triangle
2163 cmdBuffer.Draw(0, 3, 0, 1);
2164
2165 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002166 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002167 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002168
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002169 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002170}
GregFd6ebdb32015-06-03 18:40:50 -06002171
2172//bad
2173
2174
Tony Barbour01999182015-04-09 12:58:51 -06002175TEST_F(VkRenderTest, FSTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002176{
2177 // The expected result from this test is a red and green checkered triangle
2178 static const char *vertShaderText =
2179 "#version 140\n"
2180 "#extension GL_ARB_separate_shader_objects : enable\n"
2181 "#extension GL_ARB_shading_language_420pack : enable\n"
2182 "layout (location = 0) out vec2 samplePos;\n"
2183 "void main() {\n"
2184 " vec2 vertices[3];"
2185 " vertices[0] = vec2(-0.5, -0.5);\n"
2186 " vertices[1] = vec2( 0.5, -0.5);\n"
2187 " vertices[2] = vec2( 0.5, 0.5);\n"
2188 " vec2 positions[3];"
2189 " positions[0] = vec2( 0.0, 0.0);\n"
2190 " positions[1] = vec2( 1.0, 0.0);\n"
2191 " positions[2] = vec2( 1.0, 1.0);\n"
2192 " samplePos = positions[gl_VertexID % 3];\n"
2193 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2194 "}\n";
2195
2196 static const char *fragShaderText =
2197 "#version 140\n"
2198 "#extension GL_ARB_separate_shader_objects : enable\n"
2199 "#extension GL_ARB_shading_language_420pack : enable\n"
2200 "layout (location = 0) in vec2 samplePos;\n"
2201 "layout (binding = 0) uniform sampler2D surface;\n"
2202 "layout (location=0) out vec4 outColor;\n"
2203 "void main() {\n"
2204 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2205 " outColor = texColor;\n"
2206 "}\n";
2207
2208 ASSERT_NO_FATAL_FAILURE(InitState());
2209 ASSERT_NO_FATAL_FAILURE(InitViewport());
2210
Tony Barbour01999182015-04-09 12:58:51 -06002211 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2212 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2213 VkSamplerObj sampler(m_device);
2214 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002215
Tony Barbour01999182015-04-09 12:58:51 -06002216 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002217 pipelineobj.AddShader(&vs);
2218 pipelineobj.AddShader(&ps);
2219
Tony Barbour01999182015-04-09 12:58:51 -06002220 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002221 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002222
Tony Barbourdd4c9642015-01-09 12:55:14 -07002223 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002224 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002225 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2226
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002227 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002228
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002229 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002230
2231#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002232 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002233 pDSDumpDot((char*)"triTest2.dot");
2234#endif
2235 // render triangle
2236 cmdBuffer.Draw(0, 3, 0, 1);
2237
2238 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002239 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002240 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002241
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002242 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002243}
Tony Barbour01999182015-04-09 12:58:51 -06002244TEST_F(VkRenderTest, SamplerBindingsTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002245{
2246 // This test sets bindings on the samplers
2247 // For now we are asserting that sampler and texture pairs
2248 // march in lock step, and are set via GLSL binding. This can
2249 // and will probably change.
2250 // The sampler bindings should match the sampler and texture slot
2251 // number set up by the application.
2252 // This test will result in a blue triangle
2253 static const char *vertShaderText =
2254 "#version 140\n"
2255 "#extension GL_ARB_separate_shader_objects : enable\n"
2256 "#extension GL_ARB_shading_language_420pack : enable\n"
2257 "layout (location = 0) out vec4 samplePos;\n"
2258 "void main() {\n"
2259 " vec2 vertices[3];"
2260 " vertices[0] = vec2(-0.5, -0.5);\n"
2261 " vertices[1] = vec2( 0.5, -0.5);\n"
2262 " vertices[2] = vec2( 0.5, 0.5);\n"
2263 " vec2 positions[3];"
2264 " positions[0] = vec2( 0.0, 0.0);\n"
2265 " positions[1] = vec2( 1.0, 0.0);\n"
2266 " positions[2] = vec2( 1.0, 1.0);\n"
2267 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2268 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2269 "}\n";
2270
2271 static const char *fragShaderText =
2272 "#version 140\n"
2273 "#extension GL_ARB_separate_shader_objects : enable\n"
2274 "#extension GL_ARB_shading_language_420pack : enable\n"
2275 "layout (location = 0) in vec4 samplePos;\n"
2276 "layout (binding = 0) uniform sampler2D surface0;\n"
2277 "layout (binding = 1) uniform sampler2D surface1;\n"
2278 "layout (binding = 12) uniform sampler2D surface2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06002279 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002280 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002281 " outColor = textureLod(surface2, samplePos.xy, 0.0);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002282 "}\n";
2283
2284 ASSERT_NO_FATAL_FAILURE(InitState());
2285 ASSERT_NO_FATAL_FAILURE(InitViewport());
2286
Tony Barbour01999182015-04-09 12:58:51 -06002287 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2288 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002289
Tony Barbour01999182015-04-09 12:58:51 -06002290 VkSamplerObj sampler1(m_device);
2291 VkSamplerObj sampler2(m_device);
2292 VkSamplerObj sampler3(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002293
Tony Barbour2f421a02015-04-01 16:38:10 -06002294 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
Tony Barbour01999182015-04-09 12:58:51 -06002295 VkTextureObj texture1(m_device, tex_colors); // Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002296 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
Tony Barbour01999182015-04-09 12:58:51 -06002297 VkTextureObj texture2(m_device, tex_colors); // Green
Tony Barbour2f421a02015-04-01 16:38:10 -06002298 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
Tony Barbour01999182015-04-09 12:58:51 -06002299 VkTextureObj texture3(m_device, tex_colors); // Blue
Tony Barbourf43b6982014-11-25 13:18:32 -07002300
Tony Barbour01999182015-04-09 12:58:51 -06002301 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002302 pipelineobj.AddShader(&vs);
2303 pipelineobj.AddShader(&ps);
2304
Tony Barbour01999182015-04-09 12:58:51 -06002305 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002306 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2307 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2308 for (int i = 0; i < 10; i++)
2309 descriptorSet.AppendDummy();
2310 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002311
Tony Barbourdd4c9642015-01-09 12:55:14 -07002312 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002313 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002314 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2315
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002316 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002317
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002318 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002319
2320#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002321 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002322 pDSDumpDot((char*)"triTest2.dot");
2323#endif
2324 // render triangle
2325 cmdBuffer.Draw(0, 3, 0, 1);
2326
2327 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002328 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002329 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002330
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002331 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002332}
2333
Tony Barbour01999182015-04-09 12:58:51 -06002334TEST_F(VkRenderTest, TriangleVSUniformBlock)
Tony Barbourf43b6982014-11-25 13:18:32 -07002335{
2336 // The expected result from this test is a blue triangle
2337
2338 static const char *vertShaderText =
2339 "#version 140\n"
2340 "#extension GL_ARB_separate_shader_objects : enable\n"
2341 "#extension GL_ARB_shading_language_420pack : enable\n"
2342 "layout (location = 0) out vec4 outColor;\n"
2343 "layout (std140, binding = 0) uniform bufferVals {\n"
2344 " vec4 red;\n"
2345 " vec4 green;\n"
2346 " vec4 blue;\n"
2347 " vec4 white;\n"
2348 "} myBufferVals;\n"
2349 "void main() {\n"
2350 " vec2 vertices[3];"
2351 " vertices[0] = vec2(-0.5, -0.5);\n"
2352 " vertices[1] = vec2( 0.5, -0.5);\n"
2353 " vertices[2] = vec2( 0.5, 0.5);\n"
2354 " outColor = myBufferVals.blue;\n"
2355 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2356 "}\n";
2357
2358 static const char *fragShaderText =
2359 "#version 140\n"
2360 "#extension GL_ARB_separate_shader_objects : enable\n"
2361 "#extension GL_ARB_shading_language_420pack : enable\n"
2362 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -06002363 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002364 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002365 " outColor = inColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002366 "}\n";
2367
2368 ASSERT_NO_FATAL_FAILURE(InitState());
2369 ASSERT_NO_FATAL_FAILURE(InitViewport());
2370
Tony Barbour01999182015-04-09 12:58:51 -06002371 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2372 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002373
2374 // Let's populate our buffer with the following:
2375 // vec4 red;
2376 // vec4 green;
2377 // vec4 blue;
2378 // vec4 white;
2379 const int valCount = 4 * 4;
2380 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2381 0.0, 1.0, 0.0, 1.0,
2382 0.0, 0.0, 1.0, 1.0,
2383 1.0, 1.0, 1.0, 1.0 };
2384
Tony Barbour01999182015-04-09 12:58:51 -06002385 VkConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002386
Tony Barbour01999182015-04-09 12:58:51 -06002387 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002388 pipelineobj.AddShader(&vs);
2389 pipelineobj.AddShader(&ps);
2390
Tony Barbour01999182015-04-09 12:58:51 -06002391 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002392 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002393
Tony Barbourdd4c9642015-01-09 12:55:14 -07002394 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002395 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002396 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2397
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002398 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002399
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002400 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002401
2402#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002403 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002404 pDSDumpDot((char*)"triTest2.dot");
2405#endif
2406 // render triangle
2407 cmdBuffer.Draw(0, 3, 0, 1);
2408
2409 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002410 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002411 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002412
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002413 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002414}
2415
Tony Barbour01999182015-04-09 12:58:51 -06002416TEST_F(VkRenderTest, TriangleFSUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002417{
2418 // This test allows the shader to select which buffer it is
2419 // pulling from using layout binding qualifier.
2420 // There are corresponding changes in the compiler stack that
2421 // will select the buffer using binding directly.
2422 // The binding number should match the slot number set up by
2423 // the application.
2424 // The expected result from this test is a purple triangle
2425
2426 static const char *vertShaderText =
2427 "#version 140\n"
2428 "#extension GL_ARB_separate_shader_objects : enable\n"
2429 "#extension GL_ARB_shading_language_420pack : enable\n"
2430 "void main() {\n"
2431 " vec2 vertices[3];"
2432 " vertices[0] = vec2(-0.5, -0.5);\n"
2433 " vertices[1] = vec2( 0.5, -0.5);\n"
2434 " vertices[2] = vec2( 0.5, 0.5);\n"
2435 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2436 "}\n";
2437
2438 static const char *fragShaderText =
2439 "#version 140\n"
2440 "#extension GL_ARB_separate_shader_objects : enable\n"
2441 "#extension GL_ARB_shading_language_420pack : enable\n"
2442 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2443 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2444 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002445 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
GregFd6ebdb32015-06-03 18:40:50 -06002446 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002447 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002448 " outColor = myBlueVal.color;\n"
2449 " outColor += myRedVal.color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002450 "}\n";
2451
2452 ASSERT_NO_FATAL_FAILURE(InitState());
2453 ASSERT_NO_FATAL_FAILURE(InitViewport());
2454
Tony Barbour01999182015-04-09 12:58:51 -06002455 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2456 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002457
2458 // We're going to create a number of uniform buffers, and then allow
2459 // the shader to select which it wants to read from with a binding
2460
2461 // Let's populate the buffers with a single color each:
2462 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2463 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2464 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002465 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002466
2467 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2468 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2469 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2470 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2471
2472 const int redCount = sizeof(redVals) / sizeof(float);
2473 const int greenCount = sizeof(greenVals) / sizeof(float);
2474 const int blueCount = sizeof(blueVals) / sizeof(float);
2475 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2476
Tony Barbour01999182015-04-09 12:58:51 -06002477 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002478
Tony Barbour01999182015-04-09 12:58:51 -06002479 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002480
Tony Barbour01999182015-04-09 12:58:51 -06002481 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002482
Tony Barbour01999182015-04-09 12:58:51 -06002483 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002484
Tony Barbour01999182015-04-09 12:58:51 -06002485 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002486 pipelineobj.AddShader(&vs);
2487 pipelineobj.AddShader(&ps);
2488
Tony Barbour01999182015-04-09 12:58:51 -06002489 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002490 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2491 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2492 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2493 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002494
Tony Barbourdd4c9642015-01-09 12:55:14 -07002495 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002496 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002497 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002498
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002499 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002500
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002501 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002502
2503#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002504 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002505 pDSDumpDot((char*)"triTest2.dot");
2506#endif
2507 // render triangle
2508 cmdBuffer.Draw(0, 3, 0, 1);
2509
2510 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002511 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002512 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002513
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002514 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002515}
2516
Tony Barbour01999182015-04-09 12:58:51 -06002517TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002518{
2519 // This test is the same as TriangleFSUniformBlockBinding, but
2520 // it does not provide an instance name.
2521 // The expected result from this test is a purple triangle
2522
2523 static const char *vertShaderText =
2524 "#version 140\n"
2525 "#extension GL_ARB_separate_shader_objects : enable\n"
2526 "#extension GL_ARB_shading_language_420pack : enable\n"
2527 "void main() {\n"
2528 " vec2 vertices[3];"
2529 " vertices[0] = vec2(-0.5, -0.5);\n"
2530 " vertices[1] = vec2( 0.5, -0.5);\n"
2531 " vertices[2] = vec2( 0.5, 0.5);\n"
2532 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2533 "}\n";
2534
2535 static const char *fragShaderText =
2536 "#version 430\n"
2537 "#extension GL_ARB_separate_shader_objects : enable\n"
2538 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002539 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2540 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2541 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002542 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002543 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002544 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002545 " outColor = blue;\n"
2546 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002547 "}\n";
2548 ASSERT_NO_FATAL_FAILURE(InitState());
2549 ASSERT_NO_FATAL_FAILURE(InitViewport());
2550
Tony Barbour01999182015-04-09 12:58:51 -06002551 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2552 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002553
2554 // We're going to create a number of uniform buffers, and then allow
2555 // the shader to select which it wants to read from with a binding
2556
2557 // Let's populate the buffers with a single color each:
2558 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2559 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2560 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2561 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2562
2563 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2564 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2565 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2566 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2567
2568 const int redCount = sizeof(redVals) / sizeof(float);
2569 const int greenCount = sizeof(greenVals) / sizeof(float);
2570 const int blueCount = sizeof(blueVals) / sizeof(float);
2571 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2572
Tony Barbour01999182015-04-09 12:58:51 -06002573 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002574
Tony Barbour01999182015-04-09 12:58:51 -06002575 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002576
Tony Barbour01999182015-04-09 12:58:51 -06002577 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002578
Tony Barbour01999182015-04-09 12:58:51 -06002579 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002580
Tony Barbour01999182015-04-09 12:58:51 -06002581 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002582 pipelineobj.AddShader(&vs);
2583 pipelineobj.AddShader(&ps);
2584
Tony Barbour01999182015-04-09 12:58:51 -06002585 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002586 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2587 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2588 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2589 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002590
Tony Barbourdd4c9642015-01-09 12:55:14 -07002591 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002592 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002593 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2594
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002595 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002596
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002597 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002598
2599#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002600 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002601 pDSDumpDot((char*)"triTest2.dot");
2602#endif
2603 // render triangle
2604 cmdBuffer.Draw(0, 3, 0, 1);
2605
2606 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002607 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002608 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002609
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002610 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002611}
2612
Tony Barbour01999182015-04-09 12:58:51 -06002613TEST_F(VkRenderTest, CubeWithVertexFetchAndMVPAndTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07002614{
2615 static const char *vertShaderText =
2616 "#version 140\n"
2617 "#extension GL_ARB_separate_shader_objects : enable\n"
2618 "#extension GL_ARB_shading_language_420pack : enable\n"
2619 "layout (std140, binding=0) uniform bufferVals {\n"
2620 " mat4 mvp;\n"
2621 "} myBufferVals;\n"
2622 "layout (location=0) in vec4 pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002623 "layout (location=1) in vec2 input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002624 "layout (location=0) out vec2 UV;\n"
2625 "void main() {\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002626 " UV = input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002627 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002628 " gl_Position.y = -gl_Position.y;\n"
2629 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002630 "}\n";
2631
2632 static const char *fragShaderText =
2633 "#version 140\n"
2634 "#extension GL_ARB_separate_shader_objects : enable\n"
2635 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002636 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002637 "layout (location=0) out vec4 outColor;\n"
2638 "layout (location=0) in vec2 UV;\n"
2639 "void main() {\n"
2640 " outColor= textureLod(surface, UV, 0.0);\n"
2641 "}\n";
2642 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2643
2644 glm::mat4 View = glm::lookAt(
2645 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2646 glm::vec3(0,0,0), // and looks at the origin
2647 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2648 );
2649
2650 glm::mat4 Model = glm::mat4(1.0f);
2651
2652 glm::mat4 MVP = Projection * View * Model;
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002653 int num_verts = sizeof(g_vb_texture_Data) / sizeof(g_vb_texture_Data[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002654
2655
2656 ASSERT_NO_FATAL_FAILURE(InitState());
2657 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour8bef8ee2015-05-22 09:44:58 -06002658 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07002659
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002660 VkConstantBufferObj meshBuffer(m_device, num_verts,
2661 sizeof(g_vb_texture_Data[0]), g_vb_texture_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002662 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002663
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002664 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07002665
Tony Barbour01999182015-04-09 12:58:51 -06002666 VkConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2667 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2668 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2669 VkSamplerObj sampler(m_device);
2670 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002671
Tony Barbour01999182015-04-09 12:58:51 -06002672 VkPipelineObj pipelineobj(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002673 pipelineobj.AddShader(&vs);
2674 pipelineobj.AddShader(&ps);
2675
Tony Barbour01999182015-04-09 12:58:51 -06002676 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002677 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mvpBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002678 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002679
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002680#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002681 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002682 MESH_BIND_ID, // binding ID
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002683 sizeof(g_vb_texture_Data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002684 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002685 };
Tony Barbourf43b6982014-11-25 13:18:32 -07002686
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002687 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002688 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2689 vi_attribs[0].location = 0; // location
Tony Barbour8205d902015-04-16 15:59:00 -06002690 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002691 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2692 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2693 vi_attribs[1].location = 1; // location
2694 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
2695 vi_attribs[1].offsetInBytes = 16; // Offset of uv components
Tony Barbourf43b6982014-11-25 13:18:32 -07002696
Tony Barbourf43b6982014-11-25 13:18:32 -07002697 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002698 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2699 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07002700
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002701 VkPipelineDsStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002702 ds_state.depthTestEnable = VK_TRUE;
2703 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06002704 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002705 ds_state.depthBoundsEnable = VK_FALSE;
2706 ds_state.stencilTestEnable = VK_FALSE;
2707 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
2708 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
2709 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06002710 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
2711 ds_state.format = VK_FORMAT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002712 ds_state.front = ds_state.back;
2713 pipelineobj.SetDepthStencil(&ds_state);
2714
Tony Barbour17c6ab12015-03-27 17:03:18 -06002715 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour01999182015-04-09 12:58:51 -06002716 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002717 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002718
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002719 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002720
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002721 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002722
2723 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2724#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002725 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002726 pDSDumpDot((char*)"triTest2.dot");
2727#endif
2728 // render triangle
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002729 cmdBuffer.Draw(0, num_verts, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002730
2731 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002732 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002733 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002734
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002735 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002736 RotateTriangleVSUniform(Projection, View, Model, &mvpBuffer, &cmdBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002737}
Cody Northropd1ce7842014-12-09 11:17:01 -07002738
Tony Barbour01999182015-04-09 12:58:51 -06002739TEST_F(VkRenderTest, TriangleMixedSamplerUniformBlockBinding)
Cody Northropd1ce7842014-12-09 11:17:01 -07002740{
2741 // This test mixes binding slots of textures and buffers, ensuring
2742 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002743 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002744 // you can modify it to move the desired result around.
2745
2746 static const char *vertShaderText =
2747 "#version 140\n"
2748 "#extension GL_ARB_separate_shader_objects : enable\n"
2749 "#extension GL_ARB_shading_language_420pack : enable\n"
2750 "void main() {\n"
2751 " vec2 vertices[3];"
2752 " vertices[0] = vec2(-0.5, -0.5);\n"
2753 " vertices[1] = vec2( 0.5, -0.5);\n"
2754 " vertices[2] = vec2( 0.5, 0.5);\n"
2755 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2756 "}\n";
2757
2758 static const char *fragShaderText =
2759 "#version 430\n"
2760 "#extension GL_ARB_separate_shader_objects : enable\n"
2761 "#extension GL_ARB_shading_language_420pack : enable\n"
2762 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002763 "layout (binding = 3) uniform sampler2D surface1;\n"
2764 "layout (binding = 1) uniform sampler2D surface2;\n"
2765 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002766
Cody Northropa0410942014-12-09 13:59:39 -07002767
Chia-I Wuf8385062015-01-04 16:27:24 +08002768 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2769 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2770 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2771 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002772 "layout (location = 0) out vec4 outColor;\n"
2773 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002774 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002775 " outColor += white * vec4(0.00001);\n"
2776 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002777 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002778 "}\n";
2779 ASSERT_NO_FATAL_FAILURE(InitState());
2780 ASSERT_NO_FATAL_FAILURE(InitViewport());
2781
Tony Barbour01999182015-04-09 12:58:51 -06002782 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2783 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northropd1ce7842014-12-09 11:17:01 -07002784
Cody Northropd1ce7842014-12-09 11:17:01 -07002785 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2786 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2787 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2788 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2789
2790 const int redCount = sizeof(redVals) / sizeof(float);
2791 const int greenCount = sizeof(greenVals) / sizeof(float);
2792 const int blueCount = sizeof(blueVals) / sizeof(float);
2793 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2794
Tony Barbour01999182015-04-09 12:58:51 -06002795 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2796 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2797 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2798 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002799
Tony Barbour2f421a02015-04-01 16:38:10 -06002800 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002801 VkSamplerObj sampler0(m_device);
2802 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002803 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002804 VkSamplerObj sampler2(m_device);
2805 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002806 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002807 VkSamplerObj sampler4(m_device);
2808 VkTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropa0410942014-12-09 13:59:39 -07002809
2810 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2811 // TODO: Get back here ASAP and understand why.
Tony Barbour2f421a02015-04-01 16:38:10 -06002812 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06002813 VkSamplerObj sampler7(m_device);
2814 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropd1ce7842014-12-09 11:17:01 -07002815
Tony Barbour01999182015-04-09 12:58:51 -06002816 VkPipelineObj pipelineobj(m_device);
Cody Northropd1ce7842014-12-09 11:17:01 -07002817 pipelineobj.AddShader(&vs);
2818 pipelineobj.AddShader(&ps);
2819
Tony Barbour01999182015-04-09 12:58:51 -06002820 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002821 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2822 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2823 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2824 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002825 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002826 // swap blue and green
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002827 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2828 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2829 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002830
Tony Barbourdd4c9642015-01-09 12:55:14 -07002831 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002832 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002833 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002834
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002835 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002836
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002837 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002838
2839#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002840 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002841 pDSDumpDot((char*)"triTest2.dot");
2842#endif
2843 // render triangle
2844 cmdBuffer.Draw(0, 3, 0, 1);
2845
2846 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002847 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002848 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002849
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002850 RecordImages(m_renderTargets);
Cody Northropd1ce7842014-12-09 11:17:01 -07002851}
2852
Tony Barbour01999182015-04-09 12:58:51 -06002853TEST_F(VkRenderTest, TriangleMatchingSamplerUniformBlockBinding)
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002854{
2855 // This test matches binding slots of textures and buffers, requiring
2856 // the driver to give them distinct number spaces.
2857 // The expected result from this test is a red triangle, although
2858 // you can modify it to move the desired result around.
2859
2860 static const char *vertShaderText =
2861 "#version 140\n"
2862 "#extension GL_ARB_separate_shader_objects : enable\n"
2863 "#extension GL_ARB_shading_language_420pack : enable\n"
2864 "void main() {\n"
2865 " vec2 vertices[3];"
2866 " vertices[0] = vec2(-0.5, -0.5);\n"
2867 " vertices[1] = vec2( 0.5, -0.5);\n"
2868 " vertices[2] = vec2( 0.5, 0.5);\n"
2869 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2870 "}\n";
2871
2872 static const char *fragShaderText =
2873 "#version 430\n"
2874 "#extension GL_ARB_separate_shader_objects : enable\n"
2875 "#extension GL_ARB_shading_language_420pack : enable\n"
2876 "layout (binding = 0) uniform sampler2D surface0;\n"
2877 "layout (binding = 1) uniform sampler2D surface1;\n"
2878 "layout (binding = 2) uniform sampler2D surface2;\n"
2879 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002880 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2881 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2882 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2883 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002884 "layout (location = 0) out vec4 outColor;\n"
2885 "void main() {\n"
2886 " outColor = red;// * vec4(0.00001);\n"
2887 " outColor += white * vec4(0.00001);\n"
2888 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2889 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2890 "}\n";
2891 ASSERT_NO_FATAL_FAILURE(InitState());
2892 ASSERT_NO_FATAL_FAILURE(InitViewport());
2893
Tony Barbour01999182015-04-09 12:58:51 -06002894 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2895 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002896
2897 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2898 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2899 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2900 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2901
2902 const int redCount = sizeof(redVals) / sizeof(float);
2903 const int greenCount = sizeof(greenVals) / sizeof(float);
2904 const int blueCount = sizeof(blueVals) / sizeof(float);
2905 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2906
Tony Barbour01999182015-04-09 12:58:51 -06002907 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2908 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2909 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2910 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002911
Tony Barbour2f421a02015-04-01 16:38:10 -06002912 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002913 VkSamplerObj sampler0(m_device);
2914 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002915 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002916 VkSamplerObj sampler2(m_device);
2917 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002918 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002919 VkSamplerObj sampler4(m_device);
2920 VkTextureObj texture4(m_device, tex_colors); // Light Green
Tony Barbour2f421a02015-04-01 16:38:10 -06002921 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06002922 VkSamplerObj sampler7(m_device);
2923 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002924
Tony Barbour01999182015-04-09 12:58:51 -06002925 VkPipelineObj pipelineobj(m_device);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002926 pipelineobj.AddShader(&vs);
2927 pipelineobj.AddShader(&ps);
2928
Tony Barbour01999182015-04-09 12:58:51 -06002929 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002930 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2931 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2932 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2933 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002934 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2935 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2936 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2937 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002938
Tony Barbourdd4c9642015-01-09 12:55:14 -07002939 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002940 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002941 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002942
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002943 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002944
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002945 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002946
2947#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002948 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002949 pDSDumpDot((char*)"triTest2.dot");
2950#endif
2951 // render triangle
2952 cmdBuffer.Draw(0, 3, 0, 1);
2953
2954 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002955 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002956 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002957
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002958 RecordImages(m_renderTargets);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002959}
2960
Tony Barbour01999182015-04-09 12:58:51 -06002961TEST_F(VkRenderTest, TriangleUniformBufferLayout)
Cody Northrop02690bd2014-12-17 15:26:33 -07002962{
2963 // This test populates a buffer with a variety of different data
2964 // types, then reads them out with a shader.
2965 // The expected result from this test is a green triangle
2966
2967 static const char *vertShaderText =
2968 "#version 140\n"
2969 "#extension GL_ARB_separate_shader_objects : enable\n"
2970 "#extension GL_ARB_shading_language_420pack : enable\n"
2971 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2972 " vec4 fRed;\n"
2973 " vec4 fGreen;\n"
2974 " layout(row_major) mat4 worldToProj;\n"
2975 " layout(row_major) mat4 projToWorld;\n"
2976 " layout(row_major) mat4 worldToView;\n"
2977 " layout(row_major) mat4 viewToProj;\n"
2978 " layout(row_major) mat4 worldToShadow[4];\n"
2979 " float fZero;\n"
2980 " float fOne;\n"
2981 " float fTwo;\n"
2982 " float fThree;\n"
2983 " vec3 fZeroZeroZero;\n"
2984 " float fFour;\n"
2985 " vec3 fZeroZeroOne;\n"
2986 " float fFive;\n"
2987 " vec3 fZeroOneZero;\n"
2988 " float fSix;\n"
2989 " float fSeven;\n"
2990 " float fEight;\n"
2991 " float fNine;\n"
2992 " vec2 fZeroZero;\n"
2993 " vec2 fZeroOne;\n"
2994 " vec4 fBlue;\n"
2995 " vec2 fOneZero;\n"
2996 " vec2 fOneOne;\n"
2997 " vec3 fZeroOneOne;\n"
2998 " float fTen;\n"
2999 " float fEleven;\n"
3000 " float fTwelve;\n"
3001 " vec3 fOneZeroZero;\n"
3002 " vec4 uvOffsets[4];\n"
3003 "};\n"
3004 "layout (location = 0) out vec4 color;"
3005 "void main() {\n"
3006
3007 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3008 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3009 " \n"
3010
3011 // do some exact comparisons, even though we should
3012 // really have an epsilon involved.
3013 " vec4 outColor = right;\n"
3014 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3015 " outColor = wrong;\n"
3016 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3017 " outColor = wrong;\n"
3018 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3019 " outColor = wrong;\n"
3020
3021 " color = outColor;\n"
3022
3023 // generic position stuff
3024 " vec2 vertices;\n"
3025 " int vertexSelector = gl_VertexID;\n"
3026 " if (vertexSelector == 0)\n"
3027 " vertices = vec2(-0.5, -0.5);\n"
3028 " else if (vertexSelector == 1)\n"
3029 " vertices = vec2( 0.5, -0.5);\n"
3030 " else if (vertexSelector == 2)\n"
3031 " vertices = vec2( 0.5, 0.5);\n"
3032 " else\n"
3033 " vertices = vec2( 0.0, 0.0);\n"
3034 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3035 "}\n";
3036
3037 static const char *fragShaderText =
3038 "#version 140\n"
3039 "#extension GL_ARB_separate_shader_objects : enable\n"
3040 "#extension GL_ARB_shading_language_420pack : enable\n"
3041 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3042 " vec4 fRed;\n"
3043 " vec4 fGreen;\n"
3044 " layout(row_major) mat4 worldToProj;\n"
3045 " layout(row_major) mat4 projToWorld;\n"
3046 " layout(row_major) mat4 worldToView;\n"
3047 " layout(row_major) mat4 viewToProj;\n"
3048 " layout(row_major) mat4 worldToShadow[4];\n"
3049 " float fZero;\n"
3050 " float fOne;\n"
3051 " float fTwo;\n"
3052 " float fThree;\n"
3053 " vec3 fZeroZeroZero;\n"
3054 " float fFour;\n"
3055 " vec3 fZeroZeroOne;\n"
3056 " float fFive;\n"
3057 " vec3 fZeroOneZero;\n"
3058 " float fSix;\n"
3059 " float fSeven;\n"
3060 " float fEight;\n"
3061 " float fNine;\n"
3062 " vec2 fZeroZero;\n"
3063 " vec2 fZeroOne;\n"
3064 " vec4 fBlue;\n"
3065 " vec2 fOneZero;\n"
3066 " vec2 fOneOne;\n"
3067 " vec3 fZeroOneOne;\n"
3068 " float fTen;\n"
3069 " float fEleven;\n"
3070 " float fTwelve;\n"
3071 " vec3 fOneZeroZero;\n"
3072 " vec4 uvOffsets[4];\n"
3073 "};\n"
3074 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003075 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop02690bd2014-12-17 15:26:33 -07003076 "void main() {\n"
3077 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3078 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3079 " \n"
3080
3081 // start with VS value to ensure it passed
3082 " vec4 outColor = color;\n"
3083
3084 // do some exact comparisons, even though we should
3085 // really have an epsilon involved.
3086 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3087 " outColor = wrong;\n"
3088 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3089 " outColor = wrong;\n"
3090 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3091 " outColor = wrong;\n"
3092 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3093 " outColor = wrong;\n"
3094 " if (fTwo != 2.0)\n"
3095 " outColor = wrong;\n"
3096 " if (fOneOne != vec2(1.0, 1.0))\n"
3097 " outColor = wrong;\n"
3098 " if (fTen != 10.0)\n"
3099 " outColor = wrong;\n"
3100 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3101 " outColor = wrong;\n"
3102 " \n"
GregFd6ebdb32015-06-03 18:40:50 -06003103 " uFragColor = outColor;\n"
Cody Northrop02690bd2014-12-17 15:26:33 -07003104 "}\n";
3105
3106
3107 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3108 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3109 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3110 0.0, 1.0, 0.0, 1.0, // align
3111 0.0, 0.0, 1.0, 1.0, // align
3112 0.0, 0.0, 0.0, 1.0, // align
3113 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3114 0.0, 2.0, 0.0, 2.0, // align
3115 0.0, 0.0, 2.0, 2.0, // align
3116 0.0, 0.0, 0.0, 2.0, // align
3117 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3118 0.0, 3.0, 0.0, 3.0, // align
3119 0.0, 0.0, 3.0, 3.0, // align
3120 0.0, 0.0, 0.0, 3.0, // align
3121 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3122 0.0, 4.0, 0.0, 4.0, // align
3123 0.0, 0.0, 4.0, 4.0, // align
3124 0.0, 0.0, 0.0, 4.0, // align
3125 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3126 0.0, 5.0, 0.0, 5.0, // align
3127 0.0, 0.0, 5.0, 5.0, // align
3128 0.0, 0.0, 0.0, 5.0, // align
3129 6.0, 0.0, 0.0, 6.0, // align
3130 0.0, 6.0, 0.0, 6.0, // align
3131 0.0, 0.0, 6.0, 6.0, // align
3132 0.0, 0.0, 0.0, 6.0, // align
3133 7.0, 0.0, 0.0, 7.0, // align
3134 0.0, 7.0, 0.0, 7.0, // align
3135 0.0, 0.0, 7.0, 7.0, // align
3136 0.0, 0.0, 0.0, 7.0, // align
3137 8.0, 0.0, 0.0, 8.0, // align
3138 0.0, 8.0, 0.0, 8.0, // align
3139 0.0, 0.0, 8.0, 8.0, // align
3140 0.0, 0.0, 0.0, 8.0, // align
3141 0.0, // float fZero; // align
3142 1.0, // float fOne; // pack
3143 2.0, // float fTwo; // pack
3144 3.0, // float fThree; // pack
3145 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3146 4.0, // float fFour; // pack
3147 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3148 5.0, // float fFive; // pack
3149 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3150 6.0, // float fSix; // pack
3151 7.0, // float fSeven; // align
3152 8.0, // float fEight; // pack
3153 9.0, // float fNine; // pack
3154 0.0, // BUFFER
3155 0.0, 0.0, // vec2 fZeroZero; // align
3156 0.0, 1.0, // vec2 fZeroOne; // pack
3157 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3158 1.0, 0.0, // vec2 fOneZero; // align
3159 1.0, 1.0, // vec2 fOneOne; // pack
3160 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3161 10.0, // float fTen; // pack
3162 11.0, // float fEleven; // align
3163 12.0, // float fTwelve; // pack
3164 0.0, 0.0, // BUFFER
3165 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3166 0.0, // BUFFER
3167 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3168 0.5, 0.6, 0.7, 0.8, // align
3169 0.9, 1.0, 1.1, 1.2, // align
3170 1.3, 1.4, 1.5, 1.6, // align
3171 };
3172
3173 ASSERT_NO_FATAL_FAILURE(InitState());
3174 ASSERT_NO_FATAL_FAILURE(InitViewport());
3175
3176 const int constCount = sizeof(mixedVals) / sizeof(float);
3177
Tony Barbour01999182015-04-09 12:58:51 -06003178 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3179 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop02690bd2014-12-17 15:26:33 -07003180
Tony Barbour01999182015-04-09 12:58:51 -06003181 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003182
Tony Barbour01999182015-04-09 12:58:51 -06003183 VkPipelineObj pipelineobj(m_device);
Cody Northrop02690bd2014-12-17 15:26:33 -07003184 pipelineobj.AddShader(&vs);
3185 pipelineobj.AddShader(&ps);
3186
Tony Barbour01999182015-04-09 12:58:51 -06003187 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003188 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003189
3190 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06003191 VkCommandBufferObj cmdBuffer(m_device);
Cody Northrop02690bd2014-12-17 15:26:33 -07003192 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3193
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003194 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Cody Northrop02690bd2014-12-17 15:26:33 -07003195
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003196 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Cody Northrop02690bd2014-12-17 15:26:33 -07003197
3198#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003199 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop02690bd2014-12-17 15:26:33 -07003200 pDSDumpDot((char*)"triTest2.dot");
3201#endif
3202 // render triangle
3203 cmdBuffer.Draw(0, 3, 0, 1);
3204
3205 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003206 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003207 cmdBuffer.QueueCommandBuffer();
Cody Northrop02690bd2014-12-17 15:26:33 -07003208
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003209 RecordImages(m_renderTargets);
Cody Northrop02690bd2014-12-17 15:26:33 -07003210}
3211
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003212TEST_F(VkRenderTest, TextureGather)
3213{
3214 // This test introduces textureGather and textureGatherOffset
3215 // Each call is compared against an expected inline color result
3216 // Green triangle means everything worked as expected
3217 // Red means something went wrong
3218
3219 // disable SPV until texture gather is turned on in LunarGLASS
Cody Northrop1cfbd172015-06-03 16:49:20 -06003220 ScopedUseGlsl useGlsl(true);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003221
3222 static const char *vertShaderText =
3223 "#version 140\n"
3224 "#extension GL_ARB_separate_shader_objects : enable\n"
3225 "#extension GL_ARB_shading_language_420pack : enable\n"
3226 "void main() {\n"
3227 " vec2 vertices[3];"
3228 " vertices[0] = vec2(-0.5, -0.5);\n"
3229 " vertices[1] = vec2( 0.5, -0.5);\n"
3230 " vertices[2] = vec2( 0.5, 0.5);\n"
3231 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
3232 "}\n";
3233
3234 static const char *fragShaderText =
3235 "#version 430\n"
3236 "#extension GL_ARB_separate_shader_objects : enable\n"
3237 "#extension GL_ARB_shading_language_420pack : enable\n"
3238 "layout (binding = 0) uniform sampler2D surface0;\n"
3239 "layout (binding = 1) uniform sampler2D surface1;\n"
3240 "layout (binding = 2) uniform sampler2D surface2;\n"
3241 "layout (binding = 3) uniform sampler2D surface3;\n"
3242 "layout (location = 0) out vec4 outColor;\n"
3243 "void main() {\n"
3244
3245 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3246 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3247
3248 " vec4 color = right;\n"
3249
3250 // Grab a normal texture sample to ensure it can work in conjuntion
3251 // with textureGather (there are some intracacies in the backend)
3252 " vec4 sampledColor = textureLod(surface2, vec2(0.5), 0.0);\n"
3253 " if (sampledColor != vec4(0.0, 0.0, 1.0, 1.0))\n"
3254 " color = wrong;\n"
3255
3256 " vec4 gatheredColor = textureGather(surface0, vec2(0.5), 0);\n"
3257 // This just grabbed four red components from a red surface
3258 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3259 " color = wrong;\n"
3260
3261 // Yes, this is using an offset of 0, we don't have enough fine grained
3262 // control of the texture contents here.
3263 " gatheredColor = textureGatherOffset(surface1, vec2(0.5), ivec2(0, 0), 1);\n"
3264 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3265 " color = wrong;\n"
3266
3267 " outColor = color;\n"
3268
3269 "}\n";
3270
3271 ASSERT_NO_FATAL_FAILURE(InitState());
3272 ASSERT_NO_FATAL_FAILURE(InitViewport());
3273
3274 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3275 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3276
3277 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
3278 VkSamplerObj sampler0(m_device);
3279 VkTextureObj texture0(m_device, tex_colors); // Red
3280 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
3281 VkSamplerObj sampler1(m_device);
3282 VkTextureObj texture1(m_device, tex_colors); // Green
3283 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
3284 VkSamplerObj sampler2(m_device);
3285 VkTextureObj texture2(m_device, tex_colors); // Blue
3286 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
3287 VkSamplerObj sampler3(m_device);
3288 VkTextureObj texture3(m_device, tex_colors); // Red and Blue
3289
3290 VkPipelineObj pipelineobj(m_device);
3291 pipelineobj.AddShader(&vs);
3292 pipelineobj.AddShader(&ps);
3293
3294 VkDescriptorSetObj descriptorSet(m_device);
3295 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3296 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
3297 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3298 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
3299
3300 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3301 VkCommandBufferObj cmdBuffer(m_device);
3302 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3303
3304 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3305
3306 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3307
3308 // render triangle
3309 cmdBuffer.Draw(0, 3, 0, 1);
3310
3311 // finalize recording of the command buffer
3312 EndCommandBuffer(cmdBuffer);
3313 cmdBuffer.QueueCommandBuffer();
3314
3315 RecordImages(m_renderTargets);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003316}
3317
Cody Northropa44c2ff2015-04-15 11:19:06 -06003318TEST_F(VkRenderTest, GeometryShaderHelloWorld)
3319{
3320 // This test introduces a geometry shader that simply
3321 // changes the color of each vertex to red, green, blue
3322
3323 static const char *vertShaderText =
3324 "#version 140\n"
3325 "#extension GL_ARB_separate_shader_objects : enable\n"
3326 "#extension GL_ARB_shading_language_420pack : enable\n"
3327 "layout (location = 0) out vec4 color;"
3328 "void main() {\n"
3329
3330 // VS writes out red
3331 " color = vec4(1.0, 0.0, 0.0, 1.0);\n"
3332
3333 // generic position stuff
3334 " vec2 vertices;\n"
3335 " int vertexSelector = gl_VertexID;\n"
3336 " if (vertexSelector == 0)\n"
3337 " vertices = vec2(-0.5, -0.5);\n"
3338 " else if (vertexSelector == 1)\n"
3339 " vertices = vec2( 0.5, -0.5);\n"
3340 " else if (vertexSelector == 2)\n"
3341 " vertices = vec2( 0.5, 0.5);\n"
3342 " else\n"
3343 " vertices = vec2( 0.0, 0.0);\n"
3344 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3345
3346 "}\n";
3347
3348 static const char *geomShaderText =
3349 "#version 330\n"
3350 "#extension GL_ARB_separate_shader_objects : enable\n"
3351 "#extension GL_ARB_shading_language_420pack : enable\n"
3352 "layout( triangles ) in;\n"
3353 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3354 "layout( location = 0 ) in vec4 inColor[3];\n"
3355 "layout( location = 0 ) out vec4 outColor;\n"
3356 "void main()\n"
3357 "{\n"
3358
3359 // first vertex, pass through red
3360 " gl_Position = gl_in[0].gl_Position;\n"
3361 " outColor = inColor[0];\n"
3362 " EmitVertex();\n"
3363
3364 // second vertex, green
3365 " gl_Position = gl_in[1].gl_Position;\n"
3366 " outColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3367 " EmitVertex();\n"
3368
3369 // third vertex, blue
3370 " gl_Position = gl_in[2].gl_Position;\n"
3371 " outColor = vec4(0.0, 0.0, 1.0, 1.0);\n"
3372 " EmitVertex();\n"
3373
3374 // done
3375 " EndPrimitive();\n"
3376 "}\n";
3377
3378
3379 static const char *fragShaderText =
3380 "#version 140\n"
3381 "#extension GL_ARB_separate_shader_objects : enable\n"
3382 "#extension GL_ARB_shading_language_420pack : enable\n"
3383 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003384 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003385 "void main() {\n"
3386 // pass through
GregFd6ebdb32015-06-03 18:40:50 -06003387 " outColor = color;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003388 "}\n";
3389
3390
3391
3392 ASSERT_NO_FATAL_FAILURE(InitState());
3393 ASSERT_NO_FATAL_FAILURE(InitViewport());
3394
3395 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3396 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3397 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3398
3399 VkPipelineObj pipelineobj(m_device);
3400 pipelineobj.AddShader(&vs);
3401 pipelineobj.AddShader(&gs);
3402 pipelineobj.AddShader(&ps);
3403
3404 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3405 VkCommandBufferObj cmdBuffer(m_device);
3406 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3407
3408 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3409
3410 VkDescriptorSetObj descriptorSet(m_device);
3411
3412 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3413
3414 // render triangle
3415 cmdBuffer.Draw(0, 3, 0, 1);
3416
3417 // finalize recording of the command buffer
3418 EndCommandBuffer(cmdBuffer);
3419 cmdBuffer.QueueCommandBuffer();
3420
3421 RecordImages(m_renderTargets);
3422}
3423
3424TEST_F(VkRenderTest, GSUniformBufferLayout)
3425{
3426 // This test is just like TriangleUniformBufferLayout but adds
3427 // geometry as a stage that also does UBO lookups
3428 // The expected result from this test is a green triangle
3429
3430 static const char *vertShaderText =
3431 "#version 140\n"
3432 "#extension GL_ARB_separate_shader_objects : enable\n"
3433 "#extension GL_ARB_shading_language_420pack : enable\n"
3434 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3435 " vec4 fRed;\n"
3436 " vec4 fGreen;\n"
3437 " layout(row_major) mat4 worldToProj;\n"
3438 " layout(row_major) mat4 projToWorld;\n"
3439 " layout(row_major) mat4 worldToView;\n"
3440 " layout(row_major) mat4 viewToProj;\n"
3441 " layout(row_major) mat4 worldToShadow[4];\n"
3442 " float fZero;\n"
3443 " float fOne;\n"
3444 " float fTwo;\n"
3445 " float fThree;\n"
3446 " vec3 fZeroZeroZero;\n"
3447 " float fFour;\n"
3448 " vec3 fZeroZeroOne;\n"
3449 " float fFive;\n"
3450 " vec3 fZeroOneZero;\n"
3451 " float fSix;\n"
3452 " float fSeven;\n"
3453 " float fEight;\n"
3454 " float fNine;\n"
3455 " vec2 fZeroZero;\n"
3456 " vec2 fZeroOne;\n"
3457 " vec4 fBlue;\n"
3458 " vec2 fOneZero;\n"
3459 " vec2 fOneOne;\n"
3460 " vec3 fZeroOneOne;\n"
3461 " float fTen;\n"
3462 " float fEleven;\n"
3463 " float fTwelve;\n"
3464 " vec3 fOneZeroZero;\n"
3465 " vec4 uvOffsets[4];\n"
3466 "};\n"
3467 "layout (location = 0) out vec4 color;"
3468 "void main() {\n"
3469
3470 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3471 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3472 " \n"
3473
3474 // do some exact comparisons, even though we should
3475 // really have an epsilon involved.
3476 " vec4 outColor = right;\n"
3477 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3478 " outColor = wrong;\n"
3479 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3480 " outColor = wrong;\n"
3481 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3482 " outColor = wrong;\n"
3483
3484 " color = outColor;\n"
3485
3486 // generic position stuff
3487 " vec2 vertices;\n"
3488 " int vertexSelector = gl_VertexID;\n"
3489 " if (vertexSelector == 0)\n"
3490 " vertices = vec2(-0.5, -0.5);\n"
3491 " else if (vertexSelector == 1)\n"
3492 " vertices = vec2( 0.5, -0.5);\n"
3493 " else if (vertexSelector == 2)\n"
3494 " vertices = vec2( 0.5, 0.5);\n"
3495 " else\n"
3496 " vertices = vec2( 0.0, 0.0);\n"
3497 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3498 "}\n";
3499
3500 static const char *geomShaderText =
3501 "#version 330\n"
3502 "#extension GL_ARB_separate_shader_objects : enable\n"
3503 "#extension GL_ARB_shading_language_420pack : enable\n"
3504
3505 // GS layout stuff
3506 "layout( triangles ) in;\n"
3507 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3508
3509 // Between stage IO
3510 "layout( location = 0 ) in vec4 inColor[3];\n"
3511 "layout( location = 0 ) out vec4 color;\n"
3512
3513 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3514 " vec4 fRed;\n"
3515 " vec4 fGreen;\n"
3516 " layout(row_major) mat4 worldToProj;\n"
3517 " layout(row_major) mat4 projToWorld;\n"
3518 " layout(row_major) mat4 worldToView;\n"
3519 " layout(row_major) mat4 viewToProj;\n"
3520 " layout(row_major) mat4 worldToShadow[4];\n"
3521 " float fZero;\n"
3522 " float fOne;\n"
3523 " float fTwo;\n"
3524 " float fThree;\n"
3525 " vec3 fZeroZeroZero;\n"
3526 " float fFour;\n"
3527 " vec3 fZeroZeroOne;\n"
3528 " float fFive;\n"
3529 " vec3 fZeroOneZero;\n"
3530 " float fSix;\n"
3531 " float fSeven;\n"
3532 " float fEight;\n"
3533 " float fNine;\n"
3534 " vec2 fZeroZero;\n"
3535 " vec2 fZeroOne;\n"
3536 " vec4 fBlue;\n"
3537 " vec2 fOneZero;\n"
3538 " vec2 fOneOne;\n"
3539 " vec3 fZeroOneOne;\n"
3540 " float fTen;\n"
3541 " float fEleven;\n"
3542 " float fTwelve;\n"
3543 " vec3 fOneZeroZero;\n"
3544 " vec4 uvOffsets[4];\n"
3545 "};\n"
3546
3547 "void main()\n"
3548 "{\n"
3549
3550 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3551 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3552
3553 // Each vertex will validate it can read VS output
3554 // then check a few values from the UBO
3555
3556 // first vertex
3557 " vec4 outColor = inColor[0];\n"
3558
3559 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3560 " outColor = wrong;\n"
3561 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3562 " outColor = wrong;\n"
3563 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3564 " outColor = wrong;\n"
3565 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3566 " outColor = wrong;\n"
3567
3568 " gl_Position = gl_in[0].gl_Position;\n"
3569 " color = outColor;\n"
3570 " EmitVertex();\n"
3571
3572 // second vertex
3573 " outColor = inColor[1];\n"
3574
3575 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3576 " outColor = wrong;\n"
3577 " if (fSix != 6.0)\n"
3578 " outColor = wrong;\n"
3579 " if (fOneOne != vec2(1.0, 1.0))\n"
3580 " outColor = wrong;\n"
3581
3582 " gl_Position = gl_in[1].gl_Position;\n"
3583 " color = outColor;\n"
3584 " EmitVertex();\n"
3585
3586 // third vertex
3587 " outColor = inColor[2];\n"
3588
3589 " if (fSeven != 7.0)\n"
3590 " outColor = wrong;\n"
3591 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3592 " outColor = wrong;\n"
3593
3594 " gl_Position = gl_in[2].gl_Position;\n"
3595 " color = outColor;\n"
3596 " EmitVertex();\n"
3597
3598 // done
3599 " EndPrimitive();\n"
3600 "}\n";
3601
3602 static const char *fragShaderText =
3603 "#version 140\n"
3604 "#extension GL_ARB_separate_shader_objects : enable\n"
3605 "#extension GL_ARB_shading_language_420pack : enable\n"
3606 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3607 " vec4 fRed;\n"
3608 " vec4 fGreen;\n"
3609 " layout(row_major) mat4 worldToProj;\n"
3610 " layout(row_major) mat4 projToWorld;\n"
3611 " layout(row_major) mat4 worldToView;\n"
3612 " layout(row_major) mat4 viewToProj;\n"
3613 " layout(row_major) mat4 worldToShadow[4];\n"
3614 " float fZero;\n"
3615 " float fOne;\n"
3616 " float fTwo;\n"
3617 " float fThree;\n"
3618 " vec3 fZeroZeroZero;\n"
3619 " float fFour;\n"
3620 " vec3 fZeroZeroOne;\n"
3621 " float fFive;\n"
3622 " vec3 fZeroOneZero;\n"
3623 " float fSix;\n"
3624 " float fSeven;\n"
3625 " float fEight;\n"
3626 " float fNine;\n"
3627 " vec2 fZeroZero;\n"
3628 " vec2 fZeroOne;\n"
3629 " vec4 fBlue;\n"
3630 " vec2 fOneZero;\n"
3631 " vec2 fOneOne;\n"
3632 " vec3 fZeroOneOne;\n"
3633 " float fTen;\n"
3634 " float fEleven;\n"
3635 " float fTwelve;\n"
3636 " vec3 fOneZeroZero;\n"
3637 " vec4 uvOffsets[4];\n"
3638 "};\n"
3639 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003640 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003641 "void main() {\n"
3642 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3643 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3644 " \n"
3645
3646 // start with GS value to ensure it passed
3647 " vec4 outColor = color;\n"
3648
3649 // do some exact comparisons, even though we should
3650 // really have an epsilon involved.
3651 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3652 " outColor = wrong;\n"
3653 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3654 " outColor = wrong;\n"
3655 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3656 " outColor = wrong;\n"
3657 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3658 " outColor = wrong;\n"
3659 " if (fTwo != 2.0)\n"
3660 " outColor = wrong;\n"
3661 " if (fOneOne != vec2(1.0, 1.0))\n"
3662 " outColor = wrong;\n"
3663 " if (fTen != 10.0)\n"
3664 " outColor = wrong;\n"
3665 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3666 " outColor = wrong;\n"
3667 " \n"
GregFd6ebdb32015-06-03 18:40:50 -06003668 " uFragColor = outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003669 "}\n";
3670
3671
3672 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3673 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3674 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3675 0.0, 1.0, 0.0, 1.0, // align
3676 0.0, 0.0, 1.0, 1.0, // align
3677 0.0, 0.0, 0.0, 1.0, // align
3678 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3679 0.0, 2.0, 0.0, 2.0, // align
3680 0.0, 0.0, 2.0, 2.0, // align
3681 0.0, 0.0, 0.0, 2.0, // align
3682 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3683 0.0, 3.0, 0.0, 3.0, // align
3684 0.0, 0.0, 3.0, 3.0, // align
3685 0.0, 0.0, 0.0, 3.0, // align
3686 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3687 0.0, 4.0, 0.0, 4.0, // align
3688 0.0, 0.0, 4.0, 4.0, // align
3689 0.0, 0.0, 0.0, 4.0, // align
3690 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3691 0.0, 5.0, 0.0, 5.0, // align
3692 0.0, 0.0, 5.0, 5.0, // align
3693 0.0, 0.0, 0.0, 5.0, // align
3694 6.0, 0.0, 0.0, 6.0, // align
3695 0.0, 6.0, 0.0, 6.0, // align
3696 0.0, 0.0, 6.0, 6.0, // align
3697 0.0, 0.0, 0.0, 6.0, // align
3698 7.0, 0.0, 0.0, 7.0, // align
3699 0.0, 7.0, 0.0, 7.0, // align
3700 0.0, 0.0, 7.0, 7.0, // align
3701 0.0, 0.0, 0.0, 7.0, // align
3702 8.0, 0.0, 0.0, 8.0, // align
3703 0.0, 8.0, 0.0, 8.0, // align
3704 0.0, 0.0, 8.0, 8.0, // align
3705 0.0, 0.0, 0.0, 8.0, // align
3706 0.0, // float fZero; // align
3707 1.0, // float fOne; // pack
3708 2.0, // float fTwo; // pack
3709 3.0, // float fThree; // pack
3710 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3711 4.0, // float fFour; // pack
3712 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3713 5.0, // float fFive; // pack
3714 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3715 6.0, // float fSix; // pack
3716 7.0, // float fSeven; // align
3717 8.0, // float fEight; // pack
3718 9.0, // float fNine; // pack
3719 0.0, // BUFFER
3720 0.0, 0.0, // vec2 fZeroZero; // align
3721 0.0, 1.0, // vec2 fZeroOne; // pack
3722 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3723 1.0, 0.0, // vec2 fOneZero; // align
3724 1.0, 1.0, // vec2 fOneOne; // pack
3725 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3726 10.0, // float fTen; // pack
3727 11.0, // float fEleven; // align
3728 12.0, // float fTwelve; // pack
3729 0.0, 0.0, // BUFFER
3730 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3731 0.0, // BUFFER
3732 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3733 0.5, 0.6, 0.7, 0.8, // align
3734 0.9, 1.0, 1.1, 1.2, // align
3735 1.3, 1.4, 1.5, 1.6, // align
3736 };
3737
3738
3739
3740 ASSERT_NO_FATAL_FAILURE(InitState());
3741 ASSERT_NO_FATAL_FAILURE(InitViewport());
3742
3743 const int constCount = sizeof(mixedVals) / sizeof(float);
3744
3745 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3746 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3747 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3748
3749 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
3750
3751 VkPipelineObj pipelineobj(m_device);
3752 pipelineobj.AddShader(&vs);
3753 pipelineobj.AddShader(&gs);
3754 pipelineobj.AddShader(&ps);
3755
3756 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3757 VkCommandBufferObj cmdBuffer(m_device);
3758 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3759
3760 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3761
3762 VkDescriptorSetObj descriptorSet(m_device);
3763 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
3764
3765 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3766
3767 // render triangle
3768 cmdBuffer.Draw(0, 3, 0, 1);
3769
3770 // finalize recording of the command buffer
3771 EndCommandBuffer(cmdBuffer);
3772 cmdBuffer.QueueCommandBuffer();
3773
3774 RecordImages(m_renderTargets);
3775}
3776
3777TEST_F(VkRenderTest, GSPositions)
3778{
3779 // This test adds more inputs from the vertex shader and perturbs positions
3780 // Expected result is white triangle with weird positions
3781
3782 static const char *vertShaderText =
3783 "#version 140\n"
3784 "#extension GL_ARB_separate_shader_objects : enable\n"
3785 "#extension GL_ARB_shading_language_420pack : enable\n"
3786
3787 "layout(location = 0) out vec3 out_a;\n"
3788 "layout(location = 1) out vec3 out_b;\n"
3789 "layout(location = 2) out vec3 out_c;\n"
3790
3791 "void main() {\n"
3792
3793 // write a solid color to each
3794 " out_a = vec3(1.0, 0.0, 0.0);\n"
3795 " out_b = vec3(0.0, 1.0, 0.0);\n"
3796 " out_c = vec3(0.0, 0.0, 1.0);\n"
3797
3798 // generic position stuff
3799 " vec2 vertices;\n"
3800 " int vertexSelector = gl_VertexID;\n"
3801 " if (vertexSelector == 0)\n"
3802 " vertices = vec2(-0.5, -0.5);\n"
3803 " else if (vertexSelector == 1)\n"
3804 " vertices = vec2( 0.5, -0.5);\n"
3805 " else if (vertexSelector == 2)\n"
3806 " vertices = vec2( 0.5, 0.5);\n"
3807 " else\n"
3808 " vertices = vec2( 0.0, 0.0);\n"
3809 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3810
3811 "}\n";
3812
3813 static const char *geomShaderText =
3814 "#version 330\n"
3815 "#extension GL_ARB_separate_shader_objects : enable\n"
3816 "#extension GL_ARB_shading_language_420pack : enable\n"
3817 "layout( triangles ) in;\n"
3818 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3819
3820 "layout(location = 0) in vec3 in_a[3];\n"
3821 "layout(location = 1) in vec3 in_b[3];\n"
3822 "layout(location = 2) in vec3 in_c[3];\n"
3823
3824 "layout(location = 0) out vec3 out_a;\n"
3825 "layout(location = 1) out vec3 out_b;\n"
3826 "layout(location = 2) out vec3 out_c;\n"
3827
3828 "void main()\n"
3829 "{\n"
3830
3831 " gl_Position = gl_in[0].gl_Position;\n"
3832 " gl_Position.xy *= vec2(0.75);\n"
3833 " out_a = in_a[0];\n"
3834 " out_b = in_b[0];\n"
3835 " out_c = in_c[0];\n"
3836 " EmitVertex();\n"
3837
3838 " gl_Position = gl_in[1].gl_Position;\n"
3839 " gl_Position.xy *= vec2(1.5);\n"
3840 " out_a = in_a[1];\n"
3841 " out_b = in_b[1];\n"
3842 " out_c = in_c[1];\n"
3843 " EmitVertex();\n"
3844
3845 " gl_Position = gl_in[2].gl_Position;\n"
3846 " gl_Position.xy *= vec2(-0.1);\n"
3847 " out_a = in_a[2];\n"
3848 " out_b = in_b[2];\n"
3849 " out_c = in_c[2];\n"
3850 " EmitVertex();\n"
3851
3852 " EndPrimitive();\n"
3853 "}\n";
3854
3855
3856 static const char *fragShaderText =
3857 "#version 140\n"
3858 "#extension GL_ARB_separate_shader_objects : enable\n"
3859 "#extension GL_ARB_shading_language_420pack : enable\n"
3860
3861 "layout(location = 0) in vec3 in_a;\n"
3862 "layout(location = 1) in vec3 in_b;\n"
3863 "layout(location = 2) in vec3 in_c;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003864 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003865
3866 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06003867 " outColor = vec4(in_a.x, in_b.y, in_c.z, 1.0);\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003868 "}\n";
3869
3870
3871
3872 ASSERT_NO_FATAL_FAILURE(InitState());
3873 ASSERT_NO_FATAL_FAILURE(InitViewport());
3874
3875 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3876 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3877 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3878
3879 VkPipelineObj pipelineobj(m_device);
3880 pipelineobj.AddShader(&vs);
3881 pipelineobj.AddShader(&gs);
3882 pipelineobj.AddShader(&ps);
3883
3884 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3885 VkCommandBufferObj cmdBuffer(m_device);
3886 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3887
3888 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3889
3890 VkDescriptorSetObj descriptorSet(m_device);
3891
3892 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3893
3894 // render triangle
3895 cmdBuffer.Draw(0, 3, 0, 1);
3896
3897 // finalize recording of the command buffer
3898 EndCommandBuffer(cmdBuffer);
3899 cmdBuffer.QueueCommandBuffer();
3900
3901 RecordImages(m_renderTargets);
3902}
3903
GregFd6ebdb32015-06-03 18:40:50 -06003904#endif
3905
Cody Northropa44c2ff2015-04-15 11:19:06 -06003906TEST_F(VkRenderTest, GSTriStrip)
3907{
3908 // This test emits multiple multiple triangles using a GS
3909 // Correct result is an multicolor circle
3910
3911 static const char *vertShaderText =
3912 "#version 140\n"
3913 "#extension GL_ARB_separate_shader_objects : enable\n"
3914 "#extension GL_ARB_shading_language_420pack : enable\n"
3915
3916 "void main() {\n"
3917
3918 // generic position stuff
3919 " vec2 vertices;\n"
3920 " int vertexSelector = gl_VertexID;\n"
3921 " if (vertexSelector == 0)\n"
3922 " vertices = vec2(-0.5, -0.5);\n"
3923 " else if (vertexSelector == 1)\n"
3924 " vertices = vec2( 0.5, -0.5);\n"
3925 " else if (vertexSelector == 2)\n"
3926 " vertices = vec2( 0.5, 0.5);\n"
3927 " else\n"
3928 " vertices = vec2( 0.0, 0.0);\n"
3929 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3930
3931 "}\n";
3932
3933 static const char *geomShaderText =
3934 "#version 330\n"
3935 "#extension GL_ARB_separate_shader_objects : enable\n"
3936 "#extension GL_ARB_shading_language_420pack : enable\n"
3937 "layout( triangles ) in;\n"
3938 "layout( triangle_strip, max_vertices = 18 ) out;\n"
3939
3940 "layout(location = 0) out vec4 outColor;\n"
3941
3942 "void main()\n"
3943 "{\n"
3944 // init with first position to get zw
3945 " gl_Position = gl_in[0].gl_Position;\n"
3946
3947 " vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
3948 " vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
3949 " vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
3950 " vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
3951
3952 // different color per tri
3953 " vec4[6] colors = { red, white, \n"
3954 " yellow, white, \n"
3955 " blue, white }; \n"
3956
3957 // fan out the triangles
3958 " vec2[18] positions = { vec2(0.0, 0.0), vec2(-0.5, 0.0), vec2(-0.25, -0.5), \n"
3959 " vec2(0.0, 0.0), vec2(-0.25, -0.5), vec2( 0.25, -0.5), \n"
3960 " vec2(0.0, 0.0), vec2( 0.25, -0.5), vec2( 0.5, 0.0), \n"
3961 " vec2(0.0, 0.0), vec2( 0.5, 0.0), vec2( 0.25, 0.5), \n"
3962 " vec2(0.0, 0.0), vec2( 0.25, 0.5), vec2(-0.25, 0.5), \n"
3963 " vec2(0.0, 0.0), vec2(-0.25, 0.5), vec2(-0.5, 0.0) }; \n"
3964
3965 // make a triangle list of 6
3966 " for (int i = 0; i < 6; ++i) { \n"
3967 " outColor = colors[i]; \n"
3968 " for (int j = 0; j < 3; ++j) { \n"
3969 " gl_Position.xy = positions[i * 3 + j]; \n"
3970 " EmitVertex(); \n"
3971 " } \n"
3972 " EndPrimitive();\n"
3973 " } \n"
3974
3975 "}\n";
3976
3977
3978 static const char *fragShaderText =
3979 "#version 150\n"
3980 "#extension GL_ARB_separate_shader_objects : enable\n"
3981 "#extension GL_ARB_shading_language_420pack : enable\n"
3982
3983
3984 "layout(binding = 0) uniform windowDimensions {\n"
3985 " vec4 dimensions;\n"
3986 "};\n"
3987
3988 "layout(location = 0) in vec4 inColor;\n"
3989 "layout(origin_upper_left) in vec4 gl_FragCoord;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003990 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003991
3992 "void main() {\n"
3993
3994 // discard to make a nice circle
3995 " vec2 pos = abs(gl_FragCoord.xy) - vec2(dimensions.x, dimensions.y) / 2;\n"
3996 " float dist = sqrt(dot(pos, pos));\n"
3997 " if (dist > 50.0)\n"
3998 " discard;\n"
3999
GregFd6ebdb32015-06-03 18:40:50 -06004000 " outColor = inColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06004001
4002 "}\n";
4003
4004
4005
4006 ASSERT_NO_FATAL_FAILURE(InitState());
4007 ASSERT_NO_FATAL_FAILURE(InitViewport());
4008
4009 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
4010 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
4011 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
4012
4013 VkPipelineObj pipelineobj(m_device);
4014 pipelineobj.AddShader(&vs);
4015 pipelineobj.AddShader(&gs);
4016 pipelineobj.AddShader(&ps);
4017
4018 const float dimensions[4] = { VkRenderFramework::m_width, VkRenderFramework::m_height , 0.0, 0.0};
4019
4020 VkConstantBufferObj windowDimensions(m_device, sizeof(dimensions) / sizeof(dimensions[0]), sizeof(dimensions[0]), (const void*) dimensions);
4021
4022 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4023 VkCommandBufferObj cmdBuffer(m_device);
4024 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
4025
4026 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
4027
4028 VkDescriptorSetObj descriptorSet(m_device);
4029 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, windowDimensions);
4030
4031 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
4032
4033 // render triangle
4034 cmdBuffer.Draw(0, 3, 0, 1);
4035
4036 // finalize recording of the command buffer
4037 EndCommandBuffer(cmdBuffer);
4038 cmdBuffer.QueueCommandBuffer();
4039
4040 RecordImages(m_renderTargets);
4041}
4042
Chris Forbes23e6db62015-06-15 09:32:35 +12004043TEST_F(VkRenderTest, RenderPassLoadOpClear)
4044{
4045 ASSERT_NO_FATAL_FAILURE(InitState());
4046 ASSERT_NO_FATAL_FAILURE(InitViewport());
4047
4048 /* clear via load op to full green */
4049 m_clear_via_load_op = true;
4050 m_clear_color.useRawValue = false;
4051 m_clear_color.color.floatColor[0] = 0;
4052 m_clear_color.color.floatColor[1] = 1;
4053 m_clear_color.color.floatColor[2] = 0;
4054 m_clear_color.color.floatColor[3] = 0;
4055 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4056
4057 VkCommandBufferObj cmdBuffer(m_device);
4058 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
4059 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
4060 /* This command buffer contains ONLY the load op! */
4061 EndCommandBuffer(cmdBuffer);
4062 cmdBuffer.QueueCommandBuffer();
4063
4064 RecordImages(m_renderTargets);
4065}
4066
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004067int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004068 int result;
4069
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004070 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06004071 VkTestFramework::InitArgs(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004072
Chia-I Wu7133fdc2014-12-15 23:57:34 +08004073 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06004074
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004075 result = RUN_ALL_TESTS();
4076
Tony Barbour01999182015-04-09 12:58:51 -06004077 VkTestFramework::Finish();
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004078 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004079}