blob: 80cd44083a5b0b57eb9d8088f73e786ed7868320 [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
31// XGL tests
32//
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
63#include <xgl.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
71#include <xglDbg.h>
72#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 Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -060081#include "xglrenderframework.h"
Tobin Ehlis791a49c2014-11-10 12:29:12 -070082#ifdef DEBUG_CALLBACK
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060083void XGLAPI myDbgFunc(
Tobin Ehlis791a49c2014-11-10 12:29:12 -070084 XGL_DBG_MSG_TYPE msgType,
85 XGL_VALIDATION_LEVEL validationLevel,
86 XGL_BASE_OBJECT 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 {
94 case XGL_DBG_MSG_WARNING:
95 printf("CALLBACK WARNING : %s\n", pMsg);
96 break;
97 case XGL_DBG_MSG_ERROR:
98 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
120#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
121
122static const Vertex g_vbData[] =
123{
124 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
125 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
126 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
127 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
128 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
129 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
130
131 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
132 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
133 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
134 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
135 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
136 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
137
138 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
139 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.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( 1.f, 1.f, 0.f ) },
143 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
144
145 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
146 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
147 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
148 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
149 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
150 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
151
152 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
153 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
154 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
155 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
156 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
157 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
158
159 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
160 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
161 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
162 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
163 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
164 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
165};
166
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600167static const Vertex g_vb_solid_face_colors_Data[] =
168{
169 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
170 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
171 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
172 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
173 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
174 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
175
176 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
177 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
178 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
179 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
180 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
181 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
182
183 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
184 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
185 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
186 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
187 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
188 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
189
190 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
191 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
192 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
193 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
194 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
195 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
196
197 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
198 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
199 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
200 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
201 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
202 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
203
204 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
205 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
206 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
207 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
208 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
209 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
210};
211
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600212class XglRenderTest : public XglRenderFramework
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -0600213{
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600214public:
Cody Northrop4e6b4762014-10-09 21:25:22 -0600215
Tony Barbourf43b6982014-11-25 13:18:32 -0700216 void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbourdd4c9642015-01-09 12:55:14 -0700217 XglConstantBufferObj *constantBuffer, XglCommandBufferObj *cmdBuffer);
Tony Barbour02472db2015-01-08 17:08:28 -0700218 void GenericDrawPreparation(XglCommandBufferObj *cmdBuffer, XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600219 void InitDepthStencil();
Tony Barbourae442072015-01-12 13:27:11 -0700220 void XGLTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate);
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600221
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600222
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600223protected:
Cody Northrop350727b2014-10-06 15:42:00 -0600224 XGL_IMAGE m_texture;
225 XGL_IMAGE_VIEW m_textureView;
226 XGL_IMAGE_VIEW_ATTACH_INFO m_textureViewInfo;
227 XGL_GPU_MEMORY m_textureMem;
228
229 XGL_SAMPLER m_sampler;
230
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600231 XGL_FORMAT m_depth_stencil_fmt;
232 XGL_IMAGE m_depthStencilImage;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600233 uint32_t m_num_mem;
Jon Ashburna9ae3832015-01-16 09:37:43 -0700234 XGL_GPU_MEMORY *m_depthStencilMem;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600235 XGL_DEPTH_STENCIL_VIEW m_depthStencilView;
Tony Barbourf43b6982014-11-25 13:18:32 -0700236 XglMemoryRefManager m_memoryRefManager;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600237
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600238
239 virtual void SetUp() {
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600240
241 this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO;
242 this->app_info.pNext = NULL;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800243 this->app_info.pAppName = "render_tests";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600244 this->app_info.appVersion = 1;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800245 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600246 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter211cc542015-02-23 17:40:15 -0700247 this->app_info.apiVersion = XGL_API_VERSION;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600248
Cody Northrop350727b2014-10-06 15:42:00 -0600249 memset(&m_textureViewInfo, 0, sizeof(m_textureViewInfo));
250 m_textureViewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO;
Tony Barbour97a36232014-12-04 17:14:45 -0700251 memset(&m_depthStencilImage, 0, sizeof(m_depthStencilImage));
Cody Northrop350727b2014-10-06 15:42:00 -0600252
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600253 InitFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600254 }
255
256 virtual void TearDown() {
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600257 // Clean up resources before we reset
258 ShutdownFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600259 }
260};
261
Tony Barbour02472db2015-01-08 17:08:28 -0700262void XglRenderTest::GenericDrawPreparation(XglCommandBufferObj *cmdBuffer, XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet)
263{
264 cmdBuffer->ClearAllBuffers(&m_depthStencilBinding, m_depthStencilImage);
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700265 cmdBuffer->PrepareAttachments();
Tony Barbour02472db2015-01-08 17:08:28 -0700266 cmdBuffer->BindStateObject(XGL_STATE_BIND_RASTER, m_stateRaster);
267 cmdBuffer->BindStateObject(XGL_STATE_BIND_VIEWPORT, m_stateViewport);
268 cmdBuffer->BindStateObject(XGL_STATE_BIND_COLOR_BLEND, m_colorBlend);
269 cmdBuffer->BindStateObject(XGL_STATE_BIND_DEPTH_STENCIL, m_stateDepthStencil);
Chia-I Wuf8385062015-01-04 16:27:24 +0800270 descriptorSet->CreateXGLDescriptorSet(cmdBuffer);
Tony Barbour02472db2015-01-08 17:08:28 -0700271 pipelineobj->CreateXGLPipeline(descriptorSet);
272 cmdBuffer->BindPipeline(pipelineobj->GetPipelineHandle());
Tony Barbour02472db2015-01-08 17:08:28 -0700273 cmdBuffer->BindDescriptorSet(descriptorSet->GetDescriptorSetHandle());
274}
Tony Barbourf43b6982014-11-25 13:18:32 -0700275
Tony Barbourf43b6982014-11-25 13:18:32 -0700276void XglRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbourdd4c9642015-01-09 12:55:14 -0700277 XglConstantBufferObj *constantBuffer, XglCommandBufferObj *cmdBuffer)
278{
279 int i;
280 glm::mat4 MVP;
281 int matrixSize = sizeof(MVP);
282 XGL_RESULT err;
283
284 for (i = 0; i < 8; i++) {
285 void *pData = constantBuffer->map();
286
287 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
288 MVP = Projection * View * Model;
289 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
290
291 constantBuffer->unmap();
292
293 // submit the command buffer to the universal queue
294 cmdBuffer->QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
295
Tony Barbourdd4c9642015-01-09 12:55:14 -0700296 err = xglQueueWaitIdle( m_device->m_queue );
297 ASSERT_XGL_SUCCESS( err );
298
299 // Wait for work to finish before cleaning up.
300 xglDeviceWaitIdle(m_device->device());
301
302 assert(m_renderTargetCount == 1);
303 RecordImage(m_renderTargets[0]);
304 }
305}
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600306
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600307void dumpMatrix(const char *note, glm::mat4 MVP)
308{
Chia-I Wu7133fdc2014-12-15 23:57:34 +0800309 int i;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600310
311 printf("%s: \n", note);
312 for (i=0; i<4; i++) {
313 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
314 }
315 printf("\n");
316 fflush(stdout);
317}
318
319void dumpVec4(const char *note, glm::vec4 vector)
320{
321 printf("%s: \n", note);
322 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
323 printf("\n");
324 fflush(stdout);
325}
326
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600327void XglRenderTest::InitDepthStencil()
328{
329 XGL_RESULT err;
330 XGL_IMAGE_CREATE_INFO image;
331 XGL_MEMORY_ALLOC_INFO mem_alloc;
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700332 XGL_MEMORY_ALLOC_IMAGE_INFO img_alloc;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600333 XGL_DEPTH_STENCIL_VIEW_CREATE_INFO view;
Jon Ashburna9ae3832015-01-16 09:37:43 -0700334 XGL_MEMORY_REQUIREMENTS *mem_reqs;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600335 size_t mem_reqs_size=sizeof(XGL_MEMORY_REQUIREMENTS);
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700336 XGL_IMAGE_MEMORY_REQUIREMENTS img_reqs;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600337 size_t img_reqs_size = sizeof(XGL_IMAGE_MEMORY_REQUIREMENTS);
338 uint32_t num_allocations = 0;
339 size_t num_alloc_size = sizeof(num_allocations);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600340
341 // Clean up default state created by framework
342 if (m_stateDepthStencil) xglDestroyObject(m_stateDepthStencil);
343
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700344 m_depth_stencil_fmt = XGL_FMT_D16_UNORM;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600345
346 image.sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
347 image.pNext = NULL;
348 image.imageType = XGL_IMAGE_2D;
349 image.format = m_depth_stencil_fmt;
350 image.extent.width = m_width;
351 image.extent.height = m_height;
352 image.extent.depth = 1;
353 image.mipLevels = 1;
354 image.arraySize = 1;
355 image.samples = 1;
356 image.tiling = XGL_OPTIMAL_TILING;
357 image.usage = XGL_IMAGE_USAGE_DEPTH_STENCIL_BIT;
358 image.flags = 0;
359
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700360 img_alloc.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_IMAGE_INFO;
361 img_alloc.pNext = NULL;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600362 mem_alloc.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700363 mem_alloc.pNext = &img_alloc;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600364 mem_alloc.allocationSize = 0;
Jon Ashburn542cd092015-01-20 13:55:32 -0700365 mem_alloc.memProps = XGL_MEMORY_PROPERTY_GPU_ONLY;
Jon Ashburn32769172015-01-20 15:06:59 -0700366 mem_alloc.memType = XGL_MEMORY_TYPE_IMAGE;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600367 mem_alloc.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
368
369 /* create image */
370 err = xglCreateImage(device(), &image,
371 &m_depthStencilImage);
372 ASSERT_XGL_SUCCESS(err);
373
374 err = xglGetObjectInfo(m_depthStencilImage,
Jon Ashburna9ae3832015-01-16 09:37:43 -0700375 XGL_INFO_TYPE_MEMORY_ALLOCATION_COUNT,
376 &num_alloc_size, &num_allocations);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600377 ASSERT_XGL_SUCCESS(err);
Jon Ashburna9ae3832015-01-16 09:37:43 -0700378 ASSERT_EQ(num_alloc_size, sizeof(num_allocations));
379 mem_reqs = (XGL_MEMORY_REQUIREMENTS *) malloc(num_allocations * sizeof(XGL_MEMORY_REQUIREMENTS));
380 m_depthStencilMem = (XGL_GPU_MEMORY *) malloc(num_allocations * sizeof(XGL_GPU_MEMORY));
381 m_num_mem = num_allocations;
382 err = xglGetObjectInfo(m_depthStencilImage,
383 XGL_INFO_TYPE_MEMORY_REQUIREMENTS,
384 &mem_reqs_size, mem_reqs);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600385 ASSERT_XGL_SUCCESS(err);
Jon Ashburna9ae3832015-01-16 09:37:43 -0700386 ASSERT_EQ(mem_reqs_size, sizeof(*mem_reqs));
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700387 err = xglGetObjectInfo(m_depthStencilImage,
388 XGL_INFO_TYPE_IMAGE_MEMORY_REQUIREMENTS,
389 &img_reqs_size, &img_reqs);
390 ASSERT_XGL_SUCCESS(err);
391 ASSERT_EQ(img_reqs_size, sizeof(XGL_IMAGE_MEMORY_REQUIREMENTS));
392 img_alloc.usage = img_reqs.usage;
393 img_alloc.formatClass = img_reqs.formatClass;
394 img_alloc.samples = img_reqs.samples;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600395 for (uint32_t i = 0; i < num_allocations; i ++) {
Jon Ashburna9ae3832015-01-16 09:37:43 -0700396 mem_alloc.allocationSize = mem_reqs[i].size;
Jon Ashburna9ae3832015-01-16 09:37:43 -0700397
398 /* allocate memory */
399 err = xglAllocMemory(device(), &mem_alloc, &m_depthStencilMem[i]);
400 ASSERT_XGL_SUCCESS(err);
401
402 /* bind memory */
403 err = xglBindObjectMemory(m_depthStencilImage, i,
404 m_depthStencilMem[i], 0);
405 ASSERT_XGL_SUCCESS(err);
406 }
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600407
Tony Barbourfa6cac72015-01-16 14:27:35 -0700408 XGL_DYNAMIC_DS_STATE_CREATE_INFO depthStencil = {};
409 depthStencil.sType = XGL_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO;
410
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600411 depthStencil.minDepth = 0.f;
412 depthStencil.maxDepth = 1.f;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700413 depthStencil.stencilBackRef = 0;
414 depthStencil.stencilFrontRef = 0;
415 depthStencil.stencilReadMask = 0xff;
416 depthStencil.stencilWriteMask = 0xff;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600417
Tony Barbourfa6cac72015-01-16 14:27:35 -0700418 err = xglCreateDynamicDepthStencilState( device(), &depthStencil, &m_stateDepthStencil );
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600419 ASSERT_XGL_SUCCESS( err );
420
421 /* create image view */
422 view.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO;
423 view.pNext = NULL;
424 view.image = XGL_NULL_HANDLE;
425 view.mipLevel = 0;
426 view.baseArraySlice = 0;
427 view.arraySize = 1;
428 view.flags = 0;
429 view.image = m_depthStencilImage;
430 err = xglCreateDepthStencilView(device(), &view, &m_depthStencilView);
431 ASSERT_XGL_SUCCESS(err);
432
433 m_depthStencilBinding.view = m_depthStencilView;
Mike Stroyan55658c22014-12-04 11:08:39 +0000434 m_depthStencilBinding.layout = XGL_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600435}
436
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600437struct xgltriangle_vs_uniform {
438 // Must start with MVP
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600439 float mvp[4][4];
440 float position[3][4];
441 float color[3][4];
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600442};
443
Tony Barbourae442072015-01-12 13:27:11 -0700444void XglRenderTest::XGLTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600445{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700446#ifdef DEBUG_CALLBACK
447 xglDbgRegisterMsgCallback(myDbgFunc, NULL);
448#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600449 // Create identity matrix
450 int i;
451 struct xgltriangle_vs_uniform data;
452
453 glm::mat4 Projection = glm::mat4(1.0f);
454 glm::mat4 View = glm::mat4(1.0f);
455 glm::mat4 Model = glm::mat4(1.0f);
456 glm::mat4 MVP = Projection * View * Model;
457 const int matrixSize = sizeof(MVP);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600458 const int bufSize = sizeof(xgltriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600459 memcpy(&data.mvp, &MVP[0][0], matrixSize);
460
461 static const Vertex tri_data[] =
462 {
463 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
464 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
465 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
466 };
467
468 for (i=0; i<3; i++) {
469 data.position[i][0] = tri_data[i].posX;
470 data.position[i][1] = tri_data[i].posY;
471 data.position[i][2] = tri_data[i].posZ;
472 data.position[i][3] = tri_data[i].posW;
473 data.color[i][0] = tri_data[i].r;
474 data.color[i][1] = tri_data[i].g;
475 data.color[i][2] = tri_data[i].b;
476 data.color[i][3] = tri_data[i].a;
477 }
478
Tony Barbourf43b6982014-11-25 13:18:32 -0700479 ASSERT_NO_FATAL_FAILURE(InitState());
480 ASSERT_NO_FATAL_FAILURE(InitViewport());
481
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600482 XglConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barbourf43b6982014-11-25 13:18:32 -0700483
484 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
485 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700486
487 XglPipelineObj pipelineobj(m_device);
488 pipelineobj.AddShader(&vs);
489 pipelineobj.AddShader(&ps);
490
491 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +0800492 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700493 m_memoryRefManager.AddMemoryRef(&constantBuffer);
494
Tony Barbour71ba3612015-01-09 16:12:35 -0700495 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski15427102015-02-18 16:38:17 -0600496 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargetCount);
Tony Barbour71ba3612015-01-09 16:12:35 -0700497 XglCommandBufferObj cmdBuffer(m_device);
498 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700499
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700500 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour71ba3612015-01-09 16:12:35 -0700501
502 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Tony Barbour71ba3612015-01-09 16:12:35 -0700503#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600504 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour71ba3612015-01-09 16:12:35 -0700505 pDSDumpDot((char*)"triTest2.dot");
506#endif
507 // render triangle
508 cmdBuffer.Draw(0, 3, 0, 1);
509
510 // finalize recording of the command buffer
511 cmdBuffer.EndCommandBuffer();
512 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
513
514 for (int i = 0; i < m_renderTargetCount; i++)
515 RecordImage(m_renderTargets[i]);
516
517 if (rotate)
Tobin Ehlis12ee35f2015-03-26 08:23:25 -0600518 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
Tony Barbour71ba3612015-01-09 16:12:35 -0700519
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700520#ifdef PRINT_OBJECTS
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600521 //uint64_t objTrackGetObjectCount(XGL_OBJECT_TYPE type)
522 OBJ_TRACK_GET_OBJECT_COUNT pObjTrackGetObjectCount = (OBJ_TRACK_GET_OBJECT_COUNT)xglGetProcAddr(gpu(), (char*)"objTrackGetObjectCount");
523 uint64_t numObjects = pObjTrackGetObjectCount(XGL_OBJECT_TYPE_ANY);
524 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = xglGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700525 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600526 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)xglGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700527 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
528 pObjTrackGetObjs(XGL_OBJECT_TYPE_ANY, numObjects, pObjNodeArray);
529 for (i=0; i < numObjects; i++) {
530 printf("Object %i of type %s has objID (%p) and %lu uses\n", i, string_XGL_OBJECT_TYPE(pObjNodeArray[i].objType), pObjNodeArray[i].pObj, pObjNodeArray[i].numUses);
531 }
532 free(pObjNodeArray);
533#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700534
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600535}
536
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600537TEST_F(XglRenderTest, XGLTriangle_FragColor)
538{
539 static const char *vertShaderText =
540 "#version 140\n"
541 "#extension GL_ARB_separate_shader_objects : enable\n"
542 "#extension GL_ARB_shading_language_420pack : enable\n"
543 "\n"
544 "layout(binding = 0) uniform buf {\n"
545 " mat4 MVP;\n"
546 " vec4 position[3];\n"
547 " vec4 color[3];\n"
548 "} ubuf;\n"
549 "\n"
550 "layout (location = 0) out vec4 outColor;\n"
551 "\n"
552 "void main() \n"
553 "{\n"
554 " outColor = ubuf.color[gl_VertexID];\n"
555 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
556 "}\n";
557
558 static const char *fragShaderText =
559 "#version 140\n"
560 "#extension GL_ARB_separate_shader_objects : enable\n"
561 "#extension GL_ARB_shading_language_420pack : enable\n"
562 "\n"
563 "layout (location = 0) in vec4 inColor;\n"
564 "\n"
565 "void main()\n"
566 "{\n"
567 " gl_FragColor = inColor;\n"
568 "}\n";
569
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600570 TEST_DESCRIPTION("XGL-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
Tony Barbourae442072015-01-12 13:27:11 -0700571 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600572}
573
574TEST_F(XglRenderTest, XGLTriangle_OutputLocation)
575{
576 static const char *vertShaderText =
577 "#version 140\n"
578 "#extension GL_ARB_separate_shader_objects : enable\n"
579 "#extension GL_ARB_shading_language_420pack : enable\n"
580 "\n"
581 "layout(binding = 0) uniform buf {\n"
582 " mat4 MVP;\n"
583 " vec4 position[3];\n"
584 " vec4 color[3];\n"
585 "} ubuf;\n"
586 "\n"
587 "layout (location = 0) out vec4 outColor;\n"
588 "\n"
589 "void main() \n"
590 "{\n"
591 " outColor = ubuf.color[gl_VertexID];\n"
592 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
593 "}\n";
594
595 static const char *fragShaderText =
596 "#version 140\n"
597 "#extension GL_ARB_separate_shader_objects : enable\n"
598 "#extension GL_ARB_shading_language_420pack : enable\n"
599 "\n"
600 "layout (location = 0) in vec4 inColor;\n"
601 "layout (location = 0) out vec4 outColor;\n"
602 "\n"
603 "void main()\n"
604 "{\n"
605 " outColor = inColor;\n"
606 "}\n";
607
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600608 TEST_DESCRIPTION("XGL-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 -0600609
Tony Barbourae442072015-01-12 13:27:11 -0700610 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600611}
612
Cody Northropacfb0492015-03-17 15:55:58 -0600613TEST_F(XglRenderTest, SPV_XGLTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700614{
Cody Northropacfb0492015-03-17 15:55:58 -0600615 bool saved_use_spv = XglTestFramework::m_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700616
617 static const char *vertShaderText =
618 "#version 140\n"
619 "#extension GL_ARB_separate_shader_objects : enable\n"
620 "#extension GL_ARB_shading_language_420pack : enable\n"
621 "\n"
622 "layout(binding = 0) uniform buf {\n"
623 " mat4 MVP;\n"
624 " vec4 position[3];\n"
625 " vec4 color[3];\n"
626 "} ubuf;\n"
627 "\n"
628 "layout (location = 0) out vec4 outColor;\n"
629 "\n"
630 "void main() \n"
631 "{\n"
632 " outColor = ubuf.color[gl_VertexID];\n"
633 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
634 "}\n";
635
636 static const char *fragShaderText =
637 "#version 140\n"
638 "#extension GL_ARB_separate_shader_objects : enable\n"
639 "#extension GL_ARB_shading_language_420pack : enable\n"
640 "\n"
641 "layout (location = 0) in vec4 inColor;\n"
642 "\n"
643 "void main()\n"
644 "{\n"
645 " gl_FragColor = inColor;\n"
646 "}\n";
647
Cody Northropacfb0492015-03-17 15:55:58 -0600648 TEST_DESCRIPTION("XGL-style shaders, but force test framework to compile shader to SPV and pass SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700649
Cody Northropacfb0492015-03-17 15:55:58 -0600650 XglTestFramework::m_use_spv = true;
Tony Barbourf43b6982014-11-25 13:18:32 -0700651
Tony Barbourae442072015-01-12 13:27:11 -0700652 XGLTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700653
Cody Northropacfb0492015-03-17 15:55:58 -0600654 XglTestFramework::m_use_spv = saved_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700655}
656
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600657TEST_F(XglRenderTest, GreenTriangle)
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600658{
659 static const char *vertShaderText =
660 "#version 130\n"
661 "vec2 vertices[3];\n"
662 "void main() {\n"
663 " vertices[0] = vec2(-1.0, -1.0);\n"
664 " vertices[1] = vec2( 1.0, -1.0);\n"
665 " vertices[2] = vec2( 0.0, 1.0);\n"
666 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
667 "}\n";
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600668
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600669 static const char *fragShaderText =
670 "#version 130\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600671 "void main() {\n"
Steve K10b32512014-10-10 08:54:29 -0600672 " gl_FragColor = vec4(0,1,0,1);\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600673 "}\n";
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600674
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600675 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
676
Tony Barbourae442072015-01-12 13:27:11 -0700677 XGLTriangleTest(vertShaderText, fragShaderText, false);
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600678}
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600679
Cody Northropacfb0492015-03-17 15:55:58 -0600680TEST_F(XglRenderTest, SPV_GreenTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700681{
Cody Northropacfb0492015-03-17 15:55:58 -0600682 bool saved_use_spv = XglTestFramework::m_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700683
684 static const char *vertShaderText =
685 "#version 130\n"
686 "vec2 vertices[3];\n"
687 "void main() {\n"
688 " vertices[0] = vec2(-1.0, -1.0);\n"
689 " vertices[1] = vec2( 1.0, -1.0);\n"
690 " vertices[2] = vec2( 0.0, 1.0);\n"
691 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
692 "}\n";
693
694 static const char *fragShaderText =
695 "#version 130\n"
696 "void main() {\n"
697 " gl_FragColor = vec4(0,1,0,1);\n"
698 "}\n";
699
Cody Northropacfb0492015-03-17 15:55:58 -0600700 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700701
Cody Northropacfb0492015-03-17 15:55:58 -0600702 XglTestFramework::m_use_spv = true;
Tony Barbourae442072015-01-12 13:27:11 -0700703 XGLTriangleTest(vertShaderText, fragShaderText, false);
Cody Northropacfb0492015-03-17 15:55:58 -0600704 XglTestFramework::m_use_spv = saved_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700705}
706
707TEST_F(XglRenderTest, YellowTriangle)
708{
709 static const char *vertShaderText =
710 "#version 130\n"
711 "void main() {\n"
712 " vec2 vertices[3];"
713 " vertices[0] = vec2(-0.5, -0.5);\n"
714 " vertices[1] = vec2( 0.5, -0.5);\n"
715 " vertices[2] = vec2( 0.5, 0.5);\n"
716 " vec4 colors[3];\n"
717 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
718 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
719 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
720 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
721 "}\n";
722
723 static const char *fragShaderText =
724 "#version 130\n"
725 "void main() {\n"
726 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
727 "}\n";
728
Tony Barbourae442072015-01-12 13:27:11 -0700729 XGLTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700730}
731
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600732TEST_F(XglRenderTest, TriangleWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600733{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600734 static const char *vertShaderText =
Tony Barbourf43b6982014-11-25 13:18:32 -0700735 "#version 130\n"
736 //XYZ1( -1, -1, -1 )
737 "in vec4 pos;\n"
738 //XYZ1( 0.f, 0.f, 0.f )
739 "in vec4 inColor;\n"
740 "out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600741 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600742 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600743 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600744 "}\n";
745
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600746
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600747 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700748 "#version 140\n"
749 "#extension GL_ARB_separate_shader_objects : enable\n"
750 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700751 "in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700752 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600753 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700754 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600755 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600756
Tony Barbourf43b6982014-11-25 13:18:32 -0700757
758
759 ASSERT_NO_FATAL_FAILURE(InitState());
760 ASSERT_NO_FATAL_FAILURE(InitViewport());
761
762 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000763 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700764
765 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
766 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
767
768 XglPipelineObj pipelineobj(m_device);
769 pipelineobj.AddShader(&vs);
770 pipelineobj.AddShader(&ps);
771
772 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +0800773 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700774
Mark Lobodzinski15427102015-02-18 16:38:17 -0600775 m_memoryRefManager.AddMemoryRef(&meshBuffer);
776
Tony Barbourf43b6982014-11-25 13:18:32 -0700777 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
778 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
779 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
780 };
781
782 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
783 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700784 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -0700785 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
786 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700787 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -0700788 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
789
790 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
791 pipelineobj.AddVertexInputBindings(&vi_binding,1);
792 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
793
Tony Barboure4ed9942015-01-09 10:06:53 -0700794 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski15427102015-02-18 16:38:17 -0600795 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargetCount);
Tony Barboure4ed9942015-01-09 10:06:53 -0700796 XglCommandBufferObj cmdBuffer(m_device);
797 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700798
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700799 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -0700800 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
801
Tony Barboure4ed9942015-01-09 10:06:53 -0700802 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
803
804 // render two triangles
805 cmdBuffer.Draw(0, 6, 0, 1);
806
807 // finalize recording of the command buffer
808 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -0600809 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barboure4ed9942015-01-09 10:06:53 -0700810
811 for (int i = 0; i < m_renderTargetCount; i++)
812 RecordImage(m_renderTargets[i]);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600813}
814
Chia-I Wue09d1a72014-12-05 10:32:23 +0800815TEST_F(XglRenderTest, TriangleMRT)
816{
817 static const char *vertShaderText =
818 "#version 130\n"
819 "in vec4 pos;\n"
820 "void main() {\n"
821 " gl_Position = pos;\n"
822 "}\n";
823
824 static const char *fragShaderText =
825 "#version 130\n"
826 "void main() {\n"
827 " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
828 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
829 "}\n";
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600830 const float vb_data[][2] = {
Chia-I Wue09d1a72014-12-05 10:32:23 +0800831 { -1.0f, -1.0f },
832 { 1.0f, -1.0f },
833 { -1.0f, 1.0f }
834 };
835
836 ASSERT_NO_FATAL_FAILURE(InitState());
837 ASSERT_NO_FATAL_FAILURE(InitViewport());
838
839 XglConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000840 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800841
842 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
843 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
844
845 XglPipelineObj pipelineobj(m_device);
846 pipelineobj.AddShader(&vs);
847 pipelineobj.AddShader(&ps);
848
849 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
850 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
851 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
852 };
853
854 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attrib;
855 vi_attrib.binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700856 vi_attrib.format = XGL_FMT_R32G32_SFLOAT; // format of source data
Chia-I Wue09d1a72014-12-05 10:32:23 +0800857 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
858
859 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
860 pipelineobj.AddVertexInputBindings(&vi_binding,1);
861 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
862
863 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -0600864 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800865
866 m_renderTargetCount = 2;
Tony Barboure4ed9942015-01-09 10:06:53 -0700867 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski15427102015-02-18 16:38:17 -0600868 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargetCount);
869 m_memoryRefManager.AddMemoryRef(&meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800870
871 XGL_PIPELINE_CB_ATTACHMENT_STATE att = {};
872 att.blendEnable = XGL_FALSE;
873 att.format = m_render_target_fmt;
874 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700875 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800876
Tony Barbour5ed79702015-01-07 14:31:52 -0700877 XglCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700878
Tony Barbour5ed79702015-01-07 14:31:52 -0700879 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
880 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barboure4ed9942015-01-09 10:06:53 -0700881
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700882 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour5ed79702015-01-07 14:31:52 -0700883
Tony Barboure4ed9942015-01-09 10:06:53 -0700884 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
885
Tony Barbour5ed79702015-01-07 14:31:52 -0700886 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700887#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600888 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour5ed79702015-01-07 14:31:52 -0700889 pDSDumpDot((char*)"triTest2.dot");
890#endif
891 // render triangle
892 cmdBuffer.Draw(0, 3, 0, 1);
893
894 // finalize recording of the command buffer
895 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -0600896 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbour5ed79702015-01-07 14:31:52 -0700897
898 for (int i = 0; i < m_renderTargetCount; i++)
899 RecordImage(m_renderTargets[i]);
900
Chia-I Wue09d1a72014-12-05 10:32:23 +0800901}
902
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700903TEST_F(XglRenderTest, QuadWithIndexedVertexFetch)
904{
905 static const char *vertShaderText =
906 "#version 140\n"
907 "#extension GL_ARB_separate_shader_objects : enable\n"
908 "#extension GL_ARB_shading_language_420pack : enable\n"
909 "layout(location = 0) in vec4 pos;\n"
910 "layout(location = 1) in vec4 inColor;\n"
911 "layout(location = 0) out vec4 outColor;\n"
912 "void main() {\n"
913 " outColor = inColor;\n"
914 " gl_Position = pos;\n"
915 "}\n";
916
917
918 static const char *fragShaderText =
919 "#version 140\n"
920 "#extension GL_ARB_separate_shader_objects : enable\n"
921 "#extension GL_ARB_shading_language_420pack : enable\n"
922 "layout(location = 0) in vec4 color;\n"
923 "void main() {\n"
924 " gl_FragColor = color;\n"
925 "}\n";
926
927 const Vertex g_vbData[] =
928 {
929 // first tri
930 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
931 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
932 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
933
934 // second tri
935 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
936 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
937 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
938 };
939
940 const uint16_t g_idxData[6] = {
941 0, 1, 2,
942 3, 4, 5,
943 };
944
945 ASSERT_NO_FATAL_FAILURE(InitState());
946 ASSERT_NO_FATAL_FAILURE(InitViewport());
947
948 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000949 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700950
951 XglIndexBufferObj indexBuffer(m_device);
952 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), XGL_INDEX_16, g_idxData);
Mark Lobodzinskid30f82a2015-02-16 14:24:23 -0600953 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700954
955 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
956 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
957
958 XglPipelineObj pipelineobj(m_device);
959 pipelineobj.AddShader(&vs);
960 pipelineobj.AddShader(&ps);
961
962 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -0600963 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
964 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &indexBuffer);
965
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700966
Mark Lobodzinski15427102015-02-18 16:38:17 -0600967 m_memoryRefManager.AddMemoryRef(&meshBuffer);
968 m_memoryRefManager.AddMemoryRef(&indexBuffer);
969
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700970 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
971 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
972 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
973 };
974
975 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
976 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700977 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700978 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
979 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700980 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700981 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
982
983 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
984 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700985
986 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski15427102015-02-18 16:38:17 -0600987 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargetCount);
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700988 XglCommandBufferObj cmdBuffer(m_device);
989 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700990 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -0700991
992 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700993
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700994#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600995 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700996 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700997#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700998
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700999 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1000 cmdBuffer.BindIndexBuffer(&indexBuffer,0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001001
1002 // render two triangles
Tony Barbourde9cf2e2014-12-17 11:16:05 -07001003 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001004
1005 // finalize recording of the command buffer
Tony Barbourde9cf2e2014-12-17 11:16:05 -07001006 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06001007 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001008
Tony Barbourde9cf2e2014-12-17 11:16:05 -07001009 for (int i = 0; i < m_renderTargetCount; i++)
1010 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001011
1012}
1013
GregF6bef1212014-12-02 15:41:44 -07001014TEST_F(XglRenderTest, GreyandRedCirclesonBlue)
1015{
1016 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -07001017
GregF6bef1212014-12-02 15:41:44 -07001018 static const char *vertShaderText =
1019 "#version 140\n"
1020 "#extension GL_ARB_separate_shader_objects : enable\n"
1021 "#extension GL_ARB_shading_language_420pack : enable\n"
1022 "layout (location = 0) in vec4 pos;\n"
1023 "layout (location = 0) out vec4 outColor;\n"
1024 "layout (location = 1) out vec4 outColor2;\n"
1025 "void main() {\n"
1026 " gl_Position = pos;\n"
1027 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1028 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1029 "}\n";
1030
1031 static const char *fragShaderText =
1032 //"#version 140\n"
1033 "#version 330\n"
1034 "#extension GL_ARB_separate_shader_objects : enable\n"
1035 "#extension GL_ARB_shading_language_420pack : enable\n"
1036 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1037 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1038 "layout (location = 0) in vec4 color;\n"
1039 "layout (location = 1) in vec4 color2;\n"
1040 "void main() {\n"
1041 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1042 " float dist_squared = dot(pos, pos);\n"
1043 " gl_FragColor = (dist_squared < 400.0)\n"
1044 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1045 " : color2;\n"
1046 "}\n";
1047
1048 ASSERT_NO_FATAL_FAILURE(InitState());
1049 ASSERT_NO_FATAL_FAILURE(InitViewport());
1050
1051 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001052 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001053
1054 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1055 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1056
1057 XglPipelineObj pipelineobj(m_device);
1058 pipelineobj.AddShader(&vs);
1059 pipelineobj.AddShader(&ps);
1060
1061 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001062 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001063
Mark Lobodzinski15427102015-02-18 16:38:17 -06001064 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1065
GregF6bef1212014-12-02 15:41:44 -07001066 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1067 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1068 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1069 };
1070
1071 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1072 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001073 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001074 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1075 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001076 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001077 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1078
1079 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1080 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1081 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1082
Tony Barbourdd4c9642015-01-09 12:55:14 -07001083 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski15427102015-02-18 16:38:17 -06001084 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargetCount);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001085 XglCommandBufferObj cmdBuffer(m_device);
1086 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1087
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001088 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001089
1090 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1091
1092 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1093#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001094 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001095 pDSDumpDot((char*)"triTest2.dot");
1096#endif
1097 // render triangle
1098 cmdBuffer.Draw(0, 6, 0, 1);
1099
1100 // finalize recording of the command buffer
1101 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06001102 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001103
1104 for (int i = 0; i < m_renderTargetCount; i++)
1105 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001106
1107}
1108
1109TEST_F(XglRenderTest, RedCirclesonBlue)
1110{
1111 // This tests that we correctly handle unread fragment inputs
1112
1113 static const char *vertShaderText =
1114 "#version 140\n"
1115 "#extension GL_ARB_separate_shader_objects : enable\n"
1116 "#extension GL_ARB_shading_language_420pack : enable\n"
1117 "layout (location = 0) in vec4 pos;\n"
1118 "layout (location = 0) out vec4 outColor;\n"
1119 "layout (location = 1) out vec4 outColor2;\n"
1120 "void main() {\n"
1121 " gl_Position = pos;\n"
1122 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1123 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1124 "}\n";
1125
1126 static const char *fragShaderText =
1127 //"#version 140\n"
1128 "#version 330\n"
1129 "#extension GL_ARB_separate_shader_objects : enable\n"
1130 "#extension GL_ARB_shading_language_420pack : enable\n"
1131 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1132 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1133 "layout (location = 0) in vec4 color;\n"
1134 "layout (location = 1) in vec4 color2;\n"
1135 "void main() {\n"
1136 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1137 " float dist_squared = dot(pos, pos);\n"
1138 " gl_FragColor = (dist_squared < 400.0)\n"
1139 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1140 " : color2;\n"
1141 "}\n";
1142
1143 ASSERT_NO_FATAL_FAILURE(InitState());
1144 ASSERT_NO_FATAL_FAILURE(InitViewport());
1145
1146 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001147 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001148
1149 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1150 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1151
1152 XglPipelineObj pipelineobj(m_device);
1153 pipelineobj.AddShader(&vs);
1154 pipelineobj.AddShader(&ps);
1155
1156 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001157 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001158
Mark Lobodzinski15427102015-02-18 16:38:17 -06001159 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1160
GregF6bef1212014-12-02 15:41:44 -07001161 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1162 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1163 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1164 };
1165
1166 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1167 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001168 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001169 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1170 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001171 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001172 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1173
1174 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1175 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1176 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1177
Tony Barbourdd4c9642015-01-09 12:55:14 -07001178 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski15427102015-02-18 16:38:17 -06001179 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargetCount);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001180 XglCommandBufferObj cmdBuffer(m_device);
1181 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1182
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001183 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001184
1185 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1186
1187 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1188#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001189 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001190 pDSDumpDot((char*)"triTest2.dot");
1191#endif
1192 // render triangle
1193 cmdBuffer.Draw(0, 6, 0, 1);
1194
1195 // finalize recording of the command buffer
1196 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06001197 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001198
1199 for (int i = 0; i < m_renderTargetCount; i++)
1200 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001201
1202}
1203
1204TEST_F(XglRenderTest, GreyCirclesonBlueFade)
1205{
1206 // This tests reading gl_ClipDistance from FS
1207
1208 static const char *vertShaderText =
1209 "#version 330\n"
1210 "#extension GL_ARB_separate_shader_objects : enable\n"
1211 "#extension GL_ARB_shading_language_420pack : enable\n"
1212 "out gl_PerVertex {\n"
1213 " vec4 gl_Position;\n"
1214 " float gl_ClipDistance[1];\n"
1215 "};\n"
1216 "layout (location = 0) in vec4 pos;\n"
1217 "layout (location = 0) out vec4 outColor;\n"
1218 "layout (location = 1) out vec4 outColor2;\n"
1219 "void main() {\n"
1220 " gl_Position = pos;\n"
1221 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1222 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1223 " float dists[3];\n"
1224 " dists[0] = 0.0;\n"
1225 " dists[1] = 1.0;\n"
1226 " dists[2] = 1.0;\n"
1227 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1228 "}\n";
1229
1230
1231 static const char *fragShaderText =
1232 //"#version 140\n"
1233 "#version 330\n"
1234 "#extension GL_ARB_separate_shader_objects : enable\n"
1235 "#extension GL_ARB_shading_language_420pack : enable\n"
1236 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1237 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1238 "layout (location = 0) in vec4 color;\n"
1239 "layout (location = 1) in vec4 color2;\n"
1240 "void main() {\n"
1241 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1242 " float dist_squared = dot(pos, pos);\n"
1243 " gl_FragColor = (dist_squared < 400.0)\n"
1244 " ? color * gl_ClipDistance[0]\n"
1245 " : color2;\n"
1246 "}\n";
1247
1248 ASSERT_NO_FATAL_FAILURE(InitState());
1249 ASSERT_NO_FATAL_FAILURE(InitViewport());
1250
1251 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001252 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001253
1254 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1255 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1256
1257 XglPipelineObj pipelineobj(m_device);
1258 pipelineobj.AddShader(&vs);
1259 pipelineobj.AddShader(&ps);
1260
1261 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001262 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001263
Mark Lobodzinski15427102015-02-18 16:38:17 -06001264 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1265
GregF6bef1212014-12-02 15:41:44 -07001266 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1267 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1268 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1269 };
1270
1271 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1272 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001273 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001274 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1275 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001276 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001277 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1278
1279 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1280 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1281 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1282
Tony Barbourdd4c9642015-01-09 12:55:14 -07001283 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski15427102015-02-18 16:38:17 -06001284 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargetCount);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001285 XglCommandBufferObj cmdBuffer(m_device);
1286 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF6bef1212014-12-02 15:41:44 -07001287
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001288 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001289
1290 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1291
1292 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1293#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001294 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001295 pDSDumpDot((char*)"triTest2.dot");
1296#endif
1297 // render triangle
1298 cmdBuffer.Draw(0, 6, 0, 1);
1299
1300 // finalize recording of the command buffer
1301 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06001302 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001303
1304 for (int i = 0; i < m_renderTargetCount; i++)
1305 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001306}
Tony Barbourf43b6982014-11-25 13:18:32 -07001307
GregF7a23c792014-12-02 17:19:34 -07001308TEST_F(XglRenderTest, GreyCirclesonBlueDiscard)
1309{
1310 static const char *vertShaderText =
1311 "#version 140\n"
1312 "#extension GL_ARB_separate_shader_objects : enable\n"
1313 "#extension GL_ARB_shading_language_420pack : enable\n"
1314 "layout (location = 0) in vec4 pos;\n"
1315 "layout (location = 0) out vec4 outColor;\n"
1316 "layout (location = 1) out vec4 outColor2;\n"
1317 "void main() {\n"
1318 " gl_Position = pos;\n"
1319 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1320 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1321 "}\n";
1322
1323
1324 static const char *fragShaderText =
1325 //"#version 140\n"
1326 "#version 330\n"
1327 "#extension GL_ARB_separate_shader_objects : enable\n"
1328 "#extension GL_ARB_shading_language_420pack : enable\n"
1329 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1330 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1331 "layout (location = 0) in vec4 color;\n"
1332 "layout (location = 1) in vec4 color2;\n"
1333 "void main() {\n"
1334 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1335 " float dist_squared = dot(pos, pos);\n"
1336 " if (dist_squared < 100.0)\n"
1337 " discard;\n"
1338 " gl_FragColor = (dist_squared < 400.0)\n"
1339 " ? color\n"
1340 " : color2;\n"
1341 "}\n";
1342
1343 ASSERT_NO_FATAL_FAILURE(InitState());
1344 ASSERT_NO_FATAL_FAILURE(InitViewport());
1345
1346 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001347 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001348
1349 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1350 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1351
1352 XglPipelineObj pipelineobj(m_device);
1353 pipelineobj.AddShader(&vs);
1354 pipelineobj.AddShader(&ps);
1355
1356 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001357 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF7a23c792014-12-02 17:19:34 -07001358
Mark Lobodzinski15427102015-02-18 16:38:17 -06001359 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1360
GregF7a23c792014-12-02 17:19:34 -07001361 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1362 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1363 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1364 };
1365
1366 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1367 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001368 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF7a23c792014-12-02 17:19:34 -07001369 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1370 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001371 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF7a23c792014-12-02 17:19:34 -07001372 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1373
1374 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1375 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1376 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1377
Tony Barbourdd4c9642015-01-09 12:55:14 -07001378 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski15427102015-02-18 16:38:17 -06001379 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargetCount);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001380 XglCommandBufferObj cmdBuffer(m_device);
1381 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1382
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001383 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001384
1385 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1386
1387 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1388#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001389 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001390 pDSDumpDot((char*)"triTest2.dot");
1391#endif
1392 // render triangle
1393 cmdBuffer.Draw(0, 6, 0, 1);
1394
1395 // finalize recording of the command buffer
1396 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06001397 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001398
1399 for (int i = 0; i < m_renderTargetCount; i++)
1400 RecordImage(m_renderTargets[i]);
GregF7a23c792014-12-02 17:19:34 -07001401
1402}
1403
1404
Courtney Goeltzenleuchter3d10c9c2014-10-27 13:06:08 -06001405TEST_F(XglRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001406{
1407 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001408 "#version 140\n"
1409 "#extension GL_ARB_separate_shader_objects : enable\n"
1410 "#extension GL_ARB_shading_language_420pack : enable\n"
1411 "\n"
1412 "layout(binding = 0) uniform buf {\n"
1413 " mat4 MVP;\n"
1414 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001415 "void main() {\n"
1416 " vec2 vertices[3];"
1417 " vertices[0] = vec2(-0.5, -0.5);\n"
1418 " vertices[1] = vec2( 0.5, -0.5);\n"
1419 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001420 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001421 "}\n";
1422
1423 static const char *fragShaderText =
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001424 "#version 130\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001425 "void main() {\n"
Cody Northrop78eac042014-10-10 15:45:00 -06001426 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001427 "}\n";
1428
Tony Barbourf43b6982014-11-25 13:18:32 -07001429 ASSERT_NO_FATAL_FAILURE(InitState());
1430 ASSERT_NO_FATAL_FAILURE(InitViewport());
1431
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001432 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001433 glm::mat4 Projection = glm::mat4(1.0f);
1434 glm::mat4 View = glm::mat4(1.0f);
1435 glm::mat4 Model = glm::mat4(1.0f);
1436 glm::mat4 MVP = Projection * View * Model;
1437 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1438
Tony Barbourf43b6982014-11-25 13:18:32 -07001439 XglConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1440 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1441 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001442
Tony Barbourf43b6982014-11-25 13:18:32 -07001443 XglPipelineObj pipelineobj(m_device);
1444 pipelineobj.AddShader(&vs);
1445 pipelineobj.AddShader(&ps);
1446
1447 // Create descriptor set and attach the constant buffer to it
1448 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001449 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001450
1451 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1452
Tony Barbourdd4c9642015-01-09 12:55:14 -07001453 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski15427102015-02-18 16:38:17 -06001454 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargetCount);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001455 XglCommandBufferObj cmdBuffer(m_device);
1456 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001457
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001458 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001459
1460 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1461
1462 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1463#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001464 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001465 pDSDumpDot((char*)"triTest2.dot");
1466#endif
1467 // render triangle
1468 cmdBuffer.Draw(0, 6, 0, 1);
1469
1470 // finalize recording of the command buffer
1471 cmdBuffer.EndCommandBuffer();
1472 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
1473
1474 for (int i = 0; i < m_renderTargetCount; i++)
1475 RecordImage(m_renderTargets[i]);
1476
1477 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001478}
1479
Tony Barbourf43b6982014-11-25 13:18:32 -07001480TEST_F(XglRenderTest, MixTriangle)
1481{
1482 // This tests location applied to varyings. Notice that we have switched foo
1483 // and bar in the FS. The triangle should be blended with red, green and blue
1484 // corners.
1485 static const char *vertShaderText =
1486 "#version 140\n"
1487 "#extension GL_ARB_separate_shader_objects : enable\n"
1488 "#extension GL_ARB_shading_language_420pack : enable\n"
1489 "layout (location=0) out vec4 bar;\n"
1490 "layout (location=1) out vec4 foo;\n"
1491 "layout (location=2) out float scale;\n"
1492 "vec2 vertices[3];\n"
1493 "void main() {\n"
1494 " vertices[0] = vec2(-1.0, -1.0);\n"
1495 " vertices[1] = vec2( 1.0, -1.0);\n"
1496 " vertices[2] = vec2( 0.0, 1.0);\n"
1497 "vec4 colors[3];\n"
1498 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1499 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1500 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1501 " foo = colors[gl_VertexID % 3];\n"
1502 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1503 " scale = 1.0;\n"
1504 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1505 "}\n";
1506
1507 static const char *fragShaderText =
1508 "#version 140\n"
1509 "#extension GL_ARB_separate_shader_objects : enable\n"
1510 "#extension GL_ARB_shading_language_420pack : enable\n"
1511 "layout (location = 1) in vec4 bar;\n"
1512 "layout (location = 0) in vec4 foo;\n"
1513 "layout (location = 2) in float scale;\n"
1514 "void main() {\n"
1515 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
1516 "}\n";
1517
1518 ASSERT_NO_FATAL_FAILURE(InitState());
1519 ASSERT_NO_FATAL_FAILURE(InitViewport());
1520
1521 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1522 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1523
1524 XglPipelineObj pipelineobj(m_device);
1525 pipelineobj.AddShader(&vs);
1526 pipelineobj.AddShader(&ps);
1527
1528 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06001529 descriptorSet.AppendDummy();
Tony Barbourf43b6982014-11-25 13:18:32 -07001530
Tony Barbourdd4c9642015-01-09 12:55:14 -07001531 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski15427102015-02-18 16:38:17 -06001532 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargetCount);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001533 XglCommandBufferObj cmdBuffer(m_device);
1534 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1535
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001536 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001537
1538 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1539
1540#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001541 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001542 pDSDumpDot((char*)"triTest2.dot");
1543#endif
1544 // render triangle
1545 cmdBuffer.Draw(0, 3, 0, 1);
1546
1547 // finalize recording of the command buffer
1548 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06001549 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001550
1551 for (int i = 0; i < m_renderTargetCount; i++)
1552 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001553}
1554
1555TEST_F(XglRenderTest, TriVertFetchAndVertID)
1556{
1557 // This tests that attributes work in the presence of gl_VertexID
1558
1559 static const char *vertShaderText =
1560 "#version 140\n"
1561 "#extension GL_ARB_separate_shader_objects : enable\n"
1562 "#extension GL_ARB_shading_language_420pack : enable\n"
1563 //XYZ1( -1, -1, -1 )
1564 "layout (location = 0) in vec4 pos;\n"
1565 //XYZ1( 0.f, 0.f, 0.f )
1566 "layout (location = 1) in vec4 inColor;\n"
1567 "layout (location = 0) out vec4 outColor;\n"
1568 "void main() {\n"
1569 " outColor = inColor;\n"
1570 " vec4 vertices[3];"
1571 " vertices[gl_VertexID % 3] = pos;\n"
1572 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1573 "}\n";
1574
1575
1576 static const char *fragShaderText =
1577 "#version 140\n"
1578 "#extension GL_ARB_separate_shader_objects : enable\n"
1579 "#extension GL_ARB_shading_language_420pack : enable\n"
1580 "layout (location = 0) in vec4 color;\n"
1581 "void main() {\n"
1582 " gl_FragColor = color;\n"
1583 "}\n";
1584
1585 ASSERT_NO_FATAL_FAILURE(InitState());
1586 ASSERT_NO_FATAL_FAILURE(InitViewport());
1587
1588 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001589 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001590
1591 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1592 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1593
1594 XglPipelineObj pipelineobj(m_device);
1595 pipelineobj.AddShader(&vs);
1596 pipelineobj.AddShader(&ps);
1597
1598 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001599 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001600
Mark Lobodzinski15427102015-02-18 16:38:17 -06001601 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1602
Tony Barbourf43b6982014-11-25 13:18:32 -07001603 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1604 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1605 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1606 };
1607
1608 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1609 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001610 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001611 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1612 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001613 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001614 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1615
1616 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1617 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1618 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1619
Tony Barbourdd4c9642015-01-09 12:55:14 -07001620 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski15427102015-02-18 16:38:17 -06001621 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargetCount);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001622 XglCommandBufferObj cmdBuffer(m_device);
1623 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1624
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001625 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001626
1627 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1628
1629 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1630#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001631 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001632 pDSDumpDot((char*)"triTest2.dot");
1633#endif
1634 // render triangle
1635 cmdBuffer.Draw(0, 6, 0, 1);
1636
1637 // finalize recording of the command buffer
1638 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06001639 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001640
1641 for (int i = 0; i < m_renderTargetCount; i++)
1642 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001643}
1644
1645TEST_F(XglRenderTest, TriVertFetchDeadAttr)
1646{
1647 // This tests that attributes work in the presence of gl_VertexID
1648 // and a dead attribute in position 0. Draws a triangle with yellow,
1649 // red and green corners, starting at top and going clockwise.
1650
1651 static const char *vertShaderText =
1652 "#version 140\n"
1653 "#extension GL_ARB_separate_shader_objects : enable\n"
1654 "#extension GL_ARB_shading_language_420pack : enable\n"
1655 //XYZ1( -1, -1, -1 )
1656 "layout (location = 0) in vec4 pos;\n"
1657 //XYZ1( 0.f, 0.f, 0.f )
1658 "layout (location = 1) in vec4 inColor;\n"
1659 "layout (location = 0) out vec4 outColor;\n"
1660 "void main() {\n"
1661 " outColor = inColor;\n"
1662 " vec2 vertices[3];"
1663 " vertices[0] = vec2(-1.0, -1.0);\n"
1664 " vertices[1] = vec2( 1.0, -1.0);\n"
1665 " vertices[2] = vec2( 0.0, 1.0);\n"
1666 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1667 "}\n";
1668
1669
1670 static const char *fragShaderText =
1671 "#version 140\n"
1672 "#extension GL_ARB_separate_shader_objects : enable\n"
1673 "#extension GL_ARB_shading_language_420pack : enable\n"
1674 "layout (location = 0) in vec4 color;\n"
1675 "void main() {\n"
1676 " gl_FragColor = color;\n"
1677 "}\n";
1678
1679 ASSERT_NO_FATAL_FAILURE(InitState());
1680 ASSERT_NO_FATAL_FAILURE(InitViewport());
1681
1682 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001683 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001684
1685 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1686 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1687
1688 XglPipelineObj pipelineobj(m_device);
1689 pipelineobj.AddShader(&vs);
1690 pipelineobj.AddShader(&ps);
1691
1692 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001693 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001694
Mark Lobodzinski15427102015-02-18 16:38:17 -06001695 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1696
Tony Barbourf43b6982014-11-25 13:18:32 -07001697 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1698 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1699 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1700 };
1701
1702 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1703 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001704 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001705 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1706 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001707 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001708 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1709
1710 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1711 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1712 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1713
Tony Barbourdd4c9642015-01-09 12:55:14 -07001714 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski15427102015-02-18 16:38:17 -06001715 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargetCount);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001716 XglCommandBufferObj cmdBuffer(m_device);
1717 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001718
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001719 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001720
1721 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1722
1723 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1724#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001725 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001726 pDSDumpDot((char*)"triTest2.dot");
1727#endif
1728 // render triangle
1729 cmdBuffer.Draw(0, 6, 0, 1);
1730
1731 // finalize recording of the command buffer
1732 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06001733 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001734
1735 for (int i = 0; i < m_renderTargetCount; i++)
1736 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001737}
1738
1739TEST_F(XglRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001740{
1741 static const char *vertShaderText =
1742 "#version 140\n"
1743 "layout (std140) uniform bufferVals {\n"
1744 " mat4 mvp;\n"
1745 "} myBufferVals;\n"
1746 "in vec4 pos;\n"
1747 "in vec4 inColor;\n"
1748 "out vec4 outColor;\n"
1749 "void main() {\n"
1750 " outColor = inColor;\n"
1751 " gl_Position = myBufferVals.mvp * pos;\n"
1752 "}\n";
1753
1754 static const char *fragShaderText =
1755 "#version 130\n"
1756 "in vec4 color;\n"
1757 "void main() {\n"
1758 " gl_FragColor = color;\n"
1759 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001760 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001761
Tony Barbourf43b6982014-11-25 13:18:32 -07001762 glm::mat4 View = glm::lookAt(
1763 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1764 glm::vec3(0,0,0), // and looks at the origin
1765 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
1766 );
1767
1768 glm::mat4 Model = glm::mat4(1.0f);
1769
1770 glm::mat4 MVP = Projection * View * Model;
1771
1772 ASSERT_NO_FATAL_FAILURE(InitState());
1773 ASSERT_NO_FATAL_FAILURE(InitViewport());
1774 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
1775
1776 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
1777 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1778
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001779 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07001780
1781 XglConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1782 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1783 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1784
Tony Barbourf43b6982014-11-25 13:18:32 -07001785 XglPipelineObj pipelineobj(m_device);
1786 pipelineobj.AddShader(&vs);
1787 pipelineobj.AddShader(&ps);
1788
Tony Barbourfa6cac72015-01-16 14:27:35 -07001789 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
1790 ds_state.depthTestEnable = XGL_TRUE;
1791 ds_state.depthWriteEnable = XGL_TRUE;
1792 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
1793 ds_state.depthBoundsEnable = XGL_FALSE;
1794 ds_state.stencilTestEnable = XGL_FALSE;
1795 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
1796 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
1797 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
1798 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001799 ds_state.format = XGL_FMT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001800 ds_state.front = ds_state.back;
1801 pipelineobj.SetDepthStencil(&ds_state);
1802
Tony Barbourf43b6982014-11-25 13:18:32 -07001803 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001804 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001805
1806 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1807 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001808 m_memoryRefManager.AddMemoryRef(m_depthStencilMem, m_num_mem);
Tony Barbourf43b6982014-11-25 13:18:32 -07001809
1810 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1811 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1812 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1813 };
1814
1815 // this is the current description of g_vbData
1816 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1817 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001818 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001819 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1820 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001821 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001822 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1823
1824 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1825 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1826 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1827
Tony Barboure4ed9942015-01-09 10:06:53 -07001828 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski15427102015-02-18 16:38:17 -06001829 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargetCount);
Tony Barboure4ed9942015-01-09 10:06:53 -07001830 XglCommandBufferObj cmdBuffer(m_device);
1831 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001832
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001833 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -07001834 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001835
Tony Barboure4ed9942015-01-09 10:06:53 -07001836 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1837#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001838 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barboure4ed9942015-01-09 10:06:53 -07001839 pDSDumpDot((char*)"triTest2.dot");
1840#endif
1841 // render triangle
1842 cmdBuffer.Draw(0, 36, 0, 1);
1843
1844 // finalize recording of the command buffer
1845 cmdBuffer.EndCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001846 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barboure4ed9942015-01-09 10:06:53 -07001847
1848 for (int i = 0; i < m_renderTargetCount; i++)
1849 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001850}
1851
Tony Barbourf43b6982014-11-25 13:18:32 -07001852TEST_F(XglRenderTest, VSTexture)
1853{
1854 // The expected result from this test is a green and red triangle;
1855 // one red vertex on the left, two green vertices on the right.
1856 static const char *vertShaderText =
1857 "#version 130\n"
1858 "out vec4 texColor;\n"
1859 "uniform sampler2D surface;\n"
1860 "void main() {\n"
1861 " vec2 vertices[3];"
1862 " vertices[0] = vec2(-0.5, -0.5);\n"
1863 " vertices[1] = vec2( 0.5, -0.5);\n"
1864 " vertices[2] = vec2( 0.5, 0.5);\n"
1865 " vec2 positions[3];"
1866 " positions[0] = vec2( 0.0, 0.0);\n"
1867 " positions[1] = vec2( 0.25, 0.1);\n"
1868 " positions[2] = vec2( 0.1, 0.25);\n"
1869 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1870 " texColor = textureLod(surface, samplePos, 0.0);\n"
1871 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1872 "}\n";
1873
1874 static const char *fragShaderText =
1875 "#version 130\n"
1876 "in vec4 texColor;\n"
1877 "void main() {\n"
1878 " gl_FragColor = texColor;\n"
1879 "}\n";
1880
1881 ASSERT_NO_FATAL_FAILURE(InitState());
1882 ASSERT_NO_FATAL_FAILURE(InitViewport());
1883
1884 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1885 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1886 XglSamplerObj sampler(m_device);
1887 XglTextureObj texture(m_device);
1888
Tony Barbourf43b6982014-11-25 13:18:32 -07001889 XglPipelineObj pipelineobj(m_device);
1890 pipelineobj.AddShader(&vs);
1891 pipelineobj.AddShader(&ps);
1892
1893 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001894 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001895
1896 m_memoryRefManager.AddMemoryRef(&texture);
1897
Tony Barbourdd4c9642015-01-09 12:55:14 -07001898 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski15427102015-02-18 16:38:17 -06001899 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargetCount);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001900 XglCommandBufferObj cmdBuffer(m_device);
1901 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001902
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001903 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001904
1905 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1906
1907#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001908 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001909 pDSDumpDot((char*)"triTest2.dot");
1910#endif
1911 // render triangle
1912 cmdBuffer.Draw(0, 3, 0, 1);
1913
1914 // finalize recording of the command buffer
1915 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06001916 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001917
1918 for (int i = 0; i < m_renderTargetCount; i++)
1919 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001920}
1921TEST_F(XglRenderTest, TexturedTriangle)
1922{
1923 // The expected result from this test is a red and green checkered triangle
1924 static const char *vertShaderText =
1925 "#version 140\n"
1926 "#extension GL_ARB_separate_shader_objects : enable\n"
1927 "#extension GL_ARB_shading_language_420pack : enable\n"
1928 "layout (location = 0) out vec2 samplePos;\n"
1929 "void main() {\n"
1930 " vec2 vertices[3];"
1931 " vertices[0] = vec2(-0.5, -0.5);\n"
1932 " vertices[1] = vec2( 0.5, -0.5);\n"
1933 " vertices[2] = vec2( 0.5, 0.5);\n"
1934 " vec2 positions[3];"
1935 " positions[0] = vec2( 0.0, 0.0);\n"
1936 " positions[1] = vec2( 1.0, 0.0);\n"
1937 " positions[2] = vec2( 1.0, 1.0);\n"
1938 " samplePos = positions[gl_VertexID % 3];\n"
1939 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1940 "}\n";
1941
1942 static const char *fragShaderText =
1943 "#version 140\n"
1944 "#extension GL_ARB_separate_shader_objects : enable\n"
1945 "#extension GL_ARB_shading_language_420pack : enable\n"
1946 "layout (location = 0) in vec2 samplePos;\n"
1947 "layout (binding = 0) uniform sampler2D surface;\n"
1948 "layout (location=0) out vec4 outColor;\n"
1949 "void main() {\n"
1950 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1951 " outColor = texColor;\n"
1952 "}\n";
1953
1954 ASSERT_NO_FATAL_FAILURE(InitState());
1955 ASSERT_NO_FATAL_FAILURE(InitViewport());
1956
1957 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1958 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1959 XglSamplerObj sampler(m_device);
1960 XglTextureObj texture(m_device);
1961
Tony Barbourf43b6982014-11-25 13:18:32 -07001962 XglPipelineObj pipelineobj(m_device);
1963 pipelineobj.AddShader(&vs);
1964 pipelineobj.AddShader(&ps);
1965
1966 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001967 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001968
1969 m_memoryRefManager.AddMemoryRef(&texture);
1970
Tony Barbourdd4c9642015-01-09 12:55:14 -07001971 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski15427102015-02-18 16:38:17 -06001972 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargetCount);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001973 XglCommandBufferObj cmdBuffer(m_device);
1974 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1975
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001976 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001977
1978 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1979
1980#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001981 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001982 pDSDumpDot((char*)"triTest2.dot");
1983#endif
1984 // render triangle
1985 cmdBuffer.Draw(0, 3, 0, 1);
1986
1987 // finalize recording of the command buffer
1988 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06001989 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001990
1991 for (int i = 0; i < m_renderTargetCount; i++)
1992 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001993}
1994TEST_F(XglRenderTest, TexturedTriangleClip)
1995{
1996 // The expected result from this test is a red and green checkered triangle
1997 static const char *vertShaderText =
1998 "#version 330\n"
1999 "#extension GL_ARB_separate_shader_objects : enable\n"
2000 "#extension GL_ARB_shading_language_420pack : enable\n"
2001 "layout (location = 0) out vec2 samplePos;\n"
2002 "out gl_PerVertex {\n"
2003 " vec4 gl_Position;\n"
2004 " float gl_ClipDistance[1];\n"
2005 "};\n"
2006 "void main() {\n"
2007 " vec2 vertices[3];"
2008 " vertices[0] = vec2(-0.5, -0.5);\n"
2009 " vertices[1] = vec2( 0.5, -0.5);\n"
2010 " vertices[2] = vec2( 0.5, 0.5);\n"
2011 " vec2 positions[3];"
2012 " positions[0] = vec2( 0.0, 0.0);\n"
2013 " positions[1] = vec2( 1.0, 0.0);\n"
2014 " positions[2] = vec2( 1.0, 1.0);\n"
2015 " float dists[3];\n"
2016 " dists[0] = 1.0;\n"
2017 " dists[1] = 1.0;\n"
2018 " dists[2] = -1.0;\n"
2019 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2020 " samplePos = positions[gl_VertexID % 3];\n"
2021 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2022 "}\n";
2023
2024 static const char *fragShaderText =
2025 "#version 140\n"
2026 "#extension GL_ARB_separate_shader_objects : enable\n"
2027 "#extension GL_ARB_shading_language_420pack : enable\n"
2028 "layout (location = 0) in vec2 samplePos;\n"
2029 "layout (binding = 0) uniform sampler2D surface;\n"
2030 "layout (location=0) out vec4 outColor;\n"
2031 "void main() {\n"
2032 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2033 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2034 " outColor = texColor;\n"
2035 "}\n";
2036
2037
2038 ASSERT_NO_FATAL_FAILURE(InitState());
2039 ASSERT_NO_FATAL_FAILURE(InitViewport());
2040
2041 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2042 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2043 XglSamplerObj sampler(m_device);
2044 XglTextureObj texture(m_device);
2045
Tony Barbourf43b6982014-11-25 13:18:32 -07002046 XglPipelineObj pipelineobj(m_device);
2047 pipelineobj.AddShader(&vs);
2048 pipelineobj.AddShader(&ps);
2049
2050 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002051 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002052
2053 m_memoryRefManager.AddMemoryRef(&texture);
2054
Tony Barbourdd4c9642015-01-09 12:55:14 -07002055 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski15427102015-02-18 16:38:17 -06002056 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargetCount);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002057 XglCommandBufferObj cmdBuffer(m_device);
2058 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2059
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002060 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002061
2062 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2063
2064#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002065 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002066 pDSDumpDot((char*)"triTest2.dot");
2067#endif
2068 // render triangle
2069 cmdBuffer.Draw(0, 3, 0, 1);
2070
2071 // finalize recording of the command buffer
2072 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06002073 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002074
2075 for (int i = 0; i < m_renderTargetCount; i++)
2076 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002077}
2078TEST_F(XglRenderTest, FSTriangle)
2079{
2080 // The expected result from this test is a red and green checkered triangle
2081 static const char *vertShaderText =
2082 "#version 140\n"
2083 "#extension GL_ARB_separate_shader_objects : enable\n"
2084 "#extension GL_ARB_shading_language_420pack : enable\n"
2085 "layout (location = 0) out vec2 samplePos;\n"
2086 "void main() {\n"
2087 " vec2 vertices[3];"
2088 " vertices[0] = vec2(-0.5, -0.5);\n"
2089 " vertices[1] = vec2( 0.5, -0.5);\n"
2090 " vertices[2] = vec2( 0.5, 0.5);\n"
2091 " vec2 positions[3];"
2092 " positions[0] = vec2( 0.0, 0.0);\n"
2093 " positions[1] = vec2( 1.0, 0.0);\n"
2094 " positions[2] = vec2( 1.0, 1.0);\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);\n"
2108 " outColor = texColor;\n"
2109 "}\n";
2110
2111 ASSERT_NO_FATAL_FAILURE(InitState());
2112 ASSERT_NO_FATAL_FAILURE(InitViewport());
2113
2114 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2115 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2116 XglSamplerObj sampler(m_device);
2117 XglTextureObj texture(m_device);
2118
Tony Barbourf43b6982014-11-25 13:18:32 -07002119 XglPipelineObj pipelineobj(m_device);
2120 pipelineobj.AddShader(&vs);
2121 pipelineobj.AddShader(&ps);
2122
2123 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002124 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002125
2126 m_memoryRefManager.AddMemoryRef(&texture);
2127
Tony Barbourdd4c9642015-01-09 12:55:14 -07002128 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski15427102015-02-18 16:38:17 -06002129 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargetCount);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002130 XglCommandBufferObj cmdBuffer(m_device);
2131 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2132
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002133 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002134
2135 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2136
2137#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002138 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(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
2145 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06002146 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002147
2148 for (int i = 0; i < m_renderTargetCount; i++)
2149 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002150}
2151TEST_F(XglRenderTest, SamplerBindingsTriangle)
2152{
2153 // This test sets bindings on the samplers
2154 // For now we are asserting that sampler and texture pairs
2155 // march in lock step, and are set via GLSL binding. This can
2156 // and will probably change.
2157 // The sampler bindings should match the sampler and texture slot
2158 // number set up by the application.
2159 // This test will result in a blue triangle
2160 static const char *vertShaderText =
2161 "#version 140\n"
2162 "#extension GL_ARB_separate_shader_objects : enable\n"
2163 "#extension GL_ARB_shading_language_420pack : enable\n"
2164 "layout (location = 0) out vec4 samplePos;\n"
2165 "void main() {\n"
2166 " vec2 vertices[3];"
2167 " vertices[0] = vec2(-0.5, -0.5);\n"
2168 " vertices[1] = vec2( 0.5, -0.5);\n"
2169 " vertices[2] = vec2( 0.5, 0.5);\n"
2170 " vec2 positions[3];"
2171 " positions[0] = vec2( 0.0, 0.0);\n"
2172 " positions[1] = vec2( 1.0, 0.0);\n"
2173 " positions[2] = vec2( 1.0, 1.0);\n"
2174 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2175 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2176 "}\n";
2177
2178 static const char *fragShaderText =
2179 "#version 140\n"
2180 "#extension GL_ARB_separate_shader_objects : enable\n"
2181 "#extension GL_ARB_shading_language_420pack : enable\n"
2182 "layout (location = 0) in vec4 samplePos;\n"
2183 "layout (binding = 0) uniform sampler2D surface0;\n"
2184 "layout (binding = 1) uniform sampler2D surface1;\n"
2185 "layout (binding = 12) uniform sampler2D surface2;\n"
2186 "void main() {\n"
2187 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
2188 "}\n";
2189
2190 ASSERT_NO_FATAL_FAILURE(InitState());
2191 ASSERT_NO_FATAL_FAILURE(InitViewport());
2192
2193 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2194 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2195
2196 XglSamplerObj sampler1(m_device);
2197 XglSamplerObj sampler2(m_device);
2198 XglSamplerObj sampler3(m_device);
2199
Tony Barbour2f421a02015-04-01 16:38:10 -06002200 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
2201 XglTextureObj texture1(m_device, tex_colors); // Red
2202 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
2203 XglTextureObj texture2(m_device, tex_colors); // Green
2204 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
2205 XglTextureObj texture3(m_device, tex_colors); // Blue
Tony Barbourf43b6982014-11-25 13:18:32 -07002206
Tony Barbourf43b6982014-11-25 13:18:32 -07002207 XglPipelineObj pipelineobj(m_device);
2208 pipelineobj.AddShader(&vs);
2209 pipelineobj.AddShader(&ps);
2210
2211 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002212 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2213 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2214 for (int i = 0; i < 10; i++)
2215 descriptorSet.AppendDummy();
2216 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002217
2218 m_memoryRefManager.AddMemoryRef(&texture1);
2219 m_memoryRefManager.AddMemoryRef(&texture2);
2220 m_memoryRefManager.AddMemoryRef(&texture3);
2221
Tony Barbourdd4c9642015-01-09 12:55:14 -07002222 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski15427102015-02-18 16:38:17 -06002223 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargetCount);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002224 XglCommandBufferObj cmdBuffer(m_device);
2225 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2226
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002227 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002228
2229 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2230
2231#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002232 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002233 pDSDumpDot((char*)"triTest2.dot");
2234#endif
2235 // render triangle
2236 cmdBuffer.Draw(0, 3, 0, 1);
2237
2238 // finalize recording of the command buffer
2239 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06002240 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002241
2242 for (int i = 0; i < m_renderTargetCount; i++)
2243 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002244
2245}
2246
2247TEST_F(XglRenderTest, TriangleVSUniformBlock)
2248{
2249 // The expected result from this test is a blue triangle
2250
2251 static const char *vertShaderText =
2252 "#version 140\n"
2253 "#extension GL_ARB_separate_shader_objects : enable\n"
2254 "#extension GL_ARB_shading_language_420pack : enable\n"
2255 "layout (location = 0) out vec4 outColor;\n"
2256 "layout (std140, binding = 0) uniform bufferVals {\n"
2257 " vec4 red;\n"
2258 " vec4 green;\n"
2259 " vec4 blue;\n"
2260 " vec4 white;\n"
2261 "} myBufferVals;\n"
2262 "void main() {\n"
2263 " vec2 vertices[3];"
2264 " vertices[0] = vec2(-0.5, -0.5);\n"
2265 " vertices[1] = vec2( 0.5, -0.5);\n"
2266 " vertices[2] = vec2( 0.5, 0.5);\n"
2267 " outColor = myBufferVals.blue;\n"
2268 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2269 "}\n";
2270
2271 static const char *fragShaderText =
2272 "#version 140\n"
2273 "#extension GL_ARB_separate_shader_objects : enable\n"
2274 "#extension GL_ARB_shading_language_420pack : enable\n"
2275 "layout (location = 0) in vec4 inColor;\n"
2276 "void main() {\n"
2277 " gl_FragColor = inColor;\n"
2278 "}\n";
2279
2280 ASSERT_NO_FATAL_FAILURE(InitState());
2281 ASSERT_NO_FATAL_FAILURE(InitViewport());
2282
2283 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2284 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2285
2286 // Let's populate our buffer with the following:
2287 // vec4 red;
2288 // vec4 green;
2289 // vec4 blue;
2290 // vec4 white;
2291 const int valCount = 4 * 4;
2292 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2293 0.0, 1.0, 0.0, 1.0,
2294 0.0, 0.0, 1.0, 1.0,
2295 1.0, 1.0, 1.0, 1.0 };
2296
2297 XglConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002298
2299 XglPipelineObj pipelineobj(m_device);
2300 pipelineobj.AddShader(&vs);
2301 pipelineobj.AddShader(&ps);
2302
2303 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002304 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002305
Tony Barbourdd4c9642015-01-09 12:55:14 -07002306 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski15427102015-02-18 16:38:17 -06002307 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargetCount);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002308 XglCommandBufferObj cmdBuffer(m_device);
2309 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2310
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002311 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002312
2313 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2314
2315#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002316 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002317 pDSDumpDot((char*)"triTest2.dot");
2318#endif
2319 // render triangle
2320 cmdBuffer.Draw(0, 3, 0, 1);
2321
2322 // finalize recording of the command buffer
2323 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06002324 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002325
2326 for (int i = 0; i < m_renderTargetCount; i++)
2327 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002328
2329}
2330
2331TEST_F(XglRenderTest, TriangleFSUniformBlockBinding)
2332{
2333 // This test allows the shader to select which buffer it is
2334 // pulling from using layout binding qualifier.
2335 // There are corresponding changes in the compiler stack that
2336 // will select the buffer using binding directly.
2337 // The binding number should match the slot number set up by
2338 // the application.
2339 // The expected result from this test is a purple triangle
2340
2341 static const char *vertShaderText =
2342 "#version 140\n"
2343 "#extension GL_ARB_separate_shader_objects : enable\n"
2344 "#extension GL_ARB_shading_language_420pack : enable\n"
2345 "void main() {\n"
2346 " vec2 vertices[3];"
2347 " vertices[0] = vec2(-0.5, -0.5);\n"
2348 " vertices[1] = vec2( 0.5, -0.5);\n"
2349 " vertices[2] = vec2( 0.5, 0.5);\n"
2350 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2351 "}\n";
2352
2353 static const char *fragShaderText =
2354 "#version 140\n"
2355 "#extension GL_ARB_separate_shader_objects : enable\n"
2356 "#extension GL_ARB_shading_language_420pack : enable\n"
2357 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2358 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2359 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002360 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
Tony Barbourf43b6982014-11-25 13:18:32 -07002361 "void main() {\n"
2362 " gl_FragColor = myBlueVal.color;\n"
2363 " gl_FragColor += myRedVal.color;\n"
2364 "}\n";
2365
2366 ASSERT_NO_FATAL_FAILURE(InitState());
2367 ASSERT_NO_FATAL_FAILURE(InitViewport());
2368
2369 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2370 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2371
2372 // We're going to create a number of uniform buffers, and then allow
2373 // the shader to select which it wants to read from with a binding
2374
2375 // Let's populate the buffers with a single color each:
2376 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2377 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2378 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002379 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002380
2381 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2382 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2383 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2384 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2385
2386 const int redCount = sizeof(redVals) / sizeof(float);
2387 const int greenCount = sizeof(greenVals) / sizeof(float);
2388 const int blueCount = sizeof(blueVals) / sizeof(float);
2389 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2390
2391 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002392
2393 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002394
2395 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002396
2397 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002398
2399 XglPipelineObj pipelineobj(m_device);
2400 pipelineobj.AddShader(&vs);
2401 pipelineobj.AddShader(&ps);
2402
2403 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002404 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2405 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2406 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2407 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002408
Tony Barbourdd4c9642015-01-09 12:55:14 -07002409 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski15427102015-02-18 16:38:17 -06002410 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargetCount);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002411 XglCommandBufferObj cmdBuffer(m_device);
2412 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002413
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002414 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002415
2416 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2417
2418#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002419 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002420 pDSDumpDot((char*)"triTest2.dot");
2421#endif
2422 // render triangle
2423 cmdBuffer.Draw(0, 3, 0, 1);
2424
2425 // finalize recording of the command buffer
2426 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06002427 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002428
2429 for (int i = 0; i < m_renderTargetCount; i++)
2430 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002431}
2432
2433TEST_F(XglRenderTest, TriangleFSAnonymousUniformBlockBinding)
2434{
2435 // This test is the same as TriangleFSUniformBlockBinding, but
2436 // it does not provide an instance name.
2437 // The expected result from this test is a purple triangle
2438
2439 static const char *vertShaderText =
2440 "#version 140\n"
2441 "#extension GL_ARB_separate_shader_objects : enable\n"
2442 "#extension GL_ARB_shading_language_420pack : enable\n"
2443 "void main() {\n"
2444 " vec2 vertices[3];"
2445 " vertices[0] = vec2(-0.5, -0.5);\n"
2446 " vertices[1] = vec2( 0.5, -0.5);\n"
2447 " vertices[2] = vec2( 0.5, 0.5);\n"
2448 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2449 "}\n";
2450
2451 static const char *fragShaderText =
2452 "#version 430\n"
2453 "#extension GL_ARB_separate_shader_objects : enable\n"
2454 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002455 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2456 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2457 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002458 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002459 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002460 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002461 " outColor = blue;\n"
2462 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002463 "}\n";
2464 ASSERT_NO_FATAL_FAILURE(InitState());
2465 ASSERT_NO_FATAL_FAILURE(InitViewport());
2466
2467 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2468 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2469
2470 // We're going to create a number of uniform buffers, and then allow
2471 // the shader to select which it wants to read from with a binding
2472
2473 // Let's populate the buffers with a single color each:
2474 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2475 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2476 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2477 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2478
2479 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2480 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2481 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2482 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2483
2484 const int redCount = sizeof(redVals) / sizeof(float);
2485 const int greenCount = sizeof(greenVals) / sizeof(float);
2486 const int blueCount = sizeof(blueVals) / sizeof(float);
2487 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2488
2489 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002490
2491 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002492
2493 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002494
2495 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002496
2497 XglPipelineObj pipelineobj(m_device);
2498 pipelineobj.AddShader(&vs);
2499 pipelineobj.AddShader(&ps);
2500
2501 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002502 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2503 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2504 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2505 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002506
Tony Barbourdd4c9642015-01-09 12:55:14 -07002507 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski15427102015-02-18 16:38:17 -06002508 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargetCount);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002509 XglCommandBufferObj cmdBuffer(m_device);
2510 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2511
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002512 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002513
2514 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2515
2516#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002517 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002518 pDSDumpDot((char*)"triTest2.dot");
2519#endif
2520 // render triangle
2521 cmdBuffer.Draw(0, 3, 0, 1);
2522
2523 // finalize recording of the command buffer
2524 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06002525 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002526
2527 for (int i = 0; i < m_renderTargetCount; i++)
2528 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002529
2530}
2531
2532TEST_F(XglRenderTest, CubeWithVertexFetchAndMVPAndTexture)
2533{
2534 static const char *vertShaderText =
2535 "#version 140\n"
2536 "#extension GL_ARB_separate_shader_objects : enable\n"
2537 "#extension GL_ARB_shading_language_420pack : enable\n"
2538 "layout (std140, binding=0) uniform bufferVals {\n"
2539 " mat4 mvp;\n"
2540 "} myBufferVals;\n"
2541 "layout (location=0) in vec4 pos;\n"
2542 "layout (location=0) out vec2 UV;\n"
2543 "void main() {\n"
2544 " vec2 positions[3];"
2545 " positions[0] = vec2( 0.0, 0.0);\n"
2546 " positions[1] = vec2( 0.25, 0.1);\n"
2547 " positions[2] = vec2( 0.1, 0.25);\n"
2548 " UV = positions[gl_VertexID % 3];\n"
2549 " gl_Position = myBufferVals.mvp * pos;\n"
2550 "}\n";
2551
2552 static const char *fragShaderText =
2553 "#version 140\n"
2554 "#extension GL_ARB_separate_shader_objects : enable\n"
2555 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002556 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002557 "layout (location=0) out vec4 outColor;\n"
2558 "layout (location=0) in vec2 UV;\n"
2559 "void main() {\n"
2560 " outColor= textureLod(surface, UV, 0.0);\n"
2561 "}\n";
2562 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2563
2564 glm::mat4 View = glm::lookAt(
2565 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2566 glm::vec3(0,0,0), // and looks at the origin
2567 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2568 );
2569
2570 glm::mat4 Model = glm::mat4(1.0f);
2571
2572 glm::mat4 MVP = Projection * View * Model;
2573
2574
2575 ASSERT_NO_FATAL_FAILURE(InitState());
2576 ASSERT_NO_FATAL_FAILURE(InitViewport());
2577 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
2578
2579 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
2580 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002581 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002582
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002583 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07002584
2585 XglConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2586 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2587 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2588 XglSamplerObj sampler(m_device);
2589 XglTextureObj texture(m_device);
2590
Tony Barbourf43b6982014-11-25 13:18:32 -07002591 XglPipelineObj pipelineobj(m_device);
2592 pipelineobj.AddShader(&vs);
2593 pipelineobj.AddShader(&ps);
2594
2595 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06002596 // descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer); // TODO: Why does this break images??
Chia-I Wuf8385062015-01-04 16:27:24 +08002597 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mvpBuffer);
2598 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002599
2600 m_memoryRefManager.AddMemoryRef(&meshBuffer);
2601 m_memoryRefManager.AddMemoryRef(&mvpBuffer);
2602 m_memoryRefManager.AddMemoryRef(&texture);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002603 m_memoryRefManager.AddMemoryRef(m_depthStencilMem, m_num_mem);
Tony Barbourf43b6982014-11-25 13:18:32 -07002604
2605 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
2606 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
2607 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
2608 };
2609
2610 // this is the current description of g_vbData
2611 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
2612 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07002613 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07002614 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2615 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07002616 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07002617 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
2618
2619 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2620 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
2621 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
2622
Tony Barbourfa6cac72015-01-16 14:27:35 -07002623 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
2624 ds_state.depthTestEnable = XGL_TRUE;
2625 ds_state.depthWriteEnable = XGL_TRUE;
2626 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
2627 ds_state.depthBoundsEnable = XGL_FALSE;
2628 ds_state.stencilTestEnable = XGL_FALSE;
2629 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
2630 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
2631 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
2632 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07002633 ds_state.format = XGL_FMT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002634 ds_state.front = ds_state.back;
2635 pipelineobj.SetDepthStencil(&ds_state);
2636
Tony Barbourdd4c9642015-01-09 12:55:14 -07002637 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski15427102015-02-18 16:38:17 -06002638 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargetCount);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002639 XglCommandBufferObj cmdBuffer(m_device);
2640 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002641
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002642 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002643 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2644
2645 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2646#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002647 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002648 pDSDumpDot((char*)"triTest2.dot");
2649#endif
2650 // render triangle
2651 cmdBuffer.Draw(0, 36, 0, 1);
2652
2653 // finalize recording of the command buffer
2654 cmdBuffer.EndCommandBuffer();
2655 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
2656
2657 for (int i = 0; i < m_renderTargetCount; i++)
2658 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002659
2660}
Cody Northropd1ce7842014-12-09 11:17:01 -07002661
2662TEST_F(XglRenderTest, TriangleMixedSamplerUniformBlockBinding)
2663{
2664 // This test mixes binding slots of textures and buffers, ensuring
2665 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002666 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002667 // you can modify it to move the desired result around.
2668
2669 static const char *vertShaderText =
2670 "#version 140\n"
2671 "#extension GL_ARB_separate_shader_objects : enable\n"
2672 "#extension GL_ARB_shading_language_420pack : enable\n"
2673 "void main() {\n"
2674 " vec2 vertices[3];"
2675 " vertices[0] = vec2(-0.5, -0.5);\n"
2676 " vertices[1] = vec2( 0.5, -0.5);\n"
2677 " vertices[2] = vec2( 0.5, 0.5);\n"
2678 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2679 "}\n";
2680
2681 static const char *fragShaderText =
2682 "#version 430\n"
2683 "#extension GL_ARB_separate_shader_objects : enable\n"
2684 "#extension GL_ARB_shading_language_420pack : enable\n"
2685 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002686 "layout (binding = 3) uniform sampler2D surface1;\n"
2687 "layout (binding = 1) uniform sampler2D surface2;\n"
2688 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002689
Cody Northropa0410942014-12-09 13:59:39 -07002690
Chia-I Wuf8385062015-01-04 16:27:24 +08002691 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2692 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2693 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2694 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002695 "layout (location = 0) out vec4 outColor;\n"
2696 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002697 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002698 " outColor += white * vec4(0.00001);\n"
2699 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002700 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002701 "}\n";
2702 ASSERT_NO_FATAL_FAILURE(InitState());
2703 ASSERT_NO_FATAL_FAILURE(InitViewport());
2704
2705 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2706 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2707
Cody Northropd1ce7842014-12-09 11:17:01 -07002708 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2709 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2710 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2711 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2712
2713 const int redCount = sizeof(redVals) / sizeof(float);
2714 const int greenCount = sizeof(greenVals) / sizeof(float);
2715 const int blueCount = sizeof(blueVals) / sizeof(float);
2716 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2717
2718 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002719 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002720 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002721 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002722
Tony Barbour2f421a02015-04-01 16:38:10 -06002723 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Cody Northropd1ce7842014-12-09 11:17:01 -07002724 XglSamplerObj sampler0(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002725 XglTextureObj texture0(m_device, tex_colors); // Light Red
2726 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Cody Northropd1ce7842014-12-09 11:17:01 -07002727 XglSamplerObj sampler2(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002728 XglTextureObj texture2(m_device, tex_colors); // Light Blue
2729 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Cody Northropd1ce7842014-12-09 11:17:01 -07002730 XglSamplerObj sampler4(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002731 XglTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropa0410942014-12-09 13:59:39 -07002732
2733 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2734 // TODO: Get back here ASAP and understand why.
Tony Barbour2f421a02015-04-01 16:38:10 -06002735 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Cody Northropa0410942014-12-09 13:59:39 -07002736 XglSamplerObj sampler7(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002737 XglTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropd1ce7842014-12-09 11:17:01 -07002738
2739 XglPipelineObj pipelineobj(m_device);
2740 pipelineobj.AddShader(&vs);
2741 pipelineobj.AddShader(&ps);
2742
2743 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002744 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2745 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2746 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2747 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2748 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2749 // swap blue and green
2750 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2751 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2752 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002753
2754 m_memoryRefManager.AddMemoryRef(&texture0);
2755 m_memoryRefManager.AddMemoryRef(&texture2);
2756 m_memoryRefManager.AddMemoryRef(&texture4);
Cody Northropa0410942014-12-09 13:59:39 -07002757 m_memoryRefManager.AddMemoryRef(&texture7);
Cody Northropd1ce7842014-12-09 11:17:01 -07002758
Tony Barbourdd4c9642015-01-09 12:55:14 -07002759 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski15427102015-02-18 16:38:17 -06002760 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargetCount);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002761 XglCommandBufferObj cmdBuffer(m_device);
2762 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002763
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002764 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002765
2766 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2767
2768#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002769 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002770 pDSDumpDot((char*)"triTest2.dot");
2771#endif
2772 // render triangle
2773 cmdBuffer.Draw(0, 3, 0, 1);
2774
2775 // finalize recording of the command buffer
2776 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06002777 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002778
2779 for (int i = 0; i < m_renderTargetCount; i++)
2780 RecordImage(m_renderTargets[i]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002781
2782}
2783
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002784TEST_F(XglRenderTest, TriangleMatchingSamplerUniformBlockBinding)
2785{
2786 // This test matches binding slots of textures and buffers, requiring
2787 // the driver to give them distinct number spaces.
2788 // The expected result from this test is a red triangle, although
2789 // you can modify it to move the desired result around.
2790
2791 static const char *vertShaderText =
2792 "#version 140\n"
2793 "#extension GL_ARB_separate_shader_objects : enable\n"
2794 "#extension GL_ARB_shading_language_420pack : enable\n"
2795 "void main() {\n"
2796 " vec2 vertices[3];"
2797 " vertices[0] = vec2(-0.5, -0.5);\n"
2798 " vertices[1] = vec2( 0.5, -0.5);\n"
2799 " vertices[2] = vec2( 0.5, 0.5);\n"
2800 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2801 "}\n";
2802
2803 static const char *fragShaderText =
2804 "#version 430\n"
2805 "#extension GL_ARB_separate_shader_objects : enable\n"
2806 "#extension GL_ARB_shading_language_420pack : enable\n"
2807 "layout (binding = 0) uniform sampler2D surface0;\n"
2808 "layout (binding = 1) uniform sampler2D surface1;\n"
2809 "layout (binding = 2) uniform sampler2D surface2;\n"
2810 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002811 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2812 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2813 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2814 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002815 "layout (location = 0) out vec4 outColor;\n"
2816 "void main() {\n"
2817 " outColor = red;// * vec4(0.00001);\n"
2818 " outColor += white * vec4(0.00001);\n"
2819 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2820 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2821 "}\n";
2822 ASSERT_NO_FATAL_FAILURE(InitState());
2823 ASSERT_NO_FATAL_FAILURE(InitViewport());
2824
2825 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2826 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2827
2828 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2829 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2830 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2831 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2832
2833 const int redCount = sizeof(redVals) / sizeof(float);
2834 const int greenCount = sizeof(greenVals) / sizeof(float);
2835 const int blueCount = sizeof(blueVals) / sizeof(float);
2836 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2837
2838 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002839 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002840 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002841 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002842
Tony Barbour2f421a02015-04-01 16:38:10 -06002843 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002844 XglSamplerObj sampler0(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002845 XglTextureObj texture0(m_device, tex_colors); // Light Red
2846 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002847 XglSamplerObj sampler2(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002848 XglTextureObj texture2(m_device, tex_colors); // Light Blue
2849 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002850 XglSamplerObj sampler4(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002851 XglTextureObj texture4(m_device, tex_colors); // Light Green
2852 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002853 XglSamplerObj sampler7(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002854 XglTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002855
2856 XglPipelineObj pipelineobj(m_device);
2857 pipelineobj.AddShader(&vs);
2858 pipelineobj.AddShader(&ps);
2859
2860 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002861 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2862 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2863 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2864 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2865 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2866 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2867 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2868 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002869
2870 m_memoryRefManager.AddMemoryRef(&texture0);
2871 m_memoryRefManager.AddMemoryRef(&texture2);
2872 m_memoryRefManager.AddMemoryRef(&texture4);
2873 m_memoryRefManager.AddMemoryRef(&texture7);
2874
Tony Barbourdd4c9642015-01-09 12:55:14 -07002875 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski15427102015-02-18 16:38:17 -06002876 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargetCount);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002877 XglCommandBufferObj cmdBuffer(m_device);
2878 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002879
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002880 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002881
2882 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2883
2884#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002885 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002886 pDSDumpDot((char*)"triTest2.dot");
2887#endif
2888 // render triangle
2889 cmdBuffer.Draw(0, 3, 0, 1);
2890
2891 // finalize recording of the command buffer
2892 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06002893 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002894
2895 for (int i = 0; i < m_renderTargetCount; i++)
2896 RecordImage(m_renderTargets[i]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002897
2898}
2899
Cody Northrop02690bd2014-12-17 15:26:33 -07002900TEST_F(XglRenderTest, TriangleUniformBufferLayout)
2901{
2902 // This test populates a buffer with a variety of different data
2903 // types, then reads them out with a shader.
2904 // The expected result from this test is a green triangle
2905
2906 static const char *vertShaderText =
2907 "#version 140\n"
2908 "#extension GL_ARB_separate_shader_objects : enable\n"
2909 "#extension GL_ARB_shading_language_420pack : enable\n"
2910 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2911 " vec4 fRed;\n"
2912 " vec4 fGreen;\n"
2913 " layout(row_major) mat4 worldToProj;\n"
2914 " layout(row_major) mat4 projToWorld;\n"
2915 " layout(row_major) mat4 worldToView;\n"
2916 " layout(row_major) mat4 viewToProj;\n"
2917 " layout(row_major) mat4 worldToShadow[4];\n"
2918 " float fZero;\n"
2919 " float fOne;\n"
2920 " float fTwo;\n"
2921 " float fThree;\n"
2922 " vec3 fZeroZeroZero;\n"
2923 " float fFour;\n"
2924 " vec3 fZeroZeroOne;\n"
2925 " float fFive;\n"
2926 " vec3 fZeroOneZero;\n"
2927 " float fSix;\n"
2928 " float fSeven;\n"
2929 " float fEight;\n"
2930 " float fNine;\n"
2931 " vec2 fZeroZero;\n"
2932 " vec2 fZeroOne;\n"
2933 " vec4 fBlue;\n"
2934 " vec2 fOneZero;\n"
2935 " vec2 fOneOne;\n"
2936 " vec3 fZeroOneOne;\n"
2937 " float fTen;\n"
2938 " float fEleven;\n"
2939 " float fTwelve;\n"
2940 " vec3 fOneZeroZero;\n"
2941 " vec4 uvOffsets[4];\n"
2942 "};\n"
2943 "layout (location = 0) out vec4 color;"
2944 "void main() {\n"
2945
2946 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2947 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2948 " \n"
2949
2950 // do some exact comparisons, even though we should
2951 // really have an epsilon involved.
2952 " vec4 outColor = right;\n"
2953 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
2954 " outColor = wrong;\n"
2955 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
2956 " outColor = wrong;\n"
2957 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
2958 " outColor = wrong;\n"
2959
2960 " color = outColor;\n"
2961
2962 // generic position stuff
2963 " vec2 vertices;\n"
2964 " int vertexSelector = gl_VertexID;\n"
2965 " if (vertexSelector == 0)\n"
2966 " vertices = vec2(-0.5, -0.5);\n"
2967 " else if (vertexSelector == 1)\n"
2968 " vertices = vec2( 0.5, -0.5);\n"
2969 " else if (vertexSelector == 2)\n"
2970 " vertices = vec2( 0.5, 0.5);\n"
2971 " else\n"
2972 " vertices = vec2( 0.0, 0.0);\n"
2973 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
2974 "}\n";
2975
2976 static const char *fragShaderText =
2977 "#version 140\n"
2978 "#extension GL_ARB_separate_shader_objects : enable\n"
2979 "#extension GL_ARB_shading_language_420pack : enable\n"
2980 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2981 " vec4 fRed;\n"
2982 " vec4 fGreen;\n"
2983 " layout(row_major) mat4 worldToProj;\n"
2984 " layout(row_major) mat4 projToWorld;\n"
2985 " layout(row_major) mat4 worldToView;\n"
2986 " layout(row_major) mat4 viewToProj;\n"
2987 " layout(row_major) mat4 worldToShadow[4];\n"
2988 " float fZero;\n"
2989 " float fOne;\n"
2990 " float fTwo;\n"
2991 " float fThree;\n"
2992 " vec3 fZeroZeroZero;\n"
2993 " float fFour;\n"
2994 " vec3 fZeroZeroOne;\n"
2995 " float fFive;\n"
2996 " vec3 fZeroOneZero;\n"
2997 " float fSix;\n"
2998 " float fSeven;\n"
2999 " float fEight;\n"
3000 " float fNine;\n"
3001 " vec2 fZeroZero;\n"
3002 " vec2 fZeroOne;\n"
3003 " vec4 fBlue;\n"
3004 " vec2 fOneZero;\n"
3005 " vec2 fOneOne;\n"
3006 " vec3 fZeroOneOne;\n"
3007 " float fTen;\n"
3008 " float fEleven;\n"
3009 " float fTwelve;\n"
3010 " vec3 fOneZeroZero;\n"
3011 " vec4 uvOffsets[4];\n"
3012 "};\n"
3013 "layout (location = 0) in vec4 color;\n"
3014 "void main() {\n"
3015 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3016 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3017 " \n"
3018
3019 // start with VS value to ensure it passed
3020 " vec4 outColor = color;\n"
3021
3022 // do some exact comparisons, even though we should
3023 // really have an epsilon involved.
3024 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3025 " outColor = wrong;\n"
3026 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3027 " outColor = wrong;\n"
3028 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3029 " outColor = wrong;\n"
3030 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3031 " outColor = wrong;\n"
3032 " if (fTwo != 2.0)\n"
3033 " outColor = wrong;\n"
3034 " if (fOneOne != vec2(1.0, 1.0))\n"
3035 " outColor = wrong;\n"
3036 " if (fTen != 10.0)\n"
3037 " outColor = wrong;\n"
3038 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3039 " outColor = wrong;\n"
3040 " \n"
3041 " gl_FragColor = outColor;\n"
3042 "}\n";
3043
3044
3045 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3046 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3047 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3048 0.0, 1.0, 0.0, 1.0, // align
3049 0.0, 0.0, 1.0, 1.0, // align
3050 0.0, 0.0, 0.0, 1.0, // align
3051 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3052 0.0, 2.0, 0.0, 2.0, // align
3053 0.0, 0.0, 2.0, 2.0, // align
3054 0.0, 0.0, 0.0, 2.0, // align
3055 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3056 0.0, 3.0, 0.0, 3.0, // align
3057 0.0, 0.0, 3.0, 3.0, // align
3058 0.0, 0.0, 0.0, 3.0, // align
3059 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3060 0.0, 4.0, 0.0, 4.0, // align
3061 0.0, 0.0, 4.0, 4.0, // align
3062 0.0, 0.0, 0.0, 4.0, // align
3063 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3064 0.0, 5.0, 0.0, 5.0, // align
3065 0.0, 0.0, 5.0, 5.0, // align
3066 0.0, 0.0, 0.0, 5.0, // align
3067 6.0, 0.0, 0.0, 6.0, // align
3068 0.0, 6.0, 0.0, 6.0, // align
3069 0.0, 0.0, 6.0, 6.0, // align
3070 0.0, 0.0, 0.0, 6.0, // align
3071 7.0, 0.0, 0.0, 7.0, // align
3072 0.0, 7.0, 0.0, 7.0, // align
3073 0.0, 0.0, 7.0, 7.0, // align
3074 0.0, 0.0, 0.0, 7.0, // align
3075 8.0, 0.0, 0.0, 8.0, // align
3076 0.0, 8.0, 0.0, 8.0, // align
3077 0.0, 0.0, 8.0, 8.0, // align
3078 0.0, 0.0, 0.0, 8.0, // align
3079 0.0, // float fZero; // align
3080 1.0, // float fOne; // pack
3081 2.0, // float fTwo; // pack
3082 3.0, // float fThree; // pack
3083 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3084 4.0, // float fFour; // pack
3085 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3086 5.0, // float fFive; // pack
3087 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3088 6.0, // float fSix; // pack
3089 7.0, // float fSeven; // align
3090 8.0, // float fEight; // pack
3091 9.0, // float fNine; // pack
3092 0.0, // BUFFER
3093 0.0, 0.0, // vec2 fZeroZero; // align
3094 0.0, 1.0, // vec2 fZeroOne; // pack
3095 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3096 1.0, 0.0, // vec2 fOneZero; // align
3097 1.0, 1.0, // vec2 fOneOne; // pack
3098 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3099 10.0, // float fTen; // pack
3100 11.0, // float fEleven; // align
3101 12.0, // float fTwelve; // pack
3102 0.0, 0.0, // BUFFER
3103 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3104 0.0, // BUFFER
3105 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3106 0.5, 0.6, 0.7, 0.8, // align
3107 0.9, 1.0, 1.1, 1.2, // align
3108 1.3, 1.4, 1.5, 1.6, // align
3109 };
3110
3111 ASSERT_NO_FATAL_FAILURE(InitState());
3112 ASSERT_NO_FATAL_FAILURE(InitViewport());
3113
3114 const int constCount = sizeof(mixedVals) / sizeof(float);
3115
3116 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
3117 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
3118
3119 XglConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003120
3121 XglPipelineObj pipelineobj(m_device);
3122 pipelineobj.AddShader(&vs);
3123 pipelineobj.AddShader(&ps);
3124
3125 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08003126 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003127
3128 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski15427102015-02-18 16:38:17 -06003129 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargetCount);
Cody Northrop02690bd2014-12-17 15:26:33 -07003130 XglCommandBufferObj cmdBuffer(m_device);
3131 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3132
Jeremy Hayese0c3b222015-01-14 16:17:08 -07003133 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Cody Northrop02690bd2014-12-17 15:26:33 -07003134
3135 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
3136
3137#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003138 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop02690bd2014-12-17 15:26:33 -07003139 pDSDumpDot((char*)"triTest2.dot");
3140#endif
3141 // render triangle
3142 cmdBuffer.Draw(0, 3, 0, 1);
3143
3144 // finalize recording of the command buffer
3145 cmdBuffer.EndCommandBuffer();
Mark Lobodzinski15427102015-02-18 16:38:17 -06003146 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Cody Northrop02690bd2014-12-17 15:26:33 -07003147
3148 for (int i = 0; i < m_renderTargetCount; i++)
3149 RecordImage(m_renderTargets[i]);
3150}
3151
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003152int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003153 int result;
3154
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003155 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003156 XglTestFramework::InitArgs(&argc, argv);
3157
Chia-I Wu7133fdc2014-12-15 23:57:34 +08003158 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06003159
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003160 result = RUN_ALL_TESTS();
3161
3162 XglTestFramework::Finish();
3163 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003164}