blob: df575d425cbdb2cb6aab77a1fa4e39ca7d16c8b3 [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
1592TEST_F(XglRenderTest, TriVertFetchDeadAttr)
1593{
1594 // This tests that attributes work in the presence of gl_VertexID
1595 // and a dead attribute in position 0. Draws a triangle with yellow,
1596 // red and green corners, starting at top and going clockwise.
1597
1598 static const char *vertShaderText =
1599 "#version 140\n"
1600 "#extension GL_ARB_separate_shader_objects : enable\n"
1601 "#extension GL_ARB_shading_language_420pack : enable\n"
1602 //XYZ1( -1, -1, -1 )
1603 "layout (location = 0) in vec4 pos;\n"
1604 //XYZ1( 0.f, 0.f, 0.f )
1605 "layout (location = 1) in vec4 inColor;\n"
1606 "layout (location = 0) out vec4 outColor;\n"
1607 "void main() {\n"
1608 " outColor = inColor;\n"
1609 " vec2 vertices[3];"
1610 " vertices[0] = vec2(-1.0, -1.0);\n"
1611 " vertices[1] = vec2( 1.0, -1.0);\n"
1612 " vertices[2] = vec2( 0.0, 1.0);\n"
1613 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1614 "}\n";
1615
1616
1617 static const char *fragShaderText =
1618 "#version 140\n"
1619 "#extension GL_ARB_separate_shader_objects : enable\n"
1620 "#extension GL_ARB_shading_language_420pack : enable\n"
1621 "layout (location = 0) in vec4 color;\n"
1622 "void main() {\n"
1623 " gl_FragColor = color;\n"
1624 "}\n";
1625
1626 ASSERT_NO_FATAL_FAILURE(InitState());
1627 ASSERT_NO_FATAL_FAILURE(InitViewport());
1628
1629 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001630 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001631
1632 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1633 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1634
1635 XglPipelineObj pipelineobj(m_device);
1636 pipelineobj.AddShader(&vs);
1637 pipelineobj.AddShader(&ps);
1638
1639 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001640 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001641
Mark Lobodzinski15427102015-02-18 16:38:17 -06001642 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1643
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001644#define MESH_BUF_ID 0
Tony Barbourf43b6982014-11-25 13:18:32 -07001645 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001646 MESH_BUF_ID, // Binding ID
1647 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1648 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001649 };
1650
1651 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001652 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1653 vi_attribs[0].location = 0;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001654 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001655 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1656 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1657 vi_attribs[1].location = 1;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001658 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001659 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001660
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001661 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001662 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001663 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001664
Tony Barbourdd4c9642015-01-09 12:55:14 -07001665 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001666 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001667 XglCommandBufferObj cmdBuffer(m_device);
1668 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001669
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001670 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001671
1672 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1673
1674 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1675#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001676 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001677 pDSDumpDot((char*)"triTest2.dot");
1678#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001679
1680 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001681 cmdBuffer.Draw(0, 6, 0, 1);
1682
1683 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001684 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001685 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001686
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001687 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001688 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001689}
1690
1691TEST_F(XglRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001692{
1693 static const char *vertShaderText =
1694 "#version 140\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001695 "#extension GL_ARB_separate_shader_objects : enable\n"
1696 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001697 "layout (std140) uniform bufferVals {\n"
1698 " mat4 mvp;\n"
1699 "} myBufferVals;\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001700 "layout (location = 0) in vec4 pos;\n"
1701 "layout (location = 1) in vec4 inColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001702 "out vec4 outColor;\n"
1703 "void main() {\n"
1704 " outColor = inColor;\n"
1705 " gl_Position = myBufferVals.mvp * pos;\n"
1706 "}\n";
1707
1708 static const char *fragShaderText =
1709 "#version 130\n"
1710 "in vec4 color;\n"
1711 "void main() {\n"
1712 " gl_FragColor = color;\n"
1713 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001714 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001715
Tony Barbourf43b6982014-11-25 13:18:32 -07001716 glm::mat4 View = glm::lookAt(
1717 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1718 glm::vec3(0,0,0), // and looks at the origin
1719 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
1720 );
1721
1722 glm::mat4 Model = glm::mat4(1.0f);
1723
1724 glm::mat4 MVP = Projection * View * Model;
1725
1726 ASSERT_NO_FATAL_FAILURE(InitState());
1727 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour17c6ab12015-03-27 17:03:18 -06001728 m_depthStencil->Init(m_device, m_width, m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07001729
1730 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
1731 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1732
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001733 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07001734
1735 XglConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1736 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1737 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1738
Tony Barbourf43b6982014-11-25 13:18:32 -07001739 XglPipelineObj pipelineobj(m_device);
1740 pipelineobj.AddShader(&vs);
1741 pipelineobj.AddShader(&ps);
1742
Tony Barbourfa6cac72015-01-16 14:27:35 -07001743 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
1744 ds_state.depthTestEnable = XGL_TRUE;
1745 ds_state.depthWriteEnable = XGL_TRUE;
1746 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
1747 ds_state.depthBoundsEnable = XGL_FALSE;
1748 ds_state.stencilTestEnable = XGL_FALSE;
1749 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
1750 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
1751 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
1752 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001753 ds_state.format = XGL_FMT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001754 ds_state.front = ds_state.back;
1755 pipelineobj.SetDepthStencil(&ds_state);
1756
Tony Barbourf43b6982014-11-25 13:18:32 -07001757 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001758 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001759
1760 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1761 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
Tony Barbour17c6ab12015-03-27 17:03:18 -06001762 m_memoryRefManager.AddMemoryRef(m_depthStencil);
Tony Barbourf43b6982014-11-25 13:18:32 -07001763
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001764#define MESH_BUF_ID 0
Tony Barbourf43b6982014-11-25 13:18:32 -07001765 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001766 MESH_BUF_ID, // Binding ID
1767 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1768 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1769 };
Tony Barbourf43b6982014-11-25 13:18:32 -07001770
Tony Barbourf43b6982014-11-25 13:18:32 -07001771 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001772 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1773 vi_attribs[0].location = 0;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001774 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001775 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1776 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1777 vi_attribs[1].location = 1;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001778 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001779 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001780
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001781 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001782 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001783 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001784
Tony Barbour17c6ab12015-03-27 17:03:18 -06001785 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001786 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbour17c6ab12015-03-27 17:03:18 -06001787
Tony Barboure4ed9942015-01-09 10:06:53 -07001788 XglCommandBufferObj cmdBuffer(m_device);
1789 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001790
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001791 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barboure4ed9942015-01-09 10:06:53 -07001792 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001793
Tony Barboure4ed9942015-01-09 10:06:53 -07001794 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1795#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001796 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barboure4ed9942015-01-09 10:06:53 -07001797 pDSDumpDot((char*)"triTest2.dot");
1798#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001799
1800 // render triangles
Tony Barboure4ed9942015-01-09 10:06:53 -07001801 cmdBuffer.Draw(0, 36, 0, 1);
1802
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001803
Tony Barboure4ed9942015-01-09 10:06:53 -07001804 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001805 EndCommandBuffer(cmdBuffer);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001806 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barboure4ed9942015-01-09 10:06:53 -07001807
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001808 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barboure4ed9942015-01-09 10:06:53 -07001809 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001810}
1811
Tony Barbourf43b6982014-11-25 13:18:32 -07001812TEST_F(XglRenderTest, VSTexture)
1813{
1814 // The expected result from this test is a green and red triangle;
1815 // one red vertex on the left, two green vertices on the right.
1816 static const char *vertShaderText =
1817 "#version 130\n"
1818 "out vec4 texColor;\n"
1819 "uniform sampler2D surface;\n"
1820 "void main() {\n"
1821 " vec2 vertices[3];"
1822 " vertices[0] = vec2(-0.5, -0.5);\n"
1823 " vertices[1] = vec2( 0.5, -0.5);\n"
1824 " vertices[2] = vec2( 0.5, 0.5);\n"
1825 " vec2 positions[3];"
1826 " positions[0] = vec2( 0.0, 0.0);\n"
1827 " positions[1] = vec2( 0.25, 0.1);\n"
1828 " positions[2] = vec2( 0.1, 0.25);\n"
1829 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1830 " texColor = textureLod(surface, samplePos, 0.0);\n"
1831 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1832 "}\n";
1833
1834 static const char *fragShaderText =
1835 "#version 130\n"
1836 "in vec4 texColor;\n"
1837 "void main() {\n"
1838 " gl_FragColor = texColor;\n"
1839 "}\n";
1840
1841 ASSERT_NO_FATAL_FAILURE(InitState());
1842 ASSERT_NO_FATAL_FAILURE(InitViewport());
1843
1844 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1845 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1846 XglSamplerObj sampler(m_device);
1847 XglTextureObj texture(m_device);
1848
Tony Barbourf43b6982014-11-25 13:18:32 -07001849 XglPipelineObj pipelineobj(m_device);
1850 pipelineobj.AddShader(&vs);
1851 pipelineobj.AddShader(&ps);
1852
1853 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001854 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001855
1856 m_memoryRefManager.AddMemoryRef(&texture);
1857
Tony Barbourdd4c9642015-01-09 12:55:14 -07001858 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001859 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001860 XglCommandBufferObj cmdBuffer(m_device);
1861 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001862
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001863 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001864
1865 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1866
1867#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001868 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001869 pDSDumpDot((char*)"triTest2.dot");
1870#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001871
Tony Barbourdd4c9642015-01-09 12:55:14 -07001872 // render triangle
1873 cmdBuffer.Draw(0, 3, 0, 1);
1874
1875 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001876 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001877 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001878
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001879 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001880 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001881}
1882TEST_F(XglRenderTest, TexturedTriangle)
1883{
1884 // The expected result from this test is a red and green checkered triangle
1885 static const char *vertShaderText =
1886 "#version 140\n"
1887 "#extension GL_ARB_separate_shader_objects : enable\n"
1888 "#extension GL_ARB_shading_language_420pack : enable\n"
1889 "layout (location = 0) out vec2 samplePos;\n"
1890 "void main() {\n"
1891 " vec2 vertices[3];"
1892 " vertices[0] = vec2(-0.5, -0.5);\n"
1893 " vertices[1] = vec2( 0.5, -0.5);\n"
1894 " vertices[2] = vec2( 0.5, 0.5);\n"
1895 " vec2 positions[3];"
1896 " positions[0] = vec2( 0.0, 0.0);\n"
1897 " positions[1] = vec2( 1.0, 0.0);\n"
1898 " positions[2] = vec2( 1.0, 1.0);\n"
1899 " samplePos = positions[gl_VertexID % 3];\n"
1900 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1901 "}\n";
1902
1903 static const char *fragShaderText =
1904 "#version 140\n"
1905 "#extension GL_ARB_separate_shader_objects : enable\n"
1906 "#extension GL_ARB_shading_language_420pack : enable\n"
1907 "layout (location = 0) in vec2 samplePos;\n"
1908 "layout (binding = 0) uniform sampler2D surface;\n"
1909 "layout (location=0) out vec4 outColor;\n"
1910 "void main() {\n"
1911 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1912 " outColor = texColor;\n"
1913 "}\n";
1914
1915 ASSERT_NO_FATAL_FAILURE(InitState());
1916 ASSERT_NO_FATAL_FAILURE(InitViewport());
1917
1918 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1919 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1920 XglSamplerObj sampler(m_device);
1921 XglTextureObj texture(m_device);
1922
Tony Barbourf43b6982014-11-25 13:18:32 -07001923 XglPipelineObj pipelineobj(m_device);
1924 pipelineobj.AddShader(&vs);
1925 pipelineobj.AddShader(&ps);
1926
1927 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001928 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001929
1930 m_memoryRefManager.AddMemoryRef(&texture);
1931
Tony Barbourdd4c9642015-01-09 12:55:14 -07001932 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001933 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001934 XglCommandBufferObj cmdBuffer(m_device);
1935 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1936
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001937 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001938
1939 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1940
1941#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001942 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001943 pDSDumpDot((char*)"triTest2.dot");
1944#endif
1945 // render triangle
1946 cmdBuffer.Draw(0, 3, 0, 1);
1947
1948 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001949 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001950 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001951
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001952 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001953 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001954}
1955TEST_F(XglRenderTest, TexturedTriangleClip)
1956{
1957 // The expected result from this test is a red and green checkered triangle
1958 static const char *vertShaderText =
1959 "#version 330\n"
1960 "#extension GL_ARB_separate_shader_objects : enable\n"
1961 "#extension GL_ARB_shading_language_420pack : enable\n"
1962 "layout (location = 0) out vec2 samplePos;\n"
1963 "out gl_PerVertex {\n"
1964 " vec4 gl_Position;\n"
1965 " float gl_ClipDistance[1];\n"
1966 "};\n"
1967 "void main() {\n"
1968 " vec2 vertices[3];"
1969 " vertices[0] = vec2(-0.5, -0.5);\n"
1970 " vertices[1] = vec2( 0.5, -0.5);\n"
1971 " vertices[2] = vec2( 0.5, 0.5);\n"
1972 " vec2 positions[3];"
1973 " positions[0] = vec2( 0.0, 0.0);\n"
1974 " positions[1] = vec2( 1.0, 0.0);\n"
1975 " positions[2] = vec2( 1.0, 1.0);\n"
1976 " float dists[3];\n"
1977 " dists[0] = 1.0;\n"
1978 " dists[1] = 1.0;\n"
1979 " dists[2] = -1.0;\n"
1980 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1981 " samplePos = positions[gl_VertexID % 3];\n"
1982 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1983 "}\n";
1984
1985 static const char *fragShaderText =
1986 "#version 140\n"
1987 "#extension GL_ARB_separate_shader_objects : enable\n"
1988 "#extension GL_ARB_shading_language_420pack : enable\n"
1989 "layout (location = 0) in vec2 samplePos;\n"
1990 "layout (binding = 0) uniform sampler2D surface;\n"
1991 "layout (location=0) out vec4 outColor;\n"
1992 "void main() {\n"
1993 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
1994 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1995 " outColor = texColor;\n"
1996 "}\n";
1997
1998
1999 ASSERT_NO_FATAL_FAILURE(InitState());
2000 ASSERT_NO_FATAL_FAILURE(InitViewport());
2001
2002 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2003 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2004 XglSamplerObj sampler(m_device);
2005 XglTextureObj texture(m_device);
2006
Tony Barbourf43b6982014-11-25 13:18:32 -07002007 XglPipelineObj pipelineobj(m_device);
2008 pipelineobj.AddShader(&vs);
2009 pipelineobj.AddShader(&ps);
2010
2011 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002012 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002013
2014 m_memoryRefManager.AddMemoryRef(&texture);
2015
Tony Barbourdd4c9642015-01-09 12:55:14 -07002016 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002017 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002018 XglCommandBufferObj cmdBuffer(m_device);
2019 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2020
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002021 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002022
2023 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2024
2025#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002026 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002027 pDSDumpDot((char*)"triTest2.dot");
2028#endif
2029 // render triangle
2030 cmdBuffer.Draw(0, 3, 0, 1);
2031
2032 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002033 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002034 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002035
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002036 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002037 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002038}
2039TEST_F(XglRenderTest, FSTriangle)
2040{
2041 // The expected result from this test is a red and green checkered triangle
2042 static const char *vertShaderText =
2043 "#version 140\n"
2044 "#extension GL_ARB_separate_shader_objects : enable\n"
2045 "#extension GL_ARB_shading_language_420pack : enable\n"
2046 "layout (location = 0) out vec2 samplePos;\n"
2047 "void main() {\n"
2048 " vec2 vertices[3];"
2049 " vertices[0] = vec2(-0.5, -0.5);\n"
2050 " vertices[1] = vec2( 0.5, -0.5);\n"
2051 " vertices[2] = vec2( 0.5, 0.5);\n"
2052 " vec2 positions[3];"
2053 " positions[0] = vec2( 0.0, 0.0);\n"
2054 " positions[1] = vec2( 1.0, 0.0);\n"
2055 " positions[2] = vec2( 1.0, 1.0);\n"
2056 " samplePos = positions[gl_VertexID % 3];\n"
2057 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2058 "}\n";
2059
2060 static const char *fragShaderText =
2061 "#version 140\n"
2062 "#extension GL_ARB_separate_shader_objects : enable\n"
2063 "#extension GL_ARB_shading_language_420pack : enable\n"
2064 "layout (location = 0) in vec2 samplePos;\n"
2065 "layout (binding = 0) uniform sampler2D surface;\n"
2066 "layout (location=0) out vec4 outColor;\n"
2067 "void main() {\n"
2068 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2069 " outColor = texColor;\n"
2070 "}\n";
2071
2072 ASSERT_NO_FATAL_FAILURE(InitState());
2073 ASSERT_NO_FATAL_FAILURE(InitViewport());
2074
2075 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2076 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2077 XglSamplerObj sampler(m_device);
2078 XglTextureObj texture(m_device);
2079
Tony Barbourf43b6982014-11-25 13:18:32 -07002080 XglPipelineObj pipelineobj(m_device);
2081 pipelineobj.AddShader(&vs);
2082 pipelineobj.AddShader(&ps);
2083
2084 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002085 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002086
2087 m_memoryRefManager.AddMemoryRef(&texture);
2088
Tony Barbourdd4c9642015-01-09 12:55:14 -07002089 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002090 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002091 XglCommandBufferObj cmdBuffer(m_device);
2092 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2093
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002094 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002095
2096 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2097
2098#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002099 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002100 pDSDumpDot((char*)"triTest2.dot");
2101#endif
2102 // render triangle
2103 cmdBuffer.Draw(0, 3, 0, 1);
2104
2105 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002106 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002107 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002108
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002109 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002110 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002111}
2112TEST_F(XglRenderTest, SamplerBindingsTriangle)
2113{
2114 // This test sets bindings on the samplers
2115 // For now we are asserting that sampler and texture pairs
2116 // march in lock step, and are set via GLSL binding. This can
2117 // and will probably change.
2118 // The sampler bindings should match the sampler and texture slot
2119 // number set up by the application.
2120 // This test will result in a blue triangle
2121 static const char *vertShaderText =
2122 "#version 140\n"
2123 "#extension GL_ARB_separate_shader_objects : enable\n"
2124 "#extension GL_ARB_shading_language_420pack : enable\n"
2125 "layout (location = 0) out vec4 samplePos;\n"
2126 "void main() {\n"
2127 " vec2 vertices[3];"
2128 " vertices[0] = vec2(-0.5, -0.5);\n"
2129 " vertices[1] = vec2( 0.5, -0.5);\n"
2130 " vertices[2] = vec2( 0.5, 0.5);\n"
2131 " vec2 positions[3];"
2132 " positions[0] = vec2( 0.0, 0.0);\n"
2133 " positions[1] = vec2( 1.0, 0.0);\n"
2134 " positions[2] = vec2( 1.0, 1.0);\n"
2135 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2136 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2137 "}\n";
2138
2139 static const char *fragShaderText =
2140 "#version 140\n"
2141 "#extension GL_ARB_separate_shader_objects : enable\n"
2142 "#extension GL_ARB_shading_language_420pack : enable\n"
2143 "layout (location = 0) in vec4 samplePos;\n"
2144 "layout (binding = 0) uniform sampler2D surface0;\n"
2145 "layout (binding = 1) uniform sampler2D surface1;\n"
2146 "layout (binding = 12) uniform sampler2D surface2;\n"
2147 "void main() {\n"
2148 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
2149 "}\n";
2150
2151 ASSERT_NO_FATAL_FAILURE(InitState());
2152 ASSERT_NO_FATAL_FAILURE(InitViewport());
2153
2154 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2155 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2156
2157 XglSamplerObj sampler1(m_device);
2158 XglSamplerObj sampler2(m_device);
2159 XglSamplerObj sampler3(m_device);
2160
Tony Barbour2f421a02015-04-01 16:38:10 -06002161 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
2162 XglTextureObj texture1(m_device, tex_colors); // Red
2163 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
2164 XglTextureObj texture2(m_device, tex_colors); // Green
2165 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
2166 XglTextureObj texture3(m_device, tex_colors); // Blue
Tony Barbourf43b6982014-11-25 13:18:32 -07002167
Tony Barbourf43b6982014-11-25 13:18:32 -07002168 XglPipelineObj pipelineobj(m_device);
2169 pipelineobj.AddShader(&vs);
2170 pipelineobj.AddShader(&ps);
2171
2172 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002173 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2174 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2175 for (int i = 0; i < 10; i++)
2176 descriptorSet.AppendDummy();
2177 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002178
2179 m_memoryRefManager.AddMemoryRef(&texture1);
2180 m_memoryRefManager.AddMemoryRef(&texture2);
2181 m_memoryRefManager.AddMemoryRef(&texture3);
2182
Tony Barbourdd4c9642015-01-09 12:55:14 -07002183 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002184 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002185 XglCommandBufferObj cmdBuffer(m_device);
2186 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2187
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002188 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002189
2190 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2191
2192#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002193 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002194 pDSDumpDot((char*)"triTest2.dot");
2195#endif
2196 // render triangle
2197 cmdBuffer.Draw(0, 3, 0, 1);
2198
2199 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002200 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002201 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002202
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002203 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002204 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002205
2206}
2207
2208TEST_F(XglRenderTest, TriangleVSUniformBlock)
2209{
2210 // The expected result from this test is a blue triangle
2211
2212 static const char *vertShaderText =
2213 "#version 140\n"
2214 "#extension GL_ARB_separate_shader_objects : enable\n"
2215 "#extension GL_ARB_shading_language_420pack : enable\n"
2216 "layout (location = 0) out vec4 outColor;\n"
2217 "layout (std140, binding = 0) uniform bufferVals {\n"
2218 " vec4 red;\n"
2219 " vec4 green;\n"
2220 " vec4 blue;\n"
2221 " vec4 white;\n"
2222 "} myBufferVals;\n"
2223 "void main() {\n"
2224 " vec2 vertices[3];"
2225 " vertices[0] = vec2(-0.5, -0.5);\n"
2226 " vertices[1] = vec2( 0.5, -0.5);\n"
2227 " vertices[2] = vec2( 0.5, 0.5);\n"
2228 " outColor = myBufferVals.blue;\n"
2229 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2230 "}\n";
2231
2232 static const char *fragShaderText =
2233 "#version 140\n"
2234 "#extension GL_ARB_separate_shader_objects : enable\n"
2235 "#extension GL_ARB_shading_language_420pack : enable\n"
2236 "layout (location = 0) in vec4 inColor;\n"
2237 "void main() {\n"
2238 " gl_FragColor = inColor;\n"
2239 "}\n";
2240
2241 ASSERT_NO_FATAL_FAILURE(InitState());
2242 ASSERT_NO_FATAL_FAILURE(InitViewport());
2243
2244 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2245 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2246
2247 // Let's populate our buffer with the following:
2248 // vec4 red;
2249 // vec4 green;
2250 // vec4 blue;
2251 // vec4 white;
2252 const int valCount = 4 * 4;
2253 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2254 0.0, 1.0, 0.0, 1.0,
2255 0.0, 0.0, 1.0, 1.0,
2256 1.0, 1.0, 1.0, 1.0 };
2257
2258 XglConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002259
2260 XglPipelineObj pipelineobj(m_device);
2261 pipelineobj.AddShader(&vs);
2262 pipelineobj.AddShader(&ps);
2263
2264 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002265 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002266
Tony Barbourdd4c9642015-01-09 12:55:14 -07002267 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002268 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002269 XglCommandBufferObj cmdBuffer(m_device);
2270 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2271
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002272 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002273
2274 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2275
2276#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002277 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002278 pDSDumpDot((char*)"triTest2.dot");
2279#endif
2280 // render triangle
2281 cmdBuffer.Draw(0, 3, 0, 1);
2282
2283 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002284 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002285 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002286
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002287 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002288 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002289
2290}
2291
2292TEST_F(XglRenderTest, TriangleFSUniformBlockBinding)
2293{
2294 // This test allows the shader to select which buffer it is
2295 // pulling from using layout binding qualifier.
2296 // There are corresponding changes in the compiler stack that
2297 // will select the buffer using binding directly.
2298 // The binding number should match the slot number set up by
2299 // the application.
2300 // The expected result from this test is a purple triangle
2301
2302 static const char *vertShaderText =
2303 "#version 140\n"
2304 "#extension GL_ARB_separate_shader_objects : enable\n"
2305 "#extension GL_ARB_shading_language_420pack : enable\n"
2306 "void main() {\n"
2307 " vec2 vertices[3];"
2308 " vertices[0] = vec2(-0.5, -0.5);\n"
2309 " vertices[1] = vec2( 0.5, -0.5);\n"
2310 " vertices[2] = vec2( 0.5, 0.5);\n"
2311 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2312 "}\n";
2313
2314 static const char *fragShaderText =
2315 "#version 140\n"
2316 "#extension GL_ARB_separate_shader_objects : enable\n"
2317 "#extension GL_ARB_shading_language_420pack : enable\n"
2318 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2319 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2320 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002321 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
Tony Barbourf43b6982014-11-25 13:18:32 -07002322 "void main() {\n"
2323 " gl_FragColor = myBlueVal.color;\n"
2324 " gl_FragColor += myRedVal.color;\n"
2325 "}\n";
2326
2327 ASSERT_NO_FATAL_FAILURE(InitState());
2328 ASSERT_NO_FATAL_FAILURE(InitViewport());
2329
2330 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2331 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2332
2333 // We're going to create a number of uniform buffers, and then allow
2334 // the shader to select which it wants to read from with a binding
2335
2336 // Let's populate the buffers with a single color each:
2337 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2338 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2339 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002340 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002341
2342 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2343 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2344 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2345 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2346
2347 const int redCount = sizeof(redVals) / sizeof(float);
2348 const int greenCount = sizeof(greenVals) / sizeof(float);
2349 const int blueCount = sizeof(blueVals) / sizeof(float);
2350 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2351
2352 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002353
2354 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002355
2356 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002357
2358 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002359
2360 XglPipelineObj pipelineobj(m_device);
2361 pipelineobj.AddShader(&vs);
2362 pipelineobj.AddShader(&ps);
2363
2364 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002365 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2366 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2367 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2368 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002369
Tony Barbourdd4c9642015-01-09 12:55:14 -07002370 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002371 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002372 XglCommandBufferObj cmdBuffer(m_device);
2373 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002374
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002375 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002376
2377 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2378
2379#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002380 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002381 pDSDumpDot((char*)"triTest2.dot");
2382#endif
2383 // render triangle
2384 cmdBuffer.Draw(0, 3, 0, 1);
2385
2386 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002387 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002388 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002389
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002390 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002391 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002392}
2393
2394TEST_F(XglRenderTest, TriangleFSAnonymousUniformBlockBinding)
2395{
2396 // This test is the same as TriangleFSUniformBlockBinding, but
2397 // it does not provide an instance name.
2398 // The expected result from this test is a purple triangle
2399
2400 static const char *vertShaderText =
2401 "#version 140\n"
2402 "#extension GL_ARB_separate_shader_objects : enable\n"
2403 "#extension GL_ARB_shading_language_420pack : enable\n"
2404 "void main() {\n"
2405 " vec2 vertices[3];"
2406 " vertices[0] = vec2(-0.5, -0.5);\n"
2407 " vertices[1] = vec2( 0.5, -0.5);\n"
2408 " vertices[2] = vec2( 0.5, 0.5);\n"
2409 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2410 "}\n";
2411
2412 static const char *fragShaderText =
2413 "#version 430\n"
2414 "#extension GL_ARB_separate_shader_objects : enable\n"
2415 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002416 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2417 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2418 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002419 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002420 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002421 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002422 " outColor = blue;\n"
2423 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002424 "}\n";
2425 ASSERT_NO_FATAL_FAILURE(InitState());
2426 ASSERT_NO_FATAL_FAILURE(InitViewport());
2427
2428 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2429 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2430
2431 // We're going to create a number of uniform buffers, and then allow
2432 // the shader to select which it wants to read from with a binding
2433
2434 // Let's populate the buffers with a single color each:
2435 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2436 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2437 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2438 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2439
2440 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2441 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2442 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2443 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2444
2445 const int redCount = sizeof(redVals) / sizeof(float);
2446 const int greenCount = sizeof(greenVals) / sizeof(float);
2447 const int blueCount = sizeof(blueVals) / sizeof(float);
2448 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2449
2450 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002451
2452 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002453
2454 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002455
2456 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002457
2458 XglPipelineObj pipelineobj(m_device);
2459 pipelineobj.AddShader(&vs);
2460 pipelineobj.AddShader(&ps);
2461
2462 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002463 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2464 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2465 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2466 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002467
Tony Barbourdd4c9642015-01-09 12:55:14 -07002468 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002469 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002470 XglCommandBufferObj cmdBuffer(m_device);
2471 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2472
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002473 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002474
2475 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2476
2477#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002478 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002479 pDSDumpDot((char*)"triTest2.dot");
2480#endif
2481 // render triangle
2482 cmdBuffer.Draw(0, 3, 0, 1);
2483
2484 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002485 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002486 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002487
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002488 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002489 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002490
2491}
2492
2493TEST_F(XglRenderTest, CubeWithVertexFetchAndMVPAndTexture)
2494{
2495 static const char *vertShaderText =
2496 "#version 140\n"
2497 "#extension GL_ARB_separate_shader_objects : enable\n"
2498 "#extension GL_ARB_shading_language_420pack : enable\n"
2499 "layout (std140, binding=0) uniform bufferVals {\n"
2500 " mat4 mvp;\n"
2501 "} myBufferVals;\n"
2502 "layout (location=0) in vec4 pos;\n"
2503 "layout (location=0) out vec2 UV;\n"
2504 "void main() {\n"
2505 " vec2 positions[3];"
2506 " positions[0] = vec2( 0.0, 0.0);\n"
2507 " positions[1] = vec2( 0.25, 0.1);\n"
2508 " positions[2] = vec2( 0.1, 0.25);\n"
2509 " UV = positions[gl_VertexID % 3];\n"
2510 " gl_Position = myBufferVals.mvp * pos;\n"
2511 "}\n";
2512
2513 static const char *fragShaderText =
2514 "#version 140\n"
2515 "#extension GL_ARB_separate_shader_objects : enable\n"
2516 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002517 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002518 "layout (location=0) out vec4 outColor;\n"
2519 "layout (location=0) in vec2 UV;\n"
2520 "void main() {\n"
2521 " outColor= textureLod(surface, UV, 0.0);\n"
2522 "}\n";
2523 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2524
2525 glm::mat4 View = glm::lookAt(
2526 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2527 glm::vec3(0,0,0), // and looks at the origin
2528 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2529 );
2530
2531 glm::mat4 Model = glm::mat4(1.0f);
2532
2533 glm::mat4 MVP = Projection * View * Model;
2534
2535
2536 ASSERT_NO_FATAL_FAILURE(InitState());
2537 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour17c6ab12015-03-27 17:03:18 -06002538 m_depthStencil->Init(m_device, m_width, m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07002539
2540 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
2541 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002542 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002543
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002544 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07002545
2546 XglConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2547 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2548 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2549 XglSamplerObj sampler(m_device);
2550 XglTextureObj texture(m_device);
2551
Tony Barbourf43b6982014-11-25 13:18:32 -07002552 XglPipelineObj pipelineobj(m_device);
2553 pipelineobj.AddShader(&vs);
2554 pipelineobj.AddShader(&ps);
2555
2556 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06002557 // descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer); // TODO: Why does this break images??
Chia-I Wuf8385062015-01-04 16:27:24 +08002558 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mvpBuffer);
2559 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002560
2561 m_memoryRefManager.AddMemoryRef(&meshBuffer);
2562 m_memoryRefManager.AddMemoryRef(&mvpBuffer);
2563 m_memoryRefManager.AddMemoryRef(&texture);
Tony Barbour17c6ab12015-03-27 17:03:18 -06002564 m_memoryRefManager.AddMemoryRef(m_depthStencil);
Tony Barbourf43b6982014-11-25 13:18:32 -07002565
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002566#define MESH_BIND_ID 0
Tony Barbourf43b6982014-11-25 13:18:32 -07002567 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002568 MESH_BIND_ID, // binding ID
2569 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
2570 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
2571 };
Tony Barbourf43b6982014-11-25 13:18:32 -07002572
Tony Barbourf43b6982014-11-25 13:18:32 -07002573 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002574 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2575 vi_attribs[0].location = 0; // location
2576 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
2577 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2578 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2579 vi_attribs[1].location = 1; // location
2580 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
2581 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07002582
Tony Barbourf43b6982014-11-25 13:18:32 -07002583 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002584 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2585 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07002586
Tony Barbourfa6cac72015-01-16 14:27:35 -07002587 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
2588 ds_state.depthTestEnable = XGL_TRUE;
2589 ds_state.depthWriteEnable = XGL_TRUE;
2590 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
2591 ds_state.depthBoundsEnable = XGL_FALSE;
2592 ds_state.stencilTestEnable = XGL_FALSE;
2593 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
2594 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
2595 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
2596 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07002597 ds_state.format = XGL_FMT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002598 ds_state.front = ds_state.back;
2599 pipelineobj.SetDepthStencil(&ds_state);
2600
Tony Barbour17c6ab12015-03-27 17:03:18 -06002601 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002602 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002603 XglCommandBufferObj cmdBuffer(m_device);
2604 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002605
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002606 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
2607
Tony Barbourdd4c9642015-01-09 12:55:14 -07002608 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2609
2610 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2611#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002612 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002613 pDSDumpDot((char*)"triTest2.dot");
2614#endif
2615 // render triangle
2616 cmdBuffer.Draw(0, 36, 0, 1);
2617
2618 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002619 EndCommandBuffer(cmdBuffer);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002620 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
2621
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002622 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002623 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002624
2625}
Cody Northropd1ce7842014-12-09 11:17:01 -07002626
2627TEST_F(XglRenderTest, TriangleMixedSamplerUniformBlockBinding)
2628{
2629 // This test mixes binding slots of textures and buffers, ensuring
2630 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002631 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002632 // you can modify it to move the desired result around.
2633
2634 static const char *vertShaderText =
2635 "#version 140\n"
2636 "#extension GL_ARB_separate_shader_objects : enable\n"
2637 "#extension GL_ARB_shading_language_420pack : enable\n"
2638 "void main() {\n"
2639 " vec2 vertices[3];"
2640 " vertices[0] = vec2(-0.5, -0.5);\n"
2641 " vertices[1] = vec2( 0.5, -0.5);\n"
2642 " vertices[2] = vec2( 0.5, 0.5);\n"
2643 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2644 "}\n";
2645
2646 static const char *fragShaderText =
2647 "#version 430\n"
2648 "#extension GL_ARB_separate_shader_objects : enable\n"
2649 "#extension GL_ARB_shading_language_420pack : enable\n"
2650 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002651 "layout (binding = 3) uniform sampler2D surface1;\n"
2652 "layout (binding = 1) uniform sampler2D surface2;\n"
2653 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002654
Cody Northropa0410942014-12-09 13:59:39 -07002655
Chia-I Wuf8385062015-01-04 16:27:24 +08002656 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2657 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2658 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2659 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002660 "layout (location = 0) out vec4 outColor;\n"
2661 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002662 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002663 " outColor += white * vec4(0.00001);\n"
2664 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002665 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002666 "}\n";
2667 ASSERT_NO_FATAL_FAILURE(InitState());
2668 ASSERT_NO_FATAL_FAILURE(InitViewport());
2669
2670 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2671 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2672
Cody Northropd1ce7842014-12-09 11:17:01 -07002673 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2674 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2675 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2676 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2677
2678 const int redCount = sizeof(redVals) / sizeof(float);
2679 const int greenCount = sizeof(greenVals) / sizeof(float);
2680 const int blueCount = sizeof(blueVals) / sizeof(float);
2681 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2682
2683 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002684 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002685 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002686 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002687
Tony Barbour2f421a02015-04-01 16:38:10 -06002688 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Cody Northropd1ce7842014-12-09 11:17:01 -07002689 XglSamplerObj sampler0(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002690 XglTextureObj texture0(m_device, tex_colors); // Light Red
2691 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Cody Northropd1ce7842014-12-09 11:17:01 -07002692 XglSamplerObj sampler2(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002693 XglTextureObj texture2(m_device, tex_colors); // Light Blue
2694 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Cody Northropd1ce7842014-12-09 11:17:01 -07002695 XglSamplerObj sampler4(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002696 XglTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropa0410942014-12-09 13:59:39 -07002697
2698 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2699 // TODO: Get back here ASAP and understand why.
Tony Barbour2f421a02015-04-01 16:38:10 -06002700 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Cody Northropa0410942014-12-09 13:59:39 -07002701 XglSamplerObj sampler7(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002702 XglTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropd1ce7842014-12-09 11:17:01 -07002703
2704 XglPipelineObj pipelineobj(m_device);
2705 pipelineobj.AddShader(&vs);
2706 pipelineobj.AddShader(&ps);
2707
2708 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002709 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2710 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2711 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2712 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2713 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2714 // swap blue and green
2715 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2716 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2717 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002718
2719 m_memoryRefManager.AddMemoryRef(&texture0);
2720 m_memoryRefManager.AddMemoryRef(&texture2);
2721 m_memoryRefManager.AddMemoryRef(&texture4);
Cody Northropa0410942014-12-09 13:59:39 -07002722 m_memoryRefManager.AddMemoryRef(&texture7);
Cody Northropd1ce7842014-12-09 11:17:01 -07002723
Tony Barbourdd4c9642015-01-09 12:55:14 -07002724 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002725 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002726 XglCommandBufferObj cmdBuffer(m_device);
2727 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002728
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002729 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002730
2731 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2732
2733#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002734 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002735 pDSDumpDot((char*)"triTest2.dot");
2736#endif
2737 // render triangle
2738 cmdBuffer.Draw(0, 3, 0, 1);
2739
2740 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002741 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002742 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002743
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002744 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002745 RecordImage(m_renderTargets[i]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002746
2747}
2748
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002749TEST_F(XglRenderTest, TriangleMatchingSamplerUniformBlockBinding)
2750{
2751 // This test matches binding slots of textures and buffers, requiring
2752 // the driver to give them distinct number spaces.
2753 // The expected result from this test is a red triangle, although
2754 // you can modify it to move the desired result around.
2755
2756 static const char *vertShaderText =
2757 "#version 140\n"
2758 "#extension GL_ARB_separate_shader_objects : enable\n"
2759 "#extension GL_ARB_shading_language_420pack : enable\n"
2760 "void main() {\n"
2761 " vec2 vertices[3];"
2762 " vertices[0] = vec2(-0.5, -0.5);\n"
2763 " vertices[1] = vec2( 0.5, -0.5);\n"
2764 " vertices[2] = vec2( 0.5, 0.5);\n"
2765 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2766 "}\n";
2767
2768 static const char *fragShaderText =
2769 "#version 430\n"
2770 "#extension GL_ARB_separate_shader_objects : enable\n"
2771 "#extension GL_ARB_shading_language_420pack : enable\n"
2772 "layout (binding = 0) uniform sampler2D surface0;\n"
2773 "layout (binding = 1) uniform sampler2D surface1;\n"
2774 "layout (binding = 2) uniform sampler2D surface2;\n"
2775 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002776 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2777 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2778 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2779 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002780 "layout (location = 0) out vec4 outColor;\n"
2781 "void main() {\n"
2782 " outColor = red;// * vec4(0.00001);\n"
2783 " outColor += white * vec4(0.00001);\n"
2784 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2785 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2786 "}\n";
2787 ASSERT_NO_FATAL_FAILURE(InitState());
2788 ASSERT_NO_FATAL_FAILURE(InitViewport());
2789
2790 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2791 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2792
2793 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2794 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2795 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2796 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2797
2798 const int redCount = sizeof(redVals) / sizeof(float);
2799 const int greenCount = sizeof(greenVals) / sizeof(float);
2800 const int blueCount = sizeof(blueVals) / sizeof(float);
2801 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2802
2803 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002804 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002805 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002806 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002807
Tony Barbour2f421a02015-04-01 16:38:10 -06002808 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002809 XglSamplerObj sampler0(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002810 XglTextureObj texture0(m_device, tex_colors); // Light Red
2811 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002812 XglSamplerObj sampler2(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002813 XglTextureObj texture2(m_device, tex_colors); // Light Blue
2814 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002815 XglSamplerObj sampler4(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002816 XglTextureObj texture4(m_device, tex_colors); // Light Green
2817 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002818 XglSamplerObj sampler7(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002819 XglTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002820
2821 XglPipelineObj pipelineobj(m_device);
2822 pipelineobj.AddShader(&vs);
2823 pipelineobj.AddShader(&ps);
2824
2825 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002826 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2827 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2828 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2829 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2830 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2831 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2832 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2833 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002834
2835 m_memoryRefManager.AddMemoryRef(&texture0);
2836 m_memoryRefManager.AddMemoryRef(&texture2);
2837 m_memoryRefManager.AddMemoryRef(&texture4);
2838 m_memoryRefManager.AddMemoryRef(&texture7);
2839
Tony Barbourdd4c9642015-01-09 12:55:14 -07002840 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002841 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002842 XglCommandBufferObj cmdBuffer(m_device);
2843 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002844
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002845 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002846
2847 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2848
2849#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002850 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002851 pDSDumpDot((char*)"triTest2.dot");
2852#endif
2853 // render triangle
2854 cmdBuffer.Draw(0, 3, 0, 1);
2855
2856 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002857 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002858 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002859
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002860 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002861 RecordImage(m_renderTargets[i]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002862
2863}
2864
Cody Northrop02690bd2014-12-17 15:26:33 -07002865TEST_F(XglRenderTest, TriangleUniformBufferLayout)
2866{
2867 // This test populates a buffer with a variety of different data
2868 // types, then reads them out with a shader.
2869 // The expected result from this test is a green triangle
2870
2871 static const char *vertShaderText =
2872 "#version 140\n"
2873 "#extension GL_ARB_separate_shader_objects : enable\n"
2874 "#extension GL_ARB_shading_language_420pack : enable\n"
2875 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2876 " vec4 fRed;\n"
2877 " vec4 fGreen;\n"
2878 " layout(row_major) mat4 worldToProj;\n"
2879 " layout(row_major) mat4 projToWorld;\n"
2880 " layout(row_major) mat4 worldToView;\n"
2881 " layout(row_major) mat4 viewToProj;\n"
2882 " layout(row_major) mat4 worldToShadow[4];\n"
2883 " float fZero;\n"
2884 " float fOne;\n"
2885 " float fTwo;\n"
2886 " float fThree;\n"
2887 " vec3 fZeroZeroZero;\n"
2888 " float fFour;\n"
2889 " vec3 fZeroZeroOne;\n"
2890 " float fFive;\n"
2891 " vec3 fZeroOneZero;\n"
2892 " float fSix;\n"
2893 " float fSeven;\n"
2894 " float fEight;\n"
2895 " float fNine;\n"
2896 " vec2 fZeroZero;\n"
2897 " vec2 fZeroOne;\n"
2898 " vec4 fBlue;\n"
2899 " vec2 fOneZero;\n"
2900 " vec2 fOneOne;\n"
2901 " vec3 fZeroOneOne;\n"
2902 " float fTen;\n"
2903 " float fEleven;\n"
2904 " float fTwelve;\n"
2905 " vec3 fOneZeroZero;\n"
2906 " vec4 uvOffsets[4];\n"
2907 "};\n"
2908 "layout (location = 0) out vec4 color;"
2909 "void main() {\n"
2910
2911 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2912 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2913 " \n"
2914
2915 // do some exact comparisons, even though we should
2916 // really have an epsilon involved.
2917 " vec4 outColor = right;\n"
2918 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
2919 " outColor = wrong;\n"
2920 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
2921 " outColor = wrong;\n"
2922 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
2923 " outColor = wrong;\n"
2924
2925 " color = outColor;\n"
2926
2927 // generic position stuff
2928 " vec2 vertices;\n"
2929 " int vertexSelector = gl_VertexID;\n"
2930 " if (vertexSelector == 0)\n"
2931 " vertices = vec2(-0.5, -0.5);\n"
2932 " else if (vertexSelector == 1)\n"
2933 " vertices = vec2( 0.5, -0.5);\n"
2934 " else if (vertexSelector == 2)\n"
2935 " vertices = vec2( 0.5, 0.5);\n"
2936 " else\n"
2937 " vertices = vec2( 0.0, 0.0);\n"
2938 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
2939 "}\n";
2940
2941 static const char *fragShaderText =
2942 "#version 140\n"
2943 "#extension GL_ARB_separate_shader_objects : enable\n"
2944 "#extension GL_ARB_shading_language_420pack : enable\n"
2945 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2946 " vec4 fRed;\n"
2947 " vec4 fGreen;\n"
2948 " layout(row_major) mat4 worldToProj;\n"
2949 " layout(row_major) mat4 projToWorld;\n"
2950 " layout(row_major) mat4 worldToView;\n"
2951 " layout(row_major) mat4 viewToProj;\n"
2952 " layout(row_major) mat4 worldToShadow[4];\n"
2953 " float fZero;\n"
2954 " float fOne;\n"
2955 " float fTwo;\n"
2956 " float fThree;\n"
2957 " vec3 fZeroZeroZero;\n"
2958 " float fFour;\n"
2959 " vec3 fZeroZeroOne;\n"
2960 " float fFive;\n"
2961 " vec3 fZeroOneZero;\n"
2962 " float fSix;\n"
2963 " float fSeven;\n"
2964 " float fEight;\n"
2965 " float fNine;\n"
2966 " vec2 fZeroZero;\n"
2967 " vec2 fZeroOne;\n"
2968 " vec4 fBlue;\n"
2969 " vec2 fOneZero;\n"
2970 " vec2 fOneOne;\n"
2971 " vec3 fZeroOneOne;\n"
2972 " float fTen;\n"
2973 " float fEleven;\n"
2974 " float fTwelve;\n"
2975 " vec3 fOneZeroZero;\n"
2976 " vec4 uvOffsets[4];\n"
2977 "};\n"
2978 "layout (location = 0) in vec4 color;\n"
2979 "void main() {\n"
2980 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2981 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2982 " \n"
2983
2984 // start with VS value to ensure it passed
2985 " vec4 outColor = color;\n"
2986
2987 // do some exact comparisons, even though we should
2988 // really have an epsilon involved.
2989 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
2990 " outColor = wrong;\n"
2991 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
2992 " outColor = wrong;\n"
2993 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
2994 " outColor = wrong;\n"
2995 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
2996 " outColor = wrong;\n"
2997 " if (fTwo != 2.0)\n"
2998 " outColor = wrong;\n"
2999 " if (fOneOne != vec2(1.0, 1.0))\n"
3000 " outColor = wrong;\n"
3001 " if (fTen != 10.0)\n"
3002 " outColor = wrong;\n"
3003 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3004 " outColor = wrong;\n"
3005 " \n"
3006 " gl_FragColor = outColor;\n"
3007 "}\n";
3008
3009
3010 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3011 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3012 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3013 0.0, 1.0, 0.0, 1.0, // align
3014 0.0, 0.0, 1.0, 1.0, // align
3015 0.0, 0.0, 0.0, 1.0, // align
3016 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3017 0.0, 2.0, 0.0, 2.0, // align
3018 0.0, 0.0, 2.0, 2.0, // align
3019 0.0, 0.0, 0.0, 2.0, // align
3020 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3021 0.0, 3.0, 0.0, 3.0, // align
3022 0.0, 0.0, 3.0, 3.0, // align
3023 0.0, 0.0, 0.0, 3.0, // align
3024 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3025 0.0, 4.0, 0.0, 4.0, // align
3026 0.0, 0.0, 4.0, 4.0, // align
3027 0.0, 0.0, 0.0, 4.0, // align
3028 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3029 0.0, 5.0, 0.0, 5.0, // align
3030 0.0, 0.0, 5.0, 5.0, // align
3031 0.0, 0.0, 0.0, 5.0, // align
3032 6.0, 0.0, 0.0, 6.0, // align
3033 0.0, 6.0, 0.0, 6.0, // align
3034 0.0, 0.0, 6.0, 6.0, // align
3035 0.0, 0.0, 0.0, 6.0, // align
3036 7.0, 0.0, 0.0, 7.0, // align
3037 0.0, 7.0, 0.0, 7.0, // align
3038 0.0, 0.0, 7.0, 7.0, // align
3039 0.0, 0.0, 0.0, 7.0, // align
3040 8.0, 0.0, 0.0, 8.0, // align
3041 0.0, 8.0, 0.0, 8.0, // align
3042 0.0, 0.0, 8.0, 8.0, // align
3043 0.0, 0.0, 0.0, 8.0, // align
3044 0.0, // float fZero; // align
3045 1.0, // float fOne; // pack
3046 2.0, // float fTwo; // pack
3047 3.0, // float fThree; // pack
3048 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3049 4.0, // float fFour; // pack
3050 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3051 5.0, // float fFive; // pack
3052 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3053 6.0, // float fSix; // pack
3054 7.0, // float fSeven; // align
3055 8.0, // float fEight; // pack
3056 9.0, // float fNine; // pack
3057 0.0, // BUFFER
3058 0.0, 0.0, // vec2 fZeroZero; // align
3059 0.0, 1.0, // vec2 fZeroOne; // pack
3060 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3061 1.0, 0.0, // vec2 fOneZero; // align
3062 1.0, 1.0, // vec2 fOneOne; // pack
3063 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3064 10.0, // float fTen; // pack
3065 11.0, // float fEleven; // align
3066 12.0, // float fTwelve; // pack
3067 0.0, 0.0, // BUFFER
3068 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3069 0.0, // BUFFER
3070 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3071 0.5, 0.6, 0.7, 0.8, // align
3072 0.9, 1.0, 1.1, 1.2, // align
3073 1.3, 1.4, 1.5, 1.6, // align
3074 };
3075
3076 ASSERT_NO_FATAL_FAILURE(InitState());
3077 ASSERT_NO_FATAL_FAILURE(InitViewport());
3078
3079 const int constCount = sizeof(mixedVals) / sizeof(float);
3080
3081 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
3082 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
3083
3084 XglConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003085
3086 XglPipelineObj pipelineobj(m_device);
3087 pipelineobj.AddShader(&vs);
3088 pipelineobj.AddShader(&ps);
3089
3090 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08003091 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003092
3093 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07003094 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Cody Northrop02690bd2014-12-17 15:26:33 -07003095 XglCommandBufferObj cmdBuffer(m_device);
3096 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3097
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003098 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Cody Northrop02690bd2014-12-17 15:26:33 -07003099
3100 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
3101
3102#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003103 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop02690bd2014-12-17 15:26:33 -07003104 pDSDumpDot((char*)"triTest2.dot");
3105#endif
3106 // render triangle
3107 cmdBuffer.Draw(0, 3, 0, 1);
3108
3109 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003110 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06003111 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Cody Northrop02690bd2014-12-17 15:26:33 -07003112
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07003113 for (int i = 0; i < m_renderTargets.size(); i++)
Cody Northrop02690bd2014-12-17 15:26:33 -07003114 RecordImage(m_renderTargets[i]);
3115}
3116
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003117int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003118 int result;
3119
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003120 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003121 XglTestFramework::InitArgs(&argc, argv);
3122
Chia-I Wu7133fdc2014-12-15 23:57:34 +08003123 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06003124
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003125 result = RUN_ALL_TESTS();
3126
3127 XglTestFramework::Finish();
3128 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003129}