blob: e98e62a1ac557c35cb16664541b0c909306ccf2b [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;
366 mem_alloc.alignment = 0;
367 mem_alloc.flags = 0;
368 mem_alloc.heapCount = 0;
369 mem_alloc.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
370
371 /* create image */
372 err = xglCreateImage(device(), &image,
373 &m_depthStencilImage);
374 ASSERT_XGL_SUCCESS(err);
375
376 err = xglGetObjectInfo(m_depthStencilImage,
Jon Ashburna9ae3832015-01-16 09:37:43 -0700377 XGL_INFO_TYPE_MEMORY_ALLOCATION_COUNT,
378 &num_alloc_size, &num_allocations);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600379 ASSERT_XGL_SUCCESS(err);
Jon Ashburna9ae3832015-01-16 09:37:43 -0700380 ASSERT_EQ(num_alloc_size, sizeof(num_allocations));
381 mem_reqs = (XGL_MEMORY_REQUIREMENTS *) malloc(num_allocations * sizeof(XGL_MEMORY_REQUIREMENTS));
382 m_depthStencilMem = (XGL_GPU_MEMORY *) malloc(num_allocations * sizeof(XGL_GPU_MEMORY));
383 m_num_mem = num_allocations;
384 err = xglGetObjectInfo(m_depthStencilImage,
385 XGL_INFO_TYPE_MEMORY_REQUIREMENTS,
386 &mem_reqs_size, mem_reqs);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600387 ASSERT_XGL_SUCCESS(err);
Jon Ashburna9ae3832015-01-16 09:37:43 -0700388 ASSERT_EQ(mem_reqs_size, sizeof(*mem_reqs));
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700389 err = xglGetObjectInfo(m_depthStencilImage,
390 XGL_INFO_TYPE_IMAGE_MEMORY_REQUIREMENTS,
391 &img_reqs_size, &img_reqs);
392 ASSERT_XGL_SUCCESS(err);
393 ASSERT_EQ(img_reqs_size, sizeof(XGL_IMAGE_MEMORY_REQUIREMENTS));
394 img_alloc.usage = img_reqs.usage;
395 img_alloc.formatClass = img_reqs.formatClass;
396 img_alloc.samples = img_reqs.samples;
Jon Ashburna9ae3832015-01-16 09:37:43 -0700397 for (XGL_UINT i = 0; i < num_allocations; i ++) {
398 mem_alloc.allocationSize = mem_reqs[i].size;
399 mem_alloc.alignment = mem_reqs[i].alignment;
400 mem_alloc.heapCount = mem_reqs[i].heapCount;
401 XGL_UINT heapInfo[mem_reqs[i].heapCount];
402 mem_alloc.pHeaps = heapInfo;
403 memcpy(heapInfo, mem_reqs[i].pHeaps,
404 sizeof(mem_reqs[i].pHeaps[0]) * mem_reqs[i].heapCount);
405
406 /* allocate memory */
407 err = xglAllocMemory(device(), &mem_alloc, &m_depthStencilMem[i]);
408 ASSERT_XGL_SUCCESS(err);
409
410 /* bind memory */
411 err = xglBindObjectMemory(m_depthStencilImage, i,
412 m_depthStencilMem[i], 0);
413 ASSERT_XGL_SUCCESS(err);
414 }
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600415
Tony Barbourfa6cac72015-01-16 14:27:35 -0700416 XGL_DYNAMIC_DS_STATE_CREATE_INFO depthStencil = {};
417 depthStencil.sType = XGL_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO;
418
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600419 depthStencil.minDepth = 0.f;
420 depthStencil.maxDepth = 1.f;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700421 depthStencil.stencilBackRef = 0;
422 depthStencil.stencilFrontRef = 0;
423 depthStencil.stencilReadMask = 0xff;
424 depthStencil.stencilWriteMask = 0xff;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600425
Tony Barbourfa6cac72015-01-16 14:27:35 -0700426 err = xglCreateDynamicDepthStencilState( device(), &depthStencil, &m_stateDepthStencil );
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600427 ASSERT_XGL_SUCCESS( err );
428
429 /* create image view */
430 view.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO;
431 view.pNext = NULL;
432 view.image = XGL_NULL_HANDLE;
433 view.mipLevel = 0;
434 view.baseArraySlice = 0;
435 view.arraySize = 1;
436 view.flags = 0;
437 view.image = m_depthStencilImage;
438 err = xglCreateDepthStencilView(device(), &view, &m_depthStencilView);
439 ASSERT_XGL_SUCCESS(err);
440
441 m_depthStencilBinding.view = m_depthStencilView;
Mike Stroyan55658c22014-12-04 11:08:39 +0000442 m_depthStencilBinding.layout = XGL_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600443}
444
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600445struct xgltriangle_vs_uniform {
446 // Must start with MVP
447 XGL_FLOAT mvp[4][4];
448 XGL_FLOAT position[3][4];
449 XGL_FLOAT color[3][4];
450};
451
Tony Barbourae442072015-01-12 13:27:11 -0700452void XglRenderTest::XGLTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600453{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700454#ifdef DEBUG_CALLBACK
455 xglDbgRegisterMsgCallback(myDbgFunc, NULL);
456#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600457 // Create identity matrix
458 int i;
459 struct xgltriangle_vs_uniform data;
460
461 glm::mat4 Projection = glm::mat4(1.0f);
462 glm::mat4 View = glm::mat4(1.0f);
463 glm::mat4 Model = glm::mat4(1.0f);
464 glm::mat4 MVP = Projection * View * Model;
465 const int matrixSize = sizeof(MVP);
466 const int bufSize = sizeof(xgltriangle_vs_uniform) / sizeof(XGL_FLOAT);
467 memcpy(&data.mvp, &MVP[0][0], matrixSize);
468
469 static const Vertex tri_data[] =
470 {
471 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
472 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
473 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
474 };
475
476 for (i=0; i<3; i++) {
477 data.position[i][0] = tri_data[i].posX;
478 data.position[i][1] = tri_data[i].posY;
479 data.position[i][2] = tri_data[i].posZ;
480 data.position[i][3] = tri_data[i].posW;
481 data.color[i][0] = tri_data[i].r;
482 data.color[i][1] = tri_data[i].g;
483 data.color[i][2] = tri_data[i].b;
484 data.color[i][3] = tri_data[i].a;
485 }
486
Tony Barbourf43b6982014-11-25 13:18:32 -0700487 ASSERT_NO_FATAL_FAILURE(InitState());
488 ASSERT_NO_FATAL_FAILURE(InitViewport());
489
490 XglConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(XGL_FLOAT), (const void*) &data);
491
492 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
493 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700494
495 XglPipelineObj pipelineobj(m_device);
496 pipelineobj.AddShader(&vs);
497 pipelineobj.AddShader(&ps);
498
499 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +0800500 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700501 m_memoryRefManager.AddMemoryRef(&constantBuffer);
502
Tony Barbour71ba3612015-01-09 16:12:35 -0700503 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
504 XglCommandBufferObj cmdBuffer(m_device);
505 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700506
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700507 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour71ba3612015-01-09 16:12:35 -0700508
509 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
510
511 cmdBuffer.BindVertexBuffer(&constantBuffer, 0, 0);
512#ifdef DUMP_STATE_DOT
513 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
514 pDSDumpDot((char*)"triTest2.dot");
515#endif
516 // render triangle
517 cmdBuffer.Draw(0, 3, 0, 1);
518
519 // finalize recording of the command buffer
520 cmdBuffer.EndCommandBuffer();
521 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
522
523 for (int i = 0; i < m_renderTargetCount; i++)
524 RecordImage(m_renderTargets[i]);
525
526 if (rotate)
527 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
528
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700529#ifdef PRINT_OBJECTS
530 //XGL_UINT64 objTrackGetObjectCount(XGL_OBJECT_TYPE type)
531 OBJ_TRACK_GET_OBJECT_COUNT pObjTrackGetObjectCount = (OBJ_TRACK_GET_OBJECT_COUNT)xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjectCount");
532 XGL_UINT64 numObjects = pObjTrackGetObjectCount(XGL_OBJECT_TYPE_ANY);
533 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjects");
534 printf("DEBUG : Number of Objects : %lu\n", numObjects);
535 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjects");
536 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
537 pObjTrackGetObjs(XGL_OBJECT_TYPE_ANY, numObjects, pObjNodeArray);
538 for (i=0; i < numObjects; i++) {
539 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);
540 }
541 free(pObjNodeArray);
542#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700543
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600544}
545
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600546TEST_F(XglRenderTest, XGLTriangle_FragColor)
547{
548 static const char *vertShaderText =
549 "#version 140\n"
550 "#extension GL_ARB_separate_shader_objects : enable\n"
551 "#extension GL_ARB_shading_language_420pack : enable\n"
552 "\n"
553 "layout(binding = 0) uniform buf {\n"
554 " mat4 MVP;\n"
555 " vec4 position[3];\n"
556 " vec4 color[3];\n"
557 "} ubuf;\n"
558 "\n"
559 "layout (location = 0) out vec4 outColor;\n"
560 "\n"
561 "void main() \n"
562 "{\n"
563 " outColor = ubuf.color[gl_VertexID];\n"
564 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
565 "}\n";
566
567 static const char *fragShaderText =
568 "#version 140\n"
569 "#extension GL_ARB_separate_shader_objects : enable\n"
570 "#extension GL_ARB_shading_language_420pack : enable\n"
571 "\n"
572 "layout (location = 0) in vec4 inColor;\n"
573 "\n"
574 "void main()\n"
575 "{\n"
576 " gl_FragColor = inColor;\n"
577 "}\n";
578
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600579 TEST_DESCRIPTION("XGL-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
Tony Barbourae442072015-01-12 13:27:11 -0700580 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600581}
582
583TEST_F(XglRenderTest, XGLTriangle_OutputLocation)
584{
585 static const char *vertShaderText =
586 "#version 140\n"
587 "#extension GL_ARB_separate_shader_objects : enable\n"
588 "#extension GL_ARB_shading_language_420pack : enable\n"
589 "\n"
590 "layout(binding = 0) uniform buf {\n"
591 " mat4 MVP;\n"
592 " vec4 position[3];\n"
593 " vec4 color[3];\n"
594 "} ubuf;\n"
595 "\n"
596 "layout (location = 0) out vec4 outColor;\n"
597 "\n"
598 "void main() \n"
599 "{\n"
600 " outColor = ubuf.color[gl_VertexID];\n"
601 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
602 "}\n";
603
604 static const char *fragShaderText =
605 "#version 140\n"
606 "#extension GL_ARB_separate_shader_objects : enable\n"
607 "#extension GL_ARB_shading_language_420pack : enable\n"
608 "\n"
609 "layout (location = 0) in vec4 inColor;\n"
610 "layout (location = 0) out vec4 outColor;\n"
611 "\n"
612 "void main()\n"
613 "{\n"
614 " outColor = inColor;\n"
615 "}\n";
616
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600617 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 -0600618
Tony Barbourae442072015-01-12 13:27:11 -0700619 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600620}
621
Tony Barbourf43b6982014-11-25 13:18:32 -0700622TEST_F(XglRenderTest, BIL_XGLTriangle)
623{
624 bool saved_use_bil = XglTestFramework::m_use_bil;
625
626 static const char *vertShaderText =
627 "#version 140\n"
628 "#extension GL_ARB_separate_shader_objects : enable\n"
629 "#extension GL_ARB_shading_language_420pack : enable\n"
630 "\n"
631 "layout(binding = 0) uniform buf {\n"
632 " mat4 MVP;\n"
633 " vec4 position[3];\n"
634 " vec4 color[3];\n"
635 "} ubuf;\n"
636 "\n"
637 "layout (location = 0) out vec4 outColor;\n"
638 "\n"
639 "void main() \n"
640 "{\n"
641 " outColor = ubuf.color[gl_VertexID];\n"
642 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
643 "}\n";
644
645 static const char *fragShaderText =
646 "#version 140\n"
647 "#extension GL_ARB_separate_shader_objects : enable\n"
648 "#extension GL_ARB_shading_language_420pack : enable\n"
649 "\n"
650 "layout (location = 0) in vec4 inColor;\n"
651 "\n"
652 "void main()\n"
653 "{\n"
654 " gl_FragColor = inColor;\n"
655 "}\n";
656
657 TEST_DESCRIPTION("XGL-style shaders, but force test framework to compile shader to BIL and pass BIL to driver.");
658
659 XglTestFramework::m_use_bil = true;
660
Tony Barbourae442072015-01-12 13:27:11 -0700661 XGLTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700662
663 XglTestFramework::m_use_bil = saved_use_bil;
664}
665
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600666TEST_F(XglRenderTest, GreenTriangle)
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600667{
668 static const char *vertShaderText =
669 "#version 130\n"
670 "vec2 vertices[3];\n"
671 "void main() {\n"
672 " vertices[0] = vec2(-1.0, -1.0);\n"
673 " vertices[1] = vec2( 1.0, -1.0);\n"
674 " vertices[2] = vec2( 0.0, 1.0);\n"
675 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
676 "}\n";
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600677
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600678 static const char *fragShaderText =
679 "#version 130\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600680 "void main() {\n"
Steve K10b32512014-10-10 08:54:29 -0600681 " gl_FragColor = vec4(0,1,0,1);\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600682 "}\n";
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600683
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600684 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
685
Tony Barbourae442072015-01-12 13:27:11 -0700686 XGLTriangleTest(vertShaderText, fragShaderText, false);
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600687}
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600688
Tony Barbourf43b6982014-11-25 13:18:32 -0700689TEST_F(XglRenderTest, BIL_GreenTriangle)
690{
691 bool saved_use_bil = XglTestFramework::m_use_bil;
692
693 static const char *vertShaderText =
694 "#version 130\n"
695 "vec2 vertices[3];\n"
696 "void main() {\n"
697 " vertices[0] = vec2(-1.0, -1.0);\n"
698 " vertices[1] = vec2( 1.0, -1.0);\n"
699 " vertices[2] = vec2( 0.0, 1.0);\n"
700 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
701 "}\n";
702
703 static const char *fragShaderText =
704 "#version 130\n"
705 "void main() {\n"
706 " gl_FragColor = vec4(0,1,0,1);\n"
707 "}\n";
708
709 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to BIL and gives BIL to driver.");
710
711 XglTestFramework::m_use_bil = true;
Tony Barbourae442072015-01-12 13:27:11 -0700712 XGLTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700713 XglTestFramework::m_use_bil = saved_use_bil;
714}
715
716TEST_F(XglRenderTest, YellowTriangle)
717{
718 static const char *vertShaderText =
719 "#version 130\n"
720 "void main() {\n"
721 " vec2 vertices[3];"
722 " vertices[0] = vec2(-0.5, -0.5);\n"
723 " vertices[1] = vec2( 0.5, -0.5);\n"
724 " vertices[2] = vec2( 0.5, 0.5);\n"
725 " vec4 colors[3];\n"
726 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
727 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
728 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
729 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
730 "}\n";
731
732 static const char *fragShaderText =
733 "#version 130\n"
734 "void main() {\n"
735 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
736 "}\n";
737
Tony Barbourae442072015-01-12 13:27:11 -0700738 XGLTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700739}
740
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600741TEST_F(XglRenderTest, TriangleWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600742{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600743 static const char *vertShaderText =
Tony Barbourf43b6982014-11-25 13:18:32 -0700744 "#version 130\n"
745 //XYZ1( -1, -1, -1 )
746 "in vec4 pos;\n"
747 //XYZ1( 0.f, 0.f, 0.f )
748 "in vec4 inColor;\n"
749 "out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600750 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600751 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600752 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600753 "}\n";
754
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600755
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600756 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700757 "#version 140\n"
758 "#extension GL_ARB_separate_shader_objects : enable\n"
759 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700760 "in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700761 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600762 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700763 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600764 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600765
Tony Barbourf43b6982014-11-25 13:18:32 -0700766
767
768 ASSERT_NO_FATAL_FAILURE(InitState());
769 ASSERT_NO_FATAL_FAILURE(InitViewport());
770
771 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000772 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700773
774 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
775 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
776
777 XglPipelineObj pipelineobj(m_device);
778 pipelineobj.AddShader(&vs);
779 pipelineobj.AddShader(&ps);
780
781 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +0800782 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700783
784 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
785 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
786 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
787 };
788
789 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
790 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
791 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
792 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
793 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
794 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
795 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
796 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
797 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
798
799 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
800 pipelineobj.AddVertexInputBindings(&vi_binding,1);
801 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
802
Tony Barboure4ed9942015-01-09 10:06:53 -0700803 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
804 XglCommandBufferObj cmdBuffer(m_device);
805 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700806
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700807 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -0700808 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
809
Tony Barboure4ed9942015-01-09 10:06:53 -0700810 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
811
812 // render two triangles
813 cmdBuffer.Draw(0, 6, 0, 1);
814
815 // finalize recording of the command buffer
816 cmdBuffer.EndCommandBuffer();
817 cmdBuffer.QueueCommandBuffer(NULL, 0);
818
819 for (int i = 0; i < m_renderTargetCount; i++)
820 RecordImage(m_renderTargets[i]);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600821}
822
Chia-I Wue09d1a72014-12-05 10:32:23 +0800823TEST_F(XglRenderTest, TriangleMRT)
824{
825 static const char *vertShaderText =
826 "#version 130\n"
827 "in vec4 pos;\n"
828 "void main() {\n"
829 " gl_Position = pos;\n"
830 "}\n";
831
832 static const char *fragShaderText =
833 "#version 130\n"
834 "void main() {\n"
835 " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
836 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
837 "}\n";
838 const XGL_FLOAT vb_data[][2] = {
839 { -1.0f, -1.0f },
840 { 1.0f, -1.0f },
841 { -1.0f, 1.0f }
842 };
843
844 ASSERT_NO_FATAL_FAILURE(InitState());
845 ASSERT_NO_FATAL_FAILURE(InitViewport());
846
847 XglConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000848 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800849
850 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
851 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
852
853 XglPipelineObj pipelineobj(m_device);
854 pipelineobj.AddShader(&vs);
855 pipelineobj.AddShader(&ps);
856
857 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
858 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
859 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
860 };
861
862 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attrib;
863 vi_attrib.binding = 0; // index into vertexBindingDescriptions
864 vi_attrib.format.channelFormat = XGL_CH_FMT_R32G32; // format of source data
865 vi_attrib.format.numericFormat = XGL_NUM_FMT_FLOAT;
866 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
867
868 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
869 pipelineobj.AddVertexInputBindings(&vi_binding,1);
870 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
871
872 XglDescriptorSetObj descriptorSet(m_device);
873
874 m_renderTargetCount = 2;
Tony Barboure4ed9942015-01-09 10:06:53 -0700875 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wue09d1a72014-12-05 10:32:23 +0800876
877 XGL_PIPELINE_CB_ATTACHMENT_STATE att = {};
878 att.blendEnable = XGL_FALSE;
879 att.format = m_render_target_fmt;
880 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700881 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800882
Tony Barbour5ed79702015-01-07 14:31:52 -0700883 XglCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700884
Tony Barbour5ed79702015-01-07 14:31:52 -0700885 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
886 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barboure4ed9942015-01-09 10:06:53 -0700887
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700888 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour5ed79702015-01-07 14:31:52 -0700889
Tony Barboure4ed9942015-01-09 10:06:53 -0700890 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
891
Tony Barbour5ed79702015-01-07 14:31:52 -0700892 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700893#ifdef DUMP_STATE_DOT
894 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
895 pDSDumpDot((char*)"triTest2.dot");
896#endif
897 // render triangle
898 cmdBuffer.Draw(0, 3, 0, 1);
899
900 // finalize recording of the command buffer
901 cmdBuffer.EndCommandBuffer();
902 cmdBuffer.QueueCommandBuffer(NULL, 0);
903
904 for (int i = 0; i < m_renderTargetCount; i++)
905 RecordImage(m_renderTargets[i]);
906
Chia-I Wue09d1a72014-12-05 10:32:23 +0800907}
908
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700909TEST_F(XglRenderTest, QuadWithIndexedVertexFetch)
910{
911 static const char *vertShaderText =
912 "#version 140\n"
913 "#extension GL_ARB_separate_shader_objects : enable\n"
914 "#extension GL_ARB_shading_language_420pack : enable\n"
915 "layout(location = 0) in vec4 pos;\n"
916 "layout(location = 1) in vec4 inColor;\n"
917 "layout(location = 0) out vec4 outColor;\n"
918 "void main() {\n"
919 " outColor = inColor;\n"
920 " gl_Position = pos;\n"
921 "}\n";
922
923
924 static const char *fragShaderText =
925 "#version 140\n"
926 "#extension GL_ARB_separate_shader_objects : enable\n"
927 "#extension GL_ARB_shading_language_420pack : enable\n"
928 "layout(location = 0) in vec4 color;\n"
929 "void main() {\n"
930 " gl_FragColor = color;\n"
931 "}\n";
932
933 const Vertex g_vbData[] =
934 {
935 // first tri
936 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
937 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
938 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
939
940 // second tri
941 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
942 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
943 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
944 };
945
946 const uint16_t g_idxData[6] = {
947 0, 1, 2,
948 3, 4, 5,
949 };
950
951 ASSERT_NO_FATAL_FAILURE(InitState());
952 ASSERT_NO_FATAL_FAILURE(InitViewport());
953
954 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000955 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700956
957 XglIndexBufferObj indexBuffer(m_device);
958 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), XGL_INDEX_16, g_idxData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000959 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700960
961 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
962 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
963
964 XglPipelineObj pipelineobj(m_device);
965 pipelineobj.AddShader(&vs);
966 pipelineobj.AddShader(&ps);
967
968 XglDescriptorSetObj descriptorSet(m_device);
969
970 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
971 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
972 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
973 };
974
975 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
976 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
977 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
978 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
979 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
980 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
981 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
982 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
983 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
984
985 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
986 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700987
988 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700989 XglCommandBufferObj cmdBuffer(m_device);
990 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700991 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -0700992
993 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700994
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700995#ifdef DUMP_STATE_DOT
996 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700997 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700998#endif
Tony Barbour02472db2015-01-08 17:08:28 -0700999
Tony Barbourde9cf2e2014-12-17 11:16:05 -07001000 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1001 cmdBuffer.BindIndexBuffer(&indexBuffer,0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001002
1003 // render two triangles
Tony Barbourde9cf2e2014-12-17 11:16:05 -07001004 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001005
1006 // finalize recording of the command buffer
Tony Barbourde9cf2e2014-12-17 11:16:05 -07001007 cmdBuffer.EndCommandBuffer();
1008 cmdBuffer.QueueCommandBuffer(NULL, 0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001009
Tony Barbourde9cf2e2014-12-17 11:16:05 -07001010 for (int i = 0; i < m_renderTargetCount; i++)
1011 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001012
1013}
1014
GregF6bef1212014-12-02 15:41:44 -07001015TEST_F(XglRenderTest, GreyandRedCirclesonBlue)
1016{
1017 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -07001018
GregF6bef1212014-12-02 15:41:44 -07001019 static const char *vertShaderText =
1020 "#version 140\n"
1021 "#extension GL_ARB_separate_shader_objects : enable\n"
1022 "#extension GL_ARB_shading_language_420pack : enable\n"
1023 "layout (location = 0) in vec4 pos;\n"
1024 "layout (location = 0) out vec4 outColor;\n"
1025 "layout (location = 1) out vec4 outColor2;\n"
1026 "void main() {\n"
1027 " gl_Position = pos;\n"
1028 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1029 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1030 "}\n";
1031
1032 static const char *fragShaderText =
1033 //"#version 140\n"
1034 "#version 330\n"
1035 "#extension GL_ARB_separate_shader_objects : enable\n"
1036 "#extension GL_ARB_shading_language_420pack : enable\n"
1037 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1038 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1039 "layout (location = 0) in vec4 color;\n"
1040 "layout (location = 1) in vec4 color2;\n"
1041 "void main() {\n"
1042 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1043 " float dist_squared = dot(pos, pos);\n"
1044 " gl_FragColor = (dist_squared < 400.0)\n"
1045 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1046 " : color2;\n"
1047 "}\n";
1048
1049 ASSERT_NO_FATAL_FAILURE(InitState());
1050 ASSERT_NO_FATAL_FAILURE(InitViewport());
1051
1052 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001053 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001054
1055 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1056 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1057
1058 XglPipelineObj pipelineobj(m_device);
1059 pipelineobj.AddShader(&vs);
1060 pipelineobj.AddShader(&ps);
1061
1062 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001063 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001064
1065 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1066 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1067 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1068 };
1069
1070 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1071 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1072 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1073 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1074 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1075 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1076 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1077 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1078 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1079
1080 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1081 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1082 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1083
Tony Barbourdd4c9642015-01-09 12:55:14 -07001084 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1085 XglCommandBufferObj cmdBuffer(m_device);
1086 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1087
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001088 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001089
1090 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1091
1092 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1093#ifdef DUMP_STATE_DOT
1094 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1095 pDSDumpDot((char*)"triTest2.dot");
1096#endif
1097 // render triangle
1098 cmdBuffer.Draw(0, 6, 0, 1);
1099
1100 // finalize recording of the command buffer
1101 cmdBuffer.EndCommandBuffer();
1102 cmdBuffer.QueueCommandBuffer(NULL, 0);
1103
1104 for (int i = 0; i < m_renderTargetCount; i++)
1105 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001106
1107}
1108
1109TEST_F(XglRenderTest, RedCirclesonBlue)
1110{
1111 // This tests that we correctly handle unread fragment inputs
1112
1113 static const char *vertShaderText =
1114 "#version 140\n"
1115 "#extension GL_ARB_separate_shader_objects : enable\n"
1116 "#extension GL_ARB_shading_language_420pack : enable\n"
1117 "layout (location = 0) in vec4 pos;\n"
1118 "layout (location = 0) out vec4 outColor;\n"
1119 "layout (location = 1) out vec4 outColor2;\n"
1120 "void main() {\n"
1121 " gl_Position = pos;\n"
1122 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1123 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1124 "}\n";
1125
1126 static const char *fragShaderText =
1127 //"#version 140\n"
1128 "#version 330\n"
1129 "#extension GL_ARB_separate_shader_objects : enable\n"
1130 "#extension GL_ARB_shading_language_420pack : enable\n"
1131 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1132 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1133 "layout (location = 0) in vec4 color;\n"
1134 "layout (location = 1) in vec4 color2;\n"
1135 "void main() {\n"
1136 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1137 " float dist_squared = dot(pos, pos);\n"
1138 " gl_FragColor = (dist_squared < 400.0)\n"
1139 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1140 " : color2;\n"
1141 "}\n";
1142
1143 ASSERT_NO_FATAL_FAILURE(InitState());
1144 ASSERT_NO_FATAL_FAILURE(InitViewport());
1145
1146 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001147 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001148
1149 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1150 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1151
1152 XglPipelineObj pipelineobj(m_device);
1153 pipelineobj.AddShader(&vs);
1154 pipelineobj.AddShader(&ps);
1155
1156 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001157 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001158
1159 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1160 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1161 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1162 };
1163
1164 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1165 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1166 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1167 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1168 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1169 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1170 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1171 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1172 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1173
1174 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1175 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1176 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1177
Tony Barbourdd4c9642015-01-09 12:55:14 -07001178 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1179 XglCommandBufferObj cmdBuffer(m_device);
1180 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1181
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001182 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001183
1184 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1185
1186 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1187#ifdef DUMP_STATE_DOT
1188 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1189 pDSDumpDot((char*)"triTest2.dot");
1190#endif
1191 // render triangle
1192 cmdBuffer.Draw(0, 6, 0, 1);
1193
1194 // finalize recording of the command buffer
1195 cmdBuffer.EndCommandBuffer();
1196 cmdBuffer.QueueCommandBuffer(NULL, 0);
1197
1198 for (int i = 0; i < m_renderTargetCount; i++)
1199 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001200
1201}
1202
1203TEST_F(XglRenderTest, GreyCirclesonBlueFade)
1204{
1205 // This tests reading gl_ClipDistance from FS
1206
1207 static const char *vertShaderText =
1208 "#version 330\n"
1209 "#extension GL_ARB_separate_shader_objects : enable\n"
1210 "#extension GL_ARB_shading_language_420pack : enable\n"
1211 "out gl_PerVertex {\n"
1212 " vec4 gl_Position;\n"
1213 " float gl_ClipDistance[1];\n"
1214 "};\n"
1215 "layout (location = 0) in vec4 pos;\n"
1216 "layout (location = 0) out vec4 outColor;\n"
1217 "layout (location = 1) out vec4 outColor2;\n"
1218 "void main() {\n"
1219 " gl_Position = pos;\n"
1220 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1221 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1222 " float dists[3];\n"
1223 " dists[0] = 0.0;\n"
1224 " dists[1] = 1.0;\n"
1225 " dists[2] = 1.0;\n"
1226 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1227 "}\n";
1228
1229
1230 static const char *fragShaderText =
1231 //"#version 140\n"
1232 "#version 330\n"
1233 "#extension GL_ARB_separate_shader_objects : enable\n"
1234 "#extension GL_ARB_shading_language_420pack : enable\n"
1235 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1236 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1237 "layout (location = 0) in vec4 color;\n"
1238 "layout (location = 1) in vec4 color2;\n"
1239 "void main() {\n"
1240 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1241 " float dist_squared = dot(pos, pos);\n"
1242 " gl_FragColor = (dist_squared < 400.0)\n"
1243 " ? color * gl_ClipDistance[0]\n"
1244 " : color2;\n"
1245 "}\n";
1246
1247 ASSERT_NO_FATAL_FAILURE(InitState());
1248 ASSERT_NO_FATAL_FAILURE(InitViewport());
1249
1250 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001251 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001252
1253 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1254 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1255
1256 XglPipelineObj pipelineobj(m_device);
1257 pipelineobj.AddShader(&vs);
1258 pipelineobj.AddShader(&ps);
1259
1260 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001261 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001262
1263 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1264 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1265 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1266 };
1267
1268 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1269 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1270 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1271 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1272 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1273 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1274 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1275 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1276 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1277
1278 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1279 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1280 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1281
Tony Barbourdd4c9642015-01-09 12:55:14 -07001282 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1283 XglCommandBufferObj cmdBuffer(m_device);
1284 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF6bef1212014-12-02 15:41:44 -07001285
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001286 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001287
1288 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1289
1290 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1291#ifdef DUMP_STATE_DOT
1292 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1293 pDSDumpDot((char*)"triTest2.dot");
1294#endif
1295 // render triangle
1296 cmdBuffer.Draw(0, 6, 0, 1);
1297
1298 // finalize recording of the command buffer
1299 cmdBuffer.EndCommandBuffer();
1300 cmdBuffer.QueueCommandBuffer(NULL, 0);
1301
1302 for (int i = 0; i < m_renderTargetCount; i++)
1303 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001304}
Tony Barbourf43b6982014-11-25 13:18:32 -07001305
GregF7a23c792014-12-02 17:19:34 -07001306TEST_F(XglRenderTest, GreyCirclesonBlueDiscard)
1307{
1308 static const char *vertShaderText =
1309 "#version 140\n"
1310 "#extension GL_ARB_separate_shader_objects : enable\n"
1311 "#extension GL_ARB_shading_language_420pack : enable\n"
1312 "layout (location = 0) in vec4 pos;\n"
1313 "layout (location = 0) out vec4 outColor;\n"
1314 "layout (location = 1) out vec4 outColor2;\n"
1315 "void main() {\n"
1316 " gl_Position = pos;\n"
1317 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1318 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1319 "}\n";
1320
1321
1322 static const char *fragShaderText =
1323 //"#version 140\n"
1324 "#version 330\n"
1325 "#extension GL_ARB_separate_shader_objects : enable\n"
1326 "#extension GL_ARB_shading_language_420pack : enable\n"
1327 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1328 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1329 "layout (location = 0) in vec4 color;\n"
1330 "layout (location = 1) in vec4 color2;\n"
1331 "void main() {\n"
1332 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1333 " float dist_squared = dot(pos, pos);\n"
1334 " if (dist_squared < 100.0)\n"
1335 " discard;\n"
1336 " gl_FragColor = (dist_squared < 400.0)\n"
1337 " ? color\n"
1338 " : color2;\n"
1339 "}\n";
1340
1341 ASSERT_NO_FATAL_FAILURE(InitState());
1342 ASSERT_NO_FATAL_FAILURE(InitViewport());
1343
1344 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001345 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001346
1347 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1348 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1349
1350 XglPipelineObj pipelineobj(m_device);
1351 pipelineobj.AddShader(&vs);
1352 pipelineobj.AddShader(&ps);
1353
1354 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001355 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF7a23c792014-12-02 17:19:34 -07001356
1357 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1358 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1359 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1360 };
1361
1362 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1363 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1364 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1365 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1366 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1367 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1368 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1369 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1370 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1371
1372 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1373 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1374 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1375
Tony Barbourdd4c9642015-01-09 12:55:14 -07001376 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1377 XglCommandBufferObj cmdBuffer(m_device);
1378 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1379
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001380 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001381
1382 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1383
1384 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1385#ifdef DUMP_STATE_DOT
1386 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1387 pDSDumpDot((char*)"triTest2.dot");
1388#endif
1389 // render triangle
1390 cmdBuffer.Draw(0, 6, 0, 1);
1391
1392 // finalize recording of the command buffer
1393 cmdBuffer.EndCommandBuffer();
1394 cmdBuffer.QueueCommandBuffer(NULL, 0);
1395
1396 for (int i = 0; i < m_renderTargetCount; i++)
1397 RecordImage(m_renderTargets[i]);
GregF7a23c792014-12-02 17:19:34 -07001398
1399}
1400
1401
Courtney Goeltzenleuchter3d10c9c2014-10-27 13:06:08 -06001402TEST_F(XglRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001403{
1404 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001405 "#version 140\n"
1406 "#extension GL_ARB_separate_shader_objects : enable\n"
1407 "#extension GL_ARB_shading_language_420pack : enable\n"
1408 "\n"
1409 "layout(binding = 0) uniform buf {\n"
1410 " mat4 MVP;\n"
1411 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001412 "void main() {\n"
1413 " vec2 vertices[3];"
1414 " vertices[0] = vec2(-0.5, -0.5);\n"
1415 " vertices[1] = vec2( 0.5, -0.5);\n"
1416 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001417 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001418 "}\n";
1419
1420 static const char *fragShaderText =
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001421 "#version 130\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001422 "void main() {\n"
Cody Northrop78eac042014-10-10 15:45:00 -06001423 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001424 "}\n";
1425
Tony Barbourf43b6982014-11-25 13:18:32 -07001426 ASSERT_NO_FATAL_FAILURE(InitState());
1427 ASSERT_NO_FATAL_FAILURE(InitViewport());
1428
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001429 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001430 glm::mat4 Projection = glm::mat4(1.0f);
1431 glm::mat4 View = glm::mat4(1.0f);
1432 glm::mat4 Model = glm::mat4(1.0f);
1433 glm::mat4 MVP = Projection * View * Model;
1434 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1435
Tony Barbourf43b6982014-11-25 13:18:32 -07001436 XglConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1437 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1438 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001439
Tony Barbourf43b6982014-11-25 13:18:32 -07001440 XglPipelineObj pipelineobj(m_device);
1441 pipelineobj.AddShader(&vs);
1442 pipelineobj.AddShader(&ps);
1443
1444 // Create descriptor set and attach the constant buffer to it
1445 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001446 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001447
1448 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1449
Tony Barbourdd4c9642015-01-09 12:55:14 -07001450 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1451 XglCommandBufferObj cmdBuffer(m_device);
1452 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001453
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001454 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001455
1456 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1457
1458 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1459#ifdef DUMP_STATE_DOT
1460 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1461 pDSDumpDot((char*)"triTest2.dot");
1462#endif
1463 // render triangle
1464 cmdBuffer.Draw(0, 6, 0, 1);
1465
1466 // finalize recording of the command buffer
1467 cmdBuffer.EndCommandBuffer();
1468 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
1469
1470 for (int i = 0; i < m_renderTargetCount; i++)
1471 RecordImage(m_renderTargets[i]);
1472
1473 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001474}
1475
Tony Barbourf43b6982014-11-25 13:18:32 -07001476TEST_F(XglRenderTest, MixTriangle)
1477{
1478 // This tests location applied to varyings. Notice that we have switched foo
1479 // and bar in the FS. The triangle should be blended with red, green and blue
1480 // corners.
1481 static const char *vertShaderText =
1482 "#version 140\n"
1483 "#extension GL_ARB_separate_shader_objects : enable\n"
1484 "#extension GL_ARB_shading_language_420pack : enable\n"
1485 "layout (location=0) out vec4 bar;\n"
1486 "layout (location=1) out vec4 foo;\n"
1487 "layout (location=2) out float scale;\n"
1488 "vec2 vertices[3];\n"
1489 "void main() {\n"
1490 " vertices[0] = vec2(-1.0, -1.0);\n"
1491 " vertices[1] = vec2( 1.0, -1.0);\n"
1492 " vertices[2] = vec2( 0.0, 1.0);\n"
1493 "vec4 colors[3];\n"
1494 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1495 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1496 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1497 " foo = colors[gl_VertexID % 3];\n"
1498 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1499 " scale = 1.0;\n"
1500 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1501 "}\n";
1502
1503 static const char *fragShaderText =
1504 "#version 140\n"
1505 "#extension GL_ARB_separate_shader_objects : enable\n"
1506 "#extension GL_ARB_shading_language_420pack : enable\n"
1507 "layout (location = 1) in vec4 bar;\n"
1508 "layout (location = 0) in vec4 foo;\n"
1509 "layout (location = 2) in float scale;\n"
1510 "void main() {\n"
1511 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
1512 "}\n";
1513
1514 ASSERT_NO_FATAL_FAILURE(InitState());
1515 ASSERT_NO_FATAL_FAILURE(InitViewport());
1516
1517 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1518 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1519
1520 XglPipelineObj pipelineobj(m_device);
1521 pipelineobj.AddShader(&vs);
1522 pipelineobj.AddShader(&ps);
1523
1524 XglDescriptorSetObj descriptorSet(m_device);
1525
Tony Barbourdd4c9642015-01-09 12:55:14 -07001526 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1527 XglCommandBufferObj cmdBuffer(m_device);
1528 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1529
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001530 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001531
1532 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1533
1534#ifdef DUMP_STATE_DOT
1535 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1536 pDSDumpDot((char*)"triTest2.dot");
1537#endif
1538 // render triangle
1539 cmdBuffer.Draw(0, 3, 0, 1);
1540
1541 // finalize recording of the command buffer
1542 cmdBuffer.EndCommandBuffer();
1543 cmdBuffer.QueueCommandBuffer(NULL, 0);
1544
1545 for (int i = 0; i < m_renderTargetCount; i++)
1546 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001547}
1548
1549TEST_F(XglRenderTest, TriVertFetchAndVertID)
1550{
1551 // This tests that attributes work in the presence of gl_VertexID
1552
1553 static const char *vertShaderText =
1554 "#version 140\n"
1555 "#extension GL_ARB_separate_shader_objects : enable\n"
1556 "#extension GL_ARB_shading_language_420pack : enable\n"
1557 //XYZ1( -1, -1, -1 )
1558 "layout (location = 0) in vec4 pos;\n"
1559 //XYZ1( 0.f, 0.f, 0.f )
1560 "layout (location = 1) in vec4 inColor;\n"
1561 "layout (location = 0) out vec4 outColor;\n"
1562 "void main() {\n"
1563 " outColor = inColor;\n"
1564 " vec4 vertices[3];"
1565 " vertices[gl_VertexID % 3] = pos;\n"
1566 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1567 "}\n";
1568
1569
1570 static const char *fragShaderText =
1571 "#version 140\n"
1572 "#extension GL_ARB_separate_shader_objects : enable\n"
1573 "#extension GL_ARB_shading_language_420pack : enable\n"
1574 "layout (location = 0) in vec4 color;\n"
1575 "void main() {\n"
1576 " gl_FragColor = color;\n"
1577 "}\n";
1578
1579 ASSERT_NO_FATAL_FAILURE(InitState());
1580 ASSERT_NO_FATAL_FAILURE(InitViewport());
1581
1582 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001583 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001584
1585 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1586 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1587
1588 XglPipelineObj pipelineobj(m_device);
1589 pipelineobj.AddShader(&vs);
1590 pipelineobj.AddShader(&ps);
1591
1592 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001593 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001594
1595 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1596 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1597 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1598 };
1599
1600 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1601 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1602 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1603 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1604 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1605 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1606 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1607 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1608 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1609
1610 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1611 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1612 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1613
Tony Barbourdd4c9642015-01-09 12:55:14 -07001614 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1615 XglCommandBufferObj cmdBuffer(m_device);
1616 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1617
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001618 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001619
1620 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1621
1622 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1623#ifdef DUMP_STATE_DOT
1624 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1625 pDSDumpDot((char*)"triTest2.dot");
1626#endif
1627 // render triangle
1628 cmdBuffer.Draw(0, 6, 0, 1);
1629
1630 // finalize recording of the command buffer
1631 cmdBuffer.EndCommandBuffer();
1632 cmdBuffer.QueueCommandBuffer(NULL, 0);
1633
1634 for (int i = 0; i < m_renderTargetCount; i++)
1635 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001636}
1637
1638TEST_F(XglRenderTest, TriVertFetchDeadAttr)
1639{
1640 // This tests that attributes work in the presence of gl_VertexID
1641 // and a dead attribute in position 0. Draws a triangle with yellow,
1642 // red and green corners, starting at top and going clockwise.
1643
1644 static const char *vertShaderText =
1645 "#version 140\n"
1646 "#extension GL_ARB_separate_shader_objects : enable\n"
1647 "#extension GL_ARB_shading_language_420pack : enable\n"
1648 //XYZ1( -1, -1, -1 )
1649 "layout (location = 0) in vec4 pos;\n"
1650 //XYZ1( 0.f, 0.f, 0.f )
1651 "layout (location = 1) in vec4 inColor;\n"
1652 "layout (location = 0) out vec4 outColor;\n"
1653 "void main() {\n"
1654 " outColor = inColor;\n"
1655 " vec2 vertices[3];"
1656 " vertices[0] = vec2(-1.0, -1.0);\n"
1657 " vertices[1] = vec2( 1.0, -1.0);\n"
1658 " vertices[2] = vec2( 0.0, 1.0);\n"
1659 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1660 "}\n";
1661
1662
1663 static const char *fragShaderText =
1664 "#version 140\n"
1665 "#extension GL_ARB_separate_shader_objects : enable\n"
1666 "#extension GL_ARB_shading_language_420pack : enable\n"
1667 "layout (location = 0) in vec4 color;\n"
1668 "void main() {\n"
1669 " gl_FragColor = color;\n"
1670 "}\n";
1671
1672 ASSERT_NO_FATAL_FAILURE(InitState());
1673 ASSERT_NO_FATAL_FAILURE(InitViewport());
1674
1675 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001676 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001677
1678 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1679 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1680
1681 XglPipelineObj pipelineobj(m_device);
1682 pipelineobj.AddShader(&vs);
1683 pipelineobj.AddShader(&ps);
1684
1685 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001686 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001687
1688 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1689 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1690 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1691 };
1692
1693 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1694 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1695 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1696 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1697 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1698 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1699 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1700 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1701 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1702
1703 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1704 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1705 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1706
Tony Barbourdd4c9642015-01-09 12:55:14 -07001707 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1708 XglCommandBufferObj cmdBuffer(m_device);
1709 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001710
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001711 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001712
1713 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1714
1715 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1716#ifdef DUMP_STATE_DOT
1717 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1718 pDSDumpDot((char*)"triTest2.dot");
1719#endif
1720 // render triangle
1721 cmdBuffer.Draw(0, 6, 0, 1);
1722
1723 // finalize recording of the command buffer
1724 cmdBuffer.EndCommandBuffer();
1725 cmdBuffer.QueueCommandBuffer(NULL, 0);
1726
1727 for (int i = 0; i < m_renderTargetCount; i++)
1728 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001729}
1730
1731TEST_F(XglRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001732{
1733 static const char *vertShaderText =
1734 "#version 140\n"
1735 "layout (std140) uniform bufferVals {\n"
1736 " mat4 mvp;\n"
1737 "} myBufferVals;\n"
1738 "in vec4 pos;\n"
1739 "in vec4 inColor;\n"
1740 "out vec4 outColor;\n"
1741 "void main() {\n"
1742 " outColor = inColor;\n"
1743 " gl_Position = myBufferVals.mvp * pos;\n"
1744 "}\n";
1745
1746 static const char *fragShaderText =
1747 "#version 130\n"
1748 "in vec4 color;\n"
1749 "void main() {\n"
1750 " gl_FragColor = color;\n"
1751 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001752 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001753
Tony Barbourf43b6982014-11-25 13:18:32 -07001754 glm::mat4 View = glm::lookAt(
1755 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1756 glm::vec3(0,0,0), // and looks at the origin
1757 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
1758 );
1759
1760 glm::mat4 Model = glm::mat4(1.0f);
1761
1762 glm::mat4 MVP = Projection * View * Model;
1763
1764 ASSERT_NO_FATAL_FAILURE(InitState());
1765 ASSERT_NO_FATAL_FAILURE(InitViewport());
1766 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
1767
1768 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
1769 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1770
1771 const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT);
1772
1773 XglConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1774 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1775 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1776
Tony Barbourf43b6982014-11-25 13:18:32 -07001777 XglPipelineObj pipelineobj(m_device);
1778 pipelineobj.AddShader(&vs);
1779 pipelineobj.AddShader(&ps);
1780
Tony Barbourfa6cac72015-01-16 14:27:35 -07001781 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
1782 ds_state.depthTestEnable = XGL_TRUE;
1783 ds_state.depthWriteEnable = XGL_TRUE;
1784 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
1785 ds_state.depthBoundsEnable = XGL_FALSE;
1786 ds_state.stencilTestEnable = XGL_FALSE;
1787 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
1788 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
1789 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
1790 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
1791 ds_state.format.channelFormat = XGL_CH_FMT_R32;
1792 ds_state.format.numericFormat = XGL_NUM_FMT_DS;
1793 ds_state.front = ds_state.back;
1794 pipelineobj.SetDepthStencil(&ds_state);
1795
Tony Barbourf43b6982014-11-25 13:18:32 -07001796 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001797 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001798
1799 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1800 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1801
1802 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1803 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1804 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1805 };
1806
1807 // this is the current description of g_vbData
1808 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1809 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1810 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1811 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1812 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1813 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1814 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1815 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1816 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1817
1818 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1819 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1820 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1821
Tony Barboure4ed9942015-01-09 10:06:53 -07001822 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1823 XglCommandBufferObj cmdBuffer(m_device);
1824 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001825
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001826 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -07001827 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001828
Tony Barboure4ed9942015-01-09 10:06:53 -07001829 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1830#ifdef DUMP_STATE_DOT
1831 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1832 pDSDumpDot((char*)"triTest2.dot");
1833#endif
1834 // render triangle
1835 cmdBuffer.Draw(0, 36, 0, 1);
1836
1837 // finalize recording of the command buffer
1838 cmdBuffer.EndCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001839 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barboure4ed9942015-01-09 10:06:53 -07001840
1841 for (int i = 0; i < m_renderTargetCount; i++)
1842 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001843}
1844
Tony Barbourf43b6982014-11-25 13:18:32 -07001845TEST_F(XglRenderTest, VSTexture)
1846{
1847 // The expected result from this test is a green and red triangle;
1848 // one red vertex on the left, two green vertices on the right.
1849 static const char *vertShaderText =
1850 "#version 130\n"
1851 "out vec4 texColor;\n"
1852 "uniform sampler2D surface;\n"
1853 "void main() {\n"
1854 " vec2 vertices[3];"
1855 " vertices[0] = vec2(-0.5, -0.5);\n"
1856 " vertices[1] = vec2( 0.5, -0.5);\n"
1857 " vertices[2] = vec2( 0.5, 0.5);\n"
1858 " vec2 positions[3];"
1859 " positions[0] = vec2( 0.0, 0.0);\n"
1860 " positions[1] = vec2( 0.25, 0.1);\n"
1861 " positions[2] = vec2( 0.1, 0.25);\n"
1862 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1863 " texColor = textureLod(surface, samplePos, 0.0);\n"
1864 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1865 "}\n";
1866
1867 static const char *fragShaderText =
1868 "#version 130\n"
1869 "in vec4 texColor;\n"
1870 "void main() {\n"
1871 " gl_FragColor = texColor;\n"
1872 "}\n";
1873
1874 ASSERT_NO_FATAL_FAILURE(InitState());
1875 ASSERT_NO_FATAL_FAILURE(InitViewport());
1876
1877 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1878 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1879 XglSamplerObj sampler(m_device);
1880 XglTextureObj texture(m_device);
1881
Tony Barbourf43b6982014-11-25 13:18:32 -07001882 XglPipelineObj pipelineobj(m_device);
1883 pipelineobj.AddShader(&vs);
1884 pipelineobj.AddShader(&ps);
1885
1886 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001887 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001888
1889 m_memoryRefManager.AddMemoryRef(&texture);
1890
Tony Barbourdd4c9642015-01-09 12:55:14 -07001891 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1892 XglCommandBufferObj cmdBuffer(m_device);
1893 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001894
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001895 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001896
1897 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1898
1899#ifdef DUMP_STATE_DOT
1900 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1901 pDSDumpDot((char*)"triTest2.dot");
1902#endif
1903 // render triangle
1904 cmdBuffer.Draw(0, 3, 0, 1);
1905
1906 // finalize recording of the command buffer
1907 cmdBuffer.EndCommandBuffer();
1908 cmdBuffer.QueueCommandBuffer(NULL, 0);
1909
1910 for (int i = 0; i < m_renderTargetCount; i++)
1911 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001912}
1913TEST_F(XglRenderTest, TexturedTriangle)
1914{
1915 // The expected result from this test is a red and green checkered triangle
1916 static const char *vertShaderText =
1917 "#version 140\n"
1918 "#extension GL_ARB_separate_shader_objects : enable\n"
1919 "#extension GL_ARB_shading_language_420pack : enable\n"
1920 "layout (location = 0) out vec2 samplePos;\n"
1921 "void main() {\n"
1922 " vec2 vertices[3];"
1923 " vertices[0] = vec2(-0.5, -0.5);\n"
1924 " vertices[1] = vec2( 0.5, -0.5);\n"
1925 " vertices[2] = vec2( 0.5, 0.5);\n"
1926 " vec2 positions[3];"
1927 " positions[0] = vec2( 0.0, 0.0);\n"
1928 " positions[1] = vec2( 1.0, 0.0);\n"
1929 " positions[2] = vec2( 1.0, 1.0);\n"
1930 " samplePos = positions[gl_VertexID % 3];\n"
1931 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1932 "}\n";
1933
1934 static const char *fragShaderText =
1935 "#version 140\n"
1936 "#extension GL_ARB_separate_shader_objects : enable\n"
1937 "#extension GL_ARB_shading_language_420pack : enable\n"
1938 "layout (location = 0) in vec2 samplePos;\n"
1939 "layout (binding = 0) uniform sampler2D surface;\n"
1940 "layout (location=0) out vec4 outColor;\n"
1941 "void main() {\n"
1942 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1943 " outColor = texColor;\n"
1944 "}\n";
1945
1946 ASSERT_NO_FATAL_FAILURE(InitState());
1947 ASSERT_NO_FATAL_FAILURE(InitViewport());
1948
1949 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1950 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1951 XglSamplerObj sampler(m_device);
1952 XglTextureObj texture(m_device);
1953
Tony Barbourf43b6982014-11-25 13:18:32 -07001954 XglPipelineObj pipelineobj(m_device);
1955 pipelineobj.AddShader(&vs);
1956 pipelineobj.AddShader(&ps);
1957
1958 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001959 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001960
1961 m_memoryRefManager.AddMemoryRef(&texture);
1962
Tony Barbourdd4c9642015-01-09 12:55:14 -07001963 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1964 XglCommandBufferObj cmdBuffer(m_device);
1965 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1966
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001967 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001968
1969 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1970
1971#ifdef DUMP_STATE_DOT
1972 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1973 pDSDumpDot((char*)"triTest2.dot");
1974#endif
1975 // render triangle
1976 cmdBuffer.Draw(0, 3, 0, 1);
1977
1978 // finalize recording of the command buffer
1979 cmdBuffer.EndCommandBuffer();
1980 cmdBuffer.QueueCommandBuffer(NULL, 0);
1981
1982 for (int i = 0; i < m_renderTargetCount; i++)
1983 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001984}
1985TEST_F(XglRenderTest, TexturedTriangleClip)
1986{
1987 // The expected result from this test is a red and green checkered triangle
1988 static const char *vertShaderText =
1989 "#version 330\n"
1990 "#extension GL_ARB_separate_shader_objects : enable\n"
1991 "#extension GL_ARB_shading_language_420pack : enable\n"
1992 "layout (location = 0) out vec2 samplePos;\n"
1993 "out gl_PerVertex {\n"
1994 " vec4 gl_Position;\n"
1995 " float gl_ClipDistance[1];\n"
1996 "};\n"
1997 "void main() {\n"
1998 " vec2 vertices[3];"
1999 " vertices[0] = vec2(-0.5, -0.5);\n"
2000 " vertices[1] = vec2( 0.5, -0.5);\n"
2001 " vertices[2] = vec2( 0.5, 0.5);\n"
2002 " vec2 positions[3];"
2003 " positions[0] = vec2( 0.0, 0.0);\n"
2004 " positions[1] = vec2( 1.0, 0.0);\n"
2005 " positions[2] = vec2( 1.0, 1.0);\n"
2006 " float dists[3];\n"
2007 " dists[0] = 1.0;\n"
2008 " dists[1] = 1.0;\n"
2009 " dists[2] = -1.0;\n"
2010 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2011 " samplePos = positions[gl_VertexID % 3];\n"
2012 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2013 "}\n";
2014
2015 static const char *fragShaderText =
2016 "#version 140\n"
2017 "#extension GL_ARB_separate_shader_objects : enable\n"
2018 "#extension GL_ARB_shading_language_420pack : enable\n"
2019 "layout (location = 0) in vec2 samplePos;\n"
2020 "layout (binding = 0) uniform sampler2D surface;\n"
2021 "layout (location=0) out vec4 outColor;\n"
2022 "void main() {\n"
2023 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2024 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2025 " outColor = texColor;\n"
2026 "}\n";
2027
2028
2029 ASSERT_NO_FATAL_FAILURE(InitState());
2030 ASSERT_NO_FATAL_FAILURE(InitViewport());
2031
2032 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2033 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2034 XglSamplerObj sampler(m_device);
2035 XglTextureObj texture(m_device);
2036
Tony Barbourf43b6982014-11-25 13:18:32 -07002037 XglPipelineObj pipelineobj(m_device);
2038 pipelineobj.AddShader(&vs);
2039 pipelineobj.AddShader(&ps);
2040
2041 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002042 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002043
2044 m_memoryRefManager.AddMemoryRef(&texture);
2045
Tony Barbourdd4c9642015-01-09 12:55:14 -07002046 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2047 XglCommandBufferObj cmdBuffer(m_device);
2048 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2049
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002050 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002051
2052 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2053
2054#ifdef DUMP_STATE_DOT
2055 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2056 pDSDumpDot((char*)"triTest2.dot");
2057#endif
2058 // render triangle
2059 cmdBuffer.Draw(0, 3, 0, 1);
2060
2061 // finalize recording of the command buffer
2062 cmdBuffer.EndCommandBuffer();
2063 cmdBuffer.QueueCommandBuffer(NULL, 0);
2064
2065 for (int i = 0; i < m_renderTargetCount; i++)
2066 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002067}
2068TEST_F(XglRenderTest, FSTriangle)
2069{
2070 // The expected result from this test is a red and green checkered triangle
2071 static const char *vertShaderText =
2072 "#version 140\n"
2073 "#extension GL_ARB_separate_shader_objects : enable\n"
2074 "#extension GL_ARB_shading_language_420pack : enable\n"
2075 "layout (location = 0) out vec2 samplePos;\n"
2076 "void main() {\n"
2077 " vec2 vertices[3];"
2078 " vertices[0] = vec2(-0.5, -0.5);\n"
2079 " vertices[1] = vec2( 0.5, -0.5);\n"
2080 " vertices[2] = vec2( 0.5, 0.5);\n"
2081 " vec2 positions[3];"
2082 " positions[0] = vec2( 0.0, 0.0);\n"
2083 " positions[1] = vec2( 1.0, 0.0);\n"
2084 " positions[2] = vec2( 1.0, 1.0);\n"
2085 " samplePos = positions[gl_VertexID % 3];\n"
2086 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2087 "}\n";
2088
2089 static const char *fragShaderText =
2090 "#version 140\n"
2091 "#extension GL_ARB_separate_shader_objects : enable\n"
2092 "#extension GL_ARB_shading_language_420pack : enable\n"
2093 "layout (location = 0) in vec2 samplePos;\n"
2094 "layout (binding = 0) uniform sampler2D surface;\n"
2095 "layout (location=0) out vec4 outColor;\n"
2096 "void main() {\n"
2097 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2098 " outColor = texColor;\n"
2099 "}\n";
2100
2101 ASSERT_NO_FATAL_FAILURE(InitState());
2102 ASSERT_NO_FATAL_FAILURE(InitViewport());
2103
2104 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2105 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2106 XglSamplerObj sampler(m_device);
2107 XglTextureObj texture(m_device);
2108
Tony Barbourf43b6982014-11-25 13:18:32 -07002109 XglPipelineObj pipelineobj(m_device);
2110 pipelineobj.AddShader(&vs);
2111 pipelineobj.AddShader(&ps);
2112
2113 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002114 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002115
2116 m_memoryRefManager.AddMemoryRef(&texture);
2117
Tony Barbourdd4c9642015-01-09 12:55:14 -07002118 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2119 XglCommandBufferObj cmdBuffer(m_device);
2120 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2121
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002122 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002123
2124 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2125
2126#ifdef DUMP_STATE_DOT
2127 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2128 pDSDumpDot((char*)"triTest2.dot");
2129#endif
2130 // render triangle
2131 cmdBuffer.Draw(0, 3, 0, 1);
2132
2133 // finalize recording of the command buffer
2134 cmdBuffer.EndCommandBuffer();
2135 cmdBuffer.QueueCommandBuffer(NULL, 0);
2136
2137 for (int i = 0; i < m_renderTargetCount; i++)
2138 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002139}
2140TEST_F(XglRenderTest, SamplerBindingsTriangle)
2141{
2142 // This test sets bindings on the samplers
2143 // For now we are asserting that sampler and texture pairs
2144 // march in lock step, and are set via GLSL binding. This can
2145 // and will probably change.
2146 // The sampler bindings should match the sampler and texture slot
2147 // number set up by the application.
2148 // This test will result in a blue triangle
2149 static const char *vertShaderText =
2150 "#version 140\n"
2151 "#extension GL_ARB_separate_shader_objects : enable\n"
2152 "#extension GL_ARB_shading_language_420pack : enable\n"
2153 "layout (location = 0) out vec4 samplePos;\n"
2154 "void main() {\n"
2155 " vec2 vertices[3];"
2156 " vertices[0] = vec2(-0.5, -0.5);\n"
2157 " vertices[1] = vec2( 0.5, -0.5);\n"
2158 " vertices[2] = vec2( 0.5, 0.5);\n"
2159 " vec2 positions[3];"
2160 " positions[0] = vec2( 0.0, 0.0);\n"
2161 " positions[1] = vec2( 1.0, 0.0);\n"
2162 " positions[2] = vec2( 1.0, 1.0);\n"
2163 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2164 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2165 "}\n";
2166
2167 static const char *fragShaderText =
2168 "#version 140\n"
2169 "#extension GL_ARB_separate_shader_objects : enable\n"
2170 "#extension GL_ARB_shading_language_420pack : enable\n"
2171 "layout (location = 0) in vec4 samplePos;\n"
2172 "layout (binding = 0) uniform sampler2D surface0;\n"
2173 "layout (binding = 1) uniform sampler2D surface1;\n"
2174 "layout (binding = 12) uniform sampler2D surface2;\n"
2175 "void main() {\n"
2176 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
2177 "}\n";
2178
2179 ASSERT_NO_FATAL_FAILURE(InitState());
2180 ASSERT_NO_FATAL_FAILURE(InitViewport());
2181
2182 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2183 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2184
2185 XglSamplerObj sampler1(m_device);
2186 XglSamplerObj sampler2(m_device);
2187 XglSamplerObj sampler3(m_device);
2188
2189 XglTextureObj texture1(m_device); // Red
2190 texture1.ChangeColors(0xffff0000,0xffff0000);
2191 XglTextureObj texture2(m_device); // Green
2192 texture2.ChangeColors(0xff00ff00,0xff00ff00);
2193 XglTextureObj texture3(m_device); // Blue
2194 texture3.ChangeColors(0xff0000ff,0xff0000ff);
2195
Tony Barbourf43b6982014-11-25 13:18:32 -07002196 XglPipelineObj pipelineobj(m_device);
2197 pipelineobj.AddShader(&vs);
2198 pipelineobj.AddShader(&ps);
2199
2200 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002201 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2202 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2203 for (int i = 0; i < 10; i++)
2204 descriptorSet.AppendDummy();
2205 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002206
2207 m_memoryRefManager.AddMemoryRef(&texture1);
2208 m_memoryRefManager.AddMemoryRef(&texture2);
2209 m_memoryRefManager.AddMemoryRef(&texture3);
2210
Tony Barbourdd4c9642015-01-09 12:55:14 -07002211 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2212 XglCommandBufferObj cmdBuffer(m_device);
2213 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2214
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002215 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002216
2217 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2218
2219#ifdef DUMP_STATE_DOT
2220 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2221 pDSDumpDot((char*)"triTest2.dot");
2222#endif
2223 // render triangle
2224 cmdBuffer.Draw(0, 3, 0, 1);
2225
2226 // finalize recording of the command buffer
2227 cmdBuffer.EndCommandBuffer();
2228 cmdBuffer.QueueCommandBuffer(NULL, 0);
2229
2230 for (int i = 0; i < m_renderTargetCount; i++)
2231 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002232
2233}
2234
2235TEST_F(XglRenderTest, TriangleVSUniformBlock)
2236{
2237 // The expected result from this test is a blue triangle
2238
2239 static const char *vertShaderText =
2240 "#version 140\n"
2241 "#extension GL_ARB_separate_shader_objects : enable\n"
2242 "#extension GL_ARB_shading_language_420pack : enable\n"
2243 "layout (location = 0) out vec4 outColor;\n"
2244 "layout (std140, binding = 0) uniform bufferVals {\n"
2245 " vec4 red;\n"
2246 " vec4 green;\n"
2247 " vec4 blue;\n"
2248 " vec4 white;\n"
2249 "} myBufferVals;\n"
2250 "void main() {\n"
2251 " vec2 vertices[3];"
2252 " vertices[0] = vec2(-0.5, -0.5);\n"
2253 " vertices[1] = vec2( 0.5, -0.5);\n"
2254 " vertices[2] = vec2( 0.5, 0.5);\n"
2255 " outColor = myBufferVals.blue;\n"
2256 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2257 "}\n";
2258
2259 static const char *fragShaderText =
2260 "#version 140\n"
2261 "#extension GL_ARB_separate_shader_objects : enable\n"
2262 "#extension GL_ARB_shading_language_420pack : enable\n"
2263 "layout (location = 0) in vec4 inColor;\n"
2264 "void main() {\n"
2265 " gl_FragColor = inColor;\n"
2266 "}\n";
2267
2268 ASSERT_NO_FATAL_FAILURE(InitState());
2269 ASSERT_NO_FATAL_FAILURE(InitViewport());
2270
2271 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2272 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2273
2274 // Let's populate our buffer with the following:
2275 // vec4 red;
2276 // vec4 green;
2277 // vec4 blue;
2278 // vec4 white;
2279 const int valCount = 4 * 4;
2280 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2281 0.0, 1.0, 0.0, 1.0,
2282 0.0, 0.0, 1.0, 1.0,
2283 1.0, 1.0, 1.0, 1.0 };
2284
2285 XglConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002286
2287 XglPipelineObj pipelineobj(m_device);
2288 pipelineobj.AddShader(&vs);
2289 pipelineobj.AddShader(&ps);
2290
2291 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002292 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002293
Tony Barbourdd4c9642015-01-09 12:55:14 -07002294 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2295 XglCommandBufferObj cmdBuffer(m_device);
2296 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2297
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002298 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002299
2300 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2301
2302#ifdef DUMP_STATE_DOT
2303 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2304 pDSDumpDot((char*)"triTest2.dot");
2305#endif
2306 // render triangle
2307 cmdBuffer.Draw(0, 3, 0, 1);
2308
2309 // finalize recording of the command buffer
2310 cmdBuffer.EndCommandBuffer();
2311 cmdBuffer.QueueCommandBuffer(NULL, 0);
2312
2313 for (int i = 0; i < m_renderTargetCount; i++)
2314 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002315
2316}
2317
2318TEST_F(XglRenderTest, TriangleFSUniformBlockBinding)
2319{
2320 // This test allows the shader to select which buffer it is
2321 // pulling from using layout binding qualifier.
2322 // There are corresponding changes in the compiler stack that
2323 // will select the buffer using binding directly.
2324 // The binding number should match the slot number set up by
2325 // the application.
2326 // The expected result from this test is a purple triangle
2327
2328 static const char *vertShaderText =
2329 "#version 140\n"
2330 "#extension GL_ARB_separate_shader_objects : enable\n"
2331 "#extension GL_ARB_shading_language_420pack : enable\n"
2332 "void main() {\n"
2333 " vec2 vertices[3];"
2334 " vertices[0] = vec2(-0.5, -0.5);\n"
2335 " vertices[1] = vec2( 0.5, -0.5);\n"
2336 " vertices[2] = vec2( 0.5, 0.5);\n"
2337 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2338 "}\n";
2339
2340 static const char *fragShaderText =
2341 "#version 140\n"
2342 "#extension GL_ARB_separate_shader_objects : enable\n"
2343 "#extension GL_ARB_shading_language_420pack : enable\n"
2344 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2345 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2346 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002347 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
Tony Barbourf43b6982014-11-25 13:18:32 -07002348 "void main() {\n"
2349 " gl_FragColor = myBlueVal.color;\n"
2350 " gl_FragColor += myRedVal.color;\n"
2351 "}\n";
2352
2353 ASSERT_NO_FATAL_FAILURE(InitState());
2354 ASSERT_NO_FATAL_FAILURE(InitViewport());
2355
2356 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2357 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2358
2359 // We're going to create a number of uniform buffers, and then allow
2360 // the shader to select which it wants to read from with a binding
2361
2362 // Let's populate the buffers with a single color each:
2363 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2364 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2365 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002366 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002367
2368 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2369 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2370 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2371 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2372
2373 const int redCount = sizeof(redVals) / sizeof(float);
2374 const int greenCount = sizeof(greenVals) / sizeof(float);
2375 const int blueCount = sizeof(blueVals) / sizeof(float);
2376 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2377
2378 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002379
2380 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002381
2382 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002383
2384 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002385
2386 XglPipelineObj pipelineobj(m_device);
2387 pipelineobj.AddShader(&vs);
2388 pipelineobj.AddShader(&ps);
2389
2390 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002391 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2392 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2393 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2394 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002395
Tony Barbourdd4c9642015-01-09 12:55:14 -07002396 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2397 XglCommandBufferObj cmdBuffer(m_device);
2398 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002399
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002400 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002401
2402 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2403
2404#ifdef DUMP_STATE_DOT
2405 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2406 pDSDumpDot((char*)"triTest2.dot");
2407#endif
2408 // render triangle
2409 cmdBuffer.Draw(0, 3, 0, 1);
2410
2411 // finalize recording of the command buffer
2412 cmdBuffer.EndCommandBuffer();
2413 cmdBuffer.QueueCommandBuffer(NULL, 0);
2414
2415 for (int i = 0; i < m_renderTargetCount; i++)
2416 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002417}
2418
2419TEST_F(XglRenderTest, TriangleFSAnonymousUniformBlockBinding)
2420{
2421 // This test is the same as TriangleFSUniformBlockBinding, but
2422 // it does not provide an instance name.
2423 // The expected result from this test is a purple triangle
2424
2425 static const char *vertShaderText =
2426 "#version 140\n"
2427 "#extension GL_ARB_separate_shader_objects : enable\n"
2428 "#extension GL_ARB_shading_language_420pack : enable\n"
2429 "void main() {\n"
2430 " vec2 vertices[3];"
2431 " vertices[0] = vec2(-0.5, -0.5);\n"
2432 " vertices[1] = vec2( 0.5, -0.5);\n"
2433 " vertices[2] = vec2( 0.5, 0.5);\n"
2434 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2435 "}\n";
2436
2437 static const char *fragShaderText =
2438 "#version 430\n"
2439 "#extension GL_ARB_separate_shader_objects : enable\n"
2440 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002441 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2442 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2443 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002444 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002445 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002446 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002447 " outColor = blue;\n"
2448 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002449 "}\n";
2450 ASSERT_NO_FATAL_FAILURE(InitState());
2451 ASSERT_NO_FATAL_FAILURE(InitViewport());
2452
2453 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2454 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2455
2456 // We're going to create a number of uniform buffers, and then allow
2457 // the shader to select which it wants to read from with a binding
2458
2459 // Let's populate the buffers with a single color each:
2460 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2461 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2462 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2463 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2464
2465 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2466 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2467 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2468 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2469
2470 const int redCount = sizeof(redVals) / sizeof(float);
2471 const int greenCount = sizeof(greenVals) / sizeof(float);
2472 const int blueCount = sizeof(blueVals) / sizeof(float);
2473 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2474
2475 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002476
2477 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002478
2479 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002480
2481 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002482
2483 XglPipelineObj pipelineobj(m_device);
2484 pipelineobj.AddShader(&vs);
2485 pipelineobj.AddShader(&ps);
2486
2487 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002488 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2489 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2490 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2491 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002492
Tony Barbourdd4c9642015-01-09 12:55:14 -07002493 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2494 XglCommandBufferObj cmdBuffer(m_device);
2495 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2496
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002497 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002498
2499 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2500
2501#ifdef DUMP_STATE_DOT
2502 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2503 pDSDumpDot((char*)"triTest2.dot");
2504#endif
2505 // render triangle
2506 cmdBuffer.Draw(0, 3, 0, 1);
2507
2508 // finalize recording of the command buffer
2509 cmdBuffer.EndCommandBuffer();
2510 cmdBuffer.QueueCommandBuffer(NULL, 0);
2511
2512 for (int i = 0; i < m_renderTargetCount; i++)
2513 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002514
2515}
2516
2517TEST_F(XglRenderTest, CubeWithVertexFetchAndMVPAndTexture)
2518{
2519 static const char *vertShaderText =
2520 "#version 140\n"
2521 "#extension GL_ARB_separate_shader_objects : enable\n"
2522 "#extension GL_ARB_shading_language_420pack : enable\n"
2523 "layout (std140, binding=0) uniform bufferVals {\n"
2524 " mat4 mvp;\n"
2525 "} myBufferVals;\n"
2526 "layout (location=0) in vec4 pos;\n"
2527 "layout (location=0) out vec2 UV;\n"
2528 "void main() {\n"
2529 " vec2 positions[3];"
2530 " positions[0] = vec2( 0.0, 0.0);\n"
2531 " positions[1] = vec2( 0.25, 0.1);\n"
2532 " positions[2] = vec2( 0.1, 0.25);\n"
2533 " UV = positions[gl_VertexID % 3];\n"
2534 " gl_Position = myBufferVals.mvp * pos;\n"
2535 "}\n";
2536
2537 static const char *fragShaderText =
2538 "#version 140\n"
2539 "#extension GL_ARB_separate_shader_objects : enable\n"
2540 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002541 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002542 "layout (location=0) out vec4 outColor;\n"
2543 "layout (location=0) in vec2 UV;\n"
2544 "void main() {\n"
2545 " outColor= textureLod(surface, UV, 0.0);\n"
2546 "}\n";
2547 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2548
2549 glm::mat4 View = glm::lookAt(
2550 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2551 glm::vec3(0,0,0), // and looks at the origin
2552 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2553 );
2554
2555 glm::mat4 Model = glm::mat4(1.0f);
2556
2557 glm::mat4 MVP = Projection * View * Model;
2558
2559
2560 ASSERT_NO_FATAL_FAILURE(InitState());
2561 ASSERT_NO_FATAL_FAILURE(InitViewport());
2562 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
2563
2564 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
2565 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002566 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002567
2568 const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT);
2569
2570 XglConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2571 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2572 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2573 XglSamplerObj sampler(m_device);
2574 XglTextureObj texture(m_device);
2575
Tony Barbourf43b6982014-11-25 13:18:32 -07002576 XglPipelineObj pipelineobj(m_device);
2577 pipelineobj.AddShader(&vs);
2578 pipelineobj.AddShader(&ps);
2579
2580 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002581 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mvpBuffer);
2582 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002583
2584 m_memoryRefManager.AddMemoryRef(&meshBuffer);
2585 m_memoryRefManager.AddMemoryRef(&mvpBuffer);
2586 m_memoryRefManager.AddMemoryRef(&texture);
2587
2588 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
2589 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
2590 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
2591 };
2592
2593 // this is the current description of g_vbData
2594 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
2595 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
2596 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
2597 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
2598 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2599 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
2600 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
2601 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
2602 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
2603
2604 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2605 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
2606 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
2607
Tony Barbourfa6cac72015-01-16 14:27:35 -07002608 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
2609 ds_state.depthTestEnable = XGL_TRUE;
2610 ds_state.depthWriteEnable = XGL_TRUE;
2611 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
2612 ds_state.depthBoundsEnable = XGL_FALSE;
2613 ds_state.stencilTestEnable = XGL_FALSE;
2614 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
2615 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
2616 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
2617 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
2618 ds_state.format.channelFormat = XGL_CH_FMT_R32;
2619 ds_state.format.numericFormat = XGL_NUM_FMT_DS;
2620 ds_state.front = ds_state.back;
2621 pipelineobj.SetDepthStencil(&ds_state);
2622
Tony Barbourdd4c9642015-01-09 12:55:14 -07002623 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2624 XglCommandBufferObj cmdBuffer(m_device);
2625 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002626
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002627 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002628 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2629
2630 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2631#ifdef DUMP_STATE_DOT
2632 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2633 pDSDumpDot((char*)"triTest2.dot");
2634#endif
2635 // render triangle
2636 cmdBuffer.Draw(0, 36, 0, 1);
2637
2638 // finalize recording of the command buffer
2639 cmdBuffer.EndCommandBuffer();
2640 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
2641
2642 for (int i = 0; i < m_renderTargetCount; i++)
2643 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002644
2645}
Cody Northropd1ce7842014-12-09 11:17:01 -07002646
2647TEST_F(XglRenderTest, TriangleMixedSamplerUniformBlockBinding)
2648{
2649 // This test mixes binding slots of textures and buffers, ensuring
2650 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002651 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002652 // you can modify it to move the desired result around.
2653
2654 static const char *vertShaderText =
2655 "#version 140\n"
2656 "#extension GL_ARB_separate_shader_objects : enable\n"
2657 "#extension GL_ARB_shading_language_420pack : enable\n"
2658 "void main() {\n"
2659 " vec2 vertices[3];"
2660 " vertices[0] = vec2(-0.5, -0.5);\n"
2661 " vertices[1] = vec2( 0.5, -0.5);\n"
2662 " vertices[2] = vec2( 0.5, 0.5);\n"
2663 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2664 "}\n";
2665
2666 static const char *fragShaderText =
2667 "#version 430\n"
2668 "#extension GL_ARB_separate_shader_objects : enable\n"
2669 "#extension GL_ARB_shading_language_420pack : enable\n"
2670 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002671 "layout (binding = 3) uniform sampler2D surface1;\n"
2672 "layout (binding = 1) uniform sampler2D surface2;\n"
2673 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002674
Cody Northropa0410942014-12-09 13:59:39 -07002675
Chia-I Wuf8385062015-01-04 16:27:24 +08002676 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2677 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2678 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2679 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002680 "layout (location = 0) out vec4 outColor;\n"
2681 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002682 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002683 " outColor += white * vec4(0.00001);\n"
2684 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002685 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002686 "}\n";
2687 ASSERT_NO_FATAL_FAILURE(InitState());
2688 ASSERT_NO_FATAL_FAILURE(InitViewport());
2689
2690 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2691 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2692
Cody Northropd1ce7842014-12-09 11:17:01 -07002693 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2694 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2695 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2696 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2697
2698 const int redCount = sizeof(redVals) / sizeof(float);
2699 const int greenCount = sizeof(greenVals) / sizeof(float);
2700 const int blueCount = sizeof(blueVals) / sizeof(float);
2701 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2702
2703 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002704 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002705 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002706 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002707
2708 XglSamplerObj sampler0(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002709 XglTextureObj texture0(m_device); // Light Red
2710 texture0.ChangeColors(0xff800000,0xff800000);
Cody Northropd1ce7842014-12-09 11:17:01 -07002711 XglSamplerObj sampler2(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002712 XglTextureObj texture2(m_device); // Light Blue
2713 texture2.ChangeColors(0xff000080,0xff000080);
Cody Northropd1ce7842014-12-09 11:17:01 -07002714 XglSamplerObj sampler4(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002715 XglTextureObj texture4(m_device); // Light Green
2716 texture4.ChangeColors(0xff008000,0xff008000);
Cody Northropa0410942014-12-09 13:59:39 -07002717
2718 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2719 // TODO: Get back here ASAP and understand why.
2720 XglSamplerObj sampler7(m_device);
2721 XglTextureObj texture7(m_device); // Red and Blue
2722 texture7.ChangeColors(0xffff00ff,0xffff00ff);
Cody Northropd1ce7842014-12-09 11:17:01 -07002723
2724 XglPipelineObj pipelineobj(m_device);
2725 pipelineobj.AddShader(&vs);
2726 pipelineobj.AddShader(&ps);
2727
2728 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002729 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2730 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2731 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2732 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2733 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2734 // swap blue and green
2735 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2736 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2737 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002738
2739 m_memoryRefManager.AddMemoryRef(&texture0);
2740 m_memoryRefManager.AddMemoryRef(&texture2);
2741 m_memoryRefManager.AddMemoryRef(&texture4);
Cody Northropa0410942014-12-09 13:59:39 -07002742 m_memoryRefManager.AddMemoryRef(&texture7);
Cody Northropd1ce7842014-12-09 11:17:01 -07002743
Tony Barbourdd4c9642015-01-09 12:55:14 -07002744 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2745 XglCommandBufferObj cmdBuffer(m_device);
2746 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002747
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002748 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002749
2750 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2751
2752#ifdef DUMP_STATE_DOT
2753 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2754 pDSDumpDot((char*)"triTest2.dot");
2755#endif
2756 // render triangle
2757 cmdBuffer.Draw(0, 3, 0, 1);
2758
2759 // finalize recording of the command buffer
2760 cmdBuffer.EndCommandBuffer();
2761 cmdBuffer.QueueCommandBuffer(NULL, 0);
2762
2763 for (int i = 0; i < m_renderTargetCount; i++)
2764 RecordImage(m_renderTargets[i]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002765
2766}
2767
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002768TEST_F(XglRenderTest, TriangleMatchingSamplerUniformBlockBinding)
2769{
2770 // This test matches binding slots of textures and buffers, requiring
2771 // the driver to give them distinct number spaces.
2772 // The expected result from this test is a red triangle, although
2773 // you can modify it to move the desired result around.
2774
2775 static const char *vertShaderText =
2776 "#version 140\n"
2777 "#extension GL_ARB_separate_shader_objects : enable\n"
2778 "#extension GL_ARB_shading_language_420pack : enable\n"
2779 "void main() {\n"
2780 " vec2 vertices[3];"
2781 " vertices[0] = vec2(-0.5, -0.5);\n"
2782 " vertices[1] = vec2( 0.5, -0.5);\n"
2783 " vertices[2] = vec2( 0.5, 0.5);\n"
2784 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2785 "}\n";
2786
2787 static const char *fragShaderText =
2788 "#version 430\n"
2789 "#extension GL_ARB_separate_shader_objects : enable\n"
2790 "#extension GL_ARB_shading_language_420pack : enable\n"
2791 "layout (binding = 0) uniform sampler2D surface0;\n"
2792 "layout (binding = 1) uniform sampler2D surface1;\n"
2793 "layout (binding = 2) uniform sampler2D surface2;\n"
2794 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002795 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2796 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2797 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2798 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002799 "layout (location = 0) out vec4 outColor;\n"
2800 "void main() {\n"
2801 " outColor = red;// * vec4(0.00001);\n"
2802 " outColor += white * vec4(0.00001);\n"
2803 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2804 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2805 "}\n";
2806 ASSERT_NO_FATAL_FAILURE(InitState());
2807 ASSERT_NO_FATAL_FAILURE(InitViewport());
2808
2809 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2810 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2811
2812 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2813 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2814 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2815 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2816
2817 const int redCount = sizeof(redVals) / sizeof(float);
2818 const int greenCount = sizeof(greenVals) / sizeof(float);
2819 const int blueCount = sizeof(blueVals) / sizeof(float);
2820 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2821
2822 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002823 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002824 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002825 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002826
2827 XglSamplerObj sampler0(m_device);
2828 XglTextureObj texture0(m_device); // Light Red
2829 texture0.ChangeColors(0xff800000,0xff800000);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002830 XglSamplerObj sampler2(m_device);
2831 XglTextureObj texture2(m_device); // Light Blue
2832 texture2.ChangeColors(0xff000080,0xff000080);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002833 XglSamplerObj sampler4(m_device);
2834 XglTextureObj texture4(m_device); // Light Green
2835 texture4.ChangeColors(0xff008000,0xff008000);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002836 XglSamplerObj sampler7(m_device);
2837 XglTextureObj texture7(m_device); // Red and Blue
2838 texture7.ChangeColors(0xffff00ff,0xffff00ff);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002839
2840
2841 XglPipelineObj pipelineobj(m_device);
2842 pipelineobj.AddShader(&vs);
2843 pipelineobj.AddShader(&ps);
2844
2845 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002846 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2847 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2848 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2849 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2850 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2851 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2852 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2853 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002854
2855 m_memoryRefManager.AddMemoryRef(&texture0);
2856 m_memoryRefManager.AddMemoryRef(&texture2);
2857 m_memoryRefManager.AddMemoryRef(&texture4);
2858 m_memoryRefManager.AddMemoryRef(&texture7);
2859
Tony Barbourdd4c9642015-01-09 12:55:14 -07002860 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2861 XglCommandBufferObj cmdBuffer(m_device);
2862 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002863
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002864 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002865
2866 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2867
2868#ifdef DUMP_STATE_DOT
2869 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2870 pDSDumpDot((char*)"triTest2.dot");
2871#endif
2872 // render triangle
2873 cmdBuffer.Draw(0, 3, 0, 1);
2874
2875 // finalize recording of the command buffer
2876 cmdBuffer.EndCommandBuffer();
2877 cmdBuffer.QueueCommandBuffer(NULL, 0);
2878
2879 for (int i = 0; i < m_renderTargetCount; i++)
2880 RecordImage(m_renderTargets[i]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002881
2882}
2883
Cody Northrop02690bd2014-12-17 15:26:33 -07002884TEST_F(XglRenderTest, TriangleUniformBufferLayout)
2885{
2886 // This test populates a buffer with a variety of different data
2887 // types, then reads them out with a shader.
2888 // The expected result from this test is a green triangle
2889
2890 static const char *vertShaderText =
2891 "#version 140\n"
2892 "#extension GL_ARB_separate_shader_objects : enable\n"
2893 "#extension GL_ARB_shading_language_420pack : enable\n"
2894 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2895 " vec4 fRed;\n"
2896 " vec4 fGreen;\n"
2897 " layout(row_major) mat4 worldToProj;\n"
2898 " layout(row_major) mat4 projToWorld;\n"
2899 " layout(row_major) mat4 worldToView;\n"
2900 " layout(row_major) mat4 viewToProj;\n"
2901 " layout(row_major) mat4 worldToShadow[4];\n"
2902 " float fZero;\n"
2903 " float fOne;\n"
2904 " float fTwo;\n"
2905 " float fThree;\n"
2906 " vec3 fZeroZeroZero;\n"
2907 " float fFour;\n"
2908 " vec3 fZeroZeroOne;\n"
2909 " float fFive;\n"
2910 " vec3 fZeroOneZero;\n"
2911 " float fSix;\n"
2912 " float fSeven;\n"
2913 " float fEight;\n"
2914 " float fNine;\n"
2915 " vec2 fZeroZero;\n"
2916 " vec2 fZeroOne;\n"
2917 " vec4 fBlue;\n"
2918 " vec2 fOneZero;\n"
2919 " vec2 fOneOne;\n"
2920 " vec3 fZeroOneOne;\n"
2921 " float fTen;\n"
2922 " float fEleven;\n"
2923 " float fTwelve;\n"
2924 " vec3 fOneZeroZero;\n"
2925 " vec4 uvOffsets[4];\n"
2926 "};\n"
2927 "layout (location = 0) out vec4 color;"
2928 "void main() {\n"
2929
2930 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2931 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2932 " \n"
2933
2934 // do some exact comparisons, even though we should
2935 // really have an epsilon involved.
2936 " vec4 outColor = right;\n"
2937 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
2938 " outColor = wrong;\n"
2939 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
2940 " outColor = wrong;\n"
2941 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
2942 " outColor = wrong;\n"
2943
2944 " color = outColor;\n"
2945
2946 // generic position stuff
2947 " vec2 vertices;\n"
2948 " int vertexSelector = gl_VertexID;\n"
2949 " if (vertexSelector == 0)\n"
2950 " vertices = vec2(-0.5, -0.5);\n"
2951 " else if (vertexSelector == 1)\n"
2952 " vertices = vec2( 0.5, -0.5);\n"
2953 " else if (vertexSelector == 2)\n"
2954 " vertices = vec2( 0.5, 0.5);\n"
2955 " else\n"
2956 " vertices = vec2( 0.0, 0.0);\n"
2957 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
2958 "}\n";
2959
2960 static const char *fragShaderText =
2961 "#version 140\n"
2962 "#extension GL_ARB_separate_shader_objects : enable\n"
2963 "#extension GL_ARB_shading_language_420pack : enable\n"
2964 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2965 " vec4 fRed;\n"
2966 " vec4 fGreen;\n"
2967 " layout(row_major) mat4 worldToProj;\n"
2968 " layout(row_major) mat4 projToWorld;\n"
2969 " layout(row_major) mat4 worldToView;\n"
2970 " layout(row_major) mat4 viewToProj;\n"
2971 " layout(row_major) mat4 worldToShadow[4];\n"
2972 " float fZero;\n"
2973 " float fOne;\n"
2974 " float fTwo;\n"
2975 " float fThree;\n"
2976 " vec3 fZeroZeroZero;\n"
2977 " float fFour;\n"
2978 " vec3 fZeroZeroOne;\n"
2979 " float fFive;\n"
2980 " vec3 fZeroOneZero;\n"
2981 " float fSix;\n"
2982 " float fSeven;\n"
2983 " float fEight;\n"
2984 " float fNine;\n"
2985 " vec2 fZeroZero;\n"
2986 " vec2 fZeroOne;\n"
2987 " vec4 fBlue;\n"
2988 " vec2 fOneZero;\n"
2989 " vec2 fOneOne;\n"
2990 " vec3 fZeroOneOne;\n"
2991 " float fTen;\n"
2992 " float fEleven;\n"
2993 " float fTwelve;\n"
2994 " vec3 fOneZeroZero;\n"
2995 " vec4 uvOffsets[4];\n"
2996 "};\n"
2997 "layout (location = 0) in vec4 color;\n"
2998 "void main() {\n"
2999 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3000 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3001 " \n"
3002
3003 // start with VS value to ensure it passed
3004 " vec4 outColor = color;\n"
3005
3006 // do some exact comparisons, even though we should
3007 // really have an epsilon involved.
3008 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3009 " outColor = wrong;\n"
3010 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3011 " outColor = wrong;\n"
3012 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3013 " outColor = wrong;\n"
3014 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3015 " outColor = wrong;\n"
3016 " if (fTwo != 2.0)\n"
3017 " outColor = wrong;\n"
3018 " if (fOneOne != vec2(1.0, 1.0))\n"
3019 " outColor = wrong;\n"
3020 " if (fTen != 10.0)\n"
3021 " outColor = wrong;\n"
3022 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3023 " outColor = wrong;\n"
3024 " \n"
3025 " gl_FragColor = outColor;\n"
3026 "}\n";
3027
3028
3029 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3030 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3031 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3032 0.0, 1.0, 0.0, 1.0, // align
3033 0.0, 0.0, 1.0, 1.0, // align
3034 0.0, 0.0, 0.0, 1.0, // align
3035 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3036 0.0, 2.0, 0.0, 2.0, // align
3037 0.0, 0.0, 2.0, 2.0, // align
3038 0.0, 0.0, 0.0, 2.0, // align
3039 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3040 0.0, 3.0, 0.0, 3.0, // align
3041 0.0, 0.0, 3.0, 3.0, // align
3042 0.0, 0.0, 0.0, 3.0, // align
3043 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3044 0.0, 4.0, 0.0, 4.0, // align
3045 0.0, 0.0, 4.0, 4.0, // align
3046 0.0, 0.0, 0.0, 4.0, // align
3047 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3048 0.0, 5.0, 0.0, 5.0, // align
3049 0.0, 0.0, 5.0, 5.0, // align
3050 0.0, 0.0, 0.0, 5.0, // align
3051 6.0, 0.0, 0.0, 6.0, // align
3052 0.0, 6.0, 0.0, 6.0, // align
3053 0.0, 0.0, 6.0, 6.0, // align
3054 0.0, 0.0, 0.0, 6.0, // align
3055 7.0, 0.0, 0.0, 7.0, // align
3056 0.0, 7.0, 0.0, 7.0, // align
3057 0.0, 0.0, 7.0, 7.0, // align
3058 0.0, 0.0, 0.0, 7.0, // align
3059 8.0, 0.0, 0.0, 8.0, // align
3060 0.0, 8.0, 0.0, 8.0, // align
3061 0.0, 0.0, 8.0, 8.0, // align
3062 0.0, 0.0, 0.0, 8.0, // align
3063 0.0, // float fZero; // align
3064 1.0, // float fOne; // pack
3065 2.0, // float fTwo; // pack
3066 3.0, // float fThree; // pack
3067 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3068 4.0, // float fFour; // pack
3069 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3070 5.0, // float fFive; // pack
3071 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3072 6.0, // float fSix; // pack
3073 7.0, // float fSeven; // align
3074 8.0, // float fEight; // pack
3075 9.0, // float fNine; // pack
3076 0.0, // BUFFER
3077 0.0, 0.0, // vec2 fZeroZero; // align
3078 0.0, 1.0, // vec2 fZeroOne; // pack
3079 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3080 1.0, 0.0, // vec2 fOneZero; // align
3081 1.0, 1.0, // vec2 fOneOne; // pack
3082 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3083 10.0, // float fTen; // pack
3084 11.0, // float fEleven; // align
3085 12.0, // float fTwelve; // pack
3086 0.0, 0.0, // BUFFER
3087 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3088 0.0, // BUFFER
3089 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3090 0.5, 0.6, 0.7, 0.8, // align
3091 0.9, 1.0, 1.1, 1.2, // align
3092 1.3, 1.4, 1.5, 1.6, // align
3093 };
3094
3095 ASSERT_NO_FATAL_FAILURE(InitState());
3096 ASSERT_NO_FATAL_FAILURE(InitViewport());
3097
3098 const int constCount = sizeof(mixedVals) / sizeof(float);
3099
3100 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
3101 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
3102
3103 XglConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003104
3105 XglPipelineObj pipelineobj(m_device);
3106 pipelineobj.AddShader(&vs);
3107 pipelineobj.AddShader(&ps);
3108
3109 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08003110 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003111
3112 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3113 XglCommandBufferObj cmdBuffer(m_device);
3114 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3115
Jeremy Hayese0c3b222015-01-14 16:17:08 -07003116 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Cody Northrop02690bd2014-12-17 15:26:33 -07003117
3118 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
3119
3120#ifdef DUMP_STATE_DOT
3121 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
3122 pDSDumpDot((char*)"triTest2.dot");
3123#endif
3124 // render triangle
3125 cmdBuffer.Draw(0, 3, 0, 1);
3126
3127 // finalize recording of the command buffer
3128 cmdBuffer.EndCommandBuffer();
3129 cmdBuffer.QueueCommandBuffer(NULL, 0);
3130
3131 for (int i = 0; i < m_renderTargetCount; i++)
3132 RecordImage(m_renderTargets[i]);
3133}
3134
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003135int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003136 int result;
3137
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003138 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003139 XglTestFramework::InitArgs(&argc, argv);
3140
Chia-I Wu7133fdc2014-12-15 23:57:34 +08003141 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06003142
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003143 result = RUN_ALL_TESTS();
3144
3145 XglTestFramework::Finish();
3146 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003147}