blob: eb1efd86689424b2987de3490803489931bd8d2d [file] [log] [blame]
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06001// Copyright 2005, Google Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14// * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30
31// XGL tests
32//
33// Copyright (C) 2014 LunarG, Inc.
34//
35// Permission is hereby granted, free of charge, to any person obtaining a
36// copy of this software and associated documentation files (the "Software"),
37// to deal in the Software without restriction, including without limitation
38// the rights to use, copy, modify, merge, publish, distribute, sublicense,
39// and/or sell copies of the Software, and to permit persons to whom the
40// Software is furnished to do so, subject to the following conditions:
41//
42// The above copyright notice and this permission notice shall be included
43// in all copies or substantial portions of the Software.
44//
45// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
48// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
49// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
50// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
51// DEALINGS IN THE SOFTWARE.
52
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060053// Basic rendering tests
54
55#include <stdlib.h>
56#include <stdio.h>
57#include <stdbool.h>
58#include <string.h>
Courtney Goeltzenleuchter76a643b2014-08-21 17:34:22 -060059#include <iostream>
60#include <fstream>
61using namespace std;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060062
63#include <xgl.h>
Tobin Ehlis31446e52014-11-28 11:17:19 -070064#ifdef DUMP_STATE_DOT
65#include "../layers/draw_state.h"
66#endif
Tobin Ehlis3c26a542014-11-18 11:28:33 -070067#ifdef PRINT_OBJECTS
68#include "../layers/object_track.h"
69#endif
Tobin Ehlis791a49c2014-11-10 12:29:12 -070070#ifdef DEBUG_CALLBACK
71#include <xglDbg.h>
72#endif
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060073#include "gtest-1.7.0/include/gtest/gtest.h"
74
Cody Northropd4e020a2015-03-17 14:54:35 -060075#include "icd-spv.h"
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060076
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -060077#define GLM_FORCE_RADIANS
78#include "glm/glm.hpp"
79#include <glm/gtc/matrix_transform.hpp>
80
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -060081#include "xglrenderframework.h"
Tobin Ehlis791a49c2014-11-10 12:29:12 -070082#ifdef DEBUG_CALLBACK
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060083void XGLAPI myDbgFunc(
Tobin Ehlis791a49c2014-11-10 12:29:12 -070084 XGL_DBG_MSG_TYPE msgType,
85 XGL_VALIDATION_LEVEL validationLevel,
86 XGL_BASE_OBJECT srcObject,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060087 size_t location,
88 int32_t msgCode,
89 const char* pMsg,
90 void* pUserData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -070091{
Tobin Ehlis3c26a542014-11-18 11:28:33 -070092 switch (msgType)
93 {
94 case XGL_DBG_MSG_WARNING:
95 printf("CALLBACK WARNING : %s\n", pMsg);
96 break;
97 case XGL_DBG_MSG_ERROR:
98 printf("CALLBACK ERROR : %s\n", pMsg);
99 break;
100 default:
101 printf("EATING Msg of type %u\n", msgType);
102 break;
103 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700104}
105#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700106
107
108#undef ASSERT_NO_FATAL_FAILURE
109#define ASSERT_NO_FATAL_FAILURE(x) x
110
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600111//--------------------------------------------------------------------------------------
112// Mesh and VertexFormat Data
113//--------------------------------------------------------------------------------------
114struct Vertex
115{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600116 float posX, posY, posZ, posW; // Position data
117 float r, g, b, a; // Color
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600118};
119
120#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
121
122static const Vertex g_vbData[] =
123{
124 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
125 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
126 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
127 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
128 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
129 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
130
131 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
132 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
133 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
134 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
135 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
136 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
137
138 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
139 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
140 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
141 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
142 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
143 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
144
145 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
146 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
147 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
148 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
149 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
150 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
151
152 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
153 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
154 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
155 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
156 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
157 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
158
159 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
160 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
161 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
162 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
163 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
164 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
165};
166
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600167static const Vertex g_vb_solid_face_colors_Data[] =
168{
169 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
170 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
171 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
172 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
173 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
174 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
175
176 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
177 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
178 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
179 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
180 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
181 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
182
183 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
184 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
185 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
186 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
187 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
188 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
189
190 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
191 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
192 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
193 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
194 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
195 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
196
197 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
198 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
199 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
200 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
201 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
202 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
203
204 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
205 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
206 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
207 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
208 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
209 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
210};
211
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600212class XglRenderTest : public XglRenderFramework
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -0600213{
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600214public:
Cody Northrop4e6b4762014-10-09 21:25:22 -0600215
Tony Barbourf43b6982014-11-25 13:18:32 -0700216 void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbourdd4c9642015-01-09 12:55:14 -0700217 XglConstantBufferObj *constantBuffer, XglCommandBufferObj *cmdBuffer);
Tony Barbour02472db2015-01-08 17:08:28 -0700218 void GenericDrawPreparation(XglCommandBufferObj *cmdBuffer, XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600219 void InitDepthStencil();
Tony Barbourae442072015-01-12 13:27:11 -0700220 void XGLTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate);
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600221
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600222 XGL_RESULT BeginCommandBuffer(XglCommandBufferObj &cmdBuffer);
223 XGL_RESULT EndCommandBuffer(XglCommandBufferObj &cmdBuffer);
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600224
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600225protected:
Cody Northrop350727b2014-10-06 15:42:00 -0600226 XGL_IMAGE m_texture;
227 XGL_IMAGE_VIEW m_textureView;
228 XGL_IMAGE_VIEW_ATTACH_INFO m_textureViewInfo;
229 XGL_GPU_MEMORY m_textureMem;
230
231 XGL_SAMPLER m_sampler;
Tony Barbourf43b6982014-11-25 13:18:32 -0700232 XglMemoryRefManager m_memoryRefManager;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600233
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600234
235 virtual void SetUp() {
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600236
237 this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO;
238 this->app_info.pNext = NULL;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800239 this->app_info.pAppName = "render_tests";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600240 this->app_info.appVersion = 1;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800241 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600242 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter211cc542015-02-23 17:40:15 -0700243 this->app_info.apiVersion = XGL_API_VERSION;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600244
Cody Northrop350727b2014-10-06 15:42:00 -0600245 memset(&m_textureViewInfo, 0, sizeof(m_textureViewInfo));
246 m_textureViewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO;
247
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600248 InitFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600249 }
250
251 virtual void TearDown() {
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600252 // Clean up resources before we reset
253 ShutdownFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600254 }
255};
256
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600257XGL_RESULT XglRenderTest::BeginCommandBuffer(XglCommandBufferObj &cmdBuffer)
258{
259 XGL_RESULT result;
260
261 result = cmdBuffer.BeginCommandBuffer();
262
263 /*
264 * For render test all drawing happens in a single render pass
265 * on a single command buffer.
266 */
267 if (XGL_SUCCESS == result) {
268 cmdBuffer.BeginRenderPass(renderPass(), framebuffer());
269 }
270
271 return result;
272}
273
274XGL_RESULT XglRenderTest::EndCommandBuffer(XglCommandBufferObj &cmdBuffer)
275{
276 XGL_RESULT result;
277
278 cmdBuffer.EndRenderPass(renderPass());
279
280 result = cmdBuffer.EndCommandBuffer();
281
282 return result;
283}
284
285
Tony Barbour02472db2015-01-08 17:08:28 -0700286void XglRenderTest::GenericDrawPreparation(XglCommandBufferObj *cmdBuffer, XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet)
287{
Tony Barbour17c6ab12015-03-27 17:03:18 -0600288 if (m_depthStencil->Initialized()) {
289 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color,
290 m_depthStencil->BindInfo(), m_depthStencil->obj());
291 } else {
292 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color,
293 NULL, NULL);
294 }
295
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700296 cmdBuffer->PrepareAttachments();
Tony Barbour02472db2015-01-08 17:08:28 -0700297 cmdBuffer->BindStateObject(XGL_STATE_BIND_RASTER, m_stateRaster);
298 cmdBuffer->BindStateObject(XGL_STATE_BIND_VIEWPORT, m_stateViewport);
299 cmdBuffer->BindStateObject(XGL_STATE_BIND_COLOR_BLEND, m_colorBlend);
300 cmdBuffer->BindStateObject(XGL_STATE_BIND_DEPTH_STENCIL, m_stateDepthStencil);
Chia-I Wuf8385062015-01-04 16:27:24 +0800301 descriptorSet->CreateXGLDescriptorSet(cmdBuffer);
Tony Barbour02472db2015-01-08 17:08:28 -0700302 pipelineobj->CreateXGLPipeline(descriptorSet);
303 cmdBuffer->BindPipeline(pipelineobj->GetPipelineHandle());
Tony Barbour02472db2015-01-08 17:08:28 -0700304 cmdBuffer->BindDescriptorSet(descriptorSet->GetDescriptorSetHandle());
305}
Tony Barbourf43b6982014-11-25 13:18:32 -0700306
Tony Barbourf43b6982014-11-25 13:18:32 -0700307void XglRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbourdd4c9642015-01-09 12:55:14 -0700308 XglConstantBufferObj *constantBuffer, XglCommandBufferObj *cmdBuffer)
309{
310 int i;
311 glm::mat4 MVP;
312 int matrixSize = sizeof(MVP);
313 XGL_RESULT err;
314
315 for (i = 0; i < 8; i++) {
316 void *pData = constantBuffer->map();
317
318 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
319 MVP = Projection * View * Model;
320 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
321
322 constantBuffer->unmap();
323
324 // submit the command buffer to the universal queue
325 cmdBuffer->QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
326
Tony Barbourdd4c9642015-01-09 12:55:14 -0700327 err = xglQueueWaitIdle( m_device->m_queue );
328 ASSERT_XGL_SUCCESS( err );
329
330 // Wait for work to finish before cleaning up.
331 xglDeviceWaitIdle(m_device->device());
332
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700333 assert(m_renderTargets.size() == 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -0700334 RecordImage(m_renderTargets[0]);
335 }
336}
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600337
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600338void dumpMatrix(const char *note, glm::mat4 MVP)
339{
Chia-I Wu7133fdc2014-12-15 23:57:34 +0800340 int i;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600341
342 printf("%s: \n", note);
343 for (i=0; i<4; i++) {
344 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
345 }
346 printf("\n");
347 fflush(stdout);
348}
349
350void dumpVec4(const char *note, glm::vec4 vector)
351{
352 printf("%s: \n", note);
353 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
354 printf("\n");
355 fflush(stdout);
356}
357
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600358struct xgltriangle_vs_uniform {
359 // Must start with MVP
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600360 float mvp[4][4];
361 float position[3][4];
362 float color[3][4];
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600363};
364
Tony Barbourae442072015-01-12 13:27:11 -0700365void XglRenderTest::XGLTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600366{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700367#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9d36ef42015-04-13 14:10:06 -0600368 xglDbgRegisterMsgCallback(inst, myDbgFunc, NULL);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700369#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600370 // Create identity matrix
371 int i;
372 struct xgltriangle_vs_uniform data;
373
374 glm::mat4 Projection = glm::mat4(1.0f);
375 glm::mat4 View = glm::mat4(1.0f);
376 glm::mat4 Model = glm::mat4(1.0f);
377 glm::mat4 MVP = Projection * View * Model;
378 const int matrixSize = sizeof(MVP);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600379 const int bufSize = sizeof(xgltriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600380 memcpy(&data.mvp, &MVP[0][0], matrixSize);
381
382 static const Vertex tri_data[] =
383 {
384 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
385 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
386 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
387 };
388
389 for (i=0; i<3; i++) {
390 data.position[i][0] = tri_data[i].posX;
391 data.position[i][1] = tri_data[i].posY;
392 data.position[i][2] = tri_data[i].posZ;
393 data.position[i][3] = tri_data[i].posW;
394 data.color[i][0] = tri_data[i].r;
395 data.color[i][1] = tri_data[i].g;
396 data.color[i][2] = tri_data[i].b;
397 data.color[i][3] = tri_data[i].a;
398 }
399
Tony Barbourf43b6982014-11-25 13:18:32 -0700400 ASSERT_NO_FATAL_FAILURE(InitState());
401 ASSERT_NO_FATAL_FAILURE(InitViewport());
402
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600403 XglConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barbourf43b6982014-11-25 13:18:32 -0700404
405 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
406 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700407
408 XglPipelineObj pipelineobj(m_device);
409 pipelineobj.AddShader(&vs);
410 pipelineobj.AddShader(&ps);
411
412 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +0800413 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700414 m_memoryRefManager.AddMemoryRef(&constantBuffer);
415
Tony Barbour71ba3612015-01-09 16:12:35 -0700416 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700417 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbour71ba3612015-01-09 16:12:35 -0700418 XglCommandBufferObj cmdBuffer(m_device);
419 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700420
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600421 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour71ba3612015-01-09 16:12:35 -0700422
423 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Tony Barbour71ba3612015-01-09 16:12:35 -0700424#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600425 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour71ba3612015-01-09 16:12:35 -0700426 pDSDumpDot((char*)"triTest2.dot");
427#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600428
Tony Barbour71ba3612015-01-09 16:12:35 -0700429 // render triangle
430 cmdBuffer.Draw(0, 3, 0, 1);
431
432 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600433 EndCommandBuffer(cmdBuffer);
434
Tony Barbour71ba3612015-01-09 16:12:35 -0700435 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
436
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700437 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbour71ba3612015-01-09 16:12:35 -0700438 RecordImage(m_renderTargets[i]);
439
440 if (rotate)
Tobin Ehlis12ee35f2015-03-26 08:23:25 -0600441 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
Tony Barbour71ba3612015-01-09 16:12:35 -0700442
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700443#ifdef PRINT_OBJECTS
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600444 //uint64_t objTrackGetObjectCount(XGL_OBJECT_TYPE type)
445 OBJ_TRACK_GET_OBJECT_COUNT pObjTrackGetObjectCount = (OBJ_TRACK_GET_OBJECT_COUNT)xglGetProcAddr(gpu(), (char*)"objTrackGetObjectCount");
446 uint64_t numObjects = pObjTrackGetObjectCount(XGL_OBJECT_TYPE_ANY);
447 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = xglGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700448 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600449 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)xglGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700450 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
451 pObjTrackGetObjs(XGL_OBJECT_TYPE_ANY, numObjects, pObjNodeArray);
452 for (i=0; i < numObjects; i++) {
453 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);
454 }
455 free(pObjNodeArray);
456#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700457
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600458}
459
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600460TEST_F(XglRenderTest, XGLTriangle_FragColor)
461{
462 static const char *vertShaderText =
463 "#version 140\n"
464 "#extension GL_ARB_separate_shader_objects : enable\n"
465 "#extension GL_ARB_shading_language_420pack : enable\n"
466 "\n"
467 "layout(binding = 0) uniform buf {\n"
468 " mat4 MVP;\n"
469 " vec4 position[3];\n"
470 " vec4 color[3];\n"
471 "} ubuf;\n"
472 "\n"
473 "layout (location = 0) out vec4 outColor;\n"
474 "\n"
475 "void main() \n"
476 "{\n"
477 " outColor = ubuf.color[gl_VertexID];\n"
478 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
479 "}\n";
480
481 static const char *fragShaderText =
482 "#version 140\n"
483 "#extension GL_ARB_separate_shader_objects : enable\n"
484 "#extension GL_ARB_shading_language_420pack : enable\n"
485 "\n"
486 "layout (location = 0) in vec4 inColor;\n"
487 "\n"
488 "void main()\n"
489 "{\n"
490 " gl_FragColor = inColor;\n"
491 "}\n";
492
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600493 TEST_DESCRIPTION("XGL-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
Tony Barbourae442072015-01-12 13:27:11 -0700494 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600495}
496
497TEST_F(XglRenderTest, XGLTriangle_OutputLocation)
498{
499 static const char *vertShaderText =
500 "#version 140\n"
501 "#extension GL_ARB_separate_shader_objects : enable\n"
502 "#extension GL_ARB_shading_language_420pack : enable\n"
503 "\n"
504 "layout(binding = 0) uniform buf {\n"
505 " mat4 MVP;\n"
506 " vec4 position[3];\n"
507 " vec4 color[3];\n"
508 "} ubuf;\n"
509 "\n"
510 "layout (location = 0) out vec4 outColor;\n"
511 "\n"
512 "void main() \n"
513 "{\n"
514 " outColor = ubuf.color[gl_VertexID];\n"
515 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
516 "}\n";
517
518 static const char *fragShaderText =
519 "#version 140\n"
520 "#extension GL_ARB_separate_shader_objects : enable\n"
521 "#extension GL_ARB_shading_language_420pack : enable\n"
522 "\n"
523 "layout (location = 0) in vec4 inColor;\n"
524 "layout (location = 0) out vec4 outColor;\n"
525 "\n"
526 "void main()\n"
527 "{\n"
528 " outColor = inColor;\n"
529 "}\n";
530
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600531 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 -0600532
Tony Barbourae442072015-01-12 13:27:11 -0700533 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600534}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600535#ifndef _WIN32 // Implicit (for now at least) in WIN32 is that we are using the Nvidia driver and it won't consume SPIRV yet
Cody Northropacfb0492015-03-17 15:55:58 -0600536TEST_F(XglRenderTest, SPV_XGLTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700537{
Cody Northropacfb0492015-03-17 15:55:58 -0600538 bool saved_use_spv = XglTestFramework::m_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700539
540 static const char *vertShaderText =
541 "#version 140\n"
542 "#extension GL_ARB_separate_shader_objects : enable\n"
543 "#extension GL_ARB_shading_language_420pack : enable\n"
544 "\n"
545 "layout(binding = 0) uniform buf {\n"
546 " mat4 MVP;\n"
547 " vec4 position[3];\n"
548 " vec4 color[3];\n"
549 "} ubuf;\n"
550 "\n"
551 "layout (location = 0) out vec4 outColor;\n"
552 "\n"
553 "void main() \n"
554 "{\n"
555 " outColor = ubuf.color[gl_VertexID];\n"
556 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
557 "}\n";
558
559 static const char *fragShaderText =
560 "#version 140\n"
561 "#extension GL_ARB_separate_shader_objects : enable\n"
562 "#extension GL_ARB_shading_language_420pack : enable\n"
563 "\n"
564 "layout (location = 0) in vec4 inColor;\n"
565 "\n"
566 "void main()\n"
567 "{\n"
568 " gl_FragColor = inColor;\n"
569 "}\n";
570
Cody Northropacfb0492015-03-17 15:55:58 -0600571 TEST_DESCRIPTION("XGL-style shaders, but force test framework to compile shader to SPV and pass SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700572
Cody Northropacfb0492015-03-17 15:55:58 -0600573 XglTestFramework::m_use_spv = true;
Tony Barbourf43b6982014-11-25 13:18:32 -0700574
Tony Barbourae442072015-01-12 13:27:11 -0700575 XGLTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700576
Cody Northropacfb0492015-03-17 15:55:58 -0600577 XglTestFramework::m_use_spv = saved_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700578}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600579#endif
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600580TEST_F(XglRenderTest, GreenTriangle)
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600581{
582 static const char *vertShaderText =
583 "#version 130\n"
584 "vec2 vertices[3];\n"
585 "void main() {\n"
586 " vertices[0] = vec2(-1.0, -1.0);\n"
587 " vertices[1] = vec2( 1.0, -1.0);\n"
588 " vertices[2] = vec2( 0.0, 1.0);\n"
589 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
590 "}\n";
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600591
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600592 static const char *fragShaderText =
593 "#version 130\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600594 "void main() {\n"
Steve K10b32512014-10-10 08:54:29 -0600595 " gl_FragColor = vec4(0,1,0,1);\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600596 "}\n";
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600597
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600598 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
599
Tony Barbourae442072015-01-12 13:27:11 -0700600 XGLTriangleTest(vertShaderText, fragShaderText, false);
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600601}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600602#ifndef _WIN32 // Implicit (for now at least) in WIN32 is that we are using the Nvidia driver and it won't consume SPIRV yet
Cody Northropacfb0492015-03-17 15:55:58 -0600603TEST_F(XglRenderTest, SPV_GreenTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700604{
Cody Northropacfb0492015-03-17 15:55:58 -0600605 bool saved_use_spv = XglTestFramework::m_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700606
607 static const char *vertShaderText =
608 "#version 130\n"
609 "vec2 vertices[3];\n"
610 "void main() {\n"
611 " vertices[0] = vec2(-1.0, -1.0);\n"
612 " vertices[1] = vec2( 1.0, -1.0);\n"
613 " vertices[2] = vec2( 0.0, 1.0);\n"
614 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
615 "}\n";
616
617 static const char *fragShaderText =
618 "#version 130\n"
619 "void main() {\n"
620 " gl_FragColor = vec4(0,1,0,1);\n"
621 "}\n";
622
Cody Northropacfb0492015-03-17 15:55:58 -0600623 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700624
Cody Northropacfb0492015-03-17 15:55:58 -0600625 XglTestFramework::m_use_spv = true;
Tony Barbourae442072015-01-12 13:27:11 -0700626 XGLTriangleTest(vertShaderText, fragShaderText, false);
Cody Northropacfb0492015-03-17 15:55:58 -0600627 XglTestFramework::m_use_spv = saved_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700628}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600629#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700630TEST_F(XglRenderTest, YellowTriangle)
631{
632 static const char *vertShaderText =
633 "#version 130\n"
634 "void main() {\n"
635 " vec2 vertices[3];"
636 " vertices[0] = vec2(-0.5, -0.5);\n"
637 " vertices[1] = vec2( 0.5, -0.5);\n"
638 " vertices[2] = vec2( 0.5, 0.5);\n"
639 " vec4 colors[3];\n"
640 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
641 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
642 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
643 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
644 "}\n";
645
646 static const char *fragShaderText =
647 "#version 130\n"
648 "void main() {\n"
649 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
650 "}\n";
651
Tony Barbourae442072015-01-12 13:27:11 -0700652 XGLTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700653}
654
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600655TEST_F(XglRenderTest, TriangleWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600656{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600657 static const char *vertShaderText =
Tony Barbourf43b6982014-11-25 13:18:32 -0700658 "#version 130\n"
659 //XYZ1( -1, -1, -1 )
660 "in vec4 pos;\n"
661 //XYZ1( 0.f, 0.f, 0.f )
662 "in vec4 inColor;\n"
663 "out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600664 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600665 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600666 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600667 "}\n";
668
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600669
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600670 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700671 "#version 140\n"
672 "#extension GL_ARB_separate_shader_objects : enable\n"
673 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700674 "in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700675 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600676 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700677 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600678 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600679
Tony Barbourf43b6982014-11-25 13:18:32 -0700680
681
682 ASSERT_NO_FATAL_FAILURE(InitState());
683 ASSERT_NO_FATAL_FAILURE(InitViewport());
684
685 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000686 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700687
688 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
689 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
690
691 XglPipelineObj pipelineobj(m_device);
692 pipelineobj.AddShader(&vs);
693 pipelineobj.AddShader(&ps);
694
695 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +0800696 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700697
Mark Lobodzinski15427102015-02-18 16:38:17 -0600698 m_memoryRefManager.AddMemoryRef(&meshBuffer);
699
Tony Barbourf43b6982014-11-25 13:18:32 -0700700 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
701 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
702 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
703 };
704
705 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
706 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700707 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -0700708 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
709 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700710 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -0700711 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
712
713 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
714 pipelineobj.AddVertexInputBindings(&vi_binding,1);
715 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
716
Tony Barboure4ed9942015-01-09 10:06:53 -0700717 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700718 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barboure4ed9942015-01-09 10:06:53 -0700719 XglCommandBufferObj cmdBuffer(m_device);
720 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700721
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600722 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
723
Tony Barboure4ed9942015-01-09 10:06:53 -0700724 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
725
Tony Barboure4ed9942015-01-09 10:06:53 -0700726 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
727
728 // render two triangles
729 cmdBuffer.Draw(0, 6, 0, 1);
730
731 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600732 EndCommandBuffer(cmdBuffer);
733
Mark Lobodzinski15427102015-02-18 16:38:17 -0600734 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barboure4ed9942015-01-09 10:06:53 -0700735
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700736 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barboure4ed9942015-01-09 10:06:53 -0700737 RecordImage(m_renderTargets[i]);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600738}
739
Chia-I Wue09d1a72014-12-05 10:32:23 +0800740TEST_F(XglRenderTest, TriangleMRT)
741{
742 static const char *vertShaderText =
743 "#version 130\n"
744 "in vec4 pos;\n"
745 "void main() {\n"
746 " gl_Position = pos;\n"
747 "}\n";
748
749 static const char *fragShaderText =
750 "#version 130\n"
751 "void main() {\n"
752 " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
753 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
754 "}\n";
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600755 const float vb_data[][2] = {
Chia-I Wue09d1a72014-12-05 10:32:23 +0800756 { -1.0f, -1.0f },
757 { 1.0f, -1.0f },
758 { -1.0f, 1.0f }
759 };
760
761 ASSERT_NO_FATAL_FAILURE(InitState());
762 ASSERT_NO_FATAL_FAILURE(InitViewport());
763
764 XglConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000765 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800766
767 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
768 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
769
770 XglPipelineObj pipelineobj(m_device);
771 pipelineobj.AddShader(&vs);
772 pipelineobj.AddShader(&ps);
773
774 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
775 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
776 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
777 };
778
779 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attrib;
780 vi_attrib.binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700781 vi_attrib.format = XGL_FMT_R32G32_SFLOAT; // format of source data
Chia-I Wue09d1a72014-12-05 10:32:23 +0800782 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
783
784 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
785 pipelineobj.AddVertexInputBindings(&vi_binding,1);
786 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
787
788 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -0600789 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800790
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700791 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
792 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Mark Lobodzinski15427102015-02-18 16:38:17 -0600793 m_memoryRefManager.AddMemoryRef(&meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800794
795 XGL_PIPELINE_CB_ATTACHMENT_STATE att = {};
796 att.blendEnable = XGL_FALSE;
797 att.format = m_render_target_fmt;
798 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700799 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800800
Tony Barbour5ed79702015-01-07 14:31:52 -0700801 XglCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700802
Tony Barbour5ed79702015-01-07 14:31:52 -0700803 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
804 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barboure4ed9942015-01-09 10:06:53 -0700805
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600806 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour5ed79702015-01-07 14:31:52 -0700807
Tony Barboure4ed9942015-01-09 10:06:53 -0700808 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
809
Tony Barbour5ed79702015-01-07 14:31:52 -0700810 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700811#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600812 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour5ed79702015-01-07 14:31:52 -0700813 pDSDumpDot((char*)"triTest2.dot");
814#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600815
Tony Barbour5ed79702015-01-07 14:31:52 -0700816 // render triangle
817 cmdBuffer.Draw(0, 3, 0, 1);
818
819 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600820 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -0600821 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbour5ed79702015-01-07 14:31:52 -0700822
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700823 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbour5ed79702015-01-07 14:31:52 -0700824 RecordImage(m_renderTargets[i]);
825
Chia-I Wue09d1a72014-12-05 10:32:23 +0800826}
827
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700828TEST_F(XglRenderTest, QuadWithIndexedVertexFetch)
829{
830 static const char *vertShaderText =
831 "#version 140\n"
832 "#extension GL_ARB_separate_shader_objects : enable\n"
833 "#extension GL_ARB_shading_language_420pack : enable\n"
834 "layout(location = 0) in vec4 pos;\n"
835 "layout(location = 1) in vec4 inColor;\n"
836 "layout(location = 0) out vec4 outColor;\n"
837 "void main() {\n"
838 " outColor = inColor;\n"
839 " gl_Position = pos;\n"
840 "}\n";
841
842
843 static const char *fragShaderText =
844 "#version 140\n"
845 "#extension GL_ARB_separate_shader_objects : enable\n"
846 "#extension GL_ARB_shading_language_420pack : enable\n"
847 "layout(location = 0) in vec4 color;\n"
848 "void main() {\n"
849 " gl_FragColor = color;\n"
850 "}\n";
851
852 const Vertex g_vbData[] =
853 {
854 // first tri
855 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
856 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
857 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
858
859 // second tri
860 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
861 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
862 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
863 };
864
865 const uint16_t g_idxData[6] = {
866 0, 1, 2,
867 3, 4, 5,
868 };
869
870 ASSERT_NO_FATAL_FAILURE(InitState());
871 ASSERT_NO_FATAL_FAILURE(InitViewport());
872
873 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000874 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700875
876 XglIndexBufferObj indexBuffer(m_device);
877 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), XGL_INDEX_16, g_idxData);
Mark Lobodzinskid30f82a2015-02-16 14:24:23 -0600878 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700879
880 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
881 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
882
883 XglPipelineObj pipelineobj(m_device);
884 pipelineobj.AddShader(&vs);
885 pipelineobj.AddShader(&ps);
886
887 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -0600888 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
889 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &indexBuffer);
890
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700891
Mark Lobodzinski15427102015-02-18 16:38:17 -0600892 m_memoryRefManager.AddMemoryRef(&meshBuffer);
893 m_memoryRefManager.AddMemoryRef(&indexBuffer);
894
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700895 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
896 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
897 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
898 };
899
900 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
901 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700902 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700903 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
904 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700905 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700906 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
907
908 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
909 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700910
911 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700912 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700913 XglCommandBufferObj cmdBuffer(m_device);
914 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600915 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barboure4ed9942015-01-09 10:06:53 -0700916
917 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700918
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700919#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600920 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700921 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700922#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700923
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700924 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
925 cmdBuffer.BindIndexBuffer(&indexBuffer,0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700926
927 // render two triangles
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700928 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700929
930 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600931 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -0600932 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700933
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700934 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700935 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700936
937}
938
GregF6bef1212014-12-02 15:41:44 -0700939TEST_F(XglRenderTest, GreyandRedCirclesonBlue)
940{
941 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -0700942
GregF6bef1212014-12-02 15:41:44 -0700943 static const char *vertShaderText =
944 "#version 140\n"
945 "#extension GL_ARB_separate_shader_objects : enable\n"
946 "#extension GL_ARB_shading_language_420pack : enable\n"
947 "layout (location = 0) in vec4 pos;\n"
948 "layout (location = 0) out vec4 outColor;\n"
949 "layout (location = 1) out vec4 outColor2;\n"
950 "void main() {\n"
951 " gl_Position = pos;\n"
952 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
953 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
954 "}\n";
955
956 static const char *fragShaderText =
957 //"#version 140\n"
958 "#version 330\n"
959 "#extension GL_ARB_separate_shader_objects : enable\n"
960 "#extension GL_ARB_shading_language_420pack : enable\n"
961 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
962 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
963 "layout (location = 0) in vec4 color;\n"
964 "layout (location = 1) in vec4 color2;\n"
965 "void main() {\n"
966 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
967 " float dist_squared = dot(pos, pos);\n"
968 " gl_FragColor = (dist_squared < 400.0)\n"
969 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
970 " : color2;\n"
971 "}\n";
972
973 ASSERT_NO_FATAL_FAILURE(InitState());
974 ASSERT_NO_FATAL_FAILURE(InitViewport());
975
976 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000977 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -0700978
979 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
980 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
981
982 XglPipelineObj pipelineobj(m_device);
983 pipelineobj.AddShader(&vs);
984 pipelineobj.AddShader(&ps);
985
986 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +0800987 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -0700988
Mark Lobodzinski15427102015-02-18 16:38:17 -0600989 m_memoryRefManager.AddMemoryRef(&meshBuffer);
990
GregF6bef1212014-12-02 15:41:44 -0700991 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
992 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
993 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
994 };
995
996 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
997 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700998 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -0700999 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1000 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001001 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001002 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1003
1004 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1005 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1006 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1007
Tony Barbourdd4c9642015-01-09 12:55:14 -07001008 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001009 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001010 XglCommandBufferObj cmdBuffer(m_device);
1011 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1012
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001013 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001014
1015 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1016
1017 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1018#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001019 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001020 pDSDumpDot((char*)"triTest2.dot");
1021#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001022
Tony Barbourdd4c9642015-01-09 12:55:14 -07001023 // render triangle
1024 cmdBuffer.Draw(0, 6, 0, 1);
1025
1026 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001027 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001028 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001029
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001030 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001031 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001032
1033}
1034
1035TEST_F(XglRenderTest, RedCirclesonBlue)
1036{
1037 // This tests that we correctly handle unread fragment inputs
1038
1039 static const char *vertShaderText =
1040 "#version 140\n"
1041 "#extension GL_ARB_separate_shader_objects : enable\n"
1042 "#extension GL_ARB_shading_language_420pack : enable\n"
1043 "layout (location = 0) in vec4 pos;\n"
1044 "layout (location = 0) out vec4 outColor;\n"
1045 "layout (location = 1) out vec4 outColor2;\n"
1046 "void main() {\n"
1047 " gl_Position = pos;\n"
1048 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1049 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1050 "}\n";
1051
1052 static const char *fragShaderText =
1053 //"#version 140\n"
1054 "#version 330\n"
1055 "#extension GL_ARB_separate_shader_objects : enable\n"
1056 "#extension GL_ARB_shading_language_420pack : enable\n"
1057 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1058 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1059 "layout (location = 0) in vec4 color;\n"
1060 "layout (location = 1) in vec4 color2;\n"
1061 "void main() {\n"
1062 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1063 " float dist_squared = dot(pos, pos);\n"
1064 " gl_FragColor = (dist_squared < 400.0)\n"
1065 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1066 " : color2;\n"
1067 "}\n";
1068
1069 ASSERT_NO_FATAL_FAILURE(InitState());
1070 ASSERT_NO_FATAL_FAILURE(InitViewport());
1071
1072 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001073 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001074
1075 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1076 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1077
1078 XglPipelineObj pipelineobj(m_device);
1079 pipelineobj.AddShader(&vs);
1080 pipelineobj.AddShader(&ps);
1081
1082 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001083 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001084
Mark Lobodzinski15427102015-02-18 16:38:17 -06001085 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1086
GregF6bef1212014-12-02 15:41:44 -07001087 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1088 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1089 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1090 };
1091
1092 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1093 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001094 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001095 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1096 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001097 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001098 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1099
1100 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1101 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1102 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1103
Tony Barbourdd4c9642015-01-09 12:55:14 -07001104 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001105 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001106 XglCommandBufferObj cmdBuffer(m_device);
1107 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1108
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001109 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001110
1111 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1112
1113 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1114#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001115 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001116 pDSDumpDot((char*)"triTest2.dot");
1117#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001118 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001119 cmdBuffer.Draw(0, 6, 0, 1);
1120
1121 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001122 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001123 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001124
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001125 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001126 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001127
1128}
1129
1130TEST_F(XglRenderTest, GreyCirclesonBlueFade)
1131{
1132 // This tests reading gl_ClipDistance from FS
1133
1134 static const char *vertShaderText =
1135 "#version 330\n"
1136 "#extension GL_ARB_separate_shader_objects : enable\n"
1137 "#extension GL_ARB_shading_language_420pack : enable\n"
1138 "out gl_PerVertex {\n"
1139 " vec4 gl_Position;\n"
1140 " float gl_ClipDistance[1];\n"
1141 "};\n"
1142 "layout (location = 0) in vec4 pos;\n"
1143 "layout (location = 0) out vec4 outColor;\n"
1144 "layout (location = 1) out vec4 outColor2;\n"
1145 "void main() {\n"
1146 " gl_Position = pos;\n"
1147 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1148 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1149 " float dists[3];\n"
1150 " dists[0] = 0.0;\n"
1151 " dists[1] = 1.0;\n"
1152 " dists[2] = 1.0;\n"
1153 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1154 "}\n";
1155
1156
1157 static const char *fragShaderText =
1158 //"#version 140\n"
1159 "#version 330\n"
1160 "#extension GL_ARB_separate_shader_objects : enable\n"
1161 "#extension GL_ARB_shading_language_420pack : enable\n"
1162 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1163 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1164 "layout (location = 0) in vec4 color;\n"
1165 "layout (location = 1) in vec4 color2;\n"
1166 "void main() {\n"
1167 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1168 " float dist_squared = dot(pos, pos);\n"
1169 " gl_FragColor = (dist_squared < 400.0)\n"
1170 " ? color * gl_ClipDistance[0]\n"
1171 " : color2;\n"
1172 "}\n";
1173
1174 ASSERT_NO_FATAL_FAILURE(InitState());
1175 ASSERT_NO_FATAL_FAILURE(InitViewport());
1176
1177 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001178 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001179
1180 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1181 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1182
1183 XglPipelineObj pipelineobj(m_device);
1184 pipelineobj.AddShader(&vs);
1185 pipelineobj.AddShader(&ps);
1186
1187 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001188 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001189
Mark Lobodzinski15427102015-02-18 16:38:17 -06001190 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1191
GregF6bef1212014-12-02 15:41:44 -07001192 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
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001199 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001200 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1201 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001202 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF6bef1212014-12-02 15:41:44 -07001203 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1204
1205 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1206 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1207 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1208
Tony Barbourdd4c9642015-01-09 12:55:14 -07001209 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001210 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001211 XglCommandBufferObj cmdBuffer(m_device);
1212 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF6bef1212014-12-02 15:41:44 -07001213
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001214 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001215
1216 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1217
1218 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1219#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001220 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001221 pDSDumpDot((char*)"triTest2.dot");
1222#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001223
1224 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001225 cmdBuffer.Draw(0, 6, 0, 1);
1226
1227 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001228 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001229 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001230
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001231 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001232 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001233}
Tony Barbourf43b6982014-11-25 13:18:32 -07001234
GregF7a23c792014-12-02 17:19:34 -07001235TEST_F(XglRenderTest, GreyCirclesonBlueDiscard)
1236{
1237 static const char *vertShaderText =
1238 "#version 140\n"
1239 "#extension GL_ARB_separate_shader_objects : enable\n"
1240 "#extension GL_ARB_shading_language_420pack : enable\n"
1241 "layout (location = 0) in vec4 pos;\n"
1242 "layout (location = 0) out vec4 outColor;\n"
1243 "layout (location = 1) out vec4 outColor2;\n"
1244 "void main() {\n"
1245 " gl_Position = pos;\n"
1246 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1247 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1248 "}\n";
1249
1250
1251 static const char *fragShaderText =
1252 //"#version 140\n"
1253 "#version 330\n"
1254 "#extension GL_ARB_separate_shader_objects : enable\n"
1255 "#extension GL_ARB_shading_language_420pack : enable\n"
1256 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1257 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1258 "layout (location = 0) in vec4 color;\n"
1259 "layout (location = 1) in vec4 color2;\n"
1260 "void main() {\n"
1261 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1262 " float dist_squared = dot(pos, pos);\n"
1263 " if (dist_squared < 100.0)\n"
1264 " discard;\n"
1265 " gl_FragColor = (dist_squared < 400.0)\n"
1266 " ? color\n"
1267 " : color2;\n"
1268 "}\n";
1269
1270 ASSERT_NO_FATAL_FAILURE(InitState());
1271 ASSERT_NO_FATAL_FAILURE(InitViewport());
1272
1273 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001274 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001275
1276 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1277 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1278
1279 XglPipelineObj pipelineobj(m_device);
1280 pipelineobj.AddShader(&vs);
1281 pipelineobj.AddShader(&ps);
1282
1283 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001284 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF7a23c792014-12-02 17:19:34 -07001285
Mark Lobodzinski15427102015-02-18 16:38:17 -06001286 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1287
GregF7a23c792014-12-02 17:19:34 -07001288 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1289 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1290 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1291 };
1292
1293 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1294 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001295 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF7a23c792014-12-02 17:19:34 -07001296 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1297 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001298 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
GregF7a23c792014-12-02 17:19:34 -07001299 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1300
1301 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1302 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1303 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1304
Tony Barbourdd4c9642015-01-09 12:55:14 -07001305 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001306 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001307 XglCommandBufferObj cmdBuffer(m_device);
1308 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1309
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001310 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001311
1312 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1313
1314 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1315#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001316 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001317 pDSDumpDot((char*)"triTest2.dot");
1318#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001319
1320 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001321 cmdBuffer.Draw(0, 6, 0, 1);
1322
1323 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001324 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001325 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001326
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001327 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001328 RecordImage(m_renderTargets[i]);
GregF7a23c792014-12-02 17:19:34 -07001329
1330}
1331
1332
Courtney Goeltzenleuchter3d10c9c2014-10-27 13:06:08 -06001333TEST_F(XglRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001334{
1335 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001336 "#version 140\n"
1337 "#extension GL_ARB_separate_shader_objects : enable\n"
1338 "#extension GL_ARB_shading_language_420pack : enable\n"
1339 "\n"
1340 "layout(binding = 0) uniform buf {\n"
1341 " mat4 MVP;\n"
1342 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001343 "void main() {\n"
1344 " vec2 vertices[3];"
1345 " vertices[0] = vec2(-0.5, -0.5);\n"
1346 " vertices[1] = vec2( 0.5, -0.5);\n"
1347 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001348 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001349 "}\n";
1350
1351 static const char *fragShaderText =
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001352 "#version 130\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001353 "void main() {\n"
Cody Northrop78eac042014-10-10 15:45:00 -06001354 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001355 "}\n";
1356
Tony Barbourf43b6982014-11-25 13:18:32 -07001357 ASSERT_NO_FATAL_FAILURE(InitState());
1358 ASSERT_NO_FATAL_FAILURE(InitViewport());
1359
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001360 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001361 glm::mat4 Projection = glm::mat4(1.0f);
1362 glm::mat4 View = glm::mat4(1.0f);
1363 glm::mat4 Model = glm::mat4(1.0f);
1364 glm::mat4 MVP = Projection * View * Model;
1365 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1366
Tony Barbourf43b6982014-11-25 13:18:32 -07001367 XglConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1368 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1369 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001370
Tony Barbourf43b6982014-11-25 13:18:32 -07001371 XglPipelineObj pipelineobj(m_device);
1372 pipelineobj.AddShader(&vs);
1373 pipelineobj.AddShader(&ps);
1374
1375 // Create descriptor set and attach the constant buffer to it
1376 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001377 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001378
1379 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1380
Tony Barbourdd4c9642015-01-09 12:55:14 -07001381 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001382 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001383 XglCommandBufferObj cmdBuffer(m_device);
1384 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001385
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001386 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001387
1388 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1389
1390 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1391#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001392 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001393 pDSDumpDot((char*)"triTest2.dot");
1394#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001395
1396 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001397 cmdBuffer.Draw(0, 6, 0, 1);
1398
1399 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001400 EndCommandBuffer(cmdBuffer);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001401 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
1402
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001403 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001404 RecordImage(m_renderTargets[i]);
1405
1406 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001407}
1408
Tony Barbourf43b6982014-11-25 13:18:32 -07001409TEST_F(XglRenderTest, MixTriangle)
1410{
1411 // This tests location applied to varyings. Notice that we have switched foo
1412 // and bar in the FS. The triangle should be blended with red, green and blue
1413 // corners.
1414 static const char *vertShaderText =
1415 "#version 140\n"
1416 "#extension GL_ARB_separate_shader_objects : enable\n"
1417 "#extension GL_ARB_shading_language_420pack : enable\n"
1418 "layout (location=0) out vec4 bar;\n"
1419 "layout (location=1) out vec4 foo;\n"
1420 "layout (location=2) out float scale;\n"
1421 "vec2 vertices[3];\n"
1422 "void main() {\n"
1423 " vertices[0] = vec2(-1.0, -1.0);\n"
1424 " vertices[1] = vec2( 1.0, -1.0);\n"
1425 " vertices[2] = vec2( 0.0, 1.0);\n"
1426 "vec4 colors[3];\n"
1427 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1428 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1429 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1430 " foo = colors[gl_VertexID % 3];\n"
1431 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1432 " scale = 1.0;\n"
1433 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1434 "}\n";
1435
1436 static const char *fragShaderText =
1437 "#version 140\n"
1438 "#extension GL_ARB_separate_shader_objects : enable\n"
1439 "#extension GL_ARB_shading_language_420pack : enable\n"
1440 "layout (location = 1) in vec4 bar;\n"
1441 "layout (location = 0) in vec4 foo;\n"
1442 "layout (location = 2) in float scale;\n"
1443 "void main() {\n"
1444 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
1445 "}\n";
1446
1447 ASSERT_NO_FATAL_FAILURE(InitState());
1448 ASSERT_NO_FATAL_FAILURE(InitViewport());
1449
1450 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1451 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1452
1453 XglPipelineObj pipelineobj(m_device);
1454 pipelineobj.AddShader(&vs);
1455 pipelineobj.AddShader(&ps);
1456
1457 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06001458 descriptorSet.AppendDummy();
Tony Barbourf43b6982014-11-25 13:18:32 -07001459
Tony Barbourdd4c9642015-01-09 12:55:14 -07001460 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001461 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001462 XglCommandBufferObj cmdBuffer(m_device);
1463 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1464
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001465 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001466
1467 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1468
1469#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001470 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001471 pDSDumpDot((char*)"triTest2.dot");
1472#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001473
Tony Barbourdd4c9642015-01-09 12:55:14 -07001474 // render triangle
1475 cmdBuffer.Draw(0, 3, 0, 1);
1476
1477 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001478 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001479 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001480
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001481 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001482 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001483}
1484
1485TEST_F(XglRenderTest, TriVertFetchAndVertID)
1486{
1487 // This tests that attributes work in the presence of gl_VertexID
1488
1489 static const char *vertShaderText =
1490 "#version 140\n"
1491 "#extension GL_ARB_separate_shader_objects : enable\n"
1492 "#extension GL_ARB_shading_language_420pack : enable\n"
1493 //XYZ1( -1, -1, -1 )
1494 "layout (location = 0) in vec4 pos;\n"
1495 //XYZ1( 0.f, 0.f, 0.f )
1496 "layout (location = 1) in vec4 inColor;\n"
1497 "layout (location = 0) out vec4 outColor;\n"
1498 "void main() {\n"
1499 " outColor = inColor;\n"
1500 " vec4 vertices[3];"
1501 " vertices[gl_VertexID % 3] = pos;\n"
1502 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1503 "}\n";
1504
1505
1506 static const char *fragShaderText =
1507 "#version 140\n"
1508 "#extension GL_ARB_separate_shader_objects : enable\n"
1509 "#extension GL_ARB_shading_language_420pack : enable\n"
1510 "layout (location = 0) in vec4 color;\n"
1511 "void main() {\n"
1512 " gl_FragColor = color;\n"
1513 "}\n";
1514
1515 ASSERT_NO_FATAL_FAILURE(InitState());
1516 ASSERT_NO_FATAL_FAILURE(InitViewport());
1517
1518 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001519 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001520
1521 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1522 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1523
1524 XglPipelineObj pipelineobj(m_device);
1525 pipelineobj.AddShader(&vs);
1526 pipelineobj.AddShader(&ps);
1527
1528 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001529 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001530
Mark Lobodzinski15427102015-02-18 16:38:17 -06001531 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1532
Tony Barbourf43b6982014-11-25 13:18:32 -07001533 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1534 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1535 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1536 };
1537
1538 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1539 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001540 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001541 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1542 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001543 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001544 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1545
1546 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1547 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1548 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1549
Tony Barbourdd4c9642015-01-09 12:55:14 -07001550 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001551 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001552 XglCommandBufferObj cmdBuffer(m_device);
1553 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1554
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001555 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001556
1557 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1558
1559 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1560#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001561 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001562 pDSDumpDot((char*)"triTest2.dot");
1563#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001564
1565 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001566 cmdBuffer.Draw(0, 6, 0, 1);
1567
1568 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001569 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001570 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001571
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001572 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001573 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001574}
1575
1576TEST_F(XglRenderTest, TriVertFetchDeadAttr)
1577{
1578 // This tests that attributes work in the presence of gl_VertexID
1579 // and a dead attribute in position 0. Draws a triangle with yellow,
1580 // red and green corners, starting at top and going clockwise.
1581
1582 static const char *vertShaderText =
1583 "#version 140\n"
1584 "#extension GL_ARB_separate_shader_objects : enable\n"
1585 "#extension GL_ARB_shading_language_420pack : enable\n"
1586 //XYZ1( -1, -1, -1 )
1587 "layout (location = 0) in vec4 pos;\n"
1588 //XYZ1( 0.f, 0.f, 0.f )
1589 "layout (location = 1) in vec4 inColor;\n"
1590 "layout (location = 0) out vec4 outColor;\n"
1591 "void main() {\n"
1592 " outColor = inColor;\n"
1593 " vec2 vertices[3];"
1594 " vertices[0] = vec2(-1.0, -1.0);\n"
1595 " vertices[1] = vec2( 1.0, -1.0);\n"
1596 " vertices[2] = vec2( 0.0, 1.0);\n"
1597 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1598 "}\n";
1599
1600
1601 static const char *fragShaderText =
1602 "#version 140\n"
1603 "#extension GL_ARB_separate_shader_objects : enable\n"
1604 "#extension GL_ARB_shading_language_420pack : enable\n"
1605 "layout (location = 0) in vec4 color;\n"
1606 "void main() {\n"
1607 " gl_FragColor = color;\n"
1608 "}\n";
1609
1610 ASSERT_NO_FATAL_FAILURE(InitState());
1611 ASSERT_NO_FATAL_FAILURE(InitViewport());
1612
1613 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001614 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001615
1616 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1617 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1618
1619 XglPipelineObj pipelineobj(m_device);
1620 pipelineobj.AddShader(&vs);
1621 pipelineobj.AddShader(&ps);
1622
1623 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001624 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001625
Mark Lobodzinski15427102015-02-18 16:38:17 -06001626 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1627
Tony Barbourf43b6982014-11-25 13:18:32 -07001628 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1629 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1630 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1631 };
1632
1633 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1634 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001635 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001636 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1637 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001638 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001639 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1640
1641 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1642 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1643 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1644
Tony Barbourdd4c9642015-01-09 12:55:14 -07001645 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001646 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001647 XglCommandBufferObj cmdBuffer(m_device);
1648 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001649
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001650 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001651
1652 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1653
1654 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1655#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001656 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001657 pDSDumpDot((char*)"triTest2.dot");
1658#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001659
1660 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001661 cmdBuffer.Draw(0, 6, 0, 1);
1662
1663 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001664 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001665 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001666
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001667 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001668 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001669}
1670
1671TEST_F(XglRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001672{
1673 static const char *vertShaderText =
1674 "#version 140\n"
1675 "layout (std140) uniform bufferVals {\n"
1676 " mat4 mvp;\n"
1677 "} myBufferVals;\n"
1678 "in vec4 pos;\n"
1679 "in vec4 inColor;\n"
1680 "out vec4 outColor;\n"
1681 "void main() {\n"
1682 " outColor = inColor;\n"
1683 " gl_Position = myBufferVals.mvp * pos;\n"
1684 "}\n";
1685
1686 static const char *fragShaderText =
1687 "#version 130\n"
1688 "in vec4 color;\n"
1689 "void main() {\n"
1690 " gl_FragColor = color;\n"
1691 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001692 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001693
Tony Barbourf43b6982014-11-25 13:18:32 -07001694 glm::mat4 View = glm::lookAt(
1695 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1696 glm::vec3(0,0,0), // and looks at the origin
1697 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
1698 );
1699
1700 glm::mat4 Model = glm::mat4(1.0f);
1701
1702 glm::mat4 MVP = Projection * View * Model;
1703
1704 ASSERT_NO_FATAL_FAILURE(InitState());
1705 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour17c6ab12015-03-27 17:03:18 -06001706 m_depthStencil->Init(m_device, m_width, m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07001707
1708 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
1709 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1710
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001711 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07001712
1713 XglConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1714 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1715 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1716
Tony Barbourf43b6982014-11-25 13:18:32 -07001717 XglPipelineObj pipelineobj(m_device);
1718 pipelineobj.AddShader(&vs);
1719 pipelineobj.AddShader(&ps);
1720
Tony Barbourfa6cac72015-01-16 14:27:35 -07001721 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
1722 ds_state.depthTestEnable = XGL_TRUE;
1723 ds_state.depthWriteEnable = XGL_TRUE;
1724 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
1725 ds_state.depthBoundsEnable = XGL_FALSE;
1726 ds_state.stencilTestEnable = XGL_FALSE;
1727 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
1728 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
1729 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
1730 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001731 ds_state.format = XGL_FMT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001732 ds_state.front = ds_state.back;
1733 pipelineobj.SetDepthStencil(&ds_state);
1734
Tony Barbourf43b6982014-11-25 13:18:32 -07001735 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001736 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001737
1738 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1739 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
Tony Barbour17c6ab12015-03-27 17:03:18 -06001740 m_memoryRefManager.AddMemoryRef(m_depthStencil);
Tony Barbourf43b6982014-11-25 13:18:32 -07001741
1742 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1743 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1744 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1745 };
1746
1747 // this is the current description of g_vbData
1748 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1749 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001750 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001751 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1752 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001753 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07001754 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1755
1756 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1757 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1758 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1759
Tony Barbour17c6ab12015-03-27 17:03:18 -06001760 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001761 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbour17c6ab12015-03-27 17:03:18 -06001762
Tony Barboure4ed9942015-01-09 10:06:53 -07001763 XglCommandBufferObj cmdBuffer(m_device);
1764 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001765
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001766 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barboure4ed9942015-01-09 10:06:53 -07001767 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001768
Tony Barboure4ed9942015-01-09 10:06:53 -07001769 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1770#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001771 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barboure4ed9942015-01-09 10:06:53 -07001772 pDSDumpDot((char*)"triTest2.dot");
1773#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001774
1775 // render triangles
Tony Barboure4ed9942015-01-09 10:06:53 -07001776 cmdBuffer.Draw(0, 36, 0, 1);
1777
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001778
Tony Barboure4ed9942015-01-09 10:06:53 -07001779 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001780 EndCommandBuffer(cmdBuffer);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001781 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barboure4ed9942015-01-09 10:06:53 -07001782
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001783 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barboure4ed9942015-01-09 10:06:53 -07001784 RecordImage(m_renderTargets[i]);
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
Tony Barbourf43b6982014-11-25 13:18:32 -07001824 XglPipelineObj pipelineobj(m_device);
1825 pipelineobj.AddShader(&vs);
1826 pipelineobj.AddShader(&ps);
1827
1828 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001829 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001830
1831 m_memoryRefManager.AddMemoryRef(&texture);
1832
Tony Barbourdd4c9642015-01-09 12:55:14 -07001833 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001834 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001835 XglCommandBufferObj cmdBuffer(m_device);
1836 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001837
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001838 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001839
1840 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1841
1842#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001843 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001844 pDSDumpDot((char*)"triTest2.dot");
1845#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001846
Tony Barbourdd4c9642015-01-09 12:55:14 -07001847 // render triangle
1848 cmdBuffer.Draw(0, 3, 0, 1);
1849
1850 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001851 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001852 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001853
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001854 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001855 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001856}
1857TEST_F(XglRenderTest, TexturedTriangle)
1858{
1859 // The expected result from this test is a red and green checkered triangle
1860 static const char *vertShaderText =
1861 "#version 140\n"
1862 "#extension GL_ARB_separate_shader_objects : enable\n"
1863 "#extension GL_ARB_shading_language_420pack : enable\n"
1864 "layout (location = 0) out vec2 samplePos;\n"
1865 "void main() {\n"
1866 " vec2 vertices[3];"
1867 " vertices[0] = vec2(-0.5, -0.5);\n"
1868 " vertices[1] = vec2( 0.5, -0.5);\n"
1869 " vertices[2] = vec2( 0.5, 0.5);\n"
1870 " vec2 positions[3];"
1871 " positions[0] = vec2( 0.0, 0.0);\n"
1872 " positions[1] = vec2( 1.0, 0.0);\n"
1873 " positions[2] = vec2( 1.0, 1.0);\n"
1874 " samplePos = positions[gl_VertexID % 3];\n"
1875 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1876 "}\n";
1877
1878 static const char *fragShaderText =
1879 "#version 140\n"
1880 "#extension GL_ARB_separate_shader_objects : enable\n"
1881 "#extension GL_ARB_shading_language_420pack : enable\n"
1882 "layout (location = 0) in vec2 samplePos;\n"
1883 "layout (binding = 0) uniform sampler2D surface;\n"
1884 "layout (location=0) out vec4 outColor;\n"
1885 "void main() {\n"
1886 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1887 " outColor = texColor;\n"
1888 "}\n";
1889
1890 ASSERT_NO_FATAL_FAILURE(InitState());
1891 ASSERT_NO_FATAL_FAILURE(InitViewport());
1892
1893 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1894 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1895 XglSamplerObj sampler(m_device);
1896 XglTextureObj texture(m_device);
1897
Tony Barbourf43b6982014-11-25 13:18:32 -07001898 XglPipelineObj pipelineobj(m_device);
1899 pipelineobj.AddShader(&vs);
1900 pipelineobj.AddShader(&ps);
1901
1902 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001903 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001904
1905 m_memoryRefManager.AddMemoryRef(&texture);
1906
Tony Barbourdd4c9642015-01-09 12:55:14 -07001907 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001908 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001909 XglCommandBufferObj cmdBuffer(m_device);
1910 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1911
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001912 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001913
1914 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1915
1916#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001917 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001918 pDSDumpDot((char*)"triTest2.dot");
1919#endif
1920 // render triangle
1921 cmdBuffer.Draw(0, 3, 0, 1);
1922
1923 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001924 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001925 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001926
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001927 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001928 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001929}
1930TEST_F(XglRenderTest, TexturedTriangleClip)
1931{
1932 // The expected result from this test is a red and green checkered triangle
1933 static const char *vertShaderText =
1934 "#version 330\n"
1935 "#extension GL_ARB_separate_shader_objects : enable\n"
1936 "#extension GL_ARB_shading_language_420pack : enable\n"
1937 "layout (location = 0) out vec2 samplePos;\n"
1938 "out gl_PerVertex {\n"
1939 " vec4 gl_Position;\n"
1940 " float gl_ClipDistance[1];\n"
1941 "};\n"
1942 "void main() {\n"
1943 " vec2 vertices[3];"
1944 " vertices[0] = vec2(-0.5, -0.5);\n"
1945 " vertices[1] = vec2( 0.5, -0.5);\n"
1946 " vertices[2] = vec2( 0.5, 0.5);\n"
1947 " vec2 positions[3];"
1948 " positions[0] = vec2( 0.0, 0.0);\n"
1949 " positions[1] = vec2( 1.0, 0.0);\n"
1950 " positions[2] = vec2( 1.0, 1.0);\n"
1951 " float dists[3];\n"
1952 " dists[0] = 1.0;\n"
1953 " dists[1] = 1.0;\n"
1954 " dists[2] = -1.0;\n"
1955 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1956 " samplePos = positions[gl_VertexID % 3];\n"
1957 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1958 "}\n";
1959
1960 static const char *fragShaderText =
1961 "#version 140\n"
1962 "#extension GL_ARB_separate_shader_objects : enable\n"
1963 "#extension GL_ARB_shading_language_420pack : enable\n"
1964 "layout (location = 0) in vec2 samplePos;\n"
1965 "layout (binding = 0) uniform sampler2D surface;\n"
1966 "layout (location=0) out vec4 outColor;\n"
1967 "void main() {\n"
1968 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
1969 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1970 " outColor = texColor;\n"
1971 "}\n";
1972
1973
1974 ASSERT_NO_FATAL_FAILURE(InitState());
1975 ASSERT_NO_FATAL_FAILURE(InitViewport());
1976
1977 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1978 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1979 XglSamplerObj sampler(m_device);
1980 XglTextureObj texture(m_device);
1981
Tony Barbourf43b6982014-11-25 13:18:32 -07001982 XglPipelineObj pipelineobj(m_device);
1983 pipelineobj.AddShader(&vs);
1984 pipelineobj.AddShader(&ps);
1985
1986 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001987 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001988
1989 m_memoryRefManager.AddMemoryRef(&texture);
1990
Tony Barbourdd4c9642015-01-09 12:55:14 -07001991 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001992 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001993 XglCommandBufferObj cmdBuffer(m_device);
1994 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1995
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001996 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001997
1998 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1999
2000#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002001 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002002 pDSDumpDot((char*)"triTest2.dot");
2003#endif
2004 // render triangle
2005 cmdBuffer.Draw(0, 3, 0, 1);
2006
2007 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002008 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002009 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002010
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002011 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002012 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002013}
2014TEST_F(XglRenderTest, FSTriangle)
2015{
2016 // The expected result from this test is a red and green checkered triangle
2017 static const char *vertShaderText =
2018 "#version 140\n"
2019 "#extension GL_ARB_separate_shader_objects : enable\n"
2020 "#extension GL_ARB_shading_language_420pack : enable\n"
2021 "layout (location = 0) out vec2 samplePos;\n"
2022 "void main() {\n"
2023 " vec2 vertices[3];"
2024 " vertices[0] = vec2(-0.5, -0.5);\n"
2025 " vertices[1] = vec2( 0.5, -0.5);\n"
2026 " vertices[2] = vec2( 0.5, 0.5);\n"
2027 " vec2 positions[3];"
2028 " positions[0] = vec2( 0.0, 0.0);\n"
2029 " positions[1] = vec2( 1.0, 0.0);\n"
2030 " positions[2] = vec2( 1.0, 1.0);\n"
2031 " samplePos = positions[gl_VertexID % 3];\n"
2032 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2033 "}\n";
2034
2035 static const char *fragShaderText =
2036 "#version 140\n"
2037 "#extension GL_ARB_separate_shader_objects : enable\n"
2038 "#extension GL_ARB_shading_language_420pack : enable\n"
2039 "layout (location = 0) in vec2 samplePos;\n"
2040 "layout (binding = 0) uniform sampler2D surface;\n"
2041 "layout (location=0) out vec4 outColor;\n"
2042 "void main() {\n"
2043 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2044 " outColor = texColor;\n"
2045 "}\n";
2046
2047 ASSERT_NO_FATAL_FAILURE(InitState());
2048 ASSERT_NO_FATAL_FAILURE(InitViewport());
2049
2050 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2051 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2052 XglSamplerObj sampler(m_device);
2053 XglTextureObj texture(m_device);
2054
Tony Barbourf43b6982014-11-25 13:18:32 -07002055 XglPipelineObj pipelineobj(m_device);
2056 pipelineobj.AddShader(&vs);
2057 pipelineobj.AddShader(&ps);
2058
2059 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002060 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002061
2062 m_memoryRefManager.AddMemoryRef(&texture);
2063
Tony Barbourdd4c9642015-01-09 12:55:14 -07002064 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002065 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002066 XglCommandBufferObj cmdBuffer(m_device);
2067 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2068
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002069 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002070
2071 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2072
2073#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002074 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002075 pDSDumpDot((char*)"triTest2.dot");
2076#endif
2077 // render triangle
2078 cmdBuffer.Draw(0, 3, 0, 1);
2079
2080 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002081 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002082 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002083
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002084 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002085 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002086}
2087TEST_F(XglRenderTest, SamplerBindingsTriangle)
2088{
2089 // This test sets bindings on the samplers
2090 // For now we are asserting that sampler and texture pairs
2091 // march in lock step, and are set via GLSL binding. This can
2092 // and will probably change.
2093 // The sampler bindings should match the sampler and texture slot
2094 // number set up by the application.
2095 // This test will result in a blue triangle
2096 static const char *vertShaderText =
2097 "#version 140\n"
2098 "#extension GL_ARB_separate_shader_objects : enable\n"
2099 "#extension GL_ARB_shading_language_420pack : enable\n"
2100 "layout (location = 0) out vec4 samplePos;\n"
2101 "void main() {\n"
2102 " vec2 vertices[3];"
2103 " vertices[0] = vec2(-0.5, -0.5);\n"
2104 " vertices[1] = vec2( 0.5, -0.5);\n"
2105 " vertices[2] = vec2( 0.5, 0.5);\n"
2106 " vec2 positions[3];"
2107 " positions[0] = vec2( 0.0, 0.0);\n"
2108 " positions[1] = vec2( 1.0, 0.0);\n"
2109 " positions[2] = vec2( 1.0, 1.0);\n"
2110 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2111 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2112 "}\n";
2113
2114 static const char *fragShaderText =
2115 "#version 140\n"
2116 "#extension GL_ARB_separate_shader_objects : enable\n"
2117 "#extension GL_ARB_shading_language_420pack : enable\n"
2118 "layout (location = 0) in vec4 samplePos;\n"
2119 "layout (binding = 0) uniform sampler2D surface0;\n"
2120 "layout (binding = 1) uniform sampler2D surface1;\n"
2121 "layout (binding = 12) uniform sampler2D surface2;\n"
2122 "void main() {\n"
2123 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
2124 "}\n";
2125
2126 ASSERT_NO_FATAL_FAILURE(InitState());
2127 ASSERT_NO_FATAL_FAILURE(InitViewport());
2128
2129 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2130 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2131
2132 XglSamplerObj sampler1(m_device);
2133 XglSamplerObj sampler2(m_device);
2134 XglSamplerObj sampler3(m_device);
2135
Tony Barbour2f421a02015-04-01 16:38:10 -06002136 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
2137 XglTextureObj texture1(m_device, tex_colors); // Red
2138 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
2139 XglTextureObj texture2(m_device, tex_colors); // Green
2140 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
2141 XglTextureObj texture3(m_device, tex_colors); // Blue
Tony Barbourf43b6982014-11-25 13:18:32 -07002142
Tony Barbourf43b6982014-11-25 13:18:32 -07002143 XglPipelineObj pipelineobj(m_device);
2144 pipelineobj.AddShader(&vs);
2145 pipelineobj.AddShader(&ps);
2146
2147 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002148 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2149 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2150 for (int i = 0; i < 10; i++)
2151 descriptorSet.AppendDummy();
2152 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002153
2154 m_memoryRefManager.AddMemoryRef(&texture1);
2155 m_memoryRefManager.AddMemoryRef(&texture2);
2156 m_memoryRefManager.AddMemoryRef(&texture3);
2157
Tony Barbourdd4c9642015-01-09 12:55:14 -07002158 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002159 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002160 XglCommandBufferObj cmdBuffer(m_device);
2161 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2162
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002163 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002164
2165 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2166
2167#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002168 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002169 pDSDumpDot((char*)"triTest2.dot");
2170#endif
2171 // render triangle
2172 cmdBuffer.Draw(0, 3, 0, 1);
2173
2174 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002175 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002176 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002177
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002178 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002179 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002180
2181}
2182
2183TEST_F(XglRenderTest, TriangleVSUniformBlock)
2184{
2185 // The expected result from this test is a blue triangle
2186
2187 static const char *vertShaderText =
2188 "#version 140\n"
2189 "#extension GL_ARB_separate_shader_objects : enable\n"
2190 "#extension GL_ARB_shading_language_420pack : enable\n"
2191 "layout (location = 0) out vec4 outColor;\n"
2192 "layout (std140, binding = 0) uniform bufferVals {\n"
2193 " vec4 red;\n"
2194 " vec4 green;\n"
2195 " vec4 blue;\n"
2196 " vec4 white;\n"
2197 "} myBufferVals;\n"
2198 "void main() {\n"
2199 " vec2 vertices[3];"
2200 " vertices[0] = vec2(-0.5, -0.5);\n"
2201 " vertices[1] = vec2( 0.5, -0.5);\n"
2202 " vertices[2] = vec2( 0.5, 0.5);\n"
2203 " outColor = myBufferVals.blue;\n"
2204 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2205 "}\n";
2206
2207 static const char *fragShaderText =
2208 "#version 140\n"
2209 "#extension GL_ARB_separate_shader_objects : enable\n"
2210 "#extension GL_ARB_shading_language_420pack : enable\n"
2211 "layout (location = 0) in vec4 inColor;\n"
2212 "void main() {\n"
2213 " gl_FragColor = inColor;\n"
2214 "}\n";
2215
2216 ASSERT_NO_FATAL_FAILURE(InitState());
2217 ASSERT_NO_FATAL_FAILURE(InitViewport());
2218
2219 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2220 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2221
2222 // Let's populate our buffer with the following:
2223 // vec4 red;
2224 // vec4 green;
2225 // vec4 blue;
2226 // vec4 white;
2227 const int valCount = 4 * 4;
2228 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2229 0.0, 1.0, 0.0, 1.0,
2230 0.0, 0.0, 1.0, 1.0,
2231 1.0, 1.0, 1.0, 1.0 };
2232
2233 XglConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002234
2235 XglPipelineObj pipelineobj(m_device);
2236 pipelineobj.AddShader(&vs);
2237 pipelineobj.AddShader(&ps);
2238
2239 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002240 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002241
Tony Barbourdd4c9642015-01-09 12:55:14 -07002242 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002243 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002244 XglCommandBufferObj cmdBuffer(m_device);
2245 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2246
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002247 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002248
2249 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2250
2251#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002252 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002253 pDSDumpDot((char*)"triTest2.dot");
2254#endif
2255 // render triangle
2256 cmdBuffer.Draw(0, 3, 0, 1);
2257
2258 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002259 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002260 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002261
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002262 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002263 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002264
2265}
2266
2267TEST_F(XglRenderTest, TriangleFSUniformBlockBinding)
2268{
2269 // This test allows the shader to select which buffer it is
2270 // pulling from using layout binding qualifier.
2271 // There are corresponding changes in the compiler stack that
2272 // will select the buffer using binding directly.
2273 // The binding number should match the slot number set up by
2274 // the application.
2275 // The expected result from this test is a purple triangle
2276
2277 static const char *vertShaderText =
2278 "#version 140\n"
2279 "#extension GL_ARB_separate_shader_objects : enable\n"
2280 "#extension GL_ARB_shading_language_420pack : enable\n"
2281 "void main() {\n"
2282 " vec2 vertices[3];"
2283 " vertices[0] = vec2(-0.5, -0.5);\n"
2284 " vertices[1] = vec2( 0.5, -0.5);\n"
2285 " vertices[2] = vec2( 0.5, 0.5);\n"
2286 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2287 "}\n";
2288
2289 static const char *fragShaderText =
2290 "#version 140\n"
2291 "#extension GL_ARB_separate_shader_objects : enable\n"
2292 "#extension GL_ARB_shading_language_420pack : enable\n"
2293 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2294 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2295 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002296 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
Tony Barbourf43b6982014-11-25 13:18:32 -07002297 "void main() {\n"
2298 " gl_FragColor = myBlueVal.color;\n"
2299 " gl_FragColor += myRedVal.color;\n"
2300 "}\n";
2301
2302 ASSERT_NO_FATAL_FAILURE(InitState());
2303 ASSERT_NO_FATAL_FAILURE(InitViewport());
2304
2305 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2306 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2307
2308 // We're going to create a number of uniform buffers, and then allow
2309 // the shader to select which it wants to read from with a binding
2310
2311 // Let's populate the buffers with a single color each:
2312 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2313 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2314 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002315 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002316
2317 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2318 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2319 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2320 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2321
2322 const int redCount = sizeof(redVals) / sizeof(float);
2323 const int greenCount = sizeof(greenVals) / sizeof(float);
2324 const int blueCount = sizeof(blueVals) / sizeof(float);
2325 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2326
2327 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002328
2329 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002330
2331 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002332
2333 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002334
2335 XglPipelineObj pipelineobj(m_device);
2336 pipelineobj.AddShader(&vs);
2337 pipelineobj.AddShader(&ps);
2338
2339 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002340 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2341 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2342 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2343 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002344
Tony Barbourdd4c9642015-01-09 12:55:14 -07002345 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002346 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002347 XglCommandBufferObj cmdBuffer(m_device);
2348 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002349
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002350 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002351
2352 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2353
2354#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002355 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002356 pDSDumpDot((char*)"triTest2.dot");
2357#endif
2358 // render triangle
2359 cmdBuffer.Draw(0, 3, 0, 1);
2360
2361 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002362 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002363 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002364
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002365 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002366 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002367}
2368
2369TEST_F(XglRenderTest, TriangleFSAnonymousUniformBlockBinding)
2370{
2371 // This test is the same as TriangleFSUniformBlockBinding, but
2372 // it does not provide an instance name.
2373 // The expected result from this test is a purple triangle
2374
2375 static const char *vertShaderText =
2376 "#version 140\n"
2377 "#extension GL_ARB_separate_shader_objects : enable\n"
2378 "#extension GL_ARB_shading_language_420pack : enable\n"
2379 "void main() {\n"
2380 " vec2 vertices[3];"
2381 " vertices[0] = vec2(-0.5, -0.5);\n"
2382 " vertices[1] = vec2( 0.5, -0.5);\n"
2383 " vertices[2] = vec2( 0.5, 0.5);\n"
2384 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2385 "}\n";
2386
2387 static const char *fragShaderText =
2388 "#version 430\n"
2389 "#extension GL_ARB_separate_shader_objects : enable\n"
2390 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002391 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2392 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2393 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002394 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002395 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002396 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002397 " outColor = blue;\n"
2398 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002399 "}\n";
2400 ASSERT_NO_FATAL_FAILURE(InitState());
2401 ASSERT_NO_FATAL_FAILURE(InitViewport());
2402
2403 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2404 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2405
2406 // We're going to create a number of uniform buffers, and then allow
2407 // the shader to select which it wants to read from with a binding
2408
2409 // Let's populate the buffers with a single color each:
2410 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2411 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2412 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2413 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2414
2415 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2416 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2417 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2418 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2419
2420 const int redCount = sizeof(redVals) / sizeof(float);
2421 const int greenCount = sizeof(greenVals) / sizeof(float);
2422 const int blueCount = sizeof(blueVals) / sizeof(float);
2423 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2424
2425 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002426
2427 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002428
2429 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002430
2431 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002432
2433 XglPipelineObj pipelineobj(m_device);
2434 pipelineobj.AddShader(&vs);
2435 pipelineobj.AddShader(&ps);
2436
2437 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002438 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2439 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2440 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2441 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002442
Tony Barbourdd4c9642015-01-09 12:55:14 -07002443 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002444 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002445 XglCommandBufferObj cmdBuffer(m_device);
2446 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2447
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002448 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002449
2450 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2451
2452#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002453 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002454 pDSDumpDot((char*)"triTest2.dot");
2455#endif
2456 // render triangle
2457 cmdBuffer.Draw(0, 3, 0, 1);
2458
2459 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002460 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002461 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002462
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002463 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002464 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002465
2466}
2467
2468TEST_F(XglRenderTest, CubeWithVertexFetchAndMVPAndTexture)
2469{
2470 static const char *vertShaderText =
2471 "#version 140\n"
2472 "#extension GL_ARB_separate_shader_objects : enable\n"
2473 "#extension GL_ARB_shading_language_420pack : enable\n"
2474 "layout (std140, binding=0) uniform bufferVals {\n"
2475 " mat4 mvp;\n"
2476 "} myBufferVals;\n"
2477 "layout (location=0) in vec4 pos;\n"
2478 "layout (location=0) out vec2 UV;\n"
2479 "void main() {\n"
2480 " vec2 positions[3];"
2481 " positions[0] = vec2( 0.0, 0.0);\n"
2482 " positions[1] = vec2( 0.25, 0.1);\n"
2483 " positions[2] = vec2( 0.1, 0.25);\n"
2484 " UV = positions[gl_VertexID % 3];\n"
2485 " gl_Position = myBufferVals.mvp * pos;\n"
2486 "}\n";
2487
2488 static const char *fragShaderText =
2489 "#version 140\n"
2490 "#extension GL_ARB_separate_shader_objects : enable\n"
2491 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002492 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002493 "layout (location=0) out vec4 outColor;\n"
2494 "layout (location=0) in vec2 UV;\n"
2495 "void main() {\n"
2496 " outColor= textureLod(surface, UV, 0.0);\n"
2497 "}\n";
2498 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2499
2500 glm::mat4 View = glm::lookAt(
2501 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2502 glm::vec3(0,0,0), // and looks at the origin
2503 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2504 );
2505
2506 glm::mat4 Model = glm::mat4(1.0f);
2507
2508 glm::mat4 MVP = Projection * View * Model;
2509
2510
2511 ASSERT_NO_FATAL_FAILURE(InitState());
2512 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour17c6ab12015-03-27 17:03:18 -06002513 m_depthStencil->Init(m_device, m_width, m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07002514
2515 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
2516 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002517 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002518
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002519 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07002520
2521 XglConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2522 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2523 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2524 XglSamplerObj sampler(m_device);
2525 XglTextureObj texture(m_device);
2526
Tony Barbourf43b6982014-11-25 13:18:32 -07002527 XglPipelineObj pipelineobj(m_device);
2528 pipelineobj.AddShader(&vs);
2529 pipelineobj.AddShader(&ps);
2530
2531 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06002532 // descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer); // TODO: Why does this break images??
Chia-I Wuf8385062015-01-04 16:27:24 +08002533 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mvpBuffer);
2534 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002535
2536 m_memoryRefManager.AddMemoryRef(&meshBuffer);
2537 m_memoryRefManager.AddMemoryRef(&mvpBuffer);
2538 m_memoryRefManager.AddMemoryRef(&texture);
Tony Barbour17c6ab12015-03-27 17:03:18 -06002539 m_memoryRefManager.AddMemoryRef(m_depthStencil);
Tony Barbourf43b6982014-11-25 13:18:32 -07002540
2541 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
2542 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
2543 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
2544 };
2545
2546 // this is the current description of g_vbData
2547 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
2548 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07002549 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07002550 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2551 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07002552 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Tony Barbourf43b6982014-11-25 13:18:32 -07002553 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
2554
2555 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2556 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
2557 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
2558
Tony Barbourfa6cac72015-01-16 14:27:35 -07002559 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
2560 ds_state.depthTestEnable = XGL_TRUE;
2561 ds_state.depthWriteEnable = XGL_TRUE;
2562 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
2563 ds_state.depthBoundsEnable = XGL_FALSE;
2564 ds_state.stencilTestEnable = XGL_FALSE;
2565 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
2566 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
2567 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
2568 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07002569 ds_state.format = XGL_FMT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002570 ds_state.front = ds_state.back;
2571 pipelineobj.SetDepthStencil(&ds_state);
2572
Tony Barbour17c6ab12015-03-27 17:03:18 -06002573 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002574 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002575 XglCommandBufferObj cmdBuffer(m_device);
2576 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002577
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002578 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
2579
Tony Barbourdd4c9642015-01-09 12:55:14 -07002580 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2581
2582 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2583#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002584 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002585 pDSDumpDot((char*)"triTest2.dot");
2586#endif
2587 // render triangle
2588 cmdBuffer.Draw(0, 36, 0, 1);
2589
2590 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002591 EndCommandBuffer(cmdBuffer);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002592 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
2593
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002594 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002595 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002596
2597}
Cody Northropd1ce7842014-12-09 11:17:01 -07002598
2599TEST_F(XglRenderTest, TriangleMixedSamplerUniformBlockBinding)
2600{
2601 // This test mixes binding slots of textures and buffers, ensuring
2602 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002603 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002604 // you can modify it to move the desired result around.
2605
2606 static const char *vertShaderText =
2607 "#version 140\n"
2608 "#extension GL_ARB_separate_shader_objects : enable\n"
2609 "#extension GL_ARB_shading_language_420pack : enable\n"
2610 "void main() {\n"
2611 " vec2 vertices[3];"
2612 " vertices[0] = vec2(-0.5, -0.5);\n"
2613 " vertices[1] = vec2( 0.5, -0.5);\n"
2614 " vertices[2] = vec2( 0.5, 0.5);\n"
2615 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2616 "}\n";
2617
2618 static const char *fragShaderText =
2619 "#version 430\n"
2620 "#extension GL_ARB_separate_shader_objects : enable\n"
2621 "#extension GL_ARB_shading_language_420pack : enable\n"
2622 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002623 "layout (binding = 3) uniform sampler2D surface1;\n"
2624 "layout (binding = 1) uniform sampler2D surface2;\n"
2625 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002626
Cody Northropa0410942014-12-09 13:59:39 -07002627
Chia-I Wuf8385062015-01-04 16:27:24 +08002628 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2629 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2630 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2631 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002632 "layout (location = 0) out vec4 outColor;\n"
2633 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002634 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002635 " outColor += white * vec4(0.00001);\n"
2636 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002637 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002638 "}\n";
2639 ASSERT_NO_FATAL_FAILURE(InitState());
2640 ASSERT_NO_FATAL_FAILURE(InitViewport());
2641
2642 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2643 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2644
Cody Northropd1ce7842014-12-09 11:17:01 -07002645 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2646 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2647 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2648 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2649
2650 const int redCount = sizeof(redVals) / sizeof(float);
2651 const int greenCount = sizeof(greenVals) / sizeof(float);
2652 const int blueCount = sizeof(blueVals) / sizeof(float);
2653 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2654
2655 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002656 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002657 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002658 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002659
Tony Barbour2f421a02015-04-01 16:38:10 -06002660 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Cody Northropd1ce7842014-12-09 11:17:01 -07002661 XglSamplerObj sampler0(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002662 XglTextureObj texture0(m_device, tex_colors); // Light Red
2663 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Cody Northropd1ce7842014-12-09 11:17:01 -07002664 XglSamplerObj sampler2(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002665 XglTextureObj texture2(m_device, tex_colors); // Light Blue
2666 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Cody Northropd1ce7842014-12-09 11:17:01 -07002667 XglSamplerObj sampler4(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002668 XglTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropa0410942014-12-09 13:59:39 -07002669
2670 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2671 // TODO: Get back here ASAP and understand why.
Tony Barbour2f421a02015-04-01 16:38:10 -06002672 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Cody Northropa0410942014-12-09 13:59:39 -07002673 XglSamplerObj sampler7(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002674 XglTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropd1ce7842014-12-09 11:17:01 -07002675
2676 XglPipelineObj pipelineobj(m_device);
2677 pipelineobj.AddShader(&vs);
2678 pipelineobj.AddShader(&ps);
2679
2680 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002681 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2682 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2683 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2684 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2685 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2686 // swap blue and green
2687 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2688 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2689 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002690
2691 m_memoryRefManager.AddMemoryRef(&texture0);
2692 m_memoryRefManager.AddMemoryRef(&texture2);
2693 m_memoryRefManager.AddMemoryRef(&texture4);
Cody Northropa0410942014-12-09 13:59:39 -07002694 m_memoryRefManager.AddMemoryRef(&texture7);
Cody Northropd1ce7842014-12-09 11:17:01 -07002695
Tony Barbourdd4c9642015-01-09 12:55:14 -07002696 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002697 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002698 XglCommandBufferObj cmdBuffer(m_device);
2699 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002700
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002701 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002702
2703 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2704
2705#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002706 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002707 pDSDumpDot((char*)"triTest2.dot");
2708#endif
2709 // render triangle
2710 cmdBuffer.Draw(0, 3, 0, 1);
2711
2712 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002713 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002714 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002715
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002716 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002717 RecordImage(m_renderTargets[i]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002718
2719}
2720
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002721TEST_F(XglRenderTest, TriangleMatchingSamplerUniformBlockBinding)
2722{
2723 // This test matches binding slots of textures and buffers, requiring
2724 // the driver to give them distinct number spaces.
2725 // The expected result from this test is a red triangle, although
2726 // you can modify it to move the desired result around.
2727
2728 static const char *vertShaderText =
2729 "#version 140\n"
2730 "#extension GL_ARB_separate_shader_objects : enable\n"
2731 "#extension GL_ARB_shading_language_420pack : enable\n"
2732 "void main() {\n"
2733 " vec2 vertices[3];"
2734 " vertices[0] = vec2(-0.5, -0.5);\n"
2735 " vertices[1] = vec2( 0.5, -0.5);\n"
2736 " vertices[2] = vec2( 0.5, 0.5);\n"
2737 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2738 "}\n";
2739
2740 static const char *fragShaderText =
2741 "#version 430\n"
2742 "#extension GL_ARB_separate_shader_objects : enable\n"
2743 "#extension GL_ARB_shading_language_420pack : enable\n"
2744 "layout (binding = 0) uniform sampler2D surface0;\n"
2745 "layout (binding = 1) uniform sampler2D surface1;\n"
2746 "layout (binding = 2) uniform sampler2D surface2;\n"
2747 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002748 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2749 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2750 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2751 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002752 "layout (location = 0) out vec4 outColor;\n"
2753 "void main() {\n"
2754 " outColor = red;// * vec4(0.00001);\n"
2755 " outColor += white * vec4(0.00001);\n"
2756 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2757 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2758 "}\n";
2759 ASSERT_NO_FATAL_FAILURE(InitState());
2760 ASSERT_NO_FATAL_FAILURE(InitViewport());
2761
2762 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2763 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2764
2765 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2766 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2767 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2768 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2769
2770 const int redCount = sizeof(redVals) / sizeof(float);
2771 const int greenCount = sizeof(greenVals) / sizeof(float);
2772 const int blueCount = sizeof(blueVals) / sizeof(float);
2773 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2774
2775 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002776 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002777 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002778 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002779
Tony Barbour2f421a02015-04-01 16:38:10 -06002780 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002781 XglSamplerObj sampler0(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002782 XglTextureObj texture0(m_device, tex_colors); // Light Red
2783 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002784 XglSamplerObj sampler2(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002785 XglTextureObj texture2(m_device, tex_colors); // Light Blue
2786 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002787 XglSamplerObj sampler4(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002788 XglTextureObj texture4(m_device, tex_colors); // Light Green
2789 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002790 XglSamplerObj sampler7(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002791 XglTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002792
2793 XglPipelineObj pipelineobj(m_device);
2794 pipelineobj.AddShader(&vs);
2795 pipelineobj.AddShader(&ps);
2796
2797 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002798 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2799 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2800 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2801 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2802 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2803 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2804 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2805 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002806
2807 m_memoryRefManager.AddMemoryRef(&texture0);
2808 m_memoryRefManager.AddMemoryRef(&texture2);
2809 m_memoryRefManager.AddMemoryRef(&texture4);
2810 m_memoryRefManager.AddMemoryRef(&texture7);
2811
Tony Barbourdd4c9642015-01-09 12:55:14 -07002812 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002813 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002814 XglCommandBufferObj cmdBuffer(m_device);
2815 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002816
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002817 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002818
2819 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2820
2821#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002822 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002823 pDSDumpDot((char*)"triTest2.dot");
2824#endif
2825 // render triangle
2826 cmdBuffer.Draw(0, 3, 0, 1);
2827
2828 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002829 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002830 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002831
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002832 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002833 RecordImage(m_renderTargets[i]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002834
2835}
2836
Cody Northrop02690bd2014-12-17 15:26:33 -07002837TEST_F(XglRenderTest, TriangleUniformBufferLayout)
2838{
2839 // This test populates a buffer with a variety of different data
2840 // types, then reads them out with a shader.
2841 // The expected result from this test is a green triangle
2842
2843 static const char *vertShaderText =
2844 "#version 140\n"
2845 "#extension GL_ARB_separate_shader_objects : enable\n"
2846 "#extension GL_ARB_shading_language_420pack : enable\n"
2847 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2848 " vec4 fRed;\n"
2849 " vec4 fGreen;\n"
2850 " layout(row_major) mat4 worldToProj;\n"
2851 " layout(row_major) mat4 projToWorld;\n"
2852 " layout(row_major) mat4 worldToView;\n"
2853 " layout(row_major) mat4 viewToProj;\n"
2854 " layout(row_major) mat4 worldToShadow[4];\n"
2855 " float fZero;\n"
2856 " float fOne;\n"
2857 " float fTwo;\n"
2858 " float fThree;\n"
2859 " vec3 fZeroZeroZero;\n"
2860 " float fFour;\n"
2861 " vec3 fZeroZeroOne;\n"
2862 " float fFive;\n"
2863 " vec3 fZeroOneZero;\n"
2864 " float fSix;\n"
2865 " float fSeven;\n"
2866 " float fEight;\n"
2867 " float fNine;\n"
2868 " vec2 fZeroZero;\n"
2869 " vec2 fZeroOne;\n"
2870 " vec4 fBlue;\n"
2871 " vec2 fOneZero;\n"
2872 " vec2 fOneOne;\n"
2873 " vec3 fZeroOneOne;\n"
2874 " float fTen;\n"
2875 " float fEleven;\n"
2876 " float fTwelve;\n"
2877 " vec3 fOneZeroZero;\n"
2878 " vec4 uvOffsets[4];\n"
2879 "};\n"
2880 "layout (location = 0) out vec4 color;"
2881 "void main() {\n"
2882
2883 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2884 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2885 " \n"
2886
2887 // do some exact comparisons, even though we should
2888 // really have an epsilon involved.
2889 " vec4 outColor = right;\n"
2890 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
2891 " outColor = wrong;\n"
2892 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
2893 " outColor = wrong;\n"
2894 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
2895 " outColor = wrong;\n"
2896
2897 " color = outColor;\n"
2898
2899 // generic position stuff
2900 " vec2 vertices;\n"
2901 " int vertexSelector = gl_VertexID;\n"
2902 " if (vertexSelector == 0)\n"
2903 " vertices = vec2(-0.5, -0.5);\n"
2904 " else if (vertexSelector == 1)\n"
2905 " vertices = vec2( 0.5, -0.5);\n"
2906 " else if (vertexSelector == 2)\n"
2907 " vertices = vec2( 0.5, 0.5);\n"
2908 " else\n"
2909 " vertices = vec2( 0.0, 0.0);\n"
2910 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
2911 "}\n";
2912
2913 static const char *fragShaderText =
2914 "#version 140\n"
2915 "#extension GL_ARB_separate_shader_objects : enable\n"
2916 "#extension GL_ARB_shading_language_420pack : enable\n"
2917 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2918 " vec4 fRed;\n"
2919 " vec4 fGreen;\n"
2920 " layout(row_major) mat4 worldToProj;\n"
2921 " layout(row_major) mat4 projToWorld;\n"
2922 " layout(row_major) mat4 worldToView;\n"
2923 " layout(row_major) mat4 viewToProj;\n"
2924 " layout(row_major) mat4 worldToShadow[4];\n"
2925 " float fZero;\n"
2926 " float fOne;\n"
2927 " float fTwo;\n"
2928 " float fThree;\n"
2929 " vec3 fZeroZeroZero;\n"
2930 " float fFour;\n"
2931 " vec3 fZeroZeroOne;\n"
2932 " float fFive;\n"
2933 " vec3 fZeroOneZero;\n"
2934 " float fSix;\n"
2935 " float fSeven;\n"
2936 " float fEight;\n"
2937 " float fNine;\n"
2938 " vec2 fZeroZero;\n"
2939 " vec2 fZeroOne;\n"
2940 " vec4 fBlue;\n"
2941 " vec2 fOneZero;\n"
2942 " vec2 fOneOne;\n"
2943 " vec3 fZeroOneOne;\n"
2944 " float fTen;\n"
2945 " float fEleven;\n"
2946 " float fTwelve;\n"
2947 " vec3 fOneZeroZero;\n"
2948 " vec4 uvOffsets[4];\n"
2949 "};\n"
2950 "layout (location = 0) in vec4 color;\n"
2951 "void main() {\n"
2952 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2953 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2954 " \n"
2955
2956 // start with VS value to ensure it passed
2957 " vec4 outColor = color;\n"
2958
2959 // do some exact comparisons, even though we should
2960 // really have an epsilon involved.
2961 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
2962 " outColor = wrong;\n"
2963 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
2964 " outColor = wrong;\n"
2965 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
2966 " outColor = wrong;\n"
2967 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
2968 " outColor = wrong;\n"
2969 " if (fTwo != 2.0)\n"
2970 " outColor = wrong;\n"
2971 " if (fOneOne != vec2(1.0, 1.0))\n"
2972 " outColor = wrong;\n"
2973 " if (fTen != 10.0)\n"
2974 " outColor = wrong;\n"
2975 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
2976 " outColor = wrong;\n"
2977 " \n"
2978 " gl_FragColor = outColor;\n"
2979 "}\n";
2980
2981
2982 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
2983 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
2984 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
2985 0.0, 1.0, 0.0, 1.0, // align
2986 0.0, 0.0, 1.0, 1.0, // align
2987 0.0, 0.0, 0.0, 1.0, // align
2988 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
2989 0.0, 2.0, 0.0, 2.0, // align
2990 0.0, 0.0, 2.0, 2.0, // align
2991 0.0, 0.0, 0.0, 2.0, // align
2992 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
2993 0.0, 3.0, 0.0, 3.0, // align
2994 0.0, 0.0, 3.0, 3.0, // align
2995 0.0, 0.0, 0.0, 3.0, // align
2996 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
2997 0.0, 4.0, 0.0, 4.0, // align
2998 0.0, 0.0, 4.0, 4.0, // align
2999 0.0, 0.0, 0.0, 4.0, // align
3000 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3001 0.0, 5.0, 0.0, 5.0, // align
3002 0.0, 0.0, 5.0, 5.0, // align
3003 0.0, 0.0, 0.0, 5.0, // align
3004 6.0, 0.0, 0.0, 6.0, // align
3005 0.0, 6.0, 0.0, 6.0, // align
3006 0.0, 0.0, 6.0, 6.0, // align
3007 0.0, 0.0, 0.0, 6.0, // align
3008 7.0, 0.0, 0.0, 7.0, // align
3009 0.0, 7.0, 0.0, 7.0, // align
3010 0.0, 0.0, 7.0, 7.0, // align
3011 0.0, 0.0, 0.0, 7.0, // align
3012 8.0, 0.0, 0.0, 8.0, // align
3013 0.0, 8.0, 0.0, 8.0, // align
3014 0.0, 0.0, 8.0, 8.0, // align
3015 0.0, 0.0, 0.0, 8.0, // align
3016 0.0, // float fZero; // align
3017 1.0, // float fOne; // pack
3018 2.0, // float fTwo; // pack
3019 3.0, // float fThree; // pack
3020 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3021 4.0, // float fFour; // pack
3022 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3023 5.0, // float fFive; // pack
3024 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3025 6.0, // float fSix; // pack
3026 7.0, // float fSeven; // align
3027 8.0, // float fEight; // pack
3028 9.0, // float fNine; // pack
3029 0.0, // BUFFER
3030 0.0, 0.0, // vec2 fZeroZero; // align
3031 0.0, 1.0, // vec2 fZeroOne; // pack
3032 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3033 1.0, 0.0, // vec2 fOneZero; // align
3034 1.0, 1.0, // vec2 fOneOne; // pack
3035 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3036 10.0, // float fTen; // pack
3037 11.0, // float fEleven; // align
3038 12.0, // float fTwelve; // pack
3039 0.0, 0.0, // BUFFER
3040 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3041 0.0, // BUFFER
3042 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3043 0.5, 0.6, 0.7, 0.8, // align
3044 0.9, 1.0, 1.1, 1.2, // align
3045 1.3, 1.4, 1.5, 1.6, // align
3046 };
3047
3048 ASSERT_NO_FATAL_FAILURE(InitState());
3049 ASSERT_NO_FATAL_FAILURE(InitViewport());
3050
3051 const int constCount = sizeof(mixedVals) / sizeof(float);
3052
3053 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
3054 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
3055
3056 XglConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003057
3058 XglPipelineObj pipelineobj(m_device);
3059 pipelineobj.AddShader(&vs);
3060 pipelineobj.AddShader(&ps);
3061
3062 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08003063 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003064
3065 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07003066 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Cody Northrop02690bd2014-12-17 15:26:33 -07003067 XglCommandBufferObj cmdBuffer(m_device);
3068 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3069
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003070 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Cody Northrop02690bd2014-12-17 15:26:33 -07003071
3072 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
3073
3074#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003075 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop02690bd2014-12-17 15:26:33 -07003076 pDSDumpDot((char*)"triTest2.dot");
3077#endif
3078 // render triangle
3079 cmdBuffer.Draw(0, 3, 0, 1);
3080
3081 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003082 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06003083 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Cody Northrop02690bd2014-12-17 15:26:33 -07003084
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07003085 for (int i = 0; i < m_renderTargets.size(); i++)
Cody Northrop02690bd2014-12-17 15:26:33 -07003086 RecordImage(m_renderTargets[i]);
3087}
3088
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003089int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003090 int result;
3091
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003092 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003093 XglTestFramework::InitArgs(&argc, argv);
3094
Chia-I Wu7133fdc2014-12-15 23:57:34 +08003095 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06003096
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003097 result = RUN_ALL_TESTS();
3098
3099 XglTestFramework::Finish();
3100 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003101}