blob: c7873e9aa74bba65c56563e7d1a836e7ecc6ca79 [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;
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700332 XGL_MEMORY_ALLOC_IMAGE_INFO img_alloc;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600333 XGL_DEPTH_STENCIL_VIEW_CREATE_INFO view;
Jon Ashburna9ae3832015-01-16 09:37:43 -0700334 XGL_MEMORY_REQUIREMENTS *mem_reqs;
Jon Ashburn6317c492014-11-21 11:33:20 -0700335 XGL_SIZE mem_reqs_size=sizeof(XGL_MEMORY_REQUIREMENTS);
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700336 XGL_IMAGE_MEMORY_REQUIREMENTS img_reqs;
337 XGL_SIZE img_reqs_size = sizeof(XGL_IMAGE_MEMORY_REQUIREMENTS);
Jon Ashburna9ae3832015-01-16 09:37:43 -0700338 XGL_UINT num_allocations = 0;
339 XGL_SIZE num_alloc_size = sizeof(num_allocations);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600340
341 // Clean up default state created by framework
342 if (m_stateDepthStencil) xglDestroyObject(m_stateDepthStencil);
343
344 m_depth_stencil_fmt.channelFormat = XGL_CH_FMT_R16;
345 m_depth_stencil_fmt.numericFormat = XGL_NUM_FMT_DS;
346
347 image.sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
348 image.pNext = NULL;
349 image.imageType = XGL_IMAGE_2D;
350 image.format = m_depth_stencil_fmt;
351 image.extent.width = m_width;
352 image.extent.height = m_height;
353 image.extent.depth = 1;
354 image.mipLevels = 1;
355 image.arraySize = 1;
356 image.samples = 1;
357 image.tiling = XGL_OPTIMAL_TILING;
358 image.usage = XGL_IMAGE_USAGE_DEPTH_STENCIL_BIT;
359 image.flags = 0;
360
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700361 img_alloc.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_IMAGE_INFO;
362 img_alloc.pNext = NULL;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600363 mem_alloc.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700364 mem_alloc.pNext = &img_alloc;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600365 mem_alloc.allocationSize = 0;
Jon Ashburn542cd092015-01-20 13:55:32 -0700366 mem_alloc.memProps = XGL_MEMORY_PROPERTY_GPU_ONLY;
Jon Ashburn32769172015-01-20 15:06:59 -0700367 mem_alloc.memType = XGL_MEMORY_TYPE_IMAGE;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600368 mem_alloc.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
369
370 /* create image */
371 err = xglCreateImage(device(), &image,
372 &m_depthStencilImage);
373 ASSERT_XGL_SUCCESS(err);
374
375 err = xglGetObjectInfo(m_depthStencilImage,
Jon Ashburna9ae3832015-01-16 09:37:43 -0700376 XGL_INFO_TYPE_MEMORY_ALLOCATION_COUNT,
377 &num_alloc_size, &num_allocations);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600378 ASSERT_XGL_SUCCESS(err);
Jon Ashburna9ae3832015-01-16 09:37:43 -0700379 ASSERT_EQ(num_alloc_size, sizeof(num_allocations));
380 mem_reqs = (XGL_MEMORY_REQUIREMENTS *) malloc(num_allocations * sizeof(XGL_MEMORY_REQUIREMENTS));
381 m_depthStencilMem = (XGL_GPU_MEMORY *) malloc(num_allocations * sizeof(XGL_GPU_MEMORY));
382 m_num_mem = num_allocations;
383 err = xglGetObjectInfo(m_depthStencilImage,
384 XGL_INFO_TYPE_MEMORY_REQUIREMENTS,
385 &mem_reqs_size, mem_reqs);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600386 ASSERT_XGL_SUCCESS(err);
Jon Ashburna9ae3832015-01-16 09:37:43 -0700387 ASSERT_EQ(mem_reqs_size, sizeof(*mem_reqs));
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700388 err = xglGetObjectInfo(m_depthStencilImage,
389 XGL_INFO_TYPE_IMAGE_MEMORY_REQUIREMENTS,
390 &img_reqs_size, &img_reqs);
391 ASSERT_XGL_SUCCESS(err);
392 ASSERT_EQ(img_reqs_size, sizeof(XGL_IMAGE_MEMORY_REQUIREMENTS));
393 img_alloc.usage = img_reqs.usage;
394 img_alloc.formatClass = img_reqs.formatClass;
395 img_alloc.samples = img_reqs.samples;
Jon Ashburna9ae3832015-01-16 09:37:43 -0700396 for (XGL_UINT i = 0; i < num_allocations; i ++) {
397 mem_alloc.allocationSize = mem_reqs[i].size;
Jon Ashburna9ae3832015-01-16 09:37:43 -0700398
399 /* allocate memory */
400 err = xglAllocMemory(device(), &mem_alloc, &m_depthStencilMem[i]);
401 ASSERT_XGL_SUCCESS(err);
402
403 /* bind memory */
404 err = xglBindObjectMemory(m_depthStencilImage, i,
405 m_depthStencilMem[i], 0);
406 ASSERT_XGL_SUCCESS(err);
407 }
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600408
Tony Barbourfa6cac72015-01-16 14:27:35 -0700409 XGL_DYNAMIC_DS_STATE_CREATE_INFO depthStencil = {};
410 depthStencil.sType = XGL_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO;
411
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600412 depthStencil.minDepth = 0.f;
413 depthStencil.maxDepth = 1.f;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700414 depthStencil.stencilBackRef = 0;
415 depthStencil.stencilFrontRef = 0;
416 depthStencil.stencilReadMask = 0xff;
417 depthStencil.stencilWriteMask = 0xff;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600418
Tony Barbourfa6cac72015-01-16 14:27:35 -0700419 err = xglCreateDynamicDepthStencilState( device(), &depthStencil, &m_stateDepthStencil );
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600420 ASSERT_XGL_SUCCESS( err );
421
422 /* create image view */
423 view.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO;
424 view.pNext = NULL;
425 view.image = XGL_NULL_HANDLE;
426 view.mipLevel = 0;
427 view.baseArraySlice = 0;
428 view.arraySize = 1;
429 view.flags = 0;
430 view.image = m_depthStencilImage;
431 err = xglCreateDepthStencilView(device(), &view, &m_depthStencilView);
432 ASSERT_XGL_SUCCESS(err);
433
434 m_depthStencilBinding.view = m_depthStencilView;
Mike Stroyan55658c22014-12-04 11:08:39 +0000435 m_depthStencilBinding.layout = XGL_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600436}
437
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600438struct xgltriangle_vs_uniform {
439 // Must start with MVP
440 XGL_FLOAT mvp[4][4];
441 XGL_FLOAT position[3][4];
442 XGL_FLOAT color[3][4];
443};
444
Tony Barbourae442072015-01-12 13:27:11 -0700445void XglRenderTest::XGLTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600446{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700447#ifdef DEBUG_CALLBACK
448 xglDbgRegisterMsgCallback(myDbgFunc, NULL);
449#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600450 // Create identity matrix
451 int i;
452 struct xgltriangle_vs_uniform data;
453
454 glm::mat4 Projection = glm::mat4(1.0f);
455 glm::mat4 View = glm::mat4(1.0f);
456 glm::mat4 Model = glm::mat4(1.0f);
457 glm::mat4 MVP = Projection * View * Model;
458 const int matrixSize = sizeof(MVP);
459 const int bufSize = sizeof(xgltriangle_vs_uniform) / sizeof(XGL_FLOAT);
460 memcpy(&data.mvp, &MVP[0][0], matrixSize);
461
462 static const Vertex tri_data[] =
463 {
464 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
465 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
466 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
467 };
468
469 for (i=0; i<3; i++) {
470 data.position[i][0] = tri_data[i].posX;
471 data.position[i][1] = tri_data[i].posY;
472 data.position[i][2] = tri_data[i].posZ;
473 data.position[i][3] = tri_data[i].posW;
474 data.color[i][0] = tri_data[i].r;
475 data.color[i][1] = tri_data[i].g;
476 data.color[i][2] = tri_data[i].b;
477 data.color[i][3] = tri_data[i].a;
478 }
479
Tony Barbourf43b6982014-11-25 13:18:32 -0700480 ASSERT_NO_FATAL_FAILURE(InitState());
481 ASSERT_NO_FATAL_FAILURE(InitViewport());
482
483 XglConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(XGL_FLOAT), (const void*) &data);
484
485 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
486 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700487
488 XglPipelineObj pipelineobj(m_device);
489 pipelineobj.AddShader(&vs);
490 pipelineobj.AddShader(&ps);
491
492 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +0800493 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700494 m_memoryRefManager.AddMemoryRef(&constantBuffer);
495
Tony Barbour71ba3612015-01-09 16:12:35 -0700496 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
497 XglCommandBufferObj cmdBuffer(m_device);
498 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700499
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700500 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour71ba3612015-01-09 16:12:35 -0700501
502 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
503
504 cmdBuffer.BindVertexBuffer(&constantBuffer, 0, 0);
505#ifdef DUMP_STATE_DOT
506 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
507 pDSDumpDot((char*)"triTest2.dot");
508#endif
509 // render triangle
510 cmdBuffer.Draw(0, 3, 0, 1);
511
512 // finalize recording of the command buffer
513 cmdBuffer.EndCommandBuffer();
514 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
515
516 for (int i = 0; i < m_renderTargetCount; i++)
517 RecordImage(m_renderTargets[i]);
518
519 if (rotate)
520 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
521
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700522#ifdef PRINT_OBJECTS
523 //XGL_UINT64 objTrackGetObjectCount(XGL_OBJECT_TYPE type)
524 OBJ_TRACK_GET_OBJECT_COUNT pObjTrackGetObjectCount = (OBJ_TRACK_GET_OBJECT_COUNT)xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjectCount");
525 XGL_UINT64 numObjects = pObjTrackGetObjectCount(XGL_OBJECT_TYPE_ANY);
526 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjects");
527 printf("DEBUG : Number of Objects : %lu\n", numObjects);
528 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjects");
529 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
530 pObjTrackGetObjs(XGL_OBJECT_TYPE_ANY, numObjects, pObjNodeArray);
531 for (i=0; i < numObjects; i++) {
532 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);
533 }
534 free(pObjNodeArray);
535#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700536
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600537}
538
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600539TEST_F(XglRenderTest, XGLTriangle_FragColor)
540{
541 static const char *vertShaderText =
542 "#version 140\n"
543 "#extension GL_ARB_separate_shader_objects : enable\n"
544 "#extension GL_ARB_shading_language_420pack : enable\n"
545 "\n"
546 "layout(binding = 0) uniform buf {\n"
547 " mat4 MVP;\n"
548 " vec4 position[3];\n"
549 " vec4 color[3];\n"
550 "} ubuf;\n"
551 "\n"
552 "layout (location = 0) out vec4 outColor;\n"
553 "\n"
554 "void main() \n"
555 "{\n"
556 " outColor = ubuf.color[gl_VertexID];\n"
557 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
558 "}\n";
559
560 static const char *fragShaderText =
561 "#version 140\n"
562 "#extension GL_ARB_separate_shader_objects : enable\n"
563 "#extension GL_ARB_shading_language_420pack : enable\n"
564 "\n"
565 "layout (location = 0) in vec4 inColor;\n"
566 "\n"
567 "void main()\n"
568 "{\n"
569 " gl_FragColor = inColor;\n"
570 "}\n";
571
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600572 TEST_DESCRIPTION("XGL-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
Tony Barbourae442072015-01-12 13:27:11 -0700573 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600574}
575
576TEST_F(XglRenderTest, XGLTriangle_OutputLocation)
577{
578 static const char *vertShaderText =
579 "#version 140\n"
580 "#extension GL_ARB_separate_shader_objects : enable\n"
581 "#extension GL_ARB_shading_language_420pack : enable\n"
582 "\n"
583 "layout(binding = 0) uniform buf {\n"
584 " mat4 MVP;\n"
585 " vec4 position[3];\n"
586 " vec4 color[3];\n"
587 "} ubuf;\n"
588 "\n"
589 "layout (location = 0) out vec4 outColor;\n"
590 "\n"
591 "void main() \n"
592 "{\n"
593 " outColor = ubuf.color[gl_VertexID];\n"
594 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
595 "}\n";
596
597 static const char *fragShaderText =
598 "#version 140\n"
599 "#extension GL_ARB_separate_shader_objects : enable\n"
600 "#extension GL_ARB_shading_language_420pack : enable\n"
601 "\n"
602 "layout (location = 0) in vec4 inColor;\n"
603 "layout (location = 0) out vec4 outColor;\n"
604 "\n"
605 "void main()\n"
606 "{\n"
607 " outColor = inColor;\n"
608 "}\n";
609
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600610 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 -0600611
Tony Barbourae442072015-01-12 13:27:11 -0700612 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600613}
614
Tony Barbourf43b6982014-11-25 13:18:32 -0700615TEST_F(XglRenderTest, BIL_XGLTriangle)
616{
617 bool saved_use_bil = XglTestFramework::m_use_bil;
618
619 static const char *vertShaderText =
620 "#version 140\n"
621 "#extension GL_ARB_separate_shader_objects : enable\n"
622 "#extension GL_ARB_shading_language_420pack : enable\n"
623 "\n"
624 "layout(binding = 0) uniform buf {\n"
625 " mat4 MVP;\n"
626 " vec4 position[3];\n"
627 " vec4 color[3];\n"
628 "} ubuf;\n"
629 "\n"
630 "layout (location = 0) out vec4 outColor;\n"
631 "\n"
632 "void main() \n"
633 "{\n"
634 " outColor = ubuf.color[gl_VertexID];\n"
635 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
636 "}\n";
637
638 static const char *fragShaderText =
639 "#version 140\n"
640 "#extension GL_ARB_separate_shader_objects : enable\n"
641 "#extension GL_ARB_shading_language_420pack : enable\n"
642 "\n"
643 "layout (location = 0) in vec4 inColor;\n"
644 "\n"
645 "void main()\n"
646 "{\n"
647 " gl_FragColor = inColor;\n"
648 "}\n";
649
650 TEST_DESCRIPTION("XGL-style shaders, but force test framework to compile shader to BIL and pass BIL to driver.");
651
652 XglTestFramework::m_use_bil = true;
653
Tony Barbourae442072015-01-12 13:27:11 -0700654 XGLTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700655
656 XglTestFramework::m_use_bil = saved_use_bil;
657}
658
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600659TEST_F(XglRenderTest, GreenTriangle)
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600660{
661 static const char *vertShaderText =
662 "#version 130\n"
663 "vec2 vertices[3];\n"
664 "void main() {\n"
665 " vertices[0] = vec2(-1.0, -1.0);\n"
666 " vertices[1] = vec2( 1.0, -1.0);\n"
667 " vertices[2] = vec2( 0.0, 1.0);\n"
668 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
669 "}\n";
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600670
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600671 static const char *fragShaderText =
672 "#version 130\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600673 "void main() {\n"
Steve K10b32512014-10-10 08:54:29 -0600674 " gl_FragColor = vec4(0,1,0,1);\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600675 "}\n";
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600676
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600677 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
678
Tony Barbourae442072015-01-12 13:27:11 -0700679 XGLTriangleTest(vertShaderText, fragShaderText, false);
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600680}
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600681
Tony Barbourf43b6982014-11-25 13:18:32 -0700682TEST_F(XglRenderTest, BIL_GreenTriangle)
683{
684 bool saved_use_bil = XglTestFramework::m_use_bil;
685
686 static const char *vertShaderText =
687 "#version 130\n"
688 "vec2 vertices[3];\n"
689 "void main() {\n"
690 " vertices[0] = vec2(-1.0, -1.0);\n"
691 " vertices[1] = vec2( 1.0, -1.0);\n"
692 " vertices[2] = vec2( 0.0, 1.0);\n"
693 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
694 "}\n";
695
696 static const char *fragShaderText =
697 "#version 130\n"
698 "void main() {\n"
699 " gl_FragColor = vec4(0,1,0,1);\n"
700 "}\n";
701
702 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to BIL and gives BIL to driver.");
703
704 XglTestFramework::m_use_bil = true;
Tony Barbourae442072015-01-12 13:27:11 -0700705 XGLTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700706 XglTestFramework::m_use_bil = saved_use_bil;
707}
708
709TEST_F(XglRenderTest, YellowTriangle)
710{
711 static const char *vertShaderText =
712 "#version 130\n"
713 "void main() {\n"
714 " vec2 vertices[3];"
715 " vertices[0] = vec2(-0.5, -0.5);\n"
716 " vertices[1] = vec2( 0.5, -0.5);\n"
717 " vertices[2] = vec2( 0.5, 0.5);\n"
718 " vec4 colors[3];\n"
719 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
720 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
721 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
722 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
723 "}\n";
724
725 static const char *fragShaderText =
726 "#version 130\n"
727 "void main() {\n"
728 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
729 "}\n";
730
Tony Barbourae442072015-01-12 13:27:11 -0700731 XGLTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700732}
733
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600734TEST_F(XglRenderTest, TriangleWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600735{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600736 static const char *vertShaderText =
Tony Barbourf43b6982014-11-25 13:18:32 -0700737 "#version 130\n"
738 //XYZ1( -1, -1, -1 )
739 "in vec4 pos;\n"
740 //XYZ1( 0.f, 0.f, 0.f )
741 "in vec4 inColor;\n"
742 "out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600743 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600744 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600745 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600746 "}\n";
747
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600748
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600749 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700750 "#version 140\n"
751 "#extension GL_ARB_separate_shader_objects : enable\n"
752 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700753 "in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700754 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600755 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700756 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600757 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600758
Tony Barbourf43b6982014-11-25 13:18:32 -0700759
760
761 ASSERT_NO_FATAL_FAILURE(InitState());
762 ASSERT_NO_FATAL_FAILURE(InitViewport());
763
764 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000765 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700766
767 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
768 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
769
770 XglPipelineObj pipelineobj(m_device);
771 pipelineobj.AddShader(&vs);
772 pipelineobj.AddShader(&ps);
773
774 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +0800775 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700776
777 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
778 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
779 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
780 };
781
782 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
783 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
784 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
785 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
786 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
787 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
788 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
789 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
790 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
791
792 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
793 pipelineobj.AddVertexInputBindings(&vi_binding,1);
794 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
795
Tony Barboure4ed9942015-01-09 10:06:53 -0700796 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
797 XglCommandBufferObj cmdBuffer(m_device);
798 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700799
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700800 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -0700801 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
802
Tony Barboure4ed9942015-01-09 10:06:53 -0700803 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
804
805 // render two triangles
806 cmdBuffer.Draw(0, 6, 0, 1);
807
808 // finalize recording of the command buffer
809 cmdBuffer.EndCommandBuffer();
810 cmdBuffer.QueueCommandBuffer(NULL, 0);
811
812 for (int i = 0; i < m_renderTargetCount; i++)
813 RecordImage(m_renderTargets[i]);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600814}
815
Chia-I Wue09d1a72014-12-05 10:32:23 +0800816TEST_F(XglRenderTest, TriangleMRT)
817{
818 static const char *vertShaderText =
819 "#version 130\n"
820 "in vec4 pos;\n"
821 "void main() {\n"
822 " gl_Position = pos;\n"
823 "}\n";
824
825 static const char *fragShaderText =
826 "#version 130\n"
827 "void main() {\n"
828 " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
829 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
830 "}\n";
831 const XGL_FLOAT vb_data[][2] = {
832 { -1.0f, -1.0f },
833 { 1.0f, -1.0f },
834 { -1.0f, 1.0f }
835 };
836
837 ASSERT_NO_FATAL_FAILURE(InitState());
838 ASSERT_NO_FATAL_FAILURE(InitViewport());
839
840 XglConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000841 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800842
843 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
844 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
845
846 XglPipelineObj pipelineobj(m_device);
847 pipelineobj.AddShader(&vs);
848 pipelineobj.AddShader(&ps);
849
850 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
851 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
852 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
853 };
854
855 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attrib;
856 vi_attrib.binding = 0; // index into vertexBindingDescriptions
857 vi_attrib.format.channelFormat = XGL_CH_FMT_R32G32; // format of source data
858 vi_attrib.format.numericFormat = XGL_NUM_FMT_FLOAT;
859 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
860
861 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
862 pipelineobj.AddVertexInputBindings(&vi_binding,1);
863 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
864
865 XglDescriptorSetObj descriptorSet(m_device);
866
867 m_renderTargetCount = 2;
Tony Barboure4ed9942015-01-09 10:06:53 -0700868 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wue09d1a72014-12-05 10:32:23 +0800869
870 XGL_PIPELINE_CB_ATTACHMENT_STATE att = {};
871 att.blendEnable = XGL_FALSE;
872 att.format = m_render_target_fmt;
873 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700874 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800875
Tony Barbour5ed79702015-01-07 14:31:52 -0700876 XglCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700877
Tony Barbour5ed79702015-01-07 14:31:52 -0700878 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
879 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barboure4ed9942015-01-09 10:06:53 -0700880
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700881 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour5ed79702015-01-07 14:31:52 -0700882
Tony Barboure4ed9942015-01-09 10:06:53 -0700883 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
884
Tony Barbour5ed79702015-01-07 14:31:52 -0700885 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700886#ifdef DUMP_STATE_DOT
887 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
888 pDSDumpDot((char*)"triTest2.dot");
889#endif
890 // render triangle
891 cmdBuffer.Draw(0, 3, 0, 1);
892
893 // finalize recording of the command buffer
894 cmdBuffer.EndCommandBuffer();
895 cmdBuffer.QueueCommandBuffer(NULL, 0);
896
897 for (int i = 0; i < m_renderTargetCount; i++)
898 RecordImage(m_renderTargets[i]);
899
Chia-I Wue09d1a72014-12-05 10:32:23 +0800900}
901
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700902TEST_F(XglRenderTest, QuadWithIndexedVertexFetch)
903{
904 static const char *vertShaderText =
905 "#version 140\n"
906 "#extension GL_ARB_separate_shader_objects : enable\n"
907 "#extension GL_ARB_shading_language_420pack : enable\n"
908 "layout(location = 0) in vec4 pos;\n"
909 "layout(location = 1) in vec4 inColor;\n"
910 "layout(location = 0) out vec4 outColor;\n"
911 "void main() {\n"
912 " outColor = inColor;\n"
913 " gl_Position = pos;\n"
914 "}\n";
915
916
917 static const char *fragShaderText =
918 "#version 140\n"
919 "#extension GL_ARB_separate_shader_objects : enable\n"
920 "#extension GL_ARB_shading_language_420pack : enable\n"
921 "layout(location = 0) in vec4 color;\n"
922 "void main() {\n"
923 " gl_FragColor = color;\n"
924 "}\n";
925
926 const Vertex g_vbData[] =
927 {
928 // first tri
929 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
930 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
931 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
932
933 // second tri
934 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
935 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
936 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
937 };
938
939 const uint16_t g_idxData[6] = {
940 0, 1, 2,
941 3, 4, 5,
942 };
943
944 ASSERT_NO_FATAL_FAILURE(InitState());
945 ASSERT_NO_FATAL_FAILURE(InitViewport());
946
947 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000948 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700949
950 XglIndexBufferObj indexBuffer(m_device);
951 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), XGL_INDEX_16, g_idxData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000952 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700953
954 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
955 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
956
957 XglPipelineObj pipelineobj(m_device);
958 pipelineobj.AddShader(&vs);
959 pipelineobj.AddShader(&ps);
960
961 XglDescriptorSetObj descriptorSet(m_device);
962
963 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
964 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
965 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
966 };
967
968 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
969 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
970 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
971 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
972 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
973 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
974 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
975 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
976 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
977
978 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
979 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700980
981 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700982 XglCommandBufferObj cmdBuffer(m_device);
983 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700984 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -0700985
986 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700987
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700988#ifdef DUMP_STATE_DOT
989 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700990 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700991#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700992
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700993 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
994 cmdBuffer.BindIndexBuffer(&indexBuffer,0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700995
996 // render two triangles
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700997 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700998
999 // finalize recording of the command buffer
Tony Barbourde9cf2e2014-12-17 11:16:05 -07001000 cmdBuffer.EndCommandBuffer();
1001 cmdBuffer.QueueCommandBuffer(NULL, 0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001002
Tony Barbourde9cf2e2014-12-17 11:16:05 -07001003 for (int i = 0; i < m_renderTargetCount; i++)
1004 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001005
1006}
1007
GregF6bef1212014-12-02 15:41:44 -07001008TEST_F(XglRenderTest, GreyandRedCirclesonBlue)
1009{
1010 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -07001011
GregF6bef1212014-12-02 15:41:44 -07001012 static const char *vertShaderText =
1013 "#version 140\n"
1014 "#extension GL_ARB_separate_shader_objects : enable\n"
1015 "#extension GL_ARB_shading_language_420pack : enable\n"
1016 "layout (location = 0) in vec4 pos;\n"
1017 "layout (location = 0) out vec4 outColor;\n"
1018 "layout (location = 1) out vec4 outColor2;\n"
1019 "void main() {\n"
1020 " gl_Position = pos;\n"
1021 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1022 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1023 "}\n";
1024
1025 static const char *fragShaderText =
1026 //"#version 140\n"
1027 "#version 330\n"
1028 "#extension GL_ARB_separate_shader_objects : enable\n"
1029 "#extension GL_ARB_shading_language_420pack : enable\n"
1030 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1031 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1032 "layout (location = 0) in vec4 color;\n"
1033 "layout (location = 1) in vec4 color2;\n"
1034 "void main() {\n"
1035 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1036 " float dist_squared = dot(pos, pos);\n"
1037 " gl_FragColor = (dist_squared < 400.0)\n"
1038 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1039 " : color2;\n"
1040 "}\n";
1041
1042 ASSERT_NO_FATAL_FAILURE(InitState());
1043 ASSERT_NO_FATAL_FAILURE(InitViewport());
1044
1045 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001046 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001047
1048 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1049 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1050
1051 XglPipelineObj pipelineobj(m_device);
1052 pipelineobj.AddShader(&vs);
1053 pipelineobj.AddShader(&ps);
1054
1055 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001056 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001057
1058 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1059 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1060 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1061 };
1062
1063 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1064 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1065 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1066 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1067 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1068 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1069 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1070 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1071 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1072
1073 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1074 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1075 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1076
Tony Barbourdd4c9642015-01-09 12:55:14 -07001077 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1078 XglCommandBufferObj cmdBuffer(m_device);
1079 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1080
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001081 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001082
1083 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1084
1085 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1086#ifdef DUMP_STATE_DOT
1087 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1088 pDSDumpDot((char*)"triTest2.dot");
1089#endif
1090 // render triangle
1091 cmdBuffer.Draw(0, 6, 0, 1);
1092
1093 // finalize recording of the command buffer
1094 cmdBuffer.EndCommandBuffer();
1095 cmdBuffer.QueueCommandBuffer(NULL, 0);
1096
1097 for (int i = 0; i < m_renderTargetCount; i++)
1098 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001099
1100}
1101
1102TEST_F(XglRenderTest, RedCirclesonBlue)
1103{
1104 // This tests that we correctly handle unread fragment inputs
1105
1106 static const char *vertShaderText =
1107 "#version 140\n"
1108 "#extension GL_ARB_separate_shader_objects : enable\n"
1109 "#extension GL_ARB_shading_language_420pack : enable\n"
1110 "layout (location = 0) in vec4 pos;\n"
1111 "layout (location = 0) out vec4 outColor;\n"
1112 "layout (location = 1) out vec4 outColor2;\n"
1113 "void main() {\n"
1114 " gl_Position = pos;\n"
1115 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1116 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1117 "}\n";
1118
1119 static const char *fragShaderText =
1120 //"#version 140\n"
1121 "#version 330\n"
1122 "#extension GL_ARB_separate_shader_objects : enable\n"
1123 "#extension GL_ARB_shading_language_420pack : enable\n"
1124 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1125 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1126 "layout (location = 0) in vec4 color;\n"
1127 "layout (location = 1) in vec4 color2;\n"
1128 "void main() {\n"
1129 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1130 " float dist_squared = dot(pos, pos);\n"
1131 " gl_FragColor = (dist_squared < 400.0)\n"
1132 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1133 " : color2;\n"
1134 "}\n";
1135
1136 ASSERT_NO_FATAL_FAILURE(InitState());
1137 ASSERT_NO_FATAL_FAILURE(InitViewport());
1138
1139 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001140 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001141
1142 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1143 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1144
1145 XglPipelineObj pipelineobj(m_device);
1146 pipelineobj.AddShader(&vs);
1147 pipelineobj.AddShader(&ps);
1148
1149 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001150 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001151
1152 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1153 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1154 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1155 };
1156
1157 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1158 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1159 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1160 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1161 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1162 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1163 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1164 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1165 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1166
1167 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1168 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1169 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1170
Tony Barbourdd4c9642015-01-09 12:55:14 -07001171 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1172 XglCommandBufferObj cmdBuffer(m_device);
1173 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1174
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001175 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001176
1177 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1178
1179 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1180#ifdef DUMP_STATE_DOT
1181 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1182 pDSDumpDot((char*)"triTest2.dot");
1183#endif
1184 // render triangle
1185 cmdBuffer.Draw(0, 6, 0, 1);
1186
1187 // finalize recording of the command buffer
1188 cmdBuffer.EndCommandBuffer();
1189 cmdBuffer.QueueCommandBuffer(NULL, 0);
1190
1191 for (int i = 0; i < m_renderTargetCount; i++)
1192 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001193
1194}
1195
1196TEST_F(XglRenderTest, GreyCirclesonBlueFade)
1197{
1198 // This tests reading gl_ClipDistance from FS
1199
1200 static const char *vertShaderText =
1201 "#version 330\n"
1202 "#extension GL_ARB_separate_shader_objects : enable\n"
1203 "#extension GL_ARB_shading_language_420pack : enable\n"
1204 "out gl_PerVertex {\n"
1205 " vec4 gl_Position;\n"
1206 " float gl_ClipDistance[1];\n"
1207 "};\n"
1208 "layout (location = 0) in vec4 pos;\n"
1209 "layout (location = 0) out vec4 outColor;\n"
1210 "layout (location = 1) out vec4 outColor2;\n"
1211 "void main() {\n"
1212 " gl_Position = pos;\n"
1213 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1214 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1215 " float dists[3];\n"
1216 " dists[0] = 0.0;\n"
1217 " dists[1] = 1.0;\n"
1218 " dists[2] = 1.0;\n"
1219 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1220 "}\n";
1221
1222
1223 static const char *fragShaderText =
1224 //"#version 140\n"
1225 "#version 330\n"
1226 "#extension GL_ARB_separate_shader_objects : enable\n"
1227 "#extension GL_ARB_shading_language_420pack : enable\n"
1228 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1229 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1230 "layout (location = 0) in vec4 color;\n"
1231 "layout (location = 1) in vec4 color2;\n"
1232 "void main() {\n"
1233 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1234 " float dist_squared = dot(pos, pos);\n"
1235 " gl_FragColor = (dist_squared < 400.0)\n"
1236 " ? color * gl_ClipDistance[0]\n"
1237 " : color2;\n"
1238 "}\n";
1239
1240 ASSERT_NO_FATAL_FAILURE(InitState());
1241 ASSERT_NO_FATAL_FAILURE(InitViewport());
1242
1243 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001244 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001245
1246 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1247 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1248
1249 XglPipelineObj pipelineobj(m_device);
1250 pipelineobj.AddShader(&vs);
1251 pipelineobj.AddShader(&ps);
1252
1253 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001254 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001255
1256 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1257 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1258 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1259 };
1260
1261 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1262 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1263 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1264 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1265 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1266 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1267 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1268 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1269 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1270
1271 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1272 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1273 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1274
Tony Barbourdd4c9642015-01-09 12:55:14 -07001275 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1276 XglCommandBufferObj cmdBuffer(m_device);
1277 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF6bef1212014-12-02 15:41:44 -07001278
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001279 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001280
1281 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1282
1283 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1284#ifdef DUMP_STATE_DOT
1285 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1286 pDSDumpDot((char*)"triTest2.dot");
1287#endif
1288 // render triangle
1289 cmdBuffer.Draw(0, 6, 0, 1);
1290
1291 // finalize recording of the command buffer
1292 cmdBuffer.EndCommandBuffer();
1293 cmdBuffer.QueueCommandBuffer(NULL, 0);
1294
1295 for (int i = 0; i < m_renderTargetCount; i++)
1296 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001297}
Tony Barbourf43b6982014-11-25 13:18:32 -07001298
GregF7a23c792014-12-02 17:19:34 -07001299TEST_F(XglRenderTest, GreyCirclesonBlueDiscard)
1300{
1301 static const char *vertShaderText =
1302 "#version 140\n"
1303 "#extension GL_ARB_separate_shader_objects : enable\n"
1304 "#extension GL_ARB_shading_language_420pack : enable\n"
1305 "layout (location = 0) in vec4 pos;\n"
1306 "layout (location = 0) out vec4 outColor;\n"
1307 "layout (location = 1) out vec4 outColor2;\n"
1308 "void main() {\n"
1309 " gl_Position = pos;\n"
1310 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1311 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1312 "}\n";
1313
1314
1315 static const char *fragShaderText =
1316 //"#version 140\n"
1317 "#version 330\n"
1318 "#extension GL_ARB_separate_shader_objects : enable\n"
1319 "#extension GL_ARB_shading_language_420pack : enable\n"
1320 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1321 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1322 "layout (location = 0) in vec4 color;\n"
1323 "layout (location = 1) in vec4 color2;\n"
1324 "void main() {\n"
1325 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1326 " float dist_squared = dot(pos, pos);\n"
1327 " if (dist_squared < 100.0)\n"
1328 " discard;\n"
1329 " gl_FragColor = (dist_squared < 400.0)\n"
1330 " ? color\n"
1331 " : color2;\n"
1332 "}\n";
1333
1334 ASSERT_NO_FATAL_FAILURE(InitState());
1335 ASSERT_NO_FATAL_FAILURE(InitViewport());
1336
1337 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001338 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001339
1340 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1341 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1342
1343 XglPipelineObj pipelineobj(m_device);
1344 pipelineobj.AddShader(&vs);
1345 pipelineobj.AddShader(&ps);
1346
1347 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001348 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF7a23c792014-12-02 17:19:34 -07001349
1350 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1351 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1352 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1353 };
1354
1355 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1356 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1357 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1358 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1359 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1360 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1361 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1362 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1363 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1364
1365 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1366 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1367 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1368
Tony Barbourdd4c9642015-01-09 12:55:14 -07001369 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1370 XglCommandBufferObj cmdBuffer(m_device);
1371 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1372
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001373 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001374
1375 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1376
1377 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1378#ifdef DUMP_STATE_DOT
1379 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1380 pDSDumpDot((char*)"triTest2.dot");
1381#endif
1382 // render triangle
1383 cmdBuffer.Draw(0, 6, 0, 1);
1384
1385 // finalize recording of the command buffer
1386 cmdBuffer.EndCommandBuffer();
1387 cmdBuffer.QueueCommandBuffer(NULL, 0);
1388
1389 for (int i = 0; i < m_renderTargetCount; i++)
1390 RecordImage(m_renderTargets[i]);
GregF7a23c792014-12-02 17:19:34 -07001391
1392}
1393
1394
Courtney Goeltzenleuchter3d10c9c2014-10-27 13:06:08 -06001395TEST_F(XglRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001396{
1397 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001398 "#version 140\n"
1399 "#extension GL_ARB_separate_shader_objects : enable\n"
1400 "#extension GL_ARB_shading_language_420pack : enable\n"
1401 "\n"
1402 "layout(binding = 0) uniform buf {\n"
1403 " mat4 MVP;\n"
1404 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001405 "void main() {\n"
1406 " vec2 vertices[3];"
1407 " vertices[0] = vec2(-0.5, -0.5);\n"
1408 " vertices[1] = vec2( 0.5, -0.5);\n"
1409 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001410 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001411 "}\n";
1412
1413 static const char *fragShaderText =
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001414 "#version 130\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001415 "void main() {\n"
Cody Northrop78eac042014-10-10 15:45:00 -06001416 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001417 "}\n";
1418
Tony Barbourf43b6982014-11-25 13:18:32 -07001419 ASSERT_NO_FATAL_FAILURE(InitState());
1420 ASSERT_NO_FATAL_FAILURE(InitViewport());
1421
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001422 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001423 glm::mat4 Projection = glm::mat4(1.0f);
1424 glm::mat4 View = glm::mat4(1.0f);
1425 glm::mat4 Model = glm::mat4(1.0f);
1426 glm::mat4 MVP = Projection * View * Model;
1427 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1428
Tony Barbourf43b6982014-11-25 13:18:32 -07001429 XglConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1430 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1431 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001432
Tony Barbourf43b6982014-11-25 13:18:32 -07001433 XglPipelineObj pipelineobj(m_device);
1434 pipelineobj.AddShader(&vs);
1435 pipelineobj.AddShader(&ps);
1436
1437 // Create descriptor set and attach the constant buffer to it
1438 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001439 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001440
1441 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1442
Tony Barbourdd4c9642015-01-09 12:55:14 -07001443 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1444 XglCommandBufferObj cmdBuffer(m_device);
1445 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001446
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001447 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001448
1449 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1450
1451 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1452#ifdef DUMP_STATE_DOT
1453 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1454 pDSDumpDot((char*)"triTest2.dot");
1455#endif
1456 // render triangle
1457 cmdBuffer.Draw(0, 6, 0, 1);
1458
1459 // finalize recording of the command buffer
1460 cmdBuffer.EndCommandBuffer();
1461 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
1462
1463 for (int i = 0; i < m_renderTargetCount; i++)
1464 RecordImage(m_renderTargets[i]);
1465
1466 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001467}
1468
Tony Barbourf43b6982014-11-25 13:18:32 -07001469TEST_F(XglRenderTest, MixTriangle)
1470{
1471 // This tests location applied to varyings. Notice that we have switched foo
1472 // and bar in the FS. The triangle should be blended with red, green and blue
1473 // corners.
1474 static const char *vertShaderText =
1475 "#version 140\n"
1476 "#extension GL_ARB_separate_shader_objects : enable\n"
1477 "#extension GL_ARB_shading_language_420pack : enable\n"
1478 "layout (location=0) out vec4 bar;\n"
1479 "layout (location=1) out vec4 foo;\n"
1480 "layout (location=2) out float scale;\n"
1481 "vec2 vertices[3];\n"
1482 "void main() {\n"
1483 " vertices[0] = vec2(-1.0, -1.0);\n"
1484 " vertices[1] = vec2( 1.0, -1.0);\n"
1485 " vertices[2] = vec2( 0.0, 1.0);\n"
1486 "vec4 colors[3];\n"
1487 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1488 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1489 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1490 " foo = colors[gl_VertexID % 3];\n"
1491 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1492 " scale = 1.0;\n"
1493 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1494 "}\n";
1495
1496 static const char *fragShaderText =
1497 "#version 140\n"
1498 "#extension GL_ARB_separate_shader_objects : enable\n"
1499 "#extension GL_ARB_shading_language_420pack : enable\n"
1500 "layout (location = 1) in vec4 bar;\n"
1501 "layout (location = 0) in vec4 foo;\n"
1502 "layout (location = 2) in float scale;\n"
1503 "void main() {\n"
1504 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
1505 "}\n";
1506
1507 ASSERT_NO_FATAL_FAILURE(InitState());
1508 ASSERT_NO_FATAL_FAILURE(InitViewport());
1509
1510 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1511 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1512
1513 XglPipelineObj pipelineobj(m_device);
1514 pipelineobj.AddShader(&vs);
1515 pipelineobj.AddShader(&ps);
1516
1517 XglDescriptorSetObj descriptorSet(m_device);
1518
Tony Barbourdd4c9642015-01-09 12:55:14 -07001519 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1520 XglCommandBufferObj cmdBuffer(m_device);
1521 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1522
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001523 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001524
1525 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1526
1527#ifdef DUMP_STATE_DOT
1528 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1529 pDSDumpDot((char*)"triTest2.dot");
1530#endif
1531 // render triangle
1532 cmdBuffer.Draw(0, 3, 0, 1);
1533
1534 // finalize recording of the command buffer
1535 cmdBuffer.EndCommandBuffer();
1536 cmdBuffer.QueueCommandBuffer(NULL, 0);
1537
1538 for (int i = 0; i < m_renderTargetCount; i++)
1539 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001540}
1541
1542TEST_F(XglRenderTest, TriVertFetchAndVertID)
1543{
1544 // This tests that attributes work in the presence of gl_VertexID
1545
1546 static const char *vertShaderText =
1547 "#version 140\n"
1548 "#extension GL_ARB_separate_shader_objects : enable\n"
1549 "#extension GL_ARB_shading_language_420pack : enable\n"
1550 //XYZ1( -1, -1, -1 )
1551 "layout (location = 0) in vec4 pos;\n"
1552 //XYZ1( 0.f, 0.f, 0.f )
1553 "layout (location = 1) in vec4 inColor;\n"
1554 "layout (location = 0) out vec4 outColor;\n"
1555 "void main() {\n"
1556 " outColor = inColor;\n"
1557 " vec4 vertices[3];"
1558 " vertices[gl_VertexID % 3] = pos;\n"
1559 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1560 "}\n";
1561
1562
1563 static const char *fragShaderText =
1564 "#version 140\n"
1565 "#extension GL_ARB_separate_shader_objects : enable\n"
1566 "#extension GL_ARB_shading_language_420pack : enable\n"
1567 "layout (location = 0) in vec4 color;\n"
1568 "void main() {\n"
1569 " gl_FragColor = color;\n"
1570 "}\n";
1571
1572 ASSERT_NO_FATAL_FAILURE(InitState());
1573 ASSERT_NO_FATAL_FAILURE(InitViewport());
1574
1575 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001576 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001577
1578 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1579 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1580
1581 XglPipelineObj pipelineobj(m_device);
1582 pipelineobj.AddShader(&vs);
1583 pipelineobj.AddShader(&ps);
1584
1585 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001586 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001587
1588 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1589 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1590 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1591 };
1592
1593 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1594 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1595 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1596 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1597 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1598 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1599 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1600 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1601 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1602
1603 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1604 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1605 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1606
Tony Barbourdd4c9642015-01-09 12:55:14 -07001607 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1608 XglCommandBufferObj cmdBuffer(m_device);
1609 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1610
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001611 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001612
1613 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1614
1615 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1616#ifdef DUMP_STATE_DOT
1617 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1618 pDSDumpDot((char*)"triTest2.dot");
1619#endif
1620 // render triangle
1621 cmdBuffer.Draw(0, 6, 0, 1);
1622
1623 // finalize recording of the command buffer
1624 cmdBuffer.EndCommandBuffer();
1625 cmdBuffer.QueueCommandBuffer(NULL, 0);
1626
1627 for (int i = 0; i < m_renderTargetCount; i++)
1628 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001629}
1630
1631TEST_F(XglRenderTest, TriVertFetchDeadAttr)
1632{
1633 // This tests that attributes work in the presence of gl_VertexID
1634 // and a dead attribute in position 0. Draws a triangle with yellow,
1635 // red and green corners, starting at top and going clockwise.
1636
1637 static const char *vertShaderText =
1638 "#version 140\n"
1639 "#extension GL_ARB_separate_shader_objects : enable\n"
1640 "#extension GL_ARB_shading_language_420pack : enable\n"
1641 //XYZ1( -1, -1, -1 )
1642 "layout (location = 0) in vec4 pos;\n"
1643 //XYZ1( 0.f, 0.f, 0.f )
1644 "layout (location = 1) in vec4 inColor;\n"
1645 "layout (location = 0) out vec4 outColor;\n"
1646 "void main() {\n"
1647 " outColor = inColor;\n"
1648 " vec2 vertices[3];"
1649 " vertices[0] = vec2(-1.0, -1.0);\n"
1650 " vertices[1] = vec2( 1.0, -1.0);\n"
1651 " vertices[2] = vec2( 0.0, 1.0);\n"
1652 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1653 "}\n";
1654
1655
1656 static const char *fragShaderText =
1657 "#version 140\n"
1658 "#extension GL_ARB_separate_shader_objects : enable\n"
1659 "#extension GL_ARB_shading_language_420pack : enable\n"
1660 "layout (location = 0) in vec4 color;\n"
1661 "void main() {\n"
1662 " gl_FragColor = color;\n"
1663 "}\n";
1664
1665 ASSERT_NO_FATAL_FAILURE(InitState());
1666 ASSERT_NO_FATAL_FAILURE(InitViewport());
1667
1668 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001669 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001670
1671 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1672 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1673
1674 XglPipelineObj pipelineobj(m_device);
1675 pipelineobj.AddShader(&vs);
1676 pipelineobj.AddShader(&ps);
1677
1678 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001679 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001680
1681 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1682 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1683 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1684 };
1685
1686 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1687 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1688 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1689 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1690 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1691 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1692 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1693 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1694 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1695
1696 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1697 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1698 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1699
Tony Barbourdd4c9642015-01-09 12:55:14 -07001700 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1701 XglCommandBufferObj cmdBuffer(m_device);
1702 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001703
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001704 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001705
1706 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1707
1708 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1709#ifdef DUMP_STATE_DOT
1710 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1711 pDSDumpDot((char*)"triTest2.dot");
1712#endif
1713 // render triangle
1714 cmdBuffer.Draw(0, 6, 0, 1);
1715
1716 // finalize recording of the command buffer
1717 cmdBuffer.EndCommandBuffer();
1718 cmdBuffer.QueueCommandBuffer(NULL, 0);
1719
1720 for (int i = 0; i < m_renderTargetCount; i++)
1721 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001722}
1723
1724TEST_F(XglRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001725{
1726 static const char *vertShaderText =
1727 "#version 140\n"
1728 "layout (std140) uniform bufferVals {\n"
1729 " mat4 mvp;\n"
1730 "} myBufferVals;\n"
1731 "in vec4 pos;\n"
1732 "in vec4 inColor;\n"
1733 "out vec4 outColor;\n"
1734 "void main() {\n"
1735 " outColor = inColor;\n"
1736 " gl_Position = myBufferVals.mvp * pos;\n"
1737 "}\n";
1738
1739 static const char *fragShaderText =
1740 "#version 130\n"
1741 "in vec4 color;\n"
1742 "void main() {\n"
1743 " gl_FragColor = color;\n"
1744 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001745 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001746
Tony Barbourf43b6982014-11-25 13:18:32 -07001747 glm::mat4 View = glm::lookAt(
1748 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1749 glm::vec3(0,0,0), // and looks at the origin
1750 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
1751 );
1752
1753 glm::mat4 Model = glm::mat4(1.0f);
1754
1755 glm::mat4 MVP = Projection * View * Model;
1756
1757 ASSERT_NO_FATAL_FAILURE(InitState());
1758 ASSERT_NO_FATAL_FAILURE(InitViewport());
1759 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
1760
1761 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
1762 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1763
1764 const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT);
1765
1766 XglConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1767 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1768 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1769
Tony Barbourf43b6982014-11-25 13:18:32 -07001770 XglPipelineObj pipelineobj(m_device);
1771 pipelineobj.AddShader(&vs);
1772 pipelineobj.AddShader(&ps);
1773
Tony Barbourfa6cac72015-01-16 14:27:35 -07001774 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
1775 ds_state.depthTestEnable = XGL_TRUE;
1776 ds_state.depthWriteEnable = XGL_TRUE;
1777 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
1778 ds_state.depthBoundsEnable = XGL_FALSE;
1779 ds_state.stencilTestEnable = XGL_FALSE;
1780 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
1781 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
1782 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
1783 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
1784 ds_state.format.channelFormat = XGL_CH_FMT_R32;
1785 ds_state.format.numericFormat = XGL_NUM_FMT_DS;
1786 ds_state.front = ds_state.back;
1787 pipelineobj.SetDepthStencil(&ds_state);
1788
Tony Barbourf43b6982014-11-25 13:18:32 -07001789 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001790 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001791
1792 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1793 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1794
1795 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1796 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1797 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1798 };
1799
1800 // this is the current description of g_vbData
1801 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1802 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1803 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1804 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1805 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1806 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1807 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1808 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1809 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1810
1811 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1812 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1813 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1814
Tony Barboure4ed9942015-01-09 10:06:53 -07001815 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1816 XglCommandBufferObj cmdBuffer(m_device);
1817 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001818
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001819 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -07001820 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001821
Tony Barboure4ed9942015-01-09 10:06:53 -07001822 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1823#ifdef DUMP_STATE_DOT
1824 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1825 pDSDumpDot((char*)"triTest2.dot");
1826#endif
1827 // render triangle
1828 cmdBuffer.Draw(0, 36, 0, 1);
1829
1830 // finalize recording of the command buffer
1831 cmdBuffer.EndCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001832 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barboure4ed9942015-01-09 10:06:53 -07001833
1834 for (int i = 0; i < m_renderTargetCount; i++)
1835 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001836}
1837
Tony Barbourf43b6982014-11-25 13:18:32 -07001838TEST_F(XglRenderTest, VSTexture)
1839{
1840 // The expected result from this test is a green and red triangle;
1841 // one red vertex on the left, two green vertices on the right.
1842 static const char *vertShaderText =
1843 "#version 130\n"
1844 "out vec4 texColor;\n"
1845 "uniform sampler2D surface;\n"
1846 "void main() {\n"
1847 " vec2 vertices[3];"
1848 " vertices[0] = vec2(-0.5, -0.5);\n"
1849 " vertices[1] = vec2( 0.5, -0.5);\n"
1850 " vertices[2] = vec2( 0.5, 0.5);\n"
1851 " vec2 positions[3];"
1852 " positions[0] = vec2( 0.0, 0.0);\n"
1853 " positions[1] = vec2( 0.25, 0.1);\n"
1854 " positions[2] = vec2( 0.1, 0.25);\n"
1855 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1856 " texColor = textureLod(surface, samplePos, 0.0);\n"
1857 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1858 "}\n";
1859
1860 static const char *fragShaderText =
1861 "#version 130\n"
1862 "in vec4 texColor;\n"
1863 "void main() {\n"
1864 " gl_FragColor = texColor;\n"
1865 "}\n";
1866
1867 ASSERT_NO_FATAL_FAILURE(InitState());
1868 ASSERT_NO_FATAL_FAILURE(InitViewport());
1869
1870 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1871 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1872 XglSamplerObj sampler(m_device);
1873 XglTextureObj texture(m_device);
1874
Tony Barbourf43b6982014-11-25 13:18:32 -07001875 XglPipelineObj pipelineobj(m_device);
1876 pipelineobj.AddShader(&vs);
1877 pipelineobj.AddShader(&ps);
1878
1879 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001880 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001881
1882 m_memoryRefManager.AddMemoryRef(&texture);
1883
Tony Barbourdd4c9642015-01-09 12:55:14 -07001884 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1885 XglCommandBufferObj cmdBuffer(m_device);
1886 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001887
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001888 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001889
1890 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1891
1892#ifdef DUMP_STATE_DOT
1893 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1894 pDSDumpDot((char*)"triTest2.dot");
1895#endif
1896 // render triangle
1897 cmdBuffer.Draw(0, 3, 0, 1);
1898
1899 // finalize recording of the command buffer
1900 cmdBuffer.EndCommandBuffer();
1901 cmdBuffer.QueueCommandBuffer(NULL, 0);
1902
1903 for (int i = 0; i < m_renderTargetCount; i++)
1904 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001905}
1906TEST_F(XglRenderTest, TexturedTriangle)
1907{
1908 // The expected result from this test is a red and green checkered triangle
1909 static const char *vertShaderText =
1910 "#version 140\n"
1911 "#extension GL_ARB_separate_shader_objects : enable\n"
1912 "#extension GL_ARB_shading_language_420pack : enable\n"
1913 "layout (location = 0) out vec2 samplePos;\n"
1914 "void main() {\n"
1915 " vec2 vertices[3];"
1916 " vertices[0] = vec2(-0.5, -0.5);\n"
1917 " vertices[1] = vec2( 0.5, -0.5);\n"
1918 " vertices[2] = vec2( 0.5, 0.5);\n"
1919 " vec2 positions[3];"
1920 " positions[0] = vec2( 0.0, 0.0);\n"
1921 " positions[1] = vec2( 1.0, 0.0);\n"
1922 " positions[2] = vec2( 1.0, 1.0);\n"
1923 " samplePos = positions[gl_VertexID % 3];\n"
1924 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1925 "}\n";
1926
1927 static const char *fragShaderText =
1928 "#version 140\n"
1929 "#extension GL_ARB_separate_shader_objects : enable\n"
1930 "#extension GL_ARB_shading_language_420pack : enable\n"
1931 "layout (location = 0) in vec2 samplePos;\n"
1932 "layout (binding = 0) uniform sampler2D surface;\n"
1933 "layout (location=0) out vec4 outColor;\n"
1934 "void main() {\n"
1935 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1936 " outColor = texColor;\n"
1937 "}\n";
1938
1939 ASSERT_NO_FATAL_FAILURE(InitState());
1940 ASSERT_NO_FATAL_FAILURE(InitViewport());
1941
1942 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1943 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1944 XglSamplerObj sampler(m_device);
1945 XglTextureObj texture(m_device);
1946
Tony Barbourf43b6982014-11-25 13:18:32 -07001947 XglPipelineObj pipelineobj(m_device);
1948 pipelineobj.AddShader(&vs);
1949 pipelineobj.AddShader(&ps);
1950
1951 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001952 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001953
1954 m_memoryRefManager.AddMemoryRef(&texture);
1955
Tony Barbourdd4c9642015-01-09 12:55:14 -07001956 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1957 XglCommandBufferObj cmdBuffer(m_device);
1958 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1959
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001960 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001961
1962 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1963
1964#ifdef DUMP_STATE_DOT
1965 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1966 pDSDumpDot((char*)"triTest2.dot");
1967#endif
1968 // render triangle
1969 cmdBuffer.Draw(0, 3, 0, 1);
1970
1971 // finalize recording of the command buffer
1972 cmdBuffer.EndCommandBuffer();
1973 cmdBuffer.QueueCommandBuffer(NULL, 0);
1974
1975 for (int i = 0; i < m_renderTargetCount; i++)
1976 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001977}
1978TEST_F(XglRenderTest, TexturedTriangleClip)
1979{
1980 // The expected result from this test is a red and green checkered triangle
1981 static const char *vertShaderText =
1982 "#version 330\n"
1983 "#extension GL_ARB_separate_shader_objects : enable\n"
1984 "#extension GL_ARB_shading_language_420pack : enable\n"
1985 "layout (location = 0) out vec2 samplePos;\n"
1986 "out gl_PerVertex {\n"
1987 " vec4 gl_Position;\n"
1988 " float gl_ClipDistance[1];\n"
1989 "};\n"
1990 "void main() {\n"
1991 " vec2 vertices[3];"
1992 " vertices[0] = vec2(-0.5, -0.5);\n"
1993 " vertices[1] = vec2( 0.5, -0.5);\n"
1994 " vertices[2] = vec2( 0.5, 0.5);\n"
1995 " vec2 positions[3];"
1996 " positions[0] = vec2( 0.0, 0.0);\n"
1997 " positions[1] = vec2( 1.0, 0.0);\n"
1998 " positions[2] = vec2( 1.0, 1.0);\n"
1999 " float dists[3];\n"
2000 " dists[0] = 1.0;\n"
2001 " dists[1] = 1.0;\n"
2002 " dists[2] = -1.0;\n"
2003 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2004 " samplePos = positions[gl_VertexID % 3];\n"
2005 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2006 "}\n";
2007
2008 static const char *fragShaderText =
2009 "#version 140\n"
2010 "#extension GL_ARB_separate_shader_objects : enable\n"
2011 "#extension GL_ARB_shading_language_420pack : enable\n"
2012 "layout (location = 0) in vec2 samplePos;\n"
2013 "layout (binding = 0) uniform sampler2D surface;\n"
2014 "layout (location=0) out vec4 outColor;\n"
2015 "void main() {\n"
2016 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2017 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2018 " outColor = texColor;\n"
2019 "}\n";
2020
2021
2022 ASSERT_NO_FATAL_FAILURE(InitState());
2023 ASSERT_NO_FATAL_FAILURE(InitViewport());
2024
2025 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2026 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2027 XglSamplerObj sampler(m_device);
2028 XglTextureObj texture(m_device);
2029
Tony Barbourf43b6982014-11-25 13:18:32 -07002030 XglPipelineObj pipelineobj(m_device);
2031 pipelineobj.AddShader(&vs);
2032 pipelineobj.AddShader(&ps);
2033
2034 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002035 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002036
2037 m_memoryRefManager.AddMemoryRef(&texture);
2038
Tony Barbourdd4c9642015-01-09 12:55:14 -07002039 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2040 XglCommandBufferObj cmdBuffer(m_device);
2041 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2042
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002043 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002044
2045 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2046
2047#ifdef DUMP_STATE_DOT
2048 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2049 pDSDumpDot((char*)"triTest2.dot");
2050#endif
2051 // render triangle
2052 cmdBuffer.Draw(0, 3, 0, 1);
2053
2054 // finalize recording of the command buffer
2055 cmdBuffer.EndCommandBuffer();
2056 cmdBuffer.QueueCommandBuffer(NULL, 0);
2057
2058 for (int i = 0; i < m_renderTargetCount; i++)
2059 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002060}
2061TEST_F(XglRenderTest, FSTriangle)
2062{
2063 // The expected result from this test is a red and green checkered triangle
2064 static const char *vertShaderText =
2065 "#version 140\n"
2066 "#extension GL_ARB_separate_shader_objects : enable\n"
2067 "#extension GL_ARB_shading_language_420pack : enable\n"
2068 "layout (location = 0) out vec2 samplePos;\n"
2069 "void main() {\n"
2070 " vec2 vertices[3];"
2071 " vertices[0] = vec2(-0.5, -0.5);\n"
2072 " vertices[1] = vec2( 0.5, -0.5);\n"
2073 " vertices[2] = vec2( 0.5, 0.5);\n"
2074 " vec2 positions[3];"
2075 " positions[0] = vec2( 0.0, 0.0);\n"
2076 " positions[1] = vec2( 1.0, 0.0);\n"
2077 " positions[2] = vec2( 1.0, 1.0);\n"
2078 " samplePos = positions[gl_VertexID % 3];\n"
2079 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2080 "}\n";
2081
2082 static const char *fragShaderText =
2083 "#version 140\n"
2084 "#extension GL_ARB_separate_shader_objects : enable\n"
2085 "#extension GL_ARB_shading_language_420pack : enable\n"
2086 "layout (location = 0) in vec2 samplePos;\n"
2087 "layout (binding = 0) uniform sampler2D surface;\n"
2088 "layout (location=0) out vec4 outColor;\n"
2089 "void main() {\n"
2090 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2091 " outColor = texColor;\n"
2092 "}\n";
2093
2094 ASSERT_NO_FATAL_FAILURE(InitState());
2095 ASSERT_NO_FATAL_FAILURE(InitViewport());
2096
2097 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2098 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2099 XglSamplerObj sampler(m_device);
2100 XglTextureObj texture(m_device);
2101
Tony Barbourf43b6982014-11-25 13:18:32 -07002102 XglPipelineObj pipelineobj(m_device);
2103 pipelineobj.AddShader(&vs);
2104 pipelineobj.AddShader(&ps);
2105
2106 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002107 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002108
2109 m_memoryRefManager.AddMemoryRef(&texture);
2110
Tony Barbourdd4c9642015-01-09 12:55:14 -07002111 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2112 XglCommandBufferObj cmdBuffer(m_device);
2113 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2114
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002115 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002116
2117 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2118
2119#ifdef DUMP_STATE_DOT
2120 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2121 pDSDumpDot((char*)"triTest2.dot");
2122#endif
2123 // render triangle
2124 cmdBuffer.Draw(0, 3, 0, 1);
2125
2126 // finalize recording of the command buffer
2127 cmdBuffer.EndCommandBuffer();
2128 cmdBuffer.QueueCommandBuffer(NULL, 0);
2129
2130 for (int i = 0; i < m_renderTargetCount; i++)
2131 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002132}
2133TEST_F(XglRenderTest, SamplerBindingsTriangle)
2134{
2135 // This test sets bindings on the samplers
2136 // For now we are asserting that sampler and texture pairs
2137 // march in lock step, and are set via GLSL binding. This can
2138 // and will probably change.
2139 // The sampler bindings should match the sampler and texture slot
2140 // number set up by the application.
2141 // This test will result in a blue triangle
2142 static const char *vertShaderText =
2143 "#version 140\n"
2144 "#extension GL_ARB_separate_shader_objects : enable\n"
2145 "#extension GL_ARB_shading_language_420pack : enable\n"
2146 "layout (location = 0) out vec4 samplePos;\n"
2147 "void main() {\n"
2148 " vec2 vertices[3];"
2149 " vertices[0] = vec2(-0.5, -0.5);\n"
2150 " vertices[1] = vec2( 0.5, -0.5);\n"
2151 " vertices[2] = vec2( 0.5, 0.5);\n"
2152 " vec2 positions[3];"
2153 " positions[0] = vec2( 0.0, 0.0);\n"
2154 " positions[1] = vec2( 1.0, 0.0);\n"
2155 " positions[2] = vec2( 1.0, 1.0);\n"
2156 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2157 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2158 "}\n";
2159
2160 static const char *fragShaderText =
2161 "#version 140\n"
2162 "#extension GL_ARB_separate_shader_objects : enable\n"
2163 "#extension GL_ARB_shading_language_420pack : enable\n"
2164 "layout (location = 0) in vec4 samplePos;\n"
2165 "layout (binding = 0) uniform sampler2D surface0;\n"
2166 "layout (binding = 1) uniform sampler2D surface1;\n"
2167 "layout (binding = 12) uniform sampler2D surface2;\n"
2168 "void main() {\n"
2169 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
2170 "}\n";
2171
2172 ASSERT_NO_FATAL_FAILURE(InitState());
2173 ASSERT_NO_FATAL_FAILURE(InitViewport());
2174
2175 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2176 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2177
2178 XglSamplerObj sampler1(m_device);
2179 XglSamplerObj sampler2(m_device);
2180 XglSamplerObj sampler3(m_device);
2181
2182 XglTextureObj texture1(m_device); // Red
2183 texture1.ChangeColors(0xffff0000,0xffff0000);
2184 XglTextureObj texture2(m_device); // Green
2185 texture2.ChangeColors(0xff00ff00,0xff00ff00);
2186 XglTextureObj texture3(m_device); // Blue
2187 texture3.ChangeColors(0xff0000ff,0xff0000ff);
2188
Tony Barbourf43b6982014-11-25 13:18:32 -07002189 XglPipelineObj pipelineobj(m_device);
2190 pipelineobj.AddShader(&vs);
2191 pipelineobj.AddShader(&ps);
2192
2193 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002194 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2195 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2196 for (int i = 0; i < 10; i++)
2197 descriptorSet.AppendDummy();
2198 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002199
2200 m_memoryRefManager.AddMemoryRef(&texture1);
2201 m_memoryRefManager.AddMemoryRef(&texture2);
2202 m_memoryRefManager.AddMemoryRef(&texture3);
2203
Tony Barbourdd4c9642015-01-09 12:55:14 -07002204 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2205 XglCommandBufferObj cmdBuffer(m_device);
2206 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2207
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002208 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002209
2210 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2211
2212#ifdef DUMP_STATE_DOT
2213 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2214 pDSDumpDot((char*)"triTest2.dot");
2215#endif
2216 // render triangle
2217 cmdBuffer.Draw(0, 3, 0, 1);
2218
2219 // finalize recording of the command buffer
2220 cmdBuffer.EndCommandBuffer();
2221 cmdBuffer.QueueCommandBuffer(NULL, 0);
2222
2223 for (int i = 0; i < m_renderTargetCount; i++)
2224 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002225
2226}
2227
2228TEST_F(XglRenderTest, TriangleVSUniformBlock)
2229{
2230 // The expected result from this test is a blue triangle
2231
2232 static const char *vertShaderText =
2233 "#version 140\n"
2234 "#extension GL_ARB_separate_shader_objects : enable\n"
2235 "#extension GL_ARB_shading_language_420pack : enable\n"
2236 "layout (location = 0) out vec4 outColor;\n"
2237 "layout (std140, binding = 0) uniform bufferVals {\n"
2238 " vec4 red;\n"
2239 " vec4 green;\n"
2240 " vec4 blue;\n"
2241 " vec4 white;\n"
2242 "} myBufferVals;\n"
2243 "void main() {\n"
2244 " vec2 vertices[3];"
2245 " vertices[0] = vec2(-0.5, -0.5);\n"
2246 " vertices[1] = vec2( 0.5, -0.5);\n"
2247 " vertices[2] = vec2( 0.5, 0.5);\n"
2248 " outColor = myBufferVals.blue;\n"
2249 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2250 "}\n";
2251
2252 static const char *fragShaderText =
2253 "#version 140\n"
2254 "#extension GL_ARB_separate_shader_objects : enable\n"
2255 "#extension GL_ARB_shading_language_420pack : enable\n"
2256 "layout (location = 0) in vec4 inColor;\n"
2257 "void main() {\n"
2258 " gl_FragColor = inColor;\n"
2259 "}\n";
2260
2261 ASSERT_NO_FATAL_FAILURE(InitState());
2262 ASSERT_NO_FATAL_FAILURE(InitViewport());
2263
2264 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2265 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2266
2267 // Let's populate our buffer with the following:
2268 // vec4 red;
2269 // vec4 green;
2270 // vec4 blue;
2271 // vec4 white;
2272 const int valCount = 4 * 4;
2273 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2274 0.0, 1.0, 0.0, 1.0,
2275 0.0, 0.0, 1.0, 1.0,
2276 1.0, 1.0, 1.0, 1.0 };
2277
2278 XglConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002279
2280 XglPipelineObj pipelineobj(m_device);
2281 pipelineobj.AddShader(&vs);
2282 pipelineobj.AddShader(&ps);
2283
2284 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002285 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002286
Tony Barbourdd4c9642015-01-09 12:55:14 -07002287 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2288 XglCommandBufferObj cmdBuffer(m_device);
2289 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2290
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002291 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002292
2293 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2294
2295#ifdef DUMP_STATE_DOT
2296 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2297 pDSDumpDot((char*)"triTest2.dot");
2298#endif
2299 // render triangle
2300 cmdBuffer.Draw(0, 3, 0, 1);
2301
2302 // finalize recording of the command buffer
2303 cmdBuffer.EndCommandBuffer();
2304 cmdBuffer.QueueCommandBuffer(NULL, 0);
2305
2306 for (int i = 0; i < m_renderTargetCount; i++)
2307 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002308
2309}
2310
2311TEST_F(XglRenderTest, TriangleFSUniformBlockBinding)
2312{
2313 // This test allows the shader to select which buffer it is
2314 // pulling from using layout binding qualifier.
2315 // There are corresponding changes in the compiler stack that
2316 // will select the buffer using binding directly.
2317 // The binding number should match the slot number set up by
2318 // the application.
2319 // The expected result from this test is a purple triangle
2320
2321 static const char *vertShaderText =
2322 "#version 140\n"
2323 "#extension GL_ARB_separate_shader_objects : enable\n"
2324 "#extension GL_ARB_shading_language_420pack : enable\n"
2325 "void main() {\n"
2326 " vec2 vertices[3];"
2327 " vertices[0] = vec2(-0.5, -0.5);\n"
2328 " vertices[1] = vec2( 0.5, -0.5);\n"
2329 " vertices[2] = vec2( 0.5, 0.5);\n"
2330 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2331 "}\n";
2332
2333 static const char *fragShaderText =
2334 "#version 140\n"
2335 "#extension GL_ARB_separate_shader_objects : enable\n"
2336 "#extension GL_ARB_shading_language_420pack : enable\n"
2337 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2338 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2339 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002340 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
Tony Barbourf43b6982014-11-25 13:18:32 -07002341 "void main() {\n"
2342 " gl_FragColor = myBlueVal.color;\n"
2343 " gl_FragColor += myRedVal.color;\n"
2344 "}\n";
2345
2346 ASSERT_NO_FATAL_FAILURE(InitState());
2347 ASSERT_NO_FATAL_FAILURE(InitViewport());
2348
2349 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2350 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2351
2352 // We're going to create a number of uniform buffers, and then allow
2353 // the shader to select which it wants to read from with a binding
2354
2355 // Let's populate the buffers with a single color each:
2356 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2357 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2358 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002359 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002360
2361 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2362 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2363 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2364 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2365
2366 const int redCount = sizeof(redVals) / sizeof(float);
2367 const int greenCount = sizeof(greenVals) / sizeof(float);
2368 const int blueCount = sizeof(blueVals) / sizeof(float);
2369 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2370
2371 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002372
2373 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002374
2375 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002376
2377 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002378
2379 XglPipelineObj pipelineobj(m_device);
2380 pipelineobj.AddShader(&vs);
2381 pipelineobj.AddShader(&ps);
2382
2383 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002384 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2385 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2386 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2387 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002388
Tony Barbourdd4c9642015-01-09 12:55:14 -07002389 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2390 XglCommandBufferObj cmdBuffer(m_device);
2391 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002392
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002393 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002394
2395 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2396
2397#ifdef DUMP_STATE_DOT
2398 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2399 pDSDumpDot((char*)"triTest2.dot");
2400#endif
2401 // render triangle
2402 cmdBuffer.Draw(0, 3, 0, 1);
2403
2404 // finalize recording of the command buffer
2405 cmdBuffer.EndCommandBuffer();
2406 cmdBuffer.QueueCommandBuffer(NULL, 0);
2407
2408 for (int i = 0; i < m_renderTargetCount; i++)
2409 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002410}
2411
2412TEST_F(XglRenderTest, TriangleFSAnonymousUniformBlockBinding)
2413{
2414 // This test is the same as TriangleFSUniformBlockBinding, but
2415 // it does not provide an instance name.
2416 // The expected result from this test is a purple triangle
2417
2418 static const char *vertShaderText =
2419 "#version 140\n"
2420 "#extension GL_ARB_separate_shader_objects : enable\n"
2421 "#extension GL_ARB_shading_language_420pack : enable\n"
2422 "void main() {\n"
2423 " vec2 vertices[3];"
2424 " vertices[0] = vec2(-0.5, -0.5);\n"
2425 " vertices[1] = vec2( 0.5, -0.5);\n"
2426 " vertices[2] = vec2( 0.5, 0.5);\n"
2427 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2428 "}\n";
2429
2430 static const char *fragShaderText =
2431 "#version 430\n"
2432 "#extension GL_ARB_separate_shader_objects : enable\n"
2433 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002434 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2435 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2436 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002437 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002438 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002439 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002440 " outColor = blue;\n"
2441 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002442 "}\n";
2443 ASSERT_NO_FATAL_FAILURE(InitState());
2444 ASSERT_NO_FATAL_FAILURE(InitViewport());
2445
2446 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2447 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2448
2449 // We're going to create a number of uniform buffers, and then allow
2450 // the shader to select which it wants to read from with a binding
2451
2452 // Let's populate the buffers with a single color each:
2453 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2454 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2455 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2456 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2457
2458 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2459 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2460 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2461 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2462
2463 const int redCount = sizeof(redVals) / sizeof(float);
2464 const int greenCount = sizeof(greenVals) / sizeof(float);
2465 const int blueCount = sizeof(blueVals) / sizeof(float);
2466 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2467
2468 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002469
2470 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002471
2472 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002473
2474 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002475
2476 XglPipelineObj pipelineobj(m_device);
2477 pipelineobj.AddShader(&vs);
2478 pipelineobj.AddShader(&ps);
2479
2480 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002481 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2482 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2483 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2484 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002485
Tony Barbourdd4c9642015-01-09 12:55:14 -07002486 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2487 XglCommandBufferObj cmdBuffer(m_device);
2488 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2489
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002490 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002491
2492 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2493
2494#ifdef DUMP_STATE_DOT
2495 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2496 pDSDumpDot((char*)"triTest2.dot");
2497#endif
2498 // render triangle
2499 cmdBuffer.Draw(0, 3, 0, 1);
2500
2501 // finalize recording of the command buffer
2502 cmdBuffer.EndCommandBuffer();
2503 cmdBuffer.QueueCommandBuffer(NULL, 0);
2504
2505 for (int i = 0; i < m_renderTargetCount; i++)
2506 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002507
2508}
2509
2510TEST_F(XglRenderTest, CubeWithVertexFetchAndMVPAndTexture)
2511{
2512 static const char *vertShaderText =
2513 "#version 140\n"
2514 "#extension GL_ARB_separate_shader_objects : enable\n"
2515 "#extension GL_ARB_shading_language_420pack : enable\n"
2516 "layout (std140, binding=0) uniform bufferVals {\n"
2517 " mat4 mvp;\n"
2518 "} myBufferVals;\n"
2519 "layout (location=0) in vec4 pos;\n"
2520 "layout (location=0) out vec2 UV;\n"
2521 "void main() {\n"
2522 " vec2 positions[3];"
2523 " positions[0] = vec2( 0.0, 0.0);\n"
2524 " positions[1] = vec2( 0.25, 0.1);\n"
2525 " positions[2] = vec2( 0.1, 0.25);\n"
2526 " UV = positions[gl_VertexID % 3];\n"
2527 " gl_Position = myBufferVals.mvp * pos;\n"
2528 "}\n";
2529
2530 static const char *fragShaderText =
2531 "#version 140\n"
2532 "#extension GL_ARB_separate_shader_objects : enable\n"
2533 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002534 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002535 "layout (location=0) out vec4 outColor;\n"
2536 "layout (location=0) in vec2 UV;\n"
2537 "void main() {\n"
2538 " outColor= textureLod(surface, UV, 0.0);\n"
2539 "}\n";
2540 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2541
2542 glm::mat4 View = glm::lookAt(
2543 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2544 glm::vec3(0,0,0), // and looks at the origin
2545 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2546 );
2547
2548 glm::mat4 Model = glm::mat4(1.0f);
2549
2550 glm::mat4 MVP = Projection * View * Model;
2551
2552
2553 ASSERT_NO_FATAL_FAILURE(InitState());
2554 ASSERT_NO_FATAL_FAILURE(InitViewport());
2555 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
2556
2557 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
2558 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002559 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002560
2561 const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT);
2562
2563 XglConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2564 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2565 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2566 XglSamplerObj sampler(m_device);
2567 XglTextureObj texture(m_device);
2568
Tony Barbourf43b6982014-11-25 13:18:32 -07002569 XglPipelineObj pipelineobj(m_device);
2570 pipelineobj.AddShader(&vs);
2571 pipelineobj.AddShader(&ps);
2572
2573 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002574 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mvpBuffer);
2575 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002576
2577 m_memoryRefManager.AddMemoryRef(&meshBuffer);
2578 m_memoryRefManager.AddMemoryRef(&mvpBuffer);
2579 m_memoryRefManager.AddMemoryRef(&texture);
2580
2581 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
2582 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
2583 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
2584 };
2585
2586 // this is the current description of g_vbData
2587 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
2588 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
2589 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
2590 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
2591 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2592 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
2593 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
2594 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
2595 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
2596
2597 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2598 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
2599 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
2600
Tony Barbourfa6cac72015-01-16 14:27:35 -07002601 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
2602 ds_state.depthTestEnable = XGL_TRUE;
2603 ds_state.depthWriteEnable = XGL_TRUE;
2604 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
2605 ds_state.depthBoundsEnable = XGL_FALSE;
2606 ds_state.stencilTestEnable = XGL_FALSE;
2607 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
2608 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
2609 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
2610 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
2611 ds_state.format.channelFormat = XGL_CH_FMT_R32;
2612 ds_state.format.numericFormat = XGL_NUM_FMT_DS;
2613 ds_state.front = ds_state.back;
2614 pipelineobj.SetDepthStencil(&ds_state);
2615
Tony Barbourdd4c9642015-01-09 12:55:14 -07002616 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2617 XglCommandBufferObj cmdBuffer(m_device);
2618 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002619
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002620 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002621 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2622
2623 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2624#ifdef DUMP_STATE_DOT
2625 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2626 pDSDumpDot((char*)"triTest2.dot");
2627#endif
2628 // render triangle
2629 cmdBuffer.Draw(0, 36, 0, 1);
2630
2631 // finalize recording of the command buffer
2632 cmdBuffer.EndCommandBuffer();
2633 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
2634
2635 for (int i = 0; i < m_renderTargetCount; i++)
2636 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002637
2638}
Cody Northropd1ce7842014-12-09 11:17:01 -07002639
2640TEST_F(XglRenderTest, TriangleMixedSamplerUniformBlockBinding)
2641{
2642 // This test mixes binding slots of textures and buffers, ensuring
2643 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002644 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002645 // you can modify it to move the desired result around.
2646
2647 static const char *vertShaderText =
2648 "#version 140\n"
2649 "#extension GL_ARB_separate_shader_objects : enable\n"
2650 "#extension GL_ARB_shading_language_420pack : enable\n"
2651 "void main() {\n"
2652 " vec2 vertices[3];"
2653 " vertices[0] = vec2(-0.5, -0.5);\n"
2654 " vertices[1] = vec2( 0.5, -0.5);\n"
2655 " vertices[2] = vec2( 0.5, 0.5);\n"
2656 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2657 "}\n";
2658
2659 static const char *fragShaderText =
2660 "#version 430\n"
2661 "#extension GL_ARB_separate_shader_objects : enable\n"
2662 "#extension GL_ARB_shading_language_420pack : enable\n"
2663 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002664 "layout (binding = 3) uniform sampler2D surface1;\n"
2665 "layout (binding = 1) uniform sampler2D surface2;\n"
2666 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002667
Cody Northropa0410942014-12-09 13:59:39 -07002668
Chia-I Wuf8385062015-01-04 16:27:24 +08002669 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2670 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2671 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2672 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002673 "layout (location = 0) out vec4 outColor;\n"
2674 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002675 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002676 " outColor += white * vec4(0.00001);\n"
2677 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002678 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002679 "}\n";
2680 ASSERT_NO_FATAL_FAILURE(InitState());
2681 ASSERT_NO_FATAL_FAILURE(InitViewport());
2682
2683 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2684 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2685
Cody Northropd1ce7842014-12-09 11:17:01 -07002686 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2687 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2688 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2689 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2690
2691 const int redCount = sizeof(redVals) / sizeof(float);
2692 const int greenCount = sizeof(greenVals) / sizeof(float);
2693 const int blueCount = sizeof(blueVals) / sizeof(float);
2694 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2695
2696 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002697 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002698 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002699 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002700
2701 XglSamplerObj sampler0(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002702 XglTextureObj texture0(m_device); // Light Red
2703 texture0.ChangeColors(0xff800000,0xff800000);
Cody Northropd1ce7842014-12-09 11:17:01 -07002704 XglSamplerObj sampler2(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002705 XglTextureObj texture2(m_device); // Light Blue
2706 texture2.ChangeColors(0xff000080,0xff000080);
Cody Northropd1ce7842014-12-09 11:17:01 -07002707 XglSamplerObj sampler4(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002708 XglTextureObj texture4(m_device); // Light Green
2709 texture4.ChangeColors(0xff008000,0xff008000);
Cody Northropa0410942014-12-09 13:59:39 -07002710
2711 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2712 // TODO: Get back here ASAP and understand why.
2713 XglSamplerObj sampler7(m_device);
2714 XglTextureObj texture7(m_device); // Red and Blue
2715 texture7.ChangeColors(0xffff00ff,0xffff00ff);
Cody Northropd1ce7842014-12-09 11:17:01 -07002716
2717 XglPipelineObj pipelineobj(m_device);
2718 pipelineobj.AddShader(&vs);
2719 pipelineobj.AddShader(&ps);
2720
2721 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002722 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2723 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2724 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2725 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2726 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2727 // swap blue and green
2728 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2729 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2730 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002731
2732 m_memoryRefManager.AddMemoryRef(&texture0);
2733 m_memoryRefManager.AddMemoryRef(&texture2);
2734 m_memoryRefManager.AddMemoryRef(&texture4);
Cody Northropa0410942014-12-09 13:59:39 -07002735 m_memoryRefManager.AddMemoryRef(&texture7);
Cody Northropd1ce7842014-12-09 11:17:01 -07002736
Tony Barbourdd4c9642015-01-09 12:55:14 -07002737 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2738 XglCommandBufferObj cmdBuffer(m_device);
2739 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002740
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002741 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002742
2743 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2744
2745#ifdef DUMP_STATE_DOT
2746 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2747 pDSDumpDot((char*)"triTest2.dot");
2748#endif
2749 // render triangle
2750 cmdBuffer.Draw(0, 3, 0, 1);
2751
2752 // finalize recording of the command buffer
2753 cmdBuffer.EndCommandBuffer();
2754 cmdBuffer.QueueCommandBuffer(NULL, 0);
2755
2756 for (int i = 0; i < m_renderTargetCount; i++)
2757 RecordImage(m_renderTargets[i]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002758
2759}
2760
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002761TEST_F(XglRenderTest, TriangleMatchingSamplerUniformBlockBinding)
2762{
2763 // This test matches binding slots of textures and buffers, requiring
2764 // the driver to give them distinct number spaces.
2765 // The expected result from this test is a red triangle, although
2766 // you can modify it to move the desired result around.
2767
2768 static const char *vertShaderText =
2769 "#version 140\n"
2770 "#extension GL_ARB_separate_shader_objects : enable\n"
2771 "#extension GL_ARB_shading_language_420pack : enable\n"
2772 "void main() {\n"
2773 " vec2 vertices[3];"
2774 " vertices[0] = vec2(-0.5, -0.5);\n"
2775 " vertices[1] = vec2( 0.5, -0.5);\n"
2776 " vertices[2] = vec2( 0.5, 0.5);\n"
2777 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2778 "}\n";
2779
2780 static const char *fragShaderText =
2781 "#version 430\n"
2782 "#extension GL_ARB_separate_shader_objects : enable\n"
2783 "#extension GL_ARB_shading_language_420pack : enable\n"
2784 "layout (binding = 0) uniform sampler2D surface0;\n"
2785 "layout (binding = 1) uniform sampler2D surface1;\n"
2786 "layout (binding = 2) uniform sampler2D surface2;\n"
2787 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002788 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2789 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2790 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2791 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002792 "layout (location = 0) out vec4 outColor;\n"
2793 "void main() {\n"
2794 " outColor = red;// * vec4(0.00001);\n"
2795 " outColor += white * vec4(0.00001);\n"
2796 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2797 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2798 "}\n";
2799 ASSERT_NO_FATAL_FAILURE(InitState());
2800 ASSERT_NO_FATAL_FAILURE(InitViewport());
2801
2802 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2803 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2804
2805 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2806 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2807 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2808 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2809
2810 const int redCount = sizeof(redVals) / sizeof(float);
2811 const int greenCount = sizeof(greenVals) / sizeof(float);
2812 const int blueCount = sizeof(blueVals) / sizeof(float);
2813 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2814
2815 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002816 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002817 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002818 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002819
2820 XglSamplerObj sampler0(m_device);
2821 XglTextureObj texture0(m_device); // Light Red
2822 texture0.ChangeColors(0xff800000,0xff800000);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002823 XglSamplerObj sampler2(m_device);
2824 XglTextureObj texture2(m_device); // Light Blue
2825 texture2.ChangeColors(0xff000080,0xff000080);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002826 XglSamplerObj sampler4(m_device);
2827 XglTextureObj texture4(m_device); // Light Green
2828 texture4.ChangeColors(0xff008000,0xff008000);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002829 XglSamplerObj sampler7(m_device);
2830 XglTextureObj texture7(m_device); // Red and Blue
2831 texture7.ChangeColors(0xffff00ff,0xffff00ff);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002832
2833
2834 XglPipelineObj pipelineobj(m_device);
2835 pipelineobj.AddShader(&vs);
2836 pipelineobj.AddShader(&ps);
2837
2838 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002839 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2840 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2841 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2842 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2843 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2844 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2845 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2846 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002847
2848 m_memoryRefManager.AddMemoryRef(&texture0);
2849 m_memoryRefManager.AddMemoryRef(&texture2);
2850 m_memoryRefManager.AddMemoryRef(&texture4);
2851 m_memoryRefManager.AddMemoryRef(&texture7);
2852
Tony Barbourdd4c9642015-01-09 12:55:14 -07002853 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2854 XglCommandBufferObj cmdBuffer(m_device);
2855 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002856
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002857 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002858
2859 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2860
2861#ifdef DUMP_STATE_DOT
2862 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2863 pDSDumpDot((char*)"triTest2.dot");
2864#endif
2865 // render triangle
2866 cmdBuffer.Draw(0, 3, 0, 1);
2867
2868 // finalize recording of the command buffer
2869 cmdBuffer.EndCommandBuffer();
2870 cmdBuffer.QueueCommandBuffer(NULL, 0);
2871
2872 for (int i = 0; i < m_renderTargetCount; i++)
2873 RecordImage(m_renderTargets[i]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002874
2875}
2876
Cody Northrop02690bd2014-12-17 15:26:33 -07002877TEST_F(XglRenderTest, TriangleUniformBufferLayout)
2878{
2879 // This test populates a buffer with a variety of different data
2880 // types, then reads them out with a shader.
2881 // The expected result from this test is a green triangle
2882
2883 static const char *vertShaderText =
2884 "#version 140\n"
2885 "#extension GL_ARB_separate_shader_objects : enable\n"
2886 "#extension GL_ARB_shading_language_420pack : enable\n"
2887 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2888 " vec4 fRed;\n"
2889 " vec4 fGreen;\n"
2890 " layout(row_major) mat4 worldToProj;\n"
2891 " layout(row_major) mat4 projToWorld;\n"
2892 " layout(row_major) mat4 worldToView;\n"
2893 " layout(row_major) mat4 viewToProj;\n"
2894 " layout(row_major) mat4 worldToShadow[4];\n"
2895 " float fZero;\n"
2896 " float fOne;\n"
2897 " float fTwo;\n"
2898 " float fThree;\n"
2899 " vec3 fZeroZeroZero;\n"
2900 " float fFour;\n"
2901 " vec3 fZeroZeroOne;\n"
2902 " float fFive;\n"
2903 " vec3 fZeroOneZero;\n"
2904 " float fSix;\n"
2905 " float fSeven;\n"
2906 " float fEight;\n"
2907 " float fNine;\n"
2908 " vec2 fZeroZero;\n"
2909 " vec2 fZeroOne;\n"
2910 " vec4 fBlue;\n"
2911 " vec2 fOneZero;\n"
2912 " vec2 fOneOne;\n"
2913 " vec3 fZeroOneOne;\n"
2914 " float fTen;\n"
2915 " float fEleven;\n"
2916 " float fTwelve;\n"
2917 " vec3 fOneZeroZero;\n"
2918 " vec4 uvOffsets[4];\n"
2919 "};\n"
2920 "layout (location = 0) out vec4 color;"
2921 "void main() {\n"
2922
2923 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2924 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2925 " \n"
2926
2927 // do some exact comparisons, even though we should
2928 // really have an epsilon involved.
2929 " vec4 outColor = right;\n"
2930 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
2931 " outColor = wrong;\n"
2932 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
2933 " outColor = wrong;\n"
2934 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
2935 " outColor = wrong;\n"
2936
2937 " color = outColor;\n"
2938
2939 // generic position stuff
2940 " vec2 vertices;\n"
2941 " int vertexSelector = gl_VertexID;\n"
2942 " if (vertexSelector == 0)\n"
2943 " vertices = vec2(-0.5, -0.5);\n"
2944 " else if (vertexSelector == 1)\n"
2945 " vertices = vec2( 0.5, -0.5);\n"
2946 " else if (vertexSelector == 2)\n"
2947 " vertices = vec2( 0.5, 0.5);\n"
2948 " else\n"
2949 " vertices = vec2( 0.0, 0.0);\n"
2950 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
2951 "}\n";
2952
2953 static const char *fragShaderText =
2954 "#version 140\n"
2955 "#extension GL_ARB_separate_shader_objects : enable\n"
2956 "#extension GL_ARB_shading_language_420pack : enable\n"
2957 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2958 " vec4 fRed;\n"
2959 " vec4 fGreen;\n"
2960 " layout(row_major) mat4 worldToProj;\n"
2961 " layout(row_major) mat4 projToWorld;\n"
2962 " layout(row_major) mat4 worldToView;\n"
2963 " layout(row_major) mat4 viewToProj;\n"
2964 " layout(row_major) mat4 worldToShadow[4];\n"
2965 " float fZero;\n"
2966 " float fOne;\n"
2967 " float fTwo;\n"
2968 " float fThree;\n"
2969 " vec3 fZeroZeroZero;\n"
2970 " float fFour;\n"
2971 " vec3 fZeroZeroOne;\n"
2972 " float fFive;\n"
2973 " vec3 fZeroOneZero;\n"
2974 " float fSix;\n"
2975 " float fSeven;\n"
2976 " float fEight;\n"
2977 " float fNine;\n"
2978 " vec2 fZeroZero;\n"
2979 " vec2 fZeroOne;\n"
2980 " vec4 fBlue;\n"
2981 " vec2 fOneZero;\n"
2982 " vec2 fOneOne;\n"
2983 " vec3 fZeroOneOne;\n"
2984 " float fTen;\n"
2985 " float fEleven;\n"
2986 " float fTwelve;\n"
2987 " vec3 fOneZeroZero;\n"
2988 " vec4 uvOffsets[4];\n"
2989 "};\n"
2990 "layout (location = 0) in vec4 color;\n"
2991 "void main() {\n"
2992 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2993 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2994 " \n"
2995
2996 // start with VS value to ensure it passed
2997 " vec4 outColor = color;\n"
2998
2999 // do some exact comparisons, even though we should
3000 // really have an epsilon involved.
3001 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3002 " outColor = wrong;\n"
3003 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3004 " outColor = wrong;\n"
3005 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3006 " outColor = wrong;\n"
3007 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3008 " outColor = wrong;\n"
3009 " if (fTwo != 2.0)\n"
3010 " outColor = wrong;\n"
3011 " if (fOneOne != vec2(1.0, 1.0))\n"
3012 " outColor = wrong;\n"
3013 " if (fTen != 10.0)\n"
3014 " outColor = wrong;\n"
3015 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3016 " outColor = wrong;\n"
3017 " \n"
3018 " gl_FragColor = outColor;\n"
3019 "}\n";
3020
3021
3022 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3023 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3024 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3025 0.0, 1.0, 0.0, 1.0, // align
3026 0.0, 0.0, 1.0, 1.0, // align
3027 0.0, 0.0, 0.0, 1.0, // align
3028 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3029 0.0, 2.0, 0.0, 2.0, // align
3030 0.0, 0.0, 2.0, 2.0, // align
3031 0.0, 0.0, 0.0, 2.0, // align
3032 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3033 0.0, 3.0, 0.0, 3.0, // align
3034 0.0, 0.0, 3.0, 3.0, // align
3035 0.0, 0.0, 0.0, 3.0, // align
3036 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3037 0.0, 4.0, 0.0, 4.0, // align
3038 0.0, 0.0, 4.0, 4.0, // align
3039 0.0, 0.0, 0.0, 4.0, // align
3040 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3041 0.0, 5.0, 0.0, 5.0, // align
3042 0.0, 0.0, 5.0, 5.0, // align
3043 0.0, 0.0, 0.0, 5.0, // align
3044 6.0, 0.0, 0.0, 6.0, // align
3045 0.0, 6.0, 0.0, 6.0, // align
3046 0.0, 0.0, 6.0, 6.0, // align
3047 0.0, 0.0, 0.0, 6.0, // align
3048 7.0, 0.0, 0.0, 7.0, // align
3049 0.0, 7.0, 0.0, 7.0, // align
3050 0.0, 0.0, 7.0, 7.0, // align
3051 0.0, 0.0, 0.0, 7.0, // align
3052 8.0, 0.0, 0.0, 8.0, // align
3053 0.0, 8.0, 0.0, 8.0, // align
3054 0.0, 0.0, 8.0, 8.0, // align
3055 0.0, 0.0, 0.0, 8.0, // align
3056 0.0, // float fZero; // align
3057 1.0, // float fOne; // pack
3058 2.0, // float fTwo; // pack
3059 3.0, // float fThree; // pack
3060 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3061 4.0, // float fFour; // pack
3062 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3063 5.0, // float fFive; // pack
3064 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3065 6.0, // float fSix; // pack
3066 7.0, // float fSeven; // align
3067 8.0, // float fEight; // pack
3068 9.0, // float fNine; // pack
3069 0.0, // BUFFER
3070 0.0, 0.0, // vec2 fZeroZero; // align
3071 0.0, 1.0, // vec2 fZeroOne; // pack
3072 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3073 1.0, 0.0, // vec2 fOneZero; // align
3074 1.0, 1.0, // vec2 fOneOne; // pack
3075 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3076 10.0, // float fTen; // pack
3077 11.0, // float fEleven; // align
3078 12.0, // float fTwelve; // pack
3079 0.0, 0.0, // BUFFER
3080 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3081 0.0, // BUFFER
3082 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3083 0.5, 0.6, 0.7, 0.8, // align
3084 0.9, 1.0, 1.1, 1.2, // align
3085 1.3, 1.4, 1.5, 1.6, // align
3086 };
3087
3088 ASSERT_NO_FATAL_FAILURE(InitState());
3089 ASSERT_NO_FATAL_FAILURE(InitViewport());
3090
3091 const int constCount = sizeof(mixedVals) / sizeof(float);
3092
3093 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
3094 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
3095
3096 XglConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003097
3098 XglPipelineObj pipelineobj(m_device);
3099 pipelineobj.AddShader(&vs);
3100 pipelineobj.AddShader(&ps);
3101
3102 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08003103 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003104
3105 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3106 XglCommandBufferObj cmdBuffer(m_device);
3107 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3108
Jeremy Hayese0c3b222015-01-14 16:17:08 -07003109 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Cody Northrop02690bd2014-12-17 15:26:33 -07003110
3111 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
3112
3113#ifdef DUMP_STATE_DOT
3114 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
3115 pDSDumpDot((char*)"triTest2.dot");
3116#endif
3117 // render triangle
3118 cmdBuffer.Draw(0, 3, 0, 1);
3119
3120 // finalize recording of the command buffer
3121 cmdBuffer.EndCommandBuffer();
3122 cmdBuffer.QueueCommandBuffer(NULL, 0);
3123
3124 for (int i = 0; i < m_renderTargetCount; i++)
3125 RecordImage(m_renderTargets[i]);
3126}
3127
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003128int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003129 int result;
3130
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003131 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003132 XglTestFramework::InitArgs(&argc, argv);
3133
Chia-I Wu7133fdc2014-12-15 23:57:34 +08003134 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06003135
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003136 result = RUN_ALL_TESTS();
3137
3138 XglTestFramework::Finish();
3139 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003140}