blob: ffaaa7ba4c4a503905ebc743da03764654744994 [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
Chia-I Wu4115c892014-08-28 11:56:29 +080075#include "icd-bil.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
83XGL_VOID XGLAPI myDbgFunc(
84 XGL_DBG_MSG_TYPE msgType,
85 XGL_VALIDATION_LEVEL validationLevel,
86 XGL_BASE_OBJECT srcObject,
87 XGL_SIZE location,
88 XGL_INT msgCode,
89 const XGL_CHAR* pMsg,
90 XGL_VOID* pUserData)
91{
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{
116 XGL_FLOAT posX, posY, posZ, posW; // Position data
117 XGL_FLOAT r, g, b, a; // Color
118};
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;
233 XGL_GPU_MEMORY m_depthStencilMem;
234 XGL_DEPTH_STENCIL_VIEW m_depthStencilView;
Tony Barbourf43b6982014-11-25 13:18:32 -0700235 XglMemoryRefManager m_memoryRefManager;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600236
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600237
238 virtual void SetUp() {
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600239
240 this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO;
241 this->app_info.pNext = NULL;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800242 this->app_info.pAppName = "render_tests";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600243 this->app_info.appVersion = 1;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800244 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600245 this->app_info.engineVersion = 1;
246 this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0);
247
Cody Northrop350727b2014-10-06 15:42:00 -0600248 memset(&m_textureViewInfo, 0, sizeof(m_textureViewInfo));
249 m_textureViewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO;
Tony Barbour97a36232014-12-04 17:14:45 -0700250 memset(&m_depthStencilImage, 0, sizeof(m_depthStencilImage));
Cody Northrop350727b2014-10-06 15:42:00 -0600251
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600252 InitFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600253 }
254
255 virtual void TearDown() {
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600256 // Clean up resources before we reset
257 ShutdownFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600258 }
259};
260
Tony Barbour02472db2015-01-08 17:08:28 -0700261void XglRenderTest::GenericDrawPreparation(XglCommandBufferObj *cmdBuffer, XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet)
262{
263 cmdBuffer->ClearAllBuffers(&m_depthStencilBinding, m_depthStencilImage);
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700264 cmdBuffer->PrepareAttachments();
Tony Barbour02472db2015-01-08 17:08:28 -0700265 cmdBuffer->BindStateObject(XGL_STATE_BIND_RASTER, m_stateRaster);
266 cmdBuffer->BindStateObject(XGL_STATE_BIND_VIEWPORT, m_stateViewport);
267 cmdBuffer->BindStateObject(XGL_STATE_BIND_COLOR_BLEND, m_colorBlend);
268 cmdBuffer->BindStateObject(XGL_STATE_BIND_DEPTH_STENCIL, m_stateDepthStencil);
Chia-I Wuf8385062015-01-04 16:27:24 +0800269 descriptorSet->CreateXGLDescriptorSet(cmdBuffer);
Tony Barbour02472db2015-01-08 17:08:28 -0700270 pipelineobj->CreateXGLPipeline(descriptorSet);
271 cmdBuffer->BindPipeline(pipelineobj->GetPipelineHandle());
Tony Barbour02472db2015-01-08 17:08:28 -0700272 cmdBuffer->BindDescriptorSet(descriptorSet->GetDescriptorSetHandle());
273}
Tony Barbourf43b6982014-11-25 13:18:32 -0700274
Tony Barbourf43b6982014-11-25 13:18:32 -0700275void XglRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbourdd4c9642015-01-09 12:55:14 -0700276 XglConstantBufferObj *constantBuffer, XglCommandBufferObj *cmdBuffer)
277{
278 int i;
279 glm::mat4 MVP;
280 int matrixSize = sizeof(MVP);
281 XGL_RESULT err;
282
283 for (i = 0; i < 8; i++) {
284 void *pData = constantBuffer->map();
285
286 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
287 MVP = Projection * View * Model;
288 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
289
290 constantBuffer->unmap();
291
292 // submit the command buffer to the universal queue
293 cmdBuffer->QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
294
Tony Barbourdd4c9642015-01-09 12:55:14 -0700295 err = xglQueueWaitIdle( m_device->m_queue );
296 ASSERT_XGL_SUCCESS( err );
297
298 // Wait for work to finish before cleaning up.
299 xglDeviceWaitIdle(m_device->device());
300
301 assert(m_renderTargetCount == 1);
302 RecordImage(m_renderTargets[0]);
303 }
304}
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600305
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600306void dumpMatrix(const char *note, glm::mat4 MVP)
307{
Chia-I Wu7133fdc2014-12-15 23:57:34 +0800308 int i;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600309
310 printf("%s: \n", note);
311 for (i=0; i<4; i++) {
312 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
313 }
314 printf("\n");
315 fflush(stdout);
316}
317
318void dumpVec4(const char *note, glm::vec4 vector)
319{
320 printf("%s: \n", note);
321 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
322 printf("\n");
323 fflush(stdout);
324}
325
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600326void XglRenderTest::InitDepthStencil()
327{
328 XGL_RESULT err;
329 XGL_IMAGE_CREATE_INFO image;
330 XGL_MEMORY_ALLOC_INFO mem_alloc;
331 XGL_DEPTH_STENCIL_VIEW_CREATE_INFO view;
332 XGL_MEMORY_REQUIREMENTS mem_reqs;
Jon Ashburn6317c492014-11-21 11:33:20 -0700333 XGL_SIZE mem_reqs_size=sizeof(XGL_MEMORY_REQUIREMENTS);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600334
335 // Clean up default state created by framework
336 if (m_stateDepthStencil) xglDestroyObject(m_stateDepthStencil);
337
338 m_depth_stencil_fmt.channelFormat = XGL_CH_FMT_R16;
339 m_depth_stencil_fmt.numericFormat = XGL_NUM_FMT_DS;
340
341 image.sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
342 image.pNext = NULL;
343 image.imageType = XGL_IMAGE_2D;
344 image.format = m_depth_stencil_fmt;
345 image.extent.width = m_width;
346 image.extent.height = m_height;
347 image.extent.depth = 1;
348 image.mipLevels = 1;
349 image.arraySize = 1;
350 image.samples = 1;
351 image.tiling = XGL_OPTIMAL_TILING;
352 image.usage = XGL_IMAGE_USAGE_DEPTH_STENCIL_BIT;
353 image.flags = 0;
354
355 mem_alloc.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
356 mem_alloc.pNext = NULL;
357 mem_alloc.allocationSize = 0;
358 mem_alloc.alignment = 0;
359 mem_alloc.flags = 0;
360 mem_alloc.heapCount = 0;
361 mem_alloc.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
362
363 /* create image */
364 err = xglCreateImage(device(), &image,
365 &m_depthStencilImage);
366 ASSERT_XGL_SUCCESS(err);
367
368 err = xglGetObjectInfo(m_depthStencilImage,
369 XGL_INFO_TYPE_MEMORY_REQUIREMENTS,
370 &mem_reqs_size, &mem_reqs);
371 ASSERT_XGL_SUCCESS(err);
372 ASSERT_EQ(mem_reqs_size, sizeof(mem_reqs));
373
Tony Barbourfa6cac72015-01-16 14:27:35 -0700374 XGL_UINT heapInfo[mem_reqs.heapCount];
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600375 mem_alloc.allocationSize = mem_reqs.size;
376 mem_alloc.alignment = mem_reqs.alignment;
377 mem_alloc.heapCount = mem_reqs.heapCount;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700378 mem_alloc.pHeaps = heapInfo;
379 memcpy(heapInfo, mem_reqs.pHeaps,
380 sizeof(mem_reqs.pHeaps) * mem_reqs.heapCount);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600381
382 /* allocate memory */
383 err = xglAllocMemory(device(), &mem_alloc, &m_depthStencilMem);
384 ASSERT_XGL_SUCCESS(err);
385
386 /* bind memory */
387 err = xglBindObjectMemory(m_depthStencilImage, m_depthStencilMem, 0);
388 ASSERT_XGL_SUCCESS(err);
389
Tony Barbourfa6cac72015-01-16 14:27:35 -0700390 XGL_DYNAMIC_DS_STATE_CREATE_INFO depthStencil = {};
391 depthStencil.sType = XGL_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO;
392
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600393 depthStencil.minDepth = 0.f;
394 depthStencil.maxDepth = 1.f;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700395 depthStencil.stencilBackRef = 0;
396 depthStencil.stencilFrontRef = 0;
397 depthStencil.stencilReadMask = 0xff;
398 depthStencil.stencilWriteMask = 0xff;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600399
Tony Barbourfa6cac72015-01-16 14:27:35 -0700400 err = xglCreateDynamicDepthStencilState( device(), &depthStencil, &m_stateDepthStencil );
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600401 ASSERT_XGL_SUCCESS( err );
402
403 /* create image view */
404 view.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO;
405 view.pNext = NULL;
406 view.image = XGL_NULL_HANDLE;
407 view.mipLevel = 0;
408 view.baseArraySlice = 0;
409 view.arraySize = 1;
410 view.flags = 0;
411 view.image = m_depthStencilImage;
412 err = xglCreateDepthStencilView(device(), &view, &m_depthStencilView);
413 ASSERT_XGL_SUCCESS(err);
414
415 m_depthStencilBinding.view = m_depthStencilView;
Mike Stroyan55658c22014-12-04 11:08:39 +0000416 m_depthStencilBinding.layout = XGL_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600417}
418
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600419struct xgltriangle_vs_uniform {
420 // Must start with MVP
421 XGL_FLOAT mvp[4][4];
422 XGL_FLOAT position[3][4];
423 XGL_FLOAT color[3][4];
424};
425
Tony Barbourae442072015-01-12 13:27:11 -0700426void XglRenderTest::XGLTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600427{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700428#ifdef DEBUG_CALLBACK
429 xglDbgRegisterMsgCallback(myDbgFunc, NULL);
430#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600431 // Create identity matrix
432 int i;
433 struct xgltriangle_vs_uniform data;
434
435 glm::mat4 Projection = glm::mat4(1.0f);
436 glm::mat4 View = glm::mat4(1.0f);
437 glm::mat4 Model = glm::mat4(1.0f);
438 glm::mat4 MVP = Projection * View * Model;
439 const int matrixSize = sizeof(MVP);
440 const int bufSize = sizeof(xgltriangle_vs_uniform) / sizeof(XGL_FLOAT);
441 memcpy(&data.mvp, &MVP[0][0], matrixSize);
442
443 static const Vertex tri_data[] =
444 {
445 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
446 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
447 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
448 };
449
450 for (i=0; i<3; i++) {
451 data.position[i][0] = tri_data[i].posX;
452 data.position[i][1] = tri_data[i].posY;
453 data.position[i][2] = tri_data[i].posZ;
454 data.position[i][3] = tri_data[i].posW;
455 data.color[i][0] = tri_data[i].r;
456 data.color[i][1] = tri_data[i].g;
457 data.color[i][2] = tri_data[i].b;
458 data.color[i][3] = tri_data[i].a;
459 }
460
Tony Barbourf43b6982014-11-25 13:18:32 -0700461 ASSERT_NO_FATAL_FAILURE(InitState());
462 ASSERT_NO_FATAL_FAILURE(InitViewport());
463
464 XglConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(XGL_FLOAT), (const void*) &data);
465
466 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
467 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700468
469 XglPipelineObj pipelineobj(m_device);
470 pipelineobj.AddShader(&vs);
471 pipelineobj.AddShader(&ps);
472
473 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +0800474 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700475 m_memoryRefManager.AddMemoryRef(&constantBuffer);
476
Tony Barbour71ba3612015-01-09 16:12:35 -0700477 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
478 XglCommandBufferObj cmdBuffer(m_device);
479 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700480
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700481 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour71ba3612015-01-09 16:12:35 -0700482
483 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
484
485 cmdBuffer.BindVertexBuffer(&constantBuffer, 0, 0);
486#ifdef DUMP_STATE_DOT
487 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
488 pDSDumpDot((char*)"triTest2.dot");
489#endif
490 // render triangle
491 cmdBuffer.Draw(0, 3, 0, 1);
492
493 // finalize recording of the command buffer
494 cmdBuffer.EndCommandBuffer();
495 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
496
497 for (int i = 0; i < m_renderTargetCount; i++)
498 RecordImage(m_renderTargets[i]);
499
500 if (rotate)
501 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
502
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700503#ifdef PRINT_OBJECTS
504 //XGL_UINT64 objTrackGetObjectCount(XGL_OBJECT_TYPE type)
505 OBJ_TRACK_GET_OBJECT_COUNT pObjTrackGetObjectCount = (OBJ_TRACK_GET_OBJECT_COUNT)xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjectCount");
506 XGL_UINT64 numObjects = pObjTrackGetObjectCount(XGL_OBJECT_TYPE_ANY);
507 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjects");
508 printf("DEBUG : Number of Objects : %lu\n", numObjects);
509 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjects");
510 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
511 pObjTrackGetObjs(XGL_OBJECT_TYPE_ANY, numObjects, pObjNodeArray);
512 for (i=0; i < numObjects; i++) {
513 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);
514 }
515 free(pObjNodeArray);
516#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700517
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600518}
519
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600520TEST_F(XglRenderTest, XGLTriangle_FragColor)
521{
522 static const char *vertShaderText =
523 "#version 140\n"
524 "#extension GL_ARB_separate_shader_objects : enable\n"
525 "#extension GL_ARB_shading_language_420pack : enable\n"
526 "\n"
527 "layout(binding = 0) uniform buf {\n"
528 " mat4 MVP;\n"
529 " vec4 position[3];\n"
530 " vec4 color[3];\n"
531 "} ubuf;\n"
532 "\n"
533 "layout (location = 0) out vec4 outColor;\n"
534 "\n"
535 "void main() \n"
536 "{\n"
537 " outColor = ubuf.color[gl_VertexID];\n"
538 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
539 "}\n";
540
541 static const char *fragShaderText =
542 "#version 140\n"
543 "#extension GL_ARB_separate_shader_objects : enable\n"
544 "#extension GL_ARB_shading_language_420pack : enable\n"
545 "\n"
546 "layout (location = 0) in vec4 inColor;\n"
547 "\n"
548 "void main()\n"
549 "{\n"
550 " gl_FragColor = inColor;\n"
551 "}\n";
552
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600553 TEST_DESCRIPTION("XGL-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
Tony Barbourae442072015-01-12 13:27:11 -0700554 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600555}
556
557TEST_F(XglRenderTest, XGLTriangle_OutputLocation)
558{
559 static const char *vertShaderText =
560 "#version 140\n"
561 "#extension GL_ARB_separate_shader_objects : enable\n"
562 "#extension GL_ARB_shading_language_420pack : enable\n"
563 "\n"
564 "layout(binding = 0) uniform buf {\n"
565 " mat4 MVP;\n"
566 " vec4 position[3];\n"
567 " vec4 color[3];\n"
568 "} ubuf;\n"
569 "\n"
570 "layout (location = 0) out vec4 outColor;\n"
571 "\n"
572 "void main() \n"
573 "{\n"
574 " outColor = ubuf.color[gl_VertexID];\n"
575 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
576 "}\n";
577
578 static const char *fragShaderText =
579 "#version 140\n"
580 "#extension GL_ARB_separate_shader_objects : enable\n"
581 "#extension GL_ARB_shading_language_420pack : enable\n"
582 "\n"
583 "layout (location = 0) in vec4 inColor;\n"
584 "layout (location = 0) out vec4 outColor;\n"
585 "\n"
586 "void main()\n"
587 "{\n"
588 " outColor = inColor;\n"
589 "}\n";
590
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600591 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 -0600592
Tony Barbourae442072015-01-12 13:27:11 -0700593 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600594}
595
Tony Barbourf43b6982014-11-25 13:18:32 -0700596TEST_F(XglRenderTest, BIL_XGLTriangle)
597{
598 bool saved_use_bil = XglTestFramework::m_use_bil;
599
600 static const char *vertShaderText =
601 "#version 140\n"
602 "#extension GL_ARB_separate_shader_objects : enable\n"
603 "#extension GL_ARB_shading_language_420pack : enable\n"
604 "\n"
605 "layout(binding = 0) uniform buf {\n"
606 " mat4 MVP;\n"
607 " vec4 position[3];\n"
608 " vec4 color[3];\n"
609 "} ubuf;\n"
610 "\n"
611 "layout (location = 0) out vec4 outColor;\n"
612 "\n"
613 "void main() \n"
614 "{\n"
615 " outColor = ubuf.color[gl_VertexID];\n"
616 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
617 "}\n";
618
619 static const char *fragShaderText =
620 "#version 140\n"
621 "#extension GL_ARB_separate_shader_objects : enable\n"
622 "#extension GL_ARB_shading_language_420pack : enable\n"
623 "\n"
624 "layout (location = 0) in vec4 inColor;\n"
625 "\n"
626 "void main()\n"
627 "{\n"
628 " gl_FragColor = inColor;\n"
629 "}\n";
630
631 TEST_DESCRIPTION("XGL-style shaders, but force test framework to compile shader to BIL and pass BIL to driver.");
632
633 XglTestFramework::m_use_bil = true;
634
Tony Barbourae442072015-01-12 13:27:11 -0700635 XGLTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700636
637 XglTestFramework::m_use_bil = saved_use_bil;
638}
639
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600640TEST_F(XglRenderTest, GreenTriangle)
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600641{
642 static const char *vertShaderText =
643 "#version 130\n"
644 "vec2 vertices[3];\n"
645 "void main() {\n"
646 " vertices[0] = vec2(-1.0, -1.0);\n"
647 " vertices[1] = vec2( 1.0, -1.0);\n"
648 " vertices[2] = vec2( 0.0, 1.0);\n"
649 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
650 "}\n";
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600651
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600652 static const char *fragShaderText =
653 "#version 130\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600654 "void main() {\n"
Steve K10b32512014-10-10 08:54:29 -0600655 " gl_FragColor = vec4(0,1,0,1);\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600656 "}\n";
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600657
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600658 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
659
Tony Barbourae442072015-01-12 13:27:11 -0700660 XGLTriangleTest(vertShaderText, fragShaderText, false);
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600661}
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600662
Tony Barbourf43b6982014-11-25 13:18:32 -0700663TEST_F(XglRenderTest, BIL_GreenTriangle)
664{
665 bool saved_use_bil = XglTestFramework::m_use_bil;
666
667 static const char *vertShaderText =
668 "#version 130\n"
669 "vec2 vertices[3];\n"
670 "void main() {\n"
671 " vertices[0] = vec2(-1.0, -1.0);\n"
672 " vertices[1] = vec2( 1.0, -1.0);\n"
673 " vertices[2] = vec2( 0.0, 1.0);\n"
674 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
675 "}\n";
676
677 static const char *fragShaderText =
678 "#version 130\n"
679 "void main() {\n"
680 " gl_FragColor = vec4(0,1,0,1);\n"
681 "}\n";
682
683 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to BIL and gives BIL to driver.");
684
685 XglTestFramework::m_use_bil = true;
Tony Barbourae442072015-01-12 13:27:11 -0700686 XGLTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700687 XglTestFramework::m_use_bil = saved_use_bil;
688}
689
690TEST_F(XglRenderTest, YellowTriangle)
691{
692 static const char *vertShaderText =
693 "#version 130\n"
694 "void main() {\n"
695 " vec2 vertices[3];"
696 " vertices[0] = vec2(-0.5, -0.5);\n"
697 " vertices[1] = vec2( 0.5, -0.5);\n"
698 " vertices[2] = vec2( 0.5, 0.5);\n"
699 " vec4 colors[3];\n"
700 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
701 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
702 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
703 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
704 "}\n";
705
706 static const char *fragShaderText =
707 "#version 130\n"
708 "void main() {\n"
709 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
710 "}\n";
711
Tony Barbourae442072015-01-12 13:27:11 -0700712 XGLTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700713}
714
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600715TEST_F(XglRenderTest, TriangleWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600716{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600717 static const char *vertShaderText =
Tony Barbourf43b6982014-11-25 13:18:32 -0700718 "#version 130\n"
719 //XYZ1( -1, -1, -1 )
720 "in vec4 pos;\n"
721 //XYZ1( 0.f, 0.f, 0.f )
722 "in vec4 inColor;\n"
723 "out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600724 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600725 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600726 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600727 "}\n";
728
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600729
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600730 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700731 "#version 140\n"
732 "#extension GL_ARB_separate_shader_objects : enable\n"
733 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700734 "in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700735 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600736 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700737 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600738 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600739
Tony Barbourf43b6982014-11-25 13:18:32 -0700740
741
742 ASSERT_NO_FATAL_FAILURE(InitState());
743 ASSERT_NO_FATAL_FAILURE(InitViewport());
744
745 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000746 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700747
748 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
749 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
750
751 XglPipelineObj pipelineobj(m_device);
752 pipelineobj.AddShader(&vs);
753 pipelineobj.AddShader(&ps);
754
755 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +0800756 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700757
758 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
759 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
760 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
761 };
762
763 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
764 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
765 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
766 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
767 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
768 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
769 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
770 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
771 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
772
773 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
774 pipelineobj.AddVertexInputBindings(&vi_binding,1);
775 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
776
Tony Barboure4ed9942015-01-09 10:06:53 -0700777 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
778 XglCommandBufferObj cmdBuffer(m_device);
779 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700780
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700781 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -0700782 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
783
Tony Barboure4ed9942015-01-09 10:06:53 -0700784 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
785
786 // render two triangles
787 cmdBuffer.Draw(0, 6, 0, 1);
788
789 // finalize recording of the command buffer
790 cmdBuffer.EndCommandBuffer();
791 cmdBuffer.QueueCommandBuffer(NULL, 0);
792
793 for (int i = 0; i < m_renderTargetCount; i++)
794 RecordImage(m_renderTargets[i]);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600795}
796
Chia-I Wue09d1a72014-12-05 10:32:23 +0800797TEST_F(XglRenderTest, TriangleMRT)
798{
799 static const char *vertShaderText =
800 "#version 130\n"
801 "in vec4 pos;\n"
802 "void main() {\n"
803 " gl_Position = pos;\n"
804 "}\n";
805
806 static const char *fragShaderText =
807 "#version 130\n"
808 "void main() {\n"
809 " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
810 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
811 "}\n";
812 const XGL_FLOAT vb_data[][2] = {
813 { -1.0f, -1.0f },
814 { 1.0f, -1.0f },
815 { -1.0f, 1.0f }
816 };
817
818 ASSERT_NO_FATAL_FAILURE(InitState());
819 ASSERT_NO_FATAL_FAILURE(InitViewport());
820
821 XglConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000822 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800823
824 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
825 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
826
827 XglPipelineObj pipelineobj(m_device);
828 pipelineobj.AddShader(&vs);
829 pipelineobj.AddShader(&ps);
830
831 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
832 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
833 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
834 };
835
836 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attrib;
837 vi_attrib.binding = 0; // index into vertexBindingDescriptions
838 vi_attrib.format.channelFormat = XGL_CH_FMT_R32G32; // format of source data
839 vi_attrib.format.numericFormat = XGL_NUM_FMT_FLOAT;
840 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
841
842 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
843 pipelineobj.AddVertexInputBindings(&vi_binding,1);
844 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
845
846 XglDescriptorSetObj descriptorSet(m_device);
847
848 m_renderTargetCount = 2;
Tony Barboure4ed9942015-01-09 10:06:53 -0700849 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wue09d1a72014-12-05 10:32:23 +0800850
851 XGL_PIPELINE_CB_ATTACHMENT_STATE att = {};
852 att.blendEnable = XGL_FALSE;
853 att.format = m_render_target_fmt;
854 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700855 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800856
Tony Barbour5ed79702015-01-07 14:31:52 -0700857 XglCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700858
Tony Barbour5ed79702015-01-07 14:31:52 -0700859 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
860 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barboure4ed9942015-01-09 10:06:53 -0700861
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700862 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour5ed79702015-01-07 14:31:52 -0700863
Tony Barboure4ed9942015-01-09 10:06:53 -0700864 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
865
Tony Barbour5ed79702015-01-07 14:31:52 -0700866 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700867#ifdef DUMP_STATE_DOT
868 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
869 pDSDumpDot((char*)"triTest2.dot");
870#endif
871 // render triangle
872 cmdBuffer.Draw(0, 3, 0, 1);
873
874 // finalize recording of the command buffer
875 cmdBuffer.EndCommandBuffer();
876 cmdBuffer.QueueCommandBuffer(NULL, 0);
877
878 for (int i = 0; i < m_renderTargetCount; i++)
879 RecordImage(m_renderTargets[i]);
880
Chia-I Wue09d1a72014-12-05 10:32:23 +0800881}
882
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700883TEST_F(XglRenderTest, QuadWithIndexedVertexFetch)
884{
885 static const char *vertShaderText =
886 "#version 140\n"
887 "#extension GL_ARB_separate_shader_objects : enable\n"
888 "#extension GL_ARB_shading_language_420pack : enable\n"
889 "layout(location = 0) in vec4 pos;\n"
890 "layout(location = 1) in vec4 inColor;\n"
891 "layout(location = 0) out vec4 outColor;\n"
892 "void main() {\n"
893 " outColor = inColor;\n"
894 " gl_Position = pos;\n"
895 "}\n";
896
897
898 static const char *fragShaderText =
899 "#version 140\n"
900 "#extension GL_ARB_separate_shader_objects : enable\n"
901 "#extension GL_ARB_shading_language_420pack : enable\n"
902 "layout(location = 0) in vec4 color;\n"
903 "void main() {\n"
904 " gl_FragColor = color;\n"
905 "}\n";
906
907 const Vertex g_vbData[] =
908 {
909 // first tri
910 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
911 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
912 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
913
914 // second tri
915 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
916 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
917 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
918 };
919
920 const uint16_t g_idxData[6] = {
921 0, 1, 2,
922 3, 4, 5,
923 };
924
925 ASSERT_NO_FATAL_FAILURE(InitState());
926 ASSERT_NO_FATAL_FAILURE(InitViewport());
927
928 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000929 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700930
931 XglIndexBufferObj indexBuffer(m_device);
932 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), XGL_INDEX_16, g_idxData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000933 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700934
935 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
936 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
937
938 XglPipelineObj pipelineobj(m_device);
939 pipelineobj.AddShader(&vs);
940 pipelineobj.AddShader(&ps);
941
942 XglDescriptorSetObj descriptorSet(m_device);
943
944 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
945 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
946 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
947 };
948
949 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
950 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
951 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
952 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
953 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
954 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
955 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
956 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
957 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
958
959 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
960 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700961
962 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700963 XglCommandBufferObj cmdBuffer(m_device);
964 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700965 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -0700966
967 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700968
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700969#ifdef DUMP_STATE_DOT
970 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700971 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700972#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700973
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700974 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
975 cmdBuffer.BindIndexBuffer(&indexBuffer,0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700976
977 // render two triangles
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700978 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700979
980 // finalize recording of the command buffer
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700981 cmdBuffer.EndCommandBuffer();
982 cmdBuffer.QueueCommandBuffer(NULL, 0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700983
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700984 for (int i = 0; i < m_renderTargetCount; i++)
985 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700986
987}
988
GregF6bef1212014-12-02 15:41:44 -0700989TEST_F(XglRenderTest, GreyandRedCirclesonBlue)
990{
991 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -0700992
GregF6bef1212014-12-02 15:41:44 -0700993 static const char *vertShaderText =
994 "#version 140\n"
995 "#extension GL_ARB_separate_shader_objects : enable\n"
996 "#extension GL_ARB_shading_language_420pack : enable\n"
997 "layout (location = 0) in vec4 pos;\n"
998 "layout (location = 0) out vec4 outColor;\n"
999 "layout (location = 1) out vec4 outColor2;\n"
1000 "void main() {\n"
1001 " gl_Position = pos;\n"
1002 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1003 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1004 "}\n";
1005
1006 static const char *fragShaderText =
1007 //"#version 140\n"
1008 "#version 330\n"
1009 "#extension GL_ARB_separate_shader_objects : enable\n"
1010 "#extension GL_ARB_shading_language_420pack : enable\n"
1011 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1012 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1013 "layout (location = 0) in vec4 color;\n"
1014 "layout (location = 1) in vec4 color2;\n"
1015 "void main() {\n"
1016 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1017 " float dist_squared = dot(pos, pos);\n"
1018 " gl_FragColor = (dist_squared < 400.0)\n"
1019 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1020 " : color2;\n"
1021 "}\n";
1022
1023 ASSERT_NO_FATAL_FAILURE(InitState());
1024 ASSERT_NO_FATAL_FAILURE(InitViewport());
1025
1026 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001027 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001028
1029 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1030 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1031
1032 XglPipelineObj pipelineobj(m_device);
1033 pipelineobj.AddShader(&vs);
1034 pipelineobj.AddShader(&ps);
1035
1036 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001037 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001038
1039 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1040 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1041 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1042 };
1043
1044 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1045 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1046 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1047 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1048 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1049 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1050 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1051 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1052 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1053
1054 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1055 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1056 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1057
Tony Barbourdd4c9642015-01-09 12:55:14 -07001058 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1059 XglCommandBufferObj cmdBuffer(m_device);
1060 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1061
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001062 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001063
1064 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1065
1066 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1067#ifdef DUMP_STATE_DOT
1068 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1069 pDSDumpDot((char*)"triTest2.dot");
1070#endif
1071 // render triangle
1072 cmdBuffer.Draw(0, 6, 0, 1);
1073
1074 // finalize recording of the command buffer
1075 cmdBuffer.EndCommandBuffer();
1076 cmdBuffer.QueueCommandBuffer(NULL, 0);
1077
1078 for (int i = 0; i < m_renderTargetCount; i++)
1079 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001080
1081}
1082
1083TEST_F(XglRenderTest, RedCirclesonBlue)
1084{
1085 // This tests that we correctly handle unread fragment inputs
1086
1087 static const char *vertShaderText =
1088 "#version 140\n"
1089 "#extension GL_ARB_separate_shader_objects : enable\n"
1090 "#extension GL_ARB_shading_language_420pack : enable\n"
1091 "layout (location = 0) in vec4 pos;\n"
1092 "layout (location = 0) out vec4 outColor;\n"
1093 "layout (location = 1) out vec4 outColor2;\n"
1094 "void main() {\n"
1095 " gl_Position = pos;\n"
1096 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1097 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1098 "}\n";
1099
1100 static const char *fragShaderText =
1101 //"#version 140\n"
1102 "#version 330\n"
1103 "#extension GL_ARB_separate_shader_objects : enable\n"
1104 "#extension GL_ARB_shading_language_420pack : enable\n"
1105 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1106 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1107 "layout (location = 0) in vec4 color;\n"
1108 "layout (location = 1) in vec4 color2;\n"
1109 "void main() {\n"
1110 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1111 " float dist_squared = dot(pos, pos);\n"
1112 " gl_FragColor = (dist_squared < 400.0)\n"
1113 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1114 " : color2;\n"
1115 "}\n";
1116
1117 ASSERT_NO_FATAL_FAILURE(InitState());
1118 ASSERT_NO_FATAL_FAILURE(InitViewport());
1119
1120 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001121 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001122
1123 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1124 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1125
1126 XglPipelineObj pipelineobj(m_device);
1127 pipelineobj.AddShader(&vs);
1128 pipelineobj.AddShader(&ps);
1129
1130 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001131 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001132
1133 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1134 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1135 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1136 };
1137
1138 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1139 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1140 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1141 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1142 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1143 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1144 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1145 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1146 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1147
1148 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1149 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1150 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1151
Tony Barbourdd4c9642015-01-09 12:55:14 -07001152 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1153 XglCommandBufferObj cmdBuffer(m_device);
1154 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1155
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001156 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001157
1158 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1159
1160 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1161#ifdef DUMP_STATE_DOT
1162 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1163 pDSDumpDot((char*)"triTest2.dot");
1164#endif
1165 // render triangle
1166 cmdBuffer.Draw(0, 6, 0, 1);
1167
1168 // finalize recording of the command buffer
1169 cmdBuffer.EndCommandBuffer();
1170 cmdBuffer.QueueCommandBuffer(NULL, 0);
1171
1172 for (int i = 0; i < m_renderTargetCount; i++)
1173 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001174
1175}
1176
1177TEST_F(XglRenderTest, GreyCirclesonBlueFade)
1178{
1179 // This tests reading gl_ClipDistance from FS
1180
1181 static const char *vertShaderText =
1182 "#version 330\n"
1183 "#extension GL_ARB_separate_shader_objects : enable\n"
1184 "#extension GL_ARB_shading_language_420pack : enable\n"
1185 "out gl_PerVertex {\n"
1186 " vec4 gl_Position;\n"
1187 " float gl_ClipDistance[1];\n"
1188 "};\n"
1189 "layout (location = 0) in vec4 pos;\n"
1190 "layout (location = 0) out vec4 outColor;\n"
1191 "layout (location = 1) out vec4 outColor2;\n"
1192 "void main() {\n"
1193 " gl_Position = pos;\n"
1194 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1195 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1196 " float dists[3];\n"
1197 " dists[0] = 0.0;\n"
1198 " dists[1] = 1.0;\n"
1199 " dists[2] = 1.0;\n"
1200 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1201 "}\n";
1202
1203
1204 static const char *fragShaderText =
1205 //"#version 140\n"
1206 "#version 330\n"
1207 "#extension GL_ARB_separate_shader_objects : enable\n"
1208 "#extension GL_ARB_shading_language_420pack : enable\n"
1209 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1210 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1211 "layout (location = 0) in vec4 color;\n"
1212 "layout (location = 1) in vec4 color2;\n"
1213 "void main() {\n"
1214 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1215 " float dist_squared = dot(pos, pos);\n"
1216 " gl_FragColor = (dist_squared < 400.0)\n"
1217 " ? color * gl_ClipDistance[0]\n"
1218 " : color2;\n"
1219 "}\n";
1220
1221 ASSERT_NO_FATAL_FAILURE(InitState());
1222 ASSERT_NO_FATAL_FAILURE(InitViewport());
1223
1224 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001225 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001226
1227 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1228 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1229
1230 XglPipelineObj pipelineobj(m_device);
1231 pipelineobj.AddShader(&vs);
1232 pipelineobj.AddShader(&ps);
1233
1234 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001235 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001236
1237 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1238 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1239 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1240 };
1241
1242 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1243 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1244 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1245 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1246 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1247 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1248 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1249 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1250 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1251
1252 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1253 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1254 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1255
Tony Barbourdd4c9642015-01-09 12:55:14 -07001256 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1257 XglCommandBufferObj cmdBuffer(m_device);
1258 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF6bef1212014-12-02 15:41:44 -07001259
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001260 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001261
1262 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1263
1264 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1265#ifdef DUMP_STATE_DOT
1266 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1267 pDSDumpDot((char*)"triTest2.dot");
1268#endif
1269 // render triangle
1270 cmdBuffer.Draw(0, 6, 0, 1);
1271
1272 // finalize recording of the command buffer
1273 cmdBuffer.EndCommandBuffer();
1274 cmdBuffer.QueueCommandBuffer(NULL, 0);
1275
1276 for (int i = 0; i < m_renderTargetCount; i++)
1277 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001278}
Tony Barbourf43b6982014-11-25 13:18:32 -07001279
GregF7a23c792014-12-02 17:19:34 -07001280TEST_F(XglRenderTest, GreyCirclesonBlueDiscard)
1281{
1282 static const char *vertShaderText =
1283 "#version 140\n"
1284 "#extension GL_ARB_separate_shader_objects : enable\n"
1285 "#extension GL_ARB_shading_language_420pack : enable\n"
1286 "layout (location = 0) in vec4 pos;\n"
1287 "layout (location = 0) out vec4 outColor;\n"
1288 "layout (location = 1) out vec4 outColor2;\n"
1289 "void main() {\n"
1290 " gl_Position = pos;\n"
1291 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1292 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1293 "}\n";
1294
1295
1296 static const char *fragShaderText =
1297 //"#version 140\n"
1298 "#version 330\n"
1299 "#extension GL_ARB_separate_shader_objects : enable\n"
1300 "#extension GL_ARB_shading_language_420pack : enable\n"
1301 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1302 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1303 "layout (location = 0) in vec4 color;\n"
1304 "layout (location = 1) in vec4 color2;\n"
1305 "void main() {\n"
1306 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1307 " float dist_squared = dot(pos, pos);\n"
1308 " if (dist_squared < 100.0)\n"
1309 " discard;\n"
1310 " gl_FragColor = (dist_squared < 400.0)\n"
1311 " ? color\n"
1312 " : color2;\n"
1313 "}\n";
1314
1315 ASSERT_NO_FATAL_FAILURE(InitState());
1316 ASSERT_NO_FATAL_FAILURE(InitViewport());
1317
1318 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001319 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001320
1321 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1322 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1323
1324 XglPipelineObj pipelineobj(m_device);
1325 pipelineobj.AddShader(&vs);
1326 pipelineobj.AddShader(&ps);
1327
1328 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001329 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF7a23c792014-12-02 17:19:34 -07001330
1331 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1332 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1333 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1334 };
1335
1336 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1337 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1338 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1339 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1340 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1341 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1342 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1343 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1344 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1345
1346 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1347 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1348 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1349
Tony Barbourdd4c9642015-01-09 12:55:14 -07001350 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1351 XglCommandBufferObj cmdBuffer(m_device);
1352 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1353
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001354 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001355
1356 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1357
1358 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1359#ifdef DUMP_STATE_DOT
1360 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1361 pDSDumpDot((char*)"triTest2.dot");
1362#endif
1363 // render triangle
1364 cmdBuffer.Draw(0, 6, 0, 1);
1365
1366 // finalize recording of the command buffer
1367 cmdBuffer.EndCommandBuffer();
1368 cmdBuffer.QueueCommandBuffer(NULL, 0);
1369
1370 for (int i = 0; i < m_renderTargetCount; i++)
1371 RecordImage(m_renderTargets[i]);
GregF7a23c792014-12-02 17:19:34 -07001372
1373}
1374
1375
Courtney Goeltzenleuchter3d10c9c2014-10-27 13:06:08 -06001376TEST_F(XglRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001377{
1378 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001379 "#version 140\n"
1380 "#extension GL_ARB_separate_shader_objects : enable\n"
1381 "#extension GL_ARB_shading_language_420pack : enable\n"
1382 "\n"
1383 "layout(binding = 0) uniform buf {\n"
1384 " mat4 MVP;\n"
1385 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001386 "void main() {\n"
1387 " vec2 vertices[3];"
1388 " vertices[0] = vec2(-0.5, -0.5);\n"
1389 " vertices[1] = vec2( 0.5, -0.5);\n"
1390 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001391 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001392 "}\n";
1393
1394 static const char *fragShaderText =
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001395 "#version 130\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001396 "void main() {\n"
Cody Northrop78eac042014-10-10 15:45:00 -06001397 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001398 "}\n";
1399
Tony Barbourf43b6982014-11-25 13:18:32 -07001400 ASSERT_NO_FATAL_FAILURE(InitState());
1401 ASSERT_NO_FATAL_FAILURE(InitViewport());
1402
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001403 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001404 glm::mat4 Projection = glm::mat4(1.0f);
1405 glm::mat4 View = glm::mat4(1.0f);
1406 glm::mat4 Model = glm::mat4(1.0f);
1407 glm::mat4 MVP = Projection * View * Model;
1408 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1409
Tony Barbourf43b6982014-11-25 13:18:32 -07001410 XglConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1411 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1412 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001413
Tony Barbourf43b6982014-11-25 13:18:32 -07001414 XglPipelineObj pipelineobj(m_device);
1415 pipelineobj.AddShader(&vs);
1416 pipelineobj.AddShader(&ps);
1417
1418 // Create descriptor set and attach the constant buffer to it
1419 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001420 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001421
1422 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1423
Tony Barbourdd4c9642015-01-09 12:55:14 -07001424 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1425 XglCommandBufferObj cmdBuffer(m_device);
1426 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001427
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001428 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001429
1430 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1431
1432 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1433#ifdef DUMP_STATE_DOT
1434 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1435 pDSDumpDot((char*)"triTest2.dot");
1436#endif
1437 // render triangle
1438 cmdBuffer.Draw(0, 6, 0, 1);
1439
1440 // finalize recording of the command buffer
1441 cmdBuffer.EndCommandBuffer();
1442 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
1443
1444 for (int i = 0; i < m_renderTargetCount; i++)
1445 RecordImage(m_renderTargets[i]);
1446
1447 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001448}
1449
Tony Barbourf43b6982014-11-25 13:18:32 -07001450TEST_F(XglRenderTest, MixTriangle)
1451{
1452 // This tests location applied to varyings. Notice that we have switched foo
1453 // and bar in the FS. The triangle should be blended with red, green and blue
1454 // corners.
1455 static const char *vertShaderText =
1456 "#version 140\n"
1457 "#extension GL_ARB_separate_shader_objects : enable\n"
1458 "#extension GL_ARB_shading_language_420pack : enable\n"
1459 "layout (location=0) out vec4 bar;\n"
1460 "layout (location=1) out vec4 foo;\n"
1461 "layout (location=2) out float scale;\n"
1462 "vec2 vertices[3];\n"
1463 "void main() {\n"
1464 " vertices[0] = vec2(-1.0, -1.0);\n"
1465 " vertices[1] = vec2( 1.0, -1.0);\n"
1466 " vertices[2] = vec2( 0.0, 1.0);\n"
1467 "vec4 colors[3];\n"
1468 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1469 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1470 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1471 " foo = colors[gl_VertexID % 3];\n"
1472 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1473 " scale = 1.0;\n"
1474 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1475 "}\n";
1476
1477 static const char *fragShaderText =
1478 "#version 140\n"
1479 "#extension GL_ARB_separate_shader_objects : enable\n"
1480 "#extension GL_ARB_shading_language_420pack : enable\n"
1481 "layout (location = 1) in vec4 bar;\n"
1482 "layout (location = 0) in vec4 foo;\n"
1483 "layout (location = 2) in float scale;\n"
1484 "void main() {\n"
1485 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
1486 "}\n";
1487
1488 ASSERT_NO_FATAL_FAILURE(InitState());
1489 ASSERT_NO_FATAL_FAILURE(InitViewport());
1490
1491 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1492 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1493
1494 XglPipelineObj pipelineobj(m_device);
1495 pipelineobj.AddShader(&vs);
1496 pipelineobj.AddShader(&ps);
1497
1498 XglDescriptorSetObj descriptorSet(m_device);
1499
Tony Barbourdd4c9642015-01-09 12:55:14 -07001500 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1501 XglCommandBufferObj cmdBuffer(m_device);
1502 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1503
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001504 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001505
1506 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1507
1508#ifdef DUMP_STATE_DOT
1509 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1510 pDSDumpDot((char*)"triTest2.dot");
1511#endif
1512 // render triangle
1513 cmdBuffer.Draw(0, 3, 0, 1);
1514
1515 // finalize recording of the command buffer
1516 cmdBuffer.EndCommandBuffer();
1517 cmdBuffer.QueueCommandBuffer(NULL, 0);
1518
1519 for (int i = 0; i < m_renderTargetCount; i++)
1520 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001521}
1522
1523TEST_F(XglRenderTest, TriVertFetchAndVertID)
1524{
1525 // This tests that attributes work in the presence of gl_VertexID
1526
1527 static const char *vertShaderText =
1528 "#version 140\n"
1529 "#extension GL_ARB_separate_shader_objects : enable\n"
1530 "#extension GL_ARB_shading_language_420pack : enable\n"
1531 //XYZ1( -1, -1, -1 )
1532 "layout (location = 0) in vec4 pos;\n"
1533 //XYZ1( 0.f, 0.f, 0.f )
1534 "layout (location = 1) in vec4 inColor;\n"
1535 "layout (location = 0) out vec4 outColor;\n"
1536 "void main() {\n"
1537 " outColor = inColor;\n"
1538 " vec4 vertices[3];"
1539 " vertices[gl_VertexID % 3] = pos;\n"
1540 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1541 "}\n";
1542
1543
1544 static const char *fragShaderText =
1545 "#version 140\n"
1546 "#extension GL_ARB_separate_shader_objects : enable\n"
1547 "#extension GL_ARB_shading_language_420pack : enable\n"
1548 "layout (location = 0) in vec4 color;\n"
1549 "void main() {\n"
1550 " gl_FragColor = color;\n"
1551 "}\n";
1552
1553 ASSERT_NO_FATAL_FAILURE(InitState());
1554 ASSERT_NO_FATAL_FAILURE(InitViewport());
1555
1556 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001557 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001558
1559 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1560 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1561
1562 XglPipelineObj pipelineobj(m_device);
1563 pipelineobj.AddShader(&vs);
1564 pipelineobj.AddShader(&ps);
1565
1566 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001567 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001568
1569 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1570 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1571 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1572 };
1573
1574 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1575 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1576 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1577 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1578 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1579 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1580 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1581 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1582 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1583
1584 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1585 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1586 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1587
Tony Barbourdd4c9642015-01-09 12:55:14 -07001588 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1589 XglCommandBufferObj cmdBuffer(m_device);
1590 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1591
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001592 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001593
1594 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1595
1596 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1597#ifdef DUMP_STATE_DOT
1598 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1599 pDSDumpDot((char*)"triTest2.dot");
1600#endif
1601 // render triangle
1602 cmdBuffer.Draw(0, 6, 0, 1);
1603
1604 // finalize recording of the command buffer
1605 cmdBuffer.EndCommandBuffer();
1606 cmdBuffer.QueueCommandBuffer(NULL, 0);
1607
1608 for (int i = 0; i < m_renderTargetCount; i++)
1609 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001610}
1611
1612TEST_F(XglRenderTest, TriVertFetchDeadAttr)
1613{
1614 // This tests that attributes work in the presence of gl_VertexID
1615 // and a dead attribute in position 0. Draws a triangle with yellow,
1616 // red and green corners, starting at top and going clockwise.
1617
1618 static const char *vertShaderText =
1619 "#version 140\n"
1620 "#extension GL_ARB_separate_shader_objects : enable\n"
1621 "#extension GL_ARB_shading_language_420pack : enable\n"
1622 //XYZ1( -1, -1, -1 )
1623 "layout (location = 0) in vec4 pos;\n"
1624 //XYZ1( 0.f, 0.f, 0.f )
1625 "layout (location = 1) in vec4 inColor;\n"
1626 "layout (location = 0) out vec4 outColor;\n"
1627 "void main() {\n"
1628 " outColor = inColor;\n"
1629 " vec2 vertices[3];"
1630 " vertices[0] = vec2(-1.0, -1.0);\n"
1631 " vertices[1] = vec2( 1.0, -1.0);\n"
1632 " vertices[2] = vec2( 0.0, 1.0);\n"
1633 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1634 "}\n";
1635
1636
1637 static const char *fragShaderText =
1638 "#version 140\n"
1639 "#extension GL_ARB_separate_shader_objects : enable\n"
1640 "#extension GL_ARB_shading_language_420pack : enable\n"
1641 "layout (location = 0) in vec4 color;\n"
1642 "void main() {\n"
1643 " gl_FragColor = color;\n"
1644 "}\n";
1645
1646 ASSERT_NO_FATAL_FAILURE(InitState());
1647 ASSERT_NO_FATAL_FAILURE(InitViewport());
1648
1649 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001650 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001651
1652 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1653 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1654
1655 XglPipelineObj pipelineobj(m_device);
1656 pipelineobj.AddShader(&vs);
1657 pipelineobj.AddShader(&ps);
1658
1659 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001660 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001661
1662 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1663 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1664 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1665 };
1666
1667 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1668 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1669 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1670 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1671 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1672 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1673 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1674 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1675 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1676
1677 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1678 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1679 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1680
Tony Barbourdd4c9642015-01-09 12:55:14 -07001681 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1682 XglCommandBufferObj cmdBuffer(m_device);
1683 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001684
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001685 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001686
1687 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1688
1689 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1690#ifdef DUMP_STATE_DOT
1691 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1692 pDSDumpDot((char*)"triTest2.dot");
1693#endif
1694 // render triangle
1695 cmdBuffer.Draw(0, 6, 0, 1);
1696
1697 // finalize recording of the command buffer
1698 cmdBuffer.EndCommandBuffer();
1699 cmdBuffer.QueueCommandBuffer(NULL, 0);
1700
1701 for (int i = 0; i < m_renderTargetCount; i++)
1702 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001703}
1704
1705TEST_F(XglRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001706{
1707 static const char *vertShaderText =
1708 "#version 140\n"
1709 "layout (std140) uniform bufferVals {\n"
1710 " mat4 mvp;\n"
1711 "} myBufferVals;\n"
1712 "in vec4 pos;\n"
1713 "in vec4 inColor;\n"
1714 "out vec4 outColor;\n"
1715 "void main() {\n"
1716 " outColor = inColor;\n"
1717 " gl_Position = myBufferVals.mvp * pos;\n"
1718 "}\n";
1719
1720 static const char *fragShaderText =
1721 "#version 130\n"
1722 "in vec4 color;\n"
1723 "void main() {\n"
1724 " gl_FragColor = color;\n"
1725 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001726 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001727
Tony Barbourf43b6982014-11-25 13:18:32 -07001728 glm::mat4 View = glm::lookAt(
1729 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1730 glm::vec3(0,0,0), // and looks at the origin
1731 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
1732 );
1733
1734 glm::mat4 Model = glm::mat4(1.0f);
1735
1736 glm::mat4 MVP = Projection * View * Model;
1737
1738 ASSERT_NO_FATAL_FAILURE(InitState());
1739 ASSERT_NO_FATAL_FAILURE(InitViewport());
1740 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
1741
1742 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
1743 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1744
1745 const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT);
1746
1747 XglConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1748 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1749 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1750
Tony Barbourf43b6982014-11-25 13:18:32 -07001751 XglPipelineObj pipelineobj(m_device);
1752 pipelineobj.AddShader(&vs);
1753 pipelineobj.AddShader(&ps);
1754
Tony Barbourfa6cac72015-01-16 14:27:35 -07001755 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
1756 ds_state.depthTestEnable = XGL_TRUE;
1757 ds_state.depthWriteEnable = XGL_TRUE;
1758 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
1759 ds_state.depthBoundsEnable = XGL_FALSE;
1760 ds_state.stencilTestEnable = XGL_FALSE;
1761 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
1762 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
1763 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
1764 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
1765 ds_state.format.channelFormat = XGL_CH_FMT_R32;
1766 ds_state.format.numericFormat = XGL_NUM_FMT_DS;
1767 ds_state.front = ds_state.back;
1768 pipelineobj.SetDepthStencil(&ds_state);
1769
Tony Barbourf43b6982014-11-25 13:18:32 -07001770 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001771 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001772
1773 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1774 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1775
1776 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1777 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1778 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1779 };
1780
1781 // this is the current description of g_vbData
1782 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1783 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1784 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1785 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1786 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1787 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1788 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1789 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1790 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1791
1792 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1793 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1794 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1795
Tony Barboure4ed9942015-01-09 10:06:53 -07001796 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1797 XglCommandBufferObj cmdBuffer(m_device);
1798 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001799
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001800 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -07001801 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001802
Tony Barboure4ed9942015-01-09 10:06:53 -07001803 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1804#ifdef DUMP_STATE_DOT
1805 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1806 pDSDumpDot((char*)"triTest2.dot");
1807#endif
1808 // render triangle
1809 cmdBuffer.Draw(0, 36, 0, 1);
1810
1811 // finalize recording of the command buffer
1812 cmdBuffer.EndCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001813 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barboure4ed9942015-01-09 10:06:53 -07001814
1815 for (int i = 0; i < m_renderTargetCount; i++)
1816 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001817}
1818
Tony Barbourf43b6982014-11-25 13:18:32 -07001819TEST_F(XglRenderTest, VSTexture)
1820{
1821 // The expected result from this test is a green and red triangle;
1822 // one red vertex on the left, two green vertices on the right.
1823 static const char *vertShaderText =
1824 "#version 130\n"
1825 "out vec4 texColor;\n"
1826 "uniform sampler2D surface;\n"
1827 "void main() {\n"
1828 " vec2 vertices[3];"
1829 " vertices[0] = vec2(-0.5, -0.5);\n"
1830 " vertices[1] = vec2( 0.5, -0.5);\n"
1831 " vertices[2] = vec2( 0.5, 0.5);\n"
1832 " vec2 positions[3];"
1833 " positions[0] = vec2( 0.0, 0.0);\n"
1834 " positions[1] = vec2( 0.25, 0.1);\n"
1835 " positions[2] = vec2( 0.1, 0.25);\n"
1836 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1837 " texColor = textureLod(surface, samplePos, 0.0);\n"
1838 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1839 "}\n";
1840
1841 static const char *fragShaderText =
1842 "#version 130\n"
1843 "in vec4 texColor;\n"
1844 "void main() {\n"
1845 " gl_FragColor = texColor;\n"
1846 "}\n";
1847
1848 ASSERT_NO_FATAL_FAILURE(InitState());
1849 ASSERT_NO_FATAL_FAILURE(InitViewport());
1850
1851 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1852 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1853 XglSamplerObj sampler(m_device);
1854 XglTextureObj texture(m_device);
1855
Tony Barbourf43b6982014-11-25 13:18:32 -07001856 XglPipelineObj pipelineobj(m_device);
1857 pipelineobj.AddShader(&vs);
1858 pipelineobj.AddShader(&ps);
1859
1860 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001861 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001862
1863 m_memoryRefManager.AddMemoryRef(&texture);
1864
Tony Barbourdd4c9642015-01-09 12:55:14 -07001865 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1866 XglCommandBufferObj cmdBuffer(m_device);
1867 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001868
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001869 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001870
1871 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1872
1873#ifdef DUMP_STATE_DOT
1874 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1875 pDSDumpDot((char*)"triTest2.dot");
1876#endif
1877 // render triangle
1878 cmdBuffer.Draw(0, 3, 0, 1);
1879
1880 // finalize recording of the command buffer
1881 cmdBuffer.EndCommandBuffer();
1882 cmdBuffer.QueueCommandBuffer(NULL, 0);
1883
1884 for (int i = 0; i < m_renderTargetCount; i++)
1885 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001886}
1887TEST_F(XglRenderTest, TexturedTriangle)
1888{
1889 // The expected result from this test is a red and green checkered triangle
1890 static const char *vertShaderText =
1891 "#version 140\n"
1892 "#extension GL_ARB_separate_shader_objects : enable\n"
1893 "#extension GL_ARB_shading_language_420pack : enable\n"
1894 "layout (location = 0) out vec2 samplePos;\n"
1895 "void main() {\n"
1896 " vec2 vertices[3];"
1897 " vertices[0] = vec2(-0.5, -0.5);\n"
1898 " vertices[1] = vec2( 0.5, -0.5);\n"
1899 " vertices[2] = vec2( 0.5, 0.5);\n"
1900 " vec2 positions[3];"
1901 " positions[0] = vec2( 0.0, 0.0);\n"
1902 " positions[1] = vec2( 1.0, 0.0);\n"
1903 " positions[2] = vec2( 1.0, 1.0);\n"
1904 " samplePos = positions[gl_VertexID % 3];\n"
1905 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1906 "}\n";
1907
1908 static const char *fragShaderText =
1909 "#version 140\n"
1910 "#extension GL_ARB_separate_shader_objects : enable\n"
1911 "#extension GL_ARB_shading_language_420pack : enable\n"
1912 "layout (location = 0) in vec2 samplePos;\n"
1913 "layout (binding = 0) uniform sampler2D surface;\n"
1914 "layout (location=0) out vec4 outColor;\n"
1915 "void main() {\n"
1916 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1917 " outColor = texColor;\n"
1918 "}\n";
1919
1920 ASSERT_NO_FATAL_FAILURE(InitState());
1921 ASSERT_NO_FATAL_FAILURE(InitViewport());
1922
1923 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1924 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1925 XglSamplerObj sampler(m_device);
1926 XglTextureObj texture(m_device);
1927
Tony Barbourf43b6982014-11-25 13:18:32 -07001928 XglPipelineObj pipelineobj(m_device);
1929 pipelineobj.AddShader(&vs);
1930 pipelineobj.AddShader(&ps);
1931
1932 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001933 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001934
1935 m_memoryRefManager.AddMemoryRef(&texture);
1936
Tony Barbourdd4c9642015-01-09 12:55:14 -07001937 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1938 XglCommandBufferObj cmdBuffer(m_device);
1939 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1940
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001941 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001942
1943 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1944
1945#ifdef DUMP_STATE_DOT
1946 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1947 pDSDumpDot((char*)"triTest2.dot");
1948#endif
1949 // render triangle
1950 cmdBuffer.Draw(0, 3, 0, 1);
1951
1952 // finalize recording of the command buffer
1953 cmdBuffer.EndCommandBuffer();
1954 cmdBuffer.QueueCommandBuffer(NULL, 0);
1955
1956 for (int i = 0; i < m_renderTargetCount; i++)
1957 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001958}
1959TEST_F(XglRenderTest, TexturedTriangleClip)
1960{
1961 // The expected result from this test is a red and green checkered triangle
1962 static const char *vertShaderText =
1963 "#version 330\n"
1964 "#extension GL_ARB_separate_shader_objects : enable\n"
1965 "#extension GL_ARB_shading_language_420pack : enable\n"
1966 "layout (location = 0) out vec2 samplePos;\n"
1967 "out gl_PerVertex {\n"
1968 " vec4 gl_Position;\n"
1969 " float gl_ClipDistance[1];\n"
1970 "};\n"
1971 "void main() {\n"
1972 " vec2 vertices[3];"
1973 " vertices[0] = vec2(-0.5, -0.5);\n"
1974 " vertices[1] = vec2( 0.5, -0.5);\n"
1975 " vertices[2] = vec2( 0.5, 0.5);\n"
1976 " vec2 positions[3];"
1977 " positions[0] = vec2( 0.0, 0.0);\n"
1978 " positions[1] = vec2( 1.0, 0.0);\n"
1979 " positions[2] = vec2( 1.0, 1.0);\n"
1980 " float dists[3];\n"
1981 " dists[0] = 1.0;\n"
1982 " dists[1] = 1.0;\n"
1983 " dists[2] = -1.0;\n"
1984 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1985 " samplePos = positions[gl_VertexID % 3];\n"
1986 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1987 "}\n";
1988
1989 static const char *fragShaderText =
1990 "#version 140\n"
1991 "#extension GL_ARB_separate_shader_objects : enable\n"
1992 "#extension GL_ARB_shading_language_420pack : enable\n"
1993 "layout (location = 0) in vec2 samplePos;\n"
1994 "layout (binding = 0) uniform sampler2D surface;\n"
1995 "layout (location=0) out vec4 outColor;\n"
1996 "void main() {\n"
1997 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
1998 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1999 " outColor = texColor;\n"
2000 "}\n";
2001
2002
2003 ASSERT_NO_FATAL_FAILURE(InitState());
2004 ASSERT_NO_FATAL_FAILURE(InitViewport());
2005
2006 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2007 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2008 XglSamplerObj sampler(m_device);
2009 XglTextureObj texture(m_device);
2010
Tony Barbourf43b6982014-11-25 13:18:32 -07002011 XglPipelineObj pipelineobj(m_device);
2012 pipelineobj.AddShader(&vs);
2013 pipelineobj.AddShader(&ps);
2014
2015 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002016 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002017
2018 m_memoryRefManager.AddMemoryRef(&texture);
2019
Tony Barbourdd4c9642015-01-09 12:55:14 -07002020 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2021 XglCommandBufferObj cmdBuffer(m_device);
2022 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2023
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002024 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002025
2026 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2027
2028#ifdef DUMP_STATE_DOT
2029 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2030 pDSDumpDot((char*)"triTest2.dot");
2031#endif
2032 // render triangle
2033 cmdBuffer.Draw(0, 3, 0, 1);
2034
2035 // finalize recording of the command buffer
2036 cmdBuffer.EndCommandBuffer();
2037 cmdBuffer.QueueCommandBuffer(NULL, 0);
2038
2039 for (int i = 0; i < m_renderTargetCount; i++)
2040 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002041}
2042TEST_F(XglRenderTest, FSTriangle)
2043{
2044 // The expected result from this test is a red and green checkered triangle
2045 static const char *vertShaderText =
2046 "#version 140\n"
2047 "#extension GL_ARB_separate_shader_objects : enable\n"
2048 "#extension GL_ARB_shading_language_420pack : enable\n"
2049 "layout (location = 0) out vec2 samplePos;\n"
2050 "void main() {\n"
2051 " vec2 vertices[3];"
2052 " vertices[0] = vec2(-0.5, -0.5);\n"
2053 " vertices[1] = vec2( 0.5, -0.5);\n"
2054 " vertices[2] = vec2( 0.5, 0.5);\n"
2055 " vec2 positions[3];"
2056 " positions[0] = vec2( 0.0, 0.0);\n"
2057 " positions[1] = vec2( 1.0, 0.0);\n"
2058 " positions[2] = vec2( 1.0, 1.0);\n"
2059 " samplePos = positions[gl_VertexID % 3];\n"
2060 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2061 "}\n";
2062
2063 static const char *fragShaderText =
2064 "#version 140\n"
2065 "#extension GL_ARB_separate_shader_objects : enable\n"
2066 "#extension GL_ARB_shading_language_420pack : enable\n"
2067 "layout (location = 0) in vec2 samplePos;\n"
2068 "layout (binding = 0) uniform sampler2D surface;\n"
2069 "layout (location=0) out vec4 outColor;\n"
2070 "void main() {\n"
2071 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2072 " outColor = texColor;\n"
2073 "}\n";
2074
2075 ASSERT_NO_FATAL_FAILURE(InitState());
2076 ASSERT_NO_FATAL_FAILURE(InitViewport());
2077
2078 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2079 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2080 XglSamplerObj sampler(m_device);
2081 XglTextureObj texture(m_device);
2082
Tony Barbourf43b6982014-11-25 13:18:32 -07002083 XglPipelineObj pipelineobj(m_device);
2084 pipelineobj.AddShader(&vs);
2085 pipelineobj.AddShader(&ps);
2086
2087 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002088 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002089
2090 m_memoryRefManager.AddMemoryRef(&texture);
2091
Tony Barbourdd4c9642015-01-09 12:55:14 -07002092 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2093 XglCommandBufferObj cmdBuffer(m_device);
2094 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2095
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002096 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002097
2098 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2099
2100#ifdef DUMP_STATE_DOT
2101 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2102 pDSDumpDot((char*)"triTest2.dot");
2103#endif
2104 // render triangle
2105 cmdBuffer.Draw(0, 3, 0, 1);
2106
2107 // finalize recording of the command buffer
2108 cmdBuffer.EndCommandBuffer();
2109 cmdBuffer.QueueCommandBuffer(NULL, 0);
2110
2111 for (int i = 0; i < m_renderTargetCount; i++)
2112 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002113}
2114TEST_F(XglRenderTest, SamplerBindingsTriangle)
2115{
2116 // This test sets bindings on the samplers
2117 // For now we are asserting that sampler and texture pairs
2118 // march in lock step, and are set via GLSL binding. This can
2119 // and will probably change.
2120 // The sampler bindings should match the sampler and texture slot
2121 // number set up by the application.
2122 // This test will result in a blue triangle
2123 static const char *vertShaderText =
2124 "#version 140\n"
2125 "#extension GL_ARB_separate_shader_objects : enable\n"
2126 "#extension GL_ARB_shading_language_420pack : enable\n"
2127 "layout (location = 0) out vec4 samplePos;\n"
2128 "void main() {\n"
2129 " vec2 vertices[3];"
2130 " vertices[0] = vec2(-0.5, -0.5);\n"
2131 " vertices[1] = vec2( 0.5, -0.5);\n"
2132 " vertices[2] = vec2( 0.5, 0.5);\n"
2133 " vec2 positions[3];"
2134 " positions[0] = vec2( 0.0, 0.0);\n"
2135 " positions[1] = vec2( 1.0, 0.0);\n"
2136 " positions[2] = vec2( 1.0, 1.0);\n"
2137 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2138 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2139 "}\n";
2140
2141 static const char *fragShaderText =
2142 "#version 140\n"
2143 "#extension GL_ARB_separate_shader_objects : enable\n"
2144 "#extension GL_ARB_shading_language_420pack : enable\n"
2145 "layout (location = 0) in vec4 samplePos;\n"
2146 "layout (binding = 0) uniform sampler2D surface0;\n"
2147 "layout (binding = 1) uniform sampler2D surface1;\n"
2148 "layout (binding = 12) uniform sampler2D surface2;\n"
2149 "void main() {\n"
2150 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
2151 "}\n";
2152
2153 ASSERT_NO_FATAL_FAILURE(InitState());
2154 ASSERT_NO_FATAL_FAILURE(InitViewport());
2155
2156 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2157 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2158
2159 XglSamplerObj sampler1(m_device);
2160 XglSamplerObj sampler2(m_device);
2161 XglSamplerObj sampler3(m_device);
2162
2163 XglTextureObj texture1(m_device); // Red
2164 texture1.ChangeColors(0xffff0000,0xffff0000);
2165 XglTextureObj texture2(m_device); // Green
2166 texture2.ChangeColors(0xff00ff00,0xff00ff00);
2167 XglTextureObj texture3(m_device); // Blue
2168 texture3.ChangeColors(0xff0000ff,0xff0000ff);
2169
Tony Barbourf43b6982014-11-25 13:18:32 -07002170 XglPipelineObj pipelineobj(m_device);
2171 pipelineobj.AddShader(&vs);
2172 pipelineobj.AddShader(&ps);
2173
2174 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002175 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2176 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2177 for (int i = 0; i < 10; i++)
2178 descriptorSet.AppendDummy();
2179 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002180
2181 m_memoryRefManager.AddMemoryRef(&texture1);
2182 m_memoryRefManager.AddMemoryRef(&texture2);
2183 m_memoryRefManager.AddMemoryRef(&texture3);
2184
Tony Barbourdd4c9642015-01-09 12:55:14 -07002185 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2186 XglCommandBufferObj cmdBuffer(m_device);
2187 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2188
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002189 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002190
2191 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2192
2193#ifdef DUMP_STATE_DOT
2194 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2195 pDSDumpDot((char*)"triTest2.dot");
2196#endif
2197 // render triangle
2198 cmdBuffer.Draw(0, 3, 0, 1);
2199
2200 // finalize recording of the command buffer
2201 cmdBuffer.EndCommandBuffer();
2202 cmdBuffer.QueueCommandBuffer(NULL, 0);
2203
2204 for (int i = 0; i < m_renderTargetCount; i++)
2205 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002206
2207}
2208
2209TEST_F(XglRenderTest, TriangleVSUniformBlock)
2210{
2211 // The expected result from this test is a blue triangle
2212
2213 static const char *vertShaderText =
2214 "#version 140\n"
2215 "#extension GL_ARB_separate_shader_objects : enable\n"
2216 "#extension GL_ARB_shading_language_420pack : enable\n"
2217 "layout (location = 0) out vec4 outColor;\n"
2218 "layout (std140, binding = 0) uniform bufferVals {\n"
2219 " vec4 red;\n"
2220 " vec4 green;\n"
2221 " vec4 blue;\n"
2222 " vec4 white;\n"
2223 "} myBufferVals;\n"
2224 "void main() {\n"
2225 " vec2 vertices[3];"
2226 " vertices[0] = vec2(-0.5, -0.5);\n"
2227 " vertices[1] = vec2( 0.5, -0.5);\n"
2228 " vertices[2] = vec2( 0.5, 0.5);\n"
2229 " outColor = myBufferVals.blue;\n"
2230 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2231 "}\n";
2232
2233 static const char *fragShaderText =
2234 "#version 140\n"
2235 "#extension GL_ARB_separate_shader_objects : enable\n"
2236 "#extension GL_ARB_shading_language_420pack : enable\n"
2237 "layout (location = 0) in vec4 inColor;\n"
2238 "void main() {\n"
2239 " gl_FragColor = inColor;\n"
2240 "}\n";
2241
2242 ASSERT_NO_FATAL_FAILURE(InitState());
2243 ASSERT_NO_FATAL_FAILURE(InitViewport());
2244
2245 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2246 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2247
2248 // Let's populate our buffer with the following:
2249 // vec4 red;
2250 // vec4 green;
2251 // vec4 blue;
2252 // vec4 white;
2253 const int valCount = 4 * 4;
2254 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2255 0.0, 1.0, 0.0, 1.0,
2256 0.0, 0.0, 1.0, 1.0,
2257 1.0, 1.0, 1.0, 1.0 };
2258
2259 XglConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002260
2261 XglPipelineObj pipelineobj(m_device);
2262 pipelineobj.AddShader(&vs);
2263 pipelineobj.AddShader(&ps);
2264
2265 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002266 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002267
Tony Barbourdd4c9642015-01-09 12:55:14 -07002268 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2269 XglCommandBufferObj cmdBuffer(m_device);
2270 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2271
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002272 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002273
2274 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2275
2276#ifdef DUMP_STATE_DOT
2277 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2278 pDSDumpDot((char*)"triTest2.dot");
2279#endif
2280 // render triangle
2281 cmdBuffer.Draw(0, 3, 0, 1);
2282
2283 // finalize recording of the command buffer
2284 cmdBuffer.EndCommandBuffer();
2285 cmdBuffer.QueueCommandBuffer(NULL, 0);
2286
2287 for (int i = 0; i < m_renderTargetCount; i++)
2288 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002289
2290}
2291
2292TEST_F(XglRenderTest, TriangleFSUniformBlockBinding)
2293{
2294 // This test allows the shader to select which buffer it is
2295 // pulling from using layout binding qualifier.
2296 // There are corresponding changes in the compiler stack that
2297 // will select the buffer using binding directly.
2298 // The binding number should match the slot number set up by
2299 // the application.
2300 // The expected result from this test is a purple triangle
2301
2302 static const char *vertShaderText =
2303 "#version 140\n"
2304 "#extension GL_ARB_separate_shader_objects : enable\n"
2305 "#extension GL_ARB_shading_language_420pack : enable\n"
2306 "void main() {\n"
2307 " vec2 vertices[3];"
2308 " vertices[0] = vec2(-0.5, -0.5);\n"
2309 " vertices[1] = vec2( 0.5, -0.5);\n"
2310 " vertices[2] = vec2( 0.5, 0.5);\n"
2311 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2312 "}\n";
2313
2314 static const char *fragShaderText =
2315 "#version 140\n"
2316 "#extension GL_ARB_separate_shader_objects : enable\n"
2317 "#extension GL_ARB_shading_language_420pack : enable\n"
2318 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2319 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2320 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002321 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
Tony Barbourf43b6982014-11-25 13:18:32 -07002322 "void main() {\n"
2323 " gl_FragColor = myBlueVal.color;\n"
2324 " gl_FragColor += myRedVal.color;\n"
2325 "}\n";
2326
2327 ASSERT_NO_FATAL_FAILURE(InitState());
2328 ASSERT_NO_FATAL_FAILURE(InitViewport());
2329
2330 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2331 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2332
2333 // We're going to create a number of uniform buffers, and then allow
2334 // the shader to select which it wants to read from with a binding
2335
2336 // Let's populate the buffers with a single color each:
2337 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2338 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2339 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002340 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002341
2342 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2343 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2344 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2345 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2346
2347 const int redCount = sizeof(redVals) / sizeof(float);
2348 const int greenCount = sizeof(greenVals) / sizeof(float);
2349 const int blueCount = sizeof(blueVals) / sizeof(float);
2350 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2351
2352 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002353
2354 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002355
2356 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002357
2358 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002359
2360 XglPipelineObj pipelineobj(m_device);
2361 pipelineobj.AddShader(&vs);
2362 pipelineobj.AddShader(&ps);
2363
2364 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002365 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2366 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2367 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2368 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002369
Tony Barbourdd4c9642015-01-09 12:55:14 -07002370 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2371 XglCommandBufferObj cmdBuffer(m_device);
2372 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002373
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002374 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002375
2376 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2377
2378#ifdef DUMP_STATE_DOT
2379 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2380 pDSDumpDot((char*)"triTest2.dot");
2381#endif
2382 // render triangle
2383 cmdBuffer.Draw(0, 3, 0, 1);
2384
2385 // finalize recording of the command buffer
2386 cmdBuffer.EndCommandBuffer();
2387 cmdBuffer.QueueCommandBuffer(NULL, 0);
2388
2389 for (int i = 0; i < m_renderTargetCount; i++)
2390 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002391}
2392
2393TEST_F(XglRenderTest, TriangleFSAnonymousUniformBlockBinding)
2394{
2395 // This test is the same as TriangleFSUniformBlockBinding, but
2396 // it does not provide an instance name.
2397 // The expected result from this test is a purple triangle
2398
2399 static const char *vertShaderText =
2400 "#version 140\n"
2401 "#extension GL_ARB_separate_shader_objects : enable\n"
2402 "#extension GL_ARB_shading_language_420pack : enable\n"
2403 "void main() {\n"
2404 " vec2 vertices[3];"
2405 " vertices[0] = vec2(-0.5, -0.5);\n"
2406 " vertices[1] = vec2( 0.5, -0.5);\n"
2407 " vertices[2] = vec2( 0.5, 0.5);\n"
2408 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2409 "}\n";
2410
2411 static const char *fragShaderText =
2412 "#version 430\n"
2413 "#extension GL_ARB_separate_shader_objects : enable\n"
2414 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002415 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2416 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2417 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002418 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002419 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002420 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002421 " outColor = blue;\n"
2422 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002423 "}\n";
2424 ASSERT_NO_FATAL_FAILURE(InitState());
2425 ASSERT_NO_FATAL_FAILURE(InitViewport());
2426
2427 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2428 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2429
2430 // We're going to create a number of uniform buffers, and then allow
2431 // the shader to select which it wants to read from with a binding
2432
2433 // Let's populate the buffers with a single color each:
2434 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2435 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2436 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2437 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2438
2439 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2440 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2441 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2442 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2443
2444 const int redCount = sizeof(redVals) / sizeof(float);
2445 const int greenCount = sizeof(greenVals) / sizeof(float);
2446 const int blueCount = sizeof(blueVals) / sizeof(float);
2447 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2448
2449 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002450
2451 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002452
2453 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002454
2455 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002456
2457 XglPipelineObj pipelineobj(m_device);
2458 pipelineobj.AddShader(&vs);
2459 pipelineobj.AddShader(&ps);
2460
2461 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002462 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2463 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2464 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2465 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002466
Tony Barbourdd4c9642015-01-09 12:55:14 -07002467 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2468 XglCommandBufferObj cmdBuffer(m_device);
2469 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2470
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002471 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002472
2473 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2474
2475#ifdef DUMP_STATE_DOT
2476 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2477 pDSDumpDot((char*)"triTest2.dot");
2478#endif
2479 // render triangle
2480 cmdBuffer.Draw(0, 3, 0, 1);
2481
2482 // finalize recording of the command buffer
2483 cmdBuffer.EndCommandBuffer();
2484 cmdBuffer.QueueCommandBuffer(NULL, 0);
2485
2486 for (int i = 0; i < m_renderTargetCount; i++)
2487 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002488
2489}
2490
2491TEST_F(XglRenderTest, CubeWithVertexFetchAndMVPAndTexture)
2492{
2493 static const char *vertShaderText =
2494 "#version 140\n"
2495 "#extension GL_ARB_separate_shader_objects : enable\n"
2496 "#extension GL_ARB_shading_language_420pack : enable\n"
2497 "layout (std140, binding=0) uniform bufferVals {\n"
2498 " mat4 mvp;\n"
2499 "} myBufferVals;\n"
2500 "layout (location=0) in vec4 pos;\n"
2501 "layout (location=0) out vec2 UV;\n"
2502 "void main() {\n"
2503 " vec2 positions[3];"
2504 " positions[0] = vec2( 0.0, 0.0);\n"
2505 " positions[1] = vec2( 0.25, 0.1);\n"
2506 " positions[2] = vec2( 0.1, 0.25);\n"
2507 " UV = positions[gl_VertexID % 3];\n"
2508 " gl_Position = myBufferVals.mvp * pos;\n"
2509 "}\n";
2510
2511 static const char *fragShaderText =
2512 "#version 140\n"
2513 "#extension GL_ARB_separate_shader_objects : enable\n"
2514 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002515 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002516 "layout (location=0) out vec4 outColor;\n"
2517 "layout (location=0) in vec2 UV;\n"
2518 "void main() {\n"
2519 " outColor= textureLod(surface, UV, 0.0);\n"
2520 "}\n";
2521 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2522
2523 glm::mat4 View = glm::lookAt(
2524 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2525 glm::vec3(0,0,0), // and looks at the origin
2526 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2527 );
2528
2529 glm::mat4 Model = glm::mat4(1.0f);
2530
2531 glm::mat4 MVP = Projection * View * Model;
2532
2533
2534 ASSERT_NO_FATAL_FAILURE(InitState());
2535 ASSERT_NO_FATAL_FAILURE(InitViewport());
2536 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
2537
2538 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
2539 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002540 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002541
2542 const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT);
2543
2544 XglConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2545 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2546 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2547 XglSamplerObj sampler(m_device);
2548 XglTextureObj texture(m_device);
2549
Tony Barbourf43b6982014-11-25 13:18:32 -07002550 XglPipelineObj pipelineobj(m_device);
2551 pipelineobj.AddShader(&vs);
2552 pipelineobj.AddShader(&ps);
2553
2554 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002555 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mvpBuffer);
2556 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002557
2558 m_memoryRefManager.AddMemoryRef(&meshBuffer);
2559 m_memoryRefManager.AddMemoryRef(&mvpBuffer);
2560 m_memoryRefManager.AddMemoryRef(&texture);
2561
2562 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
2563 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
2564 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
2565 };
2566
2567 // this is the current description of g_vbData
2568 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
2569 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
2570 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
2571 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
2572 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2573 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
2574 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
2575 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
2576 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
2577
2578 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2579 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
2580 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
2581
Tony Barbourfa6cac72015-01-16 14:27:35 -07002582 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
2583 ds_state.depthTestEnable = XGL_TRUE;
2584 ds_state.depthWriteEnable = XGL_TRUE;
2585 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
2586 ds_state.depthBoundsEnable = XGL_FALSE;
2587 ds_state.stencilTestEnable = XGL_FALSE;
2588 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
2589 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
2590 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
2591 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
2592 ds_state.format.channelFormat = XGL_CH_FMT_R32;
2593 ds_state.format.numericFormat = XGL_NUM_FMT_DS;
2594 ds_state.front = ds_state.back;
2595 pipelineobj.SetDepthStencil(&ds_state);
2596
Tony Barbourdd4c9642015-01-09 12:55:14 -07002597 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2598 XglCommandBufferObj cmdBuffer(m_device);
2599 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002600
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002601 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002602 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2603
2604 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2605#ifdef DUMP_STATE_DOT
2606 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2607 pDSDumpDot((char*)"triTest2.dot");
2608#endif
2609 // render triangle
2610 cmdBuffer.Draw(0, 36, 0, 1);
2611
2612 // finalize recording of the command buffer
2613 cmdBuffer.EndCommandBuffer();
2614 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
2615
2616 for (int i = 0; i < m_renderTargetCount; i++)
2617 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002618
2619}
Cody Northropd1ce7842014-12-09 11:17:01 -07002620
2621TEST_F(XglRenderTest, TriangleMixedSamplerUniformBlockBinding)
2622{
2623 // This test mixes binding slots of textures and buffers, ensuring
2624 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002625 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002626 // you can modify it to move the desired result around.
2627
2628 static const char *vertShaderText =
2629 "#version 140\n"
2630 "#extension GL_ARB_separate_shader_objects : enable\n"
2631 "#extension GL_ARB_shading_language_420pack : enable\n"
2632 "void main() {\n"
2633 " vec2 vertices[3];"
2634 " vertices[0] = vec2(-0.5, -0.5);\n"
2635 " vertices[1] = vec2( 0.5, -0.5);\n"
2636 " vertices[2] = vec2( 0.5, 0.5);\n"
2637 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2638 "}\n";
2639
2640 static const char *fragShaderText =
2641 "#version 430\n"
2642 "#extension GL_ARB_separate_shader_objects : enable\n"
2643 "#extension GL_ARB_shading_language_420pack : enable\n"
2644 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002645 "layout (binding = 3) uniform sampler2D surface1;\n"
2646 "layout (binding = 1) uniform sampler2D surface2;\n"
2647 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002648
Cody Northropa0410942014-12-09 13:59:39 -07002649
Chia-I Wuf8385062015-01-04 16:27:24 +08002650 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2651 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2652 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2653 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002654 "layout (location = 0) out vec4 outColor;\n"
2655 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002656 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002657 " outColor += white * vec4(0.00001);\n"
2658 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002659 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002660 "}\n";
2661 ASSERT_NO_FATAL_FAILURE(InitState());
2662 ASSERT_NO_FATAL_FAILURE(InitViewport());
2663
2664 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2665 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2666
Cody Northropd1ce7842014-12-09 11:17:01 -07002667 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2668 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2669 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2670 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2671
2672 const int redCount = sizeof(redVals) / sizeof(float);
2673 const int greenCount = sizeof(greenVals) / sizeof(float);
2674 const int blueCount = sizeof(blueVals) / sizeof(float);
2675 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2676
2677 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002678 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002679 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002680 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002681
2682 XglSamplerObj sampler0(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002683 XglTextureObj texture0(m_device); // Light Red
2684 texture0.ChangeColors(0xff800000,0xff800000);
Cody Northropd1ce7842014-12-09 11:17:01 -07002685 XglSamplerObj sampler2(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002686 XglTextureObj texture2(m_device); // Light Blue
2687 texture2.ChangeColors(0xff000080,0xff000080);
Cody Northropd1ce7842014-12-09 11:17:01 -07002688 XglSamplerObj sampler4(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002689 XglTextureObj texture4(m_device); // Light Green
2690 texture4.ChangeColors(0xff008000,0xff008000);
Cody Northropa0410942014-12-09 13:59:39 -07002691
2692 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2693 // TODO: Get back here ASAP and understand why.
2694 XglSamplerObj sampler7(m_device);
2695 XglTextureObj texture7(m_device); // Red and Blue
2696 texture7.ChangeColors(0xffff00ff,0xffff00ff);
Cody Northropd1ce7842014-12-09 11:17:01 -07002697
2698 XglPipelineObj pipelineobj(m_device);
2699 pipelineobj.AddShader(&vs);
2700 pipelineobj.AddShader(&ps);
2701
2702 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002703 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2704 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2705 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2706 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2707 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2708 // swap blue and green
2709 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2710 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2711 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002712
2713 m_memoryRefManager.AddMemoryRef(&texture0);
2714 m_memoryRefManager.AddMemoryRef(&texture2);
2715 m_memoryRefManager.AddMemoryRef(&texture4);
Cody Northropa0410942014-12-09 13:59:39 -07002716 m_memoryRefManager.AddMemoryRef(&texture7);
Cody Northropd1ce7842014-12-09 11:17:01 -07002717
Tony Barbourdd4c9642015-01-09 12:55:14 -07002718 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2719 XglCommandBufferObj cmdBuffer(m_device);
2720 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002721
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002722 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002723
2724 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2725
2726#ifdef DUMP_STATE_DOT
2727 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2728 pDSDumpDot((char*)"triTest2.dot");
2729#endif
2730 // render triangle
2731 cmdBuffer.Draw(0, 3, 0, 1);
2732
2733 // finalize recording of the command buffer
2734 cmdBuffer.EndCommandBuffer();
2735 cmdBuffer.QueueCommandBuffer(NULL, 0);
2736
2737 for (int i = 0; i < m_renderTargetCount; i++)
2738 RecordImage(m_renderTargets[i]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002739
2740}
2741
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002742TEST_F(XglRenderTest, TriangleMatchingSamplerUniformBlockBinding)
2743{
2744 // This test matches binding slots of textures and buffers, requiring
2745 // the driver to give them distinct number spaces.
2746 // The expected result from this test is a red triangle, although
2747 // you can modify it to move the desired result around.
2748
2749 static const char *vertShaderText =
2750 "#version 140\n"
2751 "#extension GL_ARB_separate_shader_objects : enable\n"
2752 "#extension GL_ARB_shading_language_420pack : enable\n"
2753 "void main() {\n"
2754 " vec2 vertices[3];"
2755 " vertices[0] = vec2(-0.5, -0.5);\n"
2756 " vertices[1] = vec2( 0.5, -0.5);\n"
2757 " vertices[2] = vec2( 0.5, 0.5);\n"
2758 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2759 "}\n";
2760
2761 static const char *fragShaderText =
2762 "#version 430\n"
2763 "#extension GL_ARB_separate_shader_objects : enable\n"
2764 "#extension GL_ARB_shading_language_420pack : enable\n"
2765 "layout (binding = 0) uniform sampler2D surface0;\n"
2766 "layout (binding = 1) uniform sampler2D surface1;\n"
2767 "layout (binding = 2) uniform sampler2D surface2;\n"
2768 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002769 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2770 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2771 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2772 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002773 "layout (location = 0) out vec4 outColor;\n"
2774 "void main() {\n"
2775 " outColor = red;// * vec4(0.00001);\n"
2776 " outColor += white * vec4(0.00001);\n"
2777 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2778 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2779 "}\n";
2780 ASSERT_NO_FATAL_FAILURE(InitState());
2781 ASSERT_NO_FATAL_FAILURE(InitViewport());
2782
2783 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2784 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2785
2786 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2787 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2788 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2789 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2790
2791 const int redCount = sizeof(redVals) / sizeof(float);
2792 const int greenCount = sizeof(greenVals) / sizeof(float);
2793 const int blueCount = sizeof(blueVals) / sizeof(float);
2794 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2795
2796 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002797 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002798 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002799 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002800
2801 XglSamplerObj sampler0(m_device);
2802 XglTextureObj texture0(m_device); // Light Red
2803 texture0.ChangeColors(0xff800000,0xff800000);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002804 XglSamplerObj sampler2(m_device);
2805 XglTextureObj texture2(m_device); // Light Blue
2806 texture2.ChangeColors(0xff000080,0xff000080);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002807 XglSamplerObj sampler4(m_device);
2808 XglTextureObj texture4(m_device); // Light Green
2809 texture4.ChangeColors(0xff008000,0xff008000);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002810 XglSamplerObj sampler7(m_device);
2811 XglTextureObj texture7(m_device); // Red and Blue
2812 texture7.ChangeColors(0xffff00ff,0xffff00ff);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002813
2814
2815 XglPipelineObj pipelineobj(m_device);
2816 pipelineobj.AddShader(&vs);
2817 pipelineobj.AddShader(&ps);
2818
2819 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002820 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2821 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2822 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2823 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2824 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2825 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2826 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2827 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002828
2829 m_memoryRefManager.AddMemoryRef(&texture0);
2830 m_memoryRefManager.AddMemoryRef(&texture2);
2831 m_memoryRefManager.AddMemoryRef(&texture4);
2832 m_memoryRefManager.AddMemoryRef(&texture7);
2833
Tony Barbourdd4c9642015-01-09 12:55:14 -07002834 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2835 XglCommandBufferObj cmdBuffer(m_device);
2836 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002837
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002838 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002839
2840 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2841
2842#ifdef DUMP_STATE_DOT
2843 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2844 pDSDumpDot((char*)"triTest2.dot");
2845#endif
2846 // render triangle
2847 cmdBuffer.Draw(0, 3, 0, 1);
2848
2849 // finalize recording of the command buffer
2850 cmdBuffer.EndCommandBuffer();
2851 cmdBuffer.QueueCommandBuffer(NULL, 0);
2852
2853 for (int i = 0; i < m_renderTargetCount; i++)
2854 RecordImage(m_renderTargets[i]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002855
2856}
2857
Cody Northrop02690bd2014-12-17 15:26:33 -07002858TEST_F(XglRenderTest, TriangleUniformBufferLayout)
2859{
2860 // This test populates a buffer with a variety of different data
2861 // types, then reads them out with a shader.
2862 // The expected result from this test is a green triangle
2863
2864 static const char *vertShaderText =
2865 "#version 140\n"
2866 "#extension GL_ARB_separate_shader_objects : enable\n"
2867 "#extension GL_ARB_shading_language_420pack : enable\n"
2868 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2869 " vec4 fRed;\n"
2870 " vec4 fGreen;\n"
2871 " layout(row_major) mat4 worldToProj;\n"
2872 " layout(row_major) mat4 projToWorld;\n"
2873 " layout(row_major) mat4 worldToView;\n"
2874 " layout(row_major) mat4 viewToProj;\n"
2875 " layout(row_major) mat4 worldToShadow[4];\n"
2876 " float fZero;\n"
2877 " float fOne;\n"
2878 " float fTwo;\n"
2879 " float fThree;\n"
2880 " vec3 fZeroZeroZero;\n"
2881 " float fFour;\n"
2882 " vec3 fZeroZeroOne;\n"
2883 " float fFive;\n"
2884 " vec3 fZeroOneZero;\n"
2885 " float fSix;\n"
2886 " float fSeven;\n"
2887 " float fEight;\n"
2888 " float fNine;\n"
2889 " vec2 fZeroZero;\n"
2890 " vec2 fZeroOne;\n"
2891 " vec4 fBlue;\n"
2892 " vec2 fOneZero;\n"
2893 " vec2 fOneOne;\n"
2894 " vec3 fZeroOneOne;\n"
2895 " float fTen;\n"
2896 " float fEleven;\n"
2897 " float fTwelve;\n"
2898 " vec3 fOneZeroZero;\n"
2899 " vec4 uvOffsets[4];\n"
2900 "};\n"
2901 "layout (location = 0) out vec4 color;"
2902 "void main() {\n"
2903
2904 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2905 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2906 " \n"
2907
2908 // do some exact comparisons, even though we should
2909 // really have an epsilon involved.
2910 " vec4 outColor = right;\n"
2911 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
2912 " outColor = wrong;\n"
2913 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
2914 " outColor = wrong;\n"
2915 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
2916 " outColor = wrong;\n"
2917
2918 " color = outColor;\n"
2919
2920 // generic position stuff
2921 " vec2 vertices;\n"
2922 " int vertexSelector = gl_VertexID;\n"
2923 " if (vertexSelector == 0)\n"
2924 " vertices = vec2(-0.5, -0.5);\n"
2925 " else if (vertexSelector == 1)\n"
2926 " vertices = vec2( 0.5, -0.5);\n"
2927 " else if (vertexSelector == 2)\n"
2928 " vertices = vec2( 0.5, 0.5);\n"
2929 " else\n"
2930 " vertices = vec2( 0.0, 0.0);\n"
2931 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
2932 "}\n";
2933
2934 static const char *fragShaderText =
2935 "#version 140\n"
2936 "#extension GL_ARB_separate_shader_objects : enable\n"
2937 "#extension GL_ARB_shading_language_420pack : enable\n"
2938 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2939 " vec4 fRed;\n"
2940 " vec4 fGreen;\n"
2941 " layout(row_major) mat4 worldToProj;\n"
2942 " layout(row_major) mat4 projToWorld;\n"
2943 " layout(row_major) mat4 worldToView;\n"
2944 " layout(row_major) mat4 viewToProj;\n"
2945 " layout(row_major) mat4 worldToShadow[4];\n"
2946 " float fZero;\n"
2947 " float fOne;\n"
2948 " float fTwo;\n"
2949 " float fThree;\n"
2950 " vec3 fZeroZeroZero;\n"
2951 " float fFour;\n"
2952 " vec3 fZeroZeroOne;\n"
2953 " float fFive;\n"
2954 " vec3 fZeroOneZero;\n"
2955 " float fSix;\n"
2956 " float fSeven;\n"
2957 " float fEight;\n"
2958 " float fNine;\n"
2959 " vec2 fZeroZero;\n"
2960 " vec2 fZeroOne;\n"
2961 " vec4 fBlue;\n"
2962 " vec2 fOneZero;\n"
2963 " vec2 fOneOne;\n"
2964 " vec3 fZeroOneOne;\n"
2965 " float fTen;\n"
2966 " float fEleven;\n"
2967 " float fTwelve;\n"
2968 " vec3 fOneZeroZero;\n"
2969 " vec4 uvOffsets[4];\n"
2970 "};\n"
2971 "layout (location = 0) in vec4 color;\n"
2972 "void main() {\n"
2973 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2974 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2975 " \n"
2976
2977 // start with VS value to ensure it passed
2978 " vec4 outColor = color;\n"
2979
2980 // do some exact comparisons, even though we should
2981 // really have an epsilon involved.
2982 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
2983 " outColor = wrong;\n"
2984 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
2985 " outColor = wrong;\n"
2986 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
2987 " outColor = wrong;\n"
2988 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
2989 " outColor = wrong;\n"
2990 " if (fTwo != 2.0)\n"
2991 " outColor = wrong;\n"
2992 " if (fOneOne != vec2(1.0, 1.0))\n"
2993 " outColor = wrong;\n"
2994 " if (fTen != 10.0)\n"
2995 " outColor = wrong;\n"
2996 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
2997 " outColor = wrong;\n"
2998 " \n"
2999 " gl_FragColor = outColor;\n"
3000 "}\n";
3001
3002
3003 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3004 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3005 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3006 0.0, 1.0, 0.0, 1.0, // align
3007 0.0, 0.0, 1.0, 1.0, // align
3008 0.0, 0.0, 0.0, 1.0, // align
3009 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3010 0.0, 2.0, 0.0, 2.0, // align
3011 0.0, 0.0, 2.0, 2.0, // align
3012 0.0, 0.0, 0.0, 2.0, // align
3013 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3014 0.0, 3.0, 0.0, 3.0, // align
3015 0.0, 0.0, 3.0, 3.0, // align
3016 0.0, 0.0, 0.0, 3.0, // align
3017 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3018 0.0, 4.0, 0.0, 4.0, // align
3019 0.0, 0.0, 4.0, 4.0, // align
3020 0.0, 0.0, 0.0, 4.0, // align
3021 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3022 0.0, 5.0, 0.0, 5.0, // align
3023 0.0, 0.0, 5.0, 5.0, // align
3024 0.0, 0.0, 0.0, 5.0, // align
3025 6.0, 0.0, 0.0, 6.0, // align
3026 0.0, 6.0, 0.0, 6.0, // align
3027 0.0, 0.0, 6.0, 6.0, // align
3028 0.0, 0.0, 0.0, 6.0, // align
3029 7.0, 0.0, 0.0, 7.0, // align
3030 0.0, 7.0, 0.0, 7.0, // align
3031 0.0, 0.0, 7.0, 7.0, // align
3032 0.0, 0.0, 0.0, 7.0, // align
3033 8.0, 0.0, 0.0, 8.0, // align
3034 0.0, 8.0, 0.0, 8.0, // align
3035 0.0, 0.0, 8.0, 8.0, // align
3036 0.0, 0.0, 0.0, 8.0, // align
3037 0.0, // float fZero; // align
3038 1.0, // float fOne; // pack
3039 2.0, // float fTwo; // pack
3040 3.0, // float fThree; // pack
3041 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3042 4.0, // float fFour; // pack
3043 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3044 5.0, // float fFive; // pack
3045 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3046 6.0, // float fSix; // pack
3047 7.0, // float fSeven; // align
3048 8.0, // float fEight; // pack
3049 9.0, // float fNine; // pack
3050 0.0, // BUFFER
3051 0.0, 0.0, // vec2 fZeroZero; // align
3052 0.0, 1.0, // vec2 fZeroOne; // pack
3053 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3054 1.0, 0.0, // vec2 fOneZero; // align
3055 1.0, 1.0, // vec2 fOneOne; // pack
3056 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3057 10.0, // float fTen; // pack
3058 11.0, // float fEleven; // align
3059 12.0, // float fTwelve; // pack
3060 0.0, 0.0, // BUFFER
3061 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3062 0.0, // BUFFER
3063 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3064 0.5, 0.6, 0.7, 0.8, // align
3065 0.9, 1.0, 1.1, 1.2, // align
3066 1.3, 1.4, 1.5, 1.6, // align
3067 };
3068
3069 ASSERT_NO_FATAL_FAILURE(InitState());
3070 ASSERT_NO_FATAL_FAILURE(InitViewport());
3071
3072 const int constCount = sizeof(mixedVals) / sizeof(float);
3073
3074 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
3075 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
3076
3077 XglConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003078
3079 XglPipelineObj pipelineobj(m_device);
3080 pipelineobj.AddShader(&vs);
3081 pipelineobj.AddShader(&ps);
3082
3083 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08003084 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003085
3086 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3087 XglCommandBufferObj cmdBuffer(m_device);
3088 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3089
Jeremy Hayese0c3b222015-01-14 16:17:08 -07003090 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Cody Northrop02690bd2014-12-17 15:26:33 -07003091
3092 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
3093
3094#ifdef DUMP_STATE_DOT
3095 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
3096 pDSDumpDot((char*)"triTest2.dot");
3097#endif
3098 // render triangle
3099 cmdBuffer.Draw(0, 3, 0, 1);
3100
3101 // finalize recording of the command buffer
3102 cmdBuffer.EndCommandBuffer();
3103 cmdBuffer.QueueCommandBuffer(NULL, 0);
3104
3105 for (int i = 0; i < m_renderTargetCount; i++)
3106 RecordImage(m_renderTargets[i]);
3107}
3108
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003109int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003110 int result;
3111
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003112 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003113 XglTestFramework::InitArgs(&argc, argv);
3114
Chia-I Wu7133fdc2014-12-15 23:57:34 +08003115 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06003116
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003117 result = RUN_ALL_TESTS();
3118
3119 XglTestFramework::Finish();
3120 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003121}