blob: 92603b7c5a1647add8ec842c5f9fc9dd62ae4d20 [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
Chia-I Wu4115c892014-08-28 11:56:29 +080075#include "icd-bil.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
83XGL_VOID XGLAPI myDbgFunc(
84 XGL_DBG_MSG_TYPE msgType,
85 XGL_VALIDATION_LEVEL validationLevel,
86 XGL_BASE_OBJECT srcObject,
87 XGL_SIZE location,
88 XGL_INT msgCode,
89 const XGL_CHAR* pMsg,
90 XGL_VOID* pUserData)
91{
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{
116 XGL_FLOAT posX, posY, posZ, posW; // Position data
117 XGL_FLOAT r, g, b, a; // Color
118};
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
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600222
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600223protected:
Cody Northrop350727b2014-10-06 15:42:00 -0600224 XGL_IMAGE m_texture;
225 XGL_IMAGE_VIEW m_textureView;
226 XGL_IMAGE_VIEW_ATTACH_INFO m_textureViewInfo;
227 XGL_GPU_MEMORY m_textureMem;
228
229 XGL_SAMPLER m_sampler;
230
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600231 XGL_FORMAT m_depth_stencil_fmt;
232 XGL_IMAGE m_depthStencilImage;
Jon Ashburna9ae3832015-01-16 09:37:43 -0700233 XGL_UINT m_num_mem;
234 XGL_GPU_MEMORY *m_depthStencilMem;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600235 XGL_DEPTH_STENCIL_VIEW m_depthStencilView;
Tony Barbourf43b6982014-11-25 13:18:32 -0700236 XglMemoryRefManager m_memoryRefManager;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600237
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600238
239 virtual void SetUp() {
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600240
241 this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO;
242 this->app_info.pNext = NULL;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800243 this->app_info.pAppName = "render_tests";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600244 this->app_info.appVersion = 1;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800245 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600246 this->app_info.engineVersion = 1;
247 this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0);
248
Cody Northrop350727b2014-10-06 15:42:00 -0600249 memset(&m_textureViewInfo, 0, sizeof(m_textureViewInfo));
250 m_textureViewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO;
Tony Barbour97a36232014-12-04 17:14:45 -0700251 memset(&m_depthStencilImage, 0, sizeof(m_depthStencilImage));
Cody Northrop350727b2014-10-06 15:42:00 -0600252
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600253 InitFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600254 }
255
256 virtual void TearDown() {
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -0600257 // Clean up resources before we reset
258 ShutdownFramework();
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -0600259 }
260};
261
Tony Barbour02472db2015-01-08 17:08:28 -0700262void XglRenderTest::GenericDrawPreparation(XglCommandBufferObj *cmdBuffer, XglPipelineObj *pipelineobj, XglDescriptorSetObj *descriptorSet)
263{
264 cmdBuffer->ClearAllBuffers(&m_depthStencilBinding, m_depthStencilImage);
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700265 cmdBuffer->PrepareAttachments();
Tony Barbour02472db2015-01-08 17:08:28 -0700266 cmdBuffer->BindStateObject(XGL_STATE_BIND_RASTER, m_stateRaster);
267 cmdBuffer->BindStateObject(XGL_STATE_BIND_VIEWPORT, m_stateViewport);
268 cmdBuffer->BindStateObject(XGL_STATE_BIND_COLOR_BLEND, m_colorBlend);
269 cmdBuffer->BindStateObject(XGL_STATE_BIND_DEPTH_STENCIL, m_stateDepthStencil);
Chia-I Wuf8385062015-01-04 16:27:24 +0800270 descriptorSet->CreateXGLDescriptorSet(cmdBuffer);
Tony Barbour02472db2015-01-08 17:08:28 -0700271 pipelineobj->CreateXGLPipeline(descriptorSet);
272 cmdBuffer->BindPipeline(pipelineobj->GetPipelineHandle());
Tony Barbour02472db2015-01-08 17:08:28 -0700273 cmdBuffer->BindDescriptorSet(descriptorSet->GetDescriptorSetHandle());
274}
Tony Barbourf43b6982014-11-25 13:18:32 -0700275
Tony Barbourf43b6982014-11-25 13:18:32 -0700276void XglRenderTest::RotateTriangleVSUniform(glm::mat4 Projection, glm::mat4 View, glm::mat4 Model,
Tony Barbourdd4c9642015-01-09 12:55:14 -0700277 XglConstantBufferObj *constantBuffer, XglCommandBufferObj *cmdBuffer)
278{
279 int i;
280 glm::mat4 MVP;
281 int matrixSize = sizeof(MVP);
282 XGL_RESULT err;
283
284 for (i = 0; i < 8; i++) {
285 void *pData = constantBuffer->map();
286
287 Model = glm::rotate(Model, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f));
288 MVP = Projection * View * Model;
289 memcpy(pData, (const void*) &MVP[0][0], matrixSize);
290
291 constantBuffer->unmap();
292
293 // submit the command buffer to the universal queue
294 cmdBuffer->QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
295
Tony Barbourdd4c9642015-01-09 12:55:14 -0700296 err = xglQueueWaitIdle( m_device->m_queue );
297 ASSERT_XGL_SUCCESS( err );
298
299 // Wait for work to finish before cleaning up.
300 xglDeviceWaitIdle(m_device->device());
301
302 assert(m_renderTargetCount == 1);
303 RecordImage(m_renderTargets[0]);
304 }
305}
Courtney Goeltzenleuchter3c601d82014-10-13 13:03:31 -0600306
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600307void dumpMatrix(const char *note, glm::mat4 MVP)
308{
Chia-I Wu7133fdc2014-12-15 23:57:34 +0800309 int i;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600310
311 printf("%s: \n", note);
312 for (i=0; i<4; i++) {
313 printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]);
314 }
315 printf("\n");
316 fflush(stdout);
317}
318
319void dumpVec4(const char *note, glm::vec4 vector)
320{
321 printf("%s: \n", note);
322 printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]);
323 printf("\n");
324 fflush(stdout);
325}
326
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600327void XglRenderTest::InitDepthStencil()
328{
329 XGL_RESULT err;
330 XGL_IMAGE_CREATE_INFO image;
331 XGL_MEMORY_ALLOC_INFO mem_alloc;
332 XGL_DEPTH_STENCIL_VIEW_CREATE_INFO view;
Jon Ashburna9ae3832015-01-16 09:37:43 -0700333 XGL_MEMORY_REQUIREMENTS *mem_reqs;
Jon Ashburn6317c492014-11-21 11:33:20 -0700334 XGL_SIZE mem_reqs_size=sizeof(XGL_MEMORY_REQUIREMENTS);
Jon Ashburna9ae3832015-01-16 09:37:43 -0700335 XGL_UINT num_allocations = 0;
336 XGL_SIZE num_alloc_size = sizeof(num_allocations);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600337
338 // Clean up default state created by framework
339 if (m_stateDepthStencil) xglDestroyObject(m_stateDepthStencil);
340
341 m_depth_stencil_fmt.channelFormat = XGL_CH_FMT_R16;
342 m_depth_stencil_fmt.numericFormat = XGL_NUM_FMT_DS;
343
344 image.sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
345 image.pNext = NULL;
346 image.imageType = XGL_IMAGE_2D;
347 image.format = m_depth_stencil_fmt;
348 image.extent.width = m_width;
349 image.extent.height = m_height;
350 image.extent.depth = 1;
351 image.mipLevels = 1;
352 image.arraySize = 1;
353 image.samples = 1;
354 image.tiling = XGL_OPTIMAL_TILING;
355 image.usage = XGL_IMAGE_USAGE_DEPTH_STENCIL_BIT;
356 image.flags = 0;
357
358 mem_alloc.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
359 mem_alloc.pNext = NULL;
360 mem_alloc.allocationSize = 0;
361 mem_alloc.alignment = 0;
362 mem_alloc.flags = 0;
363 mem_alloc.heapCount = 0;
364 mem_alloc.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
365
366 /* create image */
367 err = xglCreateImage(device(), &image,
368 &m_depthStencilImage);
369 ASSERT_XGL_SUCCESS(err);
370
371 err = xglGetObjectInfo(m_depthStencilImage,
Jon Ashburna9ae3832015-01-16 09:37:43 -0700372 XGL_INFO_TYPE_MEMORY_ALLOCATION_COUNT,
373 &num_alloc_size, &num_allocations);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600374 ASSERT_XGL_SUCCESS(err);
Jon Ashburna9ae3832015-01-16 09:37:43 -0700375 ASSERT_EQ(num_alloc_size, sizeof(num_allocations));
376 mem_reqs = (XGL_MEMORY_REQUIREMENTS *) malloc(num_allocations * sizeof(XGL_MEMORY_REQUIREMENTS));
377 m_depthStencilMem = (XGL_GPU_MEMORY *) malloc(num_allocations * sizeof(XGL_GPU_MEMORY));
378 m_num_mem = num_allocations;
379 err = xglGetObjectInfo(m_depthStencilImage,
380 XGL_INFO_TYPE_MEMORY_REQUIREMENTS,
381 &mem_reqs_size, mem_reqs);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600382 ASSERT_XGL_SUCCESS(err);
Jon Ashburna9ae3832015-01-16 09:37:43 -0700383 ASSERT_EQ(mem_reqs_size, sizeof(*mem_reqs));
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600384
Jon Ashburna9ae3832015-01-16 09:37:43 -0700385 for (XGL_UINT i = 0; i < num_allocations; i ++) {
386 mem_alloc.allocationSize = mem_reqs[i].size;
387 mem_alloc.alignment = mem_reqs[i].alignment;
388 mem_alloc.heapCount = mem_reqs[i].heapCount;
389 XGL_UINT heapInfo[mem_reqs[i].heapCount];
390 mem_alloc.pHeaps = heapInfo;
391 memcpy(heapInfo, mem_reqs[i].pHeaps,
392 sizeof(mem_reqs[i].pHeaps[0]) * mem_reqs[i].heapCount);
393
394 /* allocate memory */
395 err = xglAllocMemory(device(), &mem_alloc, &m_depthStencilMem[i]);
396 ASSERT_XGL_SUCCESS(err);
397
398 /* bind memory */
399 err = xglBindObjectMemory(m_depthStencilImage, i,
400 m_depthStencilMem[i], 0);
401 ASSERT_XGL_SUCCESS(err);
402 }
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600403
Tony Barbourfa6cac72015-01-16 14:27:35 -0700404 XGL_DYNAMIC_DS_STATE_CREATE_INFO depthStencil = {};
405 depthStencil.sType = XGL_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO;
406
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600407 depthStencil.minDepth = 0.f;
408 depthStencil.maxDepth = 1.f;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700409 depthStencil.stencilBackRef = 0;
410 depthStencil.stencilFrontRef = 0;
411 depthStencil.stencilReadMask = 0xff;
412 depthStencil.stencilWriteMask = 0xff;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600413
Tony Barbourfa6cac72015-01-16 14:27:35 -0700414 err = xglCreateDynamicDepthStencilState( device(), &depthStencil, &m_stateDepthStencil );
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600415 ASSERT_XGL_SUCCESS( err );
416
417 /* create image view */
418 view.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO;
419 view.pNext = NULL;
420 view.image = XGL_NULL_HANDLE;
421 view.mipLevel = 0;
422 view.baseArraySlice = 0;
423 view.arraySize = 1;
424 view.flags = 0;
425 view.image = m_depthStencilImage;
426 err = xglCreateDepthStencilView(device(), &view, &m_depthStencilView);
427 ASSERT_XGL_SUCCESS(err);
428
429 m_depthStencilBinding.view = m_depthStencilView;
Mike Stroyan55658c22014-12-04 11:08:39 +0000430 m_depthStencilBinding.layout = XGL_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600431}
432
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600433struct xgltriangle_vs_uniform {
434 // Must start with MVP
435 XGL_FLOAT mvp[4][4];
436 XGL_FLOAT position[3][4];
437 XGL_FLOAT color[3][4];
438};
439
Tony Barbourae442072015-01-12 13:27:11 -0700440void XglRenderTest::XGLTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600441{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700442#ifdef DEBUG_CALLBACK
443 xglDbgRegisterMsgCallback(myDbgFunc, NULL);
444#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600445 // Create identity matrix
446 int i;
447 struct xgltriangle_vs_uniform data;
448
449 glm::mat4 Projection = glm::mat4(1.0f);
450 glm::mat4 View = glm::mat4(1.0f);
451 glm::mat4 Model = glm::mat4(1.0f);
452 glm::mat4 MVP = Projection * View * Model;
453 const int matrixSize = sizeof(MVP);
454 const int bufSize = sizeof(xgltriangle_vs_uniform) / sizeof(XGL_FLOAT);
455 memcpy(&data.mvp, &MVP[0][0], matrixSize);
456
457 static const Vertex tri_data[] =
458 {
459 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
460 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
461 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
462 };
463
464 for (i=0; i<3; i++) {
465 data.position[i][0] = tri_data[i].posX;
466 data.position[i][1] = tri_data[i].posY;
467 data.position[i][2] = tri_data[i].posZ;
468 data.position[i][3] = tri_data[i].posW;
469 data.color[i][0] = tri_data[i].r;
470 data.color[i][1] = tri_data[i].g;
471 data.color[i][2] = tri_data[i].b;
472 data.color[i][3] = tri_data[i].a;
473 }
474
Tony Barbourf43b6982014-11-25 13:18:32 -0700475 ASSERT_NO_FATAL_FAILURE(InitState());
476 ASSERT_NO_FATAL_FAILURE(InitViewport());
477
478 XglConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(XGL_FLOAT), (const void*) &data);
479
480 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
481 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700482
483 XglPipelineObj pipelineobj(m_device);
484 pipelineobj.AddShader(&vs);
485 pipelineobj.AddShader(&ps);
486
487 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +0800488 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700489 m_memoryRefManager.AddMemoryRef(&constantBuffer);
490
Tony Barbour71ba3612015-01-09 16:12:35 -0700491 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
492 XglCommandBufferObj cmdBuffer(m_device);
493 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700494
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700495 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour71ba3612015-01-09 16:12:35 -0700496
497 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
498
499 cmdBuffer.BindVertexBuffer(&constantBuffer, 0, 0);
500#ifdef DUMP_STATE_DOT
501 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
502 pDSDumpDot((char*)"triTest2.dot");
503#endif
504 // render triangle
505 cmdBuffer.Draw(0, 3, 0, 1);
506
507 // finalize recording of the command buffer
508 cmdBuffer.EndCommandBuffer();
509 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
510
511 for (int i = 0; i < m_renderTargetCount; i++)
512 RecordImage(m_renderTargets[i]);
513
514 if (rotate)
515 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
516
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700517#ifdef PRINT_OBJECTS
518 //XGL_UINT64 objTrackGetObjectCount(XGL_OBJECT_TYPE type)
519 OBJ_TRACK_GET_OBJECT_COUNT pObjTrackGetObjectCount = (OBJ_TRACK_GET_OBJECT_COUNT)xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjectCount");
520 XGL_UINT64 numObjects = pObjTrackGetObjectCount(XGL_OBJECT_TYPE_ANY);
521 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjects");
522 printf("DEBUG : Number of Objects : %lu\n", numObjects);
523 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjects");
524 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
525 pObjTrackGetObjs(XGL_OBJECT_TYPE_ANY, numObjects, pObjNodeArray);
526 for (i=0; i < numObjects; i++) {
527 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);
528 }
529 free(pObjNodeArray);
530#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700531
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600532}
533
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600534TEST_F(XglRenderTest, XGLTriangle_FragColor)
535{
536 static const char *vertShaderText =
537 "#version 140\n"
538 "#extension GL_ARB_separate_shader_objects : enable\n"
539 "#extension GL_ARB_shading_language_420pack : enable\n"
540 "\n"
541 "layout(binding = 0) uniform buf {\n"
542 " mat4 MVP;\n"
543 " vec4 position[3];\n"
544 " vec4 color[3];\n"
545 "} ubuf;\n"
546 "\n"
547 "layout (location = 0) out vec4 outColor;\n"
548 "\n"
549 "void main() \n"
550 "{\n"
551 " outColor = ubuf.color[gl_VertexID];\n"
552 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
553 "}\n";
554
555 static const char *fragShaderText =
556 "#version 140\n"
557 "#extension GL_ARB_separate_shader_objects : enable\n"
558 "#extension GL_ARB_shading_language_420pack : enable\n"
559 "\n"
560 "layout (location = 0) in vec4 inColor;\n"
561 "\n"
562 "void main()\n"
563 "{\n"
564 " gl_FragColor = inColor;\n"
565 "}\n";
566
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600567 TEST_DESCRIPTION("XGL-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
Tony Barbourae442072015-01-12 13:27:11 -0700568 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600569}
570
571TEST_F(XglRenderTest, XGLTriangle_OutputLocation)
572{
573 static const char *vertShaderText =
574 "#version 140\n"
575 "#extension GL_ARB_separate_shader_objects : enable\n"
576 "#extension GL_ARB_shading_language_420pack : enable\n"
577 "\n"
578 "layout(binding = 0) uniform buf {\n"
579 " mat4 MVP;\n"
580 " vec4 position[3];\n"
581 " vec4 color[3];\n"
582 "} ubuf;\n"
583 "\n"
584 "layout (location = 0) out vec4 outColor;\n"
585 "\n"
586 "void main() \n"
587 "{\n"
588 " outColor = ubuf.color[gl_VertexID];\n"
589 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
590 "}\n";
591
592 static const char *fragShaderText =
593 "#version 140\n"
594 "#extension GL_ARB_separate_shader_objects : enable\n"
595 "#extension GL_ARB_shading_language_420pack : enable\n"
596 "\n"
597 "layout (location = 0) in vec4 inColor;\n"
598 "layout (location = 0) out vec4 outColor;\n"
599 "\n"
600 "void main()\n"
601 "{\n"
602 " outColor = inColor;\n"
603 "}\n";
604
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600605 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 -0600606
Tony Barbourae442072015-01-12 13:27:11 -0700607 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600608}
609
Tony Barbourf43b6982014-11-25 13:18:32 -0700610TEST_F(XglRenderTest, BIL_XGLTriangle)
611{
612 bool saved_use_bil = XglTestFramework::m_use_bil;
613
614 static const char *vertShaderText =
615 "#version 140\n"
616 "#extension GL_ARB_separate_shader_objects : enable\n"
617 "#extension GL_ARB_shading_language_420pack : enable\n"
618 "\n"
619 "layout(binding = 0) uniform buf {\n"
620 " mat4 MVP;\n"
621 " vec4 position[3];\n"
622 " vec4 color[3];\n"
623 "} ubuf;\n"
624 "\n"
625 "layout (location = 0) out vec4 outColor;\n"
626 "\n"
627 "void main() \n"
628 "{\n"
629 " outColor = ubuf.color[gl_VertexID];\n"
630 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
631 "}\n";
632
633 static const char *fragShaderText =
634 "#version 140\n"
635 "#extension GL_ARB_separate_shader_objects : enable\n"
636 "#extension GL_ARB_shading_language_420pack : enable\n"
637 "\n"
638 "layout (location = 0) in vec4 inColor;\n"
639 "\n"
640 "void main()\n"
641 "{\n"
642 " gl_FragColor = inColor;\n"
643 "}\n";
644
645 TEST_DESCRIPTION("XGL-style shaders, but force test framework to compile shader to BIL and pass BIL to driver.");
646
647 XglTestFramework::m_use_bil = true;
648
Tony Barbourae442072015-01-12 13:27:11 -0700649 XGLTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700650
651 XglTestFramework::m_use_bil = saved_use_bil;
652}
653
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600654TEST_F(XglRenderTest, GreenTriangle)
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600655{
656 static const char *vertShaderText =
657 "#version 130\n"
658 "vec2 vertices[3];\n"
659 "void main() {\n"
660 " vertices[0] = vec2(-1.0, -1.0);\n"
661 " vertices[1] = vec2( 1.0, -1.0);\n"
662 " vertices[2] = vec2( 0.0, 1.0);\n"
663 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
664 "}\n";
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600665
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600666 static const char *fragShaderText =
667 "#version 130\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600668 "void main() {\n"
Steve K10b32512014-10-10 08:54:29 -0600669 " gl_FragColor = vec4(0,1,0,1);\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600670 "}\n";
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600671
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600672 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
673
Tony Barbourae442072015-01-12 13:27:11 -0700674 XGLTriangleTest(vertShaderText, fragShaderText, false);
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600675}
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600676
Tony Barbourf43b6982014-11-25 13:18:32 -0700677TEST_F(XglRenderTest, BIL_GreenTriangle)
678{
679 bool saved_use_bil = XglTestFramework::m_use_bil;
680
681 static const char *vertShaderText =
682 "#version 130\n"
683 "vec2 vertices[3];\n"
684 "void main() {\n"
685 " vertices[0] = vec2(-1.0, -1.0);\n"
686 " vertices[1] = vec2( 1.0, -1.0);\n"
687 " vertices[2] = vec2( 0.0, 1.0);\n"
688 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
689 "}\n";
690
691 static const char *fragShaderText =
692 "#version 130\n"
693 "void main() {\n"
694 " gl_FragColor = vec4(0,1,0,1);\n"
695 "}\n";
696
697 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to BIL and gives BIL to driver.");
698
699 XglTestFramework::m_use_bil = true;
Tony Barbourae442072015-01-12 13:27:11 -0700700 XGLTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700701 XglTestFramework::m_use_bil = saved_use_bil;
702}
703
704TEST_F(XglRenderTest, YellowTriangle)
705{
706 static const char *vertShaderText =
707 "#version 130\n"
708 "void main() {\n"
709 " vec2 vertices[3];"
710 " vertices[0] = vec2(-0.5, -0.5);\n"
711 " vertices[1] = vec2( 0.5, -0.5);\n"
712 " vertices[2] = vec2( 0.5, 0.5);\n"
713 " vec4 colors[3];\n"
714 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
715 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
716 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
717 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
718 "}\n";
719
720 static const char *fragShaderText =
721 "#version 130\n"
722 "void main() {\n"
723 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
724 "}\n";
725
Tony Barbourae442072015-01-12 13:27:11 -0700726 XGLTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700727}
728
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600729TEST_F(XglRenderTest, TriangleWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600730{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600731 static const char *vertShaderText =
Tony Barbourf43b6982014-11-25 13:18:32 -0700732 "#version 130\n"
733 //XYZ1( -1, -1, -1 )
734 "in vec4 pos;\n"
735 //XYZ1( 0.f, 0.f, 0.f )
736 "in vec4 inColor;\n"
737 "out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600738 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600739 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600740 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600741 "}\n";
742
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600743
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600744 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700745 "#version 140\n"
746 "#extension GL_ARB_separate_shader_objects : enable\n"
747 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700748 "in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700749 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600750 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700751 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600752 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600753
Tony Barbourf43b6982014-11-25 13:18:32 -0700754
755
756 ASSERT_NO_FATAL_FAILURE(InitState());
757 ASSERT_NO_FATAL_FAILURE(InitViewport());
758
759 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000760 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700761
762 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
763 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
764
765 XglPipelineObj pipelineobj(m_device);
766 pipelineobj.AddShader(&vs);
767 pipelineobj.AddShader(&ps);
768
769 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +0800770 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700771
772 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
773 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
774 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
775 };
776
777 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
778 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
779 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
780 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
781 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
782 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
783 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
784 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
785 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
786
787 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
788 pipelineobj.AddVertexInputBindings(&vi_binding,1);
789 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
790
Tony Barboure4ed9942015-01-09 10:06:53 -0700791 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
792 XglCommandBufferObj cmdBuffer(m_device);
793 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700794
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700795 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -0700796 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
797
Tony Barboure4ed9942015-01-09 10:06:53 -0700798 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
799
800 // render two triangles
801 cmdBuffer.Draw(0, 6, 0, 1);
802
803 // finalize recording of the command buffer
804 cmdBuffer.EndCommandBuffer();
805 cmdBuffer.QueueCommandBuffer(NULL, 0);
806
807 for (int i = 0; i < m_renderTargetCount; i++)
808 RecordImage(m_renderTargets[i]);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600809}
810
Chia-I Wue09d1a72014-12-05 10:32:23 +0800811TEST_F(XglRenderTest, TriangleMRT)
812{
813 static const char *vertShaderText =
814 "#version 130\n"
815 "in vec4 pos;\n"
816 "void main() {\n"
817 " gl_Position = pos;\n"
818 "}\n";
819
820 static const char *fragShaderText =
821 "#version 130\n"
822 "void main() {\n"
823 " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
824 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
825 "}\n";
826 const XGL_FLOAT vb_data[][2] = {
827 { -1.0f, -1.0f },
828 { 1.0f, -1.0f },
829 { -1.0f, 1.0f }
830 };
831
832 ASSERT_NO_FATAL_FAILURE(InitState());
833 ASSERT_NO_FATAL_FAILURE(InitViewport());
834
835 XglConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000836 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800837
838 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
839 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
840
841 XglPipelineObj pipelineobj(m_device);
842 pipelineobj.AddShader(&vs);
843 pipelineobj.AddShader(&ps);
844
845 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
846 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
847 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
848 };
849
850 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attrib;
851 vi_attrib.binding = 0; // index into vertexBindingDescriptions
852 vi_attrib.format.channelFormat = XGL_CH_FMT_R32G32; // format of source data
853 vi_attrib.format.numericFormat = XGL_NUM_FMT_FLOAT;
854 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
855
856 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
857 pipelineobj.AddVertexInputBindings(&vi_binding,1);
858 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
859
860 XglDescriptorSetObj descriptorSet(m_device);
861
862 m_renderTargetCount = 2;
Tony Barboure4ed9942015-01-09 10:06:53 -0700863 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wue09d1a72014-12-05 10:32:23 +0800864
865 XGL_PIPELINE_CB_ATTACHMENT_STATE att = {};
866 att.blendEnable = XGL_FALSE;
867 att.format = m_render_target_fmt;
868 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700869 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800870
Tony Barbour5ed79702015-01-07 14:31:52 -0700871 XglCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700872
Tony Barbour5ed79702015-01-07 14:31:52 -0700873 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
874 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barboure4ed9942015-01-09 10:06:53 -0700875
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700876 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour5ed79702015-01-07 14:31:52 -0700877
Tony Barboure4ed9942015-01-09 10:06:53 -0700878 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
879
Tony Barbour5ed79702015-01-07 14:31:52 -0700880 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700881#ifdef DUMP_STATE_DOT
882 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
883 pDSDumpDot((char*)"triTest2.dot");
884#endif
885 // render triangle
886 cmdBuffer.Draw(0, 3, 0, 1);
887
888 // finalize recording of the command buffer
889 cmdBuffer.EndCommandBuffer();
890 cmdBuffer.QueueCommandBuffer(NULL, 0);
891
892 for (int i = 0; i < m_renderTargetCount; i++)
893 RecordImage(m_renderTargets[i]);
894
Chia-I Wue09d1a72014-12-05 10:32:23 +0800895}
896
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700897TEST_F(XglRenderTest, QuadWithIndexedVertexFetch)
898{
899 static const char *vertShaderText =
900 "#version 140\n"
901 "#extension GL_ARB_separate_shader_objects : enable\n"
902 "#extension GL_ARB_shading_language_420pack : enable\n"
903 "layout(location = 0) in vec4 pos;\n"
904 "layout(location = 1) in vec4 inColor;\n"
905 "layout(location = 0) out vec4 outColor;\n"
906 "void main() {\n"
907 " outColor = inColor;\n"
908 " gl_Position = pos;\n"
909 "}\n";
910
911
912 static const char *fragShaderText =
913 "#version 140\n"
914 "#extension GL_ARB_separate_shader_objects : enable\n"
915 "#extension GL_ARB_shading_language_420pack : enable\n"
916 "layout(location = 0) in vec4 color;\n"
917 "void main() {\n"
918 " gl_FragColor = color;\n"
919 "}\n";
920
921 const Vertex g_vbData[] =
922 {
923 // first tri
924 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
925 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
926 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
927
928 // second tri
929 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
930 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
931 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
932 };
933
934 const uint16_t g_idxData[6] = {
935 0, 1, 2,
936 3, 4, 5,
937 };
938
939 ASSERT_NO_FATAL_FAILURE(InitState());
940 ASSERT_NO_FATAL_FAILURE(InitViewport());
941
942 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000943 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700944
945 XglIndexBufferObj indexBuffer(m_device);
946 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), XGL_INDEX_16, g_idxData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000947 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700948
949 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
950 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
951
952 XglPipelineObj pipelineobj(m_device);
953 pipelineobj.AddShader(&vs);
954 pipelineobj.AddShader(&ps);
955
956 XglDescriptorSetObj descriptorSet(m_device);
957
958 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
959 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
960 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
961 };
962
963 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
964 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
965 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
966 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
967 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
968 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
969 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
970 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
971 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
972
973 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
974 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700975
976 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700977 XglCommandBufferObj cmdBuffer(m_device);
978 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700979 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -0700980
981 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700982
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700983#ifdef DUMP_STATE_DOT
984 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700985 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700986#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700987
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700988 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
989 cmdBuffer.BindIndexBuffer(&indexBuffer,0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700990
991 // render two triangles
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700992 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700993
994 // finalize recording of the command buffer
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700995 cmdBuffer.EndCommandBuffer();
996 cmdBuffer.QueueCommandBuffer(NULL, 0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700997
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700998 for (int i = 0; i < m_renderTargetCount; i++)
999 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001000
1001}
1002
GregF6bef1212014-12-02 15:41:44 -07001003TEST_F(XglRenderTest, GreyandRedCirclesonBlue)
1004{
1005 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -07001006
GregF6bef1212014-12-02 15:41:44 -07001007 static const char *vertShaderText =
1008 "#version 140\n"
1009 "#extension GL_ARB_separate_shader_objects : enable\n"
1010 "#extension GL_ARB_shading_language_420pack : enable\n"
1011 "layout (location = 0) in vec4 pos;\n"
1012 "layout (location = 0) out vec4 outColor;\n"
1013 "layout (location = 1) out vec4 outColor2;\n"
1014 "void main() {\n"
1015 " gl_Position = pos;\n"
1016 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1017 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1018 "}\n";
1019
1020 static const char *fragShaderText =
1021 //"#version 140\n"
1022 "#version 330\n"
1023 "#extension GL_ARB_separate_shader_objects : enable\n"
1024 "#extension GL_ARB_shading_language_420pack : enable\n"
1025 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1026 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1027 "layout (location = 0) in vec4 color;\n"
1028 "layout (location = 1) in vec4 color2;\n"
1029 "void main() {\n"
1030 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1031 " float dist_squared = dot(pos, pos);\n"
1032 " gl_FragColor = (dist_squared < 400.0)\n"
1033 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1034 " : color2;\n"
1035 "}\n";
1036
1037 ASSERT_NO_FATAL_FAILURE(InitState());
1038 ASSERT_NO_FATAL_FAILURE(InitViewport());
1039
1040 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001041 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001042
1043 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1044 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1045
1046 XglPipelineObj pipelineobj(m_device);
1047 pipelineobj.AddShader(&vs);
1048 pipelineobj.AddShader(&ps);
1049
1050 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001051 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001052
1053 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1054 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1055 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1056 };
1057
1058 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1059 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1060 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1061 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1062 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1063 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1064 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1065 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1066 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1067
1068 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1069 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1070 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1071
Tony Barbourdd4c9642015-01-09 12:55:14 -07001072 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1073 XglCommandBufferObj cmdBuffer(m_device);
1074 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1075
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001076 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001077
1078 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1079
1080 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1081#ifdef DUMP_STATE_DOT
1082 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1083 pDSDumpDot((char*)"triTest2.dot");
1084#endif
1085 // render triangle
1086 cmdBuffer.Draw(0, 6, 0, 1);
1087
1088 // finalize recording of the command buffer
1089 cmdBuffer.EndCommandBuffer();
1090 cmdBuffer.QueueCommandBuffer(NULL, 0);
1091
1092 for (int i = 0; i < m_renderTargetCount; i++)
1093 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001094
1095}
1096
1097TEST_F(XglRenderTest, RedCirclesonBlue)
1098{
1099 // This tests that we correctly handle unread fragment inputs
1100
1101 static const char *vertShaderText =
1102 "#version 140\n"
1103 "#extension GL_ARB_separate_shader_objects : enable\n"
1104 "#extension GL_ARB_shading_language_420pack : enable\n"
1105 "layout (location = 0) in vec4 pos;\n"
1106 "layout (location = 0) out vec4 outColor;\n"
1107 "layout (location = 1) out vec4 outColor2;\n"
1108 "void main() {\n"
1109 " gl_Position = pos;\n"
1110 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1111 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1112 "}\n";
1113
1114 static const char *fragShaderText =
1115 //"#version 140\n"
1116 "#version 330\n"
1117 "#extension GL_ARB_separate_shader_objects : enable\n"
1118 "#extension GL_ARB_shading_language_420pack : enable\n"
1119 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1120 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1121 "layout (location = 0) in vec4 color;\n"
1122 "layout (location = 1) in vec4 color2;\n"
1123 "void main() {\n"
1124 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1125 " float dist_squared = dot(pos, pos);\n"
1126 " gl_FragColor = (dist_squared < 400.0)\n"
1127 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1128 " : color2;\n"
1129 "}\n";
1130
1131 ASSERT_NO_FATAL_FAILURE(InitState());
1132 ASSERT_NO_FATAL_FAILURE(InitViewport());
1133
1134 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001135 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001136
1137 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1138 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1139
1140 XglPipelineObj pipelineobj(m_device);
1141 pipelineobj.AddShader(&vs);
1142 pipelineobj.AddShader(&ps);
1143
1144 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001145 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001146
1147 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1148 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1149 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1150 };
1151
1152 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1153 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1154 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1155 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1156 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1157 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1158 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1159 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1160 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1161
1162 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1163 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1164 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1165
Tony Barbourdd4c9642015-01-09 12:55:14 -07001166 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1167 XglCommandBufferObj cmdBuffer(m_device);
1168 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1169
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001170 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001171
1172 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1173
1174 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1175#ifdef DUMP_STATE_DOT
1176 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1177 pDSDumpDot((char*)"triTest2.dot");
1178#endif
1179 // render triangle
1180 cmdBuffer.Draw(0, 6, 0, 1);
1181
1182 // finalize recording of the command buffer
1183 cmdBuffer.EndCommandBuffer();
1184 cmdBuffer.QueueCommandBuffer(NULL, 0);
1185
1186 for (int i = 0; i < m_renderTargetCount; i++)
1187 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001188
1189}
1190
1191TEST_F(XglRenderTest, GreyCirclesonBlueFade)
1192{
1193 // This tests reading gl_ClipDistance from FS
1194
1195 static const char *vertShaderText =
1196 "#version 330\n"
1197 "#extension GL_ARB_separate_shader_objects : enable\n"
1198 "#extension GL_ARB_shading_language_420pack : enable\n"
1199 "out gl_PerVertex {\n"
1200 " vec4 gl_Position;\n"
1201 " float gl_ClipDistance[1];\n"
1202 "};\n"
1203 "layout (location = 0) in vec4 pos;\n"
1204 "layout (location = 0) out vec4 outColor;\n"
1205 "layout (location = 1) out vec4 outColor2;\n"
1206 "void main() {\n"
1207 " gl_Position = pos;\n"
1208 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1209 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1210 " float dists[3];\n"
1211 " dists[0] = 0.0;\n"
1212 " dists[1] = 1.0;\n"
1213 " dists[2] = 1.0;\n"
1214 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1215 "}\n";
1216
1217
1218 static const char *fragShaderText =
1219 //"#version 140\n"
1220 "#version 330\n"
1221 "#extension GL_ARB_separate_shader_objects : enable\n"
1222 "#extension GL_ARB_shading_language_420pack : enable\n"
1223 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1224 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1225 "layout (location = 0) in vec4 color;\n"
1226 "layout (location = 1) in vec4 color2;\n"
1227 "void main() {\n"
1228 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1229 " float dist_squared = dot(pos, pos);\n"
1230 " gl_FragColor = (dist_squared < 400.0)\n"
1231 " ? color * gl_ClipDistance[0]\n"
1232 " : color2;\n"
1233 "}\n";
1234
1235 ASSERT_NO_FATAL_FAILURE(InitState());
1236 ASSERT_NO_FATAL_FAILURE(InitViewport());
1237
1238 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001239 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001240
1241 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1242 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1243
1244 XglPipelineObj pipelineobj(m_device);
1245 pipelineobj.AddShader(&vs);
1246 pipelineobj.AddShader(&ps);
1247
1248 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001249 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001250
1251 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1252 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1253 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1254 };
1255
1256 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1257 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1258 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1259 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1260 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1261 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1262 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1263 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1264 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1265
1266 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1267 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1268 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1269
Tony Barbourdd4c9642015-01-09 12:55:14 -07001270 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1271 XglCommandBufferObj cmdBuffer(m_device);
1272 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF6bef1212014-12-02 15:41:44 -07001273
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001274 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001275
1276 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1277
1278 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1279#ifdef DUMP_STATE_DOT
1280 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1281 pDSDumpDot((char*)"triTest2.dot");
1282#endif
1283 // render triangle
1284 cmdBuffer.Draw(0, 6, 0, 1);
1285
1286 // finalize recording of the command buffer
1287 cmdBuffer.EndCommandBuffer();
1288 cmdBuffer.QueueCommandBuffer(NULL, 0);
1289
1290 for (int i = 0; i < m_renderTargetCount; i++)
1291 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001292}
Tony Barbourf43b6982014-11-25 13:18:32 -07001293
GregF7a23c792014-12-02 17:19:34 -07001294TEST_F(XglRenderTest, GreyCirclesonBlueDiscard)
1295{
1296 static const char *vertShaderText =
1297 "#version 140\n"
1298 "#extension GL_ARB_separate_shader_objects : enable\n"
1299 "#extension GL_ARB_shading_language_420pack : enable\n"
1300 "layout (location = 0) in vec4 pos;\n"
1301 "layout (location = 0) out vec4 outColor;\n"
1302 "layout (location = 1) out vec4 outColor2;\n"
1303 "void main() {\n"
1304 " gl_Position = pos;\n"
1305 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1306 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1307 "}\n";
1308
1309
1310 static const char *fragShaderText =
1311 //"#version 140\n"
1312 "#version 330\n"
1313 "#extension GL_ARB_separate_shader_objects : enable\n"
1314 "#extension GL_ARB_shading_language_420pack : enable\n"
1315 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1316 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1317 "layout (location = 0) in vec4 color;\n"
1318 "layout (location = 1) in vec4 color2;\n"
1319 "void main() {\n"
1320 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1321 " float dist_squared = dot(pos, pos);\n"
1322 " if (dist_squared < 100.0)\n"
1323 " discard;\n"
1324 " gl_FragColor = (dist_squared < 400.0)\n"
1325 " ? color\n"
1326 " : color2;\n"
1327 "}\n";
1328
1329 ASSERT_NO_FATAL_FAILURE(InitState());
1330 ASSERT_NO_FATAL_FAILURE(InitViewport());
1331
1332 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001333 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001334
1335 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1336 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1337
1338 XglPipelineObj pipelineobj(m_device);
1339 pipelineobj.AddShader(&vs);
1340 pipelineobj.AddShader(&ps);
1341
1342 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001343 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF7a23c792014-12-02 17:19:34 -07001344
1345 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1346 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1347 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1348 };
1349
1350 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1351 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1352 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1353 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1354 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1355 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1356 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1357 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1358 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1359
1360 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1361 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1362 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1363
Tony Barbourdd4c9642015-01-09 12:55:14 -07001364 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1365 XglCommandBufferObj cmdBuffer(m_device);
1366 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1367
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001368 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001369
1370 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1371
1372 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1373#ifdef DUMP_STATE_DOT
1374 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1375 pDSDumpDot((char*)"triTest2.dot");
1376#endif
1377 // render triangle
1378 cmdBuffer.Draw(0, 6, 0, 1);
1379
1380 // finalize recording of the command buffer
1381 cmdBuffer.EndCommandBuffer();
1382 cmdBuffer.QueueCommandBuffer(NULL, 0);
1383
1384 for (int i = 0; i < m_renderTargetCount; i++)
1385 RecordImage(m_renderTargets[i]);
GregF7a23c792014-12-02 17:19:34 -07001386
1387}
1388
1389
Courtney Goeltzenleuchter3d10c9c2014-10-27 13:06:08 -06001390TEST_F(XglRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001391{
1392 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001393 "#version 140\n"
1394 "#extension GL_ARB_separate_shader_objects : enable\n"
1395 "#extension GL_ARB_shading_language_420pack : enable\n"
1396 "\n"
1397 "layout(binding = 0) uniform buf {\n"
1398 " mat4 MVP;\n"
1399 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001400 "void main() {\n"
1401 " vec2 vertices[3];"
1402 " vertices[0] = vec2(-0.5, -0.5);\n"
1403 " vertices[1] = vec2( 0.5, -0.5);\n"
1404 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001405 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001406 "}\n";
1407
1408 static const char *fragShaderText =
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001409 "#version 130\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001410 "void main() {\n"
Cody Northrop78eac042014-10-10 15:45:00 -06001411 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001412 "}\n";
1413
Tony Barbourf43b6982014-11-25 13:18:32 -07001414 ASSERT_NO_FATAL_FAILURE(InitState());
1415 ASSERT_NO_FATAL_FAILURE(InitViewport());
1416
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001417 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001418 glm::mat4 Projection = glm::mat4(1.0f);
1419 glm::mat4 View = glm::mat4(1.0f);
1420 glm::mat4 Model = glm::mat4(1.0f);
1421 glm::mat4 MVP = Projection * View * Model;
1422 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1423
Tony Barbourf43b6982014-11-25 13:18:32 -07001424 XglConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1425 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1426 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001427
Tony Barbourf43b6982014-11-25 13:18:32 -07001428 XglPipelineObj pipelineobj(m_device);
1429 pipelineobj.AddShader(&vs);
1430 pipelineobj.AddShader(&ps);
1431
1432 // Create descriptor set and attach the constant buffer to it
1433 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001434 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001435
1436 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1437
Tony Barbourdd4c9642015-01-09 12:55:14 -07001438 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1439 XglCommandBufferObj cmdBuffer(m_device);
1440 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001441
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001442 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001443
1444 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1445
1446 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1447#ifdef DUMP_STATE_DOT
1448 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1449 pDSDumpDot((char*)"triTest2.dot");
1450#endif
1451 // render triangle
1452 cmdBuffer.Draw(0, 6, 0, 1);
1453
1454 // finalize recording of the command buffer
1455 cmdBuffer.EndCommandBuffer();
1456 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
1457
1458 for (int i = 0; i < m_renderTargetCount; i++)
1459 RecordImage(m_renderTargets[i]);
1460
1461 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001462}
1463
Tony Barbourf43b6982014-11-25 13:18:32 -07001464TEST_F(XglRenderTest, MixTriangle)
1465{
1466 // This tests location applied to varyings. Notice that we have switched foo
1467 // and bar in the FS. The triangle should be blended with red, green and blue
1468 // corners.
1469 static const char *vertShaderText =
1470 "#version 140\n"
1471 "#extension GL_ARB_separate_shader_objects : enable\n"
1472 "#extension GL_ARB_shading_language_420pack : enable\n"
1473 "layout (location=0) out vec4 bar;\n"
1474 "layout (location=1) out vec4 foo;\n"
1475 "layout (location=2) out float scale;\n"
1476 "vec2 vertices[3];\n"
1477 "void main() {\n"
1478 " vertices[0] = vec2(-1.0, -1.0);\n"
1479 " vertices[1] = vec2( 1.0, -1.0);\n"
1480 " vertices[2] = vec2( 0.0, 1.0);\n"
1481 "vec4 colors[3];\n"
1482 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1483 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1484 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1485 " foo = colors[gl_VertexID % 3];\n"
1486 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1487 " scale = 1.0;\n"
1488 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1489 "}\n";
1490
1491 static const char *fragShaderText =
1492 "#version 140\n"
1493 "#extension GL_ARB_separate_shader_objects : enable\n"
1494 "#extension GL_ARB_shading_language_420pack : enable\n"
1495 "layout (location = 1) in vec4 bar;\n"
1496 "layout (location = 0) in vec4 foo;\n"
1497 "layout (location = 2) in float scale;\n"
1498 "void main() {\n"
1499 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
1500 "}\n";
1501
1502 ASSERT_NO_FATAL_FAILURE(InitState());
1503 ASSERT_NO_FATAL_FAILURE(InitViewport());
1504
1505 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1506 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1507
1508 XglPipelineObj pipelineobj(m_device);
1509 pipelineobj.AddShader(&vs);
1510 pipelineobj.AddShader(&ps);
1511
1512 XglDescriptorSetObj descriptorSet(m_device);
1513
Tony Barbourdd4c9642015-01-09 12:55:14 -07001514 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1515 XglCommandBufferObj cmdBuffer(m_device);
1516 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1517
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001518 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001519
1520 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1521
1522#ifdef DUMP_STATE_DOT
1523 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1524 pDSDumpDot((char*)"triTest2.dot");
1525#endif
1526 // render triangle
1527 cmdBuffer.Draw(0, 3, 0, 1);
1528
1529 // finalize recording of the command buffer
1530 cmdBuffer.EndCommandBuffer();
1531 cmdBuffer.QueueCommandBuffer(NULL, 0);
1532
1533 for (int i = 0; i < m_renderTargetCount; i++)
1534 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001535}
1536
1537TEST_F(XglRenderTest, TriVertFetchAndVertID)
1538{
1539 // This tests that attributes work in the presence of gl_VertexID
1540
1541 static const char *vertShaderText =
1542 "#version 140\n"
1543 "#extension GL_ARB_separate_shader_objects : enable\n"
1544 "#extension GL_ARB_shading_language_420pack : enable\n"
1545 //XYZ1( -1, -1, -1 )
1546 "layout (location = 0) in vec4 pos;\n"
1547 //XYZ1( 0.f, 0.f, 0.f )
1548 "layout (location = 1) in vec4 inColor;\n"
1549 "layout (location = 0) out vec4 outColor;\n"
1550 "void main() {\n"
1551 " outColor = inColor;\n"
1552 " vec4 vertices[3];"
1553 " vertices[gl_VertexID % 3] = pos;\n"
1554 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1555 "}\n";
1556
1557
1558 static const char *fragShaderText =
1559 "#version 140\n"
1560 "#extension GL_ARB_separate_shader_objects : enable\n"
1561 "#extension GL_ARB_shading_language_420pack : enable\n"
1562 "layout (location = 0) in vec4 color;\n"
1563 "void main() {\n"
1564 " gl_FragColor = color;\n"
1565 "}\n";
1566
1567 ASSERT_NO_FATAL_FAILURE(InitState());
1568 ASSERT_NO_FATAL_FAILURE(InitViewport());
1569
1570 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001571 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001572
1573 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1574 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1575
1576 XglPipelineObj pipelineobj(m_device);
1577 pipelineobj.AddShader(&vs);
1578 pipelineobj.AddShader(&ps);
1579
1580 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001581 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001582
1583 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1584 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1585 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1586 };
1587
1588 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1589 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1590 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1591 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1592 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1593 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1594 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1595 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1596 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1597
1598 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1599 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1600 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1601
Tony Barbourdd4c9642015-01-09 12:55:14 -07001602 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1603 XglCommandBufferObj cmdBuffer(m_device);
1604 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1605
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001606 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001607
1608 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1609
1610 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1611#ifdef DUMP_STATE_DOT
1612 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1613 pDSDumpDot((char*)"triTest2.dot");
1614#endif
1615 // render triangle
1616 cmdBuffer.Draw(0, 6, 0, 1);
1617
1618 // finalize recording of the command buffer
1619 cmdBuffer.EndCommandBuffer();
1620 cmdBuffer.QueueCommandBuffer(NULL, 0);
1621
1622 for (int i = 0; i < m_renderTargetCount; i++)
1623 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001624}
1625
1626TEST_F(XglRenderTest, TriVertFetchDeadAttr)
1627{
1628 // This tests that attributes work in the presence of gl_VertexID
1629 // and a dead attribute in position 0. Draws a triangle with yellow,
1630 // red and green corners, starting at top and going clockwise.
1631
1632 static const char *vertShaderText =
1633 "#version 140\n"
1634 "#extension GL_ARB_separate_shader_objects : enable\n"
1635 "#extension GL_ARB_shading_language_420pack : enable\n"
1636 //XYZ1( -1, -1, -1 )
1637 "layout (location = 0) in vec4 pos;\n"
1638 //XYZ1( 0.f, 0.f, 0.f )
1639 "layout (location = 1) in vec4 inColor;\n"
1640 "layout (location = 0) out vec4 outColor;\n"
1641 "void main() {\n"
1642 " outColor = inColor;\n"
1643 " vec2 vertices[3];"
1644 " vertices[0] = vec2(-1.0, -1.0);\n"
1645 " vertices[1] = vec2( 1.0, -1.0);\n"
1646 " vertices[2] = vec2( 0.0, 1.0);\n"
1647 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1648 "}\n";
1649
1650
1651 static const char *fragShaderText =
1652 "#version 140\n"
1653 "#extension GL_ARB_separate_shader_objects : enable\n"
1654 "#extension GL_ARB_shading_language_420pack : enable\n"
1655 "layout (location = 0) in vec4 color;\n"
1656 "void main() {\n"
1657 " gl_FragColor = color;\n"
1658 "}\n";
1659
1660 ASSERT_NO_FATAL_FAILURE(InitState());
1661 ASSERT_NO_FATAL_FAILURE(InitViewport());
1662
1663 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001664 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001665
1666 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1667 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1668
1669 XglPipelineObj pipelineobj(m_device);
1670 pipelineobj.AddShader(&vs);
1671 pipelineobj.AddShader(&ps);
1672
1673 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001674 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001675
1676 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1677 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1678 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1679 };
1680
1681 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1682 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1683 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1684 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1685 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1686 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1687 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1688 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1689 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1690
1691 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1692 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1693 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1694
Tony Barbourdd4c9642015-01-09 12:55:14 -07001695 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1696 XglCommandBufferObj cmdBuffer(m_device);
1697 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001698
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001699 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001700
1701 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1702
1703 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1704#ifdef DUMP_STATE_DOT
1705 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1706 pDSDumpDot((char*)"triTest2.dot");
1707#endif
1708 // render triangle
1709 cmdBuffer.Draw(0, 6, 0, 1);
1710
1711 // finalize recording of the command buffer
1712 cmdBuffer.EndCommandBuffer();
1713 cmdBuffer.QueueCommandBuffer(NULL, 0);
1714
1715 for (int i = 0; i < m_renderTargetCount; i++)
1716 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001717}
1718
1719TEST_F(XglRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001720{
1721 static const char *vertShaderText =
1722 "#version 140\n"
1723 "layout (std140) uniform bufferVals {\n"
1724 " mat4 mvp;\n"
1725 "} myBufferVals;\n"
1726 "in vec4 pos;\n"
1727 "in vec4 inColor;\n"
1728 "out vec4 outColor;\n"
1729 "void main() {\n"
1730 " outColor = inColor;\n"
1731 " gl_Position = myBufferVals.mvp * pos;\n"
1732 "}\n";
1733
1734 static const char *fragShaderText =
1735 "#version 130\n"
1736 "in vec4 color;\n"
1737 "void main() {\n"
1738 " gl_FragColor = color;\n"
1739 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001740 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001741
Tony Barbourf43b6982014-11-25 13:18:32 -07001742 glm::mat4 View = glm::lookAt(
1743 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1744 glm::vec3(0,0,0), // and looks at the origin
1745 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
1746 );
1747
1748 glm::mat4 Model = glm::mat4(1.0f);
1749
1750 glm::mat4 MVP = Projection * View * Model;
1751
1752 ASSERT_NO_FATAL_FAILURE(InitState());
1753 ASSERT_NO_FATAL_FAILURE(InitViewport());
1754 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
1755
1756 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
1757 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1758
1759 const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT);
1760
1761 XglConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1762 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1763 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1764
Tony Barbourf43b6982014-11-25 13:18:32 -07001765 XglPipelineObj pipelineobj(m_device);
1766 pipelineobj.AddShader(&vs);
1767 pipelineobj.AddShader(&ps);
1768
Tony Barbourfa6cac72015-01-16 14:27:35 -07001769 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
1770 ds_state.depthTestEnable = XGL_TRUE;
1771 ds_state.depthWriteEnable = XGL_TRUE;
1772 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
1773 ds_state.depthBoundsEnable = XGL_FALSE;
1774 ds_state.stencilTestEnable = XGL_FALSE;
1775 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
1776 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
1777 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
1778 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
1779 ds_state.format.channelFormat = XGL_CH_FMT_R32;
1780 ds_state.format.numericFormat = XGL_NUM_FMT_DS;
1781 ds_state.front = ds_state.back;
1782 pipelineobj.SetDepthStencil(&ds_state);
1783
Tony Barbourf43b6982014-11-25 13:18:32 -07001784 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001785 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001786
1787 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1788 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1789
1790 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1791 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1792 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1793 };
1794
1795 // this is the current description of g_vbData
1796 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1797 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1798 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1799 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1800 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1801 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1802 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1803 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1804 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1805
1806 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1807 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1808 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1809
Tony Barboure4ed9942015-01-09 10:06:53 -07001810 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1811 XglCommandBufferObj cmdBuffer(m_device);
1812 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001813
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001814 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -07001815 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001816
Tony Barboure4ed9942015-01-09 10:06:53 -07001817 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1818#ifdef DUMP_STATE_DOT
1819 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1820 pDSDumpDot((char*)"triTest2.dot");
1821#endif
1822 // render triangle
1823 cmdBuffer.Draw(0, 36, 0, 1);
1824
1825 // finalize recording of the command buffer
1826 cmdBuffer.EndCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001827 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barboure4ed9942015-01-09 10:06:53 -07001828
1829 for (int i = 0; i < m_renderTargetCount; i++)
1830 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001831}
1832
Tony Barbourf43b6982014-11-25 13:18:32 -07001833TEST_F(XglRenderTest, VSTexture)
1834{
1835 // The expected result from this test is a green and red triangle;
1836 // one red vertex on the left, two green vertices on the right.
1837 static const char *vertShaderText =
1838 "#version 130\n"
1839 "out vec4 texColor;\n"
1840 "uniform sampler2D surface;\n"
1841 "void main() {\n"
1842 " vec2 vertices[3];"
1843 " vertices[0] = vec2(-0.5, -0.5);\n"
1844 " vertices[1] = vec2( 0.5, -0.5);\n"
1845 " vertices[2] = vec2( 0.5, 0.5);\n"
1846 " vec2 positions[3];"
1847 " positions[0] = vec2( 0.0, 0.0);\n"
1848 " positions[1] = vec2( 0.25, 0.1);\n"
1849 " positions[2] = vec2( 0.1, 0.25);\n"
1850 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1851 " texColor = textureLod(surface, samplePos, 0.0);\n"
1852 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1853 "}\n";
1854
1855 static const char *fragShaderText =
1856 "#version 130\n"
1857 "in vec4 texColor;\n"
1858 "void main() {\n"
1859 " gl_FragColor = texColor;\n"
1860 "}\n";
1861
1862 ASSERT_NO_FATAL_FAILURE(InitState());
1863 ASSERT_NO_FATAL_FAILURE(InitViewport());
1864
1865 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1866 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1867 XglSamplerObj sampler(m_device);
1868 XglTextureObj texture(m_device);
1869
Tony Barbourf43b6982014-11-25 13:18:32 -07001870 XglPipelineObj pipelineobj(m_device);
1871 pipelineobj.AddShader(&vs);
1872 pipelineobj.AddShader(&ps);
1873
1874 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001875 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001876
1877 m_memoryRefManager.AddMemoryRef(&texture);
1878
Tony Barbourdd4c9642015-01-09 12:55:14 -07001879 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1880 XglCommandBufferObj cmdBuffer(m_device);
1881 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001882
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001883 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001884
1885 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1886
1887#ifdef DUMP_STATE_DOT
1888 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1889 pDSDumpDot((char*)"triTest2.dot");
1890#endif
1891 // render triangle
1892 cmdBuffer.Draw(0, 3, 0, 1);
1893
1894 // finalize recording of the command buffer
1895 cmdBuffer.EndCommandBuffer();
1896 cmdBuffer.QueueCommandBuffer(NULL, 0);
1897
1898 for (int i = 0; i < m_renderTargetCount; i++)
1899 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001900}
1901TEST_F(XglRenderTest, TexturedTriangle)
1902{
1903 // The expected result from this test is a red and green checkered triangle
1904 static const char *vertShaderText =
1905 "#version 140\n"
1906 "#extension GL_ARB_separate_shader_objects : enable\n"
1907 "#extension GL_ARB_shading_language_420pack : enable\n"
1908 "layout (location = 0) out vec2 samplePos;\n"
1909 "void main() {\n"
1910 " vec2 vertices[3];"
1911 " vertices[0] = vec2(-0.5, -0.5);\n"
1912 " vertices[1] = vec2( 0.5, -0.5);\n"
1913 " vertices[2] = vec2( 0.5, 0.5);\n"
1914 " vec2 positions[3];"
1915 " positions[0] = vec2( 0.0, 0.0);\n"
1916 " positions[1] = vec2( 1.0, 0.0);\n"
1917 " positions[2] = vec2( 1.0, 1.0);\n"
1918 " samplePos = positions[gl_VertexID % 3];\n"
1919 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1920 "}\n";
1921
1922 static const char *fragShaderText =
1923 "#version 140\n"
1924 "#extension GL_ARB_separate_shader_objects : enable\n"
1925 "#extension GL_ARB_shading_language_420pack : enable\n"
1926 "layout (location = 0) in vec2 samplePos;\n"
1927 "layout (binding = 0) uniform sampler2D surface;\n"
1928 "layout (location=0) out vec4 outColor;\n"
1929 "void main() {\n"
1930 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1931 " outColor = texColor;\n"
1932 "}\n";
1933
1934 ASSERT_NO_FATAL_FAILURE(InitState());
1935 ASSERT_NO_FATAL_FAILURE(InitViewport());
1936
1937 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1938 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1939 XglSamplerObj sampler(m_device);
1940 XglTextureObj texture(m_device);
1941
Tony Barbourf43b6982014-11-25 13:18:32 -07001942 XglPipelineObj pipelineobj(m_device);
1943 pipelineobj.AddShader(&vs);
1944 pipelineobj.AddShader(&ps);
1945
1946 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001947 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001948
1949 m_memoryRefManager.AddMemoryRef(&texture);
1950
Tony Barbourdd4c9642015-01-09 12:55:14 -07001951 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1952 XglCommandBufferObj cmdBuffer(m_device);
1953 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1954
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001955 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001956
1957 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1958
1959#ifdef DUMP_STATE_DOT
1960 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1961 pDSDumpDot((char*)"triTest2.dot");
1962#endif
1963 // render triangle
1964 cmdBuffer.Draw(0, 3, 0, 1);
1965
1966 // finalize recording of the command buffer
1967 cmdBuffer.EndCommandBuffer();
1968 cmdBuffer.QueueCommandBuffer(NULL, 0);
1969
1970 for (int i = 0; i < m_renderTargetCount; i++)
1971 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001972}
1973TEST_F(XglRenderTest, TexturedTriangleClip)
1974{
1975 // The expected result from this test is a red and green checkered triangle
1976 static const char *vertShaderText =
1977 "#version 330\n"
1978 "#extension GL_ARB_separate_shader_objects : enable\n"
1979 "#extension GL_ARB_shading_language_420pack : enable\n"
1980 "layout (location = 0) out vec2 samplePos;\n"
1981 "out gl_PerVertex {\n"
1982 " vec4 gl_Position;\n"
1983 " float gl_ClipDistance[1];\n"
1984 "};\n"
1985 "void main() {\n"
1986 " vec2 vertices[3];"
1987 " vertices[0] = vec2(-0.5, -0.5);\n"
1988 " vertices[1] = vec2( 0.5, -0.5);\n"
1989 " vertices[2] = vec2( 0.5, 0.5);\n"
1990 " vec2 positions[3];"
1991 " positions[0] = vec2( 0.0, 0.0);\n"
1992 " positions[1] = vec2( 1.0, 0.0);\n"
1993 " positions[2] = vec2( 1.0, 1.0);\n"
1994 " float dists[3];\n"
1995 " dists[0] = 1.0;\n"
1996 " dists[1] = 1.0;\n"
1997 " dists[2] = -1.0;\n"
1998 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1999 " samplePos = positions[gl_VertexID % 3];\n"
2000 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2001 "}\n";
2002
2003 static const char *fragShaderText =
2004 "#version 140\n"
2005 "#extension GL_ARB_separate_shader_objects : enable\n"
2006 "#extension GL_ARB_shading_language_420pack : enable\n"
2007 "layout (location = 0) in vec2 samplePos;\n"
2008 "layout (binding = 0) uniform sampler2D surface;\n"
2009 "layout (location=0) out vec4 outColor;\n"
2010 "void main() {\n"
2011 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2012 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2013 " outColor = texColor;\n"
2014 "}\n";
2015
2016
2017 ASSERT_NO_FATAL_FAILURE(InitState());
2018 ASSERT_NO_FATAL_FAILURE(InitViewport());
2019
2020 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2021 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2022 XglSamplerObj sampler(m_device);
2023 XglTextureObj texture(m_device);
2024
Tony Barbourf43b6982014-11-25 13:18:32 -07002025 XglPipelineObj pipelineobj(m_device);
2026 pipelineobj.AddShader(&vs);
2027 pipelineobj.AddShader(&ps);
2028
2029 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002030 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002031
2032 m_memoryRefManager.AddMemoryRef(&texture);
2033
Tony Barbourdd4c9642015-01-09 12:55:14 -07002034 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2035 XglCommandBufferObj cmdBuffer(m_device);
2036 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2037
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002038 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002039
2040 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2041
2042#ifdef DUMP_STATE_DOT
2043 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2044 pDSDumpDot((char*)"triTest2.dot");
2045#endif
2046 // render triangle
2047 cmdBuffer.Draw(0, 3, 0, 1);
2048
2049 // finalize recording of the command buffer
2050 cmdBuffer.EndCommandBuffer();
2051 cmdBuffer.QueueCommandBuffer(NULL, 0);
2052
2053 for (int i = 0; i < m_renderTargetCount; i++)
2054 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002055}
2056TEST_F(XglRenderTest, FSTriangle)
2057{
2058 // The expected result from this test is a red and green checkered triangle
2059 static const char *vertShaderText =
2060 "#version 140\n"
2061 "#extension GL_ARB_separate_shader_objects : enable\n"
2062 "#extension GL_ARB_shading_language_420pack : enable\n"
2063 "layout (location = 0) out vec2 samplePos;\n"
2064 "void main() {\n"
2065 " vec2 vertices[3];"
2066 " vertices[0] = vec2(-0.5, -0.5);\n"
2067 " vertices[1] = vec2( 0.5, -0.5);\n"
2068 " vertices[2] = vec2( 0.5, 0.5);\n"
2069 " vec2 positions[3];"
2070 " positions[0] = vec2( 0.0, 0.0);\n"
2071 " positions[1] = vec2( 1.0, 0.0);\n"
2072 " positions[2] = vec2( 1.0, 1.0);\n"
2073 " samplePos = positions[gl_VertexID % 3];\n"
2074 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2075 "}\n";
2076
2077 static const char *fragShaderText =
2078 "#version 140\n"
2079 "#extension GL_ARB_separate_shader_objects : enable\n"
2080 "#extension GL_ARB_shading_language_420pack : enable\n"
2081 "layout (location = 0) in vec2 samplePos;\n"
2082 "layout (binding = 0) uniform sampler2D surface;\n"
2083 "layout (location=0) out vec4 outColor;\n"
2084 "void main() {\n"
2085 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2086 " outColor = texColor;\n"
2087 "}\n";
2088
2089 ASSERT_NO_FATAL_FAILURE(InitState());
2090 ASSERT_NO_FATAL_FAILURE(InitViewport());
2091
2092 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2093 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2094 XglSamplerObj sampler(m_device);
2095 XglTextureObj texture(m_device);
2096
Tony Barbourf43b6982014-11-25 13:18:32 -07002097 XglPipelineObj pipelineobj(m_device);
2098 pipelineobj.AddShader(&vs);
2099 pipelineobj.AddShader(&ps);
2100
2101 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002102 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002103
2104 m_memoryRefManager.AddMemoryRef(&texture);
2105
Tony Barbourdd4c9642015-01-09 12:55:14 -07002106 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2107 XglCommandBufferObj cmdBuffer(m_device);
2108 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2109
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002110 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002111
2112 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2113
2114#ifdef DUMP_STATE_DOT
2115 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2116 pDSDumpDot((char*)"triTest2.dot");
2117#endif
2118 // render triangle
2119 cmdBuffer.Draw(0, 3, 0, 1);
2120
2121 // finalize recording of the command buffer
2122 cmdBuffer.EndCommandBuffer();
2123 cmdBuffer.QueueCommandBuffer(NULL, 0);
2124
2125 for (int i = 0; i < m_renderTargetCount; i++)
2126 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002127}
2128TEST_F(XglRenderTest, SamplerBindingsTriangle)
2129{
2130 // This test sets bindings on the samplers
2131 // For now we are asserting that sampler and texture pairs
2132 // march in lock step, and are set via GLSL binding. This can
2133 // and will probably change.
2134 // The sampler bindings should match the sampler and texture slot
2135 // number set up by the application.
2136 // This test will result in a blue triangle
2137 static const char *vertShaderText =
2138 "#version 140\n"
2139 "#extension GL_ARB_separate_shader_objects : enable\n"
2140 "#extension GL_ARB_shading_language_420pack : enable\n"
2141 "layout (location = 0) out vec4 samplePos;\n"
2142 "void main() {\n"
2143 " vec2 vertices[3];"
2144 " vertices[0] = vec2(-0.5, -0.5);\n"
2145 " vertices[1] = vec2( 0.5, -0.5);\n"
2146 " vertices[2] = vec2( 0.5, 0.5);\n"
2147 " vec2 positions[3];"
2148 " positions[0] = vec2( 0.0, 0.0);\n"
2149 " positions[1] = vec2( 1.0, 0.0);\n"
2150 " positions[2] = vec2( 1.0, 1.0);\n"
2151 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2152 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2153 "}\n";
2154
2155 static const char *fragShaderText =
2156 "#version 140\n"
2157 "#extension GL_ARB_separate_shader_objects : enable\n"
2158 "#extension GL_ARB_shading_language_420pack : enable\n"
2159 "layout (location = 0) in vec4 samplePos;\n"
2160 "layout (binding = 0) uniform sampler2D surface0;\n"
2161 "layout (binding = 1) uniform sampler2D surface1;\n"
2162 "layout (binding = 12) uniform sampler2D surface2;\n"
2163 "void main() {\n"
2164 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
2165 "}\n";
2166
2167 ASSERT_NO_FATAL_FAILURE(InitState());
2168 ASSERT_NO_FATAL_FAILURE(InitViewport());
2169
2170 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2171 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2172
2173 XglSamplerObj sampler1(m_device);
2174 XglSamplerObj sampler2(m_device);
2175 XglSamplerObj sampler3(m_device);
2176
2177 XglTextureObj texture1(m_device); // Red
2178 texture1.ChangeColors(0xffff0000,0xffff0000);
2179 XglTextureObj texture2(m_device); // Green
2180 texture2.ChangeColors(0xff00ff00,0xff00ff00);
2181 XglTextureObj texture3(m_device); // Blue
2182 texture3.ChangeColors(0xff0000ff,0xff0000ff);
2183
Tony Barbourf43b6982014-11-25 13:18:32 -07002184 XglPipelineObj pipelineobj(m_device);
2185 pipelineobj.AddShader(&vs);
2186 pipelineobj.AddShader(&ps);
2187
2188 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002189 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2190 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2191 for (int i = 0; i < 10; i++)
2192 descriptorSet.AppendDummy();
2193 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002194
2195 m_memoryRefManager.AddMemoryRef(&texture1);
2196 m_memoryRefManager.AddMemoryRef(&texture2);
2197 m_memoryRefManager.AddMemoryRef(&texture3);
2198
Tony Barbourdd4c9642015-01-09 12:55:14 -07002199 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2200 XglCommandBufferObj cmdBuffer(m_device);
2201 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2202
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002203 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002204
2205 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2206
2207#ifdef DUMP_STATE_DOT
2208 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2209 pDSDumpDot((char*)"triTest2.dot");
2210#endif
2211 // render triangle
2212 cmdBuffer.Draw(0, 3, 0, 1);
2213
2214 // finalize recording of the command buffer
2215 cmdBuffer.EndCommandBuffer();
2216 cmdBuffer.QueueCommandBuffer(NULL, 0);
2217
2218 for (int i = 0; i < m_renderTargetCount; i++)
2219 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002220
2221}
2222
2223TEST_F(XglRenderTest, TriangleVSUniformBlock)
2224{
2225 // The expected result from this test is a blue triangle
2226
2227 static const char *vertShaderText =
2228 "#version 140\n"
2229 "#extension GL_ARB_separate_shader_objects : enable\n"
2230 "#extension GL_ARB_shading_language_420pack : enable\n"
2231 "layout (location = 0) out vec4 outColor;\n"
2232 "layout (std140, binding = 0) uniform bufferVals {\n"
2233 " vec4 red;\n"
2234 " vec4 green;\n"
2235 " vec4 blue;\n"
2236 " vec4 white;\n"
2237 "} myBufferVals;\n"
2238 "void main() {\n"
2239 " vec2 vertices[3];"
2240 " vertices[0] = vec2(-0.5, -0.5);\n"
2241 " vertices[1] = vec2( 0.5, -0.5);\n"
2242 " vertices[2] = vec2( 0.5, 0.5);\n"
2243 " outColor = myBufferVals.blue;\n"
2244 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2245 "}\n";
2246
2247 static const char *fragShaderText =
2248 "#version 140\n"
2249 "#extension GL_ARB_separate_shader_objects : enable\n"
2250 "#extension GL_ARB_shading_language_420pack : enable\n"
2251 "layout (location = 0) in vec4 inColor;\n"
2252 "void main() {\n"
2253 " gl_FragColor = inColor;\n"
2254 "}\n";
2255
2256 ASSERT_NO_FATAL_FAILURE(InitState());
2257 ASSERT_NO_FATAL_FAILURE(InitViewport());
2258
2259 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2260 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2261
2262 // Let's populate our buffer with the following:
2263 // vec4 red;
2264 // vec4 green;
2265 // vec4 blue;
2266 // vec4 white;
2267 const int valCount = 4 * 4;
2268 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2269 0.0, 1.0, 0.0, 1.0,
2270 0.0, 0.0, 1.0, 1.0,
2271 1.0, 1.0, 1.0, 1.0 };
2272
2273 XglConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002274
2275 XglPipelineObj pipelineobj(m_device);
2276 pipelineobj.AddShader(&vs);
2277 pipelineobj.AddShader(&ps);
2278
2279 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002280 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002281
Tony Barbourdd4c9642015-01-09 12:55:14 -07002282 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2283 XglCommandBufferObj cmdBuffer(m_device);
2284 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2285
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002286 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002287
2288 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2289
2290#ifdef DUMP_STATE_DOT
2291 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2292 pDSDumpDot((char*)"triTest2.dot");
2293#endif
2294 // render triangle
2295 cmdBuffer.Draw(0, 3, 0, 1);
2296
2297 // finalize recording of the command buffer
2298 cmdBuffer.EndCommandBuffer();
2299 cmdBuffer.QueueCommandBuffer(NULL, 0);
2300
2301 for (int i = 0; i < m_renderTargetCount; i++)
2302 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002303
2304}
2305
2306TEST_F(XglRenderTest, TriangleFSUniformBlockBinding)
2307{
2308 // This test allows the shader to select which buffer it is
2309 // pulling from using layout binding qualifier.
2310 // There are corresponding changes in the compiler stack that
2311 // will select the buffer using binding directly.
2312 // The binding number should match the slot number set up by
2313 // the application.
2314 // The expected result from this test is a purple triangle
2315
2316 static const char *vertShaderText =
2317 "#version 140\n"
2318 "#extension GL_ARB_separate_shader_objects : enable\n"
2319 "#extension GL_ARB_shading_language_420pack : enable\n"
2320 "void main() {\n"
2321 " vec2 vertices[3];"
2322 " vertices[0] = vec2(-0.5, -0.5);\n"
2323 " vertices[1] = vec2( 0.5, -0.5);\n"
2324 " vertices[2] = vec2( 0.5, 0.5);\n"
2325 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2326 "}\n";
2327
2328 static const char *fragShaderText =
2329 "#version 140\n"
2330 "#extension GL_ARB_separate_shader_objects : enable\n"
2331 "#extension GL_ARB_shading_language_420pack : enable\n"
2332 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2333 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2334 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002335 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
Tony Barbourf43b6982014-11-25 13:18:32 -07002336 "void main() {\n"
2337 " gl_FragColor = myBlueVal.color;\n"
2338 " gl_FragColor += myRedVal.color;\n"
2339 "}\n";
2340
2341 ASSERT_NO_FATAL_FAILURE(InitState());
2342 ASSERT_NO_FATAL_FAILURE(InitViewport());
2343
2344 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2345 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2346
2347 // We're going to create a number of uniform buffers, and then allow
2348 // the shader to select which it wants to read from with a binding
2349
2350 // Let's populate the buffers with a single color each:
2351 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2352 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2353 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002354 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002355
2356 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2357 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2358 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2359 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2360
2361 const int redCount = sizeof(redVals) / sizeof(float);
2362 const int greenCount = sizeof(greenVals) / sizeof(float);
2363 const int blueCount = sizeof(blueVals) / sizeof(float);
2364 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2365
2366 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002367
2368 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002369
2370 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002371
2372 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002373
2374 XglPipelineObj pipelineobj(m_device);
2375 pipelineobj.AddShader(&vs);
2376 pipelineobj.AddShader(&ps);
2377
2378 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002379 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2380 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2381 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2382 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002383
Tony Barbourdd4c9642015-01-09 12:55:14 -07002384 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2385 XglCommandBufferObj cmdBuffer(m_device);
2386 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002387
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002388 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002389
2390 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2391
2392#ifdef DUMP_STATE_DOT
2393 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2394 pDSDumpDot((char*)"triTest2.dot");
2395#endif
2396 // render triangle
2397 cmdBuffer.Draw(0, 3, 0, 1);
2398
2399 // finalize recording of the command buffer
2400 cmdBuffer.EndCommandBuffer();
2401 cmdBuffer.QueueCommandBuffer(NULL, 0);
2402
2403 for (int i = 0; i < m_renderTargetCount; i++)
2404 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002405}
2406
2407TEST_F(XglRenderTest, TriangleFSAnonymousUniformBlockBinding)
2408{
2409 // This test is the same as TriangleFSUniformBlockBinding, but
2410 // it does not provide an instance name.
2411 // The expected result from this test is a purple triangle
2412
2413 static const char *vertShaderText =
2414 "#version 140\n"
2415 "#extension GL_ARB_separate_shader_objects : enable\n"
2416 "#extension GL_ARB_shading_language_420pack : enable\n"
2417 "void main() {\n"
2418 " vec2 vertices[3];"
2419 " vertices[0] = vec2(-0.5, -0.5);\n"
2420 " vertices[1] = vec2( 0.5, -0.5);\n"
2421 " vertices[2] = vec2( 0.5, 0.5);\n"
2422 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2423 "}\n";
2424
2425 static const char *fragShaderText =
2426 "#version 430\n"
2427 "#extension GL_ARB_separate_shader_objects : enable\n"
2428 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002429 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2430 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2431 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002432 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002433 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002434 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002435 " outColor = blue;\n"
2436 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002437 "}\n";
2438 ASSERT_NO_FATAL_FAILURE(InitState());
2439 ASSERT_NO_FATAL_FAILURE(InitViewport());
2440
2441 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2442 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2443
2444 // We're going to create a number of uniform buffers, and then allow
2445 // the shader to select which it wants to read from with a binding
2446
2447 // Let's populate the buffers with a single color each:
2448 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2449 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2450 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2451 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2452
2453 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2454 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2455 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2456 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2457
2458 const int redCount = sizeof(redVals) / sizeof(float);
2459 const int greenCount = sizeof(greenVals) / sizeof(float);
2460 const int blueCount = sizeof(blueVals) / sizeof(float);
2461 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2462
2463 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002464
2465 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002466
2467 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002468
2469 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002470
2471 XglPipelineObj pipelineobj(m_device);
2472 pipelineobj.AddShader(&vs);
2473 pipelineobj.AddShader(&ps);
2474
2475 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002476 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2477 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2478 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2479 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002480
Tony Barbourdd4c9642015-01-09 12:55:14 -07002481 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2482 XglCommandBufferObj cmdBuffer(m_device);
2483 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2484
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002485 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002486
2487 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2488
2489#ifdef DUMP_STATE_DOT
2490 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2491 pDSDumpDot((char*)"triTest2.dot");
2492#endif
2493 // render triangle
2494 cmdBuffer.Draw(0, 3, 0, 1);
2495
2496 // finalize recording of the command buffer
2497 cmdBuffer.EndCommandBuffer();
2498 cmdBuffer.QueueCommandBuffer(NULL, 0);
2499
2500 for (int i = 0; i < m_renderTargetCount; i++)
2501 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002502
2503}
2504
2505TEST_F(XglRenderTest, CubeWithVertexFetchAndMVPAndTexture)
2506{
2507 static const char *vertShaderText =
2508 "#version 140\n"
2509 "#extension GL_ARB_separate_shader_objects : enable\n"
2510 "#extension GL_ARB_shading_language_420pack : enable\n"
2511 "layout (std140, binding=0) uniform bufferVals {\n"
2512 " mat4 mvp;\n"
2513 "} myBufferVals;\n"
2514 "layout (location=0) in vec4 pos;\n"
2515 "layout (location=0) out vec2 UV;\n"
2516 "void main() {\n"
2517 " vec2 positions[3];"
2518 " positions[0] = vec2( 0.0, 0.0);\n"
2519 " positions[1] = vec2( 0.25, 0.1);\n"
2520 " positions[2] = vec2( 0.1, 0.25);\n"
2521 " UV = positions[gl_VertexID % 3];\n"
2522 " gl_Position = myBufferVals.mvp * pos;\n"
2523 "}\n";
2524
2525 static const char *fragShaderText =
2526 "#version 140\n"
2527 "#extension GL_ARB_separate_shader_objects : enable\n"
2528 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002529 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002530 "layout (location=0) out vec4 outColor;\n"
2531 "layout (location=0) in vec2 UV;\n"
2532 "void main() {\n"
2533 " outColor= textureLod(surface, UV, 0.0);\n"
2534 "}\n";
2535 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2536
2537 glm::mat4 View = glm::lookAt(
2538 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2539 glm::vec3(0,0,0), // and looks at the origin
2540 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2541 );
2542
2543 glm::mat4 Model = glm::mat4(1.0f);
2544
2545 glm::mat4 MVP = Projection * View * Model;
2546
2547
2548 ASSERT_NO_FATAL_FAILURE(InitState());
2549 ASSERT_NO_FATAL_FAILURE(InitViewport());
2550 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
2551
2552 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
2553 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002554 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002555
2556 const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT);
2557
2558 XglConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2559 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2560 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2561 XglSamplerObj sampler(m_device);
2562 XglTextureObj texture(m_device);
2563
Tony Barbourf43b6982014-11-25 13:18:32 -07002564 XglPipelineObj pipelineobj(m_device);
2565 pipelineobj.AddShader(&vs);
2566 pipelineobj.AddShader(&ps);
2567
2568 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002569 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mvpBuffer);
2570 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002571
2572 m_memoryRefManager.AddMemoryRef(&meshBuffer);
2573 m_memoryRefManager.AddMemoryRef(&mvpBuffer);
2574 m_memoryRefManager.AddMemoryRef(&texture);
2575
2576 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
2577 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
2578 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
2579 };
2580
2581 // this is the current description of g_vbData
2582 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
2583 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
2584 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
2585 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
2586 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2587 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
2588 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
2589 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
2590 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
2591
2592 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2593 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
2594 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
2595
Tony Barbourfa6cac72015-01-16 14:27:35 -07002596 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
2597 ds_state.depthTestEnable = XGL_TRUE;
2598 ds_state.depthWriteEnable = XGL_TRUE;
2599 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
2600 ds_state.depthBoundsEnable = XGL_FALSE;
2601 ds_state.stencilTestEnable = XGL_FALSE;
2602 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
2603 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
2604 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
2605 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
2606 ds_state.format.channelFormat = XGL_CH_FMT_R32;
2607 ds_state.format.numericFormat = XGL_NUM_FMT_DS;
2608 ds_state.front = ds_state.back;
2609 pipelineobj.SetDepthStencil(&ds_state);
2610
Tony Barbourdd4c9642015-01-09 12:55:14 -07002611 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2612 XglCommandBufferObj cmdBuffer(m_device);
2613 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002614
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002615 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002616 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2617
2618 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2619#ifdef DUMP_STATE_DOT
2620 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2621 pDSDumpDot((char*)"triTest2.dot");
2622#endif
2623 // render triangle
2624 cmdBuffer.Draw(0, 36, 0, 1);
2625
2626 // finalize recording of the command buffer
2627 cmdBuffer.EndCommandBuffer();
2628 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
2629
2630 for (int i = 0; i < m_renderTargetCount; i++)
2631 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002632
2633}
Cody Northropd1ce7842014-12-09 11:17:01 -07002634
2635TEST_F(XglRenderTest, TriangleMixedSamplerUniformBlockBinding)
2636{
2637 // This test mixes binding slots of textures and buffers, ensuring
2638 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002639 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002640 // you can modify it to move the desired result around.
2641
2642 static const char *vertShaderText =
2643 "#version 140\n"
2644 "#extension GL_ARB_separate_shader_objects : enable\n"
2645 "#extension GL_ARB_shading_language_420pack : enable\n"
2646 "void main() {\n"
2647 " vec2 vertices[3];"
2648 " vertices[0] = vec2(-0.5, -0.5);\n"
2649 " vertices[1] = vec2( 0.5, -0.5);\n"
2650 " vertices[2] = vec2( 0.5, 0.5);\n"
2651 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2652 "}\n";
2653
2654 static const char *fragShaderText =
2655 "#version 430\n"
2656 "#extension GL_ARB_separate_shader_objects : enable\n"
2657 "#extension GL_ARB_shading_language_420pack : enable\n"
2658 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002659 "layout (binding = 3) uniform sampler2D surface1;\n"
2660 "layout (binding = 1) uniform sampler2D surface2;\n"
2661 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002662
Cody Northropa0410942014-12-09 13:59:39 -07002663
Chia-I Wuf8385062015-01-04 16:27:24 +08002664 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2665 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2666 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2667 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002668 "layout (location = 0) out vec4 outColor;\n"
2669 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002670 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002671 " outColor += white * vec4(0.00001);\n"
2672 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002673 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002674 "}\n";
2675 ASSERT_NO_FATAL_FAILURE(InitState());
2676 ASSERT_NO_FATAL_FAILURE(InitViewport());
2677
2678 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2679 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2680
Cody Northropd1ce7842014-12-09 11:17:01 -07002681 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2682 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2683 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2684 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2685
2686 const int redCount = sizeof(redVals) / sizeof(float);
2687 const int greenCount = sizeof(greenVals) / sizeof(float);
2688 const int blueCount = sizeof(blueVals) / sizeof(float);
2689 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2690
2691 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002692 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002693 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002694 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002695
2696 XglSamplerObj sampler0(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002697 XglTextureObj texture0(m_device); // Light Red
2698 texture0.ChangeColors(0xff800000,0xff800000);
Cody Northropd1ce7842014-12-09 11:17:01 -07002699 XglSamplerObj sampler2(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002700 XglTextureObj texture2(m_device); // Light Blue
2701 texture2.ChangeColors(0xff000080,0xff000080);
Cody Northropd1ce7842014-12-09 11:17:01 -07002702 XglSamplerObj sampler4(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002703 XglTextureObj texture4(m_device); // Light Green
2704 texture4.ChangeColors(0xff008000,0xff008000);
Cody Northropa0410942014-12-09 13:59:39 -07002705
2706 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2707 // TODO: Get back here ASAP and understand why.
2708 XglSamplerObj sampler7(m_device);
2709 XglTextureObj texture7(m_device); // Red and Blue
2710 texture7.ChangeColors(0xffff00ff,0xffff00ff);
Cody Northropd1ce7842014-12-09 11:17:01 -07002711
2712 XglPipelineObj pipelineobj(m_device);
2713 pipelineobj.AddShader(&vs);
2714 pipelineobj.AddShader(&ps);
2715
2716 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002717 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2718 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2719 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2720 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2721 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2722 // swap blue and green
2723 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2724 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2725 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002726
2727 m_memoryRefManager.AddMemoryRef(&texture0);
2728 m_memoryRefManager.AddMemoryRef(&texture2);
2729 m_memoryRefManager.AddMemoryRef(&texture4);
Cody Northropa0410942014-12-09 13:59:39 -07002730 m_memoryRefManager.AddMemoryRef(&texture7);
Cody Northropd1ce7842014-12-09 11:17:01 -07002731
Tony Barbourdd4c9642015-01-09 12:55:14 -07002732 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2733 XglCommandBufferObj cmdBuffer(m_device);
2734 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002735
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002736 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002737
2738 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2739
2740#ifdef DUMP_STATE_DOT
2741 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2742 pDSDumpDot((char*)"triTest2.dot");
2743#endif
2744 // render triangle
2745 cmdBuffer.Draw(0, 3, 0, 1);
2746
2747 // finalize recording of the command buffer
2748 cmdBuffer.EndCommandBuffer();
2749 cmdBuffer.QueueCommandBuffer(NULL, 0);
2750
2751 for (int i = 0; i < m_renderTargetCount; i++)
2752 RecordImage(m_renderTargets[i]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002753
2754}
2755
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002756TEST_F(XglRenderTest, TriangleMatchingSamplerUniformBlockBinding)
2757{
2758 // This test matches binding slots of textures and buffers, requiring
2759 // the driver to give them distinct number spaces.
2760 // The expected result from this test is a red triangle, although
2761 // you can modify it to move the desired result around.
2762
2763 static const char *vertShaderText =
2764 "#version 140\n"
2765 "#extension GL_ARB_separate_shader_objects : enable\n"
2766 "#extension GL_ARB_shading_language_420pack : enable\n"
2767 "void main() {\n"
2768 " vec2 vertices[3];"
2769 " vertices[0] = vec2(-0.5, -0.5);\n"
2770 " vertices[1] = vec2( 0.5, -0.5);\n"
2771 " vertices[2] = vec2( 0.5, 0.5);\n"
2772 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2773 "}\n";
2774
2775 static const char *fragShaderText =
2776 "#version 430\n"
2777 "#extension GL_ARB_separate_shader_objects : enable\n"
2778 "#extension GL_ARB_shading_language_420pack : enable\n"
2779 "layout (binding = 0) uniform sampler2D surface0;\n"
2780 "layout (binding = 1) uniform sampler2D surface1;\n"
2781 "layout (binding = 2) uniform sampler2D surface2;\n"
2782 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002783 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2784 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2785 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2786 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002787 "layout (location = 0) out vec4 outColor;\n"
2788 "void main() {\n"
2789 " outColor = red;// * vec4(0.00001);\n"
2790 " outColor += white * vec4(0.00001);\n"
2791 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2792 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2793 "}\n";
2794 ASSERT_NO_FATAL_FAILURE(InitState());
2795 ASSERT_NO_FATAL_FAILURE(InitViewport());
2796
2797 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2798 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2799
2800 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2801 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2802 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2803 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2804
2805 const int redCount = sizeof(redVals) / sizeof(float);
2806 const int greenCount = sizeof(greenVals) / sizeof(float);
2807 const int blueCount = sizeof(blueVals) / sizeof(float);
2808 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2809
2810 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002811 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002812 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002813 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002814
2815 XglSamplerObj sampler0(m_device);
2816 XglTextureObj texture0(m_device); // Light Red
2817 texture0.ChangeColors(0xff800000,0xff800000);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002818 XglSamplerObj sampler2(m_device);
2819 XglTextureObj texture2(m_device); // Light Blue
2820 texture2.ChangeColors(0xff000080,0xff000080);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002821 XglSamplerObj sampler4(m_device);
2822 XglTextureObj texture4(m_device); // Light Green
2823 texture4.ChangeColors(0xff008000,0xff008000);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002824 XglSamplerObj sampler7(m_device);
2825 XglTextureObj texture7(m_device); // Red and Blue
2826 texture7.ChangeColors(0xffff00ff,0xffff00ff);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002827
2828
2829 XglPipelineObj pipelineobj(m_device);
2830 pipelineobj.AddShader(&vs);
2831 pipelineobj.AddShader(&ps);
2832
2833 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002834 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2835 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2836 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2837 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2838 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2839 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2840 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2841 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002842
2843 m_memoryRefManager.AddMemoryRef(&texture0);
2844 m_memoryRefManager.AddMemoryRef(&texture2);
2845 m_memoryRefManager.AddMemoryRef(&texture4);
2846 m_memoryRefManager.AddMemoryRef(&texture7);
2847
Tony Barbourdd4c9642015-01-09 12:55:14 -07002848 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2849 XglCommandBufferObj cmdBuffer(m_device);
2850 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002851
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002852 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002853
2854 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2855
2856#ifdef DUMP_STATE_DOT
2857 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2858 pDSDumpDot((char*)"triTest2.dot");
2859#endif
2860 // render triangle
2861 cmdBuffer.Draw(0, 3, 0, 1);
2862
2863 // finalize recording of the command buffer
2864 cmdBuffer.EndCommandBuffer();
2865 cmdBuffer.QueueCommandBuffer(NULL, 0);
2866
2867 for (int i = 0; i < m_renderTargetCount; i++)
2868 RecordImage(m_renderTargets[i]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002869
2870}
2871
Cody Northrop02690bd2014-12-17 15:26:33 -07002872TEST_F(XglRenderTest, TriangleUniformBufferLayout)
2873{
2874 // This test populates a buffer with a variety of different data
2875 // types, then reads them out with a shader.
2876 // The expected result from this test is a green triangle
2877
2878 static const char *vertShaderText =
2879 "#version 140\n"
2880 "#extension GL_ARB_separate_shader_objects : enable\n"
2881 "#extension GL_ARB_shading_language_420pack : enable\n"
2882 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2883 " vec4 fRed;\n"
2884 " vec4 fGreen;\n"
2885 " layout(row_major) mat4 worldToProj;\n"
2886 " layout(row_major) mat4 projToWorld;\n"
2887 " layout(row_major) mat4 worldToView;\n"
2888 " layout(row_major) mat4 viewToProj;\n"
2889 " layout(row_major) mat4 worldToShadow[4];\n"
2890 " float fZero;\n"
2891 " float fOne;\n"
2892 " float fTwo;\n"
2893 " float fThree;\n"
2894 " vec3 fZeroZeroZero;\n"
2895 " float fFour;\n"
2896 " vec3 fZeroZeroOne;\n"
2897 " float fFive;\n"
2898 " vec3 fZeroOneZero;\n"
2899 " float fSix;\n"
2900 " float fSeven;\n"
2901 " float fEight;\n"
2902 " float fNine;\n"
2903 " vec2 fZeroZero;\n"
2904 " vec2 fZeroOne;\n"
2905 " vec4 fBlue;\n"
2906 " vec2 fOneZero;\n"
2907 " vec2 fOneOne;\n"
2908 " vec3 fZeroOneOne;\n"
2909 " float fTen;\n"
2910 " float fEleven;\n"
2911 " float fTwelve;\n"
2912 " vec3 fOneZeroZero;\n"
2913 " vec4 uvOffsets[4];\n"
2914 "};\n"
2915 "layout (location = 0) out vec4 color;"
2916 "void main() {\n"
2917
2918 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2919 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2920 " \n"
2921
2922 // do some exact comparisons, even though we should
2923 // really have an epsilon involved.
2924 " vec4 outColor = right;\n"
2925 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
2926 " outColor = wrong;\n"
2927 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
2928 " outColor = wrong;\n"
2929 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
2930 " outColor = wrong;\n"
2931
2932 " color = outColor;\n"
2933
2934 // generic position stuff
2935 " vec2 vertices;\n"
2936 " int vertexSelector = gl_VertexID;\n"
2937 " if (vertexSelector == 0)\n"
2938 " vertices = vec2(-0.5, -0.5);\n"
2939 " else if (vertexSelector == 1)\n"
2940 " vertices = vec2( 0.5, -0.5);\n"
2941 " else if (vertexSelector == 2)\n"
2942 " vertices = vec2( 0.5, 0.5);\n"
2943 " else\n"
2944 " vertices = vec2( 0.0, 0.0);\n"
2945 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
2946 "}\n";
2947
2948 static const char *fragShaderText =
2949 "#version 140\n"
2950 "#extension GL_ARB_separate_shader_objects : enable\n"
2951 "#extension GL_ARB_shading_language_420pack : enable\n"
2952 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2953 " vec4 fRed;\n"
2954 " vec4 fGreen;\n"
2955 " layout(row_major) mat4 worldToProj;\n"
2956 " layout(row_major) mat4 projToWorld;\n"
2957 " layout(row_major) mat4 worldToView;\n"
2958 " layout(row_major) mat4 viewToProj;\n"
2959 " layout(row_major) mat4 worldToShadow[4];\n"
2960 " float fZero;\n"
2961 " float fOne;\n"
2962 " float fTwo;\n"
2963 " float fThree;\n"
2964 " vec3 fZeroZeroZero;\n"
2965 " float fFour;\n"
2966 " vec3 fZeroZeroOne;\n"
2967 " float fFive;\n"
2968 " vec3 fZeroOneZero;\n"
2969 " float fSix;\n"
2970 " float fSeven;\n"
2971 " float fEight;\n"
2972 " float fNine;\n"
2973 " vec2 fZeroZero;\n"
2974 " vec2 fZeroOne;\n"
2975 " vec4 fBlue;\n"
2976 " vec2 fOneZero;\n"
2977 " vec2 fOneOne;\n"
2978 " vec3 fZeroOneOne;\n"
2979 " float fTen;\n"
2980 " float fEleven;\n"
2981 " float fTwelve;\n"
2982 " vec3 fOneZeroZero;\n"
2983 " vec4 uvOffsets[4];\n"
2984 "};\n"
2985 "layout (location = 0) in vec4 color;\n"
2986 "void main() {\n"
2987 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2988 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2989 " \n"
2990
2991 // start with VS value to ensure it passed
2992 " vec4 outColor = color;\n"
2993
2994 // do some exact comparisons, even though we should
2995 // really have an epsilon involved.
2996 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
2997 " outColor = wrong;\n"
2998 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
2999 " outColor = wrong;\n"
3000 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3001 " outColor = wrong;\n"
3002 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3003 " outColor = wrong;\n"
3004 " if (fTwo != 2.0)\n"
3005 " outColor = wrong;\n"
3006 " if (fOneOne != vec2(1.0, 1.0))\n"
3007 " outColor = wrong;\n"
3008 " if (fTen != 10.0)\n"
3009 " outColor = wrong;\n"
3010 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3011 " outColor = wrong;\n"
3012 " \n"
3013 " gl_FragColor = outColor;\n"
3014 "}\n";
3015
3016
3017 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3018 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3019 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3020 0.0, 1.0, 0.0, 1.0, // align
3021 0.0, 0.0, 1.0, 1.0, // align
3022 0.0, 0.0, 0.0, 1.0, // align
3023 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3024 0.0, 2.0, 0.0, 2.0, // align
3025 0.0, 0.0, 2.0, 2.0, // align
3026 0.0, 0.0, 0.0, 2.0, // align
3027 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3028 0.0, 3.0, 0.0, 3.0, // align
3029 0.0, 0.0, 3.0, 3.0, // align
3030 0.0, 0.0, 0.0, 3.0, // align
3031 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3032 0.0, 4.0, 0.0, 4.0, // align
3033 0.0, 0.0, 4.0, 4.0, // align
3034 0.0, 0.0, 0.0, 4.0, // align
3035 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3036 0.0, 5.0, 0.0, 5.0, // align
3037 0.0, 0.0, 5.0, 5.0, // align
3038 0.0, 0.0, 0.0, 5.0, // align
3039 6.0, 0.0, 0.0, 6.0, // align
3040 0.0, 6.0, 0.0, 6.0, // align
3041 0.0, 0.0, 6.0, 6.0, // align
3042 0.0, 0.0, 0.0, 6.0, // align
3043 7.0, 0.0, 0.0, 7.0, // align
3044 0.0, 7.0, 0.0, 7.0, // align
3045 0.0, 0.0, 7.0, 7.0, // align
3046 0.0, 0.0, 0.0, 7.0, // align
3047 8.0, 0.0, 0.0, 8.0, // align
3048 0.0, 8.0, 0.0, 8.0, // align
3049 0.0, 0.0, 8.0, 8.0, // align
3050 0.0, 0.0, 0.0, 8.0, // align
3051 0.0, // float fZero; // align
3052 1.0, // float fOne; // pack
3053 2.0, // float fTwo; // pack
3054 3.0, // float fThree; // pack
3055 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3056 4.0, // float fFour; // pack
3057 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3058 5.0, // float fFive; // pack
3059 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3060 6.0, // float fSix; // pack
3061 7.0, // float fSeven; // align
3062 8.0, // float fEight; // pack
3063 9.0, // float fNine; // pack
3064 0.0, // BUFFER
3065 0.0, 0.0, // vec2 fZeroZero; // align
3066 0.0, 1.0, // vec2 fZeroOne; // pack
3067 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3068 1.0, 0.0, // vec2 fOneZero; // align
3069 1.0, 1.0, // vec2 fOneOne; // pack
3070 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3071 10.0, // float fTen; // pack
3072 11.0, // float fEleven; // align
3073 12.0, // float fTwelve; // pack
3074 0.0, 0.0, // BUFFER
3075 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3076 0.0, // BUFFER
3077 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3078 0.5, 0.6, 0.7, 0.8, // align
3079 0.9, 1.0, 1.1, 1.2, // align
3080 1.3, 1.4, 1.5, 1.6, // align
3081 };
3082
3083 ASSERT_NO_FATAL_FAILURE(InitState());
3084 ASSERT_NO_FATAL_FAILURE(InitViewport());
3085
3086 const int constCount = sizeof(mixedVals) / sizeof(float);
3087
3088 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
3089 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
3090
3091 XglConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003092
3093 XglPipelineObj pipelineobj(m_device);
3094 pipelineobj.AddShader(&vs);
3095 pipelineobj.AddShader(&ps);
3096
3097 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08003098 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003099
3100 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3101 XglCommandBufferObj cmdBuffer(m_device);
3102 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3103
Jeremy Hayese0c3b222015-01-14 16:17:08 -07003104 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Cody Northrop02690bd2014-12-17 15:26:33 -07003105
3106 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
3107
3108#ifdef DUMP_STATE_DOT
3109 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
3110 pDSDumpDot((char*)"triTest2.dot");
3111#endif
3112 // render triangle
3113 cmdBuffer.Draw(0, 3, 0, 1);
3114
3115 // finalize recording of the command buffer
3116 cmdBuffer.EndCommandBuffer();
3117 cmdBuffer.QueueCommandBuffer(NULL, 0);
3118
3119 for (int i = 0; i < m_renderTargetCount; i++)
3120 RecordImage(m_renderTargets[i]);
3121}
3122
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003123int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003124 int result;
3125
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003126 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003127 XglTestFramework::InitArgs(&argc, argv);
3128
Chia-I Wu7133fdc2014-12-15 23:57:34 +08003129 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06003130
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003131 result = RUN_ALL_TESTS();
3132
3133 XglTestFramework::Finish();
3134 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003135}