blob: ac188810ed3d42ac336f2359c814e50f5d2d5d88 [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
75#include "xgldevice.h"
Courtney Goeltzenleuchter04814f82014-09-01 16:37:18 -060076#include "xglimage.h"
Chia-I Wu4115c892014-08-28 11:56:29 +080077#include "icd-bil.h"
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060078
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -060079#define GLM_FORCE_RADIANS
80#include "glm/glm.hpp"
81#include <glm/gtc/matrix_transform.hpp>
82
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -060083#include "xglrenderframework.h"
Tobin Ehlis791a49c2014-11-10 12:29:12 -070084#ifdef DEBUG_CALLBACK
85XGL_VOID XGLAPI myDbgFunc(
86 XGL_DBG_MSG_TYPE msgType,
87 XGL_VALIDATION_LEVEL validationLevel,
88 XGL_BASE_OBJECT srcObject,
89 XGL_SIZE location,
90 XGL_INT msgCode,
91 const XGL_CHAR* pMsg,
92 XGL_VOID* pUserData)
93{
Tobin Ehlis3c26a542014-11-18 11:28:33 -070094 switch (msgType)
95 {
96 case XGL_DBG_MSG_WARNING:
97 printf("CALLBACK WARNING : %s\n", pMsg);
98 break;
99 case XGL_DBG_MSG_ERROR:
100 printf("CALLBACK ERROR : %s\n", pMsg);
101 break;
102 default:
103 printf("EATING Msg of type %u\n", msgType);
104 break;
105 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700106}
107#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700108
109
110#undef ASSERT_NO_FATAL_FAILURE
111#define ASSERT_NO_FATAL_FAILURE(x) x
112
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600113//--------------------------------------------------------------------------------------
114// Mesh and VertexFormat Data
115//--------------------------------------------------------------------------------------
116struct Vertex
117{
118 XGL_FLOAT posX, posY, posZ, posW; // Position data
119 XGL_FLOAT r, g, b, a; // Color
120};
121
122#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
123
124static const Vertex g_vbData[] =
125{
126 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
127 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
128 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
129 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
130 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
131 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
132
133 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
134 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
135 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
136 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
137 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
138 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
139
140 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
141 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
142 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
143 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
144 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
145 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
146
147 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
148 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
149 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
150 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
151 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
152 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
153
154 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
155 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
156 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
157 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
158 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
159 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
160
161 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
162 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
163 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
164 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
165 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
166 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
167};
168
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600169static const Vertex g_vb_solid_face_colors_Data[] =
170{
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 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
176 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
177
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 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
183 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
184
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 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
190 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
191
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 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
197 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
198
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 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
204 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
205
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 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
211 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
212};
213
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600214class XglRenderTest : public XglRenderFramework
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -0600215{
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600216public:
Cody Northrop4e6b4762014-10-09 21:25:22 -0600217
Tony Barbourf43b6982014-11-25 13:18:32 -0700218 void DrawTriangleTest(const char *vertShaderText, const char *fragShaderText);
219 void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbour09da2212014-12-03 16:13:23 -0700220 XglConstantBufferObj *constantBuffer);
Tony Barboura3953b82014-12-03 15:46:29 -0700221 void GenericDrawTriangleTest(XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet, int numTris);
Tony Barbourf43b6982014-11-25 13:18:32 -0700222 void QueueCommandBuffer(XGL_MEMORY_REF *memRefs, XGL_UINT32 numMemRefs);
223
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600224 void InitDepthStencil();
Courtney Goeltzenleuchterd04e38c2014-10-22 18:02:30 -0600225 void GenerateClearAndPrepareBufferCmds();
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600226 void XGLTriangleTest(const char *vertShaderText, const char *fragShaderText);
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600227
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600228
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600229protected:
Cody Northrop350727b2014-10-06 15:42:00 -0600230 XGL_IMAGE m_texture;
231 XGL_IMAGE_VIEW m_textureView;
232 XGL_IMAGE_VIEW_ATTACH_INFO m_textureViewInfo;
233 XGL_GPU_MEMORY m_textureMem;
234
235 XGL_SAMPLER m_sampler;
236
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600237 XGL_FORMAT m_depth_stencil_fmt;
238 XGL_IMAGE m_depthStencilImage;
239 XGL_GPU_MEMORY m_depthStencilMem;
240 XGL_DEPTH_STENCIL_VIEW m_depthStencilView;
Tony Barbourf43b6982014-11-25 13:18:32 -0700241 XglMemoryRefManager m_memoryRefManager;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600242
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600243
244 virtual void SetUp() {
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600245
246 this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO;
247 this->app_info.pNext = NULL;
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600248 this->app_info.pAppName = (const XGL_CHAR *) "render_tests";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600249 this->app_info.appVersion = 1;
250 this->app_info.pEngineName = (const XGL_CHAR *) "unittest";
251 this->app_info.engineVersion = 1;
252 this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0);
253
Cody Northrop350727b2014-10-06 15:42:00 -0600254 memset(&m_textureViewInfo, 0, sizeof(m_textureViewInfo));
255 m_textureViewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO;
Tony Barbour97a36232014-12-04 17:14:45 -0700256 memset(&m_depthStencilImage, 0, sizeof(m_depthStencilImage));
Cody Northrop350727b2014-10-06 15:42:00 -0600257
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600258 InitFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600259 }
260
261 virtual void TearDown() {
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600262 // Clean up resources before we reset
263 ShutdownFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600264 }
265};
266
Tony Barbourf43b6982014-11-25 13:18:32 -0700267
Tony Barboura3953b82014-12-03 15:46:29 -0700268void XglRenderTest::GenericDrawTriangleTest(XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet,int numTris)
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600269{
270 XGL_RESULT err = XGL_SUCCESS;
271
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600272 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600273 // Build command buffer
274 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
275 ASSERT_XGL_SUCCESS(err);
276
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600277 GenerateClearAndPrepareBufferCmds();
278 GenerateBindRenderTargetCmd();
Tobin Ehlis31446e52014-11-28 11:17:19 -0700279#ifdef DUMP_STATE_DOT
280 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
281 pDSDumpDot((char*)"triTest.dot");
282#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700283 GenerateBindStateAndPipelineCmds();
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600284
Tony Barboura3953b82014-12-03 15:46:29 -0700285 pipelineobj->BindPipelineCommandBuffer(m_cmdBuffer,descriptorSet);
Tony Barbourbf678472014-12-03 13:58:15 -0700286 descriptorSet->BindCommandBuffer(m_cmdBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700287
288 // render the triangle
289 xglCmdDraw( m_cmdBuffer, 0, 3*numTris, 0, 1 );
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600290
291 // finalize recording of the command buffer
292 err = xglEndCommandBuffer( m_cmdBuffer );
293 ASSERT_XGL_SUCCESS( err );
Tony Barbourf43b6982014-11-25 13:18:32 -0700294}
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600295
Tony Barbourf43b6982014-11-25 13:18:32 -0700296void XglRenderTest::QueueCommandBuffer(XGL_MEMORY_REF *memRefs, XGL_UINT32 numMemRefs)
297{
298 XGL_RESULT err = XGL_SUCCESS;
Chia-I Wue7748802014-12-05 10:45:15 +0800299 XGL_UINT i;
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600300
301 // submit the command buffer to the universal queue
Tony Barbourf43b6982014-11-25 13:18:32 -0700302 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, numMemRefs, memRefs, NULL );
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600303 ASSERT_XGL_SUCCESS( err );
304
Chia-I Wuf34ac502014-08-27 14:58:05 +0800305 err = xglQueueWaitIdle( m_device->m_queue );
306 ASSERT_XGL_SUCCESS( err );
307
Courtney Goeltzenleuchter68cfe612014-08-26 18:16:41 -0600308 // Wait for work to finish before cleaning up.
309 xglDeviceWaitIdle(m_device->device());
310
Chia-I Wue7748802014-12-05 10:45:15 +0800311 for (i = 0; i < m_renderTargetCount; i++)
312 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600313}
314
Tony Barbourf43b6982014-11-25 13:18:32 -0700315void XglRenderTest::DrawTriangleTest(const char *vertShaderText, const char *fragShaderText)
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600316{
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600317 XGL_RESULT err;
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600318
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600319 ASSERT_NO_FATAL_FAILURE(InitState());
320 ASSERT_NO_FATAL_FAILURE(InitViewport());
321
Tony Barbourf43b6982014-11-25 13:18:32 -0700322 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
323 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600324
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600325
Tony Barbourf43b6982014-11-25 13:18:32 -0700326 XglPipelineObj pipelineobj(m_device);
327 pipelineobj.AddShader(&vs);
328 pipelineobj.AddShader(&ps);
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600329
330 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
331
Tony Barbourf43b6982014-11-25 13:18:32 -0700332 // Create descriptor set
333 XglDescriptorSetObj descriptorSet(m_device);
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600334
335 // Build command buffer
336 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
337 ASSERT_XGL_SUCCESS(err);
338
339 GenerateClearAndPrepareBufferCmds();
340 GenerateBindRenderTargetCmd();
Tony Barbourf43b6982014-11-25 13:18:32 -0700341 GenerateBindStateAndPipelineCmds();
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600342
Tobin Ehlis31446e52014-11-28 11:17:19 -0700343#ifdef DUMP_STATE_DOT
344 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
345 pDSDumpDot((char*)"triUniFS.dot");
346#endif
Tony Barbourbf678472014-12-03 13:58:15 -0700347 pipelineobj.BindPipelineCommandBuffer(m_cmdBuffer,&descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -0700348 descriptorSet.BindCommandBuffer(m_cmdBuffer);
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600349
Tony Barbourf43b6982014-11-25 13:18:32 -0700350 // render the triangle
351 xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 );
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600352
353 // finalize recording of the command buffer
354 err = xglEndCommandBuffer( m_cmdBuffer );
355 ASSERT_XGL_SUCCESS( err );
356
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600357 // submit the command buffer to the universal queue
Tony Barbour75420772014-12-04 17:17:26 -0700358 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, 0, m_memRefs, NULL );
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600359 ASSERT_XGL_SUCCESS( err );
360
361 err = xglQueueWaitIdle( m_device->m_queue );
362 ASSERT_XGL_SUCCESS( err );
363
364 // Wait for work to finish before cleaning up.
365 xglDeviceWaitIdle(m_device->device());
366
Chia-I Wue7748802014-12-05 10:45:15 +0800367 assert(m_renderTargetCount == 1);
368 RecordImage(m_renderTargets[0]);
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600369
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600370}
371
Tony Barbourf43b6982014-11-25 13:18:32 -0700372void XglRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbour09da2212014-12-03 16:13:23 -0700373 XglConstantBufferObj *constantBuffer)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600374{
375 int i;
376 glm::mat4 MVP;
377 int matrixSize = sizeof(MVP);
378 XGL_RESULT err;
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600379
380 for (i = 0; i < 8; i++) {
381 XGL_UINT8 *pData;
Tony Barbour09da2212014-12-03 16:13:23 -0700382 err = xglMapMemory(constantBuffer->m_constantBufferMem, 0, (XGL_VOID **) &pData);
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600383 ASSERT_XGL_SUCCESS(err);
384
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600385 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
386 MVP = Projection * View * Model;
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600387 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
388
Tony Barbour09da2212014-12-03 16:13:23 -0700389 err = xglUnmapMemory(constantBuffer->m_constantBufferMem);
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600390 ASSERT_XGL_SUCCESS(err);
391
392 // submit the command buffer to the universal queue
Tony Barbourf43b6982014-11-25 13:18:32 -0700393 err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_memoryRefManager.GetNumRefs(), m_memoryRefManager.GetMemoryRefList(), NULL );
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600394 ASSERT_XGL_SUCCESS( err );
395
396 err = xglQueueWaitIdle( m_device->m_queue );
397 ASSERT_XGL_SUCCESS( err );
398
399 // Wait for work to finish before cleaning up.
400 xglDeviceWaitIdle(m_device->device());
401
Chia-I Wue7748802014-12-05 10:45:15 +0800402 assert(m_renderTargetCount == 1);
403 RecordImage(m_renderTargets[0]);
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600404 }
Cody Northrop7a1f0462014-10-10 14:49:36 -0600405}
406
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600407void dumpMatrix(const char *note, glm::mat4 MVP)
408{
409 int i,j;
410
411 printf("%s: \n", note);
412 for (i=0; i<4; i++) {
413 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
414 }
415 printf("\n");
416 fflush(stdout);
417}
418
419void dumpVec4(const char *note, glm::vec4 vector)
420{
421 printf("%s: \n", note);
422 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
423 printf("\n");
424 fflush(stdout);
425}
426
Courtney Goeltzenleuchterd04e38c2014-10-22 18:02:30 -0600427void XglRenderTest::GenerateClearAndPrepareBufferCmds()
428{
429 XglRenderFramework::GenerateClearAndPrepareBufferCmds();
Courtney Goeltzenleuchterd04e38c2014-10-22 18:02:30 -0600430
Tony Barbour97a36232014-12-04 17:14:45 -0700431 if (m_depthStencilImage) {
432 printf("Clearing Depth Stencil\n");fflush(stdout);
433 XGL_IMAGE_SUBRESOURCE_RANGE dsRange = {};
434 dsRange.aspect = XGL_IMAGE_ASPECT_DEPTH;
435 dsRange.baseMipLevel = 0;
436 dsRange.mipLevels = XGL_LAST_MIP_OR_SLICE;
437 dsRange.baseArraySlice = 0;
438 dsRange.arraySize = XGL_LAST_MIP_OR_SLICE;
Cody Northrop7a1f0462014-10-10 14:49:36 -0600439
Tony Barbour97a36232014-12-04 17:14:45 -0700440 // prepare the depth buffer for clear
441 XGL_IMAGE_STATE_TRANSITION transitionToClear = {};
442 transitionToClear.image = m_depthStencilImage;
443 transitionToClear.oldState = m_depthStencilBinding.depthState;
444 transitionToClear.newState = XGL_IMAGE_STATE_CLEAR;
445 transitionToClear.subresourceRange = dsRange;
446 xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToClear );
447 m_depthStencilBinding.depthState = transitionToClear.newState;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600448
Tony Barbour97a36232014-12-04 17:14:45 -0700449 xglCmdClearDepthStencil(m_cmdBuffer, m_depthStencilImage, 1.0f, 0, 1, &dsRange);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600450
Tony Barbour97a36232014-12-04 17:14:45 -0700451 // prepare depth buffer for rendering
452 XGL_IMAGE_STATE_TRANSITION transitionToRender = {};
Chia-I Wu18749b02014-12-05 10:48:20 +0800453 transitionToRender.image = m_depthStencilImage;
Tony Barbour97a36232014-12-04 17:14:45 -0700454 transitionToRender.oldState = XGL_IMAGE_STATE_CLEAR;
455 transitionToRender.newState = m_depthStencilBinding.depthState;
456 transitionToRender.subresourceRange = dsRange;
457 xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToRender );
458 m_depthStencilBinding.depthState = transitionToClear.newState;
459 }
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600460}
461
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600462void XglRenderTest::InitDepthStencil()
463{
464 XGL_RESULT err;
465 XGL_IMAGE_CREATE_INFO image;
466 XGL_MEMORY_ALLOC_INFO mem_alloc;
467 XGL_DEPTH_STENCIL_VIEW_CREATE_INFO view;
468 XGL_MEMORY_REQUIREMENTS mem_reqs;
Jon Ashburn6317c492014-11-21 11:33:20 -0700469 XGL_SIZE mem_reqs_size=sizeof(XGL_MEMORY_REQUIREMENTS);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600470
471 // Clean up default state created by framework
472 if (m_stateDepthStencil) xglDestroyObject(m_stateDepthStencil);
473
474 m_depth_stencil_fmt.channelFormat = XGL_CH_FMT_R16;
475 m_depth_stencil_fmt.numericFormat = XGL_NUM_FMT_DS;
476
477 image.sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
478 image.pNext = NULL;
479 image.imageType = XGL_IMAGE_2D;
480 image.format = m_depth_stencil_fmt;
481 image.extent.width = m_width;
482 image.extent.height = m_height;
483 image.extent.depth = 1;
484 image.mipLevels = 1;
485 image.arraySize = 1;
486 image.samples = 1;
487 image.tiling = XGL_OPTIMAL_TILING;
488 image.usage = XGL_IMAGE_USAGE_DEPTH_STENCIL_BIT;
489 image.flags = 0;
490
491 mem_alloc.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
492 mem_alloc.pNext = NULL;
493 mem_alloc.allocationSize = 0;
494 mem_alloc.alignment = 0;
495 mem_alloc.flags = 0;
496 mem_alloc.heapCount = 0;
497 mem_alloc.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
498
499 /* create image */
500 err = xglCreateImage(device(), &image,
501 &m_depthStencilImage);
502 ASSERT_XGL_SUCCESS(err);
503
504 err = xglGetObjectInfo(m_depthStencilImage,
505 XGL_INFO_TYPE_MEMORY_REQUIREMENTS,
506 &mem_reqs_size, &mem_reqs);
507 ASSERT_XGL_SUCCESS(err);
508 ASSERT_EQ(mem_reqs_size, sizeof(mem_reqs));
509
510 mem_alloc.allocationSize = mem_reqs.size;
511 mem_alloc.alignment = mem_reqs.alignment;
512 mem_alloc.heapCount = mem_reqs.heapCount;
513 memcpy(mem_alloc.heaps, mem_reqs.heaps,
514 sizeof(mem_reqs.heaps[0]) * mem_reqs.heapCount);
515
516 /* allocate memory */
517 err = xglAllocMemory(device(), &mem_alloc, &m_depthStencilMem);
518 ASSERT_XGL_SUCCESS(err);
519
520 /* bind memory */
521 err = xglBindObjectMemory(m_depthStencilImage, m_depthStencilMem, 0);
522 ASSERT_XGL_SUCCESS(err);
523
524 XGL_DEPTH_STENCIL_STATE_CREATE_INFO depthStencil = {};
525 depthStencil.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_STATE_CREATE_INFO;
526 depthStencil.depthTestEnable = XGL_TRUE;
527 depthStencil.depthWriteEnable = XGL_TRUE;
528 depthStencil.depthFunc = XGL_COMPARE_LESS_EQUAL;
529 depthStencil.depthBoundsEnable = XGL_FALSE;
530 depthStencil.minDepth = 0.f;
531 depthStencil.maxDepth = 1.f;
532 depthStencil.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
533 depthStencil.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
534 depthStencil.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
535 depthStencil.back.stencilRef = 0x00;
536 depthStencil.back.stencilFunc = XGL_COMPARE_ALWAYS;
537 depthStencil.front = depthStencil.back;
538
539 err = xglCreateDepthStencilState( device(), &depthStencil, &m_stateDepthStencil );
540 ASSERT_XGL_SUCCESS( err );
541
542 /* create image view */
543 view.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO;
544 view.pNext = NULL;
545 view.image = XGL_NULL_HANDLE;
546 view.mipLevel = 0;
547 view.baseArraySlice = 0;
548 view.arraySize = 1;
549 view.flags = 0;
550 view.image = m_depthStencilImage;
551 err = xglCreateDepthStencilView(device(), &view, &m_depthStencilView);
552 ASSERT_XGL_SUCCESS(err);
553
554 m_depthStencilBinding.view = m_depthStencilView;
555 m_depthStencilBinding.depthState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL;
556 m_depthStencilBinding.stencilState = XGL_IMAGE_STATE_TARGET_RENDER_ACCESS_OPTIMAL;
557}
558
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600559struct xgltriangle_vs_uniform {
560 // Must start with MVP
561 XGL_FLOAT mvp[4][4];
562 XGL_FLOAT position[3][4];
563 XGL_FLOAT color[3][4];
564};
565
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600566void XglRenderTest::XGLTriangleTest(const char *vertShaderText, const char *fragShaderText)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600567{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700568#ifdef DEBUG_CALLBACK
569 xglDbgRegisterMsgCallback(myDbgFunc, NULL);
570#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600571 // Create identity matrix
572 int i;
573 struct xgltriangle_vs_uniform data;
574
575 glm::mat4 Projection = glm::mat4(1.0f);
576 glm::mat4 View = glm::mat4(1.0f);
577 glm::mat4 Model = glm::mat4(1.0f);
578 glm::mat4 MVP = Projection * View * Model;
579 const int matrixSize = sizeof(MVP);
580 const int bufSize = sizeof(xgltriangle_vs_uniform) / sizeof(XGL_FLOAT);
581 memcpy(&data.mvp, &MVP[0][0], matrixSize);
582
583 static const Vertex tri_data[] =
584 {
585 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
586 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
587 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
588 };
589
590 for (i=0; i<3; i++) {
591 data.position[i][0] = tri_data[i].posX;
592 data.position[i][1] = tri_data[i].posY;
593 data.position[i][2] = tri_data[i].posZ;
594 data.position[i][3] = tri_data[i].posW;
595 data.color[i][0] = tri_data[i].r;
596 data.color[i][1] = tri_data[i].g;
597 data.color[i][2] = tri_data[i].b;
598 data.color[i][3] = tri_data[i].a;
599 }
600
Tony Barbourf43b6982014-11-25 13:18:32 -0700601 ASSERT_NO_FATAL_FAILURE(InitState());
602 ASSERT_NO_FATAL_FAILURE(InitViewport());
603
604 XglConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(XGL_FLOAT), (const void*) &data);
605
606 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
607 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
608 vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &constantBuffer);
609
610 XglPipelineObj pipelineobj(m_device);
611 pipelineobj.AddShader(&vs);
612 pipelineobj.AddShader(&ps);
613
614 XglDescriptorSetObj descriptorSet(m_device);
615 descriptorSet.AttachMemoryView(&constantBuffer);
616 m_memoryRefManager.AddMemoryRef(&constantBuffer);
617
Tony Barboura3953b82014-12-03 15:46:29 -0700618 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barbourf43b6982014-11-25 13:18:32 -0700619 QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
620
Tony Barbour09da2212014-12-03 16:13:23 -0700621 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer);
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700622#ifdef PRINT_OBJECTS
623 //XGL_UINT64 objTrackGetObjectCount(XGL_OBJECT_TYPE type)
624 OBJ_TRACK_GET_OBJECT_COUNT pObjTrackGetObjectCount = (OBJ_TRACK_GET_OBJECT_COUNT)xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjectCount");
625 XGL_UINT64 numObjects = pObjTrackGetObjectCount(XGL_OBJECT_TYPE_ANY);
626 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjects");
627 printf("DEBUG : Number of Objects : %lu\n", numObjects);
628 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjects");
629 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
630 pObjTrackGetObjs(XGL_OBJECT_TYPE_ANY, numObjects, pObjNodeArray);
631 for (i=0; i < numObjects; i++) {
632 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);
633 }
634 free(pObjNodeArray);
635#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700636
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600637}
638
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600639TEST_F(XglRenderTest, XGLTriangle_FragColor)
640{
641 static const char *vertShaderText =
642 "#version 140\n"
643 "#extension GL_ARB_separate_shader_objects : enable\n"
644 "#extension GL_ARB_shading_language_420pack : enable\n"
645 "\n"
646 "layout(binding = 0) uniform buf {\n"
647 " mat4 MVP;\n"
648 " vec4 position[3];\n"
649 " vec4 color[3];\n"
650 "} ubuf;\n"
651 "\n"
652 "layout (location = 0) out vec4 outColor;\n"
653 "\n"
654 "void main() \n"
655 "{\n"
656 " outColor = ubuf.color[gl_VertexID];\n"
657 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
658 "}\n";
659
660 static const char *fragShaderText =
661 "#version 140\n"
662 "#extension GL_ARB_separate_shader_objects : enable\n"
663 "#extension GL_ARB_shading_language_420pack : enable\n"
664 "\n"
665 "layout (location = 0) in vec4 inColor;\n"
666 "\n"
667 "void main()\n"
668 "{\n"
669 " gl_FragColor = inColor;\n"
670 "}\n";
671
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600672 TEST_DESCRIPTION("XGL-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600673 XGLTriangleTest(vertShaderText, fragShaderText);
674}
675
676TEST_F(XglRenderTest, XGLTriangle_OutputLocation)
677{
678 static const char *vertShaderText =
679 "#version 140\n"
680 "#extension GL_ARB_separate_shader_objects : enable\n"
681 "#extension GL_ARB_shading_language_420pack : enable\n"
682 "\n"
683 "layout(binding = 0) uniform buf {\n"
684 " mat4 MVP;\n"
685 " vec4 position[3];\n"
686 " vec4 color[3];\n"
687 "} ubuf;\n"
688 "\n"
689 "layout (location = 0) out vec4 outColor;\n"
690 "\n"
691 "void main() \n"
692 "{\n"
693 " outColor = ubuf.color[gl_VertexID];\n"
694 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
695 "}\n";
696
697 static const char *fragShaderText =
698 "#version 140\n"
699 "#extension GL_ARB_separate_shader_objects : enable\n"
700 "#extension GL_ARB_shading_language_420pack : enable\n"
701 "\n"
702 "layout (location = 0) in vec4 inColor;\n"
703 "layout (location = 0) out vec4 outColor;\n"
704 "\n"
705 "void main()\n"
706 "{\n"
707 " outColor = inColor;\n"
708 "}\n";
709
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600710 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 -0600711
712 XGLTriangleTest(vertShaderText, fragShaderText);
713}
714
Tony Barbourf43b6982014-11-25 13:18:32 -0700715TEST_F(XglRenderTest, BIL_XGLTriangle)
716{
717 bool saved_use_bil = XglTestFramework::m_use_bil;
718
719 static const char *vertShaderText =
720 "#version 140\n"
721 "#extension GL_ARB_separate_shader_objects : enable\n"
722 "#extension GL_ARB_shading_language_420pack : enable\n"
723 "\n"
724 "layout(binding = 0) uniform buf {\n"
725 " mat4 MVP;\n"
726 " vec4 position[3];\n"
727 " vec4 color[3];\n"
728 "} ubuf;\n"
729 "\n"
730 "layout (location = 0) out vec4 outColor;\n"
731 "\n"
732 "void main() \n"
733 "{\n"
734 " outColor = ubuf.color[gl_VertexID];\n"
735 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
736 "}\n";
737
738 static const char *fragShaderText =
739 "#version 140\n"
740 "#extension GL_ARB_separate_shader_objects : enable\n"
741 "#extension GL_ARB_shading_language_420pack : enable\n"
742 "\n"
743 "layout (location = 0) in vec4 inColor;\n"
744 "\n"
745 "void main()\n"
746 "{\n"
747 " gl_FragColor = inColor;\n"
748 "}\n";
749
750 TEST_DESCRIPTION("XGL-style shaders, but force test framework to compile shader to BIL and pass BIL to driver.");
751
752 XglTestFramework::m_use_bil = true;
753
754 XGLTriangleTest(vertShaderText, fragShaderText);
755
756 XglTestFramework::m_use_bil = saved_use_bil;
757}
758
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600759TEST_F(XglRenderTest, GreenTriangle)
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600760{
761 static const char *vertShaderText =
762 "#version 130\n"
763 "vec2 vertices[3];\n"
764 "void main() {\n"
765 " vertices[0] = vec2(-1.0, -1.0);\n"
766 " vertices[1] = vec2( 1.0, -1.0);\n"
767 " vertices[2] = vec2( 0.0, 1.0);\n"
768 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
769 "}\n";
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600770
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600771 static const char *fragShaderText =
772 "#version 130\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600773 "void main() {\n"
Steve K10b32512014-10-10 08:54:29 -0600774 " gl_FragColor = vec4(0,1,0,1);\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600775 "}\n";
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600776
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600777 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
778
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600779 DrawTriangleTest(vertShaderText, fragShaderText);
780}
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600781
Tony Barbourf43b6982014-11-25 13:18:32 -0700782TEST_F(XglRenderTest, BIL_GreenTriangle)
783{
784 bool saved_use_bil = XglTestFramework::m_use_bil;
785
786 static const char *vertShaderText =
787 "#version 130\n"
788 "vec2 vertices[3];\n"
789 "void main() {\n"
790 " vertices[0] = vec2(-1.0, -1.0);\n"
791 " vertices[1] = vec2( 1.0, -1.0);\n"
792 " vertices[2] = vec2( 0.0, 1.0);\n"
793 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
794 "}\n";
795
796 static const char *fragShaderText =
797 "#version 130\n"
798 "void main() {\n"
799 " gl_FragColor = vec4(0,1,0,1);\n"
800 "}\n";
801
802 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to BIL and gives BIL to driver.");
803
804 XglTestFramework::m_use_bil = true;
805 DrawTriangleTest(vertShaderText, fragShaderText);
806 XglTestFramework::m_use_bil = saved_use_bil;
807}
808
809TEST_F(XglRenderTest, YellowTriangle)
810{
811 static const char *vertShaderText =
812 "#version 130\n"
813 "void main() {\n"
814 " vec2 vertices[3];"
815 " vertices[0] = vec2(-0.5, -0.5);\n"
816 " vertices[1] = vec2( 0.5, -0.5);\n"
817 " vertices[2] = vec2( 0.5, 0.5);\n"
818 " vec4 colors[3];\n"
819 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
820 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
821 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
822 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
823 "}\n";
824
825 static const char *fragShaderText =
826 "#version 130\n"
827 "void main() {\n"
828 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
829 "}\n";
830
831 DrawTriangleTest(vertShaderText, fragShaderText);
832}
833
834TEST_F(XglRenderTest, TriangleTwoFSUniforms)
835{
836 static const char *vertShaderText =
837 "#version 130\n"
838 "out vec4 color;\n"
839 "out vec4 scale;\n"
840 "out vec2 samplePos;\n"
841 "void main() {\n"
842 " vec2 vertices[3];"
843 " vertices[0] = vec2(-0.5, -0.5);\n"
844 " vertices[1] = vec2( 0.5, -0.5);\n"
845 " vertices[2] = vec2( 0.5, 0.5);\n"
846 " vec4 colors[3];\n"
847 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
848 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
849 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
850 " color = colors[gl_VertexID % 3];\n"
851 " vec2 positions[3];"
852 " positions[0] = vec2( 0.0, 0.0);\n"
853 " positions[1] = vec2( 1.0, 0.0);\n"
854 " positions[2] = vec2( 1.0, 1.0);\n"
855 " scale = vec4(0.0, 0.0, 0.0, 0.0);\n"
856 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
857 "}\n";
858
859
860 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700861 "#version 130\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700862 "in vec4 color;\n"
863 "in vec4 scale;\n"
864 "uniform vec4 foo;\n"
865 "uniform vec4 bar;\n"
866 "void main() {\n"
867 // by default, with no location or blocks
868 // the compiler will read them from buffer
869 // in reverse order of first use in shader
870 // The buffer contains red, followed by blue,
871 // so foo should be blue, bar should be red
872 " gl_FragColor = color * scale * foo * bar + foo;\n"
873 "}\n";
874
875 ASSERT_NO_FATAL_FAILURE(InitState());
876 ASSERT_NO_FATAL_FAILURE(InitViewport());
877
878 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
879 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
880
881 const int constantCount = 8;
882 const float constants[constantCount] = { 1.0, 0.0, 0.0, 1.0,
883 0.0, 0.0, 1.0, 1.0 };
884 XglConstantBufferObj constantBuffer(m_device,constantCount, sizeof(constants[0]), (const void*) constants);
885 ps.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &constantBuffer);
886
887 XglPipelineObj pipelineobj(m_device);
888 pipelineobj.AddShader(&vs);
889 pipelineobj.AddShader(&ps);
890
891 XglDescriptorSetObj descriptorSet(m_device);
892 descriptorSet.AttachMemoryView(&constantBuffer);
893
Tony Barboura3953b82014-12-03 15:46:29 -0700894 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barbourf43b6982014-11-25 13:18:32 -0700895 QueueCommandBuffer(NULL, 0);
896
897}
898
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600899TEST_F(XglRenderTest, TriangleWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600900{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600901 static const char *vertShaderText =
Tony Barbourf43b6982014-11-25 13:18:32 -0700902 "#version 130\n"
903 //XYZ1( -1, -1, -1 )
904 "in vec4 pos;\n"
905 //XYZ1( 0.f, 0.f, 0.f )
906 "in vec4 inColor;\n"
907 "out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600908 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600909 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600910 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600911 "}\n";
912
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600913
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600914 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700915 "#version 140\n"
916 "#extension GL_ARB_separate_shader_objects : enable\n"
917 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700918 "in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700919 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600920 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700921 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600922 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600923
Tony Barbourf43b6982014-11-25 13:18:32 -0700924
925
926 ASSERT_NO_FATAL_FAILURE(InitState());
927 ASSERT_NO_FATAL_FAILURE(InitViewport());
928
929 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
930 meshBuffer.SetMemoryState(m_cmdBuffer,XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
931
932 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
933 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
934
935 XglPipelineObj pipelineobj(m_device);
936 pipelineobj.AddShader(&vs);
937 pipelineobj.AddShader(&ps);
938
939 XglDescriptorSetObj descriptorSet(m_device);
940 descriptorSet.AttachMemoryView(&meshBuffer);
941
942 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
943 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
944 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
945 };
946
947 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
948 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
949 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
950 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
951 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
952 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
953 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
954 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
955 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
956
957 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
958 pipelineobj.AddVertexInputBindings(&vi_binding,1);
959 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
960
Tony Barboura3953b82014-12-03 15:46:29 -0700961 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -0700962 QueueCommandBuffer(NULL, 0);
963
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600964}
965
Chia-I Wue09d1a72014-12-05 10:32:23 +0800966TEST_F(XglRenderTest, TriangleMRT)
967{
968 static const char *vertShaderText =
969 "#version 130\n"
970 "in vec4 pos;\n"
971 "void main() {\n"
972 " gl_Position = pos;\n"
973 "}\n";
974
975 static const char *fragShaderText =
976 "#version 130\n"
977 "void main() {\n"
978 " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
979 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
980 "}\n";
981 const XGL_FLOAT vb_data[][2] = {
982 { -1.0f, -1.0f },
983 { 1.0f, -1.0f },
984 { -1.0f, 1.0f }
985 };
986
987 ASSERT_NO_FATAL_FAILURE(InitState());
988 ASSERT_NO_FATAL_FAILURE(InitViewport());
989
990 XglConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
991 meshBuffer.SetMemoryState(m_cmdBuffer,XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
992
993 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
994 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
995
996 XglPipelineObj pipelineobj(m_device);
997 pipelineobj.AddShader(&vs);
998 pipelineobj.AddShader(&ps);
999
1000 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1001 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1002 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1003 };
1004
1005 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attrib;
1006 vi_attrib.binding = 0; // index into vertexBindingDescriptions
1007 vi_attrib.format.channelFormat = XGL_CH_FMT_R32G32; // format of source data
1008 vi_attrib.format.numericFormat = XGL_NUM_FMT_FLOAT;
1009 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1010
1011 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
1012 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1013 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1014
1015 XglDescriptorSetObj descriptorSet(m_device);
1016
1017 m_renderTargetCount = 2;
1018
1019 XGL_PIPELINE_CB_ATTACHMENT_STATE att = {};
1020 att.blendEnable = XGL_FALSE;
1021 att.format = m_render_target_fmt;
1022 att.channelWriteMask = 0xf;
1023 pipelineobj.SetColorAttachment(1, &att);
1024
1025 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
1026 QueueCommandBuffer(NULL, 0);
1027}
1028
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001029TEST_F(XglRenderTest, QuadWithIndexedVertexFetch)
1030{
1031 static const char *vertShaderText =
1032 "#version 140\n"
1033 "#extension GL_ARB_separate_shader_objects : enable\n"
1034 "#extension GL_ARB_shading_language_420pack : enable\n"
1035 "layout(location = 0) in vec4 pos;\n"
1036 "layout(location = 1) in vec4 inColor;\n"
1037 "layout(location = 0) out vec4 outColor;\n"
1038 "void main() {\n"
1039 " outColor = inColor;\n"
1040 " gl_Position = pos;\n"
1041 "}\n";
1042
1043
1044 static const char *fragShaderText =
1045 "#version 140\n"
1046 "#extension GL_ARB_separate_shader_objects : enable\n"
1047 "#extension GL_ARB_shading_language_420pack : enable\n"
1048 "layout(location = 0) in vec4 color;\n"
1049 "void main() {\n"
1050 " gl_FragColor = color;\n"
1051 "}\n";
1052
1053 const Vertex g_vbData[] =
1054 {
1055 // first tri
1056 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
1057 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
1058 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
1059
1060 // second tri
1061 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
1062 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
1063 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
1064 };
1065
1066 const uint16_t g_idxData[6] = {
1067 0, 1, 2,
1068 3, 4, 5,
1069 };
1070
1071 ASSERT_NO_FATAL_FAILURE(InitState());
1072 ASSERT_NO_FATAL_FAILURE(InitViewport());
1073
1074 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
1075 meshBuffer.SetMemoryState(m_cmdBuffer, XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
1076
1077 XglIndexBufferObj indexBuffer(m_device);
1078 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), XGL_INDEX_16, g_idxData);
1079 indexBuffer.SetMemoryState(m_cmdBuffer, XGL_MEMORY_STATE_INDEX_DATA);
1080
1081 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1082 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1083
1084 XglPipelineObj pipelineobj(m_device);
1085 pipelineobj.AddShader(&vs);
1086 pipelineobj.AddShader(&ps);
1087
1088 XglDescriptorSetObj descriptorSet(m_device);
1089
1090 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1091 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1092 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1093 };
1094
1095 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1096 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1097 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1098 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1099 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1100 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1101 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1102 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1103 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1104
1105 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1106 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1107
1108 XGL_RESULT err = XGL_SUCCESS;
1109
1110 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1111 // Build command buffer
1112 // TODO: SetMemoryState above also uses this command buffer, do we need to make sure
1113 // that job is complete? Or maybe we shouldn't queue those actions?
1114 err = xglBeginCommandBuffer(m_cmdBuffer, 0);
1115 ASSERT_XGL_SUCCESS(err);
1116
1117 GenerateClearAndPrepareBufferCmds();
1118 GenerateBindRenderTargetCmd();
1119#ifdef DUMP_STATE_DOT
1120 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1121 pDSDumpDot((char*)"triTest.dot");
1122#endif
1123 GenerateBindStateAndPipelineCmds();
1124
Tony Barbour9d3c3172014-12-04 17:27:08 -07001125 pipelineobj.BindPipelineCommandBuffer(m_cmdBuffer,&descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001126 descriptorSet.BindCommandBuffer(m_cmdBuffer);
1127
1128 meshBuffer.Bind(m_cmdBuffer, 0, 0);
1129 indexBuffer.Bind(m_cmdBuffer, /* offset */ 0);
1130
1131 // render two triangles
1132 xglCmdDrawIndexed(m_cmdBuffer, 0, 6, 0, 0, 1);
1133
1134 // finalize recording of the command buffer
1135 err = xglEndCommandBuffer( m_cmdBuffer );
1136 ASSERT_XGL_SUCCESS( err );
1137
1138 QueueCommandBuffer(NULL, 0);
1139
1140}
1141
GregF6bef1212014-12-02 15:41:44 -07001142TEST_F(XglRenderTest, GreyandRedCirclesonBlue)
1143{
1144 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -07001145
GregF6bef1212014-12-02 15:41:44 -07001146 static const char *vertShaderText =
1147 "#version 140\n"
1148 "#extension GL_ARB_separate_shader_objects : enable\n"
1149 "#extension GL_ARB_shading_language_420pack : enable\n"
1150 "layout (location = 0) in vec4 pos;\n"
1151 "layout (location = 0) out vec4 outColor;\n"
1152 "layout (location = 1) out vec4 outColor2;\n"
1153 "void main() {\n"
1154 " gl_Position = pos;\n"
1155 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1156 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1157 "}\n";
1158
1159 static const char *fragShaderText =
1160 //"#version 140\n"
1161 "#version 330\n"
1162 "#extension GL_ARB_separate_shader_objects : enable\n"
1163 "#extension GL_ARB_shading_language_420pack : enable\n"
1164 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1165 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1166 "layout (location = 0) in vec4 color;\n"
1167 "layout (location = 1) in vec4 color2;\n"
1168 "void main() {\n"
1169 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1170 " float dist_squared = dot(pos, pos);\n"
1171 " gl_FragColor = (dist_squared < 400.0)\n"
1172 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1173 " : color2;\n"
1174 "}\n";
1175
1176 ASSERT_NO_FATAL_FAILURE(InitState());
1177 ASSERT_NO_FATAL_FAILURE(InitViewport());
1178
1179 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
1180 meshBuffer.SetMemoryState(m_cmdBuffer,XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
1181
1182 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1183 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1184
1185 XglPipelineObj pipelineobj(m_device);
1186 pipelineobj.AddShader(&vs);
1187 pipelineobj.AddShader(&ps);
1188
1189 XglDescriptorSetObj descriptorSet(m_device);
1190 descriptorSet.AttachMemoryView(&meshBuffer);
1191
1192 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1193 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1194 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1195 };
1196
1197 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1198 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1199 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1200 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1201 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1202 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1203 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1204 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1205 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1206
1207 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1208 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1209 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1210
Tony Barbour09da2212014-12-03 16:13:23 -07001211 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 2);
GregF6bef1212014-12-02 15:41:44 -07001212 QueueCommandBuffer(NULL, 0);
1213
1214}
1215
1216TEST_F(XglRenderTest, RedCirclesonBlue)
1217{
1218 // This tests that we correctly handle unread fragment inputs
1219
1220 static const char *vertShaderText =
1221 "#version 140\n"
1222 "#extension GL_ARB_separate_shader_objects : enable\n"
1223 "#extension GL_ARB_shading_language_420pack : enable\n"
1224 "layout (location = 0) in vec4 pos;\n"
1225 "layout (location = 0) out vec4 outColor;\n"
1226 "layout (location = 1) out vec4 outColor2;\n"
1227 "void main() {\n"
1228 " gl_Position = pos;\n"
1229 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1230 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1231 "}\n";
1232
1233 static const char *fragShaderText =
1234 //"#version 140\n"
1235 "#version 330\n"
1236 "#extension GL_ARB_separate_shader_objects : enable\n"
1237 "#extension GL_ARB_shading_language_420pack : enable\n"
1238 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1239 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1240 "layout (location = 0) in vec4 color;\n"
1241 "layout (location = 1) in vec4 color2;\n"
1242 "void main() {\n"
1243 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1244 " float dist_squared = dot(pos, pos);\n"
1245 " gl_FragColor = (dist_squared < 400.0)\n"
1246 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1247 " : color2;\n"
1248 "}\n";
1249
1250 ASSERT_NO_FATAL_FAILURE(InitState());
1251 ASSERT_NO_FATAL_FAILURE(InitViewport());
1252
1253 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
1254 meshBuffer.SetMemoryState(m_cmdBuffer,XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
1255
1256 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1257 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1258
1259 XglPipelineObj pipelineobj(m_device);
1260 pipelineobj.AddShader(&vs);
1261 pipelineobj.AddShader(&ps);
1262
1263 XglDescriptorSetObj descriptorSet(m_device);
1264 descriptorSet.AttachMemoryView(&meshBuffer);
1265
1266 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1267 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1268 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1269 };
1270
1271 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1272 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1273 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1274 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1275 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1276 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1277 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1278 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1279 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1280
1281 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1282 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1283 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1284
Tony Barbour09da2212014-12-03 16:13:23 -07001285 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 2);
GregF6bef1212014-12-02 15:41:44 -07001286 QueueCommandBuffer(NULL, 0);
1287
1288}
1289
1290TEST_F(XglRenderTest, GreyCirclesonBlueFade)
1291{
1292 // This tests reading gl_ClipDistance from FS
1293
1294 static const char *vertShaderText =
1295 "#version 330\n"
1296 "#extension GL_ARB_separate_shader_objects : enable\n"
1297 "#extension GL_ARB_shading_language_420pack : enable\n"
1298 "out gl_PerVertex {\n"
1299 " vec4 gl_Position;\n"
1300 " float gl_ClipDistance[1];\n"
1301 "};\n"
1302 "layout (location = 0) in vec4 pos;\n"
1303 "layout (location = 0) out vec4 outColor;\n"
1304 "layout (location = 1) out vec4 outColor2;\n"
1305 "void main() {\n"
1306 " gl_Position = pos;\n"
1307 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1308 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1309 " float dists[3];\n"
1310 " dists[0] = 0.0;\n"
1311 " dists[1] = 1.0;\n"
1312 " dists[2] = 1.0;\n"
1313 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1314 "}\n";
1315
1316
1317 static const char *fragShaderText =
1318 //"#version 140\n"
1319 "#version 330\n"
1320 "#extension GL_ARB_separate_shader_objects : enable\n"
1321 "#extension GL_ARB_shading_language_420pack : enable\n"
1322 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1323 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1324 "layout (location = 0) in vec4 color;\n"
1325 "layout (location = 1) in vec4 color2;\n"
1326 "void main() {\n"
1327 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1328 " float dist_squared = dot(pos, pos);\n"
1329 " gl_FragColor = (dist_squared < 400.0)\n"
1330 " ? color * gl_ClipDistance[0]\n"
1331 " : color2;\n"
1332 "}\n";
1333
1334 ASSERT_NO_FATAL_FAILURE(InitState());
1335 ASSERT_NO_FATAL_FAILURE(InitViewport());
1336
1337 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
1338 meshBuffer.SetMemoryState(m_cmdBuffer,XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
1339
1340 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1341 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1342
1343 XglPipelineObj pipelineobj(m_device);
1344 pipelineobj.AddShader(&vs);
1345 pipelineobj.AddShader(&ps);
1346
1347 XglDescriptorSetObj descriptorSet(m_device);
1348 descriptorSet.AttachMemoryView(&meshBuffer);
1349
1350 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1351 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1352 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1353 };
1354
1355 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1356 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1357 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1358 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1359 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1360 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1361 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1362 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1363 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1364
1365 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1366 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1367 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1368
Tony Barboura3953b82014-12-03 15:46:29 -07001369 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 2);
GregF6bef1212014-12-02 15:41:44 -07001370 QueueCommandBuffer(NULL, 0);
1371
1372}
Tony Barbourf43b6982014-11-25 13:18:32 -07001373
GregF7a23c792014-12-02 17:19:34 -07001374TEST_F(XglRenderTest, GreyCirclesonBlueDiscard)
1375{
1376 static const char *vertShaderText =
1377 "#version 140\n"
1378 "#extension GL_ARB_separate_shader_objects : enable\n"
1379 "#extension GL_ARB_shading_language_420pack : enable\n"
1380 "layout (location = 0) in vec4 pos;\n"
1381 "layout (location = 0) out vec4 outColor;\n"
1382 "layout (location = 1) out vec4 outColor2;\n"
1383 "void main() {\n"
1384 " gl_Position = pos;\n"
1385 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1386 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1387 "}\n";
1388
1389
1390 static const char *fragShaderText =
1391 //"#version 140\n"
1392 "#version 330\n"
1393 "#extension GL_ARB_separate_shader_objects : enable\n"
1394 "#extension GL_ARB_shading_language_420pack : enable\n"
1395 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1396 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1397 "layout (location = 0) in vec4 color;\n"
1398 "layout (location = 1) in vec4 color2;\n"
1399 "void main() {\n"
1400 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1401 " float dist_squared = dot(pos, pos);\n"
1402 " if (dist_squared < 100.0)\n"
1403 " discard;\n"
1404 " gl_FragColor = (dist_squared < 400.0)\n"
1405 " ? color\n"
1406 " : color2;\n"
1407 "}\n";
1408
1409 ASSERT_NO_FATAL_FAILURE(InitState());
1410 ASSERT_NO_FATAL_FAILURE(InitViewport());
1411
1412 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
1413 meshBuffer.SetMemoryState(m_cmdBuffer,XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
1414
1415 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1416 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1417
1418 XglPipelineObj pipelineobj(m_device);
1419 pipelineobj.AddShader(&vs);
1420 pipelineobj.AddShader(&ps);
1421
1422 XglDescriptorSetObj descriptorSet(m_device);
1423 descriptorSet.AttachMemoryView(&meshBuffer);
1424
1425 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1426 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1427 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1428 };
1429
1430 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1431 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1432 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1433 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1434 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1435 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1436 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1437 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1438 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1439
1440 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1441 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1442 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1443
Tony Barbour09da2212014-12-03 16:13:23 -07001444 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 2);
GregF7a23c792014-12-02 17:19:34 -07001445 QueueCommandBuffer(NULL, 0);
1446
1447}
1448
1449
Courtney Goeltzenleuchter3d10c9c2014-10-27 13:06:08 -06001450TEST_F(XglRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001451{
1452 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001453 "#version 140\n"
1454 "#extension GL_ARB_separate_shader_objects : enable\n"
1455 "#extension GL_ARB_shading_language_420pack : enable\n"
1456 "\n"
1457 "layout(binding = 0) uniform buf {\n"
1458 " mat4 MVP;\n"
1459 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001460 "void main() {\n"
1461 " vec2 vertices[3];"
1462 " vertices[0] = vec2(-0.5, -0.5);\n"
1463 " vertices[1] = vec2( 0.5, -0.5);\n"
1464 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001465 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001466 "}\n";
1467
1468 static const char *fragShaderText =
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001469 "#version 130\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001470 "void main() {\n"
Cody Northrop78eac042014-10-10 15:45:00 -06001471 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001472 "}\n";
1473
Tony Barbourf43b6982014-11-25 13:18:32 -07001474 ASSERT_NO_FATAL_FAILURE(InitState());
1475 ASSERT_NO_FATAL_FAILURE(InitViewport());
1476
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001477 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001478 glm::mat4 Projection = glm::mat4(1.0f);
1479 glm::mat4 View = glm::mat4(1.0f);
1480 glm::mat4 Model = glm::mat4(1.0f);
1481 glm::mat4 MVP = Projection * View * Model;
1482 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1483
Tony Barbourf43b6982014-11-25 13:18:32 -07001484 XglConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1485 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1486 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001487
Tony Barbourf43b6982014-11-25 13:18:32 -07001488 vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &MVPBuffer);
1489
1490 XglPipelineObj pipelineobj(m_device);
1491 pipelineobj.AddShader(&vs);
1492 pipelineobj.AddShader(&ps);
1493
1494 // Create descriptor set and attach the constant buffer to it
1495 XglDescriptorSetObj descriptorSet(m_device);
1496 descriptorSet.AttachMemoryView(&MVPBuffer);
1497
1498 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1499
Tony Barboura3953b82014-12-03 15:46:29 -07001500 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barbourf43b6982014-11-25 13:18:32 -07001501 QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
1502
Tony Barbour09da2212014-12-03 16:13:23 -07001503 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001504}
1505
Tony Barbourf43b6982014-11-25 13:18:32 -07001506TEST_F(XglRenderTest, MixTriangle)
1507{
1508 // This tests location applied to varyings. Notice that we have switched foo
1509 // and bar in the FS. The triangle should be blended with red, green and blue
1510 // corners.
1511 static const char *vertShaderText =
1512 "#version 140\n"
1513 "#extension GL_ARB_separate_shader_objects : enable\n"
1514 "#extension GL_ARB_shading_language_420pack : enable\n"
1515 "layout (location=0) out vec4 bar;\n"
1516 "layout (location=1) out vec4 foo;\n"
1517 "layout (location=2) out float scale;\n"
1518 "vec2 vertices[3];\n"
1519 "void main() {\n"
1520 " vertices[0] = vec2(-1.0, -1.0);\n"
1521 " vertices[1] = vec2( 1.0, -1.0);\n"
1522 " vertices[2] = vec2( 0.0, 1.0);\n"
1523 "vec4 colors[3];\n"
1524 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1525 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1526 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1527 " foo = colors[gl_VertexID % 3];\n"
1528 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1529 " scale = 1.0;\n"
1530 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1531 "}\n";
1532
1533 static const char *fragShaderText =
1534 "#version 140\n"
1535 "#extension GL_ARB_separate_shader_objects : enable\n"
1536 "#extension GL_ARB_shading_language_420pack : enable\n"
1537 "layout (location = 1) in vec4 bar;\n"
1538 "layout (location = 0) in vec4 foo;\n"
1539 "layout (location = 2) in float scale;\n"
1540 "void main() {\n"
1541 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
1542 "}\n";
1543
1544 ASSERT_NO_FATAL_FAILURE(InitState());
1545 ASSERT_NO_FATAL_FAILURE(InitViewport());
1546
1547 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1548 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1549
1550 XglPipelineObj pipelineobj(m_device);
1551 pipelineobj.AddShader(&vs);
1552 pipelineobj.AddShader(&ps);
1553
1554 XglDescriptorSetObj descriptorSet(m_device);
1555
Tony Barboura3953b82014-12-03 15:46:29 -07001556 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barbourf43b6982014-11-25 13:18:32 -07001557 QueueCommandBuffer(NULL, 0);
1558}
1559
1560TEST_F(XglRenderTest, TriVertFetchAndVertID)
1561{
1562 // This tests that attributes work in the presence of gl_VertexID
1563
1564 static const char *vertShaderText =
1565 "#version 140\n"
1566 "#extension GL_ARB_separate_shader_objects : enable\n"
1567 "#extension GL_ARB_shading_language_420pack : enable\n"
1568 //XYZ1( -1, -1, -1 )
1569 "layout (location = 0) in vec4 pos;\n"
1570 //XYZ1( 0.f, 0.f, 0.f )
1571 "layout (location = 1) in vec4 inColor;\n"
1572 "layout (location = 0) out vec4 outColor;\n"
1573 "void main() {\n"
1574 " outColor = inColor;\n"
1575 " vec4 vertices[3];"
1576 " vertices[gl_VertexID % 3] = pos;\n"
1577 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1578 "}\n";
1579
1580
1581 static const char *fragShaderText =
1582 "#version 140\n"
1583 "#extension GL_ARB_separate_shader_objects : enable\n"
1584 "#extension GL_ARB_shading_language_420pack : enable\n"
1585 "layout (location = 0) in vec4 color;\n"
1586 "void main() {\n"
1587 " gl_FragColor = color;\n"
1588 "}\n";
1589
1590 ASSERT_NO_FATAL_FAILURE(InitState());
1591 ASSERT_NO_FATAL_FAILURE(InitViewport());
1592
1593 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
1594 meshBuffer.SetMemoryState(m_cmdBuffer,XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
1595
1596 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1597 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1598
1599 XglPipelineObj pipelineobj(m_device);
1600 pipelineobj.AddShader(&vs);
1601 pipelineobj.AddShader(&ps);
1602
1603 XglDescriptorSetObj descriptorSet(m_device);
1604 descriptorSet.AttachMemoryView(&meshBuffer);
1605
1606 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1607 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1608 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1609 };
1610
1611 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1612 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1613 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1614 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1615 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1616 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1617 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1618 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1619 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1620
1621 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1622 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1623 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1624
Tony Barboura3953b82014-12-03 15:46:29 -07001625 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001626 QueueCommandBuffer(NULL, 0);
1627}
1628
1629TEST_F(XglRenderTest, TriVertFetchDeadAttr)
1630{
1631 // This tests that attributes work in the presence of gl_VertexID
1632 // and a dead attribute in position 0. Draws a triangle with yellow,
1633 // red and green corners, starting at top and going clockwise.
1634
1635 static const char *vertShaderText =
1636 "#version 140\n"
1637 "#extension GL_ARB_separate_shader_objects : enable\n"
1638 "#extension GL_ARB_shading_language_420pack : enable\n"
1639 //XYZ1( -1, -1, -1 )
1640 "layout (location = 0) in vec4 pos;\n"
1641 //XYZ1( 0.f, 0.f, 0.f )
1642 "layout (location = 1) in vec4 inColor;\n"
1643 "layout (location = 0) out vec4 outColor;\n"
1644 "void main() {\n"
1645 " outColor = inColor;\n"
1646 " vec2 vertices[3];"
1647 " vertices[0] = vec2(-1.0, -1.0);\n"
1648 " vertices[1] = vec2( 1.0, -1.0);\n"
1649 " vertices[2] = vec2( 0.0, 1.0);\n"
1650 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1651 "}\n";
1652
1653
1654 static const char *fragShaderText =
1655 "#version 140\n"
1656 "#extension GL_ARB_separate_shader_objects : enable\n"
1657 "#extension GL_ARB_shading_language_420pack : enable\n"
1658 "layout (location = 0) in vec4 color;\n"
1659 "void main() {\n"
1660 " gl_FragColor = color;\n"
1661 "}\n";
1662
1663 ASSERT_NO_FATAL_FAILURE(InitState());
1664 ASSERT_NO_FATAL_FAILURE(InitViewport());
1665
1666 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
1667 meshBuffer.SetMemoryState(m_cmdBuffer,XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
1668
1669 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1670 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1671
1672 XglPipelineObj pipelineobj(m_device);
1673 pipelineobj.AddShader(&vs);
1674 pipelineobj.AddShader(&ps);
1675
1676 XglDescriptorSetObj descriptorSet(m_device);
1677 descriptorSet.AttachMemoryView(&meshBuffer);
1678
1679 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1680 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1681 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1682 };
1683
1684 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1685 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1686 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1687 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1688 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1689 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1690 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1691 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1692 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1693
1694 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1695 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1696 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1697
Tony Barbour09da2212014-12-03 16:13:23 -07001698 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001699 QueueCommandBuffer(NULL, 0);
1700
1701}
1702
1703TEST_F(XglRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001704{
1705 static const char *vertShaderText =
1706 "#version 140\n"
1707 "layout (std140) uniform bufferVals {\n"
1708 " mat4 mvp;\n"
1709 "} myBufferVals;\n"
1710 "in vec4 pos;\n"
1711 "in vec4 inColor;\n"
1712 "out vec4 outColor;\n"
1713 "void main() {\n"
1714 " outColor = inColor;\n"
1715 " gl_Position = myBufferVals.mvp * pos;\n"
1716 "}\n";
1717
1718 static const char *fragShaderText =
1719 "#version 130\n"
1720 "in vec4 color;\n"
1721 "void main() {\n"
1722 " gl_FragColor = color;\n"
1723 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001724 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001725
Tony Barbourf43b6982014-11-25 13:18:32 -07001726 glm::mat4 View = glm::lookAt(
1727 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1728 glm::vec3(0,0,0), // and looks at the origin
1729 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
1730 );
1731
1732 glm::mat4 Model = glm::mat4(1.0f);
1733
1734 glm::mat4 MVP = Projection * View * Model;
1735
1736 ASSERT_NO_FATAL_FAILURE(InitState());
1737 ASSERT_NO_FATAL_FAILURE(InitViewport());
1738 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
1739
1740 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
1741 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1742
1743 const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT);
1744
1745 XglConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1746 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1747 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1748
1749 vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &MVPBuffer);
1750
1751 XglPipelineObj pipelineobj(m_device);
1752 pipelineobj.AddShader(&vs);
1753 pipelineobj.AddShader(&ps);
1754
1755 XglDescriptorSetObj descriptorSet(m_device);
1756 descriptorSet.AttachMemoryView(&MVPBuffer);
1757
1758 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1759 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1760
1761 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1762 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1763 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1764 };
1765
1766 // this is the current description of g_vbData
1767 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1768 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1769 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1770 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1771 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1772 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1773 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1774 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1775 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1776
1777 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1778 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1779 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1780
Tony Barboura3953b82014-12-03 15:46:29 -07001781 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 12);
Tony Barbourf43b6982014-11-25 13:18:32 -07001782
1783 QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
1784
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001785}
1786
Tony Barbourf43b6982014-11-25 13:18:32 -07001787TEST_F(XglRenderTest, VSTexture)
1788{
1789 // The expected result from this test is a green and red triangle;
1790 // one red vertex on the left, two green vertices on the right.
1791 static const char *vertShaderText =
1792 "#version 130\n"
1793 "out vec4 texColor;\n"
1794 "uniform sampler2D surface;\n"
1795 "void main() {\n"
1796 " vec2 vertices[3];"
1797 " vertices[0] = vec2(-0.5, -0.5);\n"
1798 " vertices[1] = vec2( 0.5, -0.5);\n"
1799 " vertices[2] = vec2( 0.5, 0.5);\n"
1800 " vec2 positions[3];"
1801 " positions[0] = vec2( 0.0, 0.0);\n"
1802 " positions[1] = vec2( 0.25, 0.1);\n"
1803 " positions[2] = vec2( 0.1, 0.25);\n"
1804 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1805 " texColor = textureLod(surface, samplePos, 0.0);\n"
1806 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1807 "}\n";
1808
1809 static const char *fragShaderText =
1810 "#version 130\n"
1811 "in vec4 texColor;\n"
1812 "void main() {\n"
1813 " gl_FragColor = texColor;\n"
1814 "}\n";
1815
1816 ASSERT_NO_FATAL_FAILURE(InitState());
1817 ASSERT_NO_FATAL_FAILURE(InitViewport());
1818
1819 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1820 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1821 XglSamplerObj sampler(m_device);
1822 XglTextureObj texture(m_device);
1823
1824 vs.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_RESOURCE, &texture);
1825 vs.BindShaderEntitySlotToSampler(0, &sampler);
1826
1827 XglPipelineObj pipelineobj(m_device);
1828 pipelineobj.AddShader(&vs);
1829 pipelineobj.AddShader(&ps);
1830
1831 XglDescriptorSetObj descriptorSet(m_device);
1832 descriptorSet.AttachImageView(&texture);
1833 descriptorSet.AttachSampler(&sampler);
1834
1835 m_memoryRefManager.AddMemoryRef(&texture);
1836
Tony Barboura3953b82014-12-03 15:46:29 -07001837 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barbourf43b6982014-11-25 13:18:32 -07001838 QueueCommandBuffer(NULL, 0);
1839
1840}
1841TEST_F(XglRenderTest, TexturedTriangle)
1842{
1843 // The expected result from this test is a red and green checkered triangle
1844 static const char *vertShaderText =
1845 "#version 140\n"
1846 "#extension GL_ARB_separate_shader_objects : enable\n"
1847 "#extension GL_ARB_shading_language_420pack : enable\n"
1848 "layout (location = 0) out vec2 samplePos;\n"
1849 "void main() {\n"
1850 " vec2 vertices[3];"
1851 " vertices[0] = vec2(-0.5, -0.5);\n"
1852 " vertices[1] = vec2( 0.5, -0.5);\n"
1853 " vertices[2] = vec2( 0.5, 0.5);\n"
1854 " vec2 positions[3];"
1855 " positions[0] = vec2( 0.0, 0.0);\n"
1856 " positions[1] = vec2( 1.0, 0.0);\n"
1857 " positions[2] = vec2( 1.0, 1.0);\n"
1858 " samplePos = positions[gl_VertexID % 3];\n"
1859 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1860 "}\n";
1861
1862 static const char *fragShaderText =
1863 "#version 140\n"
1864 "#extension GL_ARB_separate_shader_objects : enable\n"
1865 "#extension GL_ARB_shading_language_420pack : enable\n"
1866 "layout (location = 0) in vec2 samplePos;\n"
1867 "layout (binding = 0) uniform sampler2D surface;\n"
1868 "layout (location=0) out vec4 outColor;\n"
1869 "void main() {\n"
1870 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1871 " outColor = texColor;\n"
1872 "}\n";
1873
1874 ASSERT_NO_FATAL_FAILURE(InitState());
1875 ASSERT_NO_FATAL_FAILURE(InitViewport());
1876
1877 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1878 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1879 XglSamplerObj sampler(m_device);
1880 XglTextureObj texture(m_device);
1881
1882 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_RESOURCE, &texture);
1883 ps.BindShaderEntitySlotToSampler(0, &sampler);
1884
1885 XglPipelineObj pipelineobj(m_device);
1886 pipelineobj.AddShader(&vs);
1887 pipelineobj.AddShader(&ps);
1888
1889 XglDescriptorSetObj descriptorSet(m_device);
1890 descriptorSet.AttachImageView(&texture);
1891 descriptorSet.AttachSampler(&sampler);
1892
1893 m_memoryRefManager.AddMemoryRef(&texture);
1894
Tony Barboura3953b82014-12-03 15:46:29 -07001895 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barbourf43b6982014-11-25 13:18:32 -07001896 QueueCommandBuffer(NULL, 0);
1897}
1898TEST_F(XglRenderTest, TexturedTriangleClip)
1899{
1900 // The expected result from this test is a red and green checkered triangle
1901 static const char *vertShaderText =
1902 "#version 330\n"
1903 "#extension GL_ARB_separate_shader_objects : enable\n"
1904 "#extension GL_ARB_shading_language_420pack : enable\n"
1905 "layout (location = 0) out vec2 samplePos;\n"
1906 "out gl_PerVertex {\n"
1907 " vec4 gl_Position;\n"
1908 " float gl_ClipDistance[1];\n"
1909 "};\n"
1910 "void main() {\n"
1911 " vec2 vertices[3];"
1912 " vertices[0] = vec2(-0.5, -0.5);\n"
1913 " vertices[1] = vec2( 0.5, -0.5);\n"
1914 " vertices[2] = vec2( 0.5, 0.5);\n"
1915 " vec2 positions[3];"
1916 " positions[0] = vec2( 0.0, 0.0);\n"
1917 " positions[1] = vec2( 1.0, 0.0);\n"
1918 " positions[2] = vec2( 1.0, 1.0);\n"
1919 " float dists[3];\n"
1920 " dists[0] = 1.0;\n"
1921 " dists[1] = 1.0;\n"
1922 " dists[2] = -1.0;\n"
1923 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1924 " samplePos = positions[gl_VertexID % 3];\n"
1925 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1926 "}\n";
1927
1928 static const char *fragShaderText =
1929 "#version 140\n"
1930 "#extension GL_ARB_separate_shader_objects : enable\n"
1931 "#extension GL_ARB_shading_language_420pack : enable\n"
1932 "layout (location = 0) in vec2 samplePos;\n"
1933 "layout (binding = 0) uniform sampler2D surface;\n"
1934 "layout (location=0) out vec4 outColor;\n"
1935 "void main() {\n"
1936 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
1937 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1938 " outColor = texColor;\n"
1939 "}\n";
1940
1941
1942 ASSERT_NO_FATAL_FAILURE(InitState());
1943 ASSERT_NO_FATAL_FAILURE(InitViewport());
1944
1945 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1946 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1947 XglSamplerObj sampler(m_device);
1948 XglTextureObj texture(m_device);
1949
1950 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_RESOURCE, &texture);
1951 ps.BindShaderEntitySlotToSampler(0, &sampler);
1952
1953 XglPipelineObj pipelineobj(m_device);
1954 pipelineobj.AddShader(&vs);
1955 pipelineobj.AddShader(&ps);
1956
1957 XglDescriptorSetObj descriptorSet(m_device);
1958 descriptorSet.AttachImageView(&texture);
1959 descriptorSet.AttachSampler(&sampler);
1960
1961 m_memoryRefManager.AddMemoryRef(&texture);
1962
Tony Barboura3953b82014-12-03 15:46:29 -07001963 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barbourf43b6982014-11-25 13:18:32 -07001964 QueueCommandBuffer(NULL, 0);
1965}
1966TEST_F(XglRenderTest, FSTriangle)
1967{
1968 // The expected result from this test is a red and green checkered triangle
1969 static const char *vertShaderText =
1970 "#version 140\n"
1971 "#extension GL_ARB_separate_shader_objects : enable\n"
1972 "#extension GL_ARB_shading_language_420pack : enable\n"
1973 "layout (location = 0) out vec2 samplePos;\n"
1974 "void main() {\n"
1975 " vec2 vertices[3];"
1976 " vertices[0] = vec2(-0.5, -0.5);\n"
1977 " vertices[1] = vec2( 0.5, -0.5);\n"
1978 " vertices[2] = vec2( 0.5, 0.5);\n"
1979 " vec2 positions[3];"
1980 " positions[0] = vec2( 0.0, 0.0);\n"
1981 " positions[1] = vec2( 1.0, 0.0);\n"
1982 " positions[2] = vec2( 1.0, 1.0);\n"
1983 " samplePos = positions[gl_VertexID % 3];\n"
1984 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1985 "}\n";
1986
1987 static const char *fragShaderText =
1988 "#version 140\n"
1989 "#extension GL_ARB_separate_shader_objects : enable\n"
1990 "#extension GL_ARB_shading_language_420pack : enable\n"
1991 "layout (location = 0) in vec2 samplePos;\n"
1992 "layout (binding = 0) uniform sampler2D surface;\n"
1993 "layout (location=0) out vec4 outColor;\n"
1994 "void main() {\n"
1995 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1996 " outColor = texColor;\n"
1997 "}\n";
1998
1999 ASSERT_NO_FATAL_FAILURE(InitState());
2000 ASSERT_NO_FATAL_FAILURE(InitViewport());
2001
2002 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2003 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2004 XglSamplerObj sampler(m_device);
2005 XglTextureObj texture(m_device);
2006
2007 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_RESOURCE, &texture);
2008 ps.BindShaderEntitySlotToSampler(0, &sampler);
2009
2010 XglPipelineObj pipelineobj(m_device);
2011 pipelineobj.AddShader(&vs);
2012 pipelineobj.AddShader(&ps);
2013
2014 XglDescriptorSetObj descriptorSet(m_device);
2015 descriptorSet.AttachImageView(&texture);
2016 descriptorSet.AttachSampler(&sampler);
2017
2018 m_memoryRefManager.AddMemoryRef(&texture);
2019
Tony Barboura3953b82014-12-03 15:46:29 -07002020 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barbourf43b6982014-11-25 13:18:32 -07002021 QueueCommandBuffer(NULL, 0);
2022}
2023TEST_F(XglRenderTest, SamplerBindingsTriangle)
2024{
2025 // This test sets bindings on the samplers
2026 // For now we are asserting that sampler and texture pairs
2027 // march in lock step, and are set via GLSL binding. This can
2028 // and will probably change.
2029 // The sampler bindings should match the sampler and texture slot
2030 // number set up by the application.
2031 // This test will result in a blue triangle
2032 static const char *vertShaderText =
2033 "#version 140\n"
2034 "#extension GL_ARB_separate_shader_objects : enable\n"
2035 "#extension GL_ARB_shading_language_420pack : enable\n"
2036 "layout (location = 0) out vec4 samplePos;\n"
2037 "void main() {\n"
2038 " vec2 vertices[3];"
2039 " vertices[0] = vec2(-0.5, -0.5);\n"
2040 " vertices[1] = vec2( 0.5, -0.5);\n"
2041 " vertices[2] = vec2( 0.5, 0.5);\n"
2042 " vec2 positions[3];"
2043 " positions[0] = vec2( 0.0, 0.0);\n"
2044 " positions[1] = vec2( 1.0, 0.0);\n"
2045 " positions[2] = vec2( 1.0, 1.0);\n"
2046 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2047 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2048 "}\n";
2049
2050 static const char *fragShaderText =
2051 "#version 140\n"
2052 "#extension GL_ARB_separate_shader_objects : enable\n"
2053 "#extension GL_ARB_shading_language_420pack : enable\n"
2054 "layout (location = 0) in vec4 samplePos;\n"
2055 "layout (binding = 0) uniform sampler2D surface0;\n"
2056 "layout (binding = 1) uniform sampler2D surface1;\n"
2057 "layout (binding = 12) uniform sampler2D surface2;\n"
2058 "void main() {\n"
2059 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
2060 "}\n";
2061
2062 ASSERT_NO_FATAL_FAILURE(InitState());
2063 ASSERT_NO_FATAL_FAILURE(InitViewport());
2064
2065 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2066 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2067
2068 XglSamplerObj sampler1(m_device);
2069 XglSamplerObj sampler2(m_device);
2070 XglSamplerObj sampler3(m_device);
2071
2072 XglTextureObj texture1(m_device); // Red
2073 texture1.ChangeColors(0xffff0000,0xffff0000);
2074 XglTextureObj texture2(m_device); // Green
2075 texture2.ChangeColors(0xff00ff00,0xff00ff00);
2076 XglTextureObj texture3(m_device); // Blue
2077 texture3.ChangeColors(0xff0000ff,0xff0000ff);
2078
2079 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_RESOURCE, &texture1);
2080 ps.BindShaderEntitySlotToSampler(0, &sampler1);
2081
2082 ps.BindShaderEntitySlotToImage(1, XGL_SLOT_SHADER_RESOURCE, &texture2);
2083 ps.BindShaderEntitySlotToSampler(1, &sampler2);
2084
2085 ps.BindShaderEntitySlotToImage(12, XGL_SLOT_SHADER_RESOURCE, &texture3);
2086 ps.BindShaderEntitySlotToSampler(12, &sampler3);
2087
2088 XglPipelineObj pipelineobj(m_device);
2089 pipelineobj.AddShader(&vs);
2090 pipelineobj.AddShader(&ps);
2091
2092 XglDescriptorSetObj descriptorSet(m_device);
2093 descriptorSet.AttachImageView(&texture1);
2094 descriptorSet.AttachSampler(&sampler1);
2095 descriptorSet.AttachImageView(&texture2);
2096 descriptorSet.AttachSampler(&sampler2);
2097 descriptorSet.AttachImageView(&texture3);
2098 descriptorSet.AttachSampler(&sampler3);
2099
2100 m_memoryRefManager.AddMemoryRef(&texture1);
2101 m_memoryRefManager.AddMemoryRef(&texture2);
2102 m_memoryRefManager.AddMemoryRef(&texture3);
2103
Tony Barboura3953b82014-12-03 15:46:29 -07002104 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barbourf43b6982014-11-25 13:18:32 -07002105 QueueCommandBuffer(NULL, 0);
2106
2107}
2108
2109TEST_F(XglRenderTest, TriangleVSUniformBlock)
2110{
2111 // The expected result from this test is a blue triangle
2112
2113 static const char *vertShaderText =
2114 "#version 140\n"
2115 "#extension GL_ARB_separate_shader_objects : enable\n"
2116 "#extension GL_ARB_shading_language_420pack : enable\n"
2117 "layout (location = 0) out vec4 outColor;\n"
2118 "layout (std140, binding = 0) uniform bufferVals {\n"
2119 " vec4 red;\n"
2120 " vec4 green;\n"
2121 " vec4 blue;\n"
2122 " vec4 white;\n"
2123 "} myBufferVals;\n"
2124 "void main() {\n"
2125 " vec2 vertices[3];"
2126 " vertices[0] = vec2(-0.5, -0.5);\n"
2127 " vertices[1] = vec2( 0.5, -0.5);\n"
2128 " vertices[2] = vec2( 0.5, 0.5);\n"
2129 " outColor = myBufferVals.blue;\n"
2130 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2131 "}\n";
2132
2133 static const char *fragShaderText =
2134 "#version 140\n"
2135 "#extension GL_ARB_separate_shader_objects : enable\n"
2136 "#extension GL_ARB_shading_language_420pack : enable\n"
2137 "layout (location = 0) in vec4 inColor;\n"
2138 "void main() {\n"
2139 " gl_FragColor = inColor;\n"
2140 "}\n";
2141
2142 ASSERT_NO_FATAL_FAILURE(InitState());
2143 ASSERT_NO_FATAL_FAILURE(InitViewport());
2144
2145 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2146 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2147
2148 // Let's populate our buffer with the following:
2149 // vec4 red;
2150 // vec4 green;
2151 // vec4 blue;
2152 // vec4 white;
2153 const int valCount = 4 * 4;
2154 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2155 0.0, 1.0, 0.0, 1.0,
2156 0.0, 0.0, 1.0, 1.0,
2157 1.0, 1.0, 1.0, 1.0 };
2158
2159 XglConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
2160 vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &colorBuffer);
2161
2162 XglPipelineObj pipelineobj(m_device);
2163 pipelineobj.AddShader(&vs);
2164 pipelineobj.AddShader(&ps);
2165
2166 XglDescriptorSetObj descriptorSet(m_device);
2167 descriptorSet.AttachMemoryView(&colorBuffer);
2168
Tony Barboura3953b82014-12-03 15:46:29 -07002169 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barbourf43b6982014-11-25 13:18:32 -07002170 QueueCommandBuffer(NULL, 0);
2171
2172}
2173
2174TEST_F(XglRenderTest, TriangleFSUniformBlockBinding)
2175{
2176 // This test allows the shader to select which buffer it is
2177 // pulling from using layout binding qualifier.
2178 // There are corresponding changes in the compiler stack that
2179 // will select the buffer using binding directly.
2180 // The binding number should match the slot number set up by
2181 // the application.
2182 // The expected result from this test is a purple triangle
2183
2184 static const char *vertShaderText =
2185 "#version 140\n"
2186 "#extension GL_ARB_separate_shader_objects : enable\n"
2187 "#extension GL_ARB_shading_language_420pack : enable\n"
2188 "void main() {\n"
2189 " vec2 vertices[3];"
2190 " vertices[0] = vec2(-0.5, -0.5);\n"
2191 " vertices[1] = vec2( 0.5, -0.5);\n"
2192 " vertices[2] = vec2( 0.5, 0.5);\n"
2193 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2194 "}\n";
2195
2196 static const char *fragShaderText =
2197 "#version 140\n"
2198 "#extension GL_ARB_separate_shader_objects : enable\n"
2199 "#extension GL_ARB_shading_language_420pack : enable\n"
2200 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2201 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2202 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
2203 "layout (std140, binding = 18) uniform whiteVal { vec4 color; } myWhiteVal\n;"
2204 "void main() {\n"
2205 " gl_FragColor = myBlueVal.color;\n"
2206 " gl_FragColor += myRedVal.color;\n"
2207 "}\n";
2208
2209 ASSERT_NO_FATAL_FAILURE(InitState());
2210 ASSERT_NO_FATAL_FAILURE(InitViewport());
2211
2212 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2213 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2214
2215 // We're going to create a number of uniform buffers, and then allow
2216 // the shader to select which it wants to read from with a binding
2217
2218 // Let's populate the buffers with a single color each:
2219 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2220 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2221 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2222 // layout (std140, binding = 18) uniform bufferVals { vec4 white; } myWhiteVal;
2223
2224 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2225 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2226 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2227 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2228
2229 const int redCount = sizeof(redVals) / sizeof(float);
2230 const int greenCount = sizeof(greenVals) / sizeof(float);
2231 const int blueCount = sizeof(blueVals) / sizeof(float);
2232 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2233
2234 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2235 ps.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &redBuffer);
2236
2237 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2238 ps.BindShaderEntitySlotToMemory(1, XGL_SLOT_SHADER_RESOURCE, &greenBuffer);
2239
2240 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2241 ps.BindShaderEntitySlotToMemory(2, XGL_SLOT_SHADER_RESOURCE, &blueBuffer);
2242
2243 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
2244 ps.BindShaderEntitySlotToMemory(18, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer);
2245
2246 XglPipelineObj pipelineobj(m_device);
2247 pipelineobj.AddShader(&vs);
2248 pipelineobj.AddShader(&ps);
2249
2250 XglDescriptorSetObj descriptorSet(m_device);
2251 descriptorSet.AttachMemoryView(&redBuffer);
2252 descriptorSet.AttachMemoryView(&greenBuffer);
2253 descriptorSet.AttachMemoryView(&blueBuffer);
2254 descriptorSet.AttachMemoryView(&whiteBuffer);
2255
Tony Barboura3953b82014-12-03 15:46:29 -07002256 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barbourf43b6982014-11-25 13:18:32 -07002257 QueueCommandBuffer(NULL, 0);
2258
2259}
2260
2261TEST_F(XglRenderTest, TriangleFSAnonymousUniformBlockBinding)
2262{
2263 // This test is the same as TriangleFSUniformBlockBinding, but
2264 // it does not provide an instance name.
2265 // The expected result from this test is a purple triangle
2266
2267 static const char *vertShaderText =
2268 "#version 140\n"
2269 "#extension GL_ARB_separate_shader_objects : enable\n"
2270 "#extension GL_ARB_shading_language_420pack : enable\n"
2271 "void main() {\n"
2272 " vec2 vertices[3];"
2273 " vertices[0] = vec2(-0.5, -0.5);\n"
2274 " vertices[1] = vec2( 0.5, -0.5);\n"
2275 " vertices[2] = vec2( 0.5, 0.5);\n"
2276 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2277 "}\n";
2278
2279 static const char *fragShaderText =
2280 "#version 430\n"
2281 "#extension GL_ARB_separate_shader_objects : enable\n"
2282 "#extension GL_ARB_shading_language_420pack : enable\n"
2283 "layout (location = 0) uniform vec4 foo;\n"
2284 "layout (location = 1) uniform vec4 bar;\n"
2285 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2286 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2287 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
2288 "layout (std140, binding = 18) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002289 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002290 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002291 " outColor = blue;\n"
2292 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002293 "}\n";
2294 ASSERT_NO_FATAL_FAILURE(InitState());
2295 ASSERT_NO_FATAL_FAILURE(InitViewport());
2296
2297 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2298 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2299
2300 // We're going to create a number of uniform buffers, and then allow
2301 // the shader to select which it wants to read from with a binding
2302
2303 // Let's populate the buffers with a single color each:
2304 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2305 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2306 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2307 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2308
2309 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2310 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2311 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2312 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2313
2314 const int redCount = sizeof(redVals) / sizeof(float);
2315 const int greenCount = sizeof(greenVals) / sizeof(float);
2316 const int blueCount = sizeof(blueVals) / sizeof(float);
2317 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2318
2319 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
2320 ps.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &redBuffer);
2321
2322 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
2323 ps.BindShaderEntitySlotToMemory(1, XGL_SLOT_SHADER_RESOURCE, &greenBuffer);
2324
2325 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
2326 ps.BindShaderEntitySlotToMemory(2, XGL_SLOT_SHADER_RESOURCE, &blueBuffer);
2327
2328 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
2329 ps.BindShaderEntitySlotToMemory(3, XGL_SLOT_SHADER_RESOURCE, &whiteBuffer);
2330
2331 XglPipelineObj pipelineobj(m_device);
2332 pipelineobj.AddShader(&vs);
2333 pipelineobj.AddShader(&ps);
2334
2335 XglDescriptorSetObj descriptorSet(m_device);
2336 descriptorSet.AttachMemoryView(&redBuffer);
2337 descriptorSet.AttachMemoryView(&greenBuffer);
2338 descriptorSet.AttachMemoryView(&blueBuffer);
2339 descriptorSet.AttachMemoryView(&whiteBuffer);
2340
Tony Barboura3953b82014-12-03 15:46:29 -07002341 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 1);
Tony Barbourf43b6982014-11-25 13:18:32 -07002342 QueueCommandBuffer(NULL, 0);
2343
2344}
2345
2346TEST_F(XglRenderTest, CubeWithVertexFetchAndMVPAndTexture)
2347{
2348 static const char *vertShaderText =
2349 "#version 140\n"
2350 "#extension GL_ARB_separate_shader_objects : enable\n"
2351 "#extension GL_ARB_shading_language_420pack : enable\n"
2352 "layout (std140, binding=0) uniform bufferVals {\n"
2353 " mat4 mvp;\n"
2354 "} myBufferVals;\n"
2355 "layout (location=0) in vec4 pos;\n"
2356 "layout (location=0) out vec2 UV;\n"
2357 "void main() {\n"
2358 " vec2 positions[3];"
2359 " positions[0] = vec2( 0.0, 0.0);\n"
2360 " positions[1] = vec2( 0.25, 0.1);\n"
2361 " positions[2] = vec2( 0.1, 0.25);\n"
2362 " UV = positions[gl_VertexID % 3];\n"
2363 " gl_Position = myBufferVals.mvp * pos;\n"
2364 "}\n";
2365
2366 static const char *fragShaderText =
2367 "#version 140\n"
2368 "#extension GL_ARB_separate_shader_objects : enable\n"
2369 "#extension GL_ARB_shading_language_420pack : enable\n"
2370 "layout (binding=0) uniform sampler2D surface;\n"
2371 "layout (location=0) out vec4 outColor;\n"
2372 "layout (location=0) in vec2 UV;\n"
2373 "void main() {\n"
2374 " outColor= textureLod(surface, UV, 0.0);\n"
2375 "}\n";
2376 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2377
2378 glm::mat4 View = glm::lookAt(
2379 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2380 glm::vec3(0,0,0), // and looks at the origin
2381 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2382 );
2383
2384 glm::mat4 Model = glm::mat4(1.0f);
2385
2386 glm::mat4 MVP = Projection * View * Model;
2387
2388
2389 ASSERT_NO_FATAL_FAILURE(InitState());
2390 ASSERT_NO_FATAL_FAILURE(InitViewport());
2391 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
2392
2393 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
2394 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
2395 meshBuffer.SetMemoryState(m_cmdBuffer,XGL_MEMORY_STATE_GRAPHICS_SHADER_READ_ONLY);
2396
2397
2398 const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT);
2399
2400 XglConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2401 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2402 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2403 XglSamplerObj sampler(m_device);
2404 XglTextureObj texture(m_device);
2405
2406 // vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_VERTEX_INPUT, (XGL_OBJECT) &meshBuffer.m_constantBufferView);
2407 vs.BindShaderEntitySlotToMemory(0, XGL_SLOT_SHADER_RESOURCE, &mvpBuffer);
2408 ps.BindShaderEntitySlotToImage(0, XGL_SLOT_SHADER_RESOURCE, &texture);
2409 ps.BindShaderEntitySlotToSampler(0, &sampler);
2410
2411 XglPipelineObj pipelineobj(m_device);
2412 pipelineobj.AddShader(&vs);
2413 pipelineobj.AddShader(&ps);
2414
2415 XglDescriptorSetObj descriptorSet(m_device);
2416
2417 descriptorSet.AttachMemoryView(&mvpBuffer);
2418 descriptorSet.AttachImageView(&texture);
2419 descriptorSet.AttachSampler(&sampler);
2420
2421 m_memoryRefManager.AddMemoryRef(&meshBuffer);
2422 m_memoryRefManager.AddMemoryRef(&mvpBuffer);
2423 m_memoryRefManager.AddMemoryRef(&texture);
2424
2425 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
2426 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
2427 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
2428 };
2429
2430 // this is the current description of g_vbData
2431 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
2432 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
2433 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
2434 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
2435 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2436 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
2437 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
2438 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
2439 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
2440
2441 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2442 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
2443 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
2444
Tony Barboura3953b82014-12-03 15:46:29 -07002445 GenericDrawTriangleTest(&pipelineobj, &descriptorSet, 12);
Tony Barbourf43b6982014-11-25 13:18:32 -07002446
2447 QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
2448
2449}
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06002450int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06002451 int result;
2452
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06002453 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06002454 XglTestFramework::InitArgs(&argc, argv);
2455
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06002456 ::testing::Environment* const xgl_test_env = ::testing::AddGlobalTestEnvironment(new TestEnvironment);
2457
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06002458 result = RUN_ALL_TESTS();
2459
2460 XglTestFramework::Finish();
2461 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06002462}