blob: 082280f1e1b9b810636508b9ed49c737026f19dd [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 Barbour17c6ab12015-03-27 17:03:18 -0600340 if (m_depthStencil->Initialized()) {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600341 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Tony Barbour17c6ab12015-03-27 17:03:18 -0600342 } else {
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600343 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour17c6ab12015-03-27 17:03:18 -0600344 }
345
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700346 cmdBuffer->PrepareAttachments();
Tony Barboure84a8d62015-07-10 14:10:27 -0600347 cmdBuffer->BindDynamicRasterState(m_stateRaster);
348 cmdBuffer->BindDynamicViewportState(m_stateViewport);
349 cmdBuffer->BindDynamicColorBlendState(m_colorBlend);
350 cmdBuffer->BindDynamicDepthStencilState(m_stateDepthStencil);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600351 descriptorSet.CreateVKDescriptorSet(cmdBuffer);
Chia-I Wuc278df82015-07-07 11:50:03 +0800352 pipelineobj.CreateVKPipeline(descriptorSet, renderPass());
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600353 cmdBuffer->BindPipeline(pipelineobj);
Chia-I Wu862c5572015-03-28 15:23:55 +0800354 cmdBuffer->BindDescriptorSet(descriptorSet);
Tony Barbour02472db2015-01-08 17:08:28 -0700355}
Tony Barbourf43b6982014-11-25 13:18:32 -0700356
Tony Barbour01999182015-04-09 12:58:51 -0600357void VkRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
358 VkConstantBufferObj *constantBuffer, VkCommandBufferObj *cmdBuffer)
Tony Barbourdd4c9642015-01-09 12:55:14 -0700359{
360 int i;
361 glm::mat4 MVP;
362 int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600363 VkResult err;
Tony Barbourdd4c9642015-01-09 12:55:14 -0700364
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -0600365 /* Only do 3 positions to avoid back face cull */
366 for (i = 0; i < 3; i++) {
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800367 void *pData = constantBuffer->memory().map();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700368
369 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
370 MVP = Projection * View * Model;
371 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
372
Chia-I Wuf4aed6c2015-07-03 13:44:34 +0800373 constantBuffer->memory().unmap();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700374
375 // submit the command buffer to the universal queue
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600376 cmdBuffer->QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -0700377
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600378 err = vkQueueWaitIdle( m_device->m_queue );
379 ASSERT_VK_SUCCESS( err );
Tony Barbourdd4c9642015-01-09 12:55:14 -0700380
381 // Wait for work to finish before cleaning up.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600382 vkDeviceWaitIdle(m_device->device());
Tony Barbourdd4c9642015-01-09 12:55:14 -0700383
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700384 assert(m_renderTargets.size() == 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -0700385 RecordImage(m_renderTargets[0]);
386 }
387}
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600388
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600389void dumpMatrix(const char *note, glm::mat4 MVP)
390{
Chia-I Wu7133fdc2014-12-15 23:57:34 +0800391 int i;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600392
393 printf("%s: \n", note);
394 for (i=0; i<4; i++) {
395 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
396 }
397 printf("\n");
398 fflush(stdout);
399}
400
401void dumpVec4(const char *note, glm::vec4 vector)
402{
403 printf("%s: \n", note);
404 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
405 printf("\n");
406 fflush(stdout);
407}
408
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600409struct vktriangle_vs_uniform {
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600410 // Must start with MVP
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600411 float mvp[4][4];
412 float position[3][4];
413 float color[3][4];
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600414};
415
Tony Barbour01999182015-04-09 12:58:51 -0600416void VkRenderTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600417{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700418#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600419 vkDbgRegisterMsgCallback(inst, myDbgFunc, NULL);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700420#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600421 // Create identity matrix
422 int i;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600423 struct vktriangle_vs_uniform data;
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600424
425 glm::mat4 Projection = glm::mat4(1.0f);
426 glm::mat4 View = glm::mat4(1.0f);
427 glm::mat4 Model = glm::mat4(1.0f);
428 glm::mat4 MVP = Projection * View * Model;
429 const int matrixSize = sizeof(MVP);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600430 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600431 memcpy(&data.mvp, &MVP[0][0], matrixSize);
432
433 static const Vertex tri_data[] =
434 {
435 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
436 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
437 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
438 };
439
440 for (i=0; i<3; i++) {
441 data.position[i][0] = tri_data[i].posX;
442 data.position[i][1] = tri_data[i].posY;
443 data.position[i][2] = tri_data[i].posZ;
444 data.position[i][3] = tri_data[i].posW;
445 data.color[i][0] = tri_data[i].r;
446 data.color[i][1] = tri_data[i].g;
447 data.color[i][2] = tri_data[i].b;
448 data.color[i][3] = tri_data[i].a;
449 }
450
Tony Barbourf43b6982014-11-25 13:18:32 -0700451 ASSERT_NO_FATAL_FAILURE(InitState());
452 ASSERT_NO_FATAL_FAILURE(InitViewport());
453
Tony Barbour01999182015-04-09 12:58:51 -0600454 VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barbourf43b6982014-11-25 13:18:32 -0700455
Tony Barbour01999182015-04-09 12:58:51 -0600456 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
457 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700458
Tony Barbour01999182015-04-09 12:58:51 -0600459 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800460 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -0700461 pipelineobj.AddShader(&vs);
462 pipelineobj.AddShader(&ps);
463
Tony Barbour01999182015-04-09 12:58:51 -0600464 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600465 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700466
Tony Barbour71ba3612015-01-09 16:12:35 -0700467 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600468 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour71ba3612015-01-09 16:12:35 -0700469 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700470
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600471 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour71ba3612015-01-09 16:12:35 -0700472
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600473 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbour71ba3612015-01-09 16:12:35 -0700474#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600475 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour71ba3612015-01-09 16:12:35 -0700476 pDSDumpDot((char*)"triTest2.dot");
477#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600478
Tony Barbour71ba3612015-01-09 16:12:35 -0700479 // render triangle
480 cmdBuffer.Draw(0, 3, 0, 1);
481
482 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600483 EndCommandBuffer(cmdBuffer);
484
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600485 cmdBuffer.QueueCommandBuffer();
Tony Barbour71ba3612015-01-09 16:12:35 -0700486
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600487 RecordImages(m_renderTargets);
Tony Barbour71ba3612015-01-09 16:12:35 -0700488
489 if (rotate)
Tobin Ehlis12ee35f2015-03-26 08:23:25 -0600490 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
Tony Barbour71ba3612015-01-09 16:12:35 -0700491
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700492#ifdef PRINT_OBJECTS
Mark Lobodzinski4e5016f2015-05-05 15:01:37 -0500493 OBJ_TRACK_GET_OBJECTS_COUNT pObjTrackGetObjectsCount = (OBJ_TRACK_GET_OBJECTS_COUNT)vkGetProcAddr(gpu(), (char*)"objTrackGetObjectsCount");
Mark Lobodzinski14305ad2015-06-23 11:35:12 -0600494 uint64_t numObjects = pObjTrackGetObjectsCount(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600495 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700496 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600497 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)vkGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700498 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
Mark Lobodzinski14305ad2015-06-23 11:35:12 -0600499 pObjTrackGetObjs(m_device, numObjects, pObjNodeArray);
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700500 for (i=0; i < numObjects; i++) {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600501 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 -0700502 }
503 free(pObjNodeArray);
504#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700505
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600506}
507
Tony Barbour01999182015-04-09 12:58:51 -0600508TEST_F(VkRenderTest, VKTriangle_FragColor)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600509{
510 static const char *vertShaderText =
511 "#version 140\n"
512 "#extension GL_ARB_separate_shader_objects : enable\n"
513 "#extension GL_ARB_shading_language_420pack : enable\n"
514 "\n"
515 "layout(binding = 0) uniform buf {\n"
516 " mat4 MVP;\n"
517 " vec4 position[3];\n"
518 " vec4 color[3];\n"
519 "} ubuf;\n"
520 "\n"
521 "layout (location = 0) out vec4 outColor;\n"
522 "\n"
523 "void main() \n"
524 "{\n"
525 " outColor = ubuf.color[gl_VertexID];\n"
526 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
527 "}\n";
528
529 static const char *fragShaderText =
530 "#version 140\n"
531 "#extension GL_ARB_separate_shader_objects : enable\n"
532 "#extension GL_ARB_shading_language_420pack : enable\n"
533 "\n"
534 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600535 "layout (location = 0) out vec4 uFragColor;\n"
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600536 "\n"
537 "void main()\n"
538 "{\n"
GregFd6ebdb32015-06-03 18:40:50 -0600539 " uFragColor = inColor;\n"
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600540 "}\n";
541
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600542 TEST_DESCRIPTION("VK-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
543 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600544}
545
Tony Barbour01999182015-04-09 12:58:51 -0600546TEST_F(VkRenderTest, VKTriangle_OutputLocation)
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600547{
548 static const char *vertShaderText =
549 "#version 140\n"
550 "#extension GL_ARB_separate_shader_objects : enable\n"
551 "#extension GL_ARB_shading_language_420pack : enable\n"
552 "\n"
553 "layout(binding = 0) uniform buf {\n"
554 " mat4 MVP;\n"
555 " vec4 position[3];\n"
556 " vec4 color[3];\n"
557 "} ubuf;\n"
558 "\n"
559 "layout (location = 0) out vec4 outColor;\n"
560 "\n"
561 "void main() \n"
562 "{\n"
563 " outColor = ubuf.color[gl_VertexID];\n"
564 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
565 "}\n";
566
567 static const char *fragShaderText =
568 "#version 140\n"
569 "#extension GL_ARB_separate_shader_objects : enable\n"
570 "#extension GL_ARB_shading_language_420pack : enable\n"
571 "\n"
572 "layout (location = 0) in vec4 inColor;\n"
573 "layout (location = 0) out vec4 outColor;\n"
574 "\n"
575 "void main()\n"
576 "{\n"
577 " outColor = inColor;\n"
578 "}\n";
579
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600580 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 -0600581
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600582 VKTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600583}
Cody Northrop71727d22015-06-23 13:25:51 -0600584
Tony Barbour01999182015-04-09 12:58:51 -0600585TEST_F(VkRenderTest, SPV_VKTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700586{
Tony Barbourf43b6982014-11-25 13:18:32 -0700587 static const char *vertShaderText =
588 "#version 140\n"
589 "#extension GL_ARB_separate_shader_objects : enable\n"
590 "#extension GL_ARB_shading_language_420pack : enable\n"
591 "\n"
592 "layout(binding = 0) uniform buf {\n"
593 " mat4 MVP;\n"
594 " vec4 position[3];\n"
595 " vec4 color[3];\n"
596 "} ubuf;\n"
597 "\n"
598 "layout (location = 0) out vec4 outColor;\n"
599 "\n"
600 "void main() \n"
601 "{\n"
602 " outColor = ubuf.color[gl_VertexID];\n"
603 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
604 "}\n";
605
606 static const char *fragShaderText =
607 "#version 140\n"
608 "#extension GL_ARB_separate_shader_objects : enable\n"
609 "#extension GL_ARB_shading_language_420pack : enable\n"
610 "\n"
611 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600612 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700613 "\n"
614 "void main()\n"
615 "{\n"
GregFd6ebdb32015-06-03 18:40:50 -0600616 " outColor = inColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700617 "}\n";
618
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600619 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 -0700620
Cody Northrop1cfbd172015-06-03 16:49:20 -0600621 ScopedUseGlsl useGlsl(false);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600622 VKTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700623}
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600624
Tony Barbour01999182015-04-09 12:58:51 -0600625TEST_F(VkRenderTest, SPV_GreenTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700626{
Tony Barbourf43b6982014-11-25 13:18:32 -0700627 static const char *vertShaderText =
628 "#version 130\n"
629 "vec2 vertices[3];\n"
630 "void main() {\n"
631 " vertices[0] = vec2(-1.0, -1.0);\n"
632 " vertices[1] = vec2( 1.0, -1.0);\n"
633 " vertices[2] = vec2( 0.0, 1.0);\n"
634 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
635 "}\n";
636
637 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600638 "#version 140\n"
639 "#extension GL_ARB_separate_shader_objects : enable\n"
640 "#extension GL_ARB_shading_language_420pack : enable\n"
641 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700642 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600643 " outColor = vec4(0,1,0,1);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700644 "}\n";
645
Cody Northropacfb0492015-03-17 15:55:58 -0600646 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700647
Cody Northrop1cfbd172015-06-03 16:49:20 -0600648 ScopedUseGlsl useGlsl(false);
649
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600650 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700651}
Cody Northrop71727d22015-06-23 13:25:51 -0600652
Tony Barbour01999182015-04-09 12:58:51 -0600653TEST_F(VkRenderTest, YellowTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700654{
655 static const char *vertShaderText =
656 "#version 130\n"
657 "void main() {\n"
658 " vec2 vertices[3];"
659 " vertices[0] = vec2(-0.5, -0.5);\n"
660 " vertices[1] = vec2( 0.5, -0.5);\n"
661 " vertices[2] = vec2( 0.5, 0.5);\n"
662 " vec4 colors[3];\n"
663 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
664 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
665 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
666 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
667 "}\n";
668
669 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600670 "#version 140\n"
671 "#extension GL_ARB_separate_shader_objects : enable\n"
672 "#extension GL_ARB_shading_language_420pack : enable\n"
673 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700674 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600675 " outColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700676 "}\n";
677
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600678 VKTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700679}
680
Tony Barbour01999182015-04-09 12:58:51 -0600681TEST_F(VkRenderTest, QuadWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600682{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600683 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600684 "#version 140\n"
685 "#extension GL_ARB_separate_shader_objects : enable\n"
686 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700687 //XYZ1( -1, -1, -1 )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600688 "layout (location = 0) in vec4 pos;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700689 //XYZ1( 0.f, 0.f, 0.f )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600690 "layout (location = 1) in vec4 inColor;\n"
691 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600692 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600693 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600694 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600695 "}\n";
696
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600697
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600698 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700699 "#version 140\n"
700 "#extension GL_ARB_separate_shader_objects : enable\n"
701 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600702 "layout (location = 0) in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700703 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600704 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700705 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600706 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600707
Tony Barbourf43b6982014-11-25 13:18:32 -0700708
709
710 ASSERT_NO_FATAL_FAILURE(InitState());
711 ASSERT_NO_FATAL_FAILURE(InitViewport());
712
Tony Barbour01999182015-04-09 12:58:51 -0600713 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000714 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700715
Tony Barbour01999182015-04-09 12:58:51 -0600716 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
717 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700718
Tony Barbour01999182015-04-09 12:58:51 -0600719 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800720 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -0700721 pipelineobj.AddShader(&vs);
722 pipelineobj.AddShader(&ps);
723
Tony Barbour01999182015-04-09 12:58:51 -0600724 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600725 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -0600726
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600727#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600728 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600729 MESH_BIND_ID, // binding ID
Tony Barbourf43b6982014-11-25 13:18:32 -0700730 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600731 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -0700732 };
733
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600734 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600735 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
736 vi_attribs[0].location = 0; // location, position
Tony Barbour8205d902015-04-16 15:59:00 -0600737 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600738 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
739 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
740 vi_attribs[1].location = 1; // location, color
Tony Barbour8205d902015-04-16 15:59:00 -0600741 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600742 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 -0700743
744 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
745 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600746 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -0700747
Tony Barboure4ed9942015-01-09 10:06:53 -0700748 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600749 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700750 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700751
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600752 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600753
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600754 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700755
Tony Barboure4ed9942015-01-09 10:06:53 -0700756 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
757
758 // render two triangles
759 cmdBuffer.Draw(0, 6, 0, 1);
760
761 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600762 EndCommandBuffer(cmdBuffer);
763
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600764 cmdBuffer.QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -0700765
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600766 RecordImages(m_renderTargets);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600767}
768
Tony Barbour01999182015-04-09 12:58:51 -0600769TEST_F(VkRenderTest, TriangleMRT)
Chia-I Wue09d1a72014-12-05 10:32:23 +0800770{
771 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600772 "#version 140\n"
773 "#extension GL_ARB_separate_shader_objects : enable\n"
774 "#extension GL_ARB_shading_language_420pack : enable\n"
775 "layout (location = 0) in vec4 pos;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800776 "void main() {\n"
777 " gl_Position = pos;\n"
778 "}\n";
779
780 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -0600781 "#version 140\n"
782 "#extension GL_ARB_separate_shader_objects : enable\n"
783 "#extension GL_ARB_shading_language_420pack : enable\n"
784 "layout (location = 0) out vec4 uFragData0;\n"
785 "layout (location = 1) out vec4 uFragData1;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800786 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600787 " uFragData0 = vec4(1.0, 0.0, 0.0, 1.0);\n"
788 " uFragData1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800789 "}\n";
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600790 const float vb_data[][2] = {
Chia-I Wue09d1a72014-12-05 10:32:23 +0800791 { -1.0f, -1.0f },
792 { 1.0f, -1.0f },
793 { -1.0f, 1.0f }
794 };
795
796 ASSERT_NO_FATAL_FAILURE(InitState());
797 ASSERT_NO_FATAL_FAILURE(InitViewport());
798
Tony Barbour01999182015-04-09 12:58:51 -0600799 VkConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000800 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800801
Tony Barbour01999182015-04-09 12:58:51 -0600802 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
803 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800804
Tony Barbour01999182015-04-09 12:58:51 -0600805 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800806 pipelineobj.AddColorAttachment();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800807 pipelineobj.AddShader(&vs);
808 pipelineobj.AddShader(&ps);
809
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600810#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600811 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600812 MESH_BUF_ID, // Binding ID
813 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600814 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Chia-I Wue09d1a72014-12-05 10:32:23 +0800815 };
816
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600817 VkVertexInputAttributeDescription vi_attrib;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600818 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
819 vi_attrib.location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -0600820 vi_attrib.format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600821 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
Chia-I Wue09d1a72014-12-05 10:32:23 +0800822
823 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
824 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600825 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800826
Tony Barbour01999182015-04-09 12:58:51 -0600827 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600828 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800829
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700830 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
Chia-I Wue09d1a72014-12-05 10:32:23 +0800831
Tony Barboure307f582015-07-10 15:29:03 -0600832 VkPipelineColorBlendAttachmentState att = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600833 att.blendEnable = VK_FALSE;
Chia-I Wue09d1a72014-12-05 10:32:23 +0800834 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700835 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800836
Tony Barbour01999182015-04-09 12:58:51 -0600837 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700838
Tony Barbour5ed79702015-01-07 14:31:52 -0700839 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
840 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barboure4ed9942015-01-09 10:06:53 -0700841
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600842 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour5ed79702015-01-07 14:31:52 -0700843
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600844 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barboure4ed9942015-01-09 10:06:53 -0700845
Tony Barbour5ed79702015-01-07 14:31:52 -0700846 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700847#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600848 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour5ed79702015-01-07 14:31:52 -0700849 pDSDumpDot((char*)"triTest2.dot");
850#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600851
Tony Barbour5ed79702015-01-07 14:31:52 -0700852 // render triangle
853 cmdBuffer.Draw(0, 3, 0, 1);
854
855 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600856 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600857 cmdBuffer.QueueCommandBuffer();
Tony Barbour5ed79702015-01-07 14:31:52 -0700858
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600859 RecordImages(m_renderTargets);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800860}
861
Tony Barbour01999182015-04-09 12:58:51 -0600862TEST_F(VkRenderTest, QuadWithIndexedVertexFetch)
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700863{
864 static const char *vertShaderText =
865 "#version 140\n"
866 "#extension GL_ARB_separate_shader_objects : enable\n"
867 "#extension GL_ARB_shading_language_420pack : enable\n"
868 "layout(location = 0) in vec4 pos;\n"
869 "layout(location = 1) in vec4 inColor;\n"
870 "layout(location = 0) out vec4 outColor;\n"
871 "void main() {\n"
872 " outColor = inColor;\n"
873 " gl_Position = pos;\n"
874 "}\n";
875
876
877 static const char *fragShaderText =
878 "#version 140\n"
879 "#extension GL_ARB_separate_shader_objects : enable\n"
880 "#extension GL_ARB_shading_language_420pack : enable\n"
881 "layout(location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600882 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700883 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -0600884 " outColor = color;\n"
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700885 "}\n";
886
887 const Vertex g_vbData[] =
888 {
889 // first tri
890 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
891 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
892 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
893
894 // second tri
895 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
896 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
897 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
898 };
899
900 const uint16_t g_idxData[6] = {
901 0, 1, 2,
902 3, 4, 5,
903 };
904
905 ASSERT_NO_FATAL_FAILURE(InitState());
906 ASSERT_NO_FATAL_FAILURE(InitViewport());
907
Tony Barbour01999182015-04-09 12:58:51 -0600908 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000909 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700910
Tony Barbour01999182015-04-09 12:58:51 -0600911 VkIndexBufferObj indexBuffer(m_device);
Tony Barbour8205d902015-04-16 15:59:00 -0600912 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), VK_INDEX_TYPE_UINT16, g_idxData);
Mark Lobodzinskid30f82a2015-02-16 14:24:23 -0600913 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700914
Tony Barbour01999182015-04-09 12:58:51 -0600915 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
916 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700917
Tony Barbour01999182015-04-09 12:58:51 -0600918 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +0800919 pipelineobj.AddColorAttachment();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700920 pipelineobj.AddShader(&vs);
921 pipelineobj.AddShader(&ps);
922
Tony Barbour01999182015-04-09 12:58:51 -0600923 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600924 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
925 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, indexBuffer);
Tony Barbour83a83802015-04-02 15:43:15 -0600926
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700927
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600928#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600929 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600930 MESH_BIND_ID, // binding ID
931 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600932 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700933 };
934
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600935 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600936 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
937 vi_attribs[0].location = 0; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600938 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600939 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
940 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
941 vi_attribs[1].location = 1; // layout location of vertex attribute
Tony Barbour8205d902015-04-16 15:59:00 -0600942 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600943 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700944
945 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
946 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700947
948 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -0600949 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700950 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600951 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barboure4ed9942015-01-09 10:06:53 -0700952
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600953 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700954
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700955#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600956 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700957 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700958#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700959
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600960 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600961 cmdBuffer.BindIndexBuffer(&indexBuffer, 0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700962
963 // render two triangles
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700964 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700965
966 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600967 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600968 cmdBuffer.QueueCommandBuffer();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700969
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600970 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700971}
972
Tony Barbour01999182015-04-09 12:58:51 -0600973TEST_F(VkRenderTest, GreyandRedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -0700974{
975 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -0700976
GregF6bef1212014-12-02 15:41:44 -0700977 static const char *vertShaderText =
978 "#version 140\n"
979 "#extension GL_ARB_separate_shader_objects : enable\n"
980 "#extension GL_ARB_shading_language_420pack : enable\n"
981 "layout (location = 0) in vec4 pos;\n"
982 "layout (location = 0) out vec4 outColor;\n"
983 "layout (location = 1) out vec4 outColor2;\n"
984 "void main() {\n"
985 " gl_Position = pos;\n"
986 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
987 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
988 "}\n";
989
990 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -0700991 "#version 330\n"
992 "#extension GL_ARB_separate_shader_objects : enable\n"
993 "#extension GL_ARB_shading_language_420pack : enable\n"
994 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
995 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
996 "layout (location = 0) in vec4 color;\n"
997 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -0600998 "layout (location = 0) out vec4 outColor;\n"
GregF6bef1212014-12-02 15:41:44 -0700999 "void main() {\n"
1000 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1001 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001002 " outColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001003 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1004 " : color2;\n"
1005 "}\n";
1006
1007 ASSERT_NO_FATAL_FAILURE(InitState());
1008 ASSERT_NO_FATAL_FAILURE(InitViewport());
1009
Tony Barbour01999182015-04-09 12:58:51 -06001010 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001011 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001012
Tony Barbour01999182015-04-09 12:58:51 -06001013 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1014 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001015
Tony Barbour01999182015-04-09 12:58:51 -06001016 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001017 pipelineobj.AddColorAttachment();
GregF6bef1212014-12-02 15:41:44 -07001018 pipelineobj.AddShader(&vs);
1019 pipelineobj.AddShader(&ps);
1020
Tony Barbour01999182015-04-09 12:58:51 -06001021 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001022 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001023
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001024#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001025 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001026 MESH_BIND_ID, // binding ID
1027 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001028 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001029 };
1030
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001031 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001032 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1033 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001034 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001035 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001036
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001037 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001038 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001039 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001040
Tony Barbourdd4c9642015-01-09 12:55:14 -07001041 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001042 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001043 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1044
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001045 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001046
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001047 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001048
1049 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1050#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001051 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001052 pDSDumpDot((char*)"triTest2.dot");
1053#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001054
Tony Barbourdd4c9642015-01-09 12:55:14 -07001055 // render triangle
1056 cmdBuffer.Draw(0, 6, 0, 1);
1057
1058 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001059 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001060 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001061
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001062 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001063}
1064
Tony Barbour01999182015-04-09 12:58:51 -06001065TEST_F(VkRenderTest, RedCirclesonBlue)
GregF6bef1212014-12-02 15:41:44 -07001066{
1067 // This tests that we correctly handle unread fragment inputs
1068
1069 static const char *vertShaderText =
1070 "#version 140\n"
1071 "#extension GL_ARB_separate_shader_objects : enable\n"
1072 "#extension GL_ARB_shading_language_420pack : enable\n"
1073 "layout (location = 0) in vec4 pos;\n"
1074 "layout (location = 0) out vec4 outColor;\n"
1075 "layout (location = 1) out vec4 outColor2;\n"
1076 "void main() {\n"
1077 " gl_Position = pos;\n"
1078 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1079 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1080 "}\n";
1081
1082 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001083 "#version 330\n"
1084 "#extension GL_ARB_separate_shader_objects : enable\n"
1085 "#extension GL_ARB_shading_language_420pack : enable\n"
1086 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1087 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1088 "layout (location = 0) in vec4 color;\n"
1089 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001090 "layout (location = 0) out vec4 outColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001091 "void main() {\n"
1092 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1093 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001094 " outColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001095 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1096 " : color2;\n"
1097 "}\n";
1098
1099 ASSERT_NO_FATAL_FAILURE(InitState());
1100 ASSERT_NO_FATAL_FAILURE(InitViewport());
1101
Tony Barbour01999182015-04-09 12:58:51 -06001102 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001103 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001104
Tony Barbour01999182015-04-09 12:58:51 -06001105 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1106 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001107
Tony Barbour01999182015-04-09 12:58:51 -06001108 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001109 pipelineobj.AddColorAttachment();
GregF6bef1212014-12-02 15:41:44 -07001110 pipelineobj.AddShader(&vs);
1111 pipelineobj.AddShader(&ps);
1112
Tony Barbour01999182015-04-09 12:58:51 -06001113 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001114 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001115
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001116#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001117 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001118 MESH_BIND_ID, // binding ID
1119 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001120 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001121 };
1122
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001123 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001124 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1125 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001126 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001127 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001128
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001129 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001130 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001131 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001132
Tony Barbourdd4c9642015-01-09 12:55:14 -07001133 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001134 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001135 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1136
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001137 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001138
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001139 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001140
1141 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1142#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001143 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001144 pDSDumpDot((char*)"triTest2.dot");
1145#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001146 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001147 cmdBuffer.Draw(0, 6, 0, 1);
1148
1149 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001150 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001151 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001152
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001153 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001154}
1155
Tony Barbour01999182015-04-09 12:58:51 -06001156TEST_F(VkRenderTest, GreyCirclesonBlueFade)
GregF6bef1212014-12-02 15:41:44 -07001157{
1158 // This tests reading gl_ClipDistance from FS
1159
1160 static const char *vertShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001161 //"#version 140\n"
GregF6bef1212014-12-02 15:41:44 -07001162 "#version 330\n"
1163 "#extension GL_ARB_separate_shader_objects : enable\n"
1164 "#extension GL_ARB_shading_language_420pack : enable\n"
1165 "out gl_PerVertex {\n"
1166 " vec4 gl_Position;\n"
1167 " float gl_ClipDistance[1];\n"
1168 "};\n"
1169 "layout (location = 0) in vec4 pos;\n"
1170 "layout (location = 0) out vec4 outColor;\n"
1171 "layout (location = 1) out vec4 outColor2;\n"
1172 "void main() {\n"
1173 " gl_Position = pos;\n"
1174 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1175 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1176 " float dists[3];\n"
1177 " dists[0] = 0.0;\n"
1178 " dists[1] = 1.0;\n"
1179 " dists[2] = 1.0;\n"
1180 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1181 "}\n";
1182
1183
1184 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001185 "#version 140\n"
1186 //"#version 330\n"
GregF6bef1212014-12-02 15:41:44 -07001187 "#extension GL_ARB_separate_shader_objects : enable\n"
1188 "#extension GL_ARB_shading_language_420pack : enable\n"
1189 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1190 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1191 "layout (location = 0) in vec4 color;\n"
1192 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001193 "layout (location = 0) out vec4 uFragColor;\n"
GregF6bef1212014-12-02 15:41:44 -07001194 "void main() {\n"
1195 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1196 " float dist_squared = dot(pos, pos);\n"
GregFd6ebdb32015-06-03 18:40:50 -06001197 " uFragColor = (dist_squared < 400.0)\n"
GregF6bef1212014-12-02 15:41:44 -07001198 " ? color * gl_ClipDistance[0]\n"
1199 " : color2;\n"
1200 "}\n";
1201
1202 ASSERT_NO_FATAL_FAILURE(InitState());
1203 ASSERT_NO_FATAL_FAILURE(InitViewport());
1204
Tony Barbour01999182015-04-09 12:58:51 -06001205 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001206 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001207
Tony Barbour01999182015-04-09 12:58:51 -06001208 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1209 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF6bef1212014-12-02 15:41:44 -07001210
Tony Barbour01999182015-04-09 12:58:51 -06001211 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001212 pipelineobj.AddColorAttachment();
GregF6bef1212014-12-02 15:41:44 -07001213 pipelineobj.AddShader(&vs);
1214 pipelineobj.AddShader(&ps);
1215
Tony Barbour01999182015-04-09 12:58:51 -06001216 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001217 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001218
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001219#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001220 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001221 MESH_BIND_ID, // binding ID
1222 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001223 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001224 };
1225
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001226 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001227 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1228 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001229 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001230 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001231
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001232 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001233 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001234 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001235
Tony Barbourdd4c9642015-01-09 12:55:14 -07001236 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001237 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001238 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF6bef1212014-12-02 15:41:44 -07001239
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001240 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001241
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001242 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001243
1244 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1245#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001246 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001247 pDSDumpDot((char*)"triTest2.dot");
1248#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001249
1250 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001251 cmdBuffer.Draw(0, 6, 0, 1);
1252
1253 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001254 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001255 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001256
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001257 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001258}
Tony Barbourf43b6982014-11-25 13:18:32 -07001259
Tony Barbour01999182015-04-09 12:58:51 -06001260TEST_F(VkRenderTest, GreyCirclesonBlueDiscard)
GregF7a23c792014-12-02 17:19:34 -07001261{
1262 static const char *vertShaderText =
1263 "#version 140\n"
1264 "#extension GL_ARB_separate_shader_objects : enable\n"
1265 "#extension GL_ARB_shading_language_420pack : enable\n"
1266 "layout (location = 0) in vec4 pos;\n"
1267 "layout (location = 0) out vec4 outColor;\n"
1268 "layout (location = 1) out vec4 outColor2;\n"
1269 "void main() {\n"
1270 " gl_Position = pos;\n"
1271 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1272 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1273 "}\n";
1274
1275
1276 static const char *fragShaderText =
GregF7a23c792014-12-02 17:19:34 -07001277 "#version 330\n"
1278 "#extension GL_ARB_separate_shader_objects : enable\n"
1279 "#extension GL_ARB_shading_language_420pack : enable\n"
1280 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1281 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1282 "layout (location = 0) in vec4 color;\n"
1283 "layout (location = 1) in vec4 color2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001284 "layout (location = 0) out vec4 outColor;\n"
GregF7a23c792014-12-02 17:19:34 -07001285 "void main() {\n"
1286 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1287 " float dist_squared = dot(pos, pos);\n"
1288 " if (dist_squared < 100.0)\n"
1289 " discard;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001290 " outColor = (dist_squared < 400.0)\n"
GregF7a23c792014-12-02 17:19:34 -07001291 " ? color\n"
1292 " : color2;\n"
1293 "}\n";
1294
1295 ASSERT_NO_FATAL_FAILURE(InitState());
1296 ASSERT_NO_FATAL_FAILURE(InitViewport());
1297
Tony Barbour01999182015-04-09 12:58:51 -06001298 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001299 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001300
Tony Barbour01999182015-04-09 12:58:51 -06001301 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1302 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
GregF7a23c792014-12-02 17:19:34 -07001303
Tony Barbour01999182015-04-09 12:58:51 -06001304 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001305 pipelineobj.AddColorAttachment();
GregF7a23c792014-12-02 17:19:34 -07001306 pipelineobj.AddShader(&vs);
1307 pipelineobj.AddShader(&ps);
1308
Tony Barbour01999182015-04-09 12:58:51 -06001309 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001310 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001311
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001312#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001313 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001314 MESH_BIND_ID, // binding ID
1315 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001316 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF7a23c792014-12-02 17:19:34 -07001317 };
1318
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001319 VkVertexInputAttributeDescription vi_attribs[1];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001320 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1321 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001322 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001323 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF7a23c792014-12-02 17:19:34 -07001324
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001325 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF7a23c792014-12-02 17:19:34 -07001326 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001327 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF7a23c792014-12-02 17:19:34 -07001328
Tony Barbourdd4c9642015-01-09 12:55:14 -07001329 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001330 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001331 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1332
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001333 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001334
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001335 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001336
1337 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1338#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001339 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001340 pDSDumpDot((char*)"triTest2.dot");
1341#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001342
1343 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001344 cmdBuffer.Draw(0, 6, 0, 1);
1345
1346 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001347 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001348 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001349
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001350 RecordImages(m_renderTargets);
GregF7a23c792014-12-02 17:19:34 -07001351}
1352
1353
Tony Barbour01999182015-04-09 12:58:51 -06001354TEST_F(VkRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001355{
1356 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001357 "#version 140\n"
1358 "#extension GL_ARB_separate_shader_objects : enable\n"
1359 "#extension GL_ARB_shading_language_420pack : enable\n"
1360 "\n"
1361 "layout(binding = 0) uniform buf {\n"
1362 " mat4 MVP;\n"
1363 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001364 "void main() {\n"
1365 " vec2 vertices[3];"
1366 " vertices[0] = vec2(-0.5, -0.5);\n"
1367 " vertices[1] = vec2( 0.5, -0.5);\n"
1368 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001369 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001370 "}\n";
1371
1372 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001373 "#version 140\n"
1374 "#extension GL_ARB_separate_shader_objects : enable\n"
1375 "#extension GL_ARB_shading_language_420pack : enable\n"
1376 "layout (location = 0) out vec4 outColor;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001377 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001378 " outColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001379 "}\n";
1380
Tony Barbourf43b6982014-11-25 13:18:32 -07001381 ASSERT_NO_FATAL_FAILURE(InitState());
1382 ASSERT_NO_FATAL_FAILURE(InitViewport());
1383
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001384 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001385 glm::mat4 Projection = glm::mat4(1.0f);
1386 glm::mat4 View = glm::mat4(1.0f);
1387 glm::mat4 Model = glm::mat4(1.0f);
1388 glm::mat4 MVP = Projection * View * Model;
1389 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1390
Tony Barbour01999182015-04-09 12:58:51 -06001391 VkConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1392 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1393 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001394
Tony Barbour01999182015-04-09 12:58:51 -06001395 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001396 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001397 pipelineobj.AddShader(&vs);
1398 pipelineobj.AddShader(&ps);
1399
1400 // Create descriptor set and attach the constant buffer to it
Tony Barbour01999182015-04-09 12:58:51 -06001401 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001402 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001403
Tony Barbourdd4c9642015-01-09 12:55:14 -07001404 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001405 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001406 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001407
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001408 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001409
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001410 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001411
1412 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1413#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001414 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001415 pDSDumpDot((char*)"triTest2.dot");
1416#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001417
1418 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001419 cmdBuffer.Draw(0, 6, 0, 1);
1420
1421 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001422 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001423 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001424
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001425 RecordImages(m_renderTargets);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001426
1427 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001428}
1429
Tony Barbour01999182015-04-09 12:58:51 -06001430TEST_F(VkRenderTest, MixTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07001431{
1432 // This tests location applied to varyings. Notice that we have switched foo
1433 // and bar in the FS. The triangle should be blended with red, green and blue
1434 // corners.
1435 static const char *vertShaderText =
1436 "#version 140\n"
1437 "#extension GL_ARB_separate_shader_objects : enable\n"
1438 "#extension GL_ARB_shading_language_420pack : enable\n"
1439 "layout (location=0) out vec4 bar;\n"
1440 "layout (location=1) out vec4 foo;\n"
1441 "layout (location=2) out float scale;\n"
1442 "vec2 vertices[3];\n"
1443 "void main() {\n"
1444 " vertices[0] = vec2(-1.0, -1.0);\n"
1445 " vertices[1] = vec2( 1.0, -1.0);\n"
1446 " vertices[2] = vec2( 0.0, 1.0);\n"
1447 "vec4 colors[3];\n"
1448 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1449 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1450 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1451 " foo = colors[gl_VertexID % 3];\n"
1452 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1453 " scale = 1.0;\n"
1454 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1455 "}\n";
1456
1457 static const char *fragShaderText =
1458 "#version 140\n"
1459 "#extension GL_ARB_separate_shader_objects : enable\n"
1460 "#extension GL_ARB_shading_language_420pack : enable\n"
1461 "layout (location = 1) in vec4 bar;\n"
1462 "layout (location = 0) in vec4 foo;\n"
1463 "layout (location = 2) in float scale;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001464 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001465 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001466 " outColor = bar * scale + foo * (1.0-scale);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001467 "}\n";
1468
1469 ASSERT_NO_FATAL_FAILURE(InitState());
1470 ASSERT_NO_FATAL_FAILURE(InitViewport());
1471
Tony Barbour01999182015-04-09 12:58:51 -06001472 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1473 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001474
Tony Barbour01999182015-04-09 12:58:51 -06001475 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001476 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001477 pipelineobj.AddShader(&vs);
1478 pipelineobj.AddShader(&ps);
1479
Tony Barbour01999182015-04-09 12:58:51 -06001480 VkDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06001481 descriptorSet.AppendDummy();
Tony Barbourf43b6982014-11-25 13:18:32 -07001482
Tony Barbourdd4c9642015-01-09 12:55:14 -07001483 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001484 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001485 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1486
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001487 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001488
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001489 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001490
1491#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001492 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001493 pDSDumpDot((char*)"triTest2.dot");
1494#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001495
Tony Barbourdd4c9642015-01-09 12:55:14 -07001496 // render triangle
1497 cmdBuffer.Draw(0, 3, 0, 1);
1498
1499 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001500 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001501 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001502
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001503 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001504}
1505
Tony Barbour01999182015-04-09 12:58:51 -06001506TEST_F(VkRenderTest, QuadVertFetchAndVertID)
Tony Barbourf43b6982014-11-25 13:18:32 -07001507{
1508 // This tests that attributes work in the presence of gl_VertexID
1509
1510 static const char *vertShaderText =
1511 "#version 140\n"
1512 "#extension GL_ARB_separate_shader_objects : enable\n"
1513 "#extension GL_ARB_shading_language_420pack : enable\n"
1514 //XYZ1( -1, -1, -1 )
1515 "layout (location = 0) in vec4 pos;\n"
1516 //XYZ1( 0.f, 0.f, 0.f )
1517 "layout (location = 1) in vec4 inColor;\n"
1518 "layout (location = 0) out vec4 outColor;\n"
1519 "void main() {\n"
1520 " outColor = inColor;\n"
1521 " vec4 vertices[3];"
1522 " vertices[gl_VertexID % 3] = pos;\n"
1523 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1524 "}\n";
1525
1526
1527 static const char *fragShaderText =
1528 "#version 140\n"
1529 "#extension GL_ARB_separate_shader_objects : enable\n"
1530 "#extension GL_ARB_shading_language_420pack : enable\n"
1531 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001532 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001533 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001534 " outColor = color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001535 "}\n";
1536
1537 ASSERT_NO_FATAL_FAILURE(InitState());
1538 ASSERT_NO_FATAL_FAILURE(InitViewport());
1539
Tony Barbour01999182015-04-09 12:58:51 -06001540 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001541 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001542
Tony Barbour01999182015-04-09 12:58:51 -06001543 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1544 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001545
Tony Barbour01999182015-04-09 12:58:51 -06001546 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001547 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001548 pipelineobj.AddShader(&vs);
1549 pipelineobj.AddShader(&ps);
1550
Tony Barbour01999182015-04-09 12:58:51 -06001551 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001552 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001553
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001554#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001555 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001556 MESH_BUF_ID, // Binding ID
1557 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001558 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001559 };
1560
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001561 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001562 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1563 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001564 vi_attribs[0].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001565 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1566 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1567 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001568 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001569 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001570
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001571 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001572 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001573 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001574
Tony Barbourdd4c9642015-01-09 12:55:14 -07001575 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001576 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001577 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1578
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001579 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001580
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001581 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001582
1583 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1584#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001585 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001586 pDSDumpDot((char*)"triTest2.dot");
1587#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001588
1589 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001590 cmdBuffer.Draw(0, 6, 0, 1);
1591
1592 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001593 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001594 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001595
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001596 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001597}
1598
Tony Barbour01999182015-04-09 12:58:51 -06001599TEST_F(VkRenderTest, QuadSparseVertFetch)
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001600{
1601 // This tests that attributes work in the presence of gl_VertexID
1602
1603 static const char *vertShaderText =
1604 "#version 140\n"
1605 "#extension GL_ARB_separate_shader_objects : enable\n"
1606 "#extension GL_ARB_shading_language_420pack : enable\n"
1607 //XYZ1( -1, -1, -1 )
1608 "layout (location = 1) in vec4 pos;\n"
1609 "layout (location = 4) in vec4 inColor;\n"
1610 //XYZ1( 0.f, 0.f, 0.f )
1611 "layout (location = 0) out vec4 outColor;\n"
1612 "void main() {\n"
1613 " outColor = inColor;\n"
1614 " gl_Position = pos;\n"
1615 "}\n";
1616
1617
1618 static const char *fragShaderText =
1619 "#version 140\n"
1620 "#extension GL_ARB_separate_shader_objects : enable\n"
1621 "#extension GL_ARB_shading_language_420pack : enable\n"
1622 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001623 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001624 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001625 " outColor = color;\n"
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001626 "}\n";
1627
1628 ASSERT_NO_FATAL_FAILURE(InitState());
1629 ASSERT_NO_FATAL_FAILURE(InitViewport());
1630
1631 struct VDATA
1632 {
1633 float t1, t2, t3, t4; // filler data
1634 float posX, posY, posZ, posW; // Position data
1635 float r, g, b, a; // Color
1636 };
1637 const struct VDATA vData[] =
1638 {
1639 { XYZ1(0, 0, 0), XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
1640 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1641 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1642 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1643 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1644 { XYZ1(0, 0, 0), XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
1645 };
1646
Tony Barbour01999182015-04-09 12:58:51 -06001647 VkConstantBufferObj meshBuffer(m_device,sizeof(vData)/sizeof(vData[0]),sizeof(vData[0]), vData);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001648 meshBuffer.BufferMemoryBarrier();
1649
Tony Barbour01999182015-04-09 12:58:51 -06001650 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1651 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001652
Tony Barbour01999182015-04-09 12:58:51 -06001653 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001654 pipelineobj.AddColorAttachment();
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001655 pipelineobj.AddShader(&vs);
1656 pipelineobj.AddShader(&ps);
1657
Tony Barbour01999182015-04-09 12:58:51 -06001658 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001659 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001660
1661#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001662 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001663 MESH_BUF_ID, // Binding ID
1664 sizeof(vData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001665 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001666 };
1667
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001668 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001669 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1670 vi_attribs[0].location = 4;
Tony Barbour8205d902015-04-16 15:59:00 -06001671 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001672 vi_attribs[0].offsetInBytes = sizeof(float) * 4 * 2; // Offset of first element in bytes from base of vertex
1673 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1674 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001675 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001676 vi_attribs[1].offsetInBytes = sizeof(float) * 4 * 1; // Offset of first element in bytes from base of vertex
1677
1678 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
1679 pipelineobj.AddVertexInputBindings(&vi_binding, 1);
1680 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
1681
1682 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001683 VkCommandBufferObj cmdBuffer(m_device);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001684 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1685
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001686 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001687
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001688 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001689
1690 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BUF_ID);
1691#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001692 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001693 pDSDumpDot((char*)"triTest2.dot");
1694#endif
1695
1696 // render two triangles
1697 cmdBuffer.Draw(0, 6, 0, 1);
1698
1699 // finalize recording of the command buffer
1700 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001701 cmdBuffer.QueueCommandBuffer();
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001702
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001703 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001704}
1705
Tony Barbour01999182015-04-09 12:58:51 -06001706TEST_F(VkRenderTest, TriVertFetchDeadAttr)
Tony Barbourf43b6982014-11-25 13:18:32 -07001707{
1708 // This tests that attributes work in the presence of gl_VertexID
1709 // and a dead attribute in position 0. Draws a triangle with yellow,
1710 // red and green corners, starting at top and going clockwise.
1711
1712 static const char *vertShaderText =
1713 "#version 140\n"
1714 "#extension GL_ARB_separate_shader_objects : enable\n"
1715 "#extension GL_ARB_shading_language_420pack : enable\n"
1716 //XYZ1( -1, -1, -1 )
1717 "layout (location = 0) in vec4 pos;\n"
1718 //XYZ1( 0.f, 0.f, 0.f )
1719 "layout (location = 1) in vec4 inColor;\n"
1720 "layout (location = 0) out vec4 outColor;\n"
1721 "void main() {\n"
1722 " outColor = inColor;\n"
1723 " vec2 vertices[3];"
1724 " vertices[0] = vec2(-1.0, -1.0);\n"
1725 " vertices[1] = vec2( 1.0, -1.0);\n"
1726 " vertices[2] = vec2( 0.0, 1.0);\n"
1727 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1728 "}\n";
1729
1730
1731 static const char *fragShaderText =
1732 "#version 140\n"
1733 "#extension GL_ARB_separate_shader_objects : enable\n"
1734 "#extension GL_ARB_shading_language_420pack : enable\n"
1735 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06001736 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001737 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001738 " outColor = color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001739 "}\n";
1740
1741 ASSERT_NO_FATAL_FAILURE(InitState());
1742 ASSERT_NO_FATAL_FAILURE(InitViewport());
1743
Tony Barbour01999182015-04-09 12:58:51 -06001744 VkConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001745 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001746
Tony Barbour01999182015-04-09 12:58:51 -06001747 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1748 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001749
Tony Barbour01999182015-04-09 12:58:51 -06001750 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001751 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001752 pipelineobj.AddShader(&vs);
1753 pipelineobj.AddShader(&ps);
1754
Tony Barbour01999182015-04-09 12:58:51 -06001755 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001756 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, meshBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001757
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001758#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001759 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001760 MESH_BUF_ID, // Binding ID
1761 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001762 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001763 };
1764
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001765 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001766 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1767 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001768 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001769 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1770 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1771 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001772 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001773 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001774
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001775 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001776 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001777 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001778
Tony Barbourdd4c9642015-01-09 12:55:14 -07001779 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001780 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001781 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001782
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001783 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001784
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001785 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001786
1787 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1788#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001789 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001790 pDSDumpDot((char*)"triTest2.dot");
1791#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001792
1793 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001794 cmdBuffer.Draw(0, 6, 0, 1);
1795
1796 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001797 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001798 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001799
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001800 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001801}
1802
Tony Barbour01999182015-04-09 12:58:51 -06001803TEST_F(VkRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001804{
1805 static const char *vertShaderText =
1806 "#version 140\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001807 "#extension GL_ARB_separate_shader_objects : enable\n"
1808 "#extension GL_ARB_shading_language_420pack : enable\n"
GregFd6ebdb32015-06-03 18:40:50 -06001809 "layout (std140, binding = 0) uniform bufferVals {\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001810 " mat4 mvp;\n"
1811 "} myBufferVals;\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001812 "layout (location = 0) in vec4 pos;\n"
1813 "layout (location = 1) in vec4 inColor;\n"
Cody Northrop74a2d2c2015-06-16 17:32:04 -06001814 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001815 "void main() {\n"
1816 " outColor = inColor;\n"
1817 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001818 " gl_Position.y = -gl_Position.y;\n"
1819 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001820 "}\n";
1821
1822 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001823 "#version 140\n"
1824 "#extension GL_ARB_separate_shader_objects : enable\n"
1825 "#extension GL_ARB_shading_language_420pack : enable\n"
1826 "layout (location = 0) in vec4 color;\n"
1827 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001828 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001829 " outColor = color;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001830 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001831 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001832
Tony Barbourf43b6982014-11-25 13:18:32 -07001833 glm::mat4 View = glm::lookAt(
1834 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1835 glm::vec3(0,0,0), // and looks at the origin
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06001836 glm::vec3(0,-1,0) // Head is up (set to 0,-1,0 to look upside-down)
Tony Barbourf43b6982014-11-25 13:18:32 -07001837 );
1838
1839 glm::mat4 Model = glm::mat4(1.0f);
1840
1841 glm::mat4 MVP = Projection * View * Model;
1842
1843 ASSERT_NO_FATAL_FAILURE(InitState());
1844 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wu9e81ebb2015-07-09 10:16:34 +08001845 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Chia-I Wuc278df82015-07-07 11:50:03 +08001846 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height, m_depth_stencil_fmt);
Tony Barbourf43b6982014-11-25 13:18:32 -07001847
Tony Barbour01999182015-04-09 12:58:51 -06001848 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 -07001849 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1850
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001851 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07001852
Tony Barbour01999182015-04-09 12:58:51 -06001853 VkConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1854 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1855 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07001856
Tony Barbour01999182015-04-09 12:58:51 -06001857 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001858 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001859 pipelineobj.AddShader(&vs);
1860 pipelineobj.AddShader(&ps);
1861
Tony Barboure307f582015-07-10 15:29:03 -06001862 VkPipelineDepthStencilStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001863 ds_state.depthTestEnable = VK_TRUE;
1864 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06001865 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001866 ds_state.depthBoundsEnable = VK_FALSE;
1867 ds_state.stencilTestEnable = VK_FALSE;
1868 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
1869 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
1870 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06001871 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001872 ds_state.front = ds_state.back;
1873 pipelineobj.SetDepthStencil(&ds_state);
1874
Tony Barbour01999182015-04-09 12:58:51 -06001875 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001876 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001877
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001878#define MESH_BUF_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001879 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001880 MESH_BUF_ID, // Binding ID
1881 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001882 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001883 };
Tony Barbourf43b6982014-11-25 13:18:32 -07001884
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001885 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001886 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1887 vi_attribs[0].location = 0;
Tony Barbour8205d902015-04-16 15:59:00 -06001888 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001889 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1890 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1891 vi_attribs[1].location = 1;
Tony Barbour8205d902015-04-16 15:59:00 -06001892 vi_attribs[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001893 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001894
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001895 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001896 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001897 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001898
Tony Barbour17c6ab12015-03-27 17:03:18 -06001899 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour17c6ab12015-03-27 17:03:18 -06001900
Tony Barbour01999182015-04-09 12:58:51 -06001901 VkCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -07001902 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001903
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001904 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001905 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001906
Tony Barboure4ed9942015-01-09 10:06:53 -07001907 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1908#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001909 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barboure4ed9942015-01-09 10:06:53 -07001910 pDSDumpDot((char*)"triTest2.dot");
1911#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001912
1913 // render triangles
Tony Barboure4ed9942015-01-09 10:06:53 -07001914 cmdBuffer.Draw(0, 36, 0, 1);
1915
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001916
Tony Barboure4ed9942015-01-09 10:06:53 -07001917 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001918 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001919 cmdBuffer.QueueCommandBuffer();
Tony Barboure4ed9942015-01-09 10:06:53 -07001920
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001921 RecordImages(m_renderTargets);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001922}
1923
Tony Barbour01999182015-04-09 12:58:51 -06001924TEST_F(VkRenderTest, VSTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07001925{
1926 // The expected result from this test is a green and red triangle;
1927 // one red vertex on the left, two green vertices on the right.
1928 static const char *vertShaderText =
Cody Northrop74a2d2c2015-06-16 17:32:04 -06001929 "#version 140\n"
1930 "#extension GL_ARB_separate_shader_objects : enable\n"
1931 "#extension GL_ARB_shading_language_420pack : enable\n"
1932 "layout (location = 0) out vec4 texColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001933 "uniform sampler2D surface;\n"
1934 "void main() {\n"
1935 " vec2 vertices[3];"
1936 " vertices[0] = vec2(-0.5, -0.5);\n"
1937 " vertices[1] = vec2( 0.5, -0.5);\n"
1938 " vertices[2] = vec2( 0.5, 0.5);\n"
1939 " vec2 positions[3];"
1940 " positions[0] = vec2( 0.0, 0.0);\n"
1941 " positions[1] = vec2( 0.25, 0.1);\n"
1942 " positions[2] = vec2( 0.1, 0.25);\n"
1943 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1944 " texColor = textureLod(surface, samplePos, 0.0);\n"
1945 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1946 "}\n";
1947
1948 static const char *fragShaderText =
GregFd6ebdb32015-06-03 18:40:50 -06001949 "#version 140\n"
1950 "#extension GL_ARB_separate_shader_objects : enable\n"
1951 "#extension GL_ARB_shading_language_420pack : enable\n"
1952 "layout (location = 0) in vec4 texColor;\n"
1953 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001954 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06001955 " outColor = texColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07001956 "}\n";
1957
1958 ASSERT_NO_FATAL_FAILURE(InitState());
1959 ASSERT_NO_FATAL_FAILURE(InitViewport());
1960
Tony Barbour01999182015-04-09 12:58:51 -06001961 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
1962 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
1963 VkSamplerObj sampler(m_device);
1964 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07001965
Tony Barbour01999182015-04-09 12:58:51 -06001966 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08001967 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07001968 pipelineobj.AddShader(&vs);
1969 pipelineobj.AddShader(&ps);
1970
Tony Barbour01999182015-04-09 12:58:51 -06001971 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001972 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001973
Tony Barbourdd4c9642015-01-09 12:55:14 -07001974 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06001975 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001976 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001977
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001978 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001979
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001980 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001981
1982#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001983 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001984 pDSDumpDot((char*)"triTest2.dot");
1985#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001986
Tony Barbourdd4c9642015-01-09 12:55:14 -07001987 // render triangle
1988 cmdBuffer.Draw(0, 3, 0, 1);
1989
1990 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001991 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001992 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001993
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001994 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001995}
GregFd6ebdb32015-06-03 18:40:50 -06001996
1997
1998
Tony Barbour01999182015-04-09 12:58:51 -06001999TEST_F(VkRenderTest, TexturedTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002000{
2001 // The expected result from this test is a red and green checkered triangle
2002 static const char *vertShaderText =
2003 "#version 140\n"
2004 "#extension GL_ARB_separate_shader_objects : enable\n"
2005 "#extension GL_ARB_shading_language_420pack : enable\n"
2006 "layout (location = 0) out vec2 samplePos;\n"
2007 "void main() {\n"
2008 " vec2 vertices[3];"
2009 " vertices[0] = vec2(-0.5, -0.5);\n"
2010 " vertices[1] = vec2( 0.5, -0.5);\n"
2011 " vertices[2] = vec2( 0.5, 0.5);\n"
2012 " vec2 positions[3];"
2013 " positions[0] = vec2( 0.0, 0.0);\n"
2014 " positions[1] = vec2( 1.0, 0.0);\n"
2015 " positions[2] = vec2( 1.0, 1.0);\n"
2016 " samplePos = positions[gl_VertexID % 3];\n"
2017 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2018 "}\n";
2019
2020 static const char *fragShaderText =
2021 "#version 140\n"
2022 "#extension GL_ARB_separate_shader_objects : enable\n"
2023 "#extension GL_ARB_shading_language_420pack : enable\n"
2024 "layout (location = 0) in vec2 samplePos;\n"
2025 "layout (binding = 0) uniform sampler2D surface;\n"
2026 "layout (location=0) out vec4 outColor;\n"
2027 "void main() {\n"
2028 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2029 " outColor = texColor;\n"
2030 "}\n";
2031
2032 ASSERT_NO_FATAL_FAILURE(InitState());
2033 ASSERT_NO_FATAL_FAILURE(InitViewport());
2034
Tony Barbour01999182015-04-09 12:58:51 -06002035 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2036 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2037 VkSamplerObj sampler(m_device);
2038 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002039
Tony Barbour01999182015-04-09 12:58:51 -06002040 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002041 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002042 pipelineobj.AddShader(&vs);
2043 pipelineobj.AddShader(&ps);
2044
Tony Barbour01999182015-04-09 12:58:51 -06002045 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002046 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002047
Tony Barbourdd4c9642015-01-09 12:55:14 -07002048 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002049 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002050 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2051
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002052 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002053
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002054 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002055
2056#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002057 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002058 pDSDumpDot((char*)"triTest2.dot");
2059#endif
2060 // render triangle
2061 cmdBuffer.Draw(0, 3, 0, 1);
2062
2063 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002064 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002065 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002066
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002067 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002068}
Tony Barbour01999182015-04-09 12:58:51 -06002069TEST_F(VkRenderTest, TexturedTriangleClip)
Tony Barbourf43b6982014-11-25 13:18:32 -07002070{
2071 // The expected result from this test is a red and green checkered triangle
2072 static const char *vertShaderText =
2073 "#version 330\n"
2074 "#extension GL_ARB_separate_shader_objects : enable\n"
2075 "#extension GL_ARB_shading_language_420pack : enable\n"
2076 "layout (location = 0) out vec2 samplePos;\n"
2077 "out gl_PerVertex {\n"
2078 " vec4 gl_Position;\n"
2079 " float gl_ClipDistance[1];\n"
2080 "};\n"
2081 "void main() {\n"
2082 " vec2 vertices[3];"
2083 " vertices[0] = vec2(-0.5, -0.5);\n"
2084 " vertices[1] = vec2( 0.5, -0.5);\n"
2085 " vertices[2] = vec2( 0.5, 0.5);\n"
2086 " vec2 positions[3];"
2087 " positions[0] = vec2( 0.0, 0.0);\n"
2088 " positions[1] = vec2( 1.0, 0.0);\n"
2089 " positions[2] = vec2( 1.0, 1.0);\n"
2090 " float dists[3];\n"
2091 " dists[0] = 1.0;\n"
2092 " dists[1] = 1.0;\n"
2093 " dists[2] = -1.0;\n"
2094 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2095 " samplePos = positions[gl_VertexID % 3];\n"
2096 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2097 "}\n";
2098
2099 static const char *fragShaderText =
2100 "#version 140\n"
2101 "#extension GL_ARB_separate_shader_objects : enable\n"
2102 "#extension GL_ARB_shading_language_420pack : enable\n"
2103 "layout (location = 0) in vec2 samplePos;\n"
2104 "layout (binding = 0) uniform sampler2D surface;\n"
2105 "layout (location=0) out vec4 outColor;\n"
2106 "void main() {\n"
2107 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2108 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2109 " outColor = texColor;\n"
2110 "}\n";
2111
2112
2113 ASSERT_NO_FATAL_FAILURE(InitState());
2114 ASSERT_NO_FATAL_FAILURE(InitViewport());
2115
Tony Barbour01999182015-04-09 12:58:51 -06002116 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2117 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2118 VkSamplerObj sampler(m_device);
2119 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002120
Tony Barbour01999182015-04-09 12:58:51 -06002121 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002122 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002123 pipelineobj.AddShader(&vs);
2124 pipelineobj.AddShader(&ps);
2125
Tony Barbour01999182015-04-09 12:58:51 -06002126 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002127 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002128
Tony Barbourdd4c9642015-01-09 12:55:14 -07002129 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002130 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002131 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2132
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002133 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002134
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002135 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002136
2137#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002138 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002139 pDSDumpDot((char*)"triTest2.dot");
2140#endif
2141 // render triangle
2142 cmdBuffer.Draw(0, 3, 0, 1);
2143
2144 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002145 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002146 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002147
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002148 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002149}
GregFd6ebdb32015-06-03 18:40:50 -06002150
Tony Barbour01999182015-04-09 12:58:51 -06002151TEST_F(VkRenderTest, FSTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002152{
2153 // The expected result from this test is a red and green checkered triangle
2154 static const char *vertShaderText =
2155 "#version 140\n"
2156 "#extension GL_ARB_separate_shader_objects : enable\n"
2157 "#extension GL_ARB_shading_language_420pack : enable\n"
2158 "layout (location = 0) out vec2 samplePos;\n"
2159 "void main() {\n"
2160 " vec2 vertices[3];"
2161 " vertices[0] = vec2(-0.5, -0.5);\n"
2162 " vertices[1] = vec2( 0.5, -0.5);\n"
2163 " vertices[2] = vec2( 0.5, 0.5);\n"
2164 " vec2 positions[3];"
2165 " positions[0] = vec2( 0.0, 0.0);\n"
2166 " positions[1] = vec2( 1.0, 0.0);\n"
2167 " positions[2] = vec2( 1.0, 1.0);\n"
2168 " samplePos = positions[gl_VertexID % 3];\n"
2169 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2170 "}\n";
2171
2172 static const char *fragShaderText =
2173 "#version 140\n"
2174 "#extension GL_ARB_separate_shader_objects : enable\n"
2175 "#extension GL_ARB_shading_language_420pack : enable\n"
2176 "layout (location = 0) in vec2 samplePos;\n"
2177 "layout (binding = 0) uniform sampler2D surface;\n"
2178 "layout (location=0) out vec4 outColor;\n"
2179 "void main() {\n"
2180 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2181 " outColor = texColor;\n"
2182 "}\n";
2183
2184 ASSERT_NO_FATAL_FAILURE(InitState());
2185 ASSERT_NO_FATAL_FAILURE(InitViewport());
2186
Tony Barbour01999182015-04-09 12:58:51 -06002187 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2188 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2189 VkSamplerObj sampler(m_device);
2190 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002191
Tony Barbour01999182015-04-09 12:58:51 -06002192 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002193 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002194 pipelineobj.AddShader(&vs);
2195 pipelineobj.AddShader(&ps);
2196
Tony Barbour01999182015-04-09 12:58:51 -06002197 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002198 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002199
Tony Barbourdd4c9642015-01-09 12:55:14 -07002200 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002201 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002202 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2203
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002204 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002205
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002206 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002207
2208#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002209 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002210 pDSDumpDot((char*)"triTest2.dot");
2211#endif
2212 // render triangle
2213 cmdBuffer.Draw(0, 3, 0, 1);
2214
2215 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002216 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002217 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002218
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002219 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002220}
Tony Barbour01999182015-04-09 12:58:51 -06002221TEST_F(VkRenderTest, SamplerBindingsTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -07002222{
2223 // This test sets bindings on the samplers
2224 // For now we are asserting that sampler and texture pairs
2225 // march in lock step, and are set via GLSL binding. This can
2226 // and will probably change.
2227 // The sampler bindings should match the sampler and texture slot
2228 // number set up by the application.
2229 // This test will result in a blue triangle
2230 static const char *vertShaderText =
2231 "#version 140\n"
2232 "#extension GL_ARB_separate_shader_objects : enable\n"
2233 "#extension GL_ARB_shading_language_420pack : enable\n"
2234 "layout (location = 0) out vec4 samplePos;\n"
2235 "void main() {\n"
2236 " vec2 vertices[3];"
2237 " vertices[0] = vec2(-0.5, -0.5);\n"
2238 " vertices[1] = vec2( 0.5, -0.5);\n"
2239 " vertices[2] = vec2( 0.5, 0.5);\n"
2240 " vec2 positions[3];"
2241 " positions[0] = vec2( 0.0, 0.0);\n"
2242 " positions[1] = vec2( 1.0, 0.0);\n"
2243 " positions[2] = vec2( 1.0, 1.0);\n"
2244 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2245 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2246 "}\n";
2247
2248 static const char *fragShaderText =
2249 "#version 140\n"
2250 "#extension GL_ARB_separate_shader_objects : enable\n"
2251 "#extension GL_ARB_shading_language_420pack : enable\n"
2252 "layout (location = 0) in vec4 samplePos;\n"
2253 "layout (binding = 0) uniform sampler2D surface0;\n"
2254 "layout (binding = 1) uniform sampler2D surface1;\n"
2255 "layout (binding = 12) uniform sampler2D surface2;\n"
GregFd6ebdb32015-06-03 18:40:50 -06002256 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002257 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002258 " outColor = textureLod(surface2, samplePos.xy, 0.0);\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002259 "}\n";
2260
2261 ASSERT_NO_FATAL_FAILURE(InitState());
2262 ASSERT_NO_FATAL_FAILURE(InitViewport());
2263
Tony Barbour01999182015-04-09 12:58:51 -06002264 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2265 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002266
Tony Barbour01999182015-04-09 12:58:51 -06002267 VkSamplerObj sampler1(m_device);
2268 VkSamplerObj sampler2(m_device);
2269 VkSamplerObj sampler3(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002270
Tony Barbour2f421a02015-04-01 16:38:10 -06002271 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
Tony Barbour01999182015-04-09 12:58:51 -06002272 VkTextureObj texture1(m_device, tex_colors); // Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002273 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
Tony Barbour01999182015-04-09 12:58:51 -06002274 VkTextureObj texture2(m_device, tex_colors); // Green
Tony Barbour2f421a02015-04-01 16:38:10 -06002275 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
Tony Barbour01999182015-04-09 12:58:51 -06002276 VkTextureObj texture3(m_device, tex_colors); // Blue
Tony Barbourf43b6982014-11-25 13:18:32 -07002277
Tony Barbour01999182015-04-09 12:58:51 -06002278 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002279 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002280 pipelineobj.AddShader(&vs);
2281 pipelineobj.AddShader(&ps);
2282
Tony Barbour01999182015-04-09 12:58:51 -06002283 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002284 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2285 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2286 for (int i = 0; i < 10; i++)
2287 descriptorSet.AppendDummy();
2288 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002289
Tony Barbourdd4c9642015-01-09 12:55:14 -07002290 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002291 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002292 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2293
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002294 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002295
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002296 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002297
2298#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002299 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002300 pDSDumpDot((char*)"triTest2.dot");
2301#endif
2302 // render triangle
2303 cmdBuffer.Draw(0, 3, 0, 1);
2304
2305 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002306 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002307 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002308
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002309 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002310}
2311
Tony Barbour01999182015-04-09 12:58:51 -06002312TEST_F(VkRenderTest, TriangleVSUniformBlock)
Tony Barbourf43b6982014-11-25 13:18:32 -07002313{
2314 // The expected result from this test is a blue triangle
2315
2316 static const char *vertShaderText =
2317 "#version 140\n"
2318 "#extension GL_ARB_separate_shader_objects : enable\n"
2319 "#extension GL_ARB_shading_language_420pack : enable\n"
2320 "layout (location = 0) out vec4 outColor;\n"
2321 "layout (std140, binding = 0) uniform bufferVals {\n"
2322 " vec4 red;\n"
2323 " vec4 green;\n"
2324 " vec4 blue;\n"
2325 " vec4 white;\n"
2326 "} myBufferVals;\n"
2327 "void main() {\n"
2328 " vec2 vertices[3];"
2329 " vertices[0] = vec2(-0.5, -0.5);\n"
2330 " vertices[1] = vec2( 0.5, -0.5);\n"
2331 " vertices[2] = vec2( 0.5, 0.5);\n"
2332 " outColor = myBufferVals.blue;\n"
2333 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2334 "}\n";
2335
2336 static const char *fragShaderText =
2337 "#version 140\n"
2338 "#extension GL_ARB_separate_shader_objects : enable\n"
2339 "#extension GL_ARB_shading_language_420pack : enable\n"
2340 "layout (location = 0) in vec4 inColor;\n"
GregFd6ebdb32015-06-03 18:40:50 -06002341 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002342 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002343 " outColor = inColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002344 "}\n";
2345
2346 ASSERT_NO_FATAL_FAILURE(InitState());
2347 ASSERT_NO_FATAL_FAILURE(InitViewport());
2348
Tony Barbour01999182015-04-09 12:58:51 -06002349 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2350 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002351
2352 // Let's populate our buffer with the following:
2353 // vec4 red;
2354 // vec4 green;
2355 // vec4 blue;
2356 // vec4 white;
2357 const int valCount = 4 * 4;
2358 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2359 0.0, 1.0, 0.0, 1.0,
2360 0.0, 0.0, 1.0, 1.0,
2361 1.0, 1.0, 1.0, 1.0 };
2362
Tony Barbour01999182015-04-09 12:58:51 -06002363 VkConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002364
Tony Barbour01999182015-04-09 12:58:51 -06002365 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002366 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002367 pipelineobj.AddShader(&vs);
2368 pipelineobj.AddShader(&ps);
2369
Tony Barbour01999182015-04-09 12:58:51 -06002370 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002371 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002372
Tony Barbourdd4c9642015-01-09 12:55:14 -07002373 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002374 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002375 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2376
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002377 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002378
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002379 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002380
2381#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002382 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002383 pDSDumpDot((char*)"triTest2.dot");
2384#endif
2385 // render triangle
2386 cmdBuffer.Draw(0, 3, 0, 1);
2387
2388 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002389 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002390 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002391
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002392 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002393}
2394
Tony Barbour01999182015-04-09 12:58:51 -06002395TEST_F(VkRenderTest, TriangleFSUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002396{
2397 // This test allows the shader to select which buffer it is
2398 // pulling from using layout binding qualifier.
2399 // There are corresponding changes in the compiler stack that
2400 // will select the buffer using binding directly.
2401 // The binding number should match the slot number set up by
2402 // the application.
2403 // The expected result from this test is a purple triangle
2404
2405 static const char *vertShaderText =
2406 "#version 140\n"
2407 "#extension GL_ARB_separate_shader_objects : enable\n"
2408 "#extension GL_ARB_shading_language_420pack : enable\n"
2409 "void main() {\n"
2410 " vec2 vertices[3];"
2411 " vertices[0] = vec2(-0.5, -0.5);\n"
2412 " vertices[1] = vec2( 0.5, -0.5);\n"
2413 " vertices[2] = vec2( 0.5, 0.5);\n"
2414 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2415 "}\n";
2416
2417 static const char *fragShaderText =
2418 "#version 140\n"
2419 "#extension GL_ARB_separate_shader_objects : enable\n"
2420 "#extension GL_ARB_shading_language_420pack : enable\n"
2421 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2422 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2423 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002424 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
GregFd6ebdb32015-06-03 18:40:50 -06002425 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002426 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06002427 " outColor = myBlueVal.color;\n"
2428 " outColor += myRedVal.color;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002429 "}\n";
2430
2431 ASSERT_NO_FATAL_FAILURE(InitState());
2432 ASSERT_NO_FATAL_FAILURE(InitViewport());
2433
Tony Barbour01999182015-04-09 12:58:51 -06002434 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2435 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002436
2437 // We're going to create a number of uniform buffers, and then allow
2438 // the shader to select which it wants to read from with a binding
2439
2440 // Let's populate the buffers with a single color each:
2441 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2442 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2443 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002444 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002445
2446 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2447 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2448 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2449 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2450
2451 const int redCount = sizeof(redVals) / sizeof(float);
2452 const int greenCount = sizeof(greenVals) / sizeof(float);
2453 const int blueCount = sizeof(blueVals) / sizeof(float);
2454 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2455
Tony Barbour01999182015-04-09 12:58:51 -06002456 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002457
Tony Barbour01999182015-04-09 12:58:51 -06002458 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002459
Tony Barbour01999182015-04-09 12:58:51 -06002460 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002461
Tony Barbour01999182015-04-09 12:58:51 -06002462 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002463
Tony Barbour01999182015-04-09 12:58:51 -06002464 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002465 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002466 pipelineobj.AddShader(&vs);
2467 pipelineobj.AddShader(&ps);
2468
Tony Barbour01999182015-04-09 12:58:51 -06002469 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002470 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2471 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2472 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2473 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002474
Tony Barbourdd4c9642015-01-09 12:55:14 -07002475 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002476 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002477 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002478
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002479 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002480
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002481 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002482
2483#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002484 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002485 pDSDumpDot((char*)"triTest2.dot");
2486#endif
2487 // render triangle
2488 cmdBuffer.Draw(0, 3, 0, 1);
2489
2490 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002491 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002492 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002493
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002494 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002495}
2496
Tony Barbour01999182015-04-09 12:58:51 -06002497TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBinding)
Tony Barbourf43b6982014-11-25 13:18:32 -07002498{
2499 // This test is the same as TriangleFSUniformBlockBinding, but
2500 // it does not provide an instance name.
2501 // The expected result from this test is a purple triangle
2502
2503 static const char *vertShaderText =
2504 "#version 140\n"
2505 "#extension GL_ARB_separate_shader_objects : enable\n"
2506 "#extension GL_ARB_shading_language_420pack : enable\n"
2507 "void main() {\n"
2508 " vec2 vertices[3];"
2509 " vertices[0] = vec2(-0.5, -0.5);\n"
2510 " vertices[1] = vec2( 0.5, -0.5);\n"
2511 " vertices[2] = vec2( 0.5, 0.5);\n"
2512 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2513 "}\n";
2514
2515 static const char *fragShaderText =
2516 "#version 430\n"
2517 "#extension GL_ARB_separate_shader_objects : enable\n"
2518 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002519 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2520 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2521 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002522 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002523 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002524 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002525 " outColor = blue;\n"
2526 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002527 "}\n";
2528 ASSERT_NO_FATAL_FAILURE(InitState());
2529 ASSERT_NO_FATAL_FAILURE(InitViewport());
2530
Tony Barbour01999182015-04-09 12:58:51 -06002531 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2532 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -07002533
2534 // We're going to create a number of uniform buffers, and then allow
2535 // the shader to select which it wants to read from with a binding
2536
2537 // Let's populate the buffers with a single color each:
2538 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2539 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2540 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2541 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2542
2543 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2544 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2545 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2546 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2547
2548 const int redCount = sizeof(redVals) / sizeof(float);
2549 const int greenCount = sizeof(greenVals) / sizeof(float);
2550 const int blueCount = sizeof(blueVals) / sizeof(float);
2551 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2552
Tony Barbour01999182015-04-09 12:58:51 -06002553 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002554
Tony Barbour01999182015-04-09 12:58:51 -06002555 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002556
Tony Barbour01999182015-04-09 12:58:51 -06002557 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002558
Tony Barbour01999182015-04-09 12:58:51 -06002559 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002560
Tony Barbour01999182015-04-09 12:58:51 -06002561 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002562 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002563 pipelineobj.AddShader(&vs);
2564 pipelineobj.AddShader(&ps);
2565
Tony Barbour01999182015-04-09 12:58:51 -06002566 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002567 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2568 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2569 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2570 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002571
Tony Barbourdd4c9642015-01-09 12:55:14 -07002572 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002573 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002574 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2575
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002576 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002577
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002578 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002579
2580#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002581 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002582 pDSDumpDot((char*)"triTest2.dot");
2583#endif
2584 // render triangle
2585 cmdBuffer.Draw(0, 3, 0, 1);
2586
2587 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002588 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002589 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002590
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002591 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002592}
2593
GregF54a32172015-07-01 16:11:09 -06002594TEST_F(VkRenderTest, TriangleFSAnonymousUniformBlockBindingWithStruct)
2595{
2596 // This test is the same as TriangleFSUniformBlockBinding, but
2597 // it does not provide an instance name.
2598 // The expected result from this test is a purple triangle
2599
2600 static const char *vertShaderText =
2601 "#version 140\n"
2602 "#extension GL_ARB_separate_shader_objects : enable\n"
2603 "#extension GL_ARB_shading_language_420pack : enable\n"
2604 "void main() {\n"
2605 " vec2 vertices[3];"
2606 " vertices[0] = vec2(-0.5, -0.5);\n"
2607 " vertices[1] = vec2( 0.5, -0.5);\n"
2608 " vertices[2] = vec2( 0.5, 0.5);\n"
2609 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2610 "}\n";
2611
2612 static const char *fragShaderText =
2613 "#version 430\n"
2614 "#extension GL_ARB_separate_shader_objects : enable\n"
2615 "#extension GL_ARB_shading_language_420pack : enable\n"
2616 "\n"
2617 " struct PS_INPUT {\n"
2618 " vec2 member0;\n"
2619 " vec4 member1;\n"
2620 " vec4 member2;\n"
2621 " vec4 member3;\n"
2622 " vec4 member4;\n"
2623 " vec4 member5;\n"
2624 " vec4 member6;\n"
2625 " vec4 member7;\n"
2626 " vec4 member8;\n"
2627 " vec4 member9;\n"
2628 " };\n"
2629 "\n"
2630 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2631 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2632 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2633 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
2634 "layout (location = 0) out vec4 outColor;\n"
2635 "PS_INPUT MainFs()\n"
2636 "{\n"
2637 " PS_INPUT o;\n"
2638 " o.member9 = red;\n"
2639 " return o;\n"
2640 "}\n"
2641 "\n"
2642 "void main()\n"
2643 "{\n"
2644 " PS_INPUT o;\n"
2645 " o = MainFs();\n"
2646 " outColor = blue;"
2647 " outColor += o.member9;\n"
2648 "}\n";;
2649 ASSERT_NO_FATAL_FAILURE(InitState());
2650 ASSERT_NO_FATAL_FAILURE(InitViewport());
2651
2652 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2653 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2654
2655 // We're going to create a number of uniform buffers, and then allow
2656 // the shader to select which it wants to read from with a binding
2657
2658 // Let's populate the buffers with a single color each:
2659 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2660 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2661 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2662 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2663
2664 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2665 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2666 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2667 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2668
2669 const int redCount = sizeof(redVals) / sizeof(float);
2670 const int greenCount = sizeof(greenVals) / sizeof(float);
2671 const int blueCount = sizeof(blueVals) / sizeof(float);
2672 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2673
2674 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2675
2676 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2677
2678 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2679
2680 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
2681
2682 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002683 pipelineobj.AddColorAttachment();
GregF54a32172015-07-01 16:11:09 -06002684 pipelineobj.AddShader(&vs);
2685 pipelineobj.AddShader(&ps);
2686
2687 VkDescriptorSetObj descriptorSet(m_device);
2688 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
2689 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2690 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2691 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
2692
2693 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2694 VkCommandBufferObj cmdBuffer(m_device);
2695 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2696
2697 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
2698
2699 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
2700
2701#ifdef DUMP_STATE_DOT
2702 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
2703 pDSDumpDot((char*)"triTest2.dot");
2704#endif
2705 // render triangle
2706 cmdBuffer.Draw(0, 3, 0, 1);
2707
2708 // finalize recording of the command buffer
2709 EndCommandBuffer(cmdBuffer);
2710 cmdBuffer.QueueCommandBuffer();
2711
2712 RecordImages(m_renderTargets);
2713}
2714
Tony Barbour01999182015-04-09 12:58:51 -06002715TEST_F(VkRenderTest, CubeWithVertexFetchAndMVPAndTexture)
Tony Barbourf43b6982014-11-25 13:18:32 -07002716{
2717 static const char *vertShaderText =
2718 "#version 140\n"
2719 "#extension GL_ARB_separate_shader_objects : enable\n"
2720 "#extension GL_ARB_shading_language_420pack : enable\n"
2721 "layout (std140, binding=0) uniform bufferVals {\n"
2722 " mat4 mvp;\n"
2723 "} myBufferVals;\n"
2724 "layout (location=0) in vec4 pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002725 "layout (location=1) in vec2 input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002726 "layout (location=0) out vec2 UV;\n"
2727 "void main() {\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002728 " UV = input_uv;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002729 " gl_Position = myBufferVals.mvp * pos;\n"
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002730 " gl_Position.y = -gl_Position.y;\n"
2731 " gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002732 "}\n";
2733
2734 static const char *fragShaderText =
2735 "#version 140\n"
2736 "#extension GL_ARB_separate_shader_objects : enable\n"
2737 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002738 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002739 "layout (location=0) out vec4 outColor;\n"
2740 "layout (location=0) in vec2 UV;\n"
2741 "void main() {\n"
2742 " outColor= textureLod(surface, UV, 0.0);\n"
2743 "}\n";
2744 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2745
2746 glm::mat4 View = glm::lookAt(
2747 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2748 glm::vec3(0,0,0), // and looks at the origin
2749 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2750 );
2751
2752 glm::mat4 Model = glm::mat4(1.0f);
2753
2754 glm::mat4 MVP = Projection * View * Model;
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002755 int num_verts = sizeof(g_vb_texture_Data) / sizeof(g_vb_texture_Data[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002756
2757
2758 ASSERT_NO_FATAL_FAILURE(InitState());
2759 ASSERT_NO_FATAL_FAILURE(InitViewport());
Chia-I Wu9e81ebb2015-07-09 10:16:34 +08002760 m_depth_stencil_fmt = VK_FORMAT_D16_UNORM;
Chia-I Wuc278df82015-07-07 11:50:03 +08002761 m_depthStencil->Init(m_device, (int32_t)m_width, (int32_t)m_height, m_depth_stencil_fmt);
Tony Barbourf43b6982014-11-25 13:18:32 -07002762
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002763 VkConstantBufferObj meshBuffer(m_device, num_verts,
2764 sizeof(g_vb_texture_Data[0]), g_vb_texture_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002765 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002766
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002767 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07002768
Tony Barbour01999182015-04-09 12:58:51 -06002769 VkConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2770 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2771 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
2772 VkSamplerObj sampler(m_device);
2773 VkTextureObj texture(m_device);
Tony Barbourf43b6982014-11-25 13:18:32 -07002774
Tony Barbour01999182015-04-09 12:58:51 -06002775 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002776 pipelineobj.AddColorAttachment();
Tony Barbourf43b6982014-11-25 13:18:32 -07002777 pipelineobj.AddShader(&vs);
2778 pipelineobj.AddShader(&ps);
2779
Tony Barbour01999182015-04-09 12:58:51 -06002780 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002781 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mvpBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002782 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002783
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002784#define MESH_BIND_ID 0
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002785 VkVertexInputBindingDescription vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002786 MESH_BIND_ID, // binding ID
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002787 sizeof(g_vb_texture_Data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002788 VK_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002789 };
Tony Barbourf43b6982014-11-25 13:18:32 -07002790
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002791 VkVertexInputAttributeDescription vi_attribs[2];
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002792 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2793 vi_attribs[0].location = 0; // location
Tony Barbour8205d902015-04-16 15:59:00 -06002794 vi_attribs[0].format = VK_FORMAT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002795 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2796 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2797 vi_attribs[1].location = 1; // location
2798 vi_attribs[1].format = VK_FORMAT_R32G32_SFLOAT; // format of source data
2799 vi_attribs[1].offsetInBytes = 16; // Offset of uv components
Tony Barbourf43b6982014-11-25 13:18:32 -07002800
Tony Barbourf43b6982014-11-25 13:18:32 -07002801 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002802 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2803 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07002804
Tony Barboure307f582015-07-10 15:29:03 -06002805 VkPipelineDepthStencilStateCreateInfo ds_state;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002806 ds_state.depthTestEnable = VK_TRUE;
2807 ds_state.depthWriteEnable = VK_TRUE;
Tony Barbour8205d902015-04-16 15:59:00 -06002808 ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002809 ds_state.depthBoundsEnable = VK_FALSE;
2810 ds_state.stencilTestEnable = VK_FALSE;
2811 ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
2812 ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
2813 ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbour8205d902015-04-16 15:59:00 -06002814 ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002815 ds_state.front = ds_state.back;
2816 pipelineobj.SetDepthStencil(&ds_state);
2817
Tony Barbour17c6ab12015-03-27 17:03:18 -06002818 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Tony Barbour01999182015-04-09 12:58:51 -06002819 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002820 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002821
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002822 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002823
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002824 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002825
2826 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2827#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002828 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002829 pDSDumpDot((char*)"triTest2.dot");
2830#endif
2831 // render triangle
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002832 cmdBuffer.Draw(0, num_verts, 0, 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002833
2834 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002835 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002836 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002837
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002838 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter28846ae2015-04-30 17:44:12 -06002839 RotateTriangleVSUniform(Projection, View, Model, &mvpBuffer, &cmdBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002840}
Cody Northropd1ce7842014-12-09 11:17:01 -07002841
Tony Barbour01999182015-04-09 12:58:51 -06002842TEST_F(VkRenderTest, TriangleMixedSamplerUniformBlockBinding)
Cody Northropd1ce7842014-12-09 11:17:01 -07002843{
2844 // This test mixes binding slots of textures and buffers, ensuring
2845 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002846 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002847 // you can modify it to move the desired result around.
2848
2849 static const char *vertShaderText =
2850 "#version 140\n"
2851 "#extension GL_ARB_separate_shader_objects : enable\n"
2852 "#extension GL_ARB_shading_language_420pack : enable\n"
2853 "void main() {\n"
2854 " vec2 vertices[3];"
2855 " vertices[0] = vec2(-0.5, -0.5);\n"
2856 " vertices[1] = vec2( 0.5, -0.5);\n"
2857 " vertices[2] = vec2( 0.5, 0.5);\n"
2858 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2859 "}\n";
2860
2861 static const char *fragShaderText =
2862 "#version 430\n"
2863 "#extension GL_ARB_separate_shader_objects : enable\n"
2864 "#extension GL_ARB_shading_language_420pack : enable\n"
2865 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002866 "layout (binding = 3) uniform sampler2D surface1;\n"
2867 "layout (binding = 1) uniform sampler2D surface2;\n"
2868 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002869
Cody Northropa0410942014-12-09 13:59:39 -07002870
Chia-I Wuf8385062015-01-04 16:27:24 +08002871 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2872 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2873 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2874 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002875 "layout (location = 0) out vec4 outColor;\n"
2876 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002877 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002878 " outColor += white * vec4(0.00001);\n"
2879 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002880 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002881 "}\n";
2882 ASSERT_NO_FATAL_FAILURE(InitState());
2883 ASSERT_NO_FATAL_FAILURE(InitViewport());
2884
Tony Barbour01999182015-04-09 12:58:51 -06002885 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2886 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northropd1ce7842014-12-09 11:17:01 -07002887
Cody Northropd1ce7842014-12-09 11:17:01 -07002888 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2889 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2890 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2891 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2892
2893 const int redCount = sizeof(redVals) / sizeof(float);
2894 const int greenCount = sizeof(greenVals) / sizeof(float);
2895 const int blueCount = sizeof(blueVals) / sizeof(float);
2896 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2897
Tony Barbour01999182015-04-09 12:58:51 -06002898 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2899 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2900 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2901 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002902
Tony Barbour2f421a02015-04-01 16:38:10 -06002903 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06002904 VkSamplerObj sampler0(m_device);
2905 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06002906 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06002907 VkSamplerObj sampler2(m_device);
2908 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06002909 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06002910 VkSamplerObj sampler4(m_device);
2911 VkTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropa0410942014-12-09 13:59:39 -07002912
2913 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2914 // TODO: Get back here ASAP and understand why.
Tony Barbour2f421a02015-04-01 16:38:10 -06002915 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06002916 VkSamplerObj sampler7(m_device);
2917 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropd1ce7842014-12-09 11:17:01 -07002918
Tony Barbour01999182015-04-09 12:58:51 -06002919 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08002920 pipelineobj.AddColorAttachment();
Cody Northropd1ce7842014-12-09 11:17:01 -07002921 pipelineobj.AddShader(&vs);
2922 pipelineobj.AddShader(&ps);
2923
Tony Barbour01999182015-04-09 12:58:51 -06002924 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002925 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2926 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2927 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2928 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002929 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08002930 // swap blue and green
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002931 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
2932 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
2933 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002934
Tony Barbourdd4c9642015-01-09 12:55:14 -07002935 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06002936 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002937 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002938
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002939 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002940
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002941 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002942
2943#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002944 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002945 pDSDumpDot((char*)"triTest2.dot");
2946#endif
2947 // render triangle
2948 cmdBuffer.Draw(0, 3, 0, 1);
2949
2950 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002951 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06002952 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07002953
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002954 RecordImages(m_renderTargets);
Cody Northropd1ce7842014-12-09 11:17:01 -07002955}
2956
Tony Barbour01999182015-04-09 12:58:51 -06002957TEST_F(VkRenderTest, TriangleMatchingSamplerUniformBlockBinding)
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002958{
2959 // This test matches binding slots of textures and buffers, requiring
2960 // the driver to give them distinct number spaces.
2961 // The expected result from this test is a red triangle, although
2962 // you can modify it to move the desired result around.
2963
2964 static const char *vertShaderText =
2965 "#version 140\n"
2966 "#extension GL_ARB_separate_shader_objects : enable\n"
2967 "#extension GL_ARB_shading_language_420pack : enable\n"
2968 "void main() {\n"
2969 " vec2 vertices[3];"
2970 " vertices[0] = vec2(-0.5, -0.5);\n"
2971 " vertices[1] = vec2( 0.5, -0.5);\n"
2972 " vertices[2] = vec2( 0.5, 0.5);\n"
2973 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2974 "}\n";
2975
2976 static const char *fragShaderText =
2977 "#version 430\n"
2978 "#extension GL_ARB_separate_shader_objects : enable\n"
2979 "#extension GL_ARB_shading_language_420pack : enable\n"
2980 "layout (binding = 0) uniform sampler2D surface0;\n"
2981 "layout (binding = 1) uniform sampler2D surface1;\n"
2982 "layout (binding = 2) uniform sampler2D surface2;\n"
2983 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002984 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2985 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2986 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2987 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002988 "layout (location = 0) out vec4 outColor;\n"
2989 "void main() {\n"
2990 " outColor = red;// * vec4(0.00001);\n"
2991 " outColor += white * vec4(0.00001);\n"
2992 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2993 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2994 "}\n";
2995 ASSERT_NO_FATAL_FAILURE(InitState());
2996 ASSERT_NO_FATAL_FAILURE(InitViewport());
2997
Tony Barbour01999182015-04-09 12:58:51 -06002998 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
2999 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003000
3001 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
3002 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
3003 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
3004 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
3005
3006 const int redCount = sizeof(redVals) / sizeof(float);
3007 const int greenCount = sizeof(greenVals) / sizeof(float);
3008 const int blueCount = sizeof(blueVals) / sizeof(float);
3009 const int whiteCount = sizeof(whiteVals) / sizeof(float);
3010
Tony Barbour01999182015-04-09 12:58:51 -06003011 VkConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
3012 VkConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
3013 VkConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
3014 VkConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003015
Tony Barbour2f421a02015-04-01 16:38:10 -06003016 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Tony Barbour01999182015-04-09 12:58:51 -06003017 VkSamplerObj sampler0(m_device);
3018 VkTextureObj texture0(m_device, tex_colors); // Light Red
Tony Barbour2f421a02015-04-01 16:38:10 -06003019 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Tony Barbour01999182015-04-09 12:58:51 -06003020 VkSamplerObj sampler2(m_device);
3021 VkTextureObj texture2(m_device, tex_colors); // Light Blue
Tony Barbour2f421a02015-04-01 16:38:10 -06003022 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Tony Barbour01999182015-04-09 12:58:51 -06003023 VkSamplerObj sampler4(m_device);
3024 VkTextureObj texture4(m_device, tex_colors); // Light Green
Tony Barbour2f421a02015-04-01 16:38:10 -06003025 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Tony Barbour01999182015-04-09 12:58:51 -06003026 VkSamplerObj sampler7(m_device);
3027 VkTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003028
Tony Barbour01999182015-04-09 12:58:51 -06003029 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003030 pipelineobj.AddColorAttachment();
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003031 pipelineobj.AddShader(&vs);
3032 pipelineobj.AddShader(&ps);
3033
Tony Barbour01999182015-04-09 12:58:51 -06003034 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08003035 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3036 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3037 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
3038 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003039 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, redBuffer);
3040 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, greenBuffer);
3041 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, blueBuffer);
3042 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003043
Tony Barbourdd4c9642015-01-09 12:55:14 -07003044 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06003045 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbourdd4c9642015-01-09 12:55:14 -07003046 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003047
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003048 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07003049
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003050 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Tony Barbourdd4c9642015-01-09 12:55:14 -07003051
3052#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003053 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07003054 pDSDumpDot((char*)"triTest2.dot");
3055#endif
3056 // render triangle
3057 cmdBuffer.Draw(0, 3, 0, 1);
3058
3059 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003060 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003061 cmdBuffer.QueueCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07003062
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003063 RecordImages(m_renderTargets);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07003064}
3065
Tony Barbour01999182015-04-09 12:58:51 -06003066TEST_F(VkRenderTest, TriangleUniformBufferLayout)
Cody Northrop02690bd2014-12-17 15:26:33 -07003067{
3068 // This test populates a buffer with a variety of different data
3069 // types, then reads them out with a shader.
3070 // The expected result from this test is a green triangle
3071
3072 static const char *vertShaderText =
3073 "#version 140\n"
3074 "#extension GL_ARB_separate_shader_objects : enable\n"
3075 "#extension GL_ARB_shading_language_420pack : enable\n"
3076 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3077 " vec4 fRed;\n"
3078 " vec4 fGreen;\n"
3079 " layout(row_major) mat4 worldToProj;\n"
3080 " layout(row_major) mat4 projToWorld;\n"
3081 " layout(row_major) mat4 worldToView;\n"
3082 " layout(row_major) mat4 viewToProj;\n"
3083 " layout(row_major) mat4 worldToShadow[4];\n"
3084 " float fZero;\n"
3085 " float fOne;\n"
3086 " float fTwo;\n"
3087 " float fThree;\n"
3088 " vec3 fZeroZeroZero;\n"
3089 " float fFour;\n"
3090 " vec3 fZeroZeroOne;\n"
3091 " float fFive;\n"
3092 " vec3 fZeroOneZero;\n"
3093 " float fSix;\n"
3094 " float fSeven;\n"
3095 " float fEight;\n"
3096 " float fNine;\n"
3097 " vec2 fZeroZero;\n"
3098 " vec2 fZeroOne;\n"
3099 " vec4 fBlue;\n"
3100 " vec2 fOneZero;\n"
3101 " vec2 fOneOne;\n"
3102 " vec3 fZeroOneOne;\n"
3103 " float fTen;\n"
3104 " float fEleven;\n"
3105 " float fTwelve;\n"
3106 " vec3 fOneZeroZero;\n"
3107 " vec4 uvOffsets[4];\n"
3108 "};\n"
3109 "layout (location = 0) out vec4 color;"
3110 "void main() {\n"
3111
3112 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3113 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3114 " \n"
3115
3116 // do some exact comparisons, even though we should
3117 // really have an epsilon involved.
3118 " vec4 outColor = right;\n"
3119 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3120 " outColor = wrong;\n"
3121 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3122 " outColor = wrong;\n"
3123 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3124 " outColor = wrong;\n"
3125
3126 " color = outColor;\n"
3127
3128 // generic position stuff
3129 " vec2 vertices;\n"
3130 " int vertexSelector = gl_VertexID;\n"
3131 " if (vertexSelector == 0)\n"
3132 " vertices = vec2(-0.5, -0.5);\n"
3133 " else if (vertexSelector == 1)\n"
3134 " vertices = vec2( 0.5, -0.5);\n"
3135 " else if (vertexSelector == 2)\n"
3136 " vertices = vec2( 0.5, 0.5);\n"
3137 " else\n"
3138 " vertices = vec2( 0.0, 0.0);\n"
3139 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3140 "}\n";
3141
3142 static const char *fragShaderText =
3143 "#version 140\n"
3144 "#extension GL_ARB_separate_shader_objects : enable\n"
3145 "#extension GL_ARB_shading_language_420pack : enable\n"
3146 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3147 " vec4 fRed;\n"
3148 " vec4 fGreen;\n"
3149 " layout(row_major) mat4 worldToProj;\n"
3150 " layout(row_major) mat4 projToWorld;\n"
3151 " layout(row_major) mat4 worldToView;\n"
3152 " layout(row_major) mat4 viewToProj;\n"
3153 " layout(row_major) mat4 worldToShadow[4];\n"
3154 " float fZero;\n"
3155 " float fOne;\n"
3156 " float fTwo;\n"
3157 " float fThree;\n"
3158 " vec3 fZeroZeroZero;\n"
3159 " float fFour;\n"
3160 " vec3 fZeroZeroOne;\n"
3161 " float fFive;\n"
3162 " vec3 fZeroOneZero;\n"
3163 " float fSix;\n"
3164 " float fSeven;\n"
3165 " float fEight;\n"
3166 " float fNine;\n"
3167 " vec2 fZeroZero;\n"
3168 " vec2 fZeroOne;\n"
3169 " vec4 fBlue;\n"
3170 " vec2 fOneZero;\n"
3171 " vec2 fOneOne;\n"
3172 " vec3 fZeroOneOne;\n"
3173 " float fTen;\n"
3174 " float fEleven;\n"
3175 " float fTwelve;\n"
3176 " vec3 fOneZeroZero;\n"
3177 " vec4 uvOffsets[4];\n"
3178 "};\n"
3179 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003180 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northrop02690bd2014-12-17 15:26:33 -07003181 "void main() {\n"
3182 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3183 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3184 " \n"
3185
3186 // start with VS value to ensure it passed
3187 " vec4 outColor = color;\n"
3188
3189 // do some exact comparisons, even though we should
3190 // really have an epsilon involved.
3191 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3192 " outColor = wrong;\n"
3193 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3194 " outColor = wrong;\n"
3195 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3196 " outColor = wrong;\n"
3197 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3198 " outColor = wrong;\n"
3199 " if (fTwo != 2.0)\n"
3200 " outColor = wrong;\n"
3201 " if (fOneOne != vec2(1.0, 1.0))\n"
3202 " outColor = wrong;\n"
3203 " if (fTen != 10.0)\n"
3204 " outColor = wrong;\n"
3205 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3206 " outColor = wrong;\n"
3207 " \n"
GregFd6ebdb32015-06-03 18:40:50 -06003208 " uFragColor = outColor;\n"
Cody Northrop02690bd2014-12-17 15:26:33 -07003209 "}\n";
3210
3211
3212 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3213 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3214 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3215 0.0, 1.0, 0.0, 1.0, // align
3216 0.0, 0.0, 1.0, 1.0, // align
3217 0.0, 0.0, 0.0, 1.0, // align
3218 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3219 0.0, 2.0, 0.0, 2.0, // align
3220 0.0, 0.0, 2.0, 2.0, // align
3221 0.0, 0.0, 0.0, 2.0, // align
3222 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3223 0.0, 3.0, 0.0, 3.0, // align
3224 0.0, 0.0, 3.0, 3.0, // align
3225 0.0, 0.0, 0.0, 3.0, // align
3226 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3227 0.0, 4.0, 0.0, 4.0, // align
3228 0.0, 0.0, 4.0, 4.0, // align
3229 0.0, 0.0, 0.0, 4.0, // align
3230 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3231 0.0, 5.0, 0.0, 5.0, // align
3232 0.0, 0.0, 5.0, 5.0, // align
3233 0.0, 0.0, 0.0, 5.0, // align
3234 6.0, 0.0, 0.0, 6.0, // align
3235 0.0, 6.0, 0.0, 6.0, // align
3236 0.0, 0.0, 6.0, 6.0, // align
3237 0.0, 0.0, 0.0, 6.0, // align
3238 7.0, 0.0, 0.0, 7.0, // align
3239 0.0, 7.0, 0.0, 7.0, // align
3240 0.0, 0.0, 7.0, 7.0, // align
3241 0.0, 0.0, 0.0, 7.0, // align
3242 8.0, 0.0, 0.0, 8.0, // align
3243 0.0, 8.0, 0.0, 8.0, // align
3244 0.0, 0.0, 8.0, 8.0, // align
3245 0.0, 0.0, 0.0, 8.0, // align
3246 0.0, // float fZero; // align
3247 1.0, // float fOne; // pack
3248 2.0, // float fTwo; // pack
3249 3.0, // float fThree; // pack
3250 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3251 4.0, // float fFour; // pack
3252 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3253 5.0, // float fFive; // pack
3254 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3255 6.0, // float fSix; // pack
3256 7.0, // float fSeven; // align
3257 8.0, // float fEight; // pack
3258 9.0, // float fNine; // pack
3259 0.0, // BUFFER
3260 0.0, 0.0, // vec2 fZeroZero; // align
3261 0.0, 1.0, // vec2 fZeroOne; // pack
3262 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3263 1.0, 0.0, // vec2 fOneZero; // align
3264 1.0, 1.0, // vec2 fOneOne; // pack
3265 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3266 10.0, // float fTen; // pack
3267 11.0, // float fEleven; // align
3268 12.0, // float fTwelve; // pack
3269 0.0, 0.0, // BUFFER
3270 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3271 0.0, // BUFFER
3272 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3273 0.5, 0.6, 0.7, 0.8, // align
3274 0.9, 1.0, 1.1, 1.2, // align
3275 1.3, 1.4, 1.5, 1.6, // align
3276 };
3277
3278 ASSERT_NO_FATAL_FAILURE(InitState());
3279 ASSERT_NO_FATAL_FAILURE(InitViewport());
3280
3281 const int constCount = sizeof(mixedVals) / sizeof(float);
3282
Tony Barbour01999182015-04-09 12:58:51 -06003283 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3284 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
Cody Northrop02690bd2014-12-17 15:26:33 -07003285
Tony Barbour01999182015-04-09 12:58:51 -06003286 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003287
Tony Barbour01999182015-04-09 12:58:51 -06003288 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003289 pipelineobj.AddColorAttachment();
Cody Northrop02690bd2014-12-17 15:26:33 -07003290 pipelineobj.AddShader(&vs);
3291 pipelineobj.AddShader(&ps);
3292
Tony Barbour01999182015-04-09 12:58:51 -06003293 VkDescriptorSetObj descriptorSet(m_device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003294 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003295
3296 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour01999182015-04-09 12:58:51 -06003297 VkCommandBufferObj cmdBuffer(m_device);
Cody Northrop02690bd2014-12-17 15:26:33 -07003298 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3299
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003300 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
Cody Northrop02690bd2014-12-17 15:26:33 -07003301
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003302 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
Cody Northrop02690bd2014-12-17 15:26:33 -07003303
3304#ifdef DUMP_STATE_DOT
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003305 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)vkGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop02690bd2014-12-17 15:26:33 -07003306 pDSDumpDot((char*)"triTest2.dot");
3307#endif
3308 // render triangle
3309 cmdBuffer.Draw(0, 3, 0, 1);
3310
3311 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003312 EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06003313 cmdBuffer.QueueCommandBuffer();
Cody Northrop02690bd2014-12-17 15:26:33 -07003314
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003315 RecordImages(m_renderTargets);
Cody Northrop02690bd2014-12-17 15:26:33 -07003316}
3317
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003318TEST_F(VkRenderTest, TextureGather)
3319{
3320 // This test introduces textureGather and textureGatherOffset
3321 // Each call is compared against an expected inline color result
3322 // Green triangle means everything worked as expected
3323 // Red means something went wrong
3324
3325 // disable SPV until texture gather is turned on in LunarGLASS
Cody Northrop1cfbd172015-06-03 16:49:20 -06003326 ScopedUseGlsl useGlsl(true);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003327
3328 static const char *vertShaderText =
3329 "#version 140\n"
3330 "#extension GL_ARB_separate_shader_objects : enable\n"
3331 "#extension GL_ARB_shading_language_420pack : enable\n"
3332 "void main() {\n"
3333 " vec2 vertices[3];"
3334 " vertices[0] = vec2(-0.5, -0.5);\n"
3335 " vertices[1] = vec2( 0.5, -0.5);\n"
3336 " vertices[2] = vec2( 0.5, 0.5);\n"
3337 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
3338 "}\n";
3339
3340 static const char *fragShaderText =
3341 "#version 430\n"
3342 "#extension GL_ARB_separate_shader_objects : enable\n"
3343 "#extension GL_ARB_shading_language_420pack : enable\n"
3344 "layout (binding = 0) uniform sampler2D surface0;\n"
3345 "layout (binding = 1) uniform sampler2D surface1;\n"
3346 "layout (binding = 2) uniform sampler2D surface2;\n"
3347 "layout (binding = 3) uniform sampler2D surface3;\n"
3348 "layout (location = 0) out vec4 outColor;\n"
3349 "void main() {\n"
3350
3351 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3352 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3353
3354 " vec4 color = right;\n"
3355
3356 // Grab a normal texture sample to ensure it can work in conjuntion
3357 // with textureGather (there are some intracacies in the backend)
3358 " vec4 sampledColor = textureLod(surface2, vec2(0.5), 0.0);\n"
3359 " if (sampledColor != vec4(0.0, 0.0, 1.0, 1.0))\n"
3360 " color = wrong;\n"
3361
3362 " vec4 gatheredColor = textureGather(surface0, vec2(0.5), 0);\n"
3363 // This just grabbed four red components from a red surface
3364 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3365 " color = wrong;\n"
3366
3367 // Yes, this is using an offset of 0, we don't have enough fine grained
3368 // control of the texture contents here.
3369 " gatheredColor = textureGatherOffset(surface1, vec2(0.5), ivec2(0, 0), 1);\n"
3370 " if (gatheredColor != vec4(1.0, 1.0, 1.0, 1.0))\n"
3371 " color = wrong;\n"
3372
3373 " outColor = color;\n"
3374
3375 "}\n";
3376
3377 ASSERT_NO_FATAL_FAILURE(InitState());
3378 ASSERT_NO_FATAL_FAILURE(InitViewport());
3379
3380 VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this);
3381 VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3382
3383 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
3384 VkSamplerObj sampler0(m_device);
3385 VkTextureObj texture0(m_device, tex_colors); // Red
3386 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
3387 VkSamplerObj sampler1(m_device);
3388 VkTextureObj texture1(m_device, tex_colors); // Green
3389 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
3390 VkSamplerObj sampler2(m_device);
3391 VkTextureObj texture2(m_device, tex_colors); // Blue
3392 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
3393 VkSamplerObj sampler3(m_device);
3394 VkTextureObj texture3(m_device, tex_colors); // Red and Blue
3395
3396 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003397 pipelineobj.AddColorAttachment();
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003398 pipelineobj.AddShader(&vs);
3399 pipelineobj.AddShader(&ps);
3400
3401 VkDescriptorSetObj descriptorSet(m_device);
3402 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
3403 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
3404 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
3405 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
3406
3407 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3408 VkCommandBufferObj cmdBuffer(m_device);
3409 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3410
3411 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3412
3413 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3414
3415 // render triangle
3416 cmdBuffer.Draw(0, 3, 0, 1);
3417
3418 // finalize recording of the command buffer
3419 EndCommandBuffer(cmdBuffer);
3420 cmdBuffer.QueueCommandBuffer();
3421
3422 RecordImages(m_renderTargets);
Cody Northrop5fd1a7c2015-05-07 14:39:12 -06003423}
3424
Cody Northropa44c2ff2015-04-15 11:19:06 -06003425TEST_F(VkRenderTest, GeometryShaderHelloWorld)
3426{
3427 // This test introduces a geometry shader that simply
3428 // changes the color of each vertex to red, green, blue
3429
3430 static const char *vertShaderText =
3431 "#version 140\n"
3432 "#extension GL_ARB_separate_shader_objects : enable\n"
3433 "#extension GL_ARB_shading_language_420pack : enable\n"
3434 "layout (location = 0) out vec4 color;"
3435 "void main() {\n"
3436
3437 // VS writes out red
3438 " color = vec4(1.0, 0.0, 0.0, 1.0);\n"
3439
3440 // generic position stuff
3441 " vec2 vertices;\n"
3442 " int vertexSelector = gl_VertexID;\n"
3443 " if (vertexSelector == 0)\n"
3444 " vertices = vec2(-0.5, -0.5);\n"
3445 " else if (vertexSelector == 1)\n"
3446 " vertices = vec2( 0.5, -0.5);\n"
3447 " else if (vertexSelector == 2)\n"
3448 " vertices = vec2( 0.5, 0.5);\n"
3449 " else\n"
3450 " vertices = vec2( 0.0, 0.0);\n"
3451 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3452
3453 "}\n";
3454
3455 static const char *geomShaderText =
3456 "#version 330\n"
3457 "#extension GL_ARB_separate_shader_objects : enable\n"
3458 "#extension GL_ARB_shading_language_420pack : enable\n"
3459 "layout( triangles ) in;\n"
3460 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3461 "layout( location = 0 ) in vec4 inColor[3];\n"
3462 "layout( location = 0 ) out vec4 outColor;\n"
3463 "void main()\n"
3464 "{\n"
3465
3466 // first vertex, pass through red
3467 " gl_Position = gl_in[0].gl_Position;\n"
3468 " outColor = inColor[0];\n"
3469 " EmitVertex();\n"
3470
3471 // second vertex, green
3472 " gl_Position = gl_in[1].gl_Position;\n"
3473 " outColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3474 " EmitVertex();\n"
3475
3476 // third vertex, blue
3477 " gl_Position = gl_in[2].gl_Position;\n"
3478 " outColor = vec4(0.0, 0.0, 1.0, 1.0);\n"
3479 " EmitVertex();\n"
3480
3481 // done
3482 " EndPrimitive();\n"
3483 "}\n";
3484
3485
3486 static const char *fragShaderText =
3487 "#version 140\n"
3488 "#extension GL_ARB_separate_shader_objects : enable\n"
3489 "#extension GL_ARB_shading_language_420pack : enable\n"
3490 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003491 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003492 "void main() {\n"
3493 // pass through
GregFd6ebdb32015-06-03 18:40:50 -06003494 " outColor = color;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003495 "}\n";
3496
3497
3498
3499 ASSERT_NO_FATAL_FAILURE(InitState());
3500 ASSERT_NO_FATAL_FAILURE(InitViewport());
3501
3502 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3503 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3504 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3505
3506 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003507 pipelineobj.AddColorAttachment();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003508 pipelineobj.AddShader(&vs);
3509 pipelineobj.AddShader(&gs);
3510 pipelineobj.AddShader(&ps);
3511
3512 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3513 VkCommandBufferObj cmdBuffer(m_device);
3514 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3515
3516 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3517
3518 VkDescriptorSetObj descriptorSet(m_device);
3519
3520 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3521
3522 // render triangle
3523 cmdBuffer.Draw(0, 3, 0, 1);
3524
3525 // finalize recording of the command buffer
3526 EndCommandBuffer(cmdBuffer);
3527 cmdBuffer.QueueCommandBuffer();
3528
3529 RecordImages(m_renderTargets);
3530}
3531
3532TEST_F(VkRenderTest, GSUniformBufferLayout)
3533{
3534 // This test is just like TriangleUniformBufferLayout but adds
3535 // geometry as a stage that also does UBO lookups
3536 // The expected result from this test is a green triangle
3537
3538 static const char *vertShaderText =
3539 "#version 140\n"
3540 "#extension GL_ARB_separate_shader_objects : enable\n"
3541 "#extension GL_ARB_shading_language_420pack : enable\n"
3542 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3543 " vec4 fRed;\n"
3544 " vec4 fGreen;\n"
3545 " layout(row_major) mat4 worldToProj;\n"
3546 " layout(row_major) mat4 projToWorld;\n"
3547 " layout(row_major) mat4 worldToView;\n"
3548 " layout(row_major) mat4 viewToProj;\n"
3549 " layout(row_major) mat4 worldToShadow[4];\n"
3550 " float fZero;\n"
3551 " float fOne;\n"
3552 " float fTwo;\n"
3553 " float fThree;\n"
3554 " vec3 fZeroZeroZero;\n"
3555 " float fFour;\n"
3556 " vec3 fZeroZeroOne;\n"
3557 " float fFive;\n"
3558 " vec3 fZeroOneZero;\n"
3559 " float fSix;\n"
3560 " float fSeven;\n"
3561 " float fEight;\n"
3562 " float fNine;\n"
3563 " vec2 fZeroZero;\n"
3564 " vec2 fZeroOne;\n"
3565 " vec4 fBlue;\n"
3566 " vec2 fOneZero;\n"
3567 " vec2 fOneOne;\n"
3568 " vec3 fZeroOneOne;\n"
3569 " float fTen;\n"
3570 " float fEleven;\n"
3571 " float fTwelve;\n"
3572 " vec3 fOneZeroZero;\n"
3573 " vec4 uvOffsets[4];\n"
3574 "};\n"
3575 "layout (location = 0) out vec4 color;"
3576 "void main() {\n"
3577
3578 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3579 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3580 " \n"
3581
3582 // do some exact comparisons, even though we should
3583 // really have an epsilon involved.
3584 " vec4 outColor = right;\n"
3585 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3586 " outColor = wrong;\n"
3587 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3588 " outColor = wrong;\n"
3589 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3590 " outColor = wrong;\n"
3591
3592 " color = outColor;\n"
3593
3594 // generic position stuff
3595 " vec2 vertices;\n"
3596 " int vertexSelector = gl_VertexID;\n"
3597 " if (vertexSelector == 0)\n"
3598 " vertices = vec2(-0.5, -0.5);\n"
3599 " else if (vertexSelector == 1)\n"
3600 " vertices = vec2( 0.5, -0.5);\n"
3601 " else if (vertexSelector == 2)\n"
3602 " vertices = vec2( 0.5, 0.5);\n"
3603 " else\n"
3604 " vertices = vec2( 0.0, 0.0);\n"
3605 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3606 "}\n";
3607
3608 static const char *geomShaderText =
3609 "#version 330\n"
3610 "#extension GL_ARB_separate_shader_objects : enable\n"
3611 "#extension GL_ARB_shading_language_420pack : enable\n"
3612
3613 // GS layout stuff
3614 "layout( triangles ) in;\n"
3615 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3616
3617 // Between stage IO
3618 "layout( location = 0 ) in vec4 inColor[3];\n"
3619 "layout( location = 0 ) out vec4 color;\n"
3620
3621 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3622 " vec4 fRed;\n"
3623 " vec4 fGreen;\n"
3624 " layout(row_major) mat4 worldToProj;\n"
3625 " layout(row_major) mat4 projToWorld;\n"
3626 " layout(row_major) mat4 worldToView;\n"
3627 " layout(row_major) mat4 viewToProj;\n"
3628 " layout(row_major) mat4 worldToShadow[4];\n"
3629 " float fZero;\n"
3630 " float fOne;\n"
3631 " float fTwo;\n"
3632 " float fThree;\n"
3633 " vec3 fZeroZeroZero;\n"
3634 " float fFour;\n"
3635 " vec3 fZeroZeroOne;\n"
3636 " float fFive;\n"
3637 " vec3 fZeroOneZero;\n"
3638 " float fSix;\n"
3639 " float fSeven;\n"
3640 " float fEight;\n"
3641 " float fNine;\n"
3642 " vec2 fZeroZero;\n"
3643 " vec2 fZeroOne;\n"
3644 " vec4 fBlue;\n"
3645 " vec2 fOneZero;\n"
3646 " vec2 fOneOne;\n"
3647 " vec3 fZeroOneOne;\n"
3648 " float fTen;\n"
3649 " float fEleven;\n"
3650 " float fTwelve;\n"
3651 " vec3 fOneZeroZero;\n"
3652 " vec4 uvOffsets[4];\n"
3653 "};\n"
3654
3655 "void main()\n"
3656 "{\n"
3657
3658 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3659 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3660
3661 // Each vertex will validate it can read VS output
3662 // then check a few values from the UBO
3663
3664 // first vertex
3665 " vec4 outColor = inColor[0];\n"
3666
3667 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3668 " outColor = wrong;\n"
3669 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3670 " outColor = wrong;\n"
3671 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3672 " outColor = wrong;\n"
3673 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3674 " outColor = wrong;\n"
3675
3676 " gl_Position = gl_in[0].gl_Position;\n"
3677 " color = outColor;\n"
3678 " EmitVertex();\n"
3679
3680 // second vertex
3681 " outColor = inColor[1];\n"
3682
3683 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3684 " outColor = wrong;\n"
3685 " if (fSix != 6.0)\n"
3686 " outColor = wrong;\n"
3687 " if (fOneOne != vec2(1.0, 1.0))\n"
3688 " outColor = wrong;\n"
3689
3690 " gl_Position = gl_in[1].gl_Position;\n"
3691 " color = outColor;\n"
3692 " EmitVertex();\n"
3693
3694 // third vertex
3695 " outColor = inColor[2];\n"
3696
3697 " if (fSeven != 7.0)\n"
3698 " outColor = wrong;\n"
3699 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3700 " outColor = wrong;\n"
3701
3702 " gl_Position = gl_in[2].gl_Position;\n"
3703 " color = outColor;\n"
3704 " EmitVertex();\n"
3705
3706 // done
3707 " EndPrimitive();\n"
3708 "}\n";
3709
3710 static const char *fragShaderText =
3711 "#version 140\n"
3712 "#extension GL_ARB_separate_shader_objects : enable\n"
3713 "#extension GL_ARB_shading_language_420pack : enable\n"
3714 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3715 " vec4 fRed;\n"
3716 " vec4 fGreen;\n"
3717 " layout(row_major) mat4 worldToProj;\n"
3718 " layout(row_major) mat4 projToWorld;\n"
3719 " layout(row_major) mat4 worldToView;\n"
3720 " layout(row_major) mat4 viewToProj;\n"
3721 " layout(row_major) mat4 worldToShadow[4];\n"
3722 " float fZero;\n"
3723 " float fOne;\n"
3724 " float fTwo;\n"
3725 " float fThree;\n"
3726 " vec3 fZeroZeroZero;\n"
3727 " float fFour;\n"
3728 " vec3 fZeroZeroOne;\n"
3729 " float fFive;\n"
3730 " vec3 fZeroOneZero;\n"
3731 " float fSix;\n"
3732 " float fSeven;\n"
3733 " float fEight;\n"
3734 " float fNine;\n"
3735 " vec2 fZeroZero;\n"
3736 " vec2 fZeroOne;\n"
3737 " vec4 fBlue;\n"
3738 " vec2 fOneZero;\n"
3739 " vec2 fOneOne;\n"
3740 " vec3 fZeroOneOne;\n"
3741 " float fTen;\n"
3742 " float fEleven;\n"
3743 " float fTwelve;\n"
3744 " vec3 fOneZeroZero;\n"
3745 " vec4 uvOffsets[4];\n"
3746 "};\n"
3747 "layout (location = 0) in vec4 color;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003748 "layout (location = 0) out vec4 uFragColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003749 "void main() {\n"
3750 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3751 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3752 " \n"
3753
3754 // start with GS value to ensure it passed
3755 " vec4 outColor = color;\n"
3756
3757 // do some exact comparisons, even though we should
3758 // really have an epsilon involved.
3759 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3760 " outColor = wrong;\n"
3761 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3762 " outColor = wrong;\n"
3763 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3764 " outColor = wrong;\n"
3765 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3766 " outColor = wrong;\n"
3767 " if (fTwo != 2.0)\n"
3768 " outColor = wrong;\n"
3769 " if (fOneOne != vec2(1.0, 1.0))\n"
3770 " outColor = wrong;\n"
3771 " if (fTen != 10.0)\n"
3772 " outColor = wrong;\n"
3773 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3774 " outColor = wrong;\n"
3775 " \n"
GregFd6ebdb32015-06-03 18:40:50 -06003776 " uFragColor = outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003777 "}\n";
3778
3779
3780 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3781 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3782 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3783 0.0, 1.0, 0.0, 1.0, // align
3784 0.0, 0.0, 1.0, 1.0, // align
3785 0.0, 0.0, 0.0, 1.0, // align
3786 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3787 0.0, 2.0, 0.0, 2.0, // align
3788 0.0, 0.0, 2.0, 2.0, // align
3789 0.0, 0.0, 0.0, 2.0, // align
3790 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3791 0.0, 3.0, 0.0, 3.0, // align
3792 0.0, 0.0, 3.0, 3.0, // align
3793 0.0, 0.0, 0.0, 3.0, // align
3794 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3795 0.0, 4.0, 0.0, 4.0, // align
3796 0.0, 0.0, 4.0, 4.0, // align
3797 0.0, 0.0, 0.0, 4.0, // align
3798 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3799 0.0, 5.0, 0.0, 5.0, // align
3800 0.0, 0.0, 5.0, 5.0, // align
3801 0.0, 0.0, 0.0, 5.0, // align
3802 6.0, 0.0, 0.0, 6.0, // align
3803 0.0, 6.0, 0.0, 6.0, // align
3804 0.0, 0.0, 6.0, 6.0, // align
3805 0.0, 0.0, 0.0, 6.0, // align
3806 7.0, 0.0, 0.0, 7.0, // align
3807 0.0, 7.0, 0.0, 7.0, // align
3808 0.0, 0.0, 7.0, 7.0, // align
3809 0.0, 0.0, 0.0, 7.0, // align
3810 8.0, 0.0, 0.0, 8.0, // align
3811 0.0, 8.0, 0.0, 8.0, // align
3812 0.0, 0.0, 8.0, 8.0, // align
3813 0.0, 0.0, 0.0, 8.0, // align
3814 0.0, // float fZero; // align
3815 1.0, // float fOne; // pack
3816 2.0, // float fTwo; // pack
3817 3.0, // float fThree; // pack
3818 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3819 4.0, // float fFour; // pack
3820 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3821 5.0, // float fFive; // pack
3822 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3823 6.0, // float fSix; // pack
3824 7.0, // float fSeven; // align
3825 8.0, // float fEight; // pack
3826 9.0, // float fNine; // pack
3827 0.0, // BUFFER
3828 0.0, 0.0, // vec2 fZeroZero; // align
3829 0.0, 1.0, // vec2 fZeroOne; // pack
3830 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3831 1.0, 0.0, // vec2 fOneZero; // align
3832 1.0, 1.0, // vec2 fOneOne; // pack
3833 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3834 10.0, // float fTen; // pack
3835 11.0, // float fEleven; // align
3836 12.0, // float fTwelve; // pack
3837 0.0, 0.0, // BUFFER
3838 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3839 0.0, // BUFFER
3840 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3841 0.5, 0.6, 0.7, 0.8, // align
3842 0.9, 1.0, 1.1, 1.2, // align
3843 1.3, 1.4, 1.5, 1.6, // align
3844 };
3845
3846
3847
3848 ASSERT_NO_FATAL_FAILURE(InitState());
3849 ASSERT_NO_FATAL_FAILURE(InitViewport());
3850
3851 const int constCount = sizeof(mixedVals) / sizeof(float);
3852
3853 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3854 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3855 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3856
3857 VkConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
3858
3859 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003860 pipelineobj.AddColorAttachment();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003861 pipelineobj.AddShader(&vs);
3862 pipelineobj.AddShader(&gs);
3863 pipelineobj.AddShader(&ps);
3864
3865 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3866 VkCommandBufferObj cmdBuffer(m_device);
3867 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3868
3869 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3870
3871 VkDescriptorSetObj descriptorSet(m_device);
3872 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, mixedBuffer);
3873
3874 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
3875
3876 // render triangle
3877 cmdBuffer.Draw(0, 3, 0, 1);
3878
3879 // finalize recording of the command buffer
3880 EndCommandBuffer(cmdBuffer);
3881 cmdBuffer.QueueCommandBuffer();
3882
3883 RecordImages(m_renderTargets);
3884}
3885
3886TEST_F(VkRenderTest, GSPositions)
3887{
3888 // This test adds more inputs from the vertex shader and perturbs positions
3889 // Expected result is white triangle with weird positions
3890
3891 static const char *vertShaderText =
3892 "#version 140\n"
3893 "#extension GL_ARB_separate_shader_objects : enable\n"
3894 "#extension GL_ARB_shading_language_420pack : enable\n"
3895
3896 "layout(location = 0) out vec3 out_a;\n"
3897 "layout(location = 1) out vec3 out_b;\n"
3898 "layout(location = 2) out vec3 out_c;\n"
3899
3900 "void main() {\n"
3901
3902 // write a solid color to each
3903 " out_a = vec3(1.0, 0.0, 0.0);\n"
3904 " out_b = vec3(0.0, 1.0, 0.0);\n"
3905 " out_c = vec3(0.0, 0.0, 1.0);\n"
3906
3907 // generic position stuff
3908 " vec2 vertices;\n"
3909 " int vertexSelector = gl_VertexID;\n"
3910 " if (vertexSelector == 0)\n"
3911 " vertices = vec2(-0.5, -0.5);\n"
3912 " else if (vertexSelector == 1)\n"
3913 " vertices = vec2( 0.5, -0.5);\n"
3914 " else if (vertexSelector == 2)\n"
3915 " vertices = vec2( 0.5, 0.5);\n"
3916 " else\n"
3917 " vertices = vec2( 0.0, 0.0);\n"
3918 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3919
3920 "}\n";
3921
3922 static const char *geomShaderText =
3923 "#version 330\n"
3924 "#extension GL_ARB_separate_shader_objects : enable\n"
3925 "#extension GL_ARB_shading_language_420pack : enable\n"
3926 "layout( triangles ) in;\n"
3927 "layout( triangle_strip, max_vertices = 3 ) out;\n"
3928
3929 "layout(location = 0) in vec3 in_a[3];\n"
3930 "layout(location = 1) in vec3 in_b[3];\n"
3931 "layout(location = 2) in vec3 in_c[3];\n"
3932
3933 "layout(location = 0) out vec3 out_a;\n"
3934 "layout(location = 1) out vec3 out_b;\n"
3935 "layout(location = 2) out vec3 out_c;\n"
3936
3937 "void main()\n"
3938 "{\n"
3939
3940 " gl_Position = gl_in[0].gl_Position;\n"
3941 " gl_Position.xy *= vec2(0.75);\n"
3942 " out_a = in_a[0];\n"
3943 " out_b = in_b[0];\n"
3944 " out_c = in_c[0];\n"
3945 " EmitVertex();\n"
3946
3947 " gl_Position = gl_in[1].gl_Position;\n"
3948 " gl_Position.xy *= vec2(1.5);\n"
3949 " out_a = in_a[1];\n"
3950 " out_b = in_b[1];\n"
3951 " out_c = in_c[1];\n"
3952 " EmitVertex();\n"
3953
3954 " gl_Position = gl_in[2].gl_Position;\n"
3955 " gl_Position.xy *= vec2(-0.1);\n"
3956 " out_a = in_a[2];\n"
3957 " out_b = in_b[2];\n"
3958 " out_c = in_c[2];\n"
3959 " EmitVertex();\n"
3960
3961 " EndPrimitive();\n"
3962 "}\n";
3963
3964
3965 static const char *fragShaderText =
3966 "#version 140\n"
3967 "#extension GL_ARB_separate_shader_objects : enable\n"
3968 "#extension GL_ARB_shading_language_420pack : enable\n"
3969
3970 "layout(location = 0) in vec3 in_a;\n"
3971 "layout(location = 1) in vec3 in_b;\n"
3972 "layout(location = 2) in vec3 in_c;\n"
GregFd6ebdb32015-06-03 18:40:50 -06003973 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003974
3975 "void main() {\n"
GregFd6ebdb32015-06-03 18:40:50 -06003976 " outColor = vec4(in_a.x, in_b.y, in_c.z, 1.0);\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06003977 "}\n";
3978
3979
3980
3981 ASSERT_NO_FATAL_FAILURE(InitState());
3982 ASSERT_NO_FATAL_FAILURE(InitViewport());
3983
3984 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
3985 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
3986 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
3987
3988 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08003989 pipelineobj.AddColorAttachment();
Cody Northropa44c2ff2015-04-15 11:19:06 -06003990 pipelineobj.AddShader(&vs);
3991 pipelineobj.AddShader(&gs);
3992 pipelineobj.AddShader(&ps);
3993
3994 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3995 VkCommandBufferObj cmdBuffer(m_device);
3996 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3997
3998 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
3999
4000 VkDescriptorSetObj descriptorSet(m_device);
4001
4002 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
4003
4004 // render triangle
4005 cmdBuffer.Draw(0, 3, 0, 1);
4006
4007 // finalize recording of the command buffer
4008 EndCommandBuffer(cmdBuffer);
4009 cmdBuffer.QueueCommandBuffer();
4010
4011 RecordImages(m_renderTargets);
4012}
4013
4014TEST_F(VkRenderTest, GSTriStrip)
4015{
4016 // This test emits multiple multiple triangles using a GS
4017 // Correct result is an multicolor circle
4018
4019 static const char *vertShaderText =
4020 "#version 140\n"
4021 "#extension GL_ARB_separate_shader_objects : enable\n"
4022 "#extension GL_ARB_shading_language_420pack : enable\n"
4023
4024 "void main() {\n"
4025
4026 // generic position stuff
4027 " vec2 vertices;\n"
4028 " int vertexSelector = gl_VertexID;\n"
4029 " if (vertexSelector == 0)\n"
4030 " vertices = vec2(-0.5, -0.5);\n"
4031 " else if (vertexSelector == 1)\n"
4032 " vertices = vec2( 0.5, -0.5);\n"
4033 " else if (vertexSelector == 2)\n"
4034 " vertices = vec2( 0.5, 0.5);\n"
4035 " else\n"
4036 " vertices = vec2( 0.0, 0.0);\n"
4037 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
4038
4039 "}\n";
4040
4041 static const char *geomShaderText =
4042 "#version 330\n"
4043 "#extension GL_ARB_separate_shader_objects : enable\n"
4044 "#extension GL_ARB_shading_language_420pack : enable\n"
4045 "layout( triangles ) in;\n"
4046 "layout( triangle_strip, max_vertices = 18 ) out;\n"
4047
4048 "layout(location = 0) out vec4 outColor;\n"
4049
4050 "void main()\n"
4051 "{\n"
4052 // init with first position to get zw
4053 " gl_Position = gl_in[0].gl_Position;\n"
4054
4055 " vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n"
4056 " vec4 yellow = vec4(1.0, 1.0, 0.0, 1.0);\n"
4057 " vec4 blue = vec4(0.0, 0.0, 1.0, 1.0);\n"
4058 " vec4 white = vec4(1.0, 1.0, 1.0, 1.0);\n"
4059
4060 // different color per tri
4061 " vec4[6] colors = { red, white, \n"
4062 " yellow, white, \n"
4063 " blue, white }; \n"
4064
4065 // fan out the triangles
4066 " vec2[18] positions = { vec2(0.0, 0.0), vec2(-0.5, 0.0), vec2(-0.25, -0.5), \n"
4067 " vec2(0.0, 0.0), vec2(-0.25, -0.5), vec2( 0.25, -0.5), \n"
4068 " vec2(0.0, 0.0), vec2( 0.25, -0.5), vec2( 0.5, 0.0), \n"
4069 " vec2(0.0, 0.0), vec2( 0.5, 0.0), vec2( 0.25, 0.5), \n"
4070 " vec2(0.0, 0.0), vec2( 0.25, 0.5), vec2(-0.25, 0.5), \n"
4071 " vec2(0.0, 0.0), vec2(-0.25, 0.5), vec2(-0.5, 0.0) }; \n"
4072
4073 // make a triangle list of 6
4074 " for (int i = 0; i < 6; ++i) { \n"
4075 " outColor = colors[i]; \n"
4076 " for (int j = 0; j < 3; ++j) { \n"
4077 " gl_Position.xy = positions[i * 3 + j]; \n"
4078 " EmitVertex(); \n"
4079 " } \n"
4080 " EndPrimitive();\n"
4081 " } \n"
4082
4083 "}\n";
4084
4085
4086 static const char *fragShaderText =
4087 "#version 150\n"
4088 "#extension GL_ARB_separate_shader_objects : enable\n"
4089 "#extension GL_ARB_shading_language_420pack : enable\n"
4090
4091
4092 "layout(binding = 0) uniform windowDimensions {\n"
4093 " vec4 dimensions;\n"
4094 "};\n"
4095
4096 "layout(location = 0) in vec4 inColor;\n"
4097 "layout(origin_upper_left) in vec4 gl_FragCoord;\n"
GregFd6ebdb32015-06-03 18:40:50 -06004098 "layout (location = 0) out vec4 outColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06004099
4100 "void main() {\n"
4101
4102 // discard to make a nice circle
4103 " vec2 pos = abs(gl_FragCoord.xy) - vec2(dimensions.x, dimensions.y) / 2;\n"
4104 " float dist = sqrt(dot(pos, pos));\n"
4105 " if (dist > 50.0)\n"
4106 " discard;\n"
4107
GregFd6ebdb32015-06-03 18:40:50 -06004108 " outColor = inColor;\n"
Cody Northropa44c2ff2015-04-15 11:19:06 -06004109
4110 "}\n";
4111
4112
4113
4114 ASSERT_NO_FATAL_FAILURE(InitState());
4115 ASSERT_NO_FATAL_FAILURE(InitViewport());
4116
4117 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX, this);
4118 VkShaderObj gs(m_device, geomShaderText, VK_SHADER_STAGE_GEOMETRY, this);
4119 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT, this);
4120
4121 VkPipelineObj pipelineobj(m_device);
Chia-I Wuc278df82015-07-07 11:50:03 +08004122 pipelineobj.AddColorAttachment();
Cody Northropa44c2ff2015-04-15 11:19:06 -06004123 pipelineobj.AddShader(&vs);
4124 pipelineobj.AddShader(&gs);
4125 pipelineobj.AddShader(&ps);
4126
4127 const float dimensions[4] = { VkRenderFramework::m_width, VkRenderFramework::m_height , 0.0, 0.0};
4128
4129 VkConstantBufferObj windowDimensions(m_device, sizeof(dimensions) / sizeof(dimensions[0]), sizeof(dimensions[0]), (const void*) dimensions);
4130
4131 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4132 VkCommandBufferObj cmdBuffer(m_device);
4133 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
4134
4135 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
4136
4137 VkDescriptorSetObj descriptorSet(m_device);
4138 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, windowDimensions);
4139
4140 GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet);
4141
4142 // render triangle
4143 cmdBuffer.Draw(0, 3, 0, 1);
4144
4145 // finalize recording of the command buffer
4146 EndCommandBuffer(cmdBuffer);
4147 cmdBuffer.QueueCommandBuffer();
4148
4149 RecordImages(m_renderTargets);
4150}
4151
Chris Forbes23e6db62015-06-15 09:32:35 +12004152TEST_F(VkRenderTest, RenderPassLoadOpClear)
4153{
4154 ASSERT_NO_FATAL_FAILURE(InitState());
4155 ASSERT_NO_FATAL_FAILURE(InitViewport());
4156
4157 /* clear via load op to full green */
4158 m_clear_via_load_op = true;
Chris Forbese3105972015-06-24 14:34:53 +12004159 m_clear_color.f32[0] = 0;
4160 m_clear_color.f32[1] = 1;
4161 m_clear_color.f32[2] = 0;
4162 m_clear_color.f32[3] = 0;
Chris Forbes23e6db62015-06-15 09:32:35 +12004163 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4164
4165 VkCommandBufferObj cmdBuffer(m_device);
4166 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
4167 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
4168 /* This command buffer contains ONLY the load op! */
4169 EndCommandBuffer(cmdBuffer);
4170 cmdBuffer.QueueCommandBuffer();
4171
4172 RecordImages(m_renderTargets);
4173}
4174
Chris Forbes1e16cb82015-06-24 12:05:30 +12004175TEST_F(VkRenderTest, RenderPassAttachmentClear)
4176{
4177 ASSERT_NO_FATAL_FAILURE(InitState());
4178 ASSERT_NO_FATAL_FAILURE(InitViewport());
4179
4180 /* clear via load op to full red */
4181 m_clear_via_load_op = true;
Chris Forbese3105972015-06-24 14:34:53 +12004182 m_clear_color.f32[0] = 1;
4183 m_clear_color.f32[1] = 0;
4184 m_clear_color.f32[2] = 0;
4185 m_clear_color.f32[3] = 0;
Chris Forbes1e16cb82015-06-24 12:05:30 +12004186 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4187
4188 VkCommandBufferObj cmdBuffer(m_device);
4189 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
4190 ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer));
4191
4192 /* Load op has cleared to red */
4193
4194 /* Draw, draw, draw... */
4195
4196 /* Now, partway through this renderpass we want to clear the color
4197 * attachment again, this time to green.
4198 */
Chris Forbese3105972015-06-24 14:34:53 +12004199 VkClearColorValue clear_color;
4200 clear_color.f32[0] = 0;
4201 clear_color.f32[1] = 1;
4202 clear_color.f32[2] = 0;
4203 clear_color.f32[3] = 0;
Chris Forbes1e16cb82015-06-24 12:05:30 +12004204 VkRect3D clear_rect = { { 0, 0, 0 }, { (int)m_width, (int)m_height, 1 } };
Chia-I Wu78c2a352015-07-03 11:49:42 +08004205 vkCmdClearColorAttachment(cmdBuffer.handle(), 0,
Chris Forbes1e16cb82015-06-24 12:05:30 +12004206 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4207 &clear_color, 1, &clear_rect);
4208
4209 EndCommandBuffer(cmdBuffer);
4210 cmdBuffer.QueueCommandBuffer();
4211
4212 RecordImages(m_renderTargets);
4213}
4214
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004215int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004216 int result;
4217
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004218 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -06004219 VkTestFramework::InitArgs(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004220
Chia-I Wu7133fdc2014-12-15 23:57:34 +08004221 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06004222
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004223 result = RUN_ALL_TESTS();
4224
Tony Barbour01999182015-04-09 12:58:51 -06004225 VkTestFramework::Finish();
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06004226 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06004227}