blob: cf8b3989752e73fc7ecead2c100fd7a3e74792f0 [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 Goeltzenleuchter65da6e42015-03-31 16:38:46 -0600655TEST_F(XglRenderTest, QuadWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600656{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600657 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600658 "#version 140\n"
659 "#extension GL_ARB_separate_shader_objects : enable\n"
660 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700661 //XYZ1( -1, -1, -1 )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600662 "layout (location = 0) in vec4 pos;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700663 //XYZ1( 0.f, 0.f, 0.f )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600664 "layout (location = 1) in vec4 inColor;\n"
665 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600666 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600667 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600668 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600669 "}\n";
670
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600671
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600672 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700673 "#version 140\n"
674 "#extension GL_ARB_separate_shader_objects : enable\n"
675 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600676 "layout (location = 0) in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700677 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600678 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700679 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600680 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600681
Tony Barbourf43b6982014-11-25 13:18:32 -0700682
683
684 ASSERT_NO_FATAL_FAILURE(InitState());
685 ASSERT_NO_FATAL_FAILURE(InitViewport());
686
687 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000688 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700689
690 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
691 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
692
693 XglPipelineObj pipelineobj(m_device);
694 pipelineobj.AddShader(&vs);
695 pipelineobj.AddShader(&ps);
696
697 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +0800698 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700699
Mark Lobodzinski15427102015-02-18 16:38:17 -0600700 m_memoryRefManager.AddMemoryRef(&meshBuffer);
701
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600702#define MESH_BIND_ID 0
Tony Barbourf43b6982014-11-25 13:18:32 -0700703 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600704 MESH_BIND_ID, // binding ID
Tony Barbourf43b6982014-11-25 13:18:32 -0700705 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
706 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
707 };
708
709 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600710 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
711 vi_attribs[0].location = 0; // location, position
712 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
713 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
714 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
715 vi_attribs[1].location = 1; // location, color
716 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
717 vi_attribs[1].offsetInBytes = 1*sizeof(float)*4; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -0700718
719 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
720 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600721 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -0700722
Tony Barboure4ed9942015-01-09 10:06:53 -0700723 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700724 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barboure4ed9942015-01-09 10:06:53 -0700725 XglCommandBufferObj cmdBuffer(m_device);
726 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700727
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600728 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
729
Tony Barboure4ed9942015-01-09 10:06:53 -0700730 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
731
Tony Barboure4ed9942015-01-09 10:06:53 -0700732 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
733
734 // render two triangles
735 cmdBuffer.Draw(0, 6, 0, 1);
736
737 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600738 EndCommandBuffer(cmdBuffer);
739
Mark Lobodzinski15427102015-02-18 16:38:17 -0600740 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barboure4ed9942015-01-09 10:06:53 -0700741
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700742 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barboure4ed9942015-01-09 10:06:53 -0700743 RecordImage(m_renderTargets[i]);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600744}
745
Chia-I Wue09d1a72014-12-05 10:32:23 +0800746TEST_F(XglRenderTest, TriangleMRT)
747{
748 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600749 "#version 140\n"
750 "#extension GL_ARB_separate_shader_objects : enable\n"
751 "#extension GL_ARB_shading_language_420pack : enable\n"
752 "layout (location = 0) in vec4 pos;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800753 "void main() {\n"
754 " gl_Position = pos;\n"
755 "}\n";
756
757 static const char *fragShaderText =
758 "#version 130\n"
759 "void main() {\n"
760 " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
761 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
762 "}\n";
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600763 const float vb_data[][2] = {
Chia-I Wue09d1a72014-12-05 10:32:23 +0800764 { -1.0f, -1.0f },
765 { 1.0f, -1.0f },
766 { -1.0f, 1.0f }
767 };
768
769 ASSERT_NO_FATAL_FAILURE(InitState());
770 ASSERT_NO_FATAL_FAILURE(InitViewport());
771
772 XglConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000773 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800774
775 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
776 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
777
778 XglPipelineObj pipelineobj(m_device);
779 pipelineobj.AddShader(&vs);
780 pipelineobj.AddShader(&ps);
781
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600782#define MESH_BUF_ID 0
Chia-I Wue09d1a72014-12-05 10:32:23 +0800783 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600784 MESH_BUF_ID, // Binding ID
785 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
786 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Chia-I Wue09d1a72014-12-05 10:32:23 +0800787 };
788
789 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attrib;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600790 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
791 vi_attrib.location = 0;
792 vi_attrib.format = XGL_FMT_R32G32_SFLOAT; // format of source data
793 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
Chia-I Wue09d1a72014-12-05 10:32:23 +0800794
795 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
796 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600797 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800798
799 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -0600800 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800801
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700802 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
803 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Mark Lobodzinski15427102015-02-18 16:38:17 -0600804 m_memoryRefManager.AddMemoryRef(&meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800805
806 XGL_PIPELINE_CB_ATTACHMENT_STATE att = {};
807 att.blendEnable = XGL_FALSE;
808 att.format = m_render_target_fmt;
809 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700810 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800811
Tony Barbour5ed79702015-01-07 14:31:52 -0700812 XglCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700813
Tony Barbour5ed79702015-01-07 14:31:52 -0700814 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
815 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barboure4ed9942015-01-09 10:06:53 -0700816
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600817 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour5ed79702015-01-07 14:31:52 -0700818
Tony Barboure4ed9942015-01-09 10:06:53 -0700819 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
820
Tony Barbour5ed79702015-01-07 14:31:52 -0700821 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700822#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600823 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour5ed79702015-01-07 14:31:52 -0700824 pDSDumpDot((char*)"triTest2.dot");
825#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600826
Tony Barbour5ed79702015-01-07 14:31:52 -0700827 // render triangle
828 cmdBuffer.Draw(0, 3, 0, 1);
829
830 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600831 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -0600832 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbour5ed79702015-01-07 14:31:52 -0700833
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700834 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbour5ed79702015-01-07 14:31:52 -0700835 RecordImage(m_renderTargets[i]);
836
Chia-I Wue09d1a72014-12-05 10:32:23 +0800837}
838
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700839TEST_F(XglRenderTest, QuadWithIndexedVertexFetch)
840{
841 static const char *vertShaderText =
842 "#version 140\n"
843 "#extension GL_ARB_separate_shader_objects : enable\n"
844 "#extension GL_ARB_shading_language_420pack : enable\n"
845 "layout(location = 0) in vec4 pos;\n"
846 "layout(location = 1) in vec4 inColor;\n"
847 "layout(location = 0) out vec4 outColor;\n"
848 "void main() {\n"
849 " outColor = inColor;\n"
850 " gl_Position = pos;\n"
851 "}\n";
852
853
854 static const char *fragShaderText =
855 "#version 140\n"
856 "#extension GL_ARB_separate_shader_objects : enable\n"
857 "#extension GL_ARB_shading_language_420pack : enable\n"
858 "layout(location = 0) in vec4 color;\n"
859 "void main() {\n"
860 " gl_FragColor = color;\n"
861 "}\n";
862
863 const Vertex g_vbData[] =
864 {
865 // first tri
866 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
867 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
868 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
869
870 // second tri
871 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
872 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
873 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
874 };
875
876 const uint16_t g_idxData[6] = {
877 0, 1, 2,
878 3, 4, 5,
879 };
880
881 ASSERT_NO_FATAL_FAILURE(InitState());
882 ASSERT_NO_FATAL_FAILURE(InitViewport());
883
884 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000885 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700886
887 XglIndexBufferObj indexBuffer(m_device);
888 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), XGL_INDEX_16, g_idxData);
Mark Lobodzinskid30f82a2015-02-16 14:24:23 -0600889 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700890
891 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
892 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
893
894 XglPipelineObj pipelineobj(m_device);
895 pipelineobj.AddShader(&vs);
896 pipelineobj.AddShader(&ps);
897
898 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -0600899 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
900 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &indexBuffer);
901
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700902
Mark Lobodzinski15427102015-02-18 16:38:17 -0600903 m_memoryRefManager.AddMemoryRef(&meshBuffer);
904 m_memoryRefManager.AddMemoryRef(&indexBuffer);
905
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600906#define MESH_BIND_ID 0
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700907 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600908 MESH_BIND_ID, // binding ID
909 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
910 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700911 };
912
913 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600914 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
915 vi_attribs[0].location = 0; // layout location of vertex attribute
916 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
917 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
918 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
919 vi_attribs[1].location = 1; // layout location of vertex attribute
920 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
921 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700922
923 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
924 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700925
926 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700927 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700928 XglCommandBufferObj cmdBuffer(m_device);
929 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600930 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barboure4ed9942015-01-09 10:06:53 -0700931
932 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700933
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700934#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600935 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700936 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700937#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700938
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600939 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700940 cmdBuffer.BindIndexBuffer(&indexBuffer,0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700941
942 // render two triangles
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700943 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700944
945 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600946 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -0600947 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700948
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700949 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700950 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700951
952}
953
GregF6bef1212014-12-02 15:41:44 -0700954TEST_F(XglRenderTest, GreyandRedCirclesonBlue)
955{
956 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -0700957
GregF6bef1212014-12-02 15:41:44 -0700958 static const char *vertShaderText =
959 "#version 140\n"
960 "#extension GL_ARB_separate_shader_objects : enable\n"
961 "#extension GL_ARB_shading_language_420pack : enable\n"
962 "layout (location = 0) in vec4 pos;\n"
963 "layout (location = 0) out vec4 outColor;\n"
964 "layout (location = 1) out vec4 outColor2;\n"
965 "void main() {\n"
966 " gl_Position = pos;\n"
967 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
968 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
969 "}\n";
970
971 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -0700972 "#version 330\n"
973 "#extension GL_ARB_separate_shader_objects : enable\n"
974 "#extension GL_ARB_shading_language_420pack : enable\n"
975 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
976 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
977 "layout (location = 0) in vec4 color;\n"
978 "layout (location = 1) in vec4 color2;\n"
979 "void main() {\n"
980 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
981 " float dist_squared = dot(pos, pos);\n"
982 " gl_FragColor = (dist_squared < 400.0)\n"
983 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
984 " : color2;\n"
985 "}\n";
986
987 ASSERT_NO_FATAL_FAILURE(InitState());
988 ASSERT_NO_FATAL_FAILURE(InitViewport());
989
990 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000991 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -0700992
993 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
994 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
995
996 XglPipelineObj pipelineobj(m_device);
997 pipelineobj.AddShader(&vs);
998 pipelineobj.AddShader(&ps);
999
1000 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001001 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001002
Mark Lobodzinski15427102015-02-18 16:38:17 -06001003 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1004
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001005#define MESH_BIND_ID 0
GregF6bef1212014-12-02 15:41:44 -07001006 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001007 MESH_BIND_ID, // binding ID
1008 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1009 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001010 };
1011
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001012 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[1];
1013 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1014 vi_attribs[0].location = 0;
1015 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
1016 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001017
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001018 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001019 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001020 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001021
Tony Barbourdd4c9642015-01-09 12:55:14 -07001022 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001023 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001024 XglCommandBufferObj cmdBuffer(m_device);
1025 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1026
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001027 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001028
1029 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1030
1031 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1032#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001033 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001034 pDSDumpDot((char*)"triTest2.dot");
1035#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001036
Tony Barbourdd4c9642015-01-09 12:55:14 -07001037 // render triangle
1038 cmdBuffer.Draw(0, 6, 0, 1);
1039
1040 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001041 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001042 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001043
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001044 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001045 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001046
1047}
1048
1049TEST_F(XglRenderTest, RedCirclesonBlue)
1050{
1051 // This tests that we correctly handle unread fragment inputs
1052
1053 static const char *vertShaderText =
1054 "#version 140\n"
1055 "#extension GL_ARB_separate_shader_objects : enable\n"
1056 "#extension GL_ARB_shading_language_420pack : enable\n"
1057 "layout (location = 0) in vec4 pos;\n"
1058 "layout (location = 0) out vec4 outColor;\n"
1059 "layout (location = 1) out vec4 outColor2;\n"
1060 "void main() {\n"
1061 " gl_Position = pos;\n"
1062 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1063 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1064 "}\n";
1065
1066 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001067 "#version 330\n"
1068 "#extension GL_ARB_separate_shader_objects : enable\n"
1069 "#extension GL_ARB_shading_language_420pack : enable\n"
1070 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1071 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1072 "layout (location = 0) in vec4 color;\n"
1073 "layout (location = 1) in vec4 color2;\n"
1074 "void main() {\n"
1075 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1076 " float dist_squared = dot(pos, pos);\n"
1077 " gl_FragColor = (dist_squared < 400.0)\n"
1078 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1079 " : color2;\n"
1080 "}\n";
1081
1082 ASSERT_NO_FATAL_FAILURE(InitState());
1083 ASSERT_NO_FATAL_FAILURE(InitViewport());
1084
1085 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001086 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001087
1088 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1089 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1090
1091 XglPipelineObj pipelineobj(m_device);
1092 pipelineobj.AddShader(&vs);
1093 pipelineobj.AddShader(&ps);
1094
1095 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001096 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001097
Mark Lobodzinski15427102015-02-18 16:38:17 -06001098 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1099
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001100#define MESH_BIND_ID 0
GregF6bef1212014-12-02 15:41:44 -07001101 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001102 MESH_BIND_ID, // binding ID
1103 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1104 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001105 };
1106
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001107 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[1];
1108 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1109 vi_attribs[0].location = 0;
1110 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
1111 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001112
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001113 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001114 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001115 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001116
Tony Barbourdd4c9642015-01-09 12:55:14 -07001117 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001118 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001119 XglCommandBufferObj cmdBuffer(m_device);
1120 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1121
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001122 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001123
1124 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1125
1126 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1127#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001128 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001129 pDSDumpDot((char*)"triTest2.dot");
1130#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001131 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001132 cmdBuffer.Draw(0, 6, 0, 1);
1133
1134 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001135 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001136 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001137
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001138 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001139 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001140
1141}
1142
1143TEST_F(XglRenderTest, GreyCirclesonBlueFade)
1144{
1145 // This tests reading gl_ClipDistance from FS
1146
1147 static const char *vertShaderText =
1148 "#version 330\n"
1149 "#extension GL_ARB_separate_shader_objects : enable\n"
1150 "#extension GL_ARB_shading_language_420pack : enable\n"
1151 "out gl_PerVertex {\n"
1152 " vec4 gl_Position;\n"
1153 " float gl_ClipDistance[1];\n"
1154 "};\n"
1155 "layout (location = 0) in vec4 pos;\n"
1156 "layout (location = 0) out vec4 outColor;\n"
1157 "layout (location = 1) out vec4 outColor2;\n"
1158 "void main() {\n"
1159 " gl_Position = pos;\n"
1160 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1161 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1162 " float dists[3];\n"
1163 " dists[0] = 0.0;\n"
1164 " dists[1] = 1.0;\n"
1165 " dists[2] = 1.0;\n"
1166 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1167 "}\n";
1168
1169
1170 static const char *fragShaderText =
1171 //"#version 140\n"
1172 "#version 330\n"
1173 "#extension GL_ARB_separate_shader_objects : enable\n"
1174 "#extension GL_ARB_shading_language_420pack : enable\n"
1175 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1176 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1177 "layout (location = 0) in vec4 color;\n"
1178 "layout (location = 1) in vec4 color2;\n"
1179 "void main() {\n"
1180 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1181 " float dist_squared = dot(pos, pos);\n"
1182 " gl_FragColor = (dist_squared < 400.0)\n"
1183 " ? color * gl_ClipDistance[0]\n"
1184 " : color2;\n"
1185 "}\n";
1186
1187 ASSERT_NO_FATAL_FAILURE(InitState());
1188 ASSERT_NO_FATAL_FAILURE(InitViewport());
1189
1190 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001191 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001192
1193 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1194 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1195
1196 XglPipelineObj pipelineobj(m_device);
1197 pipelineobj.AddShader(&vs);
1198 pipelineobj.AddShader(&ps);
1199
1200 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001201 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001202
Mark Lobodzinski15427102015-02-18 16:38:17 -06001203 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1204
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001205#define MESH_BIND_ID 0
GregF6bef1212014-12-02 15:41:44 -07001206 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001207 MESH_BIND_ID, // binding ID
1208 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1209 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001210 };
1211
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001212 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[1];
1213 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1214 vi_attribs[0].location = 0;
1215 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
1216 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001217
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001218 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001219 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001220 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001221
Tony Barbourdd4c9642015-01-09 12:55:14 -07001222 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001223 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001224 XglCommandBufferObj cmdBuffer(m_device);
1225 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF6bef1212014-12-02 15:41:44 -07001226
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001227 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001228
1229 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1230
1231 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1232#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001233 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001234 pDSDumpDot((char*)"triTest2.dot");
1235#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001236
1237 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001238 cmdBuffer.Draw(0, 6, 0, 1);
1239
1240 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001241 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001242 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001243
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001244 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001245 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001246}
Tony Barbourf43b6982014-11-25 13:18:32 -07001247
GregF7a23c792014-12-02 17:19:34 -07001248TEST_F(XglRenderTest, GreyCirclesonBlueDiscard)
1249{
1250 static const char *vertShaderText =
1251 "#version 140\n"
1252 "#extension GL_ARB_separate_shader_objects : enable\n"
1253 "#extension GL_ARB_shading_language_420pack : enable\n"
1254 "layout (location = 0) in vec4 pos;\n"
1255 "layout (location = 0) out vec4 outColor;\n"
1256 "layout (location = 1) out vec4 outColor2;\n"
1257 "void main() {\n"
1258 " gl_Position = pos;\n"
1259 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1260 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1261 "}\n";
1262
1263
1264 static const char *fragShaderText =
GregF7a23c792014-12-02 17:19:34 -07001265 "#version 330\n"
1266 "#extension GL_ARB_separate_shader_objects : enable\n"
1267 "#extension GL_ARB_shading_language_420pack : enable\n"
1268 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1269 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1270 "layout (location = 0) in vec4 color;\n"
1271 "layout (location = 1) in vec4 color2;\n"
1272 "void main() {\n"
1273 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1274 " float dist_squared = dot(pos, pos);\n"
1275 " if (dist_squared < 100.0)\n"
1276 " discard;\n"
1277 " gl_FragColor = (dist_squared < 400.0)\n"
1278 " ? color\n"
1279 " : color2;\n"
1280 "}\n";
1281
1282 ASSERT_NO_FATAL_FAILURE(InitState());
1283 ASSERT_NO_FATAL_FAILURE(InitViewport());
1284
1285 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001286 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001287
1288 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1289 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1290
1291 XglPipelineObj pipelineobj(m_device);
1292 pipelineobj.AddShader(&vs);
1293 pipelineobj.AddShader(&ps);
1294
1295 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001296 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF7a23c792014-12-02 17:19:34 -07001297
Mark Lobodzinski15427102015-02-18 16:38:17 -06001298 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1299
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001300#define MESH_BIND_ID 0
GregF7a23c792014-12-02 17:19:34 -07001301 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001302 MESH_BIND_ID, // binding ID
1303 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1304 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF7a23c792014-12-02 17:19:34 -07001305 };
1306
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001307 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[1];
1308 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1309 vi_attribs[0].location = 0;
1310 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
1311 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF7a23c792014-12-02 17:19:34 -07001312
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001313 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF7a23c792014-12-02 17:19:34 -07001314 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001315 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF7a23c792014-12-02 17:19:34 -07001316
Tony Barbourdd4c9642015-01-09 12:55:14 -07001317 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001318 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001319 XglCommandBufferObj cmdBuffer(m_device);
1320 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1321
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001322 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001323
1324 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1325
1326 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1327#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001328 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001329 pDSDumpDot((char*)"triTest2.dot");
1330#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001331
1332 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001333 cmdBuffer.Draw(0, 6, 0, 1);
1334
1335 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001336 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001337 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001338
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001339 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001340 RecordImage(m_renderTargets[i]);
GregF7a23c792014-12-02 17:19:34 -07001341
1342}
1343
1344
Courtney Goeltzenleuchter3d10c9c2014-10-27 13:06:08 -06001345TEST_F(XglRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001346{
1347 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001348 "#version 140\n"
1349 "#extension GL_ARB_separate_shader_objects : enable\n"
1350 "#extension GL_ARB_shading_language_420pack : enable\n"
1351 "\n"
1352 "layout(binding = 0) uniform buf {\n"
1353 " mat4 MVP;\n"
1354 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001355 "void main() {\n"
1356 " vec2 vertices[3];"
1357 " vertices[0] = vec2(-0.5, -0.5);\n"
1358 " vertices[1] = vec2( 0.5, -0.5);\n"
1359 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001360 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001361 "}\n";
1362
1363 static const char *fragShaderText =
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001364 "#version 130\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001365 "void main() {\n"
Cody Northrop78eac042014-10-10 15:45:00 -06001366 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001367 "}\n";
1368
Tony Barbourf43b6982014-11-25 13:18:32 -07001369 ASSERT_NO_FATAL_FAILURE(InitState());
1370 ASSERT_NO_FATAL_FAILURE(InitViewport());
1371
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001372 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001373 glm::mat4 Projection = glm::mat4(1.0f);
1374 glm::mat4 View = glm::mat4(1.0f);
1375 glm::mat4 Model = glm::mat4(1.0f);
1376 glm::mat4 MVP = Projection * View * Model;
1377 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1378
Tony Barbourf43b6982014-11-25 13:18:32 -07001379 XglConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1380 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1381 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001382
Tony Barbourf43b6982014-11-25 13:18:32 -07001383 XglPipelineObj pipelineobj(m_device);
1384 pipelineobj.AddShader(&vs);
1385 pipelineobj.AddShader(&ps);
1386
1387 // Create descriptor set and attach the constant buffer to it
1388 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001389 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001390
1391 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1392
Tony Barbourdd4c9642015-01-09 12:55:14 -07001393 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001394 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001395 XglCommandBufferObj cmdBuffer(m_device);
1396 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001397
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001398 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001399
1400 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1401
1402 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1403#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001404 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001405 pDSDumpDot((char*)"triTest2.dot");
1406#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001407
1408 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001409 cmdBuffer.Draw(0, 6, 0, 1);
1410
1411 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001412 EndCommandBuffer(cmdBuffer);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001413 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
1414
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001415 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001416 RecordImage(m_renderTargets[i]);
1417
1418 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001419}
1420
Tony Barbourf43b6982014-11-25 13:18:32 -07001421TEST_F(XglRenderTest, MixTriangle)
1422{
1423 // This tests location applied to varyings. Notice that we have switched foo
1424 // and bar in the FS. The triangle should be blended with red, green and blue
1425 // corners.
1426 static const char *vertShaderText =
1427 "#version 140\n"
1428 "#extension GL_ARB_separate_shader_objects : enable\n"
1429 "#extension GL_ARB_shading_language_420pack : enable\n"
1430 "layout (location=0) out vec4 bar;\n"
1431 "layout (location=1) out vec4 foo;\n"
1432 "layout (location=2) out float scale;\n"
1433 "vec2 vertices[3];\n"
1434 "void main() {\n"
1435 " vertices[0] = vec2(-1.0, -1.0);\n"
1436 " vertices[1] = vec2( 1.0, -1.0);\n"
1437 " vertices[2] = vec2( 0.0, 1.0);\n"
1438 "vec4 colors[3];\n"
1439 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1440 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1441 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1442 " foo = colors[gl_VertexID % 3];\n"
1443 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1444 " scale = 1.0;\n"
1445 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1446 "}\n";
1447
1448 static const char *fragShaderText =
1449 "#version 140\n"
1450 "#extension GL_ARB_separate_shader_objects : enable\n"
1451 "#extension GL_ARB_shading_language_420pack : enable\n"
1452 "layout (location = 1) in vec4 bar;\n"
1453 "layout (location = 0) in vec4 foo;\n"
1454 "layout (location = 2) in float scale;\n"
1455 "void main() {\n"
1456 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
1457 "}\n";
1458
1459 ASSERT_NO_FATAL_FAILURE(InitState());
1460 ASSERT_NO_FATAL_FAILURE(InitViewport());
1461
1462 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1463 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1464
1465 XglPipelineObj pipelineobj(m_device);
1466 pipelineobj.AddShader(&vs);
1467 pipelineobj.AddShader(&ps);
1468
1469 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06001470 descriptorSet.AppendDummy();
Tony Barbourf43b6982014-11-25 13:18:32 -07001471
Tony Barbourdd4c9642015-01-09 12:55:14 -07001472 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001473 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001474 XglCommandBufferObj cmdBuffer(m_device);
1475 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1476
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001477 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001478
1479 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1480
1481#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001482 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001483 pDSDumpDot((char*)"triTest2.dot");
1484#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001485
Tony Barbourdd4c9642015-01-09 12:55:14 -07001486 // render triangle
1487 cmdBuffer.Draw(0, 3, 0, 1);
1488
1489 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001490 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001491 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001492
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001493 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001494 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001495}
1496
Courtney Goeltzenleuchter65da6e42015-03-31 16:38:46 -06001497TEST_F(XglRenderTest, QuadVertFetchAndVertID)
Tony Barbourf43b6982014-11-25 13:18:32 -07001498{
1499 // This tests that attributes work in the presence of gl_VertexID
1500
1501 static const char *vertShaderText =
1502 "#version 140\n"
1503 "#extension GL_ARB_separate_shader_objects : enable\n"
1504 "#extension GL_ARB_shading_language_420pack : enable\n"
1505 //XYZ1( -1, -1, -1 )
1506 "layout (location = 0) in vec4 pos;\n"
1507 //XYZ1( 0.f, 0.f, 0.f )
1508 "layout (location = 1) in vec4 inColor;\n"
1509 "layout (location = 0) out vec4 outColor;\n"
1510 "void main() {\n"
1511 " outColor = inColor;\n"
1512 " vec4 vertices[3];"
1513 " vertices[gl_VertexID % 3] = pos;\n"
1514 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1515 "}\n";
1516
1517
1518 static const char *fragShaderText =
1519 "#version 140\n"
1520 "#extension GL_ARB_separate_shader_objects : enable\n"
1521 "#extension GL_ARB_shading_language_420pack : enable\n"
1522 "layout (location = 0) in vec4 color;\n"
1523 "void main() {\n"
1524 " gl_FragColor = color;\n"
1525 "}\n";
1526
1527 ASSERT_NO_FATAL_FAILURE(InitState());
1528 ASSERT_NO_FATAL_FAILURE(InitViewport());
1529
1530 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001531 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001532
1533 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1534 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1535
1536 XglPipelineObj pipelineobj(m_device);
1537 pipelineobj.AddShader(&vs);
1538 pipelineobj.AddShader(&ps);
1539
1540 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001541 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001542
Mark Lobodzinski15427102015-02-18 16:38:17 -06001543 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1544
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001545#define MESH_BUF_ID 0
Tony Barbourf43b6982014-11-25 13:18:32 -07001546 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001547 MESH_BUF_ID, // Binding ID
1548 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1549 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001550 };
1551
1552 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001553 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1554 vi_attribs[0].location = 0;
1555 vi_attribs[0].format = XGL_FMT_R32G32_SFLOAT; // format of source data
1556 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1557 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1558 vi_attribs[1].location = 1;
1559 vi_attribs[1].format = XGL_FMT_R32G32_SFLOAT; // format of source data
1560 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001561
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001562 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001563 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001564 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001565
Tony Barbourdd4c9642015-01-09 12:55:14 -07001566 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001567 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001568 XglCommandBufferObj cmdBuffer(m_device);
1569 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1570
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001571 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001572
1573 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1574
1575 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1576#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001577 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001578 pDSDumpDot((char*)"triTest2.dot");
1579#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001580
1581 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001582 cmdBuffer.Draw(0, 6, 0, 1);
1583
1584 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001585 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001586 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001587
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001588 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001589 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001590}
1591
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001592TEST_F(XglRenderTest, QuadSparseVertFetch)
1593{
1594 // This tests that attributes work in the presence of gl_VertexID
1595
1596 static const char *vertShaderText =
1597 "#version 140\n"
1598 "#extension GL_ARB_separate_shader_objects : enable\n"
1599 "#extension GL_ARB_shading_language_420pack : enable\n"
1600 //XYZ1( -1, -1, -1 )
1601 "layout (location = 1) in vec4 pos;\n"
1602 "layout (location = 4) in vec4 inColor;\n"
1603 //XYZ1( 0.f, 0.f, 0.f )
1604 "layout (location = 0) out vec4 outColor;\n"
1605 "void main() {\n"
1606 " outColor = inColor;\n"
1607 " gl_Position = pos;\n"
1608 "}\n";
1609
1610
1611 static const char *fragShaderText =
1612 "#version 140\n"
1613 "#extension GL_ARB_separate_shader_objects : enable\n"
1614 "#extension GL_ARB_shading_language_420pack : enable\n"
1615 "layout (location = 0) in vec4 color;\n"
1616 "void main() {\n"
1617 " gl_FragColor = color;\n"
1618 "}\n";
1619
1620 ASSERT_NO_FATAL_FAILURE(InitState());
1621 ASSERT_NO_FATAL_FAILURE(InitViewport());
1622
1623 struct VDATA
1624 {
1625 float t1, t2, t3, t4; // filler data
1626 float posX, posY, posZ, posW; // Position data
1627 float r, g, b, a; // Color
1628 };
1629 const struct VDATA vData[] =
1630 {
1631 { XYZ1(0, 0, 0), XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
1632 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1633 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1634 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1635 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1636 { XYZ1(0, 0, 0), XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
1637 };
1638
1639 XglConstantBufferObj meshBuffer(m_device,sizeof(vData)/sizeof(vData[0]),sizeof(vData[0]), vData);
1640 meshBuffer.BufferMemoryBarrier();
1641
1642 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1643 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1644
1645 XglPipelineObj pipelineobj(m_device);
1646 pipelineobj.AddShader(&vs);
1647 pipelineobj.AddShader(&ps);
1648
1649 XglDescriptorSetObj descriptorSet(m_device);
1650 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
1651
1652 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1653
1654#define MESH_BUF_ID 0
1655 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1656 MESH_BUF_ID, // Binding ID
1657 sizeof(vData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1658 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1659 };
1660
1661 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1662 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1663 vi_attribs[0].location = 4;
1664 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
1665 vi_attribs[0].offsetInBytes = sizeof(float) * 4 * 2; // Offset of first element in bytes from base of vertex
1666 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1667 vi_attribs[1].location = 1;
1668 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
1669 vi_attribs[1].offsetInBytes = sizeof(float) * 4 * 1; // Offset of first element in bytes from base of vertex
1670
1671 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
1672 pipelineobj.AddVertexInputBindings(&vi_binding, 1);
1673 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
1674
1675 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1676 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
1677 XglCommandBufferObj cmdBuffer(m_device);
1678 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1679
1680 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
1681
1682 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1683
1684 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BUF_ID);
1685#ifdef DUMP_STATE_DOT
1686 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
1687 pDSDumpDot((char*)"triTest2.dot");
1688#endif
1689
1690 // render two triangles
1691 cmdBuffer.Draw(0, 6, 0, 1);
1692
1693 // finalize recording of the command buffer
1694 EndCommandBuffer(cmdBuffer);
1695 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
1696
1697 for (int i = 0; i < m_renderTargets.size(); i++)
1698 RecordImage(m_renderTargets[i]);
1699}
1700
Tony Barbourf43b6982014-11-25 13:18:32 -07001701TEST_F(XglRenderTest, TriVertFetchDeadAttr)
1702{
1703 // This tests that attributes work in the presence of gl_VertexID
1704 // and a dead attribute in position 0. Draws a triangle with yellow,
1705 // red and green corners, starting at top and going clockwise.
1706
1707 static const char *vertShaderText =
1708 "#version 140\n"
1709 "#extension GL_ARB_separate_shader_objects : enable\n"
1710 "#extension GL_ARB_shading_language_420pack : enable\n"
1711 //XYZ1( -1, -1, -1 )
1712 "layout (location = 0) in vec4 pos;\n"
1713 //XYZ1( 0.f, 0.f, 0.f )
1714 "layout (location = 1) in vec4 inColor;\n"
1715 "layout (location = 0) out vec4 outColor;\n"
1716 "void main() {\n"
1717 " outColor = inColor;\n"
1718 " vec2 vertices[3];"
1719 " vertices[0] = vec2(-1.0, -1.0);\n"
1720 " vertices[1] = vec2( 1.0, -1.0);\n"
1721 " vertices[2] = vec2( 0.0, 1.0);\n"
1722 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1723 "}\n";
1724
1725
1726 static const char *fragShaderText =
1727 "#version 140\n"
1728 "#extension GL_ARB_separate_shader_objects : enable\n"
1729 "#extension GL_ARB_shading_language_420pack : enable\n"
1730 "layout (location = 0) in vec4 color;\n"
1731 "void main() {\n"
1732 " gl_FragColor = color;\n"
1733 "}\n";
1734
1735 ASSERT_NO_FATAL_FAILURE(InitState());
1736 ASSERT_NO_FATAL_FAILURE(InitViewport());
1737
1738 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001739 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001740
1741 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1742 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1743
1744 XglPipelineObj pipelineobj(m_device);
1745 pipelineobj.AddShader(&vs);
1746 pipelineobj.AddShader(&ps);
1747
1748 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001749 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001750
Mark Lobodzinski15427102015-02-18 16:38:17 -06001751 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1752
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001753#define MESH_BUF_ID 0
Tony Barbourf43b6982014-11-25 13:18:32 -07001754 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001755 MESH_BUF_ID, // Binding ID
1756 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1757 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001758 };
1759
1760 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001761 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1762 vi_attribs[0].location = 0;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001763 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001764 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1765 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1766 vi_attribs[1].location = 1;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001767 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001768 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001769
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001770 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001771 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001772 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001773
Tony Barbourdd4c9642015-01-09 12:55:14 -07001774 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001775 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001776 XglCommandBufferObj cmdBuffer(m_device);
1777 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001778
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001779 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001780
1781 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1782
1783 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1784#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001785 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001786 pDSDumpDot((char*)"triTest2.dot");
1787#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001788
1789 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001790 cmdBuffer.Draw(0, 6, 0, 1);
1791
1792 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001793 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001794 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001795
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001796 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001797 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001798}
1799
1800TEST_F(XglRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001801{
1802 static const char *vertShaderText =
1803 "#version 140\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001804 "#extension GL_ARB_separate_shader_objects : enable\n"
1805 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001806 "layout (std140) uniform bufferVals {\n"
1807 " mat4 mvp;\n"
1808 "} myBufferVals;\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001809 "layout (location = 0) in vec4 pos;\n"
1810 "layout (location = 1) in vec4 inColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001811 "out vec4 outColor;\n"
1812 "void main() {\n"
1813 " outColor = inColor;\n"
1814 " gl_Position = myBufferVals.mvp * pos;\n"
1815 "}\n";
1816
1817 static const char *fragShaderText =
1818 "#version 130\n"
1819 "in vec4 color;\n"
1820 "void main() {\n"
1821 " gl_FragColor = color;\n"
1822 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001823 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001824
Tony Barbourf43b6982014-11-25 13:18:32 -07001825 glm::mat4 View = glm::lookAt(
1826 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1827 glm::vec3(0,0,0), // and looks at the origin
1828 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
1829 );
1830
1831 glm::mat4 Model = glm::mat4(1.0f);
1832
1833 glm::mat4 MVP = Projection * View * Model;
1834
1835 ASSERT_NO_FATAL_FAILURE(InitState());
1836 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour17c6ab12015-03-27 17:03:18 -06001837 m_depthStencil->Init(m_device, m_width, m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07001838
1839 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
1840 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1841
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001842 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07001843
1844 XglConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1845 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1846 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1847
Tony Barbourf43b6982014-11-25 13:18:32 -07001848 XglPipelineObj pipelineobj(m_device);
1849 pipelineobj.AddShader(&vs);
1850 pipelineobj.AddShader(&ps);
1851
Tony Barbourfa6cac72015-01-16 14:27:35 -07001852 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
1853 ds_state.depthTestEnable = XGL_TRUE;
1854 ds_state.depthWriteEnable = XGL_TRUE;
1855 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
1856 ds_state.depthBoundsEnable = XGL_FALSE;
1857 ds_state.stencilTestEnable = XGL_FALSE;
1858 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
1859 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
1860 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
1861 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001862 ds_state.format = XGL_FMT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001863 ds_state.front = ds_state.back;
1864 pipelineobj.SetDepthStencil(&ds_state);
1865
Tony Barbourf43b6982014-11-25 13:18:32 -07001866 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001867 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001868
1869 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1870 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
Tony Barbour17c6ab12015-03-27 17:03:18 -06001871 m_memoryRefManager.AddMemoryRef(m_depthStencil);
Tony Barbourf43b6982014-11-25 13:18:32 -07001872
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001873#define MESH_BUF_ID 0
Tony Barbourf43b6982014-11-25 13:18:32 -07001874 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001875 MESH_BUF_ID, // Binding ID
1876 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1877 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1878 };
Tony Barbourf43b6982014-11-25 13:18:32 -07001879
Tony Barbourf43b6982014-11-25 13:18:32 -07001880 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001881 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1882 vi_attribs[0].location = 0;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001883 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001884 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1885 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1886 vi_attribs[1].location = 1;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001887 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001888 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001889
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001890 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001891 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001892 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001893
Tony Barbour17c6ab12015-03-27 17:03:18 -06001894 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001895 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbour17c6ab12015-03-27 17:03:18 -06001896
Tony Barboure4ed9942015-01-09 10:06:53 -07001897 XglCommandBufferObj cmdBuffer(m_device);
1898 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001899
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001900 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barboure4ed9942015-01-09 10:06:53 -07001901 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001902
Tony Barboure4ed9942015-01-09 10:06:53 -07001903 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1904#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001905 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barboure4ed9942015-01-09 10:06:53 -07001906 pDSDumpDot((char*)"triTest2.dot");
1907#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001908
1909 // render triangles
Tony Barboure4ed9942015-01-09 10:06:53 -07001910 cmdBuffer.Draw(0, 36, 0, 1);
1911
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001912
Tony Barboure4ed9942015-01-09 10:06:53 -07001913 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001914 EndCommandBuffer(cmdBuffer);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001915 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barboure4ed9942015-01-09 10:06:53 -07001916
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001917 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barboure4ed9942015-01-09 10:06:53 -07001918 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001919}
1920
Tony Barbourf43b6982014-11-25 13:18:32 -07001921TEST_F(XglRenderTest, VSTexture)
1922{
1923 // The expected result from this test is a green and red triangle;
1924 // one red vertex on the left, two green vertices on the right.
1925 static const char *vertShaderText =
1926 "#version 130\n"
1927 "out vec4 texColor;\n"
1928 "uniform sampler2D surface;\n"
1929 "void main() {\n"
1930 " vec2 vertices[3];"
1931 " vertices[0] = vec2(-0.5, -0.5);\n"
1932 " vertices[1] = vec2( 0.5, -0.5);\n"
1933 " vertices[2] = vec2( 0.5, 0.5);\n"
1934 " vec2 positions[3];"
1935 " positions[0] = vec2( 0.0, 0.0);\n"
1936 " positions[1] = vec2( 0.25, 0.1);\n"
1937 " positions[2] = vec2( 0.1, 0.25);\n"
1938 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1939 " texColor = textureLod(surface, samplePos, 0.0);\n"
1940 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1941 "}\n";
1942
1943 static const char *fragShaderText =
1944 "#version 130\n"
1945 "in vec4 texColor;\n"
1946 "void main() {\n"
1947 " gl_FragColor = texColor;\n"
1948 "}\n";
1949
1950 ASSERT_NO_FATAL_FAILURE(InitState());
1951 ASSERT_NO_FATAL_FAILURE(InitViewport());
1952
1953 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1954 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1955 XglSamplerObj sampler(m_device);
1956 XglTextureObj texture(m_device);
1957
Tony Barbourf43b6982014-11-25 13:18:32 -07001958 XglPipelineObj pipelineobj(m_device);
1959 pipelineobj.AddShader(&vs);
1960 pipelineobj.AddShader(&ps);
1961
1962 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001963 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001964
1965 m_memoryRefManager.AddMemoryRef(&texture);
1966
Tony Barbourdd4c9642015-01-09 12:55:14 -07001967 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001968 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001969 XglCommandBufferObj cmdBuffer(m_device);
1970 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001971
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001972 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001973
1974 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1975
1976#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001977 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001978 pDSDumpDot((char*)"triTest2.dot");
1979#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001980
Tony Barbourdd4c9642015-01-09 12:55:14 -07001981 // render triangle
1982 cmdBuffer.Draw(0, 3, 0, 1);
1983
1984 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001985 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001986 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001987
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001988 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001989 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001990}
1991TEST_F(XglRenderTest, TexturedTriangle)
1992{
1993 // The expected result from this test is a red and green checkered triangle
1994 static const char *vertShaderText =
1995 "#version 140\n"
1996 "#extension GL_ARB_separate_shader_objects : enable\n"
1997 "#extension GL_ARB_shading_language_420pack : enable\n"
1998 "layout (location = 0) out vec2 samplePos;\n"
1999 "void main() {\n"
2000 " vec2 vertices[3];"
2001 " vertices[0] = vec2(-0.5, -0.5);\n"
2002 " vertices[1] = vec2( 0.5, -0.5);\n"
2003 " vertices[2] = vec2( 0.5, 0.5);\n"
2004 " vec2 positions[3];"
2005 " positions[0] = vec2( 0.0, 0.0);\n"
2006 " positions[1] = vec2( 1.0, 0.0);\n"
2007 " positions[2] = vec2( 1.0, 1.0);\n"
2008 " samplePos = positions[gl_VertexID % 3];\n"
2009 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2010 "}\n";
2011
2012 static const char *fragShaderText =
2013 "#version 140\n"
2014 "#extension GL_ARB_separate_shader_objects : enable\n"
2015 "#extension GL_ARB_shading_language_420pack : enable\n"
2016 "layout (location = 0) in vec2 samplePos;\n"
2017 "layout (binding = 0) uniform sampler2D surface;\n"
2018 "layout (location=0) out vec4 outColor;\n"
2019 "void main() {\n"
2020 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2021 " outColor = texColor;\n"
2022 "}\n";
2023
2024 ASSERT_NO_FATAL_FAILURE(InitState());
2025 ASSERT_NO_FATAL_FAILURE(InitViewport());
2026
2027 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2028 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2029 XglSamplerObj sampler(m_device);
2030 XglTextureObj texture(m_device);
2031
Tony Barbourf43b6982014-11-25 13:18:32 -07002032 XglPipelineObj pipelineobj(m_device);
2033 pipelineobj.AddShader(&vs);
2034 pipelineobj.AddShader(&ps);
2035
2036 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002037 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002038
2039 m_memoryRefManager.AddMemoryRef(&texture);
2040
Tony Barbourdd4c9642015-01-09 12:55:14 -07002041 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002042 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002043 XglCommandBufferObj cmdBuffer(m_device);
2044 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2045
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002046 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002047
2048 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2049
2050#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002051 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002052 pDSDumpDot((char*)"triTest2.dot");
2053#endif
2054 // render triangle
2055 cmdBuffer.Draw(0, 3, 0, 1);
2056
2057 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002058 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002059 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002060
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002061 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002062 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002063}
2064TEST_F(XglRenderTest, TexturedTriangleClip)
2065{
2066 // The expected result from this test is a red and green checkered triangle
2067 static const char *vertShaderText =
2068 "#version 330\n"
2069 "#extension GL_ARB_separate_shader_objects : enable\n"
2070 "#extension GL_ARB_shading_language_420pack : enable\n"
2071 "layout (location = 0) out vec2 samplePos;\n"
2072 "out gl_PerVertex {\n"
2073 " vec4 gl_Position;\n"
2074 " float gl_ClipDistance[1];\n"
2075 "};\n"
2076 "void main() {\n"
2077 " vec2 vertices[3];"
2078 " vertices[0] = vec2(-0.5, -0.5);\n"
2079 " vertices[1] = vec2( 0.5, -0.5);\n"
2080 " vertices[2] = vec2( 0.5, 0.5);\n"
2081 " vec2 positions[3];"
2082 " positions[0] = vec2( 0.0, 0.0);\n"
2083 " positions[1] = vec2( 1.0, 0.0);\n"
2084 " positions[2] = vec2( 1.0, 1.0);\n"
2085 " float dists[3];\n"
2086 " dists[0] = 1.0;\n"
2087 " dists[1] = 1.0;\n"
2088 " dists[2] = -1.0;\n"
2089 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2090 " samplePos = positions[gl_VertexID % 3];\n"
2091 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2092 "}\n";
2093
2094 static const char *fragShaderText =
2095 "#version 140\n"
2096 "#extension GL_ARB_separate_shader_objects : enable\n"
2097 "#extension GL_ARB_shading_language_420pack : enable\n"
2098 "layout (location = 0) in vec2 samplePos;\n"
2099 "layout (binding = 0) uniform sampler2D surface;\n"
2100 "layout (location=0) out vec4 outColor;\n"
2101 "void main() {\n"
2102 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2103 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2104 " outColor = texColor;\n"
2105 "}\n";
2106
2107
2108 ASSERT_NO_FATAL_FAILURE(InitState());
2109 ASSERT_NO_FATAL_FAILURE(InitViewport());
2110
2111 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2112 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2113 XglSamplerObj sampler(m_device);
2114 XglTextureObj texture(m_device);
2115
Tony Barbourf43b6982014-11-25 13:18:32 -07002116 XglPipelineObj pipelineobj(m_device);
2117 pipelineobj.AddShader(&vs);
2118 pipelineobj.AddShader(&ps);
2119
2120 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002121 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002122
2123 m_memoryRefManager.AddMemoryRef(&texture);
2124
Tony Barbourdd4c9642015-01-09 12:55:14 -07002125 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002126 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002127 XglCommandBufferObj cmdBuffer(m_device);
2128 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2129
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002130 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002131
2132 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2133
2134#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002135 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002136 pDSDumpDot((char*)"triTest2.dot");
2137#endif
2138 // render triangle
2139 cmdBuffer.Draw(0, 3, 0, 1);
2140
2141 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002142 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002143 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002144
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002145 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002146 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002147}
2148TEST_F(XglRenderTest, FSTriangle)
2149{
2150 // The expected result from this test is a red and green checkered triangle
2151 static const char *vertShaderText =
2152 "#version 140\n"
2153 "#extension GL_ARB_separate_shader_objects : enable\n"
2154 "#extension GL_ARB_shading_language_420pack : enable\n"
2155 "layout (location = 0) out vec2 samplePos;\n"
2156 "void main() {\n"
2157 " vec2 vertices[3];"
2158 " vertices[0] = vec2(-0.5, -0.5);\n"
2159 " vertices[1] = vec2( 0.5, -0.5);\n"
2160 " vertices[2] = vec2( 0.5, 0.5);\n"
2161 " vec2 positions[3];"
2162 " positions[0] = vec2( 0.0, 0.0);\n"
2163 " positions[1] = vec2( 1.0, 0.0);\n"
2164 " positions[2] = vec2( 1.0, 1.0);\n"
2165 " samplePos = positions[gl_VertexID % 3];\n"
2166 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2167 "}\n";
2168
2169 static const char *fragShaderText =
2170 "#version 140\n"
2171 "#extension GL_ARB_separate_shader_objects : enable\n"
2172 "#extension GL_ARB_shading_language_420pack : enable\n"
2173 "layout (location = 0) in vec2 samplePos;\n"
2174 "layout (binding = 0) uniform sampler2D surface;\n"
2175 "layout (location=0) out vec4 outColor;\n"
2176 "void main() {\n"
2177 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2178 " outColor = texColor;\n"
2179 "}\n";
2180
2181 ASSERT_NO_FATAL_FAILURE(InitState());
2182 ASSERT_NO_FATAL_FAILURE(InitViewport());
2183
2184 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2185 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2186 XglSamplerObj sampler(m_device);
2187 XglTextureObj texture(m_device);
2188
Tony Barbourf43b6982014-11-25 13:18:32 -07002189 XglPipelineObj pipelineobj(m_device);
2190 pipelineobj.AddShader(&vs);
2191 pipelineobj.AddShader(&ps);
2192
2193 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002194 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002195
2196 m_memoryRefManager.AddMemoryRef(&texture);
2197
Tony Barbourdd4c9642015-01-09 12:55:14 -07002198 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002199 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002200 XglCommandBufferObj cmdBuffer(m_device);
2201 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2202
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002203 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002204
2205 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2206
2207#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002208 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002209 pDSDumpDot((char*)"triTest2.dot");
2210#endif
2211 // render triangle
2212 cmdBuffer.Draw(0, 3, 0, 1);
2213
2214 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002215 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002216 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002217
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002218 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002219 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002220}
2221TEST_F(XglRenderTest, SamplerBindingsTriangle)
2222{
2223 // This test sets bindings on the samplers
2224 // For now we are asserting that sampler and texture pairs
2225 // march in lock step, and are set via GLSL binding. This can
2226 // and will probably change.
2227 // The sampler bindings should match the sampler and texture slot
2228 // number set up by the application.
2229 // This test will result in a blue triangle
2230 static const char *vertShaderText =
2231 "#version 140\n"
2232 "#extension GL_ARB_separate_shader_objects : enable\n"
2233 "#extension GL_ARB_shading_language_420pack : enable\n"
2234 "layout (location = 0) out vec4 samplePos;\n"
2235 "void main() {\n"
2236 " vec2 vertices[3];"
2237 " vertices[0] = vec2(-0.5, -0.5);\n"
2238 " vertices[1] = vec2( 0.5, -0.5);\n"
2239 " vertices[2] = vec2( 0.5, 0.5);\n"
2240 " vec2 positions[3];"
2241 " positions[0] = vec2( 0.0, 0.0);\n"
2242 " positions[1] = vec2( 1.0, 0.0);\n"
2243 " positions[2] = vec2( 1.0, 1.0);\n"
2244 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2245 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2246 "}\n";
2247
2248 static const char *fragShaderText =
2249 "#version 140\n"
2250 "#extension GL_ARB_separate_shader_objects : enable\n"
2251 "#extension GL_ARB_shading_language_420pack : enable\n"
2252 "layout (location = 0) in vec4 samplePos;\n"
2253 "layout (binding = 0) uniform sampler2D surface0;\n"
2254 "layout (binding = 1) uniform sampler2D surface1;\n"
2255 "layout (binding = 12) uniform sampler2D surface2;\n"
2256 "void main() {\n"
2257 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
2258 "}\n";
2259
2260 ASSERT_NO_FATAL_FAILURE(InitState());
2261 ASSERT_NO_FATAL_FAILURE(InitViewport());
2262
2263 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2264 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2265
2266 XglSamplerObj sampler1(m_device);
2267 XglSamplerObj sampler2(m_device);
2268 XglSamplerObj sampler3(m_device);
2269
Tony Barbour2f421a02015-04-01 16:38:10 -06002270 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
2271 XglTextureObj texture1(m_device, tex_colors); // Red
2272 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
2273 XglTextureObj texture2(m_device, tex_colors); // Green
2274 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
2275 XglTextureObj texture3(m_device, tex_colors); // Blue
Tony Barbourf43b6982014-11-25 13:18:32 -07002276
Tony Barbourf43b6982014-11-25 13:18:32 -07002277 XglPipelineObj pipelineobj(m_device);
2278 pipelineobj.AddShader(&vs);
2279 pipelineobj.AddShader(&ps);
2280
2281 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002282 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2283 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2284 for (int i = 0; i < 10; i++)
2285 descriptorSet.AppendDummy();
2286 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002287
2288 m_memoryRefManager.AddMemoryRef(&texture1);
2289 m_memoryRefManager.AddMemoryRef(&texture2);
2290 m_memoryRefManager.AddMemoryRef(&texture3);
2291
Tony Barbourdd4c9642015-01-09 12:55:14 -07002292 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002293 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002294 XglCommandBufferObj cmdBuffer(m_device);
2295 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2296
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002297 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002298
2299 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2300
2301#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002302 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002303 pDSDumpDot((char*)"triTest2.dot");
2304#endif
2305 // render triangle
2306 cmdBuffer.Draw(0, 3, 0, 1);
2307
2308 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002309 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002310 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002311
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002312 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002313 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002314
2315}
2316
2317TEST_F(XglRenderTest, TriangleVSUniformBlock)
2318{
2319 // The expected result from this test is a blue triangle
2320
2321 static const char *vertShaderText =
2322 "#version 140\n"
2323 "#extension GL_ARB_separate_shader_objects : enable\n"
2324 "#extension GL_ARB_shading_language_420pack : enable\n"
2325 "layout (location = 0) out vec4 outColor;\n"
2326 "layout (std140, binding = 0) uniform bufferVals {\n"
2327 " vec4 red;\n"
2328 " vec4 green;\n"
2329 " vec4 blue;\n"
2330 " vec4 white;\n"
2331 "} myBufferVals;\n"
2332 "void main() {\n"
2333 " vec2 vertices[3];"
2334 " vertices[0] = vec2(-0.5, -0.5);\n"
2335 " vertices[1] = vec2( 0.5, -0.5);\n"
2336 " vertices[2] = vec2( 0.5, 0.5);\n"
2337 " outColor = myBufferVals.blue;\n"
2338 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2339 "}\n";
2340
2341 static const char *fragShaderText =
2342 "#version 140\n"
2343 "#extension GL_ARB_separate_shader_objects : enable\n"
2344 "#extension GL_ARB_shading_language_420pack : enable\n"
2345 "layout (location = 0) in vec4 inColor;\n"
2346 "void main() {\n"
2347 " gl_FragColor = inColor;\n"
2348 "}\n";
2349
2350 ASSERT_NO_FATAL_FAILURE(InitState());
2351 ASSERT_NO_FATAL_FAILURE(InitViewport());
2352
2353 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2354 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2355
2356 // Let's populate our buffer with the following:
2357 // vec4 red;
2358 // vec4 green;
2359 // vec4 blue;
2360 // vec4 white;
2361 const int valCount = 4 * 4;
2362 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2363 0.0, 1.0, 0.0, 1.0,
2364 0.0, 0.0, 1.0, 1.0,
2365 1.0, 1.0, 1.0, 1.0 };
2366
2367 XglConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002368
2369 XglPipelineObj pipelineobj(m_device);
2370 pipelineobj.AddShader(&vs);
2371 pipelineobj.AddShader(&ps);
2372
2373 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002374 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002375
Tony Barbourdd4c9642015-01-09 12:55:14 -07002376 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002377 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002378 XglCommandBufferObj cmdBuffer(m_device);
2379 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2380
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002381 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002382
2383 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2384
2385#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002386 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002387 pDSDumpDot((char*)"triTest2.dot");
2388#endif
2389 // render triangle
2390 cmdBuffer.Draw(0, 3, 0, 1);
2391
2392 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002393 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002394 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002395
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002396 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002397 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002398
2399}
2400
2401TEST_F(XglRenderTest, TriangleFSUniformBlockBinding)
2402{
2403 // This test allows the shader to select which buffer it is
2404 // pulling from using layout binding qualifier.
2405 // There are corresponding changes in the compiler stack that
2406 // will select the buffer using binding directly.
2407 // The binding number should match the slot number set up by
2408 // the application.
2409 // The expected result from this test is a purple triangle
2410
2411 static const char *vertShaderText =
2412 "#version 140\n"
2413 "#extension GL_ARB_separate_shader_objects : enable\n"
2414 "#extension GL_ARB_shading_language_420pack : enable\n"
2415 "void main() {\n"
2416 " vec2 vertices[3];"
2417 " vertices[0] = vec2(-0.5, -0.5);\n"
2418 " vertices[1] = vec2( 0.5, -0.5);\n"
2419 " vertices[2] = vec2( 0.5, 0.5);\n"
2420 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2421 "}\n";
2422
2423 static const char *fragShaderText =
2424 "#version 140\n"
2425 "#extension GL_ARB_separate_shader_objects : enable\n"
2426 "#extension GL_ARB_shading_language_420pack : enable\n"
2427 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2428 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2429 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002430 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
Tony Barbourf43b6982014-11-25 13:18:32 -07002431 "void main() {\n"
2432 " gl_FragColor = myBlueVal.color;\n"
2433 " gl_FragColor += myRedVal.color;\n"
2434 "}\n";
2435
2436 ASSERT_NO_FATAL_FAILURE(InitState());
2437 ASSERT_NO_FATAL_FAILURE(InitViewport());
2438
2439 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2440 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2441
2442 // We're going to create a number of uniform buffers, and then allow
2443 // the shader to select which it wants to read from with a binding
2444
2445 // Let's populate the buffers with a single color each:
2446 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2447 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2448 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002449 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002450
2451 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2452 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2453 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2454 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2455
2456 const int redCount = sizeof(redVals) / sizeof(float);
2457 const int greenCount = sizeof(greenVals) / sizeof(float);
2458 const int blueCount = sizeof(blueVals) / sizeof(float);
2459 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2460
2461 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002462
2463 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002464
2465 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002466
2467 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002468
2469 XglPipelineObj pipelineobj(m_device);
2470 pipelineobj.AddShader(&vs);
2471 pipelineobj.AddShader(&ps);
2472
2473 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002474 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2475 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2476 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2477 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002478
Tony Barbourdd4c9642015-01-09 12:55:14 -07002479 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002480 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002481 XglCommandBufferObj cmdBuffer(m_device);
2482 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002483
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002484 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002485
2486 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2487
2488#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002489 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002490 pDSDumpDot((char*)"triTest2.dot");
2491#endif
2492 // render triangle
2493 cmdBuffer.Draw(0, 3, 0, 1);
2494
2495 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002496 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002497 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002498
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002499 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002500 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002501}
2502
2503TEST_F(XglRenderTest, TriangleFSAnonymousUniformBlockBinding)
2504{
2505 // This test is the same as TriangleFSUniformBlockBinding, but
2506 // it does not provide an instance name.
2507 // The expected result from this test is a purple triangle
2508
2509 static const char *vertShaderText =
2510 "#version 140\n"
2511 "#extension GL_ARB_separate_shader_objects : enable\n"
2512 "#extension GL_ARB_shading_language_420pack : enable\n"
2513 "void main() {\n"
2514 " vec2 vertices[3];"
2515 " vertices[0] = vec2(-0.5, -0.5);\n"
2516 " vertices[1] = vec2( 0.5, -0.5);\n"
2517 " vertices[2] = vec2( 0.5, 0.5);\n"
2518 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2519 "}\n";
2520
2521 static const char *fragShaderText =
2522 "#version 430\n"
2523 "#extension GL_ARB_separate_shader_objects : enable\n"
2524 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002525 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2526 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2527 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002528 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002529 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002530 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002531 " outColor = blue;\n"
2532 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002533 "}\n";
2534 ASSERT_NO_FATAL_FAILURE(InitState());
2535 ASSERT_NO_FATAL_FAILURE(InitViewport());
2536
2537 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2538 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2539
2540 // We're going to create a number of uniform buffers, and then allow
2541 // the shader to select which it wants to read from with a binding
2542
2543 // Let's populate the buffers with a single color each:
2544 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2545 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2546 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2547 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2548
2549 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2550 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2551 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2552 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2553
2554 const int redCount = sizeof(redVals) / sizeof(float);
2555 const int greenCount = sizeof(greenVals) / sizeof(float);
2556 const int blueCount = sizeof(blueVals) / sizeof(float);
2557 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2558
2559 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002560
2561 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002562
2563 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002564
2565 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002566
2567 XglPipelineObj pipelineobj(m_device);
2568 pipelineobj.AddShader(&vs);
2569 pipelineobj.AddShader(&ps);
2570
2571 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002572 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2573 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2574 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2575 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002576
Tony Barbourdd4c9642015-01-09 12:55:14 -07002577 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002578 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002579 XglCommandBufferObj cmdBuffer(m_device);
2580 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2581
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002582 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002583
2584 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2585
2586#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002587 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002588 pDSDumpDot((char*)"triTest2.dot");
2589#endif
2590 // render triangle
2591 cmdBuffer.Draw(0, 3, 0, 1);
2592
2593 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002594 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002595 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002596
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002597 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002598 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002599
2600}
2601
2602TEST_F(XglRenderTest, CubeWithVertexFetchAndMVPAndTexture)
2603{
2604 static const char *vertShaderText =
2605 "#version 140\n"
2606 "#extension GL_ARB_separate_shader_objects : enable\n"
2607 "#extension GL_ARB_shading_language_420pack : enable\n"
2608 "layout (std140, binding=0) uniform bufferVals {\n"
2609 " mat4 mvp;\n"
2610 "} myBufferVals;\n"
2611 "layout (location=0) in vec4 pos;\n"
2612 "layout (location=0) out vec2 UV;\n"
2613 "void main() {\n"
2614 " vec2 positions[3];"
2615 " positions[0] = vec2( 0.0, 0.0);\n"
2616 " positions[1] = vec2( 0.25, 0.1);\n"
2617 " positions[2] = vec2( 0.1, 0.25);\n"
2618 " UV = positions[gl_VertexID % 3];\n"
2619 " gl_Position = myBufferVals.mvp * pos;\n"
2620 "}\n";
2621
2622 static const char *fragShaderText =
2623 "#version 140\n"
2624 "#extension GL_ARB_separate_shader_objects : enable\n"
2625 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002626 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002627 "layout (location=0) out vec4 outColor;\n"
2628 "layout (location=0) in vec2 UV;\n"
2629 "void main() {\n"
2630 " outColor= textureLod(surface, UV, 0.0);\n"
2631 "}\n";
2632 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2633
2634 glm::mat4 View = glm::lookAt(
2635 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2636 glm::vec3(0,0,0), // and looks at the origin
2637 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2638 );
2639
2640 glm::mat4 Model = glm::mat4(1.0f);
2641
2642 glm::mat4 MVP = Projection * View * Model;
2643
2644
2645 ASSERT_NO_FATAL_FAILURE(InitState());
2646 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour17c6ab12015-03-27 17:03:18 -06002647 m_depthStencil->Init(m_device, m_width, m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07002648
2649 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
2650 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002651 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002652
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002653 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07002654
2655 XglConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2656 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2657 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2658 XglSamplerObj sampler(m_device);
2659 XglTextureObj texture(m_device);
2660
Tony Barbourf43b6982014-11-25 13:18:32 -07002661 XglPipelineObj pipelineobj(m_device);
2662 pipelineobj.AddShader(&vs);
2663 pipelineobj.AddShader(&ps);
2664
2665 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06002666 // descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer); // TODO: Why does this break images??
Chia-I Wuf8385062015-01-04 16:27:24 +08002667 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mvpBuffer);
2668 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002669
2670 m_memoryRefManager.AddMemoryRef(&meshBuffer);
2671 m_memoryRefManager.AddMemoryRef(&mvpBuffer);
2672 m_memoryRefManager.AddMemoryRef(&texture);
Tony Barbour17c6ab12015-03-27 17:03:18 -06002673 m_memoryRefManager.AddMemoryRef(m_depthStencil);
Tony Barbourf43b6982014-11-25 13:18:32 -07002674
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002675#define MESH_BIND_ID 0
Tony Barbourf43b6982014-11-25 13:18:32 -07002676 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002677 MESH_BIND_ID, // binding ID
2678 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
2679 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
2680 };
Tony Barbourf43b6982014-11-25 13:18:32 -07002681
Tony Barbourf43b6982014-11-25 13:18:32 -07002682 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002683 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2684 vi_attribs[0].location = 0; // location
2685 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
2686 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2687 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2688 vi_attribs[1].location = 1; // location
2689 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
2690 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07002691
Tony Barbourf43b6982014-11-25 13:18:32 -07002692 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002693 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2694 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07002695
Tony Barbourfa6cac72015-01-16 14:27:35 -07002696 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
2697 ds_state.depthTestEnable = XGL_TRUE;
2698 ds_state.depthWriteEnable = XGL_TRUE;
2699 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
2700 ds_state.depthBoundsEnable = XGL_FALSE;
2701 ds_state.stencilTestEnable = XGL_FALSE;
2702 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
2703 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
2704 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
2705 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07002706 ds_state.format = XGL_FMT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002707 ds_state.front = ds_state.back;
2708 pipelineobj.SetDepthStencil(&ds_state);
2709
Tony Barbour17c6ab12015-03-27 17:03:18 -06002710 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002711 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002712 XglCommandBufferObj cmdBuffer(m_device);
2713 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002714
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002715 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
2716
Tony Barbourdd4c9642015-01-09 12:55:14 -07002717 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2718
2719 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2720#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002721 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002722 pDSDumpDot((char*)"triTest2.dot");
2723#endif
2724 // render triangle
2725 cmdBuffer.Draw(0, 36, 0, 1);
2726
2727 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002728 EndCommandBuffer(cmdBuffer);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002729 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
2730
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002731 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002732 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002733
2734}
Cody Northropd1ce7842014-12-09 11:17:01 -07002735
2736TEST_F(XglRenderTest, TriangleMixedSamplerUniformBlockBinding)
2737{
2738 // This test mixes binding slots of textures and buffers, ensuring
2739 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002740 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002741 // you can modify it to move the desired result around.
2742
2743 static const char *vertShaderText =
2744 "#version 140\n"
2745 "#extension GL_ARB_separate_shader_objects : enable\n"
2746 "#extension GL_ARB_shading_language_420pack : enable\n"
2747 "void main() {\n"
2748 " vec2 vertices[3];"
2749 " vertices[0] = vec2(-0.5, -0.5);\n"
2750 " vertices[1] = vec2( 0.5, -0.5);\n"
2751 " vertices[2] = vec2( 0.5, 0.5);\n"
2752 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2753 "}\n";
2754
2755 static const char *fragShaderText =
2756 "#version 430\n"
2757 "#extension GL_ARB_separate_shader_objects : enable\n"
2758 "#extension GL_ARB_shading_language_420pack : enable\n"
2759 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002760 "layout (binding = 3) uniform sampler2D surface1;\n"
2761 "layout (binding = 1) uniform sampler2D surface2;\n"
2762 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002763
Cody Northropa0410942014-12-09 13:59:39 -07002764
Chia-I Wuf8385062015-01-04 16:27:24 +08002765 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2766 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2767 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2768 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002769 "layout (location = 0) out vec4 outColor;\n"
2770 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002771 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002772 " outColor += white * vec4(0.00001);\n"
2773 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002774 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002775 "}\n";
2776 ASSERT_NO_FATAL_FAILURE(InitState());
2777 ASSERT_NO_FATAL_FAILURE(InitViewport());
2778
2779 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2780 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2781
Cody Northropd1ce7842014-12-09 11:17:01 -07002782 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2783 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2784 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2785 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2786
2787 const int redCount = sizeof(redVals) / sizeof(float);
2788 const int greenCount = sizeof(greenVals) / sizeof(float);
2789 const int blueCount = sizeof(blueVals) / sizeof(float);
2790 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2791
2792 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002793 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002794 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002795 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002796
Tony Barbour2f421a02015-04-01 16:38:10 -06002797 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Cody Northropd1ce7842014-12-09 11:17:01 -07002798 XglSamplerObj sampler0(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002799 XglTextureObj texture0(m_device, tex_colors); // Light Red
2800 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Cody Northropd1ce7842014-12-09 11:17:01 -07002801 XglSamplerObj sampler2(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002802 XglTextureObj texture2(m_device, tex_colors); // Light Blue
2803 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Cody Northropd1ce7842014-12-09 11:17:01 -07002804 XglSamplerObj sampler4(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002805 XglTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropa0410942014-12-09 13:59:39 -07002806
2807 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2808 // TODO: Get back here ASAP and understand why.
Tony Barbour2f421a02015-04-01 16:38:10 -06002809 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Cody Northropa0410942014-12-09 13:59:39 -07002810 XglSamplerObj sampler7(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002811 XglTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropd1ce7842014-12-09 11:17:01 -07002812
2813 XglPipelineObj pipelineobj(m_device);
2814 pipelineobj.AddShader(&vs);
2815 pipelineobj.AddShader(&ps);
2816
2817 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002818 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2819 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2820 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2821 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2822 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2823 // swap blue and green
2824 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2825 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2826 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002827
2828 m_memoryRefManager.AddMemoryRef(&texture0);
2829 m_memoryRefManager.AddMemoryRef(&texture2);
2830 m_memoryRefManager.AddMemoryRef(&texture4);
Cody Northropa0410942014-12-09 13:59:39 -07002831 m_memoryRefManager.AddMemoryRef(&texture7);
Cody Northropd1ce7842014-12-09 11:17:01 -07002832
Tony Barbourdd4c9642015-01-09 12:55:14 -07002833 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002834 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002835 XglCommandBufferObj cmdBuffer(m_device);
2836 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002837
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002838 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002839
2840 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2841
2842#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002843 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002844 pDSDumpDot((char*)"triTest2.dot");
2845#endif
2846 // render triangle
2847 cmdBuffer.Draw(0, 3, 0, 1);
2848
2849 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002850 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002851 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002852
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002853 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002854 RecordImage(m_renderTargets[i]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002855
2856}
2857
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002858TEST_F(XglRenderTest, TriangleMatchingSamplerUniformBlockBinding)
2859{
2860 // This test matches binding slots of textures and buffers, requiring
2861 // the driver to give them distinct number spaces.
2862 // The expected result from this test is a red triangle, although
2863 // you can modify it to move the desired result around.
2864
2865 static const char *vertShaderText =
2866 "#version 140\n"
2867 "#extension GL_ARB_separate_shader_objects : enable\n"
2868 "#extension GL_ARB_shading_language_420pack : enable\n"
2869 "void main() {\n"
2870 " vec2 vertices[3];"
2871 " vertices[0] = vec2(-0.5, -0.5);\n"
2872 " vertices[1] = vec2( 0.5, -0.5);\n"
2873 " vertices[2] = vec2( 0.5, 0.5);\n"
2874 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2875 "}\n";
2876
2877 static const char *fragShaderText =
2878 "#version 430\n"
2879 "#extension GL_ARB_separate_shader_objects : enable\n"
2880 "#extension GL_ARB_shading_language_420pack : enable\n"
2881 "layout (binding = 0) uniform sampler2D surface0;\n"
2882 "layout (binding = 1) uniform sampler2D surface1;\n"
2883 "layout (binding = 2) uniform sampler2D surface2;\n"
2884 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002885 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2886 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2887 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2888 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002889 "layout (location = 0) out vec4 outColor;\n"
2890 "void main() {\n"
2891 " outColor = red;// * vec4(0.00001);\n"
2892 " outColor += white * vec4(0.00001);\n"
2893 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2894 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2895 "}\n";
2896 ASSERT_NO_FATAL_FAILURE(InitState());
2897 ASSERT_NO_FATAL_FAILURE(InitViewport());
2898
2899 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2900 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2901
2902 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2903 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2904 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2905 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2906
2907 const int redCount = sizeof(redVals) / sizeof(float);
2908 const int greenCount = sizeof(greenVals) / sizeof(float);
2909 const int blueCount = sizeof(blueVals) / sizeof(float);
2910 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2911
2912 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002913 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002914 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002915 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002916
Tony Barbour2f421a02015-04-01 16:38:10 -06002917 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002918 XglSamplerObj sampler0(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002919 XglTextureObj texture0(m_device, tex_colors); // Light Red
2920 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002921 XglSamplerObj sampler2(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002922 XglTextureObj texture2(m_device, tex_colors); // Light Blue
2923 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002924 XglSamplerObj sampler4(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002925 XglTextureObj texture4(m_device, tex_colors); // Light Green
2926 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002927 XglSamplerObj sampler7(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002928 XglTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002929
2930 XglPipelineObj pipelineobj(m_device);
2931 pipelineobj.AddShader(&vs);
2932 pipelineobj.AddShader(&ps);
2933
2934 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002935 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2936 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2937 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2938 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2939 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2940 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2941 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2942 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002943
2944 m_memoryRefManager.AddMemoryRef(&texture0);
2945 m_memoryRefManager.AddMemoryRef(&texture2);
2946 m_memoryRefManager.AddMemoryRef(&texture4);
2947 m_memoryRefManager.AddMemoryRef(&texture7);
2948
Tony Barbourdd4c9642015-01-09 12:55:14 -07002949 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002950 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002951 XglCommandBufferObj cmdBuffer(m_device);
2952 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002953
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002954 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002955
2956 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2957
2958#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002959 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002960 pDSDumpDot((char*)"triTest2.dot");
2961#endif
2962 // render triangle
2963 cmdBuffer.Draw(0, 3, 0, 1);
2964
2965 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002966 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002967 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002968
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002969 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002970 RecordImage(m_renderTargets[i]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002971
2972}
2973
Cody Northrop02690bd2014-12-17 15:26:33 -07002974TEST_F(XglRenderTest, TriangleUniformBufferLayout)
2975{
2976 // This test populates a buffer with a variety of different data
2977 // types, then reads them out with a shader.
2978 // The expected result from this test is a green triangle
2979
2980 static const char *vertShaderText =
2981 "#version 140\n"
2982 "#extension GL_ARB_separate_shader_objects : enable\n"
2983 "#extension GL_ARB_shading_language_420pack : enable\n"
2984 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2985 " vec4 fRed;\n"
2986 " vec4 fGreen;\n"
2987 " layout(row_major) mat4 worldToProj;\n"
2988 " layout(row_major) mat4 projToWorld;\n"
2989 " layout(row_major) mat4 worldToView;\n"
2990 " layout(row_major) mat4 viewToProj;\n"
2991 " layout(row_major) mat4 worldToShadow[4];\n"
2992 " float fZero;\n"
2993 " float fOne;\n"
2994 " float fTwo;\n"
2995 " float fThree;\n"
2996 " vec3 fZeroZeroZero;\n"
2997 " float fFour;\n"
2998 " vec3 fZeroZeroOne;\n"
2999 " float fFive;\n"
3000 " vec3 fZeroOneZero;\n"
3001 " float fSix;\n"
3002 " float fSeven;\n"
3003 " float fEight;\n"
3004 " float fNine;\n"
3005 " vec2 fZeroZero;\n"
3006 " vec2 fZeroOne;\n"
3007 " vec4 fBlue;\n"
3008 " vec2 fOneZero;\n"
3009 " vec2 fOneOne;\n"
3010 " vec3 fZeroOneOne;\n"
3011 " float fTen;\n"
3012 " float fEleven;\n"
3013 " float fTwelve;\n"
3014 " vec3 fOneZeroZero;\n"
3015 " vec4 uvOffsets[4];\n"
3016 "};\n"
3017 "layout (location = 0) out vec4 color;"
3018 "void main() {\n"
3019
3020 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3021 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3022 " \n"
3023
3024 // do some exact comparisons, even though we should
3025 // really have an epsilon involved.
3026 " vec4 outColor = right;\n"
3027 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3028 " outColor = wrong;\n"
3029 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3030 " outColor = wrong;\n"
3031 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
3032 " outColor = wrong;\n"
3033
3034 " color = outColor;\n"
3035
3036 // generic position stuff
3037 " vec2 vertices;\n"
3038 " int vertexSelector = gl_VertexID;\n"
3039 " if (vertexSelector == 0)\n"
3040 " vertices = vec2(-0.5, -0.5);\n"
3041 " else if (vertexSelector == 1)\n"
3042 " vertices = vec2( 0.5, -0.5);\n"
3043 " else if (vertexSelector == 2)\n"
3044 " vertices = vec2( 0.5, 0.5);\n"
3045 " else\n"
3046 " vertices = vec2( 0.0, 0.0);\n"
3047 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3048 "}\n";
3049
3050 static const char *fragShaderText =
3051 "#version 140\n"
3052 "#extension GL_ARB_separate_shader_objects : enable\n"
3053 "#extension GL_ARB_shading_language_420pack : enable\n"
3054 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3055 " vec4 fRed;\n"
3056 " vec4 fGreen;\n"
3057 " layout(row_major) mat4 worldToProj;\n"
3058 " layout(row_major) mat4 projToWorld;\n"
3059 " layout(row_major) mat4 worldToView;\n"
3060 " layout(row_major) mat4 viewToProj;\n"
3061 " layout(row_major) mat4 worldToShadow[4];\n"
3062 " float fZero;\n"
3063 " float fOne;\n"
3064 " float fTwo;\n"
3065 " float fThree;\n"
3066 " vec3 fZeroZeroZero;\n"
3067 " float fFour;\n"
3068 " vec3 fZeroZeroOne;\n"
3069 " float fFive;\n"
3070 " vec3 fZeroOneZero;\n"
3071 " float fSix;\n"
3072 " float fSeven;\n"
3073 " float fEight;\n"
3074 " float fNine;\n"
3075 " vec2 fZeroZero;\n"
3076 " vec2 fZeroOne;\n"
3077 " vec4 fBlue;\n"
3078 " vec2 fOneZero;\n"
3079 " vec2 fOneOne;\n"
3080 " vec3 fZeroOneOne;\n"
3081 " float fTen;\n"
3082 " float fEleven;\n"
3083 " float fTwelve;\n"
3084 " vec3 fOneZeroZero;\n"
3085 " vec4 uvOffsets[4];\n"
3086 "};\n"
3087 "layout (location = 0) in vec4 color;\n"
3088 "void main() {\n"
3089 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3090 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3091 " \n"
3092
3093 // start with VS value to ensure it passed
3094 " vec4 outColor = color;\n"
3095
3096 // do some exact comparisons, even though we should
3097 // really have an epsilon involved.
3098 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3099 " outColor = wrong;\n"
3100 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3101 " outColor = wrong;\n"
3102 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3103 " outColor = wrong;\n"
3104 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3105 " outColor = wrong;\n"
3106 " if (fTwo != 2.0)\n"
3107 " outColor = wrong;\n"
3108 " if (fOneOne != vec2(1.0, 1.0))\n"
3109 " outColor = wrong;\n"
3110 " if (fTen != 10.0)\n"
3111 " outColor = wrong;\n"
3112 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3113 " outColor = wrong;\n"
3114 " \n"
3115 " gl_FragColor = outColor;\n"
3116 "}\n";
3117
3118
3119 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3120 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3121 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3122 0.0, 1.0, 0.0, 1.0, // align
3123 0.0, 0.0, 1.0, 1.0, // align
3124 0.0, 0.0, 0.0, 1.0, // align
3125 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3126 0.0, 2.0, 0.0, 2.0, // align
3127 0.0, 0.0, 2.0, 2.0, // align
3128 0.0, 0.0, 0.0, 2.0, // align
3129 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3130 0.0, 3.0, 0.0, 3.0, // align
3131 0.0, 0.0, 3.0, 3.0, // align
3132 0.0, 0.0, 0.0, 3.0, // align
3133 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3134 0.0, 4.0, 0.0, 4.0, // align
3135 0.0, 0.0, 4.0, 4.0, // align
3136 0.0, 0.0, 0.0, 4.0, // align
3137 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3138 0.0, 5.0, 0.0, 5.0, // align
3139 0.0, 0.0, 5.0, 5.0, // align
3140 0.0, 0.0, 0.0, 5.0, // align
3141 6.0, 0.0, 0.0, 6.0, // align
3142 0.0, 6.0, 0.0, 6.0, // align
3143 0.0, 0.0, 6.0, 6.0, // align
3144 0.0, 0.0, 0.0, 6.0, // align
3145 7.0, 0.0, 0.0, 7.0, // align
3146 0.0, 7.0, 0.0, 7.0, // align
3147 0.0, 0.0, 7.0, 7.0, // align
3148 0.0, 0.0, 0.0, 7.0, // align
3149 8.0, 0.0, 0.0, 8.0, // align
3150 0.0, 8.0, 0.0, 8.0, // align
3151 0.0, 0.0, 8.0, 8.0, // align
3152 0.0, 0.0, 0.0, 8.0, // align
3153 0.0, // float fZero; // align
3154 1.0, // float fOne; // pack
3155 2.0, // float fTwo; // pack
3156 3.0, // float fThree; // pack
3157 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3158 4.0, // float fFour; // pack
3159 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3160 5.0, // float fFive; // pack
3161 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3162 6.0, // float fSix; // pack
3163 7.0, // float fSeven; // align
3164 8.0, // float fEight; // pack
3165 9.0, // float fNine; // pack
3166 0.0, // BUFFER
3167 0.0, 0.0, // vec2 fZeroZero; // align
3168 0.0, 1.0, // vec2 fZeroOne; // pack
3169 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3170 1.0, 0.0, // vec2 fOneZero; // align
3171 1.0, 1.0, // vec2 fOneOne; // pack
3172 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3173 10.0, // float fTen; // pack
3174 11.0, // float fEleven; // align
3175 12.0, // float fTwelve; // pack
3176 0.0, 0.0, // BUFFER
3177 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3178 0.0, // BUFFER
3179 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3180 0.5, 0.6, 0.7, 0.8, // align
3181 0.9, 1.0, 1.1, 1.2, // align
3182 1.3, 1.4, 1.5, 1.6, // align
3183 };
3184
3185 ASSERT_NO_FATAL_FAILURE(InitState());
3186 ASSERT_NO_FATAL_FAILURE(InitViewport());
3187
3188 const int constCount = sizeof(mixedVals) / sizeof(float);
3189
3190 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
3191 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
3192
3193 XglConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003194
3195 XglPipelineObj pipelineobj(m_device);
3196 pipelineobj.AddShader(&vs);
3197 pipelineobj.AddShader(&ps);
3198
3199 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08003200 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003201
3202 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07003203 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Cody Northrop02690bd2014-12-17 15:26:33 -07003204 XglCommandBufferObj cmdBuffer(m_device);
3205 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3206
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003207 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Cody Northrop02690bd2014-12-17 15:26:33 -07003208
3209 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
3210
3211#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003212 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop02690bd2014-12-17 15:26:33 -07003213 pDSDumpDot((char*)"triTest2.dot");
3214#endif
3215 // render triangle
3216 cmdBuffer.Draw(0, 3, 0, 1);
3217
3218 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003219 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06003220 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Cody Northrop02690bd2014-12-17 15:26:33 -07003221
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07003222 for (int i = 0; i < m_renderTargets.size(); i++)
Cody Northrop02690bd2014-12-17 15:26:33 -07003223 RecordImage(m_renderTargets[i]);
3224}
3225
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003226int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003227 int result;
3228
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003229 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003230 XglTestFramework::InitArgs(&argc, argv);
3231
Chia-I Wu7133fdc2014-12-15 23:57:34 +08003232 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06003233
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003234 result = RUN_ALL_TESTS();
3235
3236 XglTestFramework::Finish();
3237 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003238}