blob: b3dc938cf89b0765247d36f67443fc8a2894449d [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;
Jon Ashburn542cd092015-01-20 13:55:32 -0700367 mem_alloc.memProps = XGL_MEMORY_PROPERTY_GPU_ONLY;
Jon Ashburn32769172015-01-20 15:06:59 -0700368 mem_alloc.memType = XGL_MEMORY_TYPE_IMAGE;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600369 mem_alloc.heapCount = 0;
370 mem_alloc.memPriority = XGL_MEMORY_PRIORITY_NORMAL;
371
372 /* create image */
373 err = xglCreateImage(device(), &image,
374 &m_depthStencilImage);
375 ASSERT_XGL_SUCCESS(err);
376
377 err = xglGetObjectInfo(m_depthStencilImage,
Jon Ashburna9ae3832015-01-16 09:37:43 -0700378 XGL_INFO_TYPE_MEMORY_ALLOCATION_COUNT,
379 &num_alloc_size, &num_allocations);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600380 ASSERT_XGL_SUCCESS(err);
Jon Ashburna9ae3832015-01-16 09:37:43 -0700381 ASSERT_EQ(num_alloc_size, sizeof(num_allocations));
382 mem_reqs = (XGL_MEMORY_REQUIREMENTS *) malloc(num_allocations * sizeof(XGL_MEMORY_REQUIREMENTS));
383 m_depthStencilMem = (XGL_GPU_MEMORY *) malloc(num_allocations * sizeof(XGL_GPU_MEMORY));
384 m_num_mem = num_allocations;
385 err = xglGetObjectInfo(m_depthStencilImage,
386 XGL_INFO_TYPE_MEMORY_REQUIREMENTS,
387 &mem_reqs_size, mem_reqs);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600388 ASSERT_XGL_SUCCESS(err);
Jon Ashburna9ae3832015-01-16 09:37:43 -0700389 ASSERT_EQ(mem_reqs_size, sizeof(*mem_reqs));
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700390 err = xglGetObjectInfo(m_depthStencilImage,
391 XGL_INFO_TYPE_IMAGE_MEMORY_REQUIREMENTS,
392 &img_reqs_size, &img_reqs);
393 ASSERT_XGL_SUCCESS(err);
394 ASSERT_EQ(img_reqs_size, sizeof(XGL_IMAGE_MEMORY_REQUIREMENTS));
395 img_alloc.usage = img_reqs.usage;
396 img_alloc.formatClass = img_reqs.formatClass;
397 img_alloc.samples = img_reqs.samples;
Jon Ashburna9ae3832015-01-16 09:37:43 -0700398 for (XGL_UINT i = 0; i < num_allocations; i ++) {
399 mem_alloc.allocationSize = mem_reqs[i].size;
400 mem_alloc.alignment = mem_reqs[i].alignment;
401 mem_alloc.heapCount = mem_reqs[i].heapCount;
402 XGL_UINT heapInfo[mem_reqs[i].heapCount];
403 mem_alloc.pHeaps = heapInfo;
404 memcpy(heapInfo, mem_reqs[i].pHeaps,
405 sizeof(mem_reqs[i].pHeaps[0]) * mem_reqs[i].heapCount);
406
407 /* allocate memory */
408 err = xglAllocMemory(device(), &mem_alloc, &m_depthStencilMem[i]);
409 ASSERT_XGL_SUCCESS(err);
410
411 /* bind memory */
412 err = xglBindObjectMemory(m_depthStencilImage, i,
413 m_depthStencilMem[i], 0);
414 ASSERT_XGL_SUCCESS(err);
415 }
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600416
Tony Barbourfa6cac72015-01-16 14:27:35 -0700417 XGL_DYNAMIC_DS_STATE_CREATE_INFO depthStencil = {};
418 depthStencil.sType = XGL_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO;
419
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600420 depthStencil.minDepth = 0.f;
421 depthStencil.maxDepth = 1.f;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700422 depthStencil.stencilBackRef = 0;
423 depthStencil.stencilFrontRef = 0;
424 depthStencil.stencilReadMask = 0xff;
425 depthStencil.stencilWriteMask = 0xff;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600426
Tony Barbourfa6cac72015-01-16 14:27:35 -0700427 err = xglCreateDynamicDepthStencilState( device(), &depthStencil, &m_stateDepthStencil );
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600428 ASSERT_XGL_SUCCESS( err );
429
430 /* create image view */
431 view.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO;
432 view.pNext = NULL;
433 view.image = XGL_NULL_HANDLE;
434 view.mipLevel = 0;
435 view.baseArraySlice = 0;
436 view.arraySize = 1;
437 view.flags = 0;
438 view.image = m_depthStencilImage;
439 err = xglCreateDepthStencilView(device(), &view, &m_depthStencilView);
440 ASSERT_XGL_SUCCESS(err);
441
442 m_depthStencilBinding.view = m_depthStencilView;
Mike Stroyan55658c22014-12-04 11:08:39 +0000443 m_depthStencilBinding.layout = XGL_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -0600444}
445
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600446struct xgltriangle_vs_uniform {
447 // Must start with MVP
448 XGL_FLOAT mvp[4][4];
449 XGL_FLOAT position[3][4];
450 XGL_FLOAT color[3][4];
451};
452
Tony Barbourae442072015-01-12 13:27:11 -0700453void XglRenderTest::XGLTriangleTest(const char *vertShaderText, const char *fragShaderText, const bool rotate)
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600454{
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700455#ifdef DEBUG_CALLBACK
456 xglDbgRegisterMsgCallback(myDbgFunc, NULL);
457#endif
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600458 // Create identity matrix
459 int i;
460 struct xgltriangle_vs_uniform data;
461
462 glm::mat4 Projection = glm::mat4(1.0f);
463 glm::mat4 View = glm::mat4(1.0f);
464 glm::mat4 Model = glm::mat4(1.0f);
465 glm::mat4 MVP = Projection * View * Model;
466 const int matrixSize = sizeof(MVP);
467 const int bufSize = sizeof(xgltriangle_vs_uniform) / sizeof(XGL_FLOAT);
468 memcpy(&data.mvp, &MVP[0][0], matrixSize);
469
470 static const Vertex tri_data[] =
471 {
472 { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) },
473 { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) },
474 { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) },
475 };
476
477 for (i=0; i<3; i++) {
478 data.position[i][0] = tri_data[i].posX;
479 data.position[i][1] = tri_data[i].posY;
480 data.position[i][2] = tri_data[i].posZ;
481 data.position[i][3] = tri_data[i].posW;
482 data.color[i][0] = tri_data[i].r;
483 data.color[i][1] = tri_data[i].g;
484 data.color[i][2] = tri_data[i].b;
485 data.color[i][3] = tri_data[i].a;
486 }
487
Tony Barbourf43b6982014-11-25 13:18:32 -0700488 ASSERT_NO_FATAL_FAILURE(InitState());
489 ASSERT_NO_FATAL_FAILURE(InitViewport());
490
491 XglConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(XGL_FLOAT), (const void*) &data);
492
493 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
494 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Tony Barbourf43b6982014-11-25 13:18:32 -0700495
496 XglPipelineObj pipelineobj(m_device);
497 pipelineobj.AddShader(&vs);
498 pipelineobj.AddShader(&ps);
499
500 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +0800501 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &constantBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700502 m_memoryRefManager.AddMemoryRef(&constantBuffer);
503
Tony Barbour71ba3612015-01-09 16:12:35 -0700504 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
505 XglCommandBufferObj cmdBuffer(m_device);
506 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700507
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700508 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour71ba3612015-01-09 16:12:35 -0700509
510 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
511
512 cmdBuffer.BindVertexBuffer(&constantBuffer, 0, 0);
513#ifdef DUMP_STATE_DOT
514 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
515 pDSDumpDot((char*)"triTest2.dot");
516#endif
517 // render triangle
518 cmdBuffer.Draw(0, 3, 0, 1);
519
520 // finalize recording of the command buffer
521 cmdBuffer.EndCommandBuffer();
522 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
523
524 for (int i = 0; i < m_renderTargetCount; i++)
525 RecordImage(m_renderTargets[i]);
526
527 if (rotate)
528 RotateTriangleVSUniform(Projection, View, Model, &constantBuffer, &cmdBuffer);
529
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700530#ifdef PRINT_OBJECTS
531 //XGL_UINT64 objTrackGetObjectCount(XGL_OBJECT_TYPE type)
532 OBJ_TRACK_GET_OBJECT_COUNT pObjTrackGetObjectCount = (OBJ_TRACK_GET_OBJECT_COUNT)xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjectCount");
533 XGL_UINT64 numObjects = pObjTrackGetObjectCount(XGL_OBJECT_TYPE_ANY);
534 //OBJ_TRACK_GET_OBJECTS pGetObjsFunc = xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjects");
535 printf("DEBUG : Number of Objects : %lu\n", numObjects);
536 OBJ_TRACK_GET_OBJECTS pObjTrackGetObjs = (OBJ_TRACK_GET_OBJECTS)xglGetProcAddr(gpu(), (XGL_CHAR*)"objTrackGetObjects");
537 OBJTRACK_NODE* pObjNodeArray = (OBJTRACK_NODE*)malloc(sizeof(OBJTRACK_NODE)*numObjects);
538 pObjTrackGetObjs(XGL_OBJECT_TYPE_ANY, numObjects, pObjNodeArray);
539 for (i=0; i < numObjects; i++) {
540 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);
541 }
542 free(pObjNodeArray);
543#endif
Tony Barbourf43b6982014-11-25 13:18:32 -0700544
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600545}
546
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600547TEST_F(XglRenderTest, XGLTriangle_FragColor)
548{
549 static const char *vertShaderText =
550 "#version 140\n"
551 "#extension GL_ARB_separate_shader_objects : enable\n"
552 "#extension GL_ARB_shading_language_420pack : enable\n"
553 "\n"
554 "layout(binding = 0) uniform buf {\n"
555 " mat4 MVP;\n"
556 " vec4 position[3];\n"
557 " vec4 color[3];\n"
558 "} ubuf;\n"
559 "\n"
560 "layout (location = 0) out vec4 outColor;\n"
561 "\n"
562 "void main() \n"
563 "{\n"
564 " outColor = ubuf.color[gl_VertexID];\n"
565 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
566 "}\n";
567
568 static const char *fragShaderText =
569 "#version 140\n"
570 "#extension GL_ARB_separate_shader_objects : enable\n"
571 "#extension GL_ARB_shading_language_420pack : enable\n"
572 "\n"
573 "layout (location = 0) in vec4 inColor;\n"
574 "\n"
575 "void main()\n"
576 "{\n"
577 " gl_FragColor = inColor;\n"
578 "}\n";
579
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600580 TEST_DESCRIPTION("XGL-style shaders where fragment shader outputs to GLSL built-in gl_FragColor");
Tony Barbourae442072015-01-12 13:27:11 -0700581 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600582}
583
584TEST_F(XglRenderTest, XGLTriangle_OutputLocation)
585{
586 static const char *vertShaderText =
587 "#version 140\n"
588 "#extension GL_ARB_separate_shader_objects : enable\n"
589 "#extension GL_ARB_shading_language_420pack : enable\n"
590 "\n"
591 "layout(binding = 0) uniform buf {\n"
592 " mat4 MVP;\n"
593 " vec4 position[3];\n"
594 " vec4 color[3];\n"
595 "} ubuf;\n"
596 "\n"
597 "layout (location = 0) out vec4 outColor;\n"
598 "\n"
599 "void main() \n"
600 "{\n"
601 " outColor = ubuf.color[gl_VertexID];\n"
602 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
603 "}\n";
604
605 static const char *fragShaderText =
606 "#version 140\n"
607 "#extension GL_ARB_separate_shader_objects : enable\n"
608 "#extension GL_ARB_shading_language_420pack : enable\n"
609 "\n"
610 "layout (location = 0) in vec4 inColor;\n"
611 "layout (location = 0) out vec4 outColor;\n"
612 "\n"
613 "void main()\n"
614 "{\n"
615 " outColor = inColor;\n"
616 "}\n";
617
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600618 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 -0600619
Tony Barbourae442072015-01-12 13:27:11 -0700620 XGLTriangleTest(vertShaderText, fragShaderText, true);
Courtney Goeltzenleuchter6acb8022014-10-27 13:08:55 -0600621}
622
Tony Barbourf43b6982014-11-25 13:18:32 -0700623TEST_F(XglRenderTest, BIL_XGLTriangle)
624{
625 bool saved_use_bil = XglTestFramework::m_use_bil;
626
627 static const char *vertShaderText =
628 "#version 140\n"
629 "#extension GL_ARB_separate_shader_objects : enable\n"
630 "#extension GL_ARB_shading_language_420pack : enable\n"
631 "\n"
632 "layout(binding = 0) uniform buf {\n"
633 " mat4 MVP;\n"
634 " vec4 position[3];\n"
635 " vec4 color[3];\n"
636 "} ubuf;\n"
637 "\n"
638 "layout (location = 0) out vec4 outColor;\n"
639 "\n"
640 "void main() \n"
641 "{\n"
642 " outColor = ubuf.color[gl_VertexID];\n"
643 " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n"
644 "}\n";
645
646 static const char *fragShaderText =
647 "#version 140\n"
648 "#extension GL_ARB_separate_shader_objects : enable\n"
649 "#extension GL_ARB_shading_language_420pack : enable\n"
650 "\n"
651 "layout (location = 0) in vec4 inColor;\n"
652 "\n"
653 "void main()\n"
654 "{\n"
655 " gl_FragColor = inColor;\n"
656 "}\n";
657
658 TEST_DESCRIPTION("XGL-style shaders, but force test framework to compile shader to BIL and pass BIL to driver.");
659
660 XglTestFramework::m_use_bil = true;
661
Tony Barbourae442072015-01-12 13:27:11 -0700662 XGLTriangleTest(vertShaderText, fragShaderText, true);
Tony Barbourf43b6982014-11-25 13:18:32 -0700663
664 XglTestFramework::m_use_bil = saved_use_bil;
665}
666
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600667TEST_F(XglRenderTest, GreenTriangle)
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600668{
669 static const char *vertShaderText =
670 "#version 130\n"
671 "vec2 vertices[3];\n"
672 "void main() {\n"
673 " vertices[0] = vec2(-1.0, -1.0);\n"
674 " vertices[1] = vec2( 1.0, -1.0);\n"
675 " vertices[2] = vec2( 0.0, 1.0);\n"
676 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
677 "}\n";
Courtney Goeltzenleuchter98e49432014-10-09 15:40:19 -0600678
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600679 static const char *fragShaderText =
680 "#version 130\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600681 "void main() {\n"
Steve K10b32512014-10-10 08:54:29 -0600682 " gl_FragColor = vec4(0,1,0,1);\n"
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600683 "}\n";
Courtney Goeltzenleuchter7bbb4202014-10-24 16:26:12 -0600684
Courtney Goeltzenleuchtereab90102014-10-27 13:09:23 -0600685 TEST_DESCRIPTION("Basic shader that renders a fixed Green triangle coded as part of the vertex shader.");
686
Tony Barbourae442072015-01-12 13:27:11 -0700687 XGLTriangleTest(vertShaderText, fragShaderText, false);
Cody Northrop5b7d85a2014-10-09 21:26:47 -0600688}
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600689
Tony Barbourf43b6982014-11-25 13:18:32 -0700690TEST_F(XglRenderTest, BIL_GreenTriangle)
691{
692 bool saved_use_bil = XglTestFramework::m_use_bil;
693
694 static const char *vertShaderText =
695 "#version 130\n"
696 "vec2 vertices[3];\n"
697 "void main() {\n"
698 " vertices[0] = vec2(-1.0, -1.0);\n"
699 " vertices[1] = vec2( 1.0, -1.0);\n"
700 " vertices[2] = vec2( 0.0, 1.0);\n"
701 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
702 "}\n";
703
704 static const char *fragShaderText =
705 "#version 130\n"
706 "void main() {\n"
707 " gl_FragColor = vec4(0,1,0,1);\n"
708 "}\n";
709
710 TEST_DESCRIPTION("Same shader as GreenTriangle, but compiles shader to BIL and gives BIL to driver.");
711
712 XglTestFramework::m_use_bil = true;
Tony Barbourae442072015-01-12 13:27:11 -0700713 XGLTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700714 XglTestFramework::m_use_bil = saved_use_bil;
715}
716
717TEST_F(XglRenderTest, YellowTriangle)
718{
719 static const char *vertShaderText =
720 "#version 130\n"
721 "void main() {\n"
722 " vec2 vertices[3];"
723 " vertices[0] = vec2(-0.5, -0.5);\n"
724 " vertices[1] = vec2( 0.5, -0.5);\n"
725 " vertices[2] = vec2( 0.5, 0.5);\n"
726 " vec4 colors[3];\n"
727 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
728 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
729 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
730 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
731 "}\n";
732
733 static const char *fragShaderText =
734 "#version 130\n"
735 "void main() {\n"
736 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
737 "}\n";
738
Tony Barbourae442072015-01-12 13:27:11 -0700739 XGLTriangleTest(vertShaderText, fragShaderText, false);
Tony Barbourf43b6982014-11-25 13:18:32 -0700740}
741
Courtney Goeltzenleuchter08ccb482014-10-10 17:02:53 -0600742TEST_F(XglRenderTest, TriangleWithVertexFetch)
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600743{
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -0600744 static const char *vertShaderText =
Tony Barbourf43b6982014-11-25 13:18:32 -0700745 "#version 130\n"
746 //XYZ1( -1, -1, -1 )
747 "in vec4 pos;\n"
748 //XYZ1( 0.f, 0.f, 0.f )
749 "in vec4 inColor;\n"
750 "out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600751 "void main() {\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -0600752 " outColor = inColor;\n"
Cody Northrop4e6b4762014-10-09 21:25:22 -0600753 " gl_Position = pos;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600754 "}\n";
755
Cody Northrop0dbe84f2014-10-09 19:55:56 -0600756
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600757 static const char *fragShaderText =
Cody Northrop68a10f62014-12-05 15:44:14 -0700758 "#version 140\n"
759 "#extension GL_ARB_separate_shader_objects : enable\n"
760 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -0700761 "in vec4 color;\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700762 "layout (location = 0) out vec4 outColor;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600763 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -0700764 " outColor = color;\n"
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600765 "}\n";
Courtney Goeltzenleuchter9b4ab892014-10-09 15:37:21 -0600766
Tony Barbourf43b6982014-11-25 13:18:32 -0700767
768
769 ASSERT_NO_FATAL_FAILURE(InitState());
770 ASSERT_NO_FATAL_FAILURE(InitViewport());
771
772 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000773 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -0700774
775 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
776 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
777
778 XglPipelineObj pipelineobj(m_device);
779 pipelineobj.AddShader(&vs);
780 pipelineobj.AddShader(&ps);
781
782 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +0800783 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -0700784
785 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
786 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
787 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
788 };
789
790 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
791 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
792 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
793 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
794 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
795 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
796 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
797 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
798 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
799
800 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
801 pipelineobj.AddVertexInputBindings(&vi_binding,1);
802 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
803
Tony Barboure4ed9942015-01-09 10:06:53 -0700804 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
805 XglCommandBufferObj cmdBuffer(m_device);
806 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -0700807
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700808 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -0700809 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
810
Tony Barboure4ed9942015-01-09 10:06:53 -0700811 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
812
813 // render two triangles
814 cmdBuffer.Draw(0, 6, 0, 1);
815
816 // finalize recording of the command buffer
817 cmdBuffer.EndCommandBuffer();
818 cmdBuffer.QueueCommandBuffer(NULL, 0);
819
820 for (int i = 0; i < m_renderTargetCount; i++)
821 RecordImage(m_renderTargets[i]);
Tobin Ehlis34e0e442014-10-07 14:41:29 -0600822}
823
Chia-I Wue09d1a72014-12-05 10:32:23 +0800824TEST_F(XglRenderTest, TriangleMRT)
825{
826 static const char *vertShaderText =
827 "#version 130\n"
828 "in vec4 pos;\n"
829 "void main() {\n"
830 " gl_Position = pos;\n"
831 "}\n";
832
833 static const char *fragShaderText =
834 "#version 130\n"
835 "void main() {\n"
836 " gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
837 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
838 "}\n";
839 const XGL_FLOAT vb_data[][2] = {
840 { -1.0f, -1.0f },
841 { 1.0f, -1.0f },
842 { -1.0f, 1.0f }
843 };
844
845 ASSERT_NO_FATAL_FAILURE(InitState());
846 ASSERT_NO_FATAL_FAILURE(InitViewport());
847
848 XglConstantBufferObj meshBuffer(m_device, sizeof(vb_data) / sizeof(vb_data[0]), sizeof(vb_data[0]), vb_data);
Mike Stroyan55658c22014-12-04 11:08:39 +0000849 meshBuffer.BufferMemoryBarrier();
Chia-I Wue09d1a72014-12-05 10:32:23 +0800850
851 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
852 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
853
854 XglPipelineObj pipelineobj(m_device);
855 pipelineobj.AddShader(&vs);
856 pipelineobj.AddShader(&ps);
857
858 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
859 sizeof(vb_data[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
860 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
861 };
862
863 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attrib;
864 vi_attrib.binding = 0; // index into vertexBindingDescriptions
865 vi_attrib.format.channelFormat = XGL_CH_FMT_R32G32; // format of source data
866 vi_attrib.format.numericFormat = XGL_NUM_FMT_FLOAT;
867 vi_attrib.offsetInBytes = 0; // Offset of first element in bytes from base of vertex
868
869 pipelineobj.AddVertexInputAttribs(&vi_attrib, 1);
870 pipelineobj.AddVertexInputBindings(&vi_binding,1);
871 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
872
873 XglDescriptorSetObj descriptorSet(m_device);
874
875 m_renderTargetCount = 2;
Tony Barboure4ed9942015-01-09 10:06:53 -0700876 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wue09d1a72014-12-05 10:32:23 +0800877
878 XGL_PIPELINE_CB_ATTACHMENT_STATE att = {};
879 att.blendEnable = XGL_FALSE;
880 att.format = m_render_target_fmt;
881 att.channelWriteMask = 0xf;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700882 pipelineobj.AddColorAttachment(1, &att);
Chia-I Wue09d1a72014-12-05 10:32:23 +0800883
Tony Barbour5ed79702015-01-07 14:31:52 -0700884 XglCommandBufferObj cmdBuffer(m_device);
Tony Barboure4ed9942015-01-09 10:06:53 -0700885
Tony Barbour5ed79702015-01-07 14:31:52 -0700886 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
887 cmdBuffer.AddRenderTarget(m_renderTargets[1]);
Tony Barboure4ed9942015-01-09 10:06:53 -0700888
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700889 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbour5ed79702015-01-07 14:31:52 -0700890
Tony Barboure4ed9942015-01-09 10:06:53 -0700891 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
892
Tony Barbour5ed79702015-01-07 14:31:52 -0700893 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
Tony Barbour5ed79702015-01-07 14:31:52 -0700894#ifdef DUMP_STATE_DOT
895 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
896 pDSDumpDot((char*)"triTest2.dot");
897#endif
898 // render triangle
899 cmdBuffer.Draw(0, 3, 0, 1);
900
901 // finalize recording of the command buffer
902 cmdBuffer.EndCommandBuffer();
903 cmdBuffer.QueueCommandBuffer(NULL, 0);
904
905 for (int i = 0; i < m_renderTargetCount; i++)
906 RecordImage(m_renderTargets[i]);
907
Chia-I Wue09d1a72014-12-05 10:32:23 +0800908}
909
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700910TEST_F(XglRenderTest, QuadWithIndexedVertexFetch)
911{
912 static const char *vertShaderText =
913 "#version 140\n"
914 "#extension GL_ARB_separate_shader_objects : enable\n"
915 "#extension GL_ARB_shading_language_420pack : enable\n"
916 "layout(location = 0) in vec4 pos;\n"
917 "layout(location = 1) in vec4 inColor;\n"
918 "layout(location = 0) out vec4 outColor;\n"
919 "void main() {\n"
920 " outColor = inColor;\n"
921 " gl_Position = pos;\n"
922 "}\n";
923
924
925 static const char *fragShaderText =
926 "#version 140\n"
927 "#extension GL_ARB_separate_shader_objects : enable\n"
928 "#extension GL_ARB_shading_language_420pack : enable\n"
929 "layout(location = 0) in vec4 color;\n"
930 "void main() {\n"
931 " gl_FragColor = color;\n"
932 "}\n";
933
934 const Vertex g_vbData[] =
935 {
936 // first tri
937 { XYZ1( -1, -1, -1 ), XYZ1( 0.f, 0.f, 0.f ) }, // LL: black
938 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
939 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
940
941 // second tri
942 { XYZ1( -1, 1, -1 ), XYZ1( 0.f, 1.f, 0.f ) }, // UL: green
943 { XYZ1( 1, -1, -1 ), XYZ1( 1.f, 0.f, 0.f ) }, // LR: red
944 { XYZ1( 1, 1, -1 ), XYZ1( 1.f, 1.f, 0.f ) }, // UR: yellow
945 };
946
947 const uint16_t g_idxData[6] = {
948 0, 1, 2,
949 3, 4, 5,
950 };
951
952 ASSERT_NO_FATAL_FAILURE(InitState());
953 ASSERT_NO_FATAL_FAILURE(InitViewport());
954
955 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000956 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700957
958 XglIndexBufferObj indexBuffer(m_device);
959 indexBuffer.CreateAndInitBuffer(sizeof(g_idxData)/sizeof(g_idxData[0]), XGL_INDEX_16, g_idxData);
Mike Stroyan55658c22014-12-04 11:08:39 +0000960 meshBuffer.BufferMemoryBarrier();
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700961
962 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
963 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
964
965 XglPipelineObj pipelineobj(m_device);
966 pipelineobj.AddShader(&vs);
967 pipelineobj.AddShader(&ps);
968
969 XglDescriptorSetObj descriptorSet(m_device);
970
971 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
972 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
973 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
974 };
975
976 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
977 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
978 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
979 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
980 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
981 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
982 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
983 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
984 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
985
986 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
987 pipelineobj.AddVertexInputBindings(&vi_binding,1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700988
989 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourde9cf2e2014-12-17 11:16:05 -0700990 XglCommandBufferObj cmdBuffer(m_device);
991 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700992 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -0700993
994 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700995
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700996#ifdef DUMP_STATE_DOT
997 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
Tobin Ehlis266473d2014-12-16 17:34:50 -0700998 pDSDumpDot((char*)"triTest2.dot");
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -0700999#endif
Tony Barbour02472db2015-01-08 17:08:28 -07001000
Tony Barbourde9cf2e2014-12-17 11:16:05 -07001001 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1002 cmdBuffer.BindIndexBuffer(&indexBuffer,0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001003
1004 // render two triangles
Tony Barbourde9cf2e2014-12-17 11:16:05 -07001005 cmdBuffer.DrawIndexed(0, 6, 0, 0, 1);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001006
1007 // finalize recording of the command buffer
Tony Barbourde9cf2e2014-12-17 11:16:05 -07001008 cmdBuffer.EndCommandBuffer();
1009 cmdBuffer.QueueCommandBuffer(NULL, 0);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001010
Tony Barbourde9cf2e2014-12-17 11:16:05 -07001011 for (int i = 0; i < m_renderTargetCount; i++)
1012 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchter4d6fbeb2014-12-04 15:45:16 -07001013
1014}
1015
GregF6bef1212014-12-02 15:41:44 -07001016TEST_F(XglRenderTest, GreyandRedCirclesonBlue)
1017{
1018 // This tests gl_FragCoord
Tony Barbourf43b6982014-11-25 13:18:32 -07001019
GregF6bef1212014-12-02 15:41:44 -07001020 static const char *vertShaderText =
1021 "#version 140\n"
1022 "#extension GL_ARB_separate_shader_objects : enable\n"
1023 "#extension GL_ARB_shading_language_420pack : enable\n"
1024 "layout (location = 0) in vec4 pos;\n"
1025 "layout (location = 0) out vec4 outColor;\n"
1026 "layout (location = 1) out vec4 outColor2;\n"
1027 "void main() {\n"
1028 " gl_Position = pos;\n"
1029 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1030 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1031 "}\n";
1032
1033 static const char *fragShaderText =
1034 //"#version 140\n"
1035 "#version 330\n"
1036 "#extension GL_ARB_separate_shader_objects : enable\n"
1037 "#extension GL_ARB_shading_language_420pack : enable\n"
1038 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1039 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1040 "layout (location = 0) in vec4 color;\n"
1041 "layout (location = 1) in vec4 color2;\n"
1042 "void main() {\n"
1043 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1044 " float dist_squared = dot(pos, pos);\n"
1045 " gl_FragColor = (dist_squared < 400.0)\n"
1046 " ? ((gl_FragCoord.y < 100.0) ? vec4(1.0, 0.0, 0.0, 0.0) : color)\n"
1047 " : color2;\n"
1048 "}\n";
1049
1050 ASSERT_NO_FATAL_FAILURE(InitState());
1051 ASSERT_NO_FATAL_FAILURE(InitViewport());
1052
1053 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001054 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001055
1056 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1057 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1058
1059 XglPipelineObj pipelineobj(m_device);
1060 pipelineobj.AddShader(&vs);
1061 pipelineobj.AddShader(&ps);
1062
1063 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001064 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001065
1066 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1067 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1068 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1069 };
1070
1071 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1072 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1073 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1074 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1075 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1076 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1077 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1078 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1079 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1080
1081 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1082 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1083 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1084
Tony Barbourdd4c9642015-01-09 12:55:14 -07001085 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1086 XglCommandBufferObj cmdBuffer(m_device);
1087 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1088
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001089 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001090
1091 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1092
1093 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1094#ifdef DUMP_STATE_DOT
1095 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1096 pDSDumpDot((char*)"triTest2.dot");
1097#endif
1098 // render triangle
1099 cmdBuffer.Draw(0, 6, 0, 1);
1100
1101 // finalize recording of the command buffer
1102 cmdBuffer.EndCommandBuffer();
1103 cmdBuffer.QueueCommandBuffer(NULL, 0);
1104
1105 for (int i = 0; i < m_renderTargetCount; i++)
1106 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001107
1108}
1109
1110TEST_F(XglRenderTest, RedCirclesonBlue)
1111{
1112 // This tests that we correctly handle unread fragment inputs
1113
1114 static const char *vertShaderText =
1115 "#version 140\n"
1116 "#extension GL_ARB_separate_shader_objects : enable\n"
1117 "#extension GL_ARB_shading_language_420pack : enable\n"
1118 "layout (location = 0) in vec4 pos;\n"
1119 "layout (location = 0) out vec4 outColor;\n"
1120 "layout (location = 1) out vec4 outColor2;\n"
1121 "void main() {\n"
1122 " gl_Position = pos;\n"
1123 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1124 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1125 "}\n";
1126
1127 static const char *fragShaderText =
1128 //"#version 140\n"
1129 "#version 330\n"
1130 "#extension GL_ARB_separate_shader_objects : enable\n"
1131 "#extension GL_ARB_shading_language_420pack : enable\n"
1132 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1133 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1134 "layout (location = 0) in vec4 color;\n"
1135 "layout (location = 1) in vec4 color2;\n"
1136 "void main() {\n"
1137 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1138 " float dist_squared = dot(pos, pos);\n"
1139 " gl_FragColor = (dist_squared < 400.0)\n"
1140 " ? vec4(1.0, 0.0, 0.0, 1.0)\n"
1141 " : color2;\n"
1142 "}\n";
1143
1144 ASSERT_NO_FATAL_FAILURE(InitState());
1145 ASSERT_NO_FATAL_FAILURE(InitViewport());
1146
1147 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001148 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001149
1150 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1151 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1152
1153 XglPipelineObj pipelineobj(m_device);
1154 pipelineobj.AddShader(&vs);
1155 pipelineobj.AddShader(&ps);
1156
1157 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001158 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001159
1160 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1161 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1162 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1163 };
1164
1165 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1166 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1167 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1168 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1169 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1170 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1171 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1172 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1173 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1174
1175 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1176 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1177 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1178
Tony Barbourdd4c9642015-01-09 12:55:14 -07001179 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1180 XglCommandBufferObj cmdBuffer(m_device);
1181 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1182
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001183 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001184
1185 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1186
1187 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1188#ifdef DUMP_STATE_DOT
1189 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1190 pDSDumpDot((char*)"triTest2.dot");
1191#endif
1192 // render triangle
1193 cmdBuffer.Draw(0, 6, 0, 1);
1194
1195 // finalize recording of the command buffer
1196 cmdBuffer.EndCommandBuffer();
1197 cmdBuffer.QueueCommandBuffer(NULL, 0);
1198
1199 for (int i = 0; i < m_renderTargetCount; i++)
1200 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001201
1202}
1203
1204TEST_F(XglRenderTest, GreyCirclesonBlueFade)
1205{
1206 // This tests reading gl_ClipDistance from FS
1207
1208 static const char *vertShaderText =
1209 "#version 330\n"
1210 "#extension GL_ARB_separate_shader_objects : enable\n"
1211 "#extension GL_ARB_shading_language_420pack : enable\n"
1212 "out gl_PerVertex {\n"
1213 " vec4 gl_Position;\n"
1214 " float gl_ClipDistance[1];\n"
1215 "};\n"
1216 "layout (location = 0) in vec4 pos;\n"
1217 "layout (location = 0) out vec4 outColor;\n"
1218 "layout (location = 1) out vec4 outColor2;\n"
1219 "void main() {\n"
1220 " gl_Position = pos;\n"
1221 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1222 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1223 " float dists[3];\n"
1224 " dists[0] = 0.0;\n"
1225 " dists[1] = 1.0;\n"
1226 " dists[2] = 1.0;\n"
1227 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
1228 "}\n";
1229
1230
1231 static const char *fragShaderText =
1232 //"#version 140\n"
1233 "#version 330\n"
1234 "#extension GL_ARB_separate_shader_objects : enable\n"
1235 "#extension GL_ARB_shading_language_420pack : enable\n"
1236 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1237 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1238 "layout (location = 0) in vec4 color;\n"
1239 "layout (location = 1) in vec4 color2;\n"
1240 "void main() {\n"
1241 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1242 " float dist_squared = dot(pos, pos);\n"
1243 " gl_FragColor = (dist_squared < 400.0)\n"
1244 " ? color * gl_ClipDistance[0]\n"
1245 " : color2;\n"
1246 "}\n";
1247
1248 ASSERT_NO_FATAL_FAILURE(InitState());
1249 ASSERT_NO_FATAL_FAILURE(InitViewport());
1250
1251 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001252 meshBuffer.BufferMemoryBarrier();
GregF6bef1212014-12-02 15:41:44 -07001253
1254 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1255 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1256
1257 XglPipelineObj pipelineobj(m_device);
1258 pipelineobj.AddShader(&vs);
1259 pipelineobj.AddShader(&ps);
1260
1261 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001262 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF6bef1212014-12-02 15:41:44 -07001263
1264 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1265 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1266 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1267 };
1268
1269 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1270 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1271 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1272 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1273 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1274 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1275 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1276 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1277 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1278
1279 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1280 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1281 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1282
Tony Barbourdd4c9642015-01-09 12:55:14 -07001283 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1284 XglCommandBufferObj cmdBuffer(m_device);
1285 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
GregF6bef1212014-12-02 15:41:44 -07001286
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001287 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001288
1289 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1290
1291 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1292#ifdef DUMP_STATE_DOT
1293 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1294 pDSDumpDot((char*)"triTest2.dot");
1295#endif
1296 // render triangle
1297 cmdBuffer.Draw(0, 6, 0, 1);
1298
1299 // finalize recording of the command buffer
1300 cmdBuffer.EndCommandBuffer();
1301 cmdBuffer.QueueCommandBuffer(NULL, 0);
1302
1303 for (int i = 0; i < m_renderTargetCount; i++)
1304 RecordImage(m_renderTargets[i]);
GregF6bef1212014-12-02 15:41:44 -07001305}
Tony Barbourf43b6982014-11-25 13:18:32 -07001306
GregF7a23c792014-12-02 17:19:34 -07001307TEST_F(XglRenderTest, GreyCirclesonBlueDiscard)
1308{
1309 static const char *vertShaderText =
1310 "#version 140\n"
1311 "#extension GL_ARB_separate_shader_objects : enable\n"
1312 "#extension GL_ARB_shading_language_420pack : enable\n"
1313 "layout (location = 0) in vec4 pos;\n"
1314 "layout (location = 0) out vec4 outColor;\n"
1315 "layout (location = 1) out vec4 outColor2;\n"
1316 "void main() {\n"
1317 " gl_Position = pos;\n"
1318 " outColor = vec4(0.9, 0.9, 0.9, 1.0);\n"
1319 " outColor2 = vec4(0.2, 0.2, 0.4, 1.0);\n"
1320 "}\n";
1321
1322
1323 static const char *fragShaderText =
1324 //"#version 140\n"
1325 "#version 330\n"
1326 "#extension GL_ARB_separate_shader_objects : enable\n"
1327 "#extension GL_ARB_shading_language_420pack : enable\n"
1328 //"#extension GL_ARB_fragment_coord_conventions : enable\n"
1329 //"layout (pixel_center_integer) in vec4 gl_FragCoord;\n"
1330 "layout (location = 0) in vec4 color;\n"
1331 "layout (location = 1) in vec4 color2;\n"
1332 "void main() {\n"
1333 " vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);\n"
1334 " float dist_squared = dot(pos, pos);\n"
1335 " if (dist_squared < 100.0)\n"
1336 " discard;\n"
1337 " gl_FragColor = (dist_squared < 400.0)\n"
1338 " ? color\n"
1339 " : color2;\n"
1340 "}\n";
1341
1342 ASSERT_NO_FATAL_FAILURE(InitState());
1343 ASSERT_NO_FATAL_FAILURE(InitViewport());
1344
1345 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001346 meshBuffer.BufferMemoryBarrier();
GregF7a23c792014-12-02 17:19:34 -07001347
1348 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1349 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1350
1351 XglPipelineObj pipelineobj(m_device);
1352 pipelineobj.AddShader(&vs);
1353 pipelineobj.AddShader(&ps);
1354
1355 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001356 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
GregF7a23c792014-12-02 17:19:34 -07001357
1358 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1359 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1360 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1361 };
1362
1363 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1364 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1365 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1366 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1367 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1368 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1369 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1370 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1371 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1372
1373 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1374 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1375 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1376
Tony Barbourdd4c9642015-01-09 12:55:14 -07001377 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1378 XglCommandBufferObj cmdBuffer(m_device);
1379 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1380
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001381 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001382
1383 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1384
1385 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1386#ifdef DUMP_STATE_DOT
1387 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1388 pDSDumpDot((char*)"triTest2.dot");
1389#endif
1390 // render triangle
1391 cmdBuffer.Draw(0, 6, 0, 1);
1392
1393 // finalize recording of the command buffer
1394 cmdBuffer.EndCommandBuffer();
1395 cmdBuffer.QueueCommandBuffer(NULL, 0);
1396
1397 for (int i = 0; i < m_renderTargetCount; i++)
1398 RecordImage(m_renderTargets[i]);
GregF7a23c792014-12-02 17:19:34 -07001399
1400}
1401
1402
Courtney Goeltzenleuchter3d10c9c2014-10-27 13:06:08 -06001403TEST_F(XglRenderTest, TriangleVSUniform)
Cody Northrop7a1f0462014-10-10 14:49:36 -06001404{
1405 static const char *vertShaderText =
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001406 "#version 140\n"
1407 "#extension GL_ARB_separate_shader_objects : enable\n"
1408 "#extension GL_ARB_shading_language_420pack : enable\n"
1409 "\n"
1410 "layout(binding = 0) uniform buf {\n"
1411 " mat4 MVP;\n"
1412 "} ubuf;\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001413 "void main() {\n"
1414 " vec2 vertices[3];"
1415 " vertices[0] = vec2(-0.5, -0.5);\n"
1416 " vertices[1] = vec2( 0.5, -0.5);\n"
1417 " vertices[2] = vec2( 0.5, 0.5);\n"
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001418 " gl_Position = ubuf.MVP * vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001419 "}\n";
1420
1421 static const char *fragShaderText =
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001422 "#version 130\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001423 "void main() {\n"
Cody Northrop78eac042014-10-10 15:45:00 -06001424 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
Cody Northrop7a1f0462014-10-10 14:49:36 -06001425 "}\n";
1426
Tony Barbourf43b6982014-11-25 13:18:32 -07001427 ASSERT_NO_FATAL_FAILURE(InitState());
1428 ASSERT_NO_FATAL_FAILURE(InitViewport());
1429
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -06001430 // Create identity matrix
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001431 glm::mat4 Projection = glm::mat4(1.0f);
1432 glm::mat4 View = glm::mat4(1.0f);
1433 glm::mat4 Model = glm::mat4(1.0f);
1434 glm::mat4 MVP = Projection * View * Model;
1435 const int matrixSize = sizeof(MVP) / sizeof(MVP[0]);
1436
Tony Barbourf43b6982014-11-25 13:18:32 -07001437 XglConstantBufferObj MVPBuffer(m_device, matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1438 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1439 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001440
Tony Barbourf43b6982014-11-25 13:18:32 -07001441 XglPipelineObj pipelineobj(m_device);
1442 pipelineobj.AddShader(&vs);
1443 pipelineobj.AddShader(&ps);
1444
1445 // Create descriptor set and attach the constant buffer to it
1446 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001447 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001448
1449 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1450
Tony Barbourdd4c9642015-01-09 12:55:14 -07001451 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1452 XglCommandBufferObj cmdBuffer(m_device);
1453 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001454
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001455 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001456
1457 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1458
1459 // cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1460#ifdef DUMP_STATE_DOT
1461 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1462 pDSDumpDot((char*)"triTest2.dot");
1463#endif
1464 // render triangle
1465 cmdBuffer.Draw(0, 6, 0, 1);
1466
1467 // finalize recording of the command buffer
1468 cmdBuffer.EndCommandBuffer();
1469 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
1470
1471 for (int i = 0; i < m_renderTargetCount; i++)
1472 RecordImage(m_renderTargets[i]);
1473
1474 RotateTriangleVSUniform(Projection, View, Model, &MVPBuffer, &cmdBuffer);
Courtney Goeltzenleuchterc3f4ac82014-10-27 09:48:52 -06001475}
1476
Tony Barbourf43b6982014-11-25 13:18:32 -07001477TEST_F(XglRenderTest, MixTriangle)
1478{
1479 // This tests location applied to varyings. Notice that we have switched foo
1480 // and bar in the FS. The triangle should be blended with red, green and blue
1481 // corners.
1482 static const char *vertShaderText =
1483 "#version 140\n"
1484 "#extension GL_ARB_separate_shader_objects : enable\n"
1485 "#extension GL_ARB_shading_language_420pack : enable\n"
1486 "layout (location=0) out vec4 bar;\n"
1487 "layout (location=1) out vec4 foo;\n"
1488 "layout (location=2) out float scale;\n"
1489 "vec2 vertices[3];\n"
1490 "void main() {\n"
1491 " vertices[0] = vec2(-1.0, -1.0);\n"
1492 " vertices[1] = vec2( 1.0, -1.0);\n"
1493 " vertices[2] = vec2( 0.0, 1.0);\n"
1494 "vec4 colors[3];\n"
1495 " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n"
1496 " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
1497 " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n"
1498 " foo = colors[gl_VertexID % 3];\n"
1499 " bar = vec4(1.0, 1.0, 1.0, 1.0);\n"
1500 " scale = 1.0;\n"
1501 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1502 "}\n";
1503
1504 static const char *fragShaderText =
1505 "#version 140\n"
1506 "#extension GL_ARB_separate_shader_objects : enable\n"
1507 "#extension GL_ARB_shading_language_420pack : enable\n"
1508 "layout (location = 1) in vec4 bar;\n"
1509 "layout (location = 0) in vec4 foo;\n"
1510 "layout (location = 2) in float scale;\n"
1511 "void main() {\n"
1512 " gl_FragColor = bar * scale + foo * (1.0-scale);\n"
1513 "}\n";
1514
1515 ASSERT_NO_FATAL_FAILURE(InitState());
1516 ASSERT_NO_FATAL_FAILURE(InitViewport());
1517
1518 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1519 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1520
1521 XglPipelineObj pipelineobj(m_device);
1522 pipelineobj.AddShader(&vs);
1523 pipelineobj.AddShader(&ps);
1524
1525 XglDescriptorSetObj descriptorSet(m_device);
1526
Tony Barbourdd4c9642015-01-09 12:55:14 -07001527 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1528 XglCommandBufferObj cmdBuffer(m_device);
1529 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1530
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001531 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001532
1533 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1534
1535#ifdef DUMP_STATE_DOT
1536 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1537 pDSDumpDot((char*)"triTest2.dot");
1538#endif
1539 // render triangle
1540 cmdBuffer.Draw(0, 3, 0, 1);
1541
1542 // finalize recording of the command buffer
1543 cmdBuffer.EndCommandBuffer();
1544 cmdBuffer.QueueCommandBuffer(NULL, 0);
1545
1546 for (int i = 0; i < m_renderTargetCount; i++)
1547 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001548}
1549
1550TEST_F(XglRenderTest, TriVertFetchAndVertID)
1551{
1552 // This tests that attributes work in the presence of gl_VertexID
1553
1554 static const char *vertShaderText =
1555 "#version 140\n"
1556 "#extension GL_ARB_separate_shader_objects : enable\n"
1557 "#extension GL_ARB_shading_language_420pack : enable\n"
1558 //XYZ1( -1, -1, -1 )
1559 "layout (location = 0) in vec4 pos;\n"
1560 //XYZ1( 0.f, 0.f, 0.f )
1561 "layout (location = 1) in vec4 inColor;\n"
1562 "layout (location = 0) out vec4 outColor;\n"
1563 "void main() {\n"
1564 " outColor = inColor;\n"
1565 " vec4 vertices[3];"
1566 " vertices[gl_VertexID % 3] = pos;\n"
1567 " gl_Position = vertices[(gl_VertexID + 3) % 3];\n"
1568 "}\n";
1569
1570
1571 static const char *fragShaderText =
1572 "#version 140\n"
1573 "#extension GL_ARB_separate_shader_objects : enable\n"
1574 "#extension GL_ARB_shading_language_420pack : enable\n"
1575 "layout (location = 0) in vec4 color;\n"
1576 "void main() {\n"
1577 " gl_FragColor = color;\n"
1578 "}\n";
1579
1580 ASSERT_NO_FATAL_FAILURE(InitState());
1581 ASSERT_NO_FATAL_FAILURE(InitViewport());
1582
1583 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001584 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001585
1586 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1587 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1588
1589 XglPipelineObj pipelineobj(m_device);
1590 pipelineobj.AddShader(&vs);
1591 pipelineobj.AddShader(&ps);
1592
1593 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001594 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001595
1596 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1597 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1598 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1599 };
1600
1601 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1602 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1603 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1604 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1605 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1606 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1607 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1608 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1609 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1610
1611 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1612 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1613 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1614
Tony Barbourdd4c9642015-01-09 12:55:14 -07001615 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1616 XglCommandBufferObj cmdBuffer(m_device);
1617 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1618
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001619 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001620
1621 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1622
1623 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1624#ifdef DUMP_STATE_DOT
1625 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1626 pDSDumpDot((char*)"triTest2.dot");
1627#endif
1628 // render triangle
1629 cmdBuffer.Draw(0, 6, 0, 1);
1630
1631 // finalize recording of the command buffer
1632 cmdBuffer.EndCommandBuffer();
1633 cmdBuffer.QueueCommandBuffer(NULL, 0);
1634
1635 for (int i = 0; i < m_renderTargetCount; i++)
1636 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001637}
1638
1639TEST_F(XglRenderTest, TriVertFetchDeadAttr)
1640{
1641 // This tests that attributes work in the presence of gl_VertexID
1642 // and a dead attribute in position 0. Draws a triangle with yellow,
1643 // red and green corners, starting at top and going clockwise.
1644
1645 static const char *vertShaderText =
1646 "#version 140\n"
1647 "#extension GL_ARB_separate_shader_objects : enable\n"
1648 "#extension GL_ARB_shading_language_420pack : enable\n"
1649 //XYZ1( -1, -1, -1 )
1650 "layout (location = 0) in vec4 pos;\n"
1651 //XYZ1( 0.f, 0.f, 0.f )
1652 "layout (location = 1) in vec4 inColor;\n"
1653 "layout (location = 0) out vec4 outColor;\n"
1654 "void main() {\n"
1655 " outColor = inColor;\n"
1656 " vec2 vertices[3];"
1657 " vertices[0] = vec2(-1.0, -1.0);\n"
1658 " vertices[1] = vec2( 1.0, -1.0);\n"
1659 " vertices[2] = vec2( 0.0, 1.0);\n"
1660 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1661 "}\n";
1662
1663
1664 static const char *fragShaderText =
1665 "#version 140\n"
1666 "#extension GL_ARB_separate_shader_objects : enable\n"
1667 "#extension GL_ARB_shading_language_420pack : enable\n"
1668 "layout (location = 0) in vec4 color;\n"
1669 "void main() {\n"
1670 " gl_FragColor = color;\n"
1671 "}\n";
1672
1673 ASSERT_NO_FATAL_FAILURE(InitState());
1674 ASSERT_NO_FATAL_FAILURE(InitViewport());
1675
1676 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vbData)/sizeof(g_vbData[0]),sizeof(g_vbData[0]), g_vbData);
Mike Stroyan55658c22014-12-04 11:08:39 +00001677 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07001678
1679 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1680 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1681
1682 XglPipelineObj pipelineobj(m_device);
1683 pipelineobj.AddShader(&vs);
1684 pipelineobj.AddShader(&ps);
1685
1686 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001687 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &meshBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001688
1689 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1690 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1691 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1692 };
1693
1694 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1695 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1696 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1697 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1698 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1699 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1700 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1701 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1702 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1703
1704 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1705 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1706 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1707
Tony Barbourdd4c9642015-01-09 12:55:14 -07001708 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1709 XglCommandBufferObj cmdBuffer(m_device);
1710 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001711
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001712 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001713
1714 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1715
1716 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1717#ifdef DUMP_STATE_DOT
1718 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1719 pDSDumpDot((char*)"triTest2.dot");
1720#endif
1721 // render triangle
1722 cmdBuffer.Draw(0, 6, 0, 1);
1723
1724 // finalize recording of the command buffer
1725 cmdBuffer.EndCommandBuffer();
1726 cmdBuffer.QueueCommandBuffer(NULL, 0);
1727
1728 for (int i = 0; i < m_renderTargetCount; i++)
1729 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001730}
1731
1732TEST_F(XglRenderTest, CubeWithVertexFetchAndMVP)
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001733{
1734 static const char *vertShaderText =
1735 "#version 140\n"
1736 "layout (std140) uniform bufferVals {\n"
1737 " mat4 mvp;\n"
1738 "} myBufferVals;\n"
1739 "in vec4 pos;\n"
1740 "in vec4 inColor;\n"
1741 "out vec4 outColor;\n"
1742 "void main() {\n"
1743 " outColor = inColor;\n"
1744 " gl_Position = myBufferVals.mvp * pos;\n"
1745 "}\n";
1746
1747 static const char *fragShaderText =
1748 "#version 130\n"
1749 "in vec4 color;\n"
1750 "void main() {\n"
1751 " gl_FragColor = color;\n"
1752 "}\n";
Tony Barbourf43b6982014-11-25 13:18:32 -07001753 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001754
Tony Barbourf43b6982014-11-25 13:18:32 -07001755 glm::mat4 View = glm::lookAt(
1756 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
1757 glm::vec3(0,0,0), // and looks at the origin
1758 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
1759 );
1760
1761 glm::mat4 Model = glm::mat4(1.0f);
1762
1763 glm::mat4 MVP = Projection * View * Model;
1764
1765 ASSERT_NO_FATAL_FAILURE(InitState());
1766 ASSERT_NO_FATAL_FAILURE(InitViewport());
1767 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
1768
1769 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
1770 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
1771
1772 const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT);
1773
1774 XglConstantBufferObj MVPBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
1775 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1776 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1777
Tony Barbourf43b6982014-11-25 13:18:32 -07001778 XglPipelineObj pipelineobj(m_device);
1779 pipelineobj.AddShader(&vs);
1780 pipelineobj.AddShader(&ps);
1781
Tony Barbourfa6cac72015-01-16 14:27:35 -07001782 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
1783 ds_state.depthTestEnable = XGL_TRUE;
1784 ds_state.depthWriteEnable = XGL_TRUE;
1785 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
1786 ds_state.depthBoundsEnable = XGL_FALSE;
1787 ds_state.stencilTestEnable = XGL_FALSE;
1788 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
1789 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
1790 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
1791 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
1792 ds_state.format.channelFormat = XGL_CH_FMT_R32;
1793 ds_state.format.numericFormat = XGL_NUM_FMT_DS;
1794 ds_state.front = ds_state.back;
1795 pipelineobj.SetDepthStencil(&ds_state);
1796
Tony Barbourf43b6982014-11-25 13:18:32 -07001797 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001798 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &MVPBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07001799
1800 m_memoryRefManager.AddMemoryRef(&meshBuffer);
1801 m_memoryRefManager.AddMemoryRef(&MVPBuffer);
1802
1803 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
1804 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
1805 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
1806 };
1807
1808 // this is the current description of g_vbData
1809 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
1810 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
1811 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1812 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
1813 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
1814 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
1815 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
1816 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
1817 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
1818
1819 pipelineobj.AddVertexInputBindings(&vi_binding,1);
1820 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
1821 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
1822
Tony Barboure4ed9942015-01-09 10:06:53 -07001823 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1824 XglCommandBufferObj cmdBuffer(m_device);
1825 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001826
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001827 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barboure4ed9942015-01-09 10:06:53 -07001828 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
Tony Barbourf43b6982014-11-25 13:18:32 -07001829
Tony Barboure4ed9942015-01-09 10:06:53 -07001830 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
1831#ifdef DUMP_STATE_DOT
1832 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1833 pDSDumpDot((char*)"triTest2.dot");
1834#endif
1835 // render triangle
1836 cmdBuffer.Draw(0, 36, 0, 1);
1837
1838 // finalize recording of the command buffer
1839 cmdBuffer.EndCommandBuffer();
Tony Barbourdd4c9642015-01-09 12:55:14 -07001840 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
Tony Barboure4ed9942015-01-09 10:06:53 -07001841
1842 for (int i = 0; i < m_renderTargetCount; i++)
1843 RecordImage(m_renderTargets[i]);
Courtney Goeltzenleuchterd0556292014-10-20 16:33:15 -06001844}
1845
Tony Barbourf43b6982014-11-25 13:18:32 -07001846TEST_F(XglRenderTest, VSTexture)
1847{
1848 // The expected result from this test is a green and red triangle;
1849 // one red vertex on the left, two green vertices on the right.
1850 static const char *vertShaderText =
1851 "#version 130\n"
1852 "out vec4 texColor;\n"
1853 "uniform sampler2D surface;\n"
1854 "void main() {\n"
1855 " vec2 vertices[3];"
1856 " vertices[0] = vec2(-0.5, -0.5);\n"
1857 " vertices[1] = vec2( 0.5, -0.5);\n"
1858 " vertices[2] = vec2( 0.5, 0.5);\n"
1859 " vec2 positions[3];"
1860 " positions[0] = vec2( 0.0, 0.0);\n"
1861 " positions[1] = vec2( 0.25, 0.1);\n"
1862 " positions[2] = vec2( 0.1, 0.25);\n"
1863 " vec2 samplePos = positions[gl_VertexID % 3];\n"
1864 " texColor = textureLod(surface, samplePos, 0.0);\n"
1865 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1866 "}\n";
1867
1868 static const char *fragShaderText =
1869 "#version 130\n"
1870 "in vec4 texColor;\n"
1871 "void main() {\n"
1872 " gl_FragColor = texColor;\n"
1873 "}\n";
1874
1875 ASSERT_NO_FATAL_FAILURE(InitState());
1876 ASSERT_NO_FATAL_FAILURE(InitViewport());
1877
1878 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1879 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1880 XglSamplerObj sampler(m_device);
1881 XglTextureObj texture(m_device);
1882
Tony Barbourf43b6982014-11-25 13:18:32 -07001883 XglPipelineObj pipelineobj(m_device);
1884 pipelineobj.AddShader(&vs);
1885 pipelineobj.AddShader(&ps);
1886
1887 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001888 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001889
1890 m_memoryRefManager.AddMemoryRef(&texture);
1891
Tony Barbourdd4c9642015-01-09 12:55:14 -07001892 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1893 XglCommandBufferObj cmdBuffer(m_device);
1894 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001895
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001896 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001897
1898 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1899
1900#ifdef DUMP_STATE_DOT
1901 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1902 pDSDumpDot((char*)"triTest2.dot");
1903#endif
1904 // render triangle
1905 cmdBuffer.Draw(0, 3, 0, 1);
1906
1907 // finalize recording of the command buffer
1908 cmdBuffer.EndCommandBuffer();
1909 cmdBuffer.QueueCommandBuffer(NULL, 0);
1910
1911 for (int i = 0; i < m_renderTargetCount; i++)
1912 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001913}
1914TEST_F(XglRenderTest, TexturedTriangle)
1915{
1916 // The expected result from this test is a red and green checkered triangle
1917 static const char *vertShaderText =
1918 "#version 140\n"
1919 "#extension GL_ARB_separate_shader_objects : enable\n"
1920 "#extension GL_ARB_shading_language_420pack : enable\n"
1921 "layout (location = 0) out vec2 samplePos;\n"
1922 "void main() {\n"
1923 " vec2 vertices[3];"
1924 " vertices[0] = vec2(-0.5, -0.5);\n"
1925 " vertices[1] = vec2( 0.5, -0.5);\n"
1926 " vertices[2] = vec2( 0.5, 0.5);\n"
1927 " vec2 positions[3];"
1928 " positions[0] = vec2( 0.0, 0.0);\n"
1929 " positions[1] = vec2( 1.0, 0.0);\n"
1930 " positions[2] = vec2( 1.0, 1.0);\n"
1931 " samplePos = positions[gl_VertexID % 3];\n"
1932 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
1933 "}\n";
1934
1935 static const char *fragShaderText =
1936 "#version 140\n"
1937 "#extension GL_ARB_separate_shader_objects : enable\n"
1938 "#extension GL_ARB_shading_language_420pack : enable\n"
1939 "layout (location = 0) in vec2 samplePos;\n"
1940 "layout (binding = 0) uniform sampler2D surface;\n"
1941 "layout (location=0) out vec4 outColor;\n"
1942 "void main() {\n"
1943 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
1944 " outColor = texColor;\n"
1945 "}\n";
1946
1947 ASSERT_NO_FATAL_FAILURE(InitState());
1948 ASSERT_NO_FATAL_FAILURE(InitViewport());
1949
1950 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
1951 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
1952 XglSamplerObj sampler(m_device);
1953 XglTextureObj texture(m_device);
1954
Tony Barbourf43b6982014-11-25 13:18:32 -07001955 XglPipelineObj pipelineobj(m_device);
1956 pipelineobj.AddShader(&vs);
1957 pipelineobj.AddShader(&ps);
1958
1959 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08001960 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07001961
1962 m_memoryRefManager.AddMemoryRef(&texture);
1963
Tony Barbourdd4c9642015-01-09 12:55:14 -07001964 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1965 XglCommandBufferObj cmdBuffer(m_device);
1966 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
1967
Jeremy Hayese0c3b222015-01-14 16:17:08 -07001968 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07001969
1970 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
1971
1972#ifdef DUMP_STATE_DOT
1973 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
1974 pDSDumpDot((char*)"triTest2.dot");
1975#endif
1976 // render triangle
1977 cmdBuffer.Draw(0, 3, 0, 1);
1978
1979 // finalize recording of the command buffer
1980 cmdBuffer.EndCommandBuffer();
1981 cmdBuffer.QueueCommandBuffer(NULL, 0);
1982
1983 for (int i = 0; i < m_renderTargetCount; i++)
1984 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07001985}
1986TEST_F(XglRenderTest, TexturedTriangleClip)
1987{
1988 // The expected result from this test is a red and green checkered triangle
1989 static const char *vertShaderText =
1990 "#version 330\n"
1991 "#extension GL_ARB_separate_shader_objects : enable\n"
1992 "#extension GL_ARB_shading_language_420pack : enable\n"
1993 "layout (location = 0) out vec2 samplePos;\n"
1994 "out gl_PerVertex {\n"
1995 " vec4 gl_Position;\n"
1996 " float gl_ClipDistance[1];\n"
1997 "};\n"
1998 "void main() {\n"
1999 " vec2 vertices[3];"
2000 " vertices[0] = vec2(-0.5, -0.5);\n"
2001 " vertices[1] = vec2( 0.5, -0.5);\n"
2002 " vertices[2] = vec2( 0.5, 0.5);\n"
2003 " vec2 positions[3];"
2004 " positions[0] = vec2( 0.0, 0.0);\n"
2005 " positions[1] = vec2( 1.0, 0.0);\n"
2006 " positions[2] = vec2( 1.0, 1.0);\n"
2007 " float dists[3];\n"
2008 " dists[0] = 1.0;\n"
2009 " dists[1] = 1.0;\n"
2010 " dists[2] = -1.0;\n"
2011 " gl_ClipDistance[0] = dists[gl_VertexID % 3];\n"
2012 " samplePos = positions[gl_VertexID % 3];\n"
2013 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2014 "}\n";
2015
2016 static const char *fragShaderText =
2017 "#version 140\n"
2018 "#extension GL_ARB_separate_shader_objects : enable\n"
2019 "#extension GL_ARB_shading_language_420pack : enable\n"
2020 "layout (location = 0) in vec2 samplePos;\n"
2021 "layout (binding = 0) uniform sampler2D surface;\n"
2022 "layout (location=0) out vec4 outColor;\n"
2023 "void main() {\n"
2024 //" vec4 texColor = textureLod(surface, samplePos, 0.0 + gl_ClipDistance[0]);\n"
2025 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2026 " outColor = texColor;\n"
2027 "}\n";
2028
2029
2030 ASSERT_NO_FATAL_FAILURE(InitState());
2031 ASSERT_NO_FATAL_FAILURE(InitViewport());
2032
2033 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2034 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2035 XglSamplerObj sampler(m_device);
2036 XglTextureObj texture(m_device);
2037
Tony Barbourf43b6982014-11-25 13:18:32 -07002038 XglPipelineObj pipelineobj(m_device);
2039 pipelineobj.AddShader(&vs);
2040 pipelineobj.AddShader(&ps);
2041
2042 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002043 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002044
2045 m_memoryRefManager.AddMemoryRef(&texture);
2046
Tony Barbourdd4c9642015-01-09 12:55:14 -07002047 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2048 XglCommandBufferObj cmdBuffer(m_device);
2049 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2050
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002051 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002052
2053 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2054
2055#ifdef DUMP_STATE_DOT
2056 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2057 pDSDumpDot((char*)"triTest2.dot");
2058#endif
2059 // render triangle
2060 cmdBuffer.Draw(0, 3, 0, 1);
2061
2062 // finalize recording of the command buffer
2063 cmdBuffer.EndCommandBuffer();
2064 cmdBuffer.QueueCommandBuffer(NULL, 0);
2065
2066 for (int i = 0; i < m_renderTargetCount; i++)
2067 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002068}
2069TEST_F(XglRenderTest, FSTriangle)
2070{
2071 // The expected result from this test is a red and green checkered triangle
2072 static const char *vertShaderText =
2073 "#version 140\n"
2074 "#extension GL_ARB_separate_shader_objects : enable\n"
2075 "#extension GL_ARB_shading_language_420pack : enable\n"
2076 "layout (location = 0) out vec2 samplePos;\n"
2077 "void main() {\n"
2078 " vec2 vertices[3];"
2079 " vertices[0] = vec2(-0.5, -0.5);\n"
2080 " vertices[1] = vec2( 0.5, -0.5);\n"
2081 " vertices[2] = vec2( 0.5, 0.5);\n"
2082 " vec2 positions[3];"
2083 " positions[0] = vec2( 0.0, 0.0);\n"
2084 " positions[1] = vec2( 1.0, 0.0);\n"
2085 " positions[2] = vec2( 1.0, 1.0);\n"
2086 " samplePos = positions[gl_VertexID % 3];\n"
2087 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2088 "}\n";
2089
2090 static const char *fragShaderText =
2091 "#version 140\n"
2092 "#extension GL_ARB_separate_shader_objects : enable\n"
2093 "#extension GL_ARB_shading_language_420pack : enable\n"
2094 "layout (location = 0) in vec2 samplePos;\n"
2095 "layout (binding = 0) uniform sampler2D surface;\n"
2096 "layout (location=0) out vec4 outColor;\n"
2097 "void main() {\n"
2098 " vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
2099 " outColor = texColor;\n"
2100 "}\n";
2101
2102 ASSERT_NO_FATAL_FAILURE(InitState());
2103 ASSERT_NO_FATAL_FAILURE(InitViewport());
2104
2105 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2106 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2107 XglSamplerObj sampler(m_device);
2108 XglTextureObj texture(m_device);
2109
Tony Barbourf43b6982014-11-25 13:18:32 -07002110 XglPipelineObj pipelineobj(m_device);
2111 pipelineobj.AddShader(&vs);
2112 pipelineobj.AddShader(&ps);
2113
2114 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002115 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002116
2117 m_memoryRefManager.AddMemoryRef(&texture);
2118
Tony Barbourdd4c9642015-01-09 12:55:14 -07002119 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2120 XglCommandBufferObj cmdBuffer(m_device);
2121 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2122
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002123 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002124
2125 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2126
2127#ifdef DUMP_STATE_DOT
2128 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2129 pDSDumpDot((char*)"triTest2.dot");
2130#endif
2131 // render triangle
2132 cmdBuffer.Draw(0, 3, 0, 1);
2133
2134 // finalize recording of the command buffer
2135 cmdBuffer.EndCommandBuffer();
2136 cmdBuffer.QueueCommandBuffer(NULL, 0);
2137
2138 for (int i = 0; i < m_renderTargetCount; i++)
2139 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002140}
2141TEST_F(XglRenderTest, SamplerBindingsTriangle)
2142{
2143 // This test sets bindings on the samplers
2144 // For now we are asserting that sampler and texture pairs
2145 // march in lock step, and are set via GLSL binding. This can
2146 // and will probably change.
2147 // The sampler bindings should match the sampler and texture slot
2148 // number set up by the application.
2149 // This test will result in a blue triangle
2150 static const char *vertShaderText =
2151 "#version 140\n"
2152 "#extension GL_ARB_separate_shader_objects : enable\n"
2153 "#extension GL_ARB_shading_language_420pack : enable\n"
2154 "layout (location = 0) out vec4 samplePos;\n"
2155 "void main() {\n"
2156 " vec2 vertices[3];"
2157 " vertices[0] = vec2(-0.5, -0.5);\n"
2158 " vertices[1] = vec2( 0.5, -0.5);\n"
2159 " vertices[2] = vec2( 0.5, 0.5);\n"
2160 " vec2 positions[3];"
2161 " positions[0] = vec2( 0.0, 0.0);\n"
2162 " positions[1] = vec2( 1.0, 0.0);\n"
2163 " positions[2] = vec2( 1.0, 1.0);\n"
2164 " samplePos = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n"
2165 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2166 "}\n";
2167
2168 static const char *fragShaderText =
2169 "#version 140\n"
2170 "#extension GL_ARB_separate_shader_objects : enable\n"
2171 "#extension GL_ARB_shading_language_420pack : enable\n"
2172 "layout (location = 0) in vec4 samplePos;\n"
2173 "layout (binding = 0) uniform sampler2D surface0;\n"
2174 "layout (binding = 1) uniform sampler2D surface1;\n"
2175 "layout (binding = 12) uniform sampler2D surface2;\n"
2176 "void main() {\n"
2177 " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n"
2178 "}\n";
2179
2180 ASSERT_NO_FATAL_FAILURE(InitState());
2181 ASSERT_NO_FATAL_FAILURE(InitViewport());
2182
2183 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2184 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2185
2186 XglSamplerObj sampler1(m_device);
2187 XglSamplerObj sampler2(m_device);
2188 XglSamplerObj sampler3(m_device);
2189
2190 XglTextureObj texture1(m_device); // Red
2191 texture1.ChangeColors(0xffff0000,0xffff0000);
2192 XglTextureObj texture2(m_device); // Green
2193 texture2.ChangeColors(0xff00ff00,0xff00ff00);
2194 XglTextureObj texture3(m_device); // Blue
2195 texture3.ChangeColors(0xff0000ff,0xff0000ff);
2196
Tony Barbourf43b6982014-11-25 13:18:32 -07002197 XglPipelineObj pipelineobj(m_device);
2198 pipelineobj.AddShader(&vs);
2199 pipelineobj.AddShader(&ps);
2200
2201 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002202 descriptorSet.AppendSamplerTexture(&sampler1, &texture1);
2203 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2204 for (int i = 0; i < 10; i++)
2205 descriptorSet.AppendDummy();
2206 descriptorSet.AppendSamplerTexture(&sampler3, &texture3);
Tony Barbourf43b6982014-11-25 13:18:32 -07002207
2208 m_memoryRefManager.AddMemoryRef(&texture1);
2209 m_memoryRefManager.AddMemoryRef(&texture2);
2210 m_memoryRefManager.AddMemoryRef(&texture3);
2211
Tony Barbourdd4c9642015-01-09 12:55:14 -07002212 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2213 XglCommandBufferObj cmdBuffer(m_device);
2214 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2215
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002216 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002217
2218 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2219
2220#ifdef DUMP_STATE_DOT
2221 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2222 pDSDumpDot((char*)"triTest2.dot");
2223#endif
2224 // render triangle
2225 cmdBuffer.Draw(0, 3, 0, 1);
2226
2227 // finalize recording of the command buffer
2228 cmdBuffer.EndCommandBuffer();
2229 cmdBuffer.QueueCommandBuffer(NULL, 0);
2230
2231 for (int i = 0; i < m_renderTargetCount; i++)
2232 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002233
2234}
2235
2236TEST_F(XglRenderTest, TriangleVSUniformBlock)
2237{
2238 // The expected result from this test is a blue triangle
2239
2240 static const char *vertShaderText =
2241 "#version 140\n"
2242 "#extension GL_ARB_separate_shader_objects : enable\n"
2243 "#extension GL_ARB_shading_language_420pack : enable\n"
2244 "layout (location = 0) out vec4 outColor;\n"
2245 "layout (std140, binding = 0) uniform bufferVals {\n"
2246 " vec4 red;\n"
2247 " vec4 green;\n"
2248 " vec4 blue;\n"
2249 " vec4 white;\n"
2250 "} myBufferVals;\n"
2251 "void main() {\n"
2252 " vec2 vertices[3];"
2253 " vertices[0] = vec2(-0.5, -0.5);\n"
2254 " vertices[1] = vec2( 0.5, -0.5);\n"
2255 " vertices[2] = vec2( 0.5, 0.5);\n"
2256 " outColor = myBufferVals.blue;\n"
2257 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2258 "}\n";
2259
2260 static const char *fragShaderText =
2261 "#version 140\n"
2262 "#extension GL_ARB_separate_shader_objects : enable\n"
2263 "#extension GL_ARB_shading_language_420pack : enable\n"
2264 "layout (location = 0) in vec4 inColor;\n"
2265 "void main() {\n"
2266 " gl_FragColor = inColor;\n"
2267 "}\n";
2268
2269 ASSERT_NO_FATAL_FAILURE(InitState());
2270 ASSERT_NO_FATAL_FAILURE(InitViewport());
2271
2272 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2273 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2274
2275 // Let's populate our buffer with the following:
2276 // vec4 red;
2277 // vec4 green;
2278 // vec4 blue;
2279 // vec4 white;
2280 const int valCount = 4 * 4;
2281 const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0,
2282 0.0, 1.0, 0.0, 1.0,
2283 0.0, 0.0, 1.0, 1.0,
2284 1.0, 1.0, 1.0, 1.0 };
2285
2286 XglConstantBufferObj colorBuffer(m_device, valCount, sizeof(bufferVals[0]), (const void*) bufferVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002287
2288 XglPipelineObj pipelineobj(m_device);
2289 pipelineobj.AddShader(&vs);
2290 pipelineobj.AddShader(&ps);
2291
2292 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002293 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &colorBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002294
Tony Barbourdd4c9642015-01-09 12:55:14 -07002295 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2296 XglCommandBufferObj cmdBuffer(m_device);
2297 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2298
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002299 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002300
2301 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2302
2303#ifdef DUMP_STATE_DOT
2304 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2305 pDSDumpDot((char*)"triTest2.dot");
2306#endif
2307 // render triangle
2308 cmdBuffer.Draw(0, 3, 0, 1);
2309
2310 // finalize recording of the command buffer
2311 cmdBuffer.EndCommandBuffer();
2312 cmdBuffer.QueueCommandBuffer(NULL, 0);
2313
2314 for (int i = 0; i < m_renderTargetCount; i++)
2315 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002316
2317}
2318
2319TEST_F(XglRenderTest, TriangleFSUniformBlockBinding)
2320{
2321 // This test allows the shader to select which buffer it is
2322 // pulling from using layout binding qualifier.
2323 // There are corresponding changes in the compiler stack that
2324 // will select the buffer using binding directly.
2325 // The binding number should match the slot number set up by
2326 // the application.
2327 // The expected result from this test is a purple triangle
2328
2329 static const char *vertShaderText =
2330 "#version 140\n"
2331 "#extension GL_ARB_separate_shader_objects : enable\n"
2332 "#extension GL_ARB_shading_language_420pack : enable\n"
2333 "void main() {\n"
2334 " vec2 vertices[3];"
2335 " vertices[0] = vec2(-0.5, -0.5);\n"
2336 " vertices[1] = vec2( 0.5, -0.5);\n"
2337 " vertices[2] = vec2( 0.5, 0.5);\n"
2338 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2339 "}\n";
2340
2341 static const char *fragShaderText =
2342 "#version 140\n"
2343 "#extension GL_ARB_separate_shader_objects : enable\n"
2344 "#extension GL_ARB_shading_language_420pack : enable\n"
2345 "layout (std140, binding = 0) uniform redVal { vec4 color; } myRedVal\n;"
2346 "layout (std140, binding = 1) uniform greenVal { vec4 color; } myGreenVal\n;"
2347 "layout (std140, binding = 2) uniform blueVal { vec4 color; } myBlueVal\n;"
Chia-I Wuf8385062015-01-04 16:27:24 +08002348 "layout (std140, binding = 3) uniform whiteVal { vec4 color; } myWhiteVal\n;"
Tony Barbourf43b6982014-11-25 13:18:32 -07002349 "void main() {\n"
2350 " gl_FragColor = myBlueVal.color;\n"
2351 " gl_FragColor += myRedVal.color;\n"
2352 "}\n";
2353
2354 ASSERT_NO_FATAL_FAILURE(InitState());
2355 ASSERT_NO_FATAL_FAILURE(InitViewport());
2356
2357 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2358 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2359
2360 // We're going to create a number of uniform buffers, and then allow
2361 // the shader to select which it wants to read from with a binding
2362
2363 // Let's populate the buffers with a single color each:
2364 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2365 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2366 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
Chia-I Wuf8385062015-01-04 16:27:24 +08002367 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
Tony Barbourf43b6982014-11-25 13:18:32 -07002368
2369 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2370 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2371 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2372 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2373
2374 const int redCount = sizeof(redVals) / sizeof(float);
2375 const int greenCount = sizeof(greenVals) / sizeof(float);
2376 const int blueCount = sizeof(blueVals) / sizeof(float);
2377 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2378
2379 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002380
2381 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002382
2383 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002384
2385 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002386
2387 XglPipelineObj pipelineobj(m_device);
2388 pipelineobj.AddShader(&vs);
2389 pipelineobj.AddShader(&ps);
2390
2391 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002392 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2393 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2394 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2395 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002396
Tony Barbourdd4c9642015-01-09 12:55:14 -07002397 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2398 XglCommandBufferObj cmdBuffer(m_device);
2399 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002400
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002401 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002402
2403 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2404
2405#ifdef DUMP_STATE_DOT
2406 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2407 pDSDumpDot((char*)"triTest2.dot");
2408#endif
2409 // render triangle
2410 cmdBuffer.Draw(0, 3, 0, 1);
2411
2412 // finalize recording of the command buffer
2413 cmdBuffer.EndCommandBuffer();
2414 cmdBuffer.QueueCommandBuffer(NULL, 0);
2415
2416 for (int i = 0; i < m_renderTargetCount; i++)
2417 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002418}
2419
2420TEST_F(XglRenderTest, TriangleFSAnonymousUniformBlockBinding)
2421{
2422 // This test is the same as TriangleFSUniformBlockBinding, but
2423 // it does not provide an instance name.
2424 // The expected result from this test is a purple triangle
2425
2426 static const char *vertShaderText =
2427 "#version 140\n"
2428 "#extension GL_ARB_separate_shader_objects : enable\n"
2429 "#extension GL_ARB_shading_language_420pack : enable\n"
2430 "void main() {\n"
2431 " vec2 vertices[3];"
2432 " vertices[0] = vec2(-0.5, -0.5);\n"
2433 " vertices[1] = vec2( 0.5, -0.5);\n"
2434 " vertices[2] = vec2( 0.5, 0.5);\n"
2435 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2436 "}\n";
2437
2438 static const char *fragShaderText =
2439 "#version 430\n"
2440 "#extension GL_ARB_separate_shader_objects : enable\n"
2441 "#extension GL_ARB_shading_language_420pack : enable\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002442 "layout (std140, binding = 0) uniform redVal { vec4 red; };"
2443 "layout (std140, binding = 1) uniform greenVal { vec4 green; };"
2444 "layout (std140, binding = 2) uniform blueVal { vec4 blue; };"
Chia-I Wuf8385062015-01-04 16:27:24 +08002445 "layout (std140, binding = 3) uniform whiteVal { vec4 white; };"
Cody Northrop68a10f62014-12-05 15:44:14 -07002446 "layout (location = 0) out vec4 outColor;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002447 "void main() {\n"
Cody Northrop68a10f62014-12-05 15:44:14 -07002448 " outColor = blue;\n"
2449 " outColor += red;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002450 "}\n";
2451 ASSERT_NO_FATAL_FAILURE(InitState());
2452 ASSERT_NO_FATAL_FAILURE(InitViewport());
2453
2454 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2455 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2456
2457 // We're going to create a number of uniform buffers, and then allow
2458 // the shader to select which it wants to read from with a binding
2459
2460 // Let's populate the buffers with a single color each:
2461 // layout (std140, binding = 0) uniform bufferVals { vec4 red; } myRedVal;
2462 // layout (std140, binding = 1) uniform bufferVals { vec4 green; } myGreenVal;
2463 // layout (std140, binding = 2) uniform bufferVals { vec4 blue; } myBlueVal;
2464 // layout (std140, binding = 3) uniform bufferVals { vec4 white; } myWhiteVal;
2465
2466 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2467 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2468 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2469 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2470
2471 const int redCount = sizeof(redVals) / sizeof(float);
2472 const int greenCount = sizeof(greenVals) / sizeof(float);
2473 const int blueCount = sizeof(blueVals) / sizeof(float);
2474 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2475
2476 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002477
2478 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002479
2480 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002481
2482 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Tony Barbourf43b6982014-11-25 13:18:32 -07002483
2484 XglPipelineObj pipelineobj(m_device);
2485 pipelineobj.AddShader(&vs);
2486 pipelineobj.AddShader(&ps);
2487
2488 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002489 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2490 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2491 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2492 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Tony Barbourf43b6982014-11-25 13:18:32 -07002493
Tony Barbourdd4c9642015-01-09 12:55:14 -07002494 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2495 XglCommandBufferObj cmdBuffer(m_device);
2496 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
2497
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002498 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002499
2500 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2501
2502#ifdef DUMP_STATE_DOT
2503 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2504 pDSDumpDot((char*)"triTest2.dot");
2505#endif
2506 // render triangle
2507 cmdBuffer.Draw(0, 3, 0, 1);
2508
2509 // finalize recording of the command buffer
2510 cmdBuffer.EndCommandBuffer();
2511 cmdBuffer.QueueCommandBuffer(NULL, 0);
2512
2513 for (int i = 0; i < m_renderTargetCount; i++)
2514 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002515
2516}
2517
2518TEST_F(XglRenderTest, CubeWithVertexFetchAndMVPAndTexture)
2519{
2520 static const char *vertShaderText =
2521 "#version 140\n"
2522 "#extension GL_ARB_separate_shader_objects : enable\n"
2523 "#extension GL_ARB_shading_language_420pack : enable\n"
2524 "layout (std140, binding=0) uniform bufferVals {\n"
2525 " mat4 mvp;\n"
2526 "} myBufferVals;\n"
2527 "layout (location=0) in vec4 pos;\n"
2528 "layout (location=0) out vec2 UV;\n"
2529 "void main() {\n"
2530 " vec2 positions[3];"
2531 " positions[0] = vec2( 0.0, 0.0);\n"
2532 " positions[1] = vec2( 0.25, 0.1);\n"
2533 " positions[2] = vec2( 0.1, 0.25);\n"
2534 " UV = positions[gl_VertexID % 3];\n"
2535 " gl_Position = myBufferVals.mvp * pos;\n"
2536 "}\n";
2537
2538 static const char *fragShaderText =
2539 "#version 140\n"
2540 "#extension GL_ARB_separate_shader_objects : enable\n"
2541 "#extension GL_ARB_shading_language_420pack : enable\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002542 "layout (binding=1) uniform sampler2D surface;\n"
Tony Barbourf43b6982014-11-25 13:18:32 -07002543 "layout (location=0) out vec4 outColor;\n"
2544 "layout (location=0) in vec2 UV;\n"
2545 "void main() {\n"
2546 " outColor= textureLod(surface, UV, 0.0);\n"
2547 "}\n";
2548 glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 100.0f);
2549
2550 glm::mat4 View = glm::lookAt(
2551 glm::vec3(0,3,10), // Camera is at (0,3,10), in World Space
2552 glm::vec3(0,0,0), // and looks at the origin
2553 glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
2554 );
2555
2556 glm::mat4 Model = glm::mat4(1.0f);
2557
2558 glm::mat4 MVP = Projection * View * Model;
2559
2560
2561 ASSERT_NO_FATAL_FAILURE(InitState());
2562 ASSERT_NO_FATAL_FAILURE(InitViewport());
2563 ASSERT_NO_FATAL_FAILURE(InitDepthStencil());
2564
2565 XglConstantBufferObj meshBuffer(m_device,sizeof(g_vb_solid_face_colors_Data)/sizeof(g_vb_solid_face_colors_Data[0]),
2566 sizeof(g_vb_solid_face_colors_Data[0]), g_vb_solid_face_colors_Data);
Mike Stroyan55658c22014-12-04 11:08:39 +00002567 meshBuffer.BufferMemoryBarrier();
Tony Barbourf43b6982014-11-25 13:18:32 -07002568
2569 const int buf_size = sizeof(MVP) / sizeof(XGL_FLOAT);
2570
2571 XglConstantBufferObj mvpBuffer(m_device, buf_size, sizeof(MVP[0]), (const void*) &MVP[0][0]);
2572 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2573 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2574 XglSamplerObj sampler(m_device);
2575 XglTextureObj texture(m_device);
2576
Tony Barbourf43b6982014-11-25 13:18:32 -07002577 XglPipelineObj pipelineobj(m_device);
2578 pipelineobj.AddShader(&vs);
2579 pipelineobj.AddShader(&ps);
2580
2581 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002582 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mvpBuffer);
2583 descriptorSet.AppendSamplerTexture(&sampler, &texture);
Tony Barbourf43b6982014-11-25 13:18:32 -07002584
2585 m_memoryRefManager.AddMemoryRef(&meshBuffer);
2586 m_memoryRefManager.AddMemoryRef(&mvpBuffer);
2587 m_memoryRefManager.AddMemoryRef(&texture);
2588
2589 XGL_VERTEX_INPUT_BINDING_DESCRIPTION vi_binding = {
2590 sizeof(g_vbData[0]), // strideInBytes; Distance between vertices in bytes (0 = no advancement)
2591 XGL_VERTEX_INPUT_STEP_RATE_VERTEX // stepRate; // Rate at which binding is incremented
2592 };
2593
2594 // this is the current description of g_vbData
2595 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION vi_attribs[2];
2596 vi_attribs[0].binding = 0; // index into vertexBindingDescriptions
2597 vi_attribs[0].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
2598 vi_attribs[0].format.numericFormat = XGL_NUM_FMT_FLOAT;
2599 vi_attribs[0].offsetInBytes = 0; // Offset of first element in bytes from base of vertex
2600 vi_attribs[1].binding = 0; // index into vertexBindingDescriptions
2601 vi_attribs[1].format.channelFormat = XGL_CH_FMT_R32G32B32A32; // format of source data
2602 vi_attribs[1].format.numericFormat = XGL_NUM_FMT_FLOAT;
2603 vi_attribs[1].offsetInBytes = 16; // Offset of first element in bytes from base of vertex
2604
2605 pipelineobj.AddVertexInputBindings(&vi_binding,1);
2606 pipelineobj.AddVertexInputAttribs(vi_attribs,2);
2607 pipelineobj.AddVertexDataBuffer(&meshBuffer,0);
2608
Tony Barbourfa6cac72015-01-16 14:27:35 -07002609 XGL_PIPELINE_DS_STATE_CREATE_INFO ds_state;
2610 ds_state.depthTestEnable = XGL_TRUE;
2611 ds_state.depthWriteEnable = XGL_TRUE;
2612 ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL;
2613 ds_state.depthBoundsEnable = XGL_FALSE;
2614 ds_state.stencilTestEnable = XGL_FALSE;
2615 ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP;
2616 ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP;
2617 ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP;
2618 ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS;
2619 ds_state.format.channelFormat = XGL_CH_FMT_R32;
2620 ds_state.format.numericFormat = XGL_NUM_FMT_DS;
2621 ds_state.front = ds_state.back;
2622 pipelineobj.SetDepthStencil(&ds_state);
2623
Tony Barbourdd4c9642015-01-09 12:55:14 -07002624 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2625 XglCommandBufferObj cmdBuffer(m_device);
2626 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002627
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002628 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002629 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2630
2631 cmdBuffer.BindVertexBuffer(&meshBuffer, 0, 0);
2632#ifdef DUMP_STATE_DOT
2633 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2634 pDSDumpDot((char*)"triTest2.dot");
2635#endif
2636 // render triangle
2637 cmdBuffer.Draw(0, 36, 0, 1);
2638
2639 // finalize recording of the command buffer
2640 cmdBuffer.EndCommandBuffer();
2641 cmdBuffer.QueueCommandBuffer(m_memoryRefManager.GetMemoryRefList(), m_memoryRefManager.GetNumRefs());
2642
2643 for (int i = 0; i < m_renderTargetCount; i++)
2644 RecordImage(m_renderTargets[i]);
Tony Barbourf43b6982014-11-25 13:18:32 -07002645
2646}
Cody Northropd1ce7842014-12-09 11:17:01 -07002647
2648TEST_F(XglRenderTest, TriangleMixedSamplerUniformBlockBinding)
2649{
2650 // This test mixes binding slots of textures and buffers, ensuring
2651 // that sparse and overlapping assignments work.
Cody Northropa0410942014-12-09 13:59:39 -07002652 // The expected result from this test is a purple triangle, although
Cody Northropd1ce7842014-12-09 11:17:01 -07002653 // you can modify it to move the desired result around.
2654
2655 static const char *vertShaderText =
2656 "#version 140\n"
2657 "#extension GL_ARB_separate_shader_objects : enable\n"
2658 "#extension GL_ARB_shading_language_420pack : enable\n"
2659 "void main() {\n"
2660 " vec2 vertices[3];"
2661 " vertices[0] = vec2(-0.5, -0.5);\n"
2662 " vertices[1] = vec2( 0.5, -0.5);\n"
2663 " vertices[2] = vec2( 0.5, 0.5);\n"
2664 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2665 "}\n";
2666
2667 static const char *fragShaderText =
2668 "#version 430\n"
2669 "#extension GL_ARB_separate_shader_objects : enable\n"
2670 "#extension GL_ARB_shading_language_420pack : enable\n"
2671 "layout (binding = 0) uniform sampler2D surface0;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002672 "layout (binding = 3) uniform sampler2D surface1;\n"
2673 "layout (binding = 1) uniform sampler2D surface2;\n"
2674 "layout (binding = 2) uniform sampler2D surface3;\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002675
Cody Northropa0410942014-12-09 13:59:39 -07002676
Chia-I Wuf8385062015-01-04 16:27:24 +08002677 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2678 "layout (std140, binding = 6) uniform greenVal { vec4 green; };"
2679 "layout (std140, binding = 5) uniform blueVal { vec4 blue; };"
2680 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northropd1ce7842014-12-09 11:17:01 -07002681 "layout (location = 0) out vec4 outColor;\n"
2682 "void main() {\n"
Cody Northropa0410942014-12-09 13:59:39 -07002683 " outColor = red * vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002684 " outColor += white * vec4(0.00001);\n"
2685 " outColor += textureLod(surface2, vec2(0.5), 0.0)* vec4(0.00001);\n"
Cody Northropa0410942014-12-09 13:59:39 -07002686 " outColor += textureLod(surface1, vec2(0.0), 0.0);//* vec4(0.00001);\n"
Cody Northropd1ce7842014-12-09 11:17:01 -07002687 "}\n";
2688 ASSERT_NO_FATAL_FAILURE(InitState());
2689 ASSERT_NO_FATAL_FAILURE(InitViewport());
2690
2691 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2692 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2693
Cody Northropd1ce7842014-12-09 11:17:01 -07002694 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2695 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2696 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2697 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2698
2699 const int redCount = sizeof(redVals) / sizeof(float);
2700 const int greenCount = sizeof(greenVals) / sizeof(float);
2701 const int blueCount = sizeof(blueVals) / sizeof(float);
2702 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2703
2704 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002705 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002706 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002707 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northropd1ce7842014-12-09 11:17:01 -07002708
2709 XglSamplerObj sampler0(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002710 XglTextureObj texture0(m_device); // Light Red
2711 texture0.ChangeColors(0xff800000,0xff800000);
Cody Northropd1ce7842014-12-09 11:17:01 -07002712 XglSamplerObj sampler2(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002713 XglTextureObj texture2(m_device); // Light Blue
2714 texture2.ChangeColors(0xff000080,0xff000080);
Cody Northropd1ce7842014-12-09 11:17:01 -07002715 XglSamplerObj sampler4(m_device);
Cody Northropa0410942014-12-09 13:59:39 -07002716 XglTextureObj texture4(m_device); // Light Green
2717 texture4.ChangeColors(0xff008000,0xff008000);
Cody Northropa0410942014-12-09 13:59:39 -07002718
2719 // NOTE: Bindings 1,3,5,7,8,9,11,12,14,16 work for this sampler, but 6 does not!!!
2720 // TODO: Get back here ASAP and understand why.
2721 XglSamplerObj sampler7(m_device);
2722 XglTextureObj texture7(m_device); // Red and Blue
2723 texture7.ChangeColors(0xffff00ff,0xffff00ff);
Cody Northropd1ce7842014-12-09 11:17:01 -07002724
2725 XglPipelineObj pipelineobj(m_device);
2726 pipelineobj.AddShader(&vs);
2727 pipelineobj.AddShader(&ps);
2728
2729 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002730 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2731 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2732 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2733 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2734 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2735 // swap blue and green
2736 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2737 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2738 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northropd1ce7842014-12-09 11:17:01 -07002739
2740 m_memoryRefManager.AddMemoryRef(&texture0);
2741 m_memoryRefManager.AddMemoryRef(&texture2);
2742 m_memoryRefManager.AddMemoryRef(&texture4);
Cody Northropa0410942014-12-09 13:59:39 -07002743 m_memoryRefManager.AddMemoryRef(&texture7);
Cody Northropd1ce7842014-12-09 11:17:01 -07002744
Tony Barbourdd4c9642015-01-09 12:55:14 -07002745 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2746 XglCommandBufferObj cmdBuffer(m_device);
2747 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002748
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002749 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002750
2751 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2752
2753#ifdef DUMP_STATE_DOT
2754 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2755 pDSDumpDot((char*)"triTest2.dot");
2756#endif
2757 // render triangle
2758 cmdBuffer.Draw(0, 3, 0, 1);
2759
2760 // finalize recording of the command buffer
2761 cmdBuffer.EndCommandBuffer();
2762 cmdBuffer.QueueCommandBuffer(NULL, 0);
2763
2764 for (int i = 0; i < m_renderTargetCount; i++)
2765 RecordImage(m_renderTargets[i]);
Cody Northropd1ce7842014-12-09 11:17:01 -07002766
2767}
2768
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002769TEST_F(XglRenderTest, TriangleMatchingSamplerUniformBlockBinding)
2770{
2771 // This test matches binding slots of textures and buffers, requiring
2772 // the driver to give them distinct number spaces.
2773 // The expected result from this test is a red triangle, although
2774 // you can modify it to move the desired result around.
2775
2776 static const char *vertShaderText =
2777 "#version 140\n"
2778 "#extension GL_ARB_separate_shader_objects : enable\n"
2779 "#extension GL_ARB_shading_language_420pack : enable\n"
2780 "void main() {\n"
2781 " vec2 vertices[3];"
2782 " vertices[0] = vec2(-0.5, -0.5);\n"
2783 " vertices[1] = vec2( 0.5, -0.5);\n"
2784 " vertices[2] = vec2( 0.5, 0.5);\n"
2785 " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
2786 "}\n";
2787
2788 static const char *fragShaderText =
2789 "#version 430\n"
2790 "#extension GL_ARB_separate_shader_objects : enable\n"
2791 "#extension GL_ARB_shading_language_420pack : enable\n"
2792 "layout (binding = 0) uniform sampler2D surface0;\n"
2793 "layout (binding = 1) uniform sampler2D surface1;\n"
2794 "layout (binding = 2) uniform sampler2D surface2;\n"
2795 "layout (binding = 3) uniform sampler2D surface3;\n"
Chia-I Wuf8385062015-01-04 16:27:24 +08002796 "layout (std140, binding = 4) uniform redVal { vec4 red; };"
2797 "layout (std140, binding = 5) uniform greenVal { vec4 green; };"
2798 "layout (std140, binding = 6) uniform blueVal { vec4 blue; };"
2799 "layout (std140, binding = 7) uniform whiteVal { vec4 white; };"
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002800 "layout (location = 0) out vec4 outColor;\n"
2801 "void main() {\n"
2802 " outColor = red;// * vec4(0.00001);\n"
2803 " outColor += white * vec4(0.00001);\n"
2804 " outColor += textureLod(surface1, vec2(0.5), 0.0)* vec4(0.00001);\n"
2805 " outColor += textureLod(surface3, vec2(0.0), 0.0)* vec4(0.00001);\n"
2806 "}\n";
2807 ASSERT_NO_FATAL_FAILURE(InitState());
2808 ASSERT_NO_FATAL_FAILURE(InitViewport());
2809
2810 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
2811 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
2812
2813 const float redVals[4] = { 1.0, 0.0, 0.0, 1.0 };
2814 const float greenVals[4] = { 0.0, 1.0, 0.0, 1.0 };
2815 const float blueVals[4] = { 0.0, 0.0, 1.0, 1.0 };
2816 const float whiteVals[4] = { 1.0, 1.0, 1.0, 1.0 };
2817
2818 const int redCount = sizeof(redVals) / sizeof(float);
2819 const int greenCount = sizeof(greenVals) / sizeof(float);
2820 const int blueCount = sizeof(blueVals) / sizeof(float);
2821 const int whiteCount = sizeof(whiteVals) / sizeof(float);
2822
2823 XglConstantBufferObj redBuffer(m_device, redCount, sizeof(redVals[0]), (const void*) redVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002824 XglConstantBufferObj greenBuffer(m_device, greenCount, sizeof(greenVals[0]), (const void*) greenVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002825 XglConstantBufferObj blueBuffer(m_device, blueCount, sizeof(blueVals[0]), (const void*) blueVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002826 XglConstantBufferObj whiteBuffer(m_device, whiteCount, sizeof(whiteVals[0]), (const void*) whiteVals);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002827
2828 XglSamplerObj sampler0(m_device);
2829 XglTextureObj texture0(m_device); // Light Red
2830 texture0.ChangeColors(0xff800000,0xff800000);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002831 XglSamplerObj sampler2(m_device);
2832 XglTextureObj texture2(m_device); // Light Blue
2833 texture2.ChangeColors(0xff000080,0xff000080);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002834 XglSamplerObj sampler4(m_device);
2835 XglTextureObj texture4(m_device); // Light Green
2836 texture4.ChangeColors(0xff008000,0xff008000);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002837 XglSamplerObj sampler7(m_device);
2838 XglTextureObj texture7(m_device); // Red and Blue
2839 texture7.ChangeColors(0xffff00ff,0xffff00ff);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002840
2841
2842 XglPipelineObj pipelineobj(m_device);
2843 pipelineobj.AddShader(&vs);
2844 pipelineobj.AddShader(&ps);
2845
2846 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08002847 descriptorSet.AppendSamplerTexture(&sampler0, &texture0);
2848 descriptorSet.AppendSamplerTexture(&sampler2, &texture2);
2849 descriptorSet.AppendSamplerTexture(&sampler4, &texture4);
2850 descriptorSet.AppendSamplerTexture(&sampler7, &texture7);
2851 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &redBuffer);
2852 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &greenBuffer);
2853 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &blueBuffer);
2854 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &whiteBuffer);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002855
2856 m_memoryRefManager.AddMemoryRef(&texture0);
2857 m_memoryRefManager.AddMemoryRef(&texture2);
2858 m_memoryRefManager.AddMemoryRef(&texture4);
2859 m_memoryRefManager.AddMemoryRef(&texture7);
2860
Tony Barbourdd4c9642015-01-09 12:55:14 -07002861 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2862 XglCommandBufferObj cmdBuffer(m_device);
2863 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002864
Jeremy Hayese0c3b222015-01-14 16:17:08 -07002865 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Tony Barbourdd4c9642015-01-09 12:55:14 -07002866
2867 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
2868
2869#ifdef DUMP_STATE_DOT
2870 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
2871 pDSDumpDot((char*)"triTest2.dot");
2872#endif
2873 // render triangle
2874 cmdBuffer.Draw(0, 3, 0, 1);
2875
2876 // finalize recording of the command buffer
2877 cmdBuffer.EndCommandBuffer();
2878 cmdBuffer.QueueCommandBuffer(NULL, 0);
2879
2880 for (int i = 0; i < m_renderTargetCount; i++)
2881 RecordImage(m_renderTargets[i]);
Cody Northrop5fcacbc2014-12-09 19:08:54 -07002882
2883}
2884
Cody Northrop02690bd2014-12-17 15:26:33 -07002885TEST_F(XglRenderTest, TriangleUniformBufferLayout)
2886{
2887 // This test populates a buffer with a variety of different data
2888 // types, then reads them out with a shader.
2889 // The expected result from this test is a green triangle
2890
2891 static const char *vertShaderText =
2892 "#version 140\n"
2893 "#extension GL_ARB_separate_shader_objects : enable\n"
2894 "#extension GL_ARB_shading_language_420pack : enable\n"
2895 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2896 " vec4 fRed;\n"
2897 " vec4 fGreen;\n"
2898 " layout(row_major) mat4 worldToProj;\n"
2899 " layout(row_major) mat4 projToWorld;\n"
2900 " layout(row_major) mat4 worldToView;\n"
2901 " layout(row_major) mat4 viewToProj;\n"
2902 " layout(row_major) mat4 worldToShadow[4];\n"
2903 " float fZero;\n"
2904 " float fOne;\n"
2905 " float fTwo;\n"
2906 " float fThree;\n"
2907 " vec3 fZeroZeroZero;\n"
2908 " float fFour;\n"
2909 " vec3 fZeroZeroOne;\n"
2910 " float fFive;\n"
2911 " vec3 fZeroOneZero;\n"
2912 " float fSix;\n"
2913 " float fSeven;\n"
2914 " float fEight;\n"
2915 " float fNine;\n"
2916 " vec2 fZeroZero;\n"
2917 " vec2 fZeroOne;\n"
2918 " vec4 fBlue;\n"
2919 " vec2 fOneZero;\n"
2920 " vec2 fOneOne;\n"
2921 " vec3 fZeroOneOne;\n"
2922 " float fTen;\n"
2923 " float fEleven;\n"
2924 " float fTwelve;\n"
2925 " vec3 fOneZeroZero;\n"
2926 " vec4 uvOffsets[4];\n"
2927 "};\n"
2928 "layout (location = 0) out vec4 color;"
2929 "void main() {\n"
2930
2931 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
2932 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
2933 " \n"
2934
2935 // do some exact comparisons, even though we should
2936 // really have an epsilon involved.
2937 " vec4 outColor = right;\n"
2938 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
2939 " outColor = wrong;\n"
2940 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
2941 " outColor = wrong;\n"
2942 " if (fBlue != vec4(0.0, 0.0, 1.0, 1.0))\n"
2943 " outColor = wrong;\n"
2944
2945 " color = outColor;\n"
2946
2947 // generic position stuff
2948 " vec2 vertices;\n"
2949 " int vertexSelector = gl_VertexID;\n"
2950 " if (vertexSelector == 0)\n"
2951 " vertices = vec2(-0.5, -0.5);\n"
2952 " else if (vertexSelector == 1)\n"
2953 " vertices = vec2( 0.5, -0.5);\n"
2954 " else if (vertexSelector == 2)\n"
2955 " vertices = vec2( 0.5, 0.5);\n"
2956 " else\n"
2957 " vertices = vec2( 0.0, 0.0);\n"
2958 " gl_Position = vec4(vertices, 0.0, 1.0);\n"
2959 "}\n";
2960
2961 static const char *fragShaderText =
2962 "#version 140\n"
2963 "#extension GL_ARB_separate_shader_objects : enable\n"
2964 "#extension GL_ARB_shading_language_420pack : enable\n"
2965 "layout (std140, binding = 0) uniform mixedBuffer {\n"
2966 " vec4 fRed;\n"
2967 " vec4 fGreen;\n"
2968 " layout(row_major) mat4 worldToProj;\n"
2969 " layout(row_major) mat4 projToWorld;\n"
2970 " layout(row_major) mat4 worldToView;\n"
2971 " layout(row_major) mat4 viewToProj;\n"
2972 " layout(row_major) mat4 worldToShadow[4];\n"
2973 " float fZero;\n"
2974 " float fOne;\n"
2975 " float fTwo;\n"
2976 " float fThree;\n"
2977 " vec3 fZeroZeroZero;\n"
2978 " float fFour;\n"
2979 " vec3 fZeroZeroOne;\n"
2980 " float fFive;\n"
2981 " vec3 fZeroOneZero;\n"
2982 " float fSix;\n"
2983 " float fSeven;\n"
2984 " float fEight;\n"
2985 " float fNine;\n"
2986 " vec2 fZeroZero;\n"
2987 " vec2 fZeroOne;\n"
2988 " vec4 fBlue;\n"
2989 " vec2 fOneZero;\n"
2990 " vec2 fOneOne;\n"
2991 " vec3 fZeroOneOne;\n"
2992 " float fTen;\n"
2993 " float fEleven;\n"
2994 " float fTwelve;\n"
2995 " vec3 fOneZeroZero;\n"
2996 " vec4 uvOffsets[4];\n"
2997 "};\n"
2998 "layout (location = 0) in vec4 color;\n"
2999 "void main() {\n"
3000 " vec4 right = vec4(0.0, 1.0, 0.0, 1.0);\n"
3001 " vec4 wrong = vec4(1.0, 0.0, 0.0, 1.0);\n"
3002 " \n"
3003
3004 // start with VS value to ensure it passed
3005 " vec4 outColor = color;\n"
3006
3007 // do some exact comparisons, even though we should
3008 // really have an epsilon involved.
3009 " if (fRed != vec4(1.0, 0.0, 0.0, 1.0))\n"
3010 " outColor = wrong;\n"
3011 " if (fGreen != vec4(0.0, 1.0, 0.0, 1.0))\n"
3012 " outColor = wrong;\n"
3013 " if (projToWorld[1] != vec4(0.0, 2.0, 0.0, 0.0))\n"
3014 " outColor = wrong;\n"
3015 " if (worldToShadow[2][1] != vec4(0.0, 7.0, 0.0, 0.0))\n"
3016 " outColor = wrong;\n"
3017 " if (fTwo != 2.0)\n"
3018 " outColor = wrong;\n"
3019 " if (fOneOne != vec2(1.0, 1.0))\n"
3020 " outColor = wrong;\n"
3021 " if (fTen != 10.0)\n"
3022 " outColor = wrong;\n"
3023 " if (uvOffsets[2] != vec4(0.9, 1.0, 1.1, 1.2))\n"
3024 " outColor = wrong;\n"
3025 " \n"
3026 " gl_FragColor = outColor;\n"
3027 "}\n";
3028
3029
3030 const float mixedVals[196] = { 1.0, 0.0, 0.0, 1.0, // vec4 fRed; // align
3031 0.0, 1.0, 0.0, 1.0, // vec4 fGreen; // align
3032 1.0, 0.0, 0.0, 1.0, // layout(row_major) mat4 worldToProj;
3033 0.0, 1.0, 0.0, 1.0, // align
3034 0.0, 0.0, 1.0, 1.0, // align
3035 0.0, 0.0, 0.0, 1.0, // align
3036 2.0, 0.0, 0.0, 2.0, // layout(row_major) mat4 projToWorld;
3037 0.0, 2.0, 0.0, 2.0, // align
3038 0.0, 0.0, 2.0, 2.0, // align
3039 0.0, 0.0, 0.0, 2.0, // align
3040 3.0, 0.0, 0.0, 3.0, // layout(row_major) mat4 worldToView;
3041 0.0, 3.0, 0.0, 3.0, // align
3042 0.0, 0.0, 3.0, 3.0, // align
3043 0.0, 0.0, 0.0, 3.0, // align
3044 4.0, 0.0, 0.0, 4.0, // layout(row_major) mat4 viewToProj;
3045 0.0, 4.0, 0.0, 4.0, // align
3046 0.0, 0.0, 4.0, 4.0, // align
3047 0.0, 0.0, 0.0, 4.0, // align
3048 5.0, 0.0, 0.0, 5.0, // layout(row_major) mat4 worldToShadow[4];
3049 0.0, 5.0, 0.0, 5.0, // align
3050 0.0, 0.0, 5.0, 5.0, // align
3051 0.0, 0.0, 0.0, 5.0, // align
3052 6.0, 0.0, 0.0, 6.0, // align
3053 0.0, 6.0, 0.0, 6.0, // align
3054 0.0, 0.0, 6.0, 6.0, // align
3055 0.0, 0.0, 0.0, 6.0, // align
3056 7.0, 0.0, 0.0, 7.0, // align
3057 0.0, 7.0, 0.0, 7.0, // align
3058 0.0, 0.0, 7.0, 7.0, // align
3059 0.0, 0.0, 0.0, 7.0, // align
3060 8.0, 0.0, 0.0, 8.0, // align
3061 0.0, 8.0, 0.0, 8.0, // align
3062 0.0, 0.0, 8.0, 8.0, // align
3063 0.0, 0.0, 0.0, 8.0, // align
3064 0.0, // float fZero; // align
3065 1.0, // float fOne; // pack
3066 2.0, // float fTwo; // pack
3067 3.0, // float fThree; // pack
3068 0.0, 0.0, 0.0, // vec3 fZeroZeroZero; // align
3069 4.0, // float fFour; // pack
3070 0.0, 0.0, 1.0, // vec3 fZeroZeroOne; // align
3071 5.0, // float fFive; // pack
3072 0.0, 1.0, 0.0, // vec3 fZeroOneZero; // align
3073 6.0, // float fSix; // pack
3074 7.0, // float fSeven; // align
3075 8.0, // float fEight; // pack
3076 9.0, // float fNine; // pack
3077 0.0, // BUFFER
3078 0.0, 0.0, // vec2 fZeroZero; // align
3079 0.0, 1.0, // vec2 fZeroOne; // pack
3080 0.0, 0.0, 1.0, 1.0, // vec4 fBlue; // align
3081 1.0, 0.0, // vec2 fOneZero; // align
3082 1.0, 1.0, // vec2 fOneOne; // pack
3083 0.0, 1.0, 1.0, // vec3 fZeroOneOne; // align
3084 10.0, // float fTen; // pack
3085 11.0, // float fEleven; // align
3086 12.0, // float fTwelve; // pack
3087 0.0, 0.0, // BUFFER
3088 1.0, 0.0, 0.0, // vec3 fOneZeroZero; // align
3089 0.0, // BUFFER
3090 0.1, 0.2, 0.3, 0.4, // vec4 uvOffsets[4];
3091 0.5, 0.6, 0.7, 0.8, // align
3092 0.9, 1.0, 1.1, 1.2, // align
3093 1.3, 1.4, 1.5, 1.6, // align
3094 };
3095
3096 ASSERT_NO_FATAL_FAILURE(InitState());
3097 ASSERT_NO_FATAL_FAILURE(InitViewport());
3098
3099 const int constCount = sizeof(mixedVals) / sizeof(float);
3100
3101 XglShaderObj vs(m_device,vertShaderText,XGL_SHADER_STAGE_VERTEX, this);
3102 XglShaderObj ps(m_device,fragShaderText, XGL_SHADER_STAGE_FRAGMENT, this);
3103
3104 XglConstantBufferObj mixedBuffer(m_device, constCount, sizeof(mixedVals[0]), (const void*) mixedVals);
Cody Northrop02690bd2014-12-17 15:26:33 -07003105
3106 XglPipelineObj pipelineobj(m_device);
3107 pipelineobj.AddShader(&vs);
3108 pipelineobj.AddShader(&ps);
3109
3110 XglDescriptorSetObj descriptorSet(m_device);
Chia-I Wuf8385062015-01-04 16:27:24 +08003111 descriptorSet.AppendBuffer(XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &mixedBuffer);
Cody Northrop02690bd2014-12-17 15:26:33 -07003112
3113 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3114 XglCommandBufferObj cmdBuffer(m_device);
3115 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
3116
Jeremy Hayese0c3b222015-01-14 16:17:08 -07003117 ASSERT_XGL_SUCCESS(cmdBuffer.BeginCommandBuffer(renderPass()));
Cody Northrop02690bd2014-12-17 15:26:33 -07003118
3119 GenericDrawPreparation(&cmdBuffer, &pipelineobj, &descriptorSet);
3120
3121#ifdef DUMP_STATE_DOT
3122 DRAW_STATE_DUMP_DOT_FILE pDSDumpDot = (DRAW_STATE_DUMP_DOT_FILE)xglGetProcAddr(gpu(), (XGL_CHAR*)"drawStateDumpDotFile");
3123 pDSDumpDot((char*)"triTest2.dot");
3124#endif
3125 // render triangle
3126 cmdBuffer.Draw(0, 3, 0, 1);
3127
3128 // finalize recording of the command buffer
3129 cmdBuffer.EndCommandBuffer();
3130 cmdBuffer.QueueCommandBuffer(NULL, 0);
3131
3132 for (int i = 0; i < m_renderTargetCount; i++)
3133 RecordImage(m_renderTargets[i]);
3134}
3135
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003136int main(int argc, char **argv) {
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003137 int result;
3138
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003139 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003140 XglTestFramework::InitArgs(&argc, argv);
3141
Chia-I Wu7133fdc2014-12-15 23:57:34 +08003142 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -06003143
Courtney Goeltzenleuchter28029792014-09-04 16:26:02 -06003144 result = RUN_ALL_TESTS();
3145
3146 XglTestFramework::Finish();
3147 return result;
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003148}