blob: 05c7a62a807bc6896cee0ec8465f6a8c886b4a14 [file] [log] [blame]
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06001// Copyright 2005, Google Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14// * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30
31// XGL tests
32//
33// Copyright (C) 2014 LunarG, Inc.
34//
35// Permission is hereby granted, free of charge, to any person obtaining a
36// copy of this software and associated documentation files (the "Software"),
37// to deal in the Software without restriction, including without limitation
38// the rights to use, copy, modify, merge, publish, distribute, sublicense,
39// and/or sell copies of the Software, and to permit persons to whom the
40// Software is furnished to do so, subject to the following conditions:
41//
42// The above copyright notice and this permission notice shall be included
43// in all copies or substantial portions of the Software.
44//
45// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
48// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
49// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
50// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
51// DEALINGS IN THE SOFTWARE.
52
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060053// Basic rendering tests
54
55#include <stdlib.h>
56#include <stdio.h>
57#include <stdbool.h>
58#include <string.h>
Courtney Goeltzenleuchter76a643b2014-08-21 17:34:22 -060059#include <iostream>
60#include <fstream>
61using namespace std;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060062
63#include <xgl.h>
Tobin Ehlis31446e52014-11-28 11:17:19 -070064#ifdef DUMP_STATE_DOT
65#include "../layers/draw_state.h"
66#endif
Tobin Ehlis3c26a542014-11-18 11:28:33 -070067#ifdef PRINT_OBJECTS
68#include "../layers/object_track.h"
69#endif
Tobin Ehlis791a49c2014-11-10 12:29:12 -070070#ifdef DEBUG_CALLBACK
71#include <xglDbg.h>
72#endif
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060073#include "gtest-1.7.0/include/gtest/gtest.h"
74
Cody Northropd4e020a2015-03-17 14:54:35 -060075#include "icd-spv.h"
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060076
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -060077#define GLM_FORCE_RADIANS
78#include "glm/glm.hpp"
79#include <glm/gtc/matrix_transform.hpp>
80
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -060081#include "xglrenderframework.h"
Tobin Ehlis791a49c2014-11-10 12:29:12 -070082#ifdef DEBUG_CALLBACK
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060083void XGLAPI myDbgFunc(
Tobin Ehlis791a49c2014-11-10 12:29:12 -070084 XGL_DBG_MSG_TYPE msgType,
85 XGL_VALIDATION_LEVEL validationLevel,
86 XGL_BASE_OBJECT srcObject,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060087 size_t location,
88 int32_t msgCode,
89 const char* pMsg,
90 void* pUserData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -070091{
Tobin Ehlis3c26a542014-11-18 11:28:33 -070092 switch (msgType)
93 {
94 case XGL_DBG_MSG_WARNING:
95 printf("CALLBACK WARNING : %s\n", pMsg);
96 break;
97 case XGL_DBG_MSG_ERROR:
98 printf("CALLBACK ERROR : %s\n", pMsg);
99 break;
100 default:
101 printf("EATING Msg of type %u\n", msgType);
102 break;
103 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700104}
105#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700106
107
108#undef ASSERT_NO_FATAL_FAILURE
109#define ASSERT_NO_FATAL_FAILURE(x) x
110
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600111//--------------------------------------------------------------------------------------
112// Mesh and VertexFormat Data
113//--------------------------------------------------------------------------------------
114struct Vertex
115{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600116 float posX, posY, posZ, posW; // Position data
117 float r, g, b, a; // Color
Courtney Goeltzenleuchtera948d842014-08-22 16:27:58 -0600118};
119
120#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
121
122static const Vertex g_vbData[] =
123{
124 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
125 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
126 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
127 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
128 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
129 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
130
131 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
132 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
133 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
134 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
135 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
136 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
137
138 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
139 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
140 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
141 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
142 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
143 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
144
145 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
146 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
147 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
148 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
149 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
150 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
151
152 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 1.f, 1.f ) },
153 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
154 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
155 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
156 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
157 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) },
158
159 { XYZ1( 1, -1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
160 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
161 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
162 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
163 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
164 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) },
165};
166
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600167static const Vertex g_vb_solid_face_colors_Data[] =
168{
169 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
170 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
171 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
172 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
173 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
174 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 0.f ) },
175
176 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
177 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
178 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
179 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
180 { XYZ1( -1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
181 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 1.f, 0.f ) },
182
183 { XYZ1( 1, 1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
184 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
185 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
186 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 0.f, 1.f ) },
187 { XYZ1( 1, 1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
188 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 0.f, 1.f ) },
189
190 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
191 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
192 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
193 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
194 { XYZ1( -1, -1, 1 ), XYZ1( 1.f, 1.f, 0.f ) },
195 { XYZ1( -1, -1, -1 ), XYZ1( 1.f, 1.f, 0.f ) },
196
197 { XYZ1( 1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
198 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
199 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
200 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
201 { XYZ1( -1, 1, 1 ), XYZ1( 1.f, 0.f, 1.f ) },
202 { XYZ1( -1, 1, -1 ), XYZ1( 1.f, 0.f, 1.f ) },
203
204 { XYZ1( 1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
205 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
206 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
207 { XYZ1( -1, -1, 1 ), XYZ1( 0.f, 1.f, 1.f ) },
208 { XYZ1( 1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
209 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 1.f, 1.f ) },
210};
211
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600212class XglRenderTest : public XglRenderFramework
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -0600213{
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600214public:
Cody Northrop4e6b4762014-10-09 21:25:22 -0600215
Tony Barbourf43b6982014-11-25 13:18:32 -0700216 void RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbourdd4c9642015-01-09 12:55:14 -0700217 XglConstantBufferObj *constantBuffer, XglCommandBufferObj *cmdBuffer);
Tony Barbour02472db2015-01-08 17:08:28 -0700218 void GenericDrawPreparation(XglCommandBufferObj *cmdBuffer, XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600219 void InitDepthStencil();
Tony Barbourae442072015-01-12 13:27:11 -0700220 void XGLTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate);
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600221
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600222 XGL_RESULT BeginCommandBuffer(XglCommandBufferObj &cmdBuffer);
223 XGL_RESULT EndCommandBuffer(XglCommandBufferObj &cmdBuffer);
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600224
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600225protected:
Cody Northrop350727b2014-10-06 15:42:00 -0600226 XGL_IMAGE m_texture;
227 XGL_IMAGE_VIEW m_textureView;
228 XGL_IMAGE_VIEW_ATTACH_INFO m_textureViewInfo;
229 XGL_GPU_MEMORY m_textureMem;
230
231 XGL_SAMPLER m_sampler;
Tony Barbourf43b6982014-11-25 13:18:32 -0700232 XglMemoryRefManager m_memoryRefManager;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600233
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600234
235 virtual void SetUp() {
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600236
237 this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO;
238 this->app_info.pNext = NULL;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800239 this->app_info.pAppName = "render_tests";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600240 this->app_info.appVersion = 1;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800241 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600242 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter211cc542015-02-23 17:40:15 -0700243 this->app_info.apiVersion = XGL_API_VERSION;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600244
Cody Northrop350727b2014-10-06 15:42:00 -0600245 memset(&m_textureViewInfo, 0, sizeof(m_textureViewInfo));
246 m_textureViewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO;
247
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600248 InitFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600249 }
250
251 virtual void TearDown() {
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600252 // Clean up resources before we reset
253 ShutdownFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600254 }
255};
256
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600257XGL_RESULT XglRenderTest::BeginCommandBuffer(XglCommandBufferObj &cmdBuffer)
258{
259 XGL_RESULT result;
260
261 result = cmdBuffer.BeginCommandBuffer();
262
263 /*
264 * For render test all drawing happens in a single render pass
265 * on a single command buffer.
266 */
267 if (XGL_SUCCESS == result) {
268 cmdBuffer.BeginRenderPass(renderPass(), framebuffer());
269 }
270
271 return result;
272}
273
274XGL_RESULT XglRenderTest::EndCommandBuffer(XglCommandBufferObj &cmdBuffer)
275{
276 XGL_RESULT result;
277
278 cmdBuffer.EndRenderPass(renderPass());
279
280 result = cmdBuffer.EndCommandBuffer();
281
282 return result;
283}
284
285
Tony Barbour02472db2015-01-08 17:08:28 -0700286void XglRenderTest::GenericDrawPreparation(XglCommandBufferObj *cmdBuffer, XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet)
287{
Tony Barbour17c6ab12015-03-27 17:03:18 -0600288 if (m_depthStencil->Initialized()) {
289 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color,
290 m_depthStencil->BindInfo(), m_depthStencil->obj());
291 } else {
292 cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color,
293 NULL, NULL);
294 }
295
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700296 cmdBuffer->PrepareAttachments();
Tony Barbour02472db2015-01-08 17:08:28 -0700297 cmdBuffer->BindStateObject(XGL_STATE_BIND_RASTER, m_stateRaster);
298 cmdBuffer->BindStateObject(XGL_STATE_BIND_VIEWPORT, m_stateViewport);
299 cmdBuffer->BindStateObject(XGL_STATE_BIND_COLOR_BLEND, m_colorBlend);
300 cmdBuffer->BindStateObject(XGL_STATE_BIND_DEPTH_STENCIL, m_stateDepthStencil);
Chia-I Wuf8385062015-01-04 16:27:24 +0800301 descriptorSet->CreateXGLDescriptorSet(cmdBuffer);
Tony Barbour02472db2015-01-08 17:08:28 -0700302 pipelineobj->CreateXGLPipeline(descriptorSet);
303 cmdBuffer->BindPipeline(pipelineobj->GetPipelineHandle());
Tony Barbour02472db2015-01-08 17:08:28 -0700304 cmdBuffer->BindDescriptorSet(descriptorSet->GetDescriptorSetHandle());
305}
Tony Barbourf43b6982014-11-25 13:18:32 -0700306
Tony Barbourf43b6982014-11-25 13:18:32 -0700307void XglRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbourdd4c9642015-01-09 12:55:14 -0700308 XglConstantBufferObj *constantBuffer, XglCommandBufferObj *cmdBuffer)
309{
310 int i;
311 glm::mat4 MVP;
312 int matrixSize = sizeof(MVP);
313 XGL_RESULT err;
314
315 for (i = 0; i < 8; i++) {
316 void *pData = constantBuffer->map();
317
318 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
319 MVP = Projection * View * Model;
320 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
321
322 constantBuffer->unmap();
323
324 // submit the command buffer to the universal queue
325 cmdBuffer->QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
326
Tony Barbourdd4c9642015-01-09 12:55:14 -0700327 err = xglQueueWaitIdle( m_device->m_queue );
328 ASSERT_XGL_SUCCESS( err );
329
330 // Wait for work to finish before cleaning up.
331 xglDeviceWaitIdle(m_device->device());
332
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700333 assert(m_renderTargets.size() == 1);
Tony Barbourdd4c9642015-01-09 12:55:14 -0700334 RecordImage(m_renderTargets[0]);
335 }
336}
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600337
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600338void dumpMatrix(const char *note, glm::mat4 MVP)
339{
Chia-I Wu7133fdc2014-12-15 23:57:34 +0800340 int i;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600341
342 printf("%s: \n", note);
343 for (i=0; i<4; i++) {
344 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
345 }
346 printf("\n");
347 fflush(stdout);
348}
349
350void dumpVec4(const char *note, glm::vec4 vector)
351{
352 printf("%s: \n", note);
353 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
354 printf("\n");
355 fflush(stdout);
356}
357
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600358struct xgltriangle_vs_uniform {
359 // Must start with MVP
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600360 float mvp[4][4];
361 float position[3][4];
362 float color[3][4];
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600363};
364
Tony Barbourae442072015-01-12 13:27:11 -0700365void XglRenderTest::XGLTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600366{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700367#ifdef DEBUG_CALLBACK
Courtney Goeltzenleuchter9d36ef42015-04-13 14:10:06 -0600368 xglDbgRegisterMsgCallback(inst, myDbgFunc, NULL);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700369#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600370 // Create identity matrix
371 int i;
372 struct xgltriangle_vs_uniform data;
373
374 glm::mat4 Projection = glm::mat4(1.0f);
375 glm::mat4 View = glm::mat4(1.0f);
376 glm::mat4 Model = glm::mat4(1.0f);
377 glm::mat4 MVP = Projection * View * Model;
378 const int matrixSize = sizeof(MVP);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600379 const int bufSize = sizeof(xgltriangle_vs_uniform) / sizeof(float);
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600380 memcpy(&data.mvp, &MVP[0][0], matrixSize);
381
382 static const Vertex tri_data[] =
383 {
384 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
385 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
386 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
387 };
388
389 for (i=0; i<3; i++) {
390 data.position[i][0] = tri_data[i].posX;
391 data.position[i][1] = tri_data[i].posY;
392 data.position[i][2] = tri_data[i].posZ;
393 data.position[i][3] = tri_data[i].posW;
394 data.color[i][0] = tri_data[i].r;
395 data.color[i][1] = tri_data[i].g;
396 data.color[i][2] = tri_data[i].b;
397 data.color[i][3] = tri_data[i].a;
398 }
399
Tony Barbourf43b6982014-11-25 13:18:32 -0700400 ASSERT_NO_FATAL_FAILURE(InitState());
401 ASSERT_NO_FATAL_FAILURE(InitViewport());
402
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600403 XglConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data);
Tony Barbourf43b6982014-11-25 13:18:32 -0700404
405 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
406 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700407
408 XglPipelineObj pipelineobj(m_device);
409 pipelineobj.AddShader(&vs);
410 pipelineobj.AddShader(&ps);
411
412 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +0800413 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700414 m_memoryRefManager.AddMemoryRef(&constantBuffer);
415
Tony Barbour71ba3612015-01-09 16:12:35 -0700416 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700417 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbour71ba3612015-01-09 16:12:35 -0700418 XglCommandBufferObj cmdBuffer(m_device);
419 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700420
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600421 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour71ba3612015-01-09 16:12:35 -0700422
423 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Tony Barbour71ba3612015-01-09 16:12:35 -0700424#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600425 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour71ba3612015-01-09 16:12:35 -0700426 pDSDumpDot((char*)"triTest2.dot");
427#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600428
Tony Barbour71ba3612015-01-09 16:12:35 -0700429 // render triangle
430 cmdBuffer.Draw(0, 3, 0, 1);
431
432 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600433 EndCommandBuffer(cmdBuffer);
434
Tony Barbour71ba3612015-01-09 16:12:35 -0700435 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
436
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700437 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbour71ba3612015-01-09 16:12:35 -0700438 RecordImage(m_renderTargets[i]);
439
440 if (rotate)
Tobin Ehlis12ee35f2015-03-26 08:23:25 -0600441 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
Tony Barbour71ba3612015-01-09 16:12:35 -0700442
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700443#ifdef PRINT_OBJECTS
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600444 //uint64_t objTrackGetObjectCount(XGL_OBJECT_TYPE type)
445 OBJ_TRACK_GET_OBJECT_COUNT pObjTrackGetObjectCount = (OBJ_TRACK_GET_OBJECT_COUNT)xglGetProcAddr(gpu(), (char*)"objTrackGetObjectCount");
446 uint64_t numObjects = pObjTrackGetObjectCount(XGL_OBJECT_TYPE_ANY);
447 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = xglGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700448 printf("DEBUG : Number of Objects : %lu\n", numObjects);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600449 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)xglGetProcAddr(gpu(), (char*)"objTrackGetObjects");
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700450 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
451 pObjTrackGetObjs(XGL_OBJECT_TYPE_ANY, numObjects, pObjNodeArray);
452 for (i=0; i < numObjects; i++) {
453 printf("Object %i of type %s has objID (%p) and %lu uses\n", i, string_XGL_OBJECT_TYPE(pObjNodeArray[i].objType), pObjNodeArray[i].pObj, pObjNodeArray[i].numUses);
454 }
455 free(pObjNodeArray);
456#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700457
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600458}
459
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600460TEST_F(XglRenderTest, XGLTriangle_FragColor)
461{
462 static const char *vertShaderText =
463 "#version 140\n"
464 "#extension GL_ARB_separate_shader_objects : enable\n"
465 "#extension GL_ARB_shading_language_420pack : enable\n"
466 "\n"
467 "layout(binding = 0) uniform buf {\n"
468 " mat4 MVP;\n"
469 " vec4 position[3];\n"
470 " vec4 color[3];\n"
471 "} ubuf;\n"
472 "\n"
473 "layout (location = 0) out vec4 outColor;\n"
474 "\n"
475 "void main() \n"
476 "{\n"
477 " outColor = ubuf.color[gl_VertexID];\n"
478 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
479 "}\n";
480
481 static const char *fragShaderText =
482 "#version 140\n"
483 "#extension GL_ARB_separate_shader_objects : enable\n"
484 "#extension GL_ARB_shading_language_420pack : enable\n"
485 "\n"
486 "layout (location = 0) in vec4 inColor;\n"
487 "\n"
488 "void main()\n"
489 "{\n"
490 " gl_FragColor = inColor;\n"
491 "}\n";
492
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600493 TEST_DESCRIPTION("XGL-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
Tony Barbourae442072015-01-12 13:27:11 -0700494 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600495}
496
497TEST_F(XglRenderTest, XGLTriangle_OutputLocation)
498{
499 static const char *vertShaderText =
500 "#version 140\n"
501 "#extension GL_ARB_separate_shader_objects : enable\n"
502 "#extension GL_ARB_shading_language_420pack : enable\n"
503 "\n"
504 "layout(binding = 0) uniform buf {\n"
505 " mat4 MVP;\n"
506 " vec4 position[3];\n"
507 " vec4 color[3];\n"
508 "} ubuf;\n"
509 "\n"
510 "layout (location = 0) out vec4 outColor;\n"
511 "\n"
512 "void main() \n"
513 "{\n"
514 " outColor = ubuf.color[gl_VertexID];\n"
515 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
516 "}\n";
517
518 static const char *fragShaderText =
519 "#version 140\n"
520 "#extension GL_ARB_separate_shader_objects : enable\n"
521 "#extension GL_ARB_shading_language_420pack : enable\n"
522 "\n"
523 "layout (location = 0) in vec4 inColor;\n"
524 "layout (location = 0) out vec4 outColor;\n"
525 "\n"
526 "void main()\n"
527 "{\n"
528 " outColor = inColor;\n"
529 "}\n";
530
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600531 TEST_DESCRIPTION("XGL-style shaders where fragment shader outputs to output location 0, which should be the same as gl_FragColor");
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600532
Tony Barbourae442072015-01-12 13:27:11 -0700533 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600534}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600535#ifndef _WIN32 // Implicit (for now at least) in WIN32 is that we are using the Nvidia driver and it won't consume SPIRV yet
Cody Northropacfb0492015-03-17 15:55:58 -0600536TEST_F(XglRenderTest, SPV_XGLTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700537{
Cody Northropacfb0492015-03-17 15:55:58 -0600538 bool saved_use_spv = XglTestFramework::m_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700539
540 static const char *vertShaderText =
541 "#version 140\n"
542 "#extension GL_ARB_separate_shader_objects : enable\n"
543 "#extension GL_ARB_shading_language_420pack : enable\n"
544 "\n"
545 "layout(binding = 0) uniform buf {\n"
546 " mat4 MVP;\n"
547 " vec4 position[3];\n"
548 " vec4 color[3];\n"
549 "} ubuf;\n"
550 "\n"
551 "layout (location = 0) out vec4 outColor;\n"
552 "\n"
553 "void main() \n"
554 "{\n"
555 " outColor = ubuf.color[gl_VertexID];\n"
556 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
557 "}\n";
558
559 static const char *fragShaderText =
560 "#version 140\n"
561 "#extension GL_ARB_separate_shader_objects : enable\n"
562 "#extension GL_ARB_shading_language_420pack : enable\n"
563 "\n"
564 "layout (location = 0) in vec4 inColor;\n"
565 "\n"
566 "void main()\n"
567 "{\n"
568 " gl_FragColor = inColor;\n"
569 "}\n";
570
Cody Northropacfb0492015-03-17 15:55:58 -0600571 TEST_DESCRIPTION("XGL-style shaders, but force test framework to compile shader to SPV and pass SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700572
Cody Northropacfb0492015-03-17 15:55:58 -0600573 XglTestFramework::m_use_spv = true;
Tony Barbourf43b6982014-11-25 13:18:32 -0700574
Tony Barbourae442072015-01-12 13:27:11 -0700575 XGLTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700576
Cody Northropacfb0492015-03-17 15:55:58 -0600577 XglTestFramework::m_use_spv = saved_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700578}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600579#endif
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600580TEST_F(XglRenderTest, GreenTriangle)
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600581{
582 static const char *vertShaderText =
583 "#version 130\n"
584 "vec2 vertices[3];\n"
585 "void main() {\n"
586 " vertices[0] = vec2(-1.0, -1.0);\n"
587 " vertices[1] = vec2( 1.0, -1.0);\n"
588 " vertices[2] = vec2( 0.0, 1.0);\n"
589 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
590 "}\n";
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600591
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600592 static const char *fragShaderText =
593 "#version 130\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600594 "void main() {\n"
Steve K10b32512014-10-10 08:54:29 -0600595 " gl_FragColor = vec4(0,1,0,1);\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600596 "}\n";
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600597
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600598 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
599
Tony Barbourae442072015-01-12 13:27:11 -0700600 XGLTriangleTest(vertShaderText, fragShaderText, false);
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600601}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600602#ifndef _WIN32 // Implicit (for now at least) in WIN32 is that we are using the Nvidia driver and it won't consume SPIRV yet
Cody Northropacfb0492015-03-17 15:55:58 -0600603TEST_F(XglRenderTest, SPV_GreenTriangle)
Tony Barbourf43b6982014-11-25 13:18:32 -0700604{
Cody Northropacfb0492015-03-17 15:55:58 -0600605 bool saved_use_spv = XglTestFramework::m_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700606
607 static const char *vertShaderText =
608 "#version 130\n"
609 "vec2 vertices[3];\n"
610 "void main() {\n"
611 " vertices[0] = vec2(-1.0, -1.0);\n"
612 " vertices[1] = vec2( 1.0, -1.0);\n"
613 " vertices[2] = vec2( 0.0, 1.0);\n"
614 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
615 "}\n";
616
617 static const char *fragShaderText =
618 "#version 130\n"
619 "void main() {\n"
620 " gl_FragColor = vec4(0,1,0,1);\n"
621 "}\n";
622
Cody Northropacfb0492015-03-17 15:55:58 -0600623 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to SPV and gives SPV to driver.");
Tony Barbourf43b6982014-11-25 13:18:32 -0700624
Cody Northropacfb0492015-03-17 15:55:58 -0600625 XglTestFramework::m_use_spv = true;
Tony Barbourae442072015-01-12 13:27:11 -0700626 XGLTriangleTest(vertShaderText, fragShaderText, false);
Cody Northropacfb0492015-03-17 15:55:58 -0600627 XglTestFramework::m_use_spv = saved_use_spv;
Tony Barbourf43b6982014-11-25 13:18:32 -0700628}
Tony Barbour3a5cda02015-04-02 15:48:24 -0600629#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700630TEST_F(XglRenderTest, YellowTriangle)
631{
632 static const char *vertShaderText =
633 "#version 130\n"
634 "void main() {\n"
635 " vec2 vertices[3];"
636 " vertices[0] = vec2(-0.5, -0.5);\n"
637 " vertices[1] = vec2( 0.5, -0.5);\n"
638 " vertices[2] = vec2( 0.5, 0.5);\n"
639 " vec4 colors[3];\n"
640 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
641 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
642 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
643 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
644 "}\n";
645
646 static const char *fragShaderText =
647 "#version 130\n"
648 "void main() {\n"
649 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
650 "}\n";
651
Tony Barbourae442072015-01-12 13:27:11 -0700652 XGLTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700653}
654
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600655TEST_F(XglRenderTest, TriangleWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600656{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600657 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600658 "#version 140\n"
659 "#extension GL_ARB_separate_shader_objects : enable\n"
660 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700661 //XYZ1( -1, -1, -1 )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600662 "layout (location = 0) in vec4 pos;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700663 //XYZ1( 0.f, 0.f, 0.f )
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600664 "layout (location = 1) in vec4 inColor;\n"
665 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600666 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600667 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600668 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600669 "}\n";
670
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600671
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600672 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700673 "#version 140\n"
674 "#extension GL_ARB_separate_shader_objects : enable\n"
675 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600676 "layout (location = 0) in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700677 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600678 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700679 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600680 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600681
Tony Barbourf43b6982014-11-25 13:18:32 -0700682
683
684 ASSERT_NO_FATAL_FAILURE(InitState());
685 ASSERT_NO_FATAL_FAILURE(InitViewport());
686
687 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000688 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700689
690 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
691 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
692
693 XglPipelineObj pipelineobj(m_device);
694 pipelineobj.AddShader(&vs);
695 pipelineobj.AddShader(&ps);
696
697 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +0800698 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700699
Mark Lobodzinski15427102015-02-18 16:38:17 -0600700 m_memoryRefManager.AddMemoryRef(&meshBuffer);
701
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600702#define MESH_BIND_ID 0
Tony Barbourf43b6982014-11-25 13:18:32 -0700703 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600704 MESH_BIND_ID, // binding ID
Tony Barbourf43b6982014-11-25 13:18:32 -0700705 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
706 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
707 };
708
709 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600710 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
711 vi_attribs[0].location = 0; // location, position
712 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
713 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
714 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
715 vi_attribs[1].location = 1; // location, color
716 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
717 vi_attribs[1].offsetInBytes = 1*sizeof(float)*4; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -0700718
719 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
720 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600721 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -0700722
Tony Barboure4ed9942015-01-09 10:06:53 -0700723 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700724 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barboure4ed9942015-01-09 10:06:53 -0700725 XglCommandBufferObj cmdBuffer(m_device);
726 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700727
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600728 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
729
Tony Barboure4ed9942015-01-09 10:06:53 -0700730 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
731
Tony Barboure4ed9942015-01-09 10:06:53 -0700732 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
733
734 // render two triangles
735 cmdBuffer.Draw(0, 6, 0, 1);
736
737 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600738 EndCommandBuffer(cmdBuffer);
739
Mark Lobodzinski15427102015-02-18 16:38:17 -0600740 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barboure4ed9942015-01-09 10:06:53 -0700741
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700742 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barboure4ed9942015-01-09 10:06:53 -0700743 RecordImage(m_renderTargets[i]);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600744}
745
Chia-I Wue09d1a72014-12-05 10:32:23 +0800746TEST_F(XglRenderTest, TriangleMRT)
747{
748 static const char *vertShaderText =
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600749 "#version 140\n"
750 "#extension GL_ARB_separate_shader_objects : enable\n"
751 "#extension GL_ARB_shading_language_420pack : enable\n"
752 "layout (location = 0) in vec4 pos;\n"
Chia-I Wue09d1a72014-12-05 10:32:23 +0800753 "void main() {\n"
754 " gl_Position = pos;\n"
755 "}\n";
756
757 static const char *fragShaderText =
758 "#version 130\n"
759 "void main() {\n"
760 " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
761 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
762 "}\n";
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600763 const float vb_data[][2] = {
Chia-I Wue09d1a72014-12-05 10:32:23 +0800764 { -1.0f, -1.0f },
765 { 1.0f, -1.0f },
766 { -1.0f, 1.0f }
767 };
768
769 ASSERT_NO_FATAL_FAILURE(InitState());
770 ASSERT_NO_FATAL_FAILURE(InitViewport());
771
772 XglConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000773 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800774
775 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
776 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
777
778 XglPipelineObj pipelineobj(m_device);
779 pipelineobj.AddShader(&vs);
780 pipelineobj.AddShader(&ps);
781
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600782#define MESH_BUF_ID 0
Chia-I Wue09d1a72014-12-05 10:32:23 +0800783 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600784 MESH_BUF_ID, // Binding ID
785 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
786 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Chia-I Wue09d1a72014-12-05 10:32:23 +0800787 };
788
789 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attrib;
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600790 vi_attrib.binding = MESH_BUF_ID; // index into vertexBindingDescriptions
791 vi_attrib.location = 0;
792 vi_attrib.format = XGL_FMT_R32G32_SFLOAT; // format of source data
793 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
Chia-I Wue09d1a72014-12-05 10:32:23 +0800794
795 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
796 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600797 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800798
799 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -0600800 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800801
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700802 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(2));
803 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Mark Lobodzinski15427102015-02-18 16:38:17 -0600804 m_memoryRefManager.AddMemoryRef(&meshBuffer);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800805
806 XGL_PIPELINE_CB_ATTACHMENT_STATE att = {};
807 att.blendEnable = XGL_FALSE;
808 att.format = m_render_target_fmt;
809 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700810 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800811
Tony Barbour5ed79702015-01-07 14:31:52 -0700812 XglCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700813
Tony Barbour5ed79702015-01-07 14:31:52 -0700814 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
815 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barboure4ed9942015-01-09 10:06:53 -0700816
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600817 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbour5ed79702015-01-07 14:31:52 -0700818
Tony Barboure4ed9942015-01-09 10:06:53 -0700819 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
820
Tony Barbour5ed79702015-01-07 14:31:52 -0700821 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700822#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600823 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbour5ed79702015-01-07 14:31:52 -0700824 pDSDumpDot((char*)"triTest2.dot");
825#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600826
Tony Barbour5ed79702015-01-07 14:31:52 -0700827 // render triangle
828 cmdBuffer.Draw(0, 3, 0, 1);
829
830 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600831 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -0600832 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbour5ed79702015-01-07 14:31:52 -0700833
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700834 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbour5ed79702015-01-07 14:31:52 -0700835 RecordImage(m_renderTargets[i]);
836
Chia-I Wue09d1a72014-12-05 10:32:23 +0800837}
838
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700839TEST_F(XglRenderTest, QuadWithIndexedVertexFetch)
840{
841 static const char *vertShaderText =
842 "#version 140\n"
843 "#extension GL_ARB_separate_shader_objects : enable\n"
844 "#extension GL_ARB_shading_language_420pack : enable\n"
845 "layout(location = 0) in vec4 pos;\n"
846 "layout(location = 1) in vec4 inColor;\n"
847 "layout(location = 0) out vec4 outColor;\n"
848 "void main() {\n"
849 " outColor = inColor;\n"
850 " gl_Position = pos;\n"
851 "}\n";
852
853
854 static const char *fragShaderText =
855 "#version 140\n"
856 "#extension GL_ARB_separate_shader_objects : enable\n"
857 "#extension GL_ARB_shading_language_420pack : enable\n"
858 "layout(location = 0) in vec4 color;\n"
859 "void main() {\n"
860 " gl_FragColor = color;\n"
861 "}\n";
862
863 const Vertex g_vbData[] =
864 {
865 // first tri
866 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
867 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
868 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
869
870 // second tri
871 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
872 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
873 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
874 };
875
876 const uint16_t g_idxData[6] = {
877 0, 1, 2,
878 3, 4, 5,
879 };
880
881 ASSERT_NO_FATAL_FAILURE(InitState());
882 ASSERT_NO_FATAL_FAILURE(InitViewport());
883
884 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000885 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700886
887 XglIndexBufferObj indexBuffer(m_device);
888 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), XGL_INDEX_16, g_idxData);
Mark Lobodzinskid30f82a2015-02-16 14:24:23 -0600889 indexBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700890
891 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
892 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
893
894 XglPipelineObj pipelineobj(m_device);
895 pipelineobj.AddShader(&vs);
896 pipelineobj.AddShader(&ps);
897
898 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -0600899 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
900 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &indexBuffer);
901
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700902
Mark Lobodzinski15427102015-02-18 16:38:17 -0600903 m_memoryRefManager.AddMemoryRef(&meshBuffer);
904 m_memoryRefManager.AddMemoryRef(&indexBuffer);
905
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600906#define MESH_BIND_ID 0
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700907 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600908 MESH_BIND_ID, // binding ID
909 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
910 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700911 };
912
913 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600914 vi_attribs[0].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
915 vi_attribs[0].location = 0; // layout location of vertex attribute
916 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
917 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
918 vi_attribs[1].binding = MESH_BIND_ID; // binding ID from BINDING_DESCRIPTION array to use for this attribute
919 vi_attribs[1].location = 1; // layout location of vertex attribute
920 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
921 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700922
923 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
924 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700925
926 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700927 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700928 XglCommandBufferObj cmdBuffer(m_device);
929 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600930 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barboure4ed9942015-01-09 10:06:53 -0700931
932 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700933
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700934#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600935 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700936 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700937#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700938
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -0600939 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, MESH_BIND_ID);
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700940 cmdBuffer.BindIndexBuffer(&indexBuffer,0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700941
942 // render two triangles
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700943 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700944
945 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600946 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -0600947 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700948
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -0700949 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700950 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700951
952}
953
GregF6bef1212014-12-02 15:41:44 -0700954TEST_F(XglRenderTest, GreyandRedCirclesonBlue)
955{
956 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -0700957
GregF6bef1212014-12-02 15:41:44 -0700958 static const char *vertShaderText =
959 "#version 140\n"
960 "#extension GL_ARB_separate_shader_objects : enable\n"
961 "#extension GL_ARB_shading_language_420pack : enable\n"
962 "layout (location = 0) in vec4 pos;\n"
963 "layout (location = 0) out vec4 outColor;\n"
964 "layout (location = 1) out vec4 outColor2;\n"
965 "void main() {\n"
966 " gl_Position = pos;\n"
967 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
968 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
969 "}\n";
970
971 static const char *fragShaderText =
972 //"#version 140\n"
973 "#version 330\n"
974 "#extension GL_ARB_separate_shader_objects : enable\n"
975 "#extension GL_ARB_shading_language_420pack : enable\n"
976 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
977 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
978 "layout (location = 0) in vec4 color;\n"
979 "layout (location = 1) in vec4 color2;\n"
980 "void main() {\n"
981 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
982 " float dist_squared = dot(pos, pos);\n"
983 " gl_FragColor = (dist_squared < 400.0)\n"
984 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
985 " : color2;\n"
986 "}\n";
987
988 ASSERT_NO_FATAL_FAILURE(InitState());
989 ASSERT_NO_FATAL_FAILURE(InitViewport());
990
991 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000992 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -0700993
994 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
995 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
996
997 XglPipelineObj pipelineobj(m_device);
998 pipelineobj.AddShader(&vs);
999 pipelineobj.AddShader(&ps);
1000
1001 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001002 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001003
Mark Lobodzinski15427102015-02-18 16:38:17 -06001004 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1005
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001006#define MESH_BIND_ID 0
GregF6bef1212014-12-02 15:41:44 -07001007 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001008 MESH_BIND_ID, // binding ID
1009 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1010 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001011 };
1012
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001013 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[1];
1014 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1015 vi_attribs[0].location = 0;
1016 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
1017 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001018
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001019 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001020 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001021 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001022
Tony Barbourdd4c9642015-01-09 12:55:14 -07001023 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001024 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001025 XglCommandBufferObj cmdBuffer(m_device);
1026 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1027
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001028 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001029
1030 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1031
1032 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1033#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001034 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001035 pDSDumpDot((char*)"triTest2.dot");
1036#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001037
Tony Barbourdd4c9642015-01-09 12:55:14 -07001038 // render triangle
1039 cmdBuffer.Draw(0, 6, 0, 1);
1040
1041 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001042 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001043 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001044
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001045 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001046 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001047
1048}
1049
1050TEST_F(XglRenderTest, RedCirclesonBlue)
1051{
1052 // This tests that we correctly handle unread fragment inputs
1053
1054 static const char *vertShaderText =
1055 "#version 140\n"
1056 "#extension GL_ARB_separate_shader_objects : enable\n"
1057 "#extension GL_ARB_shading_language_420pack : enable\n"
1058 "layout (location = 0) in vec4 pos;\n"
1059 "layout (location = 0) out vec4 outColor;\n"
1060 "layout (location = 1) out vec4 outColor2;\n"
1061 "void main() {\n"
1062 " gl_Position = pos;\n"
1063 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1064 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1065 "}\n";
1066
1067 static const char *fragShaderText =
1068 //"#version 140\n"
1069 "#version 330\n"
1070 "#extension GL_ARB_separate_shader_objects : enable\n"
1071 "#extension GL_ARB_shading_language_420pack : enable\n"
1072 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1073 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1074 "layout (location = 0) in vec4 color;\n"
1075 "layout (location = 1) in vec4 color2;\n"
1076 "void main() {\n"
1077 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1078 " float dist_squared = dot(pos, pos);\n"
1079 " gl_FragColor = (dist_squared < 400.0)\n"
1080 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1081 " : color2;\n"
1082 "}\n";
1083
1084 ASSERT_NO_FATAL_FAILURE(InitState());
1085 ASSERT_NO_FATAL_FAILURE(InitViewport());
1086
1087 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001088 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001089
1090 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1091 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1092
1093 XglPipelineObj pipelineobj(m_device);
1094 pipelineobj.AddShader(&vs);
1095 pipelineobj.AddShader(&ps);
1096
1097 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001098 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001099
Mark Lobodzinski15427102015-02-18 16:38:17 -06001100 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1101
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001102#define MESH_BIND_ID 0
GregF6bef1212014-12-02 15:41:44 -07001103 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001104 MESH_BIND_ID, // binding ID
1105 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1106 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001107 };
1108
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001109 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[1];
1110 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1111 vi_attribs[0].location = 0;
1112 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
1113 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001114
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001115 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001116 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001117 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001118
Tony Barbourdd4c9642015-01-09 12:55:14 -07001119 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001120 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001121 XglCommandBufferObj cmdBuffer(m_device);
1122 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1123
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001124 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001125
1126 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1127
1128 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1129#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001130 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001131 pDSDumpDot((char*)"triTest2.dot");
1132#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001133 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001134 cmdBuffer.Draw(0, 6, 0, 1);
1135
1136 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001137 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001138 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001139
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001140 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001141 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001142
1143}
1144
1145TEST_F(XglRenderTest, GreyCirclesonBlueFade)
1146{
1147 // This tests reading gl_ClipDistance from FS
1148
1149 static const char *vertShaderText =
1150 "#version 330\n"
1151 "#extension GL_ARB_separate_shader_objects : enable\n"
1152 "#extension GL_ARB_shading_language_420pack : enable\n"
1153 "out gl_PerVertex {\n"
1154 " vec4 gl_Position;\n"
1155 " float gl_ClipDistance[1];\n"
1156 "};\n"
1157 "layout (location = 0) in vec4 pos;\n"
1158 "layout (location = 0) out vec4 outColor;\n"
1159 "layout (location = 1) out vec4 outColor2;\n"
1160 "void main() {\n"
1161 " gl_Position = pos;\n"
1162 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1163 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1164 " float dists[3];\n"
1165 " dists[0] = 0.0;\n"
1166 " dists[1] = 1.0;\n"
1167 " dists[2] = 1.0;\n"
1168 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1169 "}\n";
1170
1171
1172 static const char *fragShaderText =
1173 //"#version 140\n"
1174 "#version 330\n"
1175 "#extension GL_ARB_separate_shader_objects : enable\n"
1176 "#extension GL_ARB_shading_language_420pack : enable\n"
1177 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1178 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1179 "layout (location = 0) in vec4 color;\n"
1180 "layout (location = 1) in vec4 color2;\n"
1181 "void main() {\n"
1182 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1183 " float dist_squared = dot(pos, pos);\n"
1184 " gl_FragColor = (dist_squared < 400.0)\n"
1185 " ? color * gl_ClipDistance[0]\n"
1186 " : color2;\n"
1187 "}\n";
1188
1189 ASSERT_NO_FATAL_FAILURE(InitState());
1190 ASSERT_NO_FATAL_FAILURE(InitViewport());
1191
1192 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001193 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001194
1195 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1196 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1197
1198 XglPipelineObj pipelineobj(m_device);
1199 pipelineobj.AddShader(&vs);
1200 pipelineobj.AddShader(&ps);
1201
1202 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001203 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001204
Mark Lobodzinski15427102015-02-18 16:38:17 -06001205 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1206
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001207#define MESH_BIND_ID 0
GregF6bef1212014-12-02 15:41:44 -07001208 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001209 MESH_BIND_ID, // binding ID
1210 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1211 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF6bef1212014-12-02 15:41:44 -07001212 };
1213
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001214 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[1];
1215 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1216 vi_attribs[0].location = 0;
1217 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
1218 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF6bef1212014-12-02 15:41:44 -07001219
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001220 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF6bef1212014-12-02 15:41:44 -07001221 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001222 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF6bef1212014-12-02 15:41:44 -07001223
Tony Barbourdd4c9642015-01-09 12:55:14 -07001224 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001225 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001226 XglCommandBufferObj cmdBuffer(m_device);
1227 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF6bef1212014-12-02 15:41:44 -07001228
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001229 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001230
1231 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1232
1233 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1234#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001235 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001236 pDSDumpDot((char*)"triTest2.dot");
1237#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001238
1239 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001240 cmdBuffer.Draw(0, 6, 0, 1);
1241
1242 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001243 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001244 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001245
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001246 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001247 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001248}
Tony Barbourf43b6982014-11-25 13:18:32 -07001249
GregF7a23c792014-12-02 17:19:34 -07001250TEST_F(XglRenderTest, GreyCirclesonBlueDiscard)
1251{
1252 static const char *vertShaderText =
1253 "#version 140\n"
1254 "#extension GL_ARB_separate_shader_objects : enable\n"
1255 "#extension GL_ARB_shading_language_420pack : enable\n"
1256 "layout (location = 0) in vec4 pos;\n"
1257 "layout (location = 0) out vec4 outColor;\n"
1258 "layout (location = 1) out vec4 outColor2;\n"
1259 "void main() {\n"
1260 " gl_Position = pos;\n"
1261 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1262 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1263 "}\n";
1264
1265
1266 static const char *fragShaderText =
1267 //"#version 140\n"
1268 "#version 330\n"
1269 "#extension GL_ARB_separate_shader_objects : enable\n"
1270 "#extension GL_ARB_shading_language_420pack : enable\n"
1271 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1272 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1273 "layout (location = 0) in vec4 color;\n"
1274 "layout (location = 1) in vec4 color2;\n"
1275 "void main() {\n"
1276 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1277 " float dist_squared = dot(pos, pos);\n"
1278 " if (dist_squared < 100.0)\n"
1279 " discard;\n"
1280 " gl_FragColor = (dist_squared < 400.0)\n"
1281 " ? color\n"
1282 " : color2;\n"
1283 "}\n";
1284
1285 ASSERT_NO_FATAL_FAILURE(InitState());
1286 ASSERT_NO_FATAL_FAILURE(InitViewport());
1287
1288 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001289 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001290
1291 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1292 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1293
1294 XglPipelineObj pipelineobj(m_device);
1295 pipelineobj.AddShader(&vs);
1296 pipelineobj.AddShader(&ps);
1297
1298 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001299 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF7a23c792014-12-02 17:19:34 -07001300
Mark Lobodzinski15427102015-02-18 16:38:17 -06001301 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1302
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001303#define MESH_BIND_ID 0
GregF7a23c792014-12-02 17:19:34 -07001304 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001305 MESH_BIND_ID, // binding ID
1306 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1307 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
GregF7a23c792014-12-02 17:19:34 -07001308 };
1309
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001310 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[1];
1311 vi_attribs[0].binding = MESH_BIND_ID; // binding ID
1312 vi_attribs[0].location = 0;
1313 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
1314 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
GregF7a23c792014-12-02 17:19:34 -07001315
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001316 pipelineobj.AddVertexInputAttribs(vi_attribs,1);
GregF7a23c792014-12-02 17:19:34 -07001317 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001318 pipelineobj.AddVertexDataBuffer(&meshBuffer,MESH_BIND_ID);
GregF7a23c792014-12-02 17:19:34 -07001319
Tony Barbourdd4c9642015-01-09 12:55:14 -07001320 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001321 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001322 XglCommandBufferObj cmdBuffer(m_device);
1323 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1324
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001325 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001326
1327 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1328
1329 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1330#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001331 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001332 pDSDumpDot((char*)"triTest2.dot");
1333#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001334
1335 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001336 cmdBuffer.Draw(0, 6, 0, 1);
1337
1338 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001339 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001340 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001341
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001342 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001343 RecordImage(m_renderTargets[i]);
GregF7a23c792014-12-02 17:19:34 -07001344
1345}
1346
1347
Courtney Goeltzenleuchter3d10c9c2014-10-27 13:06:08 -06001348TEST_F(XglRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001349{
1350 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001351 "#version 140\n"
1352 "#extension GL_ARB_separate_shader_objects : enable\n"
1353 "#extension GL_ARB_shading_language_420pack : enable\n"
1354 "\n"
1355 "layout(binding = 0) uniform buf {\n"
1356 " mat4 MVP;\n"
1357 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001358 "void main() {\n"
1359 " vec2 vertices[3];"
1360 " vertices[0] = vec2(-0.5, -0.5);\n"
1361 " vertices[1] = vec2( 0.5, -0.5);\n"
1362 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001363 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001364 "}\n";
1365
1366 static const char *fragShaderText =
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001367 "#version 130\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001368 "void main() {\n"
Cody Northrop78eac042014-10-10 15:45:00 -06001369 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001370 "}\n";
1371
Tony Barbourf43b6982014-11-25 13:18:32 -07001372 ASSERT_NO_FATAL_FAILURE(InitState());
1373 ASSERT_NO_FATAL_FAILURE(InitViewport());
1374
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001375 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001376 glm::mat4 Projection = glm::mat4(1.0f);
1377 glm::mat4 View = glm::mat4(1.0f);
1378 glm::mat4 Model = glm::mat4(1.0f);
1379 glm::mat4 MVP = Projection * View * Model;
1380 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1381
Tony Barbourf43b6982014-11-25 13:18:32 -07001382 XglConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1383 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1384 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001385
Tony Barbourf43b6982014-11-25 13:18:32 -07001386 XglPipelineObj pipelineobj(m_device);
1387 pipelineobj.AddShader(&vs);
1388 pipelineobj.AddShader(&ps);
1389
1390 // Create descriptor set and attach the constant buffer to it
1391 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001392 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001393
1394 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1395
Tony Barbourdd4c9642015-01-09 12:55:14 -07001396 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001397 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001398 XglCommandBufferObj cmdBuffer(m_device);
1399 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001400
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001401 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001402
1403 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1404
1405 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1406#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001407 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001408 pDSDumpDot((char*)"triTest2.dot");
1409#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001410
1411 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001412 cmdBuffer.Draw(0, 6, 0, 1);
1413
1414 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001415 EndCommandBuffer(cmdBuffer);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001416 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
1417
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001418 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001419 RecordImage(m_renderTargets[i]);
1420
1421 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001422}
1423
Tony Barbourf43b6982014-11-25 13:18:32 -07001424TEST_F(XglRenderTest, MixTriangle)
1425{
1426 // This tests location applied to varyings. Notice that we have switched foo
1427 // and bar in the FS. The triangle should be blended with red, green and blue
1428 // corners.
1429 static const char *vertShaderText =
1430 "#version 140\n"
1431 "#extension GL_ARB_separate_shader_objects : enable\n"
1432 "#extension GL_ARB_shading_language_420pack : enable\n"
1433 "layout (location=0) out vec4 bar;\n"
1434 "layout (location=1) out vec4 foo;\n"
1435 "layout (location=2) out float scale;\n"
1436 "vec2 vertices[3];\n"
1437 "void main() {\n"
1438 " vertices[0] = vec2(-1.0, -1.0);\n"
1439 " vertices[1] = vec2( 1.0, -1.0);\n"
1440 " vertices[2] = vec2( 0.0, 1.0);\n"
1441 "vec4 colors[3];\n"
1442 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1443 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1444 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1445 " foo = colors[gl_VertexID % 3];\n"
1446 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1447 " scale = 1.0;\n"
1448 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1449 "}\n";
1450
1451 static const char *fragShaderText =
1452 "#version 140\n"
1453 "#extension GL_ARB_separate_shader_objects : enable\n"
1454 "#extension GL_ARB_shading_language_420pack : enable\n"
1455 "layout (location = 1) in vec4 bar;\n"
1456 "layout (location = 0) in vec4 foo;\n"
1457 "layout (location = 2) in float scale;\n"
1458 "void main() {\n"
1459 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
1460 "}\n";
1461
1462 ASSERT_NO_FATAL_FAILURE(InitState());
1463 ASSERT_NO_FATAL_FAILURE(InitViewport());
1464
1465 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1466 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1467
1468 XglPipelineObj pipelineobj(m_device);
1469 pipelineobj.AddShader(&vs);
1470 pipelineobj.AddShader(&ps);
1471
1472 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06001473 descriptorSet.AppendDummy();
Tony Barbourf43b6982014-11-25 13:18:32 -07001474
Tony Barbourdd4c9642015-01-09 12:55:14 -07001475 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001476 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001477 XglCommandBufferObj cmdBuffer(m_device);
1478 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1479
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001480 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001481
1482 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1483
1484#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001485 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001486 pDSDumpDot((char*)"triTest2.dot");
1487#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001488
Tony Barbourdd4c9642015-01-09 12:55:14 -07001489 // render triangle
1490 cmdBuffer.Draw(0, 3, 0, 1);
1491
1492 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001493 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001494 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001495
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001496 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001497 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001498}
1499
1500TEST_F(XglRenderTest, TriVertFetchAndVertID)
1501{
1502 // This tests that attributes work in the presence of gl_VertexID
1503
1504 static const char *vertShaderText =
1505 "#version 140\n"
1506 "#extension GL_ARB_separate_shader_objects : enable\n"
1507 "#extension GL_ARB_shading_language_420pack : enable\n"
1508 //XYZ1( -1, -1, -1 )
1509 "layout (location = 0) in vec4 pos;\n"
1510 //XYZ1( 0.f, 0.f, 0.f )
1511 "layout (location = 1) in vec4 inColor;\n"
1512 "layout (location = 0) out vec4 outColor;\n"
1513 "void main() {\n"
1514 " outColor = inColor;\n"
1515 " vec4 vertices[3];"
1516 " vertices[gl_VertexID % 3] = pos;\n"
1517 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1518 "}\n";
1519
1520
1521 static const char *fragShaderText =
1522 "#version 140\n"
1523 "#extension GL_ARB_separate_shader_objects : enable\n"
1524 "#extension GL_ARB_shading_language_420pack : enable\n"
1525 "layout (location = 0) in vec4 color;\n"
1526 "void main() {\n"
1527 " gl_FragColor = color;\n"
1528 "}\n";
1529
1530 ASSERT_NO_FATAL_FAILURE(InitState());
1531 ASSERT_NO_FATAL_FAILURE(InitViewport());
1532
1533 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001534 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001535
1536 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1537 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1538
1539 XglPipelineObj pipelineobj(m_device);
1540 pipelineobj.AddShader(&vs);
1541 pipelineobj.AddShader(&ps);
1542
1543 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001544 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001545
Mark Lobodzinski15427102015-02-18 16:38:17 -06001546 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1547
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001548#define MESH_BUF_ID 0
Tony Barbourf43b6982014-11-25 13:18:32 -07001549 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001550 MESH_BUF_ID, // Binding ID
1551 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1552 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001553 };
1554
1555 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001556 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1557 vi_attribs[0].location = 0;
1558 vi_attribs[0].format = XGL_FMT_R32G32_SFLOAT; // format of source data
1559 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1560 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1561 vi_attribs[1].location = 1;
1562 vi_attribs[1].format = XGL_FMT_R32G32_SFLOAT; // format of source data
1563 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001564
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001565 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001566 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001567 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001568
Tony Barbourdd4c9642015-01-09 12:55:14 -07001569 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001570 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001571 XglCommandBufferObj cmdBuffer(m_device);
1572 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1573
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001574 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001575
1576 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1577
1578 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1579#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001580 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001581 pDSDumpDot((char*)"triTest2.dot");
1582#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001583
1584 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001585 cmdBuffer.Draw(0, 6, 0, 1);
1586
1587 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001588 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001589 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001590
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001591 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001592 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001593}
1594
1595TEST_F(XglRenderTest, TriVertFetchDeadAttr)
1596{
1597 // This tests that attributes work in the presence of gl_VertexID
1598 // and a dead attribute in position 0. Draws a triangle with yellow,
1599 // red and green corners, starting at top and going clockwise.
1600
1601 static const char *vertShaderText =
1602 "#version 140\n"
1603 "#extension GL_ARB_separate_shader_objects : enable\n"
1604 "#extension GL_ARB_shading_language_420pack : enable\n"
1605 //XYZ1( -1, -1, -1 )
1606 "layout (location = 0) in vec4 pos;\n"
1607 //XYZ1( 0.f, 0.f, 0.f )
1608 "layout (location = 1) in vec4 inColor;\n"
1609 "layout (location = 0) out vec4 outColor;\n"
1610 "void main() {\n"
1611 " outColor = inColor;\n"
1612 " vec2 vertices[3];"
1613 " vertices[0] = vec2(-1.0, -1.0);\n"
1614 " vertices[1] = vec2( 1.0, -1.0);\n"
1615 " vertices[2] = vec2( 0.0, 1.0);\n"
1616 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1617 "}\n";
1618
1619
1620 static const char *fragShaderText =
1621 "#version 140\n"
1622 "#extension GL_ARB_separate_shader_objects : enable\n"
1623 "#extension GL_ARB_shading_language_420pack : enable\n"
1624 "layout (location = 0) in vec4 color;\n"
1625 "void main() {\n"
1626 " gl_FragColor = color;\n"
1627 "}\n";
1628
1629 ASSERT_NO_FATAL_FAILURE(InitState());
1630 ASSERT_NO_FATAL_FAILURE(InitViewport());
1631
1632 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001633 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001634
1635 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1636 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1637
1638 XglPipelineObj pipelineobj(m_device);
1639 pipelineobj.AddShader(&vs);
1640 pipelineobj.AddShader(&ps);
1641
1642 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001643 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001644
Mark Lobodzinski15427102015-02-18 16:38:17 -06001645 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1646
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001647#define MESH_BUF_ID 0
Tony Barbourf43b6982014-11-25 13:18:32 -07001648 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001649 MESH_BUF_ID, // Binding ID
1650 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1651 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
Tony Barbourf43b6982014-11-25 13:18:32 -07001652 };
1653
1654 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001655 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1656 vi_attribs[0].location = 0;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001657 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001658 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1659 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1660 vi_attribs[1].location = 1;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001661 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001662 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001663
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001664 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001665 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001666 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001667
Tony Barbourdd4c9642015-01-09 12:55:14 -07001668 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001669 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001670 XglCommandBufferObj cmdBuffer(m_device);
1671 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001672
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001673 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001674
1675 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1676
1677 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1678#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001679 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001680 pDSDumpDot((char*)"triTest2.dot");
1681#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001682
1683 // render two triangles
Tony Barbourdd4c9642015-01-09 12:55:14 -07001684 cmdBuffer.Draw(0, 6, 0, 1);
1685
1686 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001687 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001688 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001689
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001690 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001691 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001692}
1693
1694TEST_F(XglRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001695{
1696 static const char *vertShaderText =
1697 "#version 140\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001698 "#extension GL_ARB_separate_shader_objects : enable\n"
1699 "#extension GL_ARB_shading_language_420pack : enable\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001700 "layout (std140) uniform bufferVals {\n"
1701 " mat4 mvp;\n"
1702 "} myBufferVals;\n"
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001703 "layout (location = 0) in vec4 pos;\n"
1704 "layout (location = 1) in vec4 inColor;\n"
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001705 "out vec4 outColor;\n"
1706 "void main() {\n"
1707 " outColor = inColor;\n"
1708 " gl_Position = myBufferVals.mvp * pos;\n"
1709 "}\n";
1710
1711 static const char *fragShaderText =
1712 "#version 130\n"
1713 "in vec4 color;\n"
1714 "void main() {\n"
1715 " gl_FragColor = color;\n"
1716 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001717 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001718
Tony Barbourf43b6982014-11-25 13:18:32 -07001719 glm::mat4 View = glm::lookAt(
1720 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1721 glm::vec3(0,0,0), // and looks at the origin
1722 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
1723 );
1724
1725 glm::mat4 Model = glm::mat4(1.0f);
1726
1727 glm::mat4 MVP = Projection * View * Model;
1728
1729 ASSERT_NO_FATAL_FAILURE(InitState());
1730 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour17c6ab12015-03-27 17:03:18 -06001731 m_depthStencil->Init(m_device, m_width, m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07001732
1733 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
1734 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1735
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001736 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07001737
1738 XglConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1739 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1740 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1741
Tony Barbourf43b6982014-11-25 13:18:32 -07001742 XglPipelineObj pipelineobj(m_device);
1743 pipelineobj.AddShader(&vs);
1744 pipelineobj.AddShader(&ps);
1745
Tony Barbourfa6cac72015-01-16 14:27:35 -07001746 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
1747 ds_state.depthTestEnable = XGL_TRUE;
1748 ds_state.depthWriteEnable = XGL_TRUE;
1749 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
1750 ds_state.depthBoundsEnable = XGL_FALSE;
1751 ds_state.stencilTestEnable = XGL_FALSE;
1752 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
1753 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
1754 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
1755 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001756 ds_state.format = XGL_FMT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001757 ds_state.front = ds_state.back;
1758 pipelineobj.SetDepthStencil(&ds_state);
1759
Tony Barbourf43b6982014-11-25 13:18:32 -07001760 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001761 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001762
1763 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1764 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
Tony Barbour17c6ab12015-03-27 17:03:18 -06001765 m_memoryRefManager.AddMemoryRef(m_depthStencil);
Tony Barbourf43b6982014-11-25 13:18:32 -07001766
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001767#define MESH_BUF_ID 0
Tony Barbourf43b6982014-11-25 13:18:32 -07001768 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001769 MESH_BUF_ID, // Binding ID
1770 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1771 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1772 };
Tony Barbourf43b6982014-11-25 13:18:32 -07001773
Tony Barbourf43b6982014-11-25 13:18:32 -07001774 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001775 vi_attribs[0].binding = MESH_BUF_ID; // binding ID
1776 vi_attribs[0].location = 0;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001777 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001778 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1779 vi_attribs[1].binding = MESH_BUF_ID; // binding ID
1780 vi_attribs[1].location = 1;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07001781 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001782 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07001783
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001784 pipelineobj.AddVertexInputAttribs(vi_attribs, 2);
Tony Barbourf43b6982014-11-25 13:18:32 -07001785 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06001786 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BUF_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07001787
Tony Barbour17c6ab12015-03-27 17:03:18 -06001788 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001789 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbour17c6ab12015-03-27 17:03:18 -06001790
Tony Barboure4ed9942015-01-09 10:06:53 -07001791 XglCommandBufferObj cmdBuffer(m_device);
1792 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001793
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001794 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barboure4ed9942015-01-09 10:06:53 -07001795 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001796
Tony Barboure4ed9942015-01-09 10:06:53 -07001797 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1798#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001799 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barboure4ed9942015-01-09 10:06:53 -07001800 pDSDumpDot((char*)"triTest2.dot");
1801#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001802
1803 // render triangles
Tony Barboure4ed9942015-01-09 10:06:53 -07001804 cmdBuffer.Draw(0, 36, 0, 1);
1805
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001806
Tony Barboure4ed9942015-01-09 10:06:53 -07001807 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001808 EndCommandBuffer(cmdBuffer);
Tony Barbourdd4c9642015-01-09 12:55:14 -07001809 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barboure4ed9942015-01-09 10:06:53 -07001810
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001811 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barboure4ed9942015-01-09 10:06:53 -07001812 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001813}
1814
Tony Barbourf43b6982014-11-25 13:18:32 -07001815TEST_F(XglRenderTest, VSTexture)
1816{
1817 // The expected result from this test is a green and red triangle;
1818 // one red vertex on the left, two green vertices on the right.
1819 static const char *vertShaderText =
1820 "#version 130\n"
1821 "out vec4 texColor;\n"
1822 "uniform sampler2D surface;\n"
1823 "void main() {\n"
1824 " vec2 vertices[3];"
1825 " vertices[0] = vec2(-0.5, -0.5);\n"
1826 " vertices[1] = vec2( 0.5, -0.5);\n"
1827 " vertices[2] = vec2( 0.5, 0.5);\n"
1828 " vec2 positions[3];"
1829 " positions[0] = vec2( 0.0, 0.0);\n"
1830 " positions[1] = vec2( 0.25, 0.1);\n"
1831 " positions[2] = vec2( 0.1, 0.25);\n"
1832 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1833 " texColor = textureLod(surface, samplePos, 0.0);\n"
1834 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1835 "}\n";
1836
1837 static const char *fragShaderText =
1838 "#version 130\n"
1839 "in vec4 texColor;\n"
1840 "void main() {\n"
1841 " gl_FragColor = texColor;\n"
1842 "}\n";
1843
1844 ASSERT_NO_FATAL_FAILURE(InitState());
1845 ASSERT_NO_FATAL_FAILURE(InitViewport());
1846
1847 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1848 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1849 XglSamplerObj sampler(m_device);
1850 XglTextureObj texture(m_device);
1851
Tony Barbourf43b6982014-11-25 13:18:32 -07001852 XglPipelineObj pipelineobj(m_device);
1853 pipelineobj.AddShader(&vs);
1854 pipelineobj.AddShader(&ps);
1855
1856 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001857 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001858
1859 m_memoryRefManager.AddMemoryRef(&texture);
1860
Tony Barbourdd4c9642015-01-09 12:55:14 -07001861 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001862 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001863 XglCommandBufferObj cmdBuffer(m_device);
1864 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001865
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001866 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001867
1868 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1869
1870#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001871 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001872 pDSDumpDot((char*)"triTest2.dot");
1873#endif
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001874
Tony Barbourdd4c9642015-01-09 12:55:14 -07001875 // render triangle
1876 cmdBuffer.Draw(0, 3, 0, 1);
1877
1878 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001879 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001880 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001881
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001882 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001883 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001884}
1885TEST_F(XglRenderTest, TexturedTriangle)
1886{
1887 // The expected result from this test is a red and green checkered triangle
1888 static const char *vertShaderText =
1889 "#version 140\n"
1890 "#extension GL_ARB_separate_shader_objects : enable\n"
1891 "#extension GL_ARB_shading_language_420pack : enable\n"
1892 "layout (location = 0) out vec2 samplePos;\n"
1893 "void main() {\n"
1894 " vec2 vertices[3];"
1895 " vertices[0] = vec2(-0.5, -0.5);\n"
1896 " vertices[1] = vec2( 0.5, -0.5);\n"
1897 " vertices[2] = vec2( 0.5, 0.5);\n"
1898 " vec2 positions[3];"
1899 " positions[0] = vec2( 0.0, 0.0);\n"
1900 " positions[1] = vec2( 1.0, 0.0);\n"
1901 " positions[2] = vec2( 1.0, 1.0);\n"
1902 " samplePos = positions[gl_VertexID % 3];\n"
1903 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1904 "}\n";
1905
1906 static const char *fragShaderText =
1907 "#version 140\n"
1908 "#extension GL_ARB_separate_shader_objects : enable\n"
1909 "#extension GL_ARB_shading_language_420pack : enable\n"
1910 "layout (location = 0) in vec2 samplePos;\n"
1911 "layout (binding = 0) uniform sampler2D surface;\n"
1912 "layout (location=0) out vec4 outColor;\n"
1913 "void main() {\n"
1914 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1915 " outColor = texColor;\n"
1916 "}\n";
1917
1918 ASSERT_NO_FATAL_FAILURE(InitState());
1919 ASSERT_NO_FATAL_FAILURE(InitViewport());
1920
1921 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1922 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1923 XglSamplerObj sampler(m_device);
1924 XglTextureObj texture(m_device);
1925
Tony Barbourf43b6982014-11-25 13:18:32 -07001926 XglPipelineObj pipelineobj(m_device);
1927 pipelineobj.AddShader(&vs);
1928 pipelineobj.AddShader(&ps);
1929
1930 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001931 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001932
1933 m_memoryRefManager.AddMemoryRef(&texture);
1934
Tony Barbourdd4c9642015-01-09 12:55:14 -07001935 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001936 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001937 XglCommandBufferObj cmdBuffer(m_device);
1938 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1939
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001940 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001941
1942 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1943
1944#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001945 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07001946 pDSDumpDot((char*)"triTest2.dot");
1947#endif
1948 // render triangle
1949 cmdBuffer.Draw(0, 3, 0, 1);
1950
1951 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001952 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001953 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07001954
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07001955 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07001956 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001957}
1958TEST_F(XglRenderTest, TexturedTriangleClip)
1959{
1960 // The expected result from this test is a red and green checkered triangle
1961 static const char *vertShaderText =
1962 "#version 330\n"
1963 "#extension GL_ARB_separate_shader_objects : enable\n"
1964 "#extension GL_ARB_shading_language_420pack : enable\n"
1965 "layout (location = 0) out vec2 samplePos;\n"
1966 "out gl_PerVertex {\n"
1967 " vec4 gl_Position;\n"
1968 " float gl_ClipDistance[1];\n"
1969 "};\n"
1970 "void main() {\n"
1971 " vec2 vertices[3];"
1972 " vertices[0] = vec2(-0.5, -0.5);\n"
1973 " vertices[1] = vec2( 0.5, -0.5);\n"
1974 " vertices[2] = vec2( 0.5, 0.5);\n"
1975 " vec2 positions[3];"
1976 " positions[0] = vec2( 0.0, 0.0);\n"
1977 " positions[1] = vec2( 1.0, 0.0);\n"
1978 " positions[2] = vec2( 1.0, 1.0);\n"
1979 " float dists[3];\n"
1980 " dists[0] = 1.0;\n"
1981 " dists[1] = 1.0;\n"
1982 " dists[2] = -1.0;\n"
1983 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1984 " samplePos = positions[gl_VertexID % 3];\n"
1985 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1986 "}\n";
1987
1988 static const char *fragShaderText =
1989 "#version 140\n"
1990 "#extension GL_ARB_separate_shader_objects : enable\n"
1991 "#extension GL_ARB_shading_language_420pack : enable\n"
1992 "layout (location = 0) in vec2 samplePos;\n"
1993 "layout (binding = 0) uniform sampler2D surface;\n"
1994 "layout (location=0) out vec4 outColor;\n"
1995 "void main() {\n"
1996 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
1997 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1998 " outColor = texColor;\n"
1999 "}\n";
2000
2001
2002 ASSERT_NO_FATAL_FAILURE(InitState());
2003 ASSERT_NO_FATAL_FAILURE(InitViewport());
2004
2005 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2006 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2007 XglSamplerObj sampler(m_device);
2008 XglTextureObj texture(m_device);
2009
Tony Barbourf43b6982014-11-25 13:18:32 -07002010 XglPipelineObj pipelineobj(m_device);
2011 pipelineobj.AddShader(&vs);
2012 pipelineobj.AddShader(&ps);
2013
2014 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002015 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002016
2017 m_memoryRefManager.AddMemoryRef(&texture);
2018
Tony Barbourdd4c9642015-01-09 12:55:14 -07002019 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002020 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002021 XglCommandBufferObj cmdBuffer(m_device);
2022 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2023
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002024 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002025
2026 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2027
2028#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002029 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002030 pDSDumpDot((char*)"triTest2.dot");
2031#endif
2032 // render triangle
2033 cmdBuffer.Draw(0, 3, 0, 1);
2034
2035 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002036 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002037 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002038
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002039 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002040 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002041}
2042TEST_F(XglRenderTest, FSTriangle)
2043{
2044 // The expected result from this test is a red and green checkered triangle
2045 static const char *vertShaderText =
2046 "#version 140\n"
2047 "#extension GL_ARB_separate_shader_objects : enable\n"
2048 "#extension GL_ARB_shading_language_420pack : enable\n"
2049 "layout (location = 0) out vec2 samplePos;\n"
2050 "void main() {\n"
2051 " vec2 vertices[3];"
2052 " vertices[0] = vec2(-0.5, -0.5);\n"
2053 " vertices[1] = vec2( 0.5, -0.5);\n"
2054 " vertices[2] = vec2( 0.5, 0.5);\n"
2055 " vec2 positions[3];"
2056 " positions[0] = vec2( 0.0, 0.0);\n"
2057 " positions[1] = vec2( 1.0, 0.0);\n"
2058 " positions[2] = vec2( 1.0, 1.0);\n"
2059 " samplePos = positions[gl_VertexID % 3];\n"
2060 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2061 "}\n";
2062
2063 static const char *fragShaderText =
2064 "#version 140\n"
2065 "#extension GL_ARB_separate_shader_objects : enable\n"
2066 "#extension GL_ARB_shading_language_420pack : enable\n"
2067 "layout (location = 0) in vec2 samplePos;\n"
2068 "layout (binding = 0) uniform sampler2D surface;\n"
2069 "layout (location=0) out vec4 outColor;\n"
2070 "void main() {\n"
2071 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2072 " outColor = texColor;\n"
2073 "}\n";
2074
2075 ASSERT_NO_FATAL_FAILURE(InitState());
2076 ASSERT_NO_FATAL_FAILURE(InitViewport());
2077
2078 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2079 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2080 XglSamplerObj sampler(m_device);
2081 XglTextureObj texture(m_device);
2082
Tony Barbourf43b6982014-11-25 13:18:32 -07002083 XglPipelineObj pipelineobj(m_device);
2084 pipelineobj.AddShader(&vs);
2085 pipelineobj.AddShader(&ps);
2086
2087 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002088 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002089
2090 m_memoryRefManager.AddMemoryRef(&texture);
2091
Tony Barbourdd4c9642015-01-09 12:55:14 -07002092 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002093 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002094 XglCommandBufferObj cmdBuffer(m_device);
2095 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2096
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002097 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002098
2099 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2100
2101#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002102 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002103 pDSDumpDot((char*)"triTest2.dot");
2104#endif
2105 // render triangle
2106 cmdBuffer.Draw(0, 3, 0, 1);
2107
2108 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002109 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002110 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002111
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002112 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002113 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002114}
2115TEST_F(XglRenderTest, SamplerBindingsTriangle)
2116{
2117 // This test sets bindings on the samplers
2118 // For now we are asserting that sampler and texture pairs
2119 // march in lock step, and are set via GLSL binding. This can
2120 // and will probably change.
2121 // The sampler bindings should match the sampler and texture slot
2122 // number set up by the application.
2123 // This test will result in a blue triangle
2124 static const char *vertShaderText =
2125 "#version 140\n"
2126 "#extension GL_ARB_separate_shader_objects : enable\n"
2127 "#extension GL_ARB_shading_language_420pack : enable\n"
2128 "layout (location = 0) out vec4 samplePos;\n"
2129 "void main() {\n"
2130 " vec2 vertices[3];"
2131 " vertices[0] = vec2(-0.5, -0.5);\n"
2132 " vertices[1] = vec2( 0.5, -0.5);\n"
2133 " vertices[2] = vec2( 0.5, 0.5);\n"
2134 " vec2 positions[3];"
2135 " positions[0] = vec2( 0.0, 0.0);\n"
2136 " positions[1] = vec2( 1.0, 0.0);\n"
2137 " positions[2] = vec2( 1.0, 1.0);\n"
2138 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2139 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2140 "}\n";
2141
2142 static const char *fragShaderText =
2143 "#version 140\n"
2144 "#extension GL_ARB_separate_shader_objects : enable\n"
2145 "#extension GL_ARB_shading_language_420pack : enable\n"
2146 "layout (location = 0) in vec4 samplePos;\n"
2147 "layout (binding = 0) uniform sampler2D surface0;\n"
2148 "layout (binding = 1) uniform sampler2D surface1;\n"
2149 "layout (binding = 12) uniform sampler2D surface2;\n"
2150 "void main() {\n"
2151 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
2152 "}\n";
2153
2154 ASSERT_NO_FATAL_FAILURE(InitState());
2155 ASSERT_NO_FATAL_FAILURE(InitViewport());
2156
2157 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2158 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2159
2160 XglSamplerObj sampler1(m_device);
2161 XglSamplerObj sampler2(m_device);
2162 XglSamplerObj sampler3(m_device);
2163
Tony Barbour2f421a02015-04-01 16:38:10 -06002164 uint32_t tex_colors[2] = { 0xffff0000, 0xffff0000 };
2165 XglTextureObj texture1(m_device, tex_colors); // Red
2166 tex_colors[0] = 0xff00ff00; tex_colors[1] = 0xff00ff00;
2167 XglTextureObj texture2(m_device, tex_colors); // Green
2168 tex_colors[0] = 0xff0000ff; tex_colors[1] = 0xff0000ff;
2169 XglTextureObj texture3(m_device, tex_colors); // Blue
Tony Barbourf43b6982014-11-25 13:18:32 -07002170
Tony Barbourf43b6982014-11-25 13:18:32 -07002171 XglPipelineObj pipelineobj(m_device);
2172 pipelineobj.AddShader(&vs);
2173 pipelineobj.AddShader(&ps);
2174
2175 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002176 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2177 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2178 for (int i = 0; i < 10; i++)
2179 descriptorSet.AppendDummy();
2180 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002181
2182 m_memoryRefManager.AddMemoryRef(&texture1);
2183 m_memoryRefManager.AddMemoryRef(&texture2);
2184 m_memoryRefManager.AddMemoryRef(&texture3);
2185
Tony Barbourdd4c9642015-01-09 12:55:14 -07002186 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002187 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002188 XglCommandBufferObj cmdBuffer(m_device);
2189 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2190
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002191 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002192
2193 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2194
2195#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002196 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002197 pDSDumpDot((char*)"triTest2.dot");
2198#endif
2199 // render triangle
2200 cmdBuffer.Draw(0, 3, 0, 1);
2201
2202 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002203 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002204 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002205
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002206 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002207 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002208
2209}
2210
2211TEST_F(XglRenderTest, TriangleVSUniformBlock)
2212{
2213 // The expected result from this test is a blue triangle
2214
2215 static const char *vertShaderText =
2216 "#version 140\n"
2217 "#extension GL_ARB_separate_shader_objects : enable\n"
2218 "#extension GL_ARB_shading_language_420pack : enable\n"
2219 "layout (location = 0) out vec4 outColor;\n"
2220 "layout (std140, binding = 0) uniform bufferVals {\n"
2221 " vec4 red;\n"
2222 " vec4 green;\n"
2223 " vec4 blue;\n"
2224 " vec4 white;\n"
2225 "} myBufferVals;\n"
2226 "void main() {\n"
2227 " vec2 vertices[3];"
2228 " vertices[0] = vec2(-0.5, -0.5);\n"
2229 " vertices[1] = vec2( 0.5, -0.5);\n"
2230 " vertices[2] = vec2( 0.5, 0.5);\n"
2231 " outColor = myBufferVals.blue;\n"
2232 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2233 "}\n";
2234
2235 static const char *fragShaderText =
2236 "#version 140\n"
2237 "#extension GL_ARB_separate_shader_objects : enable\n"
2238 "#extension GL_ARB_shading_language_420pack : enable\n"
2239 "layout (location = 0) in vec4 inColor;\n"
2240 "void main() {\n"
2241 " gl_FragColor = inColor;\n"
2242 "}\n";
2243
2244 ASSERT_NO_FATAL_FAILURE(InitState());
2245 ASSERT_NO_FATAL_FAILURE(InitViewport());
2246
2247 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2248 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2249
2250 // Let's populate our buffer with the following:
2251 // vec4 red;
2252 // vec4 green;
2253 // vec4 blue;
2254 // vec4 white;
2255 const int valCount = 4 * 4;
2256 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2257 0.0, 1.0, 0.0, 1.0,
2258 0.0, 0.0, 1.0, 1.0,
2259 1.0, 1.0, 1.0, 1.0 };
2260
2261 XglConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002262
2263 XglPipelineObj pipelineobj(m_device);
2264 pipelineobj.AddShader(&vs);
2265 pipelineobj.AddShader(&ps);
2266
2267 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002268 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002269
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 Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002290 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002291 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002292
2293}
2294
2295TEST_F(XglRenderTest, TriangleFSUniformBlockBinding)
2296{
2297 // This test allows the shader to select which buffer it is
2298 // pulling from using layout binding qualifier.
2299 // There are corresponding changes in the compiler stack that
2300 // will select the buffer using binding directly.
2301 // The binding number should match the slot number set up by
2302 // the application.
2303 // The expected result from this test is a purple triangle
2304
2305 static const char *vertShaderText =
2306 "#version 140\n"
2307 "#extension GL_ARB_separate_shader_objects : enable\n"
2308 "#extension GL_ARB_shading_language_420pack : enable\n"
2309 "void main() {\n"
2310 " vec2 vertices[3];"
2311 " vertices[0] = vec2(-0.5, -0.5);\n"
2312 " vertices[1] = vec2( 0.5, -0.5);\n"
2313 " vertices[2] = vec2( 0.5, 0.5);\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 (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2322 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2323 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002324 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
Tony Barbourf43b6982014-11-25 13:18:32 -07002325 "void main() {\n"
2326 " gl_FragColor = myBlueVal.color;\n"
2327 " gl_FragColor += myRedVal.color;\n"
2328 "}\n";
2329
2330 ASSERT_NO_FATAL_FAILURE(InitState());
2331 ASSERT_NO_FATAL_FAILURE(InitViewport());
2332
2333 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2334 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2335
2336 // We're going to create a number of uniform buffers, and then allow
2337 // the shader to select which it wants to read from with a binding
2338
2339 // Let's populate the buffers with a single color each:
2340 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2341 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2342 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002343 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002344
2345 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2346 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2347 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2348 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2349
2350 const int redCount = sizeof(redVals) / sizeof(float);
2351 const int greenCount = sizeof(greenVals) / sizeof(float);
2352 const int blueCount = sizeof(blueVals) / sizeof(float);
2353 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2354
2355 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002356
2357 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002358
2359 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002360
2361 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002362
2363 XglPipelineObj pipelineobj(m_device);
2364 pipelineobj.AddShader(&vs);
2365 pipelineobj.AddShader(&ps);
2366
2367 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002368 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2369 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2370 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2371 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002372
Tony Barbourdd4c9642015-01-09 12:55:14 -07002373 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002374 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002375 XglCommandBufferObj cmdBuffer(m_device);
2376 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002377
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002378 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002379
2380 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2381
2382#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002383 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002384 pDSDumpDot((char*)"triTest2.dot");
2385#endif
2386 // render triangle
2387 cmdBuffer.Draw(0, 3, 0, 1);
2388
2389 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002390 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002391 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002392
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002393 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002394 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002395}
2396
2397TEST_F(XglRenderTest, TriangleFSAnonymousUniformBlockBinding)
2398{
2399 // This test is the same as TriangleFSUniformBlockBinding, but
2400 // it does not provide an instance name.
2401 // The expected result from this test is a purple triangle
2402
2403 static const char *vertShaderText =
2404 "#version 140\n"
2405 "#extension GL_ARB_separate_shader_objects : enable\n"
2406 "#extension GL_ARB_shading_language_420pack : enable\n"
2407 "void main() {\n"
2408 " vec2 vertices[3];"
2409 " vertices[0] = vec2(-0.5, -0.5);\n"
2410 " vertices[1] = vec2( 0.5, -0.5);\n"
2411 " vertices[2] = vec2( 0.5, 0.5);\n"
2412 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2413 "}\n";
2414
2415 static const char *fragShaderText =
2416 "#version 430\n"
2417 "#extension GL_ARB_separate_shader_objects : enable\n"
2418 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002419 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2420 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2421 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002422 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002423 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002424 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002425 " outColor = blue;\n"
2426 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002427 "}\n";
2428 ASSERT_NO_FATAL_FAILURE(InitState());
2429 ASSERT_NO_FATAL_FAILURE(InitViewport());
2430
2431 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2432 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2433
2434 // We're going to create a number of uniform buffers, and then allow
2435 // the shader to select which it wants to read from with a binding
2436
2437 // Let's populate the buffers with a single color each:
2438 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2439 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2440 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2441 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2442
2443 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2444 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2445 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2446 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2447
2448 const int redCount = sizeof(redVals) / sizeof(float);
2449 const int greenCount = sizeof(greenVals) / sizeof(float);
2450 const int blueCount = sizeof(blueVals) / sizeof(float);
2451 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2452
2453 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002454
2455 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002456
2457 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002458
2459 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002460
2461 XglPipelineObj pipelineobj(m_device);
2462 pipelineobj.AddShader(&vs);
2463 pipelineobj.AddShader(&ps);
2464
2465 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002466 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2467 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2468 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2469 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002470
Tony Barbourdd4c9642015-01-09 12:55:14 -07002471 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002472 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002473 XglCommandBufferObj cmdBuffer(m_device);
2474 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2475
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002476 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002477
2478 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2479
2480#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002481 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002482 pDSDumpDot((char*)"triTest2.dot");
2483#endif
2484 // render triangle
2485 cmdBuffer.Draw(0, 3, 0, 1);
2486
2487 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002488 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002489 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002490
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002491 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002492 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002493
2494}
2495
2496TEST_F(XglRenderTest, CubeWithVertexFetchAndMVPAndTexture)
2497{
2498 static const char *vertShaderText =
2499 "#version 140\n"
2500 "#extension GL_ARB_separate_shader_objects : enable\n"
2501 "#extension GL_ARB_shading_language_420pack : enable\n"
2502 "layout (std140, binding=0) uniform bufferVals {\n"
2503 " mat4 mvp;\n"
2504 "} myBufferVals;\n"
2505 "layout (location=0) in vec4 pos;\n"
2506 "layout (location=0) out vec2 UV;\n"
2507 "void main() {\n"
2508 " vec2 positions[3];"
2509 " positions[0] = vec2( 0.0, 0.0);\n"
2510 " positions[1] = vec2( 0.25, 0.1);\n"
2511 " positions[2] = vec2( 0.1, 0.25);\n"
2512 " UV = positions[gl_VertexID % 3];\n"
2513 " gl_Position = myBufferVals.mvp * pos;\n"
2514 "}\n";
2515
2516 static const char *fragShaderText =
2517 "#version 140\n"
2518 "#extension GL_ARB_separate_shader_objects : enable\n"
2519 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002520 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002521 "layout (location=0) out vec4 outColor;\n"
2522 "layout (location=0) in vec2 UV;\n"
2523 "void main() {\n"
2524 " outColor= textureLod(surface, UV, 0.0);\n"
2525 "}\n";
2526 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2527
2528 glm::mat4 View = glm::lookAt(
2529 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2530 glm::vec3(0,0,0), // and looks at the origin
2531 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2532 );
2533
2534 glm::mat4 Model = glm::mat4(1.0f);
2535
2536 glm::mat4 MVP = Projection * View * Model;
2537
2538
2539 ASSERT_NO_FATAL_FAILURE(InitState());
2540 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tony Barbour17c6ab12015-03-27 17:03:18 -06002541 m_depthStencil->Init(m_device, m_width, m_height);
Tony Barbourf43b6982014-11-25 13:18:32 -07002542
2543 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
2544 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002545 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002546
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002547 const int buf_size = sizeof(MVP) / sizeof(float);
Tony Barbourf43b6982014-11-25 13:18:32 -07002548
2549 XglConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2550 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2551 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2552 XglSamplerObj sampler(m_device);
2553 XglTextureObj texture(m_device);
2554
Tony Barbourf43b6982014-11-25 13:18:32 -07002555 XglPipelineObj pipelineobj(m_device);
2556 pipelineobj.AddShader(&vs);
2557 pipelineobj.AddShader(&ps);
2558
2559 XglDescriptorSetObj descriptorSet(m_device);
Tony Barbour83a83802015-04-02 15:43:15 -06002560 // descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer); // TODO: Why does this break images??
Chia-I Wuf8385062015-01-04 16:27:24 +08002561 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mvpBuffer);
2562 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002563
2564 m_memoryRefManager.AddMemoryRef(&meshBuffer);
2565 m_memoryRefManager.AddMemoryRef(&mvpBuffer);
2566 m_memoryRefManager.AddMemoryRef(&texture);
Tony Barbour17c6ab12015-03-27 17:03:18 -06002567 m_memoryRefManager.AddMemoryRef(m_depthStencil);
Tony Barbourf43b6982014-11-25 13:18:32 -07002568
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002569#define MESH_BIND_ID 0
Tony Barbourf43b6982014-11-25 13:18:32 -07002570 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002571 MESH_BIND_ID, // binding ID
2572 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
2573 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
2574 };
Tony Barbourf43b6982014-11-25 13:18:32 -07002575
Tony Barbourf43b6982014-11-25 13:18:32 -07002576 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002577 vi_attribs[0].binding = MESH_BIND_ID; // Binding ID
2578 vi_attribs[0].location = 0; // location
2579 vi_attribs[0].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
2580 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2581 vi_attribs[1].binding = MESH_BIND_ID; // Binding ID
2582 vi_attribs[1].location = 1; // location
2583 vi_attribs[1].format = XGL_FMT_R32G32B32A32_SFLOAT; // format of source data
2584 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
Tony Barbourf43b6982014-11-25 13:18:32 -07002585
Tony Barbourf43b6982014-11-25 13:18:32 -07002586 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
Courtney Goeltzenleuchterf5cdad02015-03-31 16:36:30 -06002587 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2588 pipelineobj.AddVertexDataBuffer(&meshBuffer, MESH_BIND_ID);
Tony Barbourf43b6982014-11-25 13:18:32 -07002589
Tony Barbourfa6cac72015-01-16 14:27:35 -07002590 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
2591 ds_state.depthTestEnable = XGL_TRUE;
2592 ds_state.depthWriteEnable = XGL_TRUE;
2593 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
2594 ds_state.depthBoundsEnable = XGL_FALSE;
2595 ds_state.stencilTestEnable = XGL_FALSE;
2596 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
2597 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
2598 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
2599 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -07002600 ds_state.format = XGL_FMT_D32_SFLOAT;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002601 ds_state.front = ds_state.back;
2602 pipelineobj.SetDepthStencil(&ds_state);
2603
Tony Barbour17c6ab12015-03-27 17:03:18 -06002604 ASSERT_NO_FATAL_FAILURE(InitRenderTarget(m_depthStencil->BindInfo()));
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002605 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002606 XglCommandBufferObj cmdBuffer(m_device);
2607 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002608
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002609 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
2610
Tony Barbourdd4c9642015-01-09 12:55:14 -07002611 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2612
2613 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2614#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002615 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002616 pDSDumpDot((char*)"triTest2.dot");
2617#endif
2618 // render triangle
2619 cmdBuffer.Draw(0, 36, 0, 1);
2620
2621 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002622 EndCommandBuffer(cmdBuffer);
Tony Barbourdd4c9642015-01-09 12:55:14 -07002623 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
2624
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002625 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002626 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002627
2628}
Cody Northropd1ce7842014-12-09 11:17:01 -07002629
2630TEST_F(XglRenderTest, TriangleMixedSamplerUniformBlockBinding)
2631{
2632 // This test mixes binding slots of textures and buffers, ensuring
2633 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002634 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002635 // you can modify it to move the desired result around.
2636
2637 static const char *vertShaderText =
2638 "#version 140\n"
2639 "#extension GL_ARB_separate_shader_objects : enable\n"
2640 "#extension GL_ARB_shading_language_420pack : enable\n"
2641 "void main() {\n"
2642 " vec2 vertices[3];"
2643 " vertices[0] = vec2(-0.5, -0.5);\n"
2644 " vertices[1] = vec2( 0.5, -0.5);\n"
2645 " vertices[2] = vec2( 0.5, 0.5);\n"
2646 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2647 "}\n";
2648
2649 static const char *fragShaderText =
2650 "#version 430\n"
2651 "#extension GL_ARB_separate_shader_objects : enable\n"
2652 "#extension GL_ARB_shading_language_420pack : enable\n"
2653 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002654 "layout (binding = 3) uniform sampler2D surface1;\n"
2655 "layout (binding = 1) uniform sampler2D surface2;\n"
2656 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002657
Cody Northropa0410942014-12-09 13:59:39 -07002658
Chia-I Wuf8385062015-01-04 16:27:24 +08002659 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2660 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2661 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2662 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002663 "layout (location = 0) out vec4 outColor;\n"
2664 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002665 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002666 " outColor += white * vec4(0.00001);\n"
2667 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002668 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002669 "}\n";
2670 ASSERT_NO_FATAL_FAILURE(InitState());
2671 ASSERT_NO_FATAL_FAILURE(InitViewport());
2672
2673 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2674 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2675
Cody Northropd1ce7842014-12-09 11:17:01 -07002676 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2677 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2678 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2679 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2680
2681 const int redCount = sizeof(redVals) / sizeof(float);
2682 const int greenCount = sizeof(greenVals) / sizeof(float);
2683 const int blueCount = sizeof(blueVals) / sizeof(float);
2684 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2685
2686 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002687 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002688 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002689 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002690
Tony Barbour2f421a02015-04-01 16:38:10 -06002691 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Cody Northropd1ce7842014-12-09 11:17:01 -07002692 XglSamplerObj sampler0(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002693 XglTextureObj texture0(m_device, tex_colors); // Light Red
2694 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Cody Northropd1ce7842014-12-09 11:17:01 -07002695 XglSamplerObj sampler2(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002696 XglTextureObj texture2(m_device, tex_colors); // Light Blue
2697 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Cody Northropd1ce7842014-12-09 11:17:01 -07002698 XglSamplerObj sampler4(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002699 XglTextureObj texture4(m_device, tex_colors); // Light Green
Cody Northropa0410942014-12-09 13:59:39 -07002700
2701 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2702 // TODO: Get back here ASAP and understand why.
Tony Barbour2f421a02015-04-01 16:38:10 -06002703 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Cody Northropa0410942014-12-09 13:59:39 -07002704 XglSamplerObj sampler7(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002705 XglTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northropd1ce7842014-12-09 11:17:01 -07002706
2707 XglPipelineObj pipelineobj(m_device);
2708 pipelineobj.AddShader(&vs);
2709 pipelineobj.AddShader(&ps);
2710
2711 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002712 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2713 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2714 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2715 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2716 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2717 // swap blue and green
2718 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2719 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2720 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002721
2722 m_memoryRefManager.AddMemoryRef(&texture0);
2723 m_memoryRefManager.AddMemoryRef(&texture2);
2724 m_memoryRefManager.AddMemoryRef(&texture4);
Cody Northropa0410942014-12-09 13:59:39 -07002725 m_memoryRefManager.AddMemoryRef(&texture7);
Cody Northropd1ce7842014-12-09 11:17:01 -07002726
Tony Barbourdd4c9642015-01-09 12:55:14 -07002727 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002728 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002729 XglCommandBufferObj cmdBuffer(m_device);
2730 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002731
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002732 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002733
2734 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2735
2736#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002737 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002738 pDSDumpDot((char*)"triTest2.dot");
2739#endif
2740 // render triangle
2741 cmdBuffer.Draw(0, 3, 0, 1);
2742
2743 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002744 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002745 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002746
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002747 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002748 RecordImage(m_renderTargets[i]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002749
2750}
2751
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002752TEST_F(XglRenderTest, TriangleMatchingSamplerUniformBlockBinding)
2753{
2754 // This test matches binding slots of textures and buffers, requiring
2755 // the driver to give them distinct number spaces.
2756 // The expected result from this test is a red triangle, although
2757 // you can modify it to move the desired result around.
2758
2759 static const char *vertShaderText =
2760 "#version 140\n"
2761 "#extension GL_ARB_separate_shader_objects : enable\n"
2762 "#extension GL_ARB_shading_language_420pack : enable\n"
2763 "void main() {\n"
2764 " vec2 vertices[3];"
2765 " vertices[0] = vec2(-0.5, -0.5);\n"
2766 " vertices[1] = vec2( 0.5, -0.5);\n"
2767 " vertices[2] = vec2( 0.5, 0.5);\n"
2768 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2769 "}\n";
2770
2771 static const char *fragShaderText =
2772 "#version 430\n"
2773 "#extension GL_ARB_separate_shader_objects : enable\n"
2774 "#extension GL_ARB_shading_language_420pack : enable\n"
2775 "layout (binding = 0) uniform sampler2D surface0;\n"
2776 "layout (binding = 1) uniform sampler2D surface1;\n"
2777 "layout (binding = 2) uniform sampler2D surface2;\n"
2778 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002779 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2780 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2781 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2782 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002783 "layout (location = 0) out vec4 outColor;\n"
2784 "void main() {\n"
2785 " outColor = red;// * vec4(0.00001);\n"
2786 " outColor += white * vec4(0.00001);\n"
2787 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2788 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2789 "}\n";
2790 ASSERT_NO_FATAL_FAILURE(InitState());
2791 ASSERT_NO_FATAL_FAILURE(InitViewport());
2792
2793 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2794 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2795
2796 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2797 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2798 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2799 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2800
2801 const int redCount = sizeof(redVals) / sizeof(float);
2802 const int greenCount = sizeof(greenVals) / sizeof(float);
2803 const int blueCount = sizeof(blueVals) / sizeof(float);
2804 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2805
2806 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002807 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002808 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002809 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002810
Tony Barbour2f421a02015-04-01 16:38:10 -06002811 uint32_t tex_colors[2] = { 0xff800000, 0xff800000 };
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002812 XglSamplerObj sampler0(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002813 XglTextureObj texture0(m_device, tex_colors); // Light Red
2814 tex_colors[0] = 0xff000080; tex_colors[1] = 0xff000080;
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002815 XglSamplerObj sampler2(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002816 XglTextureObj texture2(m_device, tex_colors); // Light Blue
2817 tex_colors[0] = 0xff008000; tex_colors[1] = 0xff008000;
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002818 XglSamplerObj sampler4(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002819 XglTextureObj texture4(m_device, tex_colors); // Light Green
2820 tex_colors[0] = 0xffff00ff; tex_colors[1] = 0xffff00ff;
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002821 XglSamplerObj sampler7(m_device);
Tony Barbour2f421a02015-04-01 16:38:10 -06002822 XglTextureObj texture7(m_device, tex_colors); // Red and Blue
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002823
2824 XglPipelineObj pipelineobj(m_device);
2825 pipelineobj.AddShader(&vs);
2826 pipelineobj.AddShader(&ps);
2827
2828 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002829 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2830 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2831 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2832 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2833 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2834 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2835 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2836 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002837
2838 m_memoryRefManager.AddMemoryRef(&texture0);
2839 m_memoryRefManager.AddMemoryRef(&texture2);
2840 m_memoryRefManager.AddMemoryRef(&texture4);
2841 m_memoryRefManager.AddMemoryRef(&texture7);
2842
Tony Barbourdd4c9642015-01-09 12:55:14 -07002843 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002844 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002845 XglCommandBufferObj cmdBuffer(m_device);
2846 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002847
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002848 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002849
2850 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2851
2852#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002853 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Tony Barbourdd4c9642015-01-09 12:55:14 -07002854 pDSDumpDot((char*)"triTest2.dot");
2855#endif
2856 // render triangle
2857 cmdBuffer.Draw(0, 3, 0, 1);
2858
2859 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002860 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06002861 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barbourdd4c9642015-01-09 12:55:14 -07002862
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07002863 for (int i = 0; i < m_renderTargets.size(); i++)
Tony Barbourdd4c9642015-01-09 12:55:14 -07002864 RecordImage(m_renderTargets[i]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002865
2866}
2867
Cody Northrop02690bd2014-12-17 15:26:33 -07002868TEST_F(XglRenderTest, TriangleUniformBufferLayout)
2869{
2870 // This test populates a buffer with a variety of different data
2871 // types, then reads them out with a shader.
2872 // The expected result from this test is a green triangle
2873
2874 static const char *vertShaderText =
2875 "#version 140\n"
2876 "#extension GL_ARB_separate_shader_objects : enable\n"
2877 "#extension GL_ARB_shading_language_420pack : enable\n"
2878 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2879 " vec4 fRed;\n"
2880 " vec4 fGreen;\n"
2881 " layout(row_major) mat4 worldToProj;\n"
2882 " layout(row_major) mat4 projToWorld;\n"
2883 " layout(row_major) mat4 worldToView;\n"
2884 " layout(row_major) mat4 viewToProj;\n"
2885 " layout(row_major) mat4 worldToShadow[4];\n"
2886 " float fZero;\n"
2887 " float fOne;\n"
2888 " float fTwo;\n"
2889 " float fThree;\n"
2890 " vec3 fZeroZeroZero;\n"
2891 " float fFour;\n"
2892 " vec3 fZeroZeroOne;\n"
2893 " float fFive;\n"
2894 " vec3 fZeroOneZero;\n"
2895 " float fSix;\n"
2896 " float fSeven;\n"
2897 " float fEight;\n"
2898 " float fNine;\n"
2899 " vec2 fZeroZero;\n"
2900 " vec2 fZeroOne;\n"
2901 " vec4 fBlue;\n"
2902 " vec2 fOneZero;\n"
2903 " vec2 fOneOne;\n"
2904 " vec3 fZeroOneOne;\n"
2905 " float fTen;\n"
2906 " float fEleven;\n"
2907 " float fTwelve;\n"
2908 " vec3 fOneZeroZero;\n"
2909 " vec4 uvOffsets[4];\n"
2910 "};\n"
2911 "layout (location = 0) out vec4 color;"
2912 "void main() {\n"
2913
2914 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2915 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2916 " \n"
2917
2918 // do some exact comparisons, even though we should
2919 // really have an epsilon involved.
2920 " vec4 outColor = right;\n"
2921 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
2922 " outColor = wrong;\n"
2923 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
2924 " outColor = wrong;\n"
2925 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
2926 " outColor = wrong;\n"
2927
2928 " color = outColor;\n"
2929
2930 // generic position stuff
2931 " vec2 vertices;\n"
2932 " int vertexSelector = gl_VertexID;\n"
2933 " if (vertexSelector == 0)\n"
2934 " vertices = vec2(-0.5, -0.5);\n"
2935 " else if (vertexSelector == 1)\n"
2936 " vertices = vec2( 0.5, -0.5);\n"
2937 " else if (vertexSelector == 2)\n"
2938 " vertices = vec2( 0.5, 0.5);\n"
2939 " else\n"
2940 " vertices = vec2( 0.0, 0.0);\n"
2941 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
2942 "}\n";
2943
2944 static const char *fragShaderText =
2945 "#version 140\n"
2946 "#extension GL_ARB_separate_shader_objects : enable\n"
2947 "#extension GL_ARB_shading_language_420pack : enable\n"
2948 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2949 " vec4 fRed;\n"
2950 " vec4 fGreen;\n"
2951 " layout(row_major) mat4 worldToProj;\n"
2952 " layout(row_major) mat4 projToWorld;\n"
2953 " layout(row_major) mat4 worldToView;\n"
2954 " layout(row_major) mat4 viewToProj;\n"
2955 " layout(row_major) mat4 worldToShadow[4];\n"
2956 " float fZero;\n"
2957 " float fOne;\n"
2958 " float fTwo;\n"
2959 " float fThree;\n"
2960 " vec3 fZeroZeroZero;\n"
2961 " float fFour;\n"
2962 " vec3 fZeroZeroOne;\n"
2963 " float fFive;\n"
2964 " vec3 fZeroOneZero;\n"
2965 " float fSix;\n"
2966 " float fSeven;\n"
2967 " float fEight;\n"
2968 " float fNine;\n"
2969 " vec2 fZeroZero;\n"
2970 " vec2 fZeroOne;\n"
2971 " vec4 fBlue;\n"
2972 " vec2 fOneZero;\n"
2973 " vec2 fOneOne;\n"
2974 " vec3 fZeroOneOne;\n"
2975 " float fTen;\n"
2976 " float fEleven;\n"
2977 " float fTwelve;\n"
2978 " vec3 fOneZeroZero;\n"
2979 " vec4 uvOffsets[4];\n"
2980 "};\n"
2981 "layout (location = 0) in vec4 color;\n"
2982 "void main() {\n"
2983 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2984 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2985 " \n"
2986
2987 // start with VS value to ensure it passed
2988 " vec4 outColor = color;\n"
2989
2990 // do some exact comparisons, even though we should
2991 // really have an epsilon involved.
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 (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
2997 " outColor = wrong;\n"
2998 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
2999 " outColor = wrong;\n"
3000 " if (fTwo != 2.0)\n"
3001 " outColor = wrong;\n"
3002 " if (fOneOne != vec2(1.0, 1.0))\n"
3003 " outColor = wrong;\n"
3004 " if (fTen != 10.0)\n"
3005 " outColor = wrong;\n"
3006 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3007 " outColor = wrong;\n"
3008 " \n"
3009 " gl_FragColor = outColor;\n"
3010 "}\n";
3011
3012
3013 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3014 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3015 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3016 0.0, 1.0, 0.0, 1.0, // align
3017 0.0, 0.0, 1.0, 1.0, // align
3018 0.0, 0.0, 0.0, 1.0, // align
3019 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3020 0.0, 2.0, 0.0, 2.0, // align
3021 0.0, 0.0, 2.0, 2.0, // align
3022 0.0, 0.0, 0.0, 2.0, // align
3023 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3024 0.0, 3.0, 0.0, 3.0, // align
3025 0.0, 0.0, 3.0, 3.0, // align
3026 0.0, 0.0, 0.0, 3.0, // align
3027 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3028 0.0, 4.0, 0.0, 4.0, // align
3029 0.0, 0.0, 4.0, 4.0, // align
3030 0.0, 0.0, 0.0, 4.0, // align
3031 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3032 0.0, 5.0, 0.0, 5.0, // align
3033 0.0, 0.0, 5.0, 5.0, // align
3034 0.0, 0.0, 0.0, 5.0, // align
3035 6.0, 0.0, 0.0, 6.0, // align
3036 0.0, 6.0, 0.0, 6.0, // align
3037 0.0, 0.0, 6.0, 6.0, // align
3038 0.0, 0.0, 0.0, 6.0, // align
3039 7.0, 0.0, 0.0, 7.0, // align
3040 0.0, 7.0, 0.0, 7.0, // align
3041 0.0, 0.0, 7.0, 7.0, // align
3042 0.0, 0.0, 0.0, 7.0, // align
3043 8.0, 0.0, 0.0, 8.0, // align
3044 0.0, 8.0, 0.0, 8.0, // align
3045 0.0, 0.0, 8.0, 8.0, // align
3046 0.0, 0.0, 0.0, 8.0, // align
3047 0.0, // float fZero; // align
3048 1.0, // float fOne; // pack
3049 2.0, // float fTwo; // pack
3050 3.0, // float fThree; // pack
3051 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3052 4.0, // float fFour; // pack
3053 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3054 5.0, // float fFive; // pack
3055 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3056 6.0, // float fSix; // pack
3057 7.0, // float fSeven; // align
3058 8.0, // float fEight; // pack
3059 9.0, // float fNine; // pack
3060 0.0, // BUFFER
3061 0.0, 0.0, // vec2 fZeroZero; // align
3062 0.0, 1.0, // vec2 fZeroOne; // pack
3063 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3064 1.0, 0.0, // vec2 fOneZero; // align
3065 1.0, 1.0, // vec2 fOneOne; // pack
3066 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3067 10.0, // float fTen; // pack
3068 11.0, // float fEleven; // align
3069 12.0, // float fTwelve; // pack
3070 0.0, 0.0, // BUFFER
3071 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3072 0.0, // BUFFER
3073 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3074 0.5, 0.6, 0.7, 0.8, // align
3075 0.9, 1.0, 1.1, 1.2, // align
3076 1.3, 1.4, 1.5, 1.6, // align
3077 };
3078
3079 ASSERT_NO_FATAL_FAILURE(InitState());
3080 ASSERT_NO_FATAL_FAILURE(InitViewport());
3081
3082 const int constCount = sizeof(mixedVals) / sizeof(float);
3083
3084 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
3085 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
3086
3087 XglConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003088
3089 XglPipelineObj pipelineobj(m_device);
3090 pipelineobj.AddShader(&vs);
3091 pipelineobj.AddShader(&ps);
3092
3093 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08003094 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003095
3096 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07003097 m_memoryRefManager.AddRTMemoryRefs(m_renderTargets, m_renderTargets.size());
Cody Northrop02690bd2014-12-17 15:26:33 -07003098 XglCommandBufferObj cmdBuffer(m_device);
3099 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3100
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003101 ASSERT_XGL_SUCCESS(BeginCommandBuffer(cmdBuffer));
Cody Northrop02690bd2014-12-17 15:26:33 -07003102
3103 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
3104
3105#ifdef DUMP_STATE_DOT
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003106 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (char*)"drawStateDumpDotFile");
Cody Northrop02690bd2014-12-17 15:26:33 -07003107 pDSDumpDot((char*)"triTest2.dot");
3108#endif
3109 // render triangle
3110 cmdBuffer.Draw(0, 3, 0, 1);
3111
3112 // finalize recording of the command buffer
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003113 EndCommandBuffer(cmdBuffer);
Mark Lobodzinski15427102015-02-18 16:38:17 -06003114 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Cody Northrop02690bd2014-12-17 15:26:33 -07003115
Courtney Goeltzenleuchterdd745fd2015-03-05 16:47:18 -07003116 for (int i = 0; i < m_renderTargets.size(); i++)
Cody Northrop02690bd2014-12-17 15:26:33 -07003117 RecordImage(m_renderTargets[i]);
3118}
3119
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003120int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003121 int result;
3122
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003123 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003124 XglTestFramework::InitArgs(&argc, argv);
3125
Chia-I Wu7133fdc2014-12-15 23:57:34 +08003126 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06003127
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003128 result = RUN_ALL_TESTS();
3129
3130 XglTestFramework::Finish();
3131 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003132}