blob: 332c1c76015a5e5f7b913ad8e8ff9247843693bf [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());
Chia-I Wu862c5572015-03-28 15:23:55 +0800304 cmdBuffer->BindDescriptorSet(descriptorSet);
Tony Barbour02472db2015-01-08 17:08:28 -0700305}
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 Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600437 RecordImages(m_renderTargets);
Tony Barbour71ba3612015-01-09 16:12:35 -0700438
439 if (rotate)
Tobin Ehlis12ee35f2015-03-26 08:23:25 -0600440 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
Tony Barbour71ba3612015-01-09 16:12:35 -0700441
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700442#ifdef PRINT_OBJECTS
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600443 //uint64_t objTrackGetObjectCount(XGL_OBJECT_TYPE type)
444 OBJ_TRACK_GET_OBJECT_COUNT pObjTrackGetObjectCount = (OBJ_TRACK_GET_OBJECT_COUNT)xglGetProcAddr(gpu(), (char*)"objTrackGetObjectCount");
445 uint64_t numObjects = pObjTrackGetObjectCount(XGL_OBJECT_TYPE_ANY);
446 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = xglGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700447 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600448 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)xglGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700449 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
450 pObjTrackGetObjs(XGL_OBJECT_TYPE_ANY, numObjects, pObjNodeArray);
451 for (i=0; i < numObjects; i++) {
452 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);
453 }
454 free(pObjNodeArray);
455#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700456
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600457}
458
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600459TEST_F(XglRenderTest, XGLTriangle_FragColor)
460{
461 static const char *vertShaderText =
462 "#version 140\n"
463 "#extension GL_ARB_separate_shader_objects : enable\n"
464 "#extension GL_ARB_shading_language_420pack : enable\n"
465 "\n"
466 "layout(binding = 0) uniform buf {\n"
467 " mat4 MVP;\n"
468 " vec4 position[3];\n"
469 " vec4 color[3];\n"
470 "} ubuf;\n"
471 "\n"
472 "layout (location = 0) out vec4 outColor;\n"
473 "\n"
474 "void main() \n"
475 "{\n"
476 " outColor = ubuf.color[gl_VertexID];\n"
477 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
478 "}\n";
479
480 static const char *fragShaderText =
481 "#version 140\n"
482 "#extension GL_ARB_separate_shader_objects : enable\n"
483 "#extension GL_ARB_shading_language_420pack : enable\n"
484 "\n"
485 "layout (location = 0) in vec4 inColor;\n"
486 "\n"
487 "void main()\n"
488 "{\n"
489 " gl_FragColor = inColor;\n"
490 "}\n";
491
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600492 TEST_DESCRIPTION("XGL-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
Tony Barbourae442072015-01-12 13:27:11 -0700493 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600494}
495
496TEST_F(XglRenderTest, XGLTriangle_OutputLocation)
497{
498 static const char *vertShaderText =
499 "#version 140\n"
500 "#extension GL_ARB_separate_shader_objects : enable\n"
501 "#extension GL_ARB_shading_language_420pack : enable\n"
502 "\n"
503 "layout(binding = 0) uniform buf {\n"
504 " mat4 MVP;\n"
505 " vec4 position[3];\n"
506 " vec4 color[3];\n"
507 "} ubuf;\n"
508 "\n"
509 "layout (location = 0) out vec4 outColor;\n"
510 "\n"
511 "void main() \n"
512 "{\n"
513 " outColor = ubuf.color[gl_VertexID];\n"
514 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
515 "}\n";
516
517 static const char *fragShaderText =
518 "#version 140\n"
519 "#extension GL_ARB_separate_shader_objects : enable\n"
520 "#extension GL_ARB_shading_language_420pack : enable\n"
521 "\n"
522 "layout (location = 0) in vec4 inColor;\n"
523 "layout (location = 0) out vec4 outColor;\n"
524 "\n"
525 "void main()\n"
526 "{\n"
527 " outColor = inColor;\n"
528 "}\n";
529
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600530 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 -0600531
Tony Barbourae442072015-01-12 13:27:11 -0700532 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600533}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600534#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 -0600535TEST_F(XglRenderTest, SPV_XGLTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700536{
Cody Northropacfb0492015-03-17 15:55:58 -0600537 bool saved_use_spv = XglTestFramework::m_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700538
539 static const char *vertShaderText =
540 "#version 140\n"
541 "#extension GL_ARB_separate_shader_objects : enable\n"
542 "#extension GL_ARB_shading_language_420pack : enable\n"
543 "\n"
544 "layout(binding = 0) uniform buf {\n"
545 " mat4 MVP;\n"
546 " vec4 position[3];\n"
547 " vec4 color[3];\n"
548 "} ubuf;\n"
549 "\n"
550 "layout (location = 0) out vec4 outColor;\n"
551 "\n"
552 "void main() \n"
553 "{\n"
554 " outColor = ubuf.color[gl_VertexID];\n"
555 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
556 "}\n";
557
558 static const char *fragShaderText =
559 "#version 140\n"
560 "#extension GL_ARB_separate_shader_objects : enable\n"
561 "#extension GL_ARB_shading_language_420pack : enable\n"
562 "\n"
563 "layout (location = 0) in vec4 inColor;\n"
564 "\n"
565 "void main()\n"
566 "{\n"
567 " gl_FragColor = inColor;\n"
568 "}\n";
569
Cody Northropacfb0492015-03-17 15:55:58 -0600570 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 -0700571
Cody Northropacfb0492015-03-17 15:55:58 -0600572 XglTestFramework::m_use_spv = true;
Tony Barbourf43b6982014-11-25 13:18:32 -0700573
Tony Barbourae442072015-01-12 13:27:11 -0700574 XGLTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700575
Cody Northropacfb0492015-03-17 15:55:58 -0600576 XglTestFramework::m_use_spv = saved_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700577}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600578#endif
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600579TEST_F(XglRenderTest, GreenTriangle)
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600580{
581 static const char *vertShaderText =
582 "#version 130\n"
583 "vec2 vertices[3];\n"
584 "void main() {\n"
585 " vertices[0] = vec2(-1.0, -1.0);\n"
586 " vertices[1] = vec2( 1.0, -1.0);\n"
587 " vertices[2] = vec2( 0.0, 1.0);\n"
588 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
589 "}\n";
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600590
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600591 static const char *fragShaderText =
592 "#version 130\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600593 "void main() {\n"
Steve K10b32512014-10-10 08:54:29 -0600594 " gl_FragColor = vec4(0,1,0,1);\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600595 "}\n";
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600596
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600597 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
598
Tony Barbourae442072015-01-12 13:27:11 -0700599 XGLTriangleTest(vertShaderText, fragShaderText, false);
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600600}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600601#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 -0600602TEST_F(XglRenderTest, SPV_GreenTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700603{
Cody Northropacfb0492015-03-17 15:55:58 -0600604 bool saved_use_spv = XglTestFramework::m_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700605
606 static const char *vertShaderText =
607 "#version 130\n"
608 "vec2 vertices[3];\n"
609 "void main() {\n"
610 " vertices[0] = vec2(-1.0, -1.0);\n"
611 " vertices[1] = vec2( 1.0, -1.0);\n"
612 " vertices[2] = vec2( 0.0, 1.0);\n"
613 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
614 "}\n";
615
616 static const char *fragShaderText =
617 "#version 130\n"
618 "void main() {\n"
619 " gl_FragColor = vec4(0,1,0,1);\n"
620 "}\n";
621
Cody Northropacfb0492015-03-17 15:55:58 -0600622 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700623
Cody Northropacfb0492015-03-17 15:55:58 -0600624 XglTestFramework::m_use_spv = true;
Tony Barbourae442072015-01-12 13:27:11 -0700625 XGLTriangleTest(vertShaderText, fragShaderText, false);
Cody Northropacfb0492015-03-17 15:55:58 -0600626 XglTestFramework::m_use_spv = saved_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700627}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600628#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700629TEST_F(XglRenderTest, YellowTriangle)
630{
631 static const char *vertShaderText =
632 "#version 130\n"
633 "void main() {\n"
634 " vec2 vertices[3];"
635 " vertices[0] = vec2(-0.5, -0.5);\n"
636 " vertices[1] = vec2( 0.5, -0.5);\n"
637 " vertices[2] = vec2( 0.5, 0.5);\n"
638 " vec4 colors[3];\n"
639 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
640 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
641 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
642 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
643 "}\n";
644
645 static const char *fragShaderText =
646 "#version 130\n"
647 "void main() {\n"
648 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
649 "}\n";
650
Tony Barbourae442072015-01-12 13:27:11 -0700651 XGLTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700652}
653
Courtney Goeltzenleuchter65da6e42015-03-31 16:38:46 -0600654TEST_F(XglRenderTest, QuadWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600655{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600656 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600657 "#version 140\n"
658 "#extension GL_ARB_separate_shader_objects : enable\n"
659 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700660 //XYZ1( -1, -1, -1 )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600661 "layout (location = 0) in vec4 pos;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700662 //XYZ1( 0.f, 0.f, 0.f )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600663 "layout (location = 1) in vec4 inColor;\n"
664 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600665 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600666 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600667 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600668 "}\n";
669
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600670
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600671 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700672 "#version 140\n"
673 "#extension GL_ARB_separate_shader_objects : enable\n"
674 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600675 "layout (location = 0) in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700676 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600677 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700678 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600679 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600680
Tony Barbourf43b6982014-11-25 13:18:32 -0700681
682
683 ASSERT_NO_FATAL_FAILURE(InitState());
684 ASSERT_NO_FATAL_FAILURE(InitViewport());
685
686 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000687 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700688
689 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
690 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
691
692 XglPipelineObj pipelineobj(m_device);
693 pipelineobj.AddShader(&vs);
694 pipelineobj.AddShader(&ps);
695
696 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +0800697 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700698
Mark Lobodzinski15427102015-02-18 16:38:17 -0600699 m_memoryRefManager.AddMemoryRef(&meshBuffer);
700
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600701#define MESH_BIND_ID 0
Tony Barbourf43b6982014-11-25 13:18:32 -0700702 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600703 MESH_BIND_ID, // binding ID
Tony Barbourf43b6982014-11-25 13:18:32 -0700704 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
705 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
706 };
707
708 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600709 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
710 vi_attribs[0].location = 0; // location, position
711 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
712 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
713 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
714 vi_attribs[1].location = 1; // location, color
715 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
716 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 -0700717
718 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
719 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600720 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -0700721
Tony Barboure4ed9942015-01-09 10:06:53 -0700722 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700723 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barboure4ed9942015-01-09 10:06:53 -0700724 XglCommandBufferObj cmdBuffer(m_device);
725 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700726
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600727 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
728
Tony Barboure4ed9942015-01-09 10:06:53 -0700729 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
730
Tony Barboure4ed9942015-01-09 10:06:53 -0700731 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
732
733 // render two triangles
734 cmdBuffer.Draw(0, 6, 0, 1);
735
736 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600737 EndCommandBuffer(cmdBuffer);
738
Mark Lobodzinski15427102015-02-18 16:38:17 -0600739 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barboure4ed9942015-01-09 10:06:53 -0700740
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600741 RecordImages(m_renderTargets);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600742}
743
Chia-I Wue09d1a72014-12-05 10:32:23 +0800744TEST_F(XglRenderTest, TriangleMRT)
745{
746 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600747 "#version 140\n"
748 "#extension GL_ARB_separate_shader_objects : enable\n"
749 "#extension GL_ARB_shading_language_420pack : enable\n"
750 "layout (location = 0) in vec4 pos;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800751 "void main() {\n"
752 " gl_Position = pos;\n"
753 "}\n";
754
755 static const char *fragShaderText =
756 "#version 130\n"
757 "void main() {\n"
758 " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
759 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
760 "}\n";
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600761 const float vb_data[][2] = {
Chia-I Wue09d1a72014-12-05 10:32:23 +0800762 { -1.0f, -1.0f },
763 { 1.0f, -1.0f },
764 { -1.0f, 1.0f }
765 };
766
767 ASSERT_NO_FATAL_FAILURE(InitState());
768 ASSERT_NO_FATAL_FAILURE(InitViewport());
769
770 XglConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000771 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800772
773 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
774 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
775
776 XglPipelineObj pipelineobj(m_device);
777 pipelineobj.AddShader(&vs);
778 pipelineobj.AddShader(&ps);
779
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600780#define MESH_BUF_ID 0
Chia-I Wue09d1a72014-12-05 10:32:23 +0800781 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600782 MESH_BUF_ID, // Binding ID
783 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
784 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Chia-I Wue09d1a72014-12-05 10:32:23 +0800785 };
786
787 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attrib;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600788 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
789 vi_attrib.location = 0;
790 vi_attrib.format = XGL_FMT_R32G32_SFLOAT; // format of source data
791 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
Chia-I Wue09d1a72014-12-05 10:32:23 +0800792
793 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
794 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600795 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800796
797 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -0600798 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800799
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700800 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
801 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Mark Lobodzinski15427102015-02-18 16:38:17 -0600802 m_memoryRefManager.AddMemoryRef(&meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800803
804 XGL_PIPELINE_CB_ATTACHMENT_STATE att = {};
805 att.blendEnable = XGL_FALSE;
806 att.format = m_render_target_fmt;
807 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700808 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800809
Tony Barbour5ed79702015-01-07 14:31:52 -0700810 XglCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700811
Tony Barbour5ed79702015-01-07 14:31:52 -0700812 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
813 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barboure4ed9942015-01-09 10:06:53 -0700814
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600815 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour5ed79702015-01-07 14:31:52 -0700816
Tony Barboure4ed9942015-01-09 10:06:53 -0700817 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
818
Tony Barbour5ed79702015-01-07 14:31:52 -0700819 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700820#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600821 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour5ed79702015-01-07 14:31:52 -0700822 pDSDumpDot((char*)"triTest2.dot");
823#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600824
Tony Barbour5ed79702015-01-07 14:31:52 -0700825 // render triangle
826 cmdBuffer.Draw(0, 3, 0, 1);
827
828 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600829 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -0600830 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbour5ed79702015-01-07 14:31:52 -0700831
Tony Barbour5ed79702015-01-07 14:31:52 -0700832
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600833 RecordImages(m_renderTargets);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800834}
835
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700836TEST_F(XglRenderTest, QuadWithIndexedVertexFetch)
837{
838 static const char *vertShaderText =
839 "#version 140\n"
840 "#extension GL_ARB_separate_shader_objects : enable\n"
841 "#extension GL_ARB_shading_language_420pack : enable\n"
842 "layout(location = 0) in vec4 pos;\n"
843 "layout(location = 1) in vec4 inColor;\n"
844 "layout(location = 0) out vec4 outColor;\n"
845 "void main() {\n"
846 " outColor = inColor;\n"
847 " gl_Position = pos;\n"
848 "}\n";
849
850
851 static const char *fragShaderText =
852 "#version 140\n"
853 "#extension GL_ARB_separate_shader_objects : enable\n"
854 "#extension GL_ARB_shading_language_420pack : enable\n"
855 "layout(location = 0) in vec4 color;\n"
856 "void main() {\n"
857 " gl_FragColor = color;\n"
858 "}\n";
859
860 const Vertex g_vbData[] =
861 {
862 // first tri
863 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
864 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
865 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
866
867 // second tri
868 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
869 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
870 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
871 };
872
873 const uint16_t g_idxData[6] = {
874 0, 1, 2,
875 3, 4, 5,
876 };
877
878 ASSERT_NO_FATAL_FAILURE(InitState());
879 ASSERT_NO_FATAL_FAILURE(InitViewport());
880
881 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000882 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700883
884 XglIndexBufferObj indexBuffer(m_device);
885 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), XGL_INDEX_16, g_idxData);
Mark Lobodzinskid30f82a2015-02-16 14:24:23 -0600886 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700887
888 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
889 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
890
891 XglPipelineObj pipelineobj(m_device);
892 pipelineobj.AddShader(&vs);
893 pipelineobj.AddShader(&ps);
894
895 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -0600896 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
897 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &indexBuffer);
898
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700899
Mark Lobodzinski15427102015-02-18 16:38:17 -0600900 m_memoryRefManager.AddMemoryRef(&meshBuffer);
901 m_memoryRefManager.AddMemoryRef(&indexBuffer);
902
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600903#define MESH_BIND_ID 0
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700904 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600905 MESH_BIND_ID, // binding ID
906 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
907 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700908 };
909
910 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600911 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
912 vi_attribs[0].location = 0; // layout location of vertex attribute
913 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
914 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
915 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
916 vi_attribs[1].location = 1; // layout location of vertex attribute
917 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
918 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700919
920 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
921 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700922
923 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700924 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700925 XglCommandBufferObj cmdBuffer(m_device);
926 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600927 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barboure4ed9942015-01-09 10:06:53 -0700928
929 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700930
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700931#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600932 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700933 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700934#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700935
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600936 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700937 cmdBuffer.BindIndexBuffer(&indexBuffer,0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700938
939 // render two triangles
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700940 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700941
942 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600943 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -0600944 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700945
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -0600946 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700947}
948
GregF6bef1212014-12-02 15:41:44 -0700949TEST_F(XglRenderTest, GreyandRedCirclesonBlue)
950{
951 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -0700952
GregF6bef1212014-12-02 15:41:44 -0700953 static const char *vertShaderText =
954 "#version 140\n"
955 "#extension GL_ARB_separate_shader_objects : enable\n"
956 "#extension GL_ARB_shading_language_420pack : enable\n"
957 "layout (location = 0) in vec4 pos;\n"
958 "layout (location = 0) out vec4 outColor;\n"
959 "layout (location = 1) out vec4 outColor2;\n"
960 "void main() {\n"
961 " gl_Position = pos;\n"
962 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
963 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
964 "}\n";
965
966 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -0700967 "#version 330\n"
968 "#extension GL_ARB_separate_shader_objects : enable\n"
969 "#extension GL_ARB_shading_language_420pack : enable\n"
970 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
971 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
972 "layout (location = 0) in vec4 color;\n"
973 "layout (location = 1) in vec4 color2;\n"
974 "void main() {\n"
975 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
976 " float dist_squared = dot(pos, pos);\n"
977 " gl_FragColor = (dist_squared < 400.0)\n"
978 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
979 " : color2;\n"
980 "}\n";
981
982 ASSERT_NO_FATAL_FAILURE(InitState());
983 ASSERT_NO_FATAL_FAILURE(InitViewport());
984
985 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000986 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -0700987
988 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
989 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
990
991 XglPipelineObj pipelineobj(m_device);
992 pipelineobj.AddShader(&vs);
993 pipelineobj.AddShader(&ps);
994
995 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +0800996 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -0700997
Mark Lobodzinski15427102015-02-18 16:38:17 -0600998 m_memoryRefManager.AddMemoryRef(&meshBuffer);
999
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001000#define MESH_BIND_ID 0
GregF6bef1212014-12-02 15:41:44 -07001001 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001002 MESH_BIND_ID, // binding ID
1003 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1004 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001005 };
1006
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001007 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[1];
1008 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1009 vi_attribs[0].location = 0;
1010 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
1011 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001012
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001013 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001014 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001015 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001016
Tony Barbourdd4c9642015-01-09 12:55:14 -07001017 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001018 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001019 XglCommandBufferObj cmdBuffer(m_device);
1020 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1021
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001022 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001023
1024 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1025
1026 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1027#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001028 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001029 pDSDumpDot((char*)"triTest2.dot");
1030#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001031
Tony Barbourdd4c9642015-01-09 12:55:14 -07001032 // render triangle
1033 cmdBuffer.Draw(0, 6, 0, 1);
1034
1035 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001036 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001037 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001038
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001039 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001040}
1041
1042TEST_F(XglRenderTest, RedCirclesonBlue)
1043{
1044 // This tests that we correctly handle unread fragment inputs
1045
1046 static const char *vertShaderText =
1047 "#version 140\n"
1048 "#extension GL_ARB_separate_shader_objects : enable\n"
1049 "#extension GL_ARB_shading_language_420pack : enable\n"
1050 "layout (location = 0) in vec4 pos;\n"
1051 "layout (location = 0) out vec4 outColor;\n"
1052 "layout (location = 1) out vec4 outColor2;\n"
1053 "void main() {\n"
1054 " gl_Position = pos;\n"
1055 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1056 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1057 "}\n";
1058
1059 static const char *fragShaderText =
GregF6bef1212014-12-02 15:41:44 -07001060 "#version 330\n"
1061 "#extension GL_ARB_separate_shader_objects : enable\n"
1062 "#extension GL_ARB_shading_language_420pack : enable\n"
1063 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1064 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1065 "layout (location = 0) in vec4 color;\n"
1066 "layout (location = 1) in vec4 color2;\n"
1067 "void main() {\n"
1068 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1069 " float dist_squared = dot(pos, pos);\n"
1070 " gl_FragColor = (dist_squared < 400.0)\n"
1071 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1072 " : color2;\n"
1073 "}\n";
1074
1075 ASSERT_NO_FATAL_FAILURE(InitState());
1076 ASSERT_NO_FATAL_FAILURE(InitViewport());
1077
1078 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001079 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001080
1081 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1082 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1083
1084 XglPipelineObj pipelineobj(m_device);
1085 pipelineobj.AddShader(&vs);
1086 pipelineobj.AddShader(&ps);
1087
1088 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001089 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001090
Mark Lobodzinski15427102015-02-18 16:38:17 -06001091 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1092
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001093#define MESH_BIND_ID 0
GregF6bef1212014-12-02 15:41:44 -07001094 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001095 MESH_BIND_ID, // binding ID
1096 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1097 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001098 };
1099
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001100 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[1];
1101 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1102 vi_attribs[0].location = 0;
1103 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
1104 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001105
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001106 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001107 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001108 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001109
Tony Barbourdd4c9642015-01-09 12:55:14 -07001110 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001111 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001112 XglCommandBufferObj cmdBuffer(m_device);
1113 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1114
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001115 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001116
1117 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1118
1119 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1120#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001121 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001122 pDSDumpDot((char*)"triTest2.dot");
1123#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001124 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001125 cmdBuffer.Draw(0, 6, 0, 1);
1126
1127 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001128 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001129 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001130
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001131 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001132}
1133
1134TEST_F(XglRenderTest, GreyCirclesonBlueFade)
1135{
1136 // This tests reading gl_ClipDistance from FS
1137
1138 static const char *vertShaderText =
1139 "#version 330\n"
1140 "#extension GL_ARB_separate_shader_objects : enable\n"
1141 "#extension GL_ARB_shading_language_420pack : enable\n"
1142 "out gl_PerVertex {\n"
1143 " vec4 gl_Position;\n"
1144 " float gl_ClipDistance[1];\n"
1145 "};\n"
1146 "layout (location = 0) in vec4 pos;\n"
1147 "layout (location = 0) out vec4 outColor;\n"
1148 "layout (location = 1) out vec4 outColor2;\n"
1149 "void main() {\n"
1150 " gl_Position = pos;\n"
1151 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1152 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1153 " float dists[3];\n"
1154 " dists[0] = 0.0;\n"
1155 " dists[1] = 1.0;\n"
1156 " dists[2] = 1.0;\n"
1157 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1158 "}\n";
1159
1160
1161 static const char *fragShaderText =
1162 //"#version 140\n"
1163 "#version 330\n"
1164 "#extension GL_ARB_separate_shader_objects : enable\n"
1165 "#extension GL_ARB_shading_language_420pack : enable\n"
1166 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1167 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1168 "layout (location = 0) in vec4 color;\n"
1169 "layout (location = 1) in vec4 color2;\n"
1170 "void main() {\n"
1171 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1172 " float dist_squared = dot(pos, pos);\n"
1173 " gl_FragColor = (dist_squared < 400.0)\n"
1174 " ? color * gl_ClipDistance[0]\n"
1175 " : color2;\n"
1176 "}\n";
1177
1178 ASSERT_NO_FATAL_FAILURE(InitState());
1179 ASSERT_NO_FATAL_FAILURE(InitViewport());
1180
1181 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001182 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001183
1184 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1185 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1186
1187 XglPipelineObj pipelineobj(m_device);
1188 pipelineobj.AddShader(&vs);
1189 pipelineobj.AddShader(&ps);
1190
1191 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001192 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001193
Mark Lobodzinski15427102015-02-18 16:38:17 -06001194 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1195
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001196#define MESH_BIND_ID 0
GregF6bef1212014-12-02 15:41:44 -07001197 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001198 MESH_BIND_ID, // binding ID
1199 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1200 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001201 };
1202
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001203 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[1];
1204 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1205 vi_attribs[0].location = 0;
1206 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
1207 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001208
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001209 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001210 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001211 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001212
Tony Barbourdd4c9642015-01-09 12:55:14 -07001213 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001214 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001215 XglCommandBufferObj cmdBuffer(m_device);
1216 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF6bef1212014-12-02 15:41:44 -07001217
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001218 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001219
1220 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1221
1222 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1223#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001224 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001225 pDSDumpDot((char*)"triTest2.dot");
1226#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001227
1228 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001229 cmdBuffer.Draw(0, 6, 0, 1);
1230
1231 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001232 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001233 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001234
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001235 RecordImages(m_renderTargets);
GregF6bef1212014-12-02 15:41:44 -07001236}
Tony Barbourf43b6982014-11-25 13:18:32 -07001237
GregF7a23c792014-12-02 17:19:34 -07001238TEST_F(XglRenderTest, GreyCirclesonBlueDiscard)
1239{
1240 static const char *vertShaderText =
1241 "#version 140\n"
1242 "#extension GL_ARB_separate_shader_objects : enable\n"
1243 "#extension GL_ARB_shading_language_420pack : enable\n"
1244 "layout (location = 0) in vec4 pos;\n"
1245 "layout (location = 0) out vec4 outColor;\n"
1246 "layout (location = 1) out vec4 outColor2;\n"
1247 "void main() {\n"
1248 " gl_Position = pos;\n"
1249 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1250 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1251 "}\n";
1252
1253
1254 static const char *fragShaderText =
GregF7a23c792014-12-02 17:19:34 -07001255 "#version 330\n"
1256 "#extension GL_ARB_separate_shader_objects : enable\n"
1257 "#extension GL_ARB_shading_language_420pack : enable\n"
1258 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1259 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1260 "layout (location = 0) in vec4 color;\n"
1261 "layout (location = 1) in vec4 color2;\n"
1262 "void main() {\n"
1263 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1264 " float dist_squared = dot(pos, pos);\n"
1265 " if (dist_squared < 100.0)\n"
1266 " discard;\n"
1267 " gl_FragColor = (dist_squared < 400.0)\n"
1268 " ? color\n"
1269 " : color2;\n"
1270 "}\n";
1271
1272 ASSERT_NO_FATAL_FAILURE(InitState());
1273 ASSERT_NO_FATAL_FAILURE(InitViewport());
1274
1275 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001276 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001277
1278 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1279 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1280
1281 XglPipelineObj pipelineobj(m_device);
1282 pipelineobj.AddShader(&vs);
1283 pipelineobj.AddShader(&ps);
1284
1285 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001286 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF7a23c792014-12-02 17:19:34 -07001287
Mark Lobodzinski15427102015-02-18 16:38:17 -06001288 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1289
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001290#define MESH_BIND_ID 0
GregF7a23c792014-12-02 17:19:34 -07001291 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001292 MESH_BIND_ID, // binding ID
1293 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1294 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF7a23c792014-12-02 17:19:34 -07001295 };
1296
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001297 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[1];
1298 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1299 vi_attribs[0].location = 0;
1300 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
1301 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF7a23c792014-12-02 17:19:34 -07001302
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001303 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF7a23c792014-12-02 17:19:34 -07001304 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001305 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF7a23c792014-12-02 17:19:34 -07001306
Tony Barbourdd4c9642015-01-09 12:55:14 -07001307 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001308 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001309 XglCommandBufferObj cmdBuffer(m_device);
1310 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1311
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001312 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001313
1314 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1315
1316 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1317#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001318 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001319 pDSDumpDot((char*)"triTest2.dot");
1320#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001321
1322 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001323 cmdBuffer.Draw(0, 6, 0, 1);
1324
1325 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001326 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001327 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001328
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001329 RecordImages(m_renderTargets);
GregF7a23c792014-12-02 17:19:34 -07001330}
1331
1332
Courtney Goeltzenleuchter3d10c9c2014-10-27 13:06:08 -06001333TEST_F(XglRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001334{
1335 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001336 "#version 140\n"
1337 "#extension GL_ARB_separate_shader_objects : enable\n"
1338 "#extension GL_ARB_shading_language_420pack : enable\n"
1339 "\n"
1340 "layout(binding = 0) uniform buf {\n"
1341 " mat4 MVP;\n"
1342 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001343 "void main() {\n"
1344 " vec2 vertices[3];"
1345 " vertices[0] = vec2(-0.5, -0.5);\n"
1346 " vertices[1] = vec2( 0.5, -0.5);\n"
1347 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001348 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001349 "}\n";
1350
1351 static const char *fragShaderText =
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001352 "#version 130\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001353 "void main() {\n"
Cody Northrop78eac042014-10-10 15:45:00 -06001354 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001355 "}\n";
1356
Tony Barbourf43b6982014-11-25 13:18:32 -07001357 ASSERT_NO_FATAL_FAILURE(InitState());
1358 ASSERT_NO_FATAL_FAILURE(InitViewport());
1359
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001360 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001361 glm::mat4 Projection = glm::mat4(1.0f);
1362 glm::mat4 View = glm::mat4(1.0f);
1363 glm::mat4 Model = glm::mat4(1.0f);
1364 glm::mat4 MVP = Projection * View * Model;
1365 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1366
Tony Barbourf43b6982014-11-25 13:18:32 -07001367 XglConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1368 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1369 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001370
Tony Barbourf43b6982014-11-25 13:18:32 -07001371 XglPipelineObj pipelineobj(m_device);
1372 pipelineobj.AddShader(&vs);
1373 pipelineobj.AddShader(&ps);
1374
1375 // Create descriptor set and attach the constant buffer to it
1376 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001377 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001378
1379 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1380
Tony Barbourdd4c9642015-01-09 12:55:14 -07001381 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001382 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001383 XglCommandBufferObj cmdBuffer(m_device);
1384 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001385
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001386 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001387
1388 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1389
1390 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1391#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001392 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001393 pDSDumpDot((char*)"triTest2.dot");
1394#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001395
1396 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001397 cmdBuffer.Draw(0, 6, 0, 1);
1398
1399 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001400 EndCommandBuffer(cmdBuffer);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001401 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
1402
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001403 RecordImages(m_renderTargets);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001404
1405 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001406}
1407
Tony Barbourf43b6982014-11-25 13:18:32 -07001408TEST_F(XglRenderTest, MixTriangle)
1409{
1410 // This tests location applied to varyings. Notice that we have switched foo
1411 // and bar in the FS. The triangle should be blended with red, green and blue
1412 // corners.
1413 static const char *vertShaderText =
1414 "#version 140\n"
1415 "#extension GL_ARB_separate_shader_objects : enable\n"
1416 "#extension GL_ARB_shading_language_420pack : enable\n"
1417 "layout (location=0) out vec4 bar;\n"
1418 "layout (location=1) out vec4 foo;\n"
1419 "layout (location=2) out float scale;\n"
1420 "vec2 vertices[3];\n"
1421 "void main() {\n"
1422 " vertices[0] = vec2(-1.0, -1.0);\n"
1423 " vertices[1] = vec2( 1.0, -1.0);\n"
1424 " vertices[2] = vec2( 0.0, 1.0);\n"
1425 "vec4 colors[3];\n"
1426 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1427 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1428 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1429 " foo = colors[gl_VertexID % 3];\n"
1430 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1431 " scale = 1.0;\n"
1432 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1433 "}\n";
1434
1435 static const char *fragShaderText =
1436 "#version 140\n"
1437 "#extension GL_ARB_separate_shader_objects : enable\n"
1438 "#extension GL_ARB_shading_language_420pack : enable\n"
1439 "layout (location = 1) in vec4 bar;\n"
1440 "layout (location = 0) in vec4 foo;\n"
1441 "layout (location = 2) in float scale;\n"
1442 "void main() {\n"
1443 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
1444 "}\n";
1445
1446 ASSERT_NO_FATAL_FAILURE(InitState());
1447 ASSERT_NO_FATAL_FAILURE(InitViewport());
1448
1449 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1450 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1451
1452 XglPipelineObj pipelineobj(m_device);
1453 pipelineobj.AddShader(&vs);
1454 pipelineobj.AddShader(&ps);
1455
1456 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06001457 descriptorSet.AppendDummy();
Tony Barbourf43b6982014-11-25 13:18:32 -07001458
Tony Barbourdd4c9642015-01-09 12:55:14 -07001459 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001460 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001461 XglCommandBufferObj cmdBuffer(m_device);
1462 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1463
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001464 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001465
1466 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1467
1468#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001469 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001470 pDSDumpDot((char*)"triTest2.dot");
1471#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001472
Tony Barbourdd4c9642015-01-09 12:55:14 -07001473 // render triangle
1474 cmdBuffer.Draw(0, 3, 0, 1);
1475
1476 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001477 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001478 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001479
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001480 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001481}
1482
Courtney Goeltzenleuchter65da6e42015-03-31 16:38:46 -06001483TEST_F(XglRenderTest, QuadVertFetchAndVertID)
Tony Barbourf43b6982014-11-25 13:18:32 -07001484{
1485 // This tests that attributes work in the presence of gl_VertexID
1486
1487 static const char *vertShaderText =
1488 "#version 140\n"
1489 "#extension GL_ARB_separate_shader_objects : enable\n"
1490 "#extension GL_ARB_shading_language_420pack : enable\n"
1491 //XYZ1( -1, -1, -1 )
1492 "layout (location = 0) in vec4 pos;\n"
1493 //XYZ1( 0.f, 0.f, 0.f )
1494 "layout (location = 1) in vec4 inColor;\n"
1495 "layout (location = 0) out vec4 outColor;\n"
1496 "void main() {\n"
1497 " outColor = inColor;\n"
1498 " vec4 vertices[3];"
1499 " vertices[gl_VertexID % 3] = pos;\n"
1500 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1501 "}\n";
1502
1503
1504 static const char *fragShaderText =
1505 "#version 140\n"
1506 "#extension GL_ARB_separate_shader_objects : enable\n"
1507 "#extension GL_ARB_shading_language_420pack : enable\n"
1508 "layout (location = 0) in vec4 color;\n"
1509 "void main() {\n"
1510 " gl_FragColor = color;\n"
1511 "}\n";
1512
1513 ASSERT_NO_FATAL_FAILURE(InitState());
1514 ASSERT_NO_FATAL_FAILURE(InitViewport());
1515
1516 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001517 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001518
1519 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1520 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1521
1522 XglPipelineObj pipelineobj(m_device);
1523 pipelineobj.AddShader(&vs);
1524 pipelineobj.AddShader(&ps);
1525
1526 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001527 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001528
Mark Lobodzinski15427102015-02-18 16:38:17 -06001529 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1530
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001531#define MESH_BUF_ID 0
Tony Barbourf43b6982014-11-25 13:18:32 -07001532 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001533 MESH_BUF_ID, // Binding ID
1534 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1535 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001536 };
1537
1538 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001539 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1540 vi_attribs[0].location = 0;
1541 vi_attribs[0].format = XGL_FMT_R32G32_SFLOAT; // format of source data
1542 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1543 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1544 vi_attribs[1].location = 1;
1545 vi_attribs[1].format = XGL_FMT_R32G32_SFLOAT; // format of source data
1546 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001547
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001548 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001549 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001550 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001551
Tony Barbourdd4c9642015-01-09 12:55:14 -07001552 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001553 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001554 XglCommandBufferObj cmdBuffer(m_device);
1555 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1556
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001557 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001558
1559 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1560
1561 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1562#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001563 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001564 pDSDumpDot((char*)"triTest2.dot");
1565#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001566
1567 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001568 cmdBuffer.Draw(0, 6, 0, 1);
1569
1570 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001571 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001572 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001573
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001574 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001575}
1576
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001577TEST_F(XglRenderTest, QuadSparseVertFetch)
1578{
1579 // This tests that attributes work in the presence of gl_VertexID
1580
1581 static const char *vertShaderText =
1582 "#version 140\n"
1583 "#extension GL_ARB_separate_shader_objects : enable\n"
1584 "#extension GL_ARB_shading_language_420pack : enable\n"
1585 //XYZ1( -1, -1, -1 )
1586 "layout (location = 1) in vec4 pos;\n"
1587 "layout (location = 4) in vec4 inColor;\n"
1588 //XYZ1( 0.f, 0.f, 0.f )
1589 "layout (location = 0) out vec4 outColor;\n"
1590 "void main() {\n"
1591 " outColor = inColor;\n"
1592 " gl_Position = pos;\n"
1593 "}\n";
1594
1595
1596 static const char *fragShaderText =
1597 "#version 140\n"
1598 "#extension GL_ARB_separate_shader_objects : enable\n"
1599 "#extension GL_ARB_shading_language_420pack : enable\n"
1600 "layout (location = 0) in vec4 color;\n"
1601 "void main() {\n"
1602 " gl_FragColor = color;\n"
1603 "}\n";
1604
1605 ASSERT_NO_FATAL_FAILURE(InitState());
1606 ASSERT_NO_FATAL_FAILURE(InitViewport());
1607
1608 struct VDATA
1609 {
1610 float t1, t2, t3, t4; // filler data
1611 float posX, posY, posZ, posW; // Position data
1612 float r, g, b, a; // Color
1613 };
1614 const struct VDATA vData[] =
1615 {
1616 { XYZ1(0, 0, 0), XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
1617 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1618 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1619 { XYZ1(0, 0, 0), XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
1620 { XYZ1(0, 0, 0), XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
1621 { XYZ1(0, 0, 0), XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
1622 };
1623
1624 XglConstantBufferObj meshBuffer(m_device,sizeof(vData)/sizeof(vData[0]),sizeof(vData[0]), vData);
1625 meshBuffer.BufferMemoryBarrier();
1626
1627 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1628 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1629
1630 XglPipelineObj pipelineobj(m_device);
1631 pipelineobj.AddShader(&vs);
1632 pipelineobj.AddShader(&ps);
1633
1634 XglDescriptorSetObj descriptorSet(m_device);
1635 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
1636
1637 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1638
1639#define MESH_BUF_ID 0
1640 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1641 MESH_BUF_ID, // Binding ID
1642 sizeof(vData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1643 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1644 };
1645
1646 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1647 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1648 vi_attribs[0].location = 4;
1649 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
1650 vi_attribs[0].offsetInBytes = sizeof(float) * 4 * 2; // Offset of first element in bytes from base of vertex
1651 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1652 vi_attribs[1].location = 1;
1653 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
1654 vi_attribs[1].offsetInBytes = sizeof(float) * 4 * 1; // Offset of first element in bytes from base of vertex
1655
1656 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
1657 pipelineobj.AddVertexInputBindings(&vi_binding, 1);
1658 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
1659
1660 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1661 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
1662 XglCommandBufferObj cmdBuffer(m_device);
1663 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1664
1665 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
1666
1667 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1668
1669 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BUF_ID);
1670#ifdef DUMP_STATE_DOT
1671 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
1672 pDSDumpDot((char*)"triTest2.dot");
1673#endif
1674
1675 // render two triangles
1676 cmdBuffer.Draw(0, 6, 0, 1);
1677
1678 // finalize recording of the command buffer
1679 EndCommandBuffer(cmdBuffer);
1680 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
1681
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001682 RecordImages(m_renderTargets);
Courtney Goeltzenleuchter3bf666d2015-03-31 16:39:32 -06001683}
1684
Tony Barbourf43b6982014-11-25 13:18:32 -07001685TEST_F(XglRenderTest, TriVertFetchDeadAttr)
1686{
1687 // This tests that attributes work in the presence of gl_VertexID
1688 // and a dead attribute in position 0. Draws a triangle with yellow,
1689 // red and green corners, starting at top and going clockwise.
1690
1691 static const char *vertShaderText =
1692 "#version 140\n"
1693 "#extension GL_ARB_separate_shader_objects : enable\n"
1694 "#extension GL_ARB_shading_language_420pack : enable\n"
1695 //XYZ1( -1, -1, -1 )
1696 "layout (location = 0) in vec4 pos;\n"
1697 //XYZ1( 0.f, 0.f, 0.f )
1698 "layout (location = 1) in vec4 inColor;\n"
1699 "layout (location = 0) out vec4 outColor;\n"
1700 "void main() {\n"
1701 " outColor = inColor;\n"
1702 " vec2 vertices[3];"
1703 " vertices[0] = vec2(-1.0, -1.0);\n"
1704 " vertices[1] = vec2( 1.0, -1.0);\n"
1705 " vertices[2] = vec2( 0.0, 1.0);\n"
1706 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1707 "}\n";
1708
1709
1710 static const char *fragShaderText =
1711 "#version 140\n"
1712 "#extension GL_ARB_separate_shader_objects : enable\n"
1713 "#extension GL_ARB_shading_language_420pack : enable\n"
1714 "layout (location = 0) in vec4 color;\n"
1715 "void main() {\n"
1716 " gl_FragColor = color;\n"
1717 "}\n";
1718
1719 ASSERT_NO_FATAL_FAILURE(InitState());
1720 ASSERT_NO_FATAL_FAILURE(InitViewport());
1721
1722 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001723 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001724
1725 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1726 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1727
1728 XglPipelineObj pipelineobj(m_device);
1729 pipelineobj.AddShader(&vs);
1730 pipelineobj.AddShader(&ps);
1731
1732 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001733 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001734
Mark Lobodzinski15427102015-02-18 16:38:17 -06001735 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1736
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001737#define MESH_BUF_ID 0
Tony Barbourf43b6982014-11-25 13:18:32 -07001738 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001739 MESH_BUF_ID, // Binding ID
1740 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1741 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001742 };
1743
1744 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001745 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1746 vi_attribs[0].location = 0;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001747 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001748 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1749 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1750 vi_attribs[1].location = 1;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001751 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001752 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001753
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001754 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001755 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001756 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001757
Tony Barbourdd4c9642015-01-09 12:55:14 -07001758 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001759 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001760 XglCommandBufferObj cmdBuffer(m_device);
1761 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001762
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001763 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001764
1765 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1766
1767 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1768#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001769 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001770 pDSDumpDot((char*)"triTest2.dot");
1771#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001772
1773 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001774 cmdBuffer.Draw(0, 6, 0, 1);
1775
1776 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001777 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001778 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001779
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001780 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001781}
1782
1783TEST_F(XglRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001784{
1785 static const char *vertShaderText =
1786 "#version 140\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001787 "#extension GL_ARB_separate_shader_objects : enable\n"
1788 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001789 "layout (std140) uniform bufferVals {\n"
1790 " mat4 mvp;\n"
1791 "} myBufferVals;\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001792 "layout (location = 0) in vec4 pos;\n"
1793 "layout (location = 1) in vec4 inColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001794 "out vec4 outColor;\n"
1795 "void main() {\n"
1796 " outColor = inColor;\n"
1797 " gl_Position = myBufferVals.mvp * pos;\n"
1798 "}\n";
1799
1800 static const char *fragShaderText =
1801 "#version 130\n"
1802 "in vec4 color;\n"
1803 "void main() {\n"
1804 " gl_FragColor = color;\n"
1805 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001806 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001807
Tony Barbourf43b6982014-11-25 13:18:32 -07001808 glm::mat4 View = glm::lookAt(
1809 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1810 glm::vec3(0,0,0), // and looks at the origin
1811 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
1812 );
1813
1814 glm::mat4 Model = glm::mat4(1.0f);
1815
1816 glm::mat4 MVP = Projection * View * Model;
1817
1818 ASSERT_NO_FATAL_FAILURE(InitState());
1819 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour17c6ab12015-03-27 17:03:18 -06001820 m_depthStencil->Init(m_device, m_width, m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07001821
1822 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
1823 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1824
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001825 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07001826
1827 XglConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1828 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1829 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1830
Tony Barbourf43b6982014-11-25 13:18:32 -07001831 XglPipelineObj pipelineobj(m_device);
1832 pipelineobj.AddShader(&vs);
1833 pipelineobj.AddShader(&ps);
1834
Tony Barbourfa6cac72015-01-16 14:27:35 -07001835 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
1836 ds_state.depthTestEnable = XGL_TRUE;
1837 ds_state.depthWriteEnable = XGL_TRUE;
1838 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
1839 ds_state.depthBoundsEnable = XGL_FALSE;
1840 ds_state.stencilTestEnable = XGL_FALSE;
1841 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
1842 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
1843 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
1844 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001845 ds_state.format = XGL_FMT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001846 ds_state.front = ds_state.back;
1847 pipelineobj.SetDepthStencil(&ds_state);
1848
Tony Barbourf43b6982014-11-25 13:18:32 -07001849 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001850 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001851
1852 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1853 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
Tony Barbour17c6ab12015-03-27 17:03:18 -06001854 m_memoryRefManager.AddMemoryRef(m_depthStencil);
Tony Barbourf43b6982014-11-25 13:18:32 -07001855
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001856#define MESH_BUF_ID 0
Tony Barbourf43b6982014-11-25 13:18:32 -07001857 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001858 MESH_BUF_ID, // Binding ID
1859 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1860 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1861 };
Tony Barbourf43b6982014-11-25 13:18:32 -07001862
Tony Barbourf43b6982014-11-25 13:18:32 -07001863 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001864 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1865 vi_attribs[0].location = 0;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001866 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001867 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1868 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1869 vi_attribs[1].location = 1;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001870 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001871 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001872
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001873 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001874 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001875 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001876
Tony Barbour17c6ab12015-03-27 17:03:18 -06001877 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001878 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbour17c6ab12015-03-27 17:03:18 -06001879
Tony Barboure4ed9942015-01-09 10:06:53 -07001880 XglCommandBufferObj cmdBuffer(m_device);
1881 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001882
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001883 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barboure4ed9942015-01-09 10:06:53 -07001884 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001885
Tony Barboure4ed9942015-01-09 10:06:53 -07001886 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1887#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001888 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barboure4ed9942015-01-09 10:06:53 -07001889 pDSDumpDot((char*)"triTest2.dot");
1890#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001891
1892 // render triangles
Tony Barboure4ed9942015-01-09 10:06:53 -07001893 cmdBuffer.Draw(0, 36, 0, 1);
1894
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001895
Tony Barboure4ed9942015-01-09 10:06:53 -07001896 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001897 EndCommandBuffer(cmdBuffer);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001898 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barboure4ed9942015-01-09 10:06:53 -07001899
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001900 RecordImages(m_renderTargets);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001901}
1902
Tony Barbourf43b6982014-11-25 13:18:32 -07001903TEST_F(XglRenderTest, VSTexture)
1904{
1905 // The expected result from this test is a green and red triangle;
1906 // one red vertex on the left, two green vertices on the right.
1907 static const char *vertShaderText =
1908 "#version 130\n"
1909 "out vec4 texColor;\n"
1910 "uniform sampler2D surface;\n"
1911 "void main() {\n"
1912 " vec2 vertices[3];"
1913 " vertices[0] = vec2(-0.5, -0.5);\n"
1914 " vertices[1] = vec2( 0.5, -0.5);\n"
1915 " vertices[2] = vec2( 0.5, 0.5);\n"
1916 " vec2 positions[3];"
1917 " positions[0] = vec2( 0.0, 0.0);\n"
1918 " positions[1] = vec2( 0.25, 0.1);\n"
1919 " positions[2] = vec2( 0.1, 0.25);\n"
1920 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1921 " texColor = textureLod(surface, samplePos, 0.0);\n"
1922 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1923 "}\n";
1924
1925 static const char *fragShaderText =
1926 "#version 130\n"
1927 "in vec4 texColor;\n"
1928 "void main() {\n"
1929 " gl_FragColor = texColor;\n"
1930 "}\n";
1931
1932 ASSERT_NO_FATAL_FAILURE(InitState());
1933 ASSERT_NO_FATAL_FAILURE(InitViewport());
1934
1935 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1936 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1937 XglSamplerObj sampler(m_device);
1938 XglTextureObj texture(m_device);
1939
Tony Barbourf43b6982014-11-25 13:18:32 -07001940 XglPipelineObj pipelineobj(m_device);
1941 pipelineobj.AddShader(&vs);
1942 pipelineobj.AddShader(&ps);
1943
1944 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001945 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001946
1947 m_memoryRefManager.AddMemoryRef(&texture);
1948
Tony Barbourdd4c9642015-01-09 12:55:14 -07001949 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001950 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001951 XglCommandBufferObj cmdBuffer(m_device);
1952 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001953
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001954 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001955
1956 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1957
1958#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001959 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001960 pDSDumpDot((char*)"triTest2.dot");
1961#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001962
Tony Barbourdd4c9642015-01-09 12:55:14 -07001963 // render triangle
1964 cmdBuffer.Draw(0, 3, 0, 1);
1965
1966 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001967 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001968 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001969
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06001970 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07001971}
1972TEST_F(XglRenderTest, TexturedTriangle)
1973{
1974 // The expected result from this test is a red and green checkered triangle
1975 static const char *vertShaderText =
1976 "#version 140\n"
1977 "#extension GL_ARB_separate_shader_objects : enable\n"
1978 "#extension GL_ARB_shading_language_420pack : enable\n"
1979 "layout (location = 0) out vec2 samplePos;\n"
1980 "void main() {\n"
1981 " vec2 vertices[3];"
1982 " vertices[0] = vec2(-0.5, -0.5);\n"
1983 " vertices[1] = vec2( 0.5, -0.5);\n"
1984 " vertices[2] = vec2( 0.5, 0.5);\n"
1985 " vec2 positions[3];"
1986 " positions[0] = vec2( 0.0, 0.0);\n"
1987 " positions[1] = vec2( 1.0, 0.0);\n"
1988 " positions[2] = vec2( 1.0, 1.0);\n"
1989 " samplePos = positions[gl_VertexID % 3];\n"
1990 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1991 "}\n";
1992
1993 static const char *fragShaderText =
1994 "#version 140\n"
1995 "#extension GL_ARB_separate_shader_objects : enable\n"
1996 "#extension GL_ARB_shading_language_420pack : enable\n"
1997 "layout (location = 0) in vec2 samplePos;\n"
1998 "layout (binding = 0) uniform sampler2D surface;\n"
1999 "layout (location=0) out vec4 outColor;\n"
2000 "void main() {\n"
2001 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2002 " outColor = texColor;\n"
2003 "}\n";
2004
2005 ASSERT_NO_FATAL_FAILURE(InitState());
2006 ASSERT_NO_FATAL_FAILURE(InitViewport());
2007
2008 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2009 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2010 XglSamplerObj sampler(m_device);
2011 XglTextureObj texture(m_device);
2012
Tony Barbourf43b6982014-11-25 13:18:32 -07002013 XglPipelineObj pipelineobj(m_device);
2014 pipelineobj.AddShader(&vs);
2015 pipelineobj.AddShader(&ps);
2016
2017 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002018 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002019
2020 m_memoryRefManager.AddMemoryRef(&texture);
2021
Tony Barbourdd4c9642015-01-09 12:55:14 -07002022 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002023 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002024 XglCommandBufferObj cmdBuffer(m_device);
2025 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2026
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002027 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002028
2029 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2030
2031#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002032 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002033 pDSDumpDot((char*)"triTest2.dot");
2034#endif
2035 // render triangle
2036 cmdBuffer.Draw(0, 3, 0, 1);
2037
2038 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002039 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002040 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002041
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002042 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002043}
2044TEST_F(XglRenderTest, TexturedTriangleClip)
2045{
2046 // The expected result from this test is a red and green checkered triangle
2047 static const char *vertShaderText =
2048 "#version 330\n"
2049 "#extension GL_ARB_separate_shader_objects : enable\n"
2050 "#extension GL_ARB_shading_language_420pack : enable\n"
2051 "layout (location = 0) out vec2 samplePos;\n"
2052 "out gl_PerVertex {\n"
2053 " vec4 gl_Position;\n"
2054 " float gl_ClipDistance[1];\n"
2055 "};\n"
2056 "void main() {\n"
2057 " vec2 vertices[3];"
2058 " vertices[0] = vec2(-0.5, -0.5);\n"
2059 " vertices[1] = vec2( 0.5, -0.5);\n"
2060 " vertices[2] = vec2( 0.5, 0.5);\n"
2061 " vec2 positions[3];"
2062 " positions[0] = vec2( 0.0, 0.0);\n"
2063 " positions[1] = vec2( 1.0, 0.0);\n"
2064 " positions[2] = vec2( 1.0, 1.0);\n"
2065 " float dists[3];\n"
2066 " dists[0] = 1.0;\n"
2067 " dists[1] = 1.0;\n"
2068 " dists[2] = -1.0;\n"
2069 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2070 " samplePos = positions[gl_VertexID % 3];\n"
2071 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2072 "}\n";
2073
2074 static const char *fragShaderText =
2075 "#version 140\n"
2076 "#extension GL_ARB_separate_shader_objects : enable\n"
2077 "#extension GL_ARB_shading_language_420pack : enable\n"
2078 "layout (location = 0) in vec2 samplePos;\n"
2079 "layout (binding = 0) uniform sampler2D surface;\n"
2080 "layout (location=0) out vec4 outColor;\n"
2081 "void main() {\n"
2082 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2083 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2084 " outColor = texColor;\n"
2085 "}\n";
2086
2087
2088 ASSERT_NO_FATAL_FAILURE(InitState());
2089 ASSERT_NO_FATAL_FAILURE(InitViewport());
2090
2091 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2092 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2093 XglSamplerObj sampler(m_device);
2094 XglTextureObj texture(m_device);
2095
Tony Barbourf43b6982014-11-25 13:18:32 -07002096 XglPipelineObj pipelineobj(m_device);
2097 pipelineobj.AddShader(&vs);
2098 pipelineobj.AddShader(&ps);
2099
2100 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002101 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002102
2103 m_memoryRefManager.AddMemoryRef(&texture);
2104
Tony Barbourdd4c9642015-01-09 12:55:14 -07002105 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002106 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002107 XglCommandBufferObj cmdBuffer(m_device);
2108 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2109
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002110 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002111
2112 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2113
2114#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002115 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002116 pDSDumpDot((char*)"triTest2.dot");
2117#endif
2118 // render triangle
2119 cmdBuffer.Draw(0, 3, 0, 1);
2120
2121 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002122 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002123 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002124
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002125 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002126}
2127TEST_F(XglRenderTest, FSTriangle)
2128{
2129 // The expected result from this test is a red and green checkered triangle
2130 static const char *vertShaderText =
2131 "#version 140\n"
2132 "#extension GL_ARB_separate_shader_objects : enable\n"
2133 "#extension GL_ARB_shading_language_420pack : enable\n"
2134 "layout (location = 0) out vec2 samplePos;\n"
2135 "void main() {\n"
2136 " vec2 vertices[3];"
2137 " vertices[0] = vec2(-0.5, -0.5);\n"
2138 " vertices[1] = vec2( 0.5, -0.5);\n"
2139 " vertices[2] = vec2( 0.5, 0.5);\n"
2140 " vec2 positions[3];"
2141 " positions[0] = vec2( 0.0, 0.0);\n"
2142 " positions[1] = vec2( 1.0, 0.0);\n"
2143 " positions[2] = vec2( 1.0, 1.0);\n"
2144 " samplePos = positions[gl_VertexID % 3];\n"
2145 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2146 "}\n";
2147
2148 static const char *fragShaderText =
2149 "#version 140\n"
2150 "#extension GL_ARB_separate_shader_objects : enable\n"
2151 "#extension GL_ARB_shading_language_420pack : enable\n"
2152 "layout (location = 0) in vec2 samplePos;\n"
2153 "layout (binding = 0) uniform sampler2D surface;\n"
2154 "layout (location=0) out vec4 outColor;\n"
2155 "void main() {\n"
2156 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2157 " outColor = texColor;\n"
2158 "}\n";
2159
2160 ASSERT_NO_FATAL_FAILURE(InitState());
2161 ASSERT_NO_FATAL_FAILURE(InitViewport());
2162
2163 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2164 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2165 XglSamplerObj sampler(m_device);
2166 XglTextureObj texture(m_device);
2167
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(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002174
2175 m_memoryRefManager.AddMemoryRef(&texture);
2176
Tony Barbourdd4c9642015-01-09 12:55:14 -07002177 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002178 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002179 XglCommandBufferObj cmdBuffer(m_device);
2180 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2181
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002182 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002183
2184 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2185
2186#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002187 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002188 pDSDumpDot((char*)"triTest2.dot");
2189#endif
2190 // render triangle
2191 cmdBuffer.Draw(0, 3, 0, 1);
2192
2193 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002194 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002195 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002196
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002197 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002198}
2199TEST_F(XglRenderTest, SamplerBindingsTriangle)
2200{
2201 // This test sets bindings on the samplers
2202 // For now we are asserting that sampler and texture pairs
2203 // march in lock step, and are set via GLSL binding. This can
2204 // and will probably change.
2205 // The sampler bindings should match the sampler and texture slot
2206 // number set up by the application.
2207 // This test will result in a blue triangle
2208 static const char *vertShaderText =
2209 "#version 140\n"
2210 "#extension GL_ARB_separate_shader_objects : enable\n"
2211 "#extension GL_ARB_shading_language_420pack : enable\n"
2212 "layout (location = 0) out vec4 samplePos;\n"
2213 "void main() {\n"
2214 " vec2 vertices[3];"
2215 " vertices[0] = vec2(-0.5, -0.5);\n"
2216 " vertices[1] = vec2( 0.5, -0.5);\n"
2217 " vertices[2] = vec2( 0.5, 0.5);\n"
2218 " vec2 positions[3];"
2219 " positions[0] = vec2( 0.0, 0.0);\n"
2220 " positions[1] = vec2( 1.0, 0.0);\n"
2221 " positions[2] = vec2( 1.0, 1.0);\n"
2222 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2223 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2224 "}\n";
2225
2226 static const char *fragShaderText =
2227 "#version 140\n"
2228 "#extension GL_ARB_separate_shader_objects : enable\n"
2229 "#extension GL_ARB_shading_language_420pack : enable\n"
2230 "layout (location = 0) in vec4 samplePos;\n"
2231 "layout (binding = 0) uniform sampler2D surface0;\n"
2232 "layout (binding = 1) uniform sampler2D surface1;\n"
2233 "layout (binding = 12) uniform sampler2D surface2;\n"
2234 "void main() {\n"
2235 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
2236 "}\n";
2237
2238 ASSERT_NO_FATAL_FAILURE(InitState());
2239 ASSERT_NO_FATAL_FAILURE(InitViewport());
2240
2241 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2242 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2243
2244 XglSamplerObj sampler1(m_device);
2245 XglSamplerObj sampler2(m_device);
2246 XglSamplerObj sampler3(m_device);
2247
Tony Barbour2f421a02015-04-01 16:38:10 -06002248 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
2249 XglTextureObj texture1(m_device, tex_colors); // Red
2250 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
2251 XglTextureObj texture2(m_device, tex_colors); // Green
2252 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
2253 XglTextureObj texture3(m_device, tex_colors); // Blue
Tony Barbourf43b6982014-11-25 13:18:32 -07002254
Tony Barbourf43b6982014-11-25 13:18:32 -07002255 XglPipelineObj pipelineobj(m_device);
2256 pipelineobj.AddShader(&vs);
2257 pipelineobj.AddShader(&ps);
2258
2259 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002260 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2261 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2262 for (int i = 0; i < 10; i++)
2263 descriptorSet.AppendDummy();
2264 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002265
2266 m_memoryRefManager.AddMemoryRef(&texture1);
2267 m_memoryRefManager.AddMemoryRef(&texture2);
2268 m_memoryRefManager.AddMemoryRef(&texture3);
2269
Tony Barbourdd4c9642015-01-09 12:55:14 -07002270 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002271 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002272 XglCommandBufferObj cmdBuffer(m_device);
2273 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2274
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002275 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002276
2277 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2278
2279#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002280 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002281 pDSDumpDot((char*)"triTest2.dot");
2282#endif
2283 // render triangle
2284 cmdBuffer.Draw(0, 3, 0, 1);
2285
2286 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002287 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002288 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002289
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002290 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002291}
2292
2293TEST_F(XglRenderTest, TriangleVSUniformBlock)
2294{
2295 // The expected result from this test is a blue triangle
2296
2297 static const char *vertShaderText =
2298 "#version 140\n"
2299 "#extension GL_ARB_separate_shader_objects : enable\n"
2300 "#extension GL_ARB_shading_language_420pack : enable\n"
2301 "layout (location = 0) out vec4 outColor;\n"
2302 "layout (std140, binding = 0) uniform bufferVals {\n"
2303 " vec4 red;\n"
2304 " vec4 green;\n"
2305 " vec4 blue;\n"
2306 " vec4 white;\n"
2307 "} myBufferVals;\n"
2308 "void main() {\n"
2309 " vec2 vertices[3];"
2310 " vertices[0] = vec2(-0.5, -0.5);\n"
2311 " vertices[1] = vec2( 0.5, -0.5);\n"
2312 " vertices[2] = vec2( 0.5, 0.5);\n"
2313 " outColor = myBufferVals.blue;\n"
2314 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2315 "}\n";
2316
2317 static const char *fragShaderText =
2318 "#version 140\n"
2319 "#extension GL_ARB_separate_shader_objects : enable\n"
2320 "#extension GL_ARB_shading_language_420pack : enable\n"
2321 "layout (location = 0) in vec4 inColor;\n"
2322 "void main() {\n"
2323 " gl_FragColor = inColor;\n"
2324 "}\n";
2325
2326 ASSERT_NO_FATAL_FAILURE(InitState());
2327 ASSERT_NO_FATAL_FAILURE(InitViewport());
2328
2329 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2330 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2331
2332 // Let's populate our buffer with the following:
2333 // vec4 red;
2334 // vec4 green;
2335 // vec4 blue;
2336 // vec4 white;
2337 const int valCount = 4 * 4;
2338 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2339 0.0, 1.0, 0.0, 1.0,
2340 0.0, 0.0, 1.0, 1.0,
2341 1.0, 1.0, 1.0, 1.0 };
2342
2343 XglConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002344
2345 XglPipelineObj pipelineobj(m_device);
2346 pipelineobj.AddShader(&vs);
2347 pipelineobj.AddShader(&ps);
2348
2349 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002350 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002351
Tony Barbourdd4c9642015-01-09 12:55:14 -07002352 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002353 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002354 XglCommandBufferObj cmdBuffer(m_device);
2355 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2356
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002357 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002358
2359 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2360
2361#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002362 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002363 pDSDumpDot((char*)"triTest2.dot");
2364#endif
2365 // render triangle
2366 cmdBuffer.Draw(0, 3, 0, 1);
2367
2368 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002369 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002370 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002371
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002372 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002373}
2374
2375TEST_F(XglRenderTest, TriangleFSUniformBlockBinding)
2376{
2377 // This test allows the shader to select which buffer it is
2378 // pulling from using layout binding qualifier.
2379 // There are corresponding changes in the compiler stack that
2380 // will select the buffer using binding directly.
2381 // The binding number should match the slot number set up by
2382 // the application.
2383 // The expected result from this test is a purple triangle
2384
2385 static const char *vertShaderText =
2386 "#version 140\n"
2387 "#extension GL_ARB_separate_shader_objects : enable\n"
2388 "#extension GL_ARB_shading_language_420pack : enable\n"
2389 "void main() {\n"
2390 " vec2 vertices[3];"
2391 " vertices[0] = vec2(-0.5, -0.5);\n"
2392 " vertices[1] = vec2( 0.5, -0.5);\n"
2393 " vertices[2] = vec2( 0.5, 0.5);\n"
2394 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2395 "}\n";
2396
2397 static const char *fragShaderText =
2398 "#version 140\n"
2399 "#extension GL_ARB_separate_shader_objects : enable\n"
2400 "#extension GL_ARB_shading_language_420pack : enable\n"
2401 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2402 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2403 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002404 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
Tony Barbourf43b6982014-11-25 13:18:32 -07002405 "void main() {\n"
2406 " gl_FragColor = myBlueVal.color;\n"
2407 " gl_FragColor += myRedVal.color;\n"
2408 "}\n";
2409
2410 ASSERT_NO_FATAL_FAILURE(InitState());
2411 ASSERT_NO_FATAL_FAILURE(InitViewport());
2412
2413 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2414 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2415
2416 // We're going to create a number of uniform buffers, and then allow
2417 // the shader to select which it wants to read from with a binding
2418
2419 // Let's populate the buffers with a single color each:
2420 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2421 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2422 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002423 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002424
2425 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2426 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2427 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2428 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2429
2430 const int redCount = sizeof(redVals) / sizeof(float);
2431 const int greenCount = sizeof(greenVals) / sizeof(float);
2432 const int blueCount = sizeof(blueVals) / sizeof(float);
2433 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2434
2435 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002436
2437 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002438
2439 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002440
2441 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002442
2443 XglPipelineObj pipelineobj(m_device);
2444 pipelineobj.AddShader(&vs);
2445 pipelineobj.AddShader(&ps);
2446
2447 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002448 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2449 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2450 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2451 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002452
Tony Barbourdd4c9642015-01-09 12:55:14 -07002453 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002454 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002455 XglCommandBufferObj cmdBuffer(m_device);
2456 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002457
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002458 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002459
2460 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2461
2462#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002463 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002464 pDSDumpDot((char*)"triTest2.dot");
2465#endif
2466 // render triangle
2467 cmdBuffer.Draw(0, 3, 0, 1);
2468
2469 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002470 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002471 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002472
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002473 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002474}
2475
2476TEST_F(XglRenderTest, TriangleFSAnonymousUniformBlockBinding)
2477{
2478 // This test is the same as TriangleFSUniformBlockBinding, but
2479 // it does not provide an instance name.
2480 // The expected result from this test is a purple triangle
2481
2482 static const char *vertShaderText =
2483 "#version 140\n"
2484 "#extension GL_ARB_separate_shader_objects : enable\n"
2485 "#extension GL_ARB_shading_language_420pack : enable\n"
2486 "void main() {\n"
2487 " vec2 vertices[3];"
2488 " vertices[0] = vec2(-0.5, -0.5);\n"
2489 " vertices[1] = vec2( 0.5, -0.5);\n"
2490 " vertices[2] = vec2( 0.5, 0.5);\n"
2491 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2492 "}\n";
2493
2494 static const char *fragShaderText =
2495 "#version 430\n"
2496 "#extension GL_ARB_separate_shader_objects : enable\n"
2497 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002498 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2499 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2500 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002501 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002502 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002503 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002504 " outColor = blue;\n"
2505 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002506 "}\n";
2507 ASSERT_NO_FATAL_FAILURE(InitState());
2508 ASSERT_NO_FATAL_FAILURE(InitViewport());
2509
2510 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2511 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2512
2513 // We're going to create a number of uniform buffers, and then allow
2514 // the shader to select which it wants to read from with a binding
2515
2516 // Let's populate the buffers with a single color each:
2517 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2518 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2519 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2520 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2521
2522 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2523 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2524 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2525 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2526
2527 const int redCount = sizeof(redVals) / sizeof(float);
2528 const int greenCount = sizeof(greenVals) / sizeof(float);
2529 const int blueCount = sizeof(blueVals) / sizeof(float);
2530 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2531
2532 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002533
2534 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002535
2536 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002537
2538 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002539
2540 XglPipelineObj pipelineobj(m_device);
2541 pipelineobj.AddShader(&vs);
2542 pipelineobj.AddShader(&ps);
2543
2544 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002545 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2546 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2547 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2548 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002549
Tony Barbourdd4c9642015-01-09 12:55:14 -07002550 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002551 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002552 XglCommandBufferObj cmdBuffer(m_device);
2553 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2554
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002555 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002556
2557 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2558
2559#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002560 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002561 pDSDumpDot((char*)"triTest2.dot");
2562#endif
2563 // render triangle
2564 cmdBuffer.Draw(0, 3, 0, 1);
2565
2566 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002567 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002568 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002569
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002570 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002571}
2572
2573TEST_F(XglRenderTest, CubeWithVertexFetchAndMVPAndTexture)
2574{
2575 static const char *vertShaderText =
2576 "#version 140\n"
2577 "#extension GL_ARB_separate_shader_objects : enable\n"
2578 "#extension GL_ARB_shading_language_420pack : enable\n"
2579 "layout (std140, binding=0) uniform bufferVals {\n"
2580 " mat4 mvp;\n"
2581 "} myBufferVals;\n"
2582 "layout (location=0) in vec4 pos;\n"
2583 "layout (location=0) out vec2 UV;\n"
2584 "void main() {\n"
2585 " vec2 positions[3];"
2586 " positions[0] = vec2( 0.0, 0.0);\n"
2587 " positions[1] = vec2( 0.25, 0.1);\n"
2588 " positions[2] = vec2( 0.1, 0.25);\n"
2589 " UV = positions[gl_VertexID % 3];\n"
2590 " gl_Position = myBufferVals.mvp * pos;\n"
2591 "}\n";
2592
2593 static const char *fragShaderText =
2594 "#version 140\n"
2595 "#extension GL_ARB_separate_shader_objects : enable\n"
2596 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002597 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002598 "layout (location=0) out vec4 outColor;\n"
2599 "layout (location=0) in vec2 UV;\n"
2600 "void main() {\n"
2601 " outColor= textureLod(surface, UV, 0.0);\n"
2602 "}\n";
2603 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2604
2605 glm::mat4 View = glm::lookAt(
2606 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2607 glm::vec3(0,0,0), // and looks at the origin
2608 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2609 );
2610
2611 glm::mat4 Model = glm::mat4(1.0f);
2612
2613 glm::mat4 MVP = Projection * View * Model;
2614
2615
2616 ASSERT_NO_FATAL_FAILURE(InitState());
2617 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour17c6ab12015-03-27 17:03:18 -06002618 m_depthStencil->Init(m_device, m_width, m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07002619
2620 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
2621 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002622 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002623
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002624 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07002625
2626 XglConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2627 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2628 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2629 XglSamplerObj sampler(m_device);
2630 XglTextureObj texture(m_device);
2631
Tony Barbourf43b6982014-11-25 13:18:32 -07002632 XglPipelineObj pipelineobj(m_device);
2633 pipelineobj.AddShader(&vs);
2634 pipelineobj.AddShader(&ps);
2635
2636 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06002637 // descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer); // TODO: Why does this break images??
Chia-I Wuf8385062015-01-04 16:27:24 +08002638 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mvpBuffer);
2639 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002640
2641 m_memoryRefManager.AddMemoryRef(&meshBuffer);
2642 m_memoryRefManager.AddMemoryRef(&mvpBuffer);
2643 m_memoryRefManager.AddMemoryRef(&texture);
Tony Barbour17c6ab12015-03-27 17:03:18 -06002644 m_memoryRefManager.AddMemoryRef(m_depthStencil);
Tony Barbourf43b6982014-11-25 13:18:32 -07002645
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002646#define MESH_BIND_ID 0
Tony Barbourf43b6982014-11-25 13:18:32 -07002647 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002648 MESH_BIND_ID, // binding ID
2649 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
2650 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
2651 };
Tony Barbourf43b6982014-11-25 13:18:32 -07002652
Tony Barbourf43b6982014-11-25 13:18:32 -07002653 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002654 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2655 vi_attribs[0].location = 0; // location
2656 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
2657 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2658 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2659 vi_attribs[1].location = 1; // location
2660 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
2661 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07002662
Tony Barbourf43b6982014-11-25 13:18:32 -07002663 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002664 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2665 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07002666
Tony Barbourfa6cac72015-01-16 14:27:35 -07002667 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
2668 ds_state.depthTestEnable = XGL_TRUE;
2669 ds_state.depthWriteEnable = XGL_TRUE;
2670 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
2671 ds_state.depthBoundsEnable = XGL_FALSE;
2672 ds_state.stencilTestEnable = XGL_FALSE;
2673 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
2674 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
2675 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
2676 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07002677 ds_state.format = XGL_FMT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002678 ds_state.front = ds_state.back;
2679 pipelineobj.SetDepthStencil(&ds_state);
2680
Tony Barbour17c6ab12015-03-27 17:03:18 -06002681 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002682 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002683 XglCommandBufferObj cmdBuffer(m_device);
2684 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002685
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002686 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
2687
Tony Barbourdd4c9642015-01-09 12:55:14 -07002688 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2689
2690 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2691#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002692 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002693 pDSDumpDot((char*)"triTest2.dot");
2694#endif
2695 // render triangle
2696 cmdBuffer.Draw(0, 36, 0, 1);
2697
2698 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002699 EndCommandBuffer(cmdBuffer);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002700 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
2701
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002702 RecordImages(m_renderTargets);
Tony Barbourf43b6982014-11-25 13:18:32 -07002703}
Cody Northropd1ce7842014-12-09 11:17:01 -07002704
2705TEST_F(XglRenderTest, TriangleMixedSamplerUniformBlockBinding)
2706{
2707 // This test mixes binding slots of textures and buffers, ensuring
2708 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002709 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002710 // you can modify it to move the desired result around.
2711
2712 static const char *vertShaderText =
2713 "#version 140\n"
2714 "#extension GL_ARB_separate_shader_objects : enable\n"
2715 "#extension GL_ARB_shading_language_420pack : enable\n"
2716 "void main() {\n"
2717 " vec2 vertices[3];"
2718 " vertices[0] = vec2(-0.5, -0.5);\n"
2719 " vertices[1] = vec2( 0.5, -0.5);\n"
2720 " vertices[2] = vec2( 0.5, 0.5);\n"
2721 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2722 "}\n";
2723
2724 static const char *fragShaderText =
2725 "#version 430\n"
2726 "#extension GL_ARB_separate_shader_objects : enable\n"
2727 "#extension GL_ARB_shading_language_420pack : enable\n"
2728 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002729 "layout (binding = 3) uniform sampler2D surface1;\n"
2730 "layout (binding = 1) uniform sampler2D surface2;\n"
2731 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002732
Cody Northropa0410942014-12-09 13:59:39 -07002733
Chia-I Wuf8385062015-01-04 16:27:24 +08002734 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2735 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2736 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2737 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002738 "layout (location = 0) out vec4 outColor;\n"
2739 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002740 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002741 " outColor += white * vec4(0.00001);\n"
2742 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002743 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002744 "}\n";
2745 ASSERT_NO_FATAL_FAILURE(InitState());
2746 ASSERT_NO_FATAL_FAILURE(InitViewport());
2747
2748 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2749 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2750
Cody Northropd1ce7842014-12-09 11:17:01 -07002751 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2752 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2753 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2754 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2755
2756 const int redCount = sizeof(redVals) / sizeof(float);
2757 const int greenCount = sizeof(greenVals) / sizeof(float);
2758 const int blueCount = sizeof(blueVals) / sizeof(float);
2759 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2760
2761 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002762 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002763 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002764 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002765
Tony Barbour2f421a02015-04-01 16:38:10 -06002766 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Cody Northropd1ce7842014-12-09 11:17:01 -07002767 XglSamplerObj sampler0(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002768 XglTextureObj texture0(m_device, tex_colors); // Light Red
2769 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Cody Northropd1ce7842014-12-09 11:17:01 -07002770 XglSamplerObj sampler2(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002771 XglTextureObj texture2(m_device, tex_colors); // Light Blue
2772 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Cody Northropd1ce7842014-12-09 11:17:01 -07002773 XglSamplerObj sampler4(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002774 XglTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropa0410942014-12-09 13:59:39 -07002775
2776 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2777 // TODO: Get back here ASAP and understand why.
Tony Barbour2f421a02015-04-01 16:38:10 -06002778 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Cody Northropa0410942014-12-09 13:59:39 -07002779 XglSamplerObj sampler7(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002780 XglTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropd1ce7842014-12-09 11:17:01 -07002781
2782 XglPipelineObj pipelineobj(m_device);
2783 pipelineobj.AddShader(&vs);
2784 pipelineobj.AddShader(&ps);
2785
2786 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002787 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2788 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2789 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2790 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2791 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2792 // swap blue and green
2793 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2794 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2795 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002796
2797 m_memoryRefManager.AddMemoryRef(&texture0);
2798 m_memoryRefManager.AddMemoryRef(&texture2);
2799 m_memoryRefManager.AddMemoryRef(&texture4);
Cody Northropa0410942014-12-09 13:59:39 -07002800 m_memoryRefManager.AddMemoryRef(&texture7);
Cody Northropd1ce7842014-12-09 11:17:01 -07002801
Tony Barbourdd4c9642015-01-09 12:55:14 -07002802 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002803 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002804 XglCommandBufferObj cmdBuffer(m_device);
2805 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002806
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002807 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002808
2809 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2810
2811#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002812 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002813 pDSDumpDot((char*)"triTest2.dot");
2814#endif
2815 // render triangle
2816 cmdBuffer.Draw(0, 3, 0, 1);
2817
2818 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002819 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002820 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002821
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002822 RecordImages(m_renderTargets);
Cody Northropd1ce7842014-12-09 11:17:01 -07002823}
2824
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002825TEST_F(XglRenderTest, TriangleMatchingSamplerUniformBlockBinding)
2826{
2827 // This test matches binding slots of textures and buffers, requiring
2828 // the driver to give them distinct number spaces.
2829 // The expected result from this test is a red triangle, although
2830 // you can modify it to move the desired result around.
2831
2832 static const char *vertShaderText =
2833 "#version 140\n"
2834 "#extension GL_ARB_separate_shader_objects : enable\n"
2835 "#extension GL_ARB_shading_language_420pack : enable\n"
2836 "void main() {\n"
2837 " vec2 vertices[3];"
2838 " vertices[0] = vec2(-0.5, -0.5);\n"
2839 " vertices[1] = vec2( 0.5, -0.5);\n"
2840 " vertices[2] = vec2( 0.5, 0.5);\n"
2841 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2842 "}\n";
2843
2844 static const char *fragShaderText =
2845 "#version 430\n"
2846 "#extension GL_ARB_separate_shader_objects : enable\n"
2847 "#extension GL_ARB_shading_language_420pack : enable\n"
2848 "layout (binding = 0) uniform sampler2D surface0;\n"
2849 "layout (binding = 1) uniform sampler2D surface1;\n"
2850 "layout (binding = 2) uniform sampler2D surface2;\n"
2851 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002852 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2853 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2854 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2855 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002856 "layout (location = 0) out vec4 outColor;\n"
2857 "void main() {\n"
2858 " outColor = red;// * vec4(0.00001);\n"
2859 " outColor += white * vec4(0.00001);\n"
2860 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2861 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2862 "}\n";
2863 ASSERT_NO_FATAL_FAILURE(InitState());
2864 ASSERT_NO_FATAL_FAILURE(InitViewport());
2865
2866 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2867 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2868
2869 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2870 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2871 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2872 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2873
2874 const int redCount = sizeof(redVals) / sizeof(float);
2875 const int greenCount = sizeof(greenVals) / sizeof(float);
2876 const int blueCount = sizeof(blueVals) / sizeof(float);
2877 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2878
2879 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002880 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002881 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002882 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002883
Tony Barbour2f421a02015-04-01 16:38:10 -06002884 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002885 XglSamplerObj sampler0(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002886 XglTextureObj texture0(m_device, tex_colors); // Light Red
2887 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002888 XglSamplerObj sampler2(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002889 XglTextureObj texture2(m_device, tex_colors); // Light Blue
2890 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002891 XglSamplerObj sampler4(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002892 XglTextureObj texture4(m_device, tex_colors); // Light Green
2893 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002894 XglSamplerObj sampler7(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002895 XglTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002896
2897 XglPipelineObj pipelineobj(m_device);
2898 pipelineobj.AddShader(&vs);
2899 pipelineobj.AddShader(&ps);
2900
2901 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002902 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2903 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2904 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2905 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2906 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2907 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2908 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2909 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002910
2911 m_memoryRefManager.AddMemoryRef(&texture0);
2912 m_memoryRefManager.AddMemoryRef(&texture2);
2913 m_memoryRefManager.AddMemoryRef(&texture4);
2914 m_memoryRefManager.AddMemoryRef(&texture7);
2915
Tony Barbourdd4c9642015-01-09 12:55:14 -07002916 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002917 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002918 XglCommandBufferObj cmdBuffer(m_device);
2919 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002920
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002921 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002922
2923 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2924
2925#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002926 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002927 pDSDumpDot((char*)"triTest2.dot");
2928#endif
2929 // render triangle
2930 cmdBuffer.Draw(0, 3, 0, 1);
2931
2932 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002933 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002934 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002935
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06002936 RecordImages(m_renderTargets);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002937}
2938
Cody Northrop02690bd2014-12-17 15:26:33 -07002939TEST_F(XglRenderTest, TriangleUniformBufferLayout)
2940{
2941 // This test populates a buffer with a variety of different data
2942 // types, then reads them out with a shader.
2943 // The expected result from this test is a green triangle
2944
2945 static const char *vertShaderText =
2946 "#version 140\n"
2947 "#extension GL_ARB_separate_shader_objects : enable\n"
2948 "#extension GL_ARB_shading_language_420pack : enable\n"
2949 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2950 " vec4 fRed;\n"
2951 " vec4 fGreen;\n"
2952 " layout(row_major) mat4 worldToProj;\n"
2953 " layout(row_major) mat4 projToWorld;\n"
2954 " layout(row_major) mat4 worldToView;\n"
2955 " layout(row_major) mat4 viewToProj;\n"
2956 " layout(row_major) mat4 worldToShadow[4];\n"
2957 " float fZero;\n"
2958 " float fOne;\n"
2959 " float fTwo;\n"
2960 " float fThree;\n"
2961 " vec3 fZeroZeroZero;\n"
2962 " float fFour;\n"
2963 " vec3 fZeroZeroOne;\n"
2964 " float fFive;\n"
2965 " vec3 fZeroOneZero;\n"
2966 " float fSix;\n"
2967 " float fSeven;\n"
2968 " float fEight;\n"
2969 " float fNine;\n"
2970 " vec2 fZeroZero;\n"
2971 " vec2 fZeroOne;\n"
2972 " vec4 fBlue;\n"
2973 " vec2 fOneZero;\n"
2974 " vec2 fOneOne;\n"
2975 " vec3 fZeroOneOne;\n"
2976 " float fTen;\n"
2977 " float fEleven;\n"
2978 " float fTwelve;\n"
2979 " vec3 fOneZeroZero;\n"
2980 " vec4 uvOffsets[4];\n"
2981 "};\n"
2982 "layout (location = 0) out vec4 color;"
2983 "void main() {\n"
2984
2985 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2986 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2987 " \n"
2988
2989 // do some exact comparisons, even though we should
2990 // really have an epsilon involved.
2991 " vec4 outColor = right;\n"
2992 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
2993 " outColor = wrong;\n"
2994 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
2995 " outColor = wrong;\n"
2996 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
2997 " outColor = wrong;\n"
2998
2999 " color = outColor;\n"
3000
3001 // generic position stuff
3002 " vec2 vertices;\n"
3003 " int vertexSelector = gl_VertexID;\n"
3004 " if (vertexSelector == 0)\n"
3005 " vertices = vec2(-0.5, -0.5);\n"
3006 " else if (vertexSelector == 1)\n"
3007 " vertices = vec2( 0.5, -0.5);\n"
3008 " else if (vertexSelector == 2)\n"
3009 " vertices = vec2( 0.5, 0.5);\n"
3010 " else\n"
3011 " vertices = vec2( 0.0, 0.0);\n"
3012 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
3013 "}\n";
3014
3015 static const char *fragShaderText =
3016 "#version 140\n"
3017 "#extension GL_ARB_separate_shader_objects : enable\n"
3018 "#extension GL_ARB_shading_language_420pack : enable\n"
3019 "layout (std140, binding = 0) uniform mixedBuffer {\n"
3020 " vec4 fRed;\n"
3021 " vec4 fGreen;\n"
3022 " layout(row_major) mat4 worldToProj;\n"
3023 " layout(row_major) mat4 projToWorld;\n"
3024 " layout(row_major) mat4 worldToView;\n"
3025 " layout(row_major) mat4 viewToProj;\n"
3026 " layout(row_major) mat4 worldToShadow[4];\n"
3027 " float fZero;\n"
3028 " float fOne;\n"
3029 " float fTwo;\n"
3030 " float fThree;\n"
3031 " vec3 fZeroZeroZero;\n"
3032 " float fFour;\n"
3033 " vec3 fZeroZeroOne;\n"
3034 " float fFive;\n"
3035 " vec3 fZeroOneZero;\n"
3036 " float fSix;\n"
3037 " float fSeven;\n"
3038 " float fEight;\n"
3039 " float fNine;\n"
3040 " vec2 fZeroZero;\n"
3041 " vec2 fZeroOne;\n"
3042 " vec4 fBlue;\n"
3043 " vec2 fOneZero;\n"
3044 " vec2 fOneOne;\n"
3045 " vec3 fZeroOneOne;\n"
3046 " float fTen;\n"
3047 " float fEleven;\n"
3048 " float fTwelve;\n"
3049 " vec3 fOneZeroZero;\n"
3050 " vec4 uvOffsets[4];\n"
3051 "};\n"
3052 "layout (location = 0) in vec4 color;\n"
3053 "void main() {\n"
3054 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3055 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3056 " \n"
3057
3058 // start with VS value to ensure it passed
3059 " vec4 outColor = color;\n"
3060
3061 // do some exact comparisons, even though we should
3062 // really have an epsilon involved.
3063 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3064 " outColor = wrong;\n"
3065 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3066 " outColor = wrong;\n"
3067 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3068 " outColor = wrong;\n"
3069 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3070 " outColor = wrong;\n"
3071 " if (fTwo != 2.0)\n"
3072 " outColor = wrong;\n"
3073 " if (fOneOne != vec2(1.0, 1.0))\n"
3074 " outColor = wrong;\n"
3075 " if (fTen != 10.0)\n"
3076 " outColor = wrong;\n"
3077 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3078 " outColor = wrong;\n"
3079 " \n"
3080 " gl_FragColor = outColor;\n"
3081 "}\n";
3082
3083
3084 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3085 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3086 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3087 0.0, 1.0, 0.0, 1.0, // align
3088 0.0, 0.0, 1.0, 1.0, // align
3089 0.0, 0.0, 0.0, 1.0, // align
3090 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3091 0.0, 2.0, 0.0, 2.0, // align
3092 0.0, 0.0, 2.0, 2.0, // align
3093 0.0, 0.0, 0.0, 2.0, // align
3094 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3095 0.0, 3.0, 0.0, 3.0, // align
3096 0.0, 0.0, 3.0, 3.0, // align
3097 0.0, 0.0, 0.0, 3.0, // align
3098 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3099 0.0, 4.0, 0.0, 4.0, // align
3100 0.0, 0.0, 4.0, 4.0, // align
3101 0.0, 0.0, 0.0, 4.0, // align
3102 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3103 0.0, 5.0, 0.0, 5.0, // align
3104 0.0, 0.0, 5.0, 5.0, // align
3105 0.0, 0.0, 0.0, 5.0, // align
3106 6.0, 0.0, 0.0, 6.0, // align
3107 0.0, 6.0, 0.0, 6.0, // align
3108 0.0, 0.0, 6.0, 6.0, // align
3109 0.0, 0.0, 0.0, 6.0, // align
3110 7.0, 0.0, 0.0, 7.0, // align
3111 0.0, 7.0, 0.0, 7.0, // align
3112 0.0, 0.0, 7.0, 7.0, // align
3113 0.0, 0.0, 0.0, 7.0, // align
3114 8.0, 0.0, 0.0, 8.0, // align
3115 0.0, 8.0, 0.0, 8.0, // align
3116 0.0, 0.0, 8.0, 8.0, // align
3117 0.0, 0.0, 0.0, 8.0, // align
3118 0.0, // float fZero; // align
3119 1.0, // float fOne; // pack
3120 2.0, // float fTwo; // pack
3121 3.0, // float fThree; // pack
3122 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3123 4.0, // float fFour; // pack
3124 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3125 5.0, // float fFive; // pack
3126 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3127 6.0, // float fSix; // pack
3128 7.0, // float fSeven; // align
3129 8.0, // float fEight; // pack
3130 9.0, // float fNine; // pack
3131 0.0, // BUFFER
3132 0.0, 0.0, // vec2 fZeroZero; // align
3133 0.0, 1.0, // vec2 fZeroOne; // pack
3134 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3135 1.0, 0.0, // vec2 fOneZero; // align
3136 1.0, 1.0, // vec2 fOneOne; // pack
3137 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3138 10.0, // float fTen; // pack
3139 11.0, // float fEleven; // align
3140 12.0, // float fTwelve; // pack
3141 0.0, 0.0, // BUFFER
3142 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3143 0.0, // BUFFER
3144 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3145 0.5, 0.6, 0.7, 0.8, // align
3146 0.9, 1.0, 1.1, 1.2, // align
3147 1.3, 1.4, 1.5, 1.6, // align
3148 };
3149
3150 ASSERT_NO_FATAL_FAILURE(InitState());
3151 ASSERT_NO_FATAL_FAILURE(InitViewport());
3152
3153 const int constCount = sizeof(mixedVals) / sizeof(float);
3154
3155 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
3156 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
3157
3158 XglConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003159
3160 XglPipelineObj pipelineobj(m_device);
3161 pipelineobj.AddShader(&vs);
3162 pipelineobj.AddShader(&ps);
3163
3164 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08003165 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003166
3167 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07003168 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Cody Northrop02690bd2014-12-17 15:26:33 -07003169 XglCommandBufferObj cmdBuffer(m_device);
3170 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3171
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003172 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Cody Northrop02690bd2014-12-17 15:26:33 -07003173
3174 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
3175
3176#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003177 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop02690bd2014-12-17 15:26:33 -07003178 pDSDumpDot((char*)"triTest2.dot");
3179#endif
3180 // render triangle
3181 cmdBuffer.Draw(0, 3, 0, 1);
3182
3183 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003184 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06003185 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Cody Northrop02690bd2014-12-17 15:26:33 -07003186
Courtney Goeltzenleuchtercd5ed1e2015-04-02 14:17:44 -06003187 RecordImages(m_renderTargets);
Cody Northrop02690bd2014-12-17 15:26:33 -07003188}
3189
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003190int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003191 int result;
3192
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003193 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003194 XglTestFramework::InitArgs(&argc, argv);
3195
Chia-I Wu7133fdc2014-12-15 23:57:34 +08003196 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06003197
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003198 result = RUN_ALL_TESTS();
3199
3200 XglTestFramework::Finish();
3201 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003202}