blob: 02427a9560cbd80cb410de5cd5cf99a3ee4f94f1 [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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060071#include <vk_debug_report_lunarg.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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060097 case VK_DBG_REPORT_ERROR_BIT:
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()) {
Chia-I Wuc278df82015-07-07 11:50:03 +0800318 cmdBuffer.BeginRenderPass(renderPassBeginInfo());
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600319 }
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()) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +0800329 cmdBuffer.EndRenderPass();
Chris Forbesfe133ef2015-06-16 14:05:59 +1200330 }
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 Barbour6d841032015-07-21 17:00:26 -0600340 if (!m_clear_via_load_op) {
341 if (m_depthStencil->Initialized()) {
342 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
343 } else {
344 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
345 }
Tony Barbour17c6ab12015-03-27 17:03:18 -0600346 }
347
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700348 cmdBuffer->PrepareAttachments();
Tony Barboure84a8d62015-07-10 14:10:27 -0600349 cmdBuffer->BindDynamicRasterState(m_stateRaster);
350 cmdBuffer->BindDynamicViewportState(m_stateViewport);
351 cmdBuffer->BindDynamicColorBlendState(m_colorBlend);
352 cmdBuffer->BindDynamicDepthStencilState(m_stateDepthStencil);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600353 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
Chia-I Wuc278df82015-07-07 11:50:03 +0800354 pipelineobj.CreateVKPipeline(descriptorSet, renderPass());
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600355 cmdBuffer->BindPipeline(pipelineobj);
Chia-I Wu862c5572015-03-28 15:23:55 +0800356 cmdBuffer->BindDescriptorSet(descriptorSet);
Tony Barbour02472db2015-01-08 17:08:28 -0700357}
Tony Barbourf43b6982014-11-25 13:18:32 -0700358
Tony Barbour01999182015-04-09 12:58:51 -0600359void VkRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
360 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer)
Tony Barbourdd4c9642015-01-09 12:55:14 -0700361{
362 int i;
363 glm::mat4 MVP;
364 int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600365 VkResult err;
Tony Barbourdd4c9642015-01-09 12:55:14 -0700366
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600367 /* Only do 3 positions to avoid back face cull */
368 for (i = 0; i < 3; i++) {
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800369 void *pData = constantBuffer->memory().map();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700370
371 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
372 MVP = Projection * View * Model;
373 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
374
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800375 constantBuffer->memory().unmap();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700376
377 // submit the command buffer to the universal queue
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600378 cmdBuffer->QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700379
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600380 err = vkQueueWaitIdle( m_device->m_queue );
381 ASSERT_VK_SUCCESS( err );
Tony Barbourdd4c9642015-01-09 12:55:14 -0700382
383 // Wait for work to finish before cleaning up.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600384 vkDeviceWaitIdle(m_device->device());
Tony Barbourdd4c9642015-01-09 12:55:14 -0700385
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700386 assert(m_renderTargets.size() == 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -0700387 RecordImage(m_renderTargets[0]);
388 }
389}
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600390
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600391void dumpMatrix(const char *note, glm::mat4 MVP)
392{
Chia-I Wu7133fdc2014-12-15 23:57:34 +0800393 int i;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600394
395 printf("%s: \n", note);
396 for (i=0; i<4; i++) {
397 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
398 }
399 printf("\n");
400 fflush(stdout);
401}
402
403void dumpVec4(const char *note, glm::vec4 vector)
404{
405 printf("%s: \n", note);
406 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
407 printf("\n");
408 fflush(stdout);
409}
410
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600411struct vktriangle_vs_uniform {
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600412 // Must start with MVP
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600413 float mvp[4][4];
414 float position[3][4];
415 float color[3][4];
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600416};
417
Tony Barbour01999182015-04-09 12:58:51 -0600418void VkRenderTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600419{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700420#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600421 vkDbgRegisterMsgCallback(inst, myDbgFunc, NULL);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700422#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600423 // Create identity matrix
424 int i;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600425 struct vktriangle_vs_uniform data;
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600426
427 glm::mat4 Projection = glm::mat4(1.0f);
428 glm::mat4 View = glm::mat4(1.0f);
429 glm::mat4 Model = glm::mat4(1.0f);
430 glm::mat4 MVP = Projection * View * Model;
431 const int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600432 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600433 memcpy(&data.mvp, &MVP[0][0], matrixSize);
434
435 static const Vertex tri_data[] =
436 {
437 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
438 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
439 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
440 };
441
442 for (i=0; i<3; i++) {
443 data.position[i][0] = tri_data[i].posX;
444 data.position[i][1] = tri_data[i].posY;
445 data.position[i][2] = tri_data[i].posZ;
446 data.position[i][3] = tri_data[i].posW;
447 data.color[i][0] = tri_data[i].r;
448 data.color[i][1] = tri_data[i].g;
449 data.color[i][2] = tri_data[i].b;
450 data.color[i][3] = tri_data[i].a;
451 }
452
Tony Barbourf43b6982014-11-25 13:18:32 -0700453 ASSERT_NO_FATAL_FAILURE(InitState());
454 ASSERT_NO_FATAL_FAILURE(InitViewport());
455
Tony Barbour01999182015-04-09 12:58:51 -0600456 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barbourf43b6982014-11-25 13:18:32 -0700457
Tony Barbour01999182015-04-09 12:58:51 -0600458 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
459 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700460
Tony Barbour01999182015-04-09 12:58:51 -0600461 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800462 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -0700463 pipelineobj.AddShader(&vs);
464 pipelineobj.AddShader(&ps);
465
Tony Barbour01999182015-04-09 12:58:51 -0600466 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600467 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700468
Tony Barbour71ba3612015-01-09 16:12:35 -0700469 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600470 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour71ba3612015-01-09 16:12:35 -0700471 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700472
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600473 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour71ba3612015-01-09 16:12:35 -0700474
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600475 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour71ba3612015-01-09 16:12:35 -0700476#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600477 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour71ba3612015-01-09 16:12:35 -0700478 pDSDumpDot((char*)"triTest2.dot");
479#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600480
Tony Barbour71ba3612015-01-09 16:12:35 -0700481 // render triangle
482 cmdBuffer.Draw(0, 3, 0, 1);
483
484 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600485 EndCommandBuffer(cmdBuffer);
486
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600487 cmdBuffer.QueueCommandBuffer();
Tony Barbour71ba3612015-01-09 16:12:35 -0700488
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600489 RecordImages(m_renderTargets);
Tony Barbour71ba3612015-01-09 16:12:35 -0700490
491 if (rotate)
Tobin Ehlis12ee35f2015-03-26 08:23:25 -0600492 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
Tony Barbour71ba3612015-01-09 16:12:35 -0700493
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700494#ifdef PRINT_OBJECTS
Mark Lobodzinski4e5016f2015-05-05 15:01:37 -0500495 OBJ_TRACK_GET_OBJECTS_COUNT pObjTrackGetObjectsCount = (OBJ_TRACK_GET_OBJECTS_COUNT)vkGetProcAddr(gpu(), (char*)"objTrackGetObjectsCount");
Mark Lobodzinski14305ad2015-06-23 11:35:12 -0600496 uint64_t numObjects = pObjTrackGetObjectsCount(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600497 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700498 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600499 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700500 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
Mark Lobodzinski14305ad2015-06-23 11:35:12 -0600501 pObjTrackGetObjs(m_device, numObjects, pObjNodeArray);
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700502 for (i=0; i < numObjects; i++) {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600503 printf("Object %i of type %s has objID (%p) and %lu uses\n", i, string_VkObjectType(pObjNodeArray[i].objType), pObjNodeArray[i].pObj, pObjNodeArray[i].numUses);
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700504 }
505 free(pObjNodeArray);
506#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700507
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600508}
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}
Cody Northrop71727d22015-06-23 13:25:51 -0600586
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}
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600626
Tony Barbour01999182015-04-09 12:58:51 -0600627TEST_F(VkRenderTest, SPV_GreenTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700628{
Tony Barbourf43b6982014-11-25 13:18:32 -0700629 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";
638
639 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"
Tony Barbourf43b6982014-11-25 13:18:32 -0700644 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600645 " outColor = vec4(0,1,0,1);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700646 "}\n";
647
Cody Northropacfb0492015-03-17 15:55:58 -0600648 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700649
Cody Northrop1cfbd172015-06-03 16:49:20 -0600650 ScopedUseGlsl useGlsl(false);
651
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600652 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700653}
Cody Northrop71727d22015-06-23 13:25:51 -0600654
Tony Barbour01999182015-04-09 12:58:51 -0600655TEST_F(VkRenderTest, YellowTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700656{
657 static const char *vertShaderText =
658 "#version 130\n"
659 "void main() {\n"
660 " vec2 vertices[3];"
661 " vertices[0] = vec2(-0.5, -0.5);\n"
662 " vertices[1] = vec2( 0.5, -0.5);\n"
663 " vertices[2] = vec2( 0.5, 0.5);\n"
664 " vec4 colors[3];\n"
665 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
666 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
667 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
668 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
669 "}\n";
670
671 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600672 "#version 140\n"
673 "#extension GL_ARB_separate_shader_objects : enable\n"
674 "#extension GL_ARB_shading_language_420pack : enable\n"
675 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700676 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600677 " outColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700678 "}\n";
679
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600680 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700681}
682
Tony Barbour01999182015-04-09 12:58:51 -0600683TEST_F(VkRenderTest, QuadWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600684{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600685 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600686 "#version 140\n"
687 "#extension GL_ARB_separate_shader_objects : enable\n"
688 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700689 //XYZ1( -1, -1, -1 )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600690 "layout (location = 0) in vec4 pos;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700691 //XYZ1( 0.f, 0.f, 0.f )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600692 "layout (location = 1) in vec4 inColor;\n"
693 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600694 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600695 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600696 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600697 "}\n";
698
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600699
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600700 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700701 "#version 140\n"
702 "#extension GL_ARB_separate_shader_objects : enable\n"
703 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600704 "layout (location = 0) in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700705 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600706 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700707 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600708 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600709
Tony Barbourf43b6982014-11-25 13:18:32 -0700710
711
712 ASSERT_NO_FATAL_FAILURE(InitState());
713 ASSERT_NO_FATAL_FAILURE(InitViewport());
714
Tony Barbour01999182015-04-09 12:58:51 -0600715 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000716 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700717
Tony Barbour01999182015-04-09 12:58:51 -0600718 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
719 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700720
Tony Barbour01999182015-04-09 12:58:51 -0600721 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800722 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -0700723 pipelineobj.AddShader(&vs);
724 pipelineobj.AddShader(&ps);
725
Tony Barbour01999182015-04-09 12:58:51 -0600726 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600727 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -0600728
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600729#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600730 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600731 MESH_BIND_ID, // binding ID
Tony Barbourf43b6982014-11-25 13:18:32 -0700732 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600733 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -0700734 };
735
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600736 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600737 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
738 vi_attribs[0].location = 0; // location, position
Tony Barbour8205d902015-04-16 15:59:00 -0600739 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600740 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
741 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
742 vi_attribs[1].location = 1; // location, color
Tony Barbour8205d902015-04-16 15:59:00 -0600743 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600744 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 -0700745
746 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
747 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600748 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -0700749
Tony Barboure4ed9942015-01-09 10:06:53 -0700750 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600751 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700752 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700753
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600754 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600755
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600756 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700757
Tony Barboure4ed9942015-01-09 10:06:53 -0700758 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
759
760 // render two triangles
761 cmdBuffer.Draw(0, 6, 0, 1);
762
763 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600764 EndCommandBuffer(cmdBuffer);
765
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600766 cmdBuffer.QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -0700767
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600768 RecordImages(m_renderTargets);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600769}
770
Tony Barbour01999182015-04-09 12:58:51 -0600771TEST_F(VkRenderTest, TriangleMRT)
Chia-I Wue09d1a72014-12-05 10:32:23 +0800772{
773 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600774 "#version 140\n"
775 "#extension GL_ARB_separate_shader_objects : enable\n"
776 "#extension GL_ARB_shading_language_420pack : enable\n"
777 "layout (location = 0) in vec4 pos;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800778 "void main() {\n"
779 " gl_Position = pos;\n"
780 "}\n";
781
782 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600783 "#version 140\n"
784 "#extension GL_ARB_separate_shader_objects : enable\n"
785 "#extension GL_ARB_shading_language_420pack : enable\n"
786 "layout (location = 0) out vec4 uFragData0;\n"
787 "layout (location = 1) out vec4 uFragData1;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800788 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600789 " uFragData0 = vec4(1.0, 0.0, 0.0, 1.0);\n"
790 " uFragData1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800791 "}\n";
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600792 const float vb_data[][2] = {
Chia-I Wue09d1a72014-12-05 10:32:23 +0800793 { -1.0f, -1.0f },
794 { 1.0f, -1.0f },
795 { -1.0f, 1.0f }
796 };
797
798 ASSERT_NO_FATAL_FAILURE(InitState());
799 ASSERT_NO_FATAL_FAILURE(InitViewport());
800
Tony Barbour01999182015-04-09 12:58:51 -0600801 VkConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000802 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800803
Tony Barbour01999182015-04-09 12:58:51 -0600804 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
805 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800806
Tony Barbour01999182015-04-09 12:58:51 -0600807 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800808 pipelineobj.AddColorAttachment();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800809 pipelineobj.AddShader(&vs);
810 pipelineobj.AddShader(&ps);
811
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600812#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600813 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600814 MESH_BUF_ID, // Binding ID
815 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600816 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Chia-I Wue09d1a72014-12-05 10:32:23 +0800817 };
818
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600819 VkVertexInputAttributeDescription vi_attrib;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600820 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
821 vi_attrib.location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -0600822 vi_attrib.format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600823 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
Chia-I Wue09d1a72014-12-05 10:32:23 +0800824
825 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
826 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600827 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800828
Tony Barbour01999182015-04-09 12:58:51 -0600829 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600830 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800831
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700832 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
Chia-I Wue09d1a72014-12-05 10:32:23 +0800833
Tony Barboure307f582015-07-10 15:29:03 -0600834 VkPipelineColorBlendAttachmentState att = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600835 att.blendEnable = VK_FALSE;
Chia-I Wue09d1a72014-12-05 10:32:23 +0800836 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700837 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800838
Tony Barbour01999182015-04-09 12:58:51 -0600839 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700840
Tony Barbour5ed79702015-01-07 14:31:52 -0700841 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
842 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barboure4ed9942015-01-09 10:06:53 -0700843
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600844 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour5ed79702015-01-07 14:31:52 -0700845
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600846 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700847
Tony Barbour5ed79702015-01-07 14:31:52 -0700848 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700849#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600850 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour5ed79702015-01-07 14:31:52 -0700851 pDSDumpDot((char*)"triTest2.dot");
852#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600853
Tony Barbour5ed79702015-01-07 14:31:52 -0700854 // render triangle
855 cmdBuffer.Draw(0, 3, 0, 1);
856
857 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600858 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600859 cmdBuffer.QueueCommandBuffer();
Tony Barbour5ed79702015-01-07 14:31:52 -0700860
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600861 RecordImages(m_renderTargets);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800862}
863
Tony Barbour01999182015-04-09 12:58:51 -0600864TEST_F(VkRenderTest, QuadWithIndexedVertexFetch)
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700865{
866 static const char *vertShaderText =
867 "#version 140\n"
868 "#extension GL_ARB_separate_shader_objects : enable\n"
869 "#extension GL_ARB_shading_language_420pack : enable\n"
870 "layout(location = 0) in vec4 pos;\n"
871 "layout(location = 1) in vec4 inColor;\n"
872 "layout(location = 0) out vec4 outColor;\n"
873 "void main() {\n"
874 " outColor = inColor;\n"
875 " gl_Position = pos;\n"
876 "}\n";
877
878
879 static const char *fragShaderText =
880 "#version 140\n"
881 "#extension GL_ARB_separate_shader_objects : enable\n"
882 "#extension GL_ARB_shading_language_420pack : enable\n"
883 "layout(location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600884 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700885 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600886 " outColor = color;\n"
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700887 "}\n";
888
889 const Vertex g_vbData[] =
890 {
891 // first tri
892 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
893 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
894 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
895
896 // second tri
897 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
898 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
899 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
900 };
901
902 const uint16_t g_idxData[6] = {
903 0, 1, 2,
904 3, 4, 5,
905 };
906
907 ASSERT_NO_FATAL_FAILURE(InitState());
908 ASSERT_NO_FATAL_FAILURE(InitViewport());
909
Tony Barbour01999182015-04-09 12:58:51 -0600910 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000911 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700912
Tony Barbour01999182015-04-09 12:58:51 -0600913 VkIndexBufferObj indexBuffer(m_device);
Tony Barbour8205d902015-04-16 15:59:00 -0600914 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), VK_INDEX_TYPE_UINT16, g_idxData);
Mark Lobodzinskid30f82a2015-02-16 14:24:23 -0600915 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700916
Tony Barbour01999182015-04-09 12:58:51 -0600917 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
918 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700919
Tony Barbour01999182015-04-09 12:58:51 -0600920 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800921 pipelineobj.AddColorAttachment();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700922 pipelineobj.AddShader(&vs);
923 pipelineobj.AddShader(&ps);
924
Tony Barbour01999182015-04-09 12:58:51 -0600925 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600926 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
927 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, indexBuffer);
Tony Barbour83a83802015-04-02 15:43:15 -0600928
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700929
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600930#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600931 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600932 MESH_BIND_ID, // binding ID
933 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600934 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700935 };
936
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600937 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600938 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
939 vi_attribs[0].location = 0; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600940 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600941 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
942 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
943 vi_attribs[1].location = 1; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600944 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600945 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700946
947 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
948 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700949
950 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600951 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700952 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600953 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barboure4ed9942015-01-09 10:06:53 -0700954
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600955 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700956
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700957#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600958 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700959 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700960#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700961
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600962 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600963 cmdBuffer.BindIndexBuffer(&indexBuffer, 0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700964
965 // render two triangles
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700966 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700967
968 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600969 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600970 cmdBuffer.QueueCommandBuffer();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700971
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600972 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700973}
974
Tony Barbour01999182015-04-09 12:58:51 -0600975TEST_F(VkRenderTest, GreyandRedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -0700976{
977 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -0700978
GregF6bef1212014-12-02 15:41:44 -0700979 static const char *vertShaderText =
980 "#version 140\n"
981 "#extension GL_ARB_separate_shader_objects : enable\n"
982 "#extension GL_ARB_shading_language_420pack : enable\n"
983 "layout (location = 0) in vec4 pos;\n"
984 "layout (location = 0) out vec4 outColor;\n"
985 "layout (location = 1) out vec4 outColor2;\n"
986 "void main() {\n"
987 " gl_Position = pos;\n"
988 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
989 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
990 "}\n";
991
992 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -0700993 "#version 330\n"
994 "#extension GL_ARB_separate_shader_objects : enable\n"
995 "#extension GL_ARB_shading_language_420pack : enable\n"
996 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
997 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
998 "layout (location = 0) in vec4 color;\n"
999 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001000 "layout (location = 0) out vec4 outColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001001 "void main() {\n"
1002 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1003 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001004 " outColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001005 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1006 " : color2;\n"
1007 "}\n";
1008
1009 ASSERT_NO_FATAL_FAILURE(InitState());
1010 ASSERT_NO_FATAL_FAILURE(InitViewport());
1011
Tony Barbour01999182015-04-09 12:58:51 -06001012 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001013 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001014
Tony Barbour01999182015-04-09 12:58:51 -06001015 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1016 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001017
Tony Barbour01999182015-04-09 12:58:51 -06001018 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001019 pipelineobj.AddColorAttachment();
GregF6bef1212014-12-02 15:41:44 -07001020 pipelineobj.AddShader(&vs);
1021 pipelineobj.AddShader(&ps);
1022
Tony Barbour01999182015-04-09 12:58:51 -06001023 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001024 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001025
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001026#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001027 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001028 MESH_BIND_ID, // binding ID
1029 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001030 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001031 };
1032
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001033 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001034 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1035 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001036 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001037 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001038
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001039 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001040 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001041 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001042
Tony Barbourdd4c9642015-01-09 12:55:14 -07001043 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001044 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001045 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1046
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001047 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001048
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001049 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001050
1051 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1052#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001053 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001054 pDSDumpDot((char*)"triTest2.dot");
1055#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001056
Tony Barbourdd4c9642015-01-09 12:55:14 -07001057 // render triangle
1058 cmdBuffer.Draw(0, 6, 0, 1);
1059
1060 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001061 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001062 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001063
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001064 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001065}
1066
Tony Barbour01999182015-04-09 12:58:51 -06001067TEST_F(VkRenderTest, RedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -07001068{
1069 // This tests that we correctly handle unread fragment inputs
1070
1071 static const char *vertShaderText =
1072 "#version 140\n"
1073 "#extension GL_ARB_separate_shader_objects : enable\n"
1074 "#extension GL_ARB_shading_language_420pack : enable\n"
1075 "layout (location = 0) in vec4 pos;\n"
1076 "layout (location = 0) out vec4 outColor;\n"
1077 "layout (location = 1) out vec4 outColor2;\n"
1078 "void main() {\n"
1079 " gl_Position = pos;\n"
1080 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1081 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1082 "}\n";
1083
1084 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001085 "#version 330\n"
1086 "#extension GL_ARB_separate_shader_objects : enable\n"
1087 "#extension GL_ARB_shading_language_420pack : enable\n"
1088 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1089 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1090 "layout (location = 0) in vec4 color;\n"
1091 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001092 "layout (location = 0) out vec4 outColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001093 "void main() {\n"
1094 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1095 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001096 " outColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001097 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1098 " : color2;\n"
1099 "}\n";
1100
1101 ASSERT_NO_FATAL_FAILURE(InitState());
1102 ASSERT_NO_FATAL_FAILURE(InitViewport());
1103
Tony Barbour01999182015-04-09 12:58:51 -06001104 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001105 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001106
Tony Barbour01999182015-04-09 12:58:51 -06001107 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1108 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001109
Tony Barbour01999182015-04-09 12:58:51 -06001110 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001111 pipelineobj.AddColorAttachment();
GregF6bef1212014-12-02 15:41:44 -07001112 pipelineobj.AddShader(&vs);
1113 pipelineobj.AddShader(&ps);
1114
Tony Barbour01999182015-04-09 12:58:51 -06001115 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001116 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001117
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001118#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001119 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001120 MESH_BIND_ID, // binding ID
1121 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001122 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001123 };
1124
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001125 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001126 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1127 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001128 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001129 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001130
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001131 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001132 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001133 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001134
Tony Barbourdd4c9642015-01-09 12:55:14 -07001135 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001136 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001137 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1138
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001139 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001140
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001141 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001142
1143 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1144#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001145 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001146 pDSDumpDot((char*)"triTest2.dot");
1147#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001148 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001149 cmdBuffer.Draw(0, 6, 0, 1);
1150
1151 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001152 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001153 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001154
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001155 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001156}
1157
Tony Barbour01999182015-04-09 12:58:51 -06001158TEST_F(VkRenderTest, GreyCirclesonBlueFade)
GregF6bef1212014-12-02 15:41:44 -07001159{
1160 // This tests reading gl_ClipDistance from FS
1161
1162 static const char *vertShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001163 //"#version 140\n"
GregF6bef1212014-12-02 15:41:44 -07001164 "#version 330\n"
1165 "#extension GL_ARB_separate_shader_objects : enable\n"
1166 "#extension GL_ARB_shading_language_420pack : enable\n"
1167 "out gl_PerVertex {\n"
1168 " vec4 gl_Position;\n"
1169 " float gl_ClipDistance[1];\n"
1170 "};\n"
1171 "layout (location = 0) in vec4 pos;\n"
1172 "layout (location = 0) out vec4 outColor;\n"
1173 "layout (location = 1) out vec4 outColor2;\n"
1174 "void main() {\n"
1175 " gl_Position = pos;\n"
1176 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1177 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1178 " float dists[3];\n"
1179 " dists[0] = 0.0;\n"
1180 " dists[1] = 1.0;\n"
1181 " dists[2] = 1.0;\n"
1182 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1183 "}\n";
1184
1185
1186 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001187 "#version 140\n"
1188 //"#version 330\n"
GregF6bef1212014-12-02 15:41:44 -07001189 "#extension GL_ARB_separate_shader_objects : enable\n"
1190 "#extension GL_ARB_shading_language_420pack : enable\n"
1191 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1192 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1193 "layout (location = 0) in vec4 color;\n"
1194 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001195 "layout (location = 0) out vec4 uFragColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001196 "void main() {\n"
1197 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1198 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001199 " uFragColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001200 " ? color * gl_ClipDistance[0]\n"
1201 " : color2;\n"
1202 "}\n";
1203
1204 ASSERT_NO_FATAL_FAILURE(InitState());
1205 ASSERT_NO_FATAL_FAILURE(InitViewport());
1206
Tony Barbour01999182015-04-09 12:58:51 -06001207 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001208 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001209
Tony Barbour01999182015-04-09 12:58:51 -06001210 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1211 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001212
Tony Barbour01999182015-04-09 12:58:51 -06001213 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001214 pipelineobj.AddColorAttachment();
GregF6bef1212014-12-02 15:41:44 -07001215 pipelineobj.AddShader(&vs);
1216 pipelineobj.AddShader(&ps);
1217
Tony Barbour01999182015-04-09 12:58:51 -06001218 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001219 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001220
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001221#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001222 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001223 MESH_BIND_ID, // binding ID
1224 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001225 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001226 };
1227
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001228 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001229 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1230 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001231 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001232 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001233
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001234 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001235 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001236 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001237
Tony Barbourdd4c9642015-01-09 12:55:14 -07001238 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001239 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001240 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF6bef1212014-12-02 15:41:44 -07001241
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001242 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001243
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001244 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001245
1246 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1247#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001248 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001249 pDSDumpDot((char*)"triTest2.dot");
1250#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001251
1252 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001253 cmdBuffer.Draw(0, 6, 0, 1);
1254
1255 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001256 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001257 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001258
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001259 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001260}
Tony Barbourf43b6982014-11-25 13:18:32 -07001261
Tony Barbour01999182015-04-09 12:58:51 -06001262TEST_F(VkRenderTest, GreyCirclesonBlueDiscard)
GregF7a23c792014-12-02 17:19:34 -07001263{
1264 static const char *vertShaderText =
1265 "#version 140\n"
1266 "#extension GL_ARB_separate_shader_objects : enable\n"
1267 "#extension GL_ARB_shading_language_420pack : enable\n"
1268 "layout (location = 0) in vec4 pos;\n"
1269 "layout (location = 0) out vec4 outColor;\n"
1270 "layout (location = 1) out vec4 outColor2;\n"
1271 "void main() {\n"
1272 " gl_Position = pos;\n"
1273 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1274 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1275 "}\n";
1276
1277
1278 static const char *fragShaderText =
GregF7a23c792014-12-02 17:19:34 -07001279 "#version 330\n"
1280 "#extension GL_ARB_separate_shader_objects : enable\n"
1281 "#extension GL_ARB_shading_language_420pack : enable\n"
1282 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1283 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1284 "layout (location = 0) in vec4 color;\n"
1285 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001286 "layout (location = 0) out vec4 outColor;\n"
GregF7a23c792014-12-02 17:19:34 -07001287 "void main() {\n"
1288 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1289 " float dist_squared = dot(pos, pos);\n"
1290 " if (dist_squared < 100.0)\n"
1291 " discard;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001292 " outColor = (dist_squared < 400.0)\n"
GregF7a23c792014-12-02 17:19:34 -07001293 " ? color\n"
1294 " : color2;\n"
1295 "}\n";
1296
1297 ASSERT_NO_FATAL_FAILURE(InitState());
1298 ASSERT_NO_FATAL_FAILURE(InitViewport());
1299
Tony Barbour01999182015-04-09 12:58:51 -06001300 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001301 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001302
Tony Barbour01999182015-04-09 12:58:51 -06001303 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1304 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF7a23c792014-12-02 17:19:34 -07001305
Tony Barbour01999182015-04-09 12:58:51 -06001306 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001307 pipelineobj.AddColorAttachment();
GregF7a23c792014-12-02 17:19:34 -07001308 pipelineobj.AddShader(&vs);
1309 pipelineobj.AddShader(&ps);
1310
Tony Barbour01999182015-04-09 12:58:51 -06001311 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001312 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001313
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001314#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001315 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001316 MESH_BIND_ID, // binding ID
1317 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001318 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF7a23c792014-12-02 17:19:34 -07001319 };
1320
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001321 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001322 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1323 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001324 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001325 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF7a23c792014-12-02 17:19:34 -07001326
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001327 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF7a23c792014-12-02 17:19:34 -07001328 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001329 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF7a23c792014-12-02 17:19:34 -07001330
Tony Barbourdd4c9642015-01-09 12:55:14 -07001331 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001332 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001333 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1334
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001335 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001336
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001337 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001338
1339 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1340#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001341 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001342 pDSDumpDot((char*)"triTest2.dot");
1343#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001344
1345 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001346 cmdBuffer.Draw(0, 6, 0, 1);
1347
1348 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001349 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001350 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001351
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001352 RecordImages(m_renderTargets);
GregF7a23c792014-12-02 17:19:34 -07001353}
1354
1355
Tony Barbour01999182015-04-09 12:58:51 -06001356TEST_F(VkRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001357{
1358 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001359 "#version 140\n"
1360 "#extension GL_ARB_separate_shader_objects : enable\n"
1361 "#extension GL_ARB_shading_language_420pack : enable\n"
1362 "\n"
1363 "layout(binding = 0) uniform buf {\n"
1364 " mat4 MVP;\n"
1365 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001366 "void main() {\n"
1367 " vec2 vertices[3];"
1368 " vertices[0] = vec2(-0.5, -0.5);\n"
1369 " vertices[1] = vec2( 0.5, -0.5);\n"
1370 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001371 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001372 "}\n";
1373
1374 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001375 "#version 140\n"
1376 "#extension GL_ARB_separate_shader_objects : enable\n"
1377 "#extension GL_ARB_shading_language_420pack : enable\n"
1378 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001379 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001380 " outColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001381 "}\n";
1382
Tony Barbourf43b6982014-11-25 13:18:32 -07001383 ASSERT_NO_FATAL_FAILURE(InitState());
1384 ASSERT_NO_FATAL_FAILURE(InitViewport());
1385
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001386 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001387 glm::mat4 Projection = glm::mat4(1.0f);
1388 glm::mat4 View = glm::mat4(1.0f);
1389 glm::mat4 Model = glm::mat4(1.0f);
1390 glm::mat4 MVP = Projection * View * Model;
1391 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1392
Tony Barbour01999182015-04-09 12:58:51 -06001393 VkConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1394 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1395 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001396
Tony Barbour01999182015-04-09 12:58:51 -06001397 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001398 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001399 pipelineobj.AddShader(&vs);
1400 pipelineobj.AddShader(&ps);
1401
1402 // Create descriptor set and attach the constant buffer to it
Tony Barbour01999182015-04-09 12:58:51 -06001403 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001404 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001405
Tony Barbourdd4c9642015-01-09 12:55:14 -07001406 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001407 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001408 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001409
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001410 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001411
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001412 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001413
1414 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1415#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001416 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001417 pDSDumpDot((char*)"triTest2.dot");
1418#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001419
1420 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001421 cmdBuffer.Draw(0, 6, 0, 1);
1422
1423 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001424 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001425 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001426
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001427 RecordImages(m_renderTargets);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001428
1429 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001430}
1431
Tony Barbour01999182015-04-09 12:58:51 -06001432TEST_F(VkRenderTest, MixTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07001433{
1434 // This tests location applied to varyings. Notice that we have switched foo
1435 // and bar in the FS. The triangle should be blended with red, green and blue
1436 // corners.
1437 static const char *vertShaderText =
1438 "#version 140\n"
1439 "#extension GL_ARB_separate_shader_objects : enable\n"
1440 "#extension GL_ARB_shading_language_420pack : enable\n"
1441 "layout (location=0) out vec4 bar;\n"
1442 "layout (location=1) out vec4 foo;\n"
1443 "layout (location=2) out float scale;\n"
1444 "vec2 vertices[3];\n"
1445 "void main() {\n"
1446 " vertices[0] = vec2(-1.0, -1.0);\n"
1447 " vertices[1] = vec2( 1.0, -1.0);\n"
1448 " vertices[2] = vec2( 0.0, 1.0);\n"
1449 "vec4 colors[3];\n"
1450 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1451 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1452 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1453 " foo = colors[gl_VertexID % 3];\n"
1454 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1455 " scale = 1.0;\n"
1456 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1457 "}\n";
1458
1459 static const char *fragShaderText =
1460 "#version 140\n"
1461 "#extension GL_ARB_separate_shader_objects : enable\n"
1462 "#extension GL_ARB_shading_language_420pack : enable\n"
1463 "layout (location = 1) in vec4 bar;\n"
1464 "layout (location = 0) in vec4 foo;\n"
1465 "layout (location = 2) in float scale;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001466 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001467 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001468 " outColor = bar * scale + foo * (1.0-scale);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001469 "}\n";
1470
1471 ASSERT_NO_FATAL_FAILURE(InitState());
1472 ASSERT_NO_FATAL_FAILURE(InitViewport());
1473
Tony Barbour01999182015-04-09 12:58:51 -06001474 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1475 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001476
Tony Barbour01999182015-04-09 12:58:51 -06001477 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001478 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001479 pipelineobj.AddShader(&vs);
1480 pipelineobj.AddShader(&ps);
1481
Tony Barbour01999182015-04-09 12:58:51 -06001482 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06001483 descriptorSet.AppendDummy();
Tony Barbourf43b6982014-11-25 13:18:32 -07001484
Tony Barbourdd4c9642015-01-09 12:55:14 -07001485 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001486 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001487 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1488
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001489 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001490
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001491 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001492
1493#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001494 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001495 pDSDumpDot((char*)"triTest2.dot");
1496#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001497
Tony Barbourdd4c9642015-01-09 12:55:14 -07001498 // render triangle
1499 cmdBuffer.Draw(0, 3, 0, 1);
1500
1501 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001502 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001503 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001504
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001505 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001506}
1507
Tony Barbour01999182015-04-09 12:58:51 -06001508TEST_F(VkRenderTest, QuadVertFetchAndVertID)
Tony Barbourf43b6982014-11-25 13:18:32 -07001509{
1510 // This tests that attributes work in the presence of gl_VertexID
1511
1512 static const char *vertShaderText =
1513 "#version 140\n"
1514 "#extension GL_ARB_separate_shader_objects : enable\n"
1515 "#extension GL_ARB_shading_language_420pack : enable\n"
1516 //XYZ1( -1, -1, -1 )
1517 "layout (location = 0) in vec4 pos;\n"
1518 //XYZ1( 0.f, 0.f, 0.f )
1519 "layout (location = 1) in vec4 inColor;\n"
1520 "layout (location = 0) out vec4 outColor;\n"
1521 "void main() {\n"
1522 " outColor = inColor;\n"
1523 " vec4 vertices[3];"
1524 " vertices[gl_VertexID % 3] = pos;\n"
1525 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1526 "}\n";
1527
1528
1529 static const char *fragShaderText =
1530 "#version 140\n"
1531 "#extension GL_ARB_separate_shader_objects : enable\n"
1532 "#extension GL_ARB_shading_language_420pack : enable\n"
1533 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001534 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001535 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001536 " outColor = color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001537 "}\n";
1538
1539 ASSERT_NO_FATAL_FAILURE(InitState());
1540 ASSERT_NO_FATAL_FAILURE(InitViewport());
1541
Tony Barbour01999182015-04-09 12:58:51 -06001542 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001543 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001544
Tony Barbour01999182015-04-09 12:58:51 -06001545 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1546 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001547
Tony Barbour01999182015-04-09 12:58:51 -06001548 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001549 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001550 pipelineobj.AddShader(&vs);
1551 pipelineobj.AddShader(&ps);
1552
Tony Barbour01999182015-04-09 12:58:51 -06001553 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001554 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001555
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001556#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001557 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001558 MESH_BUF_ID, // Binding ID
1559 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001560 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001561 };
1562
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001563 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001564 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1565 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001566 vi_attribs[0].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001567 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1568 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1569 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001570 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001571 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001572
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001573 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001574 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001575 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001576
Tony Barbourdd4c9642015-01-09 12:55:14 -07001577 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001578 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001579 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1580
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001581 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001582
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001583 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001584
1585 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1586#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001587 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001588 pDSDumpDot((char*)"triTest2.dot");
1589#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001590
1591 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001592 cmdBuffer.Draw(0, 6, 0, 1);
1593
1594 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001595 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001596 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001597
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001598 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001599}
1600
Tony Barbour01999182015-04-09 12:58:51 -06001601TEST_F(VkRenderTest, QuadSparseVertFetch)
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001602{
1603 // This tests that attributes work in the presence of gl_VertexID
1604
1605 static const char *vertShaderText =
1606 "#version 140\n"
1607 "#extension GL_ARB_separate_shader_objects : enable\n"
1608 "#extension GL_ARB_shading_language_420pack : enable\n"
1609 //XYZ1( -1, -1, -1 )
1610 "layout (location = 1) in vec4 pos;\n"
1611 "layout (location = 4) in vec4 inColor;\n"
1612 //XYZ1( 0.f, 0.f, 0.f )
1613 "layout (location = 0) out vec4 outColor;\n"
1614 "void main() {\n"
1615 " outColor = inColor;\n"
1616 " gl_Position = pos;\n"
1617 "}\n";
1618
1619
1620 static const char *fragShaderText =
1621 "#version 140\n"
1622 "#extension GL_ARB_separate_shader_objects : enable\n"
1623 "#extension GL_ARB_shading_language_420pack : enable\n"
1624 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001625 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001626 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001627 " outColor = color;\n"
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001628 "}\n";
1629
1630 ASSERT_NO_FATAL_FAILURE(InitState());
1631 ASSERT_NO_FATAL_FAILURE(InitViewport());
1632
1633 struct VDATA
1634 {
1635 float t1, t2, t3, t4; // filler data
1636 float posX, posY, posZ, posW; // Position data
1637 float r, g, b, a; // Color
1638 };
1639 const struct VDATA vData[] =
1640 {
1641 { XYZ1(0, 0, 0), XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
1642 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1643 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1644 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1645 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1646 { XYZ1(0, 0, 0), XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
1647 };
1648
Tony Barbour01999182015-04-09 12:58:51 -06001649 VkConstantBufferObj meshBuffer(m_device,sizeof(vData)/sizeof(vData[0]),sizeof(vData[0]), vData);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001650 meshBuffer.BufferMemoryBarrier();
1651
Tony Barbour01999182015-04-09 12:58:51 -06001652 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1653 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001654
Tony Barbour01999182015-04-09 12:58:51 -06001655 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001656 pipelineobj.AddColorAttachment();
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001657 pipelineobj.AddShader(&vs);
1658 pipelineobj.AddShader(&ps);
1659
Tony Barbour01999182015-04-09 12:58:51 -06001660 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001661 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001662
1663#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001664 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001665 MESH_BUF_ID, // Binding ID
1666 sizeof(vData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001667 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001668 };
1669
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001670 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001671 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1672 vi_attribs[0].location = 4;
Tony Barbour8205d902015-04-16 15:59:00 -06001673 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001674 vi_attribs[0].offsetInBytes = sizeof(float) * 4 * 2; // Offset of first element in bytes from base of vertex
1675 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1676 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001677 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001678 vi_attribs[1].offsetInBytes = sizeof(float) * 4 * 1; // Offset of first element in bytes from base of vertex
1679
1680 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
1681 pipelineobj.AddVertexInputBindings(&vi_binding, 1);
1682 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
1683
1684 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001685 VkCommandBufferObj cmdBuffer(m_device);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001686 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1687
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001688 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001689
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001690 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001691
1692 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BUF_ID);
1693#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001694 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001695 pDSDumpDot((char*)"triTest2.dot");
1696#endif
1697
1698 // render two triangles
1699 cmdBuffer.Draw(0, 6, 0, 1);
1700
1701 // finalize recording of the command buffer
1702 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001703 cmdBuffer.QueueCommandBuffer();
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001704
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001705 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001706}
1707
Tony Barbour01999182015-04-09 12:58:51 -06001708TEST_F(VkRenderTest, TriVertFetchDeadAttr)
Tony Barbourf43b6982014-11-25 13:18:32 -07001709{
1710 // This tests that attributes work in the presence of gl_VertexID
1711 // and a dead attribute in position 0. Draws a triangle with yellow,
1712 // red and green corners, starting at top and going clockwise.
1713
1714 static const char *vertShaderText =
1715 "#version 140\n"
1716 "#extension GL_ARB_separate_shader_objects : enable\n"
1717 "#extension GL_ARB_shading_language_420pack : enable\n"
1718 //XYZ1( -1, -1, -1 )
1719 "layout (location = 0) in vec4 pos;\n"
1720 //XYZ1( 0.f, 0.f, 0.f )
1721 "layout (location = 1) in vec4 inColor;\n"
1722 "layout (location = 0) out vec4 outColor;\n"
1723 "void main() {\n"
1724 " outColor = inColor;\n"
1725 " vec2 vertices[3];"
1726 " vertices[0] = vec2(-1.0, -1.0);\n"
1727 " vertices[1] = vec2( 1.0, -1.0);\n"
1728 " vertices[2] = vec2( 0.0, 1.0);\n"
1729 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1730 "}\n";
1731
1732
1733 static const char *fragShaderText =
1734 "#version 140\n"
1735 "#extension GL_ARB_separate_shader_objects : enable\n"
1736 "#extension GL_ARB_shading_language_420pack : enable\n"
1737 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001738 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001739 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001740 " outColor = color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001741 "}\n";
1742
1743 ASSERT_NO_FATAL_FAILURE(InitState());
1744 ASSERT_NO_FATAL_FAILURE(InitViewport());
1745
Tony Barbour01999182015-04-09 12:58:51 -06001746 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001747 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001748
Tony Barbour01999182015-04-09 12:58:51 -06001749 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1750 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001751
Tony Barbour01999182015-04-09 12:58:51 -06001752 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001753 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001754 pipelineobj.AddShader(&vs);
1755 pipelineobj.AddShader(&ps);
1756
Tony Barbour01999182015-04-09 12:58:51 -06001757 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001758 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001759
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001760#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001761 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001762 MESH_BUF_ID, // Binding ID
1763 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001764 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001765 };
1766
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001767 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001768 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1769 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001770 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001771 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1772 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1773 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001774 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001775 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001776
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001777 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001778 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001779 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001780
Tony Barbourdd4c9642015-01-09 12:55:14 -07001781 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001782 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001783 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001784
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001785 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001786
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001787 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001788
1789 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1790#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001791 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001792 pDSDumpDot((char*)"triTest2.dot");
1793#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001794
1795 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001796 cmdBuffer.Draw(0, 6, 0, 1);
1797
1798 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001799 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001800 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001801
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001802 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001803}
1804
Tony Barbour01999182015-04-09 12:58:51 -06001805TEST_F(VkRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001806{
1807 static const char *vertShaderText =
1808 "#version 140\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001809 "#extension GL_ARB_separate_shader_objects : enable\n"
1810 "#extension GL_ARB_shading_language_420pack : enable\n"
GregFd6ebdb32015-06-03 18:40:50 -06001811 "layout (std140, binding = 0) uniform bufferVals {\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001812 " mat4 mvp;\n"
1813 "} myBufferVals;\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001814 "layout (location = 0) in vec4 pos;\n"
1815 "layout (location = 1) in vec4 inColor;\n"
Cody Northrop74a2d2c2015-06-16 17:32:04 -06001816 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001817 "void main() {\n"
1818 " outColor = inColor;\n"
1819 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001820 " gl_Position.y = -gl_Position.y;\n"
1821 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001822 "}\n";
1823
1824 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001825 "#version 140\n"
1826 "#extension GL_ARB_separate_shader_objects : enable\n"
1827 "#extension GL_ARB_shading_language_420pack : enable\n"
1828 "layout (location = 0) in vec4 color;\n"
1829 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001830 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001831 " outColor = color;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001832 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001833 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001834
Tony Barbourf43b6982014-11-25 13:18:32 -07001835 glm::mat4 View = glm::lookAt(
1836 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1837 glm::vec3(0,0,0), // and looks at the origin
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001838 glm::vec3(0,-1,0) // Head is up (set to 0,-1,0 to look upside-down)
Tony Barbourf43b6982014-11-25 13:18:32 -07001839 );
1840
1841 glm::mat4 Model = glm::mat4(1.0f);
1842
1843 glm::mat4 MVP = Projection * View * Model;
1844
1845 ASSERT_NO_FATAL_FAILURE(InitState());
1846 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wu9e81ebb2015-07-09 10:16:34 +08001847 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Chia-I Wuc278df82015-07-07 11:50:03 +08001848 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height, m_depth_stencil_fmt);
Tony Barbourf43b6982014-11-25 13:18:32 -07001849
Tony Barbour01999182015-04-09 12:58:51 -06001850 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 -07001851 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1852
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001853 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07001854
Tony Barbour01999182015-04-09 12:58:51 -06001855 VkConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1856 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1857 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001858
Tony Barbour01999182015-04-09 12:58:51 -06001859 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001860 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001861 pipelineobj.AddShader(&vs);
1862 pipelineobj.AddShader(&ps);
1863
Tony Barboure307f582015-07-10 15:29:03 -06001864 VkPipelineDepthStencilStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001865 ds_state.depthTestEnable = VK_TRUE;
1866 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06001867 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001868 ds_state.depthBoundsEnable = VK_FALSE;
1869 ds_state.stencilTestEnable = VK_FALSE;
1870 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
1871 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
1872 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06001873 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001874 ds_state.front = ds_state.back;
1875 pipelineobj.SetDepthStencil(&ds_state);
1876
Tony Barbour01999182015-04-09 12:58:51 -06001877 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001878 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001879
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001880#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001881 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001882 MESH_BUF_ID, // Binding ID
1883 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001884 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001885 };
Tony Barbourf43b6982014-11-25 13:18:32 -07001886
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001887 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001888 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1889 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001890 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001891 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1892 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1893 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001894 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001895 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001896
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001897 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001898 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001899 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001900
Tony Barbour17c6ab12015-03-27 17:03:18 -06001901 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour17c6ab12015-03-27 17:03:18 -06001902
Tony Barbour01999182015-04-09 12:58:51 -06001903 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -07001904 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001905
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001906 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001907 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001908
Tony Barboure4ed9942015-01-09 10:06:53 -07001909 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1910#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001911 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barboure4ed9942015-01-09 10:06:53 -07001912 pDSDumpDot((char*)"triTest2.dot");
1913#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001914
1915 // render triangles
Tony Barboure4ed9942015-01-09 10:06:53 -07001916 cmdBuffer.Draw(0, 36, 0, 1);
1917
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001918
Tony Barboure4ed9942015-01-09 10:06:53 -07001919 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001920 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001921 cmdBuffer.QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -07001922
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001923 RecordImages(m_renderTargets);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001924}
1925
Tony Barbour01999182015-04-09 12:58:51 -06001926TEST_F(VkRenderTest, VSTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07001927{
1928 // The expected result from this test is a green and red triangle;
1929 // one red vertex on the left, two green vertices on the right.
1930 static const char *vertShaderText =
Cody Northrop74a2d2c2015-06-16 17:32:04 -06001931 "#version 140\n"
1932 "#extension GL_ARB_separate_shader_objects : enable\n"
1933 "#extension GL_ARB_shading_language_420pack : enable\n"
1934 "layout (location = 0) out vec4 texColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001935 "uniform sampler2D surface;\n"
1936 "void main() {\n"
1937 " vec2 vertices[3];"
1938 " vertices[0] = vec2(-0.5, -0.5);\n"
1939 " vertices[1] = vec2( 0.5, -0.5);\n"
1940 " vertices[2] = vec2( 0.5, 0.5);\n"
1941 " vec2 positions[3];"
1942 " positions[0] = vec2( 0.0, 0.0);\n"
1943 " positions[1] = vec2( 0.25, 0.1);\n"
1944 " positions[2] = vec2( 0.1, 0.25);\n"
1945 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1946 " texColor = textureLod(surface, samplePos, 0.0);\n"
1947 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1948 "}\n";
1949
1950 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001951 "#version 140\n"
1952 "#extension GL_ARB_separate_shader_objects : enable\n"
1953 "#extension GL_ARB_shading_language_420pack : enable\n"
1954 "layout (location = 0) in vec4 texColor;\n"
1955 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001956 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001957 " outColor = texColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001958 "}\n";
1959
1960 ASSERT_NO_FATAL_FAILURE(InitState());
1961 ASSERT_NO_FATAL_FAILURE(InitViewport());
1962
Tony Barbour01999182015-04-09 12:58:51 -06001963 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1964 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
1965 VkSamplerObj sampler(m_device);
1966 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001967
Tony Barbour01999182015-04-09 12:58:51 -06001968 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001969 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001970 pipelineobj.AddShader(&vs);
1971 pipelineobj.AddShader(&ps);
1972
Tony Barbour01999182015-04-09 12:58:51 -06001973 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001974 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001975
Tony Barbourdd4c9642015-01-09 12:55:14 -07001976 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001977 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001978 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001979
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001980 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001981
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001982 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001983
1984#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001985 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001986 pDSDumpDot((char*)"triTest2.dot");
1987#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001988
Tony Barbourdd4c9642015-01-09 12:55:14 -07001989 // render triangle
1990 cmdBuffer.Draw(0, 3, 0, 1);
1991
1992 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001993 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001994 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001995
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001996 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001997}
GregFd6ebdb32015-06-03 18:40:50 -06001998
1999
2000
Tony Barbour01999182015-04-09 12:58:51 -06002001TEST_F(VkRenderTest, TexturedTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002002{
2003 // The expected result from this test is a red and green checkered triangle
2004 static const char *vertShaderText =
2005 "#version 140\n"
2006 "#extension GL_ARB_separate_shader_objects : enable\n"
2007 "#extension GL_ARB_shading_language_420pack : enable\n"
2008 "layout (location = 0) out vec2 samplePos;\n"
2009 "void main() {\n"
2010 " vec2 vertices[3];"
2011 " vertices[0] = vec2(-0.5, -0.5);\n"
2012 " vertices[1] = vec2( 0.5, -0.5);\n"
2013 " vertices[2] = vec2( 0.5, 0.5);\n"
2014 " vec2 positions[3];"
2015 " positions[0] = vec2( 0.0, 0.0);\n"
2016 " positions[1] = vec2( 1.0, 0.0);\n"
2017 " positions[2] = vec2( 1.0, 1.0);\n"
2018 " samplePos = positions[gl_VertexID % 3];\n"
2019 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2020 "}\n";
2021
2022 static const char *fragShaderText =
2023 "#version 140\n"
2024 "#extension GL_ARB_separate_shader_objects : enable\n"
2025 "#extension GL_ARB_shading_language_420pack : enable\n"
2026 "layout (location = 0) in vec2 samplePos;\n"
2027 "layout (binding = 0) uniform sampler2D surface;\n"
2028 "layout (location=0) out vec4 outColor;\n"
2029 "void main() {\n"
2030 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2031 " outColor = texColor;\n"
2032 "}\n";
2033
2034 ASSERT_NO_FATAL_FAILURE(InitState());
2035 ASSERT_NO_FATAL_FAILURE(InitViewport());
2036
Tony Barbour01999182015-04-09 12:58:51 -06002037 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2038 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2039 VkSamplerObj sampler(m_device);
2040 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002041
Tony Barbour01999182015-04-09 12:58:51 -06002042 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002043 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002044 pipelineobj.AddShader(&vs);
2045 pipelineobj.AddShader(&ps);
2046
Tony Barbour01999182015-04-09 12:58:51 -06002047 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002048 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002049
Tony Barbourdd4c9642015-01-09 12:55:14 -07002050 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002051 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002052 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2053
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002054 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002055
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002056 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002057
2058#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002059 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002060 pDSDumpDot((char*)"triTest2.dot");
2061#endif
2062 // render triangle
2063 cmdBuffer.Draw(0, 3, 0, 1);
2064
2065 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002066 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002067 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002068
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002069 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002070}
Tony Barbour01999182015-04-09 12:58:51 -06002071TEST_F(VkRenderTest, TexturedTriangleClip)
Tony Barbourf43b6982014-11-25 13:18:32 -07002072{
2073 // The expected result from this test is a red and green checkered triangle
2074 static const char *vertShaderText =
2075 "#version 330\n"
2076 "#extension GL_ARB_separate_shader_objects : enable\n"
2077 "#extension GL_ARB_shading_language_420pack : enable\n"
2078 "layout (location = 0) out vec2 samplePos;\n"
2079 "out gl_PerVertex {\n"
2080 " vec4 gl_Position;\n"
2081 " float gl_ClipDistance[1];\n"
2082 "};\n"
2083 "void main() {\n"
2084 " vec2 vertices[3];"
2085 " vertices[0] = vec2(-0.5, -0.5);\n"
2086 " vertices[1] = vec2( 0.5, -0.5);\n"
2087 " vertices[2] = vec2( 0.5, 0.5);\n"
2088 " vec2 positions[3];"
2089 " positions[0] = vec2( 0.0, 0.0);\n"
2090 " positions[1] = vec2( 1.0, 0.0);\n"
2091 " positions[2] = vec2( 1.0, 1.0);\n"
2092 " float dists[3];\n"
2093 " dists[0] = 1.0;\n"
2094 " dists[1] = 1.0;\n"
2095 " dists[2] = -1.0;\n"
2096 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2097 " samplePos = positions[gl_VertexID % 3];\n"
2098 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2099 "}\n";
2100
2101 static const char *fragShaderText =
2102 "#version 140\n"
2103 "#extension GL_ARB_separate_shader_objects : enable\n"
2104 "#extension GL_ARB_shading_language_420pack : enable\n"
2105 "layout (location = 0) in vec2 samplePos;\n"
2106 "layout (binding = 0) uniform sampler2D surface;\n"
2107 "layout (location=0) out vec4 outColor;\n"
2108 "void main() {\n"
2109 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2110 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2111 " outColor = texColor;\n"
2112 "}\n";
2113
2114
2115 ASSERT_NO_FATAL_FAILURE(InitState());
2116 ASSERT_NO_FATAL_FAILURE(InitViewport());
2117
Tony Barbour01999182015-04-09 12:58:51 -06002118 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2119 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2120 VkSamplerObj sampler(m_device);
2121 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002122
Tony Barbour01999182015-04-09 12:58:51 -06002123 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002124 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002125 pipelineobj.AddShader(&vs);
2126 pipelineobj.AddShader(&ps);
2127
Tony Barbour01999182015-04-09 12:58:51 -06002128 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002129 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002130
Tony Barbourdd4c9642015-01-09 12:55:14 -07002131 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002132 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002133 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2134
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002135 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002136
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002137 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002138
2139#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002140 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002141 pDSDumpDot((char*)"triTest2.dot");
2142#endif
2143 // render triangle
2144 cmdBuffer.Draw(0, 3, 0, 1);
2145
2146 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002147 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002148 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002149
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002150 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002151}
GregFd6ebdb32015-06-03 18:40:50 -06002152
Tony Barbour01999182015-04-09 12:58:51 -06002153TEST_F(VkRenderTest, FSTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002154{
2155 // The expected result from this test is a red and green checkered triangle
2156 static const char *vertShaderText =
2157 "#version 140\n"
2158 "#extension GL_ARB_separate_shader_objects : enable\n"
2159 "#extension GL_ARB_shading_language_420pack : enable\n"
2160 "layout (location = 0) out vec2 samplePos;\n"
2161 "void main() {\n"
2162 " vec2 vertices[3];"
2163 " vertices[0] = vec2(-0.5, -0.5);\n"
2164 " vertices[1] = vec2( 0.5, -0.5);\n"
2165 " vertices[2] = vec2( 0.5, 0.5);\n"
2166 " vec2 positions[3];"
2167 " positions[0] = vec2( 0.0, 0.0);\n"
2168 " positions[1] = vec2( 1.0, 0.0);\n"
2169 " positions[2] = vec2( 1.0, 1.0);\n"
2170 " samplePos = positions[gl_VertexID % 3];\n"
2171 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2172 "}\n";
2173
2174 static const char *fragShaderText =
2175 "#version 140\n"
2176 "#extension GL_ARB_separate_shader_objects : enable\n"
2177 "#extension GL_ARB_shading_language_420pack : enable\n"
2178 "layout (location = 0) in vec2 samplePos;\n"
2179 "layout (binding = 0) uniform sampler2D surface;\n"
2180 "layout (location=0) out vec4 outColor;\n"
2181 "void main() {\n"
2182 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2183 " outColor = texColor;\n"
2184 "}\n";
2185
2186 ASSERT_NO_FATAL_FAILURE(InitState());
2187 ASSERT_NO_FATAL_FAILURE(InitViewport());
2188
Tony Barbour01999182015-04-09 12:58:51 -06002189 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2190 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2191 VkSamplerObj sampler(m_device);
2192 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002193
Tony Barbour01999182015-04-09 12:58:51 -06002194 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002195 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002196 pipelineobj.AddShader(&vs);
2197 pipelineobj.AddShader(&ps);
2198
Tony Barbour01999182015-04-09 12:58:51 -06002199 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002200 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002201
Tony Barbourdd4c9642015-01-09 12:55:14 -07002202 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002203 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002204 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2205
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002206 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002207
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002208 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002209
2210#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002211 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002212 pDSDumpDot((char*)"triTest2.dot");
2213#endif
2214 // render triangle
2215 cmdBuffer.Draw(0, 3, 0, 1);
2216
2217 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002218 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002219 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002220
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002221 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002222}
Tony Barbour01999182015-04-09 12:58:51 -06002223TEST_F(VkRenderTest, SamplerBindingsTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002224{
2225 // This test sets bindings on the samplers
2226 // For now we are asserting that sampler and texture pairs
2227 // march in lock step, and are set via GLSL binding. This can
2228 // and will probably change.
2229 // The sampler bindings should match the sampler and texture slot
2230 // number set up by the application.
2231 // This test will result in a blue triangle
2232 static const char *vertShaderText =
2233 "#version 140\n"
2234 "#extension GL_ARB_separate_shader_objects : enable\n"
2235 "#extension GL_ARB_shading_language_420pack : enable\n"
2236 "layout (location = 0) out vec4 samplePos;\n"
2237 "void main() {\n"
2238 " vec2 vertices[3];"
2239 " vertices[0] = vec2(-0.5, -0.5);\n"
2240 " vertices[1] = vec2( 0.5, -0.5);\n"
2241 " vertices[2] = vec2( 0.5, 0.5);\n"
2242 " vec2 positions[3];"
2243 " positions[0] = vec2( 0.0, 0.0);\n"
2244 " positions[1] = vec2( 1.0, 0.0);\n"
2245 " positions[2] = vec2( 1.0, 1.0);\n"
2246 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2247 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2248 "}\n";
2249
2250 static const char *fragShaderText =
2251 "#version 140\n"
2252 "#extension GL_ARB_separate_shader_objects : enable\n"
2253 "#extension GL_ARB_shading_language_420pack : enable\n"
2254 "layout (location = 0) in vec4 samplePos;\n"
2255 "layout (binding = 0) uniform sampler2D surface0;\n"
2256 "layout (binding = 1) uniform sampler2D surface1;\n"
2257 "layout (binding = 12) uniform sampler2D surface2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06002258 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002259 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002260 " outColor = textureLod(surface2, samplePos.xy, 0.0);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002261 "}\n";
2262
2263 ASSERT_NO_FATAL_FAILURE(InitState());
2264 ASSERT_NO_FATAL_FAILURE(InitViewport());
2265
Tony Barbour01999182015-04-09 12:58:51 -06002266 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2267 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002268
Tony Barbour01999182015-04-09 12:58:51 -06002269 VkSamplerObj sampler1(m_device);
2270 VkSamplerObj sampler2(m_device);
2271 VkSamplerObj sampler3(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002272
Tony Barbour2f421a02015-04-01 16:38:10 -06002273 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
Tony Barbour01999182015-04-09 12:58:51 -06002274 VkTextureObj texture1(m_device, tex_colors); // Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002275 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
Tony Barbour01999182015-04-09 12:58:51 -06002276 VkTextureObj texture2(m_device, tex_colors); // Green
Tony Barbour2f421a02015-04-01 16:38:10 -06002277 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
Tony Barbour01999182015-04-09 12:58:51 -06002278 VkTextureObj texture3(m_device, tex_colors); // Blue
Tony Barbourf43b6982014-11-25 13:18:32 -07002279
Tony Barbour01999182015-04-09 12:58:51 -06002280 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002281 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002282 pipelineobj.AddShader(&vs);
2283 pipelineobj.AddShader(&ps);
2284
Tony Barbour01999182015-04-09 12:58:51 -06002285 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002286 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2287 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2288 for (int i = 0; i < 10; i++)
2289 descriptorSet.AppendDummy();
2290 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002291
Tony Barbourdd4c9642015-01-09 12:55:14 -07002292 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002293 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002294 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2295
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002296 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002297
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002298 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002299
2300#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002301 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002302 pDSDumpDot((char*)"triTest2.dot");
2303#endif
2304 // render triangle
2305 cmdBuffer.Draw(0, 3, 0, 1);
2306
2307 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002308 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002309 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002310
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002311 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002312}
2313
Tony Barbour01999182015-04-09 12:58:51 -06002314TEST_F(VkRenderTest, TriangleVSUniformBlock)
Tony Barbourf43b6982014-11-25 13:18:32 -07002315{
2316 // The expected result from this test is a blue triangle
2317
2318 static const char *vertShaderText =
2319 "#version 140\n"
2320 "#extension GL_ARB_separate_shader_objects : enable\n"
2321 "#extension GL_ARB_shading_language_420pack : enable\n"
2322 "layout (location = 0) out vec4 outColor;\n"
2323 "layout (std140, binding = 0) uniform bufferVals {\n"
2324 " vec4 red;\n"
2325 " vec4 green;\n"
2326 " vec4 blue;\n"
2327 " vec4 white;\n"
2328 "} myBufferVals;\n"
2329 "void main() {\n"
2330 " vec2 vertices[3];"
2331 " vertices[0] = vec2(-0.5, -0.5);\n"
2332 " vertices[1] = vec2( 0.5, -0.5);\n"
2333 " vertices[2] = vec2( 0.5, 0.5);\n"
2334 " outColor = myBufferVals.blue;\n"
2335 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2336 "}\n";
2337
2338 static const char *fragShaderText =
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) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -06002343 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002344 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002345 " outColor = inColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002346 "}\n";
2347
2348 ASSERT_NO_FATAL_FAILURE(InitState());
2349 ASSERT_NO_FATAL_FAILURE(InitViewport());
2350
Tony Barbour01999182015-04-09 12:58:51 -06002351 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2352 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002353
2354 // Let's populate our buffer with the following:
2355 // vec4 red;
2356 // vec4 green;
2357 // vec4 blue;
2358 // vec4 white;
2359 const int valCount = 4 * 4;
2360 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2361 0.0, 1.0, 0.0, 1.0,
2362 0.0, 0.0, 1.0, 1.0,
2363 1.0, 1.0, 1.0, 1.0 };
2364
Tony Barbour01999182015-04-09 12:58:51 -06002365 VkConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002366
Tony Barbour01999182015-04-09 12:58:51 -06002367 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002368 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002369 pipelineobj.AddShader(&vs);
2370 pipelineobj.AddShader(&ps);
2371
Tony Barbour01999182015-04-09 12:58:51 -06002372 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002373 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002374
Tony Barbourdd4c9642015-01-09 12:55:14 -07002375 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002376 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002377 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2378
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002379 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002380
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002381 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002382
2383#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002384 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002385 pDSDumpDot((char*)"triTest2.dot");
2386#endif
2387 // render triangle
2388 cmdBuffer.Draw(0, 3, 0, 1);
2389
2390 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002391 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002392 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002393
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002394 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002395}
2396
Tony Barbour01999182015-04-09 12:58:51 -06002397TEST_F(VkRenderTest, TriangleFSUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002398{
2399 // This test allows the shader to select which buffer it is
2400 // pulling from using layout binding qualifier.
2401 // There are corresponding changes in the compiler stack that
2402 // will select the buffer using binding directly.
2403 // The binding number should match the slot number set up by
2404 // the application.
2405 // The expected result from this test is a purple triangle
2406
2407 static const char *vertShaderText =
2408 "#version 140\n"
2409 "#extension GL_ARB_separate_shader_objects : enable\n"
2410 "#extension GL_ARB_shading_language_420pack : enable\n"
2411 "void main() {\n"
2412 " vec2 vertices[3];"
2413 " vertices[0] = vec2(-0.5, -0.5);\n"
2414 " vertices[1] = vec2( 0.5, -0.5);\n"
2415 " vertices[2] = vec2( 0.5, 0.5);\n"
2416 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2417 "}\n";
2418
2419 static const char *fragShaderText =
2420 "#version 140\n"
2421 "#extension GL_ARB_separate_shader_objects : enable\n"
2422 "#extension GL_ARB_shading_language_420pack : enable\n"
2423 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2424 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2425 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002426 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
GregFd6ebdb32015-06-03 18:40:50 -06002427 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002428 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002429 " outColor = myBlueVal.color;\n"
2430 " outColor += myRedVal.color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002431 "}\n";
2432
2433 ASSERT_NO_FATAL_FAILURE(InitState());
2434 ASSERT_NO_FATAL_FAILURE(InitViewport());
2435
Tony Barbour01999182015-04-09 12:58:51 -06002436 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2437 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002438
2439 // We're going to create a number of uniform buffers, and then allow
2440 // the shader to select which it wants to read from with a binding
2441
2442 // Let's populate the buffers with a single color each:
2443 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2444 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2445 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002446 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002447
2448 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2449 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2450 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2451 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2452
2453 const int redCount = sizeof(redVals) / sizeof(float);
2454 const int greenCount = sizeof(greenVals) / sizeof(float);
2455 const int blueCount = sizeof(blueVals) / sizeof(float);
2456 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2457
Tony Barbour01999182015-04-09 12:58:51 -06002458 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002459
Tony Barbour01999182015-04-09 12:58:51 -06002460 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002461
Tony Barbour01999182015-04-09 12:58:51 -06002462 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002463
Tony Barbour01999182015-04-09 12:58:51 -06002464 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002465
Tony Barbour01999182015-04-09 12:58:51 -06002466 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002467 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002468 pipelineobj.AddShader(&vs);
2469 pipelineobj.AddShader(&ps);
2470
Tony Barbour01999182015-04-09 12:58:51 -06002471 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002472 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2473 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2474 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2475 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002476
Tony Barbourdd4c9642015-01-09 12:55:14 -07002477 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002478 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002479 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002480
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002481 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002482
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002483 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002484
2485#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002486 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002487 pDSDumpDot((char*)"triTest2.dot");
2488#endif
2489 // render triangle
2490 cmdBuffer.Draw(0, 3, 0, 1);
2491
2492 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002493 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002494 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002495
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002496 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002497}
2498
Tony Barbour01999182015-04-09 12:58:51 -06002499TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002500{
2501 // This test is the same as TriangleFSUniformBlockBinding, but
2502 // it does not provide an instance name.
2503 // The expected result from this test is a purple triangle
2504
2505 static const char *vertShaderText =
2506 "#version 140\n"
2507 "#extension GL_ARB_separate_shader_objects : enable\n"
2508 "#extension GL_ARB_shading_language_420pack : enable\n"
2509 "void main() {\n"
2510 " vec2 vertices[3];"
2511 " vertices[0] = vec2(-0.5, -0.5);\n"
2512 " vertices[1] = vec2( 0.5, -0.5);\n"
2513 " vertices[2] = vec2( 0.5, 0.5);\n"
2514 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2515 "}\n";
2516
2517 static const char *fragShaderText =
2518 "#version 430\n"
2519 "#extension GL_ARB_separate_shader_objects : enable\n"
2520 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002521 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2522 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2523 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002524 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002525 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002526 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002527 " outColor = blue;\n"
2528 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002529 "}\n";
2530 ASSERT_NO_FATAL_FAILURE(InitState());
2531 ASSERT_NO_FATAL_FAILURE(InitViewport());
2532
Tony Barbour01999182015-04-09 12:58:51 -06002533 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2534 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002535
2536 // We're going to create a number of uniform buffers, and then allow
2537 // the shader to select which it wants to read from with a binding
2538
2539 // Let's populate the buffers with a single color each:
2540 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2541 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2542 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2543 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2544
2545 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2546 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2547 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2548 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2549
2550 const int redCount = sizeof(redVals) / sizeof(float);
2551 const int greenCount = sizeof(greenVals) / sizeof(float);
2552 const int blueCount = sizeof(blueVals) / sizeof(float);
2553 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2554
Tony Barbour01999182015-04-09 12:58:51 -06002555 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002556
Tony Barbour01999182015-04-09 12:58:51 -06002557 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002558
Tony Barbour01999182015-04-09 12:58:51 -06002559 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002560
Tony Barbour01999182015-04-09 12:58:51 -06002561 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002562
Tony Barbour01999182015-04-09 12:58:51 -06002563 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002564 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002565 pipelineobj.AddShader(&vs);
2566 pipelineobj.AddShader(&ps);
2567
Tony Barbour01999182015-04-09 12:58:51 -06002568 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002569 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2570 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2571 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2572 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002573
Tony Barbourdd4c9642015-01-09 12:55:14 -07002574 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002575 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002576 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2577
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002578 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002579
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002580 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002581
2582#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002583 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002584 pDSDumpDot((char*)"triTest2.dot");
2585#endif
2586 // render triangle
2587 cmdBuffer.Draw(0, 3, 0, 1);
2588
2589 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002590 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002591 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002592
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002593 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002594}
2595
GregF54a32172015-07-01 16:11:09 -06002596TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBindingWithStruct)
2597{
2598 // This test is the same as TriangleFSUniformBlockBinding, but
2599 // it does not provide an instance name.
2600 // The expected result from this test is a purple triangle
2601
2602 static const char *vertShaderText =
2603 "#version 140\n"
2604 "#extension GL_ARB_separate_shader_objects : enable\n"
2605 "#extension GL_ARB_shading_language_420pack : enable\n"
2606 "void main() {\n"
2607 " vec2 vertices[3];"
2608 " vertices[0] = vec2(-0.5, -0.5);\n"
2609 " vertices[1] = vec2( 0.5, -0.5);\n"
2610 " vertices[2] = vec2( 0.5, 0.5);\n"
2611 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2612 "}\n";
2613
2614 static const char *fragShaderText =
2615 "#version 430\n"
2616 "#extension GL_ARB_separate_shader_objects : enable\n"
2617 "#extension GL_ARB_shading_language_420pack : enable\n"
2618 "\n"
2619 " struct PS_INPUT {\n"
2620 " vec2 member0;\n"
2621 " vec4 member1;\n"
2622 " vec4 member2;\n"
2623 " vec4 member3;\n"
2624 " vec4 member4;\n"
2625 " vec4 member5;\n"
2626 " vec4 member6;\n"
2627 " vec4 member7;\n"
2628 " vec4 member8;\n"
2629 " vec4 member9;\n"
2630 " };\n"
2631 "\n"
2632 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2633 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2634 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2635 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
2636 "layout (location = 0) out vec4 outColor;\n"
2637 "PS_INPUT MainFs()\n"
2638 "{\n"
2639 " PS_INPUT o;\n"
2640 " o.member9 = red;\n"
2641 " return o;\n"
2642 "}\n"
2643 "\n"
2644 "void main()\n"
2645 "{\n"
2646 " PS_INPUT o;\n"
2647 " o = MainFs();\n"
2648 " outColor = blue;"
2649 " outColor += o.member9;\n"
2650 "}\n";;
2651 ASSERT_NO_FATAL_FAILURE(InitState());
2652 ASSERT_NO_FATAL_FAILURE(InitViewport());
2653
2654 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2655 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2656
2657 // We're going to create a number of uniform buffers, and then allow
2658 // the shader to select which it wants to read from with a binding
2659
2660 // Let's populate the buffers with a single color each:
2661 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2662 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2663 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2664 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2665
2666 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2667 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2668 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2669 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2670
2671 const int redCount = sizeof(redVals) / sizeof(float);
2672 const int greenCount = sizeof(greenVals) / sizeof(float);
2673 const int blueCount = sizeof(blueVals) / sizeof(float);
2674 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2675
2676 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2677
2678 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2679
2680 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2681
2682 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
2683
2684 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002685 pipelineobj.AddColorAttachment();
GregF54a32172015-07-01 16:11:09 -06002686 pipelineobj.AddShader(&vs);
2687 pipelineobj.AddShader(&ps);
2688
2689 VkDescriptorSetObj descriptorSet(m_device);
2690 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2691 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2692 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2693 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
2694
2695 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2696 VkCommandBufferObj cmdBuffer(m_device);
2697 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2698
2699 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
2700
2701 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
2702
2703#ifdef DUMP_STATE_DOT
2704 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
2705 pDSDumpDot((char*)"triTest2.dot");
2706#endif
2707 // render triangle
2708 cmdBuffer.Draw(0, 3, 0, 1);
2709
2710 // finalize recording of the command buffer
2711 EndCommandBuffer(cmdBuffer);
2712 cmdBuffer.QueueCommandBuffer();
2713
2714 RecordImages(m_renderTargets);
2715}
2716
Tony Barbour01999182015-04-09 12:58:51 -06002717TEST_F(VkRenderTest, CubeWithVertexFetchAndMVPAndTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07002718{
2719 static const char *vertShaderText =
2720 "#version 140\n"
2721 "#extension GL_ARB_separate_shader_objects : enable\n"
2722 "#extension GL_ARB_shading_language_420pack : enable\n"
2723 "layout (std140, binding=0) uniform bufferVals {\n"
2724 " mat4 mvp;\n"
2725 "} myBufferVals;\n"
2726 "layout (location=0) in vec4 pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002727 "layout (location=1) in vec2 input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002728 "layout (location=0) out vec2 UV;\n"
2729 "void main() {\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002730 " UV = input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002731 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002732 " gl_Position.y = -gl_Position.y;\n"
2733 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002734 "}\n";
2735
2736 static const char *fragShaderText =
2737 "#version 140\n"
2738 "#extension GL_ARB_separate_shader_objects : enable\n"
2739 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002740 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002741 "layout (location=0) out vec4 outColor;\n"
2742 "layout (location=0) in vec2 UV;\n"
2743 "void main() {\n"
2744 " outColor= textureLod(surface, UV, 0.0);\n"
2745 "}\n";
2746 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2747
2748 glm::mat4 View = glm::lookAt(
2749 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2750 glm::vec3(0,0,0), // and looks at the origin
2751 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2752 );
2753
2754 glm::mat4 Model = glm::mat4(1.0f);
2755
2756 glm::mat4 MVP = Projection * View * Model;
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002757 int num_verts = sizeof(g_vb_texture_Data) / sizeof(g_vb_texture_Data[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002758
2759
2760 ASSERT_NO_FATAL_FAILURE(InitState());
2761 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wu9e81ebb2015-07-09 10:16:34 +08002762 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Chia-I Wuc278df82015-07-07 11:50:03 +08002763 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height, m_depth_stencil_fmt);
Tony Barbourf43b6982014-11-25 13:18:32 -07002764
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002765 VkConstantBufferObj meshBuffer(m_device, num_verts,
2766 sizeof(g_vb_texture_Data[0]), g_vb_texture_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002767 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002768
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002769 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07002770
Tony Barbour01999182015-04-09 12:58:51 -06002771 VkConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2772 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2773 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2774 VkSamplerObj sampler(m_device);
2775 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002776
Tony Barbour01999182015-04-09 12:58:51 -06002777 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002778 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002779 pipelineobj.AddShader(&vs);
2780 pipelineobj.AddShader(&ps);
2781
Tony Barbour01999182015-04-09 12:58:51 -06002782 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002783 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mvpBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002784 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002785
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002786#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002787 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002788 MESH_BIND_ID, // binding ID
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002789 sizeof(g_vb_texture_Data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002790 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002791 };
Tony Barbourf43b6982014-11-25 13:18:32 -07002792
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002793 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002794 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2795 vi_attribs[0].location = 0; // location
Tony Barbour8205d902015-04-16 15:59:00 -06002796 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002797 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2798 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2799 vi_attribs[1].location = 1; // location
2800 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
2801 vi_attribs[1].offsetInBytes = 16; // Offset of uv components
Tony Barbourf43b6982014-11-25 13:18:32 -07002802
Tony Barbourf43b6982014-11-25 13:18:32 -07002803 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002804 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2805 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07002806
Tony Barboure307f582015-07-10 15:29:03 -06002807 VkPipelineDepthStencilStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002808 ds_state.depthTestEnable = VK_TRUE;
2809 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06002810 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002811 ds_state.depthBoundsEnable = VK_FALSE;
2812 ds_state.stencilTestEnable = VK_FALSE;
2813 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
2814 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
2815 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06002816 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002817 ds_state.front = ds_state.back;
2818 pipelineobj.SetDepthStencil(&ds_state);
2819
Tony Barbour17c6ab12015-03-27 17:03:18 -06002820 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour01999182015-04-09 12:58:51 -06002821 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002822 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002823
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002824 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002825
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002826 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002827
2828 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2829#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002830 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002831 pDSDumpDot((char*)"triTest2.dot");
2832#endif
2833 // render triangle
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002834 cmdBuffer.Draw(0, num_verts, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002835
2836 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002837 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002838 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002839
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002840 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002841 RotateTriangleVSUniform(Projection, View, Model, &mvpBuffer, &cmdBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002842}
Cody Northropd1ce7842014-12-09 11:17:01 -07002843
Tony Barbour01999182015-04-09 12:58:51 -06002844TEST_F(VkRenderTest, TriangleMixedSamplerUniformBlockBinding)
Cody Northropd1ce7842014-12-09 11:17:01 -07002845{
2846 // This test mixes binding slots of textures and buffers, ensuring
2847 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002848 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002849 // you can modify it to move the desired result around.
2850
2851 static const char *vertShaderText =
2852 "#version 140\n"
2853 "#extension GL_ARB_separate_shader_objects : enable\n"
2854 "#extension GL_ARB_shading_language_420pack : enable\n"
2855 "void main() {\n"
2856 " vec2 vertices[3];"
2857 " vertices[0] = vec2(-0.5, -0.5);\n"
2858 " vertices[1] = vec2( 0.5, -0.5);\n"
2859 " vertices[2] = vec2( 0.5, 0.5);\n"
2860 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2861 "}\n";
2862
2863 static const char *fragShaderText =
2864 "#version 430\n"
2865 "#extension GL_ARB_separate_shader_objects : enable\n"
2866 "#extension GL_ARB_shading_language_420pack : enable\n"
2867 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002868 "layout (binding = 3) uniform sampler2D surface1;\n"
2869 "layout (binding = 1) uniform sampler2D surface2;\n"
2870 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002871
Cody Northropa0410942014-12-09 13:59:39 -07002872
Chia-I Wuf8385062015-01-04 16:27:24 +08002873 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2874 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2875 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2876 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002877 "layout (location = 0) out vec4 outColor;\n"
2878 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002879 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002880 " outColor += white * vec4(0.00001);\n"
2881 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002882 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002883 "}\n";
2884 ASSERT_NO_FATAL_FAILURE(InitState());
2885 ASSERT_NO_FATAL_FAILURE(InitViewport());
2886
Tony Barbour01999182015-04-09 12:58:51 -06002887 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2888 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northropd1ce7842014-12-09 11:17:01 -07002889
Cody Northropd1ce7842014-12-09 11:17:01 -07002890 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2891 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2892 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2893 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2894
2895 const int redCount = sizeof(redVals) / sizeof(float);
2896 const int greenCount = sizeof(greenVals) / sizeof(float);
2897 const int blueCount = sizeof(blueVals) / sizeof(float);
2898 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2899
Tony Barbour01999182015-04-09 12:58:51 -06002900 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2901 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2902 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2903 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002904
Tony Barbour2f421a02015-04-01 16:38:10 -06002905 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002906 VkSamplerObj sampler0(m_device);
2907 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002908 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002909 VkSamplerObj sampler2(m_device);
2910 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002911 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002912 VkSamplerObj sampler4(m_device);
2913 VkTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropa0410942014-12-09 13:59:39 -07002914
2915 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2916 // TODO: Get back here ASAP and understand why.
Tony Barbour2f421a02015-04-01 16:38:10 -06002917 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06002918 VkSamplerObj sampler7(m_device);
2919 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropd1ce7842014-12-09 11:17:01 -07002920
Tony Barbour01999182015-04-09 12:58:51 -06002921 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002922 pipelineobj.AddColorAttachment();
Cody Northropd1ce7842014-12-09 11:17:01 -07002923 pipelineobj.AddShader(&vs);
2924 pipelineobj.AddShader(&ps);
2925
Tony Barbour01999182015-04-09 12:58:51 -06002926 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002927 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2928 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2929 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2930 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002931 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002932 // swap blue and green
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002933 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2934 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2935 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002936
Tony Barbourdd4c9642015-01-09 12:55:14 -07002937 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002938 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002939 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002940
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002941 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002942
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002943 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002944
2945#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002946 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002947 pDSDumpDot((char*)"triTest2.dot");
2948#endif
2949 // render triangle
2950 cmdBuffer.Draw(0, 3, 0, 1);
2951
2952 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002953 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002954 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002955
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002956 RecordImages(m_renderTargets);
Cody Northropd1ce7842014-12-09 11:17:01 -07002957}
2958
Tony Barbour01999182015-04-09 12:58:51 -06002959TEST_F(VkRenderTest, TriangleMatchingSamplerUniformBlockBinding)
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002960{
2961 // This test matches binding slots of textures and buffers, requiring
2962 // the driver to give them distinct number spaces.
2963 // The expected result from this test is a red triangle, although
2964 // you can modify it to move the desired result around.
2965
2966 static const char *vertShaderText =
2967 "#version 140\n"
2968 "#extension GL_ARB_separate_shader_objects : enable\n"
2969 "#extension GL_ARB_shading_language_420pack : enable\n"
2970 "void main() {\n"
2971 " vec2 vertices[3];"
2972 " vertices[0] = vec2(-0.5, -0.5);\n"
2973 " vertices[1] = vec2( 0.5, -0.5);\n"
2974 " vertices[2] = vec2( 0.5, 0.5);\n"
2975 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2976 "}\n";
2977
2978 static const char *fragShaderText =
2979 "#version 430\n"
2980 "#extension GL_ARB_separate_shader_objects : enable\n"
2981 "#extension GL_ARB_shading_language_420pack : enable\n"
2982 "layout (binding = 0) uniform sampler2D surface0;\n"
2983 "layout (binding = 1) uniform sampler2D surface1;\n"
2984 "layout (binding = 2) uniform sampler2D surface2;\n"
2985 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002986 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2987 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2988 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2989 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002990 "layout (location = 0) out vec4 outColor;\n"
2991 "void main() {\n"
2992 " outColor = red;// * vec4(0.00001);\n"
2993 " outColor += white * vec4(0.00001);\n"
2994 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2995 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2996 "}\n";
2997 ASSERT_NO_FATAL_FAILURE(InitState());
2998 ASSERT_NO_FATAL_FAILURE(InitViewport());
2999
Tony Barbour01999182015-04-09 12:58:51 -06003000 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3001 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003002
3003 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
3004 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
3005 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
3006 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
3007
3008 const int redCount = sizeof(redVals) / sizeof(float);
3009 const int greenCount = sizeof(greenVals) / sizeof(float);
3010 const int blueCount = sizeof(blueVals) / sizeof(float);
3011 const int whiteCount = sizeof(whiteVals) / sizeof(float);
3012
Tony Barbour01999182015-04-09 12:58:51 -06003013 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
3014 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
3015 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
3016 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003017
Tony Barbour2f421a02015-04-01 16:38:10 -06003018 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06003019 VkSamplerObj sampler0(m_device);
3020 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06003021 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06003022 VkSamplerObj sampler2(m_device);
3023 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06003024 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06003025 VkSamplerObj sampler4(m_device);
3026 VkTextureObj texture4(m_device, tex_colors); // Light Green
Tony Barbour2f421a02015-04-01 16:38:10 -06003027 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06003028 VkSamplerObj sampler7(m_device);
3029 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003030
Tony Barbour01999182015-04-09 12:58:51 -06003031 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003032 pipelineobj.AddColorAttachment();
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003033 pipelineobj.AddShader(&vs);
3034 pipelineobj.AddShader(&ps);
3035
Tony Barbour01999182015-04-09 12:58:51 -06003036 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08003037 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3038 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3039 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
3040 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003041 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
3042 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
3043 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
3044 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003045
Tony Barbourdd4c9642015-01-09 12:55:14 -07003046 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06003047 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07003048 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003049
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003050 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07003051
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003052 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07003053
3054#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003055 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07003056 pDSDumpDot((char*)"triTest2.dot");
3057#endif
3058 // render triangle
3059 cmdBuffer.Draw(0, 3, 0, 1);
3060
3061 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003062 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003063 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07003064
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003065 RecordImages(m_renderTargets);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003066}
3067
Tony Barbour01999182015-04-09 12:58:51 -06003068TEST_F(VkRenderTest, TriangleUniformBufferLayout)
Cody Northrop02690bd2014-12-17 15:26:33 -07003069{
3070 // This test populates a buffer with a variety of different data
3071 // types, then reads them out with a shader.
3072 // The expected result from this test is a green triangle
3073
3074 static const char *vertShaderText =
3075 "#version 140\n"
3076 "#extension GL_ARB_separate_shader_objects : enable\n"
3077 "#extension GL_ARB_shading_language_420pack : enable\n"
3078 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3079 " vec4 fRed;\n"
3080 " vec4 fGreen;\n"
3081 " layout(row_major) mat4 worldToProj;\n"
3082 " layout(row_major) mat4 projToWorld;\n"
3083 " layout(row_major) mat4 worldToView;\n"
3084 " layout(row_major) mat4 viewToProj;\n"
3085 " layout(row_major) mat4 worldToShadow[4];\n"
3086 " float fZero;\n"
3087 " float fOne;\n"
3088 " float fTwo;\n"
3089 " float fThree;\n"
3090 " vec3 fZeroZeroZero;\n"
3091 " float fFour;\n"
3092 " vec3 fZeroZeroOne;\n"
3093 " float fFive;\n"
3094 " vec3 fZeroOneZero;\n"
3095 " float fSix;\n"
3096 " float fSeven;\n"
3097 " float fEight;\n"
3098 " float fNine;\n"
3099 " vec2 fZeroZero;\n"
3100 " vec2 fZeroOne;\n"
3101 " vec4 fBlue;\n"
3102 " vec2 fOneZero;\n"
3103 " vec2 fOneOne;\n"
3104 " vec3 fZeroOneOne;\n"
3105 " float fTen;\n"
3106 " float fEleven;\n"
3107 " float fTwelve;\n"
3108 " vec3 fOneZeroZero;\n"
3109 " vec4 uvOffsets[4];\n"
3110 "};\n"
3111 "layout (location = 0) out vec4 color;"
3112 "void main() {\n"
3113
3114 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3115 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3116 " \n"
3117
3118 // do some exact comparisons, even though we should
3119 // really have an epsilon involved.
3120 " vec4 outColor = right;\n"
3121 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3122 " outColor = wrong;\n"
3123 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3124 " outColor = wrong;\n"
3125 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3126 " outColor = wrong;\n"
3127
3128 " color = outColor;\n"
3129
3130 // generic position stuff
3131 " vec2 vertices;\n"
3132 " int vertexSelector = gl_VertexID;\n"
3133 " if (vertexSelector == 0)\n"
3134 " vertices = vec2(-0.5, -0.5);\n"
3135 " else if (vertexSelector == 1)\n"
3136 " vertices = vec2( 0.5, -0.5);\n"
3137 " else if (vertexSelector == 2)\n"
3138 " vertices = vec2( 0.5, 0.5);\n"
3139 " else\n"
3140 " vertices = vec2( 0.0, 0.0);\n"
3141 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3142 "}\n";
3143
3144 static const char *fragShaderText =
3145 "#version 140\n"
3146 "#extension GL_ARB_separate_shader_objects : enable\n"
3147 "#extension GL_ARB_shading_language_420pack : enable\n"
3148 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3149 " vec4 fRed;\n"
3150 " vec4 fGreen;\n"
3151 " layout(row_major) mat4 worldToProj;\n"
3152 " layout(row_major) mat4 projToWorld;\n"
3153 " layout(row_major) mat4 worldToView;\n"
3154 " layout(row_major) mat4 viewToProj;\n"
3155 " layout(row_major) mat4 worldToShadow[4];\n"
3156 " float fZero;\n"
3157 " float fOne;\n"
3158 " float fTwo;\n"
3159 " float fThree;\n"
3160 " vec3 fZeroZeroZero;\n"
3161 " float fFour;\n"
3162 " vec3 fZeroZeroOne;\n"
3163 " float fFive;\n"
3164 " vec3 fZeroOneZero;\n"
3165 " float fSix;\n"
3166 " float fSeven;\n"
3167 " float fEight;\n"
3168 " float fNine;\n"
3169 " vec2 fZeroZero;\n"
3170 " vec2 fZeroOne;\n"
3171 " vec4 fBlue;\n"
3172 " vec2 fOneZero;\n"
3173 " vec2 fOneOne;\n"
3174 " vec3 fZeroOneOne;\n"
3175 " float fTen;\n"
3176 " float fEleven;\n"
3177 " float fTwelve;\n"
3178 " vec3 fOneZeroZero;\n"
3179 " vec4 uvOffsets[4];\n"
3180 "};\n"
3181 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003182 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop02690bd2014-12-17 15:26:33 -07003183 "void main() {\n"
3184 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3185 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3186 " \n"
3187
3188 // start with VS value to ensure it passed
3189 " vec4 outColor = color;\n"
3190
3191 // do some exact comparisons, even though we should
3192 // really have an epsilon involved.
3193 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3194 " outColor = wrong;\n"
3195 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3196 " outColor = wrong;\n"
3197 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3198 " outColor = wrong;\n"
3199 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3200 " outColor = wrong;\n"
3201 " if (fTwo != 2.0)\n"
3202 " outColor = wrong;\n"
3203 " if (fOneOne != vec2(1.0, 1.0))\n"
3204 " outColor = wrong;\n"
3205 " if (fTen != 10.0)\n"
3206 " outColor = wrong;\n"
3207 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3208 " outColor = wrong;\n"
3209 " \n"
GregFd6ebdb32015-06-03 18:40:50 -06003210 " uFragColor = outColor;\n"
Cody Northrop02690bd2014-12-17 15:26:33 -07003211 "}\n";
3212
3213
3214 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3215 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3216 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3217 0.0, 1.0, 0.0, 1.0, // align
3218 0.0, 0.0, 1.0, 1.0, // align
3219 0.0, 0.0, 0.0, 1.0, // align
3220 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3221 0.0, 2.0, 0.0, 2.0, // align
3222 0.0, 0.0, 2.0, 2.0, // align
3223 0.0, 0.0, 0.0, 2.0, // align
3224 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3225 0.0, 3.0, 0.0, 3.0, // align
3226 0.0, 0.0, 3.0, 3.0, // align
3227 0.0, 0.0, 0.0, 3.0, // align
3228 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3229 0.0, 4.0, 0.0, 4.0, // align
3230 0.0, 0.0, 4.0, 4.0, // align
3231 0.0, 0.0, 0.0, 4.0, // align
3232 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3233 0.0, 5.0, 0.0, 5.0, // align
3234 0.0, 0.0, 5.0, 5.0, // align
3235 0.0, 0.0, 0.0, 5.0, // align
3236 6.0, 0.0, 0.0, 6.0, // align
3237 0.0, 6.0, 0.0, 6.0, // align
3238 0.0, 0.0, 6.0, 6.0, // align
3239 0.0, 0.0, 0.0, 6.0, // align
3240 7.0, 0.0, 0.0, 7.0, // align
3241 0.0, 7.0, 0.0, 7.0, // align
3242 0.0, 0.0, 7.0, 7.0, // align
3243 0.0, 0.0, 0.0, 7.0, // align
3244 8.0, 0.0, 0.0, 8.0, // align
3245 0.0, 8.0, 0.0, 8.0, // align
3246 0.0, 0.0, 8.0, 8.0, // align
3247 0.0, 0.0, 0.0, 8.0, // align
3248 0.0, // float fZero; // align
3249 1.0, // float fOne; // pack
3250 2.0, // float fTwo; // pack
3251 3.0, // float fThree; // pack
3252 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3253 4.0, // float fFour; // pack
3254 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3255 5.0, // float fFive; // pack
3256 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3257 6.0, // float fSix; // pack
3258 7.0, // float fSeven; // align
3259 8.0, // float fEight; // pack
3260 9.0, // float fNine; // pack
3261 0.0, // BUFFER
3262 0.0, 0.0, // vec2 fZeroZero; // align
3263 0.0, 1.0, // vec2 fZeroOne; // pack
3264 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3265 1.0, 0.0, // vec2 fOneZero; // align
3266 1.0, 1.0, // vec2 fOneOne; // pack
3267 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3268 10.0, // float fTen; // pack
3269 11.0, // float fEleven; // align
3270 12.0, // float fTwelve; // pack
3271 0.0, 0.0, // BUFFER
3272 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3273 0.0, // BUFFER
3274 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3275 0.5, 0.6, 0.7, 0.8, // align
3276 0.9, 1.0, 1.1, 1.2, // align
3277 1.3, 1.4, 1.5, 1.6, // align
3278 };
3279
3280 ASSERT_NO_FATAL_FAILURE(InitState());
3281 ASSERT_NO_FATAL_FAILURE(InitViewport());
3282
3283 const int constCount = sizeof(mixedVals) / sizeof(float);
3284
Tony Barbour01999182015-04-09 12:58:51 -06003285 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3286 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop02690bd2014-12-17 15:26:33 -07003287
Tony Barbour01999182015-04-09 12:58:51 -06003288 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003289
Tony Barbour01999182015-04-09 12:58:51 -06003290 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003291 pipelineobj.AddColorAttachment();
Cody Northrop02690bd2014-12-17 15:26:33 -07003292 pipelineobj.AddShader(&vs);
3293 pipelineobj.AddShader(&ps);
3294
Tony Barbour01999182015-04-09 12:58:51 -06003295 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003296 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003297
3298 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06003299 VkCommandBufferObj cmdBuffer(m_device);
Cody Northrop02690bd2014-12-17 15:26:33 -07003300 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3301
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003302 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Cody Northrop02690bd2014-12-17 15:26:33 -07003303
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003304 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Cody Northrop02690bd2014-12-17 15:26:33 -07003305
3306#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003307 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop02690bd2014-12-17 15:26:33 -07003308 pDSDumpDot((char*)"triTest2.dot");
3309#endif
3310 // render triangle
3311 cmdBuffer.Draw(0, 3, 0, 1);
3312
3313 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003314 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003315 cmdBuffer.QueueCommandBuffer();
Cody Northrop02690bd2014-12-17 15:26:33 -07003316
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003317 RecordImages(m_renderTargets);
Cody Northrop02690bd2014-12-17 15:26:33 -07003318}
3319
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003320TEST_F(VkRenderTest, TextureGather)
3321{
3322 // This test introduces textureGather and textureGatherOffset
3323 // Each call is compared against an expected inline color result
3324 // Green triangle means everything worked as expected
3325 // Red means something went wrong
3326
3327 // disable SPV until texture gather is turned on in LunarGLASS
Cody Northrop1cfbd172015-06-03 16:49:20 -06003328 ScopedUseGlsl useGlsl(true);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003329
3330 static const char *vertShaderText =
3331 "#version 140\n"
3332 "#extension GL_ARB_separate_shader_objects : enable\n"
3333 "#extension GL_ARB_shading_language_420pack : enable\n"
3334 "void main() {\n"
3335 " vec2 vertices[3];"
3336 " vertices[0] = vec2(-0.5, -0.5);\n"
3337 " vertices[1] = vec2( 0.5, -0.5);\n"
3338 " vertices[2] = vec2( 0.5, 0.5);\n"
3339 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
3340 "}\n";
3341
3342 static const char *fragShaderText =
3343 "#version 430\n"
3344 "#extension GL_ARB_separate_shader_objects : enable\n"
3345 "#extension GL_ARB_shading_language_420pack : enable\n"
3346 "layout (binding = 0) uniform sampler2D surface0;\n"
3347 "layout (binding = 1) uniform sampler2D surface1;\n"
3348 "layout (binding = 2) uniform sampler2D surface2;\n"
3349 "layout (binding = 3) uniform sampler2D surface3;\n"
3350 "layout (location = 0) out vec4 outColor;\n"
3351 "void main() {\n"
3352
3353 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3354 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3355
3356 " vec4 color = right;\n"
3357
3358 // Grab a normal texture sample to ensure it can work in conjuntion
3359 // with textureGather (there are some intracacies in the backend)
3360 " vec4 sampledColor = textureLod(surface2, vec2(0.5), 0.0);\n"
3361 " if (sampledColor != vec4(0.0, 0.0, 1.0, 1.0))\n"
3362 " color = wrong;\n"
3363
3364 " vec4 gatheredColor = textureGather(surface0, vec2(0.5), 0);\n"
3365 // This just grabbed four red components from a red surface
3366 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3367 " color = wrong;\n"
3368
3369 // Yes, this is using an offset of 0, we don't have enough fine grained
3370 // control of the texture contents here.
3371 " gatheredColor = textureGatherOffset(surface1, vec2(0.5), ivec2(0, 0), 1);\n"
3372 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3373 " color = wrong;\n"
3374
3375 " outColor = color;\n"
3376
3377 "}\n";
3378
3379 ASSERT_NO_FATAL_FAILURE(InitState());
3380 ASSERT_NO_FATAL_FAILURE(InitViewport());
3381
3382 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3383 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3384
3385 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
3386 VkSamplerObj sampler0(m_device);
3387 VkTextureObj texture0(m_device, tex_colors); // Red
3388 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
3389 VkSamplerObj sampler1(m_device);
3390 VkTextureObj texture1(m_device, tex_colors); // Green
3391 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
3392 VkSamplerObj sampler2(m_device);
3393 VkTextureObj texture2(m_device, tex_colors); // Blue
3394 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
3395 VkSamplerObj sampler3(m_device);
3396 VkTextureObj texture3(m_device, tex_colors); // Red and Blue
3397
3398 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003399 pipelineobj.AddColorAttachment();
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003400 pipelineobj.AddShader(&vs);
3401 pipelineobj.AddShader(&ps);
3402
3403 VkDescriptorSetObj descriptorSet(m_device);
3404 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3405 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
3406 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3407 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
3408
3409 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3410 VkCommandBufferObj cmdBuffer(m_device);
3411 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3412
3413 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3414
3415 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3416
3417 // render triangle
3418 cmdBuffer.Draw(0, 3, 0, 1);
3419
3420 // finalize recording of the command buffer
3421 EndCommandBuffer(cmdBuffer);
3422 cmdBuffer.QueueCommandBuffer();
3423
3424 RecordImages(m_renderTargets);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003425}
3426
Cody Northropa44c2ff2015-04-15 11:19:06 -06003427TEST_F(VkRenderTest, GeometryShaderHelloWorld)
3428{
3429 // This test introduces a geometry shader that simply
3430 // changes the color of each vertex to red, green, blue
3431
3432 static const char *vertShaderText =
3433 "#version 140\n"
3434 "#extension GL_ARB_separate_shader_objects : enable\n"
3435 "#extension GL_ARB_shading_language_420pack : enable\n"
3436 "layout (location = 0) out vec4 color;"
3437 "void main() {\n"
3438
3439 // VS writes out red
3440 " color = vec4(1.0, 0.0, 0.0, 1.0);\n"
3441
3442 // generic position stuff
3443 " vec2 vertices;\n"
3444 " int vertexSelector = gl_VertexID;\n"
3445 " if (vertexSelector == 0)\n"
3446 " vertices = vec2(-0.5, -0.5);\n"
3447 " else if (vertexSelector == 1)\n"
3448 " vertices = vec2( 0.5, -0.5);\n"
3449 " else if (vertexSelector == 2)\n"
3450 " vertices = vec2( 0.5, 0.5);\n"
3451 " else\n"
3452 " vertices = vec2( 0.0, 0.0);\n"
3453 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3454
3455 "}\n";
3456
3457 static const char *geomShaderText =
3458 "#version 330\n"
3459 "#extension GL_ARB_separate_shader_objects : enable\n"
3460 "#extension GL_ARB_shading_language_420pack : enable\n"
3461 "layout( triangles ) in;\n"
3462 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3463 "layout( location = 0 ) in vec4 inColor[3];\n"
3464 "layout( location = 0 ) out vec4 outColor;\n"
3465 "void main()\n"
3466 "{\n"
3467
3468 // first vertex, pass through red
3469 " gl_Position = gl_in[0].gl_Position;\n"
3470 " outColor = inColor[0];\n"
3471 " EmitVertex();\n"
3472
3473 // second vertex, green
3474 " gl_Position = gl_in[1].gl_Position;\n"
3475 " outColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3476 " EmitVertex();\n"
3477
3478 // third vertex, blue
3479 " gl_Position = gl_in[2].gl_Position;\n"
3480 " outColor = vec4(0.0, 0.0, 1.0, 1.0);\n"
3481 " EmitVertex();\n"
3482
3483 // done
3484 " EndPrimitive();\n"
3485 "}\n";
3486
3487
3488 static const char *fragShaderText =
3489 "#version 140\n"
3490 "#extension GL_ARB_separate_shader_objects : enable\n"
3491 "#extension GL_ARB_shading_language_420pack : enable\n"
3492 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003493 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003494 "void main() {\n"
3495 // pass through
GregFd6ebdb32015-06-03 18:40:50 -06003496 " outColor = color;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003497 "}\n";
3498
3499
3500
3501 ASSERT_NO_FATAL_FAILURE(InitState());
3502 ASSERT_NO_FATAL_FAILURE(InitViewport());
3503
3504 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3505 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3506 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3507
3508 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003509 pipelineobj.AddColorAttachment();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003510 pipelineobj.AddShader(&vs);
3511 pipelineobj.AddShader(&gs);
3512 pipelineobj.AddShader(&ps);
3513
3514 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3515 VkCommandBufferObj cmdBuffer(m_device);
3516 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3517
3518 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3519
3520 VkDescriptorSetObj descriptorSet(m_device);
3521
3522 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3523
3524 // render triangle
3525 cmdBuffer.Draw(0, 3, 0, 1);
3526
3527 // finalize recording of the command buffer
3528 EndCommandBuffer(cmdBuffer);
3529 cmdBuffer.QueueCommandBuffer();
3530
3531 RecordImages(m_renderTargets);
3532}
3533
3534TEST_F(VkRenderTest, GSUniformBufferLayout)
3535{
3536 // This test is just like TriangleUniformBufferLayout but adds
3537 // geometry as a stage that also does UBO lookups
3538 // The expected result from this test is a green triangle
3539
3540 static const char *vertShaderText =
3541 "#version 140\n"
3542 "#extension GL_ARB_separate_shader_objects : enable\n"
3543 "#extension GL_ARB_shading_language_420pack : enable\n"
3544 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3545 " vec4 fRed;\n"
3546 " vec4 fGreen;\n"
3547 " layout(row_major) mat4 worldToProj;\n"
3548 " layout(row_major) mat4 projToWorld;\n"
3549 " layout(row_major) mat4 worldToView;\n"
3550 " layout(row_major) mat4 viewToProj;\n"
3551 " layout(row_major) mat4 worldToShadow[4];\n"
3552 " float fZero;\n"
3553 " float fOne;\n"
3554 " float fTwo;\n"
3555 " float fThree;\n"
3556 " vec3 fZeroZeroZero;\n"
3557 " float fFour;\n"
3558 " vec3 fZeroZeroOne;\n"
3559 " float fFive;\n"
3560 " vec3 fZeroOneZero;\n"
3561 " float fSix;\n"
3562 " float fSeven;\n"
3563 " float fEight;\n"
3564 " float fNine;\n"
3565 " vec2 fZeroZero;\n"
3566 " vec2 fZeroOne;\n"
3567 " vec4 fBlue;\n"
3568 " vec2 fOneZero;\n"
3569 " vec2 fOneOne;\n"
3570 " vec3 fZeroOneOne;\n"
3571 " float fTen;\n"
3572 " float fEleven;\n"
3573 " float fTwelve;\n"
3574 " vec3 fOneZeroZero;\n"
3575 " vec4 uvOffsets[4];\n"
3576 "};\n"
3577 "layout (location = 0) out vec4 color;"
3578 "void main() {\n"
3579
3580 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3581 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3582 " \n"
3583
3584 // do some exact comparisons, even though we should
3585 // really have an epsilon involved.
3586 " vec4 outColor = right;\n"
3587 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3588 " outColor = wrong;\n"
3589 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3590 " outColor = wrong;\n"
3591 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3592 " outColor = wrong;\n"
3593
3594 " color = outColor;\n"
3595
3596 // generic position stuff
3597 " vec2 vertices;\n"
3598 " int vertexSelector = gl_VertexID;\n"
3599 " if (vertexSelector == 0)\n"
3600 " vertices = vec2(-0.5, -0.5);\n"
3601 " else if (vertexSelector == 1)\n"
3602 " vertices = vec2( 0.5, -0.5);\n"
3603 " else if (vertexSelector == 2)\n"
3604 " vertices = vec2( 0.5, 0.5);\n"
3605 " else\n"
3606 " vertices = vec2( 0.0, 0.0);\n"
3607 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3608 "}\n";
3609
3610 static const char *geomShaderText =
3611 "#version 330\n"
3612 "#extension GL_ARB_separate_shader_objects : enable\n"
3613 "#extension GL_ARB_shading_language_420pack : enable\n"
3614
3615 // GS layout stuff
3616 "layout( triangles ) in;\n"
3617 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3618
3619 // Between stage IO
3620 "layout( location = 0 ) in vec4 inColor[3];\n"
3621 "layout( location = 0 ) out vec4 color;\n"
3622
3623 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3624 " vec4 fRed;\n"
3625 " vec4 fGreen;\n"
3626 " layout(row_major) mat4 worldToProj;\n"
3627 " layout(row_major) mat4 projToWorld;\n"
3628 " layout(row_major) mat4 worldToView;\n"
3629 " layout(row_major) mat4 viewToProj;\n"
3630 " layout(row_major) mat4 worldToShadow[4];\n"
3631 " float fZero;\n"
3632 " float fOne;\n"
3633 " float fTwo;\n"
3634 " float fThree;\n"
3635 " vec3 fZeroZeroZero;\n"
3636 " float fFour;\n"
3637 " vec3 fZeroZeroOne;\n"
3638 " float fFive;\n"
3639 " vec3 fZeroOneZero;\n"
3640 " float fSix;\n"
3641 " float fSeven;\n"
3642 " float fEight;\n"
3643 " float fNine;\n"
3644 " vec2 fZeroZero;\n"
3645 " vec2 fZeroOne;\n"
3646 " vec4 fBlue;\n"
3647 " vec2 fOneZero;\n"
3648 " vec2 fOneOne;\n"
3649 " vec3 fZeroOneOne;\n"
3650 " float fTen;\n"
3651 " float fEleven;\n"
3652 " float fTwelve;\n"
3653 " vec3 fOneZeroZero;\n"
3654 " vec4 uvOffsets[4];\n"
3655 "};\n"
3656
3657 "void main()\n"
3658 "{\n"
3659
3660 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3661 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3662
3663 // Each vertex will validate it can read VS output
3664 // then check a few values from the UBO
3665
3666 // first vertex
3667 " vec4 outColor = inColor[0];\n"
3668
3669 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3670 " outColor = wrong;\n"
3671 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3672 " outColor = wrong;\n"
3673 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3674 " outColor = wrong;\n"
3675 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3676 " outColor = wrong;\n"
3677
3678 " gl_Position = gl_in[0].gl_Position;\n"
3679 " color = outColor;\n"
3680 " EmitVertex();\n"
3681
3682 // second vertex
3683 " outColor = inColor[1];\n"
3684
3685 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3686 " outColor = wrong;\n"
3687 " if (fSix != 6.0)\n"
3688 " outColor = wrong;\n"
3689 " if (fOneOne != vec2(1.0, 1.0))\n"
3690 " outColor = wrong;\n"
3691
3692 " gl_Position = gl_in[1].gl_Position;\n"
3693 " color = outColor;\n"
3694 " EmitVertex();\n"
3695
3696 // third vertex
3697 " outColor = inColor[2];\n"
3698
3699 " if (fSeven != 7.0)\n"
3700 " outColor = wrong;\n"
3701 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3702 " outColor = wrong;\n"
3703
3704 " gl_Position = gl_in[2].gl_Position;\n"
3705 " color = outColor;\n"
3706 " EmitVertex();\n"
3707
3708 // done
3709 " EndPrimitive();\n"
3710 "}\n";
3711
3712 static const char *fragShaderText =
3713 "#version 140\n"
3714 "#extension GL_ARB_separate_shader_objects : enable\n"
3715 "#extension GL_ARB_shading_language_420pack : enable\n"
3716 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3717 " vec4 fRed;\n"
3718 " vec4 fGreen;\n"
3719 " layout(row_major) mat4 worldToProj;\n"
3720 " layout(row_major) mat4 projToWorld;\n"
3721 " layout(row_major) mat4 worldToView;\n"
3722 " layout(row_major) mat4 viewToProj;\n"
3723 " layout(row_major) mat4 worldToShadow[4];\n"
3724 " float fZero;\n"
3725 " float fOne;\n"
3726 " float fTwo;\n"
3727 " float fThree;\n"
3728 " vec3 fZeroZeroZero;\n"
3729 " float fFour;\n"
3730 " vec3 fZeroZeroOne;\n"
3731 " float fFive;\n"
3732 " vec3 fZeroOneZero;\n"
3733 " float fSix;\n"
3734 " float fSeven;\n"
3735 " float fEight;\n"
3736 " float fNine;\n"
3737 " vec2 fZeroZero;\n"
3738 " vec2 fZeroOne;\n"
3739 " vec4 fBlue;\n"
3740 " vec2 fOneZero;\n"
3741 " vec2 fOneOne;\n"
3742 " vec3 fZeroOneOne;\n"
3743 " float fTen;\n"
3744 " float fEleven;\n"
3745 " float fTwelve;\n"
3746 " vec3 fOneZeroZero;\n"
3747 " vec4 uvOffsets[4];\n"
3748 "};\n"
3749 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003750 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003751 "void main() {\n"
3752 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3753 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3754 " \n"
3755
3756 // start with GS value to ensure it passed
3757 " vec4 outColor = color;\n"
3758
3759 // do some exact comparisons, even though we should
3760 // really have an epsilon involved.
3761 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3762 " outColor = wrong;\n"
3763 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3764 " outColor = wrong;\n"
3765 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3766 " outColor = wrong;\n"
3767 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3768 " outColor = wrong;\n"
3769 " if (fTwo != 2.0)\n"
3770 " outColor = wrong;\n"
3771 " if (fOneOne != vec2(1.0, 1.0))\n"
3772 " outColor = wrong;\n"
3773 " if (fTen != 10.0)\n"
3774 " outColor = wrong;\n"
3775 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3776 " outColor = wrong;\n"
3777 " \n"
GregFd6ebdb32015-06-03 18:40:50 -06003778 " uFragColor = outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003779 "}\n";
3780
3781
3782 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3783 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3784 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3785 0.0, 1.0, 0.0, 1.0, // align
3786 0.0, 0.0, 1.0, 1.0, // align
3787 0.0, 0.0, 0.0, 1.0, // align
3788 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3789 0.0, 2.0, 0.0, 2.0, // align
3790 0.0, 0.0, 2.0, 2.0, // align
3791 0.0, 0.0, 0.0, 2.0, // align
3792 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3793 0.0, 3.0, 0.0, 3.0, // align
3794 0.0, 0.0, 3.0, 3.0, // align
3795 0.0, 0.0, 0.0, 3.0, // align
3796 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3797 0.0, 4.0, 0.0, 4.0, // align
3798 0.0, 0.0, 4.0, 4.0, // align
3799 0.0, 0.0, 0.0, 4.0, // align
3800 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3801 0.0, 5.0, 0.0, 5.0, // align
3802 0.0, 0.0, 5.0, 5.0, // align
3803 0.0, 0.0, 0.0, 5.0, // align
3804 6.0, 0.0, 0.0, 6.0, // align
3805 0.0, 6.0, 0.0, 6.0, // align
3806 0.0, 0.0, 6.0, 6.0, // align
3807 0.0, 0.0, 0.0, 6.0, // align
3808 7.0, 0.0, 0.0, 7.0, // align
3809 0.0, 7.0, 0.0, 7.0, // align
3810 0.0, 0.0, 7.0, 7.0, // align
3811 0.0, 0.0, 0.0, 7.0, // align
3812 8.0, 0.0, 0.0, 8.0, // align
3813 0.0, 8.0, 0.0, 8.0, // align
3814 0.0, 0.0, 8.0, 8.0, // align
3815 0.0, 0.0, 0.0, 8.0, // align
3816 0.0, // float fZero; // align
3817 1.0, // float fOne; // pack
3818 2.0, // float fTwo; // pack
3819 3.0, // float fThree; // pack
3820 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3821 4.0, // float fFour; // pack
3822 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3823 5.0, // float fFive; // pack
3824 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3825 6.0, // float fSix; // pack
3826 7.0, // float fSeven; // align
3827 8.0, // float fEight; // pack
3828 9.0, // float fNine; // pack
3829 0.0, // BUFFER
3830 0.0, 0.0, // vec2 fZeroZero; // align
3831 0.0, 1.0, // vec2 fZeroOne; // pack
3832 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3833 1.0, 0.0, // vec2 fOneZero; // align
3834 1.0, 1.0, // vec2 fOneOne; // pack
3835 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3836 10.0, // float fTen; // pack
3837 11.0, // float fEleven; // align
3838 12.0, // float fTwelve; // pack
3839 0.0, 0.0, // BUFFER
3840 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3841 0.0, // BUFFER
3842 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3843 0.5, 0.6, 0.7, 0.8, // align
3844 0.9, 1.0, 1.1, 1.2, // align
3845 1.3, 1.4, 1.5, 1.6, // align
3846 };
3847
3848
3849
3850 ASSERT_NO_FATAL_FAILURE(InitState());
3851 ASSERT_NO_FATAL_FAILURE(InitViewport());
3852
3853 const int constCount = sizeof(mixedVals) / sizeof(float);
3854
3855 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3856 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3857 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3858
3859 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
3860
3861 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003862 pipelineobj.AddColorAttachment();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003863 pipelineobj.AddShader(&vs);
3864 pipelineobj.AddShader(&gs);
3865 pipelineobj.AddShader(&ps);
3866
3867 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3868 VkCommandBufferObj cmdBuffer(m_device);
3869 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3870
3871 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3872
3873 VkDescriptorSetObj descriptorSet(m_device);
3874 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
3875
3876 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3877
3878 // render triangle
3879 cmdBuffer.Draw(0, 3, 0, 1);
3880
3881 // finalize recording of the command buffer
3882 EndCommandBuffer(cmdBuffer);
3883 cmdBuffer.QueueCommandBuffer();
3884
3885 RecordImages(m_renderTargets);
3886}
3887
3888TEST_F(VkRenderTest, GSPositions)
3889{
3890 // This test adds more inputs from the vertex shader and perturbs positions
3891 // Expected result is white triangle with weird positions
3892
3893 static const char *vertShaderText =
3894 "#version 140\n"
3895 "#extension GL_ARB_separate_shader_objects : enable\n"
3896 "#extension GL_ARB_shading_language_420pack : enable\n"
3897
3898 "layout(location = 0) out vec3 out_a;\n"
3899 "layout(location = 1) out vec3 out_b;\n"
3900 "layout(location = 2) out vec3 out_c;\n"
3901
3902 "void main() {\n"
3903
3904 // write a solid color to each
3905 " out_a = vec3(1.0, 0.0, 0.0);\n"
3906 " out_b = vec3(0.0, 1.0, 0.0);\n"
3907 " out_c = vec3(0.0, 0.0, 1.0);\n"
3908
3909 // generic position stuff
3910 " vec2 vertices;\n"
3911 " int vertexSelector = gl_VertexID;\n"
3912 " if (vertexSelector == 0)\n"
3913 " vertices = vec2(-0.5, -0.5);\n"
3914 " else if (vertexSelector == 1)\n"
3915 " vertices = vec2( 0.5, -0.5);\n"
3916 " else if (vertexSelector == 2)\n"
3917 " vertices = vec2( 0.5, 0.5);\n"
3918 " else\n"
3919 " vertices = vec2( 0.0, 0.0);\n"
3920 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3921
3922 "}\n";
3923
3924 static const char *geomShaderText =
3925 "#version 330\n"
3926 "#extension GL_ARB_separate_shader_objects : enable\n"
3927 "#extension GL_ARB_shading_language_420pack : enable\n"
3928 "layout( triangles ) in;\n"
3929 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3930
3931 "layout(location = 0) in vec3 in_a[3];\n"
3932 "layout(location = 1) in vec3 in_b[3];\n"
3933 "layout(location = 2) in vec3 in_c[3];\n"
3934
3935 "layout(location = 0) out vec3 out_a;\n"
3936 "layout(location = 1) out vec3 out_b;\n"
3937 "layout(location = 2) out vec3 out_c;\n"
3938
3939 "void main()\n"
3940 "{\n"
3941
3942 " gl_Position = gl_in[0].gl_Position;\n"
3943 " gl_Position.xy *= vec2(0.75);\n"
3944 " out_a = in_a[0];\n"
3945 " out_b = in_b[0];\n"
3946 " out_c = in_c[0];\n"
3947 " EmitVertex();\n"
3948
3949 " gl_Position = gl_in[1].gl_Position;\n"
3950 " gl_Position.xy *= vec2(1.5);\n"
3951 " out_a = in_a[1];\n"
3952 " out_b = in_b[1];\n"
3953 " out_c = in_c[1];\n"
3954 " EmitVertex();\n"
3955
3956 " gl_Position = gl_in[2].gl_Position;\n"
3957 " gl_Position.xy *= vec2(-0.1);\n"
3958 " out_a = in_a[2];\n"
3959 " out_b = in_b[2];\n"
3960 " out_c = in_c[2];\n"
3961 " EmitVertex();\n"
3962
3963 " EndPrimitive();\n"
3964 "}\n";
3965
3966
3967 static const char *fragShaderText =
3968 "#version 140\n"
3969 "#extension GL_ARB_separate_shader_objects : enable\n"
3970 "#extension GL_ARB_shading_language_420pack : enable\n"
3971
3972 "layout(location = 0) in vec3 in_a;\n"
3973 "layout(location = 1) in vec3 in_b;\n"
3974 "layout(location = 2) in vec3 in_c;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003975 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003976
3977 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06003978 " outColor = vec4(in_a.x, in_b.y, in_c.z, 1.0);\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003979 "}\n";
3980
3981
3982
3983 ASSERT_NO_FATAL_FAILURE(InitState());
3984 ASSERT_NO_FATAL_FAILURE(InitViewport());
3985
3986 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3987 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3988 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3989
3990 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003991 pipelineobj.AddColorAttachment();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003992 pipelineobj.AddShader(&vs);
3993 pipelineobj.AddShader(&gs);
3994 pipelineobj.AddShader(&ps);
3995
3996 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3997 VkCommandBufferObj cmdBuffer(m_device);
3998 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3999
4000 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
4001
4002 VkDescriptorSetObj descriptorSet(m_device);
4003
4004 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
4005
4006 // render triangle
4007 cmdBuffer.Draw(0, 3, 0, 1);
4008
4009 // finalize recording of the command buffer
4010 EndCommandBuffer(cmdBuffer);
4011 cmdBuffer.QueueCommandBuffer();
4012
4013 RecordImages(m_renderTargets);
4014}
4015
4016TEST_F(VkRenderTest, GSTriStrip)
4017{
4018 // This test emits multiple multiple triangles using a GS
4019 // Correct result is an multicolor circle
4020
4021 static const char *vertShaderText =
4022 "#version 140\n"
4023 "#extension GL_ARB_separate_shader_objects : enable\n"
4024 "#extension GL_ARB_shading_language_420pack : enable\n"
4025
4026 "void main() {\n"
4027
4028 // generic position stuff
4029 " vec2 vertices;\n"
4030 " int vertexSelector = gl_VertexID;\n"
4031 " if (vertexSelector == 0)\n"
4032 " vertices = vec2(-0.5, -0.5);\n"
4033 " else if (vertexSelector == 1)\n"
4034 " vertices = vec2( 0.5, -0.5);\n"
4035 " else if (vertexSelector == 2)\n"
4036 " vertices = vec2( 0.5, 0.5);\n"
4037 " else\n"
4038 " vertices = vec2( 0.0, 0.0);\n"
4039 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
4040
4041 "}\n";
4042
4043 static const char *geomShaderText =
4044 "#version 330\n"
4045 "#extension GL_ARB_separate_shader_objects : enable\n"
4046 "#extension GL_ARB_shading_language_420pack : enable\n"
4047 "layout( triangles ) in;\n"
4048 "layout( triangle_strip, max_vertices = 18 ) out;\n"
4049
4050 "layout(location = 0) out vec4 outColor;\n"
4051
4052 "void main()\n"
4053 "{\n"
4054 // init with first position to get zw
4055 " gl_Position = gl_in[0].gl_Position;\n"
4056
4057 " vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
4058 " vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
4059 " vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
4060 " vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
4061
4062 // different color per tri
4063 " vec4[6] colors = { red, white, \n"
4064 " yellow, white, \n"
4065 " blue, white }; \n"
4066
4067 // fan out the triangles
4068 " vec2[18] positions = { vec2(0.0, 0.0), vec2(-0.5, 0.0), vec2(-0.25, -0.5), \n"
4069 " vec2(0.0, 0.0), vec2(-0.25, -0.5), vec2( 0.25, -0.5), \n"
4070 " vec2(0.0, 0.0), vec2( 0.25, -0.5), vec2( 0.5, 0.0), \n"
4071 " vec2(0.0, 0.0), vec2( 0.5, 0.0), vec2( 0.25, 0.5), \n"
4072 " vec2(0.0, 0.0), vec2( 0.25, 0.5), vec2(-0.25, 0.5), \n"
4073 " vec2(0.0, 0.0), vec2(-0.25, 0.5), vec2(-0.5, 0.0) }; \n"
4074
4075 // make a triangle list of 6
4076 " for (int i = 0; i < 6; ++i) { \n"
4077 " outColor = colors[i]; \n"
4078 " for (int j = 0; j < 3; ++j) { \n"
4079 " gl_Position.xy = positions[i * 3 + j]; \n"
4080 " EmitVertex(); \n"
4081 " } \n"
4082 " EndPrimitive();\n"
4083 " } \n"
4084
4085 "}\n";
4086
4087
4088 static const char *fragShaderText =
4089 "#version 150\n"
4090 "#extension GL_ARB_separate_shader_objects : enable\n"
4091 "#extension GL_ARB_shading_language_420pack : enable\n"
4092
4093
4094 "layout(binding = 0) uniform windowDimensions {\n"
4095 " vec4 dimensions;\n"
4096 "};\n"
4097
4098 "layout(location = 0) in vec4 inColor;\n"
4099 "layout(origin_upper_left) in vec4 gl_FragCoord;\n"
GregFd6ebdb32015-06-03 18:40:50 -06004100 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06004101
4102 "void main() {\n"
4103
4104 // discard to make a nice circle
4105 " vec2 pos = abs(gl_FragCoord.xy) - vec2(dimensions.x, dimensions.y) / 2;\n"
4106 " float dist = sqrt(dot(pos, pos));\n"
4107 " if (dist > 50.0)\n"
4108 " discard;\n"
4109
GregFd6ebdb32015-06-03 18:40:50 -06004110 " outColor = inColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06004111
4112 "}\n";
4113
4114
4115
4116 ASSERT_NO_FATAL_FAILURE(InitState());
4117 ASSERT_NO_FATAL_FAILURE(InitViewport());
4118
4119 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
4120 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
4121 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
4122
4123 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004124 pipelineobj.AddColorAttachment();
Cody Northropa44c2ff2015-04-15 11:19:06 -06004125 pipelineobj.AddShader(&vs);
4126 pipelineobj.AddShader(&gs);
4127 pipelineobj.AddShader(&ps);
4128
4129 const float dimensions[4] = { VkRenderFramework::m_width, VkRenderFramework::m_height , 0.0, 0.0};
4130
4131 VkConstantBufferObj windowDimensions(m_device, sizeof(dimensions) / sizeof(dimensions[0]), sizeof(dimensions[0]), (const void*) dimensions);
4132
4133 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4134 VkCommandBufferObj cmdBuffer(m_device);
4135 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
4136
4137 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
4138
4139 VkDescriptorSetObj descriptorSet(m_device);
4140 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, windowDimensions);
4141
4142 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
4143
4144 // render triangle
4145 cmdBuffer.Draw(0, 3, 0, 1);
4146
4147 // finalize recording of the command buffer
4148 EndCommandBuffer(cmdBuffer);
4149 cmdBuffer.QueueCommandBuffer();
4150
4151 RecordImages(m_renderTargets);
4152}
4153
Chris Forbes23e6db62015-06-15 09:32:35 +12004154TEST_F(VkRenderTest, RenderPassLoadOpClear)
4155{
4156 ASSERT_NO_FATAL_FAILURE(InitState());
4157 ASSERT_NO_FATAL_FAILURE(InitViewport());
4158
4159 /* clear via load op to full green */
4160 m_clear_via_load_op = true;
Chris Forbese3105972015-06-24 14:34:53 +12004161 m_clear_color.f32[0] = 0;
4162 m_clear_color.f32[1] = 1;
4163 m_clear_color.f32[2] = 0;
4164 m_clear_color.f32[3] = 0;
Chris Forbes23e6db62015-06-15 09:32:35 +12004165 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4166
4167 VkCommandBufferObj cmdBuffer(m_device);
4168 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
4169 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
4170 /* This command buffer contains ONLY the load op! */
4171 EndCommandBuffer(cmdBuffer);
4172 cmdBuffer.QueueCommandBuffer();
4173
4174 RecordImages(m_renderTargets);
4175}
4176
Chris Forbes1e16cb82015-06-24 12:05:30 +12004177TEST_F(VkRenderTest, RenderPassAttachmentClear)
4178{
4179 ASSERT_NO_FATAL_FAILURE(InitState());
4180 ASSERT_NO_FATAL_FAILURE(InitViewport());
4181
4182 /* clear via load op to full red */
4183 m_clear_via_load_op = true;
Chris Forbese3105972015-06-24 14:34:53 +12004184 m_clear_color.f32[0] = 1;
4185 m_clear_color.f32[1] = 0;
4186 m_clear_color.f32[2] = 0;
4187 m_clear_color.f32[3] = 0;
Chris Forbes1e16cb82015-06-24 12:05:30 +12004188 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4189
4190 VkCommandBufferObj cmdBuffer(m_device);
4191 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
4192 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
4193
4194 /* Load op has cleared to red */
4195
4196 /* Draw, draw, draw... */
4197
4198 /* Now, partway through this renderpass we want to clear the color
4199 * attachment again, this time to green.
4200 */
Chris Forbese3105972015-06-24 14:34:53 +12004201 VkClearColorValue clear_color;
4202 clear_color.f32[0] = 0;
4203 clear_color.f32[1] = 1;
4204 clear_color.f32[2] = 0;
4205 clear_color.f32[3] = 0;
Chris Forbes1e16cb82015-06-24 12:05:30 +12004206 VkRect3D clear_rect = { { 0, 0, 0 }, { (int)m_width, (int)m_height, 1 } };
Chia-I Wu78c2a352015-07-03 11:49:42 +08004207 vkCmdClearColorAttachment(cmdBuffer.handle(), 0,
Chris Forbes1e16cb82015-06-24 12:05:30 +12004208 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4209 &clear_color, 1, &clear_rect);
4210
4211 EndCommandBuffer(cmdBuffer);
4212 cmdBuffer.QueueCommandBuffer();
4213
4214 RecordImages(m_renderTargets);
4215}
4216
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004217int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004218 int result;
4219
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004220 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06004221 VkTestFramework::InitArgs(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004222
Chia-I Wu7133fdc2014-12-15 23:57:34 +08004223 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06004224
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004225 result = RUN_ALL_TESTS();
4226
Tony Barbour01999182015-04-09 12:58:51 -06004227 VkTestFramework::Finish();
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004228 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004229}